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

Gvergnaud/fix build for nodenext and commonjs #160

Merged
merged 8 commits into from
May 8, 2023
Merged
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: 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