Skip to content

Commit

Permalink
Merge branch 'next' into fix/cli-rn-skip-ask-for-builder
Browse files Browse the repository at this point in the history
  • Loading branch information
dannyhw authored Jun 13, 2023
2 parents 67f2dcf + ebec58e commit b93b32a
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 16 deletions.
2 changes: 2 additions & 0 deletions code/builders/builder-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@
"@storybook/preview": "7.1.0-alpha.32",
"@storybook/preview-api": "7.1.0-alpha.32",
"@storybook/types": "7.1.0-alpha.32",
"@types/find-cache-dir": "^3.2.1",
"browser-assert": "^1.2.1",
"es-module-lexer": "^0.9.3",
"express": "^4.17.3",
"find-cache-dir": "^3.0.0",
"fs-extra": "^11.1.0",
"magic-string": "^0.30.0",
"remark-external-links": "^8.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { join } from 'node:path';
import findCacheDirectory from 'find-cache-dir';
import { init, parse } from 'es-module-lexer';
import MagicString from 'magic-string';
import { emptyDir, ensureDir, ensureFile, writeFile } from 'fs-extra';
import { ensureFile, writeFile } from 'fs-extra';
import { mergeAlias } from 'vite';
import type { Alias, Plugin } from 'vite';

Expand Down Expand Up @@ -47,9 +48,10 @@ export async function externalGlobalsPlugin(externals: Record<string, string>) {
}
const newAlias = mergeAlias([], config.resolve?.alias) as Alias[];

const cachePath = join(process.cwd(), 'node_modules', '.cache', 'vite-plugin-externals');
await ensureDir(cachePath);
await emptyDir(cachePath);
const cachePath = findCacheDirectory({
name: 'sb-vite-plugin-externals',
create: true,
}) as string;
await Promise.all(
(Object.keys(externals) as Array<keyof typeof externals>).map(async (externalKey) => {
const externalCachePath = join(cachePath, `${externalKey}.js`);
Expand Down
3 changes: 2 additions & 1 deletion code/builders/builder-vite/src/vite-config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as path from 'path';
import { loadConfigFromFile, mergeConfig } from 'vite';
import findCacheDirectory from 'find-cache-dir';
import type {
ConfigEnv,
InlineConfig as ViteInlineConfig,
Expand Down Expand Up @@ -51,7 +52,7 @@ export async function commonConfig(

const sbConfig: InlineConfig = {
configFile: false,
cacheDir: 'node_modules/.cache/.vite-storybook',
cacheDir: findCacheDirectory({ name: 'sb-vite' }),
root: path.resolve(options.configDir, '..'),
// Allow storybook deployed as subfolder. See https://github.com/storybookjs/builder-vite/issues/238
base: './',
Expand Down
2 changes: 2 additions & 0 deletions code/lib/core-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@
"dependencies": {
"@storybook/node-logger": "7.1.0-alpha.32",
"@storybook/types": "7.1.0-alpha.32",
"@types/find-cache-dir": "^3.2.1",
"@types/node": "^16.0.0",
"@types/pretty-hrtime": "^1.0.0",
"chalk": "^4.1.0",
"esbuild": "^0.18.0",
"esbuild-register": "^3.4.0",
"file-system-cache": "^2.0.0",
"find-cache-dir": "^3.0.0",
"find-up": "^5.0.0",
"fs-extra": "^11.1.0",
"glob": "^10.0.0",
Expand Down
14 changes: 3 additions & 11 deletions code/lib/core-common/src/utils/resolve-path-in-sb-cache.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path';
import pkgDir from 'pkg-dir';
import findCacheDirectory from 'find-cache-dir';

/**
* Get the path of the file or directory with input name inside the Storybook cache directory:
Expand All @@ -10,16 +10,8 @@ import pkgDir from 'pkg-dir';
* @return {string} Absolute path to the file or directory
*/
export function resolvePathInStorybookCache(fileOrDirectoryName: string): string {
const cwd = process.cwd();
const projectDir = pkgDir.sync(cwd);

let cacheDirectory;

if (!projectDir) {
cacheDirectory = path.resolve(cwd, '.cache/storybook');
} else {
cacheDirectory = path.resolve(projectDir, 'node_modules/.cache/storybook');
}
let cacheDirectory = findCacheDirectory({ name: 'storybook' });
cacheDirectory ||= path.join(process.cwd(), '.cache/storybook');

return path.join(cacheDirectory, fileOrDirectoryName);
}
4 changes: 4 additions & 0 deletions code/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5849,10 +5849,12 @@ __metadata:
"@storybook/preview-api": 7.1.0-alpha.32
"@storybook/types": 7.1.0-alpha.32
"@types/express": ^4.17.13
"@types/find-cache-dir": ^3.2.1
"@types/node": ^16.0.0
browser-assert: ^1.2.1
es-module-lexer: ^0.9.3
express: ^4.17.3
find-cache-dir: ^3.0.0
fs-extra: ^11.1.0
glob: ^10.0.0
magic-string: ^0.30.0
Expand Down Expand Up @@ -6164,6 +6166,7 @@ __metadata:
dependencies:
"@storybook/node-logger": 7.1.0-alpha.32
"@storybook/types": 7.1.0-alpha.32
"@types/find-cache-dir": ^3.2.1
"@types/mock-fs": ^4.13.1
"@types/node": ^16.0.0
"@types/picomatch": ^2.3.0
Expand All @@ -6172,6 +6175,7 @@ __metadata:
esbuild: ^0.18.0
esbuild-register: ^3.4.0
file-system-cache: ^2.0.0
find-cache-dir: ^3.0.0
find-up: ^5.0.0
fs-extra: ^11.1.0
glob: ^10.0.0
Expand Down

0 comments on commit b93b32a

Please sign in to comment.