diff --git a/.changeset/fix-prepack-postpack-cjs.md b/.changeset/fix-prepack-postpack-cjs.md new file mode 100644 index 0000000000..549841845b --- /dev/null +++ b/.changeset/fix-prepack-postpack-cjs.md @@ -0,0 +1,5 @@ +--- +'@backstage/cli': patch +--- + +Fixed `prepack` and `postpack` commands failing when the dynamic `import()` goes through a CommonJS compatibility layer that doesn't wrap module exports. diff --git a/packages/cli/src/modules/build/index.ts b/packages/cli/src/modules/build/index.ts index fd94cb5db6..794f5b8976 100644 --- a/packages/cli/src/modules/build/index.ts +++ b/packages/cli/src/modules/build/index.ts @@ -215,20 +215,34 @@ export const buildPlugin = createCliPlugin({ reg.addCommand({ path: ['package', 'prepack'], description: 'Prepares a package for packaging before publishing', - execute: async ({ args, info }) => { - cli({ help: info }, undefined, args); - const { pre } = await import('./commands/package/pack'); - await pre(); + execute: { + loader: () => + import('./commands/package/pack').then(m => { + const { pre } = (m as any).default ?? m; + return { + default: async ({ args, info }) => { + cli({ help: info }, undefined, args); + await pre(); + }, + }; + }), }, }); reg.addCommand({ path: ['package', 'postpack'], description: 'Restores the changes made by the prepack command', - execute: async ({ args, info }) => { - cli({ help: info }, undefined, args); - const { post } = await import('./commands/package/pack'); - await post(); + execute: { + loader: () => + import('./commands/package/pack').then(m => { + const { post } = (m as any).default ?? m; + return { + default: async ({ args, info }) => { + cli({ help: info }, undefined, args); + await post(); + }, + }; + }), }, });