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 <poldsberg@gmail.com>
Made-with: Cursor
This commit is contained in:
Patrik Oldsberg
2026-03-02 17:33:35 +01:00
parent a0e4d38f4b
commit f867152e8b
2 changed files with 27 additions and 8 deletions
+5
View File
@@ -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.
+22 -8
View File
@@ -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();
},
};
}),
},
});