Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
},
"scripts": {
"prepublishOnly": "yarn build",
"build": "yarn build:cjs && yarn build:esm",
"build": "rimraf dist && yarn build:cjs && yarn build:esm",
"build:cjs": "tsc --project .",
"build:esm": "tsc --project tsconfig.esm.json && yarn build:esm:rename",
"build:esm:rename": "./scripts/rename-esm.sh",
Expand All @@ -54,6 +54,7 @@
"eslint-plugin-jest": "^24.1.3",
"eslint-plugin-node": "^11.1.0",
"jest": "^26.4.2",
"rimraf": "^3.0.2",
"ts-jest": "^26.4.0",
"typescript": "^4.0.5"
},
Expand Down
13 changes: 13 additions & 0 deletions scripts/rename-esm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,18 @@ if [[ ${RUNNER_DEBUG:-0} == 1 ]]; then
fi

for file in dist/esm/*.js; do
# Rename the `.js` files to `.mjs`.
mv "$file" "${file%.js}.mjs"

# Replace the sourceMappingURL to point to the new `.mjs.map` file.
sourceMap=$(basename "${file%.js}.mjs.map")
sed -i '' "s|//# sourceMappingURL=.*\.js\.map|//# sourceMappingURL=$sourceMap|" "${file%.js}.mjs"
done

for file in dist/esm/*.js.map; do
# Rename the `.js.map` files to `.mjs.map`.
mv "$file" "${file%.js.map}.mjs.map"

# Replace the file references in the source map to point to the new `.mjs` file.
sed -i '' 's/\.js/\.mjs/g' "${file%.js.map}.mjs.map"
done
4 changes: 4 additions & 0 deletions tsconfig.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@
},
"include": [
"./**/*.ts"
],
"exclude": [
"node_modules",
"dist"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"dist"
"dist",
"**/*.test.ts"

]
}
4 changes: 4 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@
},
"include": [
"./**/*.ts"
],
"exclude": [
"node_modules",
"dist"
Copy link
Member

Choose a reason for hiding this comment

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

Why is this needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Otherwise TypeScript will try to build dist again, but that results in errors since it's also writing to dist.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not really needed now that I've added rimraf I guess, but it doesn't hurt to add it.

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"dist"
"dist",
"**/*.test.ts"

]
}