Skip to content
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

fix: explicitly add import extensions #60

Merged
merged 2 commits into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion .babelrc.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
],
"plugins": [
["@babel/plugin-proposal-class-properties"],
["@babel/plugin-transform-react-jsx", { "pragma": "h" }]
["@babel/plugin-transform-react-jsx", { "pragma": "h" }],
["./add-extensions", { "extension": "mjs" }]
]
}
22 changes: 22 additions & 0 deletions add-extensions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module.exports = function (babel, opts) {
return {
visitor: {
ExportAllDeclaration: (path) => {
const { node } = path
if (node.source && node.source.extra && node.source.extra.rawValue.startsWith('./')) {
node.source = babel.types.stringLiteral(
node.source.extra && node.source.extra.rawValue + '.' + opts.extension
)
}
},
ImportDeclaration: (path) => {
const { node } = path
if (node.source && node.source.extra && node.source.extra.rawValue.startsWith('./')) {
node.source = babel.types.stringLiteral(
node.source.extra && node.source.extra.rawValue + '.' + opts.extension
)
}
}
}
}
}
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
"version": "0.0.0-semantically-released",
"description": "Simple and complete Preact DOM testing utilities that encourage good testing practices.",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"module": "dist/esm/index.mjs",
"types": "types/index.d.ts",
"exports": {
".": {
"types": "./types/index.d.ts",
"browser": "./dist/esm/index.js",
"browser": "./dist/esm/index.mjs",
"import": "./dist/esm/index.mjs",
"require": "./dist/cjs/index.js"
},
"./pure": {
"types": "./pure.d.ts",
"browser": "./dist/esm/pure.js",
"browser": "./dist/esm/pure.mjs",
"import": "./dist/esm/pure.mjs",
"require": "./dist/cjs/pure.js"
}
Expand Down Expand Up @@ -55,10 +55,9 @@
"toc": "doctoc README.md",
"lint": "eslint src/**/*.js --fix",
"clean": "rimraf dist",
"build": "npm run build:cjs && npm run build:esm && npm run copy:mjs",
"build": "npm run build:cjs && npm run build:esm",
"build:cjs": "babel src --out-dir dist/cjs --config-file ./.babelrc --ignore '**/__tests__/**,**/__mocks__/**'",
"build:esm": "babel src --no-babelrc --out-dir dist/esm --config-file ./.babelrc.esm.json --ignore '**/__tests__/**,**/__mocks__/**'",
"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",
"build:esm": "babel src --no-babelrc --out-file-extension .mjs --out-dir dist/esm --config-file ./.babelrc.esm.json --ignore '**/__tests__/**,**/__mocks__/**'",
"test": "jest src/__tests__ ",
"test:watch": "npm test --watch",
"test:update": "npm test --updateSnapshot --coverage",
Expand Down