Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print a warning when used with Node versions other than v16.15.0 #4366

Merged
merged 3 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
"webpack-extract-translation-keys-plugin": "^6.0.0"
},
"scripts": {
"preinstall": "npm run hint",
"postinstall": "patch-package && npm run copy-fonts",
"build": "npm run hint build && webpack --config webpack/prod.config.js",
"watch": "npm run hint watch && webpack-dev-server --config webpack/dev.server.js",
Expand Down
87 changes: 86 additions & 1 deletion scripts/hints.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,92 @@ if (hint) {
}

// Provide an auxiliary hint.
if (process.env.SKIP_TS_CHECK) {
const tsCheckAffects = ['build', 'watch', 'test', 'test-autobuild'];
if (process.env.SKIP_TS_CHECK && tsCheckAffects.includes(hintName)) {
jnm marked this conversation as resolved.
Show resolved Hide resolved
// bright red default
console.warn('\u001b[91m' + hints.SKIP_TS_CHECK + '\u001b[0m');
}

/*
NPM VERSION WRANING

Issue a warning if not running with npm 8.5.5, since the errors
that you get if you run a different version are not very obvious.

- Help contributors who switched their Node version inadvertently.
- Support new contributors by printing more context / steps to remedy.
- Give the benefit of the doubt to developers who run a different node/npm
version on purpose. So, don't process.exit(1), even on npm install.

Show on preinstall. Since it's easy to miss there, also show it on other
run scripts such as 'watch'.
*/
const ok_node = 'v16.15.0';
const ok_npm = '8.5.5';

if (process.version !== ok_node) {
const blu = '\u001b[94m'; // bright blue
const yel = '\u001b[93m'; // bright yellow
const red = '\u001b[91m'; // bright red
const nrm = '\u001b[0m'; // reset to "normal"

console.warn(`${blu}
--------------------------------------------------------------`);

console.warn(`${yel}
Are you running the supported version of Node and npm?
${nrm}
node ${ok_node}, npm@${ok_npm} supported`);

// Let's be more helpful by running `npm --version` instead of making
// you do it.
let detectedNpm = '?';
try {
detectedNpm = require('child_process')
.execSync('npm --version')
.toString()
.trim();
} catch (error) {
console.warn(error.message);
console.warn(error.stderr.toString());
process.exit();
}
const wrongNpm = detectedNpm !== ok_npm;
const wrongNode = process.version !== ok_node;
console.warn(
` node ${wrongNode ? yel : ''}${process.version}${nrm}, ${
wrongNpm ? red : ''
}npm@${detectedNpm}${nrm} detected`
);

// Things might actually work OK on a mismatched Node version,
// but running the wrong npm version when installing packages is
// what causes the most problems.
if (wrongNpm) {
console.warn(`
Switch to a supported Node / npm version:

Use Node v16.15.0, which comes with npm@8.5.5
\`nvm use\` or \`fnm use\`

or \`npm install -g npm@8.5.5\`
to change npm for your current Node`);

console.warn(`${red}
If you've run \`npm install\` with an unsupported npm version,${nrm}
there may be changes in node_modules and package-lock.json

(1) Don't commit these changes to package-lock.json
(2) You may want to reset these changes and run
\`npm install\` again with 8.5.5
`);

// If you switch between Node projects and see this message often,
// consider configuring `fnm` to change your Node version on `cd`.
// More info: https://github.com/Schniz/fnm#shell-setup
}

console.warn(`${blu}
--------------------------------------------------------------
`);
}