-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
is-workspace-safe.js
73 lines (66 loc) · 1.72 KB
/
is-workspace-safe.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const t = require('tap')
const isWorkspaceSafe = require('../lib/is-workspace-safe.js')
const path = require('path')
t.cleanSnapshot = s => s.replace(/\\+/g, '/')
t.test('all the potential states', async t => {
const pkg = {
name: 'foo',
}
const dir = t.testdir({
git: {
'package.json': JSON.stringify({
...pkg,
workspaces: [
'packages/a',
],
}, null, 2),
},
'git/packages/a': {
'package.json': JSON.stringify({
...pkg,
}, null, 2),
},
'git/other': {},
'not-git': {},
'git-too': {
'package.json': JSON.stringify({
...pkg,
}, null, 2),
},
'git-too/subdir': {},
})
await t.test('no git', async t => {
t.ok(await isWorkspaceSafe(
null,
`${dir}/not-git`
), 'should be safe because there is no git')
})
await t.test('is git root', async t => {
t.ok(await isWorkspaceSafe(
`${dir}/git`,
`${dir}/git`,
`${dir}/git`
), 'should be safe because cwd is git root')
})
await t.test('top level package has workspaces', async t => {
t.ok(await isWorkspaceSafe(
`${dir}/git`,
`${dir}/git`,
`${dir}/git/other`
), 'should be safe because we see the workspaces')
})
await t.test('in workspace', async t => {
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')
})
await t.test('no workspaces', async t => {
t.ok(await isWorkspaceSafe(
`${dir}/git-too`,
`${dir}/git-too`,
`${dir}/git-too/subdir`
), 'should be safe because of no workspaces')
})
})