@trustify-da/trustify-da-javascript-client 0.3.0-ea.ce73b2f → 0.3.0-ea.d2fee6b

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 (72) hide show
  1. package/README.md +191 -11
  2. package/dist/package.json +23 -10
  3. package/dist/src/analysis.d.ts +21 -5
  4. package/dist/src/analysis.js +74 -80
  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 +17 -3
  9. package/dist/src/cyclone_dx_sbom.js +48 -8
  10. package/dist/src/index.d.ts +196 -11
  11. package/dist/src/index.js +345 -7
  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/images.d.ts +4 -5
  21. package/dist/src/oci_image/utils.d.ts +4 -4
  22. package/dist/src/oci_image/utils.js +11 -2
  23. package/dist/src/provider.d.ts +17 -5
  24. package/dist/src/provider.js +29 -5
  25. package/dist/src/providers/base_java.d.ts +3 -14
  26. package/dist/src/providers/base_java.js +2 -38
  27. package/dist/src/providers/base_javascript.d.ts +29 -7
  28. package/dist/src/providers/base_javascript.js +129 -22
  29. package/dist/src/providers/base_pyproject.d.ts +153 -0
  30. package/dist/src/providers/base_pyproject.js +315 -0
  31. package/dist/src/providers/golang_gomodules.d.ts +29 -13
  32. package/dist/src/providers/golang_gomodules.js +161 -114
  33. package/dist/src/providers/gomod_parser.d.ts +4 -0
  34. package/dist/src/providers/gomod_parser.js +16 -0
  35. package/dist/src/providers/java_gradle.d.ts +28 -3
  36. package/dist/src/providers/java_gradle.js +126 -2
  37. package/dist/src/providers/java_gradle_groovy.d.ts +1 -1
  38. package/dist/src/providers/java_gradle_kotlin.d.ts +1 -1
  39. package/dist/src/providers/java_maven.d.ts +20 -5
  40. package/dist/src/providers/java_maven.js +126 -6
  41. package/dist/src/providers/javascript_npm.d.ts +1 -0
  42. package/dist/src/providers/javascript_npm.js +21 -0
  43. package/dist/src/providers/javascript_pnpm.d.ts +1 -1
  44. package/dist/src/providers/javascript_pnpm.js +8 -4
  45. package/dist/src/providers/manifest.d.ts +2 -0
  46. package/dist/src/providers/manifest.js +22 -4
  47. package/dist/src/providers/marker_evaluator.d.ts +14 -0
  48. package/dist/src/providers/marker_evaluator.js +191 -0
  49. package/dist/src/providers/processors/yarn_berry_processor.js +88 -5
  50. package/dist/src/providers/python_controller.d.ts +10 -3
  51. package/dist/src/providers/python_controller.js +61 -59
  52. package/dist/src/providers/python_pip.d.ts +15 -4
  53. package/dist/src/providers/python_pip.js +51 -58
  54. package/dist/src/providers/python_pip_pyproject.d.ts +61 -0
  55. package/dist/src/providers/python_pip_pyproject.js +144 -0
  56. package/dist/src/providers/python_poetry.d.ts +75 -0
  57. package/dist/src/providers/python_poetry.js +238 -0
  58. package/dist/src/providers/python_uv.d.ts +42 -0
  59. package/dist/src/providers/python_uv.js +160 -0
  60. package/dist/src/providers/requirements_parser.d.ts +6 -0
  61. package/dist/src/providers/requirements_parser.js +24 -0
  62. package/dist/src/providers/rust_cargo.d.ts +52 -0
  63. package/dist/src/providers/rust_cargo.js +614 -0
  64. package/dist/src/providers/tree-sitter-gomod.wasm +0 -0
  65. package/dist/src/providers/tree-sitter-requirements.wasm +0 -0
  66. package/dist/src/sbom.d.ts +17 -2
  67. package/dist/src/sbom.js +16 -4
  68. package/dist/src/tools.d.ts +48 -6
  69. package/dist/src/tools.js +114 -1
  70. package/dist/src/workspace.d.ts +61 -0
  71. package/dist/src/workspace.js +256 -0
  72. package/package.json +24 -11
@@ -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,75 @@
1
+ export default class Python_poetry extends Base_pyproject {
2
+ /**
3
+ * @param {string} manifestDir
4
+ * @param {string} _workspaceDir - unused (poetry has no workspace support)
5
+ * @param {object} parsed - parsed pyproject.toml
6
+ * @param {Object} opts
7
+ * @returns {Promise<{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}>}
8
+ */
9
+ _getDependencyData(manifestDir: string, _workspaceDir: string, parsed: object, opts: any): Promise<{
10
+ directDeps: string[];
11
+ graph: Map<string, {
12
+ name: string;
13
+ version: string;
14
+ children: string[];
15
+ }>;
16
+ }>;
17
+ /**
18
+ * Get poetry show --tree output.
19
+ * @param {string} manifestDir
20
+ * @param {boolean} hasDevGroup
21
+ * @param {Object} opts
22
+ * @returns {string}
23
+ */
24
+ _getPoetryShowTreeOutput(manifestDir: string, hasDevGroup: boolean, opts: any): string;
25
+ /**
26
+ * Get poetry show --all output (flat list with resolved versions).
27
+ * @param {string} manifestDir
28
+ * @param {Object} opts
29
+ * @returns {string}
30
+ */
31
+ _getPoetryShowAllOutput(manifestDir: string, opts: any): string;
32
+ /**
33
+ * Parse poetry show --all output into a version map.
34
+ * Lines look like: "name (!) 1.2.3 Description text..."
35
+ * or: "name 1.2.3 Description text..."
36
+ * @param {string} output
37
+ * @returns {Map<string, string>} canonical name -> version
38
+ */
39
+ _parsePoetryShowAll(output: string): Map<string, string>;
40
+ /**
41
+ * Collects PEP 508 marker expressions for direct and transitive deps.
42
+ * Direct markers come from pyproject.toml dependency strings, e.g.:
43
+ * "pywin32>=311 ; sys_platform == 'win32'" → directMarkers['pywin32'] = "sys_platform == 'win32'"
44
+ * Transitive markers come from poetry.lock [package.dependencies] entries, e.g.:
45
+ * colorama = {version = "*", markers = "sys_platform == 'win32'"}
46
+ * → transitiveMarkers['click']['colorama'] = "sys_platform == 'win32'"
47
+ * @param {string|null} lockDir
48
+ * @param {object} parsed - parsed pyproject.toml
49
+ * @returns {{directMarkers: Map<string, string>, transitiveMarkers: Map<string, Map<string, string>>}}
50
+ */
51
+ _extractMarkerData(lockDir: string | null, parsed: object): {
52
+ directMarkers: Map<string, string>;
53
+ transitiveMarkers: Map<string, Map<string, string>>;
54
+ };
55
+ /**
56
+ * Parse poetry show --tree output into a dependency graph structure.
57
+ *
58
+ * @param {string} treeOutput
59
+ * @param {Map<string, string>} versionMap - canonical name -> resolved version
60
+ * @param {{directMarkers: Map<string, string>, transitiveMarkers: Map<string, Map<string, string>>}} markerData
61
+ * @returns {{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}}
62
+ */
63
+ _parsePoetryTree(treeOutput: string, versionMap: Map<string, string>, markerData: {
64
+ directMarkers: Map<string, string>;
65
+ transitiveMarkers: Map<string, Map<string, string>>;
66
+ }): {
67
+ directDeps: string[];
68
+ graph: Map<string, {
69
+ name: string;
70
+ version: string;
71
+ children: string[];
72
+ }>;
73
+ };
74
+ }
75
+ import Base_pyproject from './base_pyproject.js';
@@ -0,0 +1,238 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { parse as parseToml } from 'smol-toml';
4
+ import { environmentVariableIsPopulated, getCustom, getCustomPath, invokeCommand } from '../tools.js';
5
+ import Base_pyproject from './base_pyproject.js';
6
+ import { evaluateMarker } from './marker_evaluator.js';
7
+ export default class Python_poetry extends Base_pyproject {
8
+ /**
9
+ * Poetry has no native workspace/monorepo support (python-poetry/poetry#2270).
10
+ * Each poetry project is treated independently — no lock file walk-up.
11
+ * Running `poetry show` from a parent directory returns the parent's deps, not
12
+ * the sub-package's, so walk-up would produce incorrect SBOMs.
13
+ * @param {string} manifestDir
14
+ * @param {Object} [opts={}]
15
+ * @returns {string|null}
16
+ * @protected
17
+ */
18
+ _findLockFileDir(manifestDir, opts = {}) {
19
+ const workspaceDir = getCustom('TRUSTIFY_DA_WORKSPACE_DIR', null, opts);
20
+ if (workspaceDir) {
21
+ const dir = path.resolve(workspaceDir);
22
+ return fs.existsSync(path.join(dir, this._lockFileName())) ? dir : null;
23
+ }
24
+ const dir = path.resolve(manifestDir);
25
+ return fs.existsSync(path.join(dir, this._lockFileName())) ? dir : null;
26
+ }
27
+ /** @returns {string} */
28
+ _lockFileName() {
29
+ return 'poetry.lock';
30
+ }
31
+ /** @returns {string} */
32
+ _cmdName() {
33
+ return 'poetry';
34
+ }
35
+ /**
36
+ * @param {string} manifestDir
37
+ * @param {string} _workspaceDir - unused (poetry has no workspace support)
38
+ * @param {object} parsed - parsed pyproject.toml
39
+ * @param {Object} opts
40
+ * @returns {Promise<{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}>}
41
+ */
42
+ // eslint-disable-next-line no-unused-vars
43
+ async _getDependencyData(manifestDir, _workspaceDir, parsed, opts) {
44
+ let hasDevGroup = !!(parsed.tool?.poetry?.group?.dev || parsed.tool?.poetry?.['dev-dependencies']);
45
+ let treeOutput = this._getPoetryShowTreeOutput(manifestDir, hasDevGroup, opts);
46
+ let showAllOutput = this._getPoetryShowAllOutput(manifestDir, opts);
47
+ let versionMap = this._parsePoetryShowAll(showAllOutput);
48
+ let lockDir = this._findLockFileDir(manifestDir, opts);
49
+ let markerData = this._extractMarkerData(lockDir, parsed);
50
+ return this._parsePoetryTree(treeOutput, versionMap, markerData);
51
+ }
52
+ /**
53
+ * Get poetry show --tree output.
54
+ * @param {string} manifestDir
55
+ * @param {boolean} hasDevGroup
56
+ * @param {Object} opts
57
+ * @returns {string}
58
+ */
59
+ _getPoetryShowTreeOutput(manifestDir, hasDevGroup, opts) {
60
+ if (environmentVariableIsPopulated('TRUSTIFY_DA_POETRY_SHOW_TREE')) {
61
+ return Buffer.from(process.env['TRUSTIFY_DA_POETRY_SHOW_TREE'], 'base64').toString('utf-8');
62
+ }
63
+ let poetryBin = getCustomPath('poetry', opts);
64
+ let args = ['show', '--tree', '--no-ansi'];
65
+ if (hasDevGroup) {
66
+ args.push('--without', 'dev');
67
+ }
68
+ return invokeCommand(poetryBin, args, { cwd: manifestDir }).toString();
69
+ }
70
+ /**
71
+ * Get poetry show --all output (flat list with resolved versions).
72
+ * @param {string} manifestDir
73
+ * @param {Object} opts
74
+ * @returns {string}
75
+ */
76
+ _getPoetryShowAllOutput(manifestDir, opts) {
77
+ if (environmentVariableIsPopulated('TRUSTIFY_DA_POETRY_SHOW_ALL')) {
78
+ return Buffer.from(process.env['TRUSTIFY_DA_POETRY_SHOW_ALL'], 'base64').toString('utf-8');
79
+ }
80
+ let poetryBin = getCustomPath('poetry', opts);
81
+ return invokeCommand(poetryBin, ['show', '--no-ansi', '--all'], { cwd: manifestDir }).toString();
82
+ }
83
+ /**
84
+ * Parse poetry show --all output into a version map.
85
+ * Lines look like: "name (!) 1.2.3 Description text..."
86
+ * or: "name 1.2.3 Description text..."
87
+ * @param {string} output
88
+ * @returns {Map<string, string>} canonical name -> version
89
+ */
90
+ _parsePoetryShowAll(output) {
91
+ let versions = new Map();
92
+ let lines = output.split(/\r?\n/);
93
+ for (let line of lines) {
94
+ let trimmed = line.trim();
95
+ if (!trimmed) {
96
+ continue;
97
+ }
98
+ let match = trimmed.match(/^([A-Za-z0-9][A-Za-z0-9._-]*)\s+(?:\(!\)\s+)?(\S+)/);
99
+ if (match) {
100
+ versions.set(this._canonicalize(match[1]), match[2]);
101
+ }
102
+ }
103
+ return versions;
104
+ }
105
+ /**
106
+ * Collects PEP 508 marker expressions for direct and transitive deps.
107
+ * Direct markers come from pyproject.toml dependency strings, e.g.:
108
+ * "pywin32>=311 ; sys_platform == 'win32'" → directMarkers['pywin32'] = "sys_platform == 'win32'"
109
+ * Transitive markers come from poetry.lock [package.dependencies] entries, e.g.:
110
+ * colorama = {version = "*", markers = "sys_platform == 'win32'"}
111
+ * → transitiveMarkers['click']['colorama'] = "sys_platform == 'win32'"
112
+ * @param {string|null} lockDir
113
+ * @param {object} parsed - parsed pyproject.toml
114
+ * @returns {{directMarkers: Map<string, string>, transitiveMarkers: Map<string, Map<string, string>>}}
115
+ */
116
+ _extractMarkerData(lockDir, parsed) {
117
+ let directMarkers = new Map();
118
+ let transitiveMarkers = new Map();
119
+ // Extract markers from PEP 621 dependency strings: "name[extras]>=ver ; marker"
120
+ let deps = parsed.project?.dependencies || [];
121
+ for (let dep of deps) {
122
+ let m = dep.match(/^([A-Za-z0-9][A-Za-z0-9._-]*)\s*[^;]*;\s*(.+)$/);
123
+ if (m) {
124
+ directMarkers.set(this._canonicalize(m[1]), m[2].trim());
125
+ }
126
+ }
127
+ if (lockDir) {
128
+ let lockPath = path.join(lockDir, this._lockFileName());
129
+ if (fs.existsSync(lockPath)) {
130
+ let lockContent = fs.readFileSync(lockPath, 'utf-8');
131
+ let lock = parseToml(lockContent);
132
+ let packages = lock.package || [];
133
+ for (let pkg of packages) {
134
+ let pkgKey = this._canonicalize(pkg.name);
135
+ let pkgDeps = pkg.dependencies || {};
136
+ for (let [depName, depSpec] of Object.entries(pkgDeps)) {
137
+ let markers = typeof depSpec === 'object' && depSpec != null ? depSpec.markers : null;
138
+ if (markers) {
139
+ if (!transitiveMarkers.has(pkgKey)) {
140
+ transitiveMarkers.set(pkgKey, new Map());
141
+ }
142
+ transitiveMarkers.get(pkgKey).set(this._canonicalize(depName), markers);
143
+ }
144
+ }
145
+ }
146
+ }
147
+ }
148
+ return { directMarkers, transitiveMarkers };
149
+ }
150
+ /**
151
+ * Parse poetry show --tree output into a dependency graph structure.
152
+ *
153
+ * @param {string} treeOutput
154
+ * @param {Map<string, string>} versionMap - canonical name -> resolved version
155
+ * @param {{directMarkers: Map<string, string>, transitiveMarkers: Map<string, Map<string, string>>}} markerData
156
+ * @returns {{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}}
157
+ */
158
+ _parsePoetryTree(treeOutput, versionMap, markerData) {
159
+ let lines = treeOutput.split(/\r?\n/);
160
+ let graph = new Map();
161
+ let directDeps = [];
162
+ let stack = []; // [{key, depth}]
163
+ let currentDirectDep = null;
164
+ for (let line of lines) {
165
+ if (!line.trim()) {
166
+ continue;
167
+ }
168
+ // top-level line: "name version description..."
169
+ let topMatch = line.match(/^([A-Za-z0-9][A-Za-z0-9._-]*)\s+(\S+)(?:\s|$)/);
170
+ if (topMatch) {
171
+ let name = topMatch[1];
172
+ let version = topMatch[2];
173
+ let key = this._canonicalize(name);
174
+ let marker = markerData.directMarkers.get(key);
175
+ if (marker && !evaluateMarker(marker)) {
176
+ currentDirectDep = null;
177
+ stack = [];
178
+ continue;
179
+ }
180
+ directDeps.push(key);
181
+ if (!graph.has(key)) {
182
+ graph.set(key, { name, version, children: [] });
183
+ }
184
+ currentDirectDep = key;
185
+ stack = [{ key, depth: -1 }];
186
+ continue;
187
+ }
188
+ if (!currentDirectDep) {
189
+ continue;
190
+ }
191
+ // indented line with tree chars (UTF-8 box-drawing: ├── └── │)
192
+ let nameStart = line.search(/[A-Za-z0-9]/);
193
+ if (nameStart < 0) {
194
+ continue;
195
+ }
196
+ let rest = line.substring(nameStart);
197
+ let depMatch = rest.match(/^([A-Za-z0-9][A-Za-z0-9._-]*)/);
198
+ if (!depMatch) {
199
+ continue;
200
+ }
201
+ let depName = depMatch[1];
202
+ let depKey = this._canonicalize(depName);
203
+ // determine depth by counting tree-drawing groups in the prefix
204
+ let prefix = line.substring(0, nameStart);
205
+ let depth = (prefix.match(/(?:[├└│ ][\s─]{2} ?)/g) || []).length;
206
+ // pop stack back to find the parent at depth-1
207
+ while (stack.length > 0 && stack[stack.length - 1].depth >= depth) {
208
+ stack.pop();
209
+ }
210
+ let parentKey = stack.length > 0 ? stack[stack.length - 1].key : null;
211
+ if (parentKey) {
212
+ let parentMarkers = markerData.transitiveMarkers.get(parentKey);
213
+ if (parentMarkers) {
214
+ let marker = parentMarkers.get(depKey);
215
+ if (marker && !evaluateMarker(marker)) {
216
+ continue;
217
+ }
218
+ }
219
+ }
220
+ // resolve version from the version map
221
+ let version = versionMap.get(depKey) || null;
222
+ if (!version) {
223
+ throw new Error(`poetry: package '${depName}' has no resolved version`);
224
+ }
225
+ if (!graph.has(depKey)) {
226
+ graph.set(depKey, { name: depName, version, children: [] });
227
+ }
228
+ if (parentKey) {
229
+ let parentEntry = graph.get(parentKey);
230
+ if (parentEntry && !parentEntry.children.includes(depKey)) {
231
+ parentEntry.children.push(depKey);
232
+ }
233
+ }
234
+ stack.push({ key: depKey, depth });
235
+ }
236
+ return { directDeps, graph };
237
+ }
238
+ }
@@ -0,0 +1,42 @@
1
+ export default class Python_uv extends Base_pyproject {
2
+ /**
3
+ * @param {string} manifestDir - directory containing the target pyproject.toml
4
+ * @param {string} workspaceDir - workspace root (for resolving editable install paths)
5
+ * @param {object} parsed - parsed pyproject.toml
6
+ * @param {Object} opts
7
+ * @returns {Promise<{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}>}
8
+ */
9
+ _getDependencyData(manifestDir: string, workspaceDir: string, parsed: object, opts: any): Promise<{
10
+ directDeps: string[];
11
+ graph: Map<string, {
12
+ name: string;
13
+ version: string;
14
+ children: string[];
15
+ }>;
16
+ }>;
17
+ /**
18
+ * Get the uv export output, either from env var or by running the command.
19
+ * @param {string} manifestDir
20
+ * @param {Object} opts
21
+ * @returns {string}
22
+ */
23
+ _getUvExportOutput(manifestDir: string, opts: any): string;
24
+ /**
25
+ * Parse uv export output into a dependency graph using tree-sitter-requirements
26
+ * for package/version extraction and string parsing for "# via" comments.
27
+ *
28
+ * @param {string} output
29
+ * @param {string} projectName - canonical project name to identify direct deps
30
+ * @param {string} workspaceDir - workspace root (for resolving editable install paths)
31
+ * @returns {Promise<{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}>}
32
+ */
33
+ _parseUvExport(output: string, projectName: string, workspaceDir: string): Promise<{
34
+ directDeps: string[];
35
+ graph: Map<string, {
36
+ name: string;
37
+ version: string;
38
+ children: string[];
39
+ }>;
40
+ }>;
41
+ }
42
+ import Base_pyproject from './base_pyproject.js';