-
Notifications
You must be signed in to change notification settings - Fork 277
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
Attach Hydrogen Version Metadata to Deployment #2645
base: main
Are you sure you want to change the base?
Conversation
Oxygen deployed a preview of your
Learn more about Hydrogen's GitHub integration. |
}, | ||
); | ||
}); | ||
|
||
it('exists when run over a prerelease "next" version', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test still made sense to leave in this file.
packages/cli/src/lib/get-version.ts
Outdated
|
||
const currentDependencies = Object.fromEntries( | ||
Object.entries(currentDependenciesWithEmptyValues).filter(([_, value]) => value) | ||
) as Record<string, string>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to add this type safety to ensure Record<string, string>
. currentDependenciesWithEmptyValues
can have undefined values, and upgrade.ts
was having a hard time after.
a8afefc
to
1aba45e
Compare
We detected some changes in |
1aba45e
to
385d285
Compare
Moving back to draft to fix a couple things:
|
385d285
to
756f8df
Compare
@@ -631,6 +724,33 @@ describe('deploy', () => { | |||
}); | |||
|
|||
it('writes a file with JSON content in CI environments', async () => { | |||
const ciDeployParams = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reworked this test to not use writeFile
, as I can't mock it since it's needed inside the test now.
}; | ||
|
||
await runDeploy(ciDeployParams); | ||
await removeFile('h2_deploy_log.json'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't figure out why, but this had a file created already when running, I am not sure if temporary folder stuff is bleeding over? But this will make the test safe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, the actual deploy
command is creating the file for real in the test since I am not mocking writeFile
anymore 🤔. This has been a pain 😞.
Very open to input here 😅, is there a way we have to create a temporary directory that will cleanup the files after?
756f8df
to
c5aa392
Compare
c5aa392
to
1940ddb
Compare
/snapit |
🫰✨ Thanks @benwolfram! Your snapshots have been published to npm. Test the snapshots by updating your "@shopify/cli-hydrogen": "0.0.0-snapshot-20241118174207",
"@shopify/hydrogen": "0.0.0-snapshot-20241118174207"
|
const nodeModulesHydrogenPath = joinPath( | ||
root, | ||
'node_modules', | ||
'@shopify', | ||
'hydrogen', | ||
'package.json', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do a more in depth review, but I'm not sure this will work in some package managers like yarn >2 and pnpm. Could you try testing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it looks like the node_modules look a lot different in yarn@latest. pnpm works, and I think my approach is here is trying to do the best we can and fall back to different options. But open to more ideas.
For example below , if they have ^
or >
in package.json for @shopify/hydrogen it can be slightly less accurate too, but we're trying to get the best data we can basically.
We can also rely on parsing the working bundle and crawling it as a fallback too if we don't like any of these. This is being used to backfill data too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@benwolfram I think we can use importLocal
that's being used within the Hydrogen CLI repo to get the Hydrogen lib version accurate to the node package itself.
- Export the
LIB_VERSION
in hydrogen package - This lib version will be updated on every release including if someone is using a next tag (which won't have a proper version tag and we can ignore showing banner in admin) - Then in CLI, we can local import hydrogen to get the lib version like this
import {importLocal} from '../../lib/import-utils.js';
export async function getHydrogenVersion({appPath}: {appPath: string}) {
const {root} = getProjectPaths(appPath);
type HydrogenType = typeof import('@shopify/hydrogen');
const {LIB_VERSION} = await importLocal<HydrogenType>(
'@shopify/hydrogen',
root,
).catch(() => {
return '1.0.0';
});
return LIB_VERSION;
}
WHY are these changes introduced?
We are looking to attach metadata to each deployment containing the Hydrogen version number. This would allow us to show this data in the Admin, and also encourage things like upgrades to merchants in order to gain new and exciting features released in Hydrogen if they are behind on versions.
WHAT is this pull request doing?
Moving
getHydrogenVersion
to a shared location and out of update.tsConsuming that command in
deploy.ts
and attaching the metadataNeed to ship to Oxygen-CLI first
HOW to test your changes?
I logged out the version number in the deploy command to see before the metadata was sent.
Post-merge steps
Checklist