@yarnpkg/shell
Advanced tools
Comparing version 3.0.0-rc.6 to 3.0.0-rc.7
@@ -123,8 +123,39 @@ "use strict"; | ||
let stdout = state.stdout; | ||
const stderr = state.stderr; | ||
let stderr = state.stderr; | ||
const inputs = []; | ||
const outputs = []; | ||
const errors = []; | ||
let t = 0; | ||
while (args[t] !== `--`) { | ||
const type = args[t++]; | ||
const key = args[t++]; | ||
const { type, fd } = JSON.parse(key); | ||
const pushInput = (readableFactory) => { | ||
switch (fd) { | ||
case null: | ||
case 0: | ||
{ | ||
inputs.push(readableFactory); | ||
} | ||
break; | ||
default: | ||
throw new Error(`Unsupported file descriptor: "${fd}"`); | ||
} | ||
}; | ||
const pushOutput = (writable) => { | ||
switch (fd) { | ||
case null: | ||
case 1: | ||
{ | ||
outputs.push(writable); | ||
} | ||
break; | ||
case 2: | ||
{ | ||
errors.push(writable); | ||
} | ||
break; | ||
default: | ||
throw new Error(`Unsupported file descriptor: "${fd}"`); | ||
} | ||
}; | ||
const count = Number(args[t++]); | ||
@@ -136,3 +167,3 @@ const last = t + count; | ||
{ | ||
inputs.push(() => { | ||
pushInput(() => { | ||
return opts.baseFs.createReadStream(fslib_1.ppath.resolve(state.cwd, fslib_1.npath.toPortablePath(args[u]))); | ||
@@ -144,3 +175,3 @@ }); | ||
{ | ||
inputs.push(() => { | ||
pushInput(() => { | ||
const input = new stream_1.PassThrough(); | ||
@@ -157,3 +188,3 @@ process.nextTick(() => { | ||
{ | ||
inputs.push(() => getFileDescriptorStream(Number(args[u]), StreamType.Readable, state)); | ||
pushInput(() => getFileDescriptorStream(Number(args[u]), StreamType.Readable, state)); | ||
} | ||
@@ -166,3 +197,3 @@ break; | ||
if (outputPath === `/dev/null`) { | ||
outputs.push(new stream_1.Writable({ | ||
pushOutput(new stream_1.Writable({ | ||
autoDestroy: true, | ||
@@ -176,3 +207,3 @@ emitClose: true, | ||
else { | ||
outputs.push(opts.baseFs.createWriteStream(outputPath, type === `>>` ? { flags: `a` } : undefined)); | ||
pushOutput(opts.baseFs.createWriteStream(outputPath, type === `>>` ? { flags: `a` } : undefined)); | ||
} | ||
@@ -183,3 +214,3 @@ } | ||
{ | ||
outputs.push(getFileDescriptorStream(Number(args[u]), StreamType.Writable, state)); | ||
pushOutput(getFileDescriptorStream(Number(args[u]), StreamType.Writable, state)); | ||
} | ||
@@ -217,2 +248,9 @@ break; | ||
} | ||
if (errors.length > 0) { | ||
const pipe = new stream_1.PassThrough(); | ||
stderr = pipe; | ||
for (const error of errors) { | ||
pipe.pipe(error); | ||
} | ||
} | ||
const exitCode = await pipe_2.start(makeCommandAction(args.slice(t + 1), opts, state), { | ||
@@ -236,2 +274,15 @@ stdin: new pipe_2.ProtectedStream(stdin), | ||
})); | ||
// Close all the errors (since the shell never closes the error stream) | ||
await Promise.all(errors.map(err => { | ||
// Wait until the error got flushed to the disk | ||
return new Promise((resolve, reject) => { | ||
err.on(`error`, error => { | ||
reject(error); | ||
}); | ||
err.on(`close`, () => { | ||
resolve(); | ||
}); | ||
err.end(); | ||
}); | ||
})); | ||
return exitCode; | ||
@@ -395,6 +446,7 @@ }], | ||
}; | ||
const redirect = (type, target) => { | ||
let targets = redirections.get(type); | ||
const redirect = (type, fd, target) => { | ||
const key = JSON.stringify({ type, fd }); | ||
let targets = redirections.get(key); | ||
if (typeof targets === `undefined`) | ||
redirections.set(type, targets = []); | ||
redirections.set(key, targets = []); | ||
targets.push(target); | ||
@@ -409,3 +461,3 @@ }; | ||
for (const interpolatedArg of interpolatedArgs) { | ||
redirect(commandArg.subtype, interpolatedArg); | ||
redirect(commandArg.subtype, commandArg.fd, interpolatedArg); | ||
} | ||
@@ -477,4 +529,4 @@ } | ||
const redirectionArgs = []; | ||
for (const [subtype, targets] of redirections.entries()) | ||
redirectionArgs.splice(redirectionArgs.length, 0, subtype, String(targets.length), ...targets); | ||
for (const [key, targets] of redirections.entries()) | ||
redirectionArgs.splice(redirectionArgs.length, 0, key, String(targets.length), ...targets); | ||
interpolated.splice(0, 0, `__ysh_set_redirects`, ...redirectionArgs, `--`); | ||
@@ -481,0 +533,0 @@ } |
{ | ||
"name": "@yarnpkg/shell", | ||
"version": "3.0.0-rc.6", | ||
"version": "3.0.0-rc.7", | ||
"license": "BSD-2-Clause", | ||
@@ -8,4 +8,4 @@ "main": "./lib/index.js", | ||
"dependencies": { | ||
"@yarnpkg/fslib": "^2.5.0-rc.6", | ||
"@yarnpkg/parsers": "^2.4.0-rc.4", | ||
"@yarnpkg/fslib": "^2.5.0-rc.7", | ||
"@yarnpkg/parsers": "^2.4.0-rc.5", | ||
"chalk": "^3.0.0", | ||
@@ -12,0 +12,0 @@ "clipanion": "^3.0.0-rc.10", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
57710
1480
Updated@yarnpkg/fslib@^2.5.0-rc.7
Updated@yarnpkg/parsers@^2.4.0-rc.5