Skip to content

Commit dc52222

Browse files
committed
fix(init): write package.json workspaces paths with / separators
This also refactors the test to use `mockNpm`
1 parent 31af1aa commit dc52222

File tree

3 files changed

+208
-333
lines changed

3 files changed

+208
-333
lines changed

lib/commands/init.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const PackageJson = require('@npmcli/package-json')
1010
const log = require('../utils/log-shim.js')
1111
const updateWorkspaces = require('../workspaces/update-workspaces.js')
1212

13+
const posixPath = p => p.split('\\').join('/')
14+
1315
const BaseCommand = require('../base-command.js')
1416

1517
class Init extends BaseCommand {
@@ -203,7 +205,7 @@ class Init extends BaseCommand {
203205
pkgJson.update({
204206
workspaces: [
205207
...(pkgJson.content.workspaces || []),
206-
relative(this.npm.localPrefix, workspacePath),
208+
posixPath(relative(this.npm.localPrefix, workspacePath)),
207209
],
208210
})
209211

tap-snapshots/test/lib/commands/init.js.test.cjs

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,25 @@
55
* Make sure to inspect the output below. Do not ignore changes!
66
*/
77
'use strict'
8-
exports[`test/lib/commands/init.js TAP npm init workspces with root > does not print helper info 1`] = `
9-
Array []
10-
`
8+
exports[`test/lib/commands/init.js TAP displays output > displays helper info 1`] = `
9+
This utility will walk you through creating a package.json file.
10+
It only covers the most common items, and tries to guess sensible defaults.
1111
12-
exports[`test/lib/commands/init.js TAP workspaces no args > should print helper info 1`] = `
13-
Array []
14-
`
12+
See \`npm help init\` for definitive documentation on these fields
13+
and exactly what they do.
14+
15+
Use \`npm install <pkg>\` afterwards to install a package and
16+
save it as a dependency in the package.json file.
1517
16-
exports[`test/lib/commands/init.js TAP workspaces no args, existing folder > should print helper info 1`] = `
17-
Array []
18+
Press ^C at any time to quit.
1819
`
1920

20-
exports[`test/lib/commands/init.js TAP workspaces post workspace-init reify > should print helper info 1`] = `
21-
Array [
22-
Array [
23-
String(
24-
25-
added 1 package in 100ms
26-
),
27-
],
28-
]
21+
exports[`test/lib/commands/init.js TAP workspaces no args -- yes > should print helper info 1`] = `
22+
23+
added 1 package in {TIME}
2924
`
3025

31-
exports[`test/lib/commands/init.js TAP workspaces post workspace-init reify > should reify tree on init ws complete 1`] = `
26+
exports[`test/lib/commands/init.js TAP workspaces no args -- yes > should reify tree on init ws complete 1`] = `
3227
{
3328
"name": "top-level",
3429
"lockfileVersion": 3,
@@ -53,7 +48,3 @@ exports[`test/lib/commands/init.js TAP workspaces post workspace-init reify > sh
5348
}
5449
5550
`
56-
57-
exports[`test/lib/commands/init.js TAP workspaces with arg but missing workspace folder > should print helper info 1`] = `
58-
Array []
59-
`

0 commit comments

Comments
 (0)