/
fromRepo.ts
176 lines (131 loc) · 5.38 KB
/
fromRepo.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import path from 'path'
import { RootLog } from '@pnpm/core-loggers'
import { prepareEmpty } from '@pnpm/prepare'
import {
addDependenciesToPackage,
install,
} from '@pnpm/core'
import isCI from 'is-ci'
import exists from 'path-exists'
import sinon from 'sinon'
import { testDefaults } from '../utils'
test('from a github repo', async () => {
const project = prepareEmpty()
const manifest = await addDependenciesToPackage({}, ['kevva/is-negative'], await testDefaults())
await project.has('is-negative')
expect(manifest.dependencies).toStrictEqual({
'is-negative': 'github:kevva/is-negative',
})
})
test('from a github repo through URL', async () => {
const project = prepareEmpty()
const manifest = await addDependenciesToPackage({}, ['https://github.com/kevva/is-negative'], await testDefaults())
await project.has('is-negative')
expect(manifest.dependencies).toStrictEqual({ 'is-negative': 'github:kevva/is-negative' })
})
test('from a github repo with different name via named installation', async () => {
const project = prepareEmpty()
const reporter = sinon.spy()
const manifest = await addDependenciesToPackage(
{},
['say-hi@github:zkochan/hi#4cdebec76b7b9d1f6e219e06c42d92a6b8ea60cd'],
await testDefaults({ fastUnpack: false, reporter })
)
const m = project.requireModule('say-hi')
expect(reporter.calledWithMatch({
added: {
dependencyType: 'prod',
name: 'say-hi',
realName: 'hi',
version: '1.0.0',
},
level: 'debug',
name: 'pnpm:root',
} as RootLog)).toBeTruthy()
expect(m).toEqual('Hi')
expect(manifest.dependencies).toStrictEqual({ 'say-hi': 'github:zkochan/hi#4cdebec76b7b9d1f6e219e06c42d92a6b8ea60cd' })
const lockfile = await project.readLockfile()
expect(lockfile.dependencies).toStrictEqual({
'say-hi': 'github.com/zkochan/hi/4cdebec76b7b9d1f6e219e06c42d92a6b8ea60cd',
})
await project.isExecutable('.bin/hi')
await project.isExecutable('.bin/szia')
})
// This used to fail. Maybe won't be needed once api/install.ts gets refactored and covered with dedicated unit tests
test('from a github repo with different name', async () => {
const project = prepareEmpty()
const reporter = sinon.spy()
const manifest = await install({
dependencies: {
'say-hi': 'github:zkochan/hi#4cdebec76b7b9d1f6e219e06c42d92a6b8ea60cd',
},
}, await testDefaults({ fastUnpack: false, reporter }))
const m = project.requireModule('say-hi')
expect(reporter.calledWithMatch({
added: {
dependencyType: 'prod',
name: 'say-hi',
realName: 'hi',
version: '1.0.0',
},
level: 'debug',
name: 'pnpm:root',
} as RootLog)).toBeTruthy()
expect(m).toBe('Hi')
expect(manifest.dependencies).toStrictEqual({
'say-hi': 'github:zkochan/hi#4cdebec76b7b9d1f6e219e06c42d92a6b8ea60cd',
})
const lockfile = await project.readLockfile()
expect(lockfile.dependencies).toStrictEqual({
'say-hi': 'github.com/zkochan/hi/4cdebec76b7b9d1f6e219e06c42d92a6b8ea60cd',
})
await project.isExecutable('.bin/hi')
await project.isExecutable('.bin/szia')
})
test('a subdependency is from a github repo with different name', async () => {
const project = prepareEmpty()
await addDependenciesToPackage({}, ['has-aliased-git-dependency'], await testDefaults({ fastUnpack: false }))
const m = project.requireModule('has-aliased-git-dependency')
expect(m).toEqual('Hi')
const lockfile = await project.readLockfile()
expect(lockfile.packages['/has-aliased-git-dependency/1.0.0'].dependencies).toStrictEqual({
'has-say-hi-peer': '1.0.0_hi@1.0.0',
'say-hi': 'github.com/zkochan/hi/4cdebec76b7b9d1f6e219e06c42d92a6b8ea60cd',
})
await project.isExecutable('has-aliased-git-dependency/node_modules/.bin/hi')
await project.isExecutable('has-aliased-git-dependency/node_modules/.bin/szia')
expect(await exists(path.resolve('node_modules/.pnpm/has-say-hi-peer@1.0.0_hi@1.0.0/node_modules/has-say-hi-peer'))).toBeTruthy()
})
test('from a git repo', async () => {
if (isCI) {
console.log('not testing the SSH GIT access via CI')
return
}
const project = prepareEmpty()
await addDependenciesToPackage({}, ['git+ssh://git@github.com/kevva/is-negative.git'], await testDefaults())
await project.has('is-negative')
})
// This test is unstable due to dependency on third party registry
// eslint-disable-next-line @typescript-eslint/dot-notation
test.skip('from a non-github git repo', async () => {
const project = prepareEmpty()
await addDependenciesToPackage({}, ['git+http://ikt.pm2.io/ikt.git#3325a3e39a502418dc2e2e4bf21529cbbde96228'], await testDefaults())
const m = project.requireModule('ikt')
expect(m).toBeTruthy()
const lockfile = await project.readLockfile()
const pkgId = 'ikt.pm2.io/ikt/3325a3e39a502418dc2e2e4bf21529cbbde96228'
expect(lockfile.packages).toHaveProperty([pkgId])
expect(lockfile.packages[pkgId].resolution).toStrictEqual({
commit: '3325a3e39a502418dc2e2e4bf21529cbbde96228',
repo: 'http://ikt.pm2.io/ikt.git',
type: 'git',
})
})
test('from a github repo the has no package.json file', async () => {
const project = prepareEmpty()
const manifest = await addDependenciesToPackage({}, ['pnpm/for-testing.no-package-json'], await testDefaults())
await project.has('for-testing.no-package-json')
expect(manifest.dependencies).toStrictEqual({
'for-testing.no-package-json': 'github:pnpm/for-testing.no-package-json',
})
})