@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.
Files changed (48) hide show
  1. package/dist/package.json +1 -1
  2. package/dist/src/cli.js +51 -2
  3. package/dist/src/cyclone_dx_sbom.d.ts +7 -1
  4. package/dist/src/cyclone_dx_sbom.js +29 -8
  5. package/dist/src/index.d.ts +72 -3
  6. package/dist/src/index.js +90 -7
  7. package/dist/src/oci_image/utils.js +11 -2
  8. package/dist/src/provider.d.ts +3 -2
  9. package/dist/src/provider.js +5 -1
  10. package/dist/src/providers/base_java.d.ts +12 -10
  11. package/dist/src/providers/base_java.js +18 -44
  12. package/dist/src/providers/base_javascript.d.ts +11 -0
  13. package/dist/src/providers/base_javascript.js +10 -3
  14. package/dist/src/providers/base_pyproject.d.ts +40 -29
  15. package/dist/src/providers/base_pyproject.js +121 -78
  16. package/dist/src/providers/golang_gomodules.d.ts +10 -0
  17. package/dist/src/providers/golang_gomodules.js +65 -8
  18. package/dist/src/providers/java_gradle.d.ts +19 -0
  19. package/dist/src/providers/java_gradle.js +116 -2
  20. package/dist/src/providers/java_maven.d.ts +8 -0
  21. package/dist/src/providers/java_maven.js +165 -1
  22. package/dist/src/providers/javascript_bun.d.ts +10 -0
  23. package/dist/src/providers/javascript_bun.js +100 -0
  24. package/dist/src/providers/javascript_npm.d.ts +1 -0
  25. package/dist/src/providers/javascript_npm.js +21 -0
  26. package/dist/src/providers/javascript_pnpm.js +6 -2
  27. package/dist/src/providers/marker_evaluator.d.ts +14 -0
  28. package/dist/src/providers/marker_evaluator.js +191 -0
  29. package/dist/src/providers/processors/yarn_berry_processor.js +6 -2
  30. package/dist/src/providers/python_controller.d.ts +5 -1
  31. package/dist/src/providers/python_controller.js +65 -7
  32. package/dist/src/providers/python_pip.d.ts +5 -0
  33. package/dist/src/providers/python_pip.js +5 -5
  34. package/dist/src/providers/python_pip_pyproject.d.ts +61 -0
  35. package/dist/src/providers/python_pip_pyproject.js +146 -0
  36. package/dist/src/providers/python_poetry.d.ts +64 -8
  37. package/dist/src/providers/python_poetry.js +165 -25
  38. package/dist/src/providers/python_uv.d.ts +21 -1
  39. package/dist/src/providers/python_uv.js +157 -6
  40. package/dist/src/providers/rust_cargo.d.ts +5 -1
  41. package/dist/src/providers/rust_cargo.js +31 -4
  42. package/dist/src/sbom.d.ts +7 -1
  43. package/dist/src/sbom.js +4 -2
  44. package/dist/src/tools.d.ts +26 -0
  45. package/dist/src/tools.js +58 -0
  46. package/dist/src/workspace.d.ts +9 -0
  47. package/dist/src/workspace.js +1 -1
  48. package/package.json +2 -2
@@ -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
- fromManifest = parsed.package?.license
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);
@@ -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: any): CycloneDxSbom;
32
+ addDependency(sourceRef: component, targetRef: PackageURL, scope?: string, targetHashes?: Array<{
33
+ alg: string;
34
+ content: string;
35
+ }>): CycloneDxSbom;
31
36
  /**
32
37
  * @return String sbom json in a string format
33
38
  */
@@ -45,6 +50,7 @@ export default class Sbom {
45
50
  version: any;
46
51
  scope: any;
47
52
  licenses?: any;
53
+ hashes?: any;
48
54
  };
49
55
  /** This method gets a component object, and a string name, and checks if the name is a substring of the component' purl.
50
56
  * @param {} component to search in its dependencies
package/dist/src/sbom.js CHANGED
@@ -43,10 +43,12 @@ export default class Sbom {
43
43
  /**
44
44
  * @param {component} sourceRef current source Component ( Starting from root component by clients)
45
45
  * @param {PackageURL} targetRef current dependency to add to Dependencies list of component sourceRef
46
+ * @param {string} [scope] - Scope of the dependency
47
+ * @param {Array<{alg: string, content: string}>} [targetHashes] - Optional hashes for the target component
46
48
  * @return Sbom
47
49
  */
48
- addDependency(sourceRef, targetRef, scope) {
49
- return this.sbomModel.addDependency(sourceRef, targetRef, scope);
50
+ addDependency(sourceRef, targetRef, scope, targetHashes) {
51
+ return this.sbomModel.addDependency(sourceRef, targetRef, scope, targetHashes);
50
52
  }
51
53
  /**
52
54
  * @return String sbom json in a string format
@@ -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
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
@@ -42,6 +42,15 @@ export function discoverWorkspacePackages(workspaceRoot: string, opts?: {
42
42
  TRUSTIFY_DA_WORKSPACE_DISCOVERY_IGNORE?: string;
43
43
  [key: string]: unknown;
44
44
  }): Promise<string[]>;
45
+ /**
46
+ * Convert workspace glob patterns to manifest-file glob patterns,
47
+ * correctly handling negation prefixes.
48
+ *
49
+ * @param {string[]} patterns - Workspace glob patterns (may include negations)
50
+ * @param {string} manifestFileName - e.g. 'package.json' or 'Cargo.toml'
51
+ * @returns {string[]}
52
+ */
53
+ export function toManifestGlobPatterns(patterns: string[], manifestFileName: string): string[];
45
54
  /**
46
55
  * Discover all Cargo.toml manifest paths in a Cargo workspace.
47
56
  * Uses `cargo metadata` to get workspace members.
@@ -172,7 +172,7 @@ function parsePnpmPackages(content) {
172
172
  * @param {string} manifestFileName - e.g. 'package.json' or 'Cargo.toml'
173
173
  * @returns {string[]}
174
174
  */
175
- function toManifestGlobPatterns(patterns, manifestFileName) {
175
+ export function toManifestGlobPatterns(patterns, manifestFileName) {
176
176
  return patterns.map(p => {
177
177
  if (p.startsWith('!')) {
178
178
  return `!${p.slice(1)}/${manifestFileName}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trustify-da/trustify-da-javascript-client",
3
- "version": "0.3.0-ea.e5bb86c",
3
+ "version": "0.3.0-ea.e660b02",
4
4
  "description": "Code-Ready Dependency Analytics JavaScript API.",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/guacsec/trustify-da-javascript-client#README.md",
@@ -51,11 +51,11 @@
51
51
  "@cyclonedx/cyclonedx-library": "^6.13.0",
52
52
  "eslint-import-resolver-typescript": "^4.4.4",
53
53
  "fast-glob": "^3.3.3",
54
- "fast-toml": "^0.5.4",
55
54
  "fast-xml-parser": "^5.3.4",
56
55
  "help": "^3.0.2",
57
56
  "https-proxy-agent": "^7.0.6",
58
57
  "js-yaml": "^4.1.1",
58
+ "jsonc-parser": "^3.3.1",
59
59
  "micromatch": "^4.0.8",
60
60
  "node-fetch": "^3.3.2",
61
61
  "p-limit": "^4.0.0",