@trustify-da/trustify-da-javascript-client 0.3.0-ea.de12f6a → 0.3.0-ea.de62188
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -3
- package/dist/package.json +26 -23
- package/dist/src/analysis.d.ts +14 -7
- package/dist/src/analysis.js +32 -15
- package/dist/src/cli.js +109 -3
- package/dist/src/cyclone_dx_sbom.d.ts +14 -1
- package/dist/src/cyclone_dx_sbom.js +43 -8
- package/dist/src/index.d.ts +84 -11
- package/dist/src/index.js +95 -8
- package/dist/src/license/index.d.ts +3 -3
- package/dist/src/license/index.js +4 -1
- package/dist/src/license/license_utils.js +4 -1
- package/dist/src/license/licenses_api.d.ts +2 -2
- package/dist/src/oci_image/images.d.ts +1 -1
- package/dist/src/oci_image/images.js +15 -1
- package/dist/src/oci_image/utils.d.ts +5 -5
- package/dist/src/oci_image/utils.js +11 -2
- package/dist/src/provider.d.ts +4 -3
- package/dist/src/provider.js +12 -2
- package/dist/src/providers/base_java.d.ts +14 -12
- package/dist/src/providers/base_java.js +18 -44
- package/dist/src/providers/base_javascript.d.ts +20 -9
- package/dist/src/providers/base_javascript.js +44 -6
- package/dist/src/providers/base_pyproject.d.ts +158 -0
- package/dist/src/providers/base_pyproject.js +322 -0
- package/dist/src/providers/containerfile_parser.d.ts +5 -0
- package/dist/src/providers/containerfile_parser.js +20 -0
- package/dist/src/providers/golang_gomodules.d.ts +11 -1
- 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_gradle_groovy.d.ts +1 -1
- package/dist/src/providers/java_gradle_kotlin.d.ts +1 -1
- package/dist/src/providers/java_maven.d.ts +10 -2
- 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 +6 -0
- package/dist/src/providers/javascript_npm.js +21 -0
- package/dist/src/providers/javascript_pnpm.js +6 -2
- package/dist/src/providers/manifest.d.ts +2 -0
- package/dist/src/providers/manifest.js +22 -4
- package/dist/src/providers/marker_evaluator.d.ts +14 -0
- package/dist/src/providers/marker_evaluator.js +191 -0
- package/dist/src/providers/oci_dockerfile.d.ts +51 -0
- package/dist/src/providers/oci_dockerfile.js +177 -0
- package/dist/src/providers/processors/yarn_berry_processor.d.ts +2 -2
- package/dist/src/providers/processors/yarn_berry_processor.js +88 -5
- package/dist/src/providers/processors/yarn_classic_processor.d.ts +2 -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 +98 -0
- package/dist/src/providers/python_poetry.js +286 -0
- package/dist/src/providers/python_uv.d.ts +46 -0
- package/dist/src/providers/python_uv.js +269 -0
- package/dist/src/providers/rust_cargo.d.ts +6 -2
- package/dist/src/providers/rust_cargo.js +31 -4
- package/dist/src/providers/tree-sitter-containerfile.wasm +0 -0
- package/dist/src/sbom.d.ts +14 -1
- package/dist/src/sbom.js +13 -2
- package/dist/src/tools.d.ts +28 -2
- package/dist/src/tools.js +58 -0
- package/dist/src/updaters/maven_updater.d.ts +26 -0
- package/dist/src/updaters/maven_updater.js +322 -0
- package/dist/src/updaters/toml_updater.d.ts +33 -0
- package/dist/src/updaters/toml_updater.js +244 -0
- package/dist/src/workspace.d.ts +9 -0
- package/dist/src/workspace.js +1 -1
- package/package.json +27 -24
|
@@ -0,0 +1,269 @@
|
|
|
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';
|
|
5
|
+
import { environmentVariableIsPopulated, getCustomPath, invokeCommand } from '../tools.js';
|
|
6
|
+
import { filterManifestPathsByDiscoveryIgnore, resolveWorkspaceDiscoveryIgnore, toManifestGlobPatterns } from '../workspace.js';
|
|
7
|
+
import Base_pyproject from './base_pyproject.js';
|
|
8
|
+
import { evaluateMarker } from './marker_evaluator.js';
|
|
9
|
+
import { getParser, getPinnedVersionQuery } from './requirements_parser.js';
|
|
10
|
+
export default class Python_uv extends Base_pyproject {
|
|
11
|
+
/** @returns {string} */
|
|
12
|
+
_lockFileName() {
|
|
13
|
+
return 'uv.lock';
|
|
14
|
+
}
|
|
15
|
+
/** @returns {string} */
|
|
16
|
+
_cmdName() {
|
|
17
|
+
return 'uv';
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* @param {string} manifestDir - directory containing the target pyproject.toml
|
|
21
|
+
* @param {string} workspaceDir - workspace root (for resolving editable install paths)
|
|
22
|
+
* @param {object} parsed - parsed pyproject.toml
|
|
23
|
+
* @param {Object} opts
|
|
24
|
+
* @returns {Promise<{directDeps: string[], graph: Map<string, import('./base_pyproject.js').GraphEntry>}>}
|
|
25
|
+
*/
|
|
26
|
+
async _getDependencyData(manifestDir, workspaceDir, parsed, opts) {
|
|
27
|
+
let projectName = this._getProjectName(parsed);
|
|
28
|
+
let uvOutput = this._getUvExportOutput(manifestDir, opts);
|
|
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
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Get the uv export output, either from env var or by running the command.
|
|
75
|
+
* @param {string} manifestDir
|
|
76
|
+
* @param {Object} opts
|
|
77
|
+
* @returns {string}
|
|
78
|
+
*/
|
|
79
|
+
_getUvExportOutput(manifestDir, opts) {
|
|
80
|
+
if (environmentVariableIsPopulated('TRUSTIFY_DA_UV_EXPORT')) {
|
|
81
|
+
return Buffer.from(process.env['TRUSTIFY_DA_UV_EXPORT'], 'base64').toString('ascii');
|
|
82
|
+
}
|
|
83
|
+
let uvBin = getCustomPath('uv', opts);
|
|
84
|
+
return invokeCommand(uvBin, ['export', '--format', 'requirements.txt', '--frozen', '--no-hashes', '--no-dev', '--no-emit-project'], { cwd: manifestDir }).toString();
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Parse uv export output into a dependency graph using tree-sitter-requirements
|
|
88
|
+
* for package/version extraction and string parsing for "# via" comments.
|
|
89
|
+
*
|
|
90
|
+
* @param {string} output
|
|
91
|
+
* @param {string} projectName - canonical project name to identify direct deps
|
|
92
|
+
* @param {string} workspaceDir - workspace root (for resolving editable install paths)
|
|
93
|
+
* @returns {Promise<{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}>}
|
|
94
|
+
*/
|
|
95
|
+
async _parseUvExport(output, projectName, workspaceDir) {
|
|
96
|
+
let [parser, pinnedVersionQuery] = await Promise.all([
|
|
97
|
+
getParser(), getPinnedVersionQuery()
|
|
98
|
+
]);
|
|
99
|
+
let tree = parser.parse(output);
|
|
100
|
+
let root = tree.rootNode;
|
|
101
|
+
let canonProjectName = this._canonicalize(projectName);
|
|
102
|
+
let packages = new Map(); // canonical name -> {name, version, parents: Set}
|
|
103
|
+
let currentPkg = null;
|
|
104
|
+
let collectingVia = false;
|
|
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
|
+
}
|
|
132
|
+
if (child.type === 'requirement') {
|
|
133
|
+
let nameNode = child.children.find(c => c.type === 'package');
|
|
134
|
+
if (!nameNode) {
|
|
135
|
+
continue;
|
|
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
|
+
}
|
|
147
|
+
let name = nameNode.text;
|
|
148
|
+
let version = null;
|
|
149
|
+
let versionMatches = pinnedVersionQuery.matches(child);
|
|
150
|
+
if (versionMatches.length > 0) {
|
|
151
|
+
version = versionMatches[0].captures.find(c => c.name === 'version').node.text;
|
|
152
|
+
}
|
|
153
|
+
if (!version) {
|
|
154
|
+
throw new Error(`uv export: package '${name}' has no pinned version`);
|
|
155
|
+
}
|
|
156
|
+
let key = this._canonicalize(name);
|
|
157
|
+
currentPkg = { name, version, parents: new Set() };
|
|
158
|
+
packages.set(key, currentPkg);
|
|
159
|
+
collectingVia = false;
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (child.type === 'comment' && currentPkg) {
|
|
163
|
+
let text = child.text.trim();
|
|
164
|
+
let viaSingle = text.match(/^# via ([A-Za-z0-9][A-Za-z0-9._-]*)$/);
|
|
165
|
+
if (viaSingle) {
|
|
166
|
+
currentPkg.parents.add(this._canonicalize(viaSingle[1]));
|
|
167
|
+
collectingVia = false;
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
if (text === '# via') {
|
|
171
|
+
collectingVia = true;
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
if (collectingVia) {
|
|
175
|
+
let parentMatch = text.match(/^#\s+([A-Za-z0-9][A-Za-z0-9._-]*)$/);
|
|
176
|
+
if (parentMatch) {
|
|
177
|
+
currentPkg.parents.add(this._canonicalize(parentMatch[1]));
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
collectingVia = false;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
// Build forward dependency map and extract direct deps in one pass
|
|
185
|
+
let graph = new Map();
|
|
186
|
+
let directDeps = [];
|
|
187
|
+
for (let [key, pkg] of packages) {
|
|
188
|
+
graph.set(key, { name: pkg.name, version: pkg.version, children: [] });
|
|
189
|
+
}
|
|
190
|
+
for (let [childKey, pkg] of packages) {
|
|
191
|
+
for (let parentKey of pkg.parents) {
|
|
192
|
+
if (parentKey === canonProjectName) {
|
|
193
|
+
directDeps.push(childKey);
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
let parentEntry = graph.get(parentKey);
|
|
197
|
+
if (parentEntry) {
|
|
198
|
+
parentEntry.children.push(childKey);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return { directDeps, graph };
|
|
203
|
+
}
|
|
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,9 +4,10 @@ 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
|
-
export type Provided =
|
|
10
|
+
export type Provided = any;
|
|
10
11
|
/**
|
|
11
12
|
* @param {string} manifestName - the subject manifest name-type
|
|
12
13
|
* @returns {boolean} - return true if `Cargo.toml` is the manifest name-type
|
|
@@ -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);
|
|
Binary file
|
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
|
|
@@ -53,6 +59,13 @@ export default class Sbom {
|
|
|
53
59
|
* @return {boolean}
|
|
54
60
|
*/
|
|
55
61
|
checkIfPackageInsideDependsOnList(component: any, name: string): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Checks if any entry in the dependsOn list of sourceRef starts with the given purl prefix.
|
|
64
|
+
* @param {PackageURL} sourceRef - The source component to check
|
|
65
|
+
* @param {string} purlPrefix - The purl prefix to match (e.g. "pkg:npm/minimist@")
|
|
66
|
+
* @return {boolean}
|
|
67
|
+
*/
|
|
68
|
+
checkDependsOnByPurlPrefix(sourceRef: PackageURL, purlPrefix: string): boolean;
|
|
56
69
|
/** Removes the root component from the sbom
|
|
57
70
|
*/
|
|
58
71
|
removeRootComponent(): void;
|
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
|
|
@@ -77,6 +79,15 @@ export default class Sbom {
|
|
|
77
79
|
checkIfPackageInsideDependsOnList(component, name) {
|
|
78
80
|
return this.sbomModel.checkIfPackageInsideDependsOnList(component, name);
|
|
79
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Checks if any entry in the dependsOn list of sourceRef starts with the given purl prefix.
|
|
84
|
+
* @param {PackageURL} sourceRef - The source component to check
|
|
85
|
+
* @param {string} purlPrefix - The purl prefix to match (e.g. "pkg:npm/minimist@")
|
|
86
|
+
* @return {boolean}
|
|
87
|
+
*/
|
|
88
|
+
checkDependsOnByPurlPrefix(sourceRef, purlPrefix) {
|
|
89
|
+
return this.sbomModel.checkDependsOnByPurlPrefix(sourceRef, purlPrefix);
|
|
90
|
+
}
|
|
80
91
|
/** Removes the root component from the sbom
|
|
81
92
|
*/
|
|
82
93
|
removeRootComponent() {
|
package/dist/src/tools.d.ts
CHANGED
|
@@ -61,6 +61,32 @@ 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;
|
|
80
|
+
/**
|
|
81
|
+
* Resolve a build-tool binary, preferring a wrapper when configured.
|
|
82
|
+
*
|
|
83
|
+
* @param {string} globalBinary - Global binary name (e.g. `mvn`, `gradle`)
|
|
84
|
+
* @param {string} localWrapper - Wrapper filename (e.g. `mvnw`, `gradlew.bat`)
|
|
85
|
+
* @param {string} startDir - Directory from which to start the wrapper search
|
|
86
|
+
* @param {import('./index.js').Options} [opts={}]
|
|
87
|
+
* @returns {string} Path to the resolved binary
|
|
88
|
+
*/
|
|
89
|
+
export function resolveBinary(globalBinary: string, localWrapper: string, startDir: string, opts?: import("./index.js").Options): string;
|
|
64
90
|
/** this method invokes command string in a process in a synchronous way.
|
|
65
91
|
* @param {string} bin - the command to be invoked
|
|
66
92
|
* @param {Array<string>} args - the args to pass to the binary
|
|
@@ -74,13 +100,13 @@ export function invokeCommand(bin: string, args: Array<string>, opts?: import("c
|
|
|
74
100
|
* @param {import("index.js").Options} opts - The trustify DA options that may contain proxy configuration
|
|
75
101
|
* @returns {RequestInit} The fetch options with proxy agent if applicable
|
|
76
102
|
*/
|
|
77
|
-
export function addProxyAgent(options: RequestInit, opts:
|
|
103
|
+
export function addProxyAgent(options: RequestInit, opts: any): RequestInit;
|
|
78
104
|
/**
|
|
79
105
|
* Utility function for fetching vendor tokens
|
|
80
106
|
* @param {import("index.js").Options} [opts={}] - optional various options to pass along the application
|
|
81
107
|
* @returns {{}}
|
|
82
108
|
*/
|
|
83
|
-
export function getTokenHeaders(opts?:
|
|
109
|
+
export function getTokenHeaders(opts?: any): {};
|
|
84
110
|
export const RegexNotToBeLogged: RegExp;
|
|
85
111
|
export const TRUSTIFY_DA_TOKEN_HEADER: "trust-da-token";
|
|
86
112
|
export const TRUSTIFY_DA_TELEMETRY_ID_HEADER: "telemetry-anonymous-id";
|
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,62 @@ 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
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Resolve a build-tool binary, preferring a wrapper when configured.
|
|
173
|
+
*
|
|
174
|
+
* @param {string} globalBinary - Global binary name (e.g. `mvn`, `gradle`)
|
|
175
|
+
* @param {string} localWrapper - Wrapper filename (e.g. `mvnw`, `gradlew.bat`)
|
|
176
|
+
* @param {string} startDir - Directory from which to start the wrapper search
|
|
177
|
+
* @param {import('./index.js').Options} [opts={}]
|
|
178
|
+
* @returns {string} Path to the resolved binary
|
|
179
|
+
*/
|
|
180
|
+
export function resolveBinary(globalBinary, localWrapper, startDir, opts = {}) {
|
|
181
|
+
if (getWrapperPreference(globalBinary, opts)) {
|
|
182
|
+
const wrapper = traverseForWrapper(startDir, localWrapper);
|
|
183
|
+
if (wrapper !== undefined) {
|
|
184
|
+
return wrapper;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return getCustomPath(globalBinary, opts);
|
|
188
|
+
}
|
|
131
189
|
/** this method invokes command string in a process in a synchronous way.
|
|
132
190
|
* @param {string} bin - the command to be invoked
|
|
133
191
|
* @param {Array<string>} args - the args to pass to the binary
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Updates dependency versions in a Maven pom.xml while preserving file formatting.
|
|
3
|
+
*
|
|
4
|
+
* Uses `fast-xml-parser` to understand the XML structure (dependencies and properties),
|
|
5
|
+
* then performs position-based string splice to replace version strings without altering
|
|
6
|
+
* any other formatting, comments, whitespace, or indentation.
|
|
7
|
+
*
|
|
8
|
+
* Supports `${property}` indirection: when a dependency's `<version>` is a property
|
|
9
|
+
* reference, the updater resolves the property chain (including recursive references)
|
|
10
|
+
* and updates the terminal property value in `<properties>` instead.
|
|
11
|
+
*
|
|
12
|
+
* @param {string} pomContent - the raw pom.xml file content
|
|
13
|
+
* @param {Array<{groupId: string, artifactId: string, newVersion: string}>} versionChanges -
|
|
14
|
+
* list of version changes to apply
|
|
15
|
+
* @returns {{content: string, applied: Array, skipped: Array}} the updated content and
|
|
16
|
+
* lists of applied and skipped changes
|
|
17
|
+
*/
|
|
18
|
+
export function updateMavenVersions(pomContent: string, versionChanges: Array<{
|
|
19
|
+
groupId: string;
|
|
20
|
+
artifactId: string;
|
|
21
|
+
newVersion: string;
|
|
22
|
+
}>): {
|
|
23
|
+
content: string;
|
|
24
|
+
applied: any[];
|
|
25
|
+
skipped: any[];
|
|
26
|
+
};
|