@trustify-da/trustify-da-javascript-client 0.3.0-ea.f501753 → 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 (64) hide show
  1. package/README.md +2 -2
  2. package/dist/package.json +25 -22
  3. package/dist/src/analysis.d.ts +14 -7
  4. package/dist/src/analysis.js +29 -13
  5. package/dist/src/cli.js +106 -2
  6. package/dist/src/cyclone_dx_sbom.js +11 -3
  7. package/dist/src/index.d.ts +17 -12
  8. package/dist/src/index.js +21 -7
  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.js +2 -2
  29. package/dist/src/providers/java_gradle_groovy.d.ts +1 -1
  30. package/dist/src/providers/java_gradle_kotlin.d.ts +1 -1
  31. package/dist/src/providers/java_maven.d.ts +2 -2
  32. package/dist/src/providers/java_maven.js +72 -0
  33. package/dist/src/providers/javascript_bun.d.ts +10 -0
  34. package/dist/src/providers/javascript_bun.js +100 -0
  35. package/dist/src/providers/javascript_npm.d.ts +6 -1
  36. package/dist/src/providers/oci_dockerfile.d.ts +51 -0
  37. package/dist/src/providers/oci_dockerfile.js +177 -0
  38. package/dist/src/providers/processors/yarn_berry_processor.d.ts +2 -2
  39. package/dist/src/providers/processors/yarn_classic_processor.d.ts +2 -2
  40. package/dist/src/providers/python_controller.js +61 -4
  41. package/dist/src/providers/python_pip.d.ts +1 -0
  42. package/dist/src/providers/python_pip.js +1 -1
  43. package/dist/src/providers/python_pip_pyproject.js +3 -1
  44. package/dist/src/providers/python_poetry.d.ts +31 -8
  45. package/dist/src/providers/python_poetry.js +62 -14
  46. package/dist/src/providers/python_uv.d.ts +18 -14
  47. package/dist/src/providers/python_uv.js +111 -2
  48. package/dist/src/providers/rust_cargo.d.ts +6 -2
  49. package/dist/src/providers/rust_cargo.js +105 -19
  50. package/dist/src/providers/tree-sitter-containerfile.wasm +0 -0
  51. package/dist/src/remediate.d.ts +21 -0
  52. package/dist/src/remediate.js +149 -0
  53. package/dist/src/remediation.d.ts +57 -0
  54. package/dist/src/remediation.js +436 -0
  55. package/dist/src/remediation_report.d.ts +40 -0
  56. package/dist/src/remediation_report.js +159 -0
  57. package/dist/src/tools.d.ts +2 -2
  58. package/dist/src/updaters/maven_updater.d.ts +26 -0
  59. package/dist/src/updaters/maven_updater.js +322 -0
  60. package/dist/src/updaters/toml_updater.d.ts +33 -0
  61. package/dist/src/updaters/toml_updater.js +244 -0
  62. package/dist/src/workspace.d.ts +9 -0
  63. package/dist/src/workspace.js +1 -1
  64. package/package.json +26 -23
@@ -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
+ };
@@ -0,0 +1,244 @@
1
+ import { parse as parseToml } from 'smol-toml';
2
+ /**
3
+ * Updates dependency versions in a Gradle version catalog (libs.versions.toml) file.
4
+ *
5
+ * Supports two version declaration patterns:
6
+ * - Centralized: [versions] section defines version aliases, [libraries] references via version.ref
7
+ * - Inline: [libraries] entries include version = "x.y.z" directly
8
+ *
9
+ * Uses smol-toml parse() to locate keys, then performs position-based string replacement
10
+ * on the raw content to preserve formatting and comments.
11
+ *
12
+ * @param {string} tomlContent - raw TOML file content
13
+ * @param {Array<{groupId: string, artifactId: string, newVersion: string}>} versionChanges
14
+ * @returns {{content: string, applied: Array<{groupId: string, artifactId: string, newVersion: string, oldVersion: string}>, skipped: Array<{groupId: string, artifactId: string, newVersion: string, reason: string}>}}
15
+ */
16
+ export function updateTomlVersions(tomlContent, versionChanges) {
17
+ const applied = [];
18
+ const skipped = [];
19
+ if (!versionChanges || versionChanges.length === 0) {
20
+ return { content: tomlContent, applied, skipped };
21
+ }
22
+ let parsed;
23
+ try {
24
+ parsed = parseToml(tomlContent);
25
+ }
26
+ catch (err) {
27
+ for (const change of versionChanges) {
28
+ skipped.push({
29
+ groupId: change.groupId,
30
+ artifactId: change.artifactId,
31
+ newVersion: change.newVersion,
32
+ reason: `Failed to parse TOML: ${err.message}`
33
+ });
34
+ }
35
+ return { content: tomlContent, applied, skipped };
36
+ }
37
+ const libraries = parsed.libraries || {};
38
+ const versions = parsed.versions || {};
39
+ const libraryIndex = buildLibraryIndex(libraries);
40
+ let updatedContent = tomlContent;
41
+ for (const change of versionChanges) {
42
+ const moduleKey = `${change.groupId}:${change.artifactId}`;
43
+ const alias = libraryIndex.get(moduleKey);
44
+ if (!alias) {
45
+ skipped.push({
46
+ groupId: change.groupId,
47
+ artifactId: change.artifactId,
48
+ newVersion: change.newVersion,
49
+ reason: `No library entry found for module ${moduleKey}`
50
+ });
51
+ continue;
52
+ }
53
+ const libEntry = libraries[alias];
54
+ const versionRef = getVersionRef(libEntry);
55
+ if (versionRef) {
56
+ const oldVersion = versions[versionRef];
57
+ if (oldVersion === undefined) {
58
+ skipped.push({
59
+ groupId: change.groupId,
60
+ artifactId: change.artifactId,
61
+ newVersion: change.newVersion,
62
+ reason: `Version ref "${versionRef}" not found in [versions] section`
63
+ });
64
+ continue;
65
+ }
66
+ if (oldVersion === change.newVersion) {
67
+ skipped.push({
68
+ groupId: change.groupId,
69
+ artifactId: change.artifactId,
70
+ newVersion: change.newVersion,
71
+ reason: `Version already at ${change.newVersion}`
72
+ });
73
+ continue;
74
+ }
75
+ updatedContent = replaceVersionInSection(updatedContent, versionRef, oldVersion, change.newVersion);
76
+ applied.push({
77
+ groupId: change.groupId,
78
+ artifactId: change.artifactId,
79
+ newVersion: change.newVersion,
80
+ oldVersion
81
+ });
82
+ }
83
+ else {
84
+ const inlineVersion = getInlineVersion(libEntry);
85
+ if (inlineVersion === undefined) {
86
+ skipped.push({
87
+ groupId: change.groupId,
88
+ artifactId: change.artifactId,
89
+ newVersion: change.newVersion,
90
+ reason: `No version.ref or inline version found for library "${alias}"`
91
+ });
92
+ continue;
93
+ }
94
+ if (inlineVersion === change.newVersion) {
95
+ skipped.push({
96
+ groupId: change.groupId,
97
+ artifactId: change.artifactId,
98
+ newVersion: change.newVersion,
99
+ reason: `Version already at ${change.newVersion}`
100
+ });
101
+ continue;
102
+ }
103
+ const beforeInline = updatedContent;
104
+ updatedContent = replaceInlineVersion(updatedContent, alias, inlineVersion, change.newVersion);
105
+ if (updatedContent !== beforeInline) {
106
+ applied.push({
107
+ groupId: change.groupId,
108
+ artifactId: change.artifactId,
109
+ newVersion: change.newVersion,
110
+ oldVersion: inlineVersion
111
+ });
112
+ }
113
+ else {
114
+ skipped.push({
115
+ groupId: change.groupId,
116
+ artifactId: change.artifactId,
117
+ newVersion: change.newVersion,
118
+ reason: `Inline version replacement did not match for library "${alias}"`
119
+ });
120
+ }
121
+ }
122
+ }
123
+ return { content: updatedContent, applied, skipped };
124
+ }
125
+ /**
126
+ * Builds a map from "groupId:artifactId" to the TOML library alias.
127
+ * @param {object} libraries - parsed [libraries] section
128
+ * @returns {Map<string, string>}
129
+ */
130
+ function buildLibraryIndex(libraries) {
131
+ const index = new Map();
132
+ for (const [alias, entry] of Object.entries(libraries)) {
133
+ const module = getModule(entry);
134
+ if (module) {
135
+ index.set(module, alias);
136
+ }
137
+ }
138
+ return index;
139
+ }
140
+ /**
141
+ * Extracts the module identifier from a library entry.
142
+ * Handles both string shorthand ("group:artifact:version") and object notation
143
+ * ({ module = "group:artifact" } or { group = "...", name = "..." }).
144
+ * @param {string|object} entry
145
+ * @returns {string|undefined} "groupId:artifactId"
146
+ */
147
+ function getModule(entry) {
148
+ if (typeof entry === 'string') {
149
+ const parts = entry.split(':');
150
+ if (parts.length >= 2) {
151
+ return `${parts[0]}:${parts[1]}`;
152
+ }
153
+ return undefined;
154
+ }
155
+ if (entry.module) {
156
+ const parts = entry.module.split(':');
157
+ if (parts.length >= 2) {
158
+ return `${parts[0]}:${parts[1]}`;
159
+ }
160
+ return entry.module;
161
+ }
162
+ if (entry.group && entry.name) {
163
+ return `${entry.group}:${entry.name}`;
164
+ }
165
+ return undefined;
166
+ }
167
+ /**
168
+ * Extracts the version.ref from a library entry, if present.
169
+ * @param {string|object} entry
170
+ * @returns {string|undefined}
171
+ */
172
+ function getVersionRef(entry) {
173
+ if (typeof entry === 'object' && entry.version) {
174
+ if (typeof entry.version === 'object' && entry.version.ref) {
175
+ return entry.version.ref;
176
+ }
177
+ }
178
+ return undefined;
179
+ }
180
+ /**
181
+ * Extracts an inline version string from a library entry.
182
+ * Handles { version = "1.2.3" } and string shorthand "group:artifact:version".
183
+ * @param {string|object} entry
184
+ * @returns {string|undefined}
185
+ */
186
+ function getInlineVersion(entry) {
187
+ if (typeof entry === 'string') {
188
+ const parts = entry.split(':');
189
+ if (parts.length >= 3) {
190
+ return parts[2];
191
+ }
192
+ return undefined;
193
+ }
194
+ if (typeof entry === 'object' && entry.version) {
195
+ if (typeof entry.version === 'string') {
196
+ return entry.version;
197
+ }
198
+ }
199
+ return undefined;
200
+ }
201
+ /**
202
+ * Replaces a version value using position-based string replacement.
203
+ * Targets lines matching: key = "oldVersion"
204
+ * @param {string} content - raw TOML content
205
+ * @param {string} key - version alias key
206
+ * @param {string} oldVersion - current version string
207
+ * @param {string} newVersion - replacement version string
208
+ * @returns {string} updated content
209
+ */
210
+ function replaceVersionInSection(content, key, oldVersion, newVersion) {
211
+ const escapedKey = escapeRegExp(key);
212
+ const escapedOld = escapeRegExp(oldVersion);
213
+ const pattern = new RegExp(`^(\\s*${escapedKey}\\s*=\\s*")${escapedOld}("\\s*)$`, 'm');
214
+ return content.replace(pattern, (_, p1, p2) => `${p1}${newVersion}${p2}`);
215
+ }
216
+ /**
217
+ * Replaces an inline version in a library entry.
218
+ * Targets patterns like: version = "oldVersion" or version ="oldVersion"
219
+ * on the line containing the library alias.
220
+ * @param {string} content - raw TOML content
221
+ * @param {string} alias - library alias
222
+ * @param {string} oldVersion - current version string
223
+ * @param {string} newVersion - replacement version string
224
+ * @returns {string} updated content
225
+ */
226
+ function replaceInlineVersion(content, alias, oldVersion, newVersion) {
227
+ const escapedAlias = escapeRegExp(alias);
228
+ const escapedOld = escapeRegExp(oldVersion);
229
+ const pattern = new RegExp(`^(\\s*${escapedAlias}\\s*=\\s*\\{[^}]*version\\s*=\\s*")${escapedOld}("[^}]*\\}\\s*)$`, 'm');
230
+ const result = content.replace(pattern, (_, p1, p2) => `${p1}${newVersion}${p2}`);
231
+ if (result !== content) {
232
+ return result;
233
+ }
234
+ const stringPattern = new RegExp(`^(\\s*${escapedAlias}\\s*=\\s*"[^:]+:[^:]+:)${escapedOld}("\\s*)$`, 'm');
235
+ return content.replace(stringPattern, (_, p1, p2) => `${p1}${newVersion}${p2}`);
236
+ }
237
+ /**
238
+ * Escapes special regex characters in a string.
239
+ * @param {string} str
240
+ * @returns {string}
241
+ */
242
+ function escapeRegExp(str) {
243
+ return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
244
+ }
@@ -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}`;