mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-26 04:57:50 +02:00
fix(cli): make docusaurus clear also remove .yarn/.cache folder (#6646)
* fix(cli): make clear also remove .yarn/.cache folder * refactor
This commit is contained in:
parent
b16b394eb6
commit
fbbec7fef8
1 changed files with 25 additions and 9 deletions
|
@ -13,20 +13,36 @@ import {
|
||||||
GENERATED_FILES_DIR_NAME,
|
GENERATED_FILES_DIR_NAME,
|
||||||
} from '@docusaurus/utils';
|
} from '@docusaurus/utils';
|
||||||
|
|
||||||
async function removePath(fsPath: string) {
|
async function removePath(entry: {path: string; description: string}) {
|
||||||
|
if (!(await fs.pathExists(entry.path))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
fs.remove(path.join(fsPath));
|
await fs.remove(entry.path);
|
||||||
logger.success`Removed the path=${fsPath} directory.`;
|
logger.success`Removed the ${entry.description} at path=${entry.path}.`;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error`Could not remove path=${fsPath} directory.
|
logger.error`Could not remove the ${entry.description} at path=${
|
||||||
|
entry.path
|
||||||
|
}.
|
||||||
${e as string}`;
|
${e as string}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function clear(siteDir: string): Promise<unknown> {
|
export default async function clear(siteDir: string): Promise<unknown> {
|
||||||
return Promise.all([
|
const generatedFolder = {
|
||||||
removePath(path.join(siteDir, GENERATED_FILES_DIR_NAME)),
|
path: path.join(siteDir, GENERATED_FILES_DIR_NAME),
|
||||||
removePath(path.join(siteDir, DEFAULT_BUILD_DIR_NAME)),
|
description: 'generated folder',
|
||||||
removePath(path.join(siteDir, 'node_modules', '.cache')),
|
};
|
||||||
]);
|
const buildFolder = {
|
||||||
|
path: path.join(siteDir, DEFAULT_BUILD_DIR_NAME),
|
||||||
|
description: 'build output folder',
|
||||||
|
};
|
||||||
|
// In Yarn PnP, cache is stored in `.yarn/.cache` because n_m doesn't exist
|
||||||
|
const cacheFolders = ['node_modules', '.yarn'].map((p) => ({
|
||||||
|
path: path.join(siteDir, p, '.cache'),
|
||||||
|
description: 'Webpack persistent cache folder',
|
||||||
|
}));
|
||||||
|
return Promise.all(
|
||||||
|
[generatedFolder, buildFolder, ...cacheFolders].map(removePath),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue