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

feat: when strict checking is off, treat like transparent #197

Merged
merged 7 commits into from
Oct 24, 2022
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
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,17 @@ This command will retrieve the given package manager from the specified archive
manager versions that will be required for the projects you'll run, using
`corepack hydrate`).

- `COREPACK_ENABLE_STRICT` can be set to `0` to prevent Corepack from checking
- `COREPACK_ENABLE_STRICT` can be set to `0` to prevent Corepack from throwing error
if the package manager does not correspond to the one defined for the current project.
This means that if a user is using the package manager specified in the current project,
it will use the version specified by the project's `packageManager` field.
But if the user is using other package manager different from the one specified
for the current project, it will use the system-wide package manager version.

- `COREPACK_ENABLE_PROJECT_SPEC` can be set to `0` to prevent Corepack from checking
if the package manager corresponds to the one defined for the current project.
This means that it will always use the system-wide package manager regardless of
what is being specified in the project's `packageManager` field.

- `COREPACK_HOME` can be set in order to define where Corepack should install
the package managers. By default it is set to `%LOCALAPPDATA%\node\corepack`
Expand Down
6 changes: 5 additions & 1 deletion sources/specUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ 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_PROJECT_SPEC === `0`)
return fallbackLocator;

if (process.env.COREPACK_ENABLE_STRICT === `0`)
transparent = true;

while (true) {
const result = await loadSpec(initialCwd);
Expand Down
31 changes: 31 additions & 0 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,14 @@ it(`should refuse to run a different package manager within a configured project
process.env.COREPACK_ENABLE_STRICT = `0`;

try {
await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({
stdout: `1.0.0\n`,
stderr: ``,
exitCode: 0,
});
await expect(runCli(cwd, [`pnpm`, `--version`])).resolves.toMatchObject({
kenrick95 marked this conversation as resolved.
Show resolved Hide resolved
stdout: `${config.definitions.pnpm.default.split(`+`, 1)[0]}\n`,
stderr: ``,
exitCode: 0,
});
} finally {
Expand All @@ -281,6 +287,31 @@ it(`should refuse to run a different package manager within a configured project
});
});


it(`should always use fallback version when project spec env is disabled`, async () => {
await xfs.mktempPromise(async cwd => {
await xfs.writeJsonPromise(ppath.join(cwd, `package.json` as Filename), {
packageManager: `yarn@1.0.0`,
});
process.env.COREPACK_ENABLE_PROJECT_SPEC = `0`;

try {
await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({
stdout: `${config.definitions.yarn.default.split(`+`, 1)[0]}\n`,
stderr: ``,
exitCode: 0,
});
await expect(runCli(cwd, [`pnpm`, `--version`])).resolves.toMatchObject({
stdout: `${config.definitions.pnpm.default.split(`+`, 1)[0]}\n`,
stderr: ``,
exitCode: 0,
});
} finally {
delete process.env.COREPACK_ENABLE_PROJECT_SPEC;
}
});
});

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), {
Expand Down
Binary file modified tests/nock/ToUs5E5EzXCAwMv31KqJGA-1.dat
Binary file not shown.
Binary file modified tests/nock/XtnC4qVqg7VJUOAoKyxAbA-2.dat
Binary file not shown.
Binary file modified tests/nock/h9H6jL9ro_imv61YP24nGg-2.dat
Binary file not shown.
Binary file added tests/nock/h9H6jL9ro_imv61YP24nGg-3.dat
Binary file not shown.
Binary file added tests/nock/ypWhs6_VxInVlmWLHRm3FA-1.dat
Binary file not shown.
Binary file added tests/nock/ypWhs6_VxInVlmWLHRm3FA-2.dat
Binary file not shown.