Skip to content
Open
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
4 changes: 3 additions & 1 deletion sources/commands/Base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ export abstract class BaseCommand extends Command<Context> {
async resolvePatternsToDescriptors({patterns}: {patterns: Array<string>}) {
const resolvedSpecs = patterns.map(pattern => specUtils.parseSpec(pattern, `CLI arguments`, {enforceExactVersion: false}));

// Always load spec to ensure .corepack.env is read before any registry calls
const lookup = await specUtils.loadSpec(this.context.cwd);

if (resolvedSpecs.length === 0) {
const lookup = await specUtils.loadSpec(this.context.cwd);
switch (lookup.type) {
case `NoProject`:
throw new UsageError(`Couldn't find a project in the local directory - please specify the package manager to pack, or run this command from a valid project`);
Expand Down
22 changes: 22 additions & 0 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1317,6 +1317,28 @@ it(`should download latest pnpm from custom registry`, async () => {
});
});

it(`should use COREPACK_NPM_REGISTRY from .corepack.env for "corepack use" command`, async t => {
// Skip that test on Node.js 18.x as it lacks support for .env files.
if (process.version.startsWith(`v18.`)) t.skip();

process.env.COREPACK_ENABLE_NETWORK = `0`;

await xfs.mktempPromise(async cwd => {
await xfs.writeJsonPromise(ppath.join(cwd, `package.json` as Filename), {});

// Set COREPACK_NPM_REGISTRY in .corepack.env
await xfs.writeFilePromise(ppath.join(cwd, `.corepack.env` as Filename), `COREPACK_NPM_REGISTRY=http://custom-registry.example.com\n`);

// "corepack use pnpm" should read .corepack.env and use the custom registry
// When network is disabled, the error message should contain the custom registry URL
await expect(runCli(cwd, [`use`, `pnpm`])).resolves.toMatchObject({
stdout: ``,
stdout: expect.stringContaining(`custom-registry.example.com`),
exitCode: 1,
});
});
});

describe(`should pick up COREPACK_INTEGRITY_KEYS from env`, () => {
beforeEach(() => {
process.env.AUTH_TYPE = `COREPACK_NPM_TOKEN`; // See `_registryServer.mjs`
Expand Down