Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add path to package.json in error message #456

Merged
merged 4 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sources/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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} 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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You would use npath.fromPortablePath to handle that.

path.join(cwd.replace(/^\/([a-zA-Z]:)\//, `$1\\`), `package.json`)
} has a "packageManager" field\n\n$ pnpm ...\n`,
exitCode: 1,
});

Expand Down