@trustify-da/trustify-da-javascript-client 0.3.0-ea.6549d2a → 0.3.0-ea.7144952
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 +107 -4
- package/dist/package.json +9 -1
- package/dist/src/analysis.d.ts +16 -0
- package/dist/src/analysis.js +50 -2
- package/dist/src/batch_opts.d.ts +24 -0
- package/dist/src/batch_opts.js +35 -0
- package/dist/src/cli.js +121 -3
- package/dist/src/cyclone_dx_sbom.js +2 -1
- package/dist/src/index.d.ts +63 -2
- package/dist/src/index.js +266 -5
- package/dist/src/license/index.d.ts +2 -2
- package/dist/src/license/index.js +4 -4
- package/dist/src/license/license_utils.d.ts +40 -0
- package/dist/src/license/license_utils.js +134 -0
- package/dist/src/license/licenses_api.js +9 -2
- package/dist/src/license/project_license.d.ts +1 -6
- package/dist/src/license/project_license.js +4 -81
- package/dist/src/provider.d.ts +6 -3
- package/dist/src/provider.js +8 -5
- package/dist/src/providers/base_javascript.d.ts +9 -3
- package/dist/src/providers/base_javascript.js +25 -15
- package/dist/src/providers/golang_gomodules.js +2 -1
- package/dist/src/providers/java_gradle.js +2 -1
- package/dist/src/providers/java_maven.d.ts +1 -1
- package/dist/src/providers/java_maven.js +10 -9
- package/dist/src/providers/javascript_pnpm.d.ts +1 -1
- package/dist/src/providers/javascript_pnpm.js +2 -2
- package/dist/src/providers/python_pip.js +2 -1
- 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-requirements.wasm +0 -0
- package/dist/src/workspace.d.ts +61 -0
- package/dist/src/workspace.js +256 -0
- package/package.json +10 -2
- package/dist/src/license/compatibility.d.ts +0 -18
- package/dist/src/license/compatibility.js +0 -45
|
@@ -10,12 +10,6 @@ export function getProjectLicense(manifestPath: string): {
|
|
|
10
10
|
fromFile: string | null;
|
|
11
11
|
mismatch: boolean;
|
|
12
12
|
};
|
|
13
|
-
/**
|
|
14
|
-
* Find LICENSE file path in the same directory as the manifest.
|
|
15
|
-
* @param {string} manifestPath
|
|
16
|
-
* @returns {string|null} - path to LICENSE file or null if not found
|
|
17
|
-
*/
|
|
18
|
-
export function findLicenseFilePath(manifestPath: string): string | null;
|
|
19
13
|
/**
|
|
20
14
|
* Call backend /licenses/identify endpoint to identify license from file.
|
|
21
15
|
* @param {string} licenseFilePath - path to LICENSE file
|
|
@@ -23,3 +17,4 @@ export function findLicenseFilePath(manifestPath: string): string | null;
|
|
|
23
17
|
* @returns {Promise<string|null>} - SPDX identifier or null
|
|
24
18
|
*/
|
|
25
19
|
export function identifyLicense(licenseFilePath: string, opts?: {}): Promise<string | null>;
|
|
20
|
+
export { findLicenseFilePath, readLicenseFile } from "./license_utils.js";
|
|
@@ -7,7 +7,7 @@ import path from 'node:path';
|
|
|
7
7
|
import { selectTrustifyDABackend } from '../index.js';
|
|
8
8
|
import { matchForLicense, availableProviders } from '../provider.js';
|
|
9
9
|
import { addProxyAgent, getTokenHeaders } from '../tools.js';
|
|
10
|
-
|
|
10
|
+
import { normalizeSpdx, readLicenseFile } from './license_utils.js';
|
|
11
11
|
/**
|
|
12
12
|
* Resolve project license from manifest and from LICENSE / LICENSE.md in manifest dir or git root.
|
|
13
13
|
* Uses local pattern matching for LICENSE file identification (synchronous).
|
|
@@ -19,7 +19,7 @@ export function getProjectLicense(manifestPath) {
|
|
|
19
19
|
const resolved = path.resolve(manifestPath);
|
|
20
20
|
const provider = matchForLicense(resolved, availableProviders);
|
|
21
21
|
const fromManifest = provider.readLicenseFromManifest(resolved);
|
|
22
|
-
const fromFile =
|
|
22
|
+
const fromFile = readLicenseFile(resolved);
|
|
23
23
|
const mismatch = Boolean(fromManifest && fromFile && normalizeSpdx(fromManifest) !== normalizeSpdx(fromFile));
|
|
24
24
|
return {
|
|
25
25
|
fromManifest: fromManifest || null,
|
|
@@ -27,26 +27,7 @@ export function getProjectLicense(manifestPath) {
|
|
|
27
27
|
mismatch
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
* Find LICENSE file path in the same directory as the manifest.
|
|
32
|
-
* @param {string} manifestPath
|
|
33
|
-
* @returns {string|null} - path to LICENSE file or null if not found
|
|
34
|
-
*/
|
|
35
|
-
export function findLicenseFilePath(manifestPath) {
|
|
36
|
-
const manifestDir = path.dirname(path.resolve(manifestPath));
|
|
37
|
-
for (const name of LICENSE_FILES) {
|
|
38
|
-
const filePath = path.join(manifestDir, name);
|
|
39
|
-
try {
|
|
40
|
-
if (fs.statSync(filePath).isFile()) {
|
|
41
|
-
return filePath;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
catch {
|
|
45
|
-
// skip
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
30
|
+
export { findLicenseFilePath, readLicenseFile } from './license_utils.js';
|
|
50
31
|
/**
|
|
51
32
|
* Call backend /licenses/identify endpoint to identify license from file.
|
|
52
33
|
* @param {string} licenseFilePath - path to LICENSE file
|
|
@@ -57,7 +38,7 @@ export async function identifyLicense(licenseFilePath, opts = {}) {
|
|
|
57
38
|
try {
|
|
58
39
|
const fileContent = fs.readFileSync(licenseFilePath);
|
|
59
40
|
const backendUrl = selectTrustifyDABackend(opts);
|
|
60
|
-
const url = new URL(`${backendUrl}/licenses/identify`);
|
|
41
|
+
const url = new URL(`${backendUrl}/api/v5/licenses/identify`);
|
|
61
42
|
const tokenHeaders = getTokenHeaders(opts);
|
|
62
43
|
const fetchOptions = addProxyAgent({
|
|
63
44
|
method: 'POST',
|
|
@@ -79,61 +60,3 @@ export async function identifyLicense(licenseFilePath, opts = {}) {
|
|
|
79
60
|
return null; // Fallback to local detection on error
|
|
80
61
|
}
|
|
81
62
|
}
|
|
82
|
-
/**
|
|
83
|
-
* Find and read LICENSE or LICENSE.md; use local pattern matching for identification.
|
|
84
|
-
* @param {string} manifestPath
|
|
85
|
-
* @returns {string|null}
|
|
86
|
-
*/
|
|
87
|
-
function readLicenseFromFile(manifestPath) {
|
|
88
|
-
const licenseFilePath = findLicenseFilePath(manifestPath);
|
|
89
|
-
if (!licenseFilePath) {
|
|
90
|
-
return null;
|
|
91
|
-
}
|
|
92
|
-
try {
|
|
93
|
-
const content = fs.readFileSync(licenseFilePath, 'utf-8');
|
|
94
|
-
return detectSpdxFromText(content) || content.split('\n')[0]?.trim() || null;
|
|
95
|
-
}
|
|
96
|
-
catch {
|
|
97
|
-
return null;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Very simple SPDX detection from common license text (first ~500 chars).
|
|
102
|
-
* @param {string} text
|
|
103
|
-
* @returns {string|null}
|
|
104
|
-
*/
|
|
105
|
-
function detectSpdxFromText(text) {
|
|
106
|
-
const head = text.slice(0, 500);
|
|
107
|
-
if (/Apache License,?\s*Version 2\.0/i.test(head)) {
|
|
108
|
-
return 'Apache-2.0';
|
|
109
|
-
}
|
|
110
|
-
if (/MIT License/i.test(head) && /Permission is hereby granted/i.test(head)) {
|
|
111
|
-
return 'MIT';
|
|
112
|
-
}
|
|
113
|
-
if (/GNU GENERAL PUBLIC LICENSE\s+Version 2/i.test(head)) {
|
|
114
|
-
return 'GPL-2.0-only';
|
|
115
|
-
}
|
|
116
|
-
if (/GNU GENERAL PUBLIC LICENSE\s+Version 3/i.test(head)) {
|
|
117
|
-
return 'GPL-3.0-only';
|
|
118
|
-
}
|
|
119
|
-
if (/BSD 2-Clause/i.test(head)) {
|
|
120
|
-
return 'BSD-2-Clause';
|
|
121
|
-
}
|
|
122
|
-
if (/BSD 3-Clause/i.test(head)) {
|
|
123
|
-
return 'BSD-3-Clause';
|
|
124
|
-
}
|
|
125
|
-
return null;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Normalize for comparison (lowercase, strip common suffixes).
|
|
129
|
-
* @param {string} spdxOrName
|
|
130
|
-
* @returns {string}
|
|
131
|
-
*/
|
|
132
|
-
function normalizeSpdx(spdxOrName) {
|
|
133
|
-
const s = String(spdxOrName).trim().toLowerCase();
|
|
134
|
-
// e.g. "MIT" vs "MIT License"
|
|
135
|
-
if (s.endsWith(' license')) {
|
|
136
|
-
return s.slice(0, -8);
|
|
137
|
-
}
|
|
138
|
-
return s;
|
|
139
|
-
}
|
package/dist/src/provider.d.ts
CHANGED
|
@@ -13,12 +13,15 @@ export function matchForLicense(manifestPath: string, providers: [Provider]): Pr
|
|
|
13
13
|
* Each provider MUST export 'provideStack' taking manifest path returning a {@link Provided}.
|
|
14
14
|
* @param {string} manifest - the name-type or path of the manifest
|
|
15
15
|
* @param {[Provider]} providers - list of providers to iterate over
|
|
16
|
+
* @param {{TRUSTIFY_DA_WORKSPACE_DIR?: string}} [opts={}] - optional; TRUSTIFY_DA_WORKSPACE_DIR overrides lock file location for workspaces
|
|
16
17
|
* @returns {Provider}
|
|
17
18
|
* @throws {Error} when the manifest is not supported and no provider was matched
|
|
18
19
|
*/
|
|
19
|
-
export function match(manifest: string, providers: [Provider]
|
|
20
|
+
export function match(manifest: string, providers: [Provider], opts?: {
|
|
21
|
+
TRUSTIFY_DA_WORKSPACE_DIR?: string;
|
|
22
|
+
}): Provider;
|
|
20
23
|
/** @typedef {{ecosystem: string, contentType: string, content: string}} Provided */
|
|
21
|
-
/** @typedef {{isSupported: function(string): boolean, validateLockFile: function(string): void, provideComponent: function(string, {}): Provided | Promise<Provided>, provideStack: function(string, {}): Provided | Promise<Provided>, readLicenseFromManifest: function(string): string | null}} Provider */
|
|
24
|
+
/** @typedef {{isSupported: function(string): boolean, validateLockFile: function(string, Object): void, provideComponent: function(string, {}): Provided | Promise<Provided>, provideStack: function(string, {}): Provided | Promise<Provided>, readLicenseFromManifest: function(string): string | null}} Provider */
|
|
22
25
|
/**
|
|
23
26
|
* MUST include all providers here.
|
|
24
27
|
* @type {[Provider]}
|
|
@@ -31,7 +34,7 @@ export type Provided = {
|
|
|
31
34
|
};
|
|
32
35
|
export type Provider = {
|
|
33
36
|
isSupported: (arg0: string) => boolean;
|
|
34
|
-
validateLockFile: (arg0: string) => void;
|
|
37
|
+
validateLockFile: (arg0: string, arg1: any) => void;
|
|
35
38
|
provideComponent: (arg0: string, arg1: {}) => Provided | Promise<Provided>;
|
|
36
39
|
provideStack: (arg0: string, arg1: {}) => Provided | Promise<Provided>;
|
|
37
40
|
readLicenseFromManifest: (arg0: string) => string | null;
|
package/dist/src/provider.js
CHANGED
|
@@ -7,8 +7,9 @@ import Javascript_npm from './providers/javascript_npm.js';
|
|
|
7
7
|
import Javascript_pnpm from './providers/javascript_pnpm.js';
|
|
8
8
|
import Javascript_yarn from './providers/javascript_yarn.js';
|
|
9
9
|
import pythonPipProvider from './providers/python_pip.js';
|
|
10
|
+
import rustCargoProvider from './providers/rust_cargo.js';
|
|
10
11
|
/** @typedef {{ecosystem: string, contentType: string, content: string}} Provided */
|
|
11
|
-
/** @typedef {{isSupported: function(string): boolean, validateLockFile: function(string): void, provideComponent: function(string, {}): Provided | Promise<Provided>, provideStack: function(string, {}): Provided | Promise<Provided>, readLicenseFromManifest: function(string): string | null}} Provider */
|
|
12
|
+
/** @typedef {{isSupported: function(string): boolean, validateLockFile: function(string, Object): void, provideComponent: function(string, {}): Provided | Promise<Provided>, provideStack: function(string, {}): Provided | Promise<Provided>, readLicenseFromManifest: function(string): string | null}} Provider */
|
|
12
13
|
/**
|
|
13
14
|
* MUST include all providers here.
|
|
14
15
|
* @type {[Provider]}
|
|
@@ -17,11 +18,12 @@ export const availableProviders = [
|
|
|
17
18
|
new Java_maven(),
|
|
18
19
|
new Java_gradle_groovy(),
|
|
19
20
|
new Java_gradle_kotlin(),
|
|
20
|
-
new Javascript_npm(),
|
|
21
21
|
new Javascript_pnpm(),
|
|
22
22
|
new Javascript_yarn(),
|
|
23
|
+
new Javascript_npm(),
|
|
23
24
|
golangGomodulesProvider,
|
|
24
|
-
pythonPipProvider
|
|
25
|
+
pythonPipProvider,
|
|
26
|
+
rustCargoProvider
|
|
25
27
|
];
|
|
26
28
|
/**
|
|
27
29
|
* Match a provider by manifest type only (no lock file check). Used for license reading.
|
|
@@ -45,16 +47,17 @@ export function matchForLicense(manifestPath, providers) {
|
|
|
45
47
|
* Each provider MUST export 'provideStack' taking manifest path returning a {@link Provided}.
|
|
46
48
|
* @param {string} manifest - the name-type or path of the manifest
|
|
47
49
|
* @param {[Provider]} providers - list of providers to iterate over
|
|
50
|
+
* @param {{TRUSTIFY_DA_WORKSPACE_DIR?: string}} [opts={}] - optional; TRUSTIFY_DA_WORKSPACE_DIR overrides lock file location for workspaces
|
|
48
51
|
* @returns {Provider}
|
|
49
52
|
* @throws {Error} when the manifest is not supported and no provider was matched
|
|
50
53
|
*/
|
|
51
|
-
export function match(manifest, providers) {
|
|
54
|
+
export function match(manifest, providers, opts = {}) {
|
|
52
55
|
const manifestPath = path.parse(manifest);
|
|
53
56
|
const supported = providers.filter(prov => prov.isSupported(manifestPath.base));
|
|
54
57
|
if (supported.length === 0) {
|
|
55
58
|
throw new Error(`${manifestPath.base} is not supported`);
|
|
56
59
|
}
|
|
57
|
-
const provider = supported.find(prov => prov.validateLockFile(manifestPath.dir));
|
|
60
|
+
const provider = supported.find(prov => prov.validateLockFile(manifestPath.dir, opts));
|
|
58
61
|
if (!provider) {
|
|
59
62
|
throw new Error(`${manifestPath.base} requires a lock file. Use your preferred package manager to generate the lock file.`);
|
|
60
63
|
}
|
|
@@ -67,11 +67,16 @@ export default class Base_javascript {
|
|
|
67
67
|
*/
|
|
68
68
|
isSupported(manifestName: string): boolean;
|
|
69
69
|
/**
|
|
70
|
-
* Checks if a required lock file exists in the
|
|
70
|
+
* Checks if a required lock file exists in the manifest directory or at the workspace root.
|
|
71
|
+
* When TRUSTIFY_DA_WORKSPACE_DIR is provided (via env var or opts),
|
|
72
|
+
* checks only that directory for the lock file.
|
|
71
73
|
* @param {string} manifestDir - The base directory where the manifest is located
|
|
74
|
+
* @param {{TRUSTIFY_DA_WORKSPACE_DIR?: string}} [opts={}] - optional workspace root
|
|
72
75
|
* @returns {boolean} True if the lock file exists
|
|
73
76
|
*/
|
|
74
|
-
validateLockFile(manifestDir: string
|
|
77
|
+
validateLockFile(manifestDir: string, opts?: {
|
|
78
|
+
TRUSTIFY_DA_WORKSPACE_DIR?: string;
|
|
79
|
+
}): boolean;
|
|
75
80
|
/**
|
|
76
81
|
* Provides content and content type for stack analysis
|
|
77
82
|
* @param {string} manifestPath - The manifest path or name
|
|
@@ -95,10 +100,11 @@ export default class Base_javascript {
|
|
|
95
100
|
/**
|
|
96
101
|
* Builds the dependency tree for the project
|
|
97
102
|
* @param {boolean} includeTransitive - Whether to include transitive dependencies
|
|
103
|
+
* @param {Object} [opts={}] - Configuration options; when `TRUSTIFY_DA_WORKSPACE_DIR` is set, commands run from workspace root
|
|
98
104
|
* @returns {Object} The dependency tree
|
|
99
105
|
* @protected
|
|
100
106
|
*/
|
|
101
|
-
protected _buildDependencyTree(includeTransitive: boolean): any;
|
|
107
|
+
protected _buildDependencyTree(includeTransitive: boolean, opts?: any): any;
|
|
102
108
|
/**
|
|
103
109
|
* Recursively builds the Sbom from the JSON that npm listing returns
|
|
104
110
|
* @param {Sbom} sbom - The SBOM object to add dependencies to
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import path from 'node:path';
|
|
4
|
+
import { getLicense } from '../license/license_utils.js';
|
|
4
5
|
import Sbom from '../sbom.js';
|
|
5
|
-
import { getCustom, getCustomPath, invokeCommand, toPurl, toPurlFromString } from
|
|
6
|
+
import { getCustom, getCustomPath, invokeCommand, toPurl, toPurlFromString } from '../tools.js';
|
|
6
7
|
import Manifest from './manifest.js';
|
|
7
8
|
/** @typedef {import('../provider').Provider} */
|
|
8
9
|
/** @typedef {import('../provider').Provided} Provided */
|
|
@@ -96,12 +97,17 @@ export default class Base_javascript {
|
|
|
96
97
|
return 'package.json' === manifestName;
|
|
97
98
|
}
|
|
98
99
|
/**
|
|
99
|
-
* Checks if a required lock file exists in the
|
|
100
|
+
* Checks if a required lock file exists in the manifest directory or at the workspace root.
|
|
101
|
+
* When TRUSTIFY_DA_WORKSPACE_DIR is provided (via env var or opts),
|
|
102
|
+
* checks only that directory for the lock file.
|
|
100
103
|
* @param {string} manifestDir - The base directory where the manifest is located
|
|
104
|
+
* @param {{TRUSTIFY_DA_WORKSPACE_DIR?: string}} [opts={}] - optional workspace root
|
|
101
105
|
* @returns {boolean} True if the lock file exists
|
|
102
106
|
*/
|
|
103
|
-
validateLockFile(manifestDir) {
|
|
104
|
-
const
|
|
107
|
+
validateLockFile(manifestDir, opts = {}) {
|
|
108
|
+
const workspaceDir = getCustom('TRUSTIFY_DA_WORKSPACE_DIR', null, opts);
|
|
109
|
+
const dirToCheck = workspaceDir ? path.resolve(workspaceDir) : manifestDir;
|
|
110
|
+
const lock = path.join(dirToCheck, this._lockFileName());
|
|
105
111
|
return fs.existsSync(lock);
|
|
106
112
|
}
|
|
107
113
|
/**
|
|
@@ -138,33 +144,37 @@ export default class Base_javascript {
|
|
|
138
144
|
* @returns {string|null}
|
|
139
145
|
*/
|
|
140
146
|
readLicenseFromManifest(manifestPath) {
|
|
147
|
+
let manifestLicense;
|
|
141
148
|
try {
|
|
142
149
|
const content = JSON.parse(fs.readFileSync(manifestPath, 'utf-8'));
|
|
143
150
|
if (typeof content.license === 'string') {
|
|
144
|
-
|
|
151
|
+
manifestLicense = content.license.trim() || null;
|
|
145
152
|
}
|
|
146
|
-
if (Array.isArray(content.licenses) && content.licenses.length > 0) {
|
|
153
|
+
else if (Array.isArray(content.licenses) && content.licenses.length > 0) {
|
|
147
154
|
const first = content.licenses[0];
|
|
148
155
|
const name = first.type || first.name;
|
|
149
|
-
|
|
156
|
+
manifestLicense = (typeof name === 'string' ? name.trim() : null);
|
|
150
157
|
}
|
|
151
|
-
return null;
|
|
152
158
|
}
|
|
153
159
|
catch {
|
|
154
|
-
|
|
160
|
+
manifestLicense = null;
|
|
155
161
|
}
|
|
162
|
+
return getLicense(manifestLicense, manifestPath);
|
|
156
163
|
}
|
|
157
164
|
/**
|
|
158
165
|
* Builds the dependency tree for the project
|
|
159
166
|
* @param {boolean} includeTransitive - Whether to include transitive dependencies
|
|
167
|
+
* @param {Object} [opts={}] - Configuration options; when `TRUSTIFY_DA_WORKSPACE_DIR` is set, commands run from workspace root
|
|
160
168
|
* @returns {Object} The dependency tree
|
|
161
169
|
* @protected
|
|
162
170
|
*/
|
|
163
|
-
_buildDependencyTree(includeTransitive) {
|
|
171
|
+
_buildDependencyTree(includeTransitive, opts = {}) {
|
|
164
172
|
this._version();
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
173
|
+
const manifestDir = path.dirname(this.#manifest.manifestPath);
|
|
174
|
+
const workspaceDir = getCustom('TRUSTIFY_DA_WORKSPACE_DIR', null, opts);
|
|
175
|
+
const cmdDir = workspaceDir ? path.resolve(workspaceDir) : manifestDir;
|
|
176
|
+
this.#createLockFile(cmdDir);
|
|
177
|
+
let output = this.#executeListCmd(includeTransitive, cmdDir);
|
|
168
178
|
output = this._parseDepTreeOutput(output);
|
|
169
179
|
return JSON.parse(output);
|
|
170
180
|
}
|
|
@@ -175,7 +185,7 @@ export default class Base_javascript {
|
|
|
175
185
|
* @private
|
|
176
186
|
*/
|
|
177
187
|
#getSBOM(opts = {}) {
|
|
178
|
-
const depsObject = this._buildDependencyTree(true);
|
|
188
|
+
const depsObject = this._buildDependencyTree(true, opts);
|
|
179
189
|
let mainComponent = toPurl(purlType, this.#manifest.name, this.#manifest.version);
|
|
180
190
|
const license = this.readLicenseFromManifest(this.#manifest.manifestPath);
|
|
181
191
|
let sbom = new Sbom();
|
|
@@ -227,7 +237,7 @@ export default class Base_javascript {
|
|
|
227
237
|
* @private
|
|
228
238
|
*/
|
|
229
239
|
#getDirectDependencySbom(opts = {}) {
|
|
230
|
-
const depTree = this._buildDependencyTree(false);
|
|
240
|
+
const depTree = this._buildDependencyTree(false, opts);
|
|
231
241
|
let mainComponent = toPurl(purlType, this.#manifest.name, this.#manifest.version);
|
|
232
242
|
const license = this.readLicenseFromManifest(this.#manifest.manifestPath);
|
|
233
243
|
let sbom = new Sbom();
|
|
@@ -2,6 +2,7 @@ import fs from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { EOL } from "os";
|
|
4
4
|
import { PackageURL } from 'packageurl-js';
|
|
5
|
+
import { readLicenseFile } from '../license/license_utils.js';
|
|
5
6
|
import Sbom from '../sbom.js';
|
|
6
7
|
import { getCustom, getCustomPath, invokeCommand } from "../tools.js";
|
|
7
8
|
export default { isSupported, validateLockFile, provideComponent, provideStack, readLicenseFromManifest };
|
|
@@ -28,7 +29,7 @@ function isSupported(manifestName) {
|
|
|
28
29
|
* @returns {string|null}
|
|
29
30
|
*/
|
|
30
31
|
// eslint-disable-next-line no-unused-vars
|
|
31
|
-
function readLicenseFromManifest(manifestPath) { return
|
|
32
|
+
function readLicenseFromManifest(manifestPath) { return readLicenseFile(manifestPath); }
|
|
32
33
|
/**
|
|
33
34
|
* @param {string} manifestDir - the directory where the manifest lies
|
|
34
35
|
*/
|
|
@@ -2,6 +2,7 @@ import fs from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { EOL } from 'os';
|
|
4
4
|
import TOML from 'fast-toml';
|
|
5
|
+
import { readLicenseFile } from '../license/license_utils.js';
|
|
5
6
|
import Sbom from '../sbom.js';
|
|
6
7
|
import Base_java, { ecosystem_gradle } from "./base_java.js";
|
|
7
8
|
/** @typedef {import('../provider.js').Provider} */
|
|
@@ -55,7 +56,7 @@ export default class Java_gradle extends Base_java {
|
|
|
55
56
|
* @returns {null}
|
|
56
57
|
*/
|
|
57
58
|
// eslint-disable-next-line no-unused-vars
|
|
58
|
-
readLicenseFromManifest(manifestPath) { return
|
|
59
|
+
readLicenseFromManifest(manifestPath) { return readLicenseFile(manifestPath); }
|
|
59
60
|
/**
|
|
60
61
|
* Provide content and content type for stack analysis.
|
|
61
62
|
* @param {string} manifest - the manifest path or name
|
|
@@ -28,7 +28,7 @@ export default class Java_maven extends Base_java {
|
|
|
28
28
|
*/
|
|
29
29
|
provideComponent(manifest: string, opts?: {}): Provided;
|
|
30
30
|
/**
|
|
31
|
-
* Read license from pom.xml manifest
|
|
31
|
+
* Read license from pom.xml manifest, with fallback to LICENSE file
|
|
32
32
|
* @param {string} manifestPath - path to pom.xml
|
|
33
33
|
* @returns {string|null}
|
|
34
34
|
*/
|
|
@@ -3,6 +3,7 @@ import os from 'node:os';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { EOL } from 'os';
|
|
5
5
|
import { XMLParser } from 'fast-xml-parser';
|
|
6
|
+
import { getLicense } from '../license/license_utils.js';
|
|
6
7
|
import Sbom from '../sbom.js';
|
|
7
8
|
import { getCustom } from '../tools.js';
|
|
8
9
|
import Base_java, { ecosystem_maven } from "./base_java.js";
|
|
@@ -52,28 +53,28 @@ export default class Java_maven extends Base_java {
|
|
|
52
53
|
};
|
|
53
54
|
}
|
|
54
55
|
/**
|
|
55
|
-
* Read license from pom.xml manifest
|
|
56
|
+
* Read license from pom.xml manifest, with fallback to LICENSE file
|
|
56
57
|
* @param {string} manifestPath - path to pom.xml
|
|
57
58
|
* @returns {string|null}
|
|
58
59
|
*/
|
|
59
60
|
readLicenseFromManifest(manifestPath) {
|
|
61
|
+
let fromPom = null;
|
|
60
62
|
try {
|
|
61
63
|
const xml = fs.readFileSync(manifestPath, 'utf-8');
|
|
62
64
|
const parser = new XMLParser({ ignoreAttributes: false });
|
|
63
65
|
const obj = parser.parse(xml);
|
|
64
66
|
const project = obj?.project;
|
|
65
|
-
if (
|
|
66
|
-
|
|
67
|
+
if (project?.licenses?.license) {
|
|
68
|
+
const license = Array.isArray(project.licenses.license)
|
|
69
|
+
? project.licenses.license[0]
|
|
70
|
+
: project.licenses.license;
|
|
71
|
+
fromPom = (license?.name && license.name.trim()) || null;
|
|
67
72
|
}
|
|
68
|
-
const license = Array.isArray(project.licenses.license)
|
|
69
|
-
? project.licenses.license[0]
|
|
70
|
-
: project.licenses.license;
|
|
71
|
-
const name = (license?.name && license.name.trim()) || null;
|
|
72
|
-
return name || null;
|
|
73
73
|
}
|
|
74
74
|
catch {
|
|
75
|
-
|
|
75
|
+
// leave fromPom as null
|
|
76
76
|
}
|
|
77
|
+
return getLicense(fromPom, manifestPath);
|
|
77
78
|
}
|
|
78
79
|
/**
|
|
79
80
|
* Create a Dot Graph dependency tree for a manifest path.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export default class Javascript_pnpm extends Base_javascript {
|
|
2
2
|
_listCmdArgs(includeTransitive: any): string[];
|
|
3
|
-
_buildDependencyTree(includeTransitive: any,
|
|
3
|
+
_buildDependencyTree(includeTransitive: any, opts?: {}): any;
|
|
4
4
|
}
|
|
5
5
|
import Base_javascript from './base_javascript.js';
|
|
@@ -12,8 +12,8 @@ export default class Javascript_pnpm extends Base_javascript {
|
|
|
12
12
|
_updateLockFileCmdArgs() {
|
|
13
13
|
return ['install', '--frozen-lockfile'];
|
|
14
14
|
}
|
|
15
|
-
_buildDependencyTree(includeTransitive,
|
|
16
|
-
const tree = super._buildDependencyTree(includeTransitive,
|
|
15
|
+
_buildDependencyTree(includeTransitive, opts = {}) {
|
|
16
|
+
const tree = super._buildDependencyTree(includeTransitive, opts);
|
|
17
17
|
if (Array.isArray(tree) && tree.length > 0) {
|
|
18
18
|
return tree[0];
|
|
19
19
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import { PackageURL } from 'packageurl-js';
|
|
3
|
+
import { readLicenseFile } from '../license/license_utils.js';
|
|
3
4
|
import Sbom from '../sbom.js';
|
|
4
5
|
import { environmentVariableIsPopulated, getCustom, getCustomPath, invokeCommand } from "../tools.js";
|
|
5
6
|
import Python_controller from './python_controller.js';
|
|
@@ -24,7 +25,7 @@ function isSupported(manifestName) {
|
|
|
24
25
|
* @returns {string|null}
|
|
25
26
|
*/
|
|
26
27
|
// eslint-disable-next-line no-unused-vars
|
|
27
|
-
function readLicenseFromManifest(manifestPath) { return
|
|
28
|
+
function readLicenseFromManifest(manifestPath) { return readLicenseFile(manifestPath); }
|
|
28
29
|
/**
|
|
29
30
|
* @param {string} manifestDir - the directory where the manifest lies
|
|
30
31
|
*/
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
2
|
import { Language, Parser, Query } from 'web-tree-sitter';
|
|
3
|
-
const
|
|
3
|
+
const wasmUrl = new URL('./tree-sitter-requirements.wasm', import.meta.url);
|
|
4
4
|
async function init() {
|
|
5
5
|
await Parser.init();
|
|
6
|
-
|
|
6
|
+
const wasmBytes = new Uint8Array(await readFile(wasmUrl));
|
|
7
|
+
return await Language.load(wasmBytes);
|
|
7
8
|
}
|
|
8
9
|
export async function getParser() {
|
|
9
10
|
const language = await init();
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
declare namespace _default {
|
|
2
|
+
export { isSupported };
|
|
3
|
+
export { validateLockFile };
|
|
4
|
+
export { provideComponent };
|
|
5
|
+
export { provideStack };
|
|
6
|
+
export { readLicenseFromManifest };
|
|
7
|
+
}
|
|
8
|
+
export default _default;
|
|
9
|
+
export type Provided = import("../provider").Provided;
|
|
10
|
+
/**
|
|
11
|
+
* @param {string} manifestName - the subject manifest name-type
|
|
12
|
+
* @returns {boolean} - return true if `Cargo.toml` is the manifest name-type
|
|
13
|
+
*/
|
|
14
|
+
declare function isSupported(manifestName: string): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Validates that Cargo.lock exists in the manifest directory or in a parent
|
|
17
|
+
* workspace root directory. In Cargo workspaces the lock file always lives at
|
|
18
|
+
* the workspace root, so when a member crate's Cargo.toml is provided we walk
|
|
19
|
+
* up the directory tree looking for Cargo.lock (stopping when we find a
|
|
20
|
+
* Cargo.toml that contains a [workspace] section, or when we reach the
|
|
21
|
+
* filesystem root).
|
|
22
|
+
* When TRUSTIFY_DA_WORKSPACE_DIR is provided (via env var or opts),
|
|
23
|
+
* checks only that directory for Cargo.lock — no walk-up.
|
|
24
|
+
* @param {string} manifestDir - the directory where the manifest lies
|
|
25
|
+
* @param {{TRUSTIFY_DA_WORKSPACE_DIR?: string}} [opts={}] - optional workspace root
|
|
26
|
+
* @returns {boolean} true if Cargo.lock is found
|
|
27
|
+
*/
|
|
28
|
+
declare function validateLockFile(manifestDir: string, opts?: {
|
|
29
|
+
TRUSTIFY_DA_WORKSPACE_DIR?: string;
|
|
30
|
+
}): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Provide content and content type for Cargo component analysis.
|
|
33
|
+
* @param {string} manifest - path to Cargo.toml for component report
|
|
34
|
+
* @param {{}} [opts={}] - optional various options to pass along the application
|
|
35
|
+
* @returns {Provided}
|
|
36
|
+
*/
|
|
37
|
+
declare function provideComponent(manifest: string, opts?: {}): Provided;
|
|
38
|
+
/**
|
|
39
|
+
* Provide content and content type for Cargo stack analysis.
|
|
40
|
+
* @param {string} manifest - the manifest path
|
|
41
|
+
* @param {{}} [opts={}] - optional various options to pass along the application
|
|
42
|
+
* @returns {Provided}
|
|
43
|
+
*/
|
|
44
|
+
declare function provideStack(manifest: string, opts?: {}): Provided;
|
|
45
|
+
/**
|
|
46
|
+
* Read project license from Cargo.toml, with fallback to LICENSE file.
|
|
47
|
+
* Supports the `license` field under `[package]` (single crate / workspace
|
|
48
|
+
* with root) and under `[workspace.package]` (virtual workspaces).
|
|
49
|
+
* @param {string} manifestPath - path to Cargo.toml
|
|
50
|
+
* @returns {string|null} SPDX identifier or null
|
|
51
|
+
*/
|
|
52
|
+
declare function readLicenseFromManifest(manifestPath: string): string | null;
|