@shopify/cli-hydrogen 11.1.0 → 11.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/hydrogen/upgrade.js +76 -30
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
|
@@ -6,7 +6,8 @@ import { ensureInsideGitDirectory, isClean } from '@shopify/cli-kit/node/git';
|
|
|
6
6
|
import Command from '@shopify/cli-kit/node/base-command';
|
|
7
7
|
import { renderSuccess, renderInfo, renderConfirmationPrompt, renderTasks, renderSelectPrompt, renderWarning } from '@shopify/cli-kit/node/ui';
|
|
8
8
|
import { readFile, isDirectory, mkdir, fileExists, touchFile, removeFile, writeFile } from '@shopify/cli-kit/node/fs';
|
|
9
|
-
import {
|
|
9
|
+
import { getPackageManager, getDependencies, installNodeModules } from '@shopify/cli-kit/node/node-package-manager';
|
|
10
|
+
import { exec } from '@shopify/cli-kit/node/system';
|
|
10
11
|
import { AbortError } from '@shopify/cli-kit/node/error';
|
|
11
12
|
import { resolvePath, joinPath, dirname } from '@shopify/cli-kit/node/path';
|
|
12
13
|
import { getCliCommand } from '../../lib/shell.js';
|
|
@@ -155,11 +156,25 @@ async function getHydrogenVersion({ appPath }) {
|
|
|
155
156
|
}
|
|
156
157
|
async function getChangelog() {
|
|
157
158
|
if (CACHED_CHANGELOG) return CACHED_CHANGELOG;
|
|
158
|
-
if (isHydrogenMonorepo && hydrogenPackagesPath && process.env.FORCE_CHANGELOG_SOURCE !== "remote") {
|
|
159
|
+
if (process.env.FORCE_CHANGELOG_SOURCE === "local" || isHydrogenMonorepo && hydrogenPackagesPath && process.env.FORCE_CHANGELOG_SOURCE !== "remote") {
|
|
159
160
|
const require2 = createRequire(import.meta.url);
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
161
|
+
const localChangelogPath = isHydrogenMonorepo && hydrogenPackagesPath ? joinPath(dirname(hydrogenPackagesPath), "docs", "changelog.json") : joinPath(process.cwd(), "docs", "changelog.json");
|
|
162
|
+
try {
|
|
163
|
+
const changelog = require2(localChangelogPath);
|
|
164
|
+
CACHED_CHANGELOG = changelog;
|
|
165
|
+
return changelog;
|
|
166
|
+
} catch (error) {
|
|
167
|
+
console.warn(
|
|
168
|
+
`Failed to load local changelog from ${localChangelogPath}:`,
|
|
169
|
+
error.message
|
|
170
|
+
);
|
|
171
|
+
if (process.env.FORCE_CHANGELOG_SOURCE === "local") {
|
|
172
|
+
throw new AbortError(
|
|
173
|
+
"Failed to load local changelog",
|
|
174
|
+
`Could not read changelog from ${localChangelogPath}`
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
163
178
|
}
|
|
164
179
|
try {
|
|
165
180
|
const response = await fetch("https://hydrogen.shopify.dev/changelog.json");
|
|
@@ -394,8 +409,8 @@ function buildUpgradeCommandArgs({
|
|
|
394
409
|
const selectedReactRouter = Object.entries(selectedRelease.dependencies).find(
|
|
395
410
|
isReactRouterDependency
|
|
396
411
|
);
|
|
397
|
-
if (
|
|
398
|
-
const shouldUpgradeReactRouter = semver.lt(
|
|
412
|
+
if (selectedReactRouter) {
|
|
413
|
+
const shouldUpgradeReactRouter = !currentReactRouter || semver.lt(
|
|
399
414
|
getAbsoluteVersion(currentReactRouter[1]),
|
|
400
415
|
getAbsoluteVersion(selectedReactRouter[1])
|
|
401
416
|
);
|
|
@@ -415,24 +430,52 @@ async function upgradeNodeModules({
|
|
|
415
430
|
selectedRelease,
|
|
416
431
|
currentDependencies
|
|
417
432
|
}) {
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
}
|
|
433
|
+
const tasks = [];
|
|
434
|
+
const depsToRemove = [
|
|
435
|
+
...selectedRelease.removeDependencies || [],
|
|
436
|
+
...selectedRelease.removeDevDependencies || []
|
|
437
|
+
].filter((dep) => dep in currentDependencies);
|
|
438
|
+
if (depsToRemove.length > 0) {
|
|
439
|
+
tasks.push({
|
|
440
|
+
title: `Removing deprecated dependencies`,
|
|
441
|
+
task: async () => {
|
|
442
|
+
await uninstallNodeModules({
|
|
443
|
+
directory: appPath,
|
|
444
|
+
packageManager: await getPackageManager(appPath),
|
|
445
|
+
args: depsToRemove
|
|
446
|
+
});
|
|
432
447
|
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
const upgradeArgs = buildUpgradeCommandArgs({
|
|
451
|
+
selectedRelease,
|
|
452
|
+
currentDependencies
|
|
453
|
+
});
|
|
454
|
+
if (upgradeArgs.length > 0) {
|
|
455
|
+
tasks.push({
|
|
456
|
+
title: `Upgrading dependencies`,
|
|
457
|
+
task: async () => {
|
|
458
|
+
await installNodeModules({
|
|
459
|
+
directory: appPath,
|
|
460
|
+
packageManager: await getPackageManager(appPath),
|
|
461
|
+
args: upgradeArgs
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
if (tasks.length > 0) {
|
|
467
|
+
await renderTasks(tasks, {});
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
async function uninstallNodeModules({
|
|
471
|
+
directory,
|
|
472
|
+
packageManager,
|
|
473
|
+
args
|
|
474
|
+
}) {
|
|
475
|
+
if (args.length === 0) return;
|
|
476
|
+
const command = packageManager === "npm" ? "uninstall" : packageManager === "yarn" ? "remove" : packageManager === "pnpm" ? "remove" : packageManager === "bun" ? "remove" : "uninstall";
|
|
477
|
+
const actualPackageManager = packageManager === "unknown" ? "npm" : packageManager;
|
|
478
|
+
await exec(actualPackageManager, [command, ...args], { cwd: directory });
|
|
436
479
|
}
|
|
437
480
|
function appendRemixDependencies({
|
|
438
481
|
currentDependencies,
|
|
@@ -453,12 +496,15 @@ function appendReactRouterDependencies({
|
|
|
453
496
|
selectedReactRouter
|
|
454
497
|
}) {
|
|
455
498
|
const command = [];
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
499
|
+
const targetVersion = getAbsoluteVersion(selectedReactRouter[1]);
|
|
500
|
+
const reactRouterPackages = [
|
|
501
|
+
"react-router",
|
|
502
|
+
"react-router-dom",
|
|
503
|
+
"@react-router/dev",
|
|
504
|
+
"@react-router/fs-routes"
|
|
505
|
+
];
|
|
506
|
+
for (const packageName of reactRouterPackages) {
|
|
507
|
+
command.push(`${packageName}@${targetVersion}`);
|
|
462
508
|
}
|
|
463
509
|
return command;
|
|
464
510
|
}
|
package/oclif.manifest.json
CHANGED