From c3b73f7dc473ccdf3024bbf30a23f081a7b6ee78 Mon Sep 17 00:00:00 2001 From: Kenrick Date: Thu, 20 Oct 2022 21:47:43 +0800 Subject: [PATCH] feat: when strict checking is off, treat like transparent --- sources/specUtils.ts | 3 ++- tests/main.test.ts | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/sources/specUtils.ts b/sources/specUtils.ts index f587d3276..12a35d8cc 100644 --- a/sources/specUtils.ts +++ b/sources/specUtils.ts @@ -44,7 +44,8 @@ export async function findProjectSpec(initialCwd: string, locator: Locator, {tra // A locator is a valid descriptor (but not the other way around) const fallbackLocator = {name: locator.name, range: locator.reference}; - if (process.env.COREPACK_ENABLE_STRICT === `0`) return fallbackLocator; + if (process.env.COREPACK_ENABLE_STRICT === `0`) + transparent = true; while (true) { const result = await loadSpec(initialCwd); diff --git a/tests/main.test.ts b/tests/main.test.ts index ecc40f2a8..6da2406a7 100644 --- a/tests/main.test.ts +++ b/tests/main.test.ts @@ -281,6 +281,31 @@ it(`should refuse to run a different package manager within a configured project }); }); + +it(`should use project-specified version when strict checking is turned off`, async () => { + await xfs.mktempPromise(async cwd => { + await xfs.writeJsonPromise(ppath.join(cwd, `package.json` as Filename), { + packageManager: `yarn@2.2.2`, + }); + + process.env.COREPACK_ENABLE_STRICT = `0`; + + try { + await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({ + stdout: `2.2.2\n`, + stderr: ``, + exitCode: 0, + }); + await expect(runCli(cwd, [`pnpm`, `--version`])).resolves.toMatchObject({ + stdout: `${config.definitions.pnpm.default.split(`+`, 1)[0]}\n`, + exitCode: 0, + }); + } finally { + delete process.env.COREPACK_ENABLE_STRICT; + } + }); +}); + it(`should allow to call "prepare" with --all to prepare all package managers`, async () => { await xfs.mktempPromise(async cwd => { await xfs.writeJsonPromise(ppath.join(cwd, `package.json` as Filename), {