@trustify-da/trustify-da-javascript-client 0.3.0-ea.63ae5c2 → 0.3.0-ea.6ca858a

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.
Files changed (59) hide show
  1. package/README.md +191 -11
  2. package/dist/package.json +13 -4
  3. package/dist/src/analysis.d.ts +16 -6
  4. package/dist/src/analysis.js +72 -68
  5. package/dist/src/batch_opts.d.ts +24 -0
  6. package/dist/src/batch_opts.js +35 -0
  7. package/dist/src/cli.js +241 -8
  8. package/dist/src/cyclone_dx_sbom.d.ts +10 -1
  9. package/dist/src/cyclone_dx_sbom.js +32 -5
  10. package/dist/src/index.d.ts +76 -1
  11. package/dist/src/index.js +285 -4
  12. package/dist/src/license/index.d.ts +28 -0
  13. package/dist/src/license/index.js +100 -0
  14. package/dist/src/license/license_utils.d.ts +40 -0
  15. package/dist/src/license/license_utils.js +134 -0
  16. package/dist/src/license/licenses_api.d.ts +34 -0
  17. package/dist/src/license/licenses_api.js +98 -0
  18. package/dist/src/license/project_license.d.ts +20 -0
  19. package/dist/src/license/project_license.js +62 -0
  20. package/dist/src/oci_image/utils.js +11 -2
  21. package/dist/src/provider.d.ts +15 -3
  22. package/dist/src/provider.js +29 -5
  23. package/dist/src/providers/base_javascript.d.ts +29 -7
  24. package/dist/src/providers/base_javascript.js +129 -22
  25. package/dist/src/providers/base_pyproject.d.ts +149 -0
  26. package/dist/src/providers/base_pyproject.js +314 -0
  27. package/dist/src/providers/golang_gomodules.d.ts +19 -12
  28. package/dist/src/providers/golang_gomodules.js +112 -114
  29. package/dist/src/providers/gomod_parser.d.ts +4 -0
  30. package/dist/src/providers/gomod_parser.js +16 -0
  31. package/dist/src/providers/java_gradle.d.ts +6 -0
  32. package/dist/src/providers/java_gradle.js +12 -2
  33. package/dist/src/providers/java_maven.d.ts +8 -1
  34. package/dist/src/providers/java_maven.js +32 -4
  35. package/dist/src/providers/javascript_pnpm.d.ts +1 -1
  36. package/dist/src/providers/javascript_pnpm.js +2 -2
  37. package/dist/src/providers/manifest.d.ts +2 -0
  38. package/dist/src/providers/manifest.js +22 -4
  39. package/dist/src/providers/processors/yarn_berry_processor.js +82 -3
  40. package/dist/src/providers/python_pip.d.ts +7 -0
  41. package/dist/src/providers/python_pip.js +14 -4
  42. package/dist/src/providers/python_pip_pyproject.d.ts +61 -0
  43. package/dist/src/providers/python_pip_pyproject.js +144 -0
  44. package/dist/src/providers/python_poetry.d.ts +43 -0
  45. package/dist/src/providers/python_poetry.js +175 -0
  46. package/dist/src/providers/python_uv.d.ts +27 -0
  47. package/dist/src/providers/python_uv.js +146 -0
  48. package/dist/src/providers/requirements_parser.js +5 -8
  49. package/dist/src/providers/rust_cargo.d.ts +52 -0
  50. package/dist/src/providers/rust_cargo.js +614 -0
  51. package/dist/src/providers/tree-sitter-gomod.wasm +0 -0
  52. package/dist/src/providers/tree-sitter-requirements.wasm +0 -0
  53. package/dist/src/sbom.d.ts +10 -1
  54. package/dist/src/sbom.js +12 -2
  55. package/dist/src/tools.d.ts +18 -0
  56. package/dist/src/tools.js +55 -0
  57. package/dist/src/workspace.d.ts +61 -0
  58. package/dist/src/workspace.js +256 -0
  59. package/package.json +14 -5
@@ -0,0 +1,146 @@
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 { getParser, getPinnedVersionQuery } from './requirements_parser.js';
7
+ export default class Python_uv extends Base_pyproject {
8
+ /** @returns {string} */
9
+ _lockFileName() {
10
+ return 'uv.lock';
11
+ }
12
+ /** @returns {string} */
13
+ _cmdName() {
14
+ return 'uv';
15
+ }
16
+ /**
17
+ * @param {string} manifestDir - directory containing the target pyproject.toml
18
+ * @param {string} workspaceDir - workspace root (for resolving editable install paths)
19
+ * @param {object} parsed - parsed pyproject.toml
20
+ * @param {Object} opts
21
+ * @returns {Promise<{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}>}
22
+ */
23
+ async _getDependencyData(manifestDir, workspaceDir, parsed, opts) {
24
+ let projectName = this._getProjectName(parsed);
25
+ let uvOutput = this._getUvExportOutput(manifestDir, opts);
26
+ return this._parseUvExport(uvOutput, projectName, workspaceDir);
27
+ }
28
+ /**
29
+ * Get the uv export output, either from env var or by running the command.
30
+ * @param {string} manifestDir
31
+ * @param {Object} opts
32
+ * @returns {string}
33
+ */
34
+ _getUvExportOutput(manifestDir, opts) {
35
+ if (environmentVariableIsPopulated('TRUSTIFY_DA_UV_EXPORT')) {
36
+ return Buffer.from(process.env['TRUSTIFY_DA_UV_EXPORT'], 'base64').toString('ascii');
37
+ }
38
+ let uvBin = getCustomPath('uv', opts);
39
+ return invokeCommand(uvBin, ['export', '--format', 'requirements.txt', '--frozen', '--no-hashes', '--no-dev'], { cwd: manifestDir }).toString();
40
+ }
41
+ /**
42
+ * Parse uv export output into a dependency graph using tree-sitter-requirements
43
+ * for package/version extraction and string parsing for "# via" comments.
44
+ *
45
+ * @param {string} output
46
+ * @param {string} projectName - canonical project name to identify direct deps
47
+ * @param {string} workspaceDir - workspace root (for resolving editable install paths)
48
+ * @returns {Promise<{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}>}
49
+ */
50
+ async _parseUvExport(output, projectName, workspaceDir) {
51
+ let [parser, pinnedVersionQuery] = await Promise.all([
52
+ getParser(), getPinnedVersionQuery()
53
+ ]);
54
+ let tree = parser.parse(output);
55
+ let root = tree.rootNode;
56
+ let canonProjectName = this._canonicalize(projectName);
57
+ let packages = new Map(); // canonical name -> {name, version, parents: Set}
58
+ let currentPkg = null;
59
+ let collectingVia = false;
60
+ for (let child of root.children) {
61
+ if (child.type === 'global_opt') {
62
+ let optNode = child.children.find(c => c.type === 'option');
63
+ let pathNode = child.children.find(c => c.type === 'path');
64
+ if (optNode?.text === '-e' && pathNode && workspaceDir) {
65
+ let memberDir = path.resolve(workspaceDir, pathNode.text);
66
+ let memberManifest = path.join(memberDir, 'pyproject.toml');
67
+ if (fs.existsSync(memberManifest)) {
68
+ let memberParsed = parseToml(fs.readFileSync(memberManifest, 'utf-8'));
69
+ let name = memberParsed.project?.name || memberParsed.tool?.poetry?.name;
70
+ let version = memberParsed.project?.version || memberParsed.tool?.poetry?.version;
71
+ if (name && version) {
72
+ let key = this._canonicalize(name);
73
+ currentPkg = { name, version, parents: new Set() };
74
+ packages.set(key, currentPkg);
75
+ collectingVia = false;
76
+ continue;
77
+ }
78
+ }
79
+ }
80
+ currentPkg = null;
81
+ collectingVia = false;
82
+ continue;
83
+ }
84
+ if (child.type === 'requirement') {
85
+ let nameNode = child.children.find(c => c.type === 'package');
86
+ if (!nameNode) {
87
+ continue;
88
+ }
89
+ let name = nameNode.text;
90
+ let version = null;
91
+ let versionMatches = pinnedVersionQuery.matches(child);
92
+ if (versionMatches.length > 0) {
93
+ version = versionMatches[0].captures.find(c => c.name === 'version').node.text;
94
+ }
95
+ if (!version) {
96
+ throw new Error(`uv export: package '${name}' has no pinned version`);
97
+ }
98
+ let key = this._canonicalize(name);
99
+ currentPkg = { name, version, parents: new Set() };
100
+ packages.set(key, currentPkg);
101
+ collectingVia = false;
102
+ continue;
103
+ }
104
+ if (child.type === 'comment' && currentPkg) {
105
+ let text = child.text.trim();
106
+ let viaSingle = text.match(/^# via ([A-Za-z0-9][A-Za-z0-9._-]*)$/);
107
+ if (viaSingle) {
108
+ currentPkg.parents.add(this._canonicalize(viaSingle[1]));
109
+ collectingVia = false;
110
+ continue;
111
+ }
112
+ if (text === '# via') {
113
+ collectingVia = true;
114
+ continue;
115
+ }
116
+ if (collectingVia) {
117
+ let parentMatch = text.match(/^#\s+([A-Za-z0-9][A-Za-z0-9._-]*)$/);
118
+ if (parentMatch) {
119
+ currentPkg.parents.add(this._canonicalize(parentMatch[1]));
120
+ continue;
121
+ }
122
+ collectingVia = false;
123
+ }
124
+ }
125
+ }
126
+ // Build forward dependency map and extract direct deps in one pass
127
+ let graph = new Map();
128
+ let directDeps = [];
129
+ for (let [key, pkg] of packages) {
130
+ graph.set(key, { name: pkg.name, version: pkg.version, children: [] });
131
+ }
132
+ for (let [childKey, pkg] of packages) {
133
+ for (let parentKey of pkg.parents) {
134
+ if (parentKey === canonProjectName) {
135
+ directDeps.push(childKey);
136
+ continue;
137
+ }
138
+ let parentEntry = graph.get(parentKey);
139
+ if (parentEntry) {
140
+ parentEntry.children.push(childKey);
141
+ }
142
+ }
143
+ }
144
+ return { directDeps, graph };
145
+ }
146
+ }
@@ -1,13 +1,10 @@
1
- import { createRequire } from 'node:module';
1
+ import { readFile } from 'node:fs/promises';
2
2
  import { Language, Parser, Query } from 'web-tree-sitter';
3
- const require = createRequire(import.meta.url);
3
+ const wasmUrl = new URL('./tree-sitter-requirements.wasm', import.meta.url);
4
4
  async function init() {
5
- await Parser.init({
6
- locateFile() {
7
- return require.resolve('web-tree-sitter/web-tree-sitter.wasm');
8
- }
9
- });
10
- return await Language.load(require.resolve('tree-sitter-requirements/tree-sitter-requirements.wasm'));
5
+ await Parser.init();
6
+ const wasmBytes = new Uint8Array(await readFile(wasmUrl));
7
+ return await Language.load(wasmBytes);
11
8
  }
12
9
  export async function getParser() {
13
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;