-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
run-script.js
76 lines (69 loc) · 1.68 KB
/
run-script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const ciInfo = require('ci-info')
const runScript = require('@npmcli/run-script')
const readPackageJson = require('read-package-json-fast')
const npmlog = require('npmlog')
const log = require('proc-log')
const noTTY = require('./no-tty.js')
const run = async ({
args,
call,
flatOptions,
locationMsg,
output = () => {},
path,
binPaths,
runPath,
scriptShell,
stdio = 'inherit',
}) => {
// turn list of args into command string
const script = call || args.shift() || scriptShell
// do the fakey runScript dance
// still should work if no package.json in cwd
const realPkg = await readPackageJson(`${path}/package.json`)
.catch(() => ({}))
const pkg = {
...realPkg,
scripts: {
...(realPkg.scripts || {}),
npx: script,
},
}
if (stdio === 'inherit') {
npmlog.disableProgress()
}
try {
if (script === scriptShell) {
if (!noTTY()) {
if (ciInfo.isCI) {
return log.warn('exec', 'Interactive mode disabled in CI environment')
}
locationMsg = locationMsg || ` at location:\n${flatOptions.chalk.dim(runPath)}`
output(`${
flatOptions.chalk.reset('\nEntering npm script environment')
}${
flatOptions.chalk.reset(locationMsg)
}${
flatOptions.chalk.bold('\nType \'exit\' or ^D when finished\n')
}`)
}
}
return await runScript({
...flatOptions,
pkg,
banner: false,
// we always run in cwd, not --prefix
path: runPath,
binPaths,
event: 'npx',
args,
stdio,
scriptShell,
})
} finally {
if (stdio === 'inherit') {
npmlog.enableProgress()
}
}
}
module.exports = run