diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cfec9fc..128aec0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -19,6 +19,8 @@ jobs: cache: "yarn" - name: Install dependencies run: yarn install --immutable + - name: Check package.json library usage + run: yarn packagejson:check - name: Spell checking with Cspell run: yarn cspell:ci - name: Lint codebase with Eslint diff --git a/lint-staged.config.cjs b/lint-staged.config.cjs index 4f1bcae..e8615ea 100644 --- a/lint-staged.config.cjs +++ b/lint-staged.config.cjs @@ -1,5 +1,5 @@ module.exports = { - "package.json": ['yarn packagejson:format'], + "package.json": ['yarn packagejson:format', 'yarn packagejson:check'], "**/*.ts": () => ["tsc -p tsconfig.json --noEmit"], "**/*.{ts,mts,cts,js,mjs,cjs}": (filenames) => `eslint -c .eslintrc.cjs ${filenames.join(" ")} --fix --cache`, }; diff --git a/package.json b/package.json index a9ef013..ef75cde 100644 --- a/package.json +++ b/package.json @@ -17,12 +17,12 @@ "access": "public", "registry": " https://registry.npmjs.org" }, - "main": "./lib/cjs/index.cjs", + "type": "module", "exports": { ".": { "types": "./lib/types/index.d.ts", "require": "./lib/cjs/index.cjs", - "default": "./lib/cjs/index.cjs" + "import": "./lib/esm/index.js" } }, "files": [ @@ -30,8 +30,8 @@ ], "types": "./lib/types/index.d.ts", "scripts": { - "build": "yarn clean && yarn build:cjs", - "build:cjs": "tsc -b tsconfig.build.cjs.json", + "build": "yarn clean && yarn build:cjs && yarn build:esm", + "build:cjs": "tsc -b tsconfig.build.cjs.json && ./scripts/convert-to-cjs.sh", "build:esm": "tsc -b tsconfig.build.esm.json", "clean": "rm -rfv reports coverage build dist lib .eslintcache", "commit": "cz", @@ -43,6 +43,7 @@ "postinstall": "husky install", "prepack": "pinst --disable", "postpack": "pinst --enable", + "packagejson:check": "package-check", "packagejson:format": "prettier-package-json --write ./package.json", "test": "yarn test:unit", "test:mutation": "stryker run", @@ -56,6 +57,7 @@ "@commitlint/cli": "^17.0.2", "@commitlint/config-conventional": "^17.0.2", "@commitlint/cz-commitlint": "^17.0.0", + "@skypack/package-check": "^0.2.2", "@stryker-mutator/core": "^6.0.2", "@stryker-mutator/mocha-runner": "^6.0.2", "@stryker-mutator/typescript-checker": "^6.0.2", diff --git a/scripts/convert-to-cjs.sh b/scripts/convert-to-cjs.sh new file mode 100755 index 0000000..de9bc31 --- /dev/null +++ b/scripts/convert-to-cjs.sh @@ -0,0 +1,11 @@ +echo "Converting .js files to .cjs" + +FILES=$(find "./lib" -name "*.js") + +for path in $FILES +do + echo "Editing $path" + sed -r -i "" "s/(require ?[^\"]+\"([^\"]+))\.js/\1.cjs/" "$path" + mv "$path" "${path/%.js/.cjs}" +done +echo "Done converting files to .cjs" diff --git a/tsconfig.build.cjs.json b/tsconfig.build.cjs.json index 4a5eb46..a7f7dcf 100644 --- a/tsconfig.build.cjs.json +++ b/tsconfig.build.cjs.json @@ -4,8 +4,8 @@ "outDir": "./lib/cjs", "target": "ES2015", "module": "CommonJS", - "declarationDir": "./lib/types", - "esModuleInterop": true + "declaration": false, + "declarationMap": false }, "include": ["./src/**/*"] } diff --git a/tsconfig.build.json b/tsconfig.build.json index 7fc6c4c..1e04dcf 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -3,7 +3,7 @@ "compilerOptions": { "baseUrl": ".", "declaration": true, - "declarationMap": false, + "declarationMap": true, "removeComments": false, "sourceMap": false, "noEmit": false, diff --git a/yarn.lock b/yarn.lock index 6c1067c..13d4fd0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1604,6 +1604,18 @@ __metadata: languageName: node linkType: hard +"@skypack/package-check@npm:^0.2.2": + version: 0.2.2 + resolution: "@skypack/package-check@npm:0.2.2" + dependencies: + kleur: ^4.1.3 + yargs-parser: ^20.2.3 + bin: + package-check: index.bin.js + checksum: 7b35c331609b743815ba9d2a7d789e8157d5119ea167fe684cd9d95978892d01aac0e36db5ea8d54fc565e5f57f3732a9793c5c711d454ce9bf1581f34829e9f + languageName: node + linkType: hard + "@stryker-mutator/api@npm:6.0.2": version: 6.0.2 resolution: "@stryker-mutator/api@npm:6.0.2" @@ -5453,6 +5465,13 @@ __metadata: languageName: node linkType: hard +"kleur@npm:^4.1.3": + version: 4.1.4 + resolution: "kleur@npm:4.1.4" + checksum: 7f6db36e378045dec14acd3cbf0b1e59130c09e984ee8b8ce56dd2d2257cfff90389c1e8f8b19bd09dd5d241080566a814b4ccd99fdcef91f59ef93ec33c8a44 + languageName: node + linkType: hard + "levn@npm:^0.4.1": version: 0.4.1 resolution: "levn@npm:0.4.1" @@ -8686,6 +8705,7 @@ __metadata: "@commitlint/cli": ^17.0.2 "@commitlint/config-conventional": ^17.0.2 "@commitlint/cz-commitlint": ^17.0.0 + "@skypack/package-check": ^0.2.2 "@stryker-mutator/core": ^6.0.2 "@stryker-mutator/mocha-runner": ^6.0.2 "@stryker-mutator/typescript-checker": ^6.0.2