@repometry/lockparse 0.0.0-dev.0 → 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +50 -3
- package/package.json +22 -3
- package/target/main/ts/formats/bundler-gemfile.d.ts +1 -0
- package/target/main/ts/formats/bundler-gemfile.js +191 -0
- package/target/main/ts/formats/bundler-lock.d.ts +26 -0
- package/target/main/ts/formats/bundler-lock.js +110 -0
- package/target/main/ts/formats/bundler.d.ts +3 -0
- package/target/main/ts/formats/bundler.js +84 -0
- package/target/main/ts/formats/cargo-lock.d.ts +15 -0
- package/target/main/ts/formats/cargo-lock.js +127 -0
- package/target/main/ts/formats/cargo-manifest.d.ts +25 -0
- package/target/main/ts/formats/cargo-manifest.js +146 -0
- package/target/main/ts/formats/cargo-roots.d.ts +10 -0
- package/target/main/ts/formats/cargo-roots.js +116 -0
- package/target/main/ts/formats/cargo.d.ts +3 -0
- package/target/main/ts/formats/cargo.js +108 -0
- package/target/main/ts/formats/carton.d.ts +3 -0
- package/target/main/ts/formats/carton.js +127 -0
- package/target/main/ts/formats/composer.d.ts +3 -0
- package/target/main/ts/formats/composer.js +112 -0
- package/target/main/ts/formats/conan-reference.d.ts +11 -0
- package/target/main/ts/formats/conan-reference.js +32 -0
- package/target/main/ts/formats/conan.d.ts +3 -0
- package/target/main/ts/formats/conan.js +138 -0
- package/target/main/ts/formats/dart.d.ts +3 -0
- package/target/main/ts/formats/dart.js +122 -0
- package/target/main/ts/formats/go-mod.d.ts +28 -0
- package/target/main/ts/formats/go-mod.js +148 -0
- package/target/main/ts/formats/go.d.ts +3 -0
- package/target/main/ts/formats/go.js +74 -0
- package/target/main/ts/formats/gradle.d.ts +3 -0
- package/target/main/ts/formats/gradle.js +42 -0
- package/target/main/ts/formats/lines.d.ts +5 -0
- package/target/main/ts/formats/lines.js +12 -0
- package/target/main/ts/formats/mix-literals.d.ts +22 -0
- package/target/main/ts/formats/mix-literals.js +145 -0
- package/target/main/ts/formats/mix.d.ts +3 -0
- package/target/main/ts/formats/mix.js +90 -0
- package/target/main/ts/formats/nuget.d.ts +3 -0
- package/target/main/ts/formats/nuget.js +112 -0
- package/target/main/ts/formats/pdm.d.ts +3 -0
- package/target/main/ts/formats/pdm.js +52 -0
- package/target/main/ts/formats/pipenv.d.ts +3 -0
- package/target/main/ts/formats/pipenv.js +151 -0
- package/target/main/ts/formats/poetry-lock.d.ts +15 -0
- package/target/main/ts/formats/poetry-lock.js +68 -0
- package/target/main/ts/formats/poetry.d.ts +3 -0
- package/target/main/ts/formats/poetry.js +9 -0
- package/target/main/ts/formats/python-graph.d.ts +16 -0
- package/target/main/ts/formats/python-graph.js +91 -0
- package/target/main/ts/formats/python-package.d.ts +15 -0
- package/target/main/ts/formats/python-package.js +63 -0
- package/target/main/ts/formats/python-project.d.ts +12 -0
- package/target/main/ts/formats/python-project.js +76 -0
- package/target/main/ts/formats/renv.d.ts +3 -0
- package/target/main/ts/formats/renv.js +93 -0
- package/target/main/ts/formats/swift.d.ts +3 -0
- package/target/main/ts/formats/swift.js +87 -0
- package/target/main/ts/formats/terraform.d.ts +3 -0
- package/target/main/ts/formats/terraform.js +85 -0
- package/target/main/ts/formats/toml-document.d.ts +11 -0
- package/target/main/ts/formats/toml-document.js +79 -0
- package/target/main/ts/formats/toml-statements.d.ts +13 -0
- package/target/main/ts/formats/toml-statements.js +144 -0
- package/target/main/ts/formats/toml-values.d.ts +12 -0
- package/target/main/ts/formats/toml-values.js +111 -0
- package/target/main/ts/formats/uv-lock.d.ts +27 -0
- package/target/main/ts/formats/uv-lock.js +80 -0
- package/target/main/ts/formats/uv.d.ts +3 -0
- package/target/main/ts/formats/uv.js +114 -0
- package/target/main/ts/index.d.ts +12 -0
- package/target/main/ts/index.js +65 -0
- package/target/main/ts/json-spans.d.ts +11 -0
- package/target/main/ts/json-spans.js +86 -0
- package/target/main/ts/json.d.ts +2 -0
- package/target/main/ts/json.js +29 -0
- package/target/main/ts/model.d.ts +47 -0
- package/target/main/ts/model.js +2 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export function recipe(value) {
|
|
2
|
+
if (typeof value !== 'string')
|
|
3
|
+
throw new Error('Expected a Conan recipe reference');
|
|
4
|
+
const match = /^([A-Za-z0-9_.+-]+)\/([A-Za-z0-9_.+-]+)(?:@([A-Za-z0-9_.+-]+)(?:\/([A-Za-z0-9_.+-]+))?)?(?:#([A-Za-z0-9_.+-]+)(?:%\d+(?:\.\d+)?)?)?$/.exec(value);
|
|
5
|
+
if (!match)
|
|
6
|
+
throw new Error('Invalid Conan recipe reference');
|
|
7
|
+
return { name: match[1], version: match[2], user: match[3], channel: match[4], revision: match[5] };
|
|
8
|
+
}
|
|
9
|
+
export function binaryField(value) {
|
|
10
|
+
if (value === undefined || value === null || value === '')
|
|
11
|
+
return undefined;
|
|
12
|
+
if (typeof value !== 'string' || !/^[A-Za-z0-9_.+-]+$/.test(value))
|
|
13
|
+
throw new Error('Invalid Conan binary pin');
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
export function coordinate({ name, version, user, channel, revision }, packageId, packageRevision) {
|
|
17
|
+
const qualifiers = new URLSearchParams();
|
|
18
|
+
if (channel !== undefined)
|
|
19
|
+
qualifiers.set('channel', channel);
|
|
20
|
+
if (packageId !== undefined)
|
|
21
|
+
qualifiers.set('package_id', packageId);
|
|
22
|
+
if (packageRevision !== undefined)
|
|
23
|
+
qualifiers.set('prev', packageRevision);
|
|
24
|
+
if (revision !== undefined)
|
|
25
|
+
qualifiers.set('rrev', revision);
|
|
26
|
+
if (user !== undefined)
|
|
27
|
+
qualifiers.set('user', user);
|
|
28
|
+
const query = qualifiers.toString();
|
|
29
|
+
const id = 'pkg:conan/' + encodeURIComponent(name) + '@' + encodeURIComponent(version) + (query === '' ? '' : '?' + query);
|
|
30
|
+
return { id, name, version };
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=conan-reference.js.map
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { isRecord, readJson } from '../json.js';
|
|
2
|
+
import { locateJsonSpans, pointer } from '../json-spans.js';
|
|
3
|
+
import { binaryField, coordinate, recipe } from './conan-reference.js';
|
|
4
|
+
export const conan = { id: 'conan', ecosystem: 'conan', files: ['conan.lock'],
|
|
5
|
+
edges: true, direct: true, licenses: false };
|
|
6
|
+
function list(value) {
|
|
7
|
+
if (value === undefined)
|
|
8
|
+
return [];
|
|
9
|
+
if (!Array.isArray(value))
|
|
10
|
+
throw new Error('Invalid Conan lock list');
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
function pinsFor(entry) {
|
|
14
|
+
if (typeof entry === 'string')
|
|
15
|
+
return [coordinate(recipe(entry))];
|
|
16
|
+
if (!Array.isArray(entry) || entry.length !== 2 || !isRecord(entry[1]))
|
|
17
|
+
throw new Error('Invalid Conan recipe pin');
|
|
18
|
+
const reference = recipe(entry[0]);
|
|
19
|
+
const binaries = Object.entries(entry[1]);
|
|
20
|
+
if (!binaries.length)
|
|
21
|
+
return [coordinate(reference)];
|
|
22
|
+
return binaries.map(([packageId, revision]) => {
|
|
23
|
+
const id = binaryField(packageId);
|
|
24
|
+
if (id === undefined)
|
|
25
|
+
throw new Error('Missing Conan binary package ID');
|
|
26
|
+
return coordinate(reference, id, binaryField(revision));
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function flatGraph(refs) {
|
|
30
|
+
const pins = [];
|
|
31
|
+
for (const group of ['requires', 'build_requires', 'python_requires', 'config_requires']) {
|
|
32
|
+
list(refs[group]).forEach((entry, index) => {
|
|
33
|
+
for (const coordinate of pinsFor(entry)) {
|
|
34
|
+
pins.push({ coordinate, at: pointer([group, index]), source: 'unknown', direct: 'unknown', groups: [group] });
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
const losses = ['edges', 'roots', 'direct'];
|
|
39
|
+
if (refs.overrides !== undefined)
|
|
40
|
+
losses.push('resolution');
|
|
41
|
+
return { pins, edges: [], roots: [], losses };
|
|
42
|
+
}
|
|
43
|
+
function readNode(key, raw, revisions) {
|
|
44
|
+
if (!isRecord(raw) || !/^\d+$/.test(key))
|
|
45
|
+
throw new Error('Invalid Conan graph node');
|
|
46
|
+
const targets = [...list(raw.requires), ...list(raw.build_requires)].map(value => {
|
|
47
|
+
if (typeof value === 'string' && /^\d+$/.test(value))
|
|
48
|
+
return value;
|
|
49
|
+
if (typeof value === 'number' && Number.isSafeInteger(value) && value >= 0)
|
|
50
|
+
return String(value);
|
|
51
|
+
throw new Error('Invalid Conan graph target');
|
|
52
|
+
});
|
|
53
|
+
const id = raw.ref === undefined ? undefined
|
|
54
|
+
: coordinate(recipe(raw.ref), binaryField(raw.package_id), revisions ? binaryField(raw.prev) : undefined);
|
|
55
|
+
return { key, coordinate: id, path: typeof raw.path === 'string' && raw.path !== '',
|
|
56
|
+
context: typeof raw.context === 'string' && raw.context !== '' ? raw.context : undefined,
|
|
57
|
+
targets, python: list(raw.python_requires).map(value => coordinate(recipe(value))) };
|
|
58
|
+
}
|
|
59
|
+
function legacyGraph(refs) {
|
|
60
|
+
if (!isRecord(refs.graph_lock) || !isRecord(refs.graph_lock.nodes))
|
|
61
|
+
throw new Error('Missing Conan graph nodes');
|
|
62
|
+
const graph = refs.graph_lock;
|
|
63
|
+
const rawNodes = graph.nodes;
|
|
64
|
+
const nodes = new Map(Object.entries(rawNodes).map(([key, node]) => [key, readNode(key, node, graph.revisions_enabled === true)]));
|
|
65
|
+
const allTargets = new Set([...nodes.values()].flatMap(row => row.targets));
|
|
66
|
+
const candidates = [...nodes.values()].filter(row => !allTargets.has(row.key));
|
|
67
|
+
// A virtual outer consumer is omitted by Conan. A recorded path identifies an actual local consumer.
|
|
68
|
+
const root = candidates.length === 1 && candidates[0].path ? candidates[0] : undefined;
|
|
69
|
+
const rootId = root?.coordinate?.id;
|
|
70
|
+
const directTargets = new Set(root?.targets);
|
|
71
|
+
const pins = [];
|
|
72
|
+
const edges = [];
|
|
73
|
+
let incomplete = false;
|
|
74
|
+
for (const node of nodes.values()) {
|
|
75
|
+
const path = ['graph_lock', 'nodes', node.key];
|
|
76
|
+
const id = node.coordinate?.id;
|
|
77
|
+
if (node.coordinate !== undefined && node !== root) {
|
|
78
|
+
pins.push({ coordinate: node.coordinate, at: pointer(path), source: node.path ? 'path' : 'unknown',
|
|
79
|
+
direct: root === undefined ? 'unknown' : directTargets.has(node.key), groups: node.context ? [node.context] : [] });
|
|
80
|
+
}
|
|
81
|
+
node.python.forEach((coordinate, index) => {
|
|
82
|
+
pins.push({ coordinate, at: pointer([...path, 'python_requires', index]), source: 'unknown',
|
|
83
|
+
direct: 'unknown', groups: ['python_requires'] });
|
|
84
|
+
});
|
|
85
|
+
// The legacy writer stores transitive Python requirements together, without their immediate edges.
|
|
86
|
+
incomplete ||= node.python.length > 0;
|
|
87
|
+
for (const target of node.targets) {
|
|
88
|
+
const to = nodes.get(target)?.coordinate?.id;
|
|
89
|
+
if (id === undefined || to === undefined)
|
|
90
|
+
incomplete = true;
|
|
91
|
+
else if (id !== to)
|
|
92
|
+
edges.push({ from: id, to });
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const losses = [];
|
|
96
|
+
if (incomplete)
|
|
97
|
+
losses.push('edges');
|
|
98
|
+
if (rootId === undefined)
|
|
99
|
+
losses.push('roots');
|
|
100
|
+
if (root === undefined || pins.some(pin => pin.direct === 'unknown'))
|
|
101
|
+
losses.push('direct');
|
|
102
|
+
if (pins.some(pin => pin.groups.length === 0))
|
|
103
|
+
losses.push('groups');
|
|
104
|
+
return { pins, edges, roots: rootId === undefined ? [] : [rootId], losses };
|
|
105
|
+
}
|
|
106
|
+
function mergePins(pins, text) {
|
|
107
|
+
const packages = new Map();
|
|
108
|
+
const spans = locateJsonSpans(text, new Set(pins.map(pin => pin.at)), 5);
|
|
109
|
+
for (const { coordinate, at, groups, direct, source } of pins) {
|
|
110
|
+
const span = spans.get(at);
|
|
111
|
+
if (span === undefined)
|
|
112
|
+
throw new Error('Missing Conan pin provenance');
|
|
113
|
+
const previous = packages.get(coordinate.id);
|
|
114
|
+
if (!previous)
|
|
115
|
+
packages.set(coordinate.id, { ...coordinate, ...span, groups, direct, source });
|
|
116
|
+
else
|
|
117
|
+
packages.set(coordinate.id, { ...previous,
|
|
118
|
+
groups: [...new Set([...previous.groups, ...groups])],
|
|
119
|
+
direct: previous.direct === true || direct === true ? true
|
|
120
|
+
: previous.direct === 'unknown' || direct === 'unknown' ? 'unknown' : false,
|
|
121
|
+
source: previous.source === 'path' ? previous.source : source,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
return [...packages.values()];
|
|
125
|
+
}
|
|
126
|
+
export function readConan({ text }) {
|
|
127
|
+
const raw = readJson(text);
|
|
128
|
+
if (!isRecord(raw) || (raw.version !== '0.4' && raw.version !== '0.5'))
|
|
129
|
+
throw new Error('Unsupported Conan lockfile');
|
|
130
|
+
const { pins, edges, roots, losses } = raw.version === '0.5' ? flatGraph(raw) : legacyGraph(raw);
|
|
131
|
+
const packages = mergePins(pins, text);
|
|
132
|
+
if (packages.length)
|
|
133
|
+
losses.push('licenses');
|
|
134
|
+
return { format: 'conan', ecosystem: 'conan', packages, edges: [...new Map(edges.map(edge => [
|
|
135
|
+
JSON.stringify([edge.from, edge.to]), edge,
|
|
136
|
+
])).values()], roots, losses };
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=conan.js.map
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { readLines } from './lines.js';
|
|
2
|
+
export const dart = { id: 'dart', ecosystem: 'pub', files: ['pubspec.lock'],
|
|
3
|
+
edges: false, direct: true, licenses: false };
|
|
4
|
+
const kinds = new Map([['hosted', 'registry'], ['git', 'git'], ['path', 'path'], ['sdk', 'unknown']]);
|
|
5
|
+
const sourceName = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
6
|
+
const packageVersion = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
7
|
+
function pair(line) {
|
|
8
|
+
const match = /^([A-Za-z_][A-Za-z0-9_-]*):(?:[ \t]*(.*))?$/.exec(line);
|
|
9
|
+
if (match === null)
|
|
10
|
+
throw new Error('Invalid pubspec.lock mapping');
|
|
11
|
+
return [match[1], scalar(match[2] ?? '')];
|
|
12
|
+
}
|
|
13
|
+
function scalar(raw) {
|
|
14
|
+
if (raw.startsWith('"')) {
|
|
15
|
+
const match = /^("(?:[^"\\]|\\.)*")(?:[ \t]+#.*)?$/.exec(raw);
|
|
16
|
+
if (match === null)
|
|
17
|
+
throw new Error('Invalid quoted pubspec.lock value');
|
|
18
|
+
return JSON.parse(match[1]);
|
|
19
|
+
}
|
|
20
|
+
if (raw.startsWith("'")) {
|
|
21
|
+
const match = /^('(?:[^']|'')*')(?:[ \t]+#.*)?$/.exec(raw);
|
|
22
|
+
if (match === null)
|
|
23
|
+
throw new Error('Invalid quoted pubspec.lock value');
|
|
24
|
+
return match[1].slice(1, -1).replaceAll("''", "'");
|
|
25
|
+
}
|
|
26
|
+
const plain = raw.replace(/(?:^|\s)#.*$/, '').trimEnd();
|
|
27
|
+
if (/^[&*!>|[\]]/.test(plain))
|
|
28
|
+
throw new Error('Unsupported pubspec.lock value');
|
|
29
|
+
return plain;
|
|
30
|
+
}
|
|
31
|
+
class PackageTable {
|
|
32
|
+
rows = new Map();
|
|
33
|
+
current;
|
|
34
|
+
describing = false;
|
|
35
|
+
record(indent, name, value, line) {
|
|
36
|
+
if (indent === 2) {
|
|
37
|
+
this.start(name, value, line);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const row = this.current;
|
|
41
|
+
if (row === undefined)
|
|
42
|
+
throw new Error('pubspec.lock package section is missing');
|
|
43
|
+
if (indent === 4) {
|
|
44
|
+
this.put(row.details, name, value);
|
|
45
|
+
this.describing = name === 'description' && value === '';
|
|
46
|
+
}
|
|
47
|
+
else if (indent === 6 && this.describing) {
|
|
48
|
+
this.put(row.description, name, value);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
throw new Error('Invalid pubspec.lock package indentation');
|
|
52
|
+
}
|
|
53
|
+
row.endLine = line;
|
|
54
|
+
}
|
|
55
|
+
start(name, value, line) {
|
|
56
|
+
if (this.rows.has(name) || !sourceName.test(name) || value !== '')
|
|
57
|
+
throw new Error('Invalid or duplicate Dart package');
|
|
58
|
+
this.current = { name, line, endLine: line, details: new Map(), description: new Map() };
|
|
59
|
+
this.rows.set(name, this.current);
|
|
60
|
+
this.describing = false;
|
|
61
|
+
}
|
|
62
|
+
put(fields, name, value) {
|
|
63
|
+
if (fields.has(name))
|
|
64
|
+
throw new Error('Duplicate pubspec.lock field');
|
|
65
|
+
fields.set(name, value);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function packageRows(text) {
|
|
69
|
+
let found = false;
|
|
70
|
+
let inPackages = false;
|
|
71
|
+
const table = new PackageTable();
|
|
72
|
+
for (const { text: row, offset } of readLines(text)) {
|
|
73
|
+
const value = row.trim();
|
|
74
|
+
if (value === '' || value.startsWith('#'))
|
|
75
|
+
continue;
|
|
76
|
+
const indent = row.length - row.trimStart().length;
|
|
77
|
+
if (indent === 0) {
|
|
78
|
+
const [name, value] = pair(row.trimEnd());
|
|
79
|
+
inPackages = name === 'packages';
|
|
80
|
+
if (inPackages) {
|
|
81
|
+
if (found || (value !== '' && value !== '{}'))
|
|
82
|
+
throw new Error('Invalid pubspec.lock package table');
|
|
83
|
+
found = true;
|
|
84
|
+
inPackages = value === '';
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else if (inPackages) {
|
|
88
|
+
if (row.startsWith('\t'))
|
|
89
|
+
throw new Error('Invalid pubspec.lock indentation');
|
|
90
|
+
const [name, assigned] = pair(value);
|
|
91
|
+
table.record(indent, name, assigned, offset + 1);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (!found)
|
|
95
|
+
throw new Error('Missing pubspec.lock package table');
|
|
96
|
+
return table.rows.values();
|
|
97
|
+
}
|
|
98
|
+
function packageOf({ name, line, endLine, details, description }) {
|
|
99
|
+
const version = details.get('version');
|
|
100
|
+
const source = details.get('source');
|
|
101
|
+
if (!version || !packageVersion.test(version) || !source)
|
|
102
|
+
throw new Error('Incomplete Dart package record');
|
|
103
|
+
const dependency = details.get('dependency');
|
|
104
|
+
const digest = description.get('sha256');
|
|
105
|
+
const integrity = source === 'hosted' && digest && /^[a-f0-9]{64}$/i.test(digest) ? 'sha256:' + digest : undefined;
|
|
106
|
+
const direct = dependency === 'transitive' ? false : dependency?.startsWith('direct ') ? true : 'unknown';
|
|
107
|
+
return { name, id: 'pkg:pub/' + encodeURIComponent(name) + '@' + encodeURIComponent(version), version,
|
|
108
|
+
source: kinds.get(source) ?? 'unknown', direct, line, endLine, groups: dependency === undefined ? [] : [dependency],
|
|
109
|
+
...(integrity === undefined ? {} : { integrity }) };
|
|
110
|
+
}
|
|
111
|
+
export function readDart({ text }) {
|
|
112
|
+
const packages = Array.from(packageRows(text), packageOf);
|
|
113
|
+
const losses = ['edges', 'roots'];
|
|
114
|
+
if (packages.some(pkg => pkg.direct === 'unknown'))
|
|
115
|
+
losses.push('direct');
|
|
116
|
+
if (packages.some(pkg => pkg.groups.length === 0))
|
|
117
|
+
losses.push('groups');
|
|
118
|
+
if (packages.length)
|
|
119
|
+
losses.push('licenses');
|
|
120
|
+
return { format: 'dart', ecosystem: 'pub', packages, edges: [], roots: [], losses };
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=dart.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
interface Coordinate {
|
|
2
|
+
readonly name: string;
|
|
3
|
+
readonly version: string;
|
|
4
|
+
}
|
|
5
|
+
interface Requirement extends Coordinate {
|
|
6
|
+
readonly line: number;
|
|
7
|
+
readonly indirect: boolean;
|
|
8
|
+
}
|
|
9
|
+
interface Replacement {
|
|
10
|
+
readonly previous: {
|
|
11
|
+
readonly name: string;
|
|
12
|
+
readonly version?: string;
|
|
13
|
+
};
|
|
14
|
+
readonly next: Coordinate | {
|
|
15
|
+
readonly path: string;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
interface Manifest {
|
|
19
|
+
module?: string;
|
|
20
|
+
readonly requirements: Requirement[];
|
|
21
|
+
readonly replacements: Replacement[];
|
|
22
|
+
readonly excluded: Coordinate[];
|
|
23
|
+
tools: boolean;
|
|
24
|
+
}
|
|
25
|
+
export declare function readGoMod(text: string): Manifest & {
|
|
26
|
+
readonly module: string;
|
|
27
|
+
};
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { readLines } from './lines.js';
|
|
2
|
+
const directives = new Set(['module', 'go', 'toolchain', 'godebug', 'require', 'exclude', 'replace', 'retract', 'tool', 'ignore']);
|
|
3
|
+
const blocks = new Set(['require', 'exclude', 'replace', 'retract', 'tool', 'ignore', 'godebug']);
|
|
4
|
+
const modulePath = /^[A-Za-z0-9._~-]+(?:\/[A-Za-z0-9._~-]+)*$/;
|
|
5
|
+
export function readGoMod(text) {
|
|
6
|
+
const result = { requirements: [], replacements: [], excluded: [], tools: false };
|
|
7
|
+
let block;
|
|
8
|
+
for (const { text: row, offset } of readLines(text)) {
|
|
9
|
+
const { items, comment } = readLine(row);
|
|
10
|
+
if (items.length === 0)
|
|
11
|
+
continue;
|
|
12
|
+
if (block && items.length === 1 && items[0] === ')') {
|
|
13
|
+
block = undefined;
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
const name = block ?? items.shift();
|
|
17
|
+
if (!directives.has(name))
|
|
18
|
+
throw invalid(offset);
|
|
19
|
+
if (!block && blocks.has(name) && items.length === 1 && items[0] === '(') {
|
|
20
|
+
block = name;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
record(result, name, items, comment, offset);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (block !== undefined || result.module === undefined)
|
|
27
|
+
throw new Error('Incomplete go.mod');
|
|
28
|
+
return { ...result, module: result.module };
|
|
29
|
+
}
|
|
30
|
+
function invalid(offset) {
|
|
31
|
+
return new Error('Invalid go.mod directive at line ' + (offset + 1));
|
|
32
|
+
}
|
|
33
|
+
function record(manifest, directive, items, comment, offset) {
|
|
34
|
+
switch (directive) {
|
|
35
|
+
case 'module':
|
|
36
|
+
if (manifest.module !== undefined || items.length !== 1 || !modulePath.test(items[0]))
|
|
37
|
+
throw invalid(offset);
|
|
38
|
+
manifest.module = items[0];
|
|
39
|
+
break;
|
|
40
|
+
case 'require':
|
|
41
|
+
manifest.requirements.push({ ...moduleVersion(items, offset), indirect: isIndirect(comment),
|
|
42
|
+
line: offset + 1 });
|
|
43
|
+
break;
|
|
44
|
+
case 'exclude':
|
|
45
|
+
manifest.excluded.push(moduleVersion(items, offset));
|
|
46
|
+
break;
|
|
47
|
+
case 'replace':
|
|
48
|
+
manifest.replacements.push(replacement(items, offset));
|
|
49
|
+
break;
|
|
50
|
+
case 'tool':
|
|
51
|
+
if (items.length !== 1 || !modulePath.test(items[0]))
|
|
52
|
+
throw invalid(offset);
|
|
53
|
+
manifest.tools = true;
|
|
54
|
+
break;
|
|
55
|
+
default:
|
|
56
|
+
if (items.length === 0 || items.includes('(') || items.includes(')'))
|
|
57
|
+
throw invalid(offset);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function isIndirect(comment) {
|
|
61
|
+
const text = comment.trimEnd();
|
|
62
|
+
return text === 'indirect' || /^indirect;\s+\S/.test(text);
|
|
63
|
+
}
|
|
64
|
+
function moduleVersion(items, offset) {
|
|
65
|
+
const [name, version] = items;
|
|
66
|
+
if (items.length !== 2 || !modulePath.test(name) || !version || /[\s()]/.test(version))
|
|
67
|
+
throw invalid(offset);
|
|
68
|
+
return { name: name, version };
|
|
69
|
+
}
|
|
70
|
+
function replacement(items, offset) {
|
|
71
|
+
const arrow = items.indexOf('=>');
|
|
72
|
+
if ((arrow !== 1 && arrow !== 2) || !modulePath.test(items[0]))
|
|
73
|
+
throw invalid(offset);
|
|
74
|
+
const previous = arrow === 2 ? moduleVersion(items.slice(0, arrow), offset) : { name: items[0] };
|
|
75
|
+
const next = items.slice(arrow + 1);
|
|
76
|
+
if (next.length === 1 && /^(?:[.]{1,2}(?:[\\/]|$)|[\\/]|[A-Za-z]:[\\/])/.test(next[0])) {
|
|
77
|
+
return { previous, next: { path: next[0] } };
|
|
78
|
+
}
|
|
79
|
+
return { previous, next: moduleVersion(next, offset) };
|
|
80
|
+
}
|
|
81
|
+
const interpreted = /"(?:[^"\\\r\n]|\\[^\r\n])*"/y;
|
|
82
|
+
const literal = /(?:[^\t \r()/'\x60"]|\/(?![/*]))+/y;
|
|
83
|
+
function readLine(line) {
|
|
84
|
+
const items = [];
|
|
85
|
+
for (let position = 0; position < line.length;) {
|
|
86
|
+
const char = line[position];
|
|
87
|
+
if (char === ' ' || char === '\t' || char === '\r') {
|
|
88
|
+
position++;
|
|
89
|
+
}
|
|
90
|
+
else if (line.startsWith('//', position)) {
|
|
91
|
+
return { items, comment: line.slice(position + 2).trimStart() };
|
|
92
|
+
}
|
|
93
|
+
else if (line.startsWith('/*', position)) {
|
|
94
|
+
throw new Error('Go manifests use line comments');
|
|
95
|
+
}
|
|
96
|
+
else if (char === '(' || char === ')') {
|
|
97
|
+
items.push(char);
|
|
98
|
+
position++;
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
const [word, end] = token(line, position, char);
|
|
102
|
+
items.push(word);
|
|
103
|
+
position = end;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return { items, comment: '' };
|
|
107
|
+
}
|
|
108
|
+
function token(line, position, char) {
|
|
109
|
+
const grave = '\x60';
|
|
110
|
+
if (char === grave) {
|
|
111
|
+
const end = line.indexOf(grave, position + 1);
|
|
112
|
+
if (end < 0)
|
|
113
|
+
throw new Error('Unclosed go.mod string');
|
|
114
|
+
return [line.slice(position + 1, end), end + 1];
|
|
115
|
+
}
|
|
116
|
+
const pattern = char === '"' ? interpreted : literal;
|
|
117
|
+
pattern.lastIndex = position;
|
|
118
|
+
const found = pattern.exec(line);
|
|
119
|
+
if (found === null)
|
|
120
|
+
throw new Error('Invalid go.mod token');
|
|
121
|
+
const raw = found[0];
|
|
122
|
+
return [char === '"' ? unquote(raw.slice(1, -1)) : raw, pattern.lastIndex];
|
|
123
|
+
}
|
|
124
|
+
const escapes = new Map([
|
|
125
|
+
['a', '\x07'], ['b', '\b'], ['f', '\f'], ['n', '\n'], ['r', '\r'], ['t', '\t'], ['v', '\x0b'], ['\\', '\\'], ['"', '"'],
|
|
126
|
+
]);
|
|
127
|
+
function unquote(raw) {
|
|
128
|
+
return raw.replace(/\\(?:([0-7]{3})|x([0-9a-fA-F]{2})|u([0-9a-fA-F]{4})|U([0-9a-fA-F]{8})|(.))/g, (_match, octal, byte, short, long, char) => {
|
|
129
|
+
if (octal !== undefined) {
|
|
130
|
+
const point = Number.parseInt(octal, 8);
|
|
131
|
+
if (point < 256)
|
|
132
|
+
return String.fromCharCode(point);
|
|
133
|
+
throw new Error('Invalid go.mod byte escape');
|
|
134
|
+
}
|
|
135
|
+
const hex = byte ?? short ?? long;
|
|
136
|
+
if (hex !== undefined) {
|
|
137
|
+
const point = Number.parseInt(hex, 16);
|
|
138
|
+
if (point >= 0xd800 && point <= 0xdfff)
|
|
139
|
+
throw new Error('Invalid go.mod Unicode escape');
|
|
140
|
+
return String.fromCodePoint(point);
|
|
141
|
+
}
|
|
142
|
+
const escaped = escapes.get(char);
|
|
143
|
+
if (escaped === undefined)
|
|
144
|
+
throw new Error('Invalid go.mod escape');
|
|
145
|
+
return escaped;
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=go-mod.js.map
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { readGoMod } from './go-mod.js';
|
|
2
|
+
import { readLines } from './lines.js';
|
|
3
|
+
export const go = { id: 'go', ecosystem: 'go', files: ['go.mod'],
|
|
4
|
+
edges: true, direct: true, licenses: false };
|
|
5
|
+
const canonical = /^v\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+incompatible)?$/;
|
|
6
|
+
function packageUrl(name, version) {
|
|
7
|
+
return 'pkg:golang/' + name.split('/').map(encodeURIComponent).join('/')
|
|
8
|
+
+ (version === undefined ? '' : '@' + encodeURIComponent(version));
|
|
9
|
+
}
|
|
10
|
+
function key({ name, version }) {
|
|
11
|
+
return name + '\0' + (version ?? '');
|
|
12
|
+
}
|
|
13
|
+
function readGoSum(text) {
|
|
14
|
+
const checksums = new Map();
|
|
15
|
+
const content = /^([A-Za-z0-9._~/-]+)[ \t]+([^ \t]+)[ \t]+(h[0-9]+:[A-Za-z0-9+/]+={0,2})$/;
|
|
16
|
+
for (const { text: row, offset } of readLines(text)) {
|
|
17
|
+
if (!row.trim())
|
|
18
|
+
continue;
|
|
19
|
+
const checksum = content.exec(row.trim());
|
|
20
|
+
if (checksum === null)
|
|
21
|
+
throw new Error('Invalid go.sum entry on line ' + (offset + 1));
|
|
22
|
+
const [, name, version, hash] = checksum;
|
|
23
|
+
if (version.endsWith('/go.mod'))
|
|
24
|
+
continue;
|
|
25
|
+
if (!canonical.test(version))
|
|
26
|
+
throw new Error('Invalid go.sum version on line ' + (offset + 1));
|
|
27
|
+
const id = key({ name: name, version });
|
|
28
|
+
const previous = checksums.get(id);
|
|
29
|
+
if (previous !== undefined && previous !== hash)
|
|
30
|
+
throw new Error('Conflicting go.sum checksums on line ' + (offset + 1));
|
|
31
|
+
checksums.set(id, hash);
|
|
32
|
+
}
|
|
33
|
+
return checksums;
|
|
34
|
+
}
|
|
35
|
+
export function readGo({ path, text, manifests }) {
|
|
36
|
+
const filename = path.slice(0, path.lastIndexOf('/') + 1) + 'go.sum';
|
|
37
|
+
if (!manifests || !Object.hasOwn(manifests, filename))
|
|
38
|
+
throw new Error('The go.mod input requires its go.sum companion');
|
|
39
|
+
const manifest = readGoMod(text);
|
|
40
|
+
const sums = readGoSum(manifests[filename]);
|
|
41
|
+
const excludes = new Set(manifest.excluded.map(key));
|
|
42
|
+
const replacements = new Map(manifest.replacements.map(({ previous, next }) => [key(previous), next]));
|
|
43
|
+
const packages = new Map();
|
|
44
|
+
const root = packageUrl(manifest.module);
|
|
45
|
+
let unresolved = false;
|
|
46
|
+
for (const row of manifest.requirements) {
|
|
47
|
+
if (excludes.has(key(row))) {
|
|
48
|
+
unresolved = true;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
const replacement = replacements.get(key(row)) ?? replacements.get(key({ name: row.name }));
|
|
52
|
+
const local = replacement !== undefined && 'path' in replacement;
|
|
53
|
+
const { name, version } = replacement !== undefined && 'version' in replacement ? replacement : row;
|
|
54
|
+
if (!canonical.test(version)) {
|
|
55
|
+
unresolved = true;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const id = packageUrl(name, version);
|
|
59
|
+
if (packages.has(id))
|
|
60
|
+
throw new Error('Duplicate Go module identity');
|
|
61
|
+
const integrity = local ? undefined : sums.get(key({ name, version }));
|
|
62
|
+
packages.set(id, { id, name, version, source: local ? 'path' : 'unknown',
|
|
63
|
+
groups: row.indirect ? ['indirect'] : [], direct: !row.indirect, line: row.line, endLine: row.line,
|
|
64
|
+
...(integrity === undefined ? {} : { integrity }) });
|
|
65
|
+
}
|
|
66
|
+
const losses = [];
|
|
67
|
+
if (packages.size > 0 || unresolved)
|
|
68
|
+
losses.push('edges', 'licenses', 'resolution');
|
|
69
|
+
if (manifest.tools)
|
|
70
|
+
losses.push('groups');
|
|
71
|
+
return { format: 'go', ecosystem: 'go', packages: [...packages.values()],
|
|
72
|
+
edges: [...packages.keys()].map(to => ({ from: root, to })), roots: [root], losses };
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=go.js.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { readLines } from './lines.js';
|
|
2
|
+
export const gradle = { id: 'gradle', ecosystem: 'maven', files: ['gradle.lockfile', 'buildscript-gradle.lockfile'],
|
|
3
|
+
edges: false, direct: false, licenses: false };
|
|
4
|
+
const coordinate = /^([^:=\s]+):([^:=\s]+):([^:=\s]+)=(.+)$/;
|
|
5
|
+
function groupNames(text) {
|
|
6
|
+
if (text === '')
|
|
7
|
+
return [];
|
|
8
|
+
const groups = text.split(',').map(name => name.trim());
|
|
9
|
+
if (groups.some(name => name === '' || /[\s=:]/.test(name)))
|
|
10
|
+
throw new Error('Invalid Gradle configuration name');
|
|
11
|
+
return groups;
|
|
12
|
+
}
|
|
13
|
+
function packageId(group, name, version) {
|
|
14
|
+
return 'pkg:maven/' + encodeURIComponent(group) + '/' + encodeURIComponent(name) + '@' + encodeURIComponent(version);
|
|
15
|
+
}
|
|
16
|
+
export function readGradle({ text }) {
|
|
17
|
+
const rows = new Map();
|
|
18
|
+
for (const { text: raw, offset } of readLines(text)) {
|
|
19
|
+
const line = raw.trim();
|
|
20
|
+
if (line === '' || line.startsWith('#'))
|
|
21
|
+
continue;
|
|
22
|
+
if (line.startsWith('empty=')) {
|
|
23
|
+
groupNames(line.slice('empty='.length));
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
const match = coordinate.exec(line);
|
|
27
|
+
if (match === null)
|
|
28
|
+
throw new Error('Invalid Gradle dependency on line ' + (offset + 1));
|
|
29
|
+
const [, group, name, version, configurations] = match;
|
|
30
|
+
const id = packageId(group, name, version);
|
|
31
|
+
const entry = rows.get(id) ?? { id, name: name, version: version, line: offset + 1, groups: new Set() };
|
|
32
|
+
for (const configuration of groupNames(configurations))
|
|
33
|
+
entry.groups.add(configuration);
|
|
34
|
+
rows.set(id, entry);
|
|
35
|
+
}
|
|
36
|
+
const packages = [...rows.values()].map(({ groups, line, ...entry }) => ({
|
|
37
|
+
...entry, line, endLine: line, groups: [...groups], source: 'unknown', direct: 'unknown',
|
|
38
|
+
}));
|
|
39
|
+
return { format: 'gradle', ecosystem: 'maven', packages, edges: [], roots: [],
|
|
40
|
+
losses: ['edges', 'roots', 'direct', 'licenses'] };
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=gradle.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function* readLines(text) {
|
|
2
|
+
let offset = 0;
|
|
3
|
+
let position = 0;
|
|
4
|
+
while (position < text.length) {
|
|
5
|
+
const next = text.indexOf('\n', position);
|
|
6
|
+
const end = next < 0 ? text.length : next;
|
|
7
|
+
const last = text[end - 1] === '\r' ? end - 1 : end;
|
|
8
|
+
yield { text: text.slice(position, last), offset: offset++ };
|
|
9
|
+
position = end + 1;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=lines.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
type Scalar = {
|
|
2
|
+
readonly type: 'atom' | 'string' | 'literal';
|
|
3
|
+
readonly value: string;
|
|
4
|
+
};
|
|
5
|
+
type Composite = {
|
|
6
|
+
readonly type: 'list' | 'tuple' | 'map';
|
|
7
|
+
readonly values: readonly Term[];
|
|
8
|
+
};
|
|
9
|
+
type Pair = {
|
|
10
|
+
readonly type: 'pair';
|
|
11
|
+
readonly key: Scalar;
|
|
12
|
+
readonly value: Term;
|
|
13
|
+
};
|
|
14
|
+
export type Term = Scalar | Composite | Pair;
|
|
15
|
+
interface Entry {
|
|
16
|
+
readonly key: string;
|
|
17
|
+
readonly value: Composite;
|
|
18
|
+
readonly line: number;
|
|
19
|
+
readonly endLine: number;
|
|
20
|
+
}
|
|
21
|
+
export declare function readMixLiterals(text: string): Entry[];
|
|
22
|
+
export {};
|