Merge pull request #30643 from storybookjs/norbert/cache-dir-in-proper-place

Core: Always place cache dir inside `node_modules`
This commit is contained in:
Valentin Palkovic 2025-02-24 12:53:19 +01:00 committed by GitHub
commit 91d2a08d08
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 2 deletions

View File

@ -635,6 +635,7 @@ jobs:
command: |
cd code
yarn local-registry --open &
yarn wait-on tcp:127.0.0.1:6001
cd ../../
mkdir features-1
cd features-1

View File

@ -13,7 +13,7 @@ import findCacheDirectory from 'find-cache-dir';
*/
export function resolvePathInStorybookCache(fileOrDirectoryName: string, sub = 'default'): string {
let cacheDirectory = findCacheDirectory({ name: 'storybook' });
cacheDirectory ||= join(process.cwd(), '.cache', 'storybook');
cacheDirectory ||= join(process.cwd(), 'node_modules', '.cache', 'storybook');
return join(cacheDirectory, sub, fileOrDirectoryName);
}

View File

@ -177,7 +177,18 @@ export const scaffoldNewProject = async (
// If target directory has a .cache folder, remove it
// so that it does not block the creation of the new project
await rm(`${targetDir}/.cache`, { recursive: true, force: true });
} catch (e) {
//
}
try {
// If target directory has a node_modules folder, remove it
// so that it does not block the creation of the new project
await rm(`${targetDir}/node_modules`, { recursive: true, force: true });
} catch (e) {
//
}
try {
// Create new project in temp directory
await execa.command(createScript, {
stdio: 'pipe',
@ -220,7 +231,7 @@ export const scaffoldNewProject = async (
logger.line(1);
};
const BASE_IGNORED_FILES = ['.git', '.gitignore', '.DS_Store', '.cache'];
const BASE_IGNORED_FILES = ['.git', '.gitignore', '.DS_Store', '.cache', 'node_modules'];
const IGNORED_FILES_BY_PACKAGE_MANAGER: Record<CoercedPackageManagerName, string[]> = {
npm: [...BASE_IGNORED_FILES],