Add --alwaysYarnPack flag to build-workspace command

Signed-off-by: Eric Peterson <ericpeterson@spotify.com>
This commit is contained in:
Eric Peterson
2023-06-20 11:53:26 +02:00
parent 29ceb11821
commit 314493fa32
4 changed files with 30 additions and 4 deletions
+6
View File
@@ -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.
+2 -1
View File
@@ -24,7 +24,7 @@ Commands:
versions:bump [options]
versions:check [options]
clean
build-workspace <workspace-dir> [packages...]
build-workspace [options] <workspace-dir> [packages...]
create-github-app <github-org>
info
help [command]
@@ -36,6 +36,7 @@ Commands:
Usage: backstage-cli build-workspace [options] <workspace-dir> [packages...]
Options:
--alwaysYarnPack
-h, --help
```
+4
View File
@@ -402,6 +402,10 @@ export function registerCommands(program: Command) {
program
.command('build-workspace <workspace-dir> [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)));
@@ -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<void> {
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`