@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,18 +1,35 @@
|
|
|
1
1
|
export default class Python_poetry extends Base_pyproject {
|
|
2
|
+
_verifyPoetryAccessible(poetryBin: any): void;
|
|
2
3
|
/**
|
|
3
|
-
* Get poetry show --tree output.
|
|
4
4
|
* @param {string} manifestDir
|
|
5
|
+
* @param {string} _workspaceDir - unused (poetry has no workspace support)
|
|
6
|
+
* @param {object} parsed - parsed pyproject.toml
|
|
5
7
|
* @param {Object} opts
|
|
8
|
+
* @returns {Promise<{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}>}
|
|
9
|
+
*/
|
|
10
|
+
_getDependencyData(manifestDir: string, _workspaceDir: string, parsed: object, opts: any): Promise<{
|
|
11
|
+
directDeps: string[];
|
|
12
|
+
graph: Map<string, {
|
|
13
|
+
name: string;
|
|
14
|
+
version: string;
|
|
15
|
+
children: string[];
|
|
16
|
+
}>;
|
|
17
|
+
}>;
|
|
18
|
+
/**
|
|
19
|
+
* Get poetry show --tree output.
|
|
20
|
+
* @param {string} manifestDir
|
|
21
|
+
* @param {boolean} hasDevGroup
|
|
22
|
+
* @param {string} poetryBin
|
|
6
23
|
* @returns {string}
|
|
7
24
|
*/
|
|
8
|
-
_getPoetryShowTreeOutput(manifestDir: string,
|
|
25
|
+
_getPoetryShowTreeOutput(manifestDir: string, hasDevGroup: boolean, poetryBin: string): string;
|
|
9
26
|
/**
|
|
10
27
|
* Get poetry show --all output (flat list with resolved versions).
|
|
11
28
|
* @param {string} manifestDir
|
|
12
|
-
* @param {
|
|
29
|
+
* @param {string} poetryBin
|
|
13
30
|
* @returns {string}
|
|
14
31
|
*/
|
|
15
|
-
_getPoetryShowAllOutput(manifestDir: string,
|
|
32
|
+
_getPoetryShowAllOutput(manifestDir: string, poetryBin: string): string;
|
|
16
33
|
/**
|
|
17
34
|
* Parse poetry show --all output into a version map.
|
|
18
35
|
* Lines look like: "name (!) 1.2.3 Description text..."
|
|
@@ -21,21 +38,60 @@ export default class Python_poetry extends Base_pyproject {
|
|
|
21
38
|
* @returns {Map<string, string>} canonical name -> version
|
|
22
39
|
*/
|
|
23
40
|
_parsePoetryShowAll(output: string): Map<string, string>;
|
|
41
|
+
/**
|
|
42
|
+
* Collects PEP 508 marker expressions for direct and transitive deps.
|
|
43
|
+
* Direct markers come from pyproject.toml dependency strings, e.g.:
|
|
44
|
+
* "pywin32>=311 ; sys_platform == 'win32'" → directMarkers['pywin32'] = "sys_platform == 'win32'"
|
|
45
|
+
* Transitive markers come from poetry.lock [package.dependencies] entries, e.g.:
|
|
46
|
+
* colorama = {version = "*", markers = "sys_platform == 'win32'"}
|
|
47
|
+
* → transitiveMarkers['click']['colorama'] = "sys_platform == 'win32'"
|
|
48
|
+
* @param {string|null} lockDir
|
|
49
|
+
* @param {object} parsed - parsed pyproject.toml
|
|
50
|
+
* @returns {{directMarkers: Map<string, string>, transitiveMarkers: Map<string, Map<string, string>>, hashMap: Map<string, Array<{alg: string, content: string}>>}}
|
|
51
|
+
*/
|
|
52
|
+
_extractMarkerData(lockDir: string | null, parsed: object): {
|
|
53
|
+
directMarkers: Map<string, string>;
|
|
54
|
+
transitiveMarkers: Map<string, Map<string, string>>;
|
|
55
|
+
hashMap: Map<string, Array<{
|
|
56
|
+
alg: string;
|
|
57
|
+
content: string;
|
|
58
|
+
}>>;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Extract a SHA-256 hex digest from poetry.lock files array.
|
|
62
|
+
* Prefers the sdist (.tar.gz) hash; falls back to the first wheel hash.
|
|
63
|
+
* @param {Array<{file: string, hash: string}>} [files]
|
|
64
|
+
* @returns {string|null}
|
|
65
|
+
*/
|
|
66
|
+
_extractSha256FromFiles(files?: Array<{
|
|
67
|
+
file: string;
|
|
68
|
+
hash: string;
|
|
69
|
+
}>): string | null;
|
|
24
70
|
/**
|
|
25
71
|
* 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
72
|
*
|
|
29
73
|
* @param {string} treeOutput
|
|
30
74
|
* @param {Map<string, string>} versionMap - canonical name -> resolved version
|
|
31
|
-
* @
|
|
75
|
+
* @param {{directMarkers: Map<string, string>, transitiveMarkers: Map<string, Map<string, string>>, hashMap: Map<string, Array<{alg: string, content: string}>>}} markerData
|
|
76
|
+
* @returns {{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[], hashes?: Array<{alg: string, content: string}>}>}}
|
|
32
77
|
*/
|
|
33
|
-
_parsePoetryTree(treeOutput: string, versionMap: Map<string, string
|
|
78
|
+
_parsePoetryTree(treeOutput: string, versionMap: Map<string, string>, markerData: {
|
|
79
|
+
directMarkers: Map<string, string>;
|
|
80
|
+
transitiveMarkers: Map<string, Map<string, string>>;
|
|
81
|
+
hashMap: Map<string, Array<{
|
|
82
|
+
alg: string;
|
|
83
|
+
content: string;
|
|
84
|
+
}>>;
|
|
85
|
+
}): {
|
|
34
86
|
directDeps: string[];
|
|
35
87
|
graph: Map<string, {
|
|
36
88
|
name: string;
|
|
37
89
|
version: string;
|
|
38
90
|
children: string[];
|
|
91
|
+
hashes?: Array<{
|
|
92
|
+
alg: string;
|
|
93
|
+
content: string;
|
|
94
|
+
}>;
|
|
39
95
|
}>;
|
|
40
96
|
};
|
|
41
97
|
}
|
|
@@ -1,6 +1,29 @@
|
|
|
1
|
-
import
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { parse as parseToml } from 'smol-toml';
|
|
4
|
+
import { environmentVariableIsPopulated, getCustom, getCustomPath, invokeCommand } from '../tools.js';
|
|
2
5
|
import Base_pyproject from './base_pyproject.js';
|
|
6
|
+
import { evaluateMarker } from './marker_evaluator.js';
|
|
3
7
|
export default class Python_poetry extends Base_pyproject {
|
|
8
|
+
/**
|
|
9
|
+
* Poetry has no native workspace/monorepo support (python-poetry/poetry#2270).
|
|
10
|
+
* Each poetry project is treated independently — no lock file walk-up.
|
|
11
|
+
* Running `poetry show` from a parent directory returns the parent's deps, not
|
|
12
|
+
* the sub-package's, so walk-up would produce incorrect SBOMs.
|
|
13
|
+
* @param {string} manifestDir
|
|
14
|
+
* @param {Object} [opts={}]
|
|
15
|
+
* @returns {string|null}
|
|
16
|
+
* @protected
|
|
17
|
+
*/
|
|
18
|
+
_findLockFileDir(manifestDir, opts = {}) {
|
|
19
|
+
const workspaceDir = getCustom('TRUSTIFY_DA_WORKSPACE_DIR', null, opts);
|
|
20
|
+
if (workspaceDir) {
|
|
21
|
+
const dir = path.resolve(workspaceDir);
|
|
22
|
+
return fs.existsSync(path.join(dir, this._lockFileName())) ? dir : null;
|
|
23
|
+
}
|
|
24
|
+
const dir = path.resolve(manifestDir);
|
|
25
|
+
return fs.existsSync(path.join(dir, this._lockFileName())) ? dir : null;
|
|
26
|
+
}
|
|
4
27
|
/** @returns {string} */
|
|
5
28
|
_lockFileName() {
|
|
6
29
|
return 'poetry.lock';
|
|
@@ -9,42 +32,67 @@ export default class Python_poetry extends Base_pyproject {
|
|
|
9
32
|
_cmdName() {
|
|
10
33
|
return 'poetry';
|
|
11
34
|
}
|
|
35
|
+
_verifyPoetryAccessible(poetryBin) {
|
|
36
|
+
try {
|
|
37
|
+
invokeCommand(poetryBin, ['--version']);
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
if (error.code === 'ENOENT') {
|
|
41
|
+
throw new Error(`poetry is not accessible at "${poetryBin}"`, { cause: error });
|
|
42
|
+
}
|
|
43
|
+
throw new Error('failed to check for poetry binary', { cause: error });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
12
46
|
/**
|
|
13
47
|
* @param {string} manifestDir
|
|
48
|
+
* @param {string} _workspaceDir - unused (poetry has no workspace support)
|
|
14
49
|
* @param {object} parsed - parsed pyproject.toml
|
|
15
50
|
* @param {Object} opts
|
|
16
51
|
* @returns {Promise<{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}>}
|
|
17
52
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
let
|
|
53
|
+
// eslint-disable-next-line no-unused-vars
|
|
54
|
+
async _getDependencyData(manifestDir, _workspaceDir, parsed, opts) {
|
|
55
|
+
let poetryBin = getCustomPath('poetry', opts);
|
|
56
|
+
let envBypass = environmentVariableIsPopulated('TRUSTIFY_DA_POETRY_SHOW_TREE')
|
|
57
|
+
&& environmentVariableIsPopulated('TRUSTIFY_DA_POETRY_SHOW_ALL');
|
|
58
|
+
if (!envBypass) {
|
|
59
|
+
this._verifyPoetryAccessible(poetryBin);
|
|
60
|
+
}
|
|
61
|
+
let hasDevGroup = !!(parsed.tool?.poetry?.group?.dev || parsed.tool?.poetry?.['dev-dependencies']);
|
|
62
|
+
let treeOutput = this._getPoetryShowTreeOutput(manifestDir, hasDevGroup, poetryBin);
|
|
63
|
+
let showAllOutput = this._getPoetryShowAllOutput(manifestDir, poetryBin);
|
|
21
64
|
let versionMap = this._parsePoetryShowAll(showAllOutput);
|
|
22
|
-
|
|
65
|
+
let lockDir = this._findLockFileDir(manifestDir, opts);
|
|
66
|
+
let markerData = this._extractMarkerData(lockDir, parsed);
|
|
67
|
+
return this._parsePoetryTree(treeOutput, versionMap, markerData);
|
|
23
68
|
}
|
|
24
69
|
/**
|
|
25
70
|
* Get poetry show --tree output.
|
|
26
71
|
* @param {string} manifestDir
|
|
27
|
-
* @param {
|
|
72
|
+
* @param {boolean} hasDevGroup
|
|
73
|
+
* @param {string} poetryBin
|
|
28
74
|
* @returns {string}
|
|
29
75
|
*/
|
|
30
|
-
_getPoetryShowTreeOutput(manifestDir,
|
|
76
|
+
_getPoetryShowTreeOutput(manifestDir, hasDevGroup, poetryBin) {
|
|
31
77
|
if (environmentVariableIsPopulated('TRUSTIFY_DA_POETRY_SHOW_TREE')) {
|
|
32
78
|
return Buffer.from(process.env['TRUSTIFY_DA_POETRY_SHOW_TREE'], 'base64').toString('utf-8');
|
|
33
79
|
}
|
|
34
|
-
let
|
|
35
|
-
|
|
80
|
+
let args = ['show', '--tree', '--no-ansi'];
|
|
81
|
+
if (hasDevGroup) {
|
|
82
|
+
args.push('--without', 'dev');
|
|
83
|
+
}
|
|
84
|
+
return invokeCommand(poetryBin, args, { cwd: manifestDir }).toString();
|
|
36
85
|
}
|
|
37
86
|
/**
|
|
38
87
|
* Get poetry show --all output (flat list with resolved versions).
|
|
39
88
|
* @param {string} manifestDir
|
|
40
|
-
* @param {
|
|
89
|
+
* @param {string} poetryBin
|
|
41
90
|
* @returns {string}
|
|
42
91
|
*/
|
|
43
|
-
_getPoetryShowAllOutput(manifestDir,
|
|
92
|
+
_getPoetryShowAllOutput(manifestDir, poetryBin) {
|
|
44
93
|
if (environmentVariableIsPopulated('TRUSTIFY_DA_POETRY_SHOW_ALL')) {
|
|
45
94
|
return Buffer.from(process.env['TRUSTIFY_DA_POETRY_SHOW_ALL'], 'base64').toString('utf-8');
|
|
46
95
|
}
|
|
47
|
-
let poetryBin = getCustomPath('poetry', opts);
|
|
48
96
|
return invokeCommand(poetryBin, ['show', '--no-ansi', '--all'], { cwd: manifestDir }).toString();
|
|
49
97
|
}
|
|
50
98
|
/**
|
|
@@ -69,16 +117,83 @@ export default class Python_poetry extends Base_pyproject {
|
|
|
69
117
|
}
|
|
70
118
|
return versions;
|
|
71
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Collects PEP 508 marker expressions for direct and transitive deps.
|
|
122
|
+
* Direct markers come from pyproject.toml dependency strings, e.g.:
|
|
123
|
+
* "pywin32>=311 ; sys_platform == 'win32'" → directMarkers['pywin32'] = "sys_platform == 'win32'"
|
|
124
|
+
* Transitive markers come from poetry.lock [package.dependencies] entries, e.g.:
|
|
125
|
+
* colorama = {version = "*", markers = "sys_platform == 'win32'"}
|
|
126
|
+
* → transitiveMarkers['click']['colorama'] = "sys_platform == 'win32'"
|
|
127
|
+
* @param {string|null} lockDir
|
|
128
|
+
* @param {object} parsed - parsed pyproject.toml
|
|
129
|
+
* @returns {{directMarkers: Map<string, string>, transitiveMarkers: Map<string, Map<string, string>>, hashMap: Map<string, Array<{alg: string, content: string}>>}}
|
|
130
|
+
*/
|
|
131
|
+
_extractMarkerData(lockDir, parsed) {
|
|
132
|
+
let directMarkers = new Map();
|
|
133
|
+
let transitiveMarkers = new Map();
|
|
134
|
+
let hashMap = new Map();
|
|
135
|
+
// Extract markers from PEP 621 dependency strings: "name[extras]>=ver ; marker"
|
|
136
|
+
let deps = parsed.project?.dependencies || [];
|
|
137
|
+
for (let dep of deps) {
|
|
138
|
+
let m = dep.match(/^([A-Za-z0-9][A-Za-z0-9._-]*)\s*[^;]*;\s*(.+)$/);
|
|
139
|
+
if (m) {
|
|
140
|
+
directMarkers.set(this._canonicalize(m[1]), m[2].trim());
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (lockDir) {
|
|
144
|
+
let lockPath = path.join(lockDir, this._lockFileName());
|
|
145
|
+
if (fs.existsSync(lockPath)) {
|
|
146
|
+
let lockContent = fs.readFileSync(lockPath, 'utf-8');
|
|
147
|
+
let lock = parseToml(lockContent);
|
|
148
|
+
let packages = lock.package || [];
|
|
149
|
+
for (let pkg of packages) {
|
|
150
|
+
let pkgKey = this._canonicalize(pkg.name);
|
|
151
|
+
let pkgDeps = pkg.dependencies || {};
|
|
152
|
+
for (let [depName, depSpec] of Object.entries(pkgDeps)) {
|
|
153
|
+
let markers = typeof depSpec === 'object' && depSpec != null ? depSpec.markers : null;
|
|
154
|
+
if (markers) {
|
|
155
|
+
if (!transitiveMarkers.has(pkgKey)) {
|
|
156
|
+
transitiveMarkers.set(pkgKey, new Map());
|
|
157
|
+
}
|
|
158
|
+
transitiveMarkers.get(pkgKey).set(this._canonicalize(depName), markers);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
let sha256Hex = this._extractSha256FromFiles(pkg.files);
|
|
162
|
+
if (sha256Hex) {
|
|
163
|
+
hashMap.set(pkgKey, [{ alg: "SHA-256", content: sha256Hex }]);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return { directMarkers, transitiveMarkers, hashMap };
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Extract a SHA-256 hex digest from poetry.lock files array.
|
|
172
|
+
* Prefers the sdist (.tar.gz) hash; falls back to the first wheel hash.
|
|
173
|
+
* @param {Array<{file: string, hash: string}>} [files]
|
|
174
|
+
* @returns {string|null}
|
|
175
|
+
*/
|
|
176
|
+
_extractSha256FromFiles(files) {
|
|
177
|
+
if (!Array.isArray(files) || files.length === 0) {
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
let sdist = files.find(f => f.file.endsWith('.tar.gz'));
|
|
181
|
+
let entry = sdist || files[0];
|
|
182
|
+
let hash = entry.hash;
|
|
183
|
+
if (hash && hash.startsWith('sha256:')) {
|
|
184
|
+
return hash.slice(7);
|
|
185
|
+
}
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
72
188
|
/**
|
|
73
189
|
* Parse poetry show --tree output into a dependency graph structure.
|
|
74
|
-
* Top-level lines (no indentation/tree chars) are direct deps: "name version description"
|
|
75
|
-
* Indented lines are transitive deps with tree chars: "├── name >=constraint"
|
|
76
190
|
*
|
|
77
191
|
* @param {string} treeOutput
|
|
78
192
|
* @param {Map<string, string>} versionMap - canonical name -> resolved version
|
|
79
|
-
* @
|
|
193
|
+
* @param {{directMarkers: Map<string, string>, transitiveMarkers: Map<string, Map<string, string>>, hashMap: Map<string, Array<{alg: string, content: string}>>}} markerData
|
|
194
|
+
* @returns {{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[], hashes?: Array<{alg: string, content: string}>}>}}
|
|
80
195
|
*/
|
|
81
|
-
_parsePoetryTree(treeOutput, versionMap) {
|
|
196
|
+
_parsePoetryTree(treeOutput, versionMap, markerData) {
|
|
82
197
|
let lines = treeOutput.split(/\r?\n/);
|
|
83
198
|
let graph = new Map();
|
|
84
199
|
let directDeps = [];
|
|
@@ -89,14 +204,25 @@ export default class Python_poetry extends Base_pyproject {
|
|
|
89
204
|
continue;
|
|
90
205
|
}
|
|
91
206
|
// top-level line: "name version description..."
|
|
92
|
-
let topMatch = line.match(/^([A-Za-z0-9][A-Za-z0-9._-]*)\s+(\S+)
|
|
207
|
+
let topMatch = line.match(/^([A-Za-z0-9][A-Za-z0-9._-]*)\s+(\S+)(?:\s|$)/);
|
|
93
208
|
if (topMatch) {
|
|
94
209
|
let name = topMatch[1];
|
|
95
210
|
let version = topMatch[2];
|
|
96
211
|
let key = this._canonicalize(name);
|
|
212
|
+
let marker = markerData.directMarkers.get(key);
|
|
213
|
+
if (marker && !evaluateMarker(marker)) {
|
|
214
|
+
currentDirectDep = null;
|
|
215
|
+
stack = [];
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
97
218
|
directDeps.push(key);
|
|
98
219
|
if (!graph.has(key)) {
|
|
99
|
-
|
|
220
|
+
let entry = { name, version, children: [] };
|
|
221
|
+
let hashes = markerData.hashMap.get(key);
|
|
222
|
+
if (hashes) {
|
|
223
|
+
entry.hashes = hashes;
|
|
224
|
+
}
|
|
225
|
+
graph.set(key, entry);
|
|
100
226
|
}
|
|
101
227
|
currentDirectDep = key;
|
|
102
228
|
stack = [{ key, depth: -1 }];
|
|
@@ -120,20 +246,34 @@ export default class Python_poetry extends Base_pyproject {
|
|
|
120
246
|
// determine depth by counting tree-drawing groups in the prefix
|
|
121
247
|
let prefix = line.substring(0, nameStart);
|
|
122
248
|
let depth = (prefix.match(/(?:[├└│ ][\s─]{2} ?)/g) || []).length;
|
|
249
|
+
// pop stack back to find the parent at depth-1
|
|
250
|
+
while (stack.length > 0 && stack[stack.length - 1].depth >= depth) {
|
|
251
|
+
stack.pop();
|
|
252
|
+
}
|
|
253
|
+
let parentKey = stack.length > 0 ? stack[stack.length - 1].key : null;
|
|
254
|
+
if (parentKey) {
|
|
255
|
+
let parentMarkers = markerData.transitiveMarkers.get(parentKey);
|
|
256
|
+
if (parentMarkers) {
|
|
257
|
+
let marker = parentMarkers.get(depKey);
|
|
258
|
+
if (marker && !evaluateMarker(marker)) {
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
123
263
|
// resolve version from the version map
|
|
124
264
|
let version = versionMap.get(depKey) || null;
|
|
125
265
|
if (!version) {
|
|
126
266
|
throw new Error(`poetry: package '${depName}' has no resolved version`);
|
|
127
267
|
}
|
|
128
268
|
if (!graph.has(depKey)) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
269
|
+
let entry = { name: depName, version, children: [] };
|
|
270
|
+
let hashes = markerData.hashMap.get(depKey);
|
|
271
|
+
if (hashes) {
|
|
272
|
+
entry.hashes = hashes;
|
|
273
|
+
}
|
|
274
|
+
graph.set(depKey, entry);
|
|
134
275
|
}
|
|
135
|
-
if (
|
|
136
|
-
let parentKey = stack[stack.length - 1].key;
|
|
276
|
+
if (parentKey) {
|
|
137
277
|
let parentEntry = graph.get(parentKey);
|
|
138
278
|
if (parentEntry && !parentEntry.children.includes(depKey)) {
|
|
139
279
|
parentEntry.children.push(depKey);
|
|
@@ -1,4 +1,23 @@
|
|
|
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
|
+
* Parse uv.lock and attach SHA-256 hashes to graph entries.
|
|
17
|
+
* @param {string} lockFilePath - path to uv.lock
|
|
18
|
+
* @param {Map<string, import('./base_pyproject.js').GraphEntry>} graph
|
|
19
|
+
*/
|
|
20
|
+
_attachHashesFromLockFile(lockFilePath: string, graph: Map<string, import("./base_pyproject.js").GraphEntry>): Promise<void>;
|
|
2
21
|
/**
|
|
3
22
|
* Get the uv export output, either from env var or by running the command.
|
|
4
23
|
* @param {string} manifestDir
|
|
@@ -12,9 +31,10 @@ export default class Python_uv extends Base_pyproject {
|
|
|
12
31
|
*
|
|
13
32
|
* @param {string} output
|
|
14
33
|
* @param {string} projectName - canonical project name to identify direct deps
|
|
34
|
+
* @param {string} workspaceDir - workspace root (for resolving editable install paths)
|
|
15
35
|
* @returns {Promise<{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}>}
|
|
16
36
|
*/
|
|
17
|
-
_parseUvExport(output: string, projectName: string): Promise<{
|
|
37
|
+
_parseUvExport(output: string, projectName: string, workspaceDir: string): Promise<{
|
|
18
38
|
directDeps: string[];
|
|
19
39
|
graph: Map<string, {
|
|
20
40
|
name: string;
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import fg from 'fast-glob';
|
|
4
|
+
import { parse as parseToml } from 'smol-toml';
|
|
1
5
|
import { environmentVariableIsPopulated, getCustomPath, invokeCommand } from '../tools.js';
|
|
6
|
+
import { filterManifestPathsByDiscoveryIgnore, resolveWorkspaceDiscoveryIgnore, toManifestGlobPatterns } from '../workspace.js';
|
|
2
7
|
import Base_pyproject from './base_pyproject.js';
|
|
8
|
+
import { evaluateMarker } from './marker_evaluator.js';
|
|
3
9
|
import { getParser, getPinnedVersionQuery } from './requirements_parser.js';
|
|
4
10
|
export default class Python_uv extends Base_pyproject {
|
|
5
11
|
/** @returns {string} */
|
|
@@ -11,15 +17,58 @@ export default class Python_uv extends Base_pyproject {
|
|
|
11
17
|
return 'uv';
|
|
12
18
|
}
|
|
13
19
|
/**
|
|
14
|
-
* @param {string} manifestDir
|
|
20
|
+
* @param {string} manifestDir - directory containing the target pyproject.toml
|
|
21
|
+
* @param {string} workspaceDir - workspace root (for resolving editable install paths)
|
|
15
22
|
* @param {object} parsed - parsed pyproject.toml
|
|
16
23
|
* @param {Object} opts
|
|
17
|
-
* @returns {Promise<{directDeps: string[], graph: Map<string,
|
|
24
|
+
* @returns {Promise<{directDeps: string[], graph: Map<string, import('./base_pyproject.js').GraphEntry>}>}
|
|
18
25
|
*/
|
|
19
|
-
async _getDependencyData(manifestDir, parsed, opts) {
|
|
26
|
+
async _getDependencyData(manifestDir, workspaceDir, parsed, opts) {
|
|
20
27
|
let projectName = this._getProjectName(parsed);
|
|
21
28
|
let uvOutput = this._getUvExportOutput(manifestDir, opts);
|
|
22
|
-
|
|
29
|
+
let { directDeps, graph } = await this._parseUvExport(uvOutput, projectName, workspaceDir);
|
|
30
|
+
await this._attachHashesFromLockFile(path.join(workspaceDir, 'uv.lock'), graph);
|
|
31
|
+
return { directDeps, graph };
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Parse uv.lock and attach SHA-256 hashes to graph entries.
|
|
35
|
+
* @param {string} lockFilePath - path to uv.lock
|
|
36
|
+
* @param {Map<string, import('./base_pyproject.js').GraphEntry>} graph
|
|
37
|
+
*/
|
|
38
|
+
async _attachHashesFromLockFile(lockFilePath, graph) {
|
|
39
|
+
let lockContent;
|
|
40
|
+
try {
|
|
41
|
+
lockContent = await fs.promises.readFile(lockFilePath, 'utf-8');
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
let parsed;
|
|
47
|
+
try {
|
|
48
|
+
parsed = parseToml(lockContent);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
let packages = parsed.package;
|
|
54
|
+
if (!Array.isArray(packages)) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
for (let pkg of packages) {
|
|
58
|
+
if (!pkg.name) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
let hashStr = pkg.sdist?.hash || pkg.wheels?.[0]?.hash;
|
|
62
|
+
if (!hashStr || !hashStr.startsWith('sha256:')) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
let key = this._canonicalize(pkg.name);
|
|
66
|
+
let entry = graph.get(key);
|
|
67
|
+
if (!entry || entry.hashes) {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
entry.hashes = [{ alg: "SHA-256", content: hashStr.slice(7) }];
|
|
71
|
+
}
|
|
23
72
|
}
|
|
24
73
|
/**
|
|
25
74
|
* Get the uv export output, either from env var or by running the command.
|
|
@@ -32,7 +81,7 @@ export default class Python_uv extends Base_pyproject {
|
|
|
32
81
|
return Buffer.from(process.env['TRUSTIFY_DA_UV_EXPORT'], 'base64').toString('ascii');
|
|
33
82
|
}
|
|
34
83
|
let uvBin = getCustomPath('uv', opts);
|
|
35
|
-
return invokeCommand(uvBin, ['export', '--format', 'requirements.txt', '--frozen', '--no-hashes'], { cwd: manifestDir }).toString();
|
|
84
|
+
return invokeCommand(uvBin, ['export', '--format', 'requirements.txt', '--frozen', '--no-hashes', '--no-dev', '--no-emit-project'], { cwd: manifestDir }).toString();
|
|
36
85
|
}
|
|
37
86
|
/**
|
|
38
87
|
* Parse uv export output into a dependency graph using tree-sitter-requirements
|
|
@@ -40,9 +89,10 @@ export default class Python_uv extends Base_pyproject {
|
|
|
40
89
|
*
|
|
41
90
|
* @param {string} output
|
|
42
91
|
* @param {string} projectName - canonical project name to identify direct deps
|
|
92
|
+
* @param {string} workspaceDir - workspace root (for resolving editable install paths)
|
|
43
93
|
* @returns {Promise<{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}>}
|
|
44
94
|
*/
|
|
45
|
-
async _parseUvExport(output, projectName) {
|
|
95
|
+
async _parseUvExport(output, projectName, workspaceDir) {
|
|
46
96
|
let [parser, pinnedVersionQuery] = await Promise.all([
|
|
47
97
|
getParser(), getPinnedVersionQuery()
|
|
48
98
|
]);
|
|
@@ -53,11 +103,47 @@ export default class Python_uv extends Base_pyproject {
|
|
|
53
103
|
let currentPkg = null;
|
|
54
104
|
let collectingVia = false;
|
|
55
105
|
for (let child of root.children) {
|
|
106
|
+
if (child.type === 'global_opt') {
|
|
107
|
+
let optNode = child.children.find(c => c.type === 'option');
|
|
108
|
+
let pathNode = child.children.find(c => c.type === 'path');
|
|
109
|
+
if (optNode?.text === '-e' && pathNode && workspaceDir) {
|
|
110
|
+
let memberDir = path.resolve(workspaceDir, pathNode.text);
|
|
111
|
+
let memberManifest = path.join(memberDir, 'pyproject.toml');
|
|
112
|
+
if (fs.existsSync(memberManifest)) {
|
|
113
|
+
let memberParsed = parseToml(fs.readFileSync(memberManifest, 'utf-8'));
|
|
114
|
+
let name = memberParsed.project?.name || memberParsed.tool?.poetry?.name;
|
|
115
|
+
let version = memberParsed.project?.version || memberParsed.tool?.poetry?.version;
|
|
116
|
+
if (name && version) {
|
|
117
|
+
let key = this._canonicalize(name);
|
|
118
|
+
if (key === canonProjectName) {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
currentPkg = { name, version, parents: new Set() };
|
|
122
|
+
packages.set(key, currentPkg);
|
|
123
|
+
collectingVia = false;
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
currentPkg = null;
|
|
129
|
+
collectingVia = false;
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
56
132
|
if (child.type === 'requirement') {
|
|
57
133
|
let nameNode = child.children.find(c => c.type === 'package');
|
|
58
134
|
if (!nameNode) {
|
|
59
135
|
continue;
|
|
60
136
|
}
|
|
137
|
+
// Skip packages with non-matching PEP 508 markers, e.g. "pywin32==311 ; sys_platform == 'win32'"
|
|
138
|
+
let markerNode = child.children.find(c => c.type === 'marker_spec');
|
|
139
|
+
if (markerNode) {
|
|
140
|
+
let markerText = markerNode.text.replace(/^\s*;\s*/, '');
|
|
141
|
+
if (!evaluateMarker(markerText)) {
|
|
142
|
+
currentPkg = null;
|
|
143
|
+
collectingVia = false;
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
61
147
|
let name = nameNode.text;
|
|
62
148
|
let version = null;
|
|
63
149
|
let versionMatches = pinnedVersionQuery.matches(child);
|
|
@@ -116,3 +202,68 @@ export default class Python_uv extends Base_pyproject {
|
|
|
116
202
|
return { directDeps, graph };
|
|
117
203
|
}
|
|
118
204
|
}
|
|
205
|
+
const DEFAULT_UV_DISCOVERY_IGNORE = [
|
|
206
|
+
'**/__pycache__/**',
|
|
207
|
+
'**/.venv/**',
|
|
208
|
+
];
|
|
209
|
+
/**
|
|
210
|
+
* Discover all pyproject.toml manifest paths in a uv workspace.
|
|
211
|
+
* Parses `[tool.uv.workspace]` from root pyproject.toml and glob-expands member patterns.
|
|
212
|
+
*
|
|
213
|
+
* @param {string} workspaceRoot - Absolute or relative path to workspace root (must contain pyproject.toml and uv.lock)
|
|
214
|
+
* @param {{ workspaceDiscoveryIgnore?: string[], TRUSTIFY_DA_WORKSPACE_DISCOVERY_IGNORE?: string, [key: string]: unknown }} [opts={}]
|
|
215
|
+
* @returns {Promise<string[]>} Paths to pyproject.toml files (absolute)
|
|
216
|
+
*/
|
|
217
|
+
export async function discoverUvWorkspaceMembers(workspaceRoot, opts = {}) {
|
|
218
|
+
const root = path.resolve(workspaceRoot);
|
|
219
|
+
const rootPyproject = path.join(root, 'pyproject.toml');
|
|
220
|
+
const uvLock = path.join(root, 'uv.lock');
|
|
221
|
+
if (!fs.existsSync(rootPyproject) || !fs.existsSync(uvLock)) {
|
|
222
|
+
return [];
|
|
223
|
+
}
|
|
224
|
+
let parsed;
|
|
225
|
+
try {
|
|
226
|
+
parsed = parseToml(fs.readFileSync(rootPyproject, 'utf-8'));
|
|
227
|
+
}
|
|
228
|
+
catch {
|
|
229
|
+
return [];
|
|
230
|
+
}
|
|
231
|
+
const workspaceConfig = parsed?.tool?.uv?.workspace;
|
|
232
|
+
if (!workspaceConfig) {
|
|
233
|
+
return [];
|
|
234
|
+
}
|
|
235
|
+
const memberPatterns = workspaceConfig.members;
|
|
236
|
+
if (!Array.isArray(memberPatterns) || memberPatterns.length === 0) {
|
|
237
|
+
return [];
|
|
238
|
+
}
|
|
239
|
+
const excludePatterns = Array.isArray(workspaceConfig.exclude) ? workspaceConfig.exclude : [];
|
|
240
|
+
const excludeGlobs = excludePatterns
|
|
241
|
+
.filter(p => typeof p === 'string' && p.trim())
|
|
242
|
+
.map(p => `${p.trim()}/pyproject.toml`);
|
|
243
|
+
const ignorePatterns = [...resolveWorkspaceDiscoveryIgnore(opts), ...DEFAULT_UV_DISCOVERY_IGNORE];
|
|
244
|
+
const globOpts = {
|
|
245
|
+
cwd: root,
|
|
246
|
+
absolute: true,
|
|
247
|
+
onlyFiles: true,
|
|
248
|
+
ignore: [...ignorePatterns, ...excludeGlobs],
|
|
249
|
+
followSymbolicLinks: false,
|
|
250
|
+
};
|
|
251
|
+
const patterns = toManifestGlobPatterns(memberPatterns.filter(p => typeof p === 'string'), 'pyproject.toml');
|
|
252
|
+
const manifestPaths = await fg(patterns, globOpts);
|
|
253
|
+
if (!manifestPaths.includes(rootPyproject) && hasProjectMetadata(parsed)) {
|
|
254
|
+
manifestPaths.unshift(rootPyproject);
|
|
255
|
+
}
|
|
256
|
+
return filterManifestPathsByDiscoveryIgnore(manifestPaths, root, ignorePatterns);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* @param {import('smol-toml').TomlTable} parsedPyProject
|
|
260
|
+
* @returns {boolean}
|
|
261
|
+
*/
|
|
262
|
+
function hasProjectMetadata(parsedPyProject) {
|
|
263
|
+
try {
|
|
264
|
+
return typeof parsedPyProject?.project?.name === 'string' && parsedPyProject.project.name.trim() !== '';
|
|
265
|
+
}
|
|
266
|
+
catch {
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
@@ -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;
|