@trustify-da/trustify-da-javascript-client 0.3.0-ea.f2d5d72 → 0.3.0-ea.fa16f06

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 (77) hide show
  1. package/README.md +2 -2
  2. package/dist/package.json +26 -23
  3. package/dist/src/analysis.d.ts +14 -7
  4. package/dist/src/analysis.js +32 -15
  5. package/dist/src/cli.js +156 -3
  6. package/dist/src/cyclone_dx_sbom.d.ts +7 -1
  7. package/dist/src/cyclone_dx_sbom.js +29 -8
  8. package/dist/src/index.d.ts +84 -11
  9. package/dist/src/index.js +95 -8
  10. package/dist/src/license/index.d.ts +3 -3
  11. package/dist/src/license/index.js +4 -1
  12. package/dist/src/license/license_utils.js +4 -1
  13. package/dist/src/license/licenses_api.d.ts +2 -2
  14. package/dist/src/oci_image/images.d.ts +1 -1
  15. package/dist/src/oci_image/images.js +15 -1
  16. package/dist/src/oci_image/utils.d.ts +5 -5
  17. package/dist/src/oci_image/utils.js +11 -2
  18. package/dist/src/provider.d.ts +4 -3
  19. package/dist/src/provider.js +8 -2
  20. package/dist/src/providers/base_java.d.ts +14 -12
  21. package/dist/src/providers/base_java.js +18 -44
  22. package/dist/src/providers/base_javascript.d.ts +20 -9
  23. package/dist/src/providers/base_javascript.js +10 -3
  24. package/dist/src/providers/base_pyproject.d.ts +42 -31
  25. package/dist/src/providers/base_pyproject.js +121 -78
  26. package/dist/src/providers/containerfile_parser.d.ts +5 -0
  27. package/dist/src/providers/containerfile_parser.js +20 -0
  28. package/dist/src/providers/golang_gomodules.d.ts +11 -1
  29. package/dist/src/providers/golang_gomodules.js +65 -8
  30. package/dist/src/providers/java_gradle.d.ts +19 -0
  31. package/dist/src/providers/java_gradle.js +116 -2
  32. package/dist/src/providers/java_gradle_groovy.d.ts +1 -1
  33. package/dist/src/providers/java_gradle_kotlin.d.ts +1 -1
  34. package/dist/src/providers/java_maven.d.ts +10 -2
  35. package/dist/src/providers/java_maven.js +165 -1
  36. package/dist/src/providers/javascript_bun.d.ts +10 -0
  37. package/dist/src/providers/javascript_bun.js +100 -0
  38. package/dist/src/providers/javascript_npm.d.ts +6 -0
  39. package/dist/src/providers/javascript_npm.js +21 -0
  40. package/dist/src/providers/javascript_pnpm.js +6 -2
  41. package/dist/src/providers/marker_evaluator.d.ts +14 -0
  42. package/dist/src/providers/marker_evaluator.js +191 -0
  43. package/dist/src/providers/oci_dockerfile.d.ts +51 -0
  44. package/dist/src/providers/oci_dockerfile.js +177 -0
  45. package/dist/src/providers/processors/yarn_berry_processor.d.ts +2 -2
  46. package/dist/src/providers/processors/yarn_berry_processor.js +6 -2
  47. package/dist/src/providers/processors/yarn_classic_processor.d.ts +2 -2
  48. package/dist/src/providers/python_controller.d.ts +5 -1
  49. package/dist/src/providers/python_controller.js +69 -8
  50. package/dist/src/providers/python_pip.d.ts +5 -0
  51. package/dist/src/providers/python_pip.js +5 -5
  52. package/dist/src/providers/python_pip_pyproject.d.ts +61 -0
  53. package/dist/src/providers/python_pip_pyproject.js +146 -0
  54. package/dist/src/providers/python_poetry.d.ts +64 -8
  55. package/dist/src/providers/python_poetry.js +165 -25
  56. package/dist/src/providers/python_uv.d.ts +22 -2
  57. package/dist/src/providers/python_uv.js +157 -6
  58. package/dist/src/providers/rust_cargo.d.ts +6 -2
  59. package/dist/src/providers/rust_cargo.js +105 -19
  60. package/dist/src/providers/tree-sitter-containerfile.wasm +0 -0
  61. package/dist/src/remediate.d.ts +21 -0
  62. package/dist/src/remediate.js +149 -0
  63. package/dist/src/remediation.d.ts +57 -0
  64. package/dist/src/remediation.js +436 -0
  65. package/dist/src/remediation_report.d.ts +40 -0
  66. package/dist/src/remediation_report.js +159 -0
  67. package/dist/src/sbom.d.ts +7 -1
  68. package/dist/src/sbom.js +4 -2
  69. package/dist/src/tools.d.ts +28 -2
  70. package/dist/src/tools.js +58 -0
  71. package/dist/src/updaters/maven_updater.d.ts +26 -0
  72. package/dist/src/updaters/maven_updater.js +322 -0
  73. package/dist/src/updaters/toml_updater.d.ts +33 -0
  74. package/dist/src/updaters/toml_updater.js +244 -0
  75. package/dist/src/workspace.d.ts +9 -0
  76. package/dist/src/workspace.js +1 -1
  77. package/package.json +27 -24
@@ -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
@@ -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: import("index.js").Options): RequestInit;
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?: import("index.js").Options): {};
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
+ };
@@ -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
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Updates dependency versions in a Gradle version catalog (libs.versions.toml) file.
3
+ *
4
+ * Supports two version declaration patterns:
5
+ * - Centralized: [versions] section defines version aliases, [libraries] references via version.ref
6
+ * - Inline: [libraries] entries include version = "x.y.z" directly
7
+ *
8
+ * Uses smol-toml parse() to locate keys, then performs position-based string replacement
9
+ * on the raw content to preserve formatting and comments.
10
+ *
11
+ * @param {string} tomlContent - raw TOML file content
12
+ * @param {Array<{groupId: string, artifactId: string, newVersion: string}>} versionChanges
13
+ * @returns {{content: string, applied: Array<{groupId: string, artifactId: string, newVersion: string, oldVersion: string}>, skipped: Array<{groupId: string, artifactId: string, newVersion: string, reason: string}>}}
14
+ */
15
+ export function updateTomlVersions(tomlContent: string, versionChanges: Array<{
16
+ groupId: string;
17
+ artifactId: string;
18
+ newVersion: string;
19
+ }>): {
20
+ content: string;
21
+ applied: Array<{
22
+ groupId: string;
23
+ artifactId: string;
24
+ newVersion: string;
25
+ oldVersion: string;
26
+ }>;
27
+ skipped: Array<{
28
+ groupId: string;
29
+ artifactId: string;
30
+ newVersion: string;
31
+ reason: string;
32
+ }>;
33
+ };