feat: add JS workspace discovery and public batch API#415
feat: add JS workspace discovery and public batch API#415a-oren wants to merge 4 commits intoguacsec:mainfrom
Conversation
Add JavaScript/TypeScript monorepo workspace support to the Java client: - Add JsWorkspaceDiscovery utility for parsing pnpm-workspace.yaml and package.json workspaces field to discover member package.json manifests - Add parent-traversal lock file discovery to JavaScriptProviderFactory so workspace members find the lock file at the workspace root - Add stackAnalysisBatch() and stackAnalysisBatchHtml() to Api interface - Implement batch methods in ExhortApi using existing performBatchAnalysis() infrastructure with TRUSTIFY_DA_CONTINUE_ON_ERROR support - Add jackson-dataformat-yaml dependency for YAML parsing - Add comprehensive test suites for workspace discovery and lock file walk-up Implements TC-3863 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
/review |
| var provider = Ecosystem.getProvider(manifest); | ||
| var content = provider.provideStack(); | ||
| var sbomJson = mapper.readTree(content.buffer); | ||
| String key = manifest.getParent().getFileName().toString(); |
There was a problem hiding this comment.
the key must be a purl, not the file name.
Use the sbom metadata.component.purl
|
|
||
| Map<String, JsonNode> getBatchStackSboms( | ||
| final Path workspaceDir, final Set<String> ignorePatterns) { | ||
| boolean continueOnError = Environment.getBoolean("TRUSTIFY_DA_CONTINUE_ON_ERROR", false); |
There was a problem hiding this comment.
This defaults to true in the JS implementation
https://github.com/guacsec/trustify-da-javascript-client/blob/main/src/batch_opts.js#L10
| boolean continueOnError = Environment.getBoolean("TRUSTIFY_DA_CONTINUE_ON_ERROR", false); | ||
| try { | ||
| List<Path> manifests = | ||
| JsWorkspaceDiscovery.discoverWorkspaceManifests(workspaceDir, ignorePatterns); |
There was a problem hiding this comment.
This should be generic and also support Cargo. At this point it should detect the provider and get the manifests for this provider.
As this PR is only for Cargo support, implement only the manifest detection and the provider resolution.
| final Path workspaceDir, final Set<String> ignorePatterns) { | ||
| boolean continueOnError = Environment.getBoolean("TRUSTIFY_DA_CONTINUE_ON_ERROR", false); | ||
| try { | ||
| List<Path> manifests = |
There was a problem hiding this comment.
I recommend that here if the root is not private we also return the root as a folder so that a report for the root is also generated having 1 + N (root + modules)
This is not possible in all package managers but when possible it should be done to provide more information about license and production deps in the root package
- Use purl as SBOM map key instead of directory name - Default TRUSTIFY_DA_CONTINUE_ON_ERROR to true (matching JS client) - Add generic ecosystem detection: Cargo workspace first, then JS - Add Cargo workspace discovery via cargo metadata --no-deps - Add configurable batch concurrency (TRUSTIFY_DA_BATCH_CONCURRENCY) - Add batch metadata logging (TRUSTIFY_DA_BATCH_METADATA) - Add ignore pattern resolution from defaults + env var + caller - Include root package.json when not private (1+N pattern) - Extract shared WorkspaceUtils.filterByIgnorePatterns() utility - Check for JS lock file before attempting JS workspace discovery Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@ruromero Thanks for the review! I pushed the changes |
Summary
JsWorkspaceDiscoveryutility for parsingpnpm-workspace.yamlandpackage.jsonworkspaces field to discover memberpackage.jsonmanifestsJavaScriptProviderFactoryso workspace members find the lock file at the workspace rootstackAnalysisBatch()andstackAnalysisBatchHtml()toApiinterface andExhortApiimplementationjackson-dataformat-yamldependency for YAML parsingDetails
JsWorkspaceDiscoveryis a static utility class that discovers workspacemember packages by parsing
pnpm-workspace.yaml(packages array) orpackage.json(workspaces array/object format). It globs forpackage.jsonfiles, filters by ignore patterns, and validates each manifest has
nameand
versionfields.JavaScriptProviderFactory.create()now walks up parent directories whenno lock file is found in the manifest directory. This enables workspace
member packages to find the single lock file at the workspace root.
The walk-up stops at workspace root boundaries or git root, and supports
TRUSTIFY_DA_WORKSPACE_DIRoverride.The batch API methods delegate to the existing
performBatchAnalysis()infrastructure, following the same pattern as
imageAnalysis(). Config(
TRUSTIFY_DA_CONTINUE_ON_ERROR) is read from environment internally.Implements TC-3863
Test plan
🤖 Generated with Claude Code