Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ jobs:
- name: Install npm packages
run: yarn install

- name: Install testrepo deps
run: cd rewatch/testrepo && yarn install

- name: Install dependencies (Linux)
if: runner.os == 'Linux'
uses: awalsh128/[email protected]
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#### :boom: Breaking Change

- Remove the legacy build system. Going forward, only the modern build system is supported, and the `rescript-legacy` command is not available anymore. https://github.com/rescript-lang/rescript/pull/8186
- Remove support for `bsconfig.json`. https://github.com/rescript-lang/rescript/pull/8187
- `Int.fromString` and `Float.fromString` use stricter number parsing and no longer uses an explicit radix argument, but instead supports parsing hexadecimal, binary and exponential notation.
- Remove `external-stdlib` configuration option from `rescript.json`. This option was rarely used and is no longer supported.

Expand Down
12 changes: 3 additions & 9 deletions analysis/reanalyze/src/Paths.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module StringMap = Map_string

let bsconfig = "bsconfig.json"
let rescriptJson = "rescript.json"

let readFile filename =
Expand All @@ -14,8 +13,7 @@ let readFile filename =

let rec findProjectRoot ~dir =
let rescriptJsonFile = Filename.concat dir rescriptJson in
let bsconfigFile = Filename.concat dir bsconfig in
if Sys.file_exists rescriptJsonFile || Sys.file_exists bsconfigFile then dir
if Sys.file_exists rescriptJsonFile then dir
else
let parent = dir |> Filename.dirname in
if parent = dir then (
Expand Down Expand Up @@ -84,10 +82,9 @@ module Config = struct
| _ -> ()

(* Read the config from rescript.json and apply it to runConfig and suppress and unsuppress *)
let processBsconfig () =
let processConfig () =
setProjectRootFromCwd ();
let rescriptFile = Filename.concat runConfig.projectRoot rescriptJson in
let bsconfigFile = Filename.concat runConfig.projectRoot bsconfig in

let processText text =
match Json.parse text with
Expand All @@ -106,10 +103,7 @@ module Config = struct

match readFile rescriptFile with
| Some text -> processText text
| None -> (
match readFile bsconfigFile with
| Some text -> processText text
| None -> ())
| None -> ()
end

(**
Expand Down
4 changes: 2 additions & 2 deletions analysis/reanalyze/src/Reanalyze.ml
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ let parse_argv (argv : string array) : string option =
cmtRootRef := cmtRoot;
analysisKindSet := true
and setConfig () =
Paths.Config.processBsconfig ();
Paths.Config.processConfig ();
analysisKindSet := true
and setDCE cmtRoot =
RunConfig.dce ();
Expand Down Expand Up @@ -787,7 +787,7 @@ let parse_argv (argv : string array) : string option =
- reanalyze can be called from anywhere within the project
Project root detection reuses the same logic as reanalyze config discovery:
walk up from a directory until we find rescript.json or bsconfig.json. *)
walk up from a directory until we find rescript.json. *)
let cli () =
let cmtRoot = parse_argv Sys.argv in
runAnalysisAndReport ~cmtRoot
Expand Down
2 changes: 1 addition & 1 deletion analysis/reanalyze/src/ReanalyzeServer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
- reanalyze can be called from anywhere within the project
Project root detection reuses the same logic as reanalyze config discovery:
walk up from a directory until we find rescript.json or bsconfig.json. *)
walk up from a directory until we find rescript.json. *)
let default_socket_filename = ".rescript-reanalyze.sock"

let project_root_from_dir (dir : string) : string option =
Expand Down
6 changes: 1 addition & 5 deletions analysis/src/FindFiles.ml
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ let findDependencyFiles base config =
(ModuleResolution.resolveNodeModulePath ~startPath:base name)
(fun path ->
let rescriptJsonPath = path /+ "rescript.json" in
let bsconfigJsonPath = path /+ "bsconfig.json" in

let parseText text =
match Json.parse text with
Expand Down Expand Up @@ -272,10 +271,7 @@ let findDependencyFiles base config =

match Files.readFile rescriptJsonPath with
| Some text -> parseText text
| None -> (
match Files.readFile bsconfigJsonPath with
| Some text -> parseText text
| None -> None))
| None -> None)
in

match result with
Expand Down
15 changes: 4 additions & 11 deletions analysis/src/Packages.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ let getReScriptVersion () =

let newBsPackage ~rootPath =
let rescriptJson = Filename.concat rootPath "rescript.json" in
let bsconfigJson = Filename.concat rootPath "bsconfig.json" in

let parseRaw raw =
let libBs =
Expand Down Expand Up @@ -192,23 +191,17 @@ let newBsPackage ~rootPath =

match Files.readFile rescriptJson with
| Some raw -> parseRaw raw
| None -> (
| None ->
Log.log ("Unable to read " ^ rescriptJson);
match Files.readFile bsconfigJson with
| Some raw -> parseRaw raw
| None ->
Log.log ("Unable to read " ^ bsconfigJson);
None)
None

let findRoot ~uri packagesByRoot =
let path = Uri.toPath uri in
let rec loop path =
if path = "/" then None
else if Hashtbl.mem packagesByRoot path then Some (`Root path)
else if
Files.exists (Filename.concat path "rescript.json")
|| Files.exists (Filename.concat path "bsconfig.json")
then Some (`Bs path)
else if Files.exists (Filename.concat path "rescript.json") then
Some (`Bs path)
else
let parent = Filename.dirname path in
if parent = path then (* reached root *) None else loop parent
Expand Down
3 changes: 1 addition & 2 deletions compiler/ext/ext_path.ml
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ let rec find_root_filename ~cwd filenames =
Ext_fmt.failwithf ~loc:__LOC__ "%s not found from %s" (List.hd filenames)
cwd

let find_config_dir cwd =
find_root_filename ~cwd [Literals.rescript_json; Literals.bsconfig_json]
let find_config_dir cwd = find_root_filename ~cwd [Literals.rescript_json]

let package_dir = lazy (find_config_dir (Lazy.force cwd))
2 changes: 0 additions & 2 deletions compiler/ext/literals.ml
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ let node_modules_length = String.length "node_modules"

let package_json = "package.json"

let bsconfig_json = "bsconfig.json"

let rescript_json = "rescript.json"

(* Name of the library file created for each external dependency. *)
Expand Down
12 changes: 6 additions & 6 deletions compiler/frontend/ast_config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ let process_directives str =
| None -> Bs_syntaxerr.err item.pstr_loc Expect_string_literal)
| _ -> ())

let rec iter_on_bs_config_str (x : Parsetree.structure) =
let rec iter_on_config_str (x : Parsetree.structure) =
match x with
| [] -> ()
| {pstr_desc = Pstr_attribute (({txt = "config"; loc}, payload) as attr)} :: _
Expand All @@ -61,14 +61,14 @@ let rec iter_on_bs_config_str (x : Parsetree.structure) =
Ext_list.iter
(Ast_payload.ident_or_record_as_config loc payload)
(Ast_payload.table_dispatch !structural_config_table)
| {pstr_desc = Pstr_attribute _} :: rest -> iter_on_bs_config_str rest
| {pstr_desc = Pstr_attribute _} :: rest -> iter_on_config_str rest
| _ :: _ -> ()

let process_str str =
iter_on_bs_config_str str;
iter_on_config_str str;
process_directives str

let rec iter_on_bs_config_sig (x : Parsetree.signature) =
let rec iter_on_config_sig (x : Parsetree.signature) =
match x with
| [] -> ()
| {psig_desc = Psig_attribute (({txt = "config"; loc}, payload) as attr)} :: _
Expand All @@ -77,7 +77,7 @@ let rec iter_on_bs_config_sig (x : Parsetree.signature) =
Ext_list.iter
(Ast_payload.ident_or_record_as_config loc payload)
(Ast_payload.table_dispatch !signature_config_table)
| {psig_desc = Psig_attribute _} :: rest -> iter_on_bs_config_sig rest
| {psig_desc = Psig_attribute _} :: rest -> iter_on_config_sig rest
| _ :: _ -> ()

let process_sig s = iter_on_bs_config_sig s
let process_sig s = iter_on_config_sig s
10 changes: 3 additions & 7 deletions compiler/gentype/GenTypeConfig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,9 @@ let set_debug ~gtconf =
| _ -> ()

let compiler_config_file = "rescript.json"
let legacy_compiler_config_file = "bsconfig.json"

let rec find_project_root ~dir =
if
Sys.file_exists (Filename.concat dir compiler_config_file)
|| Sys.file_exists (Filename.concat dir legacy_compiler_config_file)
then dir
if Sys.file_exists (Filename.concat dir compiler_config_file) then dir
else
let parent = dir |> Filename.dirname in
if parent = dir then (
Expand Down Expand Up @@ -238,9 +234,9 @@ let read_config ~get_config_file ~namespace =
in
let default_config = {default with project_root; bsb_project_root} in
match get_config_file ~project_root with
| Some bs_config_file -> (
| Some config_file -> (
try
let json = bs_config_file |> Ext_json_parse.parse_json_from_file in
let json = config_file |> Ext_json_parse.parse_json_from_file in
match json with
| Obj {map = bsconf} -> (
match bsconf |> get_opt "gentypeconfig" with
Expand Down
6 changes: 1 addition & 5 deletions compiler/gentype/Paths.ml
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@ let get_config_file ~project_root =
let config = concat project_root Config.compiler_config_file in
match config |> Sys.file_exists with
| true -> Some config
| false -> (
let config = concat project_root Config.legacy_compiler_config_file in
match config |> Sys.file_exists with
| true -> Some config
| false -> None)
| false -> None

let read_config ~namespace = Config.read_config ~get_config_file ~namespace
2 changes: 1 addition & 1 deletion rewatch/CompilerConfigurationSpec.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## ReScript build configuration

This document contains a list of all bsconfig parameters with remarks, and whether they are already implemented in rewatch. It is based on https://rescript-lang.org/docs/manual/latest/build-configuration-schema.
This document contains a list of all config parameters with remarks, and whether they are already implemented in rewatch. It is based on https://rescript-lang.org/docs/manual/latest/build-configuration-schema.

| Parameter | JSON type | Remark | Implemented? |
| --------------------- | ----------------------- | ---------------------------------------- | :----------: |
Expand Down
4 changes: 2 additions & 2 deletions rewatch/MonorepoSupport.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ All statements are derived from:

| Term | Definition |
|------|------------|
| **Package** | A folder containing `rescript.json` (or legacy `bsconfig.json`). Usually also has `package.json`. |
| **Package** | A folder containing `rescript.json`. Usually also has `package.json`. |
| **Root config** | The `rescript.json` used for global build settings (JSX, output format, etc.). |
| **Local package** | A package whose canonical path is inside the workspace AND not under any `node_modules` path component. |
| **Current package** | The package where you ran `rescript build` or `rescript watch`. |
Expand All @@ -41,7 +41,7 @@ There are **three effective modes**:
- The root `rescript.json` should list workspace packages by name in `dependencies`/`dev-dependencies`

### 3. Monorepo Leaf Package
- A parent directory contains a `rescript.json` (or `bsconfig.json`)
- A parent directory contains a `rescript.json`
- That parent config lists this package's name in its `dependencies` or `dev-dependencies`

---
Expand Down
8 changes: 1 addition & 7 deletions rewatch/src/build/packages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,7 @@ fn get_source_dirs(source: config::Source, sub_path: Option<PathBuf>) -> AHashSe

pub fn read_config(package_dir: &Path) -> Result<Config> {
let rescript_json_path = package_dir.join("rescript.json");
let bsconfig_json_path = package_dir.join("bsconfig.json");

if Path::new(&rescript_json_path).exists() {
Config::new(&rescript_json_path)
} else {
Config::new(&bsconfig_json_path)
}
Config::new(&rescript_json_path)
}

pub fn read_dependency(
Expand Down
6 changes: 3 additions & 3 deletions rewatch/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl Source {
}

/// `to_qualified_without_children` takes a tree like structure of dependencies, coming in from
/// `bsconfig`, and turns it into a flat list. The main thing we extract here are the source
/// `rescript.json`, and turns it into a flat list. The main thing we extract here are the source
/// folders, and optional subdirs, where potentially, the subdirs recurse or not.
pub fn to_qualified_without_children(&self, sub_path: Option<PathBuf>) -> PackageSource {
match self {
Expand Down Expand Up @@ -446,15 +446,15 @@ fn namespace_from_package_name(package_name: &str) -> String {
}

impl Config {
/// Try to convert a bsconfig from a certain path to a bsconfig struct
/// Try to convert a config from a certain path to a config struct
pub fn new(path: &Path) -> Result<Self> {
let read = fs::read_to_string(path)?;
let mut config = Config::new_from_json_string(&read)?;
config.set_path(path.to_path_buf())?;
Ok(config)
}

/// Try to convert a bsconfig from a string to a bsconfig struct
/// Try to convert a config from a string to a config struct
pub fn new_from_json_string(config_str: &str) -> Result<Self> {
let mut deserializer = serde_json::Deserializer::from_str(config_str);
let mut tracker = serde_path_to_error::Track::new();
Expand Down
2 changes: 1 addition & 1 deletion rewatch/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ pub fn compute_file_hash(path: &Path) -> Option<blake3::Hash> {
}

fn has_rescript_config(path: &Path) -> bool {
path.join("bsconfig.json").exists() || path.join("rescript.json").exists()
path.join("rescript.json").exists()
}

// traverse up the directory tree until we find a config.json, if not return None
Expand Down
2 changes: 1 addition & 1 deletion rewatch/tests/suite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fi
source ./utils.sh

bold "Yarn install"
(cd ../testrepo && yarn)
(cd ../testrepo && yarn && cp node_modules/rescript-nodejs/bsconfig.json node_modules/rescript-nodejs/rescript.json)

bold "Rescript version"
(cd ../testrepo && ./node_modules/.bin/rescript --version)
Expand Down
2 changes: 1 addition & 1 deletion tests/build_tests/warn_legacy_config/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ const { execBuild, execClean } = setup(import.meta.dirname);

const output = await execBuild();
assert.notEqual(output.status, 0);
assert.match(output.stderr, /no package\.json or rescript\.json file/i);
assert.match(output.stderr, /could not read rescript\.json/i);
await execClean();
3 changes: 0 additions & 3 deletions tests/tests/src/test_literals.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ let node_modules_length = "node_modules".length;

let node_modules = "node_modules";

let bsconfig_json = "bsconfig.json";

export {
node_modules,
node_modules_length,
bsconfig_json,
}
/* node_modules_length Not a pure module */
2 changes: 0 additions & 2 deletions tests/tests/src/test_literals.res
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/** nodejs */
let node_modules = "node_modules"
let node_modules_length = String.length("node_modules")

let bsconfig_json = "bsconfig.json"
2 changes: 1 addition & 1 deletion tools/bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ let main () =
(Error
(Printf.sprintf
"error: failed to load ReScript project at %s (missing \
bsconfig.json/rescript.json?)"
rescript.json?)"
rootPath))
| Some package ->
let moduleNames =
Expand Down
Loading