@trustify-da/trustify-da-javascript-client 0.3.0-ea.8e46e86 → 0.3.0-ea.8eab29b
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/cyclone_dx_sbom.d.ts +7 -1
- package/dist/src/cyclone_dx_sbom.js +29 -8
- package/dist/src/index.d.ts +62 -3
- package/dist/src/index.js +73 -6
- package/dist/src/provider.d.ts +3 -2
- package/dist/src/provider.js +5 -1
- package/dist/src/providers/base_java.d.ts +5 -9
- package/dist/src/providers/base_java.js +9 -38
- 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 +14 -26
- package/dist/src/providers/base_pyproject.js +57 -73
- 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 +93 -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 +37 -4
- package/dist/src/providers/python_poetry.js +82 -13
- package/dist/src/providers/python_uv.d.ts +28 -0
- package/dist/src/providers/python_uv.js +82 -1
- 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
|
@@ -0,0 +1,146 @@
|
|
|
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
|
+
let sha256 = pkg.download_info?.archive_info?.hashes?.sha256;
|
|
80
|
+
let hashes = sha256 ? [{ alg: "SHA-256", content: sha256 }] : undefined;
|
|
81
|
+
graph.set(key, { name, version, children: [], hashes });
|
|
82
|
+
}
|
|
83
|
+
for (let pkg of nonRootPackages) {
|
|
84
|
+
let key = this._canonicalize(pkg.metadata.name);
|
|
85
|
+
let entry = graph.get(key);
|
|
86
|
+
let requires = pkg.metadata.requires_dist || [];
|
|
87
|
+
for (let req of requires) {
|
|
88
|
+
let depName = this._extractDepName(req);
|
|
89
|
+
if (!depName) {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
let depKey = this._canonicalize(depName);
|
|
93
|
+
if (graph.has(depKey)) {
|
|
94
|
+
entry.children.push(depKey);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
let directDeps = [...directDepNames].filter(key => graph.has(key));
|
|
99
|
+
return { directDeps, graph };
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Check if a requires_dist entry is an extras-only dependency.
|
|
103
|
+
* @param {string} req - e.g. "PySocks!=1.5.7,>=1.5.6; extra == \"socks\""
|
|
104
|
+
* @returns {boolean}
|
|
105
|
+
*/
|
|
106
|
+
_hasExtraMarker(req) {
|
|
107
|
+
return /;\s*.*extra\s*==/.test(req);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Extract package name from a requires_dist entry.
|
|
111
|
+
* @param {string} req - e.g. "charset_normalizer<4,>=2"
|
|
112
|
+
* @returns {string|null}
|
|
113
|
+
*/
|
|
114
|
+
_extractDepName(req) {
|
|
115
|
+
let match = req.match(/^([A-Za-z0-9]([A-Za-z0-9._-]*[A-Za-z0-9])?)/);
|
|
116
|
+
return match ? match[1] : null;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Resolve dependencies using pip install --dry-run --report.
|
|
120
|
+
* @param {string} manifestDir
|
|
121
|
+
* @param {string} _workspaceDir - unused (pip resolves from manifest directory)
|
|
122
|
+
* @param {object} parsed - parsed pyproject.toml
|
|
123
|
+
* @param {{}} [opts={}]
|
|
124
|
+
* @returns {Promise<{directDeps: string[], graph: Map}>}
|
|
125
|
+
*/
|
|
126
|
+
// eslint-disable-next-line no-unused-vars
|
|
127
|
+
async _getDependencyData(manifestDir, _workspaceDir, parsed, opts) {
|
|
128
|
+
let reportOutput = this._getPipReportOutput(manifestDir, opts);
|
|
129
|
+
return this._parsePipReport(reportOutput);
|
|
130
|
+
}
|
|
131
|
+
_findEggInfoDirs(dir) {
|
|
132
|
+
try {
|
|
133
|
+
return fs.readdirSync(dir).filter(f => f.endsWith('.egg-info'));
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
return [];
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
_cleanupEggInfo(dir, existing) {
|
|
140
|
+
for (let entry of this._findEggInfoDirs(dir)) {
|
|
141
|
+
if (!existing.includes(entry)) {
|
|
142
|
+
fs.rmSync(path.join(dir, entry), { recursive: true, force: true });
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
@@ -1,11 +1,27 @@
|
|
|
1
1
|
export default class Python_poetry extends Base_pyproject {
|
|
2
|
+
/**
|
|
3
|
+
* @param {string} manifestDir
|
|
4
|
+
* @param {string} _workspaceDir - unused (poetry has no workspace support)
|
|
5
|
+
* @param {object} parsed - parsed pyproject.toml
|
|
6
|
+
* @param {Object} opts
|
|
7
|
+
* @returns {Promise<{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}>}
|
|
8
|
+
*/
|
|
9
|
+
_getDependencyData(manifestDir: string, _workspaceDir: string, parsed: object, opts: any): Promise<{
|
|
10
|
+
directDeps: string[];
|
|
11
|
+
graph: Map<string, {
|
|
12
|
+
name: string;
|
|
13
|
+
version: string;
|
|
14
|
+
children: string[];
|
|
15
|
+
}>;
|
|
16
|
+
}>;
|
|
2
17
|
/**
|
|
3
18
|
* Get poetry show --tree output.
|
|
4
19
|
* @param {string} manifestDir
|
|
20
|
+
* @param {boolean} hasDevGroup
|
|
5
21
|
* @param {Object} opts
|
|
6
22
|
* @returns {string}
|
|
7
23
|
*/
|
|
8
|
-
_getPoetryShowTreeOutput(manifestDir: string, opts: any): string;
|
|
24
|
+
_getPoetryShowTreeOutput(manifestDir: string, hasDevGroup: boolean, opts: any): string;
|
|
9
25
|
/**
|
|
10
26
|
* Get poetry show --all output (flat list with resolved versions).
|
|
11
27
|
* @param {string} manifestDir
|
|
@@ -21,16 +37,33 @@ export default class Python_poetry extends Base_pyproject {
|
|
|
21
37
|
* @returns {Map<string, string>} canonical name -> version
|
|
22
38
|
*/
|
|
23
39
|
_parsePoetryShowAll(output: string): Map<string, string>;
|
|
40
|
+
/**
|
|
41
|
+
* Collects PEP 508 marker expressions for direct and transitive deps.
|
|
42
|
+
* Direct markers come from pyproject.toml dependency strings, e.g.:
|
|
43
|
+
* "pywin32>=311 ; sys_platform == 'win32'" → directMarkers['pywin32'] = "sys_platform == 'win32'"
|
|
44
|
+
* Transitive markers come from poetry.lock [package.dependencies] entries, e.g.:
|
|
45
|
+
* colorama = {version = "*", markers = "sys_platform == 'win32'"}
|
|
46
|
+
* → transitiveMarkers['click']['colorama'] = "sys_platform == 'win32'"
|
|
47
|
+
* @param {string|null} lockDir
|
|
48
|
+
* @param {object} parsed - parsed pyproject.toml
|
|
49
|
+
* @returns {{directMarkers: Map<string, string>, transitiveMarkers: Map<string, Map<string, string>>}}
|
|
50
|
+
*/
|
|
51
|
+
_extractMarkerData(lockDir: string | null, parsed: object): {
|
|
52
|
+
directMarkers: Map<string, string>;
|
|
53
|
+
transitiveMarkers: Map<string, Map<string, string>>;
|
|
54
|
+
};
|
|
24
55
|
/**
|
|
25
56
|
* Parse poetry show --tree output into a dependency graph structure.
|
|
26
|
-
* Top-level lines (no indentation/tree chars) are direct deps: "name version description"
|
|
27
|
-
* Indented lines are transitive deps with tree chars: "├── name >=constraint"
|
|
28
57
|
*
|
|
29
58
|
* @param {string} treeOutput
|
|
30
59
|
* @param {Map<string, string>} versionMap - canonical name -> resolved version
|
|
60
|
+
* @param {{directMarkers: Map<string, string>, transitiveMarkers: Map<string, Map<string, string>>}} markerData
|
|
31
61
|
* @returns {{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}}
|
|
32
62
|
*/
|
|
33
|
-
_parsePoetryTree(treeOutput: string, versionMap: Map<string, string
|
|
63
|
+
_parsePoetryTree(treeOutput: string, versionMap: Map<string, string>, markerData: {
|
|
64
|
+
directMarkers: Map<string, string>;
|
|
65
|
+
transitiveMarkers: Map<string, Map<string, string>>;
|
|
66
|
+
}): {
|
|
34
67
|
directDeps: string[];
|
|
35
68
|
graph: Map<string, {
|
|
36
69
|
name: string;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
import { parse as parseToml } from 'smol-toml';
|
|
3
4
|
import { environmentVariableIsPopulated, getCustom, getCustomPath, invokeCommand } from '../tools.js';
|
|
4
5
|
import Base_pyproject from './base_pyproject.js';
|
|
6
|
+
import { evaluateMarker } from './marker_evaluator.js';
|
|
5
7
|
export default class Python_poetry extends Base_pyproject {
|
|
6
8
|
/**
|
|
7
9
|
* Poetry has no native workspace/monorepo support (python-poetry/poetry#2270).
|
|
@@ -39,23 +41,31 @@ export default class Python_poetry extends Base_pyproject {
|
|
|
39
41
|
*/
|
|
40
42
|
// eslint-disable-next-line no-unused-vars
|
|
41
43
|
async _getDependencyData(manifestDir, _workspaceDir, parsed, opts) {
|
|
42
|
-
let
|
|
44
|
+
let hasDevGroup = !!(parsed.tool?.poetry?.group?.dev || parsed.tool?.poetry?.['dev-dependencies']);
|
|
45
|
+
let treeOutput = this._getPoetryShowTreeOutput(manifestDir, hasDevGroup, opts);
|
|
43
46
|
let showAllOutput = this._getPoetryShowAllOutput(manifestDir, opts);
|
|
44
47
|
let versionMap = this._parsePoetryShowAll(showAllOutput);
|
|
45
|
-
|
|
48
|
+
let lockDir = this._findLockFileDir(manifestDir, opts);
|
|
49
|
+
let markerData = this._extractMarkerData(lockDir, parsed);
|
|
50
|
+
return this._parsePoetryTree(treeOutput, versionMap, markerData);
|
|
46
51
|
}
|
|
47
52
|
/**
|
|
48
53
|
* Get poetry show --tree output.
|
|
49
54
|
* @param {string} manifestDir
|
|
55
|
+
* @param {boolean} hasDevGroup
|
|
50
56
|
* @param {Object} opts
|
|
51
57
|
* @returns {string}
|
|
52
58
|
*/
|
|
53
|
-
_getPoetryShowTreeOutput(manifestDir, opts) {
|
|
59
|
+
_getPoetryShowTreeOutput(manifestDir, hasDevGroup, opts) {
|
|
54
60
|
if (environmentVariableIsPopulated('TRUSTIFY_DA_POETRY_SHOW_TREE')) {
|
|
55
61
|
return Buffer.from(process.env['TRUSTIFY_DA_POETRY_SHOW_TREE'], 'base64').toString('utf-8');
|
|
56
62
|
}
|
|
57
63
|
let poetryBin = getCustomPath('poetry', opts);
|
|
58
|
-
|
|
64
|
+
let args = ['show', '--tree', '--no-ansi'];
|
|
65
|
+
if (hasDevGroup) {
|
|
66
|
+
args.push('--without', 'dev');
|
|
67
|
+
}
|
|
68
|
+
return invokeCommand(poetryBin, args, { cwd: manifestDir }).toString();
|
|
59
69
|
}
|
|
60
70
|
/**
|
|
61
71
|
* Get poetry show --all output (flat list with resolved versions).
|
|
@@ -92,16 +102,60 @@ export default class Python_poetry extends Base_pyproject {
|
|
|
92
102
|
}
|
|
93
103
|
return versions;
|
|
94
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Collects PEP 508 marker expressions for direct and transitive deps.
|
|
107
|
+
* Direct markers come from pyproject.toml dependency strings, e.g.:
|
|
108
|
+
* "pywin32>=311 ; sys_platform == 'win32'" → directMarkers['pywin32'] = "sys_platform == 'win32'"
|
|
109
|
+
* Transitive markers come from poetry.lock [package.dependencies] entries, e.g.:
|
|
110
|
+
* colorama = {version = "*", markers = "sys_platform == 'win32'"}
|
|
111
|
+
* → transitiveMarkers['click']['colorama'] = "sys_platform == 'win32'"
|
|
112
|
+
* @param {string|null} lockDir
|
|
113
|
+
* @param {object} parsed - parsed pyproject.toml
|
|
114
|
+
* @returns {{directMarkers: Map<string, string>, transitiveMarkers: Map<string, Map<string, string>>}}
|
|
115
|
+
*/
|
|
116
|
+
_extractMarkerData(lockDir, parsed) {
|
|
117
|
+
let directMarkers = new Map();
|
|
118
|
+
let transitiveMarkers = new Map();
|
|
119
|
+
// Extract markers from PEP 621 dependency strings: "name[extras]>=ver ; marker"
|
|
120
|
+
let deps = parsed.project?.dependencies || [];
|
|
121
|
+
for (let dep of deps) {
|
|
122
|
+
let m = dep.match(/^([A-Za-z0-9][A-Za-z0-9._-]*)\s*[^;]*;\s*(.+)$/);
|
|
123
|
+
if (m) {
|
|
124
|
+
directMarkers.set(this._canonicalize(m[1]), m[2].trim());
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (lockDir) {
|
|
128
|
+
let lockPath = path.join(lockDir, this._lockFileName());
|
|
129
|
+
if (fs.existsSync(lockPath)) {
|
|
130
|
+
let lockContent = fs.readFileSync(lockPath, 'utf-8');
|
|
131
|
+
let lock = parseToml(lockContent);
|
|
132
|
+
let packages = lock.package || [];
|
|
133
|
+
for (let pkg of packages) {
|
|
134
|
+
let pkgKey = this._canonicalize(pkg.name);
|
|
135
|
+
let pkgDeps = pkg.dependencies || {};
|
|
136
|
+
for (let [depName, depSpec] of Object.entries(pkgDeps)) {
|
|
137
|
+
let markers = typeof depSpec === 'object' && depSpec != null ? depSpec.markers : null;
|
|
138
|
+
if (markers) {
|
|
139
|
+
if (!transitiveMarkers.has(pkgKey)) {
|
|
140
|
+
transitiveMarkers.set(pkgKey, new Map());
|
|
141
|
+
}
|
|
142
|
+
transitiveMarkers.get(pkgKey).set(this._canonicalize(depName), markers);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return { directMarkers, transitiveMarkers };
|
|
149
|
+
}
|
|
95
150
|
/**
|
|
96
151
|
* Parse poetry show --tree output into a dependency graph structure.
|
|
97
|
-
* Top-level lines (no indentation/tree chars) are direct deps: "name version description"
|
|
98
|
-
* Indented lines are transitive deps with tree chars: "├── name >=constraint"
|
|
99
152
|
*
|
|
100
153
|
* @param {string} treeOutput
|
|
101
154
|
* @param {Map<string, string>} versionMap - canonical name -> resolved version
|
|
155
|
+
* @param {{directMarkers: Map<string, string>, transitiveMarkers: Map<string, Map<string, string>>}} markerData
|
|
102
156
|
* @returns {{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}}
|
|
103
157
|
*/
|
|
104
|
-
_parsePoetryTree(treeOutput, versionMap) {
|
|
158
|
+
_parsePoetryTree(treeOutput, versionMap, markerData) {
|
|
105
159
|
let lines = treeOutput.split(/\r?\n/);
|
|
106
160
|
let graph = new Map();
|
|
107
161
|
let directDeps = [];
|
|
@@ -117,6 +171,12 @@ export default class Python_poetry extends Base_pyproject {
|
|
|
117
171
|
let name = topMatch[1];
|
|
118
172
|
let version = topMatch[2];
|
|
119
173
|
let key = this._canonicalize(name);
|
|
174
|
+
let marker = markerData.directMarkers.get(key);
|
|
175
|
+
if (marker && !evaluateMarker(marker)) {
|
|
176
|
+
currentDirectDep = null;
|
|
177
|
+
stack = [];
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
120
180
|
directDeps.push(key);
|
|
121
181
|
if (!graph.has(key)) {
|
|
122
182
|
graph.set(key, { name, version, children: [] });
|
|
@@ -143,6 +203,20 @@ export default class Python_poetry extends Base_pyproject {
|
|
|
143
203
|
// determine depth by counting tree-drawing groups in the prefix
|
|
144
204
|
let prefix = line.substring(0, nameStart);
|
|
145
205
|
let depth = (prefix.match(/(?:[├└│ ][\s─]{2} ?)/g) || []).length;
|
|
206
|
+
// pop stack back to find the parent at depth-1
|
|
207
|
+
while (stack.length > 0 && stack[stack.length - 1].depth >= depth) {
|
|
208
|
+
stack.pop();
|
|
209
|
+
}
|
|
210
|
+
let parentKey = stack.length > 0 ? stack[stack.length - 1].key : null;
|
|
211
|
+
if (parentKey) {
|
|
212
|
+
let parentMarkers = markerData.transitiveMarkers.get(parentKey);
|
|
213
|
+
if (parentMarkers) {
|
|
214
|
+
let marker = parentMarkers.get(depKey);
|
|
215
|
+
if (marker && !evaluateMarker(marker)) {
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
146
220
|
// resolve version from the version map
|
|
147
221
|
let version = versionMap.get(depKey) || null;
|
|
148
222
|
if (!version) {
|
|
@@ -151,12 +225,7 @@ export default class Python_poetry extends Base_pyproject {
|
|
|
151
225
|
if (!graph.has(depKey)) {
|
|
152
226
|
graph.set(depKey, { name: depName, version, children: [] });
|
|
153
227
|
}
|
|
154
|
-
|
|
155
|
-
while (stack.length > 0 && stack[stack.length - 1].depth >= depth) {
|
|
156
|
-
stack.pop();
|
|
157
|
-
}
|
|
158
|
-
if (stack.length > 0) {
|
|
159
|
-
let parentKey = stack[stack.length - 1].key;
|
|
228
|
+
if (parentKey) {
|
|
160
229
|
let parentEntry = graph.get(parentKey);
|
|
161
230
|
if (parentEntry && !parentEntry.children.includes(depKey)) {
|
|
162
231
|
parentEntry.children.push(depKey);
|
|
@@ -1,4 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discover all pyproject.toml manifest paths in a uv workspace.
|
|
3
|
+
* Parses `[tool.uv.workspace]` from root pyproject.toml and glob-expands member patterns.
|
|
4
|
+
*
|
|
5
|
+
* @param {string} workspaceRoot - Absolute or relative path to workspace root (must contain pyproject.toml and uv.lock)
|
|
6
|
+
* @param {{ workspaceDiscoveryIgnore?: string[], TRUSTIFY_DA_WORKSPACE_DISCOVERY_IGNORE?: string, [key: string]: unknown }} [opts={}]
|
|
7
|
+
* @returns {Promise<string[]>} Paths to pyproject.toml files (absolute)
|
|
8
|
+
*/
|
|
9
|
+
export function discoverUvWorkspaceMembers(workspaceRoot: string, opts?: {
|
|
10
|
+
workspaceDiscoveryIgnore?: string[];
|
|
11
|
+
TRUSTIFY_DA_WORKSPACE_DISCOVERY_IGNORE?: string;
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
}): Promise<string[]>;
|
|
1
14
|
export default class Python_uv extends Base_pyproject {
|
|
15
|
+
/**
|
|
16
|
+
* @param {string} manifestDir - directory containing the target pyproject.toml
|
|
17
|
+
* @param {string} workspaceDir - workspace root (for resolving editable install paths)
|
|
18
|
+
* @param {object} parsed - parsed pyproject.toml
|
|
19
|
+
* @param {Object} opts
|
|
20
|
+
* @returns {Promise<{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}>}
|
|
21
|
+
*/
|
|
22
|
+
_getDependencyData(manifestDir: string, workspaceDir: string, parsed: object, opts: any): Promise<{
|
|
23
|
+
directDeps: string[];
|
|
24
|
+
graph: Map<string, {
|
|
25
|
+
name: string;
|
|
26
|
+
version: string;
|
|
27
|
+
children: string[];
|
|
28
|
+
}>;
|
|
29
|
+
}>;
|
|
2
30
|
/**
|
|
3
31
|
* Get the uv export output, either from env var or by running the command.
|
|
4
32
|
* @param {string} manifestDir
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
import fg from 'fast-glob';
|
|
3
4
|
import { parse as parseToml } from 'smol-toml';
|
|
4
5
|
import { environmentVariableIsPopulated, getCustomPath, invokeCommand } from '../tools.js';
|
|
6
|
+
import { filterManifestPathsByDiscoveryIgnore, resolveWorkspaceDiscoveryIgnore, toManifestGlobPatterns } from '../workspace.js';
|
|
5
7
|
import Base_pyproject from './base_pyproject.js';
|
|
8
|
+
import { evaluateMarker } from './marker_evaluator.js';
|
|
6
9
|
import { getParser, getPinnedVersionQuery } from './requirements_parser.js';
|
|
7
10
|
export default class Python_uv extends Base_pyproject {
|
|
8
11
|
/** @returns {string} */
|
|
@@ -36,7 +39,7 @@ export default class Python_uv extends Base_pyproject {
|
|
|
36
39
|
return Buffer.from(process.env['TRUSTIFY_DA_UV_EXPORT'], 'base64').toString('ascii');
|
|
37
40
|
}
|
|
38
41
|
let uvBin = getCustomPath('uv', opts);
|
|
39
|
-
return invokeCommand(uvBin, ['export', '--format', 'requirements.txt', '--frozen', '--no-hashes'], { cwd: manifestDir }).toString();
|
|
42
|
+
return invokeCommand(uvBin, ['export', '--format', 'requirements.txt', '--frozen', '--no-hashes', '--no-dev', '--no-emit-project'], { cwd: manifestDir }).toString();
|
|
40
43
|
}
|
|
41
44
|
/**
|
|
42
45
|
* Parse uv export output into a dependency graph using tree-sitter-requirements
|
|
@@ -70,6 +73,9 @@ export default class Python_uv extends Base_pyproject {
|
|
|
70
73
|
let version = memberParsed.project?.version || memberParsed.tool?.poetry?.version;
|
|
71
74
|
if (name && version) {
|
|
72
75
|
let key = this._canonicalize(name);
|
|
76
|
+
if (key === canonProjectName) {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
73
79
|
currentPkg = { name, version, parents: new Set() };
|
|
74
80
|
packages.set(key, currentPkg);
|
|
75
81
|
collectingVia = false;
|
|
@@ -86,6 +92,16 @@ export default class Python_uv extends Base_pyproject {
|
|
|
86
92
|
if (!nameNode) {
|
|
87
93
|
continue;
|
|
88
94
|
}
|
|
95
|
+
// Skip packages with non-matching PEP 508 markers, e.g. "pywin32==311 ; sys_platform == 'win32'"
|
|
96
|
+
let markerNode = child.children.find(c => c.type === 'marker_spec');
|
|
97
|
+
if (markerNode) {
|
|
98
|
+
let markerText = markerNode.text.replace(/^\s*;\s*/, '');
|
|
99
|
+
if (!evaluateMarker(markerText)) {
|
|
100
|
+
currentPkg = null;
|
|
101
|
+
collectingVia = false;
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
89
105
|
let name = nameNode.text;
|
|
90
106
|
let version = null;
|
|
91
107
|
let versionMatches = pinnedVersionQuery.matches(child);
|
|
@@ -144,3 +160,68 @@ export default class Python_uv extends Base_pyproject {
|
|
|
144
160
|
return { directDeps, graph };
|
|
145
161
|
}
|
|
146
162
|
}
|
|
163
|
+
const DEFAULT_UV_DISCOVERY_IGNORE = [
|
|
164
|
+
'**/__pycache__/**',
|
|
165
|
+
'**/.venv/**',
|
|
166
|
+
];
|
|
167
|
+
/**
|
|
168
|
+
* Discover all pyproject.toml manifest paths in a uv workspace.
|
|
169
|
+
* Parses `[tool.uv.workspace]` from root pyproject.toml and glob-expands member patterns.
|
|
170
|
+
*
|
|
171
|
+
* @param {string} workspaceRoot - Absolute or relative path to workspace root (must contain pyproject.toml and uv.lock)
|
|
172
|
+
* @param {{ workspaceDiscoveryIgnore?: string[], TRUSTIFY_DA_WORKSPACE_DISCOVERY_IGNORE?: string, [key: string]: unknown }} [opts={}]
|
|
173
|
+
* @returns {Promise<string[]>} Paths to pyproject.toml files (absolute)
|
|
174
|
+
*/
|
|
175
|
+
export async function discoverUvWorkspaceMembers(workspaceRoot, opts = {}) {
|
|
176
|
+
const root = path.resolve(workspaceRoot);
|
|
177
|
+
const rootPyproject = path.join(root, 'pyproject.toml');
|
|
178
|
+
const uvLock = path.join(root, 'uv.lock');
|
|
179
|
+
if (!fs.existsSync(rootPyproject) || !fs.existsSync(uvLock)) {
|
|
180
|
+
return [];
|
|
181
|
+
}
|
|
182
|
+
let parsed;
|
|
183
|
+
try {
|
|
184
|
+
parsed = parseToml(fs.readFileSync(rootPyproject, 'utf-8'));
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
return [];
|
|
188
|
+
}
|
|
189
|
+
const workspaceConfig = parsed?.tool?.uv?.workspace;
|
|
190
|
+
if (!workspaceConfig) {
|
|
191
|
+
return [];
|
|
192
|
+
}
|
|
193
|
+
const memberPatterns = workspaceConfig.members;
|
|
194
|
+
if (!Array.isArray(memberPatterns) || memberPatterns.length === 0) {
|
|
195
|
+
return [];
|
|
196
|
+
}
|
|
197
|
+
const excludePatterns = Array.isArray(workspaceConfig.exclude) ? workspaceConfig.exclude : [];
|
|
198
|
+
const excludeGlobs = excludePatterns
|
|
199
|
+
.filter(p => typeof p === 'string' && p.trim())
|
|
200
|
+
.map(p => `${p.trim()}/pyproject.toml`);
|
|
201
|
+
const ignorePatterns = [...resolveWorkspaceDiscoveryIgnore(opts), ...DEFAULT_UV_DISCOVERY_IGNORE];
|
|
202
|
+
const globOpts = {
|
|
203
|
+
cwd: root,
|
|
204
|
+
absolute: true,
|
|
205
|
+
onlyFiles: true,
|
|
206
|
+
ignore: [...ignorePatterns, ...excludeGlobs],
|
|
207
|
+
followSymbolicLinks: false,
|
|
208
|
+
};
|
|
209
|
+
const patterns = toManifestGlobPatterns(memberPatterns.filter(p => typeof p === 'string'), 'pyproject.toml');
|
|
210
|
+
const manifestPaths = await fg(patterns, globOpts);
|
|
211
|
+
if (!manifestPaths.includes(rootPyproject) && hasProjectMetadata(parsed)) {
|
|
212
|
+
manifestPaths.unshift(rootPyproject);
|
|
213
|
+
}
|
|
214
|
+
return filterManifestPathsByDiscoveryIgnore(manifestPaths, root, ignorePatterns);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* @param {import('smol-toml').TomlTable} parsedPyProject
|
|
218
|
+
* @returns {boolean}
|
|
219
|
+
*/
|
|
220
|
+
function hasProjectMetadata(parsedPyProject) {
|
|
221
|
+
try {
|
|
222
|
+
return typeof parsedPyProject?.project?.name === 'string' && parsedPyProject.project.name.trim() !== '';
|
|
223
|
+
}
|
|
224
|
+
catch {
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
@@ -4,6 +4,7 @@ declare namespace _default {
|
|
|
4
4
|
export { provideComponent };
|
|
5
5
|
export { provideStack };
|
|
6
6
|
export { readLicenseFromManifest };
|
|
7
|
+
export function packageManagerName(): string;
|
|
7
8
|
}
|
|
8
9
|
export default _default;
|
|
9
10
|
export type Provided = import("../provider").Provided;
|
|
@@ -46,7 +47,10 @@ declare function provideStack(manifest: string, opts?: {}): Provided;
|
|
|
46
47
|
* Read project license from Cargo.toml, with fallback to LICENSE file.
|
|
47
48
|
* Supports the `license` field under `[package]` (single crate / workspace
|
|
48
49
|
* with root) and under `[workspace.package]` (virtual workspaces).
|
|
50
|
+
* When a member crate uses `license = { workspace = true }`, the actual
|
|
51
|
+
* license is resolved from the workspace root Cargo.toml.
|
|
49
52
|
* @param {string} manifestPath - path to Cargo.toml
|
|
53
|
+
* @param {object} [metadata] - cargo metadata output (needed for workspace license resolution)
|
|
50
54
|
* @returns {string|null} SPDX identifier or null
|
|
51
55
|
*/
|
|
52
|
-
declare function readLicenseFromManifest(manifestPath: string): string | null;
|
|
56
|
+
declare function readLicenseFromManifest(manifestPath: string, metadata?: object): string | null;
|
|
@@ -5,7 +5,7 @@ import { parse as parseToml } from 'smol-toml';
|
|
|
5
5
|
import { getLicense } from '../license/license_utils.js';
|
|
6
6
|
import Sbom from '../sbom.js';
|
|
7
7
|
import { getCustom, getCustomPath, invokeCommand } from '../tools.js';
|
|
8
|
-
export default { isSupported, validateLockFile, provideComponent, provideStack, readLicenseFromManifest };
|
|
8
|
+
export default { isSupported, validateLockFile, provideComponent, provideStack, readLicenseFromManifest, packageManagerName() { return 'cargo'; } };
|
|
9
9
|
/** @typedef {import('../provider').Provider} */
|
|
10
10
|
/** @typedef {import('../provider').Provided} Provided */
|
|
11
11
|
/**
|
|
@@ -71,15 +71,22 @@ function isSupported(manifestName) {
|
|
|
71
71
|
* Read project license from Cargo.toml, with fallback to LICENSE file.
|
|
72
72
|
* Supports the `license` field under `[package]` (single crate / workspace
|
|
73
73
|
* with root) and under `[workspace.package]` (virtual workspaces).
|
|
74
|
+
* When a member crate uses `license = { workspace = true }`, the actual
|
|
75
|
+
* license is resolved from the workspace root Cargo.toml.
|
|
74
76
|
* @param {string} manifestPath - path to Cargo.toml
|
|
77
|
+
* @param {object} [metadata] - cargo metadata output (needed for workspace license resolution)
|
|
75
78
|
* @returns {string|null} SPDX identifier or null
|
|
76
79
|
*/
|
|
77
|
-
function readLicenseFromManifest(manifestPath) {
|
|
80
|
+
function readLicenseFromManifest(manifestPath, metadata) {
|
|
78
81
|
let fromManifest = null;
|
|
79
82
|
try {
|
|
80
83
|
let content = fs.readFileSync(manifestPath, 'utf-8');
|
|
81
84
|
let parsed = parseToml(content);
|
|
82
|
-
|
|
85
|
+
let packageLicense = parsed.package?.license;
|
|
86
|
+
if (typeof packageLicense === 'object' && packageLicense?.workspace === true) {
|
|
87
|
+
packageLicense = resolveWorkspaceLicense(parsed, metadata);
|
|
88
|
+
}
|
|
89
|
+
fromManifest = packageLicense
|
|
83
90
|
|| parsed.workspace?.package?.license
|
|
84
91
|
|| null;
|
|
85
92
|
}
|
|
@@ -88,6 +95,26 @@ function readLicenseFromManifest(manifestPath) {
|
|
|
88
95
|
}
|
|
89
96
|
return getLicense(fromManifest, manifestPath);
|
|
90
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Resolve a workspace-inherited license from the workspace root Cargo.toml.
|
|
100
|
+
* @param {object} parsed - the parsed member crate Cargo.toml
|
|
101
|
+
* @param {object} [metadata] - cargo metadata output with workspace_root
|
|
102
|
+
* @returns {string|null} resolved license string or null
|
|
103
|
+
*/
|
|
104
|
+
function resolveWorkspaceLicense(parsed, metadata) {
|
|
105
|
+
if (metadata?.workspace_root) {
|
|
106
|
+
let cargoTomlPath = path.join(metadata.workspace_root, 'Cargo.toml');
|
|
107
|
+
try {
|
|
108
|
+
let content = fs.readFileSync(cargoTomlPath, 'utf-8');
|
|
109
|
+
let workspaceParsed = parseToml(content);
|
|
110
|
+
return workspaceParsed.workspace?.package?.license || null;
|
|
111
|
+
}
|
|
112
|
+
catch (_) {
|
|
113
|
+
// fall through
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return parsed.workspace?.package?.license || null;
|
|
117
|
+
}
|
|
91
118
|
/**
|
|
92
119
|
* Validates that Cargo.lock exists in the manifest directory or in a parent
|
|
93
120
|
* workspace root directory. In Cargo workspaces the lock file always lives at
|
|
@@ -173,7 +200,7 @@ function getSBOM(manifest, opts = {}, includeTransitive) {
|
|
|
173
200
|
let metadata = executeCargoMetadata(cargoBin, manifestDir);
|
|
174
201
|
let ignoredDeps = getIgnoredDeps(manifest, metadata);
|
|
175
202
|
let crateType = detectCrateType(metadata);
|
|
176
|
-
let license = readLicenseFromManifest(manifest);
|
|
203
|
+
let license = readLicenseFromManifest(manifest, metadata);
|
|
177
204
|
let sbom;
|
|
178
205
|
if (crateType === CrateType.WORKSPACE_VIRTUAL) {
|
|
179
206
|
sbom = handleVirtualWorkspace(manifest, metadata, ignoredDeps, includeTransitive, opts, license);
|
package/dist/src/sbom.d.ts
CHANGED
|
@@ -25,9 +25,14 @@ export default class Sbom {
|
|
|
25
25
|
/**
|
|
26
26
|
* @param {component} sourceRef current source Component ( Starting from root component by clients)
|
|
27
27
|
* @param {PackageURL} targetRef current dependency to add to Dependencies list of component sourceRef
|
|
28
|
+
* @param {string} [scope] - Scope of the dependency
|
|
29
|
+
* @param {Array<{alg: string, content: string}>} [targetHashes] - Optional hashes for the target component
|
|
28
30
|
* @return Sbom
|
|
29
31
|
*/
|
|
30
|
-
addDependency(sourceRef: component, targetRef: PackageURL, scope
|
|
32
|
+
addDependency(sourceRef: component, targetRef: PackageURL, scope?: string, targetHashes?: Array<{
|
|
33
|
+
alg: string;
|
|
34
|
+
content: string;
|
|
35
|
+
}>): CycloneDxSbom;
|
|
31
36
|
/**
|
|
32
37
|
* @return String sbom json in a string format
|
|
33
38
|
*/
|
|
@@ -45,6 +50,7 @@ export default class Sbom {
|
|
|
45
50
|
version: any;
|
|
46
51
|
scope: any;
|
|
47
52
|
licenses?: any;
|
|
53
|
+
hashes?: any;
|
|
48
54
|
};
|
|
49
55
|
/** This method gets a component object, and a string name, and checks if the name is a substring of the component' purl.
|
|
50
56
|
* @param {} component to search in its dependencies
|
package/dist/src/sbom.js
CHANGED
|
@@ -43,10 +43,12 @@ export default class Sbom {
|
|
|
43
43
|
/**
|
|
44
44
|
* @param {component} sourceRef current source Component ( Starting from root component by clients)
|
|
45
45
|
* @param {PackageURL} targetRef current dependency to add to Dependencies list of component sourceRef
|
|
46
|
+
* @param {string} [scope] - Scope of the dependency
|
|
47
|
+
* @param {Array<{alg: string, content: string}>} [targetHashes] - Optional hashes for the target component
|
|
46
48
|
* @return Sbom
|
|
47
49
|
*/
|
|
48
|
-
addDependency(sourceRef, targetRef, scope) {
|
|
49
|
-
return this.sbomModel.addDependency(sourceRef, targetRef, scope);
|
|
50
|
+
addDependency(sourceRef, targetRef, scope, targetHashes) {
|
|
51
|
+
return this.sbomModel.addDependency(sourceRef, targetRef, scope, targetHashes);
|
|
50
52
|
}
|
|
51
53
|
/**
|
|
52
54
|
* @return String sbom json in a string format
|