From f867152e8bfd431fd88679ba12cd36e554692199 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Mon, 2 Mar 2026 17:33:35 +0100 Subject: [PATCH] cli: fix prepack and postpack commands CJS compat Switch the prepack and postpack commands from using a direct dynamic import() to the execute.loader pattern, which properly handles CJS double-wrapping of module exports. Signed-off-by: Patrik Oldsberg Made-with: Cursor --- .changeset/fix-prepack-postpack-cjs.md | 5 +++++ packages/cli/src/modules/build/index.ts | 30 ++++++++++++++++++------- 2 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 .changeset/fix-prepack-postpack-cjs.md 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(); + }, + }; + }), }, });