From e452c088855277740404cdf019790141e55938e3 Mon Sep 17 00:00:00 2001 From: Joachim Viide Date: Tue, 16 Jul 2024 23:38:07 +0000 Subject: [PATCH] Avoid dual package hazard --- .changeset/odd-buttons-check.md | 5 +++++ package.json | 10 +++++----- src/index.esm.mts | 1 + tsconfig.build.json => tsconfig.cjs.json | 0 tsconfig.esm.json | 12 ++++++++++++ tsconfig.json | 6 +++--- 6 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 .changeset/odd-buttons-check.md create mode 100644 src/index.esm.mts rename tsconfig.build.json => tsconfig.cjs.json (100%) create mode 100644 tsconfig.esm.json diff --git a/.changeset/odd-buttons-check.md b/.changeset/odd-buttons-check.md new file mode 100644 index 0000000..9b38b1f --- /dev/null +++ b/.changeset/odd-buttons-check.md @@ -0,0 +1,5 @@ +--- +"@badrap/valita": patch +--- + +Avoid dual package hazard diff --git a/package.json b/package.json index 53cd4a8..60e1345 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "bun": "./src/index.ts", "node": { "module": "./dist/node-mjs/index.mjs", - "import": "./dist/node-mjs/index.mjs", + "import": "./dist/node-cjs/index.esm.mjs", "require": "./dist/node-cjs/index.js" }, "default": "./dist/mjs/index.mjs" @@ -31,10 +31,10 @@ "typecheck": "tsc --skipLibCheck --noEmit", "test": "vitest run", "build": "rm -rf dist/* && npm run build:cjs && npm run build:mjs && npm run build:node-mjs && npm run build:node-cjs", - "build:cjs": "tsc -p ./tsconfig.build.json --target es2015 --module commonjs --outDir ./dist/cjs", - "build:mjs": "tsc -p ./tsconfig.build.json --target es2015 --module es2015 --outDir ./dist/mjs && mv ./dist/mjs/index.js ./dist/mjs/index.mjs && mv ./dist/mjs/index.d.ts ./dist/mjs/index.d.mts", - "build:node-mjs": "tsc -p ./tsconfig.build.json --target es2021 --module es2015 --outDir ./dist/node-mjs && mv ./dist/node-mjs/index.js ./dist/node-mjs/index.mjs && mv ./dist/node-mjs/index.d.ts ./dist/node-mjs/index.d.mts", - "build:node-cjs": "tsc -p ./tsconfig.build.json --target es2021 --module commonjs --outDir ./dist/node-cjs", + "build:cjs": "tsc -p ./tsconfig.cjs.json --outDir ./dist/cjs", + "build:node-cjs": "tsc -p ./tsconfig.cjs.json --target es2021 --outDir ./dist/node-cjs", + "build:mjs": "tsc -p ./tsconfig.esm.json --outDir ./dist/mjs && mv ./dist/mjs/index.js ./dist/mjs/index.mjs && mv ./dist/mjs/index.d.ts ./dist/mjs/index.d.mts", + "build:node-mjs": "tsc -p ./tsconfig.esm.json --target es2021 --outDir ./dist/node-mjs && mv ./dist/node-mjs/index.js ./dist/node-mjs/index.mjs && mv ./dist/node-mjs/index.d.ts ./dist/node-mjs/index.d.mts", "changeset": "changeset", "bump": "changeset version && sed --in-place \"s/\\\"version\\\": \\\".*\\\"/\\\"version\\\": \\\"$(sed -n 's/^\\s*\\\"version\\\": \\\"\\([^\\\"/]*\\)\\\".*/\\1/p' package.json)\\\"/\" jsr.json", "release": "npm run build && changeset publish && jsr publish" diff --git a/src/index.esm.mts b/src/index.esm.mts new file mode 100644 index 0000000..8e893de --- /dev/null +++ b/src/index.esm.mts @@ -0,0 +1 @@ +export * from "./index.js"; diff --git a/tsconfig.build.json b/tsconfig.cjs.json similarity index 100% rename from tsconfig.build.json rename to tsconfig.cjs.json diff --git a/tsconfig.esm.json b/tsconfig.esm.json new file mode 100644 index 0000000..2943b75 --- /dev/null +++ b/tsconfig.esm.json @@ -0,0 +1,12 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "target": "ES2015", + "module": "ES2015", + "moduleResolution": "Node", + "noEmit": false, + "allowImportingTsExtensions": false + }, + "include": ["src/**/*"], + "exclude": ["src/index.esm.mts"] +} diff --git a/tsconfig.json b/tsconfig.json index 0f5ed55..93575e1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,11 +1,11 @@ { "compilerOptions": { "target": "es2020", - "module": "commonjs", + "module": "NodeNext", + "moduleResolution": "NodeNext", "strict": true, "noImplicitReturns": true, "declaration": true, - "moduleResolution": "node", "isolatedModules": true, "outDir": "./dist/main", "sourceMap": true, @@ -13,5 +13,5 @@ "noEmit": true, "allowImportingTsExtensions": true }, - "include": ["mod.ts", "src/**/*.ts", "tests/**/*.ts"] + "include": ["mod.ts", "src/**/*", "tests/**/*"] }