@trustify-da/trustify-da-javascript-client 0.3.0-ea.f2d5d72 → 0.3.0-ea.f501753

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 (40) hide show
  1. package/dist/package.json +1 -1
  2. package/dist/src/analysis.js +3 -2
  3. package/dist/src/cli.js +51 -2
  4. package/dist/src/cyclone_dx_sbom.d.ts +7 -1
  5. package/dist/src/cyclone_dx_sbom.js +18 -5
  6. package/dist/src/index.d.ts +70 -2
  7. package/dist/src/index.js +77 -4
  8. package/dist/src/oci_image/utils.js +11 -2
  9. package/dist/src/provider.js +2 -0
  10. package/dist/src/providers/base_java.d.ts +0 -9
  11. package/dist/src/providers/base_java.js +2 -38
  12. package/dist/src/providers/base_pyproject.d.ts +35 -29
  13. package/dist/src/providers/base_pyproject.js +114 -78
  14. package/dist/src/providers/golang_gomodules.d.ts +9 -0
  15. package/dist/src/providers/golang_gomodules.js +64 -7
  16. package/dist/src/providers/java_gradle.d.ts +19 -0
  17. package/dist/src/providers/java_gradle.js +114 -0
  18. package/dist/src/providers/java_maven.d.ts +8 -0
  19. package/dist/src/providers/java_maven.js +93 -1
  20. package/dist/src/providers/javascript_npm.d.ts +1 -0
  21. package/dist/src/providers/javascript_npm.js +21 -0
  22. package/dist/src/providers/javascript_pnpm.js +6 -2
  23. package/dist/src/providers/marker_evaluator.d.ts +14 -0
  24. package/dist/src/providers/marker_evaluator.js +191 -0
  25. package/dist/src/providers/processors/yarn_berry_processor.js +6 -2
  26. package/dist/src/providers/python_controller.d.ts +5 -1
  27. package/dist/src/providers/python_controller.js +8 -4
  28. package/dist/src/providers/python_pip.d.ts +4 -0
  29. package/dist/src/providers/python_pip.js +4 -4
  30. package/dist/src/providers/python_pip_pyproject.d.ts +61 -0
  31. package/dist/src/providers/python_pip_pyproject.js +144 -0
  32. package/dist/src/providers/python_poetry.d.ts +37 -4
  33. package/dist/src/providers/python_poetry.js +108 -16
  34. package/dist/src/providers/python_uv.d.ts +17 -1
  35. package/dist/src/providers/python_uv.js +47 -5
  36. package/dist/src/sbom.d.ts +7 -1
  37. package/dist/src/sbom.js +4 -2
  38. package/dist/src/tools.d.ts +26 -0
  39. package/dist/src/tools.js +58 -0
  40. package/package.json +2 -2
@@ -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
+ }
@@ -1,11 +1,27 @@
1
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
+ }>;
2
17
  /**
3
18
  * Get poetry show --tree output.
4
19
  * @param {string} manifestDir
20
+ * @param {boolean} hasDevGroup
5
21
  * @param {Object} opts
6
22
  * @returns {string}
7
23
  */
8
- _getPoetryShowTreeOutput(manifestDir: string, opts: any): string;
24
+ _getPoetryShowTreeOutput(manifestDir: string, hasDevGroup: boolean, opts: any): string;
9
25
  /**
10
26
  * Get poetry show --all output (flat list with resolved versions).
11
27
  * @param {string} manifestDir
@@ -21,16 +37,33 @@ export default class Python_poetry extends Base_pyproject {
21
37
  * @returns {Map<string, string>} canonical name -> version
22
38
  */
23
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
+ };
24
55
  /**
25
56
  * Parse poetry show --tree output into a dependency graph structure.
26
- * Top-level lines (no indentation/tree chars) are direct deps: "name version description"
27
- * Indented lines are transitive deps with tree chars: "├── name >=constraint"
28
57
  *
29
58
  * @param {string} treeOutput
30
59
  * @param {Map<string, string>} versionMap - canonical name -> resolved version
60
+ * @param {{directMarkers: Map<string, string>, transitiveMarkers: Map<string, Map<string, string>>}} markerData
31
61
  * @returns {{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}}
32
62
  */
33
- _parsePoetryTree(treeOutput: string, versionMap: Map<string, string>): {
63
+ _parsePoetryTree(treeOutput: string, versionMap: Map<string, string>, markerData: {
64
+ directMarkers: Map<string, string>;
65
+ transitiveMarkers: Map<string, Map<string, string>>;
66
+ }): {
34
67
  directDeps: string[];
35
68
  graph: Map<string, {
36
69
  name: string;
@@ -1,6 +1,29 @@
1
- import { environmentVariableIsPopulated, getCustomPath, invokeCommand } from '../tools.js';
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';
2
5
  import Base_pyproject from './base_pyproject.js';
6
+ import { evaluateMarker } from './marker_evaluator.js';
3
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
+ }
4
27
  /** @returns {string} */
5
28
  _lockFileName() {
6
29
  return 'poetry.lock';
@@ -11,28 +34,38 @@ export default class Python_poetry extends Base_pyproject {
11
34
  }
12
35
  /**
13
36
  * @param {string} manifestDir
37
+ * @param {string} _workspaceDir - unused (poetry has no workspace support)
14
38
  * @param {object} parsed - parsed pyproject.toml
15
39
  * @param {Object} opts
16
40
  * @returns {Promise<{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}>}
17
41
  */
18
- async _getDependencyData(manifestDir, parsed, opts) {
19
- let treeOutput = this._getPoetryShowTreeOutput(manifestDir, opts);
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);
20
46
  let showAllOutput = this._getPoetryShowAllOutput(manifestDir, opts);
21
47
  let versionMap = this._parsePoetryShowAll(showAllOutput);
22
- return this._parsePoetryTree(treeOutput, versionMap);
48
+ let lockDir = this._findLockFileDir(manifestDir, opts);
49
+ let markerData = this._extractMarkerData(lockDir, parsed);
50
+ return this._parsePoetryTree(treeOutput, versionMap, markerData);
23
51
  }
24
52
  /**
25
53
  * Get poetry show --tree output.
26
54
  * @param {string} manifestDir
55
+ * @param {boolean} hasDevGroup
27
56
  * @param {Object} opts
28
57
  * @returns {string}
29
58
  */
30
- _getPoetryShowTreeOutput(manifestDir, opts) {
59
+ _getPoetryShowTreeOutput(manifestDir, hasDevGroup, opts) {
31
60
  if (environmentVariableIsPopulated('TRUSTIFY_DA_POETRY_SHOW_TREE')) {
32
61
  return Buffer.from(process.env['TRUSTIFY_DA_POETRY_SHOW_TREE'], 'base64').toString('utf-8');
33
62
  }
34
63
  let poetryBin = getCustomPath('poetry', opts);
35
- return invokeCommand(poetryBin, ['show', '--tree', '--no-ansi'], { cwd: manifestDir }).toString();
64
+ let args = ['show', '--tree', '--no-ansi'];
65
+ if (hasDevGroup) {
66
+ args.push('--without', 'dev');
67
+ }
68
+ return invokeCommand(poetryBin, args, { cwd: manifestDir }).toString();
36
69
  }
37
70
  /**
38
71
  * Get poetry show --all output (flat list with resolved versions).
@@ -69,16 +102,60 @@ export default class Python_poetry extends Base_pyproject {
69
102
  }
70
103
  return versions;
71
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
+ }
72
150
  /**
73
151
  * Parse poetry show --tree output into a dependency graph structure.
74
- * Top-level lines (no indentation/tree chars) are direct deps: "name version description"
75
- * Indented lines are transitive deps with tree chars: "├── name >=constraint"
76
152
  *
77
153
  * @param {string} treeOutput
78
154
  * @param {Map<string, string>} versionMap - canonical name -> resolved version
155
+ * @param {{directMarkers: Map<string, string>, transitiveMarkers: Map<string, Map<string, string>>}} markerData
79
156
  * @returns {{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}}
80
157
  */
81
- _parsePoetryTree(treeOutput, versionMap) {
158
+ _parsePoetryTree(treeOutput, versionMap, markerData) {
82
159
  let lines = treeOutput.split(/\r?\n/);
83
160
  let graph = new Map();
84
161
  let directDeps = [];
@@ -89,11 +166,17 @@ export default class Python_poetry extends Base_pyproject {
89
166
  continue;
90
167
  }
91
168
  // top-level line: "name version description..."
92
- let topMatch = line.match(/^([A-Za-z0-9][A-Za-z0-9._-]*)\s+(\S+)\s/);
169
+ let topMatch = line.match(/^([A-Za-z0-9][A-Za-z0-9._-]*)\s+(\S+)(?:\s|$)/);
93
170
  if (topMatch) {
94
171
  let name = topMatch[1];
95
172
  let version = topMatch[2];
96
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
+ }
97
180
  directDeps.push(key);
98
181
  if (!graph.has(key)) {
99
182
  graph.set(key, { name, version, children: [] });
@@ -120,6 +203,20 @@ export default class Python_poetry extends Base_pyproject {
120
203
  // determine depth by counting tree-drawing groups in the prefix
121
204
  let prefix = line.substring(0, nameStart);
122
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
+ }
123
220
  // resolve version from the version map
124
221
  let version = versionMap.get(depKey) || null;
125
222
  if (!version) {
@@ -128,12 +225,7 @@ export default class Python_poetry extends Base_pyproject {
128
225
  if (!graph.has(depKey)) {
129
226
  graph.set(depKey, { name: depName, version, children: [] });
130
227
  }
131
- // pop stack back to find the parent at depth-1
132
- while (stack.length > 0 && stack[stack.length - 1].depth >= depth) {
133
- stack.pop();
134
- }
135
- if (stack.length > 0) {
136
- let parentKey = stack[stack.length - 1].key;
228
+ if (parentKey) {
137
229
  let parentEntry = graph.get(parentKey);
138
230
  if (parentEntry && !parentEntry.children.includes(depKey)) {
139
231
  parentEntry.children.push(depKey);
@@ -1,4 +1,19 @@
1
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
+ }>;
2
17
  /**
3
18
  * Get the uv export output, either from env var or by running the command.
4
19
  * @param {string} manifestDir
@@ -12,9 +27,10 @@ export default class Python_uv extends Base_pyproject {
12
27
  *
13
28
  * @param {string} output
14
29
  * @param {string} projectName - canonical project name to identify direct deps
30
+ * @param {string} workspaceDir - workspace root (for resolving editable install paths)
15
31
  * @returns {Promise<{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}>}
16
32
  */
17
- _parseUvExport(output: string, projectName: string): Promise<{
33
+ _parseUvExport(output: string, projectName: string, workspaceDir: string): Promise<{
18
34
  directDeps: string[];
19
35
  graph: Map<string, {
20
36
  name: string;
@@ -1,5 +1,9 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { parse as parseToml } from 'smol-toml';
1
4
  import { environmentVariableIsPopulated, getCustomPath, invokeCommand } from '../tools.js';
2
5
  import Base_pyproject from './base_pyproject.js';
6
+ import { evaluateMarker } from './marker_evaluator.js';
3
7
  import { getParser, getPinnedVersionQuery } from './requirements_parser.js';
4
8
  export default class Python_uv extends Base_pyproject {
5
9
  /** @returns {string} */
@@ -11,15 +15,16 @@ export default class Python_uv extends Base_pyproject {
11
15
  return 'uv';
12
16
  }
13
17
  /**
14
- * @param {string} manifestDir
18
+ * @param {string} manifestDir - directory containing the target pyproject.toml
19
+ * @param {string} workspaceDir - workspace root (for resolving editable install paths)
15
20
  * @param {object} parsed - parsed pyproject.toml
16
21
  * @param {Object} opts
17
22
  * @returns {Promise<{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}>}
18
23
  */
19
- async _getDependencyData(manifestDir, parsed, opts) {
24
+ async _getDependencyData(manifestDir, workspaceDir, parsed, opts) {
20
25
  let projectName = this._getProjectName(parsed);
21
26
  let uvOutput = this._getUvExportOutput(manifestDir, opts);
22
- return this._parseUvExport(uvOutput, projectName);
27
+ return this._parseUvExport(uvOutput, projectName, workspaceDir);
23
28
  }
24
29
  /**
25
30
  * Get the uv export output, either from env var or by running the command.
@@ -32,7 +37,7 @@ export default class Python_uv extends Base_pyproject {
32
37
  return Buffer.from(process.env['TRUSTIFY_DA_UV_EXPORT'], 'base64').toString('ascii');
33
38
  }
34
39
  let uvBin = getCustomPath('uv', opts);
35
- return invokeCommand(uvBin, ['export', '--format', 'requirements.txt', '--frozen', '--no-hashes'], { cwd: manifestDir }).toString();
40
+ return invokeCommand(uvBin, ['export', '--format', 'requirements.txt', '--frozen', '--no-hashes', '--no-dev', '--no-emit-project'], { cwd: manifestDir }).toString();
36
41
  }
37
42
  /**
38
43
  * Parse uv export output into a dependency graph using tree-sitter-requirements
@@ -40,9 +45,10 @@ export default class Python_uv extends Base_pyproject {
40
45
  *
41
46
  * @param {string} output
42
47
  * @param {string} projectName - canonical project name to identify direct deps
48
+ * @param {string} workspaceDir - workspace root (for resolving editable install paths)
43
49
  * @returns {Promise<{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}>}
44
50
  */
45
- async _parseUvExport(output, projectName) {
51
+ async _parseUvExport(output, projectName, workspaceDir) {
46
52
  let [parser, pinnedVersionQuery] = await Promise.all([
47
53
  getParser(), getPinnedVersionQuery()
48
54
  ]);
@@ -53,11 +59,47 @@ export default class Python_uv extends Base_pyproject {
53
59
  let currentPkg = null;
54
60
  let collectingVia = false;
55
61
  for (let child of root.children) {
62
+ if (child.type === 'global_opt') {
63
+ let optNode = child.children.find(c => c.type === 'option');
64
+ let pathNode = child.children.find(c => c.type === 'path');
65
+ if (optNode?.text === '-e' && pathNode && workspaceDir) {
66
+ let memberDir = path.resolve(workspaceDir, pathNode.text);
67
+ let memberManifest = path.join(memberDir, 'pyproject.toml');
68
+ if (fs.existsSync(memberManifest)) {
69
+ let memberParsed = parseToml(fs.readFileSync(memberManifest, 'utf-8'));
70
+ let name = memberParsed.project?.name || memberParsed.tool?.poetry?.name;
71
+ let version = memberParsed.project?.version || memberParsed.tool?.poetry?.version;
72
+ if (name && version) {
73
+ let key = this._canonicalize(name);
74
+ if (key === canonProjectName) {
75
+ continue;
76
+ }
77
+ currentPkg = { name, version, parents: new Set() };
78
+ packages.set(key, currentPkg);
79
+ collectingVia = false;
80
+ continue;
81
+ }
82
+ }
83
+ }
84
+ currentPkg = null;
85
+ collectingVia = false;
86
+ continue;
87
+ }
56
88
  if (child.type === 'requirement') {
57
89
  let nameNode = child.children.find(c => c.type === 'package');
58
90
  if (!nameNode) {
59
91
  continue;
60
92
  }
93
+ // Skip packages with non-matching PEP 508 markers, e.g. "pywin32==311 ; sys_platform == 'win32'"
94
+ let markerNode = child.children.find(c => c.type === 'marker_spec');
95
+ if (markerNode) {
96
+ let markerText = markerNode.text.replace(/^\s*;\s*/, '');
97
+ if (!evaluateMarker(markerText)) {
98
+ currentPkg = null;
99
+ collectingVia = false;
100
+ continue;
101
+ }
102
+ }
61
103
  let name = nameNode.text;
62
104
  let version = null;
63
105
  let versionMatches = pinnedVersionQuery.matches(child);
@@ -25,9 +25,14 @@ export default class Sbom {
25
25
  /**
26
26
  * @param {component} sourceRef current source Component ( Starting from root component by clients)
27
27
  * @param {PackageURL} targetRef current dependency to add to Dependencies list of component sourceRef
28
+ * @param {string} [scope] - Scope of the dependency
29
+ * @param {Array<{alg: string, content: string}>} [targetHashes] - Optional hashes for the target component
28
30
  * @return Sbom
29
31
  */
30
- addDependency(sourceRef: component, targetRef: PackageURL, scope: any): CycloneDxSbom;
32
+ addDependency(sourceRef: component, targetRef: PackageURL, scope?: string, targetHashes?: Array<{
33
+ alg: string;
34
+ content: string;
35
+ }>): CycloneDxSbom;
31
36
  /**
32
37
  * @return String sbom json in a string format
33
38
  */
@@ -45,6 +50,7 @@ export default class Sbom {
45
50
  version: any;
46
51
  scope: any;
47
52
  licenses?: any;
53
+ hashes?: any;
48
54
  };
49
55
  /** This method gets a component object, and a string name, and checks if the name is a substring of the component' purl.
50
56
  * @param {} component to search in its dependencies
package/dist/src/sbom.js CHANGED
@@ -43,10 +43,12 @@ export default class Sbom {
43
43
  /**
44
44
  * @param {component} sourceRef current source Component ( Starting from root component by clients)
45
45
  * @param {PackageURL} targetRef current dependency to add to Dependencies list of component sourceRef
46
+ * @param {string} [scope] - Scope of the dependency
47
+ * @param {Array<{alg: string, content: string}>} [targetHashes] - Optional hashes for the target component
46
48
  * @return Sbom
47
49
  */
48
- addDependency(sourceRef, targetRef, scope) {
49
- return this.sbomModel.addDependency(sourceRef, targetRef, scope);
50
+ addDependency(sourceRef, targetRef, scope, targetHashes) {
51
+ return this.sbomModel.addDependency(sourceRef, targetRef, scope, targetHashes);
50
52
  }
51
53
  /**
52
54
  * @return String sbom json in a string format
@@ -61,6 +61,32 @@ export function toPurlFromString(strPurl: any): PackageURL | null;
61
61
  * @param {string} cwd - directory for which to find the root of the git repository.
62
62
  */
63
63
  export function getGitRootDir(cwd: string): string | undefined;
64
+ /**
65
+ * Normalize a filesystem path, lowercasing on Windows for case-insensitive comparison.
66
+ *
67
+ * @param {string} thePath
68
+ * @returns {string}
69
+ */
70
+ export function normalizePath(thePath: string): string;
71
+ /**
72
+ * Walk up from `startDir` to `repoRoot` looking for an executable wrapper script.
73
+ *
74
+ * @param {string} startDir - Absolute directory to start from
75
+ * @param {string} wrapperName - Wrapper filename (e.g. `mvnw`, `gradlew`)
76
+ * @param {string} [repoRoot] - Stop boundary (defaults to git root or filesystem root)
77
+ * @returns {string | undefined}
78
+ */
79
+ export function traverseForWrapper(startDir: string, wrapperName: string, repoRoot?: string): string | undefined;
80
+ /**
81
+ * Resolve a build-tool binary, preferring a wrapper when configured.
82
+ *
83
+ * @param {string} globalBinary - Global binary name (e.g. `mvn`, `gradle`)
84
+ * @param {string} localWrapper - Wrapper filename (e.g. `mvnw`, `gradlew.bat`)
85
+ * @param {string} startDir - Directory from which to start the wrapper search
86
+ * @param {import('./index.js').Options} [opts={}]
87
+ * @returns {string} Path to the resolved binary
88
+ */
89
+ export function resolveBinary(globalBinary: string, localWrapper: string, startDir: string, opts?: import("./index.js").Options): string;
64
90
  /** this method invokes command string in a process in a synchronous way.
65
91
  * @param {string} bin - the command to be invoked
66
92
  * @param {Array<string>} args - the args to pass to the binary