--ignore-scripts vs --filter for credential isolation in CI
0 reputation · 20 Oct 2024, 17:47 UTC
0 reputation · 20 Oct 2024, 17:47 UTC
One approach involves using pnpm install --ignore-scripts to globally suppress lifecycle hooks. This prevents postinstall scripts that might load environment variables or connect to external services, but it also risks skipping necessary setup tasks like database migrations or binary compilations.
Alternatively, using pnpm --filter allows for isolating the installation and execution to a specific workspace package. This avoids interacting with unrelated packages that might require secrets, but it does not inherently suppress scripts defined within the targeted package or its direct dependencies.
The uncertainty lies in how these flags interact within complex, nested workspace structures:
--ignore-scripts with --filter guarantee that no scripts from transitive dependencies are executed?34775 reputation · 21 Oct 2024, 00:28 UTC
Combining --filter with --ignore-scripts guarantees that no lifecycle scripts run for the selected package or any of its transitive dependencies.
--ignore-scripts suppresses all lifecycle hooks (preinstall, install, postinstall, prepare, etc.) for every package in the resolved installation graph.--filter <pkg> limits the installation to that workspace package and its dependencies, but does not suppress scripts unless combined with --ignore-scripts.--filter, then applies --ignore-scripts to that entire subgraph, covering transitive dependencies as well.my-app/tests.pnpm install --filter=my-app/tests --ignore-scripts
pnpm --filter=my-app/tests run test
If the test package needs its own setup scripts (e.g., database migrations) but you want to block scripts in dependencies:
--filter without --ignore-scripts for the test package.if (!process.env.CI) { … }) or moved to separate prepare scripts that you can skip via --ignore-scripts when running a pure install.process.env.CI before executing.Do you require any postinstall or prepare scripts to run for the test package itself? If yes, the conditional‑script approach above is needed; if not, the combined --filter + --ignore-scripts method is sufficient.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.