Skip to content

Commit

Permalink
Merge pull request #160 from gvergnaud/gvergnaud/fix-build-for-nodene…
Browse files Browse the repository at this point in the history
…xt-and-commonjs

Gvergnaud/fix build for nodenext and commonjs
  • Loading branch information
gvergnaud committed May 8, 2023
2 parents 788c082 + b5b067f commit f147f96
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 13 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
{
"name": "ts-pattern",
"version": "4.2.3",
"version": "4.3.0",
"description": " The exhaustive Pattern Matching library for TypeScript.",
"type": "module",
"source": "src/index.ts",
"exports": {
".": {
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
},
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs",
"default": "./dist/index.mjs"
"default": "./dist/index.js"
},
"./package.json": "./package.json"
},
"types": "dist/index.d.ts",
"main": "dist/index.cjs",
"module": "dist/index.mjs",
"unpkg": "dist/index.umd.cjs",
"module": "dist/index.js",
"unpkg": "dist/index.umd.js",
"scripts": {
"build": "rimraf dist && microbundle",
"build": "rimraf dist && microbundle && sh ./scripts/generate-cts.sh",
"dev": "microbundle watch",
"prepublishOnly": "npm run test && npm run build",
"test": "jest",
Expand Down
18 changes: 18 additions & 0 deletions scripts/generate-cts.sh
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

0 comments on commit f147f96

Please sign in to comment.