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: add .js extension to imports and fix package.json #148

Closed
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
4 changes: 4 additions & 0 deletions .fix-esm-imports.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

# Search for "from './baz'" and transform to "from './baz.js'"
find dist/esm -type f -name *.js -exec sed -i -e -E "s/from '(\.\/.*)'/from '\1.js'/g" {} \;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on debian the -e parameter doesn't work.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also this won't catch any pure imports like import 'utils/myfile.js'

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for anyone else viewing this that I tried getting a rule into eslint that would resolve this for similar use-cases: import-js/eslint-plugin-import#2701

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"scripts": {
"docs": "documentation build --github --output docs --format html ./ip-address.js",
"build": "rm -rf dist/* && tsc -p tsconfig.json && tsc -p tsconfig-esm.json && ./.fix-package-types.sh",
"build": "rm -rf dist/* && tsc -p tsconfig.json && tsc -p tsconfig-esm.json && ./.fix-package-types.sh && ./.fix-esm-imports.sh",
"prepublishOnly": "npm run build",
"release": "release-it",
"test-ci": "nyc mocha",
Expand Down Expand Up @@ -53,7 +53,8 @@
"files": [
"dist/**/*.js",
"dist/**/*.ts",
"dist/**/*.map"
"dist/**/*.map",
"dist/**/*.json"
],
"repository": {
"type": "git",
Expand Down