UNPKG

1.06 kBJavaScriptView Raw
1// npm package dependency
2module.exports = class Package {
3 constructor(opts) {
4 if (!opts) {
5 throw new Error('missing package options, use "packageName" or {name: "packageName", ...}');
6 }
7
8 if (typeof opts === 'string') {
9 this.name = opts;
10 } else {
11 this.name = opts.name;
12 }
13
14 if (!this.name) {
15 throw new Error('not a valid package options, use "packageName" or {name: "packageName", ...}');
16 }
17
18 this.location = (typeof opts.location === 'string') ? opts.location : undefined;
19 this.main = (typeof opts.main === 'string') ? opts.main : undefined;
20 this.version = (typeof opts.version === 'string') ? opts.version : undefined;
21 this.lazyMain = !!opts.lazyMain;
22
23 const deps = Array.isArray(opts.deps) ? opts.deps : undefined;
24 const _exports = (typeof opts.exports === 'string') ? opts.exports : undefined;
25 const wrapShim = !!opts.wrapShim;
26
27 if (deps || _exports) {
28 this.shim = {
29 deps: deps,
30 'exports': _exports,
31 wrapShim: wrapShim
32 };
33 }
34 }
35};