Skip to content

Commit

Permalink
Fix upgrade notice in dev command (#2120)
Browse files Browse the repository at this point in the history
* Failing test

* Fix upgrade notice

* Changesets
  • Loading branch information
frandiox committed May 17, 2024
1 parent ca4cf04 commit 7b838be
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/long-emus-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/cli-hydrogen': patch
---

Fix Hydrogen upgrade notification when running the dev command.
22 changes: 21 additions & 1 deletion packages/cli/src/commands/hydrogen/upgrade.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ import {
type Release,
upgradeNodeModules,
getChangelog,
displayDevUpgradeNotice,
} from './upgrade.js';
import {type PackageJson} from 'type-fest';

vi.mock('../../lib/shell.js');
vi.mock('@shopify/cli-kit/node/session');

vi.mock('../../lib/shell.js', () => ({getCliCommand: vi.fn(() => 'h2')}));

vi.mock('@shopify/cli-kit/node/ui', async () => {
const original = await vi.importActual<
typeof import('@shopify/cli-kit/node/ui')
Expand Down Expand Up @@ -585,6 +587,24 @@ describe('upgrade', async () => {
});
});

describe('displayDevUpgradeNotice', () => {
it('shows up a notice if there are dependencies to upgrade', async () => {
await inTemporaryHydrogenRepo(
async (targetPath) => {
await expect(
displayDevUpgradeNotice({targetPath}),
).resolves.not.toThrow();

expect(outputMock.info()).toMatch(
'new @shopify/hydrogen versions available',
);
expect(outputMock.info()).toMatch('Run `h2 upgrade`');
},
{cleanGitRepo: false, packageJson: OUTDATED_HYDROGEN_PACKAGE_JSON},
);
});
});

describe('upgradeNodeModules', () => {
it('runs the upgrade command task', async () => {
await inTemporaryHydrogenRepo(
Expand Down
13 changes: 7 additions & 6 deletions packages/cli/src/commands/hydrogen/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,17 +349,15 @@ function hasOutdatedDependencies({
});
}

export function isUpgradeableRelease({
function isUpgradeableRelease({
currentDependencies,
currentPinnedVersion,
release,
}: {
currentDependencies?: Dependencies;
currentDependencies: Dependencies;
currentPinnedVersion: string;
release: Release;
}) {
if (!currentDependencies) return false;

const isHydrogenOutdated = semver.gt(release.version, currentPinnedVersion);

if (isHydrogenOutdated) return true;
Expand All @@ -383,7 +381,7 @@ export function getAvailableUpgrades({
}: {
releases: ChangeLog['releases'];
currentVersion: string;
currentDependencies?: Dependencies;
currentDependencies: Dependencies;
}) {
const currentPinnedVersion = getAbsoluteVersion(currentVersion);
let currentMajorVersion = '';
Expand Down Expand Up @@ -1000,7 +998,9 @@ export async function displayDevUpgradeNotice({
}) {
try {
const appPath = targetPath ? path.resolve(targetPath) : process.cwd();
const {currentVersion} = await getHydrogenVersion({appPath});
const {currentVersion, currentDependencies} = await getHydrogenVersion({
appPath,
});

const isPrerelease = semver.prerelease(currentVersion);

Expand All @@ -1014,6 +1014,7 @@ export async function displayDevUpgradeNotice({
const {availableUpgrades, uniqueAvailableUpgrades} = getAvailableUpgrades({
releases: changelog.releases,
currentVersion,
currentDependencies,
});

if (availableUpgrades.length === 0 || !availableUpgrades[0]?.version) {
Expand Down

0 comments on commit 7b838be

Please sign in to comment.