cli: clean up yarn install output in versions bump

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2022-02-10 17:37:48 +01:00
parent 409e99684e
commit 2c83545dda
3 changed files with 66 additions and 20 deletions
@@ -31,6 +31,7 @@ import { rest } from 'msw';
// Remove log coloring to simplify log matching
jest.mock('chalk', () => ({
red: (str: string) => str,
blue: (str: string) => str,
cyan: (str: string) => str,
green: (str: string) => str,
@@ -38,6 +39,18 @@ jest.mock('chalk', () => ({
yellow: (str: string) => str,
}));
jest.mock('ora', () => ({
__esModule: true,
default({ prefixText }: any) {
console.log(prefixText);
return {
start: () => ({
succeed: () => {},
}),
};
},
}));
const REGISTRY_VERSIONS: { [name: string]: string } = {
'@backstage/core': '1.0.6',
'@backstage/core-api': '1.0.7',
@@ -177,7 +190,11 @@ describe('bump', () => {
);
expect(runObj.run).toHaveBeenCalledTimes(1);
expect(runObj.run).toHaveBeenCalledWith('yarn', ['install']);
expect(runObj.run).toHaveBeenCalledWith(
'yarn',
['install'],
expect.any(Object),
);
const lockfileContents = await fs.readFile('/yarn.lock', 'utf8');
expect(lockfileContents).toBe(lockfileMockResult);
@@ -296,7 +313,11 @@ describe('bump', () => {
);
expect(runObj.run).toHaveBeenCalledTimes(1);
expect(runObj.run).toHaveBeenCalledWith('yarn', ['install']);
expect(runObj.run).toHaveBeenCalledWith(
'yarn',
['install'],
expect.any(Object),
);
const lockfileContents = await fs.readFile('/yarn.lock', 'utf8');
expect(lockfileContents).toBe(lockfileMockResult);
@@ -398,7 +419,11 @@ describe('bump', () => {
]);
expect(runObj.run).toHaveBeenCalledTimes(1);
expect(runObj.run).toHaveBeenCalledWith('yarn', ['install']);
expect(runObj.run).toHaveBeenCalledWith(
'yarn',
['install'],
expect.any(Object),
);
const packageA = await fs.readJson('/packages/a/package.json');
expect(packageA).toEqual({
@@ -645,7 +670,11 @@ describe('bump', () => {
);
expect(runObj.run).toHaveBeenCalledTimes(1);
expect(runObj.run).toHaveBeenCalledWith('yarn', ['install']);
expect(runObj.run).toHaveBeenCalledWith(
'yarn',
['install'],
expect.any(Object),
);
const lockfileContents = await fs.readFile('/yarn.lock', 'utf8');
expect(lockfileContents).toEqual(customLockfileMockResult);
+32 -15
View File
@@ -16,6 +16,7 @@
import fs from 'fs-extra';
import chalk from 'chalk';
import ora from 'ora';
import semver from 'semver';
import minimatch from 'minimatch';
import { Command } from 'commander';
@@ -259,21 +260,8 @@ export default async (cmd: Command) => {
),
);
}
console.log();
console.log(
`Running ${chalk.blue('yarn install')} to install new versions`,
);
console.log();
await run('yarn', ['install'], {
env: {
FORCE_COLOR: 'true',
...Object.fromEntries(
Object.entries(process.env).map(([name, value]) =>
name.startsWith('npm_') ? [name, undefined] : [name, value],
),
),
},
});
await runYarnInstall();
if (breakingUpdates.size > 0) {
console.log();
@@ -465,3 +453,32 @@ export async function bumpBackstageJsonVersion(version: string) {
},
);
}
async function runYarnInstall() {
const spinner = ora({
prefixText: `Running ${chalk.blue('yarn install')} to install new versions`,
spinner: 'arc',
color: 'green',
}).start();
const installOutput = new Array<Buffer>();
try {
await run('yarn', ['install'], {
env: {
FORCE_COLOR: 'true',
...Object.fromEntries(
Object.entries(process.env).map(([name, value]) =>
name.startsWith('npm_') ? [name, undefined] : [name, value],
),
),
},
stdoutLogFunc: data => installOutput.push(data),
stderrLogFunc: data => installOutput.push(data),
});
spinner.succeed();
} catch (error) {
spinner.fail();
process.stdout.write(Buffer.concat(installOutput));
throw error;
}
}
+1 -1
View File
@@ -14,7 +14,7 @@
* limitations under the License.
*/
export type LogFunc = (data: Buffer | string) => void;
export type LogFunc = (data: Buffer) => void;
export type LogPipe = (dst: NodeJS.WriteStream) => LogFunc;
export type LogOptions = {