feat(dlx): prompt to approve ignored builds#11452
Conversation
`pnpm dlx`/`pnpx`/`pnx`/`pnpm create` now run the same interactive `approve-builds` flow as `pnpm add -g` when the launched package depends on transitive packages with install scripts. Previously, the `strictDepBuilds` default in v11 made dlx fail with `ERR_PNPM_IGNORED_BUILDS` and required users to re-invoke with `--allow-build=<pkg>` for every offending dependency. dlx also now removes the partially-populated cache directory on install failure, so a subsequent run starts clean instead of reusing a broken install whose builds had been silently skipped.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughdlx and create now accept an optional commands map; dlx computes and passes an allowBuilds map to installs, runs an approve-builds prompt (TTY-guarded, with a test env override) when transitive install-script dependencies are ignored, and removes partially-populated dlx cache directories on failed installs. Types, exports, tests, and packaging refs were updated. Changesdlx approve-builds flow and cache cleanup
Sequence Diagram(s)sequenceDiagram
participant User
participant DLX as dlx
participant Add as add.handler
participant Policy as building.commands
participant FS as Filesystem
User->>DLX: pnpm dlx <package> ...
DLX->>FS: check cachedDir exists?
alt cache miss
DLX->>Add: add.handler(..., allowBuilds, strictDepBuilds:false)
Add->>FS: populate cachedDir (install artifacts)
DLX->>Policy: getAutomaticallyIgnoredBuilds(cachedDir)
alt ignored builds present and approval allowed (TTY or TEST env)
DLX->>Policy: approve-builds(allowBuilds[, all:true in test])
Policy-->>Add: allow selected builds
Add->>FS: run allowed build scripts / re-run install
end
DLX->>FS: mark completedDir
else parallel-recovery failure (no completedDir)
DLX->>FS: rm cachedDir (recursive, force)
DLX-->>User: rethrow error
end
DLX-->>User: execute target package
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Review rate limit: 9/10 reviews remaining, refill in 6 minutes. Comment |
📝 WalkthroughWalkthroughThe PR enables ChangesInteractive Build Approval Flow in dlx
Sequence DiagramsequenceDiagram
actor User
participant dlx as dlx.handler
participant add as add.handler
participant approveBuilds as approve-builds handler
participant fs as Filesystem (cache)
User->>dlx: invoke dlx with package name
dlx->>add: install package & dependencies
add-->>dlx: ERR_PNPM_IGNORED_BUILDS error
alt Test env var OR TTY AND approve-builds handler exists
dlx->>approveBuilds: prompt user to approve builds
approveBuilds-->>dlx: approval response
dlx->>add: retry install with approved builds
add-->>dlx: install success
dlx->>User: execute package
else No approval available
dlx->>fs: delete partially-populated cache
fs-->>dlx: cache cleaned
dlx->>User: rethrow ERR_PNPM_IGNORED_BUILDS
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Review rate limit: 9/10 reviews remaining, refill in 6 minutes. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@exec/commands/src/dlx.ts`:
- Around line 194-215: The call to commands['approve-builds'] can throw (e.g.,
user cancel) and currently bypasses the cachedDir cleanup; wrap the await
commands['approve-builds'](...) call in a try/catch so that on any exception you
call fs.promises.rm(cachedDir, { recursive: true, force: true }) before
rethrowing the error (preserve the original error), ensuring the same cleanup
path used in the else branch when install fails.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: c37e184e-e561-46b3-b56d-83954bb5ac4e
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (6)
.changeset/fix-dlx-prompt-approve-builds.mdexec/commands/package.jsonexec/commands/src/create.tsexec/commands/src/dlx.tsexec/commands/test/dlx.e2e.tsexec/commands/tsconfig.json
…uilds Mirror the global install flow: instead of letting `add.handler` throw on transitive deps with unrun build scripts and recovering from the error, dlx now sets `strictDepBuilds: false` for its install and uses `getAutomaticallyIgnoredBuilds` to detect skipped builds afterwards. The same `approve-builds` prompt is then run for those builds (or skipped silently in non-interactive mode, matching `pnpm add -g`). This addresses the review feedback that the previous catch-the-error approach was hard to reason about — the install no longer relies on strictDepBuilds being true to detect ignored builds, so there is no error path to recover from inside the IGNORED_BUILDS branch. Also exports `getAutomaticallyIgnoredBuilds` from `@pnpm/building.commands` so dlx (and other consumers) can detect skipped builds without duplicating modules-manifest reading logic, and adds `strictDepBuilds` to `InstallCommandOptions` (already accepted at runtime) so `add.handler` callers can override it explicitly.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@exec/commands/src/dlx.ts`:
- Around line 292-299: Detect skipped builds (call getAutomaticallyIgnoredBuilds
and inspect automaticallyIgnoredBuilds) before the early returns that check
commands?.['approve-builds'] and the interactive check
(autoApproveForTests/process.stdin.isTTY); if skipped builds exist and there is
no available recovery path (no approve-builds command and non-interactive
without AUTO_APPROVE_FOR_TESTS), do not let the caller treat opts.cachedDir as a
completed reusable dlx cache entry—return or mark the cache as non-final so the
directory is not linked into the shared cache. Ensure you reference the same
symbols: commands?.['approve-builds'], autoApproveForTests, process.stdin.isTTY,
getAutomaticallyIgnoredBuilds, automaticallyIgnoredBuilds, and opts.cachedDir
when implementing this reorder and early-exit behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 5c2f50d5-6a17-4087-87bc-80b04bcf3155
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (7)
.changeset/fix-dlx-prompt-approve-builds.mdbuilding/commands/src/index.tsbuilding/commands/src/policy/index.tsexec/commands/package.jsonexec/commands/src/dlx.tsexec/commands/test/dlx.e2e.tsinstalling/commands/src/install.ts
✅ Files skipped from review due to trivial changes (2)
- building/commands/src/policy/index.ts
- .changeset/fix-dlx-prompt-approve-builds.md
🚧 Files skipped from review as they are similar to previous changes (2)
- exec/commands/package.json
- exec/commands/test/dlx.e2e.ts
…ctively Mirror the same trade-off pnpm add -g makes: a non-interactive install with skipped build scripts is committed and reusable. Users who need those scripts to run can re-invoke dlx with --allow-build=<pkg>, which produces a different cache key and forces a fresh install.
Update pnpm version to patch and improve dlx prompt behavior for transitive packages. Ensure clean cache on install failure.
`pnpm dlx` (and `pnpx`/`pnx`/`pnpm create`) now mirrors the `pnpm add -g` flow when the launched package's transitive deps have install scripts: - dlx overrides `strictDepBuilds: false` for its install so the v11 default no longer turns ignored builds into an `ERR_PNPM_IGNORED_BUILDS` error. Without this, `pnpx @google/gemini-cli` (and similar — `node-pty`, `@github/keytar`) failed outright and forced users to retry with `--allow-build=<pkg>` for every offending dependency. - After install, dlx detects skipped builds via `getAutomaticallyIgnoredBuilds` and runs the same interactive `approve-builds` prompt as `pnpm add -g`. In non-interactive mode the install is committed with builds skipped, matching `pnpm add -g` in CI; users who need those scripts can re-invoke with `--allow-build=<pkg>` to force a fresh cache key. - If the install errors for unrelated reasons (network, etc.) the partially-populated prepare directory is removed so the next dlx run starts clean. Closes #11444. ### Plumbing - Exports `getAutomaticallyIgnoredBuilds` from `@pnpm/building.commands` so dlx can detect skipped builds without re-implementing modules-yaml reading. - Adds `strictDepBuilds` (optional) to `InstallCommandOptions` — already accepted at runtime via the spread, this just makes it explicit at the type level so callers can override it.
Summary
pnpm dlx(andpnpx/pnx/pnpm create) now mirrors thepnpm add -gflow when the launched package's transitive deps have install scripts:strictDepBuilds: falsefor its install so the v11 default no longer turns ignored builds into anERR_PNPM_IGNORED_BUILDSerror. Without this,pnpx @google/gemini-cli(and similar —node-pty,@github/keytar) failed outright and forced users to retry with--allow-build=<pkg>for every offending dependency.getAutomaticallyIgnoredBuildsand runs the same interactiveapprove-buildsprompt aspnpm add -g. In non-interactive mode the install is committed with builds skipped, matchingpnpm add -gin CI; users who need those scripts can re-invoke with--allow-build=<pkg>to force a fresh cache key.Closes #11444.
Plumbing
getAutomaticallyIgnoredBuildsfrom@pnpm/building.commandsso dlx can detect skipped builds without re-implementing modules-yaml reading.strictDepBuilds(optional) toInstallCommandOptions— already accepted at runtime via the spread, this just makes it explicit at the type level so callers can override it.Test plan
exec/commands/test/dlx.e2e.ts:approve-buildsand the build artifacts end up in the dlx cache when invoked with a commands map andPNPM_AUTO_APPROVE_BUILDS_FOR_TESTS=1@pnpm/exec.commandsdlx e2e tests continue to pass@pnpm/exec.commandscreate tests updated to assert the new third (commands) argument forwarded fromcreate.handlertodlx.handlerSummary by CodeRabbit
New Features
pnpm dlx(includingpnpx,pnx, andpnpm create) now uses an interactive prompt to approve package builds when transitive dependencies contain install scripts, consistent withpnpm add -gbehavior.Bug Fixes
pnpm dlxnow cleans up partially populated cache directories when installation fails, preventing reuse of broken installations.