Skip to content

Commit ff87e5c

Browse files
🚧 progress: Fix cjs build imports and test import maps.
1 parent 1ae7722 commit ff87e5c

9 files changed

+93
-29
lines changed

package.json

+61-17
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@
2222
"sideEffects": false,
2323
"type": "module",
2424
"source": "src/index.js",
25-
"main": "dist/default/index.js",
25+
"main": "dist/default/index.cjs",
2626
"module": "dist/module/index.js",
2727
"esmodule": "dist/module/index.js",
2828
"exports": {
2929
".": {
30-
"browser": "./dist/browser/index.js",
31-
"node": "./dist/node/index.js",
32-
"default": "./dist/default/index.js"
30+
"browser": "./dist/browser/index.cjs",
31+
"node": "./dist/node/index.cjs",
32+
"default": "./dist/default/index.cjs"
3333
},
34-
"./*": {
35-
"browser": "./dist/browser/*.js",
36-
"node": "./dist/node/*.js",
37-
"default": "./dist/default/*.js"
34+
"./*.js": {
35+
"browser": "./dist/browser/*.cjs",
36+
"node": "./dist/node/*.cjs",
37+
"default": "./dist/default/*.cjs"
3838
}
3939
},
4040
"files": [
@@ -48,10 +48,10 @@
4848
"build-cmd": "babel --delete-dir-on-start --source-maps --minified src",
4949
"build-docs": "esdoc",
5050
"build-gh-pages": "npm run build-docs",
51-
"build:browser": "npm run build-cmd -- --env-name browser --out-dir dist/browser",
52-
"build:default": "npm run build-cmd -- --env-name production --out-dir dist/default",
51+
"build:browser": "npm run build-cmd -- --env-name browser --out-dir dist/browser --out-file-extension .cjs",
52+
"build:default": "npm run build-cmd -- --env-name production --out-dir dist/default --out-file-extension .cjs",
5353
"build:module": "npm run build-cmd -- --env-name module --out-dir dist/module",
54-
"build:node": "npm run build-cmd -- --env-name node --out-dir dist/node",
54+
"build:node": "npm run build-cmd -- --env-name node --out-dir dist/node --out-file-extension .cjs",
5555
"commit-msg": "commitlint --edit",
5656
"cover": "NODE_ENV=cover c8 --all --src src --reporter lcov --reporter text-summary --reporter text npm test",
5757
"debug": "NODE_ENV=debug npm run test -- -st --fail-fast",
@@ -69,10 +69,11 @@
6969
"release": "np --message ':hatching_chick: release: Bumping to v%s.'",
7070
"test": "npm run test:src",
7171
"test-cmd": "NODE_LOADER_CONFIG=test/loader/config.js ava",
72-
"test:cjs": "IMPORT_MAP_PATH=test/import-maps/dist/index.json npm run test-cmd",
73-
"test:dist": "npm run test:modern && npm run test:module && npm run test:cjs",
74-
"test:modern": "IMPORT_MAP_PATH=test/import-maps/dist/index.modern.json npm run test-cmd",
72+
"test:browser": "IMPORT_MAP_PATH=test/import-maps/dist/index.browser.json npm run test-cmd",
73+
"test:default": "IMPORT_MAP_PATH=test/import-maps/dist/index.default.json npm run test-cmd",
74+
"test:dist": "npm run test:browser && npm run test:module && npm run test:node && npm run test:default",
7575
"test:module": "IMPORT_MAP_PATH=test/import-maps/dist/index.module.json npm run test-cmd",
76+
"test:node": "IMPORT_MAP_PATH=test/import-maps/dist/index.node.json npm run test-cmd",
7677
"test:src": "IMPORT_MAP_PATH=test/import-maps/src/index.json npm run test-cmd"
7778
},
7879
"dependencies": {},
@@ -87,6 +88,7 @@
8788
"@node-loader/core": "2.0.0",
8889
"@node-loader/import-maps": "1.1.0",
8990
"ava": "6.1.1",
91+
"babel-plugin-replace-import-extension": "^1.1.4",
9092
"babel-plugin-transform-remove-console": "6.9.4",
9193
"babel-plugin-unassert": "3.2.0",
9294
"babel-preset-minify": "0.5.2",
@@ -197,7 +199,21 @@
197199
]
198200
],
199201
"plugins": [
200-
"babel-plugin-unassert"
202+
"babel-plugin-unassert",
203+
[
204+
"replace-import-extension",
205+
{
206+
"extMapping": {
207+
".js": ".cjs"
208+
}
209+
}
210+
],
211+
[
212+
"@babel/plugin-transform-modules-commonjs",
213+
{
214+
"loose": true
215+
}
216+
]
201217
]
202218
},
203219
"browser": {
@@ -218,7 +234,21 @@
218234
]
219235
],
220236
"plugins": [
221-
"babel-plugin-unassert"
237+
"babel-plugin-unassert",
238+
[
239+
"replace-import-extension",
240+
{
241+
"extMapping": {
242+
".js": ".cjs"
243+
}
244+
}
245+
],
246+
[
247+
"@babel/plugin-transform-modules-commonjs",
248+
{
249+
"loose": true
250+
}
251+
]
222252
]
223253
},
224254
"module": {
@@ -262,7 +292,21 @@
262292
]
263293
],
264294
"plugins": [
265-
"babel-plugin-unassert"
295+
"babel-plugin-unassert",
296+
[
297+
"replace-import-extension",
298+
{
299+
"extMapping": {
300+
".js": ".cjs"
301+
}
302+
}
303+
],
304+
[
305+
"@babel/plugin-transform-modules-commonjs",
306+
{
307+
"loose": true
308+
}
309+
]
266310
]
267311
}
268312
}
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"imports": {
3+
"#module": "./dist/browser/index.cjs",
4+
"#module/cardinality/index.js": "./dist/browser/cardinality/index.cjs",
5+
"#module/core/blossom/index.js": "./dist/browser/core/blossom/index.cjs"
6+
}
7+
}
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"imports": {
3+
"#module": "./dist/default/index.cjs",
4+
"#module/cardinality/index.js": "./dist/default/cardinality/index.cjs",
5+
"#module/core/blossom/index.js": "./dist/default/core/blossom/index.cjs"
6+
}
7+
}

test/import-maps/dist/index.json

-5
This file was deleted.

test/import-maps/dist/index.modern.json

-5
This file was deleted.
+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"imports": {
3-
"#module": "./dist/index.module.js"
3+
"#module": "./dist/module/index.js",
4+
"#module/cardinality/index.js": "./dist/module/cardinality/index.js",
5+
"#module/core/blossom/index.js": "./dist/module/core/blossom/index.js"
46
}
57
}

test/import-maps/dist/index.node.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"imports": {
3+
"#module": "./dist/node/index.cjs",
4+
"#module/cardinality/index.js": "./dist/node/cardinality/index.cjs",
5+
"#module/core/blossom/index.js": "./dist/node/core/blossom/index.cjs"
6+
}
7+
}

test/import-maps/src/index.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"imports": {
3-
"#module": "./src/index.js"
3+
"#module": "./src/index.js",
4+
"#module/cardinality/index.js": "./src/cardinality/index.js",
5+
"#module/core/blossom/index.js": "./src/core/blossom/index.js"
46
}
57
}

yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -2602,6 +2602,11 @@ babel-plugin-polyfill-regenerator@^0.5.5:
26022602
dependencies:
26032603
"@babel/helper-define-polyfill-provider" "^0.5.0"
26042604

2605+
babel-plugin-replace-import-extension@^1.1.4:
2606+
version "1.1.4"
2607+
resolved "https://registry.yarnpkg.com/babel-plugin-replace-import-extension/-/babel-plugin-replace-import-extension-1.1.4.tgz#bfe96afd8363e47b9512086bfc0953e0493f4427"
2608+
integrity sha512-UJi5YV31JxoaHHxhytRhQqOQN3+ZsaoXVia7e58yc35pe4tNjNr7BdznnDvIPbEG/4u5kf+lLDk9peaxsOPxGw==
2609+
26052610
babel-plugin-transform-inline-consecutive-adds@^0.4.3:
26062611
version "0.4.3"
26072612
resolved "https://registry.yarnpkg.com/babel-plugin-transform-inline-consecutive-adds/-/babel-plugin-transform-inline-consecutive-adds-0.4.3.tgz#323d47a3ea63a83a7ac3c811ae8e6941faf2b0d1"

0 commit comments

Comments
 (0)