/
prune.ts
111 lines (96 loc) · 2.55 KB
/
prune.ts
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import path from 'path'
import { add, install, link, prune } from '@pnpm/plugin-commands-installation'
import { prepare } from '@pnpm/prepare'
import { REGISTRY_MOCK_PORT } from '@pnpm/registry-mock'
import { fixtures } from '@pnpm/test-fixtures'
const REGISTRY_URL = `http://localhost:${REGISTRY_MOCK_PORT}`
const f = fixtures(__dirname)
const DEFAULT_OPTIONS = {
argv: {
original: [],
},
bail: false,
bin: 'node_modules/.bin',
extraEnv: {},
cliOptions: {},
deployAllFiles: false,
include: {
dependencies: true,
devDependencies: true,
optionalDependencies: true,
},
lock: true,
linkWorkspacePackages: true,
pnpmfile: '.pnpmfile.cjs',
pnpmHomeDir: '',
rawConfig: { registry: REGISTRY_URL },
rawLocalConfig: { registry: REGISTRY_URL },
registries: {
default: REGISTRY_URL,
},
sort: true,
userConfig: {},
workspaceConcurrency: 1,
}
test('prune removes external link that is not in package.json', async () => {
const project = prepare(undefined)
const storeDir = path.resolve('store')
f.copy('local-pkg', 'local')
await link.handler({
...DEFAULT_OPTIONS,
cacheDir: path.resolve('cache'),
dir: process.cwd(),
storeDir,
}, ['./local'])
await project.has('local-pkg')
await prune.handler({
...DEFAULT_OPTIONS,
cacheDir: path.resolve('cache'),
dir: process.cwd(),
storeDir,
})
await project.hasNot('local-pkg')
})
test('prune keeps hoisted dependencies', async () => {
const project = prepare(undefined)
const storeDir = path.resolve('store')
const cacheDir = path.resolve('cache')
await add.handler({
...DEFAULT_OPTIONS,
cacheDir,
dir: process.cwd(),
storeDir,
}, ['@pnpm.e2e/pkg-with-1-dep@100.0.0'])
await prune.handler({
...DEFAULT_OPTIONS,
cacheDir,
dir: process.cwd(),
storeDir,
})
await project.hasNot('@pnpm.e2e/dep-of-pkg-with-1-dep')
})
test('prune removes dev dependencies', async () => {
const project = prepare({
dependencies: { 'is-positive': '1.0.0' },
devDependencies: { 'is-negative': '1.0.0' },
})
const storeDir = path.resolve('store')
await install.handler({
...DEFAULT_OPTIONS,
cacheDir: path.resolve('cache'),
dir: process.cwd(),
linkWorkspacePackages: true,
storeDir,
})
await prune.handler({
...DEFAULT_OPTIONS,
cacheDir: path.resolve('cache'),
dev: false,
dir: process.cwd(),
storeDir,
})
await project.has('is-positive')
await project.has('.pnpm/is-positive@1.0.0')
await project.hasNot('is-negative')
await project.hasNot('.pnpm/is-negative@1.0.0')
})