diff --git a/packages/zpm/src/commands/dlx.rs b/packages/zpm/src/commands/dlx.rs index b5b62ec3..f40008b0 100644 --- a/packages/zpm/src/commands/dlx.rs +++ b/packages/zpm/src/commands/dlx.rs @@ -158,6 +158,7 @@ pub async fn install_dependencies(workspace_path: &Path, loose_resolutions: Vec< project .run_install(RunInstallOptions { silent_or_error: quiet, + skip_constraints_check: true, enforced_resolutions, ..Default::default() }).await?; diff --git a/packages/zpm/src/project.rs b/packages/zpm/src/project.rs index 7f811de6..35dc9d23 100644 --- a/packages/zpm/src/project.rs +++ b/packages/zpm/src/project.rs @@ -125,6 +125,8 @@ pub struct RunInstallOptions { pub refresh_lockfile: bool, pub roots: Option>, pub silent_or_error: bool, + /// Temporary installs have no constraints configuration to check. + pub skip_constraints_check: bool, pub json: bool, pub inline_builds: bool, pub force: bool, @@ -1675,7 +1677,7 @@ impl Project { .with_previous_state(self.install_state.as_ref()) .with_roots(roots) .with_installed_workspaces(options.roots.clone()) - .with_constraints_check(!options.silent_or_error && self.config.settings.enable_constraints_checks.value && options.roots.is_none()) + .with_constraints_check(!options.silent_or_error && !options.skip_constraints_check && self.config.settings.enable_constraints_checks.value && options.roots.is_none()) .with_skip_link_step(options.mode == Some(InstallMode::UpdateLockfile)) .with_skip_lockfile_update(options.roots.is_some()) .with_force(options.force) diff --git a/tests/acceptance-tests/pkg-tests-specs/sources/commands/dlx.test.js b/tests/acceptance-tests/pkg-tests-specs/sources/commands/dlx.test.js index 93cfb16d..1ac5d539 100644 --- a/tests/acceptance-tests/pkg-tests-specs/sources/commands/dlx.test.js +++ b/tests/acceptance-tests/pkg-tests-specs/sources/commands/dlx.test.js @@ -96,6 +96,27 @@ describe(`Commands`, () => { }), ); + test( + `it should skip the caller's constraints for temporary installs while checking normal installs`, + makeTemporaryEnv({}, async ({path, run}) => { + await yarn.writeConfiguration(path, { + enableConstraintsChecks: true, + }); + + await writeFile(`${path}/yarn.config.cjs`, [ + `exports.constraints = ({ Yarn }) => {`, + ` for (const workspace of Yarn.workspaces()) {`, + ` workspace.set('foo', 'bar');`, + ` }`, + `};`, + ].join(`\n`)); + + await expect(run(`dlx`, `has-bin-entries`)).resolves.toBeDefined(); + + await expect(run(`install`)).rejects.toThrow(/Constraint check failed; run yarn constraints for more details/); + }), + ); + test( `it shouldn't warn on unused package extensions in projects created by dlx (dependencies)`, makeTemporaryEnv(