Skip to content

Commit

Permalink
fix: add strip-ansi
Browse files Browse the repository at this point in the history
@W-8856585@ nuts for plugin-org needs to have responses stripped of ansi chars
  • Loading branch information
peternhale committed Feb 26, 2021
1 parent 201b565 commit 1684979
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
"archiver": "^5.2.0",
"debug": "^4.3.1",
"shelljs": "^0.8.4",
"sinon": "^9.0.2"
"sinon": "^9.0.2",
"strip-ansi": "^6.0.0"
},
"devDependencies": {
"@salesforce/dev-config": "^2.0.0",
Expand Down
8 changes: 5 additions & 3 deletions src/execCmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import Debug from 'debug';
import * as shelljs from 'shelljs';
import { ExecCallback, ExecOptions, ShellString } from 'shelljs';

import stripAnsi = require('strip-ansi');

export interface ExecCmdOptions extends ExecOptions {
/**
* Throws if this exit code is not returned by the child process.
Expand Down Expand Up @@ -63,7 +65,7 @@ const hrtimeToMillisDuration = (hrTime: [number, number]) =>
const addJsonOutput = (cmd: string, result: ExecCmdResult): ExecCmdResult => {
if (cmd.includes('--json')) {
try {
result.jsonOutput = parseJson(result.shellOutput.stdout);
result.jsonOutput = parseJson(stripAnsi(result.shellOutput.stdout));
} catch (parseErr: unknown) {
result.jsonError = parseErr as Error;
}
Expand Down Expand Up @@ -162,8 +164,8 @@ const execCmdAsync = async (cmd: string, options: ExecCmdOptions): Promise<ExecC
execCmdDuration,
};
result.shellOutput.code = code;
result.shellOutput.stdout = stdout;
result.shellOutput.stderr = stderr;
result.shellOutput.stdout = stripAnsi(stdout);
result.shellOutput.stderr = stripAnsi(stderr);

resolve(addJsonOutput(cmd, result));
};
Expand Down
3 changes: 3 additions & 0 deletions src/testSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Duration, env, parseJson, sleep } from '@salesforce/kit';
import { AnyJson, getString, Optional } from '@salesforce/ts-types';
import { createSandbox, SinonStub } from 'sinon';
import * as shell from 'shelljs';
import stripAnsi = require('strip-ansi');
import { genUniqueString } from './genUniqueString';
import { zipDir } from './zip';

Expand Down Expand Up @@ -257,6 +258,8 @@ export class TestSession {
}

const rv = shell.exec(cmd, { silent: true });
rv.stdout = stripAnsi(rv.stdout);
rv.stderr = stripAnsi(rv.stderr);
if (rv.code !== 0) {
const io = cmd.includes('--json') ? rv.stdout : rv.stderr;
throw Error(`Setup command ${cmd} failed due to: ${io}`);
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5625,7 +5625,7 @@ strip-ansi@^5.0.0, strip-ansi@^5.1.0, strip-ansi@^5.2.0:

strip-ansi@^6.0.0:
version "6.0.0"
resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz#0b1571dd7669ccd4f3e06e14ef1eed26225ae532"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.0.tgz#0b1571dd7669ccd4f3e06e14ef1eed26225ae532"
integrity sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==
dependencies:
ansi-regex "^5.0.0"
Expand Down

0 comments on commit 1684979

Please sign in to comment.