@trustify-da/trustify-da-javascript-client 0.3.0-ea.2ea1d77 → 0.3.0-ea.38515a7
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/README.md +73 -8
- package/dist/package.json +6 -5
- package/dist/src/analysis.d.ts +2 -0
- package/dist/src/analysis.js +7 -4
- package/dist/src/cyclone_dx_sbom.d.ts +7 -0
- package/dist/src/cyclone_dx_sbom.js +14 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +2 -0
- package/dist/src/oci_image/utils.js +11 -2
- package/dist/src/provider.js +4 -0
- package/dist/src/providers/base_javascript.d.ts +17 -7
- package/dist/src/providers/base_javascript.js +90 -17
- package/dist/src/providers/base_pyproject.d.ts +147 -0
- package/dist/src/providers/base_pyproject.js +279 -0
- package/dist/src/providers/golang_gomodules.d.ts +12 -12
- package/dist/src/providers/golang_gomodules.js +100 -111
- package/dist/src/providers/gomod_parser.d.ts +4 -0
- package/dist/src/providers/gomod_parser.js +16 -0
- package/dist/src/providers/manifest.d.ts +2 -0
- package/dist/src/providers/manifest.js +22 -4
- package/dist/src/providers/processors/yarn_berry_processor.js +82 -3
- package/dist/src/providers/python_pip.js +1 -1
- package/dist/src/providers/python_poetry.d.ts +42 -0
- package/dist/src/providers/python_poetry.js +146 -0
- package/dist/src/providers/python_uv.d.ts +26 -0
- package/dist/src/providers/python_uv.js +118 -0
- package/dist/src/providers/tree-sitter-gomod.wasm +0 -0
- package/dist/src/sbom.d.ts +7 -0
- package/dist/src/sbom.js +9 -0
- package/package.json +7 -6
package/README.md
CHANGED
|
@@ -224,7 +224,8 @@ $ trustify-da-javascript-client license /path/to/package.json
|
|
|
224
224
|
<li><a href="https://www.javascript.com/">JavaScript</a> - <a href="https://pnpm.io/">pnpm</a></li>
|
|
225
225
|
<li><a href="https://www.javascript.com/">JavaScript</a> - <a href="https://classic.yarnpkg.com/">Yarn Classic</a> / <a href="https://yarnpkg.com/">Yarn Berry</a></li>
|
|
226
226
|
<li><a href="https://go.dev/">Golang</a> - <a href="https://go.dev/blog/using-go-modules/">Go Modules</a></li>
|
|
227
|
-
<li><a href="https://www.python.org/">Python</a> - <a href="https://pypi.org/project/pip/">pip Installer</a
|
|
227
|
+
<li><a href="https://www.python.org/">Python</a> - <a href="https://pypi.org/project/pip/">pip Installer</a> (<code>requirements.txt</code>)</li>
|
|
228
|
+
<li><a href="https://www.python.org/">Python</a> - <a href="https://python-poetry.org/">Poetry</a> / <a href="https://docs.astral.sh/uv/">uv</a> (<code>pyproject.toml</code>)</li>
|
|
228
229
|
<li><a href="https://gradle.org/">Gradle (Groovy and Kotlin DSL)</a> - <a href="https://gradle.org/install/">Gradle Installation</a></li>
|
|
229
230
|
<li><a href="https://www.rust-lang.org/">Rust</a> - <a href="https://doc.rust-lang.org/cargo/">Cargo</a></li>
|
|
230
231
|
</ul>
|
|
@@ -287,8 +288,11 @@ Excluding a package from any analysis can be achieved by marking the package for
|
|
|
287
288
|
]
|
|
288
289
|
}
|
|
289
290
|
```
|
|
291
|
+
</li>
|
|
292
|
+
|
|
293
|
+
<li>
|
|
294
|
+
<em>Golang</em> users can add in go.mod a comment with <code>// exhortignore</code> next to the package to be ignored, or to "piggyback" on existing comment ( e.g - <code>// indirect</code>), for example:
|
|
290
295
|
|
|
291
|
-
<em>Golang</em> users can add in go.mod a comment with //exhortignore next to the package to be ignored, or to "piggyback" on existing comment ( e.g - //indirect) , for example:
|
|
292
296
|
```go
|
|
293
297
|
module github.com/trustify-da/SaaSi/deployer
|
|
294
298
|
|
|
@@ -297,7 +301,7 @@ go 1.19
|
|
|
297
301
|
require (
|
|
298
302
|
github.com/gin-gonic/gin v1.9.1
|
|
299
303
|
github.com/google/uuid v1.1.2
|
|
300
|
-
github.com/jessevdk/go-flags v1.5.0 //exhortignore
|
|
304
|
+
github.com/jessevdk/go-flags v1.5.0 // exhortignore
|
|
301
305
|
github.com/kr/pretty v0.3.1
|
|
302
306
|
gopkg.in/yaml.v2 v2.4.0
|
|
303
307
|
k8s.io/apimachinery v0.26.1
|
|
@@ -305,14 +309,20 @@ require (
|
|
|
305
309
|
)
|
|
306
310
|
|
|
307
311
|
require (
|
|
308
|
-
github.com/davecgh/go-spew v1.1.1 // indirect exhortignore
|
|
312
|
+
github.com/davecgh/go-spew v1.1.1 // indirect; exhortignore
|
|
309
313
|
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
|
|
310
|
-
github.com/go-logr/logr v1.2.3 // indirect
|
|
314
|
+
github.com/go-logr/logr v1.2.3 // indirect; exhortignore
|
|
311
315
|
|
|
312
316
|
)
|
|
313
317
|
```
|
|
314
318
|
|
|
319
|
+
<b>NOTE</b>: It is important to format <code>exhortignore</code> markers on indirect dependencies as shown above, otherwise the Go tooling (as well as this library) may incorrectly parse dependencies marked as indirect as being direct dependencies instead.
|
|
320
|
+
</li>
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
<li>
|
|
315
324
|
<em>Python pip</em> users can add in requirements.txt a comment with #exhortignore(or # exhortignore) to the right of the same artifact to be ignored, for example:
|
|
325
|
+
|
|
316
326
|
```properties
|
|
317
327
|
anyio==3.6.2
|
|
318
328
|
asgiref==3.4.1
|
|
@@ -343,11 +353,14 @@ Werkzeug==2.0.3
|
|
|
343
353
|
zipp==3.6.0
|
|
344
354
|
|
|
345
355
|
```
|
|
356
|
+
</li>
|
|
346
357
|
|
|
358
|
+
<li>
|
|
347
359
|
<em>Gradle</em> users can add in build.gradle a comment with //exhortignore next to the package to be ignored:
|
|
360
|
+
|
|
348
361
|
```build.gradle
|
|
349
362
|
plugins {
|
|
350
|
-
id 'java'
|
|
363
|
+
id 'java'
|
|
351
364
|
}
|
|
352
365
|
|
|
353
366
|
group = 'groupName'
|
|
@@ -379,9 +392,31 @@ version = "1.10"
|
|
|
379
392
|
log = "0.4" # trustify-da-ignore
|
|
380
393
|
```
|
|
381
394
|
|
|
382
|
-
All of the 6 above examples are valid for marking a package to be ignored
|
|
383
|
-
</li>
|
|
384
395
|
|
|
396
|
+
<em>Python pyproject.toml</em> users can add a comment with <code>#exhortignore</code> (or <code># trustify-da-ignore</code>) next to the dependency in <code>pyproject.toml</code>.
|
|
397
|
+
|
|
398
|
+
PEP 621 style (<code>[project]</code> dependencies):
|
|
399
|
+
```toml
|
|
400
|
+
[project]
|
|
401
|
+
dependencies = [
|
|
402
|
+
"flask>=2.0.3",
|
|
403
|
+
"requests>=2.25.1",
|
|
404
|
+
"uvicorn>=0.17.0", #exhortignore
|
|
405
|
+
"click>=8.0.4", # trustify-da-ignore
|
|
406
|
+
]
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
Poetry style (<code>[tool.poetry.dependencies]</code>):
|
|
410
|
+
```toml
|
|
411
|
+
[tool.poetry.dependencies]
|
|
412
|
+
flask = "^2.0.3"
|
|
413
|
+
requests = "^2.25.1"
|
|
414
|
+
uvicorn = "^0.17.0" #exhortignore
|
|
415
|
+
click = "^8.0.4" # trustify-da-ignore
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
All of the above examples are valid for marking a package to be ignored
|
|
419
|
+
</li>
|
|
385
420
|
</ul>
|
|
386
421
|
|
|
387
422
|
<h3>Customization</h3>
|
|
@@ -410,6 +445,8 @@ let options = {
|
|
|
410
445
|
'TRUSTIFY_DA_PIP3_PATH' : '/path/to/pip3',
|
|
411
446
|
'TRUSTIFY_DA_PYTHON_PATH' : '/path/to/python',
|
|
412
447
|
'TRUSTIFY_DA_PIP_PATH' : '/path/to/pip',
|
|
448
|
+
'TRUSTIFY_DA_UV_PATH' : '/path/to/uv',
|
|
449
|
+
'TRUSTIFY_DA_POETRY_PATH' : '/path/to/poetry',
|
|
413
450
|
'TRUSTIFY_DA_GRADLE_PATH' : '/path/to/gradle',
|
|
414
451
|
'TRUSTIFY_DA_CARGO_PATH' : '/path/to/cargo',
|
|
415
452
|
// Workspace root for monorepos (Cargo, npm/pnpm/yarn); lock file expected here
|
|
@@ -556,6 +593,16 @@ following keys for setting custom paths for the said executables.
|
|
|
556
593
|
<td>TRUSTIFY_DA_CARGO_PATH</td>
|
|
557
594
|
</tr>
|
|
558
595
|
<tr>
|
|
596
|
+
<td><a href="https://docs.astral.sh/uv/">uv</a></td>
|
|
597
|
+
<td><em>uv</em></td>
|
|
598
|
+
<td>TRUSTIFY_DA_UV_PATH</td>
|
|
599
|
+
</tr>
|
|
600
|
+
<tr>
|
|
601
|
+
<td><a href="https://python-poetry.org/">Poetry</a></td>
|
|
602
|
+
<td><em>poetry</em></td>
|
|
603
|
+
<td>TRUSTIFY_DA_POETRY_PATH</td>
|
|
604
|
+
</tr>
|
|
605
|
+
<tr>
|
|
559
606
|
<td>Workspace root (monorepos)</td>
|
|
560
607
|
<td>—</td>
|
|
561
608
|
<td>workspaceDir / TRUSTIFY_DA_WORKSPACE_DIR</td>
|
|
@@ -608,6 +655,24 @@ TRUSTIFY_DA_GO_MVS_LOGIC_ENABLED=false
|
|
|
608
655
|
|
|
609
656
|
#### Python Support
|
|
610
657
|
|
|
658
|
+
The client supports two Python manifest formats:
|
|
659
|
+
|
|
660
|
+
- **`requirements.txt`** — uses pip/pip3 to resolve dependencies
|
|
661
|
+
- **`pyproject.toml`** — uses [uv](https://docs.astral.sh/uv/) or [Poetry](https://python-poetry.org/) to resolve dependencies
|
|
662
|
+
|
|
663
|
+
##### pyproject.toml
|
|
664
|
+
|
|
665
|
+
For `pyproject.toml` projects, the client detects which tool manages the project by checking for lock files:
|
|
666
|
+
- If `poetry.lock` is present and `[tool.poetry]` is defined, **Poetry** is used (`poetry show --tree` and `poetry show --all`)
|
|
667
|
+
- If `uv.lock` is present, **uv** is used (`uv export --format requirements.txt --frozen --no-hashes`)
|
|
668
|
+
- If neither lock file is found, an error is thrown
|
|
669
|
+
|
|
670
|
+
Both PEP 621 (`[project]` dependencies) and Poetry-style (`[tool.poetry.dependencies]`) are supported.
|
|
671
|
+
|
|
672
|
+
Custom executable paths can be set via `TRUSTIFY_DA_UV_PATH` and `TRUSTIFY_DA_POETRY_PATH`.
|
|
673
|
+
|
|
674
|
+
##### requirements.txt
|
|
675
|
+
|
|
611
676
|
By default, For python support, the api assumes that the package is installed using the pip/pip3 binary on the system PATH, or using the customized
|
|
612
677
|
Binaries passed to environment variables. In any case, If the package is not installed , then an error will be thrown.
|
|
613
678
|
|
package/dist/package.json
CHANGED
|
@@ -38,13 +38,13 @@
|
|
|
38
38
|
"lint": "eslint src test --ext js",
|
|
39
39
|
"lint:fix": "eslint src test --ext js --fix",
|
|
40
40
|
"test": "c8 npm run tests",
|
|
41
|
-
"tests": "mocha --config .mocharc.json
|
|
41
|
+
"tests": "mocha --config .mocharc.json",
|
|
42
42
|
"tests:rep": "mocha --reporter-option maxDiffSize=0 --reporter json > unit-tests-result.json",
|
|
43
|
-
"pretest": "cp node_modules/tree-sitter-requirements/tree-sitter-requirements.wasm src/providers/tree-sitter-requirements.wasm",
|
|
43
|
+
"pretest": "cp node_modules/tree-sitter-requirements/tree-sitter-requirements.wasm src/providers/tree-sitter-requirements.wasm && cp node_modules/tree-sitter-gomod/tree-sitter-gomod.wasm src/providers/tree-sitter-gomod.wasm",
|
|
44
44
|
"precompile": "rm -rf dist",
|
|
45
45
|
"compile": "tsc -p tsconfig.json",
|
|
46
46
|
"compile:dev": "tsc -p tsconfig.dev.json",
|
|
47
|
-
"postcompile": "cp node_modules/tree-sitter-requirements/tree-sitter-requirements.wasm dist/src/providers/tree-sitter-requirements.wasm"
|
|
47
|
+
"postcompile": "cp node_modules/tree-sitter-requirements/tree-sitter-requirements.wasm dist/src/providers/tree-sitter-requirements.wasm && cp node_modules/tree-sitter-gomod/tree-sitter-gomod.wasm dist/src/providers/tree-sitter-gomod.wasm"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@babel/core": "^7.23.2",
|
|
@@ -58,11 +58,12 @@
|
|
|
58
58
|
"js-yaml": "^4.1.1",
|
|
59
59
|
"micromatch": "^4.0.8",
|
|
60
60
|
"node-fetch": "^3.3.2",
|
|
61
|
-
"p-limit": "^
|
|
61
|
+
"p-limit": "^4.0.0",
|
|
62
62
|
"packageurl-js": "~1.0.2",
|
|
63
63
|
"smol-toml": "^1.6.0",
|
|
64
|
+
"tree-sitter-gomod": "github:strum355/tree-sitter-go-mod#56326f2ad478892ace58ff247a97d492a3cbcdda",
|
|
64
65
|
"tree-sitter-requirements": "github:Strum355/tree-sitter-requirements#d0261ee76b84253997fe70d7d397e78c006c3801",
|
|
65
|
-
"web-tree-sitter": "^0.26.
|
|
66
|
+
"web-tree-sitter": "^0.26.7",
|
|
66
67
|
"yargs": "^18.0.0"
|
|
67
68
|
},
|
|
68
69
|
"devDependencies": {
|
package/dist/src/analysis.d.ts
CHANGED
package/dist/src/analysis.js
CHANGED
|
@@ -4,6 +4,8 @@ import { EOL } from "os";
|
|
|
4
4
|
import { runLicenseCheck } from "./license/index.js";
|
|
5
5
|
import { generateImageSBOM, parseImageRef } from "./oci_image/utils.js";
|
|
6
6
|
import { addProxyAgent, getCustom, getTokenHeaders, TRUSTIFY_DA_OPERATION_TYPE_HEADER, TRUSTIFY_DA_PACKAGE_MANAGER_HEADER } from "./tools.js";
|
|
7
|
+
/** Media type for CycloneDX JSON batch payloads (batch-analysis API). */
|
|
8
|
+
export const CYCLONEDX_JSON_MEDIA_TYPE = 'application/vnd.cyclonedx+json';
|
|
7
9
|
export default { requestComponent, requestStack, requestStackBatch, requestImages, validateToken };
|
|
8
10
|
/**
|
|
9
11
|
* Send a stack analysis request and get the report as 'text/html' or 'application/json'.
|
|
@@ -141,7 +143,7 @@ async function requestStackBatch(sbomByPurl, url, html = false, opts = {}) {
|
|
|
141
143
|
method: 'POST',
|
|
142
144
|
headers: {
|
|
143
145
|
'Accept': html ? 'text/html' : 'application/json',
|
|
144
|
-
'Content-Type':
|
|
146
|
+
'Content-Type': CYCLONEDX_JSON_MEDIA_TYPE,
|
|
145
147
|
...getTokenHeaders(opts)
|
|
146
148
|
},
|
|
147
149
|
body: JSON.stringify(sbomByPurl)
|
|
@@ -187,15 +189,16 @@ async function requestImages(imageRefs, url, html = false, opts = {}) {
|
|
|
187
189
|
if (opts['TRUSTIFY_DA_RECOMMENDATIONS_ENABLED'] === 'false') {
|
|
188
190
|
finalUrl.searchParams.append('recommend', 'false');
|
|
189
191
|
}
|
|
190
|
-
const
|
|
192
|
+
const fetchOptions = addProxyAgent({
|
|
191
193
|
method: 'POST',
|
|
192
194
|
headers: {
|
|
193
195
|
'Accept': html ? 'text/html' : 'application/json',
|
|
194
|
-
'Content-Type':
|
|
196
|
+
'Content-Type': CYCLONEDX_JSON_MEDIA_TYPE,
|
|
195
197
|
...getTokenHeaders(opts)
|
|
196
198
|
},
|
|
197
199
|
body: JSON.stringify(imageSboms),
|
|
198
|
-
});
|
|
200
|
+
}, opts);
|
|
201
|
+
const resp = await fetch(finalUrl, fetchOptions);
|
|
199
202
|
if (resp.status === 200) {
|
|
200
203
|
let result;
|
|
201
204
|
if (!html) {
|
|
@@ -70,6 +70,13 @@ export default class CycloneDxSbom {
|
|
|
70
70
|
* @return {boolean}
|
|
71
71
|
*/
|
|
72
72
|
checkIfPackageInsideDependsOnList(component: any, name: string): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Checks if any entry in the dependsOn list of sourceRef starts with the given purl prefix.
|
|
75
|
+
* @param {PackageURL} sourceRef - The source component
|
|
76
|
+
* @param {string} purlPrefix - The purl prefix to match (e.g. "pkg:npm/minimist@")
|
|
77
|
+
* @return {boolean}
|
|
78
|
+
*/
|
|
79
|
+
checkDependsOnByPurlPrefix(sourceRef: PackageURL, purlPrefix: string): boolean;
|
|
73
80
|
/** Removes the root component from the sbom
|
|
74
81
|
*/
|
|
75
82
|
removeRootComponent(): void;
|
|
@@ -242,6 +242,20 @@ export default class CycloneDxSbom {
|
|
|
242
242
|
return false;
|
|
243
243
|
}
|
|
244
244
|
}
|
|
245
|
+
/**
|
|
246
|
+
* Checks if any entry in the dependsOn list of sourceRef starts with the given purl prefix.
|
|
247
|
+
* @param {PackageURL} sourceRef - The source component
|
|
248
|
+
* @param {string} purlPrefix - The purl prefix to match (e.g. "pkg:npm/minimist@")
|
|
249
|
+
* @return {boolean}
|
|
250
|
+
*/
|
|
251
|
+
checkDependsOnByPurlPrefix(sourceRef, purlPrefix) {
|
|
252
|
+
const sourcePurl = sourceRef.toString();
|
|
253
|
+
const depIndex = this.getDependencyIndex(sourcePurl);
|
|
254
|
+
if (depIndex < 0) {
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
return this.dependencies[depIndex].dependsOn.some(dep => dep.startsWith(purlPrefix));
|
|
258
|
+
}
|
|
245
259
|
/** Removes the root component from the sbom
|
|
246
260
|
*/
|
|
247
261
|
removeRootComponent() {
|
package/dist/src/index.d.ts
CHANGED
|
@@ -64,6 +64,8 @@ export type Options = {
|
|
|
64
64
|
TRUSTIFY_DA_CONTINUE_ON_ERROR?: string | undefined;
|
|
65
65
|
batchMetadata?: boolean | undefined;
|
|
66
66
|
TRUSTIFY_DA_BATCH_METADATA?: string | undefined;
|
|
67
|
+
TRUSTIFY_DA_UV_PATH?: string | undefined;
|
|
68
|
+
TRUSTIFY_DA_POETRY_PATH?: string | undefined;
|
|
67
69
|
[key: string]: string | number | boolean | string[] | undefined;
|
|
68
70
|
};
|
|
69
71
|
export type BatchAnalysisMetadata = {
|
package/dist/src/index.js
CHANGED
|
@@ -56,6 +56,8 @@ export { discoverWorkspacePackages, discoverWorkspaceCrates, validatePackageJson
|
|
|
56
56
|
* TRUSTIFY_DA_CONTINUE_ON_ERROR?: string | undefined,
|
|
57
57
|
* batchMetadata?: boolean | undefined,
|
|
58
58
|
* TRUSTIFY_DA_BATCH_METADATA?: string | undefined,
|
|
59
|
+
* TRUSTIFY_DA_UV_PATH?: string | undefined,
|
|
60
|
+
* TRUSTIFY_DA_POETRY_PATH?: string | undefined,
|
|
59
61
|
* [key: string]: string | number | boolean | string[] | undefined,
|
|
60
62
|
* }} Options
|
|
61
63
|
*/
|
|
@@ -135,7 +135,7 @@ function execSyft(imageRef, opts = {}) {
|
|
|
135
135
|
function getSyftEnvs(dockerPath, podmanPath) {
|
|
136
136
|
let path = null;
|
|
137
137
|
if (dockerPath && podmanPath) {
|
|
138
|
-
path = `${dockerPath}${
|
|
138
|
+
path = `${dockerPath}${delimiter}${podmanPath}`;
|
|
139
139
|
}
|
|
140
140
|
else if (dockerPath) {
|
|
141
141
|
path = dockerPath;
|
|
@@ -276,7 +276,16 @@ function podmanGetVariant(opts = {}) {
|
|
|
276
276
|
* @returns {string} - The information
|
|
277
277
|
*/
|
|
278
278
|
function dockerPodmanInfo(dockerSupplier, podmanSupplier, opts = {}) {
|
|
279
|
-
|
|
279
|
+
try {
|
|
280
|
+
const result = dockerSupplier(opts);
|
|
281
|
+
if (result) {
|
|
282
|
+
return result;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
catch (_) {
|
|
286
|
+
// docker not available, fall through to podman
|
|
287
|
+
}
|
|
288
|
+
return podmanSupplier(opts);
|
|
280
289
|
}
|
|
281
290
|
/**
|
|
282
291
|
* Gets the digests for an image
|
package/dist/src/provider.js
CHANGED
|
@@ -7,6 +7,8 @@ import Javascript_npm from './providers/javascript_npm.js';
|
|
|
7
7
|
import Javascript_pnpm from './providers/javascript_pnpm.js';
|
|
8
8
|
import Javascript_yarn from './providers/javascript_yarn.js';
|
|
9
9
|
import pythonPipProvider from './providers/python_pip.js';
|
|
10
|
+
import Python_poetry from './providers/python_poetry.js';
|
|
11
|
+
import Python_uv from './providers/python_uv.js';
|
|
10
12
|
import rustCargoProvider from './providers/rust_cargo.js';
|
|
11
13
|
/** @typedef {{ecosystem: string, contentType: string, content: string}} Provided */
|
|
12
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 */
|
|
@@ -23,6 +25,8 @@ export const availableProviders = [
|
|
|
23
25
|
new Javascript_npm(),
|
|
24
26
|
golangGomodulesProvider,
|
|
25
27
|
pythonPipProvider,
|
|
28
|
+
new Python_poetry(),
|
|
29
|
+
new Python_uv(),
|
|
26
30
|
rustCargoProvider
|
|
27
31
|
];
|
|
28
32
|
/**
|
|
@@ -67,16 +67,26 @@ export default class Base_javascript {
|
|
|
67
67
|
*/
|
|
68
68
|
isSupported(manifestName: string): boolean;
|
|
69
69
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
70
|
+
* Walks up the directory tree from manifestDir looking for the lock file.
|
|
71
|
+
* Stops when the lock file is found, when a package.json with a "workspaces"
|
|
72
|
+
* field is encountered without a lock file (workspace root boundary), or
|
|
73
|
+
* when the filesystem root is reached.
|
|
74
|
+
*
|
|
75
|
+
* When TRUSTIFY_DA_WORKSPACE_DIR is set, checks only that directory (no walk-up).
|
|
76
|
+
*
|
|
77
|
+
* @param {string} manifestDir - The directory to start searching from
|
|
78
|
+
* @param {Object} [opts={}] - optional; may contain TRUSTIFY_DA_WORKSPACE_DIR
|
|
79
|
+
* @returns {string|null} The directory containing the lock file, or null
|
|
80
|
+
* @protected
|
|
81
|
+
*/
|
|
82
|
+
protected _isWorkspaceRoot(dir: any): string | null;
|
|
83
|
+
_findLockFileDir(manifestDir: any, opts?: {}): string | null;
|
|
84
|
+
/**
|
|
73
85
|
* @param {string} manifestDir - The base directory where the manifest is located
|
|
74
|
-
* @param {
|
|
86
|
+
* @param {Object} [opts={}] - optional; may contain TRUSTIFY_DA_WORKSPACE_DIR
|
|
75
87
|
* @returns {boolean} True if the lock file exists
|
|
76
88
|
*/
|
|
77
|
-
validateLockFile(manifestDir: string, opts?:
|
|
78
|
-
TRUSTIFY_DA_WORKSPACE_DIR?: string;
|
|
79
|
-
}): boolean;
|
|
89
|
+
validateLockFile(manifestDir: string, opts?: any): boolean;
|
|
80
90
|
/**
|
|
81
91
|
* Provides content and content type for stack analysis
|
|
82
92
|
* @param {string} manifestPath - The manifest path or name
|
|
@@ -97,18 +97,63 @@ export default class Base_javascript {
|
|
|
97
97
|
return 'package.json' === manifestName;
|
|
98
98
|
}
|
|
99
99
|
/**
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
100
|
+
* Walks up the directory tree from manifestDir looking for the lock file.
|
|
101
|
+
* Stops when the lock file is found, when a package.json with a "workspaces"
|
|
102
|
+
* field is encountered without a lock file (workspace root boundary), or
|
|
103
|
+
* when the filesystem root is reached.
|
|
104
|
+
*
|
|
105
|
+
* When TRUSTIFY_DA_WORKSPACE_DIR is set, checks only that directory (no walk-up).
|
|
106
|
+
*
|
|
107
|
+
* @param {string} manifestDir - The directory to start searching from
|
|
108
|
+
* @param {Object} [opts={}] - optional; may contain TRUSTIFY_DA_WORKSPACE_DIR
|
|
109
|
+
* @returns {string|null} The directory containing the lock file, or null
|
|
110
|
+
* @protected
|
|
111
|
+
*/
|
|
112
|
+
_isWorkspaceRoot(dir) {
|
|
113
|
+
if (fs.existsSync(path.join(dir, 'pnpm-workspace.yaml'))) {
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
const pkgJsonPath = path.join(dir, 'package.json');
|
|
117
|
+
if (fs.existsSync(pkgJsonPath)) {
|
|
118
|
+
try {
|
|
119
|
+
const content = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf-8'));
|
|
120
|
+
if (content.workspaces) {
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
catch (_) {
|
|
125
|
+
// ignore parse errors
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
_findLockFileDir(manifestDir, opts = {}) {
|
|
131
|
+
const workspaceDir = getCustom('TRUSTIFY_DA_WORKSPACE_DIR', null, opts);
|
|
132
|
+
if (workspaceDir) {
|
|
133
|
+
const dir = path.resolve(workspaceDir);
|
|
134
|
+
return fs.existsSync(path.join(dir, this._lockFileName())) ? dir : null;
|
|
135
|
+
}
|
|
136
|
+
let dir = path.resolve(manifestDir);
|
|
137
|
+
let parent = dir;
|
|
138
|
+
do {
|
|
139
|
+
dir = parent;
|
|
140
|
+
if (fs.existsSync(path.join(dir, this._lockFileName()))) {
|
|
141
|
+
return dir;
|
|
142
|
+
}
|
|
143
|
+
if (this._isWorkspaceRoot(dir)) {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
parent = path.dirname(dir);
|
|
147
|
+
} while (parent !== dir);
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
103
151
|
* @param {string} manifestDir - The base directory where the manifest is located
|
|
104
|
-
* @param {
|
|
152
|
+
* @param {Object} [opts={}] - optional; may contain TRUSTIFY_DA_WORKSPACE_DIR
|
|
105
153
|
* @returns {boolean} True if the lock file exists
|
|
106
154
|
*/
|
|
107
155
|
validateLockFile(manifestDir, opts = {}) {
|
|
108
|
-
|
|
109
|
-
const dirToCheck = workspaceDir ? path.resolve(workspaceDir) : manifestDir;
|
|
110
|
-
const lock = path.join(dirToCheck, this._lockFileName());
|
|
111
|
-
return fs.existsSync(lock);
|
|
156
|
+
return this._findLockFileDir(manifestDir, opts) !== null;
|
|
112
157
|
}
|
|
113
158
|
/**
|
|
114
159
|
* Provides content and content type for stack analysis
|
|
@@ -171,8 +216,7 @@ export default class Base_javascript {
|
|
|
171
216
|
_buildDependencyTree(includeTransitive, opts = {}) {
|
|
172
217
|
this._version();
|
|
173
218
|
const manifestDir = path.dirname(this.#manifest.manifestPath);
|
|
174
|
-
const
|
|
175
|
-
const cmdDir = workspaceDir ? path.resolve(workspaceDir) : manifestDir;
|
|
219
|
+
const cmdDir = this._findLockFileDir(manifestDir, opts) || manifestDir;
|
|
176
220
|
this.#createLockFile(cmdDir);
|
|
177
221
|
let output = this.#executeListCmd(includeTransitive, cmdDir);
|
|
178
222
|
output = this._parseDepTreeOutput(output);
|
|
@@ -191,9 +235,32 @@ export default class Base_javascript {
|
|
|
191
235
|
let sbom = new Sbom();
|
|
192
236
|
sbom.addRoot(mainComponent, license);
|
|
193
237
|
this._addDependenciesToSbom(sbom, depsObject);
|
|
238
|
+
this.#ensurePeerAndOptionalDeps(sbom);
|
|
194
239
|
sbom.filterIgnoredDeps(this.#manifest.ignored);
|
|
195
240
|
return sbom.getAsJsonString(opts);
|
|
196
241
|
}
|
|
242
|
+
/**
|
|
243
|
+
* Ensures peer and optional dependencies declared in the manifest are
|
|
244
|
+
* present in the SBOM, even when the package manager does not resolve them
|
|
245
|
+
* (e.g. yarn does not include peer deps in its dependency listing).
|
|
246
|
+
* @param {Sbom} sbom - The SBOM to supplement
|
|
247
|
+
* @private
|
|
248
|
+
*/
|
|
249
|
+
#ensurePeerAndOptionalDeps(sbom) {
|
|
250
|
+
const rootPurl = toPurl(purlType, this.#manifest.name, this.#manifest.version);
|
|
251
|
+
const depSources = [this.#manifest.peerDependencies, this.#manifest.optionalDependencies];
|
|
252
|
+
for (const source of depSources) {
|
|
253
|
+
for (const [name, version] of Object.entries(source)) {
|
|
254
|
+
// Build the purl prefix for exact matching (e.g. "pkg:npm/minimist@"
|
|
255
|
+
// or "pkg:npm/%40hapi/joi@") to avoid substring false positives
|
|
256
|
+
const probe = toPurl(purlType, name, version);
|
|
257
|
+
const purlPrefix = probe.toString().replace(/@[^@]*$/, '@');
|
|
258
|
+
if (!sbom.checkDependsOnByPurlPrefix(rootPurl, purlPrefix)) {
|
|
259
|
+
sbom.addDependency(rootPurl, probe);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
197
264
|
/**
|
|
198
265
|
* Recursively builds the Sbom from the JSON that npm listing returns
|
|
199
266
|
* @param {Sbom} sbom - The SBOM object to add dependencies to
|
|
@@ -201,7 +268,10 @@ export default class Base_javascript {
|
|
|
201
268
|
* @protected
|
|
202
269
|
*/
|
|
203
270
|
_addDependenciesToSbom(sbom, depTree) {
|
|
204
|
-
const dependencies =
|
|
271
|
+
const dependencies = {
|
|
272
|
+
...depTree["dependencies"],
|
|
273
|
+
...depTree["optionalDependencies"],
|
|
274
|
+
};
|
|
205
275
|
Object.entries(dependencies)
|
|
206
276
|
.forEach(entry => {
|
|
207
277
|
const [name, artifact] = entry;
|
|
@@ -251,6 +321,7 @@ export default class Base_javascript {
|
|
|
251
321
|
const rootPurl = toPurlFromString(sbom.getRoot().purl);
|
|
252
322
|
sbom.addDependency(rootPurl, rootDeps.get(key));
|
|
253
323
|
}
|
|
324
|
+
this.#ensurePeerAndOptionalDeps(sbom);
|
|
254
325
|
sbom.filterIgnoredDeps(this.#manifest.ignored);
|
|
255
326
|
return sbom.getAsJsonString(opts);
|
|
256
327
|
}
|
|
@@ -261,10 +332,14 @@ export default class Base_javascript {
|
|
|
261
332
|
* @protected
|
|
262
333
|
*/
|
|
263
334
|
_getRootDependencies(depTree) {
|
|
264
|
-
|
|
335
|
+
const allDeps = {
|
|
336
|
+
...depTree.dependencies,
|
|
337
|
+
...depTree.optionalDependencies,
|
|
338
|
+
};
|
|
339
|
+
if (Object.keys(allDeps).length === 0) {
|
|
265
340
|
return new Map();
|
|
266
341
|
}
|
|
267
|
-
return new Map(Object.entries(
|
|
342
|
+
return new Map(Object.entries(allDeps).map(([key, value]) => [key, toPurl(purlType, key, value.version)]));
|
|
268
343
|
}
|
|
269
344
|
/**
|
|
270
345
|
* Executes the list command to get dependencies
|
|
@@ -275,7 +350,7 @@ export default class Base_javascript {
|
|
|
275
350
|
*/
|
|
276
351
|
#executeListCmd(includeTransitive, manifestDir) {
|
|
277
352
|
const listArgs = this._listCmdArgs(includeTransitive, manifestDir);
|
|
278
|
-
return this.#invokeCommand(listArgs);
|
|
353
|
+
return this.#invokeCommand(listArgs, { cwd: manifestDir });
|
|
279
354
|
}
|
|
280
355
|
/**
|
|
281
356
|
* Gets the version of the package manager
|
|
@@ -294,13 +369,11 @@ export default class Base_javascript {
|
|
|
294
369
|
const originalDir = process.cwd();
|
|
295
370
|
const isWindows = os.platform() === 'win32';
|
|
296
371
|
if (isWindows) {
|
|
297
|
-
// On Windows, --prefix flag doesn't work as expected
|
|
298
|
-
// Instead of installing from the prefix folder, it installs from current working directory
|
|
299
372
|
process.chdir(manifestDir);
|
|
300
373
|
}
|
|
301
374
|
try {
|
|
302
375
|
const args = this._updateLockFileCmdArgs(manifestDir);
|
|
303
|
-
this.#invokeCommand(args);
|
|
376
|
+
this.#invokeCommand(args, { cwd: manifestDir });
|
|
304
377
|
}
|
|
305
378
|
finally {
|
|
306
379
|
if (isWindows) {
|