Skip to content

Commit 8e9421a

Browse files
serhalpndhoule
authored andcommittedApr 1, 2025··
fix(npm-shrinkwrap.json): remove dev deps
We accidentally reintroduced dev dependencies in the `npm-shrinkwrap.json` file here: https://github.com/netlify/cli/pull/7119/files?file-filters%5B%5D=.js&file-filters%5B%5D=.json&file-filters%5B%5D=.md&file-filters%5B%5D=.yml&show-viewed-files=true&show-deleted-files=false#diff-3d80e6f9eb8af7a28cbe2209d086150e29b68f860376ee618a0041ca9b5c786dL18-L49. The deleted script was deleting `package.json#devDependencies` before running `npm i && npm shrinkwrap`, which resulted in the shrinkwrap being built from a modified `package-lock.json` with dev deps removed 😓.
1 parent 90afd98 commit 8e9421a

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed
 

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"test:integration": "vitest run tests/integration/",
5454
"test:unit": "vitest run tests/unit/",
5555
"postinstall": "node ./scripts/postinstall.js",
56-
"prepublishOnly": "npm shrinkwrap",
56+
"prepublishOnly": "node ./scripts/prepublishOnly.js",
5757
"typecheck": "tsc",
5858
"typecheck:watch": "tsc --watch"
5959
},

‎scripts/prepublishOnly.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import * as cp from 'node:child_process'
2+
import * as fs from 'node:fs/promises'
3+
import * as path from 'node:path'
4+
5+
const main = async () => {
6+
// It's best practice to include a shrinkwrap when shipping a CLI. npm has a bug that makes it
7+
// not ignore development dependencies in an installed package's shrinkwrap, though:
8+
//
9+
// https://github.com/npm/cli/issues/4323
10+
//
11+
// Leaving development dependencies makes the CLI installation significantly larger and increases
12+
// the risk of platform-specific dependency installation issues.
13+
// eslint-disable-next-line no-restricted-properties
14+
const packageJSONPath = path.join(process.cwd(), 'package.json')
15+
const rawPackageJSON = await fs.readFile(packageJSONPath, 'utf8')
16+
17+
try {
18+
// Remove dev dependencies from the package.json...
19+
const packageJSON = JSON.parse(rawPackageJSON)
20+
Reflect.deleteProperty(packageJSON, 'devDependencies')
21+
await fs.writeFile(packageJSONPath, JSON.stringify(packageJSON, null, 2))
22+
23+
// Prune out dev dependencies (this updates the `package-lock.json` lockfile)
24+
cp.spawnSync('npm', ['prune'], { stdio: 'inherit' })
25+
26+
// Convert `package-lock.json` lockfile to `npm-shrinkwrap.json`
27+
cp.spawnSync('npm', ['shrinkwrap'], { stdio: 'inherit' })
28+
} finally {
29+
// Restore the original `package.json`. (This makes no functional difference in a publishing
30+
// environment, it's purely to minimize how destructive this script is.)
31+
await fs.writeFile(packageJSONPath, rawPackageJSON)
32+
}
33+
}
34+
35+
await main()

1 commit comments

Comments
 (1)

github-actions[bot] commented on Apr 1, 2025

@github-actions[bot]

📊 Benchmark results

  • Dependency count: 1,171
  • Package size: 283 MB
  • Number of ts-expect-error directives: 713
Please sign in to comment.