@trustify-da/trustify-da-javascript-client 0.3.0-ea.6549d2a → 0.3.0-ea.68905d3

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 (98) hide show
  1. package/README.md +368 -14
  2. package/dist/package.json +39 -26
  3. package/dist/src/analysis.d.ts +28 -5
  4. package/dist/src/analysis.js +78 -13
  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 +287 -5
  8. package/dist/src/cyclone_dx_sbom.d.ts +27 -1
  9. package/dist/src/cyclone_dx_sbom.js +84 -10
  10. package/dist/src/index.d.ts +145 -8
  11. package/dist/src/index.js +362 -28
  12. package/dist/src/license/index.d.ts +5 -5
  13. package/dist/src/license/index.js +8 -5
  14. package/dist/src/license/license_utils.d.ts +40 -0
  15. package/dist/src/license/license_utils.js +137 -0
  16. package/dist/src/license/licenses_api.d.ts +2 -2
  17. package/dist/src/license/licenses_api.js +9 -2
  18. package/dist/src/license/project_license.d.ts +1 -6
  19. package/dist/src/license/project_license.js +4 -81
  20. package/dist/src/oci_image/images.d.ts +1 -1
  21. package/dist/src/oci_image/images.js +15 -1
  22. package/dist/src/oci_image/utils.d.ts +5 -5
  23. package/dist/src/oci_image/utils.js +11 -2
  24. package/dist/src/package_version.d.ts +8 -0
  25. package/dist/src/package_version.js +31 -0
  26. package/dist/src/provider.d.ts +8 -4
  27. package/dist/src/provider.js +18 -5
  28. package/dist/src/providers/base_java.d.ts +67 -12
  29. package/dist/src/providers/base_java.js +82 -61
  30. package/dist/src/providers/base_javascript.d.ts +91 -10
  31. package/dist/src/providers/base_javascript.js +220 -28
  32. package/dist/src/providers/base_pyproject.d.ts +158 -0
  33. package/dist/src/providers/base_pyproject.js +322 -0
  34. package/dist/src/providers/containerfile_parser.d.ts +5 -0
  35. package/dist/src/providers/containerfile_parser.js +20 -0
  36. package/dist/src/providers/golang_gomodules.d.ts +23 -13
  37. package/dist/src/providers/golang_gomodules.js +210 -121
  38. package/dist/src/providers/gomod_parser.d.ts +4 -0
  39. package/dist/src/providers/gomod_parser.js +16 -0
  40. package/dist/src/providers/java_gradle.d.ts +67 -0
  41. package/dist/src/providers/java_gradle.js +314 -21
  42. package/dist/src/providers/java_gradle_groovy.d.ts +1 -1
  43. package/dist/src/providers/java_gradle_kotlin.d.ts +1 -1
  44. package/dist/src/providers/java_maven.d.ts +38 -10
  45. package/dist/src/providers/java_maven.js +279 -20
  46. package/dist/src/providers/javascript_bun.d.ts +22 -0
  47. package/dist/src/providers/javascript_bun.js +141 -0
  48. package/dist/src/providers/javascript_npm.d.ts +19 -0
  49. package/dist/src/providers/javascript_npm.js +61 -1
  50. package/dist/src/providers/javascript_pnpm.d.ts +14 -1
  51. package/dist/src/providers/javascript_pnpm.js +55 -5
  52. package/dist/src/providers/javascript_yarn.d.ts +12 -0
  53. package/dist/src/providers/javascript_yarn.js +75 -2
  54. package/dist/src/providers/manifest.d.ts +2 -0
  55. package/dist/src/providers/manifest.js +28 -7
  56. package/dist/src/providers/marker_evaluator.d.ts +14 -0
  57. package/dist/src/providers/marker_evaluator.js +191 -0
  58. package/dist/src/providers/oci_dockerfile.d.ts +51 -0
  59. package/dist/src/providers/oci_dockerfile.js +177 -0
  60. package/dist/src/providers/processors/yarn_berry_processor.d.ts +6 -2
  61. package/dist/src/providers/processors/yarn_berry_processor.js +91 -7
  62. package/dist/src/providers/processors/yarn_classic_processor.d.ts +6 -2
  63. package/dist/src/providers/processors/yarn_classic_processor.js +8 -6
  64. package/dist/src/providers/python_controller.d.ts +5 -1
  65. package/dist/src/providers/python_controller.js +69 -8
  66. package/dist/src/providers/python_pip.d.ts +5 -0
  67. package/dist/src/providers/python_pip.js +8 -7
  68. package/dist/src/providers/python_pip_pyproject.d.ts +61 -0
  69. package/dist/src/providers/python_pip_pyproject.js +146 -0
  70. package/dist/src/providers/python_poetry.d.ts +98 -0
  71. package/dist/src/providers/python_poetry.js +286 -0
  72. package/dist/src/providers/python_uv.d.ts +46 -0
  73. package/dist/src/providers/python_uv.js +269 -0
  74. package/dist/src/providers/requirements_parser.js +5 -4
  75. package/dist/src/providers/rust_cargo.d.ts +56 -0
  76. package/dist/src/providers/rust_cargo.js +682 -0
  77. package/dist/src/providers/tree-sitter-containerfile.wasm +0 -0
  78. package/dist/src/providers/tree-sitter-gomod.wasm +0 -0
  79. package/dist/src/providers/tree-sitter-requirements.wasm +0 -0
  80. package/dist/src/remediate.d.ts +117 -0
  81. package/dist/src/remediate.js +249 -0
  82. package/dist/src/remediation.d.ts +57 -0
  83. package/dist/src/remediation.js +436 -0
  84. package/dist/src/remediation_report.d.ts +40 -0
  85. package/dist/src/remediation_report.js +159 -0
  86. package/dist/src/sbom.d.ts +25 -1
  87. package/dist/src/sbom.js +23 -2
  88. package/dist/src/tools.d.ts +28 -2
  89. package/dist/src/tools.js +82 -1
  90. package/dist/src/updaters/maven_updater.d.ts +58 -0
  91. package/dist/src/updaters/maven_updater.js +345 -0
  92. package/dist/src/updaters/toml_updater.d.ts +62 -0
  93. package/dist/src/updaters/toml_updater.js +276 -0
  94. package/dist/src/workspace.d.ts +70 -0
  95. package/dist/src/workspace.js +256 -0
  96. package/package.json +40 -27
  97. package/dist/src/license/compatibility.d.ts +0 -18
  98. package/dist/src/license/compatibility.js +0 -45
@@ -1,8 +1,9 @@
1
1
  import fs from 'node:fs';
2
2
  import os from "node:os";
3
3
  import path from 'node:path';
4
+ import { getLicense } from '../license/license_utils.js';
4
5
  import Sbom from '../sbom.js';
5
- import { getCustom, getCustomPath, invokeCommand, toPurl, toPurlFromString } from "../tools.js";
6
+ import { getCustom, getCustomPath, invokeCommand, toPurl, toPurlFromString } from '../tools.js';
6
7
  import Manifest from './manifest.js';
7
8
  /** @typedef {import('../provider').Provider} */
8
9
  /** @typedef {import('../provider').Provided} Provided */
@@ -11,6 +12,49 @@ import Manifest from './manifest.js';
11
12
  * @type {string}
12
13
  */
13
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
+ }
14
58
  /**
15
59
  * Base class for JavaScript package manager providers.
16
60
  * This class provides common functionality for different JavaScript package managers
@@ -24,6 +68,11 @@ export default class Base_javascript {
24
68
  #cmd;
25
69
  /** @type {string} */
26
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();
27
76
  /**
28
77
  * Sets up the provider with the manifest path and options
29
78
  * @param {string} manifestPath - Path to the package.json manifest file
@@ -70,6 +119,13 @@ export default class Base_javascript {
70
119
  throw new TypeError("_cmdName must be implemented");
71
120
  }
72
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
+ /**
73
129
  * Returns the command arguments for listing dependencies
74
130
  * @returns {Array<string>} The command arguments
75
131
  * @abstract
@@ -87,6 +143,58 @@ export default class Base_javascript {
87
143
  _updateLockFileCmdArgs() {
88
144
  throw new TypeError("_updateLockFileCmdArgs must be implemented");
89
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
+ }
90
198
  /**
91
199
  * Checks if the provider supports the given manifest name
92
200
  * @param {string} manifestName - The manifest name to check
@@ -96,13 +204,63 @@ export default class Base_javascript {
96
204
  return 'package.json' === manifestName;
97
205
  }
98
206
  /**
99
- * Checks if a required lock file exists in the same path as the manifest
207
+ * Walks up the directory tree from manifestDir looking for the lock file.
208
+ * Stops when the lock file is found, when a package.json with a "workspaces"
209
+ * field is encountered without a lock file (workspace root boundary), or
210
+ * when the filesystem root is reached.
211
+ *
212
+ * When TRUSTIFY_DA_WORKSPACE_DIR is set, checks only that directory (no walk-up).
213
+ *
214
+ * @param {string} manifestDir - The directory to start searching from
215
+ * @param {Object} [opts={}] - optional; may contain TRUSTIFY_DA_WORKSPACE_DIR
216
+ * @returns {string|null} The directory containing the lock file, or null
217
+ * @protected
218
+ */
219
+ _isWorkspaceRoot(dir) {
220
+ if (fs.existsSync(path.join(dir, 'pnpm-workspace.yaml'))) {
221
+ return true;
222
+ }
223
+ const pkgJsonPath = path.join(dir, 'package.json');
224
+ if (fs.existsSync(pkgJsonPath)) {
225
+ try {
226
+ const content = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf-8'));
227
+ if (content.workspaces) {
228
+ return true;
229
+ }
230
+ }
231
+ catch (_) {
232
+ // ignore parse errors
233
+ }
234
+ }
235
+ return false;
236
+ }
237
+ _findLockFileDir(manifestDir, opts = {}) {
238
+ const workspaceDir = getCustom('TRUSTIFY_DA_WORKSPACE_DIR', null, opts);
239
+ if (workspaceDir) {
240
+ const dir = path.resolve(workspaceDir);
241
+ return fs.existsSync(path.join(dir, this._lockFileName())) ? dir : null;
242
+ }
243
+ let dir = path.resolve(manifestDir);
244
+ let parent = dir;
245
+ do {
246
+ dir = parent;
247
+ if (fs.existsSync(path.join(dir, this._lockFileName()))) {
248
+ return dir;
249
+ }
250
+ if (this._isWorkspaceRoot(dir)) {
251
+ return null;
252
+ }
253
+ parent = path.dirname(dir);
254
+ } while (parent !== dir);
255
+ return null;
256
+ }
257
+ /**
100
258
  * @param {string} manifestDir - The base directory where the manifest is located
259
+ * @param {Object} [opts={}] - optional; may contain TRUSTIFY_DA_WORKSPACE_DIR
101
260
  * @returns {boolean} True if the lock file exists
102
261
  */
103
- validateLockFile(manifestDir) {
104
- const lock = path.join(manifestDir, this._lockFileName());
105
- return fs.existsSync(lock);
262
+ validateLockFile(manifestDir, opts = {}) {
263
+ return this._findLockFileDir(manifestDir, opts) !== null;
106
264
  }
107
265
  /**
108
266
  * Provides content and content type for stack analysis
@@ -138,33 +296,37 @@ export default class Base_javascript {
138
296
  * @returns {string|null}
139
297
  */
140
298
  readLicenseFromManifest(manifestPath) {
299
+ let manifestLicense;
141
300
  try {
142
301
  const content = JSON.parse(fs.readFileSync(manifestPath, 'utf-8'));
143
302
  if (typeof content.license === 'string') {
144
- return content.license.trim() || null;
303
+ manifestLicense = content.license.trim() || null;
145
304
  }
146
- if (Array.isArray(content.licenses) && content.licenses.length > 0) {
305
+ else if (Array.isArray(content.licenses) && content.licenses.length > 0) {
147
306
  const first = content.licenses[0];
148
307
  const name = first.type || first.name;
149
- return typeof name === 'string' ? name.trim() : null;
308
+ manifestLicense = (typeof name === 'string' ? name.trim() : null);
150
309
  }
151
- return null;
152
310
  }
153
311
  catch {
154
- return null;
312
+ manifestLicense = null;
155
313
  }
314
+ return getLicense(manifestLicense, manifestPath);
156
315
  }
157
316
  /**
158
317
  * Builds the dependency tree for the project
159
318
  * @param {boolean} includeTransitive - Whether to include transitive dependencies
319
+ * @param {Object} [opts={}] - Configuration options; when `TRUSTIFY_DA_WORKSPACE_DIR` is set, commands run from workspace root
160
320
  * @returns {Object} The dependency tree
161
321
  * @protected
162
322
  */
163
- _buildDependencyTree(includeTransitive) {
323
+ _buildDependencyTree(includeTransitive, opts = {}) {
164
324
  this._version();
165
- let manifestDir = path.dirname(this.#manifest.manifestPath);
166
- this.#createLockFile(manifestDir);
167
- let output = this.#executeListCmd(includeTransitive, manifestDir);
325
+ const manifestDir = path.dirname(this.#manifest.manifestPath);
326
+ const cmdDir = this._findLockFileDir(manifestDir, opts) || manifestDir;
327
+ this._createLockFile(cmdDir);
328
+ this._loadHashes(cmdDir);
329
+ let output = this.#executeListCmd(includeTransitive, cmdDir);
168
330
  output = this._parseDepTreeOutput(output);
169
331
  return JSON.parse(output);
170
332
  }
@@ -175,15 +337,38 @@ export default class Base_javascript {
175
337
  * @private
176
338
  */
177
339
  #getSBOM(opts = {}) {
178
- const depsObject = this._buildDependencyTree(true);
340
+ const depsObject = this._buildDependencyTree(true, opts);
179
341
  let mainComponent = toPurl(purlType, this.#manifest.name, this.#manifest.version);
180
342
  const license = this.readLicenseFromManifest(this.#manifest.manifestPath);
181
343
  let sbom = new Sbom();
182
344
  sbom.addRoot(mainComponent, license);
183
345
  this._addDependenciesToSbom(sbom, depsObject);
346
+ this.#ensurePeerAndOptionalDeps(sbom);
184
347
  sbom.filterIgnoredDeps(this.#manifest.ignored);
185
348
  return sbom.getAsJsonString(opts);
186
349
  }
350
+ /**
351
+ * Ensures peer and optional dependencies declared in the manifest are
352
+ * present in the SBOM, even when the package manager does not resolve them
353
+ * (e.g. yarn does not include peer deps in its dependency listing).
354
+ * @param {Sbom} sbom - The SBOM to supplement
355
+ * @private
356
+ */
357
+ #ensurePeerAndOptionalDeps(sbom) {
358
+ const rootPurl = toPurl(purlType, this.#manifest.name, this.#manifest.version);
359
+ const depSources = [this.#manifest.peerDependencies, this.#manifest.optionalDependencies];
360
+ for (const source of depSources) {
361
+ for (const [name, version] of Object.entries(source)) {
362
+ // Build the purl prefix for exact matching (e.g. "pkg:npm/minimist@"
363
+ // or "pkg:npm/%40hapi/joi@") to avoid substring false positives
364
+ const probe = toPurl(purlType, name, version);
365
+ const purlPrefix = probe.toString().replace(/@[^@]*$/, '@');
366
+ if (!sbom.checkDependsOnByPurlPrefix(rootPurl, purlPrefix)) {
367
+ sbom.addDependency(rootPurl, probe);
368
+ }
369
+ }
370
+ }
371
+ }
187
372
  /**
188
373
  * Recursively builds the Sbom from the JSON that npm listing returns
189
374
  * @param {Sbom} sbom - The SBOM object to add dependencies to
@@ -191,13 +376,16 @@ export default class Base_javascript {
191
376
  * @protected
192
377
  */
193
378
  _addDependenciesToSbom(sbom, depTree) {
194
- const dependencies = depTree["dependencies"] || {};
379
+ const dependencies = {
380
+ ...depTree["dependencies"],
381
+ ...depTree["optionalDependencies"],
382
+ };
195
383
  Object.entries(dependencies)
196
384
  .forEach(entry => {
197
385
  const [name, artifact] = entry;
198
386
  const target = toPurl(purlType, name, artifact.version);
199
387
  const rootPurl = toPurl(purlType, this.#manifest.name, this.#manifest.version);
200
- sbom.addDependency(rootPurl, target);
388
+ sbom.addDependency(rootPurl, target, undefined, this._hashesFor(name, artifact.version));
201
389
  this.#addDependenciesOf(sbom, target, artifact);
202
390
  });
203
391
  }
@@ -215,7 +403,7 @@ export default class Base_javascript {
215
403
  const [name, depArtifact] = entry;
216
404
  if (depArtifact.version !== undefined) {
217
405
  const target = toPurl(purlType, name, depArtifact.version);
218
- sbom.addDependency(from, target);
406
+ sbom.addDependency(from, target, undefined, this._hashesFor(name, depArtifact.version));
219
407
  this.#addDependenciesOf(sbom, target, depArtifact);
220
408
  }
221
409
  });
@@ -227,7 +415,7 @@ export default class Base_javascript {
227
415
  * @private
228
416
  */
229
417
  #getDirectDependencySbom(opts = {}) {
230
- const depTree = this._buildDependencyTree(false);
418
+ const depTree = this._buildDependencyTree(false, opts);
231
419
  let mainComponent = toPurl(purlType, this.#manifest.name, this.#manifest.version);
232
420
  const license = this.readLicenseFromManifest(this.#manifest.manifestPath);
233
421
  let sbom = new Sbom();
@@ -239,8 +427,10 @@ export default class Base_javascript {
239
427
  .sort();
240
428
  for (const key of sortedDepsKeys) {
241
429
  const rootPurl = toPurlFromString(sbom.getRoot().purl);
242
- sbom.addDependency(rootPurl, rootDeps.get(key));
430
+ const targetPurl = rootDeps.get(key);
431
+ sbom.addDependency(rootPurl, targetPurl, undefined, this._hashesForPurl(targetPurl));
243
432
  }
433
+ this.#ensurePeerAndOptionalDeps(sbom);
244
434
  sbom.filterIgnoredDeps(this.#manifest.ignored);
245
435
  return sbom.getAsJsonString(opts);
246
436
  }
@@ -251,10 +441,14 @@ export default class Base_javascript {
251
441
  * @protected
252
442
  */
253
443
  _getRootDependencies(depTree) {
254
- if (!depTree.dependencies) {
444
+ const allDeps = {
445
+ ...depTree.dependencies,
446
+ ...depTree.optionalDependencies,
447
+ };
448
+ if (Object.keys(allDeps).length === 0) {
255
449
  return new Map();
256
450
  }
257
- return new Map(Object.entries(depTree.dependencies).map(([key, value]) => [key, toPurl(purlType, key, value.version)]));
451
+ return new Map(Object.entries(allDeps).map(([key, value]) => [key, toPurl(purlType, key, value.version)]));
258
452
  }
259
453
  /**
260
454
  * Executes the list command to get dependencies
@@ -265,7 +459,7 @@ export default class Base_javascript {
265
459
  */
266
460
  #executeListCmd(includeTransitive, manifestDir) {
267
461
  const listArgs = this._listCmdArgs(includeTransitive, manifestDir);
268
- return this.#invokeCommand(listArgs);
462
+ return this.#invokeCommand(listArgs, { cwd: manifestDir });
269
463
  }
270
464
  /**
271
465
  * Gets the version of the package manager
@@ -278,19 +472,17 @@ export default class Base_javascript {
278
472
  /**
279
473
  * Creates or updates the lock file for the package manager
280
474
  * @param {string} manifestDir - Directory containing the manifest file
281
- * @private
475
+ * @protected
282
476
  */
283
- #createLockFile(manifestDir) {
477
+ _createLockFile(manifestDir) {
284
478
  const originalDir = process.cwd();
285
479
  const isWindows = os.platform() === 'win32';
286
480
  if (isWindows) {
287
- // On Windows, --prefix flag doesn't work as expected
288
- // Instead of installing from the prefix folder, it installs from current working directory
289
481
  process.chdir(manifestDir);
290
482
  }
291
483
  try {
292
484
  const args = this._updateLockFileCmdArgs(manifestDir);
293
- this.#invokeCommand(args);
485
+ this.#invokeCommand(args, { cwd: manifestDir });
294
486
  }
295
487
  finally {
296
488
  if (isWindows) {
@@ -0,0 +1,158 @@
1
+ /** @typedef {{name: string, version: string, children: string[], hashes?: Array<{alg: string, content: string}>}} GraphEntry */
2
+ /** @typedef {{name: string, version: string, dependencies: DepTreeEntry[]}} DepTreeEntry */
3
+ /** @typedef {{directDeps: string[], graph: Map<string, GraphEntry>}} DependencyData */
4
+ /** @typedef {{ecosystem: string, content: string, contentType: string}} Provided */
5
+ export default class Base_pyproject {
6
+ /**
7
+ * @param {string} manifestName
8
+ * @returns {boolean}
9
+ */
10
+ isSupported(manifestName: string): boolean;
11
+ /**
12
+ * @param {string} manifestDir
13
+ * @param {Object} [opts={}]
14
+ * @returns {boolean}
15
+ */
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;
36
+ /**
37
+ * Read project license from pyproject.toml, with fallback to LICENSE file.
38
+ * @param {string} manifestPath
39
+ * @returns {string|null}
40
+ */
41
+ readLicenseFromManifest(manifestPath: string): string | null;
42
+ /**
43
+ * @param {string} manifest - path to pyproject.toml
44
+ * @param {Object} [opts={}]
45
+ * @returns {Promise<Provided>}
46
+ */
47
+ provideStack(manifest: string, opts?: Object): Promise<Provided>;
48
+ /**
49
+ * @param {string} manifest - path to pyproject.toml
50
+ * @param {Object} [opts={}]
51
+ * @returns {Promise<Provided>}
52
+ */
53
+ provideComponent(manifest: string, opts?: Object): Promise<Provided>;
54
+ /**
55
+ * @returns {string}
56
+ * @protected
57
+ */
58
+ protected _lockFileName(): string;
59
+ /**
60
+ * @returns {string}
61
+ * @protected
62
+ */
63
+ protected _cmdName(): string;
64
+ /**
65
+ * Returns the package manager name (e.g. pip, poetry, uv)
66
+ * @returns {string}
67
+ */
68
+ packageManagerName(): string;
69
+ /**
70
+ * Resolve dependencies using the tool-specific command and parser.
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)
75
+ * @param {object} parsed - parsed pyproject.toml
76
+ * @param {Object} opts
77
+ * @returns {Promise<DependencyData>}
78
+ * @protected
79
+ */
80
+ protected _getDependencyData(manifestDir: string, workspaceDir: string, parsed: object, opts: Object): Promise<DependencyData>;
81
+ /**
82
+ * Canonicalize a Python package name per PEP 503.
83
+ * @param {string} name
84
+ * @returns {string}
85
+ * @protected
86
+ */
87
+ protected _canonicalize(name: string): string;
88
+ /**
89
+ * Get the project name from pyproject.toml.
90
+ * @param {object} parsed
91
+ * @returns {string|null}
92
+ * @protected
93
+ */
94
+ protected _getProjectName(parsed: object): string | null;
95
+ /**
96
+ * Get the project version from pyproject.toml.
97
+ * @param {object} parsed
98
+ * @returns {string|null}
99
+ * @protected
100
+ */
101
+ protected _getProjectVersion(parsed: object): string | null;
102
+ /**
103
+ * Scan raw pyproject.toml text for dependencies with ignore markers.
104
+ * @param {string} manifestPath
105
+ * @returns {Set<string>}
106
+ * @protected
107
+ */
108
+ protected _getIgnoredDeps(manifestPath: string): Set<string>;
109
+ /**
110
+ * Compute the set of graph nodes reachable from direct deps, excluding ignored.
111
+ * @param {Map<string, GraphEntry>} graph
112
+ * @param {string[]} directDeps
113
+ * @param {Set<string>} ignoredDeps
114
+ * @returns {Set<string>}
115
+ * @protected
116
+ */
117
+ protected _reachableNodes(graph: Map<string, GraphEntry>, directDeps: string[], ignoredDeps: Set<string>): Set<string>;
118
+ /**
119
+ * @param {string} name
120
+ * @param {string} version
121
+ * @returns {PackageURL}
122
+ * @protected
123
+ */
124
+ protected _toPurl(name: string, version: string): PackageURL;
125
+ /**
126
+ * Create SBOM json string for a pyproject.toml project.
127
+ * @param {string} manifest - path to pyproject.toml
128
+ * @param {Object} opts
129
+ * @param {boolean} includeTransitive
130
+ * @returns {Promise<string>}
131
+ * @private
132
+ */
133
+ private _createSbom;
134
+ }
135
+ export type GraphEntry = {
136
+ name: string;
137
+ version: string;
138
+ children: string[];
139
+ hashes?: Array<{
140
+ alg: string;
141
+ content: string;
142
+ }>;
143
+ };
144
+ export type DepTreeEntry = {
145
+ name: string;
146
+ version: string;
147
+ dependencies: DepTreeEntry[];
148
+ };
149
+ export type DependencyData = {
150
+ directDeps: string[];
151
+ graph: Map<string, GraphEntry>;
152
+ };
153
+ export type Provided = {
154
+ ecosystem: string;
155
+ content: string;
156
+ contentType: string;
157
+ };
158
+ import { PackageURL } from 'packageurl-js';