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

Checks if the new corepack home folder exists and creates it if necessary (Fix for issue #198) #200

Merged
merged 11 commits into from
Oct 28, 2022
4 changes: 4 additions & 0 deletions sources/commands/Hydrate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Command, Option, UsageError} from 'clipanion';
import {mkdir} from 'fs/promises';
import path from 'path';

import * as folderUtils from '../folderUtils';
Expand Down Expand Up @@ -36,6 +37,9 @@ export class HydrateCommand extends Command<Context> {

const {default: tar} = await import(/* webpackMode: 'eager' */ `tar`);

// Recreate the folder in case it was deleted somewhere else:
await mkdir(installFolder, {recursive: true});
aduh95 marked this conversation as resolved.
Show resolved Hide resolved

await tar.t({file: fileName, onentry: entry => {
const segments = entry.header.path.split(/\//g);

Expand Down
38 changes: 38 additions & 0 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,44 @@ it(`should support hydrating package managers from cached archives`, async () =>
});
});

it(`should support hydrating package managers if cache folder does not exist`, async () => {
aduh95 marked this conversation as resolved.
Show resolved Hide resolved
await xfs.mktempPromise(async cwd => {
await expect(runCli(cwd, [`prepare`, `yarn@2.2.2`, `-o`])).resolves.toMatchObject({
exitCode: 0,
stderr: ``,
});

// Use a new cache
process.env.COREPACK_HOME = npath.fromPortablePath(await xfs.mktempPromise());

// Simulate cache removal
await xfs.removePromise(npath.toPortablePath(process.env.COREPACK_HOME));

// Disable the network to make sure we don't succeed by accident
process.env.COREPACK_ENABLE_NETWORK = `0`;

try {
await expect(runCli(cwd, [`hydrate`, `corepack.tgz`])).resolves.toMatchObject({
stdout: `Hydrating yarn@2.2.2...\nAll done!\n`,
stderr: ``,
exitCode: 0,
});

await xfs.writeJsonPromise(ppath.join(cwd, `package.json` as Filename), {
packageManager: `yarn@2.2.2`,
});

await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({
stdout: `2.2.2\n`,
stderr: ``,
exitCode: 0,
});
} finally {
delete process.env.COREPACK_ENABLE_NETWORK;
}
});
});

it(`should support hydrating multiple package managers from cached archives`, async () => {
await xfs.mktempPromise(async cwd => {
await expect(runCli(cwd, [`prepare`, `yarn@2.2.2`, `pnpm@5.8.0`, `-o`])).resolves.toMatchObject({
Expand Down