Skip to content

Refactor and convert JS codebase to ESM #6899

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 37 commits into from
Mar 29, 2025
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
afb8766
cleanup TypeScript config
cometkim Jul 3, 2024
6e2feea
enable lint for js
cometkim Jul 21, 2024
1026096
upgrade Biome
cometkim Mar 18, 2025
1f59418
add lint rules
cometkim Mar 18, 2025
433dc20
fix artifact action
cometkim Mar 18, 2025
b978b2a
fix lint files
cometkim Mar 18, 2025
2b4c0da
auto-fix by Biome
cometkim Mar 18, 2025
9b170f2
biome upgrade for gentype example
cometkim Mar 18, 2025
3c883bd
fix gentype test
cometkim Mar 18, 2025
faa6ee8
fix artifact action
cometkim Mar 18, 2025
67339c3
Convert to ESM, with refactoring codebase
cometkim Mar 23, 2025
5b04b25
Use CommonJS on the playground test, due to the limit of JSOO
cometkim Mar 23, 2025
55b59e2
format
cometkim Mar 23, 2025
72492fe
windows... so painful
cometkim Mar 23, 2025
798ed6e
update artifacts
cometkim Mar 23, 2025
8f71a3c
fix json imports
cometkim Mar 23, 2025
77572e0
use `import.meta.dirname`
cometkim Mar 23, 2025
f11159a
specify node version
cometkim Mar 23, 2025
9de8d73
Update scripts/prebuilt.js
cometkim Mar 23, 2025
d0906c0
udpate lockfile
cometkim Mar 25, 2025
bf00f11
ts noEmit
cometkim Mar 25, 2025
9b50125
update artifacts
cometkim Mar 25, 2025
345c93c
make it fail early
cometkim Mar 25, 2025
bcd94bd
fix bin path
cometkim Mar 25, 2025
fd5d56e
fix tests
cometkim Mar 25, 2025
d22fafd
cleanup test rescript configs
cometkim Mar 25, 2025
ff710cd
update artifacts
cometkim Mar 25, 2025
3e69a83
fix
cometkim Mar 25, 2025
73b9765
prefer yarn
cometkim Mar 25, 2025
f194ee4
fix gentype test
cometkim Mar 25, 2025
efad3d1
fix
cometkim Mar 26, 2025
8bb32bb
disable useTemplate rule
cometkim Mar 26, 2025
c72e0bb
fix rebase miss
cometkim Mar 26, 2025
1d20225
add changelog
cometkim Mar 26, 2025
e2c6420
add README to lib_dev
cometkim Mar 26, 2025
6164bd2
ignore docstring test artifact
cometkim Mar 29, 2025
69c184b
yarn up typescript
cometkim Mar 29, 2025
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
9 changes: 7 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc

- name: Restore build cache
id: build-cache
uses: actions/cache@v4
Expand Down Expand Up @@ -401,11 +406,11 @@ jobs:
run: |
opam exec -- node packages/playground-bundling/scripts/generate_cmijs.js
opam exec -- dune build --profile browser
cp ./_build/default/compiler/jsoo/jsoo_playground_main.bc.js playground/compiler.js
cp ./_build/default/compiler/jsoo/jsoo_playground_main.bc.js playground/compiler.cjs

- name: Test playground compiler
if: matrix.build_playground
run: node playground/playground_test.js
run: node playground/playground_test.cjs

- name: Upload playground compiler to CDN
if: ${{ matrix.build_playground && startsWith(github.ref, 'refs/tags/v') }}
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/get_artifact_dir_name.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const fs = require("fs");
const os = require("os");
import * as fs from "node:fs";
import * as os from "node:os";

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

// Pass artifactDirName to subsequent GitHub actions
fs.appendFileSync(
process.env.GITHUB_ENV,
`artifact_dir_name=${artifactDirName}${os.EOL}`,
`artifact_dir_name=${platformName}${os.EOL}`,
);
7 changes: 4 additions & 3 deletions .github/workflows/prepare_package_upload.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const fs = require("fs");
const os = require("os");
import * as fs from "node:fs";
import * as os from "node:os";

import packageSpec from "rescript/package.json" with { type: "json" };

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

const commitHash = process.argv[2] || process.env.GITHUB_SHA;
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ playground/stdlib/
playground/*.cmj
playground/*.cmi
playground/.netrc
playground/compiler.js
playground/compiler.*js

rewatch/target/
rewatch/rewatch
Expand All @@ -88,3 +88,5 @@ tests/analysis_tests/**/*.bs.js
!.yarn/releases
!.yarn/sdks
!.yarn/versions

*.tsbuildinfo
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#### :house: Internal

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

# 12.0.0-alpha.10

Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ $ node

### Testing the Playground bundle

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.
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.

### Working on the Playground JS API

Expand All @@ -273,7 +273,7 @@ Whenever you are modifying any files in the ReScript compiler, or in the `jsoo_p
make playground

# optionally run your test / arbitrary node script to verify your changes
node playground/playground_test.js
node playground/playground_test.cjs
```

### Publishing the Playground Bundle on our KeyCDN
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ artifacts: lib
# Builds the core playground bundle (without the relevant cmijs files for the runtime)
playground:
dune build --profile browser
cp ./_build/default/compiler/jsoo/jsoo_playground_main.bc.js playground/compiler.js
cp ./_build/default/compiler/jsoo/jsoo_playground_main.bc.js playground/compiler.cjs

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

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

clean:
(cd runtime && ../cli/rescript clean)
(cd runtime && ../cli/rescript.js clean)
dune clean

clean-all: clean clean-gentype clean-rewatch
Expand Down
4 changes: 2 additions & 2 deletions analysis/examples/example-project/types.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
}
],
"custom": [
{"module": "Belt_HashMapInt", "path": [], "name": "t", "args": 1}
{ "module": "Belt_HashMapInt", "path": [], "name": "t", "args": 1 }
]
}
}
Empty file.
65 changes: 44 additions & 21 deletions biome.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
{
"$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"vcs": {
"enabled": true,
"clientKind": "git",
"defaultBranch": "master",
"useIgnoreFile": true
},
"linter": {
"enabled": false
"enabled": true,
"rules": {
"recommended": true,
"style": {
"useTemplate": "off"
},
"nursery": {
"noCommonJs": "error"
},
"suspicious": {
"noAssignInExpressions": "warn"
},
"correctness": {
"useImportExtensions": "error",
"noUndeclaredDependencies": "error",
"noUnusedImports": "error",
"noUnusedVariables": "warn"
}
}
},
"organizeImports": {
"enabled": false
"enabled": true
},
"formatter": {
"enabled": true,
Expand All @@ -19,24 +37,7 @@
"indentWidth": 2,
"lineEnding": "lf",
"lineWidth": 80,
"attributePosition": "auto",
"ignore": [
".yarn/**",
"tests/build_tests/**",
"tests/tests/**",
"tests/tools_tests/**",
"tests/analysis_tests/**",
"tests/docstring_tests/**",
"analysis/examples/**",
"analysis/reanalyze/examples/**",
"lib/**",
"ninja/**",
"playground/**",
"**/*.bs.js",
"**/*.res.js",
"**/*.gen.ts*",
"package.json"
]
"attributePosition": "auto"
},
"javascript": {
"formatter": {
Expand All @@ -50,5 +51,27 @@
"quoteStyle": "double",
"attributePosition": "auto"
}
},
"files": {
"ignore": [
".yarn/**",
"tests/analysis_tests/**/src/**",
"tests/build_tests/**/src/**",
"tests/docstring_tests/**",
"tests/gentype_tests/**",
"tests/tests/**/src/**",
"tests/tools_tests/**/src/**",
"analysis/examples/**/src/**",
"lib/es6/**",
"lib/js/**",
"ninja/**",
"packages/**",
"playground/**",
"*.bs.js",
"*.res.js",
"*.res.mjs",
"*.gen.ts*",
"package.json"
]
}
}
59 changes: 0 additions & 59 deletions cli/bin_path.js

This file was deleted.

16 changes: 0 additions & 16 deletions cli/bsc

This file was deleted.

18 changes: 18 additions & 0 deletions cli/bsc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env node

// @ts-check

import { execFileSync } from "node:child_process";

import { bsc_exe } from "./common/bins.js";

const delegate_args = process.argv.slice(2);

try {
execFileSync(bsc_exe, delegate_args, { stdio: "inherit" });
} catch (e) {
if (e.code === "ENOENT") {
console.error(String(e));
}
process.exit(2);
}
Loading