-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmanifest.js
More file actions
70 lines (64 loc) · 1.74 KB
/
Copy pathmanifest.js
File metadata and controls
70 lines (64 loc) · 1.74 KB
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
import fs from "fs";
import { toPurl } from "../tools.js";
const DEFAULT_VERSION = 'v0.0.0';
export default class Manifest {
constructor(manifestPath) {
if (!manifestPath) {
throw new Error("Missing required manifest path");
}
this.manifestPath = manifestPath;
const content = this.loadManifest();
this.dependencies = this.loadDependencies(content);
this.peerDependencies = content.peerDependencies || {};
this.optionalDependencies = content.optionalDependencies || {};
this.name = content.name;
this.version = content.version || DEFAULT_VERSION;
this.ignored = this.loadIgnored(content);
}
loadManifest() {
try {
let manifest = JSON.parse(fs.readFileSync(this.manifestPath, 'utf-8'));
return manifest;} catch (err) {
if(err.code === 'ENOENT') {
throw new Error("Missing manifest file: " + this.manifestPath, {cause: err});
}
throw new Error("Unable to parse manifest: " + this.manifestPath, {cause: err});
}
}
loadDependencies(content) {
let deps = [];
const depSources = [
content.dependencies,
content.peerDependencies,
content.optionalDependencies,
];
for (const source of depSources) {
if (source) {
for (let dep in source) {
if (!deps.includes(dep)) {
deps.push(dep);
}
}
}
}
// bundledDependencies is an array of package names (subset of dependencies)
if (Array.isArray(content.bundledDependencies)) {
for (const dep of content.bundledDependencies) {
if (!deps.includes(dep)) {
deps.push(dep);
}
}
}
return deps;
}
loadIgnored(content) {
let deps = [];
if(!content.exhortignore) {
return deps;
}
for(let i = 0; i < content.exhortignore.length; i++) {
deps.push(toPurl("npm", content.exhortignore[i]));
}
return deps;
}
}