@repometry/lockparse 0.0.0-stage → 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 -2
- package/package.json +31 -4
- 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,9 @@
|
|
|
1
|
+
import { readPoetryLock } from './poetry-lock.js';
|
|
2
|
+
import { pythonGraph } from './python-graph.js';
|
|
3
|
+
import { projectFor } from './python-project.js';
|
|
4
|
+
export const poetry = { id: 'poetry', ecosystem: 'pypi', files: ['poetry.lock'],
|
|
5
|
+
edges: true, direct: true, licenses: false };
|
|
6
|
+
export function readPoetry(input) {
|
|
7
|
+
return pythonGraph('poetry', readPoetryLock(input.text), projectFor(input));
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=poetry.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { PythonRequirement } from './python-package.js';
|
|
2
|
+
import type { PythonProject } from './python-project.js';
|
|
3
|
+
import type { LockGraph, LockPackage, PackageSource } from '../model.js';
|
|
4
|
+
export interface Installed {
|
|
5
|
+
readonly id: string;
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly version?: string;
|
|
8
|
+
readonly source: PackageSource;
|
|
9
|
+
readonly sourceReference?: string;
|
|
10
|
+
readonly extras?: readonly string[];
|
|
11
|
+
readonly ranges: Pick<LockPackage, 'line' | 'endLine'>;
|
|
12
|
+
readonly groups?: readonly string[];
|
|
13
|
+
readonly hashes: readonly string[];
|
|
14
|
+
readonly dependencies: readonly PythonRequirement[];
|
|
15
|
+
}
|
|
16
|
+
export declare function pythonGraph(format: 'poetry' | 'pdm', installed: readonly Installed[], project?: PythonProject): LockGraph;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { pythonName } from './python-package.js';
|
|
2
|
+
function lookupKey(name, version, source, extras) {
|
|
3
|
+
return JSON.stringify([name, version, source, extras]);
|
|
4
|
+
}
|
|
5
|
+
function indexPackages(packages) {
|
|
6
|
+
const index = new Map();
|
|
7
|
+
const record = (key, pkg) => {
|
|
8
|
+
index.set(key, index.has(key) ? null : pkg);
|
|
9
|
+
};
|
|
10
|
+
for (const pkg of packages) {
|
|
11
|
+
const name = pythonName(pkg.name);
|
|
12
|
+
record(lookupKey(name, undefined, undefined, pkg.extras), pkg);
|
|
13
|
+
if (pkg.version !== undefined)
|
|
14
|
+
record(lookupKey(name, pkg.version, undefined, pkg.extras), pkg);
|
|
15
|
+
if (pkg.sourceReference !== undefined) {
|
|
16
|
+
record(lookupKey(name, undefined, pkg.sourceReference, pkg.extras), pkg);
|
|
17
|
+
if (pkg.version !== undefined)
|
|
18
|
+
record(lookupKey(name, pkg.version, pkg.sourceReference, pkg.extras), pkg);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return index;
|
|
22
|
+
}
|
|
23
|
+
function match(index, { name, exactVersion, source, extras }) {
|
|
24
|
+
return index.get(lookupKey(name, exactVersion, source, extras)) ?? undefined;
|
|
25
|
+
}
|
|
26
|
+
function links(packages, index, byExtras) {
|
|
27
|
+
const edges = [];
|
|
28
|
+
let incomplete = false;
|
|
29
|
+
for (const pkg of packages) {
|
|
30
|
+
const targets = new Set();
|
|
31
|
+
for (const request of pkg.dependencies) {
|
|
32
|
+
const to = match(index, byExtras ? request : { ...request, extras: undefined });
|
|
33
|
+
if (to === undefined)
|
|
34
|
+
incomplete = true;
|
|
35
|
+
else
|
|
36
|
+
targets.add(to.id);
|
|
37
|
+
}
|
|
38
|
+
for (const to of targets)
|
|
39
|
+
edges.push({ from: pkg.id, to });
|
|
40
|
+
}
|
|
41
|
+
return { edges, incomplete };
|
|
42
|
+
}
|
|
43
|
+
function directEvidence(project, index, byExtras) {
|
|
44
|
+
const direct = new Map();
|
|
45
|
+
let complete = project?.complete === true;
|
|
46
|
+
for (const request of project?.declarations ?? []) {
|
|
47
|
+
const pkg = match(index, byExtras ? request : { ...request, extras: undefined });
|
|
48
|
+
if (pkg === undefined)
|
|
49
|
+
complete = false;
|
|
50
|
+
else {
|
|
51
|
+
const labels = direct.get(pkg.id) ?? new Set();
|
|
52
|
+
if (request.group !== undefined)
|
|
53
|
+
labels.add(request.group);
|
|
54
|
+
direct.set(pkg.id, labels);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return { direct, complete };
|
|
58
|
+
}
|
|
59
|
+
export function pythonGraph(format, installed, project) {
|
|
60
|
+
const index = indexPackages(installed);
|
|
61
|
+
const byExtras = format === 'pdm';
|
|
62
|
+
const { edges, incomplete } = links(installed, index, byExtras);
|
|
63
|
+
const { direct, complete } = directEvidence(project, index, byExtras);
|
|
64
|
+
const root = project?.id;
|
|
65
|
+
if (root !== undefined) {
|
|
66
|
+
for (const to of direct.keys())
|
|
67
|
+
edges.push({ from: root, to });
|
|
68
|
+
}
|
|
69
|
+
const packages = installed.map((pkg) => {
|
|
70
|
+
const { name, id, version, source, ranges, groups, hashes } = pkg;
|
|
71
|
+
const labels = direct.get(id);
|
|
72
|
+
return { id, name, ...(version !== undefined ? { version } : {}), source, ...ranges, groups: groups ?? [...labels ?? []].sort(),
|
|
73
|
+
direct: labels !== undefined ? true : complete ? false : 'unknown',
|
|
74
|
+
...(hashes.length === 1 ? { integrity: hashes[0] } : {}) };
|
|
75
|
+
});
|
|
76
|
+
const losses = [];
|
|
77
|
+
if (incomplete || !complete || root === undefined)
|
|
78
|
+
losses.push('edges');
|
|
79
|
+
if (root === undefined)
|
|
80
|
+
losses.push('roots');
|
|
81
|
+
if (!complete)
|
|
82
|
+
losses.push('direct');
|
|
83
|
+
if (packages.some(pkg => pkg.groups.length === 0))
|
|
84
|
+
losses.push('groups');
|
|
85
|
+
if (packages.length)
|
|
86
|
+
losses.push('licenses');
|
|
87
|
+
if (installed.some(pkg => pkg.hashes.length > 1))
|
|
88
|
+
losses.push('integrity');
|
|
89
|
+
return { format, ecosystem: 'pypi', packages, edges, roots: root === undefined ? [] : [root], losses };
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=python-graph.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { TomlValue } from './toml-values.js';
|
|
2
|
+
export declare function pythonName(name: string): string;
|
|
3
|
+
export declare function pypi(name: string, version?: string): string;
|
|
4
|
+
export interface PythonRequirement {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly exactVersion?: string;
|
|
7
|
+
readonly source?: string;
|
|
8
|
+
readonly extras?: readonly string[];
|
|
9
|
+
}
|
|
10
|
+
export declare function exactPythonVersion(requirement: string | undefined): string | undefined;
|
|
11
|
+
export declare function pep508(text: string): PythonRequirement;
|
|
12
|
+
export declare function tableRequirement(name: string, value: TomlValue): PythonRequirement[];
|
|
13
|
+
export declare function pypiIds<T>(rows: readonly T[], base: (row: T) => string, evidence: (row: T) => readonly unknown[]): string[];
|
|
14
|
+
export declare function fileDigests(value: TomlValue | undefined): string[];
|
|
15
|
+
export declare function tableField(value: TomlValue | undefined, ...keys: string[]): import("./toml-values.js").TomlObject | undefined;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { field, object, textField } from './toml-values.js';
|
|
3
|
+
export function pythonName(name) {
|
|
4
|
+
if (!/^[A-Za-z0-9](?:[A-Za-z0-9_.-]*[A-Za-z0-9])?$/.test(name))
|
|
5
|
+
throw new Error('Invalid Python package name');
|
|
6
|
+
return name.toLowerCase().replace(/[-_.]+/g, '-');
|
|
7
|
+
}
|
|
8
|
+
export function pypi(name, version) {
|
|
9
|
+
return 'pkg:pypi/' + pythonName(name) + (version === undefined ? '' : '@' + encodeURIComponent(version));
|
|
10
|
+
}
|
|
11
|
+
export function exactPythonVersion(requirement) {
|
|
12
|
+
// Bare versions are exact in Poetry's table syntax. Arbitrary constraints and markers remain uninterpreted.
|
|
13
|
+
return /^(?:==\s*)?([0-9][0-9a-zA-Z_.+!-]*)$/i.exec(requirement?.trim() ?? '')?.[1];
|
|
14
|
+
}
|
|
15
|
+
export function pep508(text) {
|
|
16
|
+
const match = /^([A-Za-z0-9_.-]+)(?:\[([^\]]+)\])?\s*(.*)$/.exec(text.trim());
|
|
17
|
+
if (match === null)
|
|
18
|
+
throw new Error('Invalid Python requirement');
|
|
19
|
+
const version = match[3].split(';', 1)[0].trim().replace(/^\((.*)\)$/, '$1');
|
|
20
|
+
const extras = match[2]?.split(',').map(item => pythonName(item.trim())).sort();
|
|
21
|
+
return { name: pythonName(match[1]), exactVersion: version.startsWith('==') ? exactPythonVersion(version) : undefined,
|
|
22
|
+
...(extras !== undefined ? { extras } : {}) };
|
|
23
|
+
}
|
|
24
|
+
export function tableRequirement(name, value) {
|
|
25
|
+
const candidates = Array.isArray(value) ? value : [value];
|
|
26
|
+
return candidates.map(spec => ({
|
|
27
|
+
name: pythonName(name),
|
|
28
|
+
exactVersion: exactPythonVersion(typeof spec === 'string' ? spec : textField(spec, 'version')),
|
|
29
|
+
source: textField(spec, 'source'),
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
export function pypiIds(rows, base, evidence) {
|
|
33
|
+
const counts = new Map();
|
|
34
|
+
for (const row of rows) {
|
|
35
|
+
const id = base(row);
|
|
36
|
+
counts.set(id, (counts.get(id) ?? 0) + 1);
|
|
37
|
+
}
|
|
38
|
+
const ids = rows.map(row => {
|
|
39
|
+
const id = base(row);
|
|
40
|
+
if (counts.get(id) === 1)
|
|
41
|
+
return id;
|
|
42
|
+
const fingerprint = createHash('sha256').update(JSON.stringify(evidence(row))).digest('hex');
|
|
43
|
+
return id + '?source_hash=' + fingerprint;
|
|
44
|
+
});
|
|
45
|
+
if (new Set(ids).size !== rows.length)
|
|
46
|
+
throw new Error('Duplicate Python lock package identity');
|
|
47
|
+
return ids;
|
|
48
|
+
}
|
|
49
|
+
export function fileDigests(value) {
|
|
50
|
+
if (!Array.isArray(value))
|
|
51
|
+
return [];
|
|
52
|
+
const hashes = new Set();
|
|
53
|
+
for (const item of value) {
|
|
54
|
+
const hash = typeof item === 'string' ? item : textField(item, 'hash');
|
|
55
|
+
if (hash !== undefined && /^[a-z][a-z0-9-]+:[a-f0-9]+$/i.test(hash))
|
|
56
|
+
hashes.add(hash);
|
|
57
|
+
}
|
|
58
|
+
return [...hashes];
|
|
59
|
+
}
|
|
60
|
+
export function tableField(value, ...keys) {
|
|
61
|
+
return object(keys.reduce((head, key) => field(head, key), value));
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=python-package.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PythonRequirement } from './python-package.js';
|
|
2
|
+
import type { LockInput } from '../model.js';
|
|
3
|
+
interface DeclaredRequirement extends PythonRequirement {
|
|
4
|
+
readonly group?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface PythonProject {
|
|
7
|
+
readonly id?: string;
|
|
8
|
+
readonly declarations: readonly DeclaredRequirement[];
|
|
9
|
+
readonly complete: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function projectFor({ path, manifests }: LockInput, kind?: 'poetry' | 'pdm', selectedGroups?: readonly string[]): PythonProject | undefined;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { pep508, pypi, tableField, tableRequirement } from './python-package.js';
|
|
2
|
+
import { readTomlDocument } from './toml-document.js';
|
|
3
|
+
import { textField } from './toml-values.js';
|
|
4
|
+
export function projectFor({ path, manifests }, kind = 'poetry', selectedGroups) {
|
|
5
|
+
const name = path.slice(0, path.lastIndexOf('/') + 1) + 'pyproject.toml';
|
|
6
|
+
if (!manifests || !Object.hasOwn(manifests, name))
|
|
7
|
+
return undefined;
|
|
8
|
+
try {
|
|
9
|
+
const { root } = readTomlDocument(manifests[name]);
|
|
10
|
+
const project = tableField(root, 'project');
|
|
11
|
+
const poetry = kind === 'poetry' ? tableField(root, 'tool', 'poetry') : undefined;
|
|
12
|
+
const configuration = project ?? poetry;
|
|
13
|
+
if (configuration === undefined)
|
|
14
|
+
return undefined;
|
|
15
|
+
const projectName = textField(configuration, 'name');
|
|
16
|
+
const id = projectName === undefined ? undefined : pypi(projectName, textField(configuration, 'version'));
|
|
17
|
+
const declared = [...requirementList(project?.get('dependencies'), kind === 'pdm' ? 'default' : 'main'),
|
|
18
|
+
...poetryTable(poetry?.get('dependencies'), 'main'), ...poetryTable(poetry?.get('dev-dependencies'), 'dev')];
|
|
19
|
+
for (const [group, config] of tableField(poetry, 'group') ?? []) {
|
|
20
|
+
declared.push(...poetryTable(tableField(config, 'dependencies'), group));
|
|
21
|
+
}
|
|
22
|
+
for (const [group, items] of tableField(project, 'optional-dependencies') ?? []) {
|
|
23
|
+
declared.push(...requirementList(items, kind === 'pdm' ? group : undefined));
|
|
24
|
+
}
|
|
25
|
+
if (kind === 'pdm') {
|
|
26
|
+
for (const [group, items] of tableField(root, 'tool', 'pdm', 'dev-dependencies') ?? []) {
|
|
27
|
+
declared.push(...requirementList(items, group));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const groups = dependencyGroups(tableField(root, 'dependency-groups'));
|
|
31
|
+
const dynamic = project?.get('dynamic');
|
|
32
|
+
const complete = groups.complete && (!Array.isArray(dynamic)
|
|
33
|
+
|| (!dynamic.includes('dependencies') && !dynamic.includes('optional-dependencies')));
|
|
34
|
+
const declarations = [...declared, ...groups.declarations];
|
|
35
|
+
return { id, declarations: selectedGroups === undefined ? declarations
|
|
36
|
+
: declarations.filter(item => item.group === undefined || selectedGroups.includes(item.group)), complete };
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function requirementList(value, group) {
|
|
43
|
+
if (value === undefined)
|
|
44
|
+
return [];
|
|
45
|
+
if (!Array.isArray(value))
|
|
46
|
+
throw new Error('Python requirements must use an array');
|
|
47
|
+
return value.map(item => {
|
|
48
|
+
if (typeof item !== 'string')
|
|
49
|
+
throw new Error('Python requirement must be text');
|
|
50
|
+
return { ...pep508(item), group };
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function poetryTable(value, group) {
|
|
54
|
+
if (value === undefined)
|
|
55
|
+
return [];
|
|
56
|
+
if (!(value instanceof Map))
|
|
57
|
+
throw new Error('Poetry requirements must use a table');
|
|
58
|
+
return [...value].flatMap(([name, spec]) => name.toLowerCase() === 'python' ? []
|
|
59
|
+
: tableRequirement(name, spec).map(row => ({ ...row, group })));
|
|
60
|
+
}
|
|
61
|
+
function dependencyGroups(groups) {
|
|
62
|
+
const declarations = [];
|
|
63
|
+
let complete = true;
|
|
64
|
+
for (const [group, values] of groups ?? []) {
|
|
65
|
+
if (!Array.isArray(values))
|
|
66
|
+
throw new Error('Python dependency groups must use arrays');
|
|
67
|
+
for (const value of values) {
|
|
68
|
+
if (typeof value === 'string')
|
|
69
|
+
declarations.push({ ...pep508(value), group });
|
|
70
|
+
else
|
|
71
|
+
complete = false;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return { declarations, complete };
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=python-project.js.map
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { isRecord, readJson } from '../json.js';
|
|
2
|
+
import { locateJsonSpans, pointer } from '../json-spans.js';
|
|
3
|
+
export const renv = { id: 'renv', ecosystem: 'cran', files: ['renv.lock'],
|
|
4
|
+
edges: true, direct: false, licenses: true };
|
|
5
|
+
const sources = new Map([
|
|
6
|
+
['repository', 'registry'], ['bioconductor', 'registry'],
|
|
7
|
+
['github', 'git'], ['gitlab', 'git'], ['bitbucket', 'git'], ['git', 'git'],
|
|
8
|
+
['local', 'path'], ['cellar', 'path'], ['url', 'url'],
|
|
9
|
+
]);
|
|
10
|
+
const rName = /^[a-zA-Z][a-zA-Z0-9.]*$/;
|
|
11
|
+
const runtime = ['Depends', 'Imports', 'LinkingTo'];
|
|
12
|
+
const supplements = ['Suggests', 'Enhances'];
|
|
13
|
+
function fieldText(value) {
|
|
14
|
+
return typeof value === 'string' && value.trim() !== '' ? value.trim() : undefined;
|
|
15
|
+
}
|
|
16
|
+
function declaredList(value) {
|
|
17
|
+
if (value === undefined || value === null)
|
|
18
|
+
return [];
|
|
19
|
+
if (Array.isArray(value) && value.every(item => typeof item === 'string'))
|
|
20
|
+
return value.flatMap(declaredList);
|
|
21
|
+
if (typeof value !== 'string')
|
|
22
|
+
throw new Error('Invalid renv dependency declarations');
|
|
23
|
+
return value.split(',').filter(item => item.trim()).map(item => {
|
|
24
|
+
const name = /^([a-zA-Z][a-zA-Z0-9.]*)(?:\s*\([^()]*\))?$/.exec(item.trim())?.[1];
|
|
25
|
+
if (name === undefined)
|
|
26
|
+
throw new Error('Invalid renv dependency name');
|
|
27
|
+
return name;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function dependencies(row) {
|
|
31
|
+
const required = new Set(declaredList(row.Requirements));
|
|
32
|
+
for (const field of runtime)
|
|
33
|
+
for (const name of declaredList(row[field]))
|
|
34
|
+
required.add(name);
|
|
35
|
+
const optional = new Set(supplements.flatMap(field => declaredList(row[field])));
|
|
36
|
+
// Requirements may include base R itself, which is held in the separate R version record.
|
|
37
|
+
required.delete('R');
|
|
38
|
+
optional.delete('R');
|
|
39
|
+
const known = row.Requirements !== undefined || runtime.some(field => row[field] !== undefined);
|
|
40
|
+
return { required, optional, known };
|
|
41
|
+
}
|
|
42
|
+
function readPackage(key, raw) {
|
|
43
|
+
if (!isRecord(raw))
|
|
44
|
+
throw new Error('Invalid renv package record');
|
|
45
|
+
const name = fieldText(raw.Package) ?? key;
|
|
46
|
+
const version = fieldText(raw.Version);
|
|
47
|
+
if (!rName.test(name) || !version || name !== key)
|
|
48
|
+
throw new Error('Incomplete renv package coordinate');
|
|
49
|
+
const source = sources.get((fieldText(raw.Source) ?? '').toLowerCase()) ?? 'unknown';
|
|
50
|
+
const license = fieldText(raw.License);
|
|
51
|
+
return { key, package: { id: 'pkg:cran/' + encodeURIComponent(name) + '@' + encodeURIComponent(version), name, version,
|
|
52
|
+
source, groups: [], direct: 'unknown', ...(license === undefined ? {} : { license }) },
|
|
53
|
+
dependencies: dependencies(raw) };
|
|
54
|
+
}
|
|
55
|
+
function links(entries) {
|
|
56
|
+
const index = new Map(entries.map(row => [row.key, row.package.id]));
|
|
57
|
+
const edges = [];
|
|
58
|
+
let incomplete = false;
|
|
59
|
+
for (const { package: pkg, dependencies: { known, required, optional } } of entries) {
|
|
60
|
+
if (!known)
|
|
61
|
+
incomplete = true;
|
|
62
|
+
for (const name of new Set([...required, ...optional])) {
|
|
63
|
+
const target = index.get(name);
|
|
64
|
+
if (target !== undefined)
|
|
65
|
+
edges.push({ from: pkg.id, to: target });
|
|
66
|
+
else if (required.has(name))
|
|
67
|
+
incomplete = true;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return { edges, incomplete };
|
|
71
|
+
}
|
|
72
|
+
export function readRenv({ text }) {
|
|
73
|
+
const lock = readJson(text);
|
|
74
|
+
if (!isRecord(lock) || !isRecord(lock.Packages))
|
|
75
|
+
throw new Error('Invalid renv package table');
|
|
76
|
+
const entries = Object.entries(lock.Packages).map(([key, value]) => readPackage(key, value));
|
|
77
|
+
const paths = entries.map(({ key }) => pointer(['Packages', key]));
|
|
78
|
+
const spans = locateJsonSpans(text, new Set(paths), 2);
|
|
79
|
+
const packages = entries.map(({ package: pkg }, index) => {
|
|
80
|
+
const span = spans.get(paths[index]);
|
|
81
|
+
if (span === undefined)
|
|
82
|
+
throw new Error('Missing renv package provenance');
|
|
83
|
+
return { ...pkg, ...span };
|
|
84
|
+
});
|
|
85
|
+
const { edges, incomplete } = links(entries);
|
|
86
|
+
const losses = ['roots', 'direct', 'groups'];
|
|
87
|
+
if (incomplete)
|
|
88
|
+
losses.push('edges');
|
|
89
|
+
if (packages.some(row => row.license === undefined))
|
|
90
|
+
losses.push('licenses');
|
|
91
|
+
return { format: 'renv', ecosystem: 'cran', packages, edges, roots: [], losses };
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=renv.js.map
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { isRecord, readJson } from '../json.js';
|
|
2
|
+
import { locateJsonSpans, pointer } from '../json-spans.js';
|
|
3
|
+
export const swift = { id: 'swift', ecosystem: 'swift', files: ['Package.resolved'],
|
|
4
|
+
edges: false, direct: false, licenses: false };
|
|
5
|
+
function kind(value, location, legacy) {
|
|
6
|
+
if (legacy)
|
|
7
|
+
return /^(?:\/|\.{1,2}\/|file:)/i.test(location) ? 'path' : 'git';
|
|
8
|
+
switch (value) {
|
|
9
|
+
case 'localSourceControl': return 'path';
|
|
10
|
+
case 'remoteSourceControl': return 'git';
|
|
11
|
+
case 'registry': return 'registry';
|
|
12
|
+
default: return 'unknown';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function remotePath(location) {
|
|
16
|
+
try {
|
|
17
|
+
const url = new URL(location);
|
|
18
|
+
if (url.hostname)
|
|
19
|
+
return [url.host, ...url.pathname.split('/').filter(Boolean).map(decodeURIComponent)];
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
const scp = /^(?:[^@/:]+@)?([^/:]+):([^?#]+)$/.exec(location);
|
|
23
|
+
if (scp)
|
|
24
|
+
return [scp[1], ...scp[2].split('/').filter(Boolean)];
|
|
25
|
+
}
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
function swiftId(name, location, source, pin) {
|
|
29
|
+
const normalized = name.toLowerCase();
|
|
30
|
+
let components = [normalized];
|
|
31
|
+
if (source === 'registry') {
|
|
32
|
+
const separator = normalized.indexOf('.');
|
|
33
|
+
if (separator > 0)
|
|
34
|
+
components = [normalized.slice(0, separator), normalized.slice(separator + 1)];
|
|
35
|
+
}
|
|
36
|
+
if (source === 'git') {
|
|
37
|
+
const path = remotePath(location);
|
|
38
|
+
if (path && path.length >= 2)
|
|
39
|
+
components = [...path.slice(0, -1), path.at(-1).replace(/\.git$/i, '').toLowerCase()];
|
|
40
|
+
}
|
|
41
|
+
return 'pkg:swift/' + components.map(encodeURIComponent).join('/') + '@' + encodeURIComponent(pin);
|
|
42
|
+
}
|
|
43
|
+
function readPin(value, legacy) {
|
|
44
|
+
if (!isRecord(value) || !isRecord(value.state))
|
|
45
|
+
throw new Error('Invalid Swift package pin');
|
|
46
|
+
const name = legacy ? value.package : value.identity;
|
|
47
|
+
const location = legacy ? value.repositoryURL : value.location;
|
|
48
|
+
if (typeof name !== 'string' || !name.trim() || typeof location !== 'string')
|
|
49
|
+
throw new Error('Incomplete Swift package pin');
|
|
50
|
+
const version = typeof value.state.version === 'string' && value.state.version !== '' ? value.state.version : undefined;
|
|
51
|
+
const revision = typeof value.state.revision === 'string' && value.state.revision !== '' ? value.state.revision : undefined;
|
|
52
|
+
if (version === undefined && revision === undefined)
|
|
53
|
+
throw new Error('Missing Swift package resolution');
|
|
54
|
+
if (!legacy && typeof value.kind !== 'string')
|
|
55
|
+
throw new Error('Missing Swift source kind');
|
|
56
|
+
const source = kind(value.kind, location, legacy);
|
|
57
|
+
const id = swiftId(name, location, source, version ?? revision);
|
|
58
|
+
return { id, name, ...(version === undefined ? {} : { version }), source,
|
|
59
|
+
groups: [], direct: 'unknown' };
|
|
60
|
+
}
|
|
61
|
+
export function readSwift({ text }) {
|
|
62
|
+
const value = readJson(text);
|
|
63
|
+
if (!isRecord(value) || (value.version !== 1 && value.version !== 2 && value.version !== 3))
|
|
64
|
+
throw new Error('Unsupported Swift package lock');
|
|
65
|
+
const legacy = value.version === 1;
|
|
66
|
+
const path = legacy ? ['object', 'pins'] : ['pins'];
|
|
67
|
+
const pins = legacy ? (isRecord(value.object) ? value.object.pins : undefined) : value.pins;
|
|
68
|
+
if (!Array.isArray(pins))
|
|
69
|
+
throw new Error('Invalid Swift pin list');
|
|
70
|
+
const keys = pins.map((_pin, index) => pointer([...path, index]));
|
|
71
|
+
const spans = locateJsonSpans(text, new Set(keys), path.length + 1);
|
|
72
|
+
const identities = new Set();
|
|
73
|
+
const packages = pins.map((pin, index) => {
|
|
74
|
+
const raw = readPin(pin, legacy);
|
|
75
|
+
const key = raw.name.toLowerCase();
|
|
76
|
+
if (identities.has(key))
|
|
77
|
+
throw new Error('Duplicate Swift package identity');
|
|
78
|
+
identities.add(key);
|
|
79
|
+
const span = spans.get(keys[index]);
|
|
80
|
+
if (span === undefined)
|
|
81
|
+
throw new Error('Missing Swift package provenance');
|
|
82
|
+
return { ...raw, ...span };
|
|
83
|
+
});
|
|
84
|
+
return { format: 'swift', ecosystem: 'swift', packages, edges: [], roots: [],
|
|
85
|
+
losses: ['edges', 'roots', 'direct', 'groups', 'licenses'] };
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=swift.js.map
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { isSymbol, tomlRecords } from './toml-statements.js';
|
|
2
|
+
export const terraform = { id: 'terraform', ecosystem: 'terraform', files: ['.terraform.lock.hcl'],
|
|
3
|
+
edges: false, direct: false, licenses: false };
|
|
4
|
+
const providerAddress = /^(?:[A-Za-z0-9.-]+(?::\d+)?\/)?[A-Za-z0-9_-]+\/[A-Za-z0-9_-]+$/;
|
|
5
|
+
function stringList(tokens, position) {
|
|
6
|
+
const values = [];
|
|
7
|
+
let expected = true;
|
|
8
|
+
for (let index = position + 1; index < tokens.length; index++) {
|
|
9
|
+
const token = tokens[index];
|
|
10
|
+
if (isSymbol(token, ']'))
|
|
11
|
+
return [values, index + 1];
|
|
12
|
+
if (expected && token.kind === 'text')
|
|
13
|
+
values.push(token.value);
|
|
14
|
+
else if (expected || !isSymbol(token, ','))
|
|
15
|
+
throw new Error('Invalid Terraform provider hashes');
|
|
16
|
+
expected = !expected;
|
|
17
|
+
}
|
|
18
|
+
throw new Error('Unclosed Terraform provider hashes');
|
|
19
|
+
}
|
|
20
|
+
function providerFields(tokens) {
|
|
21
|
+
const fields = new Map();
|
|
22
|
+
for (let index = 0; index < tokens.length;) {
|
|
23
|
+
const key = tokens[index];
|
|
24
|
+
const separator = tokens[index + 1];
|
|
25
|
+
const value = tokens[index + 2];
|
|
26
|
+
if (key?.kind !== 'bare' || !isSymbol(separator, '=') || fields.has(key.value)) {
|
|
27
|
+
throw new Error('Invalid Terraform provider field');
|
|
28
|
+
}
|
|
29
|
+
if (value?.kind === 'text') {
|
|
30
|
+
fields.set(key.value, value.value);
|
|
31
|
+
index += 3;
|
|
32
|
+
}
|
|
33
|
+
else if (isSymbol(value, '[')) {
|
|
34
|
+
const [items, end] = stringList(tokens, index + 2);
|
|
35
|
+
fields.set(key.value, items);
|
|
36
|
+
index = end;
|
|
37
|
+
}
|
|
38
|
+
else
|
|
39
|
+
throw new Error('Invalid Terraform provider field value');
|
|
40
|
+
}
|
|
41
|
+
return fields;
|
|
42
|
+
}
|
|
43
|
+
function readProvider({ tokens, line, endLine }) {
|
|
44
|
+
const [type, address, bracket] = tokens;
|
|
45
|
+
if (type?.kind !== 'bare' || type.value !== 'provider' || address?.kind !== 'text' || !providerAddress.test(address.value)
|
|
46
|
+
|| !isSymbol(bracket, '{') || !isSymbol(tokens.at(-1), '}'))
|
|
47
|
+
throw new Error('Invalid Terraform lock provider block');
|
|
48
|
+
const fields = providerFields(tokens.slice(3, -1));
|
|
49
|
+
const version = fields.get('version');
|
|
50
|
+
const hashes = fields.get('hashes');
|
|
51
|
+
if (typeof version !== 'string' || version === '' || (hashes !== undefined && !Array.isArray(hashes))) {
|
|
52
|
+
throw new Error('Invalid Terraform provider version or hashes');
|
|
53
|
+
}
|
|
54
|
+
const pieces = address.value.split('/');
|
|
55
|
+
if (pieces.length === 2)
|
|
56
|
+
pieces.unshift('registry.terraform.io');
|
|
57
|
+
const name = pieces.at(-1);
|
|
58
|
+
const id = 'pkg:terraform/' + pieces.map(encodeURIComponent).join('/') + '@' + encodeURIComponent(version);
|
|
59
|
+
const recorded = new Set(hashes ?? []);
|
|
60
|
+
for (const digest of recorded) {
|
|
61
|
+
if (!/^[a-z][a-z0-9-]*:[A-Za-z0-9+/]+={0,2}$/i.test(digest))
|
|
62
|
+
throw new Error('Invalid Terraform provider checksum');
|
|
63
|
+
}
|
|
64
|
+
return { row: { id, name, version, source: 'registry', groups: [], direct: 'unknown', line, endLine,
|
|
65
|
+
...(recorded.size === 1 ? { integrity: recorded.values().next().value } : {}) }, multipleDigests: recorded.size > 1 };
|
|
66
|
+
}
|
|
67
|
+
export function readTerraform({ text }) {
|
|
68
|
+
const packages = [];
|
|
69
|
+
const seen = new Set();
|
|
70
|
+
let integrityLoss = false;
|
|
71
|
+
for (const statement of tomlRecords(text)) {
|
|
72
|
+
const { row, multipleDigests } = readProvider(statement);
|
|
73
|
+
const identity = row.id.slice(0, row.id.lastIndexOf('@'));
|
|
74
|
+
if (seen.has(identity))
|
|
75
|
+
throw new Error('Duplicate Terraform provider address');
|
|
76
|
+
seen.add(identity);
|
|
77
|
+
packages.push(row);
|
|
78
|
+
integrityLoss ||= multipleDigests;
|
|
79
|
+
}
|
|
80
|
+
const losses = ['edges', 'roots', 'direct', 'groups', 'licenses'];
|
|
81
|
+
if (integrityLoss)
|
|
82
|
+
losses.push('integrity');
|
|
83
|
+
return { format: 'terraform', ecosystem: 'terraform', packages, edges: [], roots: [], losses };
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=terraform.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { TomlObject } from './toml-values.js';
|
|
2
|
+
interface Span {
|
|
3
|
+
readonly line: number;
|
|
4
|
+
endLine: number;
|
|
5
|
+
}
|
|
6
|
+
export interface TomlDocument {
|
|
7
|
+
readonly root: TomlObject;
|
|
8
|
+
readonly spans: WeakMap<TomlObject, Span>;
|
|
9
|
+
}
|
|
10
|
+
export declare function readTomlDocument(text: string): TomlDocument;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { isSymbol, tomlKey, tomlRecords } from './toml-statements.js';
|
|
2
|
+
import { assignment, writeValue } from './toml-values.js';
|
|
3
|
+
export function readTomlDocument(text) {
|
|
4
|
+
const document = new Document();
|
|
5
|
+
for (const statement of tomlRecords(text))
|
|
6
|
+
document.read(statement);
|
|
7
|
+
return { root: document.root, spans: document.spans };
|
|
8
|
+
}
|
|
9
|
+
class Document {
|
|
10
|
+
root = new Map();
|
|
11
|
+
spans = new WeakMap();
|
|
12
|
+
parents = new WeakMap();
|
|
13
|
+
arrays = new WeakSet();
|
|
14
|
+
explicit = new WeakSet();
|
|
15
|
+
current = this.root;
|
|
16
|
+
read({ tokens, line, endLine }) {
|
|
17
|
+
if (isSymbol(tokens[0], '[')) {
|
|
18
|
+
const array = isSymbol(tokens[1], '[');
|
|
19
|
+
const width = array ? 2 : 1;
|
|
20
|
+
const keys = tomlKey(tokens.slice(width, -width));
|
|
21
|
+
const path = this.path(this.root, keys.slice(0, -1));
|
|
22
|
+
const name = keys.at(-1);
|
|
23
|
+
this.current = array ? this.arrayTable(path, name) : this.table(path, name);
|
|
24
|
+
if (this.explicit.has(this.current))
|
|
25
|
+
throw new Error('Duplicate TOML table: ' + keys.join('.'));
|
|
26
|
+
this.explicit.add(this.current);
|
|
27
|
+
this.spans.set(this.current, { line, endLine });
|
|
28
|
+
this.extend(this.current, endLine);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
const [keys, value] = assignment(tokens);
|
|
32
|
+
const path = this.path(this.current, keys.slice(0, -1));
|
|
33
|
+
writeValue(path, keys.at(-1), value);
|
|
34
|
+
this.extend(path, endLine);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
path(start, keys) {
|
|
38
|
+
return keys.reduce((parent, key) => this.table(parent, key), start);
|
|
39
|
+
}
|
|
40
|
+
arrayTable(parent, key) {
|
|
41
|
+
const before = parent.get(key);
|
|
42
|
+
const row = new Map();
|
|
43
|
+
this.parents.set(row, parent);
|
|
44
|
+
if (before === undefined) {
|
|
45
|
+
const rows = [row];
|
|
46
|
+
this.arrays.add(rows);
|
|
47
|
+
parent.set(key, rows);
|
|
48
|
+
}
|
|
49
|
+
else if (Array.isArray(before) && this.arrays.has(before)) {
|
|
50
|
+
before.push(row);
|
|
51
|
+
}
|
|
52
|
+
else
|
|
53
|
+
throw new Error('Invalid TOML array table: ' + key);
|
|
54
|
+
return row;
|
|
55
|
+
}
|
|
56
|
+
table(parent, key) {
|
|
57
|
+
const before = parent.get(key);
|
|
58
|
+
if (before instanceof Map && this.parents.has(before))
|
|
59
|
+
return before;
|
|
60
|
+
if (Array.isArray(before) && this.arrays.has(before))
|
|
61
|
+
return before.at(-1);
|
|
62
|
+
if (before !== undefined)
|
|
63
|
+
throw new Error('Invalid TOML table: ' + key);
|
|
64
|
+
const row = new Map();
|
|
65
|
+
parent.set(key, row);
|
|
66
|
+
this.parents.set(row, parent);
|
|
67
|
+
return row;
|
|
68
|
+
}
|
|
69
|
+
extend(start, endLine) {
|
|
70
|
+
let row = start;
|
|
71
|
+
while (row !== undefined) {
|
|
72
|
+
const span = this.spans.get(row);
|
|
73
|
+
if (span !== undefined)
|
|
74
|
+
span.endLine = endLine;
|
|
75
|
+
row = this.parents.get(row);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=toml-document.js.map
|