From 07b3ba92fc4ed5a67e16cd304d66adc765466a6b Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sat, 13 Apr 2024 12:20:19 +0200 Subject: [PATCH 1/4] fix: add path to `package.json` in error message --- sources/Engine.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/Engine.ts b/sources/Engine.ts index aeec58442..5c1ac092b 100644 --- a/sources/Engine.ts +++ b/sources/Engine.ts @@ -278,7 +278,7 @@ export class Engine { if (transparent) { return fallbackDescriptor; } else { - throw new UsageError(`This project is configured to use ${result.spec.name}`); + throw new UsageError(`This project is configured to use ${result.spec.name} because ${result.target} defines a "packageManager" field`); } } else { return result.spec; From aae48d5145f4ce441dacee23e08c1ba0c928d2aa Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sat, 13 Apr 2024 13:17:41 +0200 Subject: [PATCH 2/4] fixup --- tests/main.test.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/main.test.ts b/tests/main.test.ts index 8df247e52..dc1ade761 100644 --- a/tests/main.test.ts +++ b/tests/main.test.ts @@ -419,7 +419,9 @@ it(`should refuse to run a different package manager within a configured project process.env.FORCE_COLOR = `0`; await expect(runCli(cwd, [`pnpm`, `--version`])).resolves.toMatchObject({ - stdout: `Usage Error: This project is configured to use yarn\n\n$ pnpm ...\n`, + stdout: `Usage Error: This project is configured to use yarn because ${ + ppath.join(cwd, `package.json` as Filename) + } defines a "packageManager" field\n\n$ pnpm ...\n`, exitCode: 1, }); From f1e6c342bb624759ada12769d1f0603c9e8954d0 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sat, 13 Apr 2024 15:26:04 +0200 Subject: [PATCH 3/4] Apply suggestions from code review Co-authored-by: Steven --- sources/Engine.ts | 2 +- tests/main.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sources/Engine.ts b/sources/Engine.ts index 5c1ac092b..5456336df 100644 --- a/sources/Engine.ts +++ b/sources/Engine.ts @@ -278,7 +278,7 @@ export class Engine { if (transparent) { return fallbackDescriptor; } else { - throw new UsageError(`This project is configured to use ${result.spec.name} because ${result.target} defines a "packageManager" field`); + throw new UsageError(`This project is configured to use ${result.spec.name} because ${result.target} has a "packageManager" field`); } } else { return result.spec; diff --git a/tests/main.test.ts b/tests/main.test.ts index dc1ade761..0410f3ede 100644 --- a/tests/main.test.ts +++ b/tests/main.test.ts @@ -421,7 +421,7 @@ it(`should refuse to run a different package manager within a configured project await expect(runCli(cwd, [`pnpm`, `--version`])).resolves.toMatchObject({ stdout: `Usage Error: This project is configured to use yarn because ${ ppath.join(cwd, `package.json` as Filename) - } defines a "packageManager" field\n\n$ pnpm ...\n`, + } has a "packageManager" field\n\n$ pnpm ...\n`, exitCode: 1, }); From f7d5725e56c33707e63d218fe7f126d025d290ab Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Mon, 15 Apr 2024 20:04:28 +0200 Subject: [PATCH 4/4] fix Windows tests --- tests/main.test.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/main.test.ts b/tests/main.test.ts index 0410f3ede..e8d764e9b 100644 --- a/tests/main.test.ts +++ b/tests/main.test.ts @@ -1,6 +1,7 @@ import {beforeEach, describe, expect, it} from '@jest/globals'; import {Filename, ppath, xfs, npath, PortablePath} from '@yarnpkg/fslib'; import os from 'node:os'; +import path from 'node:path'; import process from 'node:process'; import config from '../config.json'; @@ -420,7 +421,8 @@ it(`should refuse to run a different package manager within a configured project await expect(runCli(cwd, [`pnpm`, `--version`])).resolves.toMatchObject({ stdout: `Usage Error: This project is configured to use yarn because ${ - ppath.join(cwd, `package.json` as Filename) + // ppath and xfs do not format Windows correctly, the regex fixes that: + path.join(cwd.replace(/^\/([a-zA-Z]:)\//, `$1\\`), `package.json`) } has a "packageManager" field\n\n$ pnpm ...\n`, exitCode: 1, });