@repometry/lockparse 0.0.0-stage → 0.0.1

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.
Files changed (78) hide show
  1. package/package.json +31 -4
  2. package/target/main/ts/formats/bundler-gemfile.d.ts +1 -0
  3. package/target/main/ts/formats/bundler-gemfile.js +191 -0
  4. package/target/main/ts/formats/bundler-lock.d.ts +26 -0
  5. package/target/main/ts/formats/bundler-lock.js +110 -0
  6. package/target/main/ts/formats/bundler.d.ts +3 -0
  7. package/target/main/ts/formats/bundler.js +84 -0
  8. package/target/main/ts/formats/cargo-lock.d.ts +15 -0
  9. package/target/main/ts/formats/cargo-lock.js +127 -0
  10. package/target/main/ts/formats/cargo-manifest.d.ts +25 -0
  11. package/target/main/ts/formats/cargo-manifest.js +146 -0
  12. package/target/main/ts/formats/cargo-roots.d.ts +10 -0
  13. package/target/main/ts/formats/cargo-roots.js +116 -0
  14. package/target/main/ts/formats/cargo.d.ts +3 -0
  15. package/target/main/ts/formats/cargo.js +108 -0
  16. package/target/main/ts/formats/carton.d.ts +3 -0
  17. package/target/main/ts/formats/carton.js +127 -0
  18. package/target/main/ts/formats/composer.d.ts +5 -0
  19. package/target/main/ts/formats/composer.js +126 -0
  20. package/target/main/ts/formats/conan-reference.d.ts +11 -0
  21. package/target/main/ts/formats/conan-reference.js +32 -0
  22. package/target/main/ts/formats/conan.d.ts +3 -0
  23. package/target/main/ts/formats/conan.js +138 -0
  24. package/target/main/ts/formats/dart.d.ts +3 -0
  25. package/target/main/ts/formats/dart.js +122 -0
  26. package/target/main/ts/formats/go-mod.d.ts +28 -0
  27. package/target/main/ts/formats/go-mod.js +148 -0
  28. package/target/main/ts/formats/go.d.ts +3 -0
  29. package/target/main/ts/formats/go.js +74 -0
  30. package/target/main/ts/formats/gradle.d.ts +3 -0
  31. package/target/main/ts/formats/gradle.js +42 -0
  32. package/target/main/ts/formats/lines.d.ts +5 -0
  33. package/target/main/ts/formats/lines.js +12 -0
  34. package/target/main/ts/formats/mix-literals.d.ts +22 -0
  35. package/target/main/ts/formats/mix-literals.js +145 -0
  36. package/target/main/ts/formats/mix.d.ts +3 -0
  37. package/target/main/ts/formats/mix.js +90 -0
  38. package/target/main/ts/formats/nuget.d.ts +3 -0
  39. package/target/main/ts/formats/nuget.js +112 -0
  40. package/target/main/ts/formats/pdm.d.ts +3 -0
  41. package/target/main/ts/formats/pdm.js +52 -0
  42. package/target/main/ts/formats/pipenv.d.ts +3 -0
  43. package/target/main/ts/formats/pipenv.js +151 -0
  44. package/target/main/ts/formats/poetry-lock.d.ts +15 -0
  45. package/target/main/ts/formats/poetry-lock.js +68 -0
  46. package/target/main/ts/formats/poetry.d.ts +3 -0
  47. package/target/main/ts/formats/poetry.js +9 -0
  48. package/target/main/ts/formats/python-graph.d.ts +16 -0
  49. package/target/main/ts/formats/python-graph.js +91 -0
  50. package/target/main/ts/formats/python-package.d.ts +15 -0
  51. package/target/main/ts/formats/python-package.js +63 -0
  52. package/target/main/ts/formats/python-project.d.ts +12 -0
  53. package/target/main/ts/formats/python-project.js +76 -0
  54. package/target/main/ts/formats/renv.d.ts +3 -0
  55. package/target/main/ts/formats/renv.js +93 -0
  56. package/target/main/ts/formats/swift.d.ts +3 -0
  57. package/target/main/ts/formats/swift.js +87 -0
  58. package/target/main/ts/formats/terraform.d.ts +3 -0
  59. package/target/main/ts/formats/terraform.js +85 -0
  60. package/target/main/ts/formats/toml-document.d.ts +11 -0
  61. package/target/main/ts/formats/toml-document.js +79 -0
  62. package/target/main/ts/formats/toml-statements.d.ts +13 -0
  63. package/target/main/ts/formats/toml-statements.js +144 -0
  64. package/target/main/ts/formats/toml-values.d.ts +12 -0
  65. package/target/main/ts/formats/toml-values.js +111 -0
  66. package/target/main/ts/formats/uv-lock.d.ts +27 -0
  67. package/target/main/ts/formats/uv-lock.js +80 -0
  68. package/target/main/ts/formats/uv.d.ts +3 -0
  69. package/target/main/ts/formats/uv.js +114 -0
  70. package/target/main/ts/index.d.ts +14 -0
  71. package/target/main/ts/index.js +66 -0
  72. package/target/main/ts/json-spans.d.ts +11 -0
  73. package/target/main/ts/json-spans.js +86 -0
  74. package/target/main/ts/json.d.ts +2 -0
  75. package/target/main/ts/json.js +29 -0
  76. package/target/main/ts/model.d.ts +48 -0
  77. package/target/main/ts/model.js +2 -0
  78. package/README.md +0 -3
@@ -0,0 +1,13 @@
1
+ export interface TomlToken {
2
+ readonly kind: 'text' | 'bare' | 'symbol';
3
+ readonly value: string;
4
+ }
5
+ export interface TomlStatement {
6
+ readonly tokens: readonly TomlToken[];
7
+ readonly line: number;
8
+ readonly endLine: number;
9
+ }
10
+ export declare function tomlStatements(text: string): IterableIterator<readonly TomlToken[]>;
11
+ export declare function tomlRecords(text: string): IterableIterator<TomlStatement>;
12
+ export declare function isSymbol(token: TomlToken | undefined, value: string): boolean;
13
+ export declare function tomlKey(tokens: readonly TomlToken[]): string[];
@@ -0,0 +1,144 @@
1
+ const whitespace = /[ \t\r]/;
2
+ const symbols = new Set(['[', ']', '{', '}', '.', '=', ',']);
3
+ const bare = /[^ \t\r\n[\]{}.=,'"#]+/y;
4
+ const maxDepth = 64;
5
+ export function* tomlStatements(text) {
6
+ for (const { tokens } of tomlRecords(text))
7
+ yield tokens;
8
+ }
9
+ export function* tomlRecords(text) {
10
+ let tokens = [];
11
+ let line = 1;
12
+ let start = 1;
13
+ const opened = [];
14
+ for (let position = 0; position < text.length;) {
15
+ const char = text[position];
16
+ if (char === '\n') {
17
+ if (opened.length === 0 && tokens.length > 0) {
18
+ yield { tokens, line: start, endLine: line };
19
+ tokens = [];
20
+ }
21
+ line++;
22
+ position++;
23
+ }
24
+ else if (whitespace.test(char)) {
25
+ position++;
26
+ }
27
+ else if (char === '#') {
28
+ const end = text.indexOf('\n', position);
29
+ position = end < 0 ? text.length : end;
30
+ }
31
+ else {
32
+ if (tokens.length === 0)
33
+ start = line;
34
+ const [token, end] = readToken(text, position);
35
+ if (token.kind === 'symbol')
36
+ trackCollections(opened, token.value);
37
+ if (token.kind === 'text')
38
+ line += lineFeeds(text, position, end);
39
+ tokens.push(token);
40
+ position = end;
41
+ }
42
+ }
43
+ if (opened.length > 0)
44
+ throw new Error('Unclosed TOML collection');
45
+ if (tokens.length > 0)
46
+ yield { tokens, line: start, endLine: line };
47
+ }
48
+ function lineFeeds(text, start, end) {
49
+ let count = 0;
50
+ for (let offset = start; offset < end; offset++)
51
+ if (text[offset] === '\n')
52
+ count++;
53
+ return count;
54
+ }
55
+ function trackCollections(opened, char) {
56
+ if (char === '[' || char === '{') {
57
+ opened.push(char === '[' ? ']' : '}');
58
+ if (opened.length > maxDepth)
59
+ throw new Error('TOML collection nesting is too deep');
60
+ }
61
+ else if ((char === ']' || char === '}') && opened.pop() !== char) {
62
+ throw new Error('Unexpected TOML collection terminator');
63
+ }
64
+ }
65
+ function readToken(text, position) {
66
+ const char = text[position];
67
+ if (symbols.has(char))
68
+ return [{ kind: 'symbol', value: char }, position + 1];
69
+ if (char === '"' || char === "'")
70
+ return readString(text, position, char);
71
+ bare.lastIndex = position;
72
+ const found = bare.exec(text);
73
+ if (found === null)
74
+ throw new Error('Invalid TOML token');
75
+ return [{ kind: 'bare', value: found[0] }, bare.lastIndex];
76
+ }
77
+ function readString(text, start, quote) {
78
+ const triple = quote.repeat(3);
79
+ const multiline = text.startsWith(triple, start);
80
+ const period = multiline ? triple : quote;
81
+ const content = start + period.length;
82
+ let position = content;
83
+ while (position < text.length) {
84
+ if (text.startsWith(period, position)) {
85
+ const end = multiline ? endOfQuotes(text, position + 3, quote) : position + 1;
86
+ const value = text.slice(content, end - period.length);
87
+ const trimmed = multiline ? value.replace(/^\r?\n/, '') : value;
88
+ return [{ kind: 'text', value: quote === '"' ? basicString(trimmed, multiline) : trimmed }, end];
89
+ }
90
+ const char = text[position];
91
+ if (!multiline && (char === '\n' || char === '\r'))
92
+ break;
93
+ position += quote === '"' && char === '\\' ? 2 : 1;
94
+ }
95
+ throw new Error('Unterminated TOML string');
96
+ }
97
+ function endOfQuotes(text, start, quote) {
98
+ let end = start;
99
+ while (text[end] === quote && end < start + 2)
100
+ end++;
101
+ return end;
102
+ }
103
+ const escapes = new Map([['b', '\b'], ['t', '\t'], ['n', '\n'], ['f', '\f'], ['r', '\r'], ['"', '"'], ['\\', '\\']]);
104
+ function basicString(raw, multiline) {
105
+ return raw.replace(/\\(?:([ \t]*\r?\n[ \t\r\n]*)|u([0-9a-fA-F]{4})|U([0-9a-fA-F]{8})|([\s\S]))/g, (_match, joined, short, long, escaped) => {
106
+ if (joined !== undefined && multiline)
107
+ return '';
108
+ const code = short ?? long;
109
+ if (code !== undefined)
110
+ return codePoint(code);
111
+ const value = escapes.get(escaped);
112
+ if (value === undefined)
113
+ throw new Error('Invalid TOML escape');
114
+ return value;
115
+ });
116
+ }
117
+ function codePoint(hex) {
118
+ const code = Number.parseInt(hex, 16);
119
+ if (code >= 0xd800 && code <= 0xdfff)
120
+ throw new Error('Invalid TOML Unicode escape');
121
+ return String.fromCodePoint(code);
122
+ }
123
+ export function isSymbol(token, value) {
124
+ return token?.kind === 'symbol' && token.value === value;
125
+ }
126
+ export function tomlKey(tokens) {
127
+ if (tokens.length === 0 || tokens.length > maxDepth * 2 - 1)
128
+ throw new Error('Invalid TOML key length');
129
+ const path = [];
130
+ for (let index = 0; index < tokens.length; index++) {
131
+ const { kind, value } = tokens[index];
132
+ if (index % 2 === 0) {
133
+ if (kind !== 'text' && (kind !== 'bare' || !/^[\w-]+$/.test(value)))
134
+ throw new Error('Invalid TOML key');
135
+ path.push(value);
136
+ }
137
+ else if (kind !== 'symbol' || value !== '.')
138
+ throw new Error('Invalid TOML key separator');
139
+ }
140
+ if (tokens.length % 2 === 0)
141
+ throw new Error('Incomplete TOML key');
142
+ return path;
143
+ }
144
+ //# sourceMappingURL=toml-statements.js.map
@@ -0,0 +1,12 @@
1
+ import type { TomlToken } from './toml-statements.js';
2
+ interface OtherScalar {
3
+ readonly raw: string;
4
+ }
5
+ export type TomlValue = string | boolean | OtherScalar | TomlValue[] | TomlObject;
6
+ export type TomlObject = Map<string, TomlValue>;
7
+ export declare function assignment(tokens: readonly TomlToken[]): [readonly string[], TomlValue];
8
+ export declare function writeValue(parent: TomlObject, name: string, value: TomlValue): void;
9
+ export declare function field(object: TomlValue | undefined, key: string): TomlValue | undefined;
10
+ export declare function textField(object: TomlValue | undefined, name: string): string | undefined;
11
+ export declare function object(value: TomlValue | undefined): TomlObject | undefined;
12
+ export {};
@@ -0,0 +1,111 @@
1
+ import { isSymbol, tomlKey } from './toml-statements.js';
2
+ export function assignment(tokens) {
3
+ const boundary = tokens.findIndex(token => isSymbol(token, '='));
4
+ if (boundary < 1)
5
+ throw malformed();
6
+ const path = tomlKey(tokens.slice(0, boundary));
7
+ const reader = new ValueReader(tokens, boundary + 1);
8
+ const value = reader.read();
9
+ if (!reader.atEnd())
10
+ throw malformed();
11
+ return [path, value];
12
+ }
13
+ export function writeValue(parent, name, value) {
14
+ if (parent.has(name))
15
+ throw new Error('Duplicate TOML key: ' + name);
16
+ parent.set(name, value);
17
+ }
18
+ export function field(object, key) {
19
+ return object instanceof Map ? object.get(key) : undefined;
20
+ }
21
+ export function textField(object, name) {
22
+ const value = field(object, name);
23
+ return typeof value === 'string' ? value : undefined;
24
+ }
25
+ export function object(value) {
26
+ return value instanceof Map ? value : undefined;
27
+ }
28
+ function malformed() {
29
+ return new Error('Invalid TOML value');
30
+ }
31
+ class ValueReader {
32
+ tokens;
33
+ position;
34
+ constructor(tokens, position) {
35
+ this.tokens = tokens;
36
+ this.position = position;
37
+ }
38
+ atEnd() {
39
+ return this.position === this.tokens.length;
40
+ }
41
+ read() {
42
+ const token = this.tokens[this.position++];
43
+ if (isSymbol(token, '['))
44
+ return this.list();
45
+ if (isSymbol(token, '{'))
46
+ return this.table();
47
+ if (token?.kind === 'text')
48
+ return token.value;
49
+ if (token?.kind === 'bare')
50
+ return this.atom(token.value);
51
+ throw malformed();
52
+ }
53
+ list() {
54
+ const rows = [];
55
+ while (!this.take(']')) {
56
+ rows.push(this.read());
57
+ if (this.take(']'))
58
+ return rows;
59
+ this.require(',');
60
+ }
61
+ return rows;
62
+ }
63
+ table() {
64
+ const fields = new Map();
65
+ if (this.take('}'))
66
+ return fields;
67
+ for (;;) {
68
+ const start = this.position;
69
+ while (!this.atEnd() && !isSymbol(this.tokens[this.position], '='))
70
+ this.position++;
71
+ const keys = tomlKey(this.tokens.slice(start, this.position));
72
+ this.require('=');
73
+ let destination = fields;
74
+ for (const key of keys.slice(0, -1)) {
75
+ const existing = destination.get(key);
76
+ if (existing !== undefined && !(existing instanceof Map))
77
+ throw malformed();
78
+ const child = existing ?? new Map();
79
+ destination.set(key, child);
80
+ destination = child;
81
+ }
82
+ writeValue(destination, keys.at(-1), this.read());
83
+ if (this.take('}'))
84
+ return fields;
85
+ this.require(',');
86
+ }
87
+ }
88
+ atom(initial) {
89
+ if (initial === 'true' || initial === 'false')
90
+ return initial === 'true';
91
+ const start = this.position - 1;
92
+ while (this.moreAtom())
93
+ this.position++;
94
+ return { raw: this.tokens.slice(start, this.position).map(token => token.value).join('') };
95
+ }
96
+ moreAtom() {
97
+ const next = this.tokens[this.position];
98
+ return next?.kind === 'bare' || isSymbol(next, '.');
99
+ }
100
+ take(symbol) {
101
+ if (!isSymbol(this.tokens[this.position], symbol))
102
+ return false;
103
+ this.position++;
104
+ return true;
105
+ }
106
+ require(symbol) {
107
+ if (!this.take(symbol))
108
+ throw malformed();
109
+ }
110
+ }
111
+ //# sourceMappingURL=toml-values.js.map
@@ -0,0 +1,27 @@
1
+ import type { LockPackage, PackageSource } from '../model.js';
2
+ export interface Reference {
3
+ readonly name: string;
4
+ readonly version?: string;
5
+ readonly sourceKey?: string;
6
+ readonly group?: string;
7
+ }
8
+ interface Source {
9
+ readonly key: string;
10
+ readonly kind: PackageSource;
11
+ readonly path?: string;
12
+ }
13
+ export interface UvEntry {
14
+ readonly id: string;
15
+ readonly name: string;
16
+ readonly version?: string;
17
+ readonly ranges: Pick<LockPackage, 'line' | 'endLine'>;
18
+ readonly source: Source;
19
+ readonly requests: readonly Reference[];
20
+ readonly digests: readonly string[];
21
+ }
22
+ export declare function readUvLock(text: string): {
23
+ packages: UvEntry[];
24
+ members: readonly string[];
25
+ manifestRequests: readonly Reference[];
26
+ };
27
+ export {};
@@ -0,0 +1,80 @@
1
+ import { exactPythonVersion, fileDigests, pypi, pypiIds, pythonName, tableField } from './python-package.js';
2
+ import { readTomlDocument } from './toml-document.js';
3
+ import { field, object, textField } from './toml-values.js';
4
+ const sourceTypes = new Map([
5
+ ['registry', 'registry'], ['git', 'git'], ['url', 'url'], ['path', 'path'], ['directory', 'path'],
6
+ ['editable', 'path'], ['virtual', 'path'],
7
+ ]);
8
+ function sourceOf(value) {
9
+ const table = object(value);
10
+ if (!table?.size)
11
+ throw new Error('Missing uv package source');
12
+ const type = [...sourceTypes.keys()].filter(key => table.has(key));
13
+ if (type.length > 1)
14
+ throw new Error('Conflicting uv package origins');
15
+ const [tag] = type;
16
+ const kind = tag === undefined ? 'unknown' : sourceTypes.get(tag);
17
+ const path = tag === 'virtual' || tag === 'editable' || tag === 'directory' ? textField(table, tag) : undefined;
18
+ const key = JSON.stringify([...table].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0));
19
+ return { key, kind, path };
20
+ }
21
+ function references(value, group) {
22
+ if (value === undefined)
23
+ return [];
24
+ if (!Array.isArray(value))
25
+ throw new Error('Invalid uv dependency list');
26
+ return value.map(item => {
27
+ const name = textField(item, 'name');
28
+ if (name === undefined)
29
+ throw new Error('Missing uv dependency name');
30
+ const from = field(item, 'source');
31
+ return { name: pythonName(name), version: textField(item, 'version') ?? exactPythonVersion(textField(item, 'specifier')),
32
+ sourceKey: from === undefined ? undefined : sourceOf(from).key, group };
33
+ });
34
+ }
35
+ function groupedReferences(value, preserveGroups) {
36
+ return [...value ?? []].flatMap(([name, items]) => references(items, preserveGroups ? name : undefined));
37
+ }
38
+ function artifactDigests(pkg) {
39
+ const wheel = pkg.get('wheels');
40
+ return fileDigests([pkg.get('sdist') ?? '', ...(Array.isArray(wheel) ? wheel : [])]);
41
+ }
42
+ function readPackage(pkg, document) {
43
+ if (!(pkg instanceof Map))
44
+ throw new Error('Invalid uv package');
45
+ const name = textField(pkg, 'name');
46
+ const version = textField(pkg, 'version');
47
+ const ranges = document.spans.get(pkg);
48
+ if (!name || !ranges)
49
+ throw new Error('Incomplete uv package');
50
+ const requests = [...references(pkg.get('dependencies')),
51
+ ...groupedReferences(tableField(pkg, 'optional-dependencies'), false),
52
+ ...groupedReferences(tableField(pkg, 'dev-dependencies'), true)];
53
+ return { name, version, ranges, requests, source: sourceOf(pkg.get('source')), digests: artifactDigests(pkg) };
54
+ }
55
+ function memberNames(value) {
56
+ if (value === undefined)
57
+ return [];
58
+ if (!Array.isArray(value) || !value.every((name) => typeof name === 'string')) {
59
+ throw new Error('Invalid uv workspace membership');
60
+ }
61
+ return value.map(pythonName);
62
+ }
63
+ export function readUvLock(text) {
64
+ const document = readTomlDocument(text);
65
+ const version = document.root.get('version');
66
+ if (version === undefined || typeof version !== 'object' || !('raw' in version) || version.raw !== '1') {
67
+ throw new Error('Unsupported uv lock version');
68
+ }
69
+ const list = document.root.get('package') ?? [];
70
+ if (!Array.isArray(list))
71
+ throw new Error('Invalid uv package list');
72
+ const raw = list.map(pkg => readPackage(pkg, document));
73
+ const ids = pypiIds(raw, pkg => pypi(pkg.name, pkg.version), pkg => [pkg.source.key]);
74
+ const manifest = tableField(document.root, 'manifest');
75
+ const manifestRequests = [...references(manifest?.get('requirements')),
76
+ ...groupedReferences(tableField(manifest, 'dependency-groups'), true)];
77
+ return { packages: raw.map((pkg, index) => ({ ...pkg, id: ids[index] })), members: memberNames(manifest?.get('members')),
78
+ manifestRequests };
79
+ }
80
+ //# sourceMappingURL=uv-lock.js.map
@@ -0,0 +1,3 @@
1
+ import type { LockFormat, LockGraph, LockInput } from '../model.js';
2
+ export declare const uv: LockFormat;
3
+ export declare function readUv(input: LockInput): LockGraph;
@@ -0,0 +1,114 @@
1
+ import { pypi, pythonName } from './python-package.js';
2
+ import { projectFor } from './python-project.js';
3
+ import { readUvLock } from './uv-lock.js';
4
+ export const uv = { id: 'uv', ecosystem: 'pypi', files: ['uv.lock'],
5
+ edges: true, direct: true, licenses: false, integrity: true };
6
+ function key(name, version, sourceKey) {
7
+ return JSON.stringify([name, version, sourceKey]);
8
+ }
9
+ function indexPackages(packages) {
10
+ const index = new Map();
11
+ for (const pkg of packages) {
12
+ const name = pythonName(pkg.name);
13
+ const keys = new Set([key(name), key(name, pkg.version), key(name, undefined, pkg.source.key), key(name, pkg.version, pkg.source.key)]);
14
+ for (const id of keys)
15
+ index.set(id, index.has(id) ? null : pkg);
16
+ }
17
+ return index;
18
+ }
19
+ function identifyRoots(packages, members, input) {
20
+ const roots = new Set();
21
+ const byName = new Map();
22
+ for (const pkg of packages) {
23
+ if (pkg.source.path === undefined)
24
+ continue;
25
+ const name = pythonName(pkg.name);
26
+ byName.set(name, byName.has(name) ? null : pkg);
27
+ if (pkg.source.path === '.' || pkg.source.path === './')
28
+ roots.add(pkg.id);
29
+ }
30
+ let complete = true;
31
+ for (const name of members) {
32
+ const member = byName.get(name);
33
+ if (member)
34
+ roots.add(member.id);
35
+ else
36
+ complete = false;
37
+ }
38
+ if (roots.size === 0 && members.length === 0) {
39
+ const project = projectFor(input);
40
+ if (project?.id !== undefined) {
41
+ const matches = packages.filter(pkg => pkg.source.path !== undefined && pypi(pkg.name, pkg.version) === project.id);
42
+ if (matches.length === 1)
43
+ roots.add(matches[0].id);
44
+ }
45
+ }
46
+ return { roots, complete: complete && roots.size > 0 };
47
+ }
48
+ class Graph {
49
+ index;
50
+ edges = [];
51
+ declared = new Map();
52
+ incomplete = false;
53
+ constructor(index) {
54
+ this.index = index;
55
+ }
56
+ record(from, requests, direct) {
57
+ const targets = new Set();
58
+ for (const request of requests) {
59
+ const pkg = this.index.get(key(request.name, request.version, request.sourceKey));
60
+ if (!pkg) {
61
+ this.incomplete = true;
62
+ continue;
63
+ }
64
+ targets.add(pkg.id);
65
+ if (direct)
66
+ this.recordDirect(pkg.id, request.group);
67
+ }
68
+ if (from !== undefined)
69
+ for (const to of targets)
70
+ this.edges.push({ from, to });
71
+ }
72
+ recordDirect(id, group) {
73
+ const labels = this.declared.get(id) ?? new Set();
74
+ if (group !== undefined)
75
+ labels.add(group);
76
+ this.declared.set(id, labels);
77
+ }
78
+ }
79
+ function packageRow(pkg, declared, complete) {
80
+ const groups = declared.get(pkg.id);
81
+ const { name, id, version, ranges, source, digests } = pkg;
82
+ return { id, name, ...(version === undefined ? {} : { version }), ...ranges, source: source.kind,
83
+ groups: [...groups ?? []].sort(), direct: groups !== undefined ? true : complete ? false : 'unknown',
84
+ ...(digests.length === 1 ? { integrity: digests[0] } : {}) };
85
+ }
86
+ export function readUv(input) {
87
+ const lock = readUvLock(input.text);
88
+ const { roots, complete } = identifyRoots(lock.packages, lock.members, input);
89
+ const graph = new Graph(indexPackages(lock.packages));
90
+ const manifestRoot = roots.size === 1 ? roots.values().next().value : undefined;
91
+ for (const pkg of lock.packages) {
92
+ const requests = pkg.id === manifestRoot ? [...pkg.requests, ...lock.manifestRequests] : pkg.requests;
93
+ graph.record(pkg.id, requests, roots.has(pkg.id));
94
+ }
95
+ if (manifestRoot === undefined)
96
+ graph.record(undefined, lock.manifestRequests, true);
97
+ const completeDirect = complete && !graph.incomplete;
98
+ const packages = lock.packages.map(pkg => packageRow(pkg, graph.declared, completeDirect));
99
+ const losses = [];
100
+ if (graph.incomplete || (lock.manifestRequests.length > 0 && roots.size !== 1))
101
+ losses.push('edges');
102
+ if (!complete)
103
+ losses.push('roots');
104
+ if (!completeDirect)
105
+ losses.push('direct');
106
+ if (packages.some(row => !roots.has(row.id) && row.groups.length === 0))
107
+ losses.push('groups');
108
+ if (packages.length)
109
+ losses.push('licenses');
110
+ if (lock.packages.some(pkg => pkg.digests.length > 1))
111
+ losses.push('integrity');
112
+ return { format: 'uv', ecosystem: 'pypi', packages, edges: graph.edges, roots: [...roots], losses };
113
+ }
114
+ //# sourceMappingURL=uv.js.map
@@ -0,0 +1,14 @@
1
+ import type { FormatId, LockError, LockGraph, LockInput } from './model.js';
2
+ export { composerEvidence } from './formats/composer.js';
3
+ export type { FormatId, LockError, LockFormat, LockGraph, LockInput, LockPackage, LockEdge } from './model.js';
4
+ export declare const formats: readonly Readonly<{
5
+ id: FormatId;
6
+ ecosystem: import("./model.js").Ecosystem;
7
+ edges: boolean;
8
+ direct: boolean;
9
+ licenses: boolean;
10
+ integrity?: true;
11
+ files: readonly string[];
12
+ }>[];
13
+ export declare function detect(path: string, _text: string): FormatId | undefined;
14
+ export declare function parse(input: LockInput): LockGraph | LockError;
@@ -0,0 +1,66 @@
1
+ import { bundler, readBundler } from './formats/bundler.js';
2
+ import { carton, readCarton } from './formats/carton.js';
3
+ import { cargo, readCargo } from './formats/cargo.js';
4
+ import { conan, readConan } from './formats/conan.js';
5
+ import { composer, readComposer } from './formats/composer.js';
6
+ import { go, readGo } from './formats/go.js';
7
+ import { dart, readDart } from './formats/dart.js';
8
+ import { gradle, readGradle } from './formats/gradle.js';
9
+ import { nuget, readNuget } from './formats/nuget.js';
10
+ import { mix, readMix } from './formats/mix.js';
11
+ import { swift, readSwift } from './formats/swift.js';
12
+ import { terraform, readTerraform } from './formats/terraform.js';
13
+ import { renv, readRenv } from './formats/renv.js';
14
+ import { pdm, readPdm } from './formats/pdm.js';
15
+ import { pipenv, readPipenv } from './formats/pipenv.js';
16
+ import { poetry, readPoetry } from './formats/poetry.js';
17
+ import { uv, readUv } from './formats/uv.js';
18
+ export { composerEvidence } from './formats/composer.js';
19
+ const registry = [
20
+ [composer, readComposer],
21
+ [cargo, readCargo],
22
+ [go, readGo],
23
+ [bundler, readBundler],
24
+ [poetry, readPoetry],
25
+ [uv, readUv],
26
+ [pipenv, readPipenv],
27
+ [gradle, readGradle],
28
+ [nuget, readNuget],
29
+ [swift, readSwift],
30
+ [dart, readDart],
31
+ [mix, readMix],
32
+ [terraform, readTerraform],
33
+ [renv, readRenv],
34
+ [carton, readCarton],
35
+ [pdm, readPdm],
36
+ [conan, readConan],
37
+ ];
38
+ const readers = new Map(registry.map(([format, reader]) => [format.id, reader]));
39
+ export const formats = Object.freeze(registry.map(([format]) => Object.freeze({
40
+ ...format, files: Object.freeze([...format.files]),
41
+ })));
42
+ const inputLimit = 64 * 1024 * 1024;
43
+ export function detect(path, _text) {
44
+ const name = path.slice(path.lastIndexOf('/') + 1);
45
+ return formats.find(({ files }) => files.includes(name))?.id;
46
+ }
47
+ export function parse(input) {
48
+ try {
49
+ const { path, text, manifests } = input;
50
+ const format = detect(path, text);
51
+ if (format === undefined)
52
+ return error('unsupported-format', 'Unsupported lockfile format');
53
+ if (text.length > inputLimit || Buffer.byteLength(text, 'utf8') > inputLimit
54
+ || Object.values(manifests ?? {}).some(value => value.length > inputLimit || Buffer.byteLength(value, 'utf8') > inputLimit)) {
55
+ return error('input-limit', 'A lockfile or companion manifest exceeds 64 MiB');
56
+ }
57
+ return readers.get(format)(input);
58
+ }
59
+ catch (cause) {
60
+ return error('invalid-input', cause instanceof Error && !(cause instanceof SyntaxError) ? cause.message : 'Malformed lockfile');
61
+ }
62
+ }
63
+ function error(code, message) {
64
+ return { error: { code, message } };
65
+ }
66
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,11 @@
1
+ export declare function pointer(path: readonly (string | number)[]): string;
2
+ interface Span {
3
+ readonly line: number;
4
+ readonly endLine: number;
5
+ }
6
+ /**
7
+ * Find the lines of the wanted values in JSON text that JSON.parse has already accepted. A member starts on the line
8
+ * of its key and ends on the line where its value ends. Only paths up to `depth` keys deep are tracked.
9
+ */
10
+ export declare function locateJsonSpans(text: string, wanted: ReadonlySet<string>, depth: number): ReadonlyMap<string, Span>;
11
+ export {};