Skip to content

Commit

Permalink
fix: improve system requirements checks (#4448)
Browse files Browse the repository at this point in the history
Co-authored-by: Pavel Denisjuk <[email protected]>
  • Loading branch information
adrians5j and Pavel910 authored Jan 9, 2025
1 parent 1243fda commit 2eb1183
Show file tree
Hide file tree
Showing 20 changed files with 480 additions and 270 deletions.
32 changes: 16 additions & 16 deletions .github/workflows/pullRequests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# and run "github-actions-wac build" (or "ghawac build") to regenerate this file.
# For more information, run "github-actions-wac --help".
name: Pull Requests
'on': pull_request
"on": pull_request
concurrency:
group: pr-${{ github.event.pull_request.number }}
cancel-in-progress: true
Expand All @@ -19,7 +19,7 @@ jobs:
- uses: webiny/[email protected]
runs-on: ubuntu-latest
env:
NODE_OPTIONS: '--max_old_space_size=4096'
NODE_OPTIONS: "--max_old_space_size=4096"
YARN_ENABLE_IMMUTABLE_INSTALLS: false
validateCommitsDev:
name: Validate commit messages (dev branch, 'feat' commits not allowed)
Expand All @@ -34,7 +34,7 @@ jobs:
allowed-commit-types: fix,docs,style,refactor,test,build,perf,ci,chore,revert,merge,wip
runs-on: ubuntu-latest
env:
NODE_OPTIONS: '--max_old_space_size=4096'
NODE_OPTIONS: "--max_old_space_size=4096"
YARN_ENABLE_IMMUTABLE_INSTALLS: false
constants:
name: Create constants
Expand Down Expand Up @@ -87,7 +87,7 @@ jobs:
$GITHUB_OUTPUT
runs-on: ubuntu-latest
env:
NODE_OPTIONS: '--max_old_space_size=4096'
NODE_OPTIONS: "--max_old_space_size=4096"
YARN_ENABLE_IMMUTABLE_INSTALLS: false
assignMilestone:
name: Assign milestone
Expand Down Expand Up @@ -117,7 +117,7 @@ jobs:
milestone: ${{ steps.get-milestone-to-assign.outputs.milestone }}
runs-on: ubuntu-latest
env:
NODE_OPTIONS: '--max_old_space_size=4096'
NODE_OPTIONS: "--max_old_space_size=4096"
YARN_ENABLE_IMMUTABLE_INSTALLS: false
build:
name: Build
Expand Down Expand Up @@ -149,7 +149,7 @@ jobs:
path: ${{ github.base_ref }}/.webiny/cached-packages
key: ${{ needs.constants.outputs.run-cache-key }}
env:
NODE_OPTIONS: '--max_old_space_size=4096'
NODE_OPTIONS: "--max_old_space_size=4096"
YARN_ENABLE_IMMUTABLE_INSTALLS: false
staticCodeAnalysis:
needs:
Expand Down Expand Up @@ -190,7 +190,7 @@ jobs:
working-directory: ${{ github.base_ref }}
runs-on: ubuntu-latest
env:
NODE_OPTIONS: '--max_old_space_size=4096'
NODE_OPTIONS: "--max_old_space_size=4096"
YARN_ENABLE_IMMUTABLE_INSTALLS: false
staticCodeAnalysisTs:
name: Static code analysis (TypeScript)
Expand All @@ -216,7 +216,7 @@ jobs:
run: yarn cy:ts
working-directory: ${{ github.base_ref }}
env:
NODE_OPTIONS: '--max_old_space_size=4096'
NODE_OPTIONS: "--max_old_space_size=4096"
YARN_ENABLE_IMMUTABLE_INSTALLS: false
jestTestsNoStorageConstants:
needs:
Expand Down Expand Up @@ -244,7 +244,7 @@ jobs:
echo '${{
steps.list-packages-to-jest-test.outputs.packages-to-jest-test }}'
env:
NODE_OPTIONS: '--max_old_space_size=4096'
NODE_OPTIONS: "--max_old_space_size=4096"
YARN_ENABLE_IMMUTABLE_INSTALLS: false
jestTestsNoStorageRun:
needs:
Expand All @@ -265,7 +265,7 @@ jobs:
}}
runs-on: ${{ matrix.os }}
env:
NODE_OPTIONS: '--max_old_space_size=4096'
NODE_OPTIONS: "--max_old_space_size=4096"
YARN_ENABLE_IMMUTABLE_INSTALLS: false
AWS_REGION: eu-central-1
if: needs.jestTestsNoStorageConstants.outputs.packages-to-jest-test != '[]'
Expand Down Expand Up @@ -363,7 +363,7 @@ jobs:
echo '${{
steps.list-packages-to-jest-test.outputs.packages-to-jest-test }}'
env:
NODE_OPTIONS: '--max_old_space_size=4096'
NODE_OPTIONS: "--max_old_space_size=4096"
YARN_ENABLE_IMMUTABLE_INSTALLS: false
jestTestsddbRun:
needs:
Expand All @@ -383,7 +383,7 @@ jobs:
fromJson(needs.jestTestsddbConstants.outputs.packages-to-jest-test) }}
runs-on: ${{ matrix.os }}
env:
NODE_OPTIONS: '--max_old_space_size=4096'
NODE_OPTIONS: "--max_old_space_size=4096"
YARN_ENABLE_IMMUTABLE_INSTALLS: false
AWS_REGION: eu-central-1
if: needs.jestTestsddbConstants.outputs.packages-to-jest-test != '[]'
Expand Down Expand Up @@ -480,7 +480,7 @@ jobs:
echo '${{
steps.list-packages-to-jest-test.outputs.packages-to-jest-test }}'
env:
NODE_OPTIONS: '--max_old_space_size=4096'
NODE_OPTIONS: "--max_old_space_size=4096"
YARN_ENABLE_IMMUTABLE_INSTALLS: false
jestTestsddb-esRun:
needs:
Expand All @@ -501,7 +501,7 @@ jobs:
}}
runs-on: ${{ matrix.os }}
env:
NODE_OPTIONS: '--max_old_space_size=4096'
NODE_OPTIONS: "--max_old_space_size=4096"
YARN_ENABLE_IMMUTABLE_INSTALLS: false
AWS_REGION: eu-central-1
AWS_ELASTIC_SEARCH_DOMAIN_NAME: ${{ secrets.AWS_ELASTIC_SEARCH_DOMAIN_NAME }}
Expand Down Expand Up @@ -610,7 +610,7 @@ jobs:
echo '${{
steps.list-packages-to-jest-test.outputs.packages-to-jest-test }}'
env:
NODE_OPTIONS: '--max_old_space_size=4096'
NODE_OPTIONS: "--max_old_space_size=4096"
YARN_ENABLE_IMMUTABLE_INSTALLS: false
jestTestsddb-osRun:
needs:
Expand All @@ -631,7 +631,7 @@ jobs:
}}
runs-on: ${{ matrix.os }}
env:
NODE_OPTIONS: '--max_old_space_size=4096'
NODE_OPTIONS: "--max_old_space_size=4096"
YARN_ENABLE_IMMUTABLE_INSTALLS: false
AWS_REGION: eu-central-1
AWS_ELASTIC_SEARCH_DOMAIN_NAME: ${{ secrets.AWS_OPEN_SEARCH_DOMAIN_NAME }}
Expand Down
128 changes: 92 additions & 36 deletions packages/cli/bin.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,100 @@
#!/usr/bin/env node
"use strict";

const chalk = require("chalk");
const execa = require("execa");
const semver = require("semver");
const currentNodeVersion = process.versions.node;
// Suppress punycode warnings. This is a known issue which we can't fix.
require("./utils/suppressPunycodeWarnings");

// Ensure system requirements are met.
require("@webiny/system-requirements").ensureSystemRequirements();

const yargs = require("yargs");

// Disable help processing until after plugins are imported.
yargs.help(false);

// Loads environment variables from multiple sources.
require("./utils/loadEnvVariables");

const { blue, red, bold, bgYellow } = require("chalk");
const context = require("./context");
const { createCommands } = require("./commands");

yargs
.usage("Usage: $0 <command> [options]")
.demandCommand(1)
.recommendCommands()
.scriptName("webiny")
.epilogue(
`To find more information, docs and tutorials, see ${blue("https://www.webiny.com/docs")}.`
)
.epilogue(`Want to contribute? ${blue("https://github.com/webiny/webiny-js")}.`)
.fail(function (msg, error, yargs) {
if (msg) {
if (msg.includes("Not enough non-option arguments")) {
console.log();
context.error(red("Command was not invoked as expected!"));
context.info(
`Some non-optional arguments are missing. See the usage examples printed below.`
);
console.log();
yargs.showHelp();
return;
}

if (msg.includes("Missing required argument")) {
const args = msg
.split(":")[1]
.split(",")
.map(v => v.trim());

console.log();
context.error(red("Command was not invoked as expected!"));
context.info(
`Missing required argument(s): ${args
.map(arg => red(arg))
.join(", ")}. See the usage examples printed below.`
);
console.log();
yargs.showHelp();
return;
}
console.log();
context.error(red("Command execution was aborted!"));
context.error(msg);
console.log();

(async () => {
if (!semver.satisfies(currentNodeVersion, ">=20")) {
console.error(
chalk.red(
[
`You are running Node.js ${currentNodeVersion}, but Webiny requires version >=20.`,
`Please switch to one of the required versions and try again.`,
`For more information, please visit https://www.webiny.com/docs/get-started/install-webiny#prerequisites.`
].join(" ")
)
);
process.exit(1);
}

try {
const { stdout } = await execa("yarn", ["--version"]);
/**
* TODO In 5.43.0 put >=4 as yarn version.
* This is because of the existing yarn version (before doing the webiny upgrade) is v3.x.x.
* When the upgrade is done (5.42.0), we can safely put to >=4.
*/
const satisfiesYarnVersion = ">=3";
if (!semver.satisfies(stdout, satisfiesYarnVersion)) {
console.error(chalk.red(`"@webiny/cli" requires yarn 4!`));
process.exit(1);
}
} catch (err) {
console.error(chalk.red(`"@webiny/cli" requires yarn 4!`));
console.log(
`Run ${chalk.blue("yarn set version 4.5.3")} to install a compatible version of yarn.`
);

console.log();
// Unfortunately, yargs doesn't provide passed args here, so we had to do it via process.argv.
const debugEnabled = process.argv.includes("--debug");
if (debugEnabled) {
context.debug(error);
} else {
context.error(error.message);
}

const gracefulError = error.cause?.gracefulError;
if (gracefulError instanceof Error) {
console.log();
console.log(bgYellow(bold("💡 How can I resolve this?")));
console.log(gracefulError.message);
}

const plugins = context.plugins.byType("cli-command-error");
for (let i = 0; i < plugins.length; i++) {
const plugin = plugins[i];
plugin.handle({
error,
context
});
}

process.exit(1);
}
});

require("./cli");
(async () => {
await createCommands(yargs, context);
// Enable help and run the CLI.
yargs.help().argv;
})();
96 changes: 0 additions & 96 deletions packages/cli/cli.js

This file was deleted.

9 changes: 2 additions & 7 deletions packages/cli/commands/about/getNpmVersion.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
const execa = require("execa");
const { SystemRequirements } = require("@webiny/system-requirements");

module.exports.getNpmVersion = async () => {
try {
const { stdout } = await execa("npm", ["--version"]);
return stdout;
} catch (err) {
return "";
}
return SystemRequirements.getNpmVersion();
};
Loading

0 comments on commit 2eb1183

Please sign in to comment.