Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion packages/cli/src/hooks/app-init.ts
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
export {AppInitHook as default} from '@shopify/app'
import {Hook} from '@oclif/core'
import {randomUUID} from 'crypto'

/**
* Inlined version of the `\@shopify/app` init hook.
* The original hook imports `\@shopify/app` → local-storage → cli-kit error chain (~1s).
* This inlined version avoids those imports entirely. It lazily imports the
* LocalStorage class only at call time, and uses Node's native crypto.
*/
const init: Hook<'init'> = async (_options) => {
// Lazy import to clear the command storage (equivalent to clearCachedCommandInfo)
const {LocalStorage} = await import('@shopify/cli-kit/node/local-storage')
const store = new LocalStorage({projectName: 'shopify-cli-app-command'})
store.clear()

// Set a unique run ID so parallel commands don't collide in the cache
process.env.COMMAND_RUN_ID = randomUUID()
}

export default init
21 changes: 19 additions & 2 deletions packages/cli/src/hooks/hydrogen-init.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
import {HOOKS} from '@shopify/cli-hydrogen'
import {Hook} from '@oclif/core'

/**
* Hydrogen init hook — only loads `\@shopify/cli-hydrogen` when running a hydrogen command.
* This avoids the ~300ms+ import cost for non-hydrogen commands.
*/
const hook: Hook<'init'> = async (options) => {
// The hydrogen init hook only does work for hydrogen commands.
// Skip loading the heavy module entirely for non-hydrogen commands.
if (!options.id?.startsWith('hydrogen:') || options.id === 'hydrogen:init') {
return
}

const {HOOKS} = await import('@shopify/cli-hydrogen')
if (HOOKS.init && typeof HOOKS.init === 'function') {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
await (HOOKS.init as any).call(this, options)
}
}

const hook = HOOKS.init
export default hook
Loading