-
-
Notifications
You must be signed in to change notification settings - Fork 933
/
aliases.ts
116 lines (100 loc) · 3.92 KB
/
aliases.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
112
113
114
115
116
import { LOCKFILE_VERSION_V6 as LOCKFILE_VERSION } from '@pnpm/constants'
import { prepareEmpty } from '@pnpm/prepare'
import { addDistTag, getIntegrity } from '@pnpm/registry-mock'
import { addDependenciesToPackage } from '@pnpm/core'
import { testDefaults } from '../utils'
test('installing aliased dependency', async () => {
const project = prepareEmpty()
await addDependenciesToPackage({}, ['negative@npm:is-negative@1.0.0', 'positive@npm:is-positive'], await testDefaults({ fastUnpack: false }))
const m = project.requireModule('negative')
expect(typeof m).toBe('function')
expect(typeof project.requireModule('positive')).toBe('function')
expect(await project.readLockfile()).toStrictEqual({
settings: {
autoInstallPeers: true,
excludeLinksFromLockfile: false,
},
dependencies: {
negative: {
specifier: 'npm:is-negative@1.0.0',
version: '/is-negative@1.0.0',
},
positive: {
specifier: 'npm:is-positive@^3.1.0',
version: '/is-positive@3.1.0',
},
},
lockfileVersion: LOCKFILE_VERSION,
packages: {
'/is-negative@1.0.0': {
dev: false,
engines: {
node: '>=0.10.0',
},
resolution: {
integrity: 'sha512-1aKMsFUc7vYQGzt//8zhkjRWPoYkajY/I5MJEvrc0pDoHXrW7n5ri8DYxhy3rR+Dk0QFl7GjHHsZU1sppQrWtw==',
},
},
'/is-positive@3.1.0': {
dev: false,
engines: {
node: '>=0.10.0',
},
resolution: {
integrity: 'sha512-8ND1j3y9/HP94TOvGzr69/FgbkX2ruOldhLEsTWwcJVfo4oRjwemJmJxt7RJkKYH8tz7vYBP9JcKQY8CLuJ90Q==',
},
},
},
})
})
test('aliased dependency w/o version spec, with custom tag config', async () => {
const project = prepareEmpty()
const tag = 'beta'
await addDistTag({ package: '@pnpm.e2e/dep-of-pkg-with-1-dep', version: '100.1.0', distTag: 'latest' })
await addDistTag({ package: '@pnpm.e2e/dep-of-pkg-with-1-dep', version: '100.0.0', distTag: tag })
await addDependenciesToPackage({}, ['foo@npm:@pnpm.e2e/dep-of-pkg-with-1-dep'], await testDefaults({ tag }))
await project.storeHas('@pnpm.e2e/dep-of-pkg-with-1-dep', '100.0.0')
})
test('a dependency has an aliased subdependency', async () => {
await addDistTag({ package: '@pnpm.e2e/dep-of-pkg-with-1-dep', version: '100.1.0', distTag: 'latest' })
const project = prepareEmpty()
await addDependenciesToPackage({}, ['@pnpm.e2e/pkg-with-1-aliased-dep'], await testDefaults({ fastUnpack: false }))
expect(project.requireModule('@pnpm.e2e/pkg-with-1-aliased-dep')().name).toEqual('@pnpm.e2e/dep-of-pkg-with-1-dep')
expect(await project.readLockfile()).toStrictEqual({
settings: {
autoInstallPeers: true,
excludeLinksFromLockfile: false,
},
dependencies: {
'@pnpm.e2e/pkg-with-1-aliased-dep': {
specifier: '^100.0.0',
version: '100.0.0',
},
},
lockfileVersion: LOCKFILE_VERSION,
packages: {
'/@pnpm.e2e/dep-of-pkg-with-1-dep@100.1.0': {
dev: false,
resolution: {
integrity: getIntegrity('@pnpm.e2e/dep-of-pkg-with-1-dep', '100.1.0'),
},
},
'/@pnpm.e2e/pkg-with-1-aliased-dep@100.0.0': {
dependencies: {
dep: '/@pnpm.e2e/dep-of-pkg-with-1-dep@100.1.0',
},
dev: false,
resolution: {
integrity: getIntegrity('@pnpm.e2e/pkg-with-1-aliased-dep', '100.0.0'),
},
},
},
})
})
test('installing the same package via an alias and directly', async () => {
const project = prepareEmpty()
const manifest = await addDependenciesToPackage({}, ['negative@npm:is-negative@^1.0.1', 'is-negative@^1.0.1'], await testDefaults({ fastUnpack: false }))
expect(manifest.dependencies).toStrictEqual({ negative: 'npm:is-negative@^1.0.1', 'is-negative': '^1.0.1' })
expect(typeof project.requireModule('negative')).toEqual('function')
expect(typeof project.requireModule('is-negative')).toEqual('function')
})