@trustify-da/trustify-da-javascript-client 0.3.0-ea.a8c3942 → 0.3.0-ea.a9624b2

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 (52) hide show
  1. package/README.md +1 -1
  2. package/dist/package.json +25 -21
  3. package/dist/src/analysis.d.ts +14 -7
  4. package/dist/src/analysis.js +29 -13
  5. package/dist/src/cli.js +58 -1
  6. package/dist/src/cyclone_dx_sbom.js +11 -3
  7. package/dist/src/index.d.ts +12 -10
  8. package/dist/src/index.js +8 -3
  9. package/dist/src/license/index.d.ts +3 -3
  10. package/dist/src/license/index.js +4 -1
  11. package/dist/src/license/license_utils.js +4 -1
  12. package/dist/src/license/licenses_api.d.ts +2 -2
  13. package/dist/src/oci_image/images.d.ts +1 -1
  14. package/dist/src/oci_image/images.js +15 -1
  15. package/dist/src/oci_image/utils.d.ts +5 -5
  16. package/dist/src/provider.d.ts +4 -3
  17. package/dist/src/provider.js +6 -2
  18. package/dist/src/providers/base_java.d.ts +14 -3
  19. package/dist/src/providers/base_java.js +16 -6
  20. package/dist/src/providers/base_javascript.d.ts +20 -9
  21. package/dist/src/providers/base_javascript.js +10 -3
  22. package/dist/src/providers/base_pyproject.d.ts +10 -5
  23. package/dist/src/providers/base_pyproject.js +7 -0
  24. package/dist/src/providers/containerfile_parser.d.ts +5 -0
  25. package/dist/src/providers/containerfile_parser.js +20 -0
  26. package/dist/src/providers/golang_gomodules.d.ts +2 -1
  27. package/dist/src/providers/golang_gomodules.js +1 -1
  28. package/dist/src/providers/java_gradle_groovy.d.ts +1 -1
  29. package/dist/src/providers/java_gradle_kotlin.d.ts +1 -1
  30. package/dist/src/providers/java_maven.d.ts +2 -2
  31. package/dist/src/providers/java_maven.js +72 -0
  32. package/dist/src/providers/javascript_bun.d.ts +10 -0
  33. package/dist/src/providers/javascript_bun.js +100 -0
  34. package/dist/src/providers/javascript_npm.d.ts +6 -1
  35. package/dist/src/providers/oci_dockerfile.d.ts +51 -0
  36. package/dist/src/providers/oci_dockerfile.js +177 -0
  37. package/dist/src/providers/processors/yarn_berry_processor.d.ts +2 -2
  38. package/dist/src/providers/processors/yarn_classic_processor.d.ts +2 -2
  39. package/dist/src/providers/python_controller.js +57 -3
  40. package/dist/src/providers/python_pip.d.ts +1 -0
  41. package/dist/src/providers/python_pip.js +1 -1
  42. package/dist/src/providers/python_poetry.d.ts +31 -8
  43. package/dist/src/providers/python_poetry.js +62 -14
  44. package/dist/src/providers/python_uv.d.ts +5 -14
  45. package/dist/src/providers/python_uv.js +44 -2
  46. package/dist/src/providers/rust_cargo.d.ts +6 -2
  47. package/dist/src/providers/rust_cargo.js +31 -4
  48. package/dist/src/providers/tree-sitter-containerfile.wasm +0 -0
  49. package/dist/src/tools.d.ts +2 -2
  50. package/dist/src/updaters/maven_updater.d.ts +26 -0
  51. package/dist/src/updaters/maven_updater.js +322 -0
  52. package/package.json +26 -22
@@ -13,27 +13,18 @@ export function discoverUvWorkspaceMembers(workspaceRoot: string, opts?: {
13
13
  }): Promise<string[]>;
14
14
  export default class Python_uv extends Base_pyproject {
15
15
  /**
16
- * @param {string} manifestDir - directory containing the target pyproject.toml
17
- * @param {string} workspaceDir - workspace root (for resolving editable install paths)
18
- * @param {object} parsed - parsed pyproject.toml
19
- * @param {Object} opts
20
- * @returns {Promise<{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}>}
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
21
19
  */
22
- _getDependencyData(manifestDir: string, workspaceDir: string, parsed: object, opts: any): Promise<{
23
- directDeps: string[];
24
- graph: Map<string, {
25
- name: string;
26
- version: string;
27
- children: string[];
28
- }>;
29
- }>;
20
+ _attachHashesFromLockFile(lockFilePath: string, graph: Map<string, import("./base_pyproject.js").GraphEntry>): Promise<void>;
30
21
  /**
31
22
  * Get the uv export output, either from env var or by running the command.
32
23
  * @param {string} manifestDir
33
24
  * @param {Object} opts
34
25
  * @returns {string}
35
26
  */
36
- _getUvExportOutput(manifestDir: string, opts: any): string;
27
+ _getUvExportOutput(manifestDir: string, opts: Object): string;
37
28
  /**
38
29
  * Parse uv export output into a dependency graph using tree-sitter-requirements
39
30
  * for package/version extraction and string parsing for "# via" comments.
@@ -21,12 +21,54 @@ export default class Python_uv extends Base_pyproject {
21
21
  * @param {string} workspaceDir - workspace root (for resolving editable install paths)
22
22
  * @param {object} parsed - parsed pyproject.toml
23
23
  * @param {Object} opts
24
- * @returns {Promise<{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}>}
24
+ * @returns {Promise<{directDeps: string[], graph: Map<string, import('./base_pyproject.js').GraphEntry>}>}
25
25
  */
26
26
  async _getDependencyData(manifestDir, workspaceDir, parsed, opts) {
27
27
  let projectName = this._getProjectName(parsed);
28
28
  let uvOutput = this._getUvExportOutput(manifestDir, opts);
29
- return this._parseUvExport(uvOutput, projectName, workspaceDir);
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
+ }
30
72
  }
31
73
  /**
32
74
  * Get the uv export output, either from env var or by running the command.
@@ -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 = import("../provider").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
- 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);
@@ -100,13 +100,13 @@ export function invokeCommand(bin: string, args: Array<string>, opts?: import("c
100
100
  * @param {import("index.js").Options} opts - The trustify DA options that may contain proxy configuration
101
101
  * @returns {RequestInit} The fetch options with proxy agent if applicable
102
102
  */
103
- export function addProxyAgent(options: RequestInit, opts: import("index.js").Options): RequestInit;
103
+ export function addProxyAgent(options: RequestInit, opts: any): RequestInit;
104
104
  /**
105
105
  * Utility function for fetching vendor tokens
106
106
  * @param {import("index.js").Options} [opts={}] - optional various options to pass along the application
107
107
  * @returns {{}}
108
108
  */
109
- export function getTokenHeaders(opts?: import("index.js").Options): {};
109
+ export function getTokenHeaders(opts?: any): {};
110
110
  export const RegexNotToBeLogged: RegExp;
111
111
  export const TRUSTIFY_DA_TOKEN_HEADER: "trust-da-token";
112
112
  export const TRUSTIFY_DA_TELEMETRY_ID_HEADER: "telemetry-anonymous-id";
@@ -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
+ };
@@ -0,0 +1,322 @@
1
+ import { XMLParser } from 'fast-xml-parser';
2
+ /**
3
+ * Extracts the trimmed text content of a simple XML element from a string block.
4
+ * @param {string} block - the XML text to search within
5
+ * @param {string} tagName - the element name whose content to extract
6
+ * @returns {string|null} the trimmed text content, or null if not found
7
+ */
8
+ function extractTagContent(block, tagName) {
9
+ const openTag = `<${tagName}>`;
10
+ const closeTag = `</${tagName}>`;
11
+ const start = block.indexOf(openTag);
12
+ if (start === -1) {
13
+ return null;
14
+ }
15
+ const contentStart = start + openTag.length;
16
+ const end = block.indexOf(closeTag, contentStart);
17
+ if (end === -1) {
18
+ return null;
19
+ }
20
+ return block.substring(contentStart, end).trim();
21
+ }
22
+ /**
23
+ * Finds the character positions of an XML element's text content within the raw file.
24
+ * Returns the start (inclusive) and end (exclusive) offsets of the text between the
25
+ * opening and closing tags.
26
+ * @param {string} content - full raw XML content
27
+ * @param {number} searchStart - start offset to search from
28
+ * @param {number} searchEnd - end offset to search within
29
+ * @param {string} tagName - the element name whose content position to locate
30
+ * @returns {{start: number, end: number}|null} character offsets, or null if not found
31
+ */
32
+ function findTagContentPosition(content, searchStart, searchEnd, tagName) {
33
+ const openTag = `<${tagName}>`;
34
+ const closeTag = `</${tagName}>`;
35
+ const tagStart = content.indexOf(openTag, searchStart);
36
+ if (tagStart === -1 || tagStart >= searchEnd) {
37
+ return null;
38
+ }
39
+ const contentStart = tagStart + openTag.length;
40
+ const tagEnd = content.indexOf(closeTag, contentStart);
41
+ if (tagEnd === -1 || tagEnd > searchEnd) {
42
+ return null;
43
+ }
44
+ return { start: contentStart, end: tagEnd };
45
+ }
46
+ /**
47
+ * Checks whether the character immediately following a tag prefix indicates
48
+ * that the prefix is the complete tag name (e.g. `<dependency>` vs `<dependencyManagement>`).
49
+ * @param {string} char - the character after the tag prefix
50
+ * @returns {boolean} true if the character terminates the tag name
51
+ */
52
+ function isTagBoundary(char) {
53
+ return char === '>' || char === ' ' || char === '\t'
54
+ || char === '\n' || char === '\r' || char === '/';
55
+ }
56
+ /**
57
+ * Finds the text content position of a `<version>` element within the first
58
+ * `<dependency>` block matching the given groupId and artifactId.
59
+ * Searches through all `<dependency>` elements in the file, covering both
60
+ * `<dependencies>` and `<dependencyManagement>` sections.
61
+ * @param {string} content - full raw pom.xml content
62
+ * @param {string} groupId - the dependency's groupId to match
63
+ * @param {string} artifactId - the dependency's artifactId to match
64
+ * @returns {{start: number, end: number}|null} version content offsets, or null
65
+ */
66
+ function findDependencyVersionPosition(content, groupId, artifactId) {
67
+ let searchStart = 0;
68
+ const TAG_PREFIX = '<dependency';
69
+ const CLOSE_TAG = '</dependency>';
70
+ while (searchStart < content.length) {
71
+ const start = content.indexOf(TAG_PREFIX, searchStart);
72
+ if (start === -1) {
73
+ break;
74
+ }
75
+ // Verify this is exactly <dependency> and not <dependencyManagement> etc.
76
+ const charAfterTag = content.charAt(start + TAG_PREFIX.length);
77
+ if (!isTagBoundary(charAfterTag)) {
78
+ searchStart = start + 1;
79
+ continue;
80
+ }
81
+ // Find closing </dependency>
82
+ const end = content.indexOf(CLOSE_TAG, start + TAG_PREFIX.length);
83
+ if (end === -1) {
84
+ break;
85
+ }
86
+ const blockEnd = end + CLOSE_TAG.length;
87
+ const block = content.substring(start, blockEnd);
88
+ const gid = extractTagContent(block, 'groupId');
89
+ const aid = extractTagContent(block, 'artifactId');
90
+ if (gid === groupId && aid === artifactId) {
91
+ const pos = findTagContentPosition(content, start, blockEnd, 'version');
92
+ if (pos) {
93
+ return pos;
94
+ }
95
+ // Matching dependency but no <version> element; continue searching
96
+ // (the version may be in <dependencyManagement>)
97
+ }
98
+ searchStart = blockEnd;
99
+ }
100
+ return null;
101
+ }
102
+ /**
103
+ * Finds the text content position of a property element inside a `<properties>` block.
104
+ * Searches through all `<properties>` blocks in the file.
105
+ * @param {string} content - full raw pom.xml content
106
+ * @param {string} propName - the property element name to locate
107
+ * @returns {{start: number, end: number}|null} property value offsets, or null
108
+ */
109
+ function findPropertyPosition(content, propName) {
110
+ let searchStart = 0;
111
+ const TAG_PREFIX = '<properties';
112
+ const CLOSE_TAG = '</properties>';
113
+ while (searchStart < content.length) {
114
+ const propsStart = content.indexOf(TAG_PREFIX, searchStart);
115
+ if (propsStart === -1) {
116
+ break;
117
+ }
118
+ // Verify this is exactly <properties> and not some other tag
119
+ const charAfter = content.charAt(propsStart + TAG_PREFIX.length);
120
+ if (!isTagBoundary(charAfter)) {
121
+ searchStart = propsStart + 1;
122
+ continue;
123
+ }
124
+ const propsCloseStart = content.indexOf(CLOSE_TAG, propsStart);
125
+ if (propsCloseStart === -1) {
126
+ break;
127
+ }
128
+ const propsBlockEnd = propsCloseStart + CLOSE_TAG.length;
129
+ const result = findTagContentPosition(content, propsStart, propsBlockEnd, propName);
130
+ if (result) {
131
+ return result;
132
+ }
133
+ searchStart = propsBlockEnd;
134
+ }
135
+ return null;
136
+ }
137
+ /**
138
+ * Resolves a Maven property chain, following `${propName}` references through
139
+ * the properties map until a concrete (non-reference) value is reached.
140
+ * Detects circular references via a visited set.
141
+ * @param {string} propName - the initial property name to resolve
142
+ * @param {Object} properties - properties map from the parsed XML
143
+ * @param {Set<string>} [visited] - visited property names (for cycle detection)
144
+ * @returns {{terminalPropName: string, resolvedValue: string}|{error: string}}
145
+ */
146
+ function resolvePropertyChain(propName, properties, visited = new Set()) {
147
+ if (visited.has(propName)) {
148
+ const chain = [...visited, propName].join(' -> ');
149
+ return { error: `Circular property reference detected: ${chain}` };
150
+ }
151
+ visited.add(propName);
152
+ const value = properties[propName];
153
+ if (value == null) {
154
+ return { error: `Property '${propName}' not found in <properties>` };
155
+ }
156
+ const valueStr = String(value);
157
+ const propMatch = valueStr.match(/^\$\{(.+)\}$/);
158
+ if (propMatch) {
159
+ return resolvePropertyChain(propMatch[1], properties, visited);
160
+ }
161
+ return { terminalPropName: propName, resolvedValue: valueStr };
162
+ }
163
+ /**
164
+ * Updates dependency versions in a Maven pom.xml while preserving file formatting.
165
+ *
166
+ * Uses `fast-xml-parser` to understand the XML structure (dependencies and properties),
167
+ * then performs position-based string splice to replace version strings without altering
168
+ * any other formatting, comments, whitespace, or indentation.
169
+ *
170
+ * Supports `${property}` indirection: when a dependency's `<version>` is a property
171
+ * reference, the updater resolves the property chain (including recursive references)
172
+ * and updates the terminal property value in `<properties>` instead.
173
+ *
174
+ * @param {string} pomContent - the raw pom.xml file content
175
+ * @param {Array<{groupId: string, artifactId: string, newVersion: string}>} versionChanges -
176
+ * list of version changes to apply
177
+ * @returns {{content: string, applied: Array, skipped: Array}} the updated content and
178
+ * lists of applied and skipped changes
179
+ */
180
+ export function updateMavenVersions(pomContent, versionChanges) {
181
+ if (!versionChanges || versionChanges.length === 0) {
182
+ return { content: pomContent, applied: [], skipped: [] };
183
+ }
184
+ const parser = new XMLParser({
185
+ parseTagValue: false,
186
+ commentPropName: '#comment',
187
+ });
188
+ let parsed;
189
+ try {
190
+ parsed = parser.parse(pomContent);
191
+ }
192
+ catch (e) {
193
+ return {
194
+ content: pomContent,
195
+ applied: [],
196
+ skipped: versionChanges.map(vc => ({
197
+ groupId: vc.groupId,
198
+ artifactId: vc.artifactId,
199
+ newVersion: vc.newVersion,
200
+ reason: `Failed to parse pom.xml: ${e.message}`,
201
+ })),
202
+ };
203
+ }
204
+ const project = parsed?.project;
205
+ if (!project) {
206
+ return {
207
+ content: pomContent,
208
+ applied: [],
209
+ skipped: versionChanges.map(vc => ({
210
+ groupId: vc.groupId,
211
+ artifactId: vc.artifactId,
212
+ newVersion: vc.newVersion,
213
+ reason: 'No <project> element found in pom.xml',
214
+ })),
215
+ };
216
+ }
217
+ const properties = project.properties || {};
218
+ const applied = [];
219
+ const skipped = [];
220
+ /** @type {Map<number, {start: number, end: number, newValue: string}>} */
221
+ const replacementsByPosition = new Map();
222
+ for (const change of versionChanges) {
223
+ const versionPos = findDependencyVersionPosition(pomContent, change.groupId, change.artifactId);
224
+ if (!versionPos) {
225
+ skipped.push({
226
+ groupId: change.groupId,
227
+ artifactId: change.artifactId,
228
+ newVersion: change.newVersion,
229
+ reason: 'Dependency not found in pom.xml or has no <version> element',
230
+ });
231
+ continue;
232
+ }
233
+ const currentVersion = pomContent.substring(versionPos.start, versionPos.end);
234
+ const propMatch = currentVersion.match(/^\$\{(.+)\}$/);
235
+ if (propMatch) {
236
+ const resolved = resolvePropertyChain(propMatch[1], properties);
237
+ if (resolved.error) {
238
+ skipped.push({
239
+ groupId: change.groupId,
240
+ artifactId: change.artifactId,
241
+ newVersion: change.newVersion,
242
+ reason: resolved.error,
243
+ });
244
+ continue;
245
+ }
246
+ const propPos = findPropertyPosition(pomContent, resolved.terminalPropName);
247
+ if (!propPos) {
248
+ skipped.push({
249
+ groupId: change.groupId,
250
+ artifactId: change.artifactId,
251
+ newVersion: change.newVersion,
252
+ reason: `Could not locate property '${resolved.terminalPropName}' in pom.xml`,
253
+ });
254
+ continue;
255
+ }
256
+ // Deduplicate: multiple deps may share the same property
257
+ const existing = replacementsByPosition.get(propPos.start);
258
+ if (existing) {
259
+ if (existing.newValue !== change.newVersion) {
260
+ skipped.push({
261
+ groupId: change.groupId,
262
+ artifactId: change.artifactId,
263
+ newVersion: change.newVersion,
264
+ reason: `Property '${resolved.terminalPropName}' already targeted `
265
+ + `with a different version '${existing.newValue}'`,
266
+ });
267
+ continue;
268
+ }
269
+ // Same replacement already queued; record as applied without duplicating
270
+ }
271
+ else {
272
+ replacementsByPosition.set(propPos.start, {
273
+ start: propPos.start,
274
+ end: propPos.end,
275
+ newValue: change.newVersion,
276
+ });
277
+ }
278
+ applied.push({
279
+ groupId: change.groupId,
280
+ artifactId: change.artifactId,
281
+ newVersion: change.newVersion,
282
+ type: 'property',
283
+ property: resolved.terminalPropName,
284
+ });
285
+ }
286
+ else {
287
+ const existing = replacementsByPosition.get(versionPos.start);
288
+ if (existing) {
289
+ if (existing.newValue !== change.newVersion) {
290
+ skipped.push({
291
+ groupId: change.groupId,
292
+ artifactId: change.artifactId,
293
+ newVersion: change.newVersion,
294
+ reason: `Version already targeted with a different version '${existing.newValue}'`,
295
+ });
296
+ continue;
297
+ }
298
+ }
299
+ else {
300
+ replacementsByPosition.set(versionPos.start, {
301
+ start: versionPos.start,
302
+ end: versionPos.end,
303
+ newValue: change.newVersion,
304
+ });
305
+ }
306
+ applied.push({
307
+ groupId: change.groupId,
308
+ artifactId: change.artifactId,
309
+ newVersion: change.newVersion,
310
+ type: 'direct',
311
+ });
312
+ }
313
+ }
314
+ // Sort replacements by position descending to preserve offsets during splice
315
+ const sortedReplacements = [...replacementsByPosition.values()]
316
+ .sort((a, b) => b.start - a.start);
317
+ let result = pomContent;
318
+ for (const r of sortedReplacements) {
319
+ result = result.substring(0, r.start) + r.newValue + result.substring(r.end);
320
+ }
321
+ return { content: result, applied, skipped };
322
+ }
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.a8c3942",
3
+ "version": "0.3.0-ea.a9624b2",
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",
@@ -35,31 +35,33 @@
35
35
  "config/**/*"
36
36
  ],
37
37
  "scripts": {
38
- "lint": "eslint src test --ext js",
39
- "lint:fix": "eslint src test --ext js --fix",
38
+ "lint": "eslint src test",
39
+ "lint:fix": "eslint src test --fix",
40
40
  "test": "c8 npm run tests",
41
41
  "tests": "mocha --config .mocharc.json",
42
42
  "tests:rep": "mocha --reporter-option maxDiffSize=0 --reporter json > unit-tests-result.json",
43
- "pretest": "cp node_modules/tree-sitter-requirements/tree-sitter-requirements.wasm src/providers/tree-sitter-requirements.wasm && cp node_modules/tree-sitter-gomod/tree-sitter-gomod.wasm src/providers/tree-sitter-gomod.wasm",
43
+ "pretest": "cp node_modules/tree-sitter-requirements/tree-sitter-requirements.wasm src/providers/tree-sitter-requirements.wasm && cp node_modules/tree-sitter-gomod/tree-sitter-gomod.wasm src/providers/tree-sitter-gomod.wasm && cp node_modules/tree-sitter-containerfile/tree-sitter-containerfile.wasm src/providers/tree-sitter-containerfile.wasm",
44
44
  "precompile": "rm -rf dist",
45
45
  "compile": "tsc -p tsconfig.json",
46
46
  "compile:dev": "tsc -p tsconfig.dev.json",
47
- "postcompile": "cp node_modules/tree-sitter-requirements/tree-sitter-requirements.wasm dist/src/providers/tree-sitter-requirements.wasm && cp node_modules/tree-sitter-gomod/tree-sitter-gomod.wasm dist/src/providers/tree-sitter-gomod.wasm"
47
+ "postcompile": "cp node_modules/tree-sitter-requirements/tree-sitter-requirements.wasm dist/src/providers/tree-sitter-requirements.wasm && cp node_modules/tree-sitter-gomod/tree-sitter-gomod.wasm dist/src/providers/tree-sitter-gomod.wasm && cp node_modules/tree-sitter-containerfile/tree-sitter-containerfile.wasm dist/src/providers/tree-sitter-containerfile.wasm"
48
48
  },
49
49
  "dependencies": {
50
50
  "@babel/core": "^7.23.2",
51
- "@cyclonedx/cyclonedx-library": "^6.13.0",
51
+ "@cyclonedx/cyclonedx-library": "^10.0.0",
52
52
  "eslint-import-resolver-typescript": "^4.4.4",
53
53
  "fast-glob": "^3.3.3",
54
54
  "fast-xml-parser": "^5.3.4",
55
55
  "help": "^3.0.2",
56
- "https-proxy-agent": "^7.0.6",
56
+ "https-proxy-agent": "^9.0.0",
57
57
  "js-yaml": "^4.1.1",
58
+ "jsonc-parser": "^3.3.1",
58
59
  "micromatch": "^4.0.8",
59
60
  "node-fetch": "^3.3.2",
60
- "p-limit": "^4.0.0",
61
+ "p-limit": "^7.3.0",
61
62
  "packageurl-js": "~1.0.2",
62
63
  "smol-toml": "^1.6.0",
64
+ "tree-sitter-containerfile": "^0.8.1",
63
65
  "tree-sitter-gomod": "github:strum355/tree-sitter-go-mod#56326f2ad478892ace58ff247a97d492a3cbcdda",
64
66
  "tree-sitter-requirements": "github:Strum355/tree-sitter-requirements#d0261ee76b84253997fe70d7d397e78c006c3801",
65
67
  "web-tree-sitter": "^0.26.7",
@@ -67,23 +69,24 @@
67
69
  },
68
70
  "devDependencies": {
69
71
  "@babel/core": "^7.23.2",
70
- "@trustify-da/trustify-da-api-model": "^2.0.7",
71
- "@types/node": "^20.17.30",
72
+ "@eslint/js": "^10.0.0",
73
+ "@trustify-da/trustify-da-api-model": "^2.0.12",
74
+ "@types/node": "^25.9.1",
72
75
  "@types/which": "^3.0.4",
73
76
  "babel-plugin-rewire": "^1.2.0",
74
77
  "c8": "^11.0.0",
75
- "chai": "^4.3.7",
76
- "eslint": "^8.42.0",
78
+ "chai": "^6.2.2",
79
+ "eslint": "^10.4.1",
77
80
  "eslint-import-resolver-typescript": "^4.4.4",
78
- "eslint-plugin-editorconfig": "^4.0.3",
79
- "eslint-plugin-import": "^2.29.1",
81
+ "eslint-plugin-import-x": "^4.16.2",
80
82
  "esmock": "^2.6.2",
81
- "mocha": "^10.2.0",
83
+ "globals": "^17.6.0",
84
+ "mocha": "^11.7.6",
82
85
  "msw": "^2.12.7",
83
- "sinon": "^15.1.2",
84
- "sinon-chai": "^3.7.0",
85
- "typescript": "^5.1.3",
86
- "which": "^5.0.0"
86
+ "sinon": "^22.0.0",
87
+ "sinon-chai": "^4.0.1",
88
+ "typescript": "^6.0.3",
89
+ "which": "^7.0.0"
87
90
  },
88
91
  "mocha": {
89
92
  "check-leaks": false,
@@ -111,12 +114,13 @@
111
114
  "reporter": [
112
115
  "html",
113
116
  "json",
117
+ "lcov",
114
118
  "text"
115
119
  ]
116
120
  },
117
- "eslintIgnore": [
118
- "index.js"
119
- ],
121
+ "overrides": {
122
+ "tree-sitter": "0.22.4"
123
+ },
120
124
  "resolutions": {
121
125
  "@hapi/joi": "17.1.1"
122
126
  }