@trustify-da/trustify-da-javascript-client 0.3.0-ea.f2c4df7 → 0.3.0-ea.f501753
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 +151 -13
- package/dist/package.json +11 -3
- package/dist/src/analysis.d.ts +16 -0
- package/dist/src/analysis.js +53 -4
- package/dist/src/batch_opts.d.ts +24 -0
- package/dist/src/batch_opts.js +35 -0
- package/dist/src/cli.js +171 -4
- package/dist/src/cyclone_dx_sbom.d.ts +14 -1
- package/dist/src/cyclone_dx_sbom.js +34 -6
- package/dist/src/index.d.ts +132 -1
- package/dist/src/index.js +340 -4
- package/dist/src/license/licenses_api.js +9 -2
- package/dist/src/license/project_license.d.ts +0 -8
- package/dist/src/license/project_license.js +0 -11
- package/dist/src/oci_image/utils.js +11 -2
- package/dist/src/provider.d.ts +6 -3
- package/dist/src/provider.js +14 -5
- package/dist/src/providers/base_java.d.ts +0 -9
- package/dist/src/providers/base_java.js +2 -38
- package/dist/src/providers/base_javascript.d.ts +19 -3
- package/dist/src/providers/base_javascript.js +99 -18
- package/dist/src/providers/base_pyproject.d.ts +153 -0
- package/dist/src/providers/base_pyproject.js +315 -0
- package/dist/src/providers/golang_gomodules.d.ts +21 -12
- package/dist/src/providers/golang_gomodules.js +164 -118
- package/dist/src/providers/gomod_parser.d.ts +4 -0
- package/dist/src/providers/gomod_parser.js +16 -0
- package/dist/src/providers/java_gradle.d.ts +19 -0
- package/dist/src/providers/java_gradle.js +114 -0
- package/dist/src/providers/java_maven.d.ts +8 -0
- package/dist/src/providers/java_maven.js +93 -1
- package/dist/src/providers/javascript_npm.d.ts +1 -0
- package/dist/src/providers/javascript_npm.js +21 -0
- package/dist/src/providers/javascript_pnpm.d.ts +1 -1
- package/dist/src/providers/javascript_pnpm.js +8 -4
- 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/processors/yarn_berry_processor.js +88 -5
- package/dist/src/providers/python_controller.d.ts +5 -1
- package/dist/src/providers/python_controller.js +8 -4
- package/dist/src/providers/python_pip.d.ts +4 -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 +144 -0
- package/dist/src/providers/python_poetry.d.ts +75 -0
- package/dist/src/providers/python_poetry.js +238 -0
- package/dist/src/providers/python_uv.d.ts +42 -0
- package/dist/src/providers/python_uv.js +160 -0
- package/dist/src/providers/requirements_parser.js +4 -3
- package/dist/src/providers/rust_cargo.d.ts +52 -0
- package/dist/src/providers/rust_cargo.js +614 -0
- package/dist/src/providers/tree-sitter-gomod.wasm +0 -0
- package/dist/src/providers/tree-sitter-requirements.wasm +0 -0
- package/dist/src/sbom.d.ts +14 -1
- package/dist/src/sbom.js +13 -2
- package/dist/src/tools.d.ts +26 -0
- package/dist/src/tools.js +58 -0
- package/dist/src/workspace.d.ts +61 -0
- package/dist/src/workspace.js +256 -0
- package/package.json +12 -4
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { parse as parseToml } from 'smol-toml';
|
|
4
|
+
import { environmentVariableIsPopulated, getCustomPath, invokeCommand } from '../tools.js';
|
|
5
|
+
import Base_pyproject from './base_pyproject.js';
|
|
6
|
+
import { evaluateMarker } from './marker_evaluator.js';
|
|
7
|
+
import { getParser, getPinnedVersionQuery } from './requirements_parser.js';
|
|
8
|
+
export default class Python_uv extends Base_pyproject {
|
|
9
|
+
/** @returns {string} */
|
|
10
|
+
_lockFileName() {
|
|
11
|
+
return 'uv.lock';
|
|
12
|
+
}
|
|
13
|
+
/** @returns {string} */
|
|
14
|
+
_cmdName() {
|
|
15
|
+
return 'uv';
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* @param {string} manifestDir - directory containing the target pyproject.toml
|
|
19
|
+
* @param {string} workspaceDir - workspace root (for resolving editable install paths)
|
|
20
|
+
* @param {object} parsed - parsed pyproject.toml
|
|
21
|
+
* @param {Object} opts
|
|
22
|
+
* @returns {Promise<{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}>}
|
|
23
|
+
*/
|
|
24
|
+
async _getDependencyData(manifestDir, workspaceDir, parsed, opts) {
|
|
25
|
+
let projectName = this._getProjectName(parsed);
|
|
26
|
+
let uvOutput = this._getUvExportOutput(manifestDir, opts);
|
|
27
|
+
return this._parseUvExport(uvOutput, projectName, workspaceDir);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get the uv export output, either from env var or by running the command.
|
|
31
|
+
* @param {string} manifestDir
|
|
32
|
+
* @param {Object} opts
|
|
33
|
+
* @returns {string}
|
|
34
|
+
*/
|
|
35
|
+
_getUvExportOutput(manifestDir, opts) {
|
|
36
|
+
if (environmentVariableIsPopulated('TRUSTIFY_DA_UV_EXPORT')) {
|
|
37
|
+
return Buffer.from(process.env['TRUSTIFY_DA_UV_EXPORT'], 'base64').toString('ascii');
|
|
38
|
+
}
|
|
39
|
+
let uvBin = getCustomPath('uv', opts);
|
|
40
|
+
return invokeCommand(uvBin, ['export', '--format', 'requirements.txt', '--frozen', '--no-hashes', '--no-dev', '--no-emit-project'], { cwd: manifestDir }).toString();
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Parse uv export output into a dependency graph using tree-sitter-requirements
|
|
44
|
+
* for package/version extraction and string parsing for "# via" comments.
|
|
45
|
+
*
|
|
46
|
+
* @param {string} output
|
|
47
|
+
* @param {string} projectName - canonical project name to identify direct deps
|
|
48
|
+
* @param {string} workspaceDir - workspace root (for resolving editable install paths)
|
|
49
|
+
* @returns {Promise<{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}>}
|
|
50
|
+
*/
|
|
51
|
+
async _parseUvExport(output, projectName, workspaceDir) {
|
|
52
|
+
let [parser, pinnedVersionQuery] = await Promise.all([
|
|
53
|
+
getParser(), getPinnedVersionQuery()
|
|
54
|
+
]);
|
|
55
|
+
let tree = parser.parse(output);
|
|
56
|
+
let root = tree.rootNode;
|
|
57
|
+
let canonProjectName = this._canonicalize(projectName);
|
|
58
|
+
let packages = new Map(); // canonical name -> {name, version, parents: Set}
|
|
59
|
+
let currentPkg = null;
|
|
60
|
+
let collectingVia = false;
|
|
61
|
+
for (let child of root.children) {
|
|
62
|
+
if (child.type === 'global_opt') {
|
|
63
|
+
let optNode = child.children.find(c => c.type === 'option');
|
|
64
|
+
let pathNode = child.children.find(c => c.type === 'path');
|
|
65
|
+
if (optNode?.text === '-e' && pathNode && workspaceDir) {
|
|
66
|
+
let memberDir = path.resolve(workspaceDir, pathNode.text);
|
|
67
|
+
let memberManifest = path.join(memberDir, 'pyproject.toml');
|
|
68
|
+
if (fs.existsSync(memberManifest)) {
|
|
69
|
+
let memberParsed = parseToml(fs.readFileSync(memberManifest, 'utf-8'));
|
|
70
|
+
let name = memberParsed.project?.name || memberParsed.tool?.poetry?.name;
|
|
71
|
+
let version = memberParsed.project?.version || memberParsed.tool?.poetry?.version;
|
|
72
|
+
if (name && version) {
|
|
73
|
+
let key = this._canonicalize(name);
|
|
74
|
+
if (key === canonProjectName) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
currentPkg = { name, version, parents: new Set() };
|
|
78
|
+
packages.set(key, currentPkg);
|
|
79
|
+
collectingVia = false;
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
currentPkg = null;
|
|
85
|
+
collectingVia = false;
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (child.type === 'requirement') {
|
|
89
|
+
let nameNode = child.children.find(c => c.type === 'package');
|
|
90
|
+
if (!nameNode) {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
// Skip packages with non-matching PEP 508 markers, e.g. "pywin32==311 ; sys_platform == 'win32'"
|
|
94
|
+
let markerNode = child.children.find(c => c.type === 'marker_spec');
|
|
95
|
+
if (markerNode) {
|
|
96
|
+
let markerText = markerNode.text.replace(/^\s*;\s*/, '');
|
|
97
|
+
if (!evaluateMarker(markerText)) {
|
|
98
|
+
currentPkg = null;
|
|
99
|
+
collectingVia = false;
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
let name = nameNode.text;
|
|
104
|
+
let version = null;
|
|
105
|
+
let versionMatches = pinnedVersionQuery.matches(child);
|
|
106
|
+
if (versionMatches.length > 0) {
|
|
107
|
+
version = versionMatches[0].captures.find(c => c.name === 'version').node.text;
|
|
108
|
+
}
|
|
109
|
+
if (!version) {
|
|
110
|
+
throw new Error(`uv export: package '${name}' has no pinned version`);
|
|
111
|
+
}
|
|
112
|
+
let key = this._canonicalize(name);
|
|
113
|
+
currentPkg = { name, version, parents: new Set() };
|
|
114
|
+
packages.set(key, currentPkg);
|
|
115
|
+
collectingVia = false;
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (child.type === 'comment' && currentPkg) {
|
|
119
|
+
let text = child.text.trim();
|
|
120
|
+
let viaSingle = text.match(/^# via ([A-Za-z0-9][A-Za-z0-9._-]*)$/);
|
|
121
|
+
if (viaSingle) {
|
|
122
|
+
currentPkg.parents.add(this._canonicalize(viaSingle[1]));
|
|
123
|
+
collectingVia = false;
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
if (text === '# via') {
|
|
127
|
+
collectingVia = true;
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (collectingVia) {
|
|
131
|
+
let parentMatch = text.match(/^#\s+([A-Za-z0-9][A-Za-z0-9._-]*)$/);
|
|
132
|
+
if (parentMatch) {
|
|
133
|
+
currentPkg.parents.add(this._canonicalize(parentMatch[1]));
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
collectingVia = false;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// Build forward dependency map and extract direct deps in one pass
|
|
141
|
+
let graph = new Map();
|
|
142
|
+
let directDeps = [];
|
|
143
|
+
for (let [key, pkg] of packages) {
|
|
144
|
+
graph.set(key, { name: pkg.name, version: pkg.version, children: [] });
|
|
145
|
+
}
|
|
146
|
+
for (let [childKey, pkg] of packages) {
|
|
147
|
+
for (let parentKey of pkg.parents) {
|
|
148
|
+
if (parentKey === canonProjectName) {
|
|
149
|
+
directDeps.push(childKey);
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
let parentEntry = graph.get(parentKey);
|
|
153
|
+
if (parentEntry) {
|
|
154
|
+
parentEntry.children.push(childKey);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return { directDeps, graph };
|
|
159
|
+
}
|
|
160
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
2
|
import { Language, Parser, Query } from 'web-tree-sitter';
|
|
3
|
-
const
|
|
3
|
+
const wasmUrl = new URL('./tree-sitter-requirements.wasm', import.meta.url);
|
|
4
4
|
async function init() {
|
|
5
5
|
await Parser.init();
|
|
6
|
-
|
|
6
|
+
const wasmBytes = new Uint8Array(await readFile(wasmUrl));
|
|
7
|
+
return await Language.load(wasmBytes);
|
|
7
8
|
}
|
|
8
9
|
export async function getParser() {
|
|
9
10
|
const language = await init();
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
declare namespace _default {
|
|
2
|
+
export { isSupported };
|
|
3
|
+
export { validateLockFile };
|
|
4
|
+
export { provideComponent };
|
|
5
|
+
export { provideStack };
|
|
6
|
+
export { readLicenseFromManifest };
|
|
7
|
+
}
|
|
8
|
+
export default _default;
|
|
9
|
+
export type Provided = import("../provider").Provided;
|
|
10
|
+
/**
|
|
11
|
+
* @param {string} manifestName - the subject manifest name-type
|
|
12
|
+
* @returns {boolean} - return true if `Cargo.toml` is the manifest name-type
|
|
13
|
+
*/
|
|
14
|
+
declare function isSupported(manifestName: string): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Validates that Cargo.lock exists in the manifest directory or in a parent
|
|
17
|
+
* workspace root directory. In Cargo workspaces the lock file always lives at
|
|
18
|
+
* the workspace root, so when a member crate's Cargo.toml is provided we walk
|
|
19
|
+
* up the directory tree looking for Cargo.lock (stopping when we find a
|
|
20
|
+
* Cargo.toml that contains a [workspace] section, or when we reach the
|
|
21
|
+
* filesystem root).
|
|
22
|
+
* When TRUSTIFY_DA_WORKSPACE_DIR is provided (via env var or opts),
|
|
23
|
+
* checks only that directory for Cargo.lock — no walk-up.
|
|
24
|
+
* @param {string} manifestDir - the directory where the manifest lies
|
|
25
|
+
* @param {{TRUSTIFY_DA_WORKSPACE_DIR?: string}} [opts={}] - optional workspace root
|
|
26
|
+
* @returns {boolean} true if Cargo.lock is found
|
|
27
|
+
*/
|
|
28
|
+
declare function validateLockFile(manifestDir: string, opts?: {
|
|
29
|
+
TRUSTIFY_DA_WORKSPACE_DIR?: string;
|
|
30
|
+
}): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Provide content and content type for Cargo component analysis.
|
|
33
|
+
* @param {string} manifest - path to Cargo.toml for component report
|
|
34
|
+
* @param {{}} [opts={}] - optional various options to pass along the application
|
|
35
|
+
* @returns {Provided}
|
|
36
|
+
*/
|
|
37
|
+
declare function provideComponent(manifest: string, opts?: {}): Provided;
|
|
38
|
+
/**
|
|
39
|
+
* Provide content and content type for Cargo stack analysis.
|
|
40
|
+
* @param {string} manifest - the manifest path
|
|
41
|
+
* @param {{}} [opts={}] - optional various options to pass along the application
|
|
42
|
+
* @returns {Provided}
|
|
43
|
+
*/
|
|
44
|
+
declare function provideStack(manifest: string, opts?: {}): Provided;
|
|
45
|
+
/**
|
|
46
|
+
* Read project license from Cargo.toml, with fallback to LICENSE file.
|
|
47
|
+
* Supports the `license` field under `[package]` (single crate / workspace
|
|
48
|
+
* with root) and under `[workspace.package]` (virtual workspaces).
|
|
49
|
+
* @param {string} manifestPath - path to Cargo.toml
|
|
50
|
+
* @returns {string|null} SPDX identifier or null
|
|
51
|
+
*/
|
|
52
|
+
declare function readLicenseFromManifest(manifestPath: string): string | null;
|