@trustify-da/trustify-da-javascript-client 0.3.0-ea.5047f15 → 0.3.0-ea.5348b9e
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/src/cyclone_dx_sbom.d.ts +7 -1
- package/dist/src/cyclone_dx_sbom.js +18 -5
- package/dist/src/index.d.ts +58 -2
- package/dist/src/index.js +43 -2
- 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/java_maven.d.ts +8 -0
- package/dist/src/providers/java_maven.js +93 -1
- 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/processors/yarn_berry_processor.js +6 -2
- 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_poetry.d.ts +15 -0
- package/dist/src/providers/python_uv.d.ts +15 -0
- package/dist/src/sbom.d.ts +7 -1
- package/dist/src/sbom.js +4 -2
- package/dist/src/tools.d.ts +16 -0
- package/dist/src/tools.js +40 -0
- package/package.json +1 -1
|
@@ -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
|
@@ -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,7 @@ 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';
|
|
199
255
|
import { discoverWorkspacePackages } from './workspace.js';
|
|
200
256
|
import { discoverWorkspaceCrates } from './workspace.js';
|
|
201
257
|
import { validatePackageJson } from './workspace.js';
|
|
@@ -203,5 +259,5 @@ import { resolveWorkspaceDiscoveryIgnore } from './workspace.js';
|
|
|
203
259
|
import { filterManifestPathsByDiscoveryIgnore } from './workspace.js';
|
|
204
260
|
import { resolveContinueOnError } from './batch_opts.js';
|
|
205
261
|
import { resolveBatchMetadata } from './batch_opts.js';
|
|
206
|
-
export { discoverWorkspacePackages, discoverWorkspaceCrates, validatePackageJson, resolveWorkspaceDiscoveryIgnore, filterManifestPathsByDiscoveryIgnore, resolveContinueOnError, resolveBatchMetadata };
|
|
262
|
+
export { discoverMavenModules, discoverWorkspacePackages, discoverWorkspaceCrates, validatePackageJson, resolveWorkspaceDiscoveryIgnore, filterManifestPathsByDiscoveryIgnore, resolveContinueOnError, resolveBatchMetadata };
|
|
207
263
|
export { getProjectLicense, findLicenseFilePath, identifyLicense, getLicenseDetails, licensesFromReport, normalizeLicensesResponse, runLicenseCheck, getCompatibility } from "./license/index.js";
|
package/dist/src/index.js
CHANGED
|
@@ -6,6 +6,7 @@ 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';
|
|
9
10
|
import { discoverWorkspaceCrates, discoverWorkspacePackages, filterManifestPathsByDiscoveryIgnore, resolveWorkspaceDiscoveryIgnore, validatePackageJson, } from './workspace.js';
|
|
10
11
|
import.meta.dirname;
|
|
11
12
|
import * as url from 'url';
|
|
@@ -13,7 +14,7 @@ export { parseImageRef } from "./oci_image/utils.js";
|
|
|
13
14
|
export { ImageRef } from "./oci_image/images.js";
|
|
14
15
|
export { getProjectLicense, findLicenseFilePath, identifyLicense, getLicenseDetails, licensesFromReport, normalizeLicensesResponse, runLicenseCheck, getCompatibility } from "./license/index.js";
|
|
15
16
|
export default { componentAnalysis, stackAnalysis, stackAnalysisBatch, imageAnalysis, validateToken, generateSbom };
|
|
16
|
-
export { discoverWorkspacePackages, discoverWorkspaceCrates, validatePackageJson, resolveWorkspaceDiscoveryIgnore, filterManifestPathsByDiscoveryIgnore, resolveContinueOnError, resolveBatchMetadata, };
|
|
17
|
+
export { discoverMavenModules, discoverWorkspacePackages, discoverWorkspaceCrates, validatePackageJson, resolveWorkspaceDiscoveryIgnore, filterManifestPathsByDiscoveryIgnore, resolveContinueOnError, resolveBatchMetadata, };
|
|
17
18
|
/**
|
|
18
19
|
* @typedef {{
|
|
19
20
|
* TRUSTIFY_DA_CARGO_PATH?: string | undefined,
|
|
@@ -279,16 +280,23 @@ async function generateOneSbom(manifestPath, workspaceOpts) {
|
|
|
279
280
|
*
|
|
280
281
|
* @param {string} root - Resolved workspace root
|
|
281
282
|
* @param {Options} opts
|
|
282
|
-
* @returns {Promise<{ ecosystem: 'javascript' | 'cargo' | 'unknown', manifestPaths: string[] }>}
|
|
283
|
+
* @returns {Promise<{ ecosystem: 'javascript' | 'cargo' | 'maven' | 'unknown', manifestPaths: string[] }>}
|
|
283
284
|
* @private
|
|
284
285
|
*/
|
|
285
286
|
async function detectWorkspaceManifests(root, opts) {
|
|
286
287
|
const cargoToml = path.join(root, 'Cargo.toml');
|
|
287
288
|
const cargoLock = path.join(root, 'Cargo.lock');
|
|
288
289
|
const packageJson = path.join(root, 'package.json');
|
|
290
|
+
const pomXml = path.join(root, 'pom.xml');
|
|
289
291
|
if (fs.existsSync(cargoToml) && fs.existsSync(cargoLock)) {
|
|
290
292
|
return { ecosystem: 'cargo', manifestPaths: await discoverWorkspaceCrates(root, opts) };
|
|
291
293
|
}
|
|
294
|
+
if (fs.existsSync(pomXml)) {
|
|
295
|
+
const manifestPaths = await discoverMavenModules(root, opts);
|
|
296
|
+
if (manifestPaths.length > 0) {
|
|
297
|
+
return { ecosystem: 'maven', manifestPaths };
|
|
298
|
+
}
|
|
299
|
+
}
|
|
292
300
|
const hasJsLock = fs.existsSync(path.join(root, 'pnpm-lock.yaml'))
|
|
293
301
|
|| fs.existsSync(path.join(root, 'yarn.lock'))
|
|
294
302
|
|| fs.existsSync(path.join(root, 'package-lock.json'));
|
|
@@ -398,12 +406,45 @@ function batchError(message, wantMetadata, metadata) {
|
|
|
398
406
|
}
|
|
399
407
|
return err;
|
|
400
408
|
}
|
|
409
|
+
/**
|
|
410
|
+
* @overload
|
|
411
|
+
* @param {string} workspaceRoot
|
|
412
|
+
* @param {true} html
|
|
413
|
+
* @param {Options & { batchMetadata: true }} opts
|
|
414
|
+
* @returns {Promise<{ analysis: string, metadata: BatchAnalysisMetadata }>}
|
|
415
|
+
* @throws {Error}
|
|
416
|
+
*/
|
|
417
|
+
/**
|
|
418
|
+
* @overload
|
|
419
|
+
* @param {string} workspaceRoot
|
|
420
|
+
* @param {true} html
|
|
421
|
+
* @param {Options & { batchMetadata?: false }} [opts={}]
|
|
422
|
+
* @returns {Promise<string>}
|
|
423
|
+
* @throws {Error}
|
|
424
|
+
*/
|
|
425
|
+
/**
|
|
426
|
+
* @overload
|
|
427
|
+
* @param {string} workspaceRoot
|
|
428
|
+
* @param {false} html
|
|
429
|
+
* @param {Options & { batchMetadata: true }} opts
|
|
430
|
+
* @returns {Promise<{ analysis: Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>, metadata: BatchAnalysisMetadata }>}
|
|
431
|
+
* @throws {Error}
|
|
432
|
+
*/
|
|
433
|
+
/**
|
|
434
|
+
* @overload
|
|
435
|
+
* @param {string} workspaceRoot
|
|
436
|
+
* @param {false} html
|
|
437
|
+
* @param {Options & { batchMetadata?: false }} [opts={}]
|
|
438
|
+
* @returns {Promise<Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>>}
|
|
439
|
+
* @throws {Error}
|
|
440
|
+
*/
|
|
401
441
|
/**
|
|
402
442
|
* Get stack analysis for all workspace packages/crates (batch).
|
|
403
443
|
* Detects ecosystem from workspace root: Cargo (Cargo.toml + Cargo.lock) or JS/TS (package.json + lock file).
|
|
404
444
|
* SBOMs are generated in parallel (see `batchConcurrency`) unless `continueOnError: false` (fail-fast sequential).
|
|
405
445
|
* With `opts.batchMetadata` / `TRUSTIFY_DA_BATCH_METADATA`, returns `{ analysis, metadata }` including validation and SBOM errors.
|
|
406
446
|
*
|
|
447
|
+
* @overload
|
|
407
448
|
* @param {string} workspaceRoot - Path to workspace root (containing lock file and workspace config)
|
|
408
449
|
* @param {boolean} [html=false] - true returns HTML, false returns JSON report
|
|
409
450
|
* @param {Options} [opts={}] - `batchConcurrency`, discovery ignores, `continueOnError` (default true), `batchMetadata` (default false)
|
|
@@ -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,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discover all pom.xml manifest paths in a Maven multi-module project.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} workspaceRoot - Absolute or relative path to workspace root (must contain pom.xml)
|
|
5
|
+
* @param {object} [opts={}]
|
|
6
|
+
* @returns {Promise<string[]>} Paths to pom.xml files (absolute)
|
|
7
|
+
*/
|
|
8
|
+
export function discoverMavenModules(workspaceRoot: string, opts?: object): Promise<string[]>;
|
|
1
9
|
/** @typedef {import('../provider').Provider} */
|
|
2
10
|
/** @typedef {import('../provider').Provided} Provided */
|
|
3
11
|
/** @typedef {{name: string, version: string}} Package */
|
|
@@ -5,7 +5,8 @@ import { EOL } from 'os';
|
|
|
5
5
|
import { XMLParser } from 'fast-xml-parser';
|
|
6
6
|
import { getLicense } from '../license/license_utils.js';
|
|
7
7
|
import Sbom from '../sbom.js';
|
|
8
|
-
import { getCustom } from '../tools.js';
|
|
8
|
+
import { getCustom, invokeCommand } from '../tools.js';
|
|
9
|
+
import { filterManifestPathsByDiscoveryIgnore, resolveWorkspaceDiscoveryIgnore } from '../workspace.js';
|
|
9
10
|
import Base_java, { ecosystem_maven } from "./base_java.js";
|
|
10
11
|
/** @typedef {import('../provider').Provider} */
|
|
11
12
|
/** @typedef {import('../provider').Provided} Provided */
|
|
@@ -289,3 +290,94 @@ export default class Java_maven extends Base_java {
|
|
|
289
290
|
return deps.filter(d => dep.artifactId === d.artifactId && dep.groupId === d.groupId && dep.scope === d.scope).length > 0;
|
|
290
291
|
}
|
|
291
292
|
}
|
|
293
|
+
const DEFAULT_MAVEN_DISCOVERY_IGNORE = [
|
|
294
|
+
'**/target/**',
|
|
295
|
+
];
|
|
296
|
+
/**
|
|
297
|
+
* Discover all pom.xml manifest paths in a Maven multi-module project.
|
|
298
|
+
*
|
|
299
|
+
* @param {string} workspaceRoot - Absolute or relative path to workspace root (must contain pom.xml)
|
|
300
|
+
* @param {object} [opts={}]
|
|
301
|
+
* @returns {Promise<string[]>} Paths to pom.xml files (absolute)
|
|
302
|
+
*/
|
|
303
|
+
export async function discoverMavenModules(workspaceRoot, opts = {}) {
|
|
304
|
+
const root = path.resolve(workspaceRoot);
|
|
305
|
+
const rootPom = path.join(root, 'pom.xml');
|
|
306
|
+
if (!fs.existsSync(rootPom)) {
|
|
307
|
+
return [];
|
|
308
|
+
}
|
|
309
|
+
let mvnBin;
|
|
310
|
+
try {
|
|
311
|
+
mvnBin = new Java_maven().selectToolBinary(rootPom, opts);
|
|
312
|
+
}
|
|
313
|
+
catch {
|
|
314
|
+
return [rootPom];
|
|
315
|
+
}
|
|
316
|
+
const visited = new Set();
|
|
317
|
+
const manifestPaths = [rootPom];
|
|
318
|
+
collectMavenModules(root, mvnBin, visited, manifestPaths);
|
|
319
|
+
const ignorePatterns = [...resolveWorkspaceDiscoveryIgnore(opts), ...DEFAULT_MAVEN_DISCOVERY_IGNORE];
|
|
320
|
+
return filterManifestPathsByDiscoveryIgnore(manifestPaths, root, ignorePatterns);
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* @param {string} dir - Absolute path to directory containing pom.xml
|
|
324
|
+
* @param {string} mvnBin - Maven binary path
|
|
325
|
+
* @param {Set<string>} visited - Already-visited directories (cycle guard)
|
|
326
|
+
* @param {string[]} manifestPaths - Accumulator for discovered pom.xml paths
|
|
327
|
+
*/
|
|
328
|
+
function collectMavenModules(dir, mvnBin, visited, manifestPaths) {
|
|
329
|
+
const resolvedDir = path.resolve(dir);
|
|
330
|
+
if (visited.has(resolvedDir)) {
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
visited.add(resolvedDir);
|
|
334
|
+
const modules = listMavenModules(resolvedDir, mvnBin);
|
|
335
|
+
for (const mod of modules) {
|
|
336
|
+
const moduleDir = path.resolve(resolvedDir, mod);
|
|
337
|
+
const modulePom = path.join(moduleDir, 'pom.xml');
|
|
338
|
+
if (fs.existsSync(modulePom)) {
|
|
339
|
+
manifestPaths.push(modulePom);
|
|
340
|
+
collectMavenModules(moduleDir, mvnBin, visited, manifestPaths);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* @param {string} dir - Directory containing pom.xml
|
|
346
|
+
* @param {string} mvnBin - Maven binary path
|
|
347
|
+
* @returns {string[]} Module directory names (relative to `dir`)
|
|
348
|
+
*/
|
|
349
|
+
function listMavenModules(dir, mvnBin) {
|
|
350
|
+
let output;
|
|
351
|
+
try {
|
|
352
|
+
output = invokeCommand(mvnBin, [
|
|
353
|
+
'help:evaluate',
|
|
354
|
+
'-Dexpression=project.modules',
|
|
355
|
+
'-q',
|
|
356
|
+
'-DforceStdout',
|
|
357
|
+
'-f', path.join(dir, 'pom.xml'),
|
|
358
|
+
'--batch-mode',
|
|
359
|
+
], { cwd: dir });
|
|
360
|
+
}
|
|
361
|
+
catch {
|
|
362
|
+
return [];
|
|
363
|
+
}
|
|
364
|
+
const raw = output.toString().trim();
|
|
365
|
+
if (!raw || raw.startsWith('<modules')) {
|
|
366
|
+
return [];
|
|
367
|
+
}
|
|
368
|
+
return parseMavenModuleList(raw);
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* @param {string} raw - Raw stdout from mvn help:evaluate -DforceStdout
|
|
372
|
+
* @returns {string[]}
|
|
373
|
+
*/
|
|
374
|
+
function parseMavenModuleList(raw) {
|
|
375
|
+
const parser = new XMLParser();
|
|
376
|
+
const parsed = parser.parse(raw);
|
|
377
|
+
const entries = parsed?.strings?.string;
|
|
378
|
+
if (!entries) {
|
|
379
|
+
return [];
|
|
380
|
+
}
|
|
381
|
+
const list = Array.isArray(entries) ? entries : [entries];
|
|
382
|
+
return list.map(s => String(s).trim()).filter(Boolean);
|
|
383
|
+
}
|
|
@@ -12,4 +12,25 @@ export default class Javascript_npm extends Base_javascript {
|
|
|
12
12
|
_updateLockFileCmdArgs() {
|
|
13
13
|
return ['install', '--package-lock-only'];
|
|
14
14
|
}
|
|
15
|
+
_buildDependencyTree(includeTransitive, opts = {}) {
|
|
16
|
+
// npm ls --json returns a single tree rooted at the workspace root.
|
|
17
|
+
// When analyzing a workspace member, its deps are nested under the
|
|
18
|
+
// root's dependencies keyed by the member name — extract that subtree
|
|
19
|
+
// so downstream analysis sees only the member's dependencies.
|
|
20
|
+
const tree = super._buildDependencyTree(includeTransitive, opts);
|
|
21
|
+
const memberName = this._getManifest().name;
|
|
22
|
+
if (tree.name === memberName) {
|
|
23
|
+
return tree;
|
|
24
|
+
}
|
|
25
|
+
const memberEntry = tree.dependencies?.[memberName];
|
|
26
|
+
if (memberEntry) {
|
|
27
|
+
return {
|
|
28
|
+
name: memberName,
|
|
29
|
+
version: memberEntry.version || this._getManifest().version,
|
|
30
|
+
dependencies: memberEntry.dependencies,
|
|
31
|
+
optionalDependencies: memberEntry.optionalDependencies,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
return tree;
|
|
35
|
+
}
|
|
15
36
|
}
|
|
@@ -7,15 +7,19 @@ export default class Javascript_pnpm extends Base_javascript {
|
|
|
7
7
|
return "pnpm";
|
|
8
8
|
}
|
|
9
9
|
_listCmdArgs(includeTransitive) {
|
|
10
|
-
return ['ls', includeTransitive ? '--depth=Infinity' : '--depth=0', '--prod', '--json'];
|
|
10
|
+
return ['ls', includeTransitive ? '--depth=Infinity' : '--depth=0', '--prod', '--json', '-r'];
|
|
11
11
|
}
|
|
12
12
|
_updateLockFileCmdArgs() {
|
|
13
13
|
return ['install', '--frozen-lockfile'];
|
|
14
14
|
}
|
|
15
15
|
_buildDependencyTree(includeTransitive, opts = {}) {
|
|
16
|
+
// pnpm ls --json returns an array with one entry per workspace package.
|
|
17
|
+
// When analyzing a workspace member, find its entry by name instead of
|
|
18
|
+
// blindly taking the first element (which is the workspace root).
|
|
16
19
|
const tree = super._buildDependencyTree(includeTransitive, opts);
|
|
17
20
|
if (Array.isArray(tree) && tree.length > 0) {
|
|
18
|
-
|
|
21
|
+
const memberName = this._getManifest().name;
|
|
22
|
+
return tree.find(pkg => pkg.name === memberName) || tree[0];
|
|
19
23
|
}
|
|
20
24
|
return {};
|
|
21
25
|
}
|
|
@@ -15,7 +15,10 @@ export default class Yarn_berry_processor extends Yarn_processor {
|
|
|
15
15
|
* @returns {string[]} Command arguments for listing dependencies
|
|
16
16
|
*/
|
|
17
17
|
listCmdArgs(includeTransitive) {
|
|
18
|
-
|
|
18
|
+
// --all is needed to include workspace members in the output
|
|
19
|
+
return includeTransitive
|
|
20
|
+
? ['info', '--recursive', '--all', '--json']
|
|
21
|
+
: ['info', '--all', '--json'];
|
|
19
22
|
}
|
|
20
23
|
/**
|
|
21
24
|
* Returns the command arguments for updating the lock file
|
|
@@ -68,7 +71,8 @@ export default class Yarn_berry_processor extends Yarn_processor {
|
|
|
68
71
|
if (!name) {
|
|
69
72
|
return false;
|
|
70
73
|
}
|
|
71
|
-
|
|
74
|
+
// Workspace members use paths like "member-a@workspace:packages/member-a", not just "@workspace:."
|
|
75
|
+
return name.startsWith(`${this._manifest.name}@workspace:`);
|
|
72
76
|
}
|
|
73
77
|
/**
|
|
74
78
|
* Adds dependencies to the SBOM
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @typedef {{name: string, version: string, dependencies: DependencyEntry[]}} DependencyEntry */
|
|
1
|
+
/** @typedef {{name: string, version: string, dependencies: DependencyEntry[], hashes?: Array<{alg: string, content: string}>}} DependencyEntry */
|
|
2
2
|
export default class Python_controller {
|
|
3
3
|
/**
|
|
4
4
|
* Constructor to create new python controller instance to interact with pip package manager
|
|
@@ -31,4 +31,8 @@ export type DependencyEntry = {
|
|
|
31
31
|
name: string;
|
|
32
32
|
version: string;
|
|
33
33
|
dependencies: DependencyEntry[];
|
|
34
|
+
hashes?: Array<{
|
|
35
|
+
alg: string;
|
|
36
|
+
content: string;
|
|
37
|
+
}>;
|
|
34
38
|
};
|
|
@@ -19,7 +19,7 @@ function getPipShowOutput(depNames) {
|
|
|
19
19
|
throw new Error('fail invoking \'pip show\' to fetch metadata for all installed packages in environment', { cause: error });
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
/** @typedef {{name: string, version: string, dependencies: DependencyEntry[]}} DependencyEntry */
|
|
22
|
+
/** @typedef {{name: string, version: string, dependencies: DependencyEntry[], hashes?: Array<{alg: string, content: string}>}} DependencyEntry */
|
|
23
23
|
export default class Python_controller {
|
|
24
24
|
pythonEnvDir;
|
|
25
25
|
pathToPipBin;
|
|
@@ -6,12 +6,13 @@ import { environmentVariableIsPopulated, getCustom, getCustomPath, invokeCommand
|
|
|
6
6
|
import Python_controller from './python_controller.js';
|
|
7
7
|
import { getParser, getIgnoreQuery, getPinnedVersionQuery } from './requirements_parser.js';
|
|
8
8
|
export default { isSupported, validateLockFile, provideComponent, provideStack, readLicenseFromManifest };
|
|
9
|
-
/** @typedef {{name: string, version: string, dependencies: DependencyEntry[]}} DependencyEntry */
|
|
9
|
+
/** @typedef {{name: string, version: string, dependencies: DependencyEntry[], hashes?: Array<{alg: string, content: string}>}} DependencyEntry */
|
|
10
10
|
/**
|
|
11
11
|
* @type {string} ecosystem for python-pip is 'pip'
|
|
12
12
|
* @private
|
|
13
13
|
*/
|
|
14
14
|
const ecosystem = 'pip';
|
|
15
|
+
const NO_SCOPE = undefined;
|
|
15
16
|
/**
|
|
16
17
|
* @param {string} manifestName - the subject manifest name-type
|
|
17
18
|
* @returns {boolean} - return true if `requirements.txt` is the manifest name-type
|
|
@@ -56,7 +57,6 @@ async function provideComponent(manifest, opts = {}) {
|
|
|
56
57
|
contentType: 'application/vnd.cyclonedx+json'
|
|
57
58
|
};
|
|
58
59
|
}
|
|
59
|
-
/** @typedef {{name: string, , version: string, dependencies: DependencyEntry[]}} DependencyEntry */
|
|
60
60
|
/**
|
|
61
61
|
*
|
|
62
62
|
* @param {PackageURL}source
|
|
@@ -66,7 +66,7 @@ async function provideComponent(manifest, opts = {}) {
|
|
|
66
66
|
*/
|
|
67
67
|
function addAllDependencies(source, dep, sbom) {
|
|
68
68
|
let targetPurl = toPurl(dep["name"], dep["version"]);
|
|
69
|
-
sbom.addDependency(source, targetPurl);
|
|
69
|
+
sbom.addDependency(source, targetPurl, NO_SCOPE, dep["hashes"]);
|
|
70
70
|
let directDeps = dep["dependencies"];
|
|
71
71
|
if (directDeps !== undefined && directDeps.length > 0) {
|
|
72
72
|
directDeps.forEach((dependency) => { addAllDependencies(toPurl(dep["name"], dep["version"]), dependency, sbom); });
|
|
@@ -202,7 +202,7 @@ async function getSbomForComponentAnalysis(manifest, opts = {}) {
|
|
|
202
202
|
const license = readLicenseFromManifest(manifest);
|
|
203
203
|
sbom.addRoot(rootPurl, license);
|
|
204
204
|
dependencies.forEach(dep => {
|
|
205
|
-
sbom.addDependency(rootPurl, toPurl(dep.name, dep.version));
|
|
205
|
+
sbom.addDependency(rootPurl, toPurl(dep.name, dep.version), NO_SCOPE, dep.hashes);
|
|
206
206
|
});
|
|
207
207
|
await handleIgnoredDependencies(manifest, sbom, opts);
|
|
208
208
|
// In python there is no root component, then we must remove the dummy root we added, so the sbom json will be accepted by the DA backend
|
|
@@ -1,4 +1,19 @@
|
|
|
1
1
|
export default class Python_poetry extends Base_pyproject {
|
|
2
|
+
/**
|
|
3
|
+
* @param {string} manifestDir
|
|
4
|
+
* @param {string} _workspaceDir - unused (poetry has no workspace support)
|
|
5
|
+
* @param {object} parsed - parsed pyproject.toml
|
|
6
|
+
* @param {Object} opts
|
|
7
|
+
* @returns {Promise<{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}>}
|
|
8
|
+
*/
|
|
9
|
+
_getDependencyData(manifestDir: string, _workspaceDir: string, parsed: object, opts: any): Promise<{
|
|
10
|
+
directDeps: string[];
|
|
11
|
+
graph: Map<string, {
|
|
12
|
+
name: string;
|
|
13
|
+
version: string;
|
|
14
|
+
children: string[];
|
|
15
|
+
}>;
|
|
16
|
+
}>;
|
|
2
17
|
/**
|
|
3
18
|
* Get poetry show --tree output.
|
|
4
19
|
* @param {string} manifestDir
|
|
@@ -1,4 +1,19 @@
|
|
|
1
1
|
export default class Python_uv extends Base_pyproject {
|
|
2
|
+
/**
|
|
3
|
+
* @param {string} manifestDir - directory containing the target pyproject.toml
|
|
4
|
+
* @param {string} workspaceDir - workspace root (for resolving editable install paths)
|
|
5
|
+
* @param {object} parsed - parsed pyproject.toml
|
|
6
|
+
* @param {Object} opts
|
|
7
|
+
* @returns {Promise<{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}>}
|
|
8
|
+
*/
|
|
9
|
+
_getDependencyData(manifestDir: string, workspaceDir: string, parsed: object, opts: any): Promise<{
|
|
10
|
+
directDeps: string[];
|
|
11
|
+
graph: Map<string, {
|
|
12
|
+
name: string;
|
|
13
|
+
version: string;
|
|
14
|
+
children: string[];
|
|
15
|
+
}>;
|
|
16
|
+
}>;
|
|
2
17
|
/**
|
|
3
18
|
* Get the uv export output, either from env var or by running the command.
|
|
4
19
|
* @param {string} manifestDir
|
package/dist/src/sbom.d.ts
CHANGED
|
@@ -25,9 +25,14 @@ export default class Sbom {
|
|
|
25
25
|
/**
|
|
26
26
|
* @param {component} sourceRef current source Component ( Starting from root component by clients)
|
|
27
27
|
* @param {PackageURL} targetRef current dependency to add to Dependencies list of component sourceRef
|
|
28
|
+
* @param {string} [scope] - Scope of the dependency
|
|
29
|
+
* @param {Array<{alg: string, content: string}>} [targetHashes] - Optional hashes for the target component
|
|
28
30
|
* @return Sbom
|
|
29
31
|
*/
|
|
30
|
-
addDependency(sourceRef: component, targetRef: PackageURL, scope
|
|
32
|
+
addDependency(sourceRef: component, targetRef: PackageURL, scope?: string, targetHashes?: Array<{
|
|
33
|
+
alg: string;
|
|
34
|
+
content: string;
|
|
35
|
+
}>): CycloneDxSbom;
|
|
31
36
|
/**
|
|
32
37
|
* @return String sbom json in a string format
|
|
33
38
|
*/
|
|
@@ -45,6 +50,7 @@ export default class Sbom {
|
|
|
45
50
|
version: any;
|
|
46
51
|
scope: any;
|
|
47
52
|
licenses?: any;
|
|
53
|
+
hashes?: any;
|
|
48
54
|
};
|
|
49
55
|
/** This method gets a component object, and a string name, and checks if the name is a substring of the component' purl.
|
|
50
56
|
* @param {} component to search in its dependencies
|
package/dist/src/sbom.js
CHANGED
|
@@ -43,10 +43,12 @@ export default class Sbom {
|
|
|
43
43
|
/**
|
|
44
44
|
* @param {component} sourceRef current source Component ( Starting from root component by clients)
|
|
45
45
|
* @param {PackageURL} targetRef current dependency to add to Dependencies list of component sourceRef
|
|
46
|
+
* @param {string} [scope] - Scope of the dependency
|
|
47
|
+
* @param {Array<{alg: string, content: string}>} [targetHashes] - Optional hashes for the target component
|
|
46
48
|
* @return Sbom
|
|
47
49
|
*/
|
|
48
|
-
addDependency(sourceRef, targetRef, scope) {
|
|
49
|
-
return this.sbomModel.addDependency(sourceRef, targetRef, scope);
|
|
50
|
+
addDependency(sourceRef, targetRef, scope, targetHashes) {
|
|
51
|
+
return this.sbomModel.addDependency(sourceRef, targetRef, scope, targetHashes);
|
|
50
52
|
}
|
|
51
53
|
/**
|
|
52
54
|
* @return String sbom json in a string format
|
package/dist/src/tools.d.ts
CHANGED
|
@@ -61,6 +61,22 @@ export function toPurlFromString(strPurl: any): PackageURL | null;
|
|
|
61
61
|
* @param {string} cwd - directory for which to find the root of the git repository.
|
|
62
62
|
*/
|
|
63
63
|
export function getGitRootDir(cwd: string): string | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* Normalize a filesystem path, lowercasing on Windows for case-insensitive comparison.
|
|
66
|
+
*
|
|
67
|
+
* @param {string} thePath
|
|
68
|
+
* @returns {string}
|
|
69
|
+
*/
|
|
70
|
+
export function normalizePath(thePath: string): string;
|
|
71
|
+
/**
|
|
72
|
+
* Walk up from `startDir` to `repoRoot` looking for an executable wrapper script.
|
|
73
|
+
*
|
|
74
|
+
* @param {string} startDir - Absolute directory to start from
|
|
75
|
+
* @param {string} wrapperName - Wrapper filename (e.g. `mvnw`, `gradlew`)
|
|
76
|
+
* @param {string} [repoRoot] - Stop boundary (defaults to git root or filesystem root)
|
|
77
|
+
* @returns {string | undefined}
|
|
78
|
+
*/
|
|
79
|
+
export function traverseForWrapper(startDir: string, wrapperName: string, repoRoot?: string): string | undefined;
|
|
64
80
|
/** this method invokes command string in a process in a synchronous way.
|
|
65
81
|
* @param {string} bin - the command to be invoked
|
|
66
82
|
* @param {Array<string>} args - the args to pass to the binary
|
package/dist/src/tools.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { execFileSync } from "child_process";
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
2
4
|
import { EOL } from "os";
|
|
3
5
|
import { HttpsProxyAgent } from "https-proxy-agent";
|
|
4
6
|
import { PackageURL } from "packageurl-js";
|
|
@@ -128,6 +130,44 @@ export function getGitRootDir(cwd) {
|
|
|
128
130
|
return undefined;
|
|
129
131
|
}
|
|
130
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Normalize a filesystem path, lowercasing on Windows for case-insensitive comparison.
|
|
135
|
+
*
|
|
136
|
+
* @param {string} thePath
|
|
137
|
+
* @returns {string}
|
|
138
|
+
*/
|
|
139
|
+
export function normalizePath(thePath) {
|
|
140
|
+
const normalized = path.resolve(thePath).normalize();
|
|
141
|
+
return process.platform === 'win32' ? normalized.toLowerCase() : normalized;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Walk up from `startDir` to `repoRoot` looking for an executable wrapper script.
|
|
145
|
+
*
|
|
146
|
+
* @param {string} startDir - Absolute directory to start from
|
|
147
|
+
* @param {string} wrapperName - Wrapper filename (e.g. `mvnw`, `gradlew`)
|
|
148
|
+
* @param {string} [repoRoot] - Stop boundary (defaults to git root or filesystem root)
|
|
149
|
+
* @returns {string | undefined}
|
|
150
|
+
*/
|
|
151
|
+
export function traverseForWrapper(startDir, wrapperName, repoRoot = undefined) {
|
|
152
|
+
const currentDir = normalizePath(startDir);
|
|
153
|
+
repoRoot = repoRoot || getGitRootDir(currentDir) || path.parse(currentDir).root;
|
|
154
|
+
const wrapperPath = path.join(currentDir, wrapperName);
|
|
155
|
+
try {
|
|
156
|
+
fs.accessSync(wrapperPath, fs.constants.X_OK);
|
|
157
|
+
return wrapperPath;
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
const rootDir = path.parse(currentDir).root;
|
|
161
|
+
if (currentDir === repoRoot || currentDir === rootDir) {
|
|
162
|
+
return undefined;
|
|
163
|
+
}
|
|
164
|
+
const parentDir = path.dirname(currentDir);
|
|
165
|
+
if (parentDir === currentDir || parentDir === rootDir) {
|
|
166
|
+
return undefined;
|
|
167
|
+
}
|
|
168
|
+
return traverseForWrapper(parentDir, wrapperName, repoRoot);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
131
171
|
/** this method invokes command string in a process in a synchronous way.
|
|
132
172
|
* @param {string} bin - the command to be invoked
|
|
133
173
|
* @param {Array<string>} args - the args to pass to the binary
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trustify-da/trustify-da-javascript-client",
|
|
3
|
-
"version": "0.3.0-ea.
|
|
3
|
+
"version": "0.3.0-ea.5348b9e",
|
|
4
4
|
"description": "Code-Ready Dependency Analytics JavaScript API.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/guacsec/trustify-da-javascript-client#README.md",
|