Skip to content

Commit

Permalink
fix(create-webiny-project): update check for yarn version (#3796)
Browse files Browse the repository at this point in the history
  • Loading branch information
brunozoric committed Jan 6, 2024
1 parent e16899c commit 8e21370
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 4 deletions.
47 changes: 43 additions & 4 deletions packages/create-webiny-project/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,69 @@
const semver = require("semver");
const chalk = require("chalk");
const getYarnVersion = require("./utils/getYarnVersion");
const getNpmVersion = require("./utils/getNpmVersion");
const verifyConfig = require("./utils/verifyConfig");

(async () => {
const minNodeVersion = "16";
const minNpmVersion = "10";
const minYarnVersion = "1.22.21";
/**
* Node
*/
const nodeVersion = process.versions.node;
if (!semver.satisfies(nodeVersion, ">=14")) {
if (!semver.satisfies(nodeVersion, `>=${minNodeVersion}`)) {
console.error(
chalk.red(
[
`You are running Node.js ${nodeVersion}, but Webiny requires version 14 or higher.`,
`You are running Node.js ${nodeVersion}, but Webiny requires version ${minNodeVersion} or higher.`,
`Please switch to one of the required versions and try again.`,
"For more information, please visit https://docs.webiny.com/docs/tutorials/install-webiny#prerequisites."
].join(" ")
)
);
process.exit(1);
}
/**
* npm
*/
try {
const npmVersion = await getNpmVersion();
if (!semver.satisfies(npmVersion, `>=${minNpmVersion}`)) {
console.error(
chalk.red(
[
`Webiny requires npm@^${minNpmVersion} or higher.`,
`Please run ${chalk.green(
"npm install npm@latest -g"
)}, to get the latest version.`
].join("\n")
)
);
process.exit(1);
}
} catch (err) {
console.error(chalk.red(`Webiny depends on "npm".`));

console.log(
`Please visit https://docs.npmjs.com/try-the-latest-stable-version-of-npm to install ${chalk.green(
"npm"
)}.`
);

process.exit(1);
}

/**
* yarn
*/
try {
const yarnVersion = await getYarnVersion();
if (!semver.satisfies(yarnVersion, ">=1.22.0")) {
if (!semver.satisfies(yarnVersion, `>=${minYarnVersion}`)) {
console.error(
chalk.red(
[
`Webiny requires yarn@^1.22.0 or higher.`,
`Webiny requires yarn@^${minYarnVersion} or higher.`,
`Please visit https://yarnpkg.com/ to install ${chalk.green("yarn")}.`
].join("\n")
)
Expand Down
14 changes: 14 additions & 0 deletions packages/create-webiny-project/utils/createProject.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,18 @@ module.exports = async function createProject({
const node = process.versions.node;
const os = process.platform;

let npm = NOT_APPLICABLE;
try {
const subprocess = await execa("npm", ["--version"], { cwd: projectRoot });
npm = subprocess.stdout;
} catch {}

let npx = NOT_APPLICABLE;
try {
const subprocess = await execa("npx", ["--version"], { cwd: projectRoot });
npx = subprocess.stdout;
} catch {}

let yarn = NOT_APPLICABLE;
try {
const subprocess = await execa("yarn", ["--version"], { cwd: projectRoot });
Expand Down Expand Up @@ -312,6 +324,8 @@ module.exports = async function createProject({
`Operating System: ${os}`,
`Node: ${node}`,
`Yarn: ${yarn}`,
`Npm: ${npm}`,
`Npx: ${npx}`,
`create-webiny-project: ${cwp}`,
`Template: ${cwpTemplate}`,
`Template Options: ${templateOptionsJson}`,
Expand Down
10 changes: 10 additions & 0 deletions packages/create-webiny-project/utils/getNpmVersion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const execa = require("execa");

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

0 comments on commit 8e21370

Please sign in to comment.