Skip to content

Commit fcca5c8

Browse files
committed
new runtime resolution
1 parent 9409822 commit fcca5c8

File tree

245 files changed

+538
-547
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

245 files changed

+538
-547
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ reanalyze:
5858
reanalyze.exe -set-exit-code -all-cmt _build/default/compiler _build/default/tests -exclude-paths compiler/outcome_printer,compiler/ml,compiler/frontend,compiler/ext,compiler/depends,compiler/core,compiler/common,compiler/cmij,compiler/bsb_helper,compiler/bsb
5959

6060
lib-bsb:
61-
./scripts/buildRuntime.sh
61+
yarn workspace @rescript/runtime build:bsb
6262
./scripts/prebuilt.js
6363

6464
lib:
65-
./scripts/buildRuntimeRewatch.sh
65+
yarn workspace @rescript/runtime build:rewatch
6666
./scripts/prebuilt.js
6767

6868
artifacts: lib
@@ -96,7 +96,7 @@ clean-rewatch:
9696
cargo clean --manifest-path rewatch/Cargo.toml && rm -f rewatch/rewatch
9797

9898
clean:
99-
(cd runtime && ../cli/rescript.js clean)
99+
yarn workspace @rescript/runtime clean
100100
dune clean
101101

102102
clean-all: clean clean-gentype clean-rewatch

analysis/src/BuildSystem.ml

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,21 @@ let namespacedName namespace name =
55

66
let ( /+ ) = Filename.concat
77

8-
let getBsPlatformDir rootPath =
9-
match !Cfg.isDocGenFromCompiler with
10-
| false -> (
11-
let result =
12-
ModuleResolution.resolveNodeModulePath ~startPath:rootPath "rescript"
13-
in
14-
match result with
15-
| Some path -> Some path
16-
| None ->
17-
let message = "rescript could not be found" in
18-
Log.log message;
19-
None)
20-
| true -> Some rootPath
8+
let getRuntimeDir rootPath =
9+
let result =
10+
ModuleResolution.resolveNodeModulePath ~startPath:rootPath
11+
"@rescript/runtime"
12+
in
13+
match result with
14+
| Some path -> Some path
15+
| None ->
16+
let message = "@rescript/runtime could not be found" in
17+
Log.log message;
18+
None
2119

2220
let getLibBs root = Files.ifExists (root /+ "lib" /+ "bs")
2321

2422
let getStdlib base =
25-
match getBsPlatformDir base with
23+
match getRuntimeDir base with
2624
| None -> None
27-
| Some bsPlatformDir -> Some (bsPlatformDir /+ "lib" /+ "ocaml")
25+
| Some runtimeDir -> Some (runtimeDir /+ "lib" /+ "ocaml")

analysis/src/Files.ml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,26 @@ let rec collectDirs path =
8484
|> List.concat)
8585
| _ -> []
8686

87-
let rec collect ?(checkDir = fun _ -> true) path test =
88-
match maybeStat path with
89-
| None -> []
90-
| Some {Unix.st_kind = Unix.S_DIR} ->
87+
let rec collect ?(checkDir = fun _ -> true) ?maxDepth path test =
88+
match (maxDepth, maybeStat path) with
89+
| None, None -> []
90+
| Some 0, _ -> []
91+
| None, Some {Unix.st_kind = Unix.S_DIR} ->
9192
if checkDir path then
9293
readDirectory path
9394
|> List.map (fun name ->
9495
collect ~checkDir (Filename.concat path name) test)
9596
|> List.concat
9697
else []
98+
| Some n, Some {Unix.st_kind = Unix.S_DIR} ->
99+
if checkDir path then
100+
readDirectory path
101+
|> List.map (fun name ->
102+
collect ~checkDir ~maxDepth:(n - 1)
103+
(Filename.concat path name)
104+
test)
105+
|> List.concat
106+
else []
97107
| _ -> if test path then [path] else []
98108
99109
type classifiedFile = Res | Resi | Other

analysis/src/FindFiles.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ let findProjectFiles ~public ~namespace ~path ~sourceDirectories ~libBs =
142142
in
143143
let files =
144144
dirs |> StringSet.elements
145-
|> List.map (fun name -> Files.collect name isSourceFile)
145+
|> List.map (fun name -> Files.collect ~maxDepth:1 name isSourceFile)
146146
|> List.concat |> StringSet.of_list
147147
in
148148
dirs

analysis/src/ModuleResolution.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
let ( /+ ) = Filename.concat
22

33
let rec resolveNodeModulePath ~startPath name =
4+
let scope = Filename.dirname name in
5+
let name = Filename.basename name in
6+
let name =
7+
match scope.[0] with
8+
| '@' -> scope /+ name
9+
| _ -> name
10+
in
411
let path = startPath /+ "node_modules" /+ name in
512
if Files.exists path then Some path
613
else if Filename.dirname startPath = startPath then None

cli/common/bsb.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { createServer } from "node:http";
66
import * as os from "node:os";
77
import * as path from "node:path";
88

9-
import { WebSocket } from "./minisocket.js";
109
import { rescript_exe } from "./bins.js";
10+
import { WebSocket } from "./minisocket.js";
1111

1212
const cwd = process.cwd();
1313
const lockFileName = path.join(cwd, ".bsb.lock");

compiler/bsc/rescript_compiler_main.ml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,6 @@ let define_variable s =
184184
Bsc_args.bad_arg ("illegal definition: " ^ s)
185185
| _ -> Bsc_args.bad_arg ("illegal definition: " ^ s)
186186

187-
let print_standard_library () =
188-
let standard_library = Config.standard_library in
189-
print_string standard_library;
190-
print_newline ();
191-
exit 0
192-
193187
let bs_version_string = "ReScript " ^ Bs_version.version
194188

195189
let print_version_string () =
@@ -366,9 +360,6 @@ let buckle_script_flags : (string * Bsc_args.spec * string) array =
366360
( "-ignore-parse-errors",
367361
set Clflags.ignore_parse_errors,
368362
"*internal* continue after parse errors" );
369-
( "-where",
370-
unit_call print_standard_library,
371-
"*internal* Print location of standard library and exit" );
372363
( "-verbose",
373364
set Clflags.verbose,
374365
"*internal* Print calls to external commands" );

compiler/common/bs_version.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424
let version = "12.0.0-alpha.13"
2525
let header = "// Generated by ReScript, PLEASE EDIT WITH CARE"
26-
let package_name = ref "rescript"
26+
let package_name = ref "@rescript/runtime"

compiler/ext/config.ml

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,13 @@
11
let version = "4.06.1+BS"
22

3-
(* FIXME: Unreliable resolution *)
43
let standard_library =
54
let ( // ) = Filename.concat in
5+
(* @rescript/{platform}/bin/rescript.exe *)
66
let exe_path = Sys.executable_name in
7-
if Ext_string.contain_substring exe_path ("node_modules" // "@rescript") then
8-
(* node_modules/@rescript/{platform}/bin *)
9-
Filename.dirname exe_path // Filename.parent_dir_name
10-
// Filename.parent_dir_name // Filename.parent_dir_name // "rescript"
11-
// "lib" // "ocaml"
12-
else if Ext_string.contain_substring exe_path ("node_modules" // "rescript")
13-
then
14-
(* node_modules/rescript/{platform} *)
15-
Filename.dirname exe_path // Filename.parent_dir_name // "lib" // "ocaml"
16-
else
17-
(* git repo: rescript/packages/@rescript/{platform}/bin *)
18-
Filename.dirname exe_path // Filename.parent_dir_name
19-
// Filename.parent_dir_name // Filename.parent_dir_name
20-
// Filename.parent_dir_name // "lib" // "ocaml"
21-
22-
let standard_library_default = standard_library
7+
let bin_dir = Filename.dirname exe_path in
8+
let platform_dir = Filename.dirname bin_dir in
9+
let rescript_dir = Filename.dirname platform_dir in
10+
rescript_dir // "runtime" // "lib" // "ocaml"
2311

2412
let unsafe_empty_array = ref false
2513

@@ -32,20 +20,3 @@ and ast_intf_magic_number = "Caml1999N022"
3220
and cmt_magic_number = "Caml1999T022"
3321

3422
let load_path = ref ([] : string list)
35-
36-
(* This is normally the same as in obj.ml, but we have to define it
37-
separately because it can differ when we're in the middle of a
38-
bootstrapping phase. *)
39-
40-
let print_config oc =
41-
let p name valu = Printf.fprintf oc "%s: %s\n" name valu in
42-
p "version" version;
43-
p "standard_library_default" standard_library_default;
44-
p "standard_library" standard_library;
45-
46-
(* print the magic number *)
47-
p "cmi_magic_number" cmi_magic_number;
48-
p "ast_impl_magic_number" ast_impl_magic_number;
49-
p "ast_intf_magic_number" ast_intf_magic_number;
50-
p "cmt_magic_number" cmt_magic_number;
51-
flush oc

compiler/ext/config.mli

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,3 @@ val ast_impl_magic_number : string
3737
(* Magic number for file holding an implementation syntax tree *)
3838
val cmt_magic_number : string
3939
(* Magic number for compiled interface files *)
40-
41-
val print_config : out_channel -> unit

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
"CREDITS.md",
6262
"ninja.COPYING",
6363
"docs/docson/build-schema.json",
64-
"lib",
6564
"cli"
6665
],
6766
"exports": {
@@ -74,6 +73,9 @@
7473
"#dev/*": "./lib_dev/*.js",
7574
"#lib/minisocket": "./lib/minisocket.js"
7675
},
76+
"dependencies": {
77+
"@rescript/runtime": "workspace:packages/@rescript/runtime"
78+
},
7779
"optionalDependencies": {
7880
"@rescript/darwin-arm64": "workspace:packages/@rescript/darwin-arm64",
7981
"@rescript/darwin-x64": "workspace:packages/@rescript/darwin-x64",

packages/@rescript/runtime/package.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,20 @@
1111
"access": "public"
1212
},
1313
"files": [
14-
"lib"
14+
"lib/es6",
15+
"lib/js",
16+
"*.res",
17+
"*.resi"
1518
],
19+
"exports": {
20+
"./lib/es6/*": "./lib/es6/*",
21+
"./lib/js/*": "./lib/js/*",
22+
"./package.json": "./package.json"
23+
},
1624
"scripts": {
1725
"build:rewatch": "rewatch build",
18-
"build:bsb": "rescript build"
26+
"build:bsb": "rescript build",
27+
"clean": "rewatch clean"
1928
},
2029
"devDependencies": {
2130
"rescript": "workspace:^"

scripts/format_check.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ case "$(uname -s)" in
1717
fi
1818

1919
echo "Checking ReScript code formatting..."
20-
files=$(find runtime tests -type f \( -name "*.res" -o -name "*.resi" \) ! -name "syntaxErrors*" ! -name "generated_mocha_test.res" ! -path "tests/syntax_*" ! -path "tests/analysis_tests/tests*" ! -path "*/node_modules/*")
20+
files=$(find packages/@rescript/runtime tests -type f \( -name "*.res" -o -name "*.resi" \) ! -name "syntaxErrors*" ! -name "generated_mocha_test.res" ! -path "tests/syntax_*" ! -path "tests/analysis_tests/tests*" ! -path "*/node_modules/*")
2121
if ./cli/rescript.js format -check $files; then
2222
printf "${successGreen}✅ ReScript code formatting ok.${reset}\n"
2323
else

tests/docstring_tests/DocTest.res

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,10 @@ let getCodeBlocks = example => {
147147

148148
let batchSize = OS.cpus()->Array.length
149149

150+
let runtimePath = Path.join(["packages", "@rescript", "runtime"])
151+
150152
let extractExamples = async () => {
151-
let files = Fs.readdirSync("runtime")
153+
let files = Fs.readdirSync(runtimePath)
152154

153155
let docFiles = files->Array.filter(f =>
154156
switch f {
@@ -168,7 +170,7 @@ let extractExamples = async () => {
168170

169171
let examples = []
170172
await docFiles->ArrayUtils.forEachAsyncInBatches(~batchSize, async f => {
171-
let doc = await extractDocFromFile(Path.join(["runtime", f]))
173+
let doc = await extractDocFromFile(Path.join([runtimePath, f]))
172174
examples->Array.pushMany(doc->getExamples)
173175
})
174176

tests/docstring_tests/DocTest.res.js

Lines changed: 16 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/docstring_tests/SpawnAsync.res.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/tests/src/DictInference.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Generated by ReScript, PLEASE EDIT WITH CARE
22

3-
import * as Js_dict from "rescript/lib/es6/Js_dict.js";
3+
import * as Js_dict from "@rescript/runtime/lib/es6/Js_dict.js";
44

55
let dict = {};
66

0 commit comments

Comments
 (0)