From ebdb1f7b800fa1bccf8c06d0b09c578e226d563a Mon Sep 17 00:00:00 2001 From: Daniel Grefberg Date: Tue, 19 Sep 2023 11:59:12 +0200 Subject: [PATCH 1/2] chore: copy typings file to built folders --- build.js | 7 ++ package-lock.json | 215 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 3 +- 3 files changed, 224 insertions(+), 1 deletion(-) diff --git a/build.js b/build.js index e5f4edc7..47602b68 100755 --- a/build.js +++ b/build.js @@ -5,14 +5,20 @@ const process = require('process'); const isCI = require('is-ci'); const fg = require('fast-glob'); const esbuild = require('esbuild'); +const { copy } = require('esbuild-plugin-copy'); const isEsmBuild = process.argv[2] !== '--cjs'; +const copyTypingsPlugin = copy({ + assets: [{ from: ['./typings.d.ts'], to: ['./typings.d.ts'] }], +}); + const config = { cjs: { format: 'cjs', platform: 'node', outdir: './lib/cjs', + plugins: [copyTypingsPlugin], }, esm: { format: 'esm', @@ -33,6 +39,7 @@ const config = { }); }, }, + copyTypingsPlugin, ], }, }; diff --git a/package-lock.json b/package-lock.json index a7237670..33b71728 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,6 +21,7 @@ "ajv": "^8.8.2", "esbuild": "^0.14.0", "esbuild-jest": "^0.5.0", + "esbuild-plugin-copy": "^2.1.1", "eslint": "^8.3.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-jest": "^26.0.0", @@ -3179,6 +3180,15 @@ "node": ">=0.6" } }, + "node_modules/binary-extensions": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", + "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==", + "dev": true, + "engines": { + "node": ">=8" + } + }, "node_modules/boolbase": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz", @@ -3395,6 +3405,45 @@ "integrity": "sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==", "dev": true }, + "node_modules/chokidar": { + "version": "3.5.3", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz", + "integrity": "sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==", + "dev": true, + "funding": [ + { + "type": "individual", + "url": "https://paulmillr.com/funding/" + } + ], + "dependencies": { + "anymatch": "~3.1.2", + "braces": "~3.0.2", + "glob-parent": "~5.1.2", + "is-binary-path": "~2.1.0", + "is-glob": "~4.0.1", + "normalize-path": "~3.0.0", + "readdirp": "~3.6.0" + }, + "engines": { + "node": ">= 8.10.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.2" + } + }, + "node_modules/chokidar/node_modules/glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dev": true, + "dependencies": { + "is-glob": "^4.0.1" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/ci-info": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.3.0.tgz", @@ -4559,6 +4608,56 @@ "node": ">=12" } }, + "node_modules/esbuild-plugin-copy": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/esbuild-plugin-copy/-/esbuild-plugin-copy-2.1.1.tgz", + "integrity": "sha512-Bk66jpevTcV8KMFzZI1P7MZKZ+uDcrZm2G2egZ2jNIvVnivDpodZI+/KnpL3Jnap0PBdIHU7HwFGB8r+vV5CVw==", + "dev": true, + "dependencies": { + "chalk": "^4.1.2", + "chokidar": "^3.5.3", + "fs-extra": "^10.0.1", + "globby": "^11.0.3" + }, + "peerDependencies": { + "esbuild": ">= 0.14.0" + } + }, + "node_modules/esbuild-plugin-copy/node_modules/fs-extra": { + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz", + "integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==", + "dev": true, + "dependencies": { + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild-plugin-copy/node_modules/jsonfile": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", + "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", + "dev": true, + "dependencies": { + "universalify": "^2.0.0" + }, + "optionalDependencies": { + "graceful-fs": "^4.1.6" + } + }, + "node_modules/esbuild-plugin-copy/node_modules/universalify": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", + "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==", + "dev": true, + "engines": { + "node": ">= 10.0.0" + } + }, "node_modules/esbuild-sunos-64": { "version": "0.14.34", "resolved": "https://registry.npmjs.org/esbuild-sunos-64/-/esbuild-sunos-64-0.14.34.tgz", @@ -5971,6 +6070,18 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-binary-path": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", + "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", + "dev": true, + "dependencies": { + "binary-extensions": "^2.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/is-boolean-object": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/is-boolean-object/-/is-boolean-object-1.1.2.tgz", @@ -9632,6 +9743,18 @@ "node": ">=4" } }, + "node_modules/readdirp": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", + "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", + "dev": true, + "dependencies": { + "picomatch": "^2.2.1" + }, + "engines": { + "node": ">=8.10.0" + } + }, "node_modules/redent": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/redent/-/redent-3.0.0.tgz", @@ -15009,6 +15132,12 @@ "integrity": "sha512-GPEid2Y9QU1Exl1rpO9B2IPJGHPSupF5GnVIP0blYvNOMer2bTvSWs1jGOUg04hTmu67nmLsQ9TBo1puaotBHg==", "dev": true }, + "binary-extensions": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", + "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==", + "dev": true + }, "boolbase": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz", @@ -15166,6 +15295,33 @@ "integrity": "sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==", "dev": true }, + "chokidar": { + "version": "3.5.3", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz", + "integrity": "sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==", + "dev": true, + "requires": { + "anymatch": "~3.1.2", + "braces": "~3.0.2", + "fsevents": "~2.3.2", + "glob-parent": "~5.1.2", + "is-binary-path": "~2.1.0", + "is-glob": "~4.0.1", + "normalize-path": "~3.0.0", + "readdirp": "~3.6.0" + }, + "dependencies": { + "glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dev": true, + "requires": { + "is-glob": "^4.0.1" + } + } + } + }, "ci-info": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.3.0.tgz", @@ -16023,6 +16179,47 @@ "dev": true, "optional": true }, + "esbuild-plugin-copy": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/esbuild-plugin-copy/-/esbuild-plugin-copy-2.1.1.tgz", + "integrity": "sha512-Bk66jpevTcV8KMFzZI1P7MZKZ+uDcrZm2G2egZ2jNIvVnivDpodZI+/KnpL3Jnap0PBdIHU7HwFGB8r+vV5CVw==", + "dev": true, + "requires": { + "chalk": "^4.1.2", + "chokidar": "^3.5.3", + "fs-extra": "^10.0.1", + "globby": "^11.0.3" + }, + "dependencies": { + "fs-extra": { + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz", + "integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==", + "dev": true, + "requires": { + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + } + }, + "jsonfile": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", + "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", + "dev": true, + "requires": { + "graceful-fs": "^4.1.6", + "universalify": "^2.0.0" + } + }, + "universalify": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", + "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==", + "dev": true + } + } + }, "esbuild-sunos-64": { "version": "0.14.34", "resolved": "https://registry.npmjs.org/esbuild-sunos-64/-/esbuild-sunos-64-0.14.34.tgz", @@ -17054,6 +17251,15 @@ "has-bigints": "^1.0.1" } }, + "is-binary-path": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", + "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", + "dev": true, + "requires": { + "binary-extensions": "^2.0.0" + } + }, "is-boolean-object": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/is-boolean-object/-/is-boolean-object-1.1.2.tgz", @@ -19911,6 +20117,15 @@ } } }, + "readdirp": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", + "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", + "dev": true, + "requires": { + "picomatch": "^2.2.1" + } + }, "redent": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/redent/-/redent-3.0.0.tgz", diff --git a/package.json b/package.json index 3558990f..541cacdd 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "exports": { ".": { "require": "./lib/cjs/index.js", - "default": "./lib/esm/index.mjs" + "default": "./lib/esm/index.mjs" } }, "module": "./lib/esm/index.mjs", @@ -60,6 +60,7 @@ "ajv": "^8.8.2", "esbuild": "^0.14.0", "esbuild-jest": "^0.5.0", + "esbuild-plugin-copy": "^2.1.1", "eslint": "^8.3.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-jest": "^26.0.0", From 33690e2be4a2403ce9c172cf2582eb369f7d6b81 Mon Sep 17 00:00:00 2001 From: Daniel Grefberg Date: Tue, 19 Sep 2023 11:59:42 +0200 Subject: [PATCH 2/2] chore: fix exports definition to support both ESM and CJS --- .changeset/curly-beers-jump.md | 5 +++++ build.js | 14 ++++++++------ package.json | 13 +++++++++---- 3 files changed, 22 insertions(+), 10 deletions(-) create mode 100644 .changeset/curly-beers-jump.md diff --git a/.changeset/curly-beers-jump.md b/.changeset/curly-beers-jump.md new file mode 100644 index 00000000..a054f78a --- /dev/null +++ b/.changeset/curly-beers-jump.md @@ -0,0 +1,5 @@ +--- +'better-ajv-errors': patch +--- + +Fix exports definition for ESM and CJS types. diff --git a/build.js b/build.js index 47602b68..761a0b50 100755 --- a/build.js +++ b/build.js @@ -9,16 +9,16 @@ const { copy } = require('esbuild-plugin-copy'); const isEsmBuild = process.argv[2] !== '--cjs'; -const copyTypingsPlugin = copy({ - assets: [{ from: ['./typings.d.ts'], to: ['./typings.d.ts'] }], -}); - const config = { cjs: { format: 'cjs', platform: 'node', outdir: './lib/cjs', - plugins: [copyTypingsPlugin], + plugins: [ + copy({ + assets: [{ from: ['./typings.d.ts'], to: ['./typings.d.ts'] }], + }), + ], }, esm: { format: 'esm', @@ -39,7 +39,9 @@ const config = { }); }, }, - copyTypingsPlugin, + copy({ + assets: [{ from: ['./typings.d.ts'], to: ['./typings.d.mts'] }], + }), ], }, }; diff --git a/package.json b/package.json index 541cacdd..421a4697 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,14 @@ "main": "./lib/cjs/index.js", "exports": { ".": { - "require": "./lib/cjs/index.js", + "import": { + "types": "./lib/esm/typings.d.mts", "default": "./lib/esm/index.mjs" + }, + "require": { + "types": "./lib/cjs/typings.d.ts", + "default": "./lib/cjs/index.js" + } } }, "module": "./lib/esm/index.mjs", @@ -26,10 +32,9 @@ "Tong Li" ], "license": "Apache-2.0", - "types": "./typings.d.ts", + "types": "./lib/cjs/typings.d.ts", "files": [ - "lib", - "typings.d.ts" + "lib" ], "scripts": { "prebuild": "rm -rf lib",