Skip to content

Commit 71a466e

Browse files
authored
fix: explicitly add import extensions (#60)
* fix: explicitly add import extensions * fix: export map locations
1 parent 1f98518 commit 71a466e

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

.babelrc.esm.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
],
1111
"plugins": [
1212
["@babel/plugin-proposal-class-properties"],
13-
["@babel/plugin-transform-react-jsx", { "pragma": "h" }]
13+
["@babel/plugin-transform-react-jsx", { "pragma": "h" }],
14+
["./add-extensions", { "extension": "mjs" }]
1415
]
1516
}

add-extensions.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module.exports = function (babel, opts) {
2+
return {
3+
visitor: {
4+
ExportAllDeclaration: (path) => {
5+
const { node } = path
6+
if (node.source && node.source.extra && node.source.extra.rawValue.startsWith('./')) {
7+
node.source = babel.types.stringLiteral(
8+
node.source.extra && node.source.extra.rawValue + '.' + opts.extension
9+
)
10+
}
11+
},
12+
ImportDeclaration: (path) => {
13+
const { node } = path
14+
if (node.source && node.source.extra && node.source.extra.rawValue.startsWith('./')) {
15+
node.source = babel.types.stringLiteral(
16+
node.source.extra && node.source.extra.rawValue + '.' + opts.extension
17+
)
18+
}
19+
}
20+
}
21+
}
22+
}

package.json

+5-6
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
"version": "0.0.0-semantically-released",
44
"description": "Simple and complete Preact DOM testing utilities that encourage good testing practices.",
55
"main": "dist/cjs/index.js",
6-
"module": "dist/esm/index.js",
6+
"module": "dist/esm/index.mjs",
77
"types": "types/index.d.ts",
88
"exports": {
99
".": {
1010
"types": "./types/index.d.ts",
11-
"browser": "./dist/esm/index.js",
11+
"browser": "./dist/esm/index.mjs",
1212
"import": "./dist/esm/index.mjs",
1313
"require": "./dist/cjs/index.js"
1414
},
1515
"./pure": {
1616
"types": "./pure.d.ts",
17-
"browser": "./dist/esm/pure.js",
17+
"browser": "./dist/esm/pure.mjs",
1818
"import": "./dist/esm/pure.mjs",
1919
"require": "./dist/cjs/pure.js"
2020
}
@@ -55,10 +55,9 @@
5555
"toc": "doctoc README.md",
5656
"lint": "eslint src/**/*.js --fix",
5757
"clean": "rimraf dist",
58-
"build": "npm run build:cjs && npm run build:esm && npm run copy:mjs",
58+
"build": "npm run build:cjs && npm run build:esm",
5959
"build:cjs": "babel src --out-dir dist/cjs --config-file ./.babelrc --ignore '**/__tests__/**,**/__mocks__/**'",
60-
"build:esm": "babel src --no-babelrc --out-dir dist/esm --config-file ./.babelrc.esm.json --ignore '**/__tests__/**,**/__mocks__/**'",
61-
"copy:mjs": "cp ./dist/esm/fire-event.js ./dist/esm/fire-event.mjs && cp ./dist/esm/pure.js ./dist/esm/pure.mjs && cp ./dist/esm/index.js ./dist/esm/index.mjs",
60+
"build:esm": "babel src --no-babelrc --out-file-extension .mjs --out-dir dist/esm --config-file ./.babelrc.esm.json --ignore '**/__tests__/**,**/__mocks__/**'",
6261
"test": "jest src/__tests__ ",
6362
"test:watch": "npm test --watch",
6463
"test:update": "npm test --updateSnapshot --coverage",

0 commit comments

Comments
 (0)