Skip to content

Commit b973969

Browse files
shulhicknitt
andcommitted
Override module type for CommonJS runtime (#8194)
* Explicitly add type commonjs for commonjs runtime * Update artifacts.json * Remove es6 package.json because it's already the default * Update CHANGELOG * WIP: Add tests * commit yarn.lock * Update CHANGELOG.md Co-authored-by: Christoph Knittel <christoph@knittel.cc> --------- Co-authored-by: Christoph Knittel <christoph@knittel.cc> # Conflicts: # biome.json
1 parent 0275b76 commit b973969

File tree

13 files changed

+80
-2
lines changed

13 files changed

+80
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
- Reanalyze: fix reactive/server stale results when cross-file references change without changing dead declarations (non-transitive mode). https://github.com/rescript-lang/rescript/pull/8173
2929
- Add duplicate package detection to rewatch. https://github.com/rescript-lang/rescript/pull/8180
3030
- Rewatch: do not warn about "reanalyze" config field. https://github.com/rescript-lang/rescript/pull/8181
31+
- Fix error when importing CommonJS runtime modules with `require()`. https://github.com/rescript-lang/rescript/pull/8194
3132

3233
#### :memo: Documentation
3334

biome.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
".yarn/**",
5858
"tests/analysis_tests/**/src/**",
5959
"tests/build_tests/**/src/**",
60+
"tests/commonjs_tests/**/src/**",
6061
"tests/docstring_tests/**",
6162
"tests/gentype_tests/**",
6263
"tests/tests/**/src/**",

lib_dev/paths.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ export const buildTestDir = path.resolve(testDir, "build_tests");
5757
*/
5858
export const docstringTestDir = path.resolve(testDir, "docstring_tests");
5959

60+
/**
61+
* path: `<projectDir>/tests/commonjs_tests/`
62+
*/
63+
export const commonjsTestDir = path.resolve(testDir, "commonjs_tests");
64+
6065
/**
6166
* path: `<projectDir>/compiler/common/bs_version.ml`
6267
*/

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
"tests/docstring_tests",
106106
"tests/gentype_tests/**",
107107
"tests/tools_tests",
108+
"tests/commonjs_tests",
108109
"scripts/res"
109110
],
110111
"packageManager": "yarn@4.10.3",

packages/@rescript/runtime/lib/es6/package.json

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"type" : "commonjs"}

packages/artifacts.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@
197197
"lib/es6/Stdlib_Uint8ClampedArray.js",
198198
"lib/es6/Stdlib_WeakMap.js",
199199
"lib/es6/Stdlib_WeakSet.js",
200-
"lib/es6/package.json",
201200
"lib/js/Belt.js",
202201
"lib/js/Belt_Array.js",
203202
"lib/js/Belt_Float.js",
@@ -372,6 +371,7 @@
372371
"lib/js/Stdlib_Uint8ClampedArray.js",
373372
"lib/js/Stdlib_WeakMap.js",
374373
"lib/js/Stdlib_WeakSet.js",
374+
"lib/js/package.json",
375375
"lib/ocaml/Belt.cmi",
376376
"lib/ocaml/Belt.cmj",
377377
"lib/ocaml/Belt.cmt",

scripts/test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,18 @@ if (mochaTest) {
106106
cwd: projectDir,
107107
stdio: "inherit",
108108
});
109+
110+
// CommonJS tests
111+
const commonjsTestDir = path.join(projectDir, "tests/commonjs_tests");
112+
await execBuild([], {
113+
cwd: commonjsTestDir,
114+
stdio: "inherit",
115+
});
116+
117+
await node("tests/commonjs_tests/src/belt_import.js", [], {
118+
cwd: projectDir,
119+
stdio: "inherit",
120+
});
109121
}
110122

111123
if (bsbTest) {

tests/commonjs_tests/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "rescript-commonjs-tests",
3+
"type": "commonjs"
4+
}

tests/commonjs_tests/rescript.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "rescript-commonjs-tests",
3+
"sources": [
4+
{
5+
"dir": "src",
6+
"subdirs": true
7+
}
8+
],
9+
"package-specs": {
10+
"module": "commonjs",
11+
"in-source": true,
12+
"suffix": ".js"
13+
},
14+
"compiler-flags": [
15+
"-w -3-6-26-27-29-30-32..40-44-45-52-60-9-106+104",
16+
"-warn-error A"
17+
]
18+
}

0 commit comments

Comments
 (0)