@trustify-da/trustify-da-javascript-client 0.3.0-ea.f2c4df7 → 0.3.0-ea.f501753
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.
- package/README.md +151 -13
- package/dist/package.json +11 -3
- package/dist/src/analysis.d.ts +16 -0
- package/dist/src/analysis.js +53 -4
- package/dist/src/batch_opts.d.ts +24 -0
- package/dist/src/batch_opts.js +35 -0
- package/dist/src/cli.js +171 -4
- package/dist/src/cyclone_dx_sbom.d.ts +14 -1
- package/dist/src/cyclone_dx_sbom.js +34 -6
- package/dist/src/index.d.ts +132 -1
- package/dist/src/index.js +340 -4
- package/dist/src/license/licenses_api.js +9 -2
- package/dist/src/license/project_license.d.ts +0 -8
- package/dist/src/license/project_license.js +0 -11
- package/dist/src/oci_image/utils.js +11 -2
- package/dist/src/provider.d.ts +6 -3
- package/dist/src/provider.js +14 -5
- package/dist/src/providers/base_java.d.ts +0 -9
- package/dist/src/providers/base_java.js +2 -38
- package/dist/src/providers/base_javascript.d.ts +19 -3
- package/dist/src/providers/base_javascript.js +99 -18
- package/dist/src/providers/base_pyproject.d.ts +153 -0
- package/dist/src/providers/base_pyproject.js +315 -0
- package/dist/src/providers/golang_gomodules.d.ts +21 -12
- package/dist/src/providers/golang_gomodules.js +164 -118
- package/dist/src/providers/gomod_parser.d.ts +4 -0
- package/dist/src/providers/gomod_parser.js +16 -0
- package/dist/src/providers/java_gradle.d.ts +19 -0
- package/dist/src/providers/java_gradle.js +114 -0
- package/dist/src/providers/java_maven.d.ts +8 -0
- package/dist/src/providers/java_maven.js +93 -1
- package/dist/src/providers/javascript_npm.d.ts +1 -0
- package/dist/src/providers/javascript_npm.js +21 -0
- package/dist/src/providers/javascript_pnpm.d.ts +1 -1
- package/dist/src/providers/javascript_pnpm.js +8 -4
- package/dist/src/providers/manifest.d.ts +2 -0
- package/dist/src/providers/manifest.js +22 -4
- package/dist/src/providers/marker_evaluator.d.ts +14 -0
- package/dist/src/providers/marker_evaluator.js +191 -0
- package/dist/src/providers/processors/yarn_berry_processor.js +88 -5
- package/dist/src/providers/python_controller.d.ts +5 -1
- package/dist/src/providers/python_controller.js +8 -4
- package/dist/src/providers/python_pip.d.ts +4 -0
- package/dist/src/providers/python_pip.js +5 -5
- package/dist/src/providers/python_pip_pyproject.d.ts +61 -0
- package/dist/src/providers/python_pip_pyproject.js +144 -0
- package/dist/src/providers/python_poetry.d.ts +75 -0
- package/dist/src/providers/python_poetry.js +238 -0
- package/dist/src/providers/python_uv.d.ts +42 -0
- package/dist/src/providers/python_uv.js +160 -0
- package/dist/src/providers/requirements_parser.js +4 -3
- package/dist/src/providers/rust_cargo.d.ts +52 -0
- package/dist/src/providers/rust_cargo.js +614 -0
- package/dist/src/providers/tree-sitter-gomod.wasm +0 -0
- package/dist/src/providers/tree-sitter-requirements.wasm +0 -0
- package/dist/src/sbom.d.ts +14 -1
- package/dist/src/sbom.js +13 -2
- package/dist/src/tools.d.ts +26 -0
- package/dist/src/tools.js +58 -0
- package/dist/src/workspace.d.ts +61 -0
- package/dist/src/workspace.js +256 -0
- package/package.json +12 -4
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import { EOL } from "os";
|
|
4
3
|
import { PackageURL } from 'packageurl-js';
|
|
5
4
|
import { readLicenseFile } from '../license/license_utils.js';
|
|
6
5
|
import Sbom from '../sbom.js';
|
|
7
6
|
import { getCustom, getCustomPath, invokeCommand } from "../tools.js";
|
|
7
|
+
import { filterManifestPathsByDiscoveryIgnore, resolveWorkspaceDiscoveryIgnore } from '../workspace.js';
|
|
8
|
+
import { getParser, getRequireQuery } from './gomod_parser.js';
|
|
8
9
|
export default { isSupported, validateLockFile, provideComponent, provideStack, readLicenseFromManifest };
|
|
9
10
|
/** @typedef {import('../provider').Provider} */
|
|
10
11
|
/** @typedef {import('../provider').Provided} Provided */
|
|
@@ -17,46 +18,46 @@ export default { isSupported, validateLockFile, provideComponent, provideStack,
|
|
|
17
18
|
const ecosystem = 'golang';
|
|
18
19
|
const defaultMainModuleVersion = "v0.0.0";
|
|
19
20
|
/**
|
|
20
|
-
* @param {string} manifestName
|
|
21
|
-
* @returns {boolean}
|
|
21
|
+
* @param {string} manifestName the subject manifest name-type
|
|
22
|
+
* @returns {boolean} return true if `pom.xml` is the manifest name-type
|
|
22
23
|
*/
|
|
23
24
|
function isSupported(manifestName) {
|
|
24
25
|
return 'go.mod' === manifestName;
|
|
25
26
|
}
|
|
26
27
|
/**
|
|
27
28
|
* Go modules have no standard license field in go.mod
|
|
28
|
-
* @param {string} manifestPath
|
|
29
|
+
* @param {string} manifestPath path to go.mod
|
|
29
30
|
* @returns {string|null}
|
|
30
31
|
*/
|
|
31
32
|
// eslint-disable-next-line no-unused-vars
|
|
32
33
|
function readLicenseFromManifest(manifestPath) { return readLicenseFile(manifestPath); }
|
|
33
34
|
/**
|
|
34
|
-
* @param {string} manifestDir
|
|
35
|
+
* @param {string} manifestDir the directory where the manifest lies
|
|
35
36
|
*/
|
|
36
37
|
function validateLockFile() { return true; }
|
|
37
38
|
/**
|
|
38
39
|
* Provide content and content type for maven-maven stack analysis.
|
|
39
|
-
* @param {string} manifest
|
|
40
|
-
* @param {{}} [opts={}]
|
|
41
|
-
* @returns {Provided}
|
|
40
|
+
* @param {string} manifest the manifest path or name
|
|
41
|
+
* @param {{}} [opts={}] optional various options to pass along the application
|
|
42
|
+
* @returns {Promise<Provided>}
|
|
42
43
|
*/
|
|
43
|
-
function provideStack(manifest, opts = {}) {
|
|
44
|
+
async function provideStack(manifest, opts = {}) {
|
|
44
45
|
return {
|
|
45
46
|
ecosystem,
|
|
46
|
-
content: getSBOM(manifest, opts, true),
|
|
47
|
+
content: await getSBOM(manifest, opts, true),
|
|
47
48
|
contentType: 'application/vnd.cyclonedx+json'
|
|
48
49
|
};
|
|
49
50
|
}
|
|
50
51
|
/**
|
|
51
52
|
* Provide content and content type for maven-maven component analysis.
|
|
52
|
-
* @param {string} manifest
|
|
53
|
-
* @param {{}} [opts={}]
|
|
54
|
-
* @returns {Provided}
|
|
53
|
+
* @param {string} manifest path to go.mod for component report
|
|
54
|
+
* @param {{}} [opts={}] optional various options to pass along the application
|
|
55
|
+
* @returns {Promise<Provided>}
|
|
55
56
|
*/
|
|
56
|
-
function provideComponent(manifest, opts = {}) {
|
|
57
|
+
async function provideComponent(manifest, opts = {}) {
|
|
57
58
|
return {
|
|
58
59
|
ecosystem,
|
|
59
|
-
content: getSBOM(manifest, opts, false),
|
|
60
|
+
content: await getSBOM(manifest, opts, false),
|
|
60
61
|
contentType: 'application/vnd.cyclonedx+json'
|
|
61
62
|
};
|
|
62
63
|
}
|
|
@@ -77,50 +78,52 @@ function getChildVertexFromEdge(edge) {
|
|
|
77
78
|
return edge.split(" ")[1];
|
|
78
79
|
}
|
|
79
80
|
/**
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
81
|
+
* Check whether a require_spec has a valid exhortignore marker.
|
|
82
|
+
* For direct dependencies: `//exhortignore` or `// exhortignore`
|
|
83
|
+
* For indirect dependencies: `// indirect; exhortignore` (semicolon-separated)
|
|
84
|
+
* @param {import('web-tree-sitter').SyntaxNode} specNode
|
|
85
|
+
* @return {boolean}
|
|
83
86
|
*/
|
|
84
|
-
function
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
87
|
+
function hasExhortIgnore(specNode) {
|
|
88
|
+
// Ideally this would be the following tree-sitter query instead, but for some
|
|
89
|
+
// reason it throws an error here but not in the playground.
|
|
90
|
+
// (require_spec) ((module_path) @path (version) (comment) @comment (#match? @comment "^//.*exhortignore"))
|
|
91
|
+
// QueryError: Bad pattern structure at offset 53: '(comment) @comment (#match? @comment "^//.*exhortignore")) @spec'...
|
|
92
|
+
let comments = specNode.children.filter(c => c.type === 'comment');
|
|
93
|
+
for (let comment of comments) {
|
|
94
|
+
let text = comment.text;
|
|
95
|
+
if (/^\/\/\s*indirect;\s*exhortignore/.test(text)) {
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
if (/^\/\/\s*exhortignore/.test(text)) {
|
|
99
|
+
return true;
|
|
96
100
|
}
|
|
97
101
|
}
|
|
98
|
-
return
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* extract package name from go.mod line that contains exhortignore comment.
|
|
102
|
-
* @param line a row contains exhortignore as part of a comment
|
|
103
|
-
* @return {string} the full package name + group/namespace + version
|
|
104
|
-
* @private
|
|
105
|
-
*/
|
|
106
|
-
function extractPackageName(line) {
|
|
107
|
-
let trimmedRow = line.trim();
|
|
108
|
-
let firstRemarkNotationOccurrence = trimmedRow.indexOf("//");
|
|
109
|
-
return trimmedRow.substring(0, firstRemarkNotationOccurrence).trim();
|
|
102
|
+
return false;
|
|
110
103
|
}
|
|
111
104
|
/**
|
|
112
105
|
*
|
|
113
|
-
* @param {string
|
|
114
|
-
* @
|
|
106
|
+
* @param {string} manifestContent go.mod file contents
|
|
107
|
+
* @param {import('web-tree-sitter').Parser} parser
|
|
108
|
+
* @param {import('web-tree-sitter').Query} requireQuery
|
|
109
|
+
* @return {PackageURL[]} list of ignored dependencies
|
|
115
110
|
*/
|
|
116
|
-
function getIgnoredDeps(
|
|
117
|
-
let
|
|
118
|
-
|
|
119
|
-
|
|
111
|
+
function getIgnoredDeps(manifestContent, parser, requireQuery) {
|
|
112
|
+
let tree = parser.parse(manifestContent);
|
|
113
|
+
return requireQuery.matches(tree.rootNode)
|
|
114
|
+
.filter(match => {
|
|
115
|
+
let specNode = match.captures.find(c => c.name === 'spec').node;
|
|
116
|
+
return hasExhortIgnore(specNode);
|
|
117
|
+
})
|
|
118
|
+
.map(match => {
|
|
119
|
+
let name = match.captures.find(c => c.name === 'name').node.text;
|
|
120
|
+
let version = match.captures.find(c => c.name === 'version').node.text;
|
|
121
|
+
return toPurl(`${name} ${version}`, /[ ]{1,3}/);
|
|
122
|
+
});
|
|
120
123
|
}
|
|
121
124
|
/**
|
|
122
125
|
*
|
|
123
|
-
* @param {[
|
|
126
|
+
* @param {PackageURL[]} allIgnoredDeps list of purls of all dependencies that should be ignored
|
|
124
127
|
* @param {PackageURL} purl object to be checked if needed to be ignored
|
|
125
128
|
* @return {boolean}
|
|
126
129
|
*/
|
|
@@ -139,59 +142,29 @@ function enforceRemovingIgnoredDepsInCaseOfAutomaticVersionUpdate(ignoredDeps, s
|
|
|
139
142
|
}
|
|
140
143
|
/**
|
|
141
144
|
*
|
|
142
|
-
* @param {
|
|
143
|
-
* @param {
|
|
144
|
-
* @
|
|
145
|
+
* @param {string} manifestContent go.mod file contents
|
|
146
|
+
* @param {import('web-tree-sitter').Parser} parser
|
|
147
|
+
* @param {import('web-tree-sitter').Query} requireQuery
|
|
148
|
+
* @return {string[]} all dependencies from go.mod file as "name version" strings
|
|
145
149
|
*/
|
|
146
|
-
function collectAllDepsFromManifest(
|
|
147
|
-
let
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
while (requirePositionObject.index > -1) {
|
|
154
|
-
let depsInsideRequirementsBlock = currentSegmentOfGoMod.substring(requirePositionObject.index + requirePositionObject.startingOffeset).trim();
|
|
155
|
-
let endOfBlockIndex = depsInsideRequirementsBlock.indexOf(")");
|
|
156
|
-
let currentIndex = 0;
|
|
157
|
-
while (currentIndex < endOfBlockIndex) {
|
|
158
|
-
let endOfLinePosition = depsInsideRequirementsBlock.indexOf(EOL, currentIndex);
|
|
159
|
-
let dependency = depsInsideRequirementsBlock.substring(currentIndex, endOfLinePosition);
|
|
160
|
-
result.push(dependency.trim());
|
|
161
|
-
currentIndex = endOfLinePosition + 1;
|
|
162
|
-
}
|
|
163
|
-
currentSegmentOfGoMod = currentSegmentOfGoMod.substring(endOfBlockIndex + 1).trim();
|
|
164
|
-
requirePositionObject = decideRequireBlockIndex(currentSegmentOfGoMod);
|
|
165
|
-
}
|
|
166
|
-
function decideRequireBlockIndex(goMod) {
|
|
167
|
-
let object = {};
|
|
168
|
-
let index = goMod.indexOf("require(");
|
|
169
|
-
object.startingOffeset = "require(".length;
|
|
170
|
-
if (index === -1) {
|
|
171
|
-
index = goMod.indexOf("require (");
|
|
172
|
-
object.startingOffeset = "require (".length;
|
|
173
|
-
if (index === -1) {
|
|
174
|
-
index = goMod.indexOf("require (");
|
|
175
|
-
object.startingOffeset = "require (".length;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
object.index = index;
|
|
179
|
-
return object;
|
|
180
|
-
}
|
|
181
|
-
return result;
|
|
150
|
+
function collectAllDepsFromManifest(manifestContent, parser, requireQuery) {
|
|
151
|
+
let tree = parser.parse(manifestContent);
|
|
152
|
+
return requireQuery.matches(tree.rootNode).map(match => {
|
|
153
|
+
let name = match.captures.find(c => c.name === 'name').node.text;
|
|
154
|
+
let version = match.captures.find(c => c.name === 'version').node.text;
|
|
155
|
+
return `${name} ${version}`;
|
|
156
|
+
});
|
|
182
157
|
}
|
|
183
158
|
/**
|
|
184
159
|
*
|
|
185
160
|
* @param {string} rootElementName the rootElementName element of go mod graph, to compare only direct deps from go mod graph against go.mod manifest
|
|
186
|
-
* @param{[
|
|
187
|
-
* @param {string
|
|
161
|
+
* @param {string[]} goModGraphOutputRows the goModGraphOutputRows from go mod graph' output
|
|
162
|
+
* @param {string} manifestContent go.mod file contents
|
|
188
163
|
* @private
|
|
189
164
|
*/
|
|
190
|
-
function performManifestVersionsCheck(rootElementName, goModGraphOutputRows,
|
|
191
|
-
let goMod = fs.readFileSync(manifest).toString().trim();
|
|
192
|
-
let lines = goMod.split(getLineSeparatorGolang());
|
|
165
|
+
function performManifestVersionsCheck(rootElementName, goModGraphOutputRows, manifestContent, parser, requireQuery) {
|
|
193
166
|
let comparisonLines = goModGraphOutputRows.filter((line) => line.startsWith(rootElementName)).map((line) => getChildVertexFromEdge(line));
|
|
194
|
-
let manifestDeps = collectAllDepsFromManifest(
|
|
167
|
+
let manifestDeps = collectAllDepsFromManifest(manifestContent, parser, requireQuery);
|
|
195
168
|
try {
|
|
196
169
|
comparisonLines.forEach((dependency) => {
|
|
197
170
|
let parts = dependency.split("@");
|
|
@@ -203,7 +176,7 @@ function performManifestVersionsCheck(rootElementName, goModGraphOutputRows, man
|
|
|
203
176
|
let currentVersion = components[1];
|
|
204
177
|
if (currentDepName === depName) {
|
|
205
178
|
if (currentVersion !== version) {
|
|
206
|
-
throw new Error(`
|
|
179
|
+
throw new Error(`version mismatch for dependency "${depName}", manifest version=${currentVersion}, installed version=${version}, if you want to allow version mismatch for analysis between installed and requested packages, set environment variable/setting MATCH_MANIFEST_VERSIONS=false`);
|
|
207
180
|
}
|
|
208
181
|
}
|
|
209
182
|
});
|
|
@@ -219,10 +192,10 @@ function performManifestVersionsCheck(rootElementName, goModGraphOutputRows, man
|
|
|
219
192
|
* @param {string} manifest - path for go.mod
|
|
220
193
|
* @param {{}} [opts={}] - optional various options to pass along the application
|
|
221
194
|
* @param {boolean} includeTransitive - whether the sbom should contain transitive dependencies of the main module or not.
|
|
222
|
-
* @returns {string} the SBOM json content
|
|
195
|
+
* @returns {Promise<string>} the SBOM json content
|
|
223
196
|
* @private
|
|
224
197
|
*/
|
|
225
|
-
function getSBOM(manifest, opts = {}, includeTransitive) {
|
|
198
|
+
async function getSBOM(manifest, opts = {}, includeTransitive) {
|
|
226
199
|
// get custom goBin path
|
|
227
200
|
let goBin = getCustomPath('go', opts);
|
|
228
201
|
// verify goBin is accessible
|
|
@@ -248,14 +221,25 @@ function getSBOM(manifest, opts = {}, includeTransitive) {
|
|
|
248
221
|
catch (error) {
|
|
249
222
|
throw new Error('failed to determine root module name', { cause: error });
|
|
250
223
|
}
|
|
251
|
-
let
|
|
224
|
+
let manifestContent = fs.readFileSync(manifest).toString();
|
|
225
|
+
let [parser, requireQuery] = await Promise.all([getParser(), getRequireQuery()]);
|
|
226
|
+
let ignoredDeps = getIgnoredDeps(manifestContent, parser, requireQuery);
|
|
252
227
|
let allIgnoredDeps = ignoredDeps.map((dep) => dep.toString());
|
|
253
228
|
let sbom = new Sbom();
|
|
254
229
|
let rows = goGraphOutput.split(getLineSeparatorGolang()).filter(line => !line.includes(' go@'));
|
|
255
|
-
let root =
|
|
230
|
+
let root = goModEditOutput['Module']['Path'];
|
|
231
|
+
// Build set of direct dependency paths from go mod edit -json
|
|
232
|
+
let directDepPaths = new Set();
|
|
233
|
+
if (goModEditOutput['Require']) {
|
|
234
|
+
goModEditOutput['Require'].forEach(req => {
|
|
235
|
+
if (!req['Indirect']) {
|
|
236
|
+
directDepPaths.add(req['Path']);
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
}
|
|
256
240
|
let matchManifestVersions = getCustom("MATCH_MANIFEST_VERSIONS", "false", opts);
|
|
257
241
|
if (matchManifestVersions === "true") {
|
|
258
|
-
performManifestVersionsCheck(root, rows,
|
|
242
|
+
performManifestVersionsCheck(root, rows, manifestContent, parser, requireQuery);
|
|
259
243
|
}
|
|
260
244
|
const mainModule = toPurl(root, "@");
|
|
261
245
|
const license = readLicenseFromManifest(manifest);
|
|
@@ -273,7 +257,11 @@ function getSBOM(manifest, opts = {}, includeTransitive) {
|
|
|
273
257
|
currentParent = getParentVertexFromEdge(row);
|
|
274
258
|
source = toPurl(currentParent, "@");
|
|
275
259
|
}
|
|
276
|
-
let
|
|
260
|
+
let child = getChildVertexFromEdge(row);
|
|
261
|
+
let target = toPurl(child, "@");
|
|
262
|
+
if (getParentVertexFromEdge(row) === root && !directDepPaths.has(getPackageName(child))) {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
277
265
|
sbom.addDependency(source, target);
|
|
278
266
|
});
|
|
279
267
|
// at the end, filter out all ignored dependencies including versions.
|
|
@@ -283,10 +271,12 @@ function getSBOM(manifest, opts = {}, includeTransitive) {
|
|
|
283
271
|
else {
|
|
284
272
|
let directDependencies = rows.filter(row => row.startsWith(root));
|
|
285
273
|
directDependencies.forEach(pair => {
|
|
286
|
-
let
|
|
287
|
-
let
|
|
288
|
-
if (dependencyNotIgnored(ignoredDeps,
|
|
289
|
-
|
|
274
|
+
let child = getChildVertexFromEdge(pair);
|
|
275
|
+
let target = toPurl(child, "@");
|
|
276
|
+
if (dependencyNotIgnored(ignoredDeps, target)) {
|
|
277
|
+
if (directDepPaths.has(getPackageName(child))) {
|
|
278
|
+
sbom.addDependency(mainModule, target);
|
|
279
|
+
}
|
|
290
280
|
}
|
|
291
281
|
});
|
|
292
282
|
enforceRemovingIgnoredDepsInCaseOfAutomaticVersionUpdate(ignoredDeps, sbom);
|
|
@@ -296,7 +286,7 @@ function getSBOM(manifest, opts = {}, includeTransitive) {
|
|
|
296
286
|
/**
|
|
297
287
|
* Utility function for creating Purl String
|
|
298
288
|
|
|
299
|
-
* @param {string
|
|
289
|
+
* @param {string} dependency the name of the artifact, can include a namespace(group) or not - namespace/artifactName.
|
|
300
290
|
* @param {RegExp} delimiter delimiter between name of dependency and version
|
|
301
291
|
* @private
|
|
302
292
|
* @returns {PackageURL|null} PackageUrl Object ready to be used in SBOM
|
|
@@ -321,12 +311,12 @@ function toPurl(dependency, delimiter) {
|
|
|
321
311
|
}
|
|
322
312
|
return pkg;
|
|
323
313
|
}
|
|
324
|
-
/** This function gets rows from go mod graph
|
|
314
|
+
/** This function gets rows from go mod graph, and go.mod graph, and selecting for all
|
|
325
315
|
* packages the has more than one minor the final versions as selected by golang MVS algorithm.
|
|
326
|
-
* @param {[
|
|
316
|
+
* @param {string[]} rows all the rows from go modules dependency tree
|
|
327
317
|
* @param {string} manifestPath the path of the go.mod file
|
|
328
318
|
* @param {string} path to go binary
|
|
329
|
-
* @return {[
|
|
319
|
+
* @return {string[]} rows that contains final versions.
|
|
330
320
|
*/
|
|
331
321
|
function getFinalPackagesVersionsForModule(rows, manifestPath, goBin) {
|
|
332
322
|
let manifestDir = path.dirname(manifestPath);
|
|
@@ -339,13 +329,7 @@ function getFinalPackagesVersionsForModule(rows, manifestPath, goBin) {
|
|
|
339
329
|
catch (error) {
|
|
340
330
|
throw new Error('failed to list all modules', { cause: error });
|
|
341
331
|
}
|
|
342
|
-
let finalVersionModules =
|
|
343
|
-
finalVersionsForAllModules.split(getLineSeparatorGolang()).filter(string => string.trim() !== "")
|
|
344
|
-
.filter(string => string.trim().split(" ").length === 2)
|
|
345
|
-
.forEach((dependency) => {
|
|
346
|
-
let dep = dependency.split(" ");
|
|
347
|
-
finalVersionModules[dep[0]] = dep[1];
|
|
348
|
-
});
|
|
332
|
+
let finalVersionModules = parseModuleVersions(finalVersionsForAllModules);
|
|
349
333
|
let finalVersionModulesArray = new Array();
|
|
350
334
|
rows.filter(string => string.trim() !== "").forEach(module => {
|
|
351
335
|
let child = getChildVertexFromEdge(module);
|
|
@@ -381,7 +365,7 @@ function getFinalPackagesVersionsForModule(rows, manifestPath, goBin) {
|
|
|
381
365
|
/**
|
|
382
366
|
*
|
|
383
367
|
* @param {string} fullPackage - full package with its name and version
|
|
384
|
-
* @return
|
|
368
|
+
* @return {string} package name only
|
|
385
369
|
* @private
|
|
386
370
|
*/
|
|
387
371
|
function getPackageName(fullPackage) {
|
|
@@ -399,14 +383,76 @@ function isSpecialGoModule(moduleName) {
|
|
|
399
383
|
/**
|
|
400
384
|
*
|
|
401
385
|
* @param {string} fullPackage - full package with its name and version
|
|
402
|
-
* @return
|
|
386
|
+
* @return {string|undefined} package version only
|
|
403
387
|
* @private
|
|
404
388
|
*/
|
|
405
389
|
function getVersionOfPackage(fullPackage) {
|
|
406
390
|
let parts = fullPackage.split("@");
|
|
407
391
|
return parts.length > 1 ? parts[1] : undefined;
|
|
408
392
|
}
|
|
393
|
+
function parseModuleVersions(goListOutput) {
|
|
394
|
+
let modules = {};
|
|
395
|
+
goListOutput.split(getLineSeparatorGolang()).filter(string => string.trim() !== "")
|
|
396
|
+
.forEach((line) => {
|
|
397
|
+
let parts = line.trim().split(" ");
|
|
398
|
+
if (parts.length === 2) {
|
|
399
|
+
modules[parts[0]] = parts[1];
|
|
400
|
+
}
|
|
401
|
+
else if (parts.length >= 4 && parts[2] === "=>") {
|
|
402
|
+
modules[parts[0]] = parts[parts.length - 1];
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
return modules;
|
|
406
|
+
}
|
|
409
407
|
function getLineSeparatorGolang() {
|
|
410
408
|
let reg = /\n|\r\n/;
|
|
411
409
|
return reg;
|
|
412
410
|
}
|
|
411
|
+
/**
|
|
412
|
+
* Discover all go.mod manifest paths in a Go workspace.
|
|
413
|
+
* Uses `go work edit -json` to get workspace members.
|
|
414
|
+
*
|
|
415
|
+
* @param {string} workspaceRoot - Absolute or relative path to workspace root (must contain go.work)
|
|
416
|
+
* @param {import('../index.js').Options} [opts={}]
|
|
417
|
+
* @returns {Promise<string[]>} Paths to go.mod files (absolute)
|
|
418
|
+
*/
|
|
419
|
+
export async function discoverGoWorkspaceModules(workspaceRoot, opts = {}) {
|
|
420
|
+
const root = path.resolve(workspaceRoot);
|
|
421
|
+
const goWork = path.join(root, 'go.work');
|
|
422
|
+
if (!fs.existsSync(goWork)) {
|
|
423
|
+
return [];
|
|
424
|
+
}
|
|
425
|
+
const goBin = getCustomPath('go', opts);
|
|
426
|
+
let output;
|
|
427
|
+
try {
|
|
428
|
+
output = invokeCommand(goBin, ['work', 'edit', '-json', goWork], { cwd: root });
|
|
429
|
+
}
|
|
430
|
+
catch {
|
|
431
|
+
return [];
|
|
432
|
+
}
|
|
433
|
+
let workspace;
|
|
434
|
+
try {
|
|
435
|
+
workspace = JSON.parse(output.toString().trim());
|
|
436
|
+
}
|
|
437
|
+
catch {
|
|
438
|
+
return [];
|
|
439
|
+
}
|
|
440
|
+
const useEntries = workspace.Use || [];
|
|
441
|
+
if (useEntries.length === 0) {
|
|
442
|
+
return [];
|
|
443
|
+
}
|
|
444
|
+
const manifestPaths = [];
|
|
445
|
+
for (const entry of useEntries) {
|
|
446
|
+
const diskPath = entry.DiskPath;
|
|
447
|
+
if (!diskPath) {
|
|
448
|
+
continue;
|
|
449
|
+
}
|
|
450
|
+
const moduleDir = path.resolve(root, diskPath);
|
|
451
|
+
const goMod = path.join(moduleDir, 'go.mod');
|
|
452
|
+
if (fs.existsSync(goMod)) {
|
|
453
|
+
manifestPaths.push(goMod);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
const ignorePatterns = resolveWorkspaceDiscoveryIgnore(opts);
|
|
457
|
+
return filterManifestPathsByDiscoveryIgnore(manifestPaths, root, ignorePatterns);
|
|
458
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { Language, Parser, Query } from 'web-tree-sitter';
|
|
3
|
+
const wasmUrl = new URL('./tree-sitter-gomod.wasm', import.meta.url);
|
|
4
|
+
async function init() {
|
|
5
|
+
await Parser.init();
|
|
6
|
+
const wasmBytes = new Uint8Array(await readFile(wasmUrl));
|
|
7
|
+
return await Language.load(wasmBytes);
|
|
8
|
+
}
|
|
9
|
+
export async function getParser() {
|
|
10
|
+
const language = await init();
|
|
11
|
+
return new Parser().setLanguage(language);
|
|
12
|
+
}
|
|
13
|
+
export async function getRequireQuery() {
|
|
14
|
+
const language = await init();
|
|
15
|
+
return new Query(language, '(require_spec (module_path) @name (version) @version) @spec');
|
|
16
|
+
}
|
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discover all build.gradle[.kts] manifest paths in a Gradle multi-project build.
|
|
3
|
+
* Uses a custom init script to get structured project listing.
|
|
4
|
+
*
|
|
5
|
+
* @param {string} workspaceRoot - Absolute or relative path to workspace root (must contain settings.gradle[.kts])
|
|
6
|
+
* @param {import('../index.js').Options} [opts={}]
|
|
7
|
+
* @returns {Promise<string[]>} Paths to build.gradle[.kts] files (absolute)
|
|
8
|
+
*/
|
|
9
|
+
export function discoverGradleSubprojects(workspaceRoot: string, opts?: import("../index.js").Options): Promise<string[]>;
|
|
10
|
+
/**
|
|
11
|
+
* Parse the structured output from the Gradle init script.
|
|
12
|
+
*
|
|
13
|
+
* @param {string} raw - Raw stdout from gradle
|
|
14
|
+
* @returns {{ path: string, dir: string }[]}
|
|
15
|
+
*/
|
|
16
|
+
export function parseGradleInitScriptOutput(raw: string): {
|
|
17
|
+
path: string;
|
|
18
|
+
dir: string;
|
|
19
|
+
}[];
|
|
1
20
|
/**
|
|
2
21
|
* This class provides common functionality for Groovy and Kotlin DSL files.
|
|
3
22
|
*/
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
1
2
|
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
2
4
|
import path from 'node:path';
|
|
3
5
|
import { EOL } from 'os';
|
|
4
6
|
import TOML from 'fast-toml';
|
|
5
7
|
import { readLicenseFile } from '../license/license_utils.js';
|
|
6
8
|
import Sbom from '../sbom.js';
|
|
9
|
+
import { invokeCommand } from '../tools.js';
|
|
10
|
+
import { filterManifestPathsByDiscoveryIgnore, resolveWorkspaceDiscoveryIgnore } from '../workspace.js';
|
|
7
11
|
import Base_java, { ecosystem_gradle } from "./base_java.js";
|
|
8
12
|
/** @typedef {import('../provider.js').Provider} */
|
|
9
13
|
/** @typedef {import('../provider.js').Provided} Provided */
|
|
@@ -407,3 +411,113 @@ export default class Java_gradle extends Base_java {
|
|
|
407
411
|
return undefined;
|
|
408
412
|
}
|
|
409
413
|
}
|
|
414
|
+
const DEFAULT_GRADLE_DISCOVERY_IGNORE = [
|
|
415
|
+
'**/build/**',
|
|
416
|
+
'**/.gradle/**',
|
|
417
|
+
];
|
|
418
|
+
/** Gradle init script that emits structured project listing. */
|
|
419
|
+
const GRADLE_INIT_SCRIPT = `allprojects {
|
|
420
|
+
task daListProjects {
|
|
421
|
+
doLast {
|
|
422
|
+
println "::DA_PROJECT::\${project.path}::\${project.projectDir}"
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
`;
|
|
427
|
+
/**
|
|
428
|
+
* Discover all build.gradle[.kts] manifest paths in a Gradle multi-project build.
|
|
429
|
+
* Uses a custom init script to get structured project listing.
|
|
430
|
+
*
|
|
431
|
+
* @param {string} workspaceRoot - Absolute or relative path to workspace root (must contain settings.gradle[.kts])
|
|
432
|
+
* @param {import('../index.js').Options} [opts={}]
|
|
433
|
+
* @returns {Promise<string[]>} Paths to build.gradle[.kts] files (absolute)
|
|
434
|
+
*/
|
|
435
|
+
export async function discoverGradleSubprojects(workspaceRoot, opts = {}) {
|
|
436
|
+
const root = path.resolve(workspaceRoot);
|
|
437
|
+
const hasSettings = fs.existsSync(path.join(root, 'settings.gradle'))
|
|
438
|
+
|| fs.existsSync(path.join(root, 'settings.gradle.kts'));
|
|
439
|
+
if (!hasSettings) {
|
|
440
|
+
return [];
|
|
441
|
+
}
|
|
442
|
+
const manifestPaths = [];
|
|
443
|
+
const rootBuildKts = path.join(root, 'build.gradle.kts');
|
|
444
|
+
const rootBuild = path.join(root, 'build.gradle');
|
|
445
|
+
const rootManifest = fs.existsSync(rootBuildKts) ? rootBuildKts : fs.existsSync(rootBuild) ? rootBuild : null;
|
|
446
|
+
if (rootManifest) {
|
|
447
|
+
manifestPaths.push(rootManifest);
|
|
448
|
+
}
|
|
449
|
+
let gradleBin;
|
|
450
|
+
try {
|
|
451
|
+
gradleBin = new Java_gradle().selectToolBinary(rootManifest || rootBuild, opts);
|
|
452
|
+
}
|
|
453
|
+
catch {
|
|
454
|
+
const ignorePatterns = [...resolveWorkspaceDiscoveryIgnore(opts), ...DEFAULT_GRADLE_DISCOVERY_IGNORE];
|
|
455
|
+
return filterManifestPathsByDiscoveryIgnore(manifestPaths, root, ignorePatterns);
|
|
456
|
+
}
|
|
457
|
+
const initScriptPath = path.join(os.tmpdir(), `da-list-projects-${crypto.randomUUID()}.gradle`);
|
|
458
|
+
try {
|
|
459
|
+
fs.writeFileSync(initScriptPath, GRADLE_INIT_SCRIPT);
|
|
460
|
+
let output;
|
|
461
|
+
try {
|
|
462
|
+
output = invokeCommand(gradleBin, [
|
|
463
|
+
'-q', '--no-daemon',
|
|
464
|
+
'--init-script', initScriptPath,
|
|
465
|
+
'daListProjects',
|
|
466
|
+
], { cwd: root });
|
|
467
|
+
}
|
|
468
|
+
catch {
|
|
469
|
+
const ignorePatterns = [...resolveWorkspaceDiscoveryIgnore(opts), ...DEFAULT_GRADLE_DISCOVERY_IGNORE];
|
|
470
|
+
return filterManifestPathsByDiscoveryIgnore(manifestPaths, root, ignorePatterns);
|
|
471
|
+
}
|
|
472
|
+
const projects = parseGradleInitScriptOutput(output.toString());
|
|
473
|
+
for (const proj of projects) {
|
|
474
|
+
if (proj.path === ':') {
|
|
475
|
+
continue;
|
|
476
|
+
}
|
|
477
|
+
const projDir = path.resolve(proj.dir);
|
|
478
|
+
const buildKts = path.join(projDir, 'build.gradle.kts');
|
|
479
|
+
const buildGroovy = path.join(projDir, 'build.gradle');
|
|
480
|
+
if (fs.existsSync(buildKts)) {
|
|
481
|
+
manifestPaths.push(buildKts);
|
|
482
|
+
}
|
|
483
|
+
else if (fs.existsSync(buildGroovy)) {
|
|
484
|
+
manifestPaths.push(buildGroovy);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
finally {
|
|
489
|
+
try {
|
|
490
|
+
fs.unlinkSync(initScriptPath);
|
|
491
|
+
}
|
|
492
|
+
catch { /* ignore */ }
|
|
493
|
+
}
|
|
494
|
+
const ignorePatterns = [...resolveWorkspaceDiscoveryIgnore(opts), ...DEFAULT_GRADLE_DISCOVERY_IGNORE];
|
|
495
|
+
return filterManifestPathsByDiscoveryIgnore(manifestPaths, root, ignorePatterns);
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Parse the structured output from the Gradle init script.
|
|
499
|
+
*
|
|
500
|
+
* @param {string} raw - Raw stdout from gradle
|
|
501
|
+
* @returns {{ path: string, dir: string }[]}
|
|
502
|
+
*/
|
|
503
|
+
export function parseGradleInitScriptOutput(raw) {
|
|
504
|
+
const projects = [];
|
|
505
|
+
for (const rawLine of raw.split('\n')) {
|
|
506
|
+
const line = rawLine.trimEnd();
|
|
507
|
+
if (!line.startsWith('::DA_PROJECT::')) {
|
|
508
|
+
continue;
|
|
509
|
+
}
|
|
510
|
+
const prefix = '::DA_PROJECT::';
|
|
511
|
+
const remainder = line.substring(prefix.length);
|
|
512
|
+
const lastSep = remainder.lastIndexOf('::');
|
|
513
|
+
if (lastSep < 0) {
|
|
514
|
+
continue;
|
|
515
|
+
}
|
|
516
|
+
const projPath = remainder.substring(0, lastSep);
|
|
517
|
+
const dir = remainder.substring(lastSep + 2);
|
|
518
|
+
if (projPath && dir) {
|
|
519
|
+
projects.push({ path: projPath, dir });
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
return projects;
|
|
523
|
+
}
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discover all pom.xml manifest paths in a Maven multi-module project.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} workspaceRoot - Absolute or relative path to workspace root (must contain pom.xml)
|
|
5
|
+
* @param {object} [opts={}]
|
|
6
|
+
* @returns {Promise<string[]>} Paths to pom.xml files (absolute)
|
|
7
|
+
*/
|
|
8
|
+
export function discoverMavenModules(workspaceRoot: string, opts?: object): Promise<string[]>;
|
|
1
9
|
/** @typedef {import('../provider').Provider} */
|
|
2
10
|
/** @typedef {import('../provider').Provided} Provided */
|
|
3
11
|
/** @typedef {{name: string, version: string}} Package */
|