@trustify-da/trustify-da-javascript-client 0.3.0-ea.a109536 → 0.3.0-ea.a3789b1
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 +367 -13
- package/dist/package.json +39 -23
- package/dist/src/analysis.d.ts +28 -11
- package/dist/src/analysis.js +99 -79
- package/dist/src/batch_opts.d.ts +24 -0
- package/dist/src/batch_opts.js +35 -0
- package/dist/src/cli.js +346 -9
- package/dist/src/cyclone_dx_sbom.d.ts +30 -2
- package/dist/src/cyclone_dx_sbom.js +80 -8
- package/dist/src/index.d.ts +145 -7
- package/dist/src/index.js +358 -6
- package/dist/src/license/index.d.ts +28 -0
- package/dist/src/license/index.js +103 -0
- package/dist/src/license/license_utils.d.ts +40 -0
- package/dist/src/license/license_utils.js +137 -0
- package/dist/src/license/licenses_api.d.ts +34 -0
- package/dist/src/license/licenses_api.js +98 -0
- package/dist/src/license/project_license.d.ts +20 -0
- package/dist/src/license/project_license.js +62 -0
- package/dist/src/oci_image/images.d.ts +1 -1
- package/dist/src/oci_image/images.js +15 -1
- package/dist/src/oci_image/utils.d.ts +5 -5
- package/dist/src/oci_image/utils.js +11 -2
- package/dist/src/provider.d.ts +18 -5
- package/dist/src/provider.js +33 -5
- package/dist/src/providers/base_java.d.ts +67 -12
- package/dist/src/providers/base_java.js +82 -61
- package/dist/src/providers/base_javascript.d.ts +99 -12
- package/dist/src/providers/base_javascript.js +243 -27
- package/dist/src/providers/base_pyproject.d.ts +158 -0
- package/dist/src/providers/base_pyproject.js +322 -0
- package/dist/src/providers/containerfile_parser.d.ts +5 -0
- package/dist/src/providers/containerfile_parser.js +20 -0
- package/dist/src/providers/golang_gomodules.d.ts +30 -13
- package/dist/src/providers/golang_gomodules.js +218 -122
- package/dist/src/providers/gomod_parser.d.ts +4 -0
- package/dist/src/providers/gomod_parser.js +16 -0
- package/dist/src/providers/java_gradle.d.ts +25 -0
- package/dist/src/providers/java_gradle.js +128 -4
- package/dist/src/providers/java_gradle_groovy.d.ts +1 -1
- package/dist/src/providers/java_gradle_kotlin.d.ts +1 -1
- package/dist/src/providers/java_maven.d.ts +45 -5
- package/dist/src/providers/java_maven.js +291 -10
- package/dist/src/providers/javascript_bun.d.ts +22 -0
- package/dist/src/providers/javascript_bun.js +141 -0
- package/dist/src/providers/javascript_npm.d.ts +19 -0
- package/dist/src/providers/javascript_npm.js +61 -1
- package/dist/src/providers/javascript_pnpm.d.ts +14 -1
- package/dist/src/providers/javascript_pnpm.js +55 -5
- package/dist/src/providers/javascript_yarn.d.ts +12 -0
- package/dist/src/providers/javascript_yarn.js +75 -2
- package/dist/src/providers/manifest.d.ts +2 -0
- package/dist/src/providers/manifest.js +22 -4
- package/dist/src/providers/marker_evaluator.d.ts +14 -0
- package/dist/src/providers/marker_evaluator.js +191 -0
- package/dist/src/providers/oci_dockerfile.d.ts +51 -0
- package/dist/src/providers/oci_dockerfile.js +177 -0
- package/dist/src/providers/processors/yarn_berry_processor.d.ts +6 -2
- package/dist/src/providers/processors/yarn_berry_processor.js +91 -7
- package/dist/src/providers/processors/yarn_classic_processor.d.ts +6 -2
- package/dist/src/providers/processors/yarn_classic_processor.js +8 -6
- package/dist/src/providers/python_controller.d.ts +10 -3
- package/dist/src/providers/python_controller.js +122 -63
- package/dist/src/providers/python_pip.d.ts +16 -4
- package/dist/src/providers/python_pip.js +51 -58
- 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 +98 -0
- package/dist/src/providers/python_poetry.js +286 -0
- package/dist/src/providers/python_uv.d.ts +46 -0
- package/dist/src/providers/python_uv.js +269 -0
- package/dist/src/providers/requirements_parser.d.ts +6 -0
- package/dist/src/providers/requirements_parser.js +24 -0
- package/dist/src/providers/rust_cargo.d.ts +56 -0
- package/dist/src/providers/rust_cargo.js +700 -0
- package/dist/src/providers/tree-sitter-containerfile.wasm +0 -0
- package/dist/src/providers/tree-sitter-gomod.wasm +0 -0
- package/dist/src/providers/tree-sitter-requirements.wasm +0 -0
- package/dist/src/remediate.d.ts +21 -0
- package/dist/src/remediate.js +149 -0
- package/dist/src/remediation.d.ts +57 -0
- package/dist/src/remediation.js +436 -0
- package/dist/src/remediation_report.d.ts +40 -0
- package/dist/src/remediation_report.js +159 -0
- package/dist/src/sbom.d.ts +28 -2
- package/dist/src/sbom.js +26 -4
- package/dist/src/tools.d.ts +44 -0
- package/dist/src/tools.js +137 -1
- package/dist/src/updaters/maven_updater.d.ts +26 -0
- package/dist/src/updaters/maven_updater.js +322 -0
- package/dist/src/updaters/toml_updater.d.ts +33 -0
- package/dist/src/updaters/toml_updater.js +244 -0
- package/dist/src/workspace.d.ts +70 -0
- package/dist/src/workspace.js +256 -0
- package/package.json +40 -24
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { parse } from 'jsonc-parser';
|
|
4
|
+
import Base_javascript, { sriToHash } from './base_javascript.js';
|
|
5
|
+
export default class Javascript_bun extends Base_javascript {
|
|
6
|
+
_lockFileName() {
|
|
7
|
+
return "bun.lock";
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Parses `bun.lock` into a hash map keyed by `name@version`. Each entry in
|
|
11
|
+
* the `packages` section is an array whose first element is the resolved id
|
|
12
|
+
* (`name@version`) and whose fourth element is the SRI integrity string.
|
|
13
|
+
* @param {string} lockDir - Directory containing bun.lock
|
|
14
|
+
* @returns {Map<string, Array<{alg: string, content: string}>>} Hash map
|
|
15
|
+
* @protected
|
|
16
|
+
*/
|
|
17
|
+
_parseLockFileHashes(lockDir) {
|
|
18
|
+
const map = new Map();
|
|
19
|
+
const lockPath = path.join(lockDir, this._lockFileName());
|
|
20
|
+
if (!fs.existsSync(lockPath)) {
|
|
21
|
+
return map;
|
|
22
|
+
}
|
|
23
|
+
let lockData;
|
|
24
|
+
try {
|
|
25
|
+
lockData = parse(fs.readFileSync(lockPath, 'utf-8'));
|
|
26
|
+
}
|
|
27
|
+
catch (_) {
|
|
28
|
+
return map;
|
|
29
|
+
}
|
|
30
|
+
const packages = lockData?.packages || {};
|
|
31
|
+
for (const entry of Object.values(packages)) {
|
|
32
|
+
if (!Array.isArray(entry) || typeof entry[0] !== 'string' || typeof entry[3] !== 'string') {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
const id = entry[0];
|
|
36
|
+
const at = id.lastIndexOf('@');
|
|
37
|
+
if (at <= 0) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
const name = id.slice(0, at);
|
|
41
|
+
const version = id.slice(at + 1);
|
|
42
|
+
const hash = sriToHash(entry[3]);
|
|
43
|
+
if (name && version && hash) {
|
|
44
|
+
map.set(`${name}@${version}`, [hash]);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return map;
|
|
48
|
+
}
|
|
49
|
+
_cmdName() {
|
|
50
|
+
return "bun";
|
|
51
|
+
}
|
|
52
|
+
_listCmdArgs() {
|
|
53
|
+
throw new Error("not supported by Bun");
|
|
54
|
+
}
|
|
55
|
+
_updateLockFileCmdArgs() {
|
|
56
|
+
return ['install', '--lockfile-only'];
|
|
57
|
+
}
|
|
58
|
+
_buildDependencyTree(includeTransitive, opts = {}) {
|
|
59
|
+
this._version();
|
|
60
|
+
const manifestDir = path.dirname(this._getManifest().manifestPath);
|
|
61
|
+
const lockDir = this._findLockFileDir(manifestDir, opts) || manifestDir;
|
|
62
|
+
this._createLockFile(lockDir);
|
|
63
|
+
this._loadHashes(lockDir);
|
|
64
|
+
const lockContent = fs.readFileSync(path.join(lockDir, 'bun.lock'), 'utf-8');
|
|
65
|
+
const lockData = parse(lockContent);
|
|
66
|
+
const packages = lockData.packages || {};
|
|
67
|
+
const memberName = this._getManifest().name;
|
|
68
|
+
const workspaceEntry = this.#findWorkspaceEntry(lockData, lockDir, manifestDir, memberName);
|
|
69
|
+
const directDeps = workspaceEntry?.dependencies || {};
|
|
70
|
+
const tree = { name: memberName, version: this._getManifest().version, dependencies: {} };
|
|
71
|
+
const visited = new Set();
|
|
72
|
+
for (const depName of Object.keys(directDeps)) {
|
|
73
|
+
const resolved = this.#resolvePackage(depName, '', packages);
|
|
74
|
+
if (resolved) {
|
|
75
|
+
tree.dependencies[depName] = this.#buildNode(depName, resolved, packages, includeTransitive, visited);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return tree;
|
|
79
|
+
}
|
|
80
|
+
#findWorkspaceEntry(lockData, lockDir, manifestDir, memberName) {
|
|
81
|
+
const workspaces = lockData.workspaces || {};
|
|
82
|
+
const relPath = path.relative(lockDir, path.resolve(manifestDir));
|
|
83
|
+
if (!relPath || relPath === '.') {
|
|
84
|
+
return workspaces[''] || {};
|
|
85
|
+
}
|
|
86
|
+
const normalised = relPath.split(path.sep).join('/');
|
|
87
|
+
if (workspaces[normalised]) {
|
|
88
|
+
return workspaces[normalised];
|
|
89
|
+
}
|
|
90
|
+
for (const [wsPath, entry] of Object.entries(workspaces)) {
|
|
91
|
+
if (entry.name === memberName && wsPath !== '') {
|
|
92
|
+
return entry;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return workspaces[''] || {};
|
|
96
|
+
}
|
|
97
|
+
#resolvePackage(depName, parentKey, packages) {
|
|
98
|
+
if (parentKey) {
|
|
99
|
+
const scopedKey = `${parentKey}/${depName}`;
|
|
100
|
+
if (packages[scopedKey]) {
|
|
101
|
+
return packages[scopedKey];
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return packages[depName] || null;
|
|
105
|
+
}
|
|
106
|
+
#buildNode(depName, resolved, packages, includeTransitive, visited) {
|
|
107
|
+
const resolvedId = Array.isArray(resolved) ? resolved[0] : resolved;
|
|
108
|
+
const version = this.#extractVersion(resolvedId);
|
|
109
|
+
const node = { version };
|
|
110
|
+
if (!includeTransitive) {
|
|
111
|
+
return node;
|
|
112
|
+
}
|
|
113
|
+
const metadata = Array.isArray(resolved) ? (resolved[2] || {}) : {};
|
|
114
|
+
const subDeps = metadata.dependencies || {};
|
|
115
|
+
if (Object.keys(subDeps).length > 0) {
|
|
116
|
+
const visitKey = `${depName}@${version}`;
|
|
117
|
+
if (visited.has(visitKey)) {
|
|
118
|
+
return node;
|
|
119
|
+
}
|
|
120
|
+
visited.add(visitKey);
|
|
121
|
+
node.dependencies = {};
|
|
122
|
+
for (const subName of Object.keys(subDeps)) {
|
|
123
|
+
const subResolved = this.#resolvePackage(subName, depName, packages);
|
|
124
|
+
if (subResolved) {
|
|
125
|
+
node.dependencies[subName] = this.#buildNode(subName, subResolved, packages, true, visited);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return node;
|
|
130
|
+
}
|
|
131
|
+
#extractVersion(resolvedId) {
|
|
132
|
+
if (typeof resolvedId !== 'string') {
|
|
133
|
+
return '0.0.0';
|
|
134
|
+
}
|
|
135
|
+
const atIdx = resolvedId.lastIndexOf('@');
|
|
136
|
+
if (atIdx > 0) {
|
|
137
|
+
return resolvedId.substring(atIdx + 1);
|
|
138
|
+
}
|
|
139
|
+
return '0.0.0';
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
export default class Javascript_npm extends Base_javascript {
|
|
2
|
+
/**
|
|
3
|
+
* Parses `package-lock.json` (lockfileVersion 2/3) into a hash map keyed by
|
|
4
|
+
* `name@version`. Each `packages` entry is keyed by its install path
|
|
5
|
+
* (e.g. `node_modules/@hapi/joi`); the package name is the segment after the
|
|
6
|
+
* final `node_modules/`. The `integrity` field holds an SRI string.
|
|
7
|
+
* @param {string} lockDir - Directory containing package-lock.json
|
|
8
|
+
* @returns {Map<string, Array<{alg: string, content: string}>>} Hash map
|
|
9
|
+
* @protected
|
|
10
|
+
*/
|
|
11
|
+
protected _parseLockFileHashes(lockDir: string): Map<string, Array<{
|
|
12
|
+
alg: string;
|
|
13
|
+
content: string;
|
|
14
|
+
}>>;
|
|
2
15
|
_listCmdArgs(includeTransitive: any): string[];
|
|
16
|
+
_buildDependencyTree(includeTransitive: any, opts?: {}): Object | {
|
|
17
|
+
name: any;
|
|
18
|
+
version: any;
|
|
19
|
+
dependencies: any;
|
|
20
|
+
optionalDependencies: any;
|
|
21
|
+
};
|
|
3
22
|
}
|
|
4
23
|
import Base_javascript from './base_javascript.js';
|
|
@@ -1,8 +1,47 @@
|
|
|
1
|
-
import
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import Base_javascript, { sriToHash } from './base_javascript.js';
|
|
2
4
|
export default class Javascript_npm extends Base_javascript {
|
|
3
5
|
_lockFileName() {
|
|
4
6
|
return "package-lock.json";
|
|
5
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* Parses `package-lock.json` (lockfileVersion 2/3) into a hash map keyed by
|
|
10
|
+
* `name@version`. Each `packages` entry is keyed by its install path
|
|
11
|
+
* (e.g. `node_modules/@hapi/joi`); the package name is the segment after the
|
|
12
|
+
* final `node_modules/`. The `integrity` field holds an SRI string.
|
|
13
|
+
* @param {string} lockDir - Directory containing package-lock.json
|
|
14
|
+
* @returns {Map<string, Array<{alg: string, content: string}>>} Hash map
|
|
15
|
+
* @protected
|
|
16
|
+
*/
|
|
17
|
+
_parseLockFileHashes(lockDir) {
|
|
18
|
+
const map = new Map();
|
|
19
|
+
const lockPath = path.join(lockDir, this._lockFileName());
|
|
20
|
+
if (!fs.existsSync(lockPath)) {
|
|
21
|
+
return map;
|
|
22
|
+
}
|
|
23
|
+
let lock;
|
|
24
|
+
try {
|
|
25
|
+
lock = JSON.parse(fs.readFileSync(lockPath, 'utf-8'));
|
|
26
|
+
}
|
|
27
|
+
catch (_) {
|
|
28
|
+
return map;
|
|
29
|
+
}
|
|
30
|
+
const packages = lock.packages || {};
|
|
31
|
+
for (const [pkgPath, entry] of Object.entries(packages)) {
|
|
32
|
+
if (!pkgPath || !entry || !entry.integrity || !entry.version) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
const marker = 'node_modules/';
|
|
36
|
+
const idx = pkgPath.lastIndexOf(marker);
|
|
37
|
+
const name = idx < 0 ? pkgPath : pkgPath.slice(idx + marker.length);
|
|
38
|
+
const hash = sriToHash(entry.integrity);
|
|
39
|
+
if (name && hash) {
|
|
40
|
+
map.set(`${name}@${entry.version}`, [hash]);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return map;
|
|
44
|
+
}
|
|
6
45
|
_cmdName() {
|
|
7
46
|
return "npm";
|
|
8
47
|
}
|
|
@@ -12,4 +51,25 @@ export default class Javascript_npm extends Base_javascript {
|
|
|
12
51
|
_updateLockFileCmdArgs() {
|
|
13
52
|
return ['install', '--package-lock-only'];
|
|
14
53
|
}
|
|
54
|
+
_buildDependencyTree(includeTransitive, opts = {}) {
|
|
55
|
+
// npm ls --json returns a single tree rooted at the workspace root.
|
|
56
|
+
// When analyzing a workspace member, its deps are nested under the
|
|
57
|
+
// root's dependencies keyed by the member name — extract that subtree
|
|
58
|
+
// so downstream analysis sees only the member's dependencies.
|
|
59
|
+
const tree = super._buildDependencyTree(includeTransitive, opts);
|
|
60
|
+
const memberName = this._getManifest().name;
|
|
61
|
+
if (tree.name === memberName) {
|
|
62
|
+
return tree;
|
|
63
|
+
}
|
|
64
|
+
const memberEntry = tree.dependencies?.[memberName];
|
|
65
|
+
if (memberEntry) {
|
|
66
|
+
return {
|
|
67
|
+
name: memberName,
|
|
68
|
+
version: memberEntry.version || this._getManifest().version,
|
|
69
|
+
dependencies: memberEntry.dependencies,
|
|
70
|
+
optionalDependencies: memberEntry.optionalDependencies,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
return tree;
|
|
74
|
+
}
|
|
15
75
|
}
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
export default class Javascript_pnpm extends Base_javascript {
|
|
2
|
+
/**
|
|
3
|
+
* Parses `pnpm-lock.yaml` (lockfileVersion 9) into a hash map keyed by
|
|
4
|
+
* `name@version`. Entries in the `packages` section are keyed by
|
|
5
|
+
* `<name>@<version>` (optionally followed by a `(peer@x)` suffix); the
|
|
6
|
+
* `resolution.integrity` field holds an SRI string.
|
|
7
|
+
* @param {string} lockDir - Directory containing pnpm-lock.yaml
|
|
8
|
+
* @returns {Map<string, Array<{alg: string, content: string}>>} Hash map
|
|
9
|
+
* @protected
|
|
10
|
+
*/
|
|
11
|
+
protected _parseLockFileHashes(lockDir: string): Map<string, Array<{
|
|
12
|
+
alg: string;
|
|
13
|
+
content: string;
|
|
14
|
+
}>>;
|
|
2
15
|
_listCmdArgs(includeTransitive: any): string[];
|
|
3
|
-
_buildDependencyTree(includeTransitive: any,
|
|
16
|
+
_buildDependencyTree(includeTransitive: any, opts?: {}): any;
|
|
4
17
|
}
|
|
5
18
|
import Base_javascript from './base_javascript.js';
|
|
@@ -1,21 +1,71 @@
|
|
|
1
|
-
import
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { load as yamlLoad } from 'js-yaml';
|
|
4
|
+
import Base_javascript, { sriToHash } from './base_javascript.js';
|
|
2
5
|
export default class Javascript_pnpm extends Base_javascript {
|
|
3
6
|
_lockFileName() {
|
|
4
7
|
return "pnpm-lock.yaml";
|
|
5
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Parses `pnpm-lock.yaml` (lockfileVersion 9) into a hash map keyed by
|
|
11
|
+
* `name@version`. Entries in the `packages` section are keyed by
|
|
12
|
+
* `<name>@<version>` (optionally followed by a `(peer@x)` suffix); the
|
|
13
|
+
* `resolution.integrity` field holds an SRI string.
|
|
14
|
+
* @param {string} lockDir - Directory containing pnpm-lock.yaml
|
|
15
|
+
* @returns {Map<string, Array<{alg: string, content: string}>>} Hash map
|
|
16
|
+
* @protected
|
|
17
|
+
*/
|
|
18
|
+
_parseLockFileHashes(lockDir) {
|
|
19
|
+
const map = new Map();
|
|
20
|
+
const lockPath = path.join(lockDir, this._lockFileName());
|
|
21
|
+
if (!fs.existsSync(lockPath)) {
|
|
22
|
+
return map;
|
|
23
|
+
}
|
|
24
|
+
let lock;
|
|
25
|
+
try {
|
|
26
|
+
lock = yamlLoad(fs.readFileSync(lockPath, 'utf-8'));
|
|
27
|
+
}
|
|
28
|
+
catch (_) {
|
|
29
|
+
return map;
|
|
30
|
+
}
|
|
31
|
+
const packages = lock?.packages || {};
|
|
32
|
+
for (const [key, entry] of Object.entries(packages)) {
|
|
33
|
+
const integrity = entry?.resolution?.integrity;
|
|
34
|
+
if (!key || !integrity) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
// Strip any peer-dependency suffix, then split name from version
|
|
38
|
+
const base = key.split('(')[0];
|
|
39
|
+
const at = base.lastIndexOf('@');
|
|
40
|
+
if (at <= 0) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
const name = base.slice(0, at);
|
|
44
|
+
const version = base.slice(at + 1);
|
|
45
|
+
const hash = sriToHash(integrity);
|
|
46
|
+
if (name && version && hash) {
|
|
47
|
+
map.set(`${name}@${version}`, [hash]);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return map;
|
|
51
|
+
}
|
|
6
52
|
_cmdName() {
|
|
7
53
|
return "pnpm";
|
|
8
54
|
}
|
|
9
55
|
_listCmdArgs(includeTransitive) {
|
|
10
|
-
return ['ls', includeTransitive ? '--depth=Infinity' : '--depth=0', '--prod', '--json'];
|
|
56
|
+
return ['ls', includeTransitive ? '--depth=Infinity' : '--depth=0', '--prod', '--json', '-r'];
|
|
11
57
|
}
|
|
12
58
|
_updateLockFileCmdArgs() {
|
|
13
59
|
return ['install', '--frozen-lockfile'];
|
|
14
60
|
}
|
|
15
|
-
_buildDependencyTree(includeTransitive,
|
|
16
|
-
|
|
61
|
+
_buildDependencyTree(includeTransitive, opts = {}) {
|
|
62
|
+
// pnpm ls --json returns an array with one entry per workspace package.
|
|
63
|
+
// When analyzing a workspace member, find its entry by name instead of
|
|
64
|
+
// blindly taking the first element (which is the workspace root).
|
|
65
|
+
const tree = super._buildDependencyTree(includeTransitive, opts);
|
|
17
66
|
if (Array.isArray(tree) && tree.length > 0) {
|
|
18
|
-
|
|
67
|
+
const memberName = this._getManifest().name;
|
|
68
|
+
return tree.find(pkg => pkg.name === memberName) || tree[0];
|
|
19
69
|
}
|
|
20
70
|
return {};
|
|
21
71
|
}
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
export default class Javascript_yarn extends Base_javascript {
|
|
2
2
|
static VERSION_PATTERN: RegExp;
|
|
3
|
+
/**
|
|
4
|
+
* Parses `yarn.lock` into a hash map keyed by `name@version`. Supports both
|
|
5
|
+
* Yarn Classic (v1) entries with an `integrity` SRI field and Yarn Berry
|
|
6
|
+
* (v2+) entries with a `checksum` field.
|
|
7
|
+
* @param {string} lockDir - Directory containing yarn.lock
|
|
8
|
+
* @returns {Map<string, Array<{alg: string, content: string}>>} Hash map
|
|
9
|
+
* @protected
|
|
10
|
+
*/
|
|
11
|
+
protected _parseLockFileHashes(lockDir: string): Map<string, Array<{
|
|
12
|
+
alg: string;
|
|
13
|
+
content: string;
|
|
14
|
+
}>>;
|
|
3
15
|
_listCmdArgs(includeTransitive: any, manifestDir: any): any;
|
|
4
16
|
_updateLockFileCmdArgs(manifestDir: any): any;
|
|
5
17
|
_setUp(manifestPath: any, opts: any): void;
|
|
@@ -1,12 +1,85 @@
|
|
|
1
|
-
import
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { parseSyml } from '@yarnpkg/parsers';
|
|
4
|
+
import Base_javascript, { sriToHash } from './base_javascript.js';
|
|
2
5
|
import Yarn_berry_processor from './processors/yarn_berry_processor.js';
|
|
3
6
|
import Yarn_classic_processor from './processors/yarn_classic_processor.js';
|
|
7
|
+
/**
|
|
8
|
+
* Converts a Yarn Berry `checksum` value to a CycloneDX hash object. Berry
|
|
9
|
+
* checksums are formatted as `<cacheKey>/<hex-sha512>`; the digest is the
|
|
10
|
+
* hex-encoded SHA-512 following the final slash.
|
|
11
|
+
* @param {string} checksum - The checksum field value
|
|
12
|
+
* @returns {{alg: string, content: string}|null} CycloneDX hash, or null
|
|
13
|
+
*/
|
|
14
|
+
function berryChecksumToHash(checksum) {
|
|
15
|
+
if (typeof checksum !== 'string') {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
const slash = checksum.lastIndexOf('/');
|
|
19
|
+
const hex = (slash >= 0 ? checksum.slice(slash + 1) : checksum).trim();
|
|
20
|
+
if (!/^[0-9a-f]+$/i.test(hex)) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
return { alg: 'SHA-512', content: hex.toLowerCase() };
|
|
24
|
+
}
|
|
4
25
|
export default class Javascript_yarn extends Base_javascript {
|
|
5
26
|
static VERSION_PATTERN = /^([0-9]+)\./;
|
|
6
27
|
#processor;
|
|
7
28
|
_lockFileName() {
|
|
8
29
|
return "yarn.lock";
|
|
9
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Parses `yarn.lock` into a hash map keyed by `name@version`. Supports both
|
|
33
|
+
* Yarn Classic (v1) entries with an `integrity` SRI field and Yarn Berry
|
|
34
|
+
* (v2+) entries with a `checksum` field.
|
|
35
|
+
* @param {string} lockDir - Directory containing yarn.lock
|
|
36
|
+
* @returns {Map<string, Array<{alg: string, content: string}>>} Hash map
|
|
37
|
+
* @protected
|
|
38
|
+
*/
|
|
39
|
+
_parseLockFileHashes(lockDir) {
|
|
40
|
+
const map = new Map();
|
|
41
|
+
const lockPath = path.join(lockDir, this._lockFileName());
|
|
42
|
+
if (!fs.existsSync(lockPath)) {
|
|
43
|
+
return map;
|
|
44
|
+
}
|
|
45
|
+
let content;
|
|
46
|
+
try {
|
|
47
|
+
content = fs.readFileSync(lockPath, 'utf-8');
|
|
48
|
+
}
|
|
49
|
+
catch (_) {
|
|
50
|
+
return map;
|
|
51
|
+
}
|
|
52
|
+
const parsed = parseSyml(content);
|
|
53
|
+
for (const [spec, entry] of Object.entries(parsed)) {
|
|
54
|
+
if (spec === '__metadata') {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const version = entry.version;
|
|
58
|
+
if (!version) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
let hash = null;
|
|
62
|
+
if (entry.integrity) {
|
|
63
|
+
hash = sriToHash(entry.integrity);
|
|
64
|
+
}
|
|
65
|
+
else if (entry.checksum) {
|
|
66
|
+
hash = berryChecksumToHash(entry.checksum);
|
|
67
|
+
}
|
|
68
|
+
if (!hash) {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
// Handle comma-separated specifiers (e.g., "pkg@^1.0.0, pkg@^2.0.0")
|
|
72
|
+
for (const rawSpec of spec.split(',')) {
|
|
73
|
+
const trimmed = rawSpec.trim();
|
|
74
|
+
const atIndex = trimmed.lastIndexOf('@');
|
|
75
|
+
if (atIndex > 0) {
|
|
76
|
+
const name = trimmed.slice(0, atIndex);
|
|
77
|
+
map.set(`${name}@${version}`, [hash]);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return map;
|
|
82
|
+
}
|
|
10
83
|
_cmdName() {
|
|
11
84
|
return "yarn";
|
|
12
85
|
}
|
|
@@ -34,6 +107,6 @@ export default class Javascript_yarn extends Base_javascript {
|
|
|
34
107
|
return this.#processor.parseDepTreeOutput(output);
|
|
35
108
|
}
|
|
36
109
|
_addDependenciesToSbom(sbom, depTree) {
|
|
37
|
-
this.#processor.addDependenciesToSbom(sbom, depTree);
|
|
110
|
+
this.#processor.addDependenciesToSbom(sbom, depTree, purl => this._hashesForPurl(purl));
|
|
38
111
|
}
|
|
39
112
|
}
|
|
@@ -9,6 +9,8 @@ export default class Manifest {
|
|
|
9
9
|
this.manifestPath = manifestPath;
|
|
10
10
|
const content = this.loadManifest();
|
|
11
11
|
this.dependencies = this.loadDependencies(content);
|
|
12
|
+
this.peerDependencies = content.peerDependencies || {};
|
|
13
|
+
this.optionalDependencies = content.optionalDependencies || {};
|
|
12
14
|
this.name = content.name;
|
|
13
15
|
this.version = content.version || DEFAULT_VERSION;
|
|
14
16
|
this.ignored = this.loadIgnored(content);
|
|
@@ -27,11 +29,27 @@ export default class Manifest {
|
|
|
27
29
|
}
|
|
28
30
|
loadDependencies(content) {
|
|
29
31
|
let deps = [];
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
const depSources = [
|
|
33
|
+
content.dependencies,
|
|
34
|
+
content.peerDependencies,
|
|
35
|
+
content.optionalDependencies,
|
|
36
|
+
];
|
|
37
|
+
for (const source of depSources) {
|
|
38
|
+
if (source) {
|
|
39
|
+
for (let dep in source) {
|
|
40
|
+
if (!deps.includes(dep)) {
|
|
41
|
+
deps.push(dep);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
32
45
|
}
|
|
33
|
-
|
|
34
|
-
|
|
46
|
+
// bundledDependencies is an array of package names (subset of dependencies)
|
|
47
|
+
if (Array.isArray(content.bundledDependencies)) {
|
|
48
|
+
for (const dep of content.bundledDependencies) {
|
|
49
|
+
if (!deps.includes(dep)) {
|
|
50
|
+
deps.push(dep);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
35
53
|
}
|
|
36
54
|
return deps;
|
|
37
55
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maps Node.js/OS values to PEP 508 marker variables.
|
|
3
|
+
* Example: on Linux, sys_platform='linux', platform_system='Linux', os_name='posix'
|
|
4
|
+
* @returns {Record<string, string>}
|
|
5
|
+
*/
|
|
6
|
+
export function getEnvironmentMarkers(): Record<string, string>;
|
|
7
|
+
/**
|
|
8
|
+
* Evaluates a full PEP 508 marker expression against the current platform.
|
|
9
|
+
* Example: "sys_platform == 'win32' and python_version >= '3.8'" → false on Linux
|
|
10
|
+
* Empty/missing markers return true (unconditional dependency).
|
|
11
|
+
* @param {string} markerExpr
|
|
12
|
+
* @returns {boolean}
|
|
13
|
+
*/
|
|
14
|
+
export function evaluateMarker(markerExpr: string): boolean;
|