Skip to content

Commit

Permalink
Improve outdated CLI notice
Browse files Browse the repository at this point in the history
  • Loading branch information
juanpprieto committed Mar 6, 2024
1 parent c196180 commit 2848eb7
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions packages/cli/src/commands/hydrogen/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,29 +96,32 @@ export default class Init extends Command {
}
}

async function cliUpgradeNotice() {
// Resolving the CLI package from a local directory might fail because
// this code could be run from a global dependency (e.g. on `npm create`).
// Therefore, pass the known path to the package.json directly from here:
const packageJson = fileURLToPath(new URL('../../../package.json', import.meta.url))

const showCliUpgrade = await checkHydrogenVersion(packageJson, 'cli');

if (!showCliUpgrade) return;

const packageManager = packageManagerFromUserAgent();

const cliUpgradeMessage = packageManager === 'unknown'
? ''
: `Please upgrade the CLI with \`${packageManager} upgrade @shopify/cli-hydrogen\` before creating a new project with \`${packageManager} create @shopify/hydrogen@latest\`.\nTo `
showCliUpgrade(cliUpgradeMessage);
}

export async function runInit(
options: InitOptions = parseProcessFlags(process.argv, FLAG_MAP),
) {
supressNodeExperimentalWarnings();

options.git ??= true;

const showUpgrade = await checkHydrogenVersion(
// Resolving the CLI package from a local directory might fail because
// this code could be run from a global dependency (e.g. on `npm create`).
// Therefore, pass the known path to the package.json directly from here:
fileURLToPath(new URL('../../../package.json', import.meta.url)),
'cli',
);

if (showUpgrade) {
const packageManager = packageManagerFromUserAgent();
showUpgrade(
packageManager === 'unknown'
? ''
: `Please use the latest version with \`${packageManager} create @shopify/hydrogen@latest\``,
);
}
await cliUpgradeNotice()

const controller = new AbortController();

Expand Down

0 comments on commit 2848eb7

Please sign in to comment.