diff --git a/.changeset/cli-packs-a-punch.md b/.changeset/cli-packs-a-punch.md new file mode 100644 index 0000000000..1fabe199d1 --- /dev/null +++ b/.changeset/cli-packs-a-punch.md @@ -0,0 +1,6 @@ +--- +'@backstage/cli': patch +--- + +Introduced the `--alwaysYarnPack` flag on `backstage-cli build-workspace`, which can be passed in cases where accuracy of workspace contents is more important than the +speed with which the workspace is built. Useful in rare situations where `yarn pack` and `npm pack` produce different results. diff --git a/packages/cli/cli-report.md b/packages/cli/cli-report.md index 39bee2ed05..4cf5c6329c 100644 --- a/packages/cli/cli-report.md +++ b/packages/cli/cli-report.md @@ -24,7 +24,7 @@ Commands: versions:bump [options] versions:check [options] clean - build-workspace [packages...] + build-workspace [options] [packages...] create-github-app info help [command] @@ -36,6 +36,7 @@ Commands: Usage: backstage-cli build-workspace [options] [packages...] Options: + --alwaysYarnPack -h, --help ``` diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index 3a40839e25..1fa7fe2964 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -402,6 +402,10 @@ export function registerCommands(program: Command) { program .command('build-workspace [packages...]') + .option( + '--alwaysYarnPack', + 'Force workspace output to be a result of running `yarn pack` on each package (warning: very slow)', + ) .description('Builds a temporary dist workspace from the provided packages') .action(lazy(() => import('./buildWorkspace').then(m => m.default))); diff --git a/packages/cli/src/lib/packager/createDistWorkspace.ts b/packages/cli/src/lib/packager/createDistWorkspace.ts index ab8b20919f..e91924dd37 100644 --- a/packages/cli/src/lib/packager/createDistWorkspace.ts +++ b/packages/cli/src/lib/packager/createDistWorkspace.ts @@ -95,6 +95,13 @@ type Options = { * with the same structure as the workspace dir. */ skeleton?: 'skeleton.tar' | 'skeleton.tar.gz'; + + /** + * If set to true, `yarn pack` is always preferred when creating the dist + * workspace. This ensures correct workspace output at significant cost to + * command performance. + */ + alwaysYarnPack?: boolean; }; function prefixLogFunc(prefix: string, out: 'stdout' | 'stderr') { @@ -220,7 +227,11 @@ export async function createDistWorkspace( } } - await moveToDistWorkspace(targetDir, targets); + await moveToDistWorkspace( + targetDir, + targets, + Boolean(options.alwaysYarnPack), + ); const files: FileEntry[] = options.files ?? ['yarn.lock', 'package.json']; @@ -262,9 +273,13 @@ const FAST_PACK_SCRIPTS = [ async function moveToDistWorkspace( workspaceDir: string, localPackages: PackageGraphNode[], + alwaysYarnPack: boolean, ): Promise { - const [fastPackPackages, slowPackPackages] = partition(localPackages, pkg => - FAST_PACK_SCRIPTS.includes(pkg.packageJson.scripts?.prepack), + const [fastPackPackages, slowPackPackages] = partition( + localPackages, + pkg => + !alwaysYarnPack && + FAST_PACK_SCRIPTS.includes(pkg.packageJson.scripts?.prepack), ); // New an improved flow where we avoid calling `yarn pack`