1- const runScript = require ( '@npmcli/run-script' )
2- const { isServerPackage } = runScript
3- const pkgJson = require ( '@npmcli/package-json' )
41const { log, output } = require ( 'proc-log' )
5- const didYouMean = require ( '../utils/did-you-mean.js' )
6- const { isWindowsShell } = require ( '../utils/is-windows.js' )
7-
8- const cmdList = [
9- 'publish' ,
10- 'install' ,
11- 'uninstall' ,
12- 'test' ,
13- 'stop' ,
14- 'start' ,
15- 'restart' ,
16- 'version' ,
17- ] . reduce ( ( l , p ) => l . concat ( [ 'pre' + p , p , 'post' + p ] ) , [ ] )
2+ const pkgJson = require ( '@npmcli/package-json' )
183
194const BaseCommand = require ( '../base-command.js' )
205class RunScript extends BaseCommand {
@@ -64,9 +49,7 @@ class RunScript extends BaseCommand {
6449 }
6550
6651 async run ( [ event , ...args ] , { path = this . npm . localPrefix , pkg } = { } ) {
67- // this || undefined is because runScript will be unhappy with the default
68- // null value
69- const scriptShell = this . npm . config . get ( 'script-shell' ) || undefined
52+ const runScript = require ( '@npmcli/run-script' )
7053
7154 if ( ! pkg ) {
7255 const { content } = await pkgJson . normalize ( path )
@@ -77,19 +60,21 @@ class RunScript extends BaseCommand {
7760 if ( event === 'restart' && ! scripts . restart ) {
7861 scripts . restart = 'npm stop --if-present && npm start'
7962 } else if ( event === 'env' && ! scripts . env ) {
63+ const { isWindowsShell } = require ( '../utils/is-windows.js' )
8064 scripts . env = isWindowsShell ? 'SET' : 'env'
8165 }
8266
8367 pkg . scripts = scripts
8468
8569 if (
8670 ! Object . prototype . hasOwnProperty . call ( scripts , event ) &&
87- ! ( event === 'start' && ( await isServerPackage ( path ) ) )
71+ ! ( event === 'start' && ( await runScript . isServerPackage ( path ) ) )
8872 ) {
8973 if ( this . npm . config . get ( 'if-present' ) ) {
9074 return
9175 }
9276
77+ const didYouMean = require ( '../utils/did-you-mean.js' )
9378 const suggestions = await didYouMean ( path , event )
9479 throw new Error (
9580 `Missing script: "${ event } "${ suggestions } \n\nTo see a list of scripts, run:\n npm run`
@@ -111,7 +96,9 @@ class RunScript extends BaseCommand {
11196 for ( const [ ev , evArgs ] of events ) {
11297 await runScript ( {
11398 path,
114- scriptShell,
99+ // this || undefined is because runScript will be unhappy with the
100+ // default null value
101+ scriptShell : this . npm . config . get ( 'script-shell' ) || undefined ,
115102 stdio : 'inherit' ,
116103 pkg,
117104 event : ev ,
@@ -147,6 +134,17 @@ class RunScript extends BaseCommand {
147134 return allScripts
148135 }
149136
137+ // TODO this is missing things like prepare, prepublishOnly, and dependencies
138+ const cmdList = [
139+ 'preinstall' , 'install' , 'postinstall' ,
140+ 'prepublish' , 'publish' , 'postpublish' ,
141+ 'prerestart' , 'restart' , 'postrestart' ,
142+ 'prestart' , 'start' , 'poststart' ,
143+ 'prestop' , 'stop' , 'poststop' ,
144+ 'pretest' , 'test' , 'posttest' ,
145+ 'preuninstall' , 'uninstall' , 'postuninstall' ,
146+ 'preversion' , 'version' , 'postversion' ,
147+ ]
150148 const indent = '\n '
151149 const prefix = ' '
152150 const cmds = [ ]
0 commit comments