@trustify-da/trustify-da-javascript-client 0.3.0-ea.63ae5c2 → 0.3.0-ea.6ca858a

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 (59) hide show
  1. package/README.md +191 -11
  2. package/dist/package.json +13 -4
  3. package/dist/src/analysis.d.ts +16 -6
  4. package/dist/src/analysis.js +72 -68
  5. package/dist/src/batch_opts.d.ts +24 -0
  6. package/dist/src/batch_opts.js +35 -0
  7. package/dist/src/cli.js +241 -8
  8. package/dist/src/cyclone_dx_sbom.d.ts +10 -1
  9. package/dist/src/cyclone_dx_sbom.js +32 -5
  10. package/dist/src/index.d.ts +76 -1
  11. package/dist/src/index.js +285 -4
  12. package/dist/src/license/index.d.ts +28 -0
  13. package/dist/src/license/index.js +100 -0
  14. package/dist/src/license/license_utils.d.ts +40 -0
  15. package/dist/src/license/license_utils.js +134 -0
  16. package/dist/src/license/licenses_api.d.ts +34 -0
  17. package/dist/src/license/licenses_api.js +98 -0
  18. package/dist/src/license/project_license.d.ts +20 -0
  19. package/dist/src/license/project_license.js +62 -0
  20. package/dist/src/oci_image/utils.js +11 -2
  21. package/dist/src/provider.d.ts +15 -3
  22. package/dist/src/provider.js +29 -5
  23. package/dist/src/providers/base_javascript.d.ts +29 -7
  24. package/dist/src/providers/base_javascript.js +129 -22
  25. package/dist/src/providers/base_pyproject.d.ts +149 -0
  26. package/dist/src/providers/base_pyproject.js +314 -0
  27. package/dist/src/providers/golang_gomodules.d.ts +19 -12
  28. package/dist/src/providers/golang_gomodules.js +112 -114
  29. package/dist/src/providers/gomod_parser.d.ts +4 -0
  30. package/dist/src/providers/gomod_parser.js +16 -0
  31. package/dist/src/providers/java_gradle.d.ts +6 -0
  32. package/dist/src/providers/java_gradle.js +12 -2
  33. package/dist/src/providers/java_maven.d.ts +8 -1
  34. package/dist/src/providers/java_maven.js +32 -4
  35. package/dist/src/providers/javascript_pnpm.d.ts +1 -1
  36. package/dist/src/providers/javascript_pnpm.js +2 -2
  37. package/dist/src/providers/manifest.d.ts +2 -0
  38. package/dist/src/providers/manifest.js +22 -4
  39. package/dist/src/providers/processors/yarn_berry_processor.js +82 -3
  40. package/dist/src/providers/python_pip.d.ts +7 -0
  41. package/dist/src/providers/python_pip.js +14 -4
  42. package/dist/src/providers/python_pip_pyproject.d.ts +61 -0
  43. package/dist/src/providers/python_pip_pyproject.js +144 -0
  44. package/dist/src/providers/python_poetry.d.ts +43 -0
  45. package/dist/src/providers/python_poetry.js +175 -0
  46. package/dist/src/providers/python_uv.d.ts +27 -0
  47. package/dist/src/providers/python_uv.js +146 -0
  48. package/dist/src/providers/requirements_parser.js +5 -8
  49. package/dist/src/providers/rust_cargo.d.ts +52 -0
  50. package/dist/src/providers/rust_cargo.js +614 -0
  51. package/dist/src/providers/tree-sitter-gomod.wasm +0 -0
  52. package/dist/src/providers/tree-sitter-requirements.wasm +0 -0
  53. package/dist/src/sbom.d.ts +10 -1
  54. package/dist/src/sbom.js +12 -2
  55. package/dist/src/tools.d.ts +18 -0
  56. package/dist/src/tools.js +55 -0
  57. package/dist/src/workspace.d.ts +61 -0
  58. package/dist/src/workspace.js +256 -0
  59. package/package.json +14 -5
@@ -48,13 +48,15 @@ export default class Yarn_berry_processor extends Yarn_processor {
48
48
  if (!depTree) {
49
49
  return new Map();
50
50
  }
51
- return new Map(depTree.filter(dep => !this.#isRoot(dep.value)).map(dep => {
51
+ return new Map(depTree.filter(dep => !this.#isRoot(dep.value))
52
+ .map(dep => {
52
53
  const depName = dep.value;
53
54
  const idx = depName.lastIndexOf('@');
54
55
  const name = depName.substring(0, idx);
55
56
  const version = dep.children.Version;
56
57
  return [name, toPurl(purlType, name, version)];
57
- }));
58
+ })
59
+ .filter(([name]) => this._manifest.dependencies.includes(name)));
58
60
  }
59
61
  /**
60
62
  * Checks if a dependency is the root package
@@ -77,14 +79,58 @@ export default class Yarn_berry_processor extends Yarn_processor {
77
79
  if (!depTree) {
78
80
  return;
79
81
  }
82
+ // Build index of nodes by their value for quick lookup
83
+ const nodeIndex = new Map();
84
+ depTree.forEach(n => nodeIndex.set(n.value, n));
85
+ // Determine the set of node values reachable from root via production deps
86
+ const prodDeps = new Set(this._manifest.dependencies);
87
+ const reachable = new Set();
88
+ const queue = [];
89
+ // Seed with root's production dependencies
90
+ const rootNode = depTree.find(n => this.#isRoot(n.value));
91
+ if (rootNode?.children?.Dependencies) {
92
+ for (const d of rootNode.children.Dependencies) {
93
+ const to = this.#purlFromLocator(d.locator);
94
+ if (to) {
95
+ const fullName = to.namespace ? `${to.namespace}/${to.name}` : to.name;
96
+ if (prodDeps.has(fullName)) {
97
+ queue.push(d.locator);
98
+ }
99
+ }
100
+ }
101
+ }
102
+ // BFS to find all transitively reachable packages
103
+ while (queue.length > 0) {
104
+ const locator = queue.shift();
105
+ if (reachable.has(locator)) {
106
+ continue;
107
+ }
108
+ reachable.add(locator);
109
+ const node = nodeIndex.get(this.#nodeValueFromLocator(locator));
110
+ if (node?.children?.Dependencies) {
111
+ for (const d of node.children.Dependencies) {
112
+ if (!reachable.has(d.locator)) {
113
+ queue.push(d.locator);
114
+ }
115
+ }
116
+ }
117
+ }
118
+ // Only emit edges for root and reachable nodes
80
119
  depTree.forEach(n => {
81
120
  const depName = n.value;
82
- const from = this.#isRoot(depName) ? toPurlFromString(sbom.getRoot().purl) : this.#purlFromNode(depName, n);
121
+ const isRoot = this.#isRoot(depName);
122
+ if (!isRoot && !this.#isReachableNode(depName, reachable)) {
123
+ return;
124
+ }
125
+ const from = isRoot ? toPurlFromString(sbom.getRoot().purl) : this.#purlFromNode(depName, n);
83
126
  const deps = n.children?.Dependencies;
84
127
  if (!deps) {
85
128
  return;
86
129
  }
87
130
  deps.forEach(d => {
131
+ if (!reachable.has(d.locator)) {
132
+ return;
133
+ }
88
134
  const to = this.#purlFromLocator(d.locator);
89
135
  if (to) {
90
136
  sbom.addDependency(from, to);
@@ -92,6 +138,39 @@ export default class Yarn_berry_processor extends Yarn_processor {
92
138
  });
93
139
  });
94
140
  }
141
+ /**
142
+ * Converts a locator to the node value format used in yarn info output
143
+ * @param {string} locator - e.g. "express@npm:4.17.1"
144
+ * @returns {string} The node value, same as locator for non-virtual
145
+ * @private
146
+ */
147
+ #nodeValueFromLocator(locator) {
148
+ // Virtual locators: "@scope/name@virtual:hash#npm:version" → "@scope/name@npm:version"
149
+ const virtualMatch = Yarn_berry_processor.VIRTUAL_LOCATOR_PATTERN.exec(locator);
150
+ if (virtualMatch) {
151
+ return `${virtualMatch[1]}@npm:${virtualMatch[2]}`;
152
+ }
153
+ return locator;
154
+ }
155
+ /**
156
+ * Checks if a node is in the reachable set by matching its value against reachable locators
157
+ * @param {string} depName - The node value (e.g. "express@npm:4.17.1")
158
+ * @param {Set<string>} reachable - Set of reachable locators
159
+ * @returns {boolean}
160
+ * @private
161
+ */
162
+ #isReachableNode(depName, reachable) {
163
+ if (reachable.has(depName)) {
164
+ return true;
165
+ }
166
+ // Check if any reachable locator resolves to this node value
167
+ for (const locator of reachable) {
168
+ if (this.#nodeValueFromLocator(locator) === depName) {
169
+ return true;
170
+ }
171
+ }
172
+ return false;
173
+ }
95
174
  /**
96
175
  * Creates a PackageURL from a dependency locator
97
176
  * @param {string} locator - The dependency locator
@@ -3,6 +3,7 @@ declare namespace _default {
3
3
  export { validateLockFile };
4
4
  export { provideComponent };
5
5
  export { provideStack };
6
+ export { readLicenseFromManifest };
6
7
  }
7
8
  export default _default;
8
9
  export type DependencyEntry = {
@@ -33,3 +34,9 @@ declare function provideComponent(manifest: string, opts?: {}): Promise<Provided
33
34
  * @returns {Promise<Provided>}
34
35
  */
35
36
  declare function provideStack(manifest: string, opts?: {}): Promise<Provided>;
37
+ /**
38
+ * Python requirements.txt has no standard license field
39
+ * @param {string} manifestPath - path to requirements.txt
40
+ * @returns {string|null}
41
+ */
42
+ declare function readLicenseFromManifest(manifestPath: string): string | null;
@@ -1,10 +1,11 @@
1
1
  import fs from 'node:fs';
2
2
  import { PackageURL } from 'packageurl-js';
3
+ import { readLicenseFile } from '../license/license_utils.js';
3
4
  import Sbom from '../sbom.js';
4
5
  import { environmentVariableIsPopulated, getCustom, getCustomPath, invokeCommand } from "../tools.js";
5
6
  import Python_controller from './python_controller.js';
6
7
  import { getParser, getIgnoreQuery, getPinnedVersionQuery } from './requirements_parser.js';
7
- export default { isSupported, validateLockFile, provideComponent, provideStack };
8
+ export default { isSupported, validateLockFile, provideComponent, provideStack, readLicenseFromManifest };
8
9
  /** @typedef {{name: string, version: string, dependencies: DependencyEntry[]}} DependencyEntry */
9
10
  /**
10
11
  * @type {string} ecosystem for python-pip is 'pip'
@@ -18,6 +19,13 @@ const ecosystem = 'pip';
18
19
  function isSupported(manifestName) {
19
20
  return 'requirements.txt' === manifestName;
20
21
  }
22
+ /**
23
+ * Python requirements.txt has no standard license field
24
+ * @param {string} manifestPath - path to requirements.txt
25
+ * @returns {string|null}
26
+ */
27
+ // eslint-disable-next-line no-unused-vars
28
+ function readLicenseFromManifest(manifestPath) { return readLicenseFile(manifestPath); }
21
29
  /**
22
30
  * @param {string} manifestDir - the directory where the manifest lies
23
31
  */
@@ -67,7 +75,7 @@ function addAllDependencies(source, dep, sbom) {
67
75
  /**
68
76
  *
69
77
  * @param {string} manifest - path to requirements.txt
70
- * @return {PackageURL []}
78
+ * @return {Promise<PackageURL[]>}
71
79
  */
72
80
  async function getIgnoredDependencies(manifest) {
73
81
  const [parser, ignoreQuery, pinnedVersionQuery] = await Promise.all([
@@ -167,7 +175,8 @@ async function createSbomStackAnalysis(manifest, opts = {}) {
167
175
  let dependencies = await pythonController.getDependencies(true);
168
176
  let sbom = new Sbom();
169
177
  const rootPurl = toPurl(DEFAULT_PIP_ROOT_COMPONENT_NAME, DEFAULT_PIP_ROOT_COMPONENT_VERSION);
170
- sbom.addRoot(rootPurl);
178
+ const license = readLicenseFromManifest(manifest);
179
+ sbom.addRoot(rootPurl, license);
171
180
  dependencies.forEach(dep => {
172
181
  addAllDependencies(rootPurl, dep, sbom);
173
182
  });
@@ -190,7 +199,8 @@ async function getSbomForComponentAnalysis(manifest, opts = {}) {
190
199
  let dependencies = await pythonController.getDependencies(false);
191
200
  let sbom = new Sbom();
192
201
  const rootPurl = toPurl(DEFAULT_PIP_ROOT_COMPONENT_NAME, DEFAULT_PIP_ROOT_COMPONENT_VERSION);
193
- sbom.addRoot(rootPurl);
202
+ const license = readLicenseFromManifest(manifest);
203
+ sbom.addRoot(rootPurl, license);
194
204
  dependencies.forEach(dep => {
195
205
  sbom.addDependency(rootPurl, toPurl(dep.name, dep.version));
196
206
  });
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Python provider for pyproject.toml files using PEP 621 format without a lock file.
3
+ * Uses `pip install --dry-run --ignore-installed --report` to resolve the full dependency tree.
4
+ * Acts as the fallback provider when no lock file (uv.lock/poetry.lock) is found.
5
+ */
6
+ export default class Python_pip_pyproject extends Base_pyproject {
7
+ /**
8
+ * Always returns true — pip provider is the fallback when no lock file is found.
9
+ * @param {string} manifestDir
10
+ * @param {{}} [opts={}]
11
+ * @returns {boolean}
12
+ */
13
+ validateLockFile(manifestDir: string, opts?: {}): boolean;
14
+ /**
15
+ * Get pip report output from env var override or by running pip.
16
+ * @param {string} manifestDir - directory containing pyproject.toml
17
+ * @param {{}} [opts={}]
18
+ * @returns {string} pip report JSON string
19
+ */
20
+ _getPipReportOutput(manifestDir: string, opts?: {}): string;
21
+ /**
22
+ * Parse pip report JSON and build dependency graph.
23
+ * @param {string} reportJson - pip report JSON string
24
+ * @returns {{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}}
25
+ */
26
+ _parsePipReport(reportJson: string): {
27
+ directDeps: string[];
28
+ graph: Map<string, {
29
+ name: string;
30
+ version: string;
31
+ children: string[];
32
+ }>;
33
+ };
34
+ /**
35
+ * Check if a requires_dist entry is an extras-only dependency.
36
+ * @param {string} req - e.g. "PySocks!=1.5.7,>=1.5.6; extra == \"socks\""
37
+ * @returns {boolean}
38
+ */
39
+ _hasExtraMarker(req: string): boolean;
40
+ /**
41
+ * Extract package name from a requires_dist entry.
42
+ * @param {string} req - e.g. "charset_normalizer<4,>=2"
43
+ * @returns {string|null}
44
+ */
45
+ _extractDepName(req: string): string | null;
46
+ /**
47
+ * Resolve dependencies using pip install --dry-run --report.
48
+ * @param {string} manifestDir
49
+ * @param {string} _workspaceDir - unused (pip resolves from manifest directory)
50
+ * @param {object} parsed - parsed pyproject.toml
51
+ * @param {{}} [opts={}]
52
+ * @returns {Promise<{directDeps: string[], graph: Map}>}
53
+ */
54
+ _getDependencyData(manifestDir: string, _workspaceDir: string, parsed: object, opts?: {}): Promise<{
55
+ directDeps: string[];
56
+ graph: Map<any, any>;
57
+ }>;
58
+ _findEggInfoDirs(dir: any): string[];
59
+ _cleanupEggInfo(dir: any, existing: any): void;
60
+ }
61
+ import Base_pyproject from './base_pyproject.js';
@@ -0,0 +1,144 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { environmentVariableIsPopulated, getCustomPath, invokeCommand } from '../tools.js';
4
+ import Base_pyproject from './base_pyproject.js';
5
+ /**
6
+ * Python provider for pyproject.toml files using PEP 621 format without a lock file.
7
+ * Uses `pip install --dry-run --ignore-installed --report` to resolve the full dependency tree.
8
+ * Acts as the fallback provider when no lock file (uv.lock/poetry.lock) is found.
9
+ */
10
+ export default class Python_pip_pyproject extends Base_pyproject {
11
+ /** @returns {string} */
12
+ _lockFileName() {
13
+ return '.pip-lock-nonexistent';
14
+ }
15
+ /** @returns {string} */
16
+ _cmdName() {
17
+ return 'pip';
18
+ }
19
+ /**
20
+ * Always returns true — pip provider is the fallback when no lock file is found.
21
+ * @param {string} manifestDir
22
+ * @param {{}} [opts={}]
23
+ * @returns {boolean}
24
+ */
25
+ // eslint-disable-next-line no-unused-vars
26
+ validateLockFile(manifestDir, opts = {}) {
27
+ return true;
28
+ }
29
+ /**
30
+ * Get pip report output from env var override or by running pip.
31
+ * @param {string} manifestDir - directory containing pyproject.toml
32
+ * @param {{}} [opts={}]
33
+ * @returns {string} pip report JSON string
34
+ */
35
+ _getPipReportOutput(manifestDir, opts) {
36
+ if (environmentVariableIsPopulated('TRUSTIFY_DA_PIP_REPORT')) {
37
+ return Buffer.from(process.env['TRUSTIFY_DA_PIP_REPORT'], 'base64').toString('ascii');
38
+ }
39
+ let pipBin = getCustomPath('pip3', opts);
40
+ try {
41
+ invokeCommand(pipBin, ['--version']);
42
+ }
43
+ catch {
44
+ pipBin = getCustomPath('pip', opts);
45
+ }
46
+ let eggInfoDirs = this._findEggInfoDirs(manifestDir);
47
+ let result = invokeCommand(pipBin, [
48
+ 'install', '--dry-run', '--ignore-installed', '--quiet', '--report', '-', '.'
49
+ ], { cwd: manifestDir }).toString();
50
+ this._cleanupEggInfo(manifestDir, eggInfoDirs);
51
+ return result;
52
+ }
53
+ /**
54
+ * Parse pip report JSON and build dependency graph.
55
+ * @param {string} reportJson - pip report JSON string
56
+ * @returns {{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}}
57
+ */
58
+ _parsePipReport(reportJson) {
59
+ let report = JSON.parse(reportJson);
60
+ let packages = report.install || [];
61
+ let rootEntry = packages.find(p => p.download_info?.dir_info !== undefined);
62
+ let rootRequires = rootEntry?.metadata?.requires_dist || [];
63
+ let directDepNames = new Set();
64
+ for (let req of rootRequires) {
65
+ if (this._hasExtraMarker(req)) {
66
+ continue;
67
+ }
68
+ let name = this._extractDepName(req);
69
+ if (name) {
70
+ directDepNames.add(this._canonicalize(name));
71
+ }
72
+ }
73
+ let graph = new Map();
74
+ let nonRootPackages = packages.filter(p => p !== rootEntry);
75
+ for (let pkg of nonRootPackages) {
76
+ let name = pkg.metadata.name;
77
+ let version = pkg.metadata.version;
78
+ let key = this._canonicalize(name);
79
+ graph.set(key, { name, version, children: [] });
80
+ }
81
+ for (let pkg of nonRootPackages) {
82
+ let key = this._canonicalize(pkg.metadata.name);
83
+ let entry = graph.get(key);
84
+ let requires = pkg.metadata.requires_dist || [];
85
+ for (let req of requires) {
86
+ let depName = this._extractDepName(req);
87
+ if (!depName) {
88
+ continue;
89
+ }
90
+ let depKey = this._canonicalize(depName);
91
+ if (graph.has(depKey)) {
92
+ entry.children.push(depKey);
93
+ }
94
+ }
95
+ }
96
+ let directDeps = [...directDepNames].filter(key => graph.has(key));
97
+ return { directDeps, graph };
98
+ }
99
+ /**
100
+ * Check if a requires_dist entry is an extras-only dependency.
101
+ * @param {string} req - e.g. "PySocks!=1.5.7,>=1.5.6; extra == \"socks\""
102
+ * @returns {boolean}
103
+ */
104
+ _hasExtraMarker(req) {
105
+ return /;\s*.*extra\s*==/.test(req);
106
+ }
107
+ /**
108
+ * Extract package name from a requires_dist entry.
109
+ * @param {string} req - e.g. "charset_normalizer<4,>=2"
110
+ * @returns {string|null}
111
+ */
112
+ _extractDepName(req) {
113
+ let match = req.match(/^([A-Za-z0-9]([A-Za-z0-9._-]*[A-Za-z0-9])?)/);
114
+ return match ? match[1] : null;
115
+ }
116
+ /**
117
+ * Resolve dependencies using pip install --dry-run --report.
118
+ * @param {string} manifestDir
119
+ * @param {string} _workspaceDir - unused (pip resolves from manifest directory)
120
+ * @param {object} parsed - parsed pyproject.toml
121
+ * @param {{}} [opts={}]
122
+ * @returns {Promise<{directDeps: string[], graph: Map}>}
123
+ */
124
+ // eslint-disable-next-line no-unused-vars
125
+ async _getDependencyData(manifestDir, _workspaceDir, parsed, opts) {
126
+ let reportOutput = this._getPipReportOutput(manifestDir, opts);
127
+ return this._parsePipReport(reportOutput);
128
+ }
129
+ _findEggInfoDirs(dir) {
130
+ try {
131
+ return fs.readdirSync(dir).filter(f => f.endsWith('.egg-info'));
132
+ }
133
+ catch {
134
+ return [];
135
+ }
136
+ }
137
+ _cleanupEggInfo(dir, existing) {
138
+ for (let entry of this._findEggInfoDirs(dir)) {
139
+ if (!existing.includes(entry)) {
140
+ fs.rmSync(path.join(dir, entry), { recursive: true, force: true });
141
+ }
142
+ }
143
+ }
144
+ }
@@ -0,0 +1,43 @@
1
+ export default class Python_poetry extends Base_pyproject {
2
+ /**
3
+ * Get poetry show --tree output.
4
+ * @param {string} manifestDir
5
+ * @param {boolean} hasDevGroup
6
+ * @param {Object} opts
7
+ * @returns {string}
8
+ */
9
+ _getPoetryShowTreeOutput(manifestDir: string, hasDevGroup: boolean, opts: any): string;
10
+ /**
11
+ * Get poetry show --all output (flat list with resolved versions).
12
+ * @param {string} manifestDir
13
+ * @param {Object} opts
14
+ * @returns {string}
15
+ */
16
+ _getPoetryShowAllOutput(manifestDir: string, opts: any): string;
17
+ /**
18
+ * Parse poetry show --all output into a version map.
19
+ * Lines look like: "name (!) 1.2.3 Description text..."
20
+ * or: "name 1.2.3 Description text..."
21
+ * @param {string} output
22
+ * @returns {Map<string, string>} canonical name -> version
23
+ */
24
+ _parsePoetryShowAll(output: string): Map<string, string>;
25
+ /**
26
+ * Parse poetry show --tree output into a dependency graph structure.
27
+ * Top-level lines (no indentation/tree chars) are direct deps: "name version description"
28
+ * Indented lines are transitive deps with tree chars: "├── name >=constraint"
29
+ *
30
+ * @param {string} treeOutput
31
+ * @param {Map<string, string>} versionMap - canonical name -> resolved version
32
+ * @returns {{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}}
33
+ */
34
+ _parsePoetryTree(treeOutput: string, versionMap: Map<string, string>): {
35
+ directDeps: string[];
36
+ graph: Map<string, {
37
+ name: string;
38
+ version: string;
39
+ children: string[];
40
+ }>;
41
+ };
42
+ }
43
+ import Base_pyproject from './base_pyproject.js';
@@ -0,0 +1,175 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { environmentVariableIsPopulated, getCustom, getCustomPath, invokeCommand } from '../tools.js';
4
+ import Base_pyproject from './base_pyproject.js';
5
+ export default class Python_poetry extends Base_pyproject {
6
+ /**
7
+ * Poetry has no native workspace/monorepo support (python-poetry/poetry#2270).
8
+ * Each poetry project is treated independently — no lock file walk-up.
9
+ * Running `poetry show` from a parent directory returns the parent's deps, not
10
+ * the sub-package's, so walk-up would produce incorrect SBOMs.
11
+ * @param {string} manifestDir
12
+ * @param {Object} [opts={}]
13
+ * @returns {string|null}
14
+ * @protected
15
+ */
16
+ _findLockFileDir(manifestDir, opts = {}) {
17
+ const workspaceDir = getCustom('TRUSTIFY_DA_WORKSPACE_DIR', null, opts);
18
+ if (workspaceDir) {
19
+ const dir = path.resolve(workspaceDir);
20
+ return fs.existsSync(path.join(dir, this._lockFileName())) ? dir : null;
21
+ }
22
+ const dir = path.resolve(manifestDir);
23
+ return fs.existsSync(path.join(dir, this._lockFileName())) ? dir : null;
24
+ }
25
+ /** @returns {string} */
26
+ _lockFileName() {
27
+ return 'poetry.lock';
28
+ }
29
+ /** @returns {string} */
30
+ _cmdName() {
31
+ return 'poetry';
32
+ }
33
+ /**
34
+ * @param {string} manifestDir
35
+ * @param {string} _workspaceDir - unused (poetry has no workspace support)
36
+ * @param {object} parsed - parsed pyproject.toml
37
+ * @param {Object} opts
38
+ * @returns {Promise<{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}>}
39
+ */
40
+ // eslint-disable-next-line no-unused-vars
41
+ async _getDependencyData(manifestDir, _workspaceDir, parsed, opts) {
42
+ let hasDevGroup = !!(parsed.tool?.poetry?.group?.dev || parsed.tool?.poetry?.['dev-dependencies']);
43
+ let treeOutput = this._getPoetryShowTreeOutput(manifestDir, hasDevGroup, opts);
44
+ let showAllOutput = this._getPoetryShowAllOutput(manifestDir, opts);
45
+ let versionMap = this._parsePoetryShowAll(showAllOutput);
46
+ return this._parsePoetryTree(treeOutput, versionMap);
47
+ }
48
+ /**
49
+ * Get poetry show --tree output.
50
+ * @param {string} manifestDir
51
+ * @param {boolean} hasDevGroup
52
+ * @param {Object} opts
53
+ * @returns {string}
54
+ */
55
+ _getPoetryShowTreeOutput(manifestDir, hasDevGroup, opts) {
56
+ if (environmentVariableIsPopulated('TRUSTIFY_DA_POETRY_SHOW_TREE')) {
57
+ return Buffer.from(process.env['TRUSTIFY_DA_POETRY_SHOW_TREE'], 'base64').toString('utf-8');
58
+ }
59
+ let poetryBin = getCustomPath('poetry', opts);
60
+ let args = ['show', '--tree', '--no-ansi'];
61
+ if (hasDevGroup) {
62
+ args.push('--without', 'dev');
63
+ }
64
+ return invokeCommand(poetryBin, args, { cwd: manifestDir }).toString();
65
+ }
66
+ /**
67
+ * Get poetry show --all output (flat list with resolved versions).
68
+ * @param {string} manifestDir
69
+ * @param {Object} opts
70
+ * @returns {string}
71
+ */
72
+ _getPoetryShowAllOutput(manifestDir, opts) {
73
+ if (environmentVariableIsPopulated('TRUSTIFY_DA_POETRY_SHOW_ALL')) {
74
+ return Buffer.from(process.env['TRUSTIFY_DA_POETRY_SHOW_ALL'], 'base64').toString('utf-8');
75
+ }
76
+ let poetryBin = getCustomPath('poetry', opts);
77
+ return invokeCommand(poetryBin, ['show', '--no-ansi', '--all'], { cwd: manifestDir }).toString();
78
+ }
79
+ /**
80
+ * Parse poetry show --all output into a version map.
81
+ * Lines look like: "name (!) 1.2.3 Description text..."
82
+ * or: "name 1.2.3 Description text..."
83
+ * @param {string} output
84
+ * @returns {Map<string, string>} canonical name -> version
85
+ */
86
+ _parsePoetryShowAll(output) {
87
+ let versions = new Map();
88
+ let lines = output.split(/\r?\n/);
89
+ for (let line of lines) {
90
+ let trimmed = line.trim();
91
+ if (!trimmed) {
92
+ continue;
93
+ }
94
+ let match = trimmed.match(/^([A-Za-z0-9][A-Za-z0-9._-]*)\s+(?:\(!\)\s+)?(\S+)/);
95
+ if (match) {
96
+ versions.set(this._canonicalize(match[1]), match[2]);
97
+ }
98
+ }
99
+ return versions;
100
+ }
101
+ /**
102
+ * Parse poetry show --tree output into a dependency graph structure.
103
+ * Top-level lines (no indentation/tree chars) are direct deps: "name version description"
104
+ * Indented lines are transitive deps with tree chars: "├── name >=constraint"
105
+ *
106
+ * @param {string} treeOutput
107
+ * @param {Map<string, string>} versionMap - canonical name -> resolved version
108
+ * @returns {{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}}
109
+ */
110
+ _parsePoetryTree(treeOutput, versionMap) {
111
+ let lines = treeOutput.split(/\r?\n/);
112
+ let graph = new Map();
113
+ let directDeps = [];
114
+ let stack = []; // [{key, depth}]
115
+ let currentDirectDep = null;
116
+ for (let line of lines) {
117
+ if (!line.trim()) {
118
+ continue;
119
+ }
120
+ // top-level line: "name version description..."
121
+ let topMatch = line.match(/^([A-Za-z0-9][A-Za-z0-9._-]*)\s+(\S+)(?:\s|$)/);
122
+ if (topMatch) {
123
+ let name = topMatch[1];
124
+ let version = topMatch[2];
125
+ let key = this._canonicalize(name);
126
+ directDeps.push(key);
127
+ if (!graph.has(key)) {
128
+ graph.set(key, { name, version, children: [] });
129
+ }
130
+ currentDirectDep = key;
131
+ stack = [{ key, depth: -1 }];
132
+ continue;
133
+ }
134
+ if (!currentDirectDep) {
135
+ continue;
136
+ }
137
+ // indented line with tree chars (UTF-8 box-drawing: ├── └── │)
138
+ let nameStart = line.search(/[A-Za-z0-9]/);
139
+ if (nameStart < 0) {
140
+ continue;
141
+ }
142
+ let rest = line.substring(nameStart);
143
+ let depMatch = rest.match(/^([A-Za-z0-9][A-Za-z0-9._-]*)/);
144
+ if (!depMatch) {
145
+ continue;
146
+ }
147
+ let depName = depMatch[1];
148
+ let depKey = this._canonicalize(depName);
149
+ // determine depth by counting tree-drawing groups in the prefix
150
+ let prefix = line.substring(0, nameStart);
151
+ let depth = (prefix.match(/(?:[├└│ ][\s─]{2} ?)/g) || []).length;
152
+ // resolve version from the version map
153
+ let version = versionMap.get(depKey) || null;
154
+ if (!version) {
155
+ throw new Error(`poetry: package '${depName}' has no resolved version`);
156
+ }
157
+ if (!graph.has(depKey)) {
158
+ graph.set(depKey, { name: depName, version, children: [] });
159
+ }
160
+ // pop stack back to find the parent at depth-1
161
+ while (stack.length > 0 && stack[stack.length - 1].depth >= depth) {
162
+ stack.pop();
163
+ }
164
+ if (stack.length > 0) {
165
+ let parentKey = stack[stack.length - 1].key;
166
+ let parentEntry = graph.get(parentKey);
167
+ if (parentEntry && !parentEntry.children.includes(depKey)) {
168
+ parentEntry.children.push(depKey);
169
+ }
170
+ }
171
+ stack.push({ key: depKey, depth });
172
+ }
173
+ return { directDeps, graph };
174
+ }
175
+ }
@@ -0,0 +1,27 @@
1
+ export default class Python_uv extends Base_pyproject {
2
+ /**
3
+ * Get the uv export output, either from env var or by running the command.
4
+ * @param {string} manifestDir
5
+ * @param {Object} opts
6
+ * @returns {string}
7
+ */
8
+ _getUvExportOutput(manifestDir: string, opts: any): string;
9
+ /**
10
+ * Parse uv export output into a dependency graph using tree-sitter-requirements
11
+ * for package/version extraction and string parsing for "# via" comments.
12
+ *
13
+ * @param {string} output
14
+ * @param {string} projectName - canonical project name to identify direct deps
15
+ * @param {string} workspaceDir - workspace root (for resolving editable install paths)
16
+ * @returns {Promise<{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}>}
17
+ */
18
+ _parseUvExport(output: string, projectName: string, workspaceDir: string): Promise<{
19
+ directDeps: string[];
20
+ graph: Map<string, {
21
+ name: string;
22
+ version: string;
23
+ children: string[];
24
+ }>;
25
+ }>;
26
+ }
27
+ import Base_pyproject from './base_pyproject.js';