2022-12-06 22:18:33 -05:00
|
|
|
const ciInfo = require('ci-info')
|
2021-04-29 16:30:06 -04:00
|
|
|
const runScript = require('@npmcli/run-script')
|
|
|
|
const readPackageJson = require('read-package-json-fast')
|
2024-04-30 23:53:22 -07:00
|
|
|
const { log, output } = require('proc-log')
|
2021-04-29 16:30:06 -04:00
|
|
|
const noTTY = require('./no-tty.js')
|
|
|
|
|
|
|
|
const run = async ({
|
|
|
|
args,
|
|
|
|
call,
|
|
|
|
flatOptions,
|
|
|
|
locationMsg,
|
|
|
|
path,
|
2022-08-04 21:23:58 -07:00
|
|
|
binPaths,
|
2021-04-29 16:30:06 -04:00
|
|
|
runPath,
|
|
|
|
scriptShell,
|
|
|
|
}) => {
|
|
|
|
// 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
|
2024-04-30 23:53:22 -07:00
|
|
|
const realPkg = await readPackageJson(`${path}/package.json`).catch(() => ({}))
|
2021-04-29 16:30:06 -04:00
|
|
|
const pkg = {
|
|
|
|
...realPkg,
|
|
|
|
scripts: {
|
|
|
|
...(realPkg.scripts || {}),
|
|
|
|
npx: script,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2024-04-30 23:53:22 -07:00
|
|
|
if (script === scriptShell) {
|
|
|
|
if (!noTTY()) {
|
|
|
|
if (ciInfo.isCI) {
|
|
|
|
return log.warn('exec', 'Interactive mode disabled in CI environment')
|
|
|
|
}
|
2021-04-29 16:30:06 -04:00
|
|
|
|
2024-04-30 23:53:22 -07:00
|
|
|
const { chalk } = flatOptions
|
2021-04-29 16:30:06 -04:00
|
|
|
|
2024-04-30 23:53:22 -07:00
|
|
|
output.standard(`${
|
|
|
|
chalk.reset('\nEntering npm script environment')
|
|
|
|
}${
|
|
|
|
chalk.reset(locationMsg || ` at location:\n${chalk.dim(runPath)}`)
|
|
|
|
}${
|
|
|
|
chalk.bold('\nType \'exit\' or ^D when finished\n')
|
|
|
|
}`)
|
2021-04-29 16:30:06 -04:00
|
|
|
}
|
|
|
|
}
|
2024-04-30 23:53:22 -07:00
|
|
|
return runScript({
|
|
|
|
...flatOptions,
|
|
|
|
pkg,
|
|
|
|
// we always run in cwd, not --prefix
|
|
|
|
path: runPath,
|
|
|
|
binPaths,
|
|
|
|
event: 'npx',
|
|
|
|
args,
|
|
|
|
stdio: 'inherit',
|
|
|
|
scriptShell,
|
|
|
|
})
|
2021-04-29 16:30:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = run
|