Skip to content

Commit 02b3e5b

Browse files
shulhicknitt
andauthored
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>
1 parent 3a211c3 commit 02b3e5b

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
@@ -34,6 +34,7 @@
3434
- 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
3535
- Add duplicate package detection to rewatch. https://github.com/rescript-lang/rescript/pull/8180
3636
- Rewatch: do not warn about "reanalyze" config field. https://github.com/rescript-lang/rescript/pull/8181
37+
- Fix error when importing CommonJS runtime modules with `require()`. https://github.com/rescript-lang/rescript/pull/8194
3738

3839
#### :memo: Documentation
3940

biome.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"!**/.yarn",
5656
"!**/tests/analysis_tests/**/src",
5757
"!**/tests/build_tests/**/src",
58+
"!**/tests/commonjs_tests/src",
5859
"!**/tests/docstring_tests",
5960
"!**/tests/gentype_tests",
6061
"**/tests/gentype_tests/typescript-react-example/**",

lib_dev/paths.js

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

55+
/**
56+
* path: `<projectDir>/tests/commonjs_tests/`
57+
*/
58+
export const commonjsTestDir = path.resolve(testDir, "commonjs_tests");
59+
5560
/**
5661
* path: `<projectDir>/compiler/common/bs_version.ml`
5762
*/

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
"tests/docstring_tests",
104104
"tests/gentype_tests/**",
105105
"tests/tools_tests",
106+
"tests/commonjs_tests",
106107
"scripts/res"
107108
],
108109
"packageManager": "yarn@4.12.0",

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
@@ -191,7 +191,6 @@
191191
"lib/es6/Stdlib_Uint8ClampedArray.js",
192192
"lib/es6/Stdlib_WeakMap.js",
193193
"lib/es6/Stdlib_WeakSet.js",
194-
"lib/es6/package.json",
195194
"lib/js/Belt.js",
196195
"lib/js/Belt_Array.js",
197196
"lib/js/Belt_Float.js",
@@ -366,6 +365,7 @@
366365
"lib/js/Stdlib_Uint8ClampedArray.js",
367366
"lib/js/Stdlib_WeakMap.js",
368367
"lib/js/Stdlib_WeakSet.js",
368+
"lib/js/package.json",
369369
"lib/ocaml/Belt.cmi",
370370
"lib/ocaml/Belt.cmj",
371371
"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 (buildTest) {

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)