Skip to content

Commit f147f96

Browse files
authored
Merge pull request #160 from gvergnaud/gvergnaud/fix-build-for-nodenext-and-commonjs
Gvergnaud/fix build for nodenext and commonjs
2 parents 788c082 + b5b067f commit f147f96

3 files changed

Lines changed: 33 additions & 9 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
11
{
22
"name": "ts-pattern",
3-
"version": "4.2.3",
3+
"version": "4.3.0",
44
"description": " The exhaustive Pattern Matching library for TypeScript.",
55
"type": "module",
66
"source": "src/index.ts",
77
"exports": {
88
".": {
9+
"require": {
10+
"types": "./dist/index.d.cts",
11+
"default": "./dist/index.cjs"
12+
},
13+
"import": {
14+
"types": "./dist/index.d.ts",
15+
"default": "./dist/index.js"
16+
},
917
"types": "./dist/index.d.ts",
10-
"import": "./dist/index.mjs",
11-
"require": "./dist/index.cjs",
12-
"default": "./dist/index.mjs"
18+
"default": "./dist/index.js"
1319
},
1420
"./package.json": "./package.json"
1521
},
1622
"types": "dist/index.d.ts",
1723
"main": "dist/index.cjs",
18-
"module": "dist/index.mjs",
19-
"unpkg": "dist/index.umd.cjs",
24+
"module": "dist/index.js",
25+
"unpkg": "dist/index.umd.js",
2026
"scripts": {
21-
"build": "rimraf dist && microbundle",
27+
"build": "rimraf dist && microbundle && sh ./scripts/generate-cts.sh",
2228
"dev": "microbundle watch",
2329
"prepublishOnly": "npm run test && npm run build",
2430
"test": "jest",

scripts/generate-cts.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
# TypeScript projects using `moduleResolution: nodenext` expect
4+
# explicit extensions to be included in declaration files,
5+
# and to have a different set of declarations for commonjs
6+
# modules (.d.cts) and ES modules (.d.ts). `tsc` unfortunately
7+
# doesn't provide a way to generate these declarations files,
8+
# so I'm manually creating them in this script.
9+
10+
files=$(find dist -type f -name "*.d.ts");
11+
12+
# Loop through the declaration files
13+
for file in $files; do
14+
# Update imports to include the '.cjs' extension
15+
sed -E "s/(.*)from '([^']*)'/\1from '\2.cjs'/g" "$file" > "${file%.d.ts}.d.cts"
16+
# add `.js` extensions to .d.ts files
17+
sed -i '' -e "s/\(.*\)from '\([^']*\)'/\1from '\2.js'/g" "$file"
18+
done

0 commit comments

Comments
 (0)