-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
Copy pathlink-resolver.js
49 lines (37 loc) · 1.29 KB
/
link-resolver.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
/* @flow */
import type {Manifest} from '../../types.js';
import type {RegistryNames} from '../../registries/index.js';
import type PackageRequest from '../../package-request.js';
import ExoticResolver from './exotic-resolver.js';
import * as util from '../../util/misc.js';
import * as fs from '../../util/fs.js';
const path = require('path');
export const LINK_PROTOCOL_PREFIX = 'link:';
export default class LinkResolver extends ExoticResolver {
constructor(request: PackageRequest, fragment: string) {
super(request, fragment);
this.loc = util.removePrefix(fragment, LINK_PROTOCOL_PREFIX);
}
loc: string;
static protocol = 'link';
async resolve(): Promise<Manifest> {
let loc = this.loc;
if (!path.isAbsolute(loc)) {
loc = path.resolve(this.config.lockfileFolder, loc);
}
const name = path.basename(loc);
const registry: RegistryNames = 'npm';
const manifest: Manifest =
!await fs.exists(`${loc}/package.json`) || loc === this.config.lockfileFolder
? {_uid: '', name, version: '0.0.0', _registry: registry}
: await this.config.readManifest(loc, this.registry);
manifest._remote = {
type: 'link',
registry,
hash: null,
reference: loc,
};
manifest._uid = manifest.version;
return manifest;
}
}