From a7027c2d2a654a0deffd1355f7503166c1446001 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Sun, 15 Jun 2025 01:54:34 -0700 Subject: [PATCH] Remove `scripts` and `devDependencies` from packed `package.json` These keys are used for development purposes only, so it is wasting bandwidth to ship them with the final package. --- npm/postpack.js | 4 ++++ npm/prepack.js | 5 +++++ package.json | 3 ++- 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 npm/postpack.js diff --git a/npm/postpack.js b/npm/postpack.js new file mode 100644 index 0000000..2eeffb6 --- /dev/null +++ b/npm/postpack.js @@ -0,0 +1,4 @@ +import { copyFile, unlink } from 'node:fs/promises'; + +await copyFile('./package.backup.json', './package.json'); +await unlink('./package.backup.json'); diff --git a/npm/prepack.js b/npm/prepack.js index 6242837..054d18a 100644 --- a/npm/prepack.js +++ b/npm/prepack.js @@ -1,3 +1,8 @@ +import { copyFile } from 'node:fs/promises'; import { execSync } from 'node:child_process'; execSync('npm run types'); + +await copyFile('./package.json', './package.backup.json'); +execSync('npm pkg delete scripts'); +execSync('npm pkg delete devDependencies'); diff --git a/package.json b/package.json index 0500483..e6be717 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,8 @@ "test:large": "node --test --test-name-pattern=\"/^large:/\"", "test:coverage": "npm run test -- --experimental-test-coverage", "bench": "node ./benchmark/core.bench.js", - "prepack": "node ./npm/prepack.js" + "prepack": "node ./npm/prepack.js", + "postpack": "node ./npm/postpack.js" }, "devDependencies": { "@types/node": "^24.0.0", -- 2.47.3