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

Improve outdated CLI notice #1821

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
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
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
Loading