Skip to content

Commit 19f2d0f

Browse files
cometkimcknitt
authored andcommitted
Refactor and convert JS codebase to ESM (#6899)
Co-authored-by: Christoph Knittel <[email protected]>
1 parent ff620ca commit 19f2d0f

File tree

191 files changed

+2114
-1951
lines changed

Some content is hidden

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

191 files changed

+2114
-1951
lines changed

.github/workflows/ci.yml

+7-2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ jobs:
4545
- name: Checkout
4646
uses: actions/checkout@v4
4747

48+
- name: Use Node.js
49+
uses: actions/setup-node@v4
50+
with:
51+
node-version-file: .nvmrc
52+
4853
- name: Restore build cache
4954
id: build-cache
5055
uses: actions/cache@v4
@@ -401,11 +406,11 @@ jobs:
401406
run: |
402407
opam exec -- node packages/playground-bundling/scripts/generate_cmijs.js
403408
opam exec -- dune build --profile browser
404-
cp ./_build/default/compiler/jsoo/jsoo_playground_main.bc.js playground/compiler.js
409+
cp ./_build/default/compiler/jsoo/jsoo_playground_main.bc.js playground/compiler.cjs
405410
406411
- name: Test playground compiler
407412
if: matrix.build_playground
408-
run: node playground/playground_test.js
413+
run: node playground/playground_test.cjs
409414

410415
- name: Upload playground compiler to CDN
411416
if: ${{ matrix.build_playground && startsWith(github.ref, 'refs/tags/v') }}
+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
const fs = require("fs");
2-
const os = require("os");
1+
import * as fs from "node:fs";
2+
import * as os from "node:os";
33

4-
const { dirName: artifactDirName } = require("../../cli/bin_path.js");
4+
import { platformName } from "#cli/bins";
55

66
// Pass artifactDirName to subsequent GitHub actions
77
fs.appendFileSync(
88
process.env.GITHUB_ENV,
9-
`artifact_dir_name=${artifactDirName}${os.EOL}`,
9+
`artifact_dir_name=${platformName}${os.EOL}`,
1010
);

.github/workflows/prepare_package_upload.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
const fs = require("fs");
2-
const os = require("os");
1+
import * as fs from "node:fs";
2+
import * as os from "node:os";
3+
4+
import packageSpec from "rescript/package.json" with { type: "json" };
35

4-
const packageSpec = require("rescript/package.json");
56
const { version } = packageSpec;
67

78
const commitHash = process.argv[2] || process.env.GITHUB_SHA;

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ playground/stdlib/
7272
playground/*.cmj
7373
playground/*.cmi
7474
playground/.netrc
75-
playground/compiler.js
75+
playground/compiler.*js
7676

7777
rewatch/target/
7878
rewatch/rewatch
@@ -88,3 +88,5 @@ tests/analysis_tests/**/*.bs.js
8888
!.yarn/releases
8989
!.yarn/sdks
9090
!.yarn/versions
91+
92+
*.tsbuildinfo

.yarnrc.yml

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ yarnPath: .yarn/releases/yarn-4.7.0.cjs
33
nodeLinker: node-modules
44

55
nmMode: hardlinks-global
6+
7+
defaultSemverRangePrefix: ""

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#### :house: Internal
2020

2121
- Remove `Stdlib_Char` module for now. https://github.com/rescript-lang/rescript/pull/7367
22+
- Convert internal JavaScript codebase into ESM, ReScript package itself is now ESM (`"type": "module"`). https://github.com/rescript-lang/rescript/pull/6899
2223

2324
# 12.0.0-alpha.10
2425

CONTRIBUTING.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ $ node
263263

264264
### Testing the Playground bundle
265265

266-
Run `node playground/playground_test.js` for a quick sanity check to see if all the build artifacts are working together correctly. When releasing the playground bundle, the test will always be executed before publishing to catch regressions.
266+
Run `node playground/playground_test.cjs` for a quick sanity check to see if all the build artifacts are working together correctly. When releasing the playground bundle, the test will always be executed before publishing to catch regressions.
267267

268268
### Working on the Playground JS API
269269

@@ -273,7 +273,7 @@ Whenever you are modifying any files in the ReScript compiler, or in the `jsoo_p
273273
make playground
274274
275275
# optionally run your test / arbitrary node script to verify your changes
276-
node playground/playground_test.js
276+
node playground/playground_test.cjs
277277
```
278278

279279
### Publishing the Playground Bundle on our KeyCDN

Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ artifacts: lib
6161
# Builds the core playground bundle (without the relevant cmijs files for the runtime)
6262
playground:
6363
dune build --profile browser
64-
cp ./_build/default/compiler/jsoo/jsoo_playground_main.bc.js playground/compiler.js
64+
cp ./_build/default/compiler/jsoo/jsoo_playground_main.bc.js playground/compiler.cjs
6565

6666
# Creates all the relevant core and third party cmij files to side-load together with the playground bundle
6767
playground-cmijs: artifacts
@@ -70,7 +70,7 @@ playground-cmijs: artifacts
7070
# Builds the playground, runs some e2e tests and releases the playground to the
7171
# CDN (requires KEYCDN_USER and KEYCDN_PASSWORD set in the env variables)
7272
playground-release: playground playground-cmijs
73-
node playground/playground_test.js
73+
node playground/playground_test.cjs
7474
sh playground/upload_bundle.sh
7575

7676
format:
@@ -86,7 +86,7 @@ clean-rewatch:
8686
cargo clean --manifest-path rewatch/Cargo.toml && rm -f rewatch/rewatch
8787

8888
clean:
89-
(cd runtime && ../cli/rescript clean)
89+
(cd runtime && ../cli/rescript.js clean)
9090
dune clean
9191

9292
clean-all: clean clean-gentype clean-rewatch

analysis/examples/example-project/types.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
}
99
],
1010
"custom": [
11-
{"module": "Belt_HashMapInt", "path": [], "name": "t", "args": 1}
11+
{ "module": "Belt_HashMapInt", "path": [], "name": "t", "args": 1 }
1212
]
13-
}
13+
}

analysis/examples/larger-project/.watchmanconfig

Whitespace-only changes.

biome.json

+44-21
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,34 @@
11
{
2-
"$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
2+
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
33
"vcs": {
44
"enabled": true,
55
"clientKind": "git",
66
"defaultBranch": "master",
77
"useIgnoreFile": true
88
},
99
"linter": {
10-
"enabled": false
10+
"enabled": true,
11+
"rules": {
12+
"recommended": true,
13+
"style": {
14+
"useTemplate": "off"
15+
},
16+
"nursery": {
17+
"noCommonJs": "error"
18+
},
19+
"suspicious": {
20+
"noAssignInExpressions": "warn"
21+
},
22+
"correctness": {
23+
"useImportExtensions": "error",
24+
"noUndeclaredDependencies": "error",
25+
"noUnusedImports": "error",
26+
"noUnusedVariables": "warn"
27+
}
28+
}
1129
},
1230
"organizeImports": {
13-
"enabled": false
31+
"enabled": true
1432
},
1533
"formatter": {
1634
"enabled": true,
@@ -19,24 +37,7 @@
1937
"indentWidth": 2,
2038
"lineEnding": "lf",
2139
"lineWidth": 80,
22-
"attributePosition": "auto",
23-
"ignore": [
24-
".yarn/**",
25-
"tests/build_tests/**",
26-
"tests/tests/**",
27-
"tests/tools_tests/**",
28-
"tests/analysis_tests/**",
29-
"tests/docstring_tests/**",
30-
"analysis/examples/**",
31-
"analysis/reanalyze/examples/**",
32-
"lib/**",
33-
"ninja/**",
34-
"playground/**",
35-
"**/*.bs.js",
36-
"**/*.res.js",
37-
"**/*.gen.ts*",
38-
"package.json"
39-
]
40+
"attributePosition": "auto"
4041
},
4142
"javascript": {
4243
"formatter": {
@@ -50,5 +51,27 @@
5051
"quoteStyle": "double",
5152
"attributePosition": "auto"
5253
}
54+
},
55+
"files": {
56+
"ignore": [
57+
".yarn/**",
58+
"tests/analysis_tests/**/src/**",
59+
"tests/build_tests/**/src/**",
60+
"tests/docstring_tests/**",
61+
"tests/gentype_tests/**",
62+
"tests/tests/**/src/**",
63+
"tests/tools_tests/**/src/**",
64+
"analysis/examples/**/src/**",
65+
"lib/es6/**",
66+
"lib/js/**",
67+
"ninja/**",
68+
"packages/**",
69+
"playground/**",
70+
"*.bs.js",
71+
"*.res.js",
72+
"*.res.mjs",
73+
"*.gen.ts*",
74+
"package.json"
75+
]
5376
}
5477
}

cli/bin_path.js

-59
This file was deleted.

cli/bsc

-16
This file was deleted.

cli/bsc.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env node
2+
3+
// @ts-check
4+
5+
import { execFileSync } from "node:child_process";
6+
7+
import { bsc_exe } from "./common/bins.js";
8+
9+
const delegate_args = process.argv.slice(2);
10+
11+
try {
12+
execFileSync(bsc_exe, delegate_args, { stdio: "inherit" });
13+
} catch (e) {
14+
if (e.code === "ENOENT") {
15+
console.error(String(e));
16+
}
17+
process.exit(2);
18+
}

0 commit comments

Comments
 (0)