-
Notifications
You must be signed in to change notification settings - Fork 23
deps/proc log #198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
deps/proc log #198
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,8 +57,6 @@ runScript({ | |
// print the package id and script, and the command to be run, like: | ||
// > [email protected] postinstall | ||
// > make all-the-things | ||
// Defaults true when stdio:'inherit', otherwise suppressed | ||
banner: true, | ||
}) | ||
.then(({ code, signal, stdout, stderr, pkgid, path, event, script }) => { | ||
// do something with the results | ||
|
@@ -99,6 +97,11 @@ terminal, then it is up to the user to end it, of course. | |
- `event` Lifecycle event being run | ||
- `script` Command being run | ||
|
||
If stdio is `inherit` this package will emit a banner with the package | ||
name and version, event name, and script command to be run, and send it | ||
to [`proc-log.output.standard`](https://npm.im/proc-log). Consuming | ||
libraries can decide whether or not to display this. | ||
|
||
### Options | ||
|
||
- `path` Required. The path to the package having its script run. | ||
|
@@ -124,10 +127,6 @@ terminal, then it is up to the user to end it, of course. | |
- `stdioString` Optional, passed directly to `@npmcli/promise-spawn` which | ||
defaults it to `true`. Return string values for `stderr` and `stdout` rather | ||
than Buffers. | ||
- `banner` Optional, defaults to `true`. If the `stdio` option is set to | ||
`'inherit'`, then print a banner with the package name and version, event | ||
name, and script command to be run. Set explicitly to `false` to disable | ||
for inherited stdio. | ||
|
||
Note that this does _not_ run pre-event and post-event scripts. The | ||
caller has to manage that process themselves. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,18 +6,19 @@ const isWindows = process.platform === 'win32' | |
const emptyDir = t.testdir({}) | ||
|
||
const pkill = process.kill | ||
const consoleLog = console.log | ||
|
||
const mockConsole = t => { | ||
const logs = [] | ||
console.log = (...args) => logs.push(args) | ||
t.teardown(() => console.log = consoleLog) | ||
return logs | ||
const output = [] | ||
const appendOutput = (level, ...args) => { | ||
if (level === 'standard') { | ||
output.push([...args]) | ||
} | ||
} | ||
process.on('output', appendOutput) | ||
t.afterEach(() => output.length = 0) | ||
t.teardown(() => process.removeListener('output', appendOutput)) | ||
|
||
t.test('run-script-pkg', async t => { | ||
await t.test('do the banner when stdio is inherited, handle line breaks', async t => { | ||
const logs = mockConsole(t) | ||
await t.test('stdio inherit no args and a pkgid', async t => { | ||
spawk.spawn('sh', a => a.includes('bar\nbaz\n')) | ||
await runScript({ | ||
event: 'foo', | ||
|
@@ -33,34 +34,11 @@ t.test('run-script-pkg', async t => { | |
scripts: {}, | ||
}, | ||
}) | ||
t.strictSame(logs, [['\n> [email protected] foo\n> bar\n> baz\n']]) | ||
t.strictSame(output, [['\n> [email protected] foo\n> bar\n> baz\n']]) | ||
t.ok(spawk.done()) | ||
}) | ||
|
||
await t.test('do not show banner when stdio is inherited, if suppressed', async t => { | ||
const logs = mockConsole(t) | ||
spawk.spawn('sh', a => a.includes('bar')) | ||
await runScript({ | ||
event: 'foo', | ||
path: emptyDir, | ||
scriptShell: 'sh', | ||
env: { | ||
environ: 'value', | ||
}, | ||
stdio: 'inherit', | ||
cmd: 'bar', | ||
pkg: { | ||
_id: '[email protected]', | ||
scripts: {}, | ||
}, | ||
banner: false, | ||
}) | ||
t.strictSame(logs, []) | ||
t.ok(spawk.done()) | ||
}) | ||
|
||
await t.test('do the banner with no pkgid', async t => { | ||
const logs = mockConsole(t) | ||
await t.test('stdio inherit args and no pkgid', async t => { | ||
spawk.spawn('sh', a => a.includes('bar baz buzz')) | ||
await runScript({ | ||
event: 'foo', | ||
|
@@ -76,12 +54,11 @@ t.test('run-script-pkg', async t => { | |
scripts: {}, | ||
}, | ||
}) | ||
t.strictSame(logs, [['\n> foo\n> bar baz buzz\n']]) | ||
t.strictSame(output, [['\n> foo\n> bar baz buzz\n']]) | ||
t.ok(spawk.done()) | ||
}) | ||
|
||
await t.test('pkg has foo script', async t => { | ||
const logs = mockConsole(t) | ||
await t.test('pkg has foo script, with stdio pipe', async t => { | ||
spawk.spawn('sh', a => a.includes('bar')) | ||
await runScript({ | ||
event: 'foo', | ||
|
@@ -98,12 +75,11 @@ t.test('run-script-pkg', async t => { | |
}, | ||
}, | ||
}) | ||
t.strictSame(logs, []) | ||
t.strictSame(output, []) | ||
t.ok(spawk.done()) | ||
}) | ||
|
||
await t.test('pkg has foo script, with args', async t => { | ||
const logs = mockConsole(t) | ||
await t.test('pkg has foo script, with stdio pipe and args', async t => { | ||
spawk.spawn('sh', a => a.includes('bar a b c')) | ||
await runScript({ | ||
event: 'foo', | ||
|
@@ -122,16 +98,16 @@ t.test('run-script-pkg', async t => { | |
args: ['a', 'b', 'c'], | ||
binPaths: false, | ||
}) | ||
t.strictSame(logs, []) | ||
t.strictSame(output, []) | ||
t.ok(spawk.done()) | ||
}) | ||
|
||
await t.test('pkg has no install or preinstall script, node-gyp files present', async t => { | ||
/* eslint-disable-next-line max-len */ | ||
await t.test('pkg has no install or preinstall script, node-gyp files present, stdio pipe', async t => { | ||
const testdir = t.testdir({ | ||
'binding.gyp': 'exists', | ||
}) | ||
|
||
const logs = mockConsole(t) | ||
spawk.spawn('sh', a => a.includes('node-gyp rebuild')) | ||
await runScript({ | ||
event: 'install', | ||
|
@@ -146,11 +122,11 @@ t.test('run-script-pkg', async t => { | |
scripts: {}, | ||
}, | ||
}) | ||
t.strictSame(logs, []) | ||
t.strictSame(output, []) | ||
t.ok(spawk.done()) | ||
}) | ||
|
||
t.test('pkg has no install or preinstall script, but gypfile:false', async t => { | ||
t.test('pkg has no install or preinstall script, but gypfile:false, stdio pipe', async t => { | ||
const testdir = t.testdir({ | ||
'binding.gyp': 'exists', | ||
}) | ||
|
@@ -170,6 +146,7 @@ t.test('run-script-pkg', async t => { | |
}, | ||
}, | ||
}) | ||
t.strictSame(output, []) | ||
t.strictSame(res, { code: 0, signal: null }) | ||
}) | ||
|
||
|
@@ -190,7 +167,7 @@ t.test('run-script-pkg', async t => { | |
t.ok(interceptor.calledWith.stdio[0].writableEnded, 'stdin was ended properly') | ||
}) | ||
|
||
await t.test('kill process when foreground process ends with signal', async t => { | ||
await t.test('kill process when foreground process ends with signal, stdio inherit', async t => { | ||
t.teardown(() => { | ||
process.kill = pkill | ||
}) | ||
|
@@ -219,14 +196,15 @@ t.test('run-script-pkg', async t => { | |
}, | ||
}, | ||
})) | ||
t.strictSame(output, [['\n> [email protected] sleep\n> sleep 1000000\n']]) | ||
t.ok(spawk.done()) | ||
if (!isWindows) { | ||
t.equal(signal, 'SIGFOO', 'process.kill got expected signal') | ||
t.equal(pid, process.pid, 'process.kill got expected pid') | ||
} | ||
}) | ||
|
||
await t.test('kill process when foreground process ends with signal', async t => { | ||
await t.test('kill process when foreground process ends with signal, stdio inherit', async t => { | ||
t.teardown(() => { | ||
process.kill = pkill | ||
}) | ||
|
@@ -255,14 +233,15 @@ t.test('run-script-pkg', async t => { | |
}, | ||
}, | ||
})) | ||
t.strictSame(output, [['\n> [email protected] sleep\n> sleep 1000000\n']]) | ||
t.ok(spawk.done()) | ||
if (!isWindows) { | ||
t.equal(signal, 'SIGFOO', 'process.kill got expected signal') | ||
t.equal(pid, process.pid, 'process.kill got expected pid') | ||
} | ||
}) | ||
|
||
t.test('rejects if process.kill fails to end process', async t => { | ||
t.test('rejects if process.kill fails to end process, stdio inherit', async t => { | ||
t.teardown(() => { | ||
process.kill = pkill | ||
}) | ||
|
@@ -290,6 +269,7 @@ t.test('run-script-pkg', async t => { | |
}, | ||
}, | ||
})) | ||
t.strictSame(output, [['\n> [email protected] sleep\n> sleep 1000000\n']]) | ||
t.ok(spawk.done()) | ||
if (!isWindows) { | ||
t.equal(signal, 'SIGFOO', 'process.kill got expected signal') | ||
|
@@ -314,6 +294,7 @@ t.test('run-script-pkg', async t => { | |
}, | ||
}, | ||
})) | ||
t.strictSame(output, []) | ||
t.ok(spawk.done()) | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.