@trustify-da/trustify-da-javascript-client 0.3.0-ea.3aa2054 → 0.3.0-ea.4558b63
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/index.d.ts +58 -2
- package/dist/src/index.js +43 -2
- package/dist/src/provider.js +2 -0
- 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 +4 -25
- package/dist/src/providers/base_pyproject.js +48 -72
- 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.js +7 -3
- package/dist/src/providers/python_pip_pyproject.d.ts +61 -0
- package/dist/src/providers/python_pip_pyproject.js +144 -0
- package/dist/src/providers/python_poetry.d.ts +2 -1
- package/dist/src/providers/python_poetry.js +9 -3
- package/dist/src/providers/python_uv.js +4 -1
- package/dist/src/tools.d.ts +16 -0
- package/dist/src/tools.js +40 -0
- package/package.json +1 -1
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)
|
package/dist/src/provider.js
CHANGED
|
@@ -7,6 +7,7 @@ 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_pip_pyproject from './providers/python_pip_pyproject.js';
|
|
10
11
|
import Python_poetry from './providers/python_poetry.js';
|
|
11
12
|
import Python_uv from './providers/python_uv.js';
|
|
12
13
|
import rustCargoProvider from './providers/rust_cargo.js';
|
|
@@ -27,6 +28,7 @@ export const availableProviders = [
|
|
|
27
28
|
pythonPipProvider,
|
|
28
29
|
new Python_poetry(),
|
|
29
30
|
new Python_uv(),
|
|
31
|
+
new Python_pip_pyproject(),
|
|
30
32
|
rustCargoProvider
|
|
31
33
|
];
|
|
32
34
|
/**
|
|
@@ -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
|
}
|
|
@@ -102,26 +102,14 @@ export default class Base_pyproject {
|
|
|
102
102
|
*/
|
|
103
103
|
protected _getIgnoredDeps(manifestPath: string): Set<string>;
|
|
104
104
|
/**
|
|
105
|
-
*
|
|
105
|
+
* Compute the set of graph nodes reachable from direct deps, excluding ignored.
|
|
106
106
|
* @param {Map<string, GraphEntry>} graph
|
|
107
|
-
* @param {string[]} directDeps
|
|
107
|
+
* @param {string[]} directDeps
|
|
108
108
|
* @param {Set<string>} ignoredDeps
|
|
109
|
-
* @
|
|
110
|
-
* @returns {DepTreeEntry[]}
|
|
111
|
-
* @protected
|
|
112
|
-
*/
|
|
113
|
-
protected _buildDependencyTree(graph: Map<string, GraphEntry>, directDeps: string[], ignoredDeps: Set<string>, includeTransitive: boolean): DepTreeEntry[];
|
|
114
|
-
/**
|
|
115
|
-
* Recursively collect transitive dependencies.
|
|
116
|
-
* @param {Map<string, GraphEntry>} graph
|
|
117
|
-
* @param {string[]} childKeys
|
|
118
|
-
* @param {DepTreeEntry[]} result - mutated in place
|
|
119
|
-
* @param {Set<string>} ignoredDeps
|
|
120
|
-
* @param {Set<string>} visited
|
|
121
|
-
* @returns {void}
|
|
109
|
+
* @returns {Set<string>}
|
|
122
110
|
* @protected
|
|
123
111
|
*/
|
|
124
|
-
protected
|
|
112
|
+
protected _reachableNodes(graph: Map<string, GraphEntry>, directDeps: string[], ignoredDeps: Set<string>): Set<string>;
|
|
125
113
|
/**
|
|
126
114
|
* @param {string} name
|
|
127
115
|
* @param {string} version
|
|
@@ -129,15 +117,6 @@ export default class Base_pyproject {
|
|
|
129
117
|
* @protected
|
|
130
118
|
*/
|
|
131
119
|
protected _toPurl(name: string, version: string): PackageURL;
|
|
132
|
-
/**
|
|
133
|
-
* Recursively add a dependency and its transitive deps to the SBOM.
|
|
134
|
-
* @param {PackageURL} source
|
|
135
|
-
* @param {DepTreeEntry} dep
|
|
136
|
-
* @param {Sbom} sbom
|
|
137
|
-
* @returns {void}
|
|
138
|
-
* @private
|
|
139
|
-
*/
|
|
140
|
-
private _addAllDependencies;
|
|
141
120
|
/**
|
|
142
121
|
* Create SBOM json string for a pyproject.toml project.
|
|
143
122
|
* @param {string} manifest - path to pyproject.toml
|
|
@@ -220,64 +220,29 @@ export default class Base_pyproject {
|
|
|
220
220
|
return ignored;
|
|
221
221
|
}
|
|
222
222
|
/**
|
|
223
|
-
*
|
|
223
|
+
* Compute the set of graph nodes reachable from direct deps, excluding ignored.
|
|
224
224
|
* @param {Map<string, GraphEntry>} graph
|
|
225
|
-
* @param {string[]} directDeps
|
|
225
|
+
* @param {string[]} directDeps
|
|
226
226
|
* @param {Set<string>} ignoredDeps
|
|
227
|
-
* @
|
|
228
|
-
* @returns {DepTreeEntry[]}
|
|
229
|
-
* @protected
|
|
230
|
-
*/
|
|
231
|
-
_buildDependencyTree(graph, directDeps, ignoredDeps, includeTransitive) {
|
|
232
|
-
let result = [];
|
|
233
|
-
for (let key of directDeps) {
|
|
234
|
-
if (ignoredDeps.has(key)) {
|
|
235
|
-
continue;
|
|
236
|
-
}
|
|
237
|
-
let entry = graph.get(key);
|
|
238
|
-
if (!entry) {
|
|
239
|
-
continue;
|
|
240
|
-
}
|
|
241
|
-
let depTree = [];
|
|
242
|
-
if (includeTransitive) {
|
|
243
|
-
let visited = new Set();
|
|
244
|
-
visited.add(key);
|
|
245
|
-
this._collectTransitive(graph, entry.children, depTree, ignoredDeps, visited);
|
|
246
|
-
}
|
|
247
|
-
result.push({ name: entry.name, version: entry.version, dependencies: depTree });
|
|
248
|
-
}
|
|
249
|
-
result.sort((a, b) => a.name.toLowerCase().localeCompare(b.name.toLowerCase()));
|
|
250
|
-
return result;
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* Recursively collect transitive dependencies.
|
|
254
|
-
* @param {Map<string, GraphEntry>} graph
|
|
255
|
-
* @param {string[]} childKeys
|
|
256
|
-
* @param {DepTreeEntry[]} result - mutated in place
|
|
257
|
-
* @param {Set<string>} ignoredDeps
|
|
258
|
-
* @param {Set<string>} visited
|
|
259
|
-
* @returns {void}
|
|
227
|
+
* @returns {Set<string>}
|
|
260
228
|
* @protected
|
|
261
229
|
*/
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
if (visited.has(canonKey)) {
|
|
230
|
+
_reachableNodes(graph, directDeps, ignoredDeps) {
|
|
231
|
+
let reachable = new Set();
|
|
232
|
+
let queue = directDeps.filter(k => !ignoredDeps.has(k) && graph.has(k));
|
|
233
|
+
while (queue.length > 0) {
|
|
234
|
+
let key = queue.shift();
|
|
235
|
+
if (reachable.has(key)) {
|
|
269
236
|
continue;
|
|
270
237
|
}
|
|
271
|
-
|
|
272
|
-
let
|
|
273
|
-
|
|
274
|
-
|
|
238
|
+
reachable.add(key);
|
|
239
|
+
for (let child of graph.get(key).children) {
|
|
240
|
+
if (!ignoredDeps.has(child) && graph.has(child) && !reachable.has(child)) {
|
|
241
|
+
queue.push(child);
|
|
242
|
+
}
|
|
275
243
|
}
|
|
276
|
-
let childDeps = [];
|
|
277
|
-
this._collectTransitive(graph, entry.children, childDeps, ignoredDeps, visited);
|
|
278
|
-
result.push({ name: entry.name, version: entry.version, dependencies: childDeps });
|
|
279
244
|
}
|
|
280
|
-
|
|
245
|
+
return reachable;
|
|
281
246
|
}
|
|
282
247
|
/**
|
|
283
248
|
* @param {string} name
|
|
@@ -288,21 +253,6 @@ export default class Base_pyproject {
|
|
|
288
253
|
_toPurl(name, version) {
|
|
289
254
|
return new PackageURL('pypi', undefined, name, version, undefined, undefined);
|
|
290
255
|
}
|
|
291
|
-
/**
|
|
292
|
-
* Recursively add a dependency and its transitive deps to the SBOM.
|
|
293
|
-
* @param {PackageURL} source
|
|
294
|
-
* @param {DepTreeEntry} dep
|
|
295
|
-
* @param {Sbom} sbom
|
|
296
|
-
* @returns {void}
|
|
297
|
-
* @private
|
|
298
|
-
*/
|
|
299
|
-
_addAllDependencies(source, dep, sbom) {
|
|
300
|
-
let targetPurl = this._toPurl(dep.name, dep.version);
|
|
301
|
-
sbom.addDependency(source, targetPurl);
|
|
302
|
-
if (dep.dependencies && dep.dependencies.length > 0) {
|
|
303
|
-
dep.dependencies.forEach(child => this._addAllDependencies(this._toPurl(dep.name, dep.version), child, sbom));
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
256
|
/**
|
|
307
257
|
* Create SBOM json string for a pyproject.toml project.
|
|
308
258
|
* @param {string} manifest - path to pyproject.toml
|
|
@@ -318,21 +268,47 @@ export default class Base_pyproject {
|
|
|
318
268
|
let workspaceDir = this._findLockFileDir(manifestDir, opts) || manifestDir;
|
|
319
269
|
let { directDeps, graph } = await this._getDependencyData(manifestDir, workspaceDir, parsed, opts);
|
|
320
270
|
let ignoredDeps = this._getIgnoredDeps(manifest);
|
|
321
|
-
let dependencies = this._buildDependencyTree(graph, directDeps, ignoredDeps, includeTransitive);
|
|
322
271
|
let sbom = new Sbom();
|
|
323
272
|
let rootName = this._getProjectName(parsed) || DEFAULT_ROOT_NAME;
|
|
324
273
|
let rootVersion = this._getProjectVersion(parsed) || DEFAULT_ROOT_VERSION;
|
|
325
274
|
let rootPurl = this._toPurl(rootName, rootVersion);
|
|
326
275
|
let license = this.readLicenseFromManifest(manifest);
|
|
327
276
|
sbom.addRoot(rootPurl, license);
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
277
|
+
if (includeTransitive) {
|
|
278
|
+
let reachable = this._reachableNodes(graph, directDeps, ignoredDeps);
|
|
279
|
+
for (let key of directDeps) {
|
|
280
|
+
if (!reachable.has(key)) {
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
let entry = graph.get(key);
|
|
284
|
+
sbom.addDependency(rootPurl, this._toPurl(entry.name, entry.version));
|
|
331
285
|
}
|
|
332
|
-
|
|
333
|
-
|
|
286
|
+
for (let [key, entry] of graph) {
|
|
287
|
+
if (!reachable.has(key)) {
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
let parentPurl = this._toPurl(entry.name, entry.version);
|
|
291
|
+
for (let child of entry.children) {
|
|
292
|
+
if (!reachable.has(child)) {
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
let childEntry = graph.get(child);
|
|
296
|
+
sbom.addDependency(parentPurl, this._toPurl(childEntry.name, childEntry.version));
|
|
297
|
+
}
|
|
334
298
|
}
|
|
335
|
-
}
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
for (let key of directDeps) {
|
|
302
|
+
if (ignoredDeps.has(key)) {
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
let entry = graph.get(key);
|
|
306
|
+
if (!entry) {
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
309
|
+
sbom.addDependency(rootPurl, this._toPurl(entry.name, entry.version));
|
|
310
|
+
}
|
|
311
|
+
}
|
|
336
312
|
return sbom.getAsJsonString(opts);
|
|
337
313
|
}
|
|
338
314
|
}
|
|
@@ -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
|
|
@@ -95,7 +95,7 @@ export default class Python_controller {
|
|
|
95
95
|
}
|
|
96
96
|
/**
|
|
97
97
|
* Parse the requirements.txt file using tree-sitter and return structured requirement data.
|
|
98
|
-
* @return {Promise<{name: string, version: string|null}[]>}
|
|
98
|
+
* @return {Promise<{name: string, version: string|null, hasMarker: boolean}[]>}
|
|
99
99
|
*/
|
|
100
100
|
async #parseRequirements() {
|
|
101
101
|
const content = fs.readFileSync(this.pathToRequirements).toString();
|
|
@@ -107,7 +107,8 @@ export default class Python_controller {
|
|
|
107
107
|
const version = versionMatches.length > 0
|
|
108
108
|
? versionMatches[0].captures.find(c => c.name === 'version').node.text
|
|
109
109
|
: null;
|
|
110
|
-
|
|
110
|
+
const hasMarker = reqNode.children.some(c => c.type === 'marker_spec');
|
|
111
|
+
return { name, version, hasMarker };
|
|
111
112
|
}));
|
|
112
113
|
}
|
|
113
114
|
#decideIfWindowsOrLinuxPath(fileName) {
|
|
@@ -224,7 +225,10 @@ export default class Python_controller {
|
|
|
224
225
|
CachedEnvironmentDeps[packageName.replace("_", "-")] = pipDepTreeEntryForCache;
|
|
225
226
|
});
|
|
226
227
|
}
|
|
227
|
-
parsedRequirements.forEach(({ name: depName, version: manifestVersion }) => {
|
|
228
|
+
parsedRequirements.forEach(({ name: depName, version: manifestVersion, hasMarker }) => {
|
|
229
|
+
if (hasMarker && CachedEnvironmentDeps[depName.toLowerCase()] === undefined) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
228
232
|
if (matchManifestVersions === "true" && manifestVersion != null) {
|
|
229
233
|
let installedVersion;
|
|
230
234
|
if (CachedEnvironmentDeps[depName.toLowerCase()] !== undefined) {
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Python provider for pyproject.toml files using PEP 621 format without a lock file.
|
|
3
|
+
* Uses `pip install --dry-run --ignore-installed --report` to resolve the full dependency tree.
|
|
4
|
+
* Acts as the fallback provider when no lock file (uv.lock/poetry.lock) is found.
|
|
5
|
+
*/
|
|
6
|
+
export default class Python_pip_pyproject extends Base_pyproject {
|
|
7
|
+
/**
|
|
8
|
+
* Always returns true — pip provider is the fallback when no lock file is found.
|
|
9
|
+
* @param {string} manifestDir
|
|
10
|
+
* @param {{}} [opts={}]
|
|
11
|
+
* @returns {boolean}
|
|
12
|
+
*/
|
|
13
|
+
validateLockFile(manifestDir: string, opts?: {}): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Get pip report output from env var override or by running pip.
|
|
16
|
+
* @param {string} manifestDir - directory containing pyproject.toml
|
|
17
|
+
* @param {{}} [opts={}]
|
|
18
|
+
* @returns {string} pip report JSON string
|
|
19
|
+
*/
|
|
20
|
+
_getPipReportOutput(manifestDir: string, opts?: {}): string;
|
|
21
|
+
/**
|
|
22
|
+
* Parse pip report JSON and build dependency graph.
|
|
23
|
+
* @param {string} reportJson - pip report JSON string
|
|
24
|
+
* @returns {{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}}
|
|
25
|
+
*/
|
|
26
|
+
_parsePipReport(reportJson: string): {
|
|
27
|
+
directDeps: string[];
|
|
28
|
+
graph: Map<string, {
|
|
29
|
+
name: string;
|
|
30
|
+
version: string;
|
|
31
|
+
children: string[];
|
|
32
|
+
}>;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Check if a requires_dist entry is an extras-only dependency.
|
|
36
|
+
* @param {string} req - e.g. "PySocks!=1.5.7,>=1.5.6; extra == \"socks\""
|
|
37
|
+
* @returns {boolean}
|
|
38
|
+
*/
|
|
39
|
+
_hasExtraMarker(req: string): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Extract package name from a requires_dist entry.
|
|
42
|
+
* @param {string} req - e.g. "charset_normalizer<4,>=2"
|
|
43
|
+
* @returns {string|null}
|
|
44
|
+
*/
|
|
45
|
+
_extractDepName(req: string): string | null;
|
|
46
|
+
/**
|
|
47
|
+
* Resolve dependencies using pip install --dry-run --report.
|
|
48
|
+
* @param {string} manifestDir
|
|
49
|
+
* @param {string} _workspaceDir - unused (pip resolves from manifest directory)
|
|
50
|
+
* @param {object} parsed - parsed pyproject.toml
|
|
51
|
+
* @param {{}} [opts={}]
|
|
52
|
+
* @returns {Promise<{directDeps: string[], graph: Map}>}
|
|
53
|
+
*/
|
|
54
|
+
_getDependencyData(manifestDir: string, _workspaceDir: string, parsed: object, opts?: {}): Promise<{
|
|
55
|
+
directDeps: string[];
|
|
56
|
+
graph: Map<any, any>;
|
|
57
|
+
}>;
|
|
58
|
+
_findEggInfoDirs(dir: any): string[];
|
|
59
|
+
_cleanupEggInfo(dir: any, existing: any): void;
|
|
60
|
+
}
|
|
61
|
+
import Base_pyproject from './base_pyproject.js';
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { environmentVariableIsPopulated, getCustomPath, invokeCommand } from '../tools.js';
|
|
4
|
+
import Base_pyproject from './base_pyproject.js';
|
|
5
|
+
/**
|
|
6
|
+
* Python provider for pyproject.toml files using PEP 621 format without a lock file.
|
|
7
|
+
* Uses `pip install --dry-run --ignore-installed --report` to resolve the full dependency tree.
|
|
8
|
+
* Acts as the fallback provider when no lock file (uv.lock/poetry.lock) is found.
|
|
9
|
+
*/
|
|
10
|
+
export default class Python_pip_pyproject extends Base_pyproject {
|
|
11
|
+
/** @returns {string} */
|
|
12
|
+
_lockFileName() {
|
|
13
|
+
return '.pip-lock-nonexistent';
|
|
14
|
+
}
|
|
15
|
+
/** @returns {string} */
|
|
16
|
+
_cmdName() {
|
|
17
|
+
return 'pip';
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Always returns true — pip provider is the fallback when no lock file is found.
|
|
21
|
+
* @param {string} manifestDir
|
|
22
|
+
* @param {{}} [opts={}]
|
|
23
|
+
* @returns {boolean}
|
|
24
|
+
*/
|
|
25
|
+
// eslint-disable-next-line no-unused-vars
|
|
26
|
+
validateLockFile(manifestDir, opts = {}) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get pip report output from env var override or by running pip.
|
|
31
|
+
* @param {string} manifestDir - directory containing pyproject.toml
|
|
32
|
+
* @param {{}} [opts={}]
|
|
33
|
+
* @returns {string} pip report JSON string
|
|
34
|
+
*/
|
|
35
|
+
_getPipReportOutput(manifestDir, opts) {
|
|
36
|
+
if (environmentVariableIsPopulated('TRUSTIFY_DA_PIP_REPORT')) {
|
|
37
|
+
return Buffer.from(process.env['TRUSTIFY_DA_PIP_REPORT'], 'base64').toString('ascii');
|
|
38
|
+
}
|
|
39
|
+
let pipBin = getCustomPath('pip3', opts);
|
|
40
|
+
try {
|
|
41
|
+
invokeCommand(pipBin, ['--version']);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
pipBin = getCustomPath('pip', opts);
|
|
45
|
+
}
|
|
46
|
+
let eggInfoDirs = this._findEggInfoDirs(manifestDir);
|
|
47
|
+
let result = invokeCommand(pipBin, [
|
|
48
|
+
'install', '--dry-run', '--ignore-installed', '--quiet', '--report', '-', '.'
|
|
49
|
+
], { cwd: manifestDir }).toString();
|
|
50
|
+
this._cleanupEggInfo(manifestDir, eggInfoDirs);
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Parse pip report JSON and build dependency graph.
|
|
55
|
+
* @param {string} reportJson - pip report JSON string
|
|
56
|
+
* @returns {{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}}
|
|
57
|
+
*/
|
|
58
|
+
_parsePipReport(reportJson) {
|
|
59
|
+
let report = JSON.parse(reportJson);
|
|
60
|
+
let packages = report.install || [];
|
|
61
|
+
let rootEntry = packages.find(p => p.download_info?.dir_info !== undefined);
|
|
62
|
+
let rootRequires = rootEntry?.metadata?.requires_dist || [];
|
|
63
|
+
let directDepNames = new Set();
|
|
64
|
+
for (let req of rootRequires) {
|
|
65
|
+
if (this._hasExtraMarker(req)) {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
let name = this._extractDepName(req);
|
|
69
|
+
if (name) {
|
|
70
|
+
directDepNames.add(this._canonicalize(name));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
let graph = new Map();
|
|
74
|
+
let nonRootPackages = packages.filter(p => p !== rootEntry);
|
|
75
|
+
for (let pkg of nonRootPackages) {
|
|
76
|
+
let name = pkg.metadata.name;
|
|
77
|
+
let version = pkg.metadata.version;
|
|
78
|
+
let key = this._canonicalize(name);
|
|
79
|
+
graph.set(key, { name, version, children: [] });
|
|
80
|
+
}
|
|
81
|
+
for (let pkg of nonRootPackages) {
|
|
82
|
+
let key = this._canonicalize(pkg.metadata.name);
|
|
83
|
+
let entry = graph.get(key);
|
|
84
|
+
let requires = pkg.metadata.requires_dist || [];
|
|
85
|
+
for (let req of requires) {
|
|
86
|
+
let depName = this._extractDepName(req);
|
|
87
|
+
if (!depName) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
let depKey = this._canonicalize(depName);
|
|
91
|
+
if (graph.has(depKey)) {
|
|
92
|
+
entry.children.push(depKey);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
let directDeps = [...directDepNames].filter(key => graph.has(key));
|
|
97
|
+
return { directDeps, graph };
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Check if a requires_dist entry is an extras-only dependency.
|
|
101
|
+
* @param {string} req - e.g. "PySocks!=1.5.7,>=1.5.6; extra == \"socks\""
|
|
102
|
+
* @returns {boolean}
|
|
103
|
+
*/
|
|
104
|
+
_hasExtraMarker(req) {
|
|
105
|
+
return /;\s*.*extra\s*==/.test(req);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Extract package name from a requires_dist entry.
|
|
109
|
+
* @param {string} req - e.g. "charset_normalizer<4,>=2"
|
|
110
|
+
* @returns {string|null}
|
|
111
|
+
*/
|
|
112
|
+
_extractDepName(req) {
|
|
113
|
+
let match = req.match(/^([A-Za-z0-9]([A-Za-z0-9._-]*[A-Za-z0-9])?)/);
|
|
114
|
+
return match ? match[1] : null;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Resolve dependencies using pip install --dry-run --report.
|
|
118
|
+
* @param {string} manifestDir
|
|
119
|
+
* @param {string} _workspaceDir - unused (pip resolves from manifest directory)
|
|
120
|
+
* @param {object} parsed - parsed pyproject.toml
|
|
121
|
+
* @param {{}} [opts={}]
|
|
122
|
+
* @returns {Promise<{directDeps: string[], graph: Map}>}
|
|
123
|
+
*/
|
|
124
|
+
// eslint-disable-next-line no-unused-vars
|
|
125
|
+
async _getDependencyData(manifestDir, _workspaceDir, parsed, opts) {
|
|
126
|
+
let reportOutput = this._getPipReportOutput(manifestDir, opts);
|
|
127
|
+
return this._parsePipReport(reportOutput);
|
|
128
|
+
}
|
|
129
|
+
_findEggInfoDirs(dir) {
|
|
130
|
+
try {
|
|
131
|
+
return fs.readdirSync(dir).filter(f => f.endsWith('.egg-info'));
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
return [];
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
_cleanupEggInfo(dir, existing) {
|
|
138
|
+
for (let entry of this._findEggInfoDirs(dir)) {
|
|
139
|
+
if (!existing.includes(entry)) {
|
|
140
|
+
fs.rmSync(path.join(dir, entry), { recursive: true, force: true });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -2,10 +2,11 @@ export default class Python_poetry extends Base_pyproject {
|
|
|
2
2
|
/**
|
|
3
3
|
* Get poetry show --tree output.
|
|
4
4
|
* @param {string} manifestDir
|
|
5
|
+
* @param {boolean} hasDevGroup
|
|
5
6
|
* @param {Object} opts
|
|
6
7
|
* @returns {string}
|
|
7
8
|
*/
|
|
8
|
-
_getPoetryShowTreeOutput(manifestDir: string, opts: any): string;
|
|
9
|
+
_getPoetryShowTreeOutput(manifestDir: string, hasDevGroup: boolean, opts: any): string;
|
|
9
10
|
/**
|
|
10
11
|
* Get poetry show --all output (flat list with resolved versions).
|
|
11
12
|
* @param {string} manifestDir
|
|
@@ -39,7 +39,8 @@ export default class Python_poetry extends Base_pyproject {
|
|
|
39
39
|
*/
|
|
40
40
|
// eslint-disable-next-line no-unused-vars
|
|
41
41
|
async _getDependencyData(manifestDir, _workspaceDir, parsed, opts) {
|
|
42
|
-
let
|
|
42
|
+
let hasDevGroup = !!(parsed.tool?.poetry?.group?.dev || parsed.tool?.poetry?.['dev-dependencies']);
|
|
43
|
+
let treeOutput = this._getPoetryShowTreeOutput(manifestDir, hasDevGroup, opts);
|
|
43
44
|
let showAllOutput = this._getPoetryShowAllOutput(manifestDir, opts);
|
|
44
45
|
let versionMap = this._parsePoetryShowAll(showAllOutput);
|
|
45
46
|
return this._parsePoetryTree(treeOutput, versionMap);
|
|
@@ -47,15 +48,20 @@ export default class Python_poetry extends Base_pyproject {
|
|
|
47
48
|
/**
|
|
48
49
|
* Get poetry show --tree output.
|
|
49
50
|
* @param {string} manifestDir
|
|
51
|
+
* @param {boolean} hasDevGroup
|
|
50
52
|
* @param {Object} opts
|
|
51
53
|
* @returns {string}
|
|
52
54
|
*/
|
|
53
|
-
_getPoetryShowTreeOutput(manifestDir, opts) {
|
|
55
|
+
_getPoetryShowTreeOutput(manifestDir, hasDevGroup, opts) {
|
|
54
56
|
if (environmentVariableIsPopulated('TRUSTIFY_DA_POETRY_SHOW_TREE')) {
|
|
55
57
|
return Buffer.from(process.env['TRUSTIFY_DA_POETRY_SHOW_TREE'], 'base64').toString('utf-8');
|
|
56
58
|
}
|
|
57
59
|
let poetryBin = getCustomPath('poetry', opts);
|
|
58
|
-
|
|
60
|
+
let args = ['show', '--tree', '--no-ansi'];
|
|
61
|
+
if (hasDevGroup) {
|
|
62
|
+
args.push('--without', 'dev');
|
|
63
|
+
}
|
|
64
|
+
return invokeCommand(poetryBin, args, { cwd: manifestDir }).toString();
|
|
59
65
|
}
|
|
60
66
|
/**
|
|
61
67
|
* Get poetry show --all output (flat list with resolved versions).
|
|
@@ -36,7 +36,7 @@ export default class Python_uv extends Base_pyproject {
|
|
|
36
36
|
return Buffer.from(process.env['TRUSTIFY_DA_UV_EXPORT'], 'base64').toString('ascii');
|
|
37
37
|
}
|
|
38
38
|
let uvBin = getCustomPath('uv', opts);
|
|
39
|
-
return invokeCommand(uvBin, ['export', '--format', 'requirements.txt', '--frozen', '--no-hashes'], { cwd: manifestDir }).toString();
|
|
39
|
+
return invokeCommand(uvBin, ['export', '--format', 'requirements.txt', '--frozen', '--no-hashes', '--no-dev', '--no-emit-project'], { cwd: manifestDir }).toString();
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
42
|
* Parse uv export output into a dependency graph using tree-sitter-requirements
|
|
@@ -70,6 +70,9 @@ export default class Python_uv extends Base_pyproject {
|
|
|
70
70
|
let version = memberParsed.project?.version || memberParsed.tool?.poetry?.version;
|
|
71
71
|
if (name && version) {
|
|
72
72
|
let key = this._canonicalize(name);
|
|
73
|
+
if (key === canonProjectName) {
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
73
76
|
currentPkg = { name, version, parents: new Set() };
|
|
74
77
|
packages.set(key, currentPkg);
|
|
75
78
|
collectingVia = false;
|
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.4558b63",
|
|
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",
|