@trustify-da/trustify-da-javascript-client 0.3.0-ea.e12bc82 → 0.3.0-ea.e258fba

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 (97) hide show
  1. package/README.md +367 -13
  2. package/dist/package.json +48 -28
  3. package/dist/src/analysis.d.ts +28 -5
  4. package/dist/src/analysis.js +99 -89
  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 +346 -9
  8. package/dist/src/cyclone_dx_sbom.d.ts +30 -3
  9. package/dist/src/cyclone_dx_sbom.js +95 -9
  10. package/dist/src/index.d.ts +202 -12
  11. package/dist/src/index.js +365 -30
  12. package/dist/src/license/index.d.ts +28 -0
  13. package/dist/src/license/index.js +103 -0
  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 +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/images.js +15 -1
  22. package/dist/src/oci_image/utils.d.ts +7 -7
  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 +18 -5
  27. package/dist/src/provider.js +33 -5
  28. package/dist/src/providers/base_java.d.ts +68 -15
  29. package/dist/src/providers/base_java.js +82 -61
  30. package/dist/src/providers/base_javascript.d.ts +99 -12
  31. package/dist/src/providers/base_javascript.js +243 -27
  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 +30 -13
  37. package/dist/src/providers/golang_gomodules.js +219 -122
  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 +76 -3
  41. package/dist/src/providers/java_gradle.js +323 -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 +45 -10
  45. package/dist/src/providers/java_maven.js +300 -14
  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 +10 -3
  65. package/dist/src/providers/python_controller.js +122 -63
  66. package/dist/src/providers/python_pip.d.ts +16 -4
  67. package/dist/src/providers/python_pip.js +51 -58
  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.d.ts +6 -0
  75. package/dist/src/providers/requirements_parser.js +24 -0
  76. package/dist/src/providers/rust_cargo.d.ts +56 -0
  77. package/dist/src/providers/rust_cargo.js +682 -0
  78. package/dist/src/providers/tree-sitter-containerfile.wasm +0 -0
  79. package/dist/src/providers/tree-sitter-gomod.wasm +0 -0
  80. package/dist/src/providers/tree-sitter-requirements.wasm +0 -0
  81. package/dist/src/remediate.d.ts +21 -0
  82. package/dist/src/remediate.js +149 -0
  83. package/dist/src/remediation.d.ts +57 -0
  84. package/dist/src/remediation.js +436 -0
  85. package/dist/src/remediation_report.d.ts +40 -0
  86. package/dist/src/remediation_report.js +159 -0
  87. package/dist/src/sbom.d.ts +28 -2
  88. package/dist/src/sbom.js +26 -4
  89. package/dist/src/tools.d.ts +48 -6
  90. package/dist/src/tools.js +138 -2
  91. package/dist/src/updaters/maven_updater.d.ts +26 -0
  92. package/dist/src/updaters/maven_updater.js +322 -0
  93. package/dist/src/updaters/toml_updater.d.ts +33 -0
  94. package/dist/src/updaters/toml_updater.js +244 -0
  95. package/dist/src/workspace.d.ts +70 -0
  96. package/dist/src/workspace.js +256 -0
  97. package/package.json +49 -29
@@ -1,16 +1,60 @@
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
- /** @typedef {import('../provider.js').Provider} Provider */
8
- /** @typedef {import('../provider.js').Provided} Provided */
8
+ /** @typedef {import('../provider').Provider} */
9
+ /** @typedef {import('../provider').Provided} Provided */
9
10
  /**
10
11
  * The ecosystem identifier for JavaScript/npm packages
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
@@ -132,17 +290,43 @@ export default class Base_javascript {
132
290
  contentType: 'application/vnd.cyclonedx+json'
133
291
  };
134
292
  }
293
+ /**
294
+ * Read license from manifest (package.json). Reused by npm, pnpm, yarn.
295
+ * @param {string} manifestPath - path to package.json
296
+ * @returns {string|null}
297
+ */
298
+ readLicenseFromManifest(manifestPath) {
299
+ let manifestLicense;
300
+ try {
301
+ const content = JSON.parse(fs.readFileSync(manifestPath, 'utf-8'));
302
+ if (typeof content.license === 'string') {
303
+ manifestLicense = content.license.trim() || null;
304
+ }
305
+ else if (Array.isArray(content.licenses) && content.licenses.length > 0) {
306
+ const first = content.licenses[0];
307
+ const name = first.type || first.name;
308
+ manifestLicense = (typeof name === 'string' ? name.trim() : null);
309
+ }
310
+ }
311
+ catch {
312
+ manifestLicense = null;
313
+ }
314
+ return getLicense(manifestLicense, manifestPath);
315
+ }
135
316
  /**
136
317
  * Builds the dependency tree for the project
137
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
138
320
  * @returns {Object} The dependency tree
139
321
  * @protected
140
322
  */
141
- _buildDependencyTree(includeTransitive) {
323
+ _buildDependencyTree(includeTransitive, opts = {}) {
142
324
  this._version();
143
- let manifestDir = path.dirname(this.#manifest.manifestPath);
144
- this.#createLockFile(manifestDir);
145
- 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);
146
330
  output = this._parseDepTreeOutput(output);
147
331
  return JSON.parse(output);
148
332
  }
@@ -153,14 +337,38 @@ export default class Base_javascript {
153
337
  * @private
154
338
  */
155
339
  #getSBOM(opts = {}) {
156
- const depsObject = this._buildDependencyTree(true);
340
+ const depsObject = this._buildDependencyTree(true, opts);
157
341
  let mainComponent = toPurl(purlType, this.#manifest.name, this.#manifest.version);
342
+ const license = this.readLicenseFromManifest(this.#manifest.manifestPath);
158
343
  let sbom = new Sbom();
159
- sbom.addRoot(mainComponent);
344
+ sbom.addRoot(mainComponent, license);
160
345
  this._addDependenciesToSbom(sbom, depsObject);
346
+ this.#ensurePeerAndOptionalDeps(sbom);
161
347
  sbom.filterIgnoredDeps(this.#manifest.ignored);
162
348
  return sbom.getAsJsonString(opts);
163
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
+ }
164
372
  /**
165
373
  * Recursively builds the Sbom from the JSON that npm listing returns
166
374
  * @param {Sbom} sbom - The SBOM object to add dependencies to
@@ -168,13 +376,16 @@ export default class Base_javascript {
168
376
  * @protected
169
377
  */
170
378
  _addDependenciesToSbom(sbom, depTree) {
171
- const dependencies = depTree["dependencies"] || {};
379
+ const dependencies = {
380
+ ...depTree["dependencies"],
381
+ ...depTree["optionalDependencies"],
382
+ };
172
383
  Object.entries(dependencies)
173
384
  .forEach(entry => {
174
385
  const [name, artifact] = entry;
175
386
  const target = toPurl(purlType, name, artifact.version);
176
387
  const rootPurl = toPurl(purlType, this.#manifest.name, this.#manifest.version);
177
- sbom.addDependency(rootPurl, target);
388
+ sbom.addDependency(rootPurl, target, undefined, this._hashesFor(name, artifact.version));
178
389
  this.#addDependenciesOf(sbom, target, artifact);
179
390
  });
180
391
  }
@@ -192,7 +403,7 @@ export default class Base_javascript {
192
403
  const [name, depArtifact] = entry;
193
404
  if (depArtifact.version !== undefined) {
194
405
  const target = toPurl(purlType, name, depArtifact.version);
195
- sbom.addDependency(from, target);
406
+ sbom.addDependency(from, target, undefined, this._hashesFor(name, depArtifact.version));
196
407
  this.#addDependenciesOf(sbom, target, depArtifact);
197
408
  }
198
409
  });
@@ -204,10 +415,11 @@ export default class Base_javascript {
204
415
  * @private
205
416
  */
206
417
  #getDirectDependencySbom(opts = {}) {
207
- const depTree = this._buildDependencyTree(false);
418
+ const depTree = this._buildDependencyTree(false, opts);
208
419
  let mainComponent = toPurl(purlType, this.#manifest.name, this.#manifest.version);
420
+ const license = this.readLicenseFromManifest(this.#manifest.manifestPath);
209
421
  let sbom = new Sbom();
210
- sbom.addRoot(mainComponent);
422
+ sbom.addRoot(mainComponent, license);
211
423
  const rootDeps = this._getRootDependencies(depTree);
212
424
  const sortedDepsKeys = Array
213
425
  .from(rootDeps.keys())
@@ -215,8 +427,10 @@ export default class Base_javascript {
215
427
  .sort();
216
428
  for (const key of sortedDepsKeys) {
217
429
  const rootPurl = toPurlFromString(sbom.getRoot().purl);
218
- sbom.addDependency(rootPurl, rootDeps.get(key));
430
+ const targetPurl = rootDeps.get(key);
431
+ sbom.addDependency(rootPurl, targetPurl, undefined, this._hashesForPurl(targetPurl));
219
432
  }
433
+ this.#ensurePeerAndOptionalDeps(sbom);
220
434
  sbom.filterIgnoredDeps(this.#manifest.ignored);
221
435
  return sbom.getAsJsonString(opts);
222
436
  }
@@ -227,10 +441,14 @@ export default class Base_javascript {
227
441
  * @protected
228
442
  */
229
443
  _getRootDependencies(depTree) {
230
- if (!depTree.dependencies) {
444
+ const allDeps = {
445
+ ...depTree.dependencies,
446
+ ...depTree.optionalDependencies,
447
+ };
448
+ if (Object.keys(allDeps).length === 0) {
231
449
  return new Map();
232
450
  }
233
- 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)]));
234
452
  }
235
453
  /**
236
454
  * Executes the list command to get dependencies
@@ -241,7 +459,7 @@ export default class Base_javascript {
241
459
  */
242
460
  #executeListCmd(includeTransitive, manifestDir) {
243
461
  const listArgs = this._listCmdArgs(includeTransitive, manifestDir);
244
- return this.#invokeCommand(listArgs);
462
+ return this.#invokeCommand(listArgs, { cwd: manifestDir });
245
463
  }
246
464
  /**
247
465
  * Gets the version of the package manager
@@ -254,19 +472,17 @@ export default class Base_javascript {
254
472
  /**
255
473
  * Creates or updates the lock file for the package manager
256
474
  * @param {string} manifestDir - Directory containing the manifest file
257
- * @private
475
+ * @protected
258
476
  */
259
- #createLockFile(manifestDir) {
477
+ _createLockFile(manifestDir) {
260
478
  const originalDir = process.cwd();
261
479
  const isWindows = os.platform() === 'win32';
262
480
  if (isWindows) {
263
- // On Windows, --prefix flag doesn't work as expected
264
- // Instead of installing from the prefix folder, it installs from current working directory
265
481
  process.chdir(manifestDir);
266
482
  }
267
483
  try {
268
484
  const args = this._updateLockFileCmdArgs(manifestDir);
269
- this.#invokeCommand(args);
485
+ this.#invokeCommand(args, { cwd: manifestDir });
270
486
  }
271
487
  finally {
272
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';