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

Webiny CLI - Improving System Requirements Checks #4448

Merged
merged 27 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a782ed0
fix(plugins): improve types of plugins returned from the container
Pavel910 Dec 3, 2024
10cd1e5
fix(app-page-builder): create plugin loader components
Pavel910 Dec 3, 2024
445bb48
fix(app-page-builder): export loader components
Pavel910 Dec 3, 2024
bd1354d
fix: introduce `useLoader` hook (#4424)
adrians5j Dec 5, 2024
76ad3ee
fix: allow specifying dependency with exact version
adrians5j Dec 5, 2024
2c5b72d
Merge branch 'dev' of github.com:webiny/webiny-js into dev
adrians5j Dec 5, 2024
7e37ccb
fix: add "extension" suffix to the label
adrians5j Dec 5, 2024
6e211bb
fix: move `websiteLoaderCache` instantiation into `PageBuilderProvide…
adrians5j Dec 9, 2024
7b2e8e4
fix(form): commit field value to form even if the field doesn't exist
Pavel910 Dec 8, 2024
91cf386
fix: compress cached loader data (#4435)
adrians5j Dec 12, 2024
bb1a258
fix:replace `render` prop with `renderer` (#4444)
adrians5j Dec 13, 2024
2e18a18
fix: improve import identifier uniqueness (#4437)
adrians5j Dec 13, 2024
c5b82ea
Merge branch 'dev' of github.com:webiny/webiny-js into dev
adrians5j Dec 13, 2024
501de0a
wip
adrians5j Dec 13, 2024
709a04f
wip
adrians5j Dec 16, 2024
16d786c
wip
adrians5j Dec 16, 2024
7436874
wip
adrians5j Dec 16, 2024
e2bc9a6
wip
adrians5j Dec 16, 2024
4a578a9
wip
adrians5j Dec 16, 2024
06f462f
wip
adrians5j Dec 16, 2024
3e5d644
wip
adrians5j Dec 16, 2024
fc49057
wip
adrians5j Dec 16, 2024
8c4dcf0
Merge remote-tracking branch 'refs/remotes/origin/next' into adrian/c…
adrians5j Jan 8, 2025
8f09f12
merge: pull changes from `next`
adrians5j Jan 8, 2025
2a7d61c
merge: pull changes from `next`
adrians5j Jan 8, 2025
95ea7fe
wip
adrians5j Jan 8, 2025
8f68903
wip
adrians5j Jan 8, 2025
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
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
Loading