Skip to content

Commit

Permalink
fix: add path to package.json in error message (#456)
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 authored Apr 15, 2024
1 parent 1423190 commit 32a93ea
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion sources/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,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} has a "packageManager" field`);
}
} else {
return result.spec;
Expand Down
6 changes: 5 additions & 1 deletion tests/main.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -419,7 +420,10 @@ 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 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,
});

Expand Down

0 comments on commit 32a93ea

Please sign in to comment.