Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions build/npm/preinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// @ts-check
const path = require('path');
const fs = require('fs');
const semver = require('semver');

if (!process.env['VSCODE_SKIP_NODE_VERSION_CHECK']) {
// Get the running Node.js version
Expand Down Expand Up @@ -35,6 +36,17 @@ if (!process.env['VSCODE_SKIP_NODE_VERSION_CHECK']) {
}
}

const requiredNpmVersion = '10.5.0';
const npmUserAgent = process.env['npm_config_user_agent'];
const npmVersionMatch = npmUserAgent?.match(/npm\/(\d+\.\d+\.\d+)/);
const npmVersion = npmVersionMatch?.[1];
const currentNpmVersion = npmVersion ? semver.coerce(npmVersion) : undefined;

if (currentNpmVersion && semver.lt(currentNpmVersion, requiredNpmVersion)) {
console.error(`\x1b[1;31m*** Please use npm v${requiredNpmVersion} or later. Currently using v${npmVersion}. ***\x1b[0;0m`);
process.exit(1);
}

if (process.env.npm_execpath?.includes('yarn')) {
console.error('\x1b[1;31m*** Seems like you are using `yarn` which is not supported in this repo any more, please use `npm i` instead. ***\x1b[0;0m');
throw new Error();
Expand Down