File tree Expand file tree Collapse file tree
tap-snapshots/test/lib/commands Expand file tree Collapse file tree 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 @@ -22,29 +22,3 @@ exports[`test/lib/commands/init.js TAP workspaces no args -- yes > should print
2222
2323added 1 package in {TIME}
2424`
25-
26- exports [ `test/lib/commands/init.js TAP workspaces no args -- yes > should reify tree on init ws complete 1` ] = `
27- {
28- "name": "top-level",
29- "lockfileVersion": 3,
30- "requires": true,
31- "packages": {
32- "": {
33- "name": "top-level",
34- "workspaces": [
35- "a"
36- ]
37- },
38- "a": {
39- "version": "1.0.0",
40- "license": "ISC",
41- "devDependencies": {}
42- },
43- "node_modules/a": {
44- "resolved": "a",
45- "link": true
46- }
47- }
48- }
49-
50- `
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