-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
Copy pathfile-resolver.js
47 lines (37 loc) · 1.19 KB
/
file-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
/* @flow */
import type {Manifest} from '../../types.js';
import type PackageRequest from '../../package-request.js';
import {MessageError} from '../../errors.js';
import ExoticResolver from './exotic-resolver.js';
import * as util from '../../util/misc.js';
import * as fs from '../../util/fs.js';
const invariant = require('invariant');
const path = require('path');
export default class FileResolver extends ExoticResolver {
constructor(request: PackageRequest, fragment: string) {
super(request, fragment);
this.loc = util.removePrefix(fragment, 'file:');
}
loc: string;
static protocol = 'file';
async resolve(): Promise<Manifest> {
let loc = this.loc;
if (!path.isAbsolute(loc)) {
loc = path.join(this.config.cwd, loc);
}
if (!(await fs.exists(loc))) {
throw new MessageError(this.reporter.lang('doesntExist', loc));
}
const manifest = await this.config.readManifest(loc, this.registry);
const registry = manifest._registry;
invariant(registry, 'expected registry');
manifest._remote = {
type: 'copy',
registry,
hash: null,
reference: loc,
};
manifest._uid = manifest.version;
return manifest;
}
}