@trustify-da/trustify-da-javascript-client 0.3.0-ea.e5bb86c → 0.3.0-ea.e660b02
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json +1 -1
- package/dist/src/cli.js +51 -2
- package/dist/src/cyclone_dx_sbom.d.ts +7 -1
- package/dist/src/cyclone_dx_sbom.js +29 -8
- package/dist/src/index.d.ts +72 -3
- package/dist/src/index.js +90 -7
- package/dist/src/oci_image/utils.js +11 -2
- package/dist/src/provider.d.ts +3 -2
- package/dist/src/provider.js +5 -1
- package/dist/src/providers/base_java.d.ts +12 -10
- package/dist/src/providers/base_java.js +18 -44
- package/dist/src/providers/base_javascript.d.ts +11 -0
- package/dist/src/providers/base_javascript.js +10 -3
- package/dist/src/providers/base_pyproject.d.ts +40 -29
- package/dist/src/providers/base_pyproject.js +121 -78
- package/dist/src/providers/golang_gomodules.d.ts +10 -0
- package/dist/src/providers/golang_gomodules.js +65 -8
- package/dist/src/providers/java_gradle.d.ts +19 -0
- package/dist/src/providers/java_gradle.js +116 -2
- package/dist/src/providers/java_maven.d.ts +8 -0
- package/dist/src/providers/java_maven.js +165 -1
- package/dist/src/providers/javascript_bun.d.ts +10 -0
- package/dist/src/providers/javascript_bun.js +100 -0
- package/dist/src/providers/javascript_npm.d.ts +1 -0
- package/dist/src/providers/javascript_npm.js +21 -0
- package/dist/src/providers/javascript_pnpm.js +6 -2
- package/dist/src/providers/marker_evaluator.d.ts +14 -0
- package/dist/src/providers/marker_evaluator.js +191 -0
- package/dist/src/providers/processors/yarn_berry_processor.js +6 -2
- package/dist/src/providers/python_controller.d.ts +5 -1
- package/dist/src/providers/python_controller.js +65 -7
- package/dist/src/providers/python_pip.d.ts +5 -0
- package/dist/src/providers/python_pip.js +5 -5
- package/dist/src/providers/python_pip_pyproject.d.ts +61 -0
- package/dist/src/providers/python_pip_pyproject.js +146 -0
- package/dist/src/providers/python_poetry.d.ts +64 -8
- package/dist/src/providers/python_poetry.js +165 -25
- package/dist/src/providers/python_uv.d.ts +21 -1
- package/dist/src/providers/python_uv.js +157 -6
- package/dist/src/providers/rust_cargo.d.ts +5 -1
- package/dist/src/providers/rust_cargo.js +31 -4
- package/dist/src/sbom.d.ts +7 -1
- package/dist/src/sbom.js +4 -2
- package/dist/src/tools.d.ts +26 -0
- package/dist/src/tools.js +58 -0
- package/dist/src/workspace.d.ts +9 -0
- package/dist/src/workspace.js +1 -1
- package/package.json +2 -2
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
1
|
import path from 'node:path';
|
|
3
2
|
import { PackageURL } from 'packageurl-js';
|
|
4
|
-
import { getCustomPath,
|
|
3
|
+
import { getCustomPath, getWrapperPreference, invokeCommand, traverseForWrapper } from "../tools.js";
|
|
5
4
|
/** @typedef {import('../provider').Provider} */
|
|
6
5
|
/** @typedef {import('../provider').Provided} Provided */
|
|
7
6
|
/** @typedef {{name: string, version: string}} Package */
|
|
@@ -26,6 +25,13 @@ export default class Base_Java {
|
|
|
26
25
|
this.globalBinary = globalBinary;
|
|
27
26
|
this.localWrapper = localWrapper;
|
|
28
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Returns the package manager name (e.g. mvn, gradle)
|
|
30
|
+
* @returns {string}
|
|
31
|
+
*/
|
|
32
|
+
packageManagerName() {
|
|
33
|
+
return this.globalBinary;
|
|
34
|
+
}
|
|
29
35
|
/**
|
|
30
36
|
* Recursively populates the SBOM instance with the parsed graph
|
|
31
37
|
* @param {string} src - Source dependency to start the calculations from
|
|
@@ -42,7 +48,7 @@ export default class Base_Java {
|
|
|
42
48
|
}
|
|
43
49
|
let index = 0;
|
|
44
50
|
let target = lines[index];
|
|
45
|
-
let targetDepth = this
|
|
51
|
+
let targetDepth = this._getDepth(target);
|
|
46
52
|
while (targetDepth > srcDepth && index < lines.length) {
|
|
47
53
|
if (targetDepth === srcDepth + 1) {
|
|
48
54
|
let from = this.parseDep(src);
|
|
@@ -55,22 +61,25 @@ export default class Base_Java {
|
|
|
55
61
|
}
|
|
56
62
|
}
|
|
57
63
|
else {
|
|
58
|
-
this.parseDependencyTree(lines[index - 1], this
|
|
64
|
+
this.parseDependencyTree(lines[index - 1], this._getDepth(lines[index - 1]), lines.slice(index), sbom);
|
|
59
65
|
}
|
|
60
66
|
target = lines[++index];
|
|
61
|
-
targetDepth = this
|
|
67
|
+
targetDepth = this._getDepth(target);
|
|
62
68
|
}
|
|
63
69
|
}
|
|
64
70
|
/**
|
|
65
71
|
* Calculates how deep in the graph is the given line
|
|
66
72
|
* @param {string} line - line to calculate the depth from
|
|
67
73
|
* @returns {number} The calculated depth
|
|
68
|
-
* @
|
|
74
|
+
* @protected
|
|
69
75
|
*/
|
|
70
|
-
|
|
71
|
-
if (line ===
|
|
76
|
+
_getDepth(line) {
|
|
77
|
+
if (!line || line.trim() === '') {
|
|
72
78
|
return -1;
|
|
73
79
|
}
|
|
80
|
+
if (line.match(/^\w/)) {
|
|
81
|
+
return 0;
|
|
82
|
+
}
|
|
74
83
|
return ((line.indexOf('-') - 1) / 3) + 1;
|
|
75
84
|
}
|
|
76
85
|
/**
|
|
@@ -131,7 +140,7 @@ export default class Base_Java {
|
|
|
131
140
|
const toolPath = getCustomPath(this.globalBinary, opts);
|
|
132
141
|
const useWrapper = getWrapperPreference(this.globalBinary, opts);
|
|
133
142
|
if (useWrapper) {
|
|
134
|
-
const wrapper = this.
|
|
143
|
+
const wrapper = traverseForWrapper(manifestDir, this.localWrapper);
|
|
135
144
|
if (wrapper !== undefined) {
|
|
136
145
|
try {
|
|
137
146
|
this._invokeCommand(wrapper, ['--version'], { cwd: manifestDir });
|
|
@@ -156,39 +165,4 @@ export default class Base_Java {
|
|
|
156
165
|
}
|
|
157
166
|
return toolPath;
|
|
158
167
|
}
|
|
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
168
|
}
|
|
@@ -47,6 +47,11 @@ export default class Base_javascript {
|
|
|
47
47
|
*/
|
|
48
48
|
protected _cmdName(): string;
|
|
49
49
|
/**
|
|
50
|
+
* Returns the package manager name (e.g. npm, yarn, pnpm, bun)
|
|
51
|
+
* @returns {string} The package manager name
|
|
52
|
+
*/
|
|
53
|
+
packageManagerName(): string;
|
|
54
|
+
/**
|
|
50
55
|
* Returns the command arguments for listing dependencies
|
|
51
56
|
* @returns {Array<string>} The command arguments
|
|
52
57
|
* @abstract
|
|
@@ -136,6 +141,12 @@ export default class Base_javascript {
|
|
|
136
141
|
*/
|
|
137
142
|
protected _version(): string;
|
|
138
143
|
/**
|
|
144
|
+
* Creates or updates the lock file for the package manager
|
|
145
|
+
* @param {string} manifestDir - Directory containing the manifest file
|
|
146
|
+
* @protected
|
|
147
|
+
*/
|
|
148
|
+
protected _createLockFile(manifestDir: string): void;
|
|
149
|
+
/**
|
|
139
150
|
* Parses the dependency tree output
|
|
140
151
|
* @param {string} output - The output to parse
|
|
141
152
|
* @returns {string} The parsed output
|
|
@@ -71,6 +71,13 @@ export default class Base_javascript {
|
|
|
71
71
|
throw new TypeError("_cmdName must be implemented");
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
74
|
+
* Returns the package manager name (e.g. npm, yarn, pnpm, bun)
|
|
75
|
+
* @returns {string} The package manager name
|
|
76
|
+
*/
|
|
77
|
+
packageManagerName() {
|
|
78
|
+
return this._cmdName();
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
74
81
|
* Returns the command arguments for listing dependencies
|
|
75
82
|
* @returns {Array<string>} The command arguments
|
|
76
83
|
* @abstract
|
|
@@ -217,7 +224,7 @@ export default class Base_javascript {
|
|
|
217
224
|
this._version();
|
|
218
225
|
const manifestDir = path.dirname(this.#manifest.manifestPath);
|
|
219
226
|
const cmdDir = this._findLockFileDir(manifestDir, opts) || manifestDir;
|
|
220
|
-
this
|
|
227
|
+
this._createLockFile(cmdDir);
|
|
221
228
|
let output = this.#executeListCmd(includeTransitive, cmdDir);
|
|
222
229
|
output = this._parseDepTreeOutput(output);
|
|
223
230
|
return JSON.parse(output);
|
|
@@ -363,9 +370,9 @@ export default class Base_javascript {
|
|
|
363
370
|
/**
|
|
364
371
|
* Creates or updates the lock file for the package manager
|
|
365
372
|
* @param {string} manifestDir - Directory containing the manifest file
|
|
366
|
-
* @
|
|
373
|
+
* @protected
|
|
367
374
|
*/
|
|
368
|
-
|
|
375
|
+
_createLockFile(manifestDir) {
|
|
369
376
|
const originalDir = process.cwd();
|
|
370
377
|
const isWindows = os.platform() === 'win32';
|
|
371
378
|
if (isWindows) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @typedef {{name: string, version: string, children: string[]}} GraphEntry */
|
|
1
|
+
/** @typedef {{name: string, version: string, children: string[], hashes?: Array<{alg: string, content: string}>}} GraphEntry */
|
|
2
2
|
/** @typedef {{name: string, version: string, dependencies: DepTreeEntry[]}} DepTreeEntry */
|
|
3
3
|
/** @typedef {{directDeps: string[], graph: Map<string, GraphEntry>}} DependencyData */
|
|
4
4
|
/** @typedef {{ecosystem: string, content: string, contentType: string}} Provided */
|
|
@@ -10,9 +10,29 @@ export default class Base_pyproject {
|
|
|
10
10
|
isSupported(manifestName: string): boolean;
|
|
11
11
|
/**
|
|
12
12
|
* @param {string} manifestDir
|
|
13
|
+
* @param {Object} [opts={}]
|
|
13
14
|
* @returns {boolean}
|
|
14
15
|
*/
|
|
15
|
-
validateLockFile(manifestDir: string): boolean;
|
|
16
|
+
validateLockFile(manifestDir: string, opts?: any): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Walk up from manifestDir to find the directory containing the lock file.
|
|
19
|
+
* Follows the same pattern as Base_javascript._findLockFileDir().
|
|
20
|
+
* @param {string} manifestDir
|
|
21
|
+
* @param {Object} [opts={}]
|
|
22
|
+
* @returns {string|null}
|
|
23
|
+
* @protected
|
|
24
|
+
*/
|
|
25
|
+
protected _findLockFileDir(manifestDir: string, opts?: any): string | null;
|
|
26
|
+
/**
|
|
27
|
+
* Detect workspace root boundaries.
|
|
28
|
+
* Currently only uv has native workspace support ([tool.uv.workspace] in pyproject.toml).
|
|
29
|
+
* Poetry has no workspace/monorepo support (python-poetry/poetry#2270), so each
|
|
30
|
+
* poetry project is treated independently — see Python_poetry._findLockFileDir().
|
|
31
|
+
* @param {string} dir
|
|
32
|
+
* @returns {boolean}
|
|
33
|
+
* @protected
|
|
34
|
+
*/
|
|
35
|
+
protected _isWorkspaceRoot(dir: string): boolean;
|
|
16
36
|
/**
|
|
17
37
|
* Read project license from pyproject.toml, with fallback to LICENSE file.
|
|
18
38
|
* @param {string} manifestPath
|
|
@@ -41,15 +61,23 @@ export default class Base_pyproject {
|
|
|
41
61
|
* @protected
|
|
42
62
|
*/
|
|
43
63
|
protected _cmdName(): string;
|
|
64
|
+
/**
|
|
65
|
+
* Returns the package manager name (e.g. pip, poetry, uv)
|
|
66
|
+
* @returns {string}
|
|
67
|
+
*/
|
|
68
|
+
packageManagerName(): string;
|
|
44
69
|
/**
|
|
45
70
|
* Resolve dependencies using the tool-specific command and parser.
|
|
46
|
-
*
|
|
71
|
+
*
|
|
72
|
+
* @param {string} manifestDir - directory containing the target pyproject.toml
|
|
73
|
+
* @param {string} workspaceDir - workspace root (where the lock file lives);
|
|
74
|
+
* only used by providers that need workspace-level resolution (e.g. uv)
|
|
47
75
|
* @param {object} parsed - parsed pyproject.toml
|
|
48
76
|
* @param {Object} opts
|
|
49
77
|
* @returns {Promise<DependencyData>}
|
|
50
78
|
* @protected
|
|
51
79
|
*/
|
|
52
|
-
protected _getDependencyData(manifestDir: string, parsed: object, opts: any): Promise<DependencyData>;
|
|
80
|
+
protected _getDependencyData(manifestDir: string, workspaceDir: string, parsed: object, opts: any): Promise<DependencyData>;
|
|
53
81
|
/**
|
|
54
82
|
* Canonicalize a Python package name per PEP 503.
|
|
55
83
|
* @param {string} name
|
|
@@ -79,26 +107,14 @@ export default class Base_pyproject {
|
|
|
79
107
|
*/
|
|
80
108
|
protected _getIgnoredDeps(manifestPath: string): Set<string>;
|
|
81
109
|
/**
|
|
82
|
-
*
|
|
83
|
-
* @param {Map<string, GraphEntry>} graph
|
|
84
|
-
* @param {string[]} directDeps - canonical names of direct deps
|
|
85
|
-
* @param {Set<string>} ignoredDeps
|
|
86
|
-
* @param {boolean} includeTransitive
|
|
87
|
-
* @returns {DepTreeEntry[]}
|
|
88
|
-
* @protected
|
|
89
|
-
*/
|
|
90
|
-
protected _buildDependencyTree(graph: Map<string, GraphEntry>, directDeps: string[], ignoredDeps: Set<string>, includeTransitive: boolean): DepTreeEntry[];
|
|
91
|
-
/**
|
|
92
|
-
* Recursively collect transitive dependencies.
|
|
110
|
+
* Compute the set of graph nodes reachable from direct deps, excluding ignored.
|
|
93
111
|
* @param {Map<string, GraphEntry>} graph
|
|
94
|
-
* @param {string[]}
|
|
95
|
-
* @param {DepTreeEntry[]} result - mutated in place
|
|
112
|
+
* @param {string[]} directDeps
|
|
96
113
|
* @param {Set<string>} ignoredDeps
|
|
97
|
-
* @
|
|
98
|
-
* @returns {void}
|
|
114
|
+
* @returns {Set<string>}
|
|
99
115
|
* @protected
|
|
100
116
|
*/
|
|
101
|
-
protected
|
|
117
|
+
protected _reachableNodes(graph: Map<string, GraphEntry>, directDeps: string[], ignoredDeps: Set<string>): Set<string>;
|
|
102
118
|
/**
|
|
103
119
|
* @param {string} name
|
|
104
120
|
* @param {string} version
|
|
@@ -106,15 +122,6 @@ export default class Base_pyproject {
|
|
|
106
122
|
* @protected
|
|
107
123
|
*/
|
|
108
124
|
protected _toPurl(name: string, version: string): PackageURL;
|
|
109
|
-
/**
|
|
110
|
-
* Recursively add a dependency and its transitive deps to the SBOM.
|
|
111
|
-
* @param {PackageURL} source
|
|
112
|
-
* @param {DepTreeEntry} dep
|
|
113
|
-
* @param {Sbom} sbom
|
|
114
|
-
* @returns {void}
|
|
115
|
-
* @private
|
|
116
|
-
*/
|
|
117
|
-
private _addAllDependencies;
|
|
118
125
|
/**
|
|
119
126
|
* Create SBOM json string for a pyproject.toml project.
|
|
120
127
|
* @param {string} manifest - path to pyproject.toml
|
|
@@ -129,6 +136,10 @@ export type GraphEntry = {
|
|
|
129
136
|
name: string;
|
|
130
137
|
version: string;
|
|
131
138
|
children: string[];
|
|
139
|
+
hashes?: Array<{
|
|
140
|
+
alg: string;
|
|
141
|
+
content: string;
|
|
142
|
+
}>;
|
|
132
143
|
};
|
|
133
144
|
export type DepTreeEntry = {
|
|
134
145
|
name: string;
|
|
@@ -4,11 +4,13 @@ import { PackageURL } from 'packageurl-js';
|
|
|
4
4
|
import { parse as parseToml } from 'smol-toml';
|
|
5
5
|
import { getLicense } from '../license/license_utils.js';
|
|
6
6
|
import Sbom from '../sbom.js';
|
|
7
|
+
import { getCustom } from '../tools.js';
|
|
7
8
|
const ecosystem = 'pip';
|
|
8
9
|
const IGNORE_MARKERS = ['exhortignore', 'trustify-da-ignore'];
|
|
10
|
+
const NO_SCOPE = undefined;
|
|
9
11
|
const DEFAULT_ROOT_NAME = 'default-pip-root';
|
|
10
12
|
const DEFAULT_ROOT_VERSION = '0.0.0';
|
|
11
|
-
/** @typedef {{name: string, version: string, children: string[]}} GraphEntry */
|
|
13
|
+
/** @typedef {{name: string, version: string, children: string[], hashes?: Array<{alg: string, content: string}>}} GraphEntry */
|
|
12
14
|
/** @typedef {{name: string, version: string, dependencies: DepTreeEntry[]}} DepTreeEntry */
|
|
13
15
|
/** @typedef {{directDeps: string[], graph: Map<string, GraphEntry>}} DependencyData */
|
|
14
16
|
/** @typedef {{ecosystem: string, content: string, contentType: string}} Provided */
|
|
@@ -22,10 +24,64 @@ export default class Base_pyproject {
|
|
|
22
24
|
}
|
|
23
25
|
/**
|
|
24
26
|
* @param {string} manifestDir
|
|
27
|
+
* @param {Object} [opts={}]
|
|
25
28
|
* @returns {boolean}
|
|
26
29
|
*/
|
|
27
|
-
validateLockFile(manifestDir) {
|
|
28
|
-
return
|
|
30
|
+
validateLockFile(manifestDir, opts = {}) {
|
|
31
|
+
return this._findLockFileDir(manifestDir, opts) != null;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Walk up from manifestDir to find the directory containing the lock file.
|
|
35
|
+
* Follows the same pattern as Base_javascript._findLockFileDir().
|
|
36
|
+
* @param {string} manifestDir
|
|
37
|
+
* @param {Object} [opts={}]
|
|
38
|
+
* @returns {string|null}
|
|
39
|
+
* @protected
|
|
40
|
+
*/
|
|
41
|
+
_findLockFileDir(manifestDir, opts = {}) {
|
|
42
|
+
const workspaceDir = getCustom('TRUSTIFY_DA_WORKSPACE_DIR', null, opts);
|
|
43
|
+
if (workspaceDir) {
|
|
44
|
+
const dir = path.resolve(workspaceDir);
|
|
45
|
+
return fs.existsSync(path.join(dir, this._lockFileName())) ? dir : null;
|
|
46
|
+
}
|
|
47
|
+
let dir = path.resolve(manifestDir);
|
|
48
|
+
let parent = dir;
|
|
49
|
+
do {
|
|
50
|
+
dir = parent;
|
|
51
|
+
if (fs.existsSync(path.join(dir, this._lockFileName()))) {
|
|
52
|
+
return dir;
|
|
53
|
+
}
|
|
54
|
+
if (this._isWorkspaceRoot(dir)) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
parent = path.dirname(dir);
|
|
58
|
+
} while (parent !== dir);
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Detect workspace root boundaries.
|
|
63
|
+
* Currently only uv has native workspace support ([tool.uv.workspace] in pyproject.toml).
|
|
64
|
+
* Poetry has no workspace/monorepo support (python-poetry/poetry#2270), so each
|
|
65
|
+
* poetry project is treated independently — see Python_poetry._findLockFileDir().
|
|
66
|
+
* @param {string} dir
|
|
67
|
+
* @returns {boolean}
|
|
68
|
+
* @protected
|
|
69
|
+
*/
|
|
70
|
+
_isWorkspaceRoot(dir) {
|
|
71
|
+
const pyprojectPath = path.join(dir, 'pyproject.toml');
|
|
72
|
+
if (!fs.existsSync(pyprojectPath)) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
const content = parseToml(fs.readFileSync(pyprojectPath, 'utf-8'));
|
|
77
|
+
if (content.tool?.uv?.workspace) {
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch (_) {
|
|
82
|
+
// ignore parse errors
|
|
83
|
+
}
|
|
84
|
+
return false;
|
|
29
85
|
}
|
|
30
86
|
/**
|
|
31
87
|
* Read project license from pyproject.toml, with fallback to LICENSE file.
|
|
@@ -89,16 +145,26 @@ export default class Base_pyproject {
|
|
|
89
145
|
_cmdName() {
|
|
90
146
|
throw new TypeError('_cmdName must be implemented');
|
|
91
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* Returns the package manager name (e.g. pip, poetry, uv)
|
|
150
|
+
* @returns {string}
|
|
151
|
+
*/
|
|
152
|
+
packageManagerName() {
|
|
153
|
+
return this._cmdName();
|
|
154
|
+
}
|
|
92
155
|
/**
|
|
93
156
|
* Resolve dependencies using the tool-specific command and parser.
|
|
94
|
-
*
|
|
157
|
+
*
|
|
158
|
+
* @param {string} manifestDir - directory containing the target pyproject.toml
|
|
159
|
+
* @param {string} workspaceDir - workspace root (where the lock file lives);
|
|
160
|
+
* only used by providers that need workspace-level resolution (e.g. uv)
|
|
95
161
|
* @param {object} parsed - parsed pyproject.toml
|
|
96
162
|
* @param {Object} opts
|
|
97
163
|
* @returns {Promise<DependencyData>}
|
|
98
164
|
* @protected
|
|
99
165
|
*/
|
|
100
166
|
// eslint-disable-next-line no-unused-vars
|
|
101
|
-
async _getDependencyData(manifestDir, parsed, opts) {
|
|
167
|
+
async _getDependencyData(manifestDir, workspaceDir, parsed, opts) {
|
|
102
168
|
throw new TypeError('_getDependencyData must be implemented');
|
|
103
169
|
}
|
|
104
170
|
// --- shared helpers ---
|
|
@@ -162,64 +228,29 @@ export default class Base_pyproject {
|
|
|
162
228
|
return ignored;
|
|
163
229
|
}
|
|
164
230
|
/**
|
|
165
|
-
*
|
|
166
|
-
* @param {Map<string, GraphEntry>} graph
|
|
167
|
-
* @param {string[]} directDeps - canonical names of direct deps
|
|
168
|
-
* @param {Set<string>} ignoredDeps
|
|
169
|
-
* @param {boolean} includeTransitive
|
|
170
|
-
* @returns {DepTreeEntry[]}
|
|
171
|
-
* @protected
|
|
172
|
-
*/
|
|
173
|
-
_buildDependencyTree(graph, directDeps, ignoredDeps, includeTransitive) {
|
|
174
|
-
let result = [];
|
|
175
|
-
for (let key of directDeps) {
|
|
176
|
-
if (ignoredDeps.has(key)) {
|
|
177
|
-
continue;
|
|
178
|
-
}
|
|
179
|
-
let entry = graph.get(key);
|
|
180
|
-
if (!entry) {
|
|
181
|
-
continue;
|
|
182
|
-
}
|
|
183
|
-
let depTree = [];
|
|
184
|
-
if (includeTransitive) {
|
|
185
|
-
let visited = new Set();
|
|
186
|
-
visited.add(key);
|
|
187
|
-
this._collectTransitive(graph, entry.children, depTree, ignoredDeps, visited);
|
|
188
|
-
}
|
|
189
|
-
result.push({ name: entry.name, version: entry.version, dependencies: depTree });
|
|
190
|
-
}
|
|
191
|
-
result.sort((a, b) => a.name.toLowerCase().localeCompare(b.name.toLowerCase()));
|
|
192
|
-
return result;
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Recursively collect transitive dependencies.
|
|
231
|
+
* Compute the set of graph nodes reachable from direct deps, excluding ignored.
|
|
196
232
|
* @param {Map<string, GraphEntry>} graph
|
|
197
|
-
* @param {string[]}
|
|
198
|
-
* @param {DepTreeEntry[]} result - mutated in place
|
|
233
|
+
* @param {string[]} directDeps
|
|
199
234
|
* @param {Set<string>} ignoredDeps
|
|
200
|
-
* @
|
|
201
|
-
* @returns {void}
|
|
235
|
+
* @returns {Set<string>}
|
|
202
236
|
* @protected
|
|
203
237
|
*/
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
238
|
+
_reachableNodes(graph, directDeps, ignoredDeps) {
|
|
239
|
+
let reachable = new Set();
|
|
240
|
+
let queue = directDeps.filter(k => !ignoredDeps.has(k) && graph.has(k));
|
|
241
|
+
while (queue.length > 0) {
|
|
242
|
+
let key = queue.shift();
|
|
243
|
+
if (reachable.has(key)) {
|
|
208
244
|
continue;
|
|
209
245
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
if (!entry) {
|
|
216
|
-
continue;
|
|
246
|
+
reachable.add(key);
|
|
247
|
+
for (let child of graph.get(key).children) {
|
|
248
|
+
if (!ignoredDeps.has(child) && graph.has(child) && !reachable.has(child)) {
|
|
249
|
+
queue.push(child);
|
|
250
|
+
}
|
|
217
251
|
}
|
|
218
|
-
let childDeps = [];
|
|
219
|
-
this._collectTransitive(graph, entry.children, childDeps, ignoredDeps, visited);
|
|
220
|
-
result.push({ name: entry.name, version: entry.version, dependencies: childDeps });
|
|
221
252
|
}
|
|
222
|
-
|
|
253
|
+
return reachable;
|
|
223
254
|
}
|
|
224
255
|
/**
|
|
225
256
|
* @param {string} name
|
|
@@ -230,21 +261,6 @@ export default class Base_pyproject {
|
|
|
230
261
|
_toPurl(name, version) {
|
|
231
262
|
return new PackageURL('pypi', undefined, name, version, undefined, undefined);
|
|
232
263
|
}
|
|
233
|
-
/**
|
|
234
|
-
* Recursively add a dependency and its transitive deps to the SBOM.
|
|
235
|
-
* @param {PackageURL} source
|
|
236
|
-
* @param {DepTreeEntry} dep
|
|
237
|
-
* @param {Sbom} sbom
|
|
238
|
-
* @returns {void}
|
|
239
|
-
* @private
|
|
240
|
-
*/
|
|
241
|
-
_addAllDependencies(source, dep, sbom) {
|
|
242
|
-
let targetPurl = this._toPurl(dep.name, dep.version);
|
|
243
|
-
sbom.addDependency(source, targetPurl);
|
|
244
|
-
if (dep.dependencies && dep.dependencies.length > 0) {
|
|
245
|
-
dep.dependencies.forEach(child => this._addAllDependencies(this._toPurl(dep.name, dep.version), child, sbom));
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
264
|
/**
|
|
249
265
|
* Create SBOM json string for a pyproject.toml project.
|
|
250
266
|
* @param {string} manifest - path to pyproject.toml
|
|
@@ -257,23 +273,50 @@ export default class Base_pyproject {
|
|
|
257
273
|
let manifestDir = path.dirname(manifest);
|
|
258
274
|
let content = fs.readFileSync(manifest, 'utf-8');
|
|
259
275
|
let parsed = parseToml(content);
|
|
260
|
-
let
|
|
276
|
+
let workspaceDir = this._findLockFileDir(manifestDir, opts) || manifestDir;
|
|
277
|
+
let { directDeps, graph } = await this._getDependencyData(manifestDir, workspaceDir, parsed, opts);
|
|
261
278
|
let ignoredDeps = this._getIgnoredDeps(manifest);
|
|
262
|
-
let dependencies = this._buildDependencyTree(graph, directDeps, ignoredDeps, includeTransitive);
|
|
263
279
|
let sbom = new Sbom();
|
|
264
280
|
let rootName = this._getProjectName(parsed) || DEFAULT_ROOT_NAME;
|
|
265
281
|
let rootVersion = this._getProjectVersion(parsed) || DEFAULT_ROOT_VERSION;
|
|
266
282
|
let rootPurl = this._toPurl(rootName, rootVersion);
|
|
267
283
|
let license = this.readLicenseFromManifest(manifest);
|
|
268
284
|
sbom.addRoot(rootPurl, license);
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
285
|
+
if (includeTransitive) {
|
|
286
|
+
let reachable = this._reachableNodes(graph, directDeps, ignoredDeps);
|
|
287
|
+
for (let key of directDeps) {
|
|
288
|
+
if (!reachable.has(key)) {
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
let entry = graph.get(key);
|
|
292
|
+
sbom.addDependency(rootPurl, this._toPurl(entry.name, entry.version), NO_SCOPE, entry.hashes);
|
|
272
293
|
}
|
|
273
|
-
|
|
274
|
-
|
|
294
|
+
for (let [key, entry] of graph) {
|
|
295
|
+
if (!reachable.has(key)) {
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
let parentPurl = this._toPurl(entry.name, entry.version);
|
|
299
|
+
for (let child of entry.children) {
|
|
300
|
+
if (!reachable.has(child)) {
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
let childEntry = graph.get(child);
|
|
304
|
+
sbom.addDependency(parentPurl, this._toPurl(childEntry.name, childEntry.version), NO_SCOPE, childEntry.hashes);
|
|
305
|
+
}
|
|
275
306
|
}
|
|
276
|
-
}
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
for (let key of directDeps) {
|
|
310
|
+
if (ignoredDeps.has(key)) {
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
let entry = graph.get(key);
|
|
314
|
+
if (!entry) {
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
sbom.addDependency(rootPurl, this._toPurl(entry.name, entry.version), NO_SCOPE, entry.hashes);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
277
320
|
return sbom.getAsJsonString(opts);
|
|
278
321
|
}
|
|
279
322
|
}
|
|
@@ -1,9 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discover all go.mod manifest paths in a Go workspace.
|
|
3
|
+
* Uses `go work edit -json` to get workspace members.
|
|
4
|
+
*
|
|
5
|
+
* @param {string} workspaceRoot - Absolute or relative path to workspace root (must contain go.work)
|
|
6
|
+
* @param {import('../index.js').Options} [opts={}]
|
|
7
|
+
* @returns {Promise<string[]>} Paths to go.mod files (absolute)
|
|
8
|
+
*/
|
|
9
|
+
export function discoverGoWorkspaceModules(workspaceRoot: string, opts?: import("../index.js").Options): Promise<string[]>;
|
|
1
10
|
declare namespace _default {
|
|
2
11
|
export { isSupported };
|
|
3
12
|
export { validateLockFile };
|
|
4
13
|
export { provideComponent };
|
|
5
14
|
export { provideStack };
|
|
6
15
|
export { readLicenseFromManifest };
|
|
16
|
+
export function packageManagerName(): string;
|
|
7
17
|
}
|
|
8
18
|
export default _default;
|
|
9
19
|
export type Provided = import("../provider").Provided;
|
|
@@ -4,8 +4,9 @@ import { PackageURL } from 'packageurl-js';
|
|
|
4
4
|
import { readLicenseFile } from '../license/license_utils.js';
|
|
5
5
|
import Sbom from '../sbom.js';
|
|
6
6
|
import { getCustom, getCustomPath, invokeCommand } from "../tools.js";
|
|
7
|
+
import { filterManifestPathsByDiscoveryIgnore, resolveWorkspaceDiscoveryIgnore } from '../workspace.js';
|
|
7
8
|
import { getParser, getRequireQuery } from './gomod_parser.js';
|
|
8
|
-
export default { isSupported, validateLockFile, provideComponent, provideStack, readLicenseFromManifest };
|
|
9
|
+
export default { isSupported, validateLockFile, provideComponent, provideStack, readLicenseFromManifest, packageManagerName() { return 'go'; } };
|
|
9
10
|
/** @typedef {import('../provider').Provider} */
|
|
10
11
|
/** @typedef {import('../provider').Provided} Provided */
|
|
11
12
|
/** @typedef {{name: string, version: string}} Package */
|
|
@@ -328,13 +329,7 @@ function getFinalPackagesVersionsForModule(rows, manifestPath, goBin) {
|
|
|
328
329
|
catch (error) {
|
|
329
330
|
throw new Error('failed to list all modules', { cause: error });
|
|
330
331
|
}
|
|
331
|
-
let finalVersionModules =
|
|
332
|
-
finalVersionsForAllModules.split(getLineSeparatorGolang()).filter(string => string.trim() !== "")
|
|
333
|
-
.filter(string => string.trim().split(" ").length === 2)
|
|
334
|
-
.forEach((dependency) => {
|
|
335
|
-
let dep = dependency.split(" ");
|
|
336
|
-
finalVersionModules[dep[0]] = dep[1];
|
|
337
|
-
});
|
|
332
|
+
let finalVersionModules = parseModuleVersions(finalVersionsForAllModules);
|
|
338
333
|
let finalVersionModulesArray = new Array();
|
|
339
334
|
rows.filter(string => string.trim() !== "").forEach(module => {
|
|
340
335
|
let child = getChildVertexFromEdge(module);
|
|
@@ -395,7 +390,69 @@ function getVersionOfPackage(fullPackage) {
|
|
|
395
390
|
let parts = fullPackage.split("@");
|
|
396
391
|
return parts.length > 1 ? parts[1] : undefined;
|
|
397
392
|
}
|
|
393
|
+
function parseModuleVersions(goListOutput) {
|
|
394
|
+
let modules = {};
|
|
395
|
+
goListOutput.split(getLineSeparatorGolang()).filter(string => string.trim() !== "")
|
|
396
|
+
.forEach((line) => {
|
|
397
|
+
let parts = line.trim().split(" ");
|
|
398
|
+
if (parts.length === 2) {
|
|
399
|
+
modules[parts[0]] = parts[1];
|
|
400
|
+
}
|
|
401
|
+
else if (parts.length >= 4 && parts[2] === "=>") {
|
|
402
|
+
modules[parts[0]] = parts[parts.length - 1];
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
return modules;
|
|
406
|
+
}
|
|
398
407
|
function getLineSeparatorGolang() {
|
|
399
408
|
let reg = /\n|\r\n/;
|
|
400
409
|
return reg;
|
|
401
410
|
}
|
|
411
|
+
/**
|
|
412
|
+
* Discover all go.mod manifest paths in a Go workspace.
|
|
413
|
+
* Uses `go work edit -json` to get workspace members.
|
|
414
|
+
*
|
|
415
|
+
* @param {string} workspaceRoot - Absolute or relative path to workspace root (must contain go.work)
|
|
416
|
+
* @param {import('../index.js').Options} [opts={}]
|
|
417
|
+
* @returns {Promise<string[]>} Paths to go.mod files (absolute)
|
|
418
|
+
*/
|
|
419
|
+
export async function discoverGoWorkspaceModules(workspaceRoot, opts = {}) {
|
|
420
|
+
const root = path.resolve(workspaceRoot);
|
|
421
|
+
const goWork = path.join(root, 'go.work');
|
|
422
|
+
if (!fs.existsSync(goWork)) {
|
|
423
|
+
return [];
|
|
424
|
+
}
|
|
425
|
+
const goBin = getCustomPath('go', opts);
|
|
426
|
+
let output;
|
|
427
|
+
try {
|
|
428
|
+
output = invokeCommand(goBin, ['work', 'edit', '-json', goWork], { cwd: root });
|
|
429
|
+
}
|
|
430
|
+
catch {
|
|
431
|
+
return [];
|
|
432
|
+
}
|
|
433
|
+
let workspace;
|
|
434
|
+
try {
|
|
435
|
+
workspace = JSON.parse(output.toString().trim());
|
|
436
|
+
}
|
|
437
|
+
catch {
|
|
438
|
+
return [];
|
|
439
|
+
}
|
|
440
|
+
const useEntries = workspace.Use || [];
|
|
441
|
+
if (useEntries.length === 0) {
|
|
442
|
+
return [];
|
|
443
|
+
}
|
|
444
|
+
const manifestPaths = [];
|
|
445
|
+
for (const entry of useEntries) {
|
|
446
|
+
const diskPath = entry.DiskPath;
|
|
447
|
+
if (!diskPath) {
|
|
448
|
+
continue;
|
|
449
|
+
}
|
|
450
|
+
const moduleDir = path.resolve(root, diskPath);
|
|
451
|
+
const goMod = path.join(moduleDir, 'go.mod');
|
|
452
|
+
if (fs.existsSync(goMod)) {
|
|
453
|
+
manifestPaths.push(goMod);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
const ignorePatterns = resolveWorkspaceDiscoveryIgnore(opts);
|
|
457
|
+
return filterManifestPathsByDiscoveryIgnore(manifestPaths, root, ignorePatterns);
|
|
458
|
+
}
|