Skip to content

Commit d0e3cd0

Browse files
committed
added a new '--no-path-rewrite' option, decoupled from prefixing
1 parent a4a48cb commit d0e3cd0

File tree

4 files changed

+35
-11
lines changed

4 files changed

+35
-11
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "wsrun",
3-
"version": "3.6.6",
3+
"version": "3.7.0",
44
"description": "executes commands on packages in parallel, but is aware of the dependencies between them",
55
"main": "./build/index.js",
66
"author": "hfour",

src/cmd-process.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ import * as Bromise from 'bluebird'
33

44
import originalSplit = require('split')
55

6-
import { Result, ResultSpecialValues } from './enums';
6+
import { Result, ResultSpecialValues } from './enums'
77
import { defer } from './utils'
88

99
export interface CmdOptions {
1010
rejectOnNonZeroExit: boolean
1111
silent?: boolean
1212
collectLogs: boolean
1313
prefixer?: (basePath: string, pkg: string, line: string) => string
14+
pathRewriter?: (basePath: string, pkg: string, line: string) => string
1415
doneCriteria?: string
1516
path: string
1617
}
@@ -47,7 +48,7 @@ export class CmdProcess {
4748
}
4849

4950
get result() {
50-
return Bromise.race([this._exitCode.promise, this._cancelled.promise]);
51+
return Bromise.race([this._exitCode.promise, this._cancelled.promise])
5152
}
5253

5354
/**
@@ -82,14 +83,14 @@ export class CmdProcess {
8283
this.exitCode.then(code => {
8384
if (code > 0) {
8485
const msg = '`' + this.cmdString + '` failed with exit code ' + code
85-
if (!this.opts.silent) console.error(this.autoPrefix(msg))
86+
if (!this.opts.silent) console.error(this.autoAugmentLine(msg))
8687
if (this.opts.rejectOnNonZeroExit) return this._finished.reject(new Error(msg))
8788
}
8889
this._finished.resolve()
8990
})
9091

9192
// ignore if unhandled
92-
this._finished.promise.catch(() => { })
93+
this._finished.promise.catch(() => {})
9394
}
9495

9596
stop() {
@@ -98,13 +99,25 @@ export class CmdProcess {
9899
this.cp.removeAllListeners('exit')
99100
this.cp.kill('SIGINT')
100101
}
101-
this._cancelled.resolve(ResultSpecialValues.Cancelled);
102+
this._cancelled.resolve(ResultSpecialValues.Cancelled)
102103
}
103104

104105
private autoPrefix(line: string) {
105106
return this.opts.prefixer ? this.opts.prefixer(this.opts.path, this.pkgName, line) : line
106107
}
107108

109+
private autoPathRewrite(line: string) {
110+
return this.opts.pathRewriter
111+
? this.opts.pathRewriter(this.opts.path, this.pkgName, line)
112+
: line
113+
}
114+
115+
private autoAugmentLine(line: string) {
116+
line = this.autoPathRewrite(line)
117+
line = this.autoPrefix(line)
118+
return line
119+
}
120+
108121
private _start(cmd: string[]) {
109122
let sh: string
110123
let args: string[]
@@ -137,21 +150,21 @@ export class CmdProcess {
137150
if (this.cp.stdout)
138151
this.cp.stdout.pipe(split()).on('data', (line: string) => {
139152
if (this.opts.collectLogs) stdOutBuffer.push(line)
140-
else console.log(this.autoPrefix(line))
153+
else console.log(this.autoAugmentLine(line))
141154
if (this.doneCriteria && this.doneCriteria.test(line)) this._finished.resolve()
142155
})
143156
if (this.cp.stderr)
144157
this.cp.stderr.pipe(split()).on('data', (line: string) => {
145158
if (this.opts.collectLogs) stdErrBuffer.push(line)
146-
else console.error(this.autoPrefix(line))
159+
else console.error(this.autoAugmentLine(line))
147160
if (this.doneCriteria && this.doneCriteria.test(line)) this._finished.resolve()
148161
})
149162
if (this.opts.collectLogs)
150163
this._closed.promise.then(() => {
151164
if (stdOutBuffer.length)
152-
console.log(stdOutBuffer.map(line => this.autoPrefix(line)).join('\n'))
165+
console.log(stdOutBuffer.map(line => this.autoAugmentLine(line)).join('\n'))
153166
if (stdErrBuffer.length)
154-
console.error(stdErrBuffer.map(line => this.autoPrefix(line)).join('\n'))
167+
console.error(stdErrBuffer.map(line => this.autoAugmentLine(line)).join('\n'))
155168
})
156169
}
157170
}

src/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ let yargsParser = yargs
6969
'fast-exit',
7070
'collect-logs',
7171
'no-prefix',
72+
'no-path-rewrite',
7273
'bin',
7374
'done-criteria',
7475
'exclude',
@@ -100,6 +101,11 @@ let yargsParser = yargs
100101
boolean: true,
101102
describe: "Don't prefix output"
102103
},
104+
'no-path-rewrite': {
105+
boolean: true,
106+
describe:
107+
"Don't rewrite relative paths in the standard output, leaving them relative to the package folder"
108+
},
103109
bin: {
104110
default: 'yarn',
105111
describe: 'The program to pass the command to',
@@ -156,6 +162,7 @@ const recursive: boolean = argv.recursive || argv.r || false
156162
const fastExit: boolean = argv.fastExit || false
157163
const collectLogs: boolean = argv.collectLogs || false
158164
const addPrefix: boolean = argv.prefix === undefined ? true : false
165+
const rewritePaths: boolean = argv.rewritePaths === undefined ? true : false
159166
const doneCriteria: string = argv.doneCriteria
160167
const exclude: string[] =
161168
(argv.exclude && (Array.isArray(argv.exclude) ? argv.exclude : [argv.exclude])) || []
@@ -190,6 +197,7 @@ let runner = new RunGraph(
190197
fastExit,
191198
collectLogs,
192199
addPrefix,
200+
rewritePaths,
193201
mode: mode as any,
194202
recursive,
195203
doneCriteria,

src/run-graph.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as Bromise from 'bluebird'
22
import chalk from 'chalk'
33

44
import { PkgJson, Dict } from './workspace'
5-
import { ResultSpecialValues, Result, ProcResolution } from './enums';
5+
import { ResultSpecialValues, Result, ProcResolution } from './enums'
66
import { uniq } from 'lodash'
77
import { CmdProcess } from './cmd-process'
88
import minimatch = require('minimatch')
@@ -35,6 +35,7 @@ export interface GraphOptions {
3535
fastExit: boolean
3636
collectLogs: boolean
3737
addPrefix: boolean
38+
rewritePaths: boolean
3839
mode: 'parallel' | 'serial' | 'stages'
3940
recursive: boolean
4041
doneCriteria: string | undefined
@@ -56,6 +57,7 @@ export class RunGraph {
5657
private resultMap = new Map<string, Result>()
5758
private throat: PromiseFnRunner = passThrough
5859
prefixer = new Prefixer(this.opts.workspacePath).prefixer
60+
pathRewriter = fixPaths
5961

6062
constructor(
6163
public pkgJsons: PkgJson[],
@@ -187,6 +189,7 @@ export class RunGraph {
187189
rejectOnNonZeroExit: this.opts.fastExit,
188190
collectLogs: this.opts.collectLogs,
189191
prefixer: this.opts.addPrefix ? this.prefixer : undefined,
192+
pathRewriter: this.opts.rewritePaths ? this.pathRewriter : undefined,
190193
doneCriteria: this.opts.doneCriteria,
191194
path: this.pkgPaths[pkg]
192195
})

0 commit comments

Comments
 (0)