File tree 2 files changed +26
-2
lines changed
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 {
54
54
// reads package.json for the top-level folder first, by doing this we
55
55
// ensure the command throw if no package.json is found before trying
56
56
// 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
+ } )
58
63
59
64
// these are workspaces that are being created, so we cant use
60
65
// this.setWorkspaces()
Original file line number Diff line number Diff line change @@ -335,7 +335,7 @@ t.test('workspaces', async t => {
335
335
} )
336
336
337
337
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 , {
339
339
config : { workspace : 'a' } ,
340
340
} )
341
341
@@ -344,6 +344,25 @@ t.test('workspaces', async t => {
344
344
{ code : 'ENOENT' } ,
345
345
'should exit with missing package.json file error'
346
346
)
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 , [ ] )
347
366
} )
348
367
349
368
await t . test ( 'using args - no package.json' , async t => {
You can’t perform that action at this time.
0 commit comments