mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-10 12:57:47 +00:00
[cli] Remove preinstall script (#10157)
This will solve two of the warnings from [Socket.dev](https://socket.dev/npm/package/vercel): <img width="1126" alt="image" src="https://github.com/vercel/vercel/assets/229881/c890c973-4f5a-44d9-9b96-2580a1e40ed0"> This preinstall script isn't necessary to run Vercel CLI, its only used to improve the error message in two cases: - The system has `node` version prior to 14.x (3 years ago) - The system still has `now` installed but should be using `vercel` (last shipped 3 years ago) The usage of `preinstall` scripts have gone out of style due to security audits so we should remove this script now.
This commit is contained in:
5
.changeset/wet-spoons-boil.md
Normal file
5
.changeset/wet-spoons-boil.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"vercel": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
[cli] Remove `preinstall` script
|
||||||
@@ -11,7 +11,6 @@
|
|||||||
"directory": "packages/cli"
|
"directory": "packages/cli"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"preinstall": "node ./scripts/preinstall.js",
|
|
||||||
"test": "jest --env node --verbose --bail",
|
"test": "jest --env node --verbose --bail",
|
||||||
"test-unit": "pnpm test test/unit/",
|
"test-unit": "pnpm test test/unit/",
|
||||||
"test-e2e": "rimraf test/fixtures/integration && pnpm test test/integration-1.test.ts test/integration-2.test.ts test/integration-3.test.ts",
|
"test-e2e": "rimraf test/fixtures/integration && pnpm test test/integration-1.test.ts test/integration-2.test.ts test/integration-3.test.ts",
|
||||||
|
|||||||
@@ -1,101 +0,0 @@
|
|||||||
#!/usr/bin/env node
|
|
||||||
const { join } = require('path');
|
|
||||||
const { statSync } = require('fs');
|
|
||||||
const pkg = require('../package');
|
|
||||||
|
|
||||||
function error(command) {
|
|
||||||
console.error('> Error:', command);
|
|
||||||
}
|
|
||||||
|
|
||||||
function debug(str) {
|
|
||||||
if (
|
|
||||||
process.argv.find(str => str === '--debug') ||
|
|
||||||
process.env.PREINSTALL_DEBUG
|
|
||||||
) {
|
|
||||||
console.log(`[debug] [${new Date().toISOString()}]`, str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function isYarn() {
|
|
||||||
return process.env.npm_config_heading !== 'npm';
|
|
||||||
}
|
|
||||||
|
|
||||||
function isGlobal() {
|
|
||||||
const cmd = JSON.parse(process.env.npm_config_argv || '{ "original": [] }');
|
|
||||||
|
|
||||||
return isYarn()
|
|
||||||
? cmd.original.includes('global')
|
|
||||||
: Boolean(process.env.npm_config_global);
|
|
||||||
}
|
|
||||||
|
|
||||||
function isVercel() {
|
|
||||||
return pkg.name === 'vercel';
|
|
||||||
}
|
|
||||||
|
|
||||||
function validateNodeVersion() {
|
|
||||||
let semver = '>= 0';
|
|
||||||
let major = '1';
|
|
||||||
|
|
||||||
try {
|
|
||||||
major = process.versions.node.split('.')[0];
|
|
||||||
const pkg = require('../package.json');
|
|
||||||
semver = pkg.engines.node;
|
|
||||||
} catch (e) {
|
|
||||||
debug('Failed to read package.json engines');
|
|
||||||
}
|
|
||||||
|
|
||||||
const isValid = eval(`${major} ${semver}`);
|
|
||||||
return { isValid, expected: semver, actual: process.versions.node };
|
|
||||||
}
|
|
||||||
|
|
||||||
function isInNodeModules(name) {
|
|
||||||
try {
|
|
||||||
const nodeModules = join(__dirname, '..', '..');
|
|
||||||
const stat = statSync(join(nodeModules, name));
|
|
||||||
return stat.isDirectory();
|
|
||||||
} catch (err) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function main() {
|
|
||||||
if (!isGlobal()) {
|
|
||||||
debug('Skipping preinstall since Vercel CLI is being installed locally');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const ver = validateNodeVersion();
|
|
||||||
|
|
||||||
if (!ver.isValid) {
|
|
||||||
error(
|
|
||||||
`Detected unsupported Node.js version.\n` +
|
|
||||||
`Expected "${ver.expected}" but found "${ver.actual}".\n` +
|
|
||||||
`Please update to the latest Node.js LTS version to install Vercel CLI.`
|
|
||||||
);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isVercel() && isInNodeModules('now')) {
|
|
||||||
const uninstall = isYarn()
|
|
||||||
? 'yarn global remove now'
|
|
||||||
: 'npm uninstall -g now';
|
|
||||||
console.error(`NOTE: Run \`${uninstall}\` to uninstall \`now\`\n`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
process.on('unhandledRejection', err => {
|
|
||||||
console.error('Unhandled Rejection:');
|
|
||||||
console.error(err);
|
|
||||||
process.exit(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
process.on('uncaughtException', err => {
|
|
||||||
console.error('Uncaught Exception:');
|
|
||||||
console.error(err);
|
|
||||||
process.exit(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
main().catch(err => {
|
|
||||||
console.error(err);
|
|
||||||
process.exit(1);
|
|
||||||
});
|
|
||||||
Reference in New Issue
Block a user