@trustify-da/trustify-da-javascript-client 0.3.0-ea.c2f6c64 → 0.3.0-ea.c300d9f

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 (86) hide show
  1. package/README.md +199 -11
  2. package/dist/package.json +30 -26
  3. package/dist/src/analysis.d.ts +14 -7
  4. package/dist/src/analysis.js +32 -14
  5. package/dist/src/cli.js +188 -6
  6. package/dist/src/config.d.ts +120 -0
  7. package/dist/src/config.js +260 -0
  8. package/dist/src/cyclone_dx_sbom.d.ts +20 -1
  9. package/dist/src/cyclone_dx_sbom.js +68 -9
  10. package/dist/src/index.d.ts +79 -15
  11. package/dist/src/index.js +90 -34
  12. package/dist/src/license/index.d.ts +3 -3
  13. package/dist/src/license/index.js +4 -1
  14. package/dist/src/license/license_utils.js +4 -1
  15. package/dist/src/license/licenses_api.d.ts +2 -2
  16. package/dist/src/oci_image/images.d.ts +1 -1
  17. package/dist/src/oci_image/images.js +15 -1
  18. package/dist/src/oci_image/utils.d.ts +5 -5
  19. package/dist/src/package_version.d.ts +8 -0
  20. package/dist/src/package_version.js +31 -0
  21. package/dist/src/provider.d.ts +4 -3
  22. package/dist/src/provider.js +8 -2
  23. package/dist/src/providers/base_java.d.ts +67 -12
  24. package/dist/src/providers/base_java.js +82 -61
  25. package/dist/src/providers/base_javascript.d.ts +74 -9
  26. package/dist/src/providers/base_javascript.js +116 -7
  27. package/dist/src/providers/base_pyproject.d.ts +42 -31
  28. package/dist/src/providers/base_pyproject.js +121 -78
  29. package/dist/src/providers/containerfile_parser.d.ts +5 -0
  30. package/dist/src/providers/containerfile_parser.js +20 -0
  31. package/dist/src/providers/golang_gomodules.d.ts +11 -1
  32. package/dist/src/providers/golang_gomodules.js +114 -15
  33. package/dist/src/providers/java_gradle.d.ts +67 -0
  34. package/dist/src/providers/java_gradle.js +312 -20
  35. package/dist/src/providers/java_gradle_groovy.d.ts +1 -1
  36. package/dist/src/providers/java_gradle_kotlin.d.ts +1 -1
  37. package/dist/src/providers/java_maven.d.ts +37 -9
  38. package/dist/src/providers/java_maven.js +269 -11
  39. package/dist/src/providers/javascript_bun.d.ts +22 -0
  40. package/dist/src/providers/javascript_bun.js +141 -0
  41. package/dist/src/providers/javascript_npm.d.ts +19 -0
  42. package/dist/src/providers/javascript_npm.js +61 -1
  43. package/dist/src/providers/javascript_pnpm.d.ts +13 -0
  44. package/dist/src/providers/javascript_pnpm.js +53 -3
  45. package/dist/src/providers/javascript_yarn.d.ts +12 -0
  46. package/dist/src/providers/javascript_yarn.js +75 -2
  47. package/dist/src/providers/manifest.js +6 -3
  48. package/dist/src/providers/marker_evaluator.d.ts +14 -0
  49. package/dist/src/providers/marker_evaluator.js +191 -0
  50. package/dist/src/providers/oci_dockerfile.d.ts +51 -0
  51. package/dist/src/providers/oci_dockerfile.js +177 -0
  52. package/dist/src/providers/processors/yarn_berry_processor.d.ts +6 -2
  53. package/dist/src/providers/processors/yarn_berry_processor.js +9 -4
  54. package/dist/src/providers/processors/yarn_classic_processor.d.ts +6 -2
  55. package/dist/src/providers/processors/yarn_classic_processor.js +8 -6
  56. package/dist/src/providers/python_controller.d.ts +5 -1
  57. package/dist/src/providers/python_controller.js +69 -8
  58. package/dist/src/providers/python_pip.d.ts +5 -0
  59. package/dist/src/providers/python_pip.js +5 -5
  60. package/dist/src/providers/python_pip_pyproject.d.ts +61 -0
  61. package/dist/src/providers/python_pip_pyproject.js +146 -0
  62. package/dist/src/providers/python_poetry.d.ts +64 -8
  63. package/dist/src/providers/python_poetry.js +165 -25
  64. package/dist/src/providers/python_uv.d.ts +22 -2
  65. package/dist/src/providers/python_uv.js +157 -6
  66. package/dist/src/providers/requirements_parser.js +1 -1
  67. package/dist/src/providers/rust_cargo.d.ts +6 -2
  68. package/dist/src/providers/rust_cargo.js +101 -33
  69. package/dist/src/providers/tree-sitter-containerfile.wasm +0 -0
  70. package/dist/src/remediate.d.ts +120 -0
  71. package/dist/src/remediate.js +253 -0
  72. package/dist/src/remediation.d.ts +57 -0
  73. package/dist/src/remediation.js +436 -0
  74. package/dist/src/remediation_report.d.ts +40 -0
  75. package/dist/src/remediation_report.js +159 -0
  76. package/dist/src/sbom.d.ts +18 -1
  77. package/dist/src/sbom.js +14 -2
  78. package/dist/src/tools.d.ts +37 -13
  79. package/dist/src/tools.js +92 -13
  80. package/dist/src/updaters/maven_updater.d.ts +58 -0
  81. package/dist/src/updaters/maven_updater.js +345 -0
  82. package/dist/src/updaters/toml_updater.d.ts +62 -0
  83. package/dist/src/updaters/toml_updater.js +276 -0
  84. package/dist/src/workspace.d.ts +11 -1
  85. package/dist/src/workspace.js +3 -2
  86. package/package.json +31 -27
@@ -12,6 +12,49 @@ import Manifest from './manifest.js';
12
12
  * @type {string}
13
13
  */
14
14
  export const purlType = 'npm';
15
+ /**
16
+ * Maps a Subresource Integrity (SRI) algorithm token to its CycloneDX label.
17
+ * @type {Object<string, string>}
18
+ */
19
+ const SRI_ALG_LABELS = {
20
+ sha1: 'SHA-1',
21
+ sha256: 'SHA-256',
22
+ sha384: 'SHA-384',
23
+ sha512: 'SHA-512',
24
+ };
25
+ /**
26
+ * Converts a Subresource Integrity (SRI) string to a CycloneDX hash object.
27
+ * SRI is formatted as `<alg>-<base64>` (e.g. `sha512-Ab3d...`). CycloneDX
28
+ * expects an uppercased algorithm label (e.g. `SHA-512`) and a hex-encoded
29
+ * digest. When the SRI string contains multiple space-separated hashes, only
30
+ * the first is used.
31
+ * @param {string} integrity - SRI string from a lock file
32
+ * @returns {{alg: string, content: string}|null} CycloneDX hash, or null when unparseable
33
+ */
34
+ export function sriToHash(integrity) {
35
+ if (typeof integrity !== 'string') {
36
+ return null;
37
+ }
38
+ const first = integrity.trim().split(/\s+/)[0];
39
+ if (!first) {
40
+ return null;
41
+ }
42
+ const dash = first.indexOf('-');
43
+ if (dash < 0) {
44
+ return null;
45
+ }
46
+ const alg = SRI_ALG_LABELS[first.slice(0, dash).toLowerCase()];
47
+ // Strip any SRI options (e.g. "?foo") that may follow the base64 payload
48
+ const base64 = first.slice(dash + 1).split('?')[0];
49
+ if (!alg || !base64) {
50
+ return null;
51
+ }
52
+ const content = Buffer.from(base64, 'base64').toString('hex');
53
+ if (!content) {
54
+ return null;
55
+ }
56
+ return { alg, content };
57
+ }
15
58
  /**
16
59
  * Base class for JavaScript package manager providers.
17
60
  * This class provides common functionality for different JavaScript package managers
@@ -25,6 +68,11 @@ export default class Base_javascript {
25
68
  #cmd;
26
69
  /** @type {string} */
27
70
  #ecosystem;
71
+ /**
72
+ * Lock-file hashes keyed by `name@version`.
73
+ * @type {Map<string, Array<{alg: string, content: string}>>}
74
+ */
75
+ #hashes = new Map();
28
76
  /**
29
77
  * Sets up the provider with the manifest path and options
30
78
  * @param {string} manifestPath - Path to the package.json manifest file
@@ -71,6 +119,13 @@ export default class Base_javascript {
71
119
  throw new TypeError("_cmdName must be implemented");
72
120
  }
73
121
  /**
122
+ * Returns the package manager name (e.g. npm, yarn, pnpm, bun)
123
+ * @returns {string} The package manager name
124
+ */
125
+ packageManagerName() {
126
+ return this._cmdName();
127
+ }
128
+ /**
74
129
  * Returns the command arguments for listing dependencies
75
130
  * @returns {Array<string>} The command arguments
76
131
  * @abstract
@@ -88,6 +143,58 @@ export default class Base_javascript {
88
143
  _updateLockFileCmdArgs() {
89
144
  throw new TypeError("_updateLockFileCmdArgs must be implemented");
90
145
  }
146
+ /**
147
+ * Parses the provider's lock file into a hash map keyed by `name@version`.
148
+ * Subclasses override this (accepting the lock directory) to support their
149
+ * lock file format. The default implementation returns an empty map so
150
+ * providers without lock parsing (or without a lock file present) gracefully
151
+ * omit hashes.
152
+ * @returns {Map<string, Array<{alg: string, content: string}>>} Hash map
153
+ * @protected
154
+ */
155
+ _parseLockFileHashes() {
156
+ return new Map();
157
+ }
158
+ /**
159
+ * Loads lock-file hashes for the given directory into internal state.
160
+ * Parsing failures degrade gracefully to an empty map (no hashes emitted).
161
+ * @param {string} lockDir - Directory containing the lock file
162
+ * @protected
163
+ */
164
+ _loadHashes(lockDir) {
165
+ try {
166
+ this.#hashes = this._parseLockFileHashes(lockDir) || new Map();
167
+ }
168
+ catch (_) {
169
+ this.#hashes = new Map();
170
+ }
171
+ }
172
+ /**
173
+ * Looks up CycloneDX hashes for a package by name and resolved version.
174
+ * @param {string} name - The package name (including scope, e.g. `@hapi/joi`)
175
+ * @param {string} version - The resolved package version
176
+ * @returns {Array<{alg: string, content: string}>|undefined} Hashes, or undefined
177
+ * @protected
178
+ */
179
+ _hashesFor(name, version) {
180
+ if (!name || !version) {
181
+ return undefined;
182
+ }
183
+ return this.#hashes.get(`${name}@${version}`);
184
+ }
185
+ /**
186
+ * Looks up CycloneDX hashes for a package described by a PackageURL.
187
+ * @param {PackageURL} purl - The package URL
188
+ * @returns {Array<{alg: string, content: string}>|undefined} Hashes, or undefined
189
+ * @protected
190
+ */
191
+ _hashesForPurl(purl) {
192
+ if (!purl) {
193
+ return undefined;
194
+ }
195
+ const name = purl.namespace ? `${purl.namespace}/${purl.name}` : purl.name;
196
+ return this._hashesFor(name, purl.version);
197
+ }
91
198
  /**
92
199
  * Checks if the provider supports the given manifest name
93
200
  * @param {string} manifestName - The manifest name to check
@@ -217,7 +324,8 @@ export default class Base_javascript {
217
324
  this._version();
218
325
  const manifestDir = path.dirname(this.#manifest.manifestPath);
219
326
  const cmdDir = this._findLockFileDir(manifestDir, opts) || manifestDir;
220
- this.#createLockFile(cmdDir);
327
+ this._createLockFile(cmdDir);
328
+ this._loadHashes(cmdDir);
221
329
  let output = this.#executeListCmd(includeTransitive, cmdDir);
222
330
  output = this._parseDepTreeOutput(output);
223
331
  return JSON.parse(output);
@@ -277,7 +385,7 @@ export default class Base_javascript {
277
385
  const [name, artifact] = entry;
278
386
  const target = toPurl(purlType, name, artifact.version);
279
387
  const rootPurl = toPurl(purlType, this.#manifest.name, this.#manifest.version);
280
- sbom.addDependency(rootPurl, target);
388
+ sbom.addDependency(rootPurl, target, undefined, this._hashesFor(name, artifact.version));
281
389
  this.#addDependenciesOf(sbom, target, artifact);
282
390
  });
283
391
  }
@@ -295,7 +403,7 @@ export default class Base_javascript {
295
403
  const [name, depArtifact] = entry;
296
404
  if (depArtifact.version !== undefined) {
297
405
  const target = toPurl(purlType, name, depArtifact.version);
298
- sbom.addDependency(from, target);
406
+ sbom.addDependency(from, target, undefined, this._hashesFor(name, depArtifact.version));
299
407
  this.#addDependenciesOf(sbom, target, depArtifact);
300
408
  }
301
409
  });
@@ -319,7 +427,8 @@ export default class Base_javascript {
319
427
  .sort();
320
428
  for (const key of sortedDepsKeys) {
321
429
  const rootPurl = toPurlFromString(sbom.getRoot().purl);
322
- sbom.addDependency(rootPurl, rootDeps.get(key));
430
+ const targetPurl = rootDeps.get(key);
431
+ sbom.addDependency(rootPurl, targetPurl, undefined, this._hashesForPurl(targetPurl));
323
432
  }
324
433
  this.#ensurePeerAndOptionalDeps(sbom);
325
434
  sbom.filterIgnoredDeps(this.#manifest.ignored);
@@ -363,9 +472,9 @@ export default class Base_javascript {
363
472
  /**
364
473
  * Creates or updates the lock file for the package manager
365
474
  * @param {string} manifestDir - Directory containing the manifest file
366
- * @private
475
+ * @protected
367
476
  */
368
- #createLockFile(manifestDir) {
477
+ _createLockFile(manifestDir) {
369
478
  const originalDir = process.cwd();
370
479
  const isWindows = os.platform() === 'win32';
371
480
  if (isWindows) {
@@ -423,7 +532,7 @@ export default class Base_javascript {
423
532
  }
424
533
  }
425
534
  // Try to find the command in the following order:
426
- // 1. Custom path from environment/opts (via getCustomPath)
535
+ // 1. Custom path from opts/environment (via getCustomPath)
427
536
  // 2. Local node_modules/.bin
428
537
  // 3. Global installation
429
538
  let cmd = this.#cmd;
@@ -1,4 +1,4 @@
1
- /** @typedef {{name: string, version: string, children: string[]}} GraphEntry */
1
+ /** @typedef {{name: string, version: string, children: string[], hashes?: Array<{alg: string, content: string}>}} GraphEntry */
2
2
  /** @typedef {{name: string, version: string, dependencies: DepTreeEntry[]}} DepTreeEntry */
3
3
  /** @typedef {{directDeps: string[], graph: Map<string, GraphEntry>}} DependencyData */
4
4
  /** @typedef {{ecosystem: string, content: string, contentType: string}} Provided */
@@ -10,9 +10,29 @@ export default class Base_pyproject {
10
10
  isSupported(manifestName: string): boolean;
11
11
  /**
12
12
  * @param {string} manifestDir
13
+ * @param {Object} [opts={}]
13
14
  * @returns {boolean}
14
15
  */
15
- validateLockFile(manifestDir: string): boolean;
16
+ validateLockFile(manifestDir: string, opts?: Object): boolean;
17
+ /**
18
+ * Walk up from manifestDir to find the directory containing the lock file.
19
+ * Follows the same pattern as Base_javascript._findLockFileDir().
20
+ * @param {string} manifestDir
21
+ * @param {Object} [opts={}]
22
+ * @returns {string|null}
23
+ * @protected
24
+ */
25
+ protected _findLockFileDir(manifestDir: string, opts?: Object): string | null;
26
+ /**
27
+ * Detect workspace root boundaries.
28
+ * Currently only uv has native workspace support ([tool.uv.workspace] in pyproject.toml).
29
+ * Poetry has no workspace/monorepo support (python-poetry/poetry#2270), so each
30
+ * poetry project is treated independently — see Python_poetry._findLockFileDir().
31
+ * @param {string} dir
32
+ * @returns {boolean}
33
+ * @protected
34
+ */
35
+ protected _isWorkspaceRoot(dir: string): boolean;
16
36
  /**
17
37
  * Read project license from pyproject.toml, with fallback to LICENSE file.
18
38
  * @param {string} manifestPath
@@ -24,13 +44,13 @@ export default class Base_pyproject {
24
44
  * @param {Object} [opts={}]
25
45
  * @returns {Promise<Provided>}
26
46
  */
27
- provideStack(manifest: string, opts?: any): Promise<Provided>;
47
+ provideStack(manifest: string, opts?: Object): Promise<Provided>;
28
48
  /**
29
49
  * @param {string} manifest - path to pyproject.toml
30
50
  * @param {Object} [opts={}]
31
51
  * @returns {Promise<Provided>}
32
52
  */
33
- provideComponent(manifest: string, opts?: any): Promise<Provided>;
53
+ provideComponent(manifest: string, opts?: Object): Promise<Provided>;
34
54
  /**
35
55
  * @returns {string}
36
56
  * @protected
@@ -41,15 +61,23 @@ export default class Base_pyproject {
41
61
  * @protected
42
62
  */
43
63
  protected _cmdName(): string;
64
+ /**
65
+ * Returns the package manager name (e.g. pip, poetry, uv)
66
+ * @returns {string}
67
+ */
68
+ packageManagerName(): string;
44
69
  /**
45
70
  * Resolve dependencies using the tool-specific command and parser.
46
- * @param {string} manifestDir
71
+ *
72
+ * @param {string} manifestDir - directory containing the target pyproject.toml
73
+ * @param {string} workspaceDir - workspace root (where the lock file lives);
74
+ * only used by providers that need workspace-level resolution (e.g. uv)
47
75
  * @param {object} parsed - parsed pyproject.toml
48
76
  * @param {Object} opts
49
77
  * @returns {Promise<DependencyData>}
50
78
  * @protected
51
79
  */
52
- protected _getDependencyData(manifestDir: string, parsed: object, opts: any): Promise<DependencyData>;
80
+ protected _getDependencyData(manifestDir: string, workspaceDir: string, parsed: object, opts: Object): Promise<DependencyData>;
53
81
  /**
54
82
  * Canonicalize a Python package name per PEP 503.
55
83
  * @param {string} name
@@ -79,26 +107,14 @@ export default class Base_pyproject {
79
107
  */
80
108
  protected _getIgnoredDeps(manifestPath: string): Set<string>;
81
109
  /**
82
- * Build dependency tree from graph, starting from direct deps.
83
- * @param {Map<string, GraphEntry>} graph
84
- * @param {string[]} directDeps - canonical names of direct deps
85
- * @param {Set<string>} ignoredDeps
86
- * @param {boolean} includeTransitive
87
- * @returns {DepTreeEntry[]}
88
- * @protected
89
- */
90
- protected _buildDependencyTree(graph: Map<string, GraphEntry>, directDeps: string[], ignoredDeps: Set<string>, includeTransitive: boolean): DepTreeEntry[];
91
- /**
92
- * Recursively collect transitive dependencies.
110
+ * Compute the set of graph nodes reachable from direct deps, excluding ignored.
93
111
  * @param {Map<string, GraphEntry>} graph
94
- * @param {string[]} childKeys
95
- * @param {DepTreeEntry[]} result - mutated in place
112
+ * @param {string[]} directDeps
96
113
  * @param {Set<string>} ignoredDeps
97
- * @param {Set<string>} visited
98
- * @returns {void}
114
+ * @returns {Set<string>}
99
115
  * @protected
100
116
  */
101
- protected _collectTransitive(graph: Map<string, GraphEntry>, childKeys: string[], result: DepTreeEntry[], ignoredDeps: Set<string>, visited: Set<string>): void;
117
+ protected _reachableNodes(graph: Map<string, GraphEntry>, directDeps: string[], ignoredDeps: Set<string>): Set<string>;
102
118
  /**
103
119
  * @param {string} name
104
120
  * @param {string} version
@@ -106,15 +122,6 @@ export default class Base_pyproject {
106
122
  * @protected
107
123
  */
108
124
  protected _toPurl(name: string, version: string): PackageURL;
109
- /**
110
- * Recursively add a dependency and its transitive deps to the SBOM.
111
- * @param {PackageURL} source
112
- * @param {DepTreeEntry} dep
113
- * @param {Sbom} sbom
114
- * @returns {void}
115
- * @private
116
- */
117
- private _addAllDependencies;
118
125
  /**
119
126
  * Create SBOM json string for a pyproject.toml project.
120
127
  * @param {string} manifest - path to pyproject.toml
@@ -129,6 +136,10 @@ export type GraphEntry = {
129
136
  name: string;
130
137
  version: string;
131
138
  children: string[];
139
+ hashes?: Array<{
140
+ alg: string;
141
+ content: string;
142
+ }>;
132
143
  };
133
144
  export type DepTreeEntry = {
134
145
  name: string;
@@ -4,11 +4,13 @@ import { PackageURL } from 'packageurl-js';
4
4
  import { parse as parseToml } from 'smol-toml';
5
5
  import { getLicense } from '../license/license_utils.js';
6
6
  import Sbom from '../sbom.js';
7
+ import { getCustom } from '../tools.js';
7
8
  const ecosystem = 'pip';
8
9
  const IGNORE_MARKERS = ['exhortignore', 'trustify-da-ignore'];
10
+ const NO_SCOPE = undefined;
9
11
  const DEFAULT_ROOT_NAME = 'default-pip-root';
10
12
  const DEFAULT_ROOT_VERSION = '0.0.0';
11
- /** @typedef {{name: string, version: string, children: string[]}} GraphEntry */
13
+ /** @typedef {{name: string, version: string, children: string[], hashes?: Array<{alg: string, content: string}>}} GraphEntry */
12
14
  /** @typedef {{name: string, version: string, dependencies: DepTreeEntry[]}} DepTreeEntry */
13
15
  /** @typedef {{directDeps: string[], graph: Map<string, GraphEntry>}} DependencyData */
14
16
  /** @typedef {{ecosystem: string, content: string, contentType: string}} Provided */
@@ -22,10 +24,64 @@ export default class Base_pyproject {
22
24
  }
23
25
  /**
24
26
  * @param {string} manifestDir
27
+ * @param {Object} [opts={}]
25
28
  * @returns {boolean}
26
29
  */
27
- validateLockFile(manifestDir) {
28
- return fs.existsSync(path.join(manifestDir, this._lockFileName()));
30
+ validateLockFile(manifestDir, opts = {}) {
31
+ return this._findLockFileDir(manifestDir, opts) != null;
32
+ }
33
+ /**
34
+ * Walk up from manifestDir to find the directory containing the lock file.
35
+ * Follows the same pattern as Base_javascript._findLockFileDir().
36
+ * @param {string} manifestDir
37
+ * @param {Object} [opts={}]
38
+ * @returns {string|null}
39
+ * @protected
40
+ */
41
+ _findLockFileDir(manifestDir, opts = {}) {
42
+ const workspaceDir = getCustom('TRUSTIFY_DA_WORKSPACE_DIR', null, opts);
43
+ if (workspaceDir) {
44
+ const dir = path.resolve(workspaceDir);
45
+ return fs.existsSync(path.join(dir, this._lockFileName())) ? dir : null;
46
+ }
47
+ let dir = path.resolve(manifestDir);
48
+ let parent = dir;
49
+ do {
50
+ dir = parent;
51
+ if (fs.existsSync(path.join(dir, this._lockFileName()))) {
52
+ return dir;
53
+ }
54
+ if (this._isWorkspaceRoot(dir)) {
55
+ return null;
56
+ }
57
+ parent = path.dirname(dir);
58
+ } while (parent !== dir);
59
+ return null;
60
+ }
61
+ /**
62
+ * Detect workspace root boundaries.
63
+ * Currently only uv has native workspace support ([tool.uv.workspace] in pyproject.toml).
64
+ * Poetry has no workspace/monorepo support (python-poetry/poetry#2270), so each
65
+ * poetry project is treated independently — see Python_poetry._findLockFileDir().
66
+ * @param {string} dir
67
+ * @returns {boolean}
68
+ * @protected
69
+ */
70
+ _isWorkspaceRoot(dir) {
71
+ const pyprojectPath = path.join(dir, 'pyproject.toml');
72
+ if (!fs.existsSync(pyprojectPath)) {
73
+ return false;
74
+ }
75
+ try {
76
+ const content = parseToml(fs.readFileSync(pyprojectPath, 'utf-8'));
77
+ if (content.tool?.uv?.workspace) {
78
+ return true;
79
+ }
80
+ }
81
+ catch (_) {
82
+ // ignore parse errors
83
+ }
84
+ return false;
29
85
  }
30
86
  /**
31
87
  * Read project license from pyproject.toml, with fallback to LICENSE file.
@@ -89,16 +145,26 @@ export default class Base_pyproject {
89
145
  _cmdName() {
90
146
  throw new TypeError('_cmdName must be implemented');
91
147
  }
148
+ /**
149
+ * Returns the package manager name (e.g. pip, poetry, uv)
150
+ * @returns {string}
151
+ */
152
+ packageManagerName() {
153
+ return this._cmdName();
154
+ }
92
155
  /**
93
156
  * Resolve dependencies using the tool-specific command and parser.
94
- * @param {string} manifestDir
157
+ *
158
+ * @param {string} manifestDir - directory containing the target pyproject.toml
159
+ * @param {string} workspaceDir - workspace root (where the lock file lives);
160
+ * only used by providers that need workspace-level resolution (e.g. uv)
95
161
  * @param {object} parsed - parsed pyproject.toml
96
162
  * @param {Object} opts
97
163
  * @returns {Promise<DependencyData>}
98
164
  * @protected
99
165
  */
100
166
  // eslint-disable-next-line no-unused-vars
101
- async _getDependencyData(manifestDir, parsed, opts) {
167
+ async _getDependencyData(manifestDir, workspaceDir, parsed, opts) {
102
168
  throw new TypeError('_getDependencyData must be implemented');
103
169
  }
104
170
  // --- shared helpers ---
@@ -162,64 +228,29 @@ export default class Base_pyproject {
162
228
  return ignored;
163
229
  }
164
230
  /**
165
- * Build dependency tree from graph, starting from direct deps.
166
- * @param {Map<string, GraphEntry>} graph
167
- * @param {string[]} directDeps - canonical names of direct deps
168
- * @param {Set<string>} ignoredDeps
169
- * @param {boolean} includeTransitive
170
- * @returns {DepTreeEntry[]}
171
- * @protected
172
- */
173
- _buildDependencyTree(graph, directDeps, ignoredDeps, includeTransitive) {
174
- let result = [];
175
- for (let key of directDeps) {
176
- if (ignoredDeps.has(key)) {
177
- continue;
178
- }
179
- let entry = graph.get(key);
180
- if (!entry) {
181
- continue;
182
- }
183
- let depTree = [];
184
- if (includeTransitive) {
185
- let visited = new Set();
186
- visited.add(key);
187
- this._collectTransitive(graph, entry.children, depTree, ignoredDeps, visited);
188
- }
189
- result.push({ name: entry.name, version: entry.version, dependencies: depTree });
190
- }
191
- result.sort((a, b) => a.name.toLowerCase().localeCompare(b.name.toLowerCase()));
192
- return result;
193
- }
194
- /**
195
- * Recursively collect transitive dependencies.
231
+ * Compute the set of graph nodes reachable from direct deps, excluding ignored.
196
232
  * @param {Map<string, GraphEntry>} graph
197
- * @param {string[]} childKeys
198
- * @param {DepTreeEntry[]} result - mutated in place
233
+ * @param {string[]} directDeps
199
234
  * @param {Set<string>} ignoredDeps
200
- * @param {Set<string>} visited
201
- * @returns {void}
235
+ * @returns {Set<string>}
202
236
  * @protected
203
237
  */
204
- _collectTransitive(graph, childKeys, result, ignoredDeps, visited) {
205
- for (let childKey of childKeys) {
206
- let canonKey = this._canonicalize(childKey);
207
- if (ignoredDeps.has(canonKey)) {
238
+ _reachableNodes(graph, directDeps, ignoredDeps) {
239
+ let reachable = new Set();
240
+ let queue = directDeps.filter(k => !ignoredDeps.has(k) && graph.has(k));
241
+ while (queue.length > 0) {
242
+ let key = queue.shift();
243
+ if (reachable.has(key)) {
208
244
  continue;
209
245
  }
210
- if (visited.has(canonKey)) {
211
- continue;
212
- }
213
- visited.add(canonKey);
214
- let entry = graph.get(canonKey);
215
- if (!entry) {
216
- continue;
246
+ reachable.add(key);
247
+ for (let child of graph.get(key).children) {
248
+ if (!ignoredDeps.has(child) && graph.has(child) && !reachable.has(child)) {
249
+ queue.push(child);
250
+ }
217
251
  }
218
- let childDeps = [];
219
- this._collectTransitive(graph, entry.children, childDeps, ignoredDeps, visited);
220
- result.push({ name: entry.name, version: entry.version, dependencies: childDeps });
221
252
  }
222
- result.sort((a, b) => a.name.toLowerCase().localeCompare(b.name.toLowerCase()));
253
+ return reachable;
223
254
  }
224
255
  /**
225
256
  * @param {string} name
@@ -230,21 +261,6 @@ export default class Base_pyproject {
230
261
  _toPurl(name, version) {
231
262
  return new PackageURL('pypi', undefined, name, version, undefined, undefined);
232
263
  }
233
- /**
234
- * Recursively add a dependency and its transitive deps to the SBOM.
235
- * @param {PackageURL} source
236
- * @param {DepTreeEntry} dep
237
- * @param {Sbom} sbom
238
- * @returns {void}
239
- * @private
240
- */
241
- _addAllDependencies(source, dep, sbom) {
242
- let targetPurl = this._toPurl(dep.name, dep.version);
243
- sbom.addDependency(source, targetPurl);
244
- if (dep.dependencies && dep.dependencies.length > 0) {
245
- dep.dependencies.forEach(child => this._addAllDependencies(this._toPurl(dep.name, dep.version), child, sbom));
246
- }
247
- }
248
264
  /**
249
265
  * Create SBOM json string for a pyproject.toml project.
250
266
  * @param {string} manifest - path to pyproject.toml
@@ -257,23 +273,50 @@ export default class Base_pyproject {
257
273
  let manifestDir = path.dirname(manifest);
258
274
  let content = fs.readFileSync(manifest, 'utf-8');
259
275
  let parsed = parseToml(content);
260
- let { directDeps, graph } = await this._getDependencyData(manifestDir, parsed, opts);
276
+ let workspaceDir = this._findLockFileDir(manifestDir, opts) || manifestDir;
277
+ let { directDeps, graph } = await this._getDependencyData(manifestDir, workspaceDir, parsed, opts);
261
278
  let ignoredDeps = this._getIgnoredDeps(manifest);
262
- let dependencies = this._buildDependencyTree(graph, directDeps, ignoredDeps, includeTransitive);
263
279
  let sbom = new Sbom();
264
280
  let rootName = this._getProjectName(parsed) || DEFAULT_ROOT_NAME;
265
281
  let rootVersion = this._getProjectVersion(parsed) || DEFAULT_ROOT_VERSION;
266
282
  let rootPurl = this._toPurl(rootName, rootVersion);
267
283
  let license = this.readLicenseFromManifest(manifest);
268
284
  sbom.addRoot(rootPurl, license);
269
- dependencies.forEach(dep => {
270
- if (includeTransitive) {
271
- this._addAllDependencies(rootPurl, dep, sbom);
285
+ if (includeTransitive) {
286
+ let reachable = this._reachableNodes(graph, directDeps, ignoredDeps);
287
+ for (let key of directDeps) {
288
+ if (!reachable.has(key)) {
289
+ continue;
290
+ }
291
+ let entry = graph.get(key);
292
+ sbom.addDependency(rootPurl, this._toPurl(entry.name, entry.version), NO_SCOPE, entry.hashes);
272
293
  }
273
- else {
274
- sbom.addDependency(rootPurl, this._toPurl(dep.name, dep.version));
294
+ for (let [key, entry] of graph) {
295
+ if (!reachable.has(key)) {
296
+ continue;
297
+ }
298
+ let parentPurl = this._toPurl(entry.name, entry.version);
299
+ for (let child of entry.children) {
300
+ if (!reachable.has(child)) {
301
+ continue;
302
+ }
303
+ let childEntry = graph.get(child);
304
+ sbom.addDependency(parentPurl, this._toPurl(childEntry.name, childEntry.version), NO_SCOPE, childEntry.hashes);
305
+ }
275
306
  }
276
- });
307
+ }
308
+ else {
309
+ for (let key of directDeps) {
310
+ if (ignoredDeps.has(key)) {
311
+ continue;
312
+ }
313
+ let entry = graph.get(key);
314
+ if (!entry) {
315
+ continue;
316
+ }
317
+ sbom.addDependency(rootPurl, this._toPurl(entry.name, entry.version), NO_SCOPE, entry.hashes);
318
+ }
319
+ }
277
320
  return sbom.getAsJsonString(opts);
278
321
  }
279
322
  }
@@ -0,0 +1,5 @@
1
+ export function getParser(): Promise<Parser>;
2
+ export function getFromQuery(): Promise<Query>;
3
+ export function getArgQuery(): Promise<Query>;
4
+ import { Parser } from 'web-tree-sitter';
5
+ import { Query } from 'web-tree-sitter';
@@ -0,0 +1,20 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { Language, Parser, Query } from 'web-tree-sitter';
3
+ const wasmUrl = new URL('./tree-sitter-containerfile.wasm', import.meta.url);
4
+ async function init() {
5
+ await Parser.init();
6
+ const wasmBytes = new Uint8Array(await readFile(wasmUrl));
7
+ return await Language.load(wasmBytes);
8
+ }
9
+ export async function getParser() {
10
+ const language = await init();
11
+ return new Parser().setLanguage(language);
12
+ }
13
+ export async function getFromQuery() {
14
+ const language = await init();
15
+ return new Query(language, '(from_instruction (image_spec) @image)');
16
+ }
17
+ export async function getArgQuery() {
18
+ const language = await init();
19
+ return new Query(language, '(arg_instruction (arg_pair name: (_) @name default: (_) @default))');
20
+ }
@@ -1,12 +1,22 @@
1
+ /**
2
+ * Discover all go.mod manifest paths in a Go workspace.
3
+ * Uses `go work edit -json` to get workspace members.
4
+ *
5
+ * @param {string} workspaceRoot - Absolute or relative path to workspace root (must contain go.work)
6
+ * @param {import('../index.js').Options} [opts={}]
7
+ * @returns {Promise<string[]>} Paths to go.mod files (absolute)
8
+ */
9
+ export function discoverGoWorkspaceModules(workspaceRoot: string, opts?: import("../index.js").Options): Promise<string[]>;
1
10
  declare namespace _default {
2
11
  export { isSupported };
3
12
  export { validateLockFile };
4
13
  export { provideComponent };
5
14
  export { provideStack };
6
15
  export { readLicenseFromManifest };
16
+ export function packageManagerName(): string;
7
17
  }
8
18
  export default _default;
9
- export type Provided = import("../provider").Provided;
19
+ export type Provided = any;
10
20
  export type Package = {
11
21
  name: string;
12
22
  version: string;