File tree Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -54,7 +54,12 @@ class Init extends BaseCommand {
5454 // reads package.json for the top-level folder first, by doing this we
5555 // ensure the command throw if no package.json is found before trying
5656 // to create a workspace package.json file or its folders
57- const pkg = await rpj ( resolve ( this . npm . localPrefix , 'package.json' ) )
57+ const pkg = await rpj ( resolve ( this . npm . localPrefix , 'package.json' ) ) . catch ( ( err ) => {
58+ if ( err . code === 'ENOENT' ) {
59+ log . warn ( 'Missing package.json. Try with `--include-workspace-root`.' )
60+ }
61+ throw err
62+ } )
5863
5964 // these are workspaces that are being created, so we cant use
6065 // this.setWorkspaces()
Original file line number Diff line number Diff line change @@ -335,7 +335,7 @@ t.test('workspaces', async t => {
335335 } )
336336
337337 await t . test ( 'missing top-level package.json when settting workspace' , async t => {
338- const { npm } = await mockNpm ( t , {
338+ const { npm, logs } = await mockNpm ( t , {
339339 config : { workspace : 'a' } ,
340340 } )
341341
@@ -344,6 +344,25 @@ t.test('workspaces', async t => {
344344 { code : 'ENOENT' } ,
345345 'should exit with missing package.json file error'
346346 )
347+
348+ t . equal ( logs . warn [ 0 ] [ 0 ] , 'Missing package.json. Try with `--include-workspace-root`.' )
349+ } )
350+
351+ await t . test ( 'bad package.json when settting workspace' , async t => {
352+ const { npm, logs } = await mockNpm ( t , {
353+ prefixDir : {
354+ 'package.json' : '{{{{' ,
355+ } ,
356+ config : { workspace : 'a' } ,
357+ } )
358+
359+ await t . rejects (
360+ npm . exec ( 'init' , [ ] ) ,
361+ { code : 'EJSONPARSE' } ,
362+ 'should exit with parse file error'
363+ )
364+
365+ t . strictSame ( logs . warn , [ ] )
347366 } )
348367
349368 await t . test ( 'using args - no package.json' , async t => {
You can’t perform that action at this time.
0 commit comments