11cb0ef41Sopenharmony_ciconst ciInfo = require('ci-info') 21cb0ef41Sopenharmony_ciconst runScript = require('@npmcli/run-script') 31cb0ef41Sopenharmony_ciconst readPackageJson = require('read-package-json-fast') 41cb0ef41Sopenharmony_ciconst npmlog = require('npmlog') 51cb0ef41Sopenharmony_ciconst log = require('proc-log') 61cb0ef41Sopenharmony_ciconst noTTY = require('./no-tty.js') 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciconst run = async ({ 91cb0ef41Sopenharmony_ci args, 101cb0ef41Sopenharmony_ci call, 111cb0ef41Sopenharmony_ci flatOptions, 121cb0ef41Sopenharmony_ci locationMsg, 131cb0ef41Sopenharmony_ci output = () => {}, 141cb0ef41Sopenharmony_ci path, 151cb0ef41Sopenharmony_ci binPaths, 161cb0ef41Sopenharmony_ci runPath, 171cb0ef41Sopenharmony_ci scriptShell, 181cb0ef41Sopenharmony_ci}) => { 191cb0ef41Sopenharmony_ci // turn list of args into command string 201cb0ef41Sopenharmony_ci const script = call || args.shift() || scriptShell 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ci // do the fakey runScript dance 231cb0ef41Sopenharmony_ci // still should work if no package.json in cwd 241cb0ef41Sopenharmony_ci const realPkg = await readPackageJson(`${path}/package.json`) 251cb0ef41Sopenharmony_ci .catch(() => ({})) 261cb0ef41Sopenharmony_ci const pkg = { 271cb0ef41Sopenharmony_ci ...realPkg, 281cb0ef41Sopenharmony_ci scripts: { 291cb0ef41Sopenharmony_ci ...(realPkg.scripts || {}), 301cb0ef41Sopenharmony_ci npx: script, 311cb0ef41Sopenharmony_ci }, 321cb0ef41Sopenharmony_ci } 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci npmlog.disableProgress() 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ci try { 371cb0ef41Sopenharmony_ci if (script === scriptShell) { 381cb0ef41Sopenharmony_ci if (!noTTY()) { 391cb0ef41Sopenharmony_ci if (ciInfo.isCI) { 401cb0ef41Sopenharmony_ci return log.warn('exec', 'Interactive mode disabled in CI environment') 411cb0ef41Sopenharmony_ci } 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ci locationMsg = locationMsg || ` at location:\n${flatOptions.chalk.dim(runPath)}` 441cb0ef41Sopenharmony_ci 451cb0ef41Sopenharmony_ci output(`${ 461cb0ef41Sopenharmony_ci flatOptions.chalk.reset('\nEntering npm script environment') 471cb0ef41Sopenharmony_ci }${ 481cb0ef41Sopenharmony_ci flatOptions.chalk.reset(locationMsg) 491cb0ef41Sopenharmony_ci }${ 501cb0ef41Sopenharmony_ci flatOptions.chalk.bold('\nType \'exit\' or ^D when finished\n') 511cb0ef41Sopenharmony_ci }`) 521cb0ef41Sopenharmony_ci } 531cb0ef41Sopenharmony_ci } 541cb0ef41Sopenharmony_ci return await runScript({ 551cb0ef41Sopenharmony_ci ...flatOptions, 561cb0ef41Sopenharmony_ci pkg, 571cb0ef41Sopenharmony_ci banner: false, 581cb0ef41Sopenharmony_ci // we always run in cwd, not --prefix 591cb0ef41Sopenharmony_ci path: runPath, 601cb0ef41Sopenharmony_ci binPaths, 611cb0ef41Sopenharmony_ci event: 'npx', 621cb0ef41Sopenharmony_ci args, 631cb0ef41Sopenharmony_ci stdio: 'inherit', 641cb0ef41Sopenharmony_ci scriptShell, 651cb0ef41Sopenharmony_ci }) 661cb0ef41Sopenharmony_ci } finally { 671cb0ef41Sopenharmony_ci npmlog.enableProgress() 681cb0ef41Sopenharmony_ci } 691cb0ef41Sopenharmony_ci} 701cb0ef41Sopenharmony_ci 711cb0ef41Sopenharmony_cimodule.exports = run 72