Skip to content

Commit 9358a86

Browse files
committed
feat(dlx): add CLI-style option names for cognitive consistency
Add option names that align with npm/npx/pnpm CLI flags: DlxPackageOptions: - yes: Skip confirmation prompts (aligns with npx --yes/-y) - force: Force reinstallation (already existed) - quiet: Suppress output (aligns with npx -q, pnpm -s) - reserved for future use - call: Shell command to execute (aligns with npx --call) - reserved for future use DlxBinaryOptions: - yes: Skip confirmation prompts (aligns with npx --yes/-y) - force: Force re-download (already existed) - quiet: Suppress output - reserved for future use Logic updates: - Map yes flag to force behavior in both functions - yes = true implies force = true (auto-approve/skip prompts) This provides cognitive consistency between programmatic API and CLI tools, making the API more intuitive for users familiar with npx/pnpm.
1 parent 13522d4 commit 9358a86

2 files changed

Lines changed: 71 additions & 10 deletions

File tree

src/dlx-binary.ts

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,47 @@ function getFs() {
3737
}
3838

3939
export interface DlxBinaryOptions {
40-
/** URL to download the binary from. */
40+
/**
41+
* URL to download the binary from.
42+
*/
4143
url: string
42-
/** Optional name for the cached binary (defaults to URL hash). */
44+
45+
/**
46+
* Optional name for the cached binary (defaults to URL hash).
47+
*/
4348
name?: string | undefined
44-
/** Expected checksum (sha256) for verification. */
49+
50+
/**
51+
* Expected checksum (sha256) for verification.
52+
*/
4553
checksum?: string | undefined
46-
/** Cache TTL in milliseconds (default: 7 days). */
54+
55+
/**
56+
* Cache TTL in milliseconds (default: 7 days).
57+
*/
4758
cacheTtl?: number | undefined
48-
/** Force re-download even if cached. */
59+
60+
/**
61+
* Force re-download even if cached.
62+
* Aligns with npm/npx --force flag.
63+
*/
4964
force?: boolean | undefined
50-
/** Additional spawn options. */
65+
66+
/**
67+
* Skip confirmation prompts (auto-approve).
68+
* Aligns with npx --yes/-y flag.
69+
*/
70+
yes?: boolean | undefined
71+
72+
/**
73+
* Suppress output (quiet mode).
74+
* Aligns with npx --quiet/-q and pnpm --silent/-s flags.
75+
*/
76+
quiet?: boolean | undefined
77+
78+
/**
79+
* Additional spawn options.
80+
*/
5181
spawnOptions?: SpawnOptions | undefined
5282
}
5383

@@ -367,12 +397,16 @@ export async function dlxBinary(
367397
const {
368398
cacheTtl = /*@__INLINE__*/ require('#constants/time').DLX_BINARY_CACHE_TTL,
369399
checksum,
370-
force = false,
400+
force: userForce = false,
371401
name,
372402
spawnOptions,
373403
url,
404+
yes,
374405
} = { __proto__: null, ...options } as DlxBinaryOptions
375406

407+
// Map --yes flag to force behavior (auto-approve/skip prompts)
408+
const force = yes === true ? true : userForce
409+
376410
// Generate cache paths similar to pnpm/npx structure.
377411
const cacheDir = getDlxCachePath()
378412
const binaryName = name || `binary-${process.platform}-${os.arch()}`

src/dlx-package.ts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,10 @@ export interface DownloadPackageResult {
9696
export interface DlxPackageOptions {
9797
/**
9898
* Package to install (e.g., '@cyclonedx/cdxgen@10.0.0').
99+
* Aligns with npx --package flag.
99100
*/
100101
package: string
102+
101103
/**
102104
* Binary name to execute (optional - auto-detected in most cases).
103105
*
@@ -117,10 +119,31 @@ export interface DlxPackageOptions {
117119
* { package: 'some-tool', binaryName: 'specific-tool' }
118120
*/
119121
binaryName?: string | undefined
122+
120123
/**
121124
* Force reinstallation even if package exists.
125+
* Aligns with npx --yes/-y flag behavior.
122126
*/
123127
force?: boolean | undefined
128+
129+
/**
130+
* Skip confirmation prompts (auto-approve).
131+
* Aligns with npx --yes/-y flag.
132+
*/
133+
yes?: boolean | undefined
134+
135+
/**
136+
* Suppress output (quiet mode).
137+
* Aligns with npx --quiet/-q and pnpm --silent/-s flags.
138+
*/
139+
quiet?: boolean | undefined
140+
141+
/**
142+
* Shell command to execute in package context.
143+
* Aligns with npx --call flag.
144+
*/
145+
call?: string | undefined
146+
124147
/**
125148
* Additional spawn options for the execution.
126149
*/
@@ -449,6 +472,7 @@ export async function downloadPackage(
449472
binaryName,
450473
force: userForce,
451474
package: packageSpec,
475+
yes,
452476
} = {
453477
__proto__: null,
454478
...options,
@@ -458,11 +482,14 @@ export async function downloadPackage(
458482
const { name: packageName, version: packageVersion } =
459483
parsePackageSpec(packageSpec)
460484

461-
// Auto-force for version ranges to get latest within range.
462-
// User can still override with explicit force: false if they want cache.
485+
// Determine force behavior:
486+
// 1. Explicit force takes precedence
487+
// 2. --yes flag implies force (auto-approve/skip prompts)
488+
// 3. Version ranges auto-force to get latest
463489
const isVersionRange =
464490
packageVersion !== undefined && rangeOperatorsRegExp.test(packageVersion)
465-
const force = userForce !== undefined ? userForce : isVersionRange
491+
const force =
492+
userForce !== undefined ? userForce : yes === true ? true : isVersionRange
466493

467494
// Build full package spec for installation.
468495
const fullPackageSpec = packageVersion

0 commit comments

Comments
 (0)