diff --git a/package.json b/package.json index 8599e0ee44e..ad44caffc6c 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,6 @@ }, "files": [ "/bin", - "/npm-shrinkwrap.json", "/scripts", "/functions-templates", "/dist" @@ -52,7 +51,6 @@ "test:integration": "vitest run --retry=3 tests/integration/", "test:unit": "vitest run tests/unit/", "postinstall": "node ./scripts/postinstall.js", - "prepublishOnly": "node ./scripts/prepublishOnly.js", "typecheck": "tsc", "typecheck:watch": "tsc --watch" }, diff --git a/scripts/netlifyPackage.js b/scripts/netlifyPackage.js index b38cdc86aa4..3ee56e564c3 100644 --- a/scripts/netlifyPackage.js +++ b/scripts/netlifyPackage.js @@ -1,9 +1,6 @@ // @ts-check -import assert from 'node:assert' -import { dirname, resolve } from 'node:path' -import { readFile, stat, writeFile } from 'node:fs/promises' - -import execa from 'execa' +import { resolve } from 'node:path' +import { readFile, writeFile } from 'node:fs/promises' /** * @import {Package} from "normalize-package-data" @@ -35,34 +32,13 @@ async function preparePackageJSON() { ...packageJSON.contents, main: './dist/index.js', name: 'netlify', - scripts: { - ...packageJSON.contents.scripts, - - // We don't need the pre-publish script because we expect the work in - // there to be done when publishing the `netlify-cli` package. We'll - // ensure this is the case by throwing if a shrinkwrap file isn't found. - prepublishOnly: undefined, - }, bin: { npxnetlify: binPath, }, } - try { - const shrinkwrap = await stat(resolve(packageJSON.path, '../npm-shrinkwrap.json')) - - assert.ok(shrinkwrap.isFile()) - } catch { - throw new Error('Failed to find npm-shrinkwrap.json file. Did you run the pre-publish script?') - } - console.log(`Writing updated package.json to ${packageJSON.path}...`) await writeFile(packageJSON.path, `${JSON.stringify(newPackageJSON, null, 2)}\n`) - - console.log('Regenerating shrinkwrap file with updated package name...') - await execa('npm', ['shrinkwrap'], { - cwd: dirname(packageJSON.path), - }) } await preparePackageJSON() diff --git a/scripts/prepublishOnly.js b/scripts/prepublishOnly.js deleted file mode 100644 index a397a7de118..00000000000 --- a/scripts/prepublishOnly.js +++ /dev/null @@ -1,29 +0,0 @@ -import * as cp from 'node:child_process' -import * as fs from 'node:fs/promises' -import * as path from 'node:path' - -const main = async () => { - // It's best practice to include a shrinkwrap when shipping a CLI. npm has a bug that makes it - // not ignore development dependencies in an installed package's shrinkwrap, though: - // - // https://github.com/npm/cli/issues/4323 - // - // Leaving development dependencies makes the CLI installation significantly larger and increases - // the risk of platform-specific dependency installation issues. - // eslint-disable-next-line no-restricted-properties - const packageJSONPath = path.join(process.cwd(), 'package.json') - const rawPackageJSON = await fs.readFile(packageJSONPath, 'utf8') - - // Remove dev dependencies from the package.json... - const packageJSON = JSON.parse(rawPackageJSON) - Reflect.deleteProperty(packageJSON, 'devDependencies') - await fs.writeFile(packageJSONPath, JSON.stringify(packageJSON, null, 2)) - - // Prune out dev dependencies (this updates the `package-lock.json` lockfile) - cp.spawnSync('npm', ['prune'], { stdio: 'inherit' }) - - // Convert `package-lock.json` lockfile to `npm-shrinkwrap.json` - cp.spawnSync('npm', ['shrinkwrap'], { stdio: 'inherit' }) -} - -await main()