Skip to content

Commit e785185

Browse files
committed
add map-workspaces to dependencies and fix linting
1 parent 0de7233 commit e785185

File tree

7 files changed

+49
-20
lines changed

7 files changed

+49
-20
lines changed

DEPENDENCIES.md

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ graph LR;
7474
libnpmteam-->npmcli-template-oss["@npmcli/template-oss"];
7575
libnpmversion-->npmcli-eslint-config["@npmcli/eslint-config"];
7676
libnpmversion-->npmcli-git["@npmcli/git"];
77+
libnpmversion-->npmcli-map-workspaces["@npmcli/map-workspaces"];
7778
libnpmversion-->npmcli-run-script["@npmcli/run-script"];
7879
libnpmversion-->npmcli-template-oss["@npmcli/template-oss"];
7980
libnpmversion-->proc-log;
@@ -409,6 +410,7 @@ graph LR;
409410
libnpmversion-->json-parse-even-better-errors;
410411
libnpmversion-->npmcli-eslint-config["@npmcli/eslint-config"];
411412
libnpmversion-->npmcli-git["@npmcli/git"];
413+
libnpmversion-->npmcli-map-workspaces["@npmcli/map-workspaces"];
412414
libnpmversion-->npmcli-run-script["@npmcli/run-script"];
413415
libnpmversion-->npmcli-template-oss["@npmcli/template-oss"];
414416
libnpmversion-->proc-log;

package-lock.json

+1
Original file line numberDiff line numberDiff line change
@@ -14119,6 +14119,7 @@
1411914119
"license": "ISC",
1412014120
"dependencies": {
1412114121
"@npmcli/git": "^3.0.0",
14122+
"@npmcli/map-workspaces": "^2.0.4",
1412214123
"@npmcli/run-script": "^4.1.3",
1412314124
"json-parse-even-better-errors": "^2.3.1",
1412414125
"proc-log": "^2.0.0",

workspaces/libnpmversion/lib/is-workspace-safe.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = async (gitDir, path, cwd = process.cwd()) => {
1212
if (cwd === gitDir) {
1313
return true
1414
}
15-
// if your path's package.json contains workspaces, you are in a top level package, not a workspace
15+
// if your path's package.json contains workspaces you are in a top level package, not a workspace
1616
var rpj = await readJson(`${path}/package.json`)
1717
if (rpj.workspaces) {
1818
return true
@@ -22,11 +22,13 @@ module.exports = async (gitDir, path, cwd = process.cwd()) => {
2222
cwd = dirname(cwd)
2323
try {
2424
rpj = await readJson(`${cwd}/package.json`)
25-
} catch(er) { continue }
26-
const workspaceMap = await mapWorkspaces({cwd, pkg: rpj})
25+
} catch (er) {
26+
continue
27+
}
28+
const workspaceMap = await mapWorkspaces({ cwd, pkg: rpj })
2729
const mapValues = [...workspaceMap.values()]
2830
if (mapValues.includes(path)) {
29-
return false
31+
return false
3032
}
3133
}
3234
return true

workspaces/libnpmversion/lib/version.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ module.exports = async (newversion, opts) => {
5858

5959
// - check if git dir is clean
6060
// returns false if we should not keep doing git stuff
61-
const doGit = gitTagVersion && Boolean(gitDir) && await enforceClean(opts) && await isWorkspaceSafe(gitDir, path)
61+
const doGit = (gitTagVersion
62+
&& Boolean(gitDir)
63+
&& await enforceClean(opts)
64+
&& await isWorkspaceSafe(gitDir, path)
65+
)
6266

6367
if (!ignoreScripts) {
6468
await runScript({

workspaces/libnpmversion/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
},
3939
"dependencies": {
4040
"@npmcli/git": "^3.0.0",
41+
"@npmcli/map-workspaces": "^2.0.4",
4142
"@npmcli/run-script": "^4.1.3",
4243
"json-parse-even-better-errors": "^2.3.1",
4344
"proc-log": "^2.0.0",

workspaces/libnpmversion/test/is-workspace-safe.js

+31-12
Original file line numberDiff line numberDiff line change
@@ -9,46 +9,65 @@ t.test('all the potential states', async t => {
99
name: 'foo'
1010
}
1111
const dir = t.testdir({
12-
'git': {
12+
git: {
1313
'package.json': JSON.stringify({
1414
...pkg,
1515
workspaces: [
16-
"packages/a"
17-
]
16+
'packages/a',
17+
],
1818
}, null, 2),
1919
},
2020
'git/packages/a': {
2121
'package.json': JSON.stringify({
22-
...pkg
22+
...pkg,
2323
}, null, 2),
2424
},
2525
'git/other': {},
2626
'not-git': {},
2727
'git-too': {
2828
'package.json': JSON.stringify({
29-
...pkg
29+
...pkg,
3030
}, null, 2),
3131
},
32-
'git-too/subdir': {}
32+
'git-too/subdir': {},
3333
})
3434

3535
await t.test('no git', async t => {
36-
t.ok(await isWorkspaceSafe(null, `${dir}/not-git`), 'should be safe because there is no git')
36+
t.ok(await isWorkspaceSafe(
37+
null,
38+
`${dir}/not-git`
39+
), 'should be safe because there is no git')
3740
})
3841

3942
await t.test('is git root', async t => {
40-
t.ok(await isWorkspaceSafe(`${dir}/git`, `${dir}/git`, `${dir}/git`), 'should be safe because cwd is git root')
43+
t.ok(await isWorkspaceSafe(
44+
`${dir}/git`,
45+
`${dir}/git`,
46+
`${dir}/git`
47+
), 'should be safe because cwd is git root')
4148
})
4249

4350
await t.test('top level package has workspaces', async t => {
44-
t.ok(await isWorkspaceSafe(`${dir}/git`, `${dir}/git`, `${dir}/git/other`), 'should be safe because we see the workspaces')
51+
t.ok(await isWorkspaceSafe(
52+
`${dir}/git`,
53+
`${dir}/git`,
54+
`${dir}/git/other`
55+
), 'should be safe because we see the workspaces')
4556
})
4657

4758
await t.test('in workspace', async t => {
48-
t.notOk(await isWorkspaceSafe(`${dir}/git`, `${dir}${path.sep}git${path.sep}packages${path.sep}a`, `${dir}${path.sep}git${path.sep}packages${path.sep}a`), 'should return false for being in a workspace')
59+
t.notOk(await isWorkspaceSafe(
60+
`${dir}/git`,
61+
`${dir}${path.sep}git${path.sep}packages${path.sep}a`,
62+
`${dir}${path.sep}git${path.sep}packages${path.sep}a`
63+
), 'should return false for being in a workspace')
4964
})
5065

51-
await t.test('no workspaces', async t=> {
52-
t.ok(await isWorkspaceSafe(`${dir}/git-too`, `${dir}/git-too`, `${dir}/git-too/subdir`), 'should be safe because of no workspaces')
66+
await t.test('no workspaces', async t => {
67+
t.ok(await isWorkspaceSafe(
68+
`${dir}/git-too`,
69+
`${dir}/git-too`,
70+
`${dir}/git-too/subdir`
71+
), 'should be safe because of no workspaces')
5372
})
5473
})

workspaces/libnpmversion/test/version.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ t.test('test out bumping the version in all the ways', async t => {
4444
'package.json': JSON.stringify({
4545
...pkg,
4646
workspaces: [
47-
"packages/a"
47+
'packages/a',
4848
],
4949
}, null, 2),
5050
'package-lock.json': JSON.stringify(lock, null, 2),
@@ -65,8 +65,8 @@ t.test('test out bumping the version in all the ways', async t => {
6565
'package.json': JSON.stringify({
6666
...pkg,
6767
workspaces: [
68-
"packages/b"
69-
]
68+
'packages/b',
69+
],
7070
}, null, 2),
7171
},
7272
'not-git/packages/b': {

0 commit comments

Comments
 (0)