Skip to content

Commit

Permalink
send hydrogen version metadata in deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
benwolfram committed Nov 27, 2024
1 parent 9979415 commit 44e53a6
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 5 deletions.
39 changes: 37 additions & 2 deletions packages/cli/src/commands/hydrogen/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@ import {
getLatestGitCommit,
GitDirectoryNotCleanError,
} from '@shopify/cli-kit/node/git';
import {createRequire} from 'node:module';

import {deploymentLogger, runDeploy} from './deploy.js';
import {deploymentLogger, getHydrogenVersion, runDeploy} from './deploy.js';
import {getOxygenDeploymentData} from '../../lib/get-oxygen-deployment-data.js';
import {execAsync} from '../../lib/process.js';
import {createEnvironmentCliChoiceLabel} from '../../lib/common.js';
import {getSkeletonSourceDir} from '../../lib/build.js';
import {
CompletedDeployment,
createDeploy,
parseToken,
} from '@shopify/oxygen-cli/deploy';
import {ciPlatform} from '@shopify/cli-kit/node/context/local';
import {runBuild} from './build.js';
import {PackageJson} from 'type-fest';

vi.mock('@shopify/oxygen-cli/deploy');
vi.mock('@shopify/cli-kit/node/dot-env');
Expand Down Expand Up @@ -61,7 +64,21 @@ vi.mock('@shopify/cli-kit/node/git', async () => {
};
});

describe('deploy', () => {
async function createHydrogenDependencyPackageJson(version?: string) {
const require = createRequire(import.meta.url);
const packageJson: PackageJson = require(require.resolve(
'@shopify/hydrogen/package.json',
{paths: [getSkeletonSourceDir()]},
));

packageJson.version = version;

return packageJson;
}

describe('deploy', async () => {
await createHydrogenDependencyPackageJson('2000.1.1');

const ADMIN_SESSION: AdminSession = {
token: 'abc123',
storeFqdn: 'my-shop.myshopify.com',
Expand Down Expand Up @@ -119,6 +136,7 @@ describe('deploy', () => {
url: deployParams.metadataUrl,
user: deployParams.metadataUser,
version: deployParams.metadataVersion,
hydrogenVersion: '2000.1.1',
},
skipVerification: true,
rootPath: deployParams.path,
Expand Down Expand Up @@ -163,6 +181,7 @@ describe('deploy', () => {
oxygenDeploymentToken: 'some-encoded-token',
environments: [],
});

vi.mocked(parseToken).mockReturnValue(mockToken);
});

Expand Down Expand Up @@ -943,4 +962,20 @@ describe('deploy', () => {
});
});
});

describe('getHydrogenVersion', () => {
it('returns the version', async () => {
const version = await getHydrogenVersion({appPath: deployParams.path});
expect(version).toBe('2000.1.1');
});

describe('when there are no version is available', () => {
it('returns undefined', async () => {
await createHydrogenDependencyPackageJson(undefined);

const version = await getHydrogenVersion({appPath: deployParams.path});
expect(version).toBeUndefined();
});
});
});
});
26 changes: 23 additions & 3 deletions packages/cli/src/commands/hydrogen/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import {
} from '@shopify/cli-kit/node/output';
import {readAndParseDotEnv} from '@shopify/cli-kit/node/dot-env';
import {AbortError} from '@shopify/cli-kit/node/error';
import {writeFile} from '@shopify/cli-kit/node/fs';
import {readFile, writeFile} from '@shopify/cli-kit/node/fs';
import {
ensureIsClean,
getLatestGitCommit,
GitDirectoryNotCleanError,
} from '@shopify/cli-kit/node/git';
import {relativePath, resolvePath} from '@shopify/cli-kit/node/path';
import {joinPath, relativePath, resolvePath} from '@shopify/cli-kit/node/path';
import {
renderConfirmationPrompt,
renderSelectPrompt,
Expand All @@ -32,6 +32,7 @@ import {
DeploymentVerificationDetailsResponse,
parseToken,
} from '@shopify/oxygen-cli/deploy';
import {createRequire} from 'node:module';

import {
createEnvironmentCliChoiceLabel,
Expand All @@ -51,7 +52,7 @@ import {runClassicCompilerBuild} from '../../lib/classic-compiler/build.js';
import {runBuild} from './build.js';
import {getViteConfig} from '../../lib/vite-config.js';
import {prepareDiffDirectory} from '../../lib/template-diff.js';
import {isClassicProject} from '../../lib/remix-config.js';
import {getProjectPaths, isClassicProject} from '../../lib/remix-config.js';
import {packageManagers} from '../../lib/package-managers.js';
import {setupResourceCleanup} from '../../lib/resource-cleanup.js';

Expand Down Expand Up @@ -466,6 +467,8 @@ export async function runDeploy(
}
}

const metadataHydrogenVersion = await getHydrogenVersion({appPath: root});

const config: DeploymentConfig = {
assetsDir,
bugsnag: true,
Expand All @@ -484,6 +487,9 @@ export async function runDeploy(
...(metadataUrl ? {url: metadataUrl} : {}),
...(metadataUser ? {user: metadataUser} : {}),
...(metadataVersion ? {version: metadataVersion} : {}),
...(metadataHydrogenVersion
? {hydrogenVersion: metadataHydrogenVersion}
: {}),
},
skipVerification: noVerify,
rootPath: root,
Expand Down Expand Up @@ -673,3 +679,17 @@ Continue?`.value,

return deployPromise;
}

/**
* Gets the current @shopify/hydrogen version from the package's package.json
*/
export async function getHydrogenVersion({appPath}: {appPath: string}) {
const {root} = getProjectPaths(appPath);

const require = createRequire(import.meta.url);
const {version} = require(require.resolve('@shopify/hydrogen/package.json', {
paths: [root],
}));

return version;
}

0 comments on commit 44e53a6

Please sign in to comment.