1- const { resolve } = require ( 'path' )
21const runScript = require ( '@npmcli/run-script' )
32const { isServerPackage } = runScript
4- const rpj = require ( 'read- package-json-fast ' )
3+ const pkgJson = require ( '@npmcli/ package-json' )
54const log = require ( '../utils/log-shim.js' )
65const didYouMean = require ( '../utils/did-you-mean.js' )
76const { isWindowsShell } = require ( '../utils/is-windows.js' )
@@ -39,9 +38,8 @@ class RunScript extends BaseCommand {
3938 async completion ( opts ) {
4039 const argv = opts . conf . argv . remain
4140 if ( argv . length === 2 ) {
42- // find the script name
43- const json = resolve ( this . npm . localPrefix , 'package.json' )
44- const { scripts = { } } = await rpj ( json ) . catch ( er => ( { } ) )
41+ const { content : { scripts = { } } } = await pkgJson . normalize ( this . npm . localPrefix )
42+ . catch ( er => ( { content : { } } ) )
4543 if ( opts . isFish ) {
4644 return Object . keys ( scripts ) . map ( s => `${ s } \t${ scripts [ s ] . slice ( 0 , 30 ) } ` )
4745 }
@@ -70,7 +68,10 @@ class RunScript extends BaseCommand {
7068 // null value
7169 const scriptShell = this . npm . config . get ( 'script-shell' ) || undefined
7270
73- pkg = pkg || ( await rpj ( `${ path } /package.json` ) )
71+ if ( ! pkg ) {
72+ const { content } = await pkgJson . normalize ( path )
73+ pkg = content
74+ }
7475 const { scripts = { } } = pkg
7576
7677 if ( event === 'restart' && ! scripts . restart ) {
@@ -126,8 +127,8 @@ class RunScript extends BaseCommand {
126127 }
127128
128129 async list ( args , path ) {
129- path = path || this . npm . localPrefix
130- const { scripts, name, _id } = await rpj ( ` ${ path } /package.json` )
130+ /* eslint-disable-next-line max-len */
131+ const { content : { scripts, name, _id } } = await pkgJson . normalize ( path || this . npm . localPrefix )
131132 const pkgid = _id || name
132133
133134 if ( ! scripts ) {
@@ -197,7 +198,7 @@ class RunScript extends BaseCommand {
197198 await this . setWorkspaces ( )
198199
199200 for ( const workspacePath of this . workspacePaths ) {
200- const pkg = await rpj ( ` ${ workspacePath } /package.json` )
201+ const { content : pkg } = await pkgJson . normalize ( workspacePath )
201202 const runResult = await this . run ( args , {
202203 path : workspacePath ,
203204 pkg,
@@ -236,7 +237,7 @@ class RunScript extends BaseCommand {
236237 if ( this . npm . config . get ( 'json' ) ) {
237238 const res = { }
238239 for ( const workspacePath of this . workspacePaths ) {
239- const { scripts, name } = await rpj ( ` ${ workspacePath } /package.json` )
240+ const { content : { scripts, name } } = await pkgJson . normalize ( workspacePath )
240241 res [ name ] = { ...scripts }
241242 }
242243 this . npm . output ( JSON . stringify ( res , null , 2 ) )
@@ -245,7 +246,7 @@ class RunScript extends BaseCommand {
245246
246247 if ( this . npm . config . get ( 'parseable' ) ) {
247248 for ( const workspacePath of this . workspacePaths ) {
248- const { scripts, name } = await rpj ( ` ${ workspacePath } /package.json` )
249+ const { content : { scripts, name } } = await pkgJson . normalize ( workspacePath )
249250 for ( const [ script , cmd ] of Object . entries ( scripts || { } ) ) {
250251 this . npm . output ( `${ name } :${ script } :${ cmd } ` )
251252 }
0 commit comments