Skip to content

Commit

Permalink
'Cache clean' with multiple packages at once (#5297)
Browse files Browse the repository at this point in the history
* clean multiple modules from cache. fixes #5273

* add a test for 'cache clean' with multiple package names
  • Loading branch information
lankaapura authored and bestander committed Feb 4, 2018
1 parent aee005a commit 7fcf4dd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
14 changes: 14 additions & 0 deletions __tests__/commands/cache.js
Expand Up @@ -147,3 +147,17 @@ test('clean with package name', async (): Promise<void> => {
expect(files.length).toEqual(1); // Only .tmp folder left
});
});

test('clean with multiple package names', async (): Promise<void> => {
await runInstall({}, 'install-production', async (config): Promise<void> => {
let files = await fs.readdir(config.cacheFolder);
expect(files.length).toEqual(3);

const reporter = new BufferReporter();

await run(config, reporter, {}, ['clean', 'is-array', 'left-pad']);
expect(await fs.exists(config.cacheFolder)).toBeTruthy();
files = await fs.readdir(config.cacheFolder);
expect(files.length).toEqual(1); // Only .tmp folder left
});
});
24 changes: 13 additions & 11 deletions src/cli/commands/cache.js
Expand Up @@ -91,20 +91,22 @@ const {run, setFlags: _setFlags, examples} = buildSubCommands('cache', {
const activity = reporter.activity();

if (args.length > 0) {
// Clear named package from cache
const folders = await getPackageCachefolders(args[0]);
for (const arg of args) {
// Clear named package from cache
const folders = await getPackageCachefolders(arg);

if (folders.length === 0) {
activity.end();
reporter.warn(reporter.lang('couldntClearPackageFromCache', arg));
continue;
}

if (folders.length === 0) {
for (const folder of folders) {
await fs.unlink(folder);
}
activity.end();
reporter.warn(reporter.lang('couldntClearPackageFromCache', args[0]));
return;
reporter.success(reporter.lang('clearedPackageFromCache', arg));
}

for (const folder of folders) {
await fs.unlink(folder);
}
activity.end();
reporter.success(reporter.lang('clearedPackageFromCache', args[0]));
} else {
// Clear all cache
await fs.unlink(config._cacheRootFolder);
Expand Down

0 comments on commit 7fcf4dd

Please sign in to comment.