@trustify-da/trustify-da-javascript-client 0.3.0-ea.a783c26 → 0.3.0-ea.a8c3942
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.
- package/dist/package.json +0 -1
- package/dist/src/cyclone_dx_sbom.d.ts +7 -1
- package/dist/src/cyclone_dx_sbom.js +18 -5
- package/dist/src/index.d.ts +62 -3
- package/dist/src/index.js +68 -4
- package/dist/src/providers/base_java.d.ts +0 -9
- package/dist/src/providers/base_java.js +2 -38
- package/dist/src/providers/base_pyproject.d.ts +5 -1
- package/dist/src/providers/base_pyproject.js +5 -4
- package/dist/src/providers/golang_gomodules.d.ts +9 -0
- package/dist/src/providers/golang_gomodules.js +64 -7
- package/dist/src/providers/java_gradle.d.ts +19 -0
- package/dist/src/providers/java_gradle.js +116 -2
- package/dist/src/providers/java_maven.d.ts +8 -0
- package/dist/src/providers/java_maven.js +93 -1
- package/dist/src/providers/javascript_pnpm.js +6 -2
- package/dist/src/providers/marker_evaluator.d.ts +14 -0
- package/dist/src/providers/marker_evaluator.js +191 -0
- package/dist/src/providers/python_controller.d.ts +5 -1
- package/dist/src/providers/python_controller.js +1 -1
- package/dist/src/providers/python_pip.d.ts +4 -0
- package/dist/src/providers/python_pip.js +4 -4
- package/dist/src/providers/python_pip_pyproject.js +3 -1
- package/dist/src/providers/python_poetry.d.ts +35 -3
- package/dist/src/providers/python_poetry.js +73 -10
- package/dist/src/providers/python_uv.d.ts +28 -0
- package/dist/src/providers/python_uv.js +78 -0
- package/dist/src/sbom.d.ts +7 -1
- package/dist/src/sbom.js +4 -2
- package/dist/src/tools.d.ts +26 -0
- package/dist/src/tools.js +58 -0
- package/dist/src/workspace.d.ts +9 -0
- package/dist/src/workspace.js +1 -1
- package/package.json +1 -2
package/dist/package.json
CHANGED
|
@@ -18,9 +18,14 @@ export default class CycloneDxSbom {
|
|
|
18
18
|
* Adds a dependency relationship between two components in the SBOM
|
|
19
19
|
* @param {PackageURL} sourceRef - The source component (parent)
|
|
20
20
|
* @param {PackageURL} targetRef - The target component (dependency)
|
|
21
|
+
* @param {string} [scope] - Scope of the dependency
|
|
22
|
+
* @param {Array<{alg: string, content: string}>} [targetHashes] - Optional hashes for the target component
|
|
21
23
|
* @return {CycloneDxSbom} The updated SBOM
|
|
22
24
|
*/
|
|
23
|
-
addDependency(sourceRef: PackageURL, targetRef: PackageURL, scope
|
|
25
|
+
addDependency(sourceRef: PackageURL, targetRef: PackageURL, scope?: string, targetHashes?: Array<{
|
|
26
|
+
alg: string;
|
|
27
|
+
content: string;
|
|
28
|
+
}>): CycloneDxSbom;
|
|
24
29
|
/** @param {{}} opts - various options, settings and configuration of application.
|
|
25
30
|
* @return String CycloneDx Sbom json object in a string format
|
|
26
31
|
*/
|
|
@@ -50,6 +55,7 @@ export default class CycloneDxSbom {
|
|
|
50
55
|
version: any;
|
|
51
56
|
scope: any;
|
|
52
57
|
licenses?: any;
|
|
58
|
+
hashes?: any;
|
|
53
59
|
};
|
|
54
60
|
/**
|
|
55
61
|
* This method gets an array of dependencies to be ignored, and remove all of them from CycloneDx Sbom
|
|
@@ -6,10 +6,11 @@ import { PackageURL } from "packageurl-js";
|
|
|
6
6
|
* @param type type of package - application or library
|
|
7
7
|
* @param scope scope of the component - runtime or compile
|
|
8
8
|
* @param licenses optional license string or array of licenses for the component
|
|
9
|
-
* @
|
|
9
|
+
* @param hashes optional array of hash objects for the component, e.g. [{alg: "SHA-256", content: "..."}]
|
|
10
|
+
* @return {{"bom-ref": string, name, purl: string, type, version, scope, licenses?, hashes?}}
|
|
10
11
|
* @private
|
|
11
12
|
*/
|
|
12
|
-
function getComponent(component, type, scope, licenses) {
|
|
13
|
+
function getComponent(component, type, scope, licenses, hashes) {
|
|
13
14
|
let componentObject;
|
|
14
15
|
if (component instanceof PackageURL) {
|
|
15
16
|
if (component.namespace) {
|
|
@@ -47,6 +48,10 @@ function getComponent(component, type, scope, licenses) {
|
|
|
47
48
|
return lic;
|
|
48
49
|
});
|
|
49
50
|
}
|
|
51
|
+
// Add hashes if provided (CycloneDX 1.4 format).
|
|
52
|
+
if (hashes && hashes.length > 0) {
|
|
53
|
+
componentObject.hashes = hashes;
|
|
54
|
+
}
|
|
50
55
|
return componentObject;
|
|
51
56
|
}
|
|
52
57
|
function createDependency(dependency) {
|
|
@@ -86,16 +91,24 @@ export default class CycloneDxSbom {
|
|
|
86
91
|
* Adds a dependency relationship between two components in the SBOM
|
|
87
92
|
* @param {PackageURL} sourceRef - The source component (parent)
|
|
88
93
|
* @param {PackageURL} targetRef - The target component (dependency)
|
|
94
|
+
* @param {string} [scope] - Scope of the dependency
|
|
95
|
+
* @param {Array<{alg: string, content: string}>} [targetHashes] - Optional hashes for the target component
|
|
89
96
|
* @return {CycloneDxSbom} The updated SBOM
|
|
90
97
|
*/
|
|
91
|
-
addDependency(sourceRef, targetRef, scope) {
|
|
98
|
+
addDependency(sourceRef, targetRef, scope, targetHashes) {
|
|
92
99
|
const sourcePurl = sourceRef.toString();
|
|
93
100
|
const targetPurl = targetRef.toString();
|
|
94
101
|
// Ensure both components exist in the components list
|
|
95
102
|
[sourceRef, targetRef].forEach((ref, index) => {
|
|
96
103
|
const purl = index === 0 ? sourcePurl : targetPurl;
|
|
97
|
-
|
|
98
|
-
|
|
104
|
+
const existingIndex = this.getComponentIndex(purl);
|
|
105
|
+
if (existingIndex < 0) {
|
|
106
|
+
const hashes = index === 1 ? targetHashes : undefined;
|
|
107
|
+
this.components.push(getComponent(ref, "library", scope, undefined, hashes));
|
|
108
|
+
}
|
|
109
|
+
else if (index === 1 && targetHashes && targetHashes.length > 0 && !this.components[existingIndex].hashes) {
|
|
110
|
+
// Update hashes if the component was first seen without them (e.g. as a source)
|
|
111
|
+
this.components[existingIndex].hashes = targetHashes;
|
|
99
112
|
}
|
|
100
113
|
});
|
|
101
114
|
// Ensure source dependency exists
|
package/dist/src/index.d.ts
CHANGED
|
@@ -80,7 +80,7 @@ export type Options = {
|
|
|
80
80
|
};
|
|
81
81
|
export type BatchAnalysisMetadata = {
|
|
82
82
|
workspaceRoot: string;
|
|
83
|
-
ecosystem: "javascript" | "cargo" | "unknown";
|
|
83
|
+
ecosystem: "javascript" | "cargo" | "pyproject" | "unknown";
|
|
84
84
|
total: number;
|
|
85
85
|
successful: number;
|
|
86
86
|
failed: number;
|
|
@@ -136,19 +136,74 @@ declare function stackAnalysis(manifest: string, html: false, opts?: Options | u
|
|
|
136
136
|
* or backend request failed
|
|
137
137
|
*/
|
|
138
138
|
declare function stackAnalysis(manifest: string, html?: boolean | undefined, opts?: Options | undefined): Promise<string | import("@trustify-da/trustify-da-api-model/model/v5/AnalysisReport").AnalysisReport>;
|
|
139
|
+
/**
|
|
140
|
+
* @overload
|
|
141
|
+
* @param {string} workspaceRoot
|
|
142
|
+
* @param {true} html
|
|
143
|
+
* @param {Options & { batchMetadata: true }} opts
|
|
144
|
+
* @returns {Promise<{ analysis: string, metadata: BatchAnalysisMetadata }>}
|
|
145
|
+
* @throws {Error}
|
|
146
|
+
*/
|
|
147
|
+
declare function stackAnalysisBatch(workspaceRoot: string, html: true, opts: Options & {
|
|
148
|
+
batchMetadata: true;
|
|
149
|
+
}): Promise<{
|
|
150
|
+
analysis: string;
|
|
151
|
+
metadata: BatchAnalysisMetadata;
|
|
152
|
+
}>;
|
|
153
|
+
/**
|
|
154
|
+
* @overload
|
|
155
|
+
* @param {string} workspaceRoot
|
|
156
|
+
* @param {true} html
|
|
157
|
+
* @param {Options & { batchMetadata?: false }} [opts={}]
|
|
158
|
+
* @returns {Promise<string>}
|
|
159
|
+
* @throws {Error}
|
|
160
|
+
*/
|
|
161
|
+
declare function stackAnalysisBatch(workspaceRoot: string, html: true, opts?: (Options & {
|
|
162
|
+
batchMetadata?: false;
|
|
163
|
+
}) | undefined): Promise<string>;
|
|
164
|
+
/**
|
|
165
|
+
* @overload
|
|
166
|
+
* @param {string} workspaceRoot
|
|
167
|
+
* @param {false} html
|
|
168
|
+
* @param {Options & { batchMetadata: true }} opts
|
|
169
|
+
* @returns {Promise<{ analysis: Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>, metadata: BatchAnalysisMetadata }>}
|
|
170
|
+
* @throws {Error}
|
|
171
|
+
*/
|
|
172
|
+
declare function stackAnalysisBatch(workspaceRoot: string, html: false, opts: Options & {
|
|
173
|
+
batchMetadata: true;
|
|
174
|
+
}): Promise<{
|
|
175
|
+
analysis: {
|
|
176
|
+
[x: string]: import("@trustify-da/trustify-da-api-model/model/v5/AnalysisReport").AnalysisReport;
|
|
177
|
+
};
|
|
178
|
+
metadata: BatchAnalysisMetadata;
|
|
179
|
+
}>;
|
|
180
|
+
/**
|
|
181
|
+
* @overload
|
|
182
|
+
* @param {string} workspaceRoot
|
|
183
|
+
* @param {false} html
|
|
184
|
+
* @param {Options & { batchMetadata?: false }} [opts={}]
|
|
185
|
+
* @returns {Promise<Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>>}
|
|
186
|
+
* @throws {Error}
|
|
187
|
+
*/
|
|
188
|
+
declare function stackAnalysisBatch(workspaceRoot: string, html: false, opts?: (Options & {
|
|
189
|
+
batchMetadata?: false;
|
|
190
|
+
}) | undefined): Promise<{
|
|
191
|
+
[x: string]: import("@trustify-da/trustify-da-api-model/model/v5/AnalysisReport").AnalysisReport;
|
|
192
|
+
}>;
|
|
139
193
|
/**
|
|
140
194
|
* Get stack analysis for all workspace packages/crates (batch).
|
|
141
195
|
* Detects ecosystem from workspace root: Cargo (Cargo.toml + Cargo.lock) or JS/TS (package.json + lock file).
|
|
142
196
|
* SBOMs are generated in parallel (see `batchConcurrency`) unless `continueOnError: false` (fail-fast sequential).
|
|
143
197
|
* With `opts.batchMetadata` / `TRUSTIFY_DA_BATCH_METADATA`, returns `{ analysis, metadata }` including validation and SBOM errors.
|
|
144
198
|
*
|
|
199
|
+
* @overload
|
|
145
200
|
* @param {string} workspaceRoot - Path to workspace root (containing lock file and workspace config)
|
|
146
201
|
* @param {boolean} [html=false] - true returns HTML, false returns JSON report
|
|
147
202
|
* @param {Options} [opts={}] - `batchConcurrency`, discovery ignores, `continueOnError` (default true), `batchMetadata` (default false)
|
|
148
203
|
* @returns {Promise<string|Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>|{ analysis: string|Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>, metadata: BatchAnalysisMetadata }>}
|
|
149
204
|
* @throws {Error} if workspace root invalid, no manifests found, no packages pass validation, no SBOMs produced, or backend request failed. When `opts.batchMetadata` is set, `error.batchMetadata` may be set on thrown errors.
|
|
150
205
|
*/
|
|
151
|
-
declare function stackAnalysisBatch(workspaceRoot: string, html?: boolean, opts?: Options): Promise<string | {
|
|
206
|
+
declare function stackAnalysisBatch(workspaceRoot: string, html?: boolean | undefined, opts?: Options | undefined): Promise<string | {
|
|
152
207
|
[x: string]: import("@trustify-da/trustify-da-api-model/model/v5/AnalysisReport").AnalysisReport;
|
|
153
208
|
} | {
|
|
154
209
|
analysis: string | {
|
|
@@ -196,6 +251,10 @@ declare function imageAnalysis(imageRefs: Array<string>, html?: boolean | undefi
|
|
|
196
251
|
* @throws {Error} if the backend request failed.
|
|
197
252
|
*/
|
|
198
253
|
declare function validateToken(opts?: Options): Promise<object>;
|
|
254
|
+
import { discoverMavenModules } from './providers/java_maven.js';
|
|
255
|
+
import { discoverGradleSubprojects } from './providers/java_gradle.js';
|
|
256
|
+
import { discoverGoWorkspaceModules } from './providers/golang_gomodules.js';
|
|
257
|
+
import { discoverUvWorkspaceMembers } from './providers/python_uv.js';
|
|
199
258
|
import { discoverWorkspacePackages } from './workspace.js';
|
|
200
259
|
import { discoverWorkspaceCrates } from './workspace.js';
|
|
201
260
|
import { validatePackageJson } from './workspace.js';
|
|
@@ -203,5 +262,5 @@ import { resolveWorkspaceDiscoveryIgnore } from './workspace.js';
|
|
|
203
262
|
import { filterManifestPathsByDiscoveryIgnore } from './workspace.js';
|
|
204
263
|
import { resolveContinueOnError } from './batch_opts.js';
|
|
205
264
|
import { resolveBatchMetadata } from './batch_opts.js';
|
|
206
|
-
export { discoverWorkspacePackages, discoverWorkspaceCrates, validatePackageJson, resolveWorkspaceDiscoveryIgnore, filterManifestPathsByDiscoveryIgnore, resolveContinueOnError, resolveBatchMetadata };
|
|
265
|
+
export { discoverMavenModules, discoverGradleSubprojects, discoverGoWorkspaceModules, discoverUvWorkspaceMembers, discoverWorkspacePackages, discoverWorkspaceCrates, validatePackageJson, resolveWorkspaceDiscoveryIgnore, filterManifestPathsByDiscoveryIgnore, resolveContinueOnError, resolveBatchMetadata };
|
|
207
266
|
export { getProjectLicense, findLicenseFilePath, identifyLicense, getLicenseDetails, licensesFromReport, normalizeLicensesResponse, runLicenseCheck, getCompatibility } from "./license/index.js";
|
package/dist/src/index.js
CHANGED
|
@@ -6,6 +6,10 @@ import analysis from './analysis.js';
|
|
|
6
6
|
import fs from 'node:fs';
|
|
7
7
|
import { getCustom } from "./tools.js";
|
|
8
8
|
import { resolveBatchMetadata, resolveContinueOnError } from './batch_opts.js';
|
|
9
|
+
import { discoverMavenModules } from './providers/java_maven.js';
|
|
10
|
+
import { discoverGradleSubprojects } from './providers/java_gradle.js';
|
|
11
|
+
import { discoverGoWorkspaceModules } from './providers/golang_gomodules.js';
|
|
12
|
+
import { discoverUvWorkspaceMembers } from './providers/python_uv.js';
|
|
9
13
|
import { discoverWorkspaceCrates, discoverWorkspacePackages, filterManifestPathsByDiscoveryIgnore, resolveWorkspaceDiscoveryIgnore, validatePackageJson, } from './workspace.js';
|
|
10
14
|
import.meta.dirname;
|
|
11
15
|
import * as url from 'url';
|
|
@@ -13,7 +17,7 @@ export { parseImageRef } from "./oci_image/utils.js";
|
|
|
13
17
|
export { ImageRef } from "./oci_image/images.js";
|
|
14
18
|
export { getProjectLicense, findLicenseFilePath, identifyLicense, getLicenseDetails, licensesFromReport, normalizeLicensesResponse, runLicenseCheck, getCompatibility } from "./license/index.js";
|
|
15
19
|
export default { componentAnalysis, stackAnalysis, stackAnalysisBatch, imageAnalysis, validateToken, generateSbom };
|
|
16
|
-
export { discoverWorkspacePackages, discoverWorkspaceCrates, validatePackageJson, resolveWorkspaceDiscoveryIgnore, filterManifestPathsByDiscoveryIgnore, resolveContinueOnError, resolveBatchMetadata, };
|
|
20
|
+
export { discoverMavenModules, discoverGradleSubprojects, discoverGoWorkspaceModules, discoverUvWorkspaceMembers, discoverWorkspacePackages, discoverWorkspaceCrates, validatePackageJson, resolveWorkspaceDiscoveryIgnore, filterManifestPathsByDiscoveryIgnore, resolveContinueOnError, resolveBatchMetadata, };
|
|
17
21
|
/**
|
|
18
22
|
* @typedef {{
|
|
19
23
|
* TRUSTIFY_DA_CARGO_PATH?: string | undefined,
|
|
@@ -64,7 +68,7 @@ export { discoverWorkspacePackages, discoverWorkspaceCrates, validatePackageJson
|
|
|
64
68
|
/**
|
|
65
69
|
* @typedef {{
|
|
66
70
|
* workspaceRoot: string,
|
|
67
|
-
* ecosystem: 'javascript' | 'cargo' | 'unknown',
|
|
71
|
+
* ecosystem: 'javascript' | 'cargo' | 'pyproject' | 'unknown',
|
|
68
72
|
* total: number,
|
|
69
73
|
* successful: number,
|
|
70
74
|
* failed: number,
|
|
@@ -279,16 +283,43 @@ async function generateOneSbom(manifestPath, workspaceOpts) {
|
|
|
279
283
|
*
|
|
280
284
|
* @param {string} root - Resolved workspace root
|
|
281
285
|
* @param {Options} opts
|
|
282
|
-
* @returns {Promise<{ ecosystem: 'javascript' | 'cargo' | 'unknown', manifestPaths: string[] }>}
|
|
286
|
+
* @returns {Promise<{ ecosystem: 'javascript' | 'cargo' | 'maven' | 'gradle' | 'gomodules' | 'pyproject' | 'unknown', manifestPaths: string[] }>}
|
|
283
287
|
* @private
|
|
284
288
|
*/
|
|
285
289
|
async function detectWorkspaceManifests(root, opts) {
|
|
286
290
|
const cargoToml = path.join(root, 'Cargo.toml');
|
|
287
291
|
const cargoLock = path.join(root, 'Cargo.lock');
|
|
288
292
|
const packageJson = path.join(root, 'package.json');
|
|
293
|
+
const pomXml = path.join(root, 'pom.xml');
|
|
289
294
|
if (fs.existsSync(cargoToml) && fs.existsSync(cargoLock)) {
|
|
290
295
|
return { ecosystem: 'cargo', manifestPaths: await discoverWorkspaceCrates(root, opts) };
|
|
291
296
|
}
|
|
297
|
+
if (fs.existsSync(pomXml)) {
|
|
298
|
+
const manifestPaths = await discoverMavenModules(root, opts);
|
|
299
|
+
if (manifestPaths.length > 0) {
|
|
300
|
+
return { ecosystem: 'maven', manifestPaths };
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
const hasGradleSettings = fs.existsSync(path.join(root, 'settings.gradle'))
|
|
304
|
+
|| fs.existsSync(path.join(root, 'settings.gradle.kts'));
|
|
305
|
+
if (hasGradleSettings) {
|
|
306
|
+
const manifestPaths = await discoverGradleSubprojects(root, opts);
|
|
307
|
+
if (manifestPaths.length > 0) {
|
|
308
|
+
return { ecosystem: 'gradle', manifestPaths };
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
if (fs.existsSync(path.join(root, 'go.work'))) {
|
|
312
|
+
const manifestPaths = await discoverGoWorkspaceModules(root, opts);
|
|
313
|
+
if (manifestPaths.length > 0) {
|
|
314
|
+
return { ecosystem: 'gomodules', manifestPaths };
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
if (fs.existsSync(path.join(root, 'pyproject.toml')) && fs.existsSync(path.join(root, 'uv.lock'))) {
|
|
318
|
+
const manifestPaths = await discoverUvWorkspaceMembers(root, opts);
|
|
319
|
+
if (manifestPaths.length > 0) {
|
|
320
|
+
return { ecosystem: 'pyproject', manifestPaths };
|
|
321
|
+
}
|
|
322
|
+
}
|
|
292
323
|
const hasJsLock = fs.existsSync(path.join(root, 'pnpm-lock.yaml'))
|
|
293
324
|
|| fs.existsSync(path.join(root, 'yarn.lock'))
|
|
294
325
|
|| fs.existsSync(path.join(root, 'package-lock.json'));
|
|
@@ -398,12 +429,45 @@ function batchError(message, wantMetadata, metadata) {
|
|
|
398
429
|
}
|
|
399
430
|
return err;
|
|
400
431
|
}
|
|
432
|
+
/**
|
|
433
|
+
* @overload
|
|
434
|
+
* @param {string} workspaceRoot
|
|
435
|
+
* @param {true} html
|
|
436
|
+
* @param {Options & { batchMetadata: true }} opts
|
|
437
|
+
* @returns {Promise<{ analysis: string, metadata: BatchAnalysisMetadata }>}
|
|
438
|
+
* @throws {Error}
|
|
439
|
+
*/
|
|
440
|
+
/**
|
|
441
|
+
* @overload
|
|
442
|
+
* @param {string} workspaceRoot
|
|
443
|
+
* @param {true} html
|
|
444
|
+
* @param {Options & { batchMetadata?: false }} [opts={}]
|
|
445
|
+
* @returns {Promise<string>}
|
|
446
|
+
* @throws {Error}
|
|
447
|
+
*/
|
|
448
|
+
/**
|
|
449
|
+
* @overload
|
|
450
|
+
* @param {string} workspaceRoot
|
|
451
|
+
* @param {false} html
|
|
452
|
+
* @param {Options & { batchMetadata: true }} opts
|
|
453
|
+
* @returns {Promise<{ analysis: Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>, metadata: BatchAnalysisMetadata }>}
|
|
454
|
+
* @throws {Error}
|
|
455
|
+
*/
|
|
456
|
+
/**
|
|
457
|
+
* @overload
|
|
458
|
+
* @param {string} workspaceRoot
|
|
459
|
+
* @param {false} html
|
|
460
|
+
* @param {Options & { batchMetadata?: false }} [opts={}]
|
|
461
|
+
* @returns {Promise<Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>>}
|
|
462
|
+
* @throws {Error}
|
|
463
|
+
*/
|
|
401
464
|
/**
|
|
402
465
|
* Get stack analysis for all workspace packages/crates (batch).
|
|
403
466
|
* Detects ecosystem from workspace root: Cargo (Cargo.toml + Cargo.lock) or JS/TS (package.json + lock file).
|
|
404
467
|
* SBOMs are generated in parallel (see `batchConcurrency`) unless `continueOnError: false` (fail-fast sequential).
|
|
405
468
|
* With `opts.batchMetadata` / `TRUSTIFY_DA_BATCH_METADATA`, returns `{ analysis, metadata }` including validation and SBOM errors.
|
|
406
469
|
*
|
|
470
|
+
* @overload
|
|
407
471
|
* @param {string} workspaceRoot - Path to workspace root (containing lock file and workspace config)
|
|
408
472
|
* @param {boolean} [html=false] - true returns HTML, false returns JSON report
|
|
409
473
|
* @param {Options} [opts={}] - `batchConcurrency`, discovery ignores, `continueOnError` (default true), `batchMetadata` (default false)
|
|
@@ -434,7 +498,7 @@ async function stackAnalysisBatch(workspaceRoot, html = false, opts = {}) {
|
|
|
434
498
|
}
|
|
435
499
|
}
|
|
436
500
|
if (manifestPaths.length === 0) {
|
|
437
|
-
throw new Error(`No workspace manifests found at ${root}. Ensure Cargo.toml+Cargo.lock or package.json+lock file
|
|
501
|
+
throw new Error(`No workspace manifests found at ${root}. Ensure a supported workspace root exists (Cargo.toml+Cargo.lock, pom.xml, build.gradle, go.work, pyproject.toml+uv.lock, or package.json+lock file).`);
|
|
438
502
|
}
|
|
439
503
|
const workspaceOpts = { ...opts, TRUSTIFY_DA_WORKSPACE_DIR: root };
|
|
440
504
|
const concurrency = resolveBatchConcurrency(opts);
|
|
@@ -57,15 +57,6 @@ export default class Base_Java {
|
|
|
57
57
|
* @returns string
|
|
58
58
|
*/
|
|
59
59
|
selectToolBinary(manifestPath: string, opts: {}): string | null;
|
|
60
|
-
/**
|
|
61
|
-
*
|
|
62
|
-
* @param {string} startingManifest - the path of the manifest from which to start searching for the wrapper
|
|
63
|
-
* @param {string} repoRoot - the root of the repository at which point to stop searching for mvnw, derived via git if unset and then fallsback
|
|
64
|
-
* to the root of the drive the manifest is on (assumes absolute path is given)
|
|
65
|
-
* @returns {string|undefined}
|
|
66
|
-
*/
|
|
67
|
-
traverseForWrapper(startingManifest: string, repoRoot?: string): string | undefined;
|
|
68
|
-
normalizePath(thePath: any): string;
|
|
69
60
|
#private;
|
|
70
61
|
}
|
|
71
62
|
export type Provided = import("../provider").Provided;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
1
|
import path from 'node:path';
|
|
3
2
|
import { PackageURL } from 'packageurl-js';
|
|
4
|
-
import { getCustomPath,
|
|
3
|
+
import { getCustomPath, getWrapperPreference, invokeCommand, traverseForWrapper } from "../tools.js";
|
|
5
4
|
/** @typedef {import('../provider').Provider} */
|
|
6
5
|
/** @typedef {import('../provider').Provided} Provided */
|
|
7
6
|
/** @typedef {{name: string, version: string}} Package */
|
|
@@ -131,7 +130,7 @@ export default class Base_Java {
|
|
|
131
130
|
const toolPath = getCustomPath(this.globalBinary, opts);
|
|
132
131
|
const useWrapper = getWrapperPreference(this.globalBinary, opts);
|
|
133
132
|
if (useWrapper) {
|
|
134
|
-
const wrapper = this.
|
|
133
|
+
const wrapper = traverseForWrapper(manifestDir, this.localWrapper);
|
|
135
134
|
if (wrapper !== undefined) {
|
|
136
135
|
try {
|
|
137
136
|
this._invokeCommand(wrapper, ['--version'], { cwd: manifestDir });
|
|
@@ -156,39 +155,4 @@ export default class Base_Java {
|
|
|
156
155
|
}
|
|
157
156
|
return toolPath;
|
|
158
157
|
}
|
|
159
|
-
/**
|
|
160
|
-
*
|
|
161
|
-
* @param {string} startingManifest - the path of the manifest from which to start searching for the wrapper
|
|
162
|
-
* @param {string} repoRoot - the root of the repository at which point to stop searching for mvnw, derived via git if unset and then fallsback
|
|
163
|
-
* to the root of the drive the manifest is on (assumes absolute path is given)
|
|
164
|
-
* @returns {string|undefined}
|
|
165
|
-
*/
|
|
166
|
-
traverseForWrapper(startingManifest, repoRoot = undefined) {
|
|
167
|
-
const normalizedManifest = this.normalizePath(startingManifest);
|
|
168
|
-
const currentDir = this.normalizePath(path.dirname(normalizedManifest));
|
|
169
|
-
repoRoot = repoRoot || getGitRootDir(currentDir) || path.parse(normalizedManifest).root;
|
|
170
|
-
const wrapperPath = path.join(currentDir, this.localWrapper);
|
|
171
|
-
try {
|
|
172
|
-
fs.accessSync(wrapperPath, fs.constants.X_OK);
|
|
173
|
-
return wrapperPath;
|
|
174
|
-
}
|
|
175
|
-
catch (error) {
|
|
176
|
-
if (error.code === 'ENOENT') {
|
|
177
|
-
const rootDir = path.parse(currentDir).root;
|
|
178
|
-
if (currentDir === repoRoot || currentDir === rootDir) {
|
|
179
|
-
return undefined;
|
|
180
|
-
}
|
|
181
|
-
const parentDir = path.dirname(currentDir);
|
|
182
|
-
if (parentDir === currentDir || parentDir === rootDir) {
|
|
183
|
-
return undefined;
|
|
184
|
-
}
|
|
185
|
-
return this.traverseForWrapper(path.join(parentDir, path.basename(normalizedManifest)), repoRoot);
|
|
186
|
-
}
|
|
187
|
-
throw new Error(`failure searching for ${this.localWrapper}`, { cause: error });
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
normalizePath(thePath) {
|
|
191
|
-
const normalized = path.resolve(thePath).normalize();
|
|
192
|
-
return process.platform === 'win32' ? normalized.toLowerCase() : normalized;
|
|
193
|
-
}
|
|
194
158
|
}
|
|
@@ -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 */
|
|
@@ -131,6 +131,10 @@ export type GraphEntry = {
|
|
|
131
131
|
name: string;
|
|
132
132
|
version: string;
|
|
133
133
|
children: string[];
|
|
134
|
+
hashes?: Array<{
|
|
135
|
+
alg: string;
|
|
136
|
+
content: string;
|
|
137
|
+
}>;
|
|
134
138
|
};
|
|
135
139
|
export type DepTreeEntry = {
|
|
136
140
|
name: string;
|
|
@@ -7,9 +7,10 @@ import Sbom from '../sbom.js';
|
|
|
7
7
|
import { getCustom } from '../tools.js';
|
|
8
8
|
const ecosystem = 'pip';
|
|
9
9
|
const IGNORE_MARKERS = ['exhortignore', 'trustify-da-ignore'];
|
|
10
|
+
const NO_SCOPE = undefined;
|
|
10
11
|
const DEFAULT_ROOT_NAME = 'default-pip-root';
|
|
11
12
|
const DEFAULT_ROOT_VERSION = '0.0.0';
|
|
12
|
-
/** @typedef {{name: string, version: string, children: string[]}} GraphEntry */
|
|
13
|
+
/** @typedef {{name: string, version: string, children: string[], hashes?: Array<{alg: string, content: string}>}} GraphEntry */
|
|
13
14
|
/** @typedef {{name: string, version: string, dependencies: DepTreeEntry[]}} DepTreeEntry */
|
|
14
15
|
/** @typedef {{directDeps: string[], graph: Map<string, GraphEntry>}} DependencyData */
|
|
15
16
|
/** @typedef {{ecosystem: string, content: string, contentType: string}} Provided */
|
|
@@ -281,7 +282,7 @@ export default class Base_pyproject {
|
|
|
281
282
|
continue;
|
|
282
283
|
}
|
|
283
284
|
let entry = graph.get(key);
|
|
284
|
-
sbom.addDependency(rootPurl, this._toPurl(entry.name, entry.version));
|
|
285
|
+
sbom.addDependency(rootPurl, this._toPurl(entry.name, entry.version), NO_SCOPE, entry.hashes);
|
|
285
286
|
}
|
|
286
287
|
for (let [key, entry] of graph) {
|
|
287
288
|
if (!reachable.has(key)) {
|
|
@@ -293,7 +294,7 @@ export default class Base_pyproject {
|
|
|
293
294
|
continue;
|
|
294
295
|
}
|
|
295
296
|
let childEntry = graph.get(child);
|
|
296
|
-
sbom.addDependency(parentPurl, this._toPurl(childEntry.name, childEntry.version));
|
|
297
|
+
sbom.addDependency(parentPurl, this._toPurl(childEntry.name, childEntry.version), NO_SCOPE, childEntry.hashes);
|
|
297
298
|
}
|
|
298
299
|
}
|
|
299
300
|
}
|
|
@@ -306,7 +307,7 @@ export default class Base_pyproject {
|
|
|
306
307
|
if (!entry) {
|
|
307
308
|
continue;
|
|
308
309
|
}
|
|
309
|
-
sbom.addDependency(rootPurl, this._toPurl(entry.name, entry.version));
|
|
310
|
+
sbom.addDependency(rootPurl, this._toPurl(entry.name, entry.version), NO_SCOPE, entry.hashes);
|
|
310
311
|
}
|
|
311
312
|
}
|
|
312
313
|
return sbom.getAsJsonString(opts);
|
|
@@ -1,3 +1,12 @@
|
|
|
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,6 +4,7 @@ import { PackageURL } from 'packageurl-js';
|
|
|
4
4
|
import { readLicenseFile } from '../license/license_utils.js';
|
|
5
5
|
import Sbom from '../sbom.js';
|
|
6
6
|
import { getCustom, getCustomPath, invokeCommand } from "../tools.js";
|
|
7
|
+
import { filterManifestPathsByDiscoveryIgnore, resolveWorkspaceDiscoveryIgnore } from '../workspace.js';
|
|
7
8
|
import { getParser, getRequireQuery } from './gomod_parser.js';
|
|
8
9
|
export default { isSupported, validateLockFile, provideComponent, provideStack, readLicenseFromManifest };
|
|
9
10
|
/** @typedef {import('../provider').Provider} */
|
|
@@ -328,13 +329,7 @@ function getFinalPackagesVersionsForModule(rows, manifestPath, goBin) {
|
|
|
328
329
|
catch (error) {
|
|
329
330
|
throw new Error('failed to list all modules', { cause: error });
|
|
330
331
|
}
|
|
331
|
-
let finalVersionModules =
|
|
332
|
-
finalVersionsForAllModules.split(getLineSeparatorGolang()).filter(string => string.trim() !== "")
|
|
333
|
-
.filter(string => string.trim().split(" ").length === 2)
|
|
334
|
-
.forEach((dependency) => {
|
|
335
|
-
let dep = dependency.split(" ");
|
|
336
|
-
finalVersionModules[dep[0]] = dep[1];
|
|
337
|
-
});
|
|
332
|
+
let finalVersionModules = parseModuleVersions(finalVersionsForAllModules);
|
|
338
333
|
let finalVersionModulesArray = new Array();
|
|
339
334
|
rows.filter(string => string.trim() !== "").forEach(module => {
|
|
340
335
|
let child = getChildVertexFromEdge(module);
|
|
@@ -395,7 +390,69 @@ function getVersionOfPackage(fullPackage) {
|
|
|
395
390
|
let parts = fullPackage.split("@");
|
|
396
391
|
return parts.length > 1 ? parts[1] : undefined;
|
|
397
392
|
}
|
|
393
|
+
function parseModuleVersions(goListOutput) {
|
|
394
|
+
let modules = {};
|
|
395
|
+
goListOutput.split(getLineSeparatorGolang()).filter(string => string.trim() !== "")
|
|
396
|
+
.forEach((line) => {
|
|
397
|
+
let parts = line.trim().split(" ");
|
|
398
|
+
if (parts.length === 2) {
|
|
399
|
+
modules[parts[0]] = parts[1];
|
|
400
|
+
}
|
|
401
|
+
else if (parts.length >= 4 && parts[2] === "=>") {
|
|
402
|
+
modules[parts[0]] = parts[parts.length - 1];
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
return modules;
|
|
406
|
+
}
|
|
398
407
|
function getLineSeparatorGolang() {
|
|
399
408
|
let reg = /\n|\r\n/;
|
|
400
409
|
return reg;
|
|
401
410
|
}
|
|
411
|
+
/**
|
|
412
|
+
* Discover all go.mod manifest paths in a Go workspace.
|
|
413
|
+
* Uses `go work edit -json` to get workspace members.
|
|
414
|
+
*
|
|
415
|
+
* @param {string} workspaceRoot - Absolute or relative path to workspace root (must contain go.work)
|
|
416
|
+
* @param {import('../index.js').Options} [opts={}]
|
|
417
|
+
* @returns {Promise<string[]>} Paths to go.mod files (absolute)
|
|
418
|
+
*/
|
|
419
|
+
export async function discoverGoWorkspaceModules(workspaceRoot, opts = {}) {
|
|
420
|
+
const root = path.resolve(workspaceRoot);
|
|
421
|
+
const goWork = path.join(root, 'go.work');
|
|
422
|
+
if (!fs.existsSync(goWork)) {
|
|
423
|
+
return [];
|
|
424
|
+
}
|
|
425
|
+
const goBin = getCustomPath('go', opts);
|
|
426
|
+
let output;
|
|
427
|
+
try {
|
|
428
|
+
output = invokeCommand(goBin, ['work', 'edit', '-json', goWork], { cwd: root });
|
|
429
|
+
}
|
|
430
|
+
catch {
|
|
431
|
+
return [];
|
|
432
|
+
}
|
|
433
|
+
let workspace;
|
|
434
|
+
try {
|
|
435
|
+
workspace = JSON.parse(output.toString().trim());
|
|
436
|
+
}
|
|
437
|
+
catch {
|
|
438
|
+
return [];
|
|
439
|
+
}
|
|
440
|
+
const useEntries = workspace.Use || [];
|
|
441
|
+
if (useEntries.length === 0) {
|
|
442
|
+
return [];
|
|
443
|
+
}
|
|
444
|
+
const manifestPaths = [];
|
|
445
|
+
for (const entry of useEntries) {
|
|
446
|
+
const diskPath = entry.DiskPath;
|
|
447
|
+
if (!diskPath) {
|
|
448
|
+
continue;
|
|
449
|
+
}
|
|
450
|
+
const moduleDir = path.resolve(root, diskPath);
|
|
451
|
+
const goMod = path.join(moduleDir, 'go.mod');
|
|
452
|
+
if (fs.existsSync(goMod)) {
|
|
453
|
+
manifestPaths.push(goMod);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
const ignorePatterns = resolveWorkspaceDiscoveryIgnore(opts);
|
|
457
|
+
return filterManifestPathsByDiscoveryIgnore(manifestPaths, root, ignorePatterns);
|
|
458
|
+
}
|
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discover all build.gradle[.kts] manifest paths in a Gradle multi-project build.
|
|
3
|
+
* Uses a custom init script to get structured project listing.
|
|
4
|
+
*
|
|
5
|
+
* @param {string} workspaceRoot - Absolute or relative path to workspace root (must contain settings.gradle[.kts])
|
|
6
|
+
* @param {import('../index.js').Options} [opts={}]
|
|
7
|
+
* @returns {Promise<string[]>} Paths to build.gradle[.kts] files (absolute)
|
|
8
|
+
*/
|
|
9
|
+
export function discoverGradleSubprojects(workspaceRoot: string, opts?: import("../index.js").Options): Promise<string[]>;
|
|
10
|
+
/**
|
|
11
|
+
* Parse the structured output from the Gradle init script.
|
|
12
|
+
*
|
|
13
|
+
* @param {string} raw - Raw stdout from gradle
|
|
14
|
+
* @returns {{ path: string, dir: string }[]}
|
|
15
|
+
*/
|
|
16
|
+
export function parseGradleInitScriptOutput(raw: string): {
|
|
17
|
+
path: string;
|
|
18
|
+
dir: string;
|
|
19
|
+
}[];
|
|
1
20
|
/**
|
|
2
21
|
* This class provides common functionality for Groovy and Kotlin DSL files.
|
|
3
22
|
*/
|