Skip to content

Commit 2e21f9b

Browse files
ruromeroclaude
andcommitted
refactor: use TRUSTIFY_DA_WORKSPACE_DIR convention consistently
Remove the opts.workspaceDir fallback pattern and use only the TRUSTIFY_DA_WORKSPACE_DIR key through getCustom(), keeping the existing single-convention pattern for option propagation. TC-3862 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 01b45a5 commit 2e21f9b

7 files changed

Lines changed: 24 additions & 24 deletions

File tree

src/cli.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const component = {
3131
}),
3232
handler: async args => {
3333
let manifestName = args['/path/to/manifest']
34-
const opts = args.workspaceDir ? { workspaceDir: args.workspaceDir } : {}
34+
const opts = args.workspaceDir ? { TRUSTIFY_DA_WORKSPACE_DIR: args.workspaceDir } : {}
3535
let res = await client.componentAnalysis(manifestName, opts)
3636
console.log(JSON.stringify(res, null, 2))
3737
}
@@ -157,7 +157,7 @@ const stack = {
157157
let manifest = args['/path/to/manifest']
158158
let html = args['html']
159159
let summary = args['summary']
160-
const opts = args.workspaceDir ? { workspaceDir: args.workspaceDir } : {}
160+
const opts = args.workspaceDir ? { TRUSTIFY_DA_WORKSPACE_DIR: args.workspaceDir } : {}
161161
let theProvidersSummary = new Map();
162162
let theProvidersObject ={}
163163
let res = await client.stackAnalysis(manifest, html, opts)

src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export {
6565
* TRUSTIFY_DA_SOURCE?: string | undefined,
6666
* TRUSTIFY_DA_TOKEN?: string | undefined,
6767
* TRUSTIFY_DA_TELEMETRY_ID?: string | undefined,
68-
* workspaceDir?: string | undefined,
68+
* TRUSTIFY_DA_WORKSPACE_DIR?: string | undefined,
6969
* batchConcurrency?: number | undefined,
7070
* TRUSTIFY_DA_BATCH_CONCURRENCY?: string | undefined,
7171
* workspaceDiscoveryIgnore?: string[] | undefined,
@@ -280,7 +280,7 @@ function buildBatchAnalysisMetadata(root, ecosystem, totalSbomAttempts, successf
280280
* Generate an SBOM for a single manifest, returning a normalized result.
281281
*
282282
* @param {string} manifestPath
283-
* @param {Options} workspaceOpts - opts with `workspaceDir` set
283+
* @param {Options} workspaceOpts - opts with `TRUSTIFY_DA_WORKSPACE_DIR` set
284284
* @returns {Promise<SbomResult>}
285285
* @private
286286
*/
@@ -473,7 +473,7 @@ async function stackAnalysisBatch(workspaceRoot, html = false, opts = {}) {
473473
throw new Error(`No workspace manifests found at ${root}. Ensure Cargo.toml+Cargo.lock or package.json+lock file exist.`)
474474
}
475475

476-
const workspaceOpts = { ...opts, workspaceDir: root }
476+
const workspaceOpts = { ...opts, TRUSTIFY_DA_WORKSPACE_DIR: root }
477477
const concurrency = resolveBatchConcurrency(opts)
478478

479479
let sbomByPurl

src/provider.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export function matchForLicense(manifestPath, providers) {
5151
* Each provider MUST export 'provideStack' taking manifest path returning a {@link Provided}.
5252
* @param {string} manifest - the name-type or path of the manifest
5353
* @param {[Provider]} providers - list of providers to iterate over
54-
* @param {{workspaceDir?: string, TRUSTIFY_DA_WORKSPACE_DIR?: string}} [opts={}] - optional; workspaceDir (or TRUSTIFY_DA_WORKSPACE_DIR) overrides lock file location for workspaces
54+
* @param {{TRUSTIFY_DA_WORKSPACE_DIR?: string}} [opts={}] - optional; TRUSTIFY_DA_WORKSPACE_DIR overrides lock file location for workspaces
5555
* @returns {Provider}
5656
* @throws {Error} when the manifest is not supported and no provider was matched
5757
*/

src/providers/base_javascript.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,14 @@ export default class Base_javascript {
113113

114114
/**
115115
* Checks if a required lock file exists in the manifest directory or at the workspace root.
116-
* When workspaceDir is provided (e.g. from TRUSTIFY_DA_WORKSPACE_DIR or opts.workspaceDir),
116+
* When TRUSTIFY_DA_WORKSPACE_DIR is provided (via env var or opts),
117117
* checks only that directory for the lock file.
118118
* @param {string} manifestDir - The base directory where the manifest is located
119-
* @param {{workspaceDir?: string, TRUSTIFY_DA_WORKSPACE_DIR?: string}} [opts={}] - optional workspace root
119+
* @param {{TRUSTIFY_DA_WORKSPACE_DIR?: string}} [opts={}] - optional workspace root
120120
* @returns {boolean} True if the lock file exists
121121
*/
122122
validateLockFile(manifestDir, opts = {}) {
123-
const workspaceDir = getCustom('TRUSTIFY_DA_WORKSPACE_DIR', null, opts) ?? opts.workspaceDir
123+
const workspaceDir = getCustom('TRUSTIFY_DA_WORKSPACE_DIR', null, opts)
124124
const dirToCheck = workspaceDir ? path.resolve(workspaceDir) : manifestDir
125125
const lock = path.join(dirToCheck, this._lockFileName())
126126
return fs.existsSync(lock)
@@ -181,14 +181,14 @@ export default class Base_javascript {
181181
/**
182182
* Builds the dependency tree for the project
183183
* @param {boolean} includeTransitive - Whether to include transitive dependencies
184-
* @param {Object} [opts={}] - Configuration options; when `workspaceDir` is set, commands run from workspace root
184+
* @param {Object} [opts={}] - Configuration options; when `TRUSTIFY_DA_WORKSPACE_DIR` is set, commands run from workspace root
185185
* @returns {Object} The dependency tree
186186
* @protected
187187
*/
188188
_buildDependencyTree(includeTransitive, opts = {}) {
189189
this._version();
190190
const manifestDir = path.dirname(this.#manifest.manifestPath);
191-
const workspaceDir = getCustom('TRUSTIFY_DA_WORKSPACE_DIR', null, opts) ?? opts.workspaceDir
191+
const workspaceDir = getCustom('TRUSTIFY_DA_WORKSPACE_DIR', null, opts)
192192
const cmdDir = workspaceDir ? path.resolve(workspaceDir) : manifestDir;
193193
this.#createLockFile(cmdDir);
194194

src/providers/rust_cargo.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,14 @@ function readLicenseFromManifest(manifestPath) {
102102
* up the directory tree looking for Cargo.lock (stopping when we find a
103103
* Cargo.toml that contains a [workspace] section, or when we reach the
104104
* filesystem root).
105-
* When workspaceDir is provided (e.g. from TRUSTIFY_DA_WORKSPACE_DIR or opts.workspaceDir),
105+
* When TRUSTIFY_DA_WORKSPACE_DIR is provided (via env var or opts),
106106
* checks only that directory for Cargo.lock — no walk-up.
107107
* @param {string} manifestDir - the directory where the manifest lies
108-
* @param {{workspaceDir?: string, TRUSTIFY_DA_WORKSPACE_DIR?: string}} [opts={}] - optional workspace root
108+
* @param {{TRUSTIFY_DA_WORKSPACE_DIR?: string}} [opts={}] - optional workspace root
109109
* @returns {boolean} true if Cargo.lock is found
110110
*/
111111
function validateLockFile(manifestDir, opts = {}) {
112-
const workspaceDir = getCustom('TRUSTIFY_DA_WORKSPACE_DIR', null, opts) ?? opts.workspaceDir
112+
const workspaceDir = getCustom('TRUSTIFY_DA_WORKSPACE_DIR', null, opts)
113113
if (workspaceDir) {
114114
const dir = path.resolve(workspaceDir)
115115
return fs.existsSync(path.join(dir, 'Cargo.lock'))

test/providers/javascript.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,17 +152,17 @@ suite('testing the javascript-npm data provider', async () => {
152152
expect(() => new Manifest(manifestPath)).to.throw(Error);
153153
});
154154

155-
test('verify match with opts.workspaceDir finds npm provider when lock is at workspace root', () => {
155+
test('verify match with opts.TRUSTIFY_DA_WORKSPACE_DIR finds npm provider when lock is at workspace root', () => {
156156
const manifest = 'test/providers/provider_manifests/npm/with_lock_file/package.json'
157-
const opts = { workspaceDir: 'test/providers/provider_manifests/npm/with_lock_file' }
157+
const opts = { TRUSTIFY_DA_WORKSPACE_DIR: 'test/providers/provider_manifests/npm/with_lock_file' }
158158
const provider = match(manifest, availableProviders, opts)
159159
expect(provider).to.not.be.null
160160
expect(provider.isSupported('package.json')).to.be.true
161161
})
162162

163-
test('verify match with opts.workspaceDir finds pnpm provider when lock is at workspace root', () => {
163+
test('verify match with opts.TRUSTIFY_DA_WORKSPACE_DIR finds pnpm provider when lock is at workspace root', () => {
164164
const manifest = 'test/providers/provider_manifests/pnpm/with_lock_file/package.json'
165-
const opts = { workspaceDir: 'test/providers/provider_manifests/pnpm/with_lock_file' }
165+
const opts = { TRUSTIFY_DA_WORKSPACE_DIR: 'test/providers/provider_manifests/pnpm/with_lock_file' }
166166
const provider = match(manifest, availableProviders, opts)
167167
expect(provider).to.not.be.null
168168
expect(provider.isSupported('package.json')).to.be.true

test/providers/rust_cargo.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,18 +126,18 @@ suite('testing the rust-cargo data provider', () => {
126126
expect(rustCargo.validateLockFile('test/providers/provider_manifests/cargo/workspace_member_without_lock/member1')).to.equal(false)
127127
})
128128

129-
test('verify validateLockFile with opts.workspaceDir returns true when Cargo.lock exists at workspace root', () => {
129+
test('verify validateLockFile with opts.TRUSTIFY_DA_WORKSPACE_DIR returns true when Cargo.lock exists at workspace root', () => {
130130
const workspaceRoot = 'test/providers/provider_manifests/cargo/workspace_member_with_lock'
131-
expect(rustCargo.validateLockFile('test/providers/provider_manifests/cargo/workspace_member_with_lock/member1', { workspaceDir: workspaceRoot })).to.equal(true)
131+
expect(rustCargo.validateLockFile('test/providers/provider_manifests/cargo/workspace_member_with_lock/member1', { TRUSTIFY_DA_WORKSPACE_DIR: workspaceRoot })).to.equal(true)
132132
})
133133

134-
test('verify validateLockFile with opts.workspaceDir returns false when Cargo.lock is not at workspace root', () => {
134+
test('verify validateLockFile with opts.TRUSTIFY_DA_WORKSPACE_DIR returns false when Cargo.lock is not at workspace root', () => {
135135
const wrongDir = 'test/providers/provider_manifests/cargo/workspace_member_without_lock'
136-
expect(rustCargo.validateLockFile('test/providers/provider_manifests/cargo/workspace_member_with_lock/member1', { workspaceDir: wrongDir })).to.equal(false)
136+
expect(rustCargo.validateLockFile('test/providers/provider_manifests/cargo/workspace_member_with_lock/member1', { TRUSTIFY_DA_WORKSPACE_DIR: wrongDir })).to.equal(false)
137137
})
138138

139-
test('verify match with opts.workspaceDir finds Cargo provider when lock is at workspace root', () => {
140-
const opts = { workspaceDir: 'test/providers/provider_manifests/cargo/workspace_member_with_lock' }
139+
test('verify match with opts.TRUSTIFY_DA_WORKSPACE_DIR finds Cargo provider when lock is at workspace root', () => {
140+
const opts = { TRUSTIFY_DA_WORKSPACE_DIR: 'test/providers/provider_manifests/cargo/workspace_member_with_lock' }
141141
const provider = match('test/providers/provider_manifests/cargo/workspace_member_with_lock/member1/Cargo.toml', availableProviders, opts)
142142
expect(provider).to.not.be.null
143143
expect(provider.isSupported('Cargo.toml')).to.be.true

0 commit comments

Comments
 (0)