diff --git a/.changeset/all-suns-read.md b/.changeset/all-suns-read.md new file mode 100644 index 00000000000..fa87179a5ab --- /dev/null +++ b/.changeset/all-suns-read.md @@ -0,0 +1,5 @@ +--- +'@shopify/cli-kit': patch +--- + +Remove `custom-oclif-loader.ts` and use oclif's `Config` directly. The development-only shim for loading a local `@shopify/cli-hydrogen` plugin is no longer needed as the Hydrogen repo now handles this via its own patch scripts. diff --git a/packages/cli-kit/package.json b/packages/cli-kit/package.json index e6f7aba5d5d..ae9d4b3e910 100644 --- a/packages/cli-kit/package.json +++ b/packages/cli-kit/package.json @@ -82,7 +82,6 @@ "./error-handler.js", "../../public/node/context/local.js", "./context/local.js", - "./custom-oclif-loader.js", "@oclif/core", "./path.js", "./system.js", diff --git a/packages/cli-kit/src/public/node/cli-launcher.ts b/packages/cli-kit/src/public/node/cli-launcher.ts index 76d74928e28..dd6e82b5c1c 100644 --- a/packages/cli-kit/src/public/node/cli-launcher.ts +++ b/packages/cli-kit/src/public/node/cli-launcher.ts @@ -6,7 +6,7 @@ interface Options { } /** - * Launches the CLI through our custom OCLIF loader. + * Launches the CLI. * * @param options - Options. * @returns A promise that resolves when the CLI has been launched. @@ -14,23 +14,21 @@ interface Options { export async function launchCLI(options: Options): Promise { const {errorHandler} = await import('./error-handler.js') const {isDevelopment} = await import('./context/local.js') - const oclif = await import('@oclif/core') - const {ShopifyConfig} = await import('./custom-oclif-loader.js') + const {Config, run, flush, Errors, settings} = await import('@oclif/core') if (isDevelopment()) { - oclif.default.settings.debug = true + settings.debug = true } try { - // Use a custom OCLIF config to customize the behavior of the CLI - const config = new ShopifyConfig({root: fileURLToPath(options.moduleURL)}) + const config = new Config({root: fileURLToPath(options.moduleURL)}) await config.load() - await oclif.default.run(options.argv, config) - await oclif.default.flush() + await run(options.argv, config) + await flush() // eslint-disable-next-line no-catch-all/no-catch-all } catch (error) { await errorHandler(error as Error) - return oclif.default.Errors.handle(error as Error) + return Errors.handle(error as Error) } } diff --git a/packages/cli-kit/src/public/node/custom-oclif-loader.ts b/packages/cli-kit/src/public/node/custom-oclif-loader.ts deleted file mode 100644 index 527f837eabb..00000000000 --- a/packages/cli-kit/src/public/node/custom-oclif-loader.ts +++ /dev/null @@ -1,93 +0,0 @@ -import {fileExistsSync} from './fs.js' -import {cwd, joinPath, sniffForPath} from './path.js' -import {isDevelopment} from './context/local.js' -import {execaSync} from 'execa' -import {Command, Config} from '@oclif/core' -import {Options} from '@oclif/core/interfaces' - -export class ShopifyConfig extends Config { - constructor(options: Options) { - if (isDevelopment()) { - const currentPath = cwd() - - let path = sniffForPath() ?? currentPath - // Hydrogen CI uses `hydrogen/hydrogen` path, while local dev uses `shopify/hydrogen`. - const currentPathMightBeHydrogenMonorepo = /(shopify|hydrogen)\/hydrogen/i.test(currentPath) - const ignoreHydrogenMonorepo = process.env.IGNORE_HYDROGEN_MONOREPO - if (currentPathMightBeHydrogenMonorepo && !ignoreHydrogenMonorepo) { - path = execaSync('npm', ['prefix']).stdout.trim() - } - if (fileExistsSync(joinPath(path, 'package.json'))) { - // Hydrogen is bundled, but we still want to support loading it as an external plugin for two reasons: - // 1. To allow users to use an older version of Hydrogen. (to not force upgrades) - // 2. To allow the Hydrogen team to load a local version for testing. - options.pluginAdditions = { - core: ['@shopify/cli-hydrogen'], - path, - } - } - } - - super(options) - - if (isDevelopment()) { - // @ts-expect-error: This is a private method that we are overriding. OCLIF doesn't provide a way to extend it. - - this.determinePriority = this.customPriority - } - } - - customPriority(commands: Command.Loadable[]): Command.Loadable | undefined { - const oclifPlugins = this.pjson.oclif.plugins ?? [] - const commandPlugins = commands.sort((aCommand, bCommand) => { - // eslint-disable-next-line no-restricted-syntax - const pluginAliasA = aCommand.pluginAlias ?? 'A-Cannot-Find-This' - // eslint-disable-next-line no-restricted-syntax - const pluginAliasB = bCommand.pluginAlias ?? 'B-Cannot-Find-This' - const aIndex = oclifPlugins.indexOf(pluginAliasA) - const bIndex = oclifPlugins.indexOf(pluginAliasB) - - // If there is an external cli-hydrogen plugin, its commands should take priority over bundled ('core') commands - if (aCommand.pluginType === 'core' && bCommand.pluginAlias === '@shopify/cli-hydrogen') { - // If b is hydrogen and a is core sort b first - return 1 - } - - if (aCommand.pluginAlias === '@shopify/cli-hydrogen' && bCommand.pluginType === 'core') { - // If a is hydrogen and b is core sort a first - return -1 - } - - // All other cases are the default implementation from the private `determinePriority` method - // When both plugin types are 'core' plugins sort based on index - if (aCommand.pluginType === 'core' && bCommand.pluginType === 'core') { - // If b appears first in the pjson.plugins sort it first - return aIndex - bIndex - } - - // if b is a core plugin and a is not sort b first - if (bCommand.pluginType === 'core' && aCommand.pluginType !== 'core') { - return 1 - } - - // if a is a core plugin and b is not sort a first - if (aCommand.pluginType === 'core' && bCommand.pluginType !== 'core') { - return -1 - } - - // if a is a jit plugin and b is not sort b first - if (aCommand.pluginType === 'jit' && bCommand.pluginType !== 'jit') { - return 1 - } - - // if b is a jit plugin and a is not sort a first - if (bCommand.pluginType === 'jit' && aCommand.pluginType !== 'jit') { - return -1 - } - - // neither plugin is core, so do not change the order - return 0 - }) - return commandPlugins[0] - } -}