-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
package-request.js
91 lines (76 loc) · 3.02 KB
/
package-request.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/* @flow */
import PackageRequest from '../src/package-request.js';
import * as reporters from '../src/reporters/index.js';
import PackageResolver from '../src/package-resolver.js';
import Lockfile from '../src/lockfile';
import Config from '../src/config.js';
async function prepareRequest(pattern: string, version: string, resolved: string, parentRequest?: Object): Object {
const privateDepCache = {[pattern]: {version, resolved}};
const reporter = new reporters.NoopReporter({});
const depRequestPattern = {
pattern,
registry: 'npm',
hint: null,
optional: false,
parentNames: [],
parentRequest,
};
if (parentRequest) {
depRequestPattern.parentRequest = parentRequest;
depRequestPattern.parentNames = [...parentRequest.parentNames, parentRequest.pattern];
const lock = parentRequest.getLocked();
privateDepCache[parentRequest.pattern] = {version: lock.version, resolved: lock._remote.resolved};
}
const lockfile = new Lockfile({cache: privateDepCache});
const config = await Config.create({}, reporter);
const resolver = new PackageResolver(config, lockfile);
const request = new PackageRequest(depRequestPattern, resolver);
return {request, reporter};
}
test('Produce valid remote type for a git-over-ssh dep', async () => {
const {request, reporter} = await prepareRequest(
'private-dep@github:yarnpkg/private-dep#1.0.0',
'1.0.0',
'git+ssh://[email protected]/yarnpkg/private-dep.git#d6c57894210c52be02da7859dbb5205feb85d8b0',
);
expect(request.getLocked('git')._remote.type).toBe('git');
expect(request.getLocked('tarball')._remote.type).toBe('git');
await reporter.close();
});
test('Produce valid remote type for a git-over-https dep', async () => {
const {request, reporter} = await prepareRequest(
'public-dep@yarnpkg/public-dep#1.0.0',
'1.0.0',
'git+https://github.com/yarnpkg/public-dep#1fde368',
);
expect(request.getLocked('git')._remote.type).toBe('git');
expect(request.getLocked('tarball')._remote.type).toBe('git');
await reporter.close();
});
test('Produce valid remote type for a git public dep', async () => {
const {request, reporter} = await prepareRequest(
'public-dep@yarnpkg/public-dep#1fde368',
'1.0.0',
'https://codeload.github.com/yarnpkg/public-dep/tar.gz/1fde368',
);
expect(request.getLocked('git')._remote.type).toBe('git');
expect(request.getLocked('tarball')._remote.type).toBe('tarball');
await reporter.close();
});
test('Check parentNames flowing in the request', async () => {
const {request: parentRequest, reporter: parentReporter} = await prepareRequest(
'1.0.0',
'git+ssh://[email protected]/yarnpkg/parent.git',
);
expect(parentRequest).not.toBeNull();
const {request: childRequest, reporter: childReporter} = await prepareRequest(
'1.0.0',
'git+ssh://[email protected]/yarnpkg/child.git',
parentRequest,
);
expect(childRequest.parentNames).toContain(parentRequest.pattern);
await parentReporter.close();
await childReporter.close();
});