Skip to content

Commit 32a93ea

Browse files
authored
fix: add path to package.json in error message (#456)
1 parent 1423190 commit 32a93ea

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

sources/Engine.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ export class Engine {
263263
if (transparent) {
264264
return fallbackDescriptor;
265265
} else {
266-
throw new UsageError(`This project is configured to use ${result.spec.name}`);
266+
throw new UsageError(`This project is configured to use ${result.spec.name} because ${result.target} has a "packageManager" field`);
267267
}
268268
} else {
269269
return result.spec;

tests/main.test.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {beforeEach, describe, expect, it} from '@jest/globals';
22
import {Filename, ppath, xfs, npath, PortablePath} from '@yarnpkg/fslib';
33
import os from 'node:os';
4+
import path from 'node:path';
45
import process from 'node:process';
56

67
import config from '../config.json';
@@ -419,7 +420,10 @@ it(`should refuse to run a different package manager within a configured project
419420
process.env.FORCE_COLOR = `0`;
420421

421422
await expect(runCli(cwd, [`pnpm`, `--version`])).resolves.toMatchObject({
422-
stdout: `Usage Error: This project is configured to use yarn\n\n$ pnpm ...\n`,
423+
stdout: `Usage Error: This project is configured to use yarn because ${
424+
// ppath and xfs do not format Windows correctly, the regex fixes that:
425+
path.join(cwd.replace(/^\/([a-zA-Z]:)\//, `$1\\`), `package.json`)
426+
} has a "packageManager" field\n\n$ pnpm ...\n`,
423427
exitCode: 1,
424428
});
425429

0 commit comments

Comments
 (0)