Skip to content

Commit bfec8a2

Browse files
cknittcometkim
andauthored
@rescript/runtime package (#7796)
* move minisocket.js # Conflicts: # cli/common/bsb.js * move runtime codes * move runtime artifacts * new runtime resolution * fix ci * clean-lib-bsb * yarn constraints --fix * move cppo script * fix a diff script in ci workflow * update artifacts * remove an unused import mapping * sync gentype results * Format some files * Fix rewatch tests * Bring back advanced logic for finding runtime path * Hack to fix finding runtime module in analysis/tools * Fix package name for tools test * Fix playground build * Improve build step names * Fix apidocs generation * Remove buildRuntime.sh * Fix pkg-pr-new * Fix pnpm * CHANGELOG * Do not include *.res(i) in the runtime files * Add comment --------- Co-authored-by: Hyeseong Kim <[email protected]>
1 parent 3931a96 commit bfec8a2

File tree

898 files changed

+716
-1838
lines changed

Some content is hidden

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

898 files changed

+716
-1838
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,13 @@ jobs:
328328
run: ./scripts/test_syntax.sh
329329
shell: bash
330330

331-
- name: Build runtime/stdlib
332-
run: ./scripts/buildRuntime.sh
331+
- name: Build @rescript/runtime
332+
run: yarn workspace @rescript/runtime rescript build
333333
shell: bash
334334

335-
- name: Check for changes in lib folder
335+
- name: Check for changes in @rescript/runtime/lib
336336
run: git diff --exit-code lib/js lib/es6
337+
working-directory: packages/@rescript/runtime
337338

338339
- name: Version Check
339340
run: yarn constraints
@@ -439,7 +440,7 @@ jobs:
439440
uses: actions/upload-artifact@v4
440441
with:
441442
name: lib-ocaml
442-
path: lib/ocaml
443+
path: packages/@rescript/runtime/lib/ocaml
443444

444445
- name: Generate API Docs
445446
if: ${{ matrix.generate_api_docs }}

.github/workflows/moveArtifacts.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ check_statically_linked() {
2626
}
2727

2828
# rescript
29-
mv lib-ocaml lib/ocaml
29+
mv lib-ocaml packages/@rescript/runtime/lib/ocaml
3030

3131
# @rescript/{target}
3232
chmod +x binaries-*/*.exe
@@ -40,4 +40,4 @@ check_statically_linked "packages/@rescript/linux-arm64/bin"
4040

4141
# @rescript/std
4242
mkdir -p packages/std/lib
43-
cp -R lib/es6 lib/js packages/std/lib
43+
cp -R packages/@rescript/runtime/lib/es6 packages/@rescript/runtime/lib/js packages/std/lib

CHANGELOG.md

Lines changed: 2 additions & 0 deletions

Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ reanalyze:
5252
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
5353

5454
lib:
55-
./scripts/buildRuntime.sh
55+
yarn workspace @rescript/runtime build
5656

5757
artifacts: lib
5858
./scripts/npmPack.js --updateArtifactList
@@ -84,8 +84,10 @@ clean-gentype:
8484
clean-rewatch:
8585
cargo clean --manifest-path rewatch/Cargo.toml && rm -f rewatch/rewatch
8686

87-
clean:
88-
(cd runtime && ../cli/rescript.js clean)
87+
clean-lib:
88+
yarn workspace @rescript/runtime rescript clean
89+
90+
clean: clean-lib
8991
dune clean
9092

9193
clean-all: clean clean-gentype clean-rewatch

analysis/src/BuildSystem.ml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,24 @@ let namespacedName namespace name =
55

66
let ( /+ ) = Filename.concat
77

8-
let getBsPlatformDir rootPath =
8+
let getRuntimeDir rootPath =
99
match !Cfg.isDocGenFromCompiler with
1010
| false -> (
1111
let result =
12-
ModuleResolution.resolveNodeModulePath ~startPath:rootPath "rescript"
12+
ModuleResolution.resolveNodeModulePath ~startPath:rootPath
13+
"@rescript/runtime"
1314
in
1415
match result with
1516
| Some path -> Some path
1617
| None ->
17-
let message = "rescript could not be found" in
18+
let message = "@rescript/runtime could not be found" in
1819
Log.log message;
1920
None)
2021
| true -> Some rootPath
2122

22-
let getLibBs root = Files.ifExists (root /+ "lib" /+ "bs")
23+
let getLibBs path = Files.ifExists (path /+ "lib" /+ "bs")
2324

2425
let getStdlib base =
25-
match getBsPlatformDir base with
26+
match getRuntimeDir base with
2627
| None -> None
27-
| Some bsPlatformDir -> Some (bsPlatformDir /+ "lib" /+ "ocaml")
28+
| 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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,10 @@ let findProjectFiles ~public ~namespace ~path ~sourceDirectories ~libBs =
141141
sourceDirectories |> List.map (Filename.concat path) |> StringSet.of_list
142142
in
143143
let files =
144+
(* Use maxDepth to prevent infinite recursion where `rescript` depends on `@rescript/runtime`,
145+
but `@rescript/runtime` also has `rescript` as a dev dependency *)
144146
dirs |> StringSet.elements
145-
|> List.map (fun name -> Files.collect name isSourceFile)
147+
|> List.map (fun name -> Files.collect ~maxDepth:2 name isSourceFile)
146148
|> List.concat |> StringSet.of_list
147149
in
148150
dirs

analysis/src/ModuleResolution.ml

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

33
let rec resolveNodeModulePath ~startPath name =
4-
let path = startPath /+ "node_modules" /+ name in
5-
if Files.exists path then Some path
6-
else if Filename.dirname startPath = startPath then None
7-
else resolveNodeModulePath ~startPath:(Filename.dirname startPath) name
4+
if name = "@rescript/runtime" then
5+
(* Hack: we need a reliable way to resolve modules in monorepos. *)
6+
Some Config.runtime_module_path
7+
else
8+
let scope = Filename.dirname name in
9+
let name = Filename.basename name in
10+
let name =
11+
match scope.[0] with
12+
| '@' -> scope /+ name
13+
| _ -> name
14+
in
15+
let path = startPath /+ "node_modules" /+ name in
16+
if Files.exists path then Some path
17+
else if Filename.dirname startPath = startPath then None
18+
else resolveNodeModulePath ~startPath:(Filename.dirname startPath) name

cli/common/bsb.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import * as fs from "node:fs";
55
import { createServer } from "node:http";
66
import * as os from "node:os";
77
import * as path from "node:path";
8-
import { WebSocket } from "#lib/minisocket";
98

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

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

0 commit comments

Comments
 (0)