@trustify-da/trustify-da-javascript-client 0.3.0-ea.8e46e86 → 0.3.0-ea.8eab29b
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 +1 -1
- package/dist/src/cyclone_dx_sbom.d.ts +7 -1
- package/dist/src/cyclone_dx_sbom.js +29 -8
- package/dist/src/index.d.ts +62 -3
- package/dist/src/index.js +73 -6
- package/dist/src/provider.d.ts +3 -2
- package/dist/src/provider.js +5 -1
- package/dist/src/providers/base_java.d.ts +5 -9
- package/dist/src/providers/base_java.js +9 -38
- package/dist/src/providers/base_javascript.d.ts +11 -0
- package/dist/src/providers/base_javascript.js +10 -3
- package/dist/src/providers/base_pyproject.d.ts +14 -26
- package/dist/src/providers/base_pyproject.js +57 -73
- package/dist/src/providers/golang_gomodules.d.ts +10 -0
- package/dist/src/providers/golang_gomodules.js +65 -8
- 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_bun.d.ts +10 -0
- package/dist/src/providers/javascript_bun.js +100 -0
- package/dist/src/providers/javascript_npm.d.ts +1 -0
- package/dist/src/providers/javascript_npm.js +21 -0
- 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/processors/yarn_berry_processor.js +6 -2
- package/dist/src/providers/python_controller.d.ts +5 -1
- package/dist/src/providers/python_controller.js +65 -7
- package/dist/src/providers/python_pip.d.ts +5 -0
- package/dist/src/providers/python_pip.js +5 -5
- package/dist/src/providers/python_pip_pyproject.d.ts +61 -0
- package/dist/src/providers/python_pip_pyproject.js +146 -0
- package/dist/src/providers/python_poetry.d.ts +37 -4
- package/dist/src/providers/python_poetry.js +82 -13
- package/dist/src/providers/python_uv.d.ts +28 -0
- package/dist/src/providers/python_uv.js +82 -1
- package/dist/src/providers/rust_cargo.d.ts +5 -1
- package/dist/src/providers/rust_cargo.js +31 -4
- 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 +2 -2
package/dist/package.json
CHANGED
|
@@ -51,11 +51,11 @@
|
|
|
51
51
|
"@cyclonedx/cyclonedx-library": "^6.13.0",
|
|
52
52
|
"eslint-import-resolver-typescript": "^4.4.4",
|
|
53
53
|
"fast-glob": "^3.3.3",
|
|
54
|
-
"fast-toml": "^0.5.4",
|
|
55
54
|
"fast-xml-parser": "^5.3.4",
|
|
56
55
|
"help": "^3.0.2",
|
|
57
56
|
"https-proxy-agent": "^7.0.6",
|
|
58
57
|
"js-yaml": "^4.1.1",
|
|
58
|
+
"jsonc-parser": "^3.3.1",
|
|
59
59
|
"micromatch": "^4.0.8",
|
|
60
60
|
"node-fetch": "^3.3.2",
|
|
61
61
|
"p-limit": "^4.0.0",
|
|
@@ -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) {
|
|
@@ -40,12 +41,24 @@ function getComponent(component, type, scope, licenses) {
|
|
|
40
41
|
// Add licenses if provided (CycloneDX format). Callers must provide valid SPDX identifiers.
|
|
41
42
|
if (licenses) {
|
|
42
43
|
const licenseArray = Array.isArray(licenses) ? licenses : [licenses];
|
|
43
|
-
|
|
44
|
+
const validLicenses = licenseArray
|
|
45
|
+
.map(lic => {
|
|
44
46
|
if (typeof lic === 'string') {
|
|
45
47
|
return { license: { id: lic } };
|
|
46
48
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
if (typeof lic === 'object' && lic !== null && ('license' in lic || 'expression' in lic)) {
|
|
50
|
+
return lic;
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
})
|
|
54
|
+
.filter(Boolean);
|
|
55
|
+
if (validLicenses.length > 0) {
|
|
56
|
+
componentObject.licenses = validLicenses;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Add hashes if provided (CycloneDX 1.4 format).
|
|
60
|
+
if (hashes && hashes.length > 0) {
|
|
61
|
+
componentObject.hashes = hashes;
|
|
49
62
|
}
|
|
50
63
|
return componentObject;
|
|
51
64
|
}
|
|
@@ -86,16 +99,24 @@ export default class CycloneDxSbom {
|
|
|
86
99
|
* Adds a dependency relationship between two components in the SBOM
|
|
87
100
|
* @param {PackageURL} sourceRef - The source component (parent)
|
|
88
101
|
* @param {PackageURL} targetRef - The target component (dependency)
|
|
102
|
+
* @param {string} [scope] - Scope of the dependency
|
|
103
|
+
* @param {Array<{alg: string, content: string}>} [targetHashes] - Optional hashes for the target component
|
|
89
104
|
* @return {CycloneDxSbom} The updated SBOM
|
|
90
105
|
*/
|
|
91
|
-
addDependency(sourceRef, targetRef, scope) {
|
|
106
|
+
addDependency(sourceRef, targetRef, scope, targetHashes) {
|
|
92
107
|
const sourcePurl = sourceRef.toString();
|
|
93
108
|
const targetPurl = targetRef.toString();
|
|
94
109
|
// Ensure both components exist in the components list
|
|
95
110
|
[sourceRef, targetRef].forEach((ref, index) => {
|
|
96
111
|
const purl = index === 0 ? sourcePurl : targetPurl;
|
|
97
|
-
|
|
98
|
-
|
|
112
|
+
const existingIndex = this.getComponentIndex(purl);
|
|
113
|
+
if (existingIndex < 0) {
|
|
114
|
+
const hashes = index === 1 ? targetHashes : undefined;
|
|
115
|
+
this.components.push(getComponent(ref, "library", scope, undefined, hashes));
|
|
116
|
+
}
|
|
117
|
+
else if (index === 1 && targetHashes && targetHashes.length > 0 && !this.components[existingIndex].hashes) {
|
|
118
|
+
// Update hashes if the component was first seen without them (e.g. as a source)
|
|
119
|
+
this.components[existingIndex].hashes = targetHashes;
|
|
99
120
|
}
|
|
100
121
|
});
|
|
101
122
|
// 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,
|
|
@@ -171,7 +175,9 @@ async function componentAnalysis(manifest, opts = {}) {
|
|
|
171
175
|
fs.accessSync(manifest, fs.constants.R_OK);
|
|
172
176
|
opts["manifest-type"] = path.basename(manifest);
|
|
173
177
|
let provider = match(manifest, availableProviders, opts); // throws error if no matching provider
|
|
174
|
-
|
|
178
|
+
const result = await analysis.requestComponent(provider, manifest, theUrl, opts); // throws error request sending failed
|
|
179
|
+
result.packageManager = provider.packageManagerName();
|
|
180
|
+
return result;
|
|
175
181
|
}
|
|
176
182
|
/**
|
|
177
183
|
* @overload
|
|
@@ -279,17 +285,45 @@ async function generateOneSbom(manifestPath, workspaceOpts) {
|
|
|
279
285
|
*
|
|
280
286
|
* @param {string} root - Resolved workspace root
|
|
281
287
|
* @param {Options} opts
|
|
282
|
-
* @returns {Promise<{ ecosystem: 'javascript' | 'cargo' | 'unknown', manifestPaths: string[] }>}
|
|
288
|
+
* @returns {Promise<{ ecosystem: 'javascript' | 'cargo' | 'maven' | 'gradle' | 'gomodules' | 'pyproject' | 'unknown', manifestPaths: string[] }>}
|
|
283
289
|
* @private
|
|
284
290
|
*/
|
|
285
291
|
async function detectWorkspaceManifests(root, opts) {
|
|
286
292
|
const cargoToml = path.join(root, 'Cargo.toml');
|
|
287
293
|
const cargoLock = path.join(root, 'Cargo.lock');
|
|
288
294
|
const packageJson = path.join(root, 'package.json');
|
|
295
|
+
const pomXml = path.join(root, 'pom.xml');
|
|
289
296
|
if (fs.existsSync(cargoToml) && fs.existsSync(cargoLock)) {
|
|
290
297
|
return { ecosystem: 'cargo', manifestPaths: await discoverWorkspaceCrates(root, opts) };
|
|
291
298
|
}
|
|
292
|
-
|
|
299
|
+
if (fs.existsSync(pomXml)) {
|
|
300
|
+
const manifestPaths = await discoverMavenModules(root, opts);
|
|
301
|
+
if (manifestPaths.length > 0) {
|
|
302
|
+
return { ecosystem: 'maven', manifestPaths };
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
const hasGradleSettings = fs.existsSync(path.join(root, 'settings.gradle'))
|
|
306
|
+
|| fs.existsSync(path.join(root, 'settings.gradle.kts'));
|
|
307
|
+
if (hasGradleSettings) {
|
|
308
|
+
const manifestPaths = await discoverGradleSubprojects(root, opts);
|
|
309
|
+
if (manifestPaths.length > 0) {
|
|
310
|
+
return { ecosystem: 'gradle', manifestPaths };
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
if (fs.existsSync(path.join(root, 'go.work'))) {
|
|
314
|
+
const manifestPaths = await discoverGoWorkspaceModules(root, opts);
|
|
315
|
+
if (manifestPaths.length > 0) {
|
|
316
|
+
return { ecosystem: 'gomodules', manifestPaths };
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
if (fs.existsSync(path.join(root, 'pyproject.toml')) && fs.existsSync(path.join(root, 'uv.lock'))) {
|
|
320
|
+
const manifestPaths = await discoverUvWorkspaceMembers(root, opts);
|
|
321
|
+
if (manifestPaths.length > 0) {
|
|
322
|
+
return { ecosystem: 'pyproject', manifestPaths };
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
const hasJsLock = fs.existsSync(path.join(root, 'bun.lock'))
|
|
326
|
+
|| fs.existsSync(path.join(root, 'pnpm-lock.yaml'))
|
|
293
327
|
|| fs.existsSync(path.join(root, 'yarn.lock'))
|
|
294
328
|
|| fs.existsSync(path.join(root, 'package-lock.json'));
|
|
295
329
|
if (fs.existsSync(packageJson) && hasJsLock) {
|
|
@@ -398,12 +432,45 @@ function batchError(message, wantMetadata, metadata) {
|
|
|
398
432
|
}
|
|
399
433
|
return err;
|
|
400
434
|
}
|
|
435
|
+
/**
|
|
436
|
+
* @overload
|
|
437
|
+
* @param {string} workspaceRoot
|
|
438
|
+
* @param {true} html
|
|
439
|
+
* @param {Options & { batchMetadata: true }} opts
|
|
440
|
+
* @returns {Promise<{ analysis: string, metadata: BatchAnalysisMetadata }>}
|
|
441
|
+
* @throws {Error}
|
|
442
|
+
*/
|
|
443
|
+
/**
|
|
444
|
+
* @overload
|
|
445
|
+
* @param {string} workspaceRoot
|
|
446
|
+
* @param {true} html
|
|
447
|
+
* @param {Options & { batchMetadata?: false }} [opts={}]
|
|
448
|
+
* @returns {Promise<string>}
|
|
449
|
+
* @throws {Error}
|
|
450
|
+
*/
|
|
451
|
+
/**
|
|
452
|
+
* @overload
|
|
453
|
+
* @param {string} workspaceRoot
|
|
454
|
+
* @param {false} html
|
|
455
|
+
* @param {Options & { batchMetadata: true }} opts
|
|
456
|
+
* @returns {Promise<{ analysis: Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>, metadata: BatchAnalysisMetadata }>}
|
|
457
|
+
* @throws {Error}
|
|
458
|
+
*/
|
|
459
|
+
/**
|
|
460
|
+
* @overload
|
|
461
|
+
* @param {string} workspaceRoot
|
|
462
|
+
* @param {false} html
|
|
463
|
+
* @param {Options & { batchMetadata?: false }} [opts={}]
|
|
464
|
+
* @returns {Promise<Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>>}
|
|
465
|
+
* @throws {Error}
|
|
466
|
+
*/
|
|
401
467
|
/**
|
|
402
468
|
* Get stack analysis for all workspace packages/crates (batch).
|
|
403
469
|
* Detects ecosystem from workspace root: Cargo (Cargo.toml + Cargo.lock) or JS/TS (package.json + lock file).
|
|
404
470
|
* SBOMs are generated in parallel (see `batchConcurrency`) unless `continueOnError: false` (fail-fast sequential).
|
|
405
471
|
* With `opts.batchMetadata` / `TRUSTIFY_DA_BATCH_METADATA`, returns `{ analysis, metadata }` including validation and SBOM errors.
|
|
406
472
|
*
|
|
473
|
+
* @overload
|
|
407
474
|
* @param {string} workspaceRoot - Path to workspace root (containing lock file and workspace config)
|
|
408
475
|
* @param {boolean} [html=false] - true returns HTML, false returns JSON report
|
|
409
476
|
* @param {Options} [opts={}] - `batchConcurrency`, discovery ignores, `continueOnError` (default true), `batchMetadata` (default false)
|
|
@@ -434,7 +501,7 @@ async function stackAnalysisBatch(workspaceRoot, html = false, opts = {}) {
|
|
|
434
501
|
}
|
|
435
502
|
}
|
|
436
503
|
if (manifestPaths.length === 0) {
|
|
437
|
-
throw new Error(`No workspace manifests found at ${root}. Ensure Cargo.toml+Cargo.lock or package.json+lock file
|
|
504
|
+
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
505
|
}
|
|
439
506
|
const workspaceOpts = { ...opts, TRUSTIFY_DA_WORKSPACE_DIR: root };
|
|
440
507
|
const concurrency = resolveBatchConcurrency(opts);
|
package/dist/src/provider.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export function match(manifest: string, providers: [Provider], opts?: {
|
|
|
21
21
|
TRUSTIFY_DA_WORKSPACE_DIR?: string;
|
|
22
22
|
}): Provider;
|
|
23
23
|
/** @typedef {{ecosystem: string, contentType: string, content: string}} Provided */
|
|
24
|
-
/** @typedef {{isSupported: function(string): boolean, validateLockFile: function(string, Object): void, provideComponent: function(string, {}): Provided | Promise<Provided>, provideStack: function(string, {}): Provided | Promise<Provided>, readLicenseFromManifest: function(string): string | null}} Provider */
|
|
24
|
+
/** @typedef {{isSupported: function(string): boolean, validateLockFile: function(string, Object): void, provideComponent: function(string, {}): Provided | Promise<Provided>, provideStack: function(string, {}): Provided | Promise<Provided>, readLicenseFromManifest: function(string, Object=): string | null, packageManagerName: function(): string}} Provider */
|
|
25
25
|
/**
|
|
26
26
|
* MUST include all providers here.
|
|
27
27
|
* @type {[Provider]}
|
|
@@ -37,5 +37,6 @@ export type Provider = {
|
|
|
37
37
|
validateLockFile: (arg0: string, arg1: any) => void;
|
|
38
38
|
provideComponent: (arg0: string, arg1: {}) => Provided | Promise<Provided>;
|
|
39
39
|
provideStack: (arg0: string, arg1: {}) => Provided | Promise<Provided>;
|
|
40
|
-
readLicenseFromManifest: (arg0: string) => string | null;
|
|
40
|
+
readLicenseFromManifest: (arg0: string, arg1: any | undefined) => string | null;
|
|
41
|
+
packageManagerName: () => string;
|
|
41
42
|
};
|
package/dist/src/provider.js
CHANGED
|
@@ -3,15 +3,17 @@ import golangGomodulesProvider from './providers/golang_gomodules.js';
|
|
|
3
3
|
import Java_gradle_groovy from "./providers/java_gradle_groovy.js";
|
|
4
4
|
import Java_gradle_kotlin from "./providers/java_gradle_kotlin.js";
|
|
5
5
|
import Java_maven from "./providers/java_maven.js";
|
|
6
|
+
import Javascript_bun from './providers/javascript_bun.js';
|
|
6
7
|
import Javascript_npm from './providers/javascript_npm.js';
|
|
7
8
|
import Javascript_pnpm from './providers/javascript_pnpm.js';
|
|
8
9
|
import Javascript_yarn from './providers/javascript_yarn.js';
|
|
9
10
|
import pythonPipProvider from './providers/python_pip.js';
|
|
11
|
+
import Python_pip_pyproject from './providers/python_pip_pyproject.js';
|
|
10
12
|
import Python_poetry from './providers/python_poetry.js';
|
|
11
13
|
import Python_uv from './providers/python_uv.js';
|
|
12
14
|
import rustCargoProvider from './providers/rust_cargo.js';
|
|
13
15
|
/** @typedef {{ecosystem: string, contentType: string, content: string}} Provided */
|
|
14
|
-
/** @typedef {{isSupported: function(string): boolean, validateLockFile: function(string, Object): void, provideComponent: function(string, {}): Provided | Promise<Provided>, provideStack: function(string, {}): Provided | Promise<Provided>, readLicenseFromManifest: function(string): string | null}} Provider */
|
|
16
|
+
/** @typedef {{isSupported: function(string): boolean, validateLockFile: function(string, Object): void, provideComponent: function(string, {}): Provided | Promise<Provided>, provideStack: function(string, {}): Provided | Promise<Provided>, readLicenseFromManifest: function(string, Object=): string | null, packageManagerName: function(): string}} Provider */
|
|
15
17
|
/**
|
|
16
18
|
* MUST include all providers here.
|
|
17
19
|
* @type {[Provider]}
|
|
@@ -20,6 +22,7 @@ export const availableProviders = [
|
|
|
20
22
|
new Java_maven(),
|
|
21
23
|
new Java_gradle_groovy(),
|
|
22
24
|
new Java_gradle_kotlin(),
|
|
25
|
+
new Javascript_bun(),
|
|
23
26
|
new Javascript_pnpm(),
|
|
24
27
|
new Javascript_yarn(),
|
|
25
28
|
new Javascript_npm(),
|
|
@@ -27,6 +30,7 @@ export const availableProviders = [
|
|
|
27
30
|
pythonPipProvider,
|
|
28
31
|
new Python_poetry(),
|
|
29
32
|
new Python_uv(),
|
|
33
|
+
new Python_pip_pyproject(),
|
|
30
34
|
rustCargoProvider
|
|
31
35
|
];
|
|
32
36
|
/**
|
|
@@ -20,6 +20,11 @@ export default class Base_Java {
|
|
|
20
20
|
CONFLICT_REGEX: RegExp;
|
|
21
21
|
globalBinary: string;
|
|
22
22
|
localWrapper: string;
|
|
23
|
+
/**
|
|
24
|
+
* Returns the package manager name (e.g. mvn, gradle)
|
|
25
|
+
* @returns {string}
|
|
26
|
+
*/
|
|
27
|
+
packageManagerName(): string;
|
|
23
28
|
/**
|
|
24
29
|
* Recursively populates the SBOM instance with the parsed graph
|
|
25
30
|
* @param {string} src - Source dependency to start the calculations from
|
|
@@ -57,15 +62,6 @@ export default class Base_Java {
|
|
|
57
62
|
* @returns string
|
|
58
63
|
*/
|
|
59
64
|
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
65
|
#private;
|
|
70
66
|
}
|
|
71
67
|
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 */
|
|
@@ -26,6 +25,13 @@ export default class Base_Java {
|
|
|
26
25
|
this.globalBinary = globalBinary;
|
|
27
26
|
this.localWrapper = localWrapper;
|
|
28
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Returns the package manager name (e.g. mvn, gradle)
|
|
30
|
+
* @returns {string}
|
|
31
|
+
*/
|
|
32
|
+
packageManagerName() {
|
|
33
|
+
return this.globalBinary;
|
|
34
|
+
}
|
|
29
35
|
/**
|
|
30
36
|
* Recursively populates the SBOM instance with the parsed graph
|
|
31
37
|
* @param {string} src - Source dependency to start the calculations from
|
|
@@ -131,7 +137,7 @@ export default class Base_Java {
|
|
|
131
137
|
const toolPath = getCustomPath(this.globalBinary, opts);
|
|
132
138
|
const useWrapper = getWrapperPreference(this.globalBinary, opts);
|
|
133
139
|
if (useWrapper) {
|
|
134
|
-
const wrapper = this.
|
|
140
|
+
const wrapper = traverseForWrapper(manifestDir, this.localWrapper);
|
|
135
141
|
if (wrapper !== undefined) {
|
|
136
142
|
try {
|
|
137
143
|
this._invokeCommand(wrapper, ['--version'], { cwd: manifestDir });
|
|
@@ -156,39 +162,4 @@ export default class Base_Java {
|
|
|
156
162
|
}
|
|
157
163
|
return toolPath;
|
|
158
164
|
}
|
|
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
165
|
}
|
|
@@ -47,6 +47,11 @@ export default class Base_javascript {
|
|
|
47
47
|
*/
|
|
48
48
|
protected _cmdName(): string;
|
|
49
49
|
/**
|
|
50
|
+
* Returns the package manager name (e.g. npm, yarn, pnpm, bun)
|
|
51
|
+
* @returns {string} The package manager name
|
|
52
|
+
*/
|
|
53
|
+
packageManagerName(): string;
|
|
54
|
+
/**
|
|
50
55
|
* Returns the command arguments for listing dependencies
|
|
51
56
|
* @returns {Array<string>} The command arguments
|
|
52
57
|
* @abstract
|
|
@@ -136,6 +141,12 @@ export default class Base_javascript {
|
|
|
136
141
|
*/
|
|
137
142
|
protected _version(): string;
|
|
138
143
|
/**
|
|
144
|
+
* Creates or updates the lock file for the package manager
|
|
145
|
+
* @param {string} manifestDir - Directory containing the manifest file
|
|
146
|
+
* @protected
|
|
147
|
+
*/
|
|
148
|
+
protected _createLockFile(manifestDir: string): void;
|
|
149
|
+
/**
|
|
139
150
|
* Parses the dependency tree output
|
|
140
151
|
* @param {string} output - The output to parse
|
|
141
152
|
* @returns {string} The parsed output
|
|
@@ -71,6 +71,13 @@ export default class Base_javascript {
|
|
|
71
71
|
throw new TypeError("_cmdName must be implemented");
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
74
|
+
* Returns the package manager name (e.g. npm, yarn, pnpm, bun)
|
|
75
|
+
* @returns {string} The package manager name
|
|
76
|
+
*/
|
|
77
|
+
packageManagerName() {
|
|
78
|
+
return this._cmdName();
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
74
81
|
* Returns the command arguments for listing dependencies
|
|
75
82
|
* @returns {Array<string>} The command arguments
|
|
76
83
|
* @abstract
|
|
@@ -217,7 +224,7 @@ export default class Base_javascript {
|
|
|
217
224
|
this._version();
|
|
218
225
|
const manifestDir = path.dirname(this.#manifest.manifestPath);
|
|
219
226
|
const cmdDir = this._findLockFileDir(manifestDir, opts) || manifestDir;
|
|
220
|
-
this
|
|
227
|
+
this._createLockFile(cmdDir);
|
|
221
228
|
let output = this.#executeListCmd(includeTransitive, cmdDir);
|
|
222
229
|
output = this._parseDepTreeOutput(output);
|
|
223
230
|
return JSON.parse(output);
|
|
@@ -363,9 +370,9 @@ export default class Base_javascript {
|
|
|
363
370
|
/**
|
|
364
371
|
* Creates or updates the lock file for the package manager
|
|
365
372
|
* @param {string} manifestDir - Directory containing the manifest file
|
|
366
|
-
* @
|
|
373
|
+
* @protected
|
|
367
374
|
*/
|
|
368
|
-
|
|
375
|
+
_createLockFile(manifestDir) {
|
|
369
376
|
const originalDir = process.cwd();
|
|
370
377
|
const isWindows = os.platform() === 'win32';
|
|
371
378
|
if (isWindows) {
|
|
@@ -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 */
|
|
@@ -61,6 +61,11 @@ export default class Base_pyproject {
|
|
|
61
61
|
* @protected
|
|
62
62
|
*/
|
|
63
63
|
protected _cmdName(): string;
|
|
64
|
+
/**
|
|
65
|
+
* Returns the package manager name (e.g. pip, poetry, uv)
|
|
66
|
+
* @returns {string}
|
|
67
|
+
*/
|
|
68
|
+
packageManagerName(): string;
|
|
64
69
|
/**
|
|
65
70
|
* Resolve dependencies using the tool-specific command and parser.
|
|
66
71
|
*
|
|
@@ -102,26 +107,14 @@ export default class Base_pyproject {
|
|
|
102
107
|
*/
|
|
103
108
|
protected _getIgnoredDeps(manifestPath: string): Set<string>;
|
|
104
109
|
/**
|
|
105
|
-
*
|
|
110
|
+
* Compute the set of graph nodes reachable from direct deps, excluding ignored.
|
|
106
111
|
* @param {Map<string, GraphEntry>} graph
|
|
107
|
-
* @param {string[]} directDeps
|
|
112
|
+
* @param {string[]} directDeps
|
|
108
113
|
* @param {Set<string>} ignoredDeps
|
|
109
|
-
* @
|
|
110
|
-
* @returns {DepTreeEntry[]}
|
|
111
|
-
* @protected
|
|
112
|
-
*/
|
|
113
|
-
protected _buildDependencyTree(graph: Map<string, GraphEntry>, directDeps: string[], ignoredDeps: Set<string>, includeTransitive: boolean): DepTreeEntry[];
|
|
114
|
-
/**
|
|
115
|
-
* Recursively collect transitive dependencies.
|
|
116
|
-
* @param {Map<string, GraphEntry>} graph
|
|
117
|
-
* @param {string[]} childKeys
|
|
118
|
-
* @param {DepTreeEntry[]} result - mutated in place
|
|
119
|
-
* @param {Set<string>} ignoredDeps
|
|
120
|
-
* @param {Set<string>} visited
|
|
121
|
-
* @returns {void}
|
|
114
|
+
* @returns {Set<string>}
|
|
122
115
|
* @protected
|
|
123
116
|
*/
|
|
124
|
-
protected
|
|
117
|
+
protected _reachableNodes(graph: Map<string, GraphEntry>, directDeps: string[], ignoredDeps: Set<string>): Set<string>;
|
|
125
118
|
/**
|
|
126
119
|
* @param {string} name
|
|
127
120
|
* @param {string} version
|
|
@@ -129,15 +122,6 @@ export default class Base_pyproject {
|
|
|
129
122
|
* @protected
|
|
130
123
|
*/
|
|
131
124
|
protected _toPurl(name: string, version: string): PackageURL;
|
|
132
|
-
/**
|
|
133
|
-
* Recursively add a dependency and its transitive deps to the SBOM.
|
|
134
|
-
* @param {PackageURL} source
|
|
135
|
-
* @param {DepTreeEntry} dep
|
|
136
|
-
* @param {Sbom} sbom
|
|
137
|
-
* @returns {void}
|
|
138
|
-
* @private
|
|
139
|
-
*/
|
|
140
|
-
private _addAllDependencies;
|
|
141
125
|
/**
|
|
142
126
|
* Create SBOM json string for a pyproject.toml project.
|
|
143
127
|
* @param {string} manifest - path to pyproject.toml
|
|
@@ -152,6 +136,10 @@ export type GraphEntry = {
|
|
|
152
136
|
name: string;
|
|
153
137
|
version: string;
|
|
154
138
|
children: string[];
|
|
139
|
+
hashes?: Array<{
|
|
140
|
+
alg: string;
|
|
141
|
+
content: string;
|
|
142
|
+
}>;
|
|
155
143
|
};
|
|
156
144
|
export type DepTreeEntry = {
|
|
157
145
|
name: string;
|