@trustify-da/trustify-da-javascript-client 0.3.0-ea.1684e79 → 0.3.0-ea.2e5fe72

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.
@@ -136,19 +136,74 @@ declare function stackAnalysis(manifest: string, html: false, opts?: Options | u
136
136
  * or backend request failed
137
137
  */
138
138
  declare function stackAnalysis(manifest: string, html?: boolean | undefined, opts?: Options | undefined): Promise<string | import("@trustify-da/trustify-da-api-model/model/v5/AnalysisReport").AnalysisReport>;
139
+ /**
140
+ * @overload
141
+ * @param {string} workspaceRoot
142
+ * @param {true} html
143
+ * @param {Options & { batchMetadata: true }} opts
144
+ * @returns {Promise<{ analysis: string, metadata: BatchAnalysisMetadata }>}
145
+ * @throws {Error}
146
+ */
147
+ declare function stackAnalysisBatch(workspaceRoot: string, html: true, opts: Options & {
148
+ batchMetadata: true;
149
+ }): Promise<{
150
+ analysis: string;
151
+ metadata: BatchAnalysisMetadata;
152
+ }>;
153
+ /**
154
+ * @overload
155
+ * @param {string} workspaceRoot
156
+ * @param {true} html
157
+ * @param {Options & { batchMetadata?: false }} [opts={}]
158
+ * @returns {Promise<string>}
159
+ * @throws {Error}
160
+ */
161
+ declare function stackAnalysisBatch(workspaceRoot: string, html: true, opts?: (Options & {
162
+ batchMetadata?: false;
163
+ }) | undefined): Promise<string>;
164
+ /**
165
+ * @overload
166
+ * @param {string} workspaceRoot
167
+ * @param {false} html
168
+ * @param {Options & { batchMetadata: true }} opts
169
+ * @returns {Promise<{ analysis: Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>, metadata: BatchAnalysisMetadata }>}
170
+ * @throws {Error}
171
+ */
172
+ declare function stackAnalysisBatch(workspaceRoot: string, html: false, opts: Options & {
173
+ batchMetadata: true;
174
+ }): Promise<{
175
+ analysis: {
176
+ [x: string]: import("@trustify-da/trustify-da-api-model/model/v5/AnalysisReport").AnalysisReport;
177
+ };
178
+ metadata: BatchAnalysisMetadata;
179
+ }>;
180
+ /**
181
+ * @overload
182
+ * @param {string} workspaceRoot
183
+ * @param {false} html
184
+ * @param {Options & { batchMetadata?: false }} [opts={}]
185
+ * @returns {Promise<Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>>}
186
+ * @throws {Error}
187
+ */
188
+ declare function stackAnalysisBatch(workspaceRoot: string, html: false, opts?: (Options & {
189
+ batchMetadata?: false;
190
+ }) | undefined): Promise<{
191
+ [x: string]: import("@trustify-da/trustify-da-api-model/model/v5/AnalysisReport").AnalysisReport;
192
+ }>;
139
193
  /**
140
194
  * Get stack analysis for all workspace packages/crates (batch).
141
195
  * Detects ecosystem from workspace root: Cargo (Cargo.toml + Cargo.lock) or JS/TS (package.json + lock file).
142
196
  * SBOMs are generated in parallel (see `batchConcurrency`) unless `continueOnError: false` (fail-fast sequential).
143
197
  * With `opts.batchMetadata` / `TRUSTIFY_DA_BATCH_METADATA`, returns `{ analysis, metadata }` including validation and SBOM errors.
144
198
  *
199
+ * @overload
145
200
  * @param {string} workspaceRoot - Path to workspace root (containing lock file and workspace config)
146
201
  * @param {boolean} [html=false] - true returns HTML, false returns JSON report
147
202
  * @param {Options} [opts={}] - `batchConcurrency`, discovery ignores, `continueOnError` (default true), `batchMetadata` (default false)
148
203
  * @returns {Promise<string|Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>|{ analysis: string|Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>, metadata: BatchAnalysisMetadata }>}
149
204
  * @throws {Error} if workspace root invalid, no manifests found, no packages pass validation, no SBOMs produced, or backend request failed. When `opts.batchMetadata` is set, `error.batchMetadata` may be set on thrown errors.
150
205
  */
151
- declare function stackAnalysisBatch(workspaceRoot: string, html?: boolean, opts?: Options): Promise<string | {
206
+ declare function stackAnalysisBatch(workspaceRoot: string, html?: boolean | undefined, opts?: Options | undefined): Promise<string | {
152
207
  [x: string]: import("@trustify-da/trustify-da-api-model/model/v5/AnalysisReport").AnalysisReport;
153
208
  } | {
154
209
  analysis: string | {
package/dist/src/index.js CHANGED
@@ -398,12 +398,45 @@ function batchError(message, wantMetadata, metadata) {
398
398
  }
399
399
  return err;
400
400
  }
401
+ /**
402
+ * @overload
403
+ * @param {string} workspaceRoot
404
+ * @param {true} html
405
+ * @param {Options & { batchMetadata: true }} opts
406
+ * @returns {Promise<{ analysis: string, metadata: BatchAnalysisMetadata }>}
407
+ * @throws {Error}
408
+ */
409
+ /**
410
+ * @overload
411
+ * @param {string} workspaceRoot
412
+ * @param {true} html
413
+ * @param {Options & { batchMetadata?: false }} [opts={}]
414
+ * @returns {Promise<string>}
415
+ * @throws {Error}
416
+ */
417
+ /**
418
+ * @overload
419
+ * @param {string} workspaceRoot
420
+ * @param {false} html
421
+ * @param {Options & { batchMetadata: true }} opts
422
+ * @returns {Promise<{ analysis: Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>, metadata: BatchAnalysisMetadata }>}
423
+ * @throws {Error}
424
+ */
425
+ /**
426
+ * @overload
427
+ * @param {string} workspaceRoot
428
+ * @param {false} html
429
+ * @param {Options & { batchMetadata?: false }} [opts={}]
430
+ * @returns {Promise<Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>>}
431
+ * @throws {Error}
432
+ */
401
433
  /**
402
434
  * Get stack analysis for all workspace packages/crates (batch).
403
435
  * Detects ecosystem from workspace root: Cargo (Cargo.toml + Cargo.lock) or JS/TS (package.json + lock file).
404
436
  * SBOMs are generated in parallel (see `batchConcurrency`) unless `continueOnError: false` (fail-fast sequential).
405
437
  * With `opts.batchMetadata` / `TRUSTIFY_DA_BATCH_METADATA`, returns `{ analysis, metadata }` including validation and SBOM errors.
406
438
  *
439
+ * @overload
407
440
  * @param {string} workspaceRoot - Path to workspace root (containing lock file and workspace config)
408
441
  * @param {boolean} [html=false] - true returns HTML, false returns JSON report
409
442
  * @param {Options} [opts={}] - `batchConcurrency`, discovery ignores, `continueOnError` (default true), `batchMetadata` (default false)
@@ -1,4 +1,5 @@
1
1
  export default class Javascript_npm extends Base_javascript {
2
2
  _listCmdArgs(includeTransitive: any): string[];
3
+ _buildDependencyTree(includeTransitive: any, opts?: {}): any;
3
4
  }
4
5
  import Base_javascript from './base_javascript.js';
@@ -12,4 +12,25 @@ export default class Javascript_npm extends Base_javascript {
12
12
  _updateLockFileCmdArgs() {
13
13
  return ['install', '--package-lock-only'];
14
14
  }
15
+ _buildDependencyTree(includeTransitive, opts = {}) {
16
+ // npm ls --json returns a single tree rooted at the workspace root.
17
+ // When analyzing a workspace member, its deps are nested under the
18
+ // root's dependencies keyed by the member name — extract that subtree
19
+ // so downstream analysis sees only the member's dependencies.
20
+ const tree = super._buildDependencyTree(includeTransitive, opts);
21
+ const memberName = this._getManifest().name;
22
+ if (tree.name === memberName) {
23
+ return tree;
24
+ }
25
+ const memberEntry = tree.dependencies?.[memberName];
26
+ if (memberEntry) {
27
+ return {
28
+ name: memberName,
29
+ version: memberEntry.version || this._getManifest().version,
30
+ dependencies: memberEntry.dependencies,
31
+ optionalDependencies: memberEntry.optionalDependencies,
32
+ };
33
+ }
34
+ return tree;
35
+ }
15
36
  }
@@ -7,15 +7,19 @@ export default class Javascript_pnpm extends Base_javascript {
7
7
  return "pnpm";
8
8
  }
9
9
  _listCmdArgs(includeTransitive) {
10
- return ['ls', includeTransitive ? '--depth=Infinity' : '--depth=0', '--prod', '--json'];
10
+ return ['ls', includeTransitive ? '--depth=Infinity' : '--depth=0', '--prod', '--json', '-r'];
11
11
  }
12
12
  _updateLockFileCmdArgs() {
13
13
  return ['install', '--frozen-lockfile'];
14
14
  }
15
15
  _buildDependencyTree(includeTransitive, opts = {}) {
16
+ // pnpm ls --json returns an array with one entry per workspace package.
17
+ // When analyzing a workspace member, find its entry by name instead of
18
+ // blindly taking the first element (which is the workspace root).
16
19
  const tree = super._buildDependencyTree(includeTransitive, opts);
17
20
  if (Array.isArray(tree) && tree.length > 0) {
18
- return tree[0];
21
+ const memberName = this._getManifest().name;
22
+ return tree.find(pkg => pkg.name === memberName) || tree[0];
19
23
  }
20
24
  return {};
21
25
  }
@@ -15,7 +15,10 @@ export default class Yarn_berry_processor extends Yarn_processor {
15
15
  * @returns {string[]} Command arguments for listing dependencies
16
16
  */
17
17
  listCmdArgs(includeTransitive) {
18
- return ['info', includeTransitive ? '--recursive' : '--all', '--json'];
18
+ // --all is needed to include workspace members in the output
19
+ return includeTransitive
20
+ ? ['info', '--recursive', '--all', '--json']
21
+ : ['info', '--all', '--json'];
19
22
  }
20
23
  /**
21
24
  * Returns the command arguments for updating the lock file
@@ -68,7 +71,8 @@ export default class Yarn_berry_processor extends Yarn_processor {
68
71
  if (!name) {
69
72
  return false;
70
73
  }
71
- return name.endsWith("@workspace:.");
74
+ // Workspace members use paths like "member-a@workspace:packages/member-a", not just "@workspace:."
75
+ return name.startsWith(`${this._manifest.name}@workspace:`);
72
76
  }
73
77
  /**
74
78
  * Adds dependencies to the SBOM
@@ -36,7 +36,7 @@ export default class Python_uv extends Base_pyproject {
36
36
  return Buffer.from(process.env['TRUSTIFY_DA_UV_EXPORT'], 'base64').toString('ascii');
37
37
  }
38
38
  let uvBin = getCustomPath('uv', opts);
39
- return invokeCommand(uvBin, ['export', '--format', 'requirements.txt', '--frozen', '--no-hashes', '--no-dev'], { cwd: manifestDir }).toString();
39
+ return invokeCommand(uvBin, ['export', '--format', 'requirements.txt', '--frozen', '--no-hashes', '--no-dev', '--no-emit-project'], { cwd: manifestDir }).toString();
40
40
  }
41
41
  /**
42
42
  * Parse uv export output into a dependency graph using tree-sitter-requirements
@@ -70,6 +70,9 @@ export default class Python_uv extends Base_pyproject {
70
70
  let version = memberParsed.project?.version || memberParsed.tool?.poetry?.version;
71
71
  if (name && version) {
72
72
  let key = this._canonicalize(name);
73
+ if (key === canonProjectName) {
74
+ continue;
75
+ }
73
76
  currentPkg = { name, version, parents: new Set() };
74
77
  packages.set(key, currentPkg);
75
78
  collectingVia = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trustify-da/trustify-da-javascript-client",
3
- "version": "0.3.0-ea.1684e79",
3
+ "version": "0.3.0-ea.2e5fe72",
4
4
  "description": "Code-Ready Dependency Analytics JavaScript API.",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/guacsec/trustify-da-javascript-client#README.md",