-
-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #160 from gvergnaud/gvergnaud/fix-build-for-nodene…
…xt-and-commonjs Gvergnaud/fix build for nodenext and commonjs
- Loading branch information
Showing
3 changed files
with
33 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
|
||
# TypeScript projects using `moduleResolution: nodenext` expect | ||
# explicit extensions to be included in declaration files, | ||
# and to have a different set of declarations for commonjs | ||
# modules (.d.cts) and ES modules (.d.ts). `tsc` unfortunately | ||
# doesn't provide a way to generate these declarations files, | ||
# so I'm manually creating them in this script. | ||
|
||
files=$(find dist -type f -name "*.d.ts"); | ||
|
||
# Loop through the declaration files | ||
for file in $files; do | ||
# Update imports to include the '.cjs' extension | ||
sed -E "s/(.*)from '([^']*)'/\1from '\2.cjs'/g" "$file" > "${file%.d.ts}.d.cts" | ||
# add `.js` extensions to .d.ts files | ||
sed -i '' -e "s/\(.*\)from '\([^']*\)'/\1from '\2.js'/g" "$file" | ||
done |