Skip to content

Commit

Permalink
Suppress dependency deprecation warnings (#108)
Browse files Browse the repository at this point in the history
These are annoying and there's little that users can do about it. Most
of these come from e.g. transitive Jest dependencies, and Jest has open
issues tracking the migration to supported dependencies.
  • Loading branch information
72636c authored Jun 24, 2020
1 parent 1b7641f commit b6296ac
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/thirty-bananas-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'skuba': patch
---

**cli:** Suppress dependency deprecation warnings
8 changes: 7 additions & 1 deletion src/cli/configure/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from 'path';
import { Select } from 'enquirer';

import { createInclusionFilter } from '../../utils/copy';
import { ensureCommands, exec } from '../../utils/exec';
import { createExec, ensureCommands } from '../../utils/exec';
import { log } from '../../utils/logging';
import { showLogo } from '../../utils/logo';
import { BASE_TEMPLATE_DIR } from '../../utils/template';
Expand Down Expand Up @@ -97,6 +97,12 @@ export const configure = async () => {
}

if (fixDependencies) {
const exec = createExec({
stdio: 'pipe',
streamStdio: 'yarn',
});

log.plain('Installing dependencies...');
await exec('yarn', 'install', '--silent');
}

Expand Down
9 changes: 8 additions & 1 deletion src/cli/init/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,16 @@ export const init = async () => {
}),
]);

const exec = createExec({ cwd: destinationDir });
const exec = createExec({
cwd: destinationDir,
stdio: 'pipe',
streamStdio: 'yarn',
});

log.newline();
await initialiseRepo(exec, templateData);

log.plain('Installing dependencies...');
await exec(
'yarn',
'add',
Expand All @@ -80,6 +86,7 @@ export const init = async () => {
'--silent',
`skuba@${skubaVersion}`,
);

await commitChanges(exec, `Clone ${templateName}`);

log.newline();
Expand Down
37 changes: 33 additions & 4 deletions src/utils/exec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import stream from 'stream';
import util from 'util';

import concurrently from 'concurrently';
Expand All @@ -8,6 +9,23 @@ import npmWhich from 'npm-which';
import { isErrorWithCode } from './error';
import { log } from './logging';

class YarnWarningFilter extends stream.Transform {
_transform(
chunk: any,
_encoding: BufferEncoding,
callback: stream.TransformCallback,
) {
const str = Buffer.from(chunk).toString();

// Filter out annoying deprecation warnings that users can do little about
if (!str.startsWith('warning skuba >')) {
this.push(chunk);
}

callback();
}
}

export type Exec = (
command: string,
...args: string[]
Expand All @@ -18,7 +36,7 @@ interface ExecConcurrentlyCommand {
name: string;
}

type ExecOptions = execa.Options & { streamStdio?: true };
type ExecOptions = execa.Options & { streamStdio?: true | 'yarn' };

const envWithPath = {
PATH: npmRunPath({ cwd: __dirname }),
Expand All @@ -32,9 +50,20 @@ const runCommand = (command: string, args: string[], opts?: ExecOptions) => {
...opts,
});

if (opts?.streamStdio === true) {
subprocess.stderr?.pipe(process.stderr);
subprocess.stdout?.pipe(process.stdout);
switch (opts?.streamStdio) {
case 'yarn':
const filter = new YarnWarningFilter();

subprocess.stderr?.pipe(filter).pipe(process.stderr);
subprocess.stdout?.pipe(process.stdout);

break;

case true:
subprocess.stderr?.pipe(process.stderr);
subprocess.stdout?.pipe(process.stdout);

break;
}

return subprocess;
Expand Down

0 comments on commit b6296ac

Please sign in to comment.