-
Notifications
You must be signed in to change notification settings - Fork 280
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. |
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
}; | ||
|
||
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;
}
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.
Importing Hydrogen in the CLI might be problematic. Perhaps you can just find the package.json in a safe way and import it:
import {createRequire} from 'node:module';
const require = createRequire(import.meta.url);
const {version} = require(
require.resolve(
'@shopify/hydrogen/package.json',
{paths: [root]}
)
);
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'll give that a whirl, thanks @wizardlyhel! I appreciate the guidance!
@frandiox I am already trying to do that in the PR, but are you saying this solution would solve for Yarn>2 as well?
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 had errors/difficulty importing hydrogen with @wizardlyhel's solution, so DMd a bit and shifted to @frandiox's suggestion.
I tested Yarn@4 and it seemed good with that solution. Let me know if there are any concerns about different managers @blittle or if you have a similar experience of success.
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 am already trying to do that in the PR, but are you saying this solution would solve for Yarn>2 as well?
The code I posted relies on Node's resolution logic, which should be safer than finding the file manually. I'd expect this to work across package managers, just like any import
or require
in Node work with all of them because it uses the same algorithm.
Also, no need to use async
/ await
with this code 👍
f51a372
to
155563a
Compare
155563a
to
44e53a6
Compare
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.
Nice!
/snapit |
🫰✨ Thanks @benwolfram! Your snapshots have been published to npm. Test the snapshots by updating your "@shopify/cli-hydrogen": "0.0.0-snapshot-20241203192325",
"@shopify/hydrogen": "0.0.0-snapshot-20241203192325"
|
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