Skip to content

Fix custom-oclif-loader.ts hydrogen loader strategy for hydrogen-cli local development#6827

Open
andguy95 wants to merge 9 commits intomainfrom
an-fix-hydrogen-cli-custom-loader
Open

Fix custom-oclif-loader.ts hydrogen loader strategy for hydrogen-cli local development#6827
andguy95 wants to merge 9 commits intomainfrom
an-fix-hydrogen-cli-custom-loader

Conversation

@andguy95
Copy link

@andguy95 andguy95 commented Feb 5, 2026

WHY are these changes introduced?

During local development of the @shopify/cli in the Shopify/hydrogen you are no longer able to see your changes when running the npx shopify hydrogen commands because the custom-ocliff-loader.ts no longer loads the local Shopify/hydrgen cli in the Shopify/hydrogen monorepo.

These versions below are good:

  • 3.80.6 ✅
  • 3.80.7 ✅
  • 3.81.0 ✅
  • 3.81.1 ✅
  • 3.81.2 ✅
  • 3.82.0 ✅
  • 3.82.1 ✅
  • 3.83.0 ❌ - Looks like the hydrogen mono repo awareness stopped working here (looks like major bump of OCLIF)

In OCLIF v4, determinePriority is a standalone utility function (not an instance method), so we can't override it to customize command priority in custom-ocliff-loader.ts.

WHAT is this pull request doing?

Change the custom-ocliff-loader.ts to manually replace bundled hydrogen commands with external ones after loading completes if in dev mode.

How to test your changes?

  1. Go to dev.ts in hydrogen/packages/cli/src/commands/hydrogen/dev.ts
  2. Make arbitrary update to the run()
  3. In the cli project run npm run build
  4. In the template/skeleton project run npx shopify hydrogen dev
    • To test locally i created an alias shopify-dev pointing to a locally built version of the Shopiy/cli
# Create the following file in ~/bin/shopify:

#!/usr/bin/env node

process.env.SHOPIFY_RUBY_BINDIR = "/opt/rubies/3.1.2/bin"
process.env.SHOPIFY_HOMEBREW_FORMULA = "shopify-cli"

import("/Users/<your-user>/src/github.com/Shopify/cli/packages/cli/bin/run.js")

alias shopify-dev='/Users/$USER/bin/shopify'

Measuring impact

How do we know this change was effective? Please choose one:

  • n/a - this doesn't need measurement, e.g. a linting rule or a bug-fix

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes

@andguy95 andguy95 requested a review from a team as a code owner February 5, 2026 20:59
@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 5, 2026

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements 78.92% 14522/18402
🟡 Branches 73.45% 7229/9842
🟡 Functions 79.05% 3690/4668
🟡 Lines 79.26% 13727/17319

Test suite run success

3792 tests passing in 1453 suites.

Report generated by 🧪jest coverage report action from 317cf86

@EvilGenius13
Copy link
Contributor

Changes make sense, thank you for the pairing @andguy95. We'll want to make sure @Shopify/app-inner-loop takes a peek as they have historically made the changes to the file.

@fredericoo fredericoo changed the title Fix custom-ocliff-loader.ts hydrogen loader strategy for hydrogen-cli local development Fix custom-oclif\-loader.ts hydrogen loader strategy for hydrogen-cli local development Feb 23, 2026
@fredericoo fredericoo changed the title Fix custom-oclif\-loader.ts hydrogen loader strategy for hydrogen-cli local development Fix custom-oclif-loader.ts hydrogen loader strategy for hydrogen-cli local development Feb 23, 2026
Copy link
Contributor

@kdaviduik kdaviduik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a changeset but other than that LGTM :)

note about this, it seems to be a false alarm as apparently:

  • customPriority had zero callers anywhere in the codebase
  • customPriority was already non-functional since oclif v3.83.0
  • The sole consumer (cli-launcher.ts) already calls config.load() — no caller changes needed

@andguy95 andguy95 requested a review from a team as a code owner February 24, 2026 17:11
@binks-code-reviewer
Copy link

🤖 Code Review · #projects-dev-ai for questions
React with 👍/👎 or reply — all feedback helps improve the agent.

Complete - No issues

📋 History

✅ No issues

@andguy95 andguy95 requested a review from a team as a code owner February 24, 2026 17:11
@binks-code-reviewer
Copy link

🤖 Code Review · #projects-dev-ai for questions
React with 👍/👎 or reply — all feedback helps improve the agent.

Complete - No issues

📋 History

✅ No issues

'@shopify/cli-kit': patch
---

Fix hydrogen local dev plugin loader to correctly replace bundled hydrogen commands with external plugin commands by switching to a post-load strategy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blocking: @shopify/cli-kit exports custom-oclif-loader.js as a public entry point. The type diff shows customPriority was removed from the public declaration and load() was added. While customPriority was effectively dead code in oclif v4 (the framework no longer called it), it was part of the public type declaration.

The changeset is marked as patch, which I think is appropriate if there are no external consumers, but I think the changeset body should also mention the customPriority removal for transparency, even if it's dead code - consumers upgrading @shopify/cli-kit should be aware.

}
// Force OCLIF to ignore manifests so commands are loaded dynamically
// to be replaced later
options.ignoreManifest = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is dangerous change, ignoring the manifest will make the CLI slower at startup on every command, because it needs to discover every command again on each run. Please do a comparison to check how speed is affected with and without this 🙏.

When is this line code executed? will it affect most users or just internal hydrogen development?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@isaacroldan Thank you, this is a good callout. I will test. This ideally should be executed in development mode but only when in the Hydrogen Monorepo.

In this instance we could probably move the hydrogen monorepo check where the isDevelopment check is to ensure this ignoreManifest only runs in the expected context.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @isaacroldan. Here's what I found:

Who is affected?

ignoreManifest only fires inside isDevelopment(), which requires SHOPIFY_CLI_ENV=development. The majority of public facing end users shouldn't be affected. The only people who hit this path are CLI developers
running from source with the SHOPIFY_CLI_ENV set.

The gate fix

Even so, the original code was broader than needed, as it would set ignoreManifest = true for any dev running from source in any directory with a package.json and SHOPIFY_CLI_ENV=development.

I've tightened it so that ignoreManifest is now gated behind useHydrogenMonorepo (the same
/(shopify|hydrogen)\/hydrogen/i path check already used for the npm prefix call). It only fires when you're actually inside the Hydrogen monorepo.

Tests

Either way with and without the gate, there wasn't any noticible perf hit running outside or inside the Hydrogen Monorepo. I used hyperfine to run these tests:

image

Copy link
Contributor

Is bringing hydrogen-cli back to this repo a possible alternative to this change? We are doing hacks to support a weird repo structure :/

Copy link
Contributor

/snapit

@github-actions
Copy link
Contributor

🫰✨ Thanks @isaacroldan! Your snapshot has been published to npm.

Test the snapshot by installing your package globally:

npm i -g --@shopify:registry=https://registry.npmjs.org @shopify/cli@0.0.0-snapshot-20260227125139

Caution

After installing, validate the version by running shopify version in your terminal.
If the versions don't match, you might have multiple global instances installed.
Use which shopify to find out which one you are running and uninstall it.

@andguy95
Copy link
Author

andguy95 commented Mar 3, 2026

Is bringing hydrogen-cli back to this repo a possible alternative to this change? We are doing hacks to support a weird repo structure :/

@isaacroldan, there have been some discussions on how we can better manage this strange repo dependencies. We are going to explore patch packages as well as seeing if we can possible change the dependencies of the cli-hydrogen to avoid this hack if possible 🤞

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

Differences in type declarations

We detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:

  • Some seemingly private modules might be re-exported through public modules.
  • If the branch is behind main you might see odd diffs, rebase main into this branch.

New type declarations

We found no new type declarations in this PR

Existing type declarations

packages/cli-kit/dist/public/node/custom-oclif-loader.d.ts
@@ -1,6 +1,6 @@
-import { Command, Config } from '@oclif/core';
+import { Config } from '@oclif/core';
 import { Options } from '@oclif/core/interfaces';
 export declare class ShopifyConfig extends Config {
     constructor(options: Options);
-    customPriority(commands: Command.Loadable[]): Command.Loadable | undefined;
+    load(): Promise<void>;
 }
\ No newline at end of file

@andguy95
Copy link
Author

andguy95 commented Mar 4, 2026

/snapit

@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2026

🫰✨ Thanks @andguy95! Your snapshot has been published to npm.

Test the snapshot by installing your package globally:

npm i -g --@shopify:registry=https://registry.npmjs.org @shopify/cli@0.0.0-snapshot-20260304190535

Caution

After installing, validate the version by running shopify version in your terminal.
If the versions don't match, you might have multiple global instances installed.
Use which shopify to find out which one you are running and uninstall it.

Copy link
Contributor

@itsjustriley itsjustriley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, all comments seem to be addressed. I know we're looking at better solutions for strange repo dependencies in the future, but I think this is an appropriate solution for now given that this is blocking us.

@andguy95
Copy link
Author

andguy95 commented Mar 5, 2026

@isaacroldan I put up a draft PR in the hydrogen monorepo (Shopify/hydrogen#3531) for a strategy to offload the logic for local hydrogen monorepo development.

This custom oclif loader I believe would become simplified to still maintain that logic for hydrogen backwards compatibility as noted in the comment. (But honestly I would love your opinion to see if we could kill this off all together)

@isaacroldan
Copy link
Contributor

Love it, I think it makes the most sense for you to own this and be part of the hydrogen repo itself.

About the backwards compatibility, I think the global CLI has been out for 2 years or more, IMHO it's time to remove that part too and basically stop having a custom oclif loader :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants