diff --git a/lib/run-script.js b/lib/run-script.js index 4d27e8eed965e..568a5712f6ac7 100644 --- a/lib/run-script.js +++ b/lib/run-script.js @@ -1,4 +1,5 @@ const run = require('@npmcli/run-script') +const { isServerPackage } = run const npm = require('./npm.js') const readJson = require('read-package-json-fast') const { resolve } = require('path') @@ -45,7 +46,7 @@ const runScript = async (args) => { pkg.scripts = scripts - if (!scripts[event]) { + if (!scripts[event] && !(event === 'start' && await isServerPackage(path))) { if (npm.config.get('if-present')) return diff --git a/test/lib/run-script.js b/test/lib/run-script.js index 7a034aff01561..7ddb6ff6f63a5 100644 --- a/test/lib/run-script.js +++ b/test/lib/run-script.js @@ -25,9 +25,11 @@ const output = [] const npmlog = { level: 'warn' } const getRS = windows => requireInject('../../lib/run-script.js', { - '@npmcli/run-script': async opts => { + '@npmcli/run-script': Object.assign(async opts => { RUN_SCRIPTS.push(opts) - }, + }, { + isServerPackage: require('@npmcli/run-script').isServerPackage, + }), npmlog, '../../lib/npm.js': npm, '../../lib/utils/is-windows-shell.js': windows, @@ -90,10 +92,29 @@ t.test('fail if no package.json', async t => { await runScript(['test'], er => t.match(er, { code: 'ENOENT' })) }) -t.test('default env and restart scripts', async t => { +t.test('default env, start, and restart scripts', async t => { npm.localPrefix = t.testdir({ - 'package.json': JSON.stringify({ name: 'x', version: '1.2.3' }) + 'package.json': JSON.stringify({ name: 'x', version: '1.2.3' }), + 'server.js': 'console.log("hello, world")', + }) + + await runScript(['start'], er => { + if (er) { + throw er + } + t.match(RUN_SCRIPTS, [ + { + path: npm.localPrefix, + args: [], + scriptShell: undefined, + stdio: 'inherit', + stdioString: true, + pkg: { name: 'x', version: '1.2.3', _id: 'x@1.2.3', scripts: {}}, + event: 'start' + } + ]) }) + RUN_SCRIPTS.length = 0 await runScript(['env'], er => { if (er) {