@storybook/builder-vite 11.0.0-alpha.7 → 11.0.0-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,10 @@
1
- import CJS_COMPAT_NODE_URL_w6355p49d7o from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_w6355p49d7o from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_w6355p49d7o from "node:module";
1
+ import CJS_COMPAT_NODE_URL_lkeljefac2 from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_lkeljefac2 from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_lkeljefac2 from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_w6355p49d7o.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_w6355p49d7o.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_w6355p49d7o.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_lkeljefac2.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_lkeljefac2.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_lkeljefac2.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
@@ -1261,7 +1261,7 @@ function storybookConfigPlugin(options) {
1261
1261
 
1262
1262
  // src/plugins/storybook-optimize-deps-plugin.ts
1263
1263
  import { loadPreviewOrConfigFile } from "storybook/internal/common";
1264
- import { babelParser, extractMockCalls, findMockRedirect } from "storybook/internal/mocking-utils";
1264
+ import { extractMockCalls, findMockRedirect } from "storybook/internal/mocking-utils";
1265
1265
 
1266
1266
  // node_modules/pathe/dist/shared/pathe.ff20891b.mjs
1267
1267
  var _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
@@ -1382,7 +1382,6 @@ function storybookOptimizeDepsPlugin(options) {
1382
1382
  coreOptions: { disableTelemetry: !0 },
1383
1383
  configDir: options.configDir
1384
1384
  },
1385
- babelParser,
1386
1385
  projectRoot,
1387
1386
  findMockRedirect
1388
1387
  )
@@ -1633,9 +1632,6 @@ var SB_VIRTUAL_FILES = {
1633
1632
  function getResolvedVirtualModuleId(virtualModuleId) {
1634
1633
  return `\0${virtualModuleId}`;
1635
1634
  }
1636
- function getOriginalVirtualModuleId(resolvedVirtualModuleId) {
1637
- return resolvedVirtualModuleId.slice(1);
1638
- }
1639
1635
 
1640
1636
  // src/plugins/storybook-project-annotations-plugin.ts
1641
1637
  var VIRTUAL_ID = "virtual:/@storybook/builder-vite/project-annotations.js", RESOLVED_VIRTUAL_ID = getResolvedVirtualModuleId(VIRTUAL_ID);
@@ -1735,7 +1731,6 @@ var ENTRY_PATH = "/vite-inject-mocker-entry.js", viteInjectMockerRuntime = (opti
1735
1731
  // src/plugins/vite-mock/plugin.ts
1736
1732
  import { readFileSync } from "node:fs";
1737
1733
  import {
1738
- babelParser as babelParser2,
1739
1734
  extractMockCalls as extractMockCalls2,
1740
1735
  findMockRedirect as findMockRedirect2,
1741
1736
  getAutomockCode,
@@ -1763,13 +1758,13 @@ function viteMockPlugin(options) {
1763
1758
  viteConfig = config;
1764
1759
  },
1765
1760
  buildStart() {
1766
- mockCalls = extractMockCalls2(options, babelParser2, viteConfig.root, findMockRedirect2);
1761
+ mockCalls = extractMockCalls2(options, viteConfig.root, findMockRedirect2);
1767
1762
  },
1768
1763
  configureServer(server) {
1769
1764
  async function invalidateAffectedFiles(file) {
1770
1765
  if (file === options.previewConfigPath || file.includes("__mocks__")) {
1771
1766
  let oldMockCalls = mockCalls;
1772
- mockCalls = extractMockCalls2(options, babelParser2, viteConfig.root, findMockRedirect2);
1767
+ mockCalls = extractMockCalls2(options, viteConfig.root, findMockRedirect2);
1773
1768
  let previewMod = server.moduleGraph.getModuleById(options.previewConfigPath);
1774
1769
  previewMod && server.moduleGraph.invalidateModule(previewMod);
1775
1770
  for (let call of mockCalls)
@@ -1807,7 +1802,7 @@ function viteMockPlugin(options) {
1807
1802
  }
1808
1803
  try {
1809
1804
  if (!call.redirectPath) {
1810
- let automockedCode = getAutomockCode(code, call.spy, babelParser2);
1805
+ let automockedCode = getAutomockCode(code, call.spy, id);
1811
1806
  return {
1812
1807
  code: automockedCode.toString(),
1813
1808
  map: automockedCode.generateMap().toString()
@@ -1828,7 +1823,7 @@ function viteMockPlugin(options) {
1828
1823
  handler(code, id) {
1829
1824
  if (id === normalizedPreviewConfigPath)
1830
1825
  try {
1831
- return rewriteSbMockImportCalls(code);
1826
+ return rewriteSbMockImportCalls(code, id);
1832
1827
  } catch (e) {
1833
1828
  return logger.debug(`Could not transform sb.mock(import(...)) calls in ${id}: ${e}`), null;
1834
1829
  }
@@ -1845,8 +1840,56 @@ var builderRequire = createRequire(import.meta.url), corePath = dirname(builderR
1845
1840
 
1846
1841
  // src/vite-config.ts
1847
1842
  import { existsSync as existsSync4 } from "node:fs";
1848
- import { resolve as resolve4 } from "node:path";
1849
- import { getBuilderOptions, resolvePathInStorybookCache } from "storybook/internal/common";
1843
+ import { relative as relative3, resolve as resolve4 } from "node:path";
1844
+ import {
1845
+ getBuilderOptions,
1846
+ getProjectRoot,
1847
+ resolvePathInStorybookCache
1848
+ } from "storybook/internal/common";
1849
+ import { once } from "storybook/internal/node-logger";
1850
+
1851
+ // ../../../node_modules/empathic/find.mjs
1852
+ import { join as join3 } from "node:path";
1853
+ import { existsSync, statSync } from "node:fs";
1854
+
1855
+ // ../../../node_modules/empathic/walk.mjs
1856
+ import { dirname as dirname2 } from "node:path";
1857
+
1858
+ // ../../../node_modules/empathic/resolve.mjs
1859
+ import { isAbsolute as isAbsolute2, join as join2, resolve as resolve2 } from "node:path";
1860
+ function absolute(input, root) {
1861
+ return isAbsolute2(input) ? input : resolve2(root || ".", input);
1862
+ }
1863
+
1864
+ // ../../../node_modules/empathic/walk.mjs
1865
+ function up(base, options) {
1866
+ let { last, cwd: cwd2 } = options || {}, tmp = absolute(base, cwd2), root = absolute(last || "/", cwd2), prev, arr = [];
1867
+ for (; prev !== root && (arr.push(tmp), tmp = dirname2(prev = tmp), tmp !== prev); )
1868
+ ;
1869
+ return arr;
1870
+ }
1871
+
1872
+ // ../../../node_modules/empathic/find.mjs
1873
+ function up2(name, options) {
1874
+ let dir, tmp, start = options && options.cwd || "";
1875
+ for (dir of up(start, options))
1876
+ if (tmp = join3(dir, name), existsSync(tmp)) return tmp;
1877
+ }
1878
+ function any(names, options) {
1879
+ let dir, start = options && options.cwd || "", j = 0, len = names.length, tmp, stats, type = options?.type, kind = type ? type === "dir" ? 1 : -1 : 0;
1880
+ for (dir of up(start, options))
1881
+ for (j = 0; j < len; j++)
1882
+ if (tmp = join3(dir, names[j]), kind)
1883
+ try {
1884
+ if (stats = statSync(tmp), kind === 1 ? stats.isDirectory() : stats.isFile()) return tmp;
1885
+ } catch {
1886
+ }
1887
+ else if (existsSync(tmp))
1888
+ return tmp;
1889
+ }
1890
+
1891
+ // src/vite-config.ts
1892
+ import { dedent as dedent4 } from "ts-dedent";
1850
1893
 
1851
1894
  // src/plugins/code-generator-plugin.ts
1852
1895
  import { readFileSync as readFileSync2 } from "node:fs";
@@ -3364,59 +3407,51 @@ async function storybookEntryPlugin(options) {
3364
3407
  }
3365
3408
 
3366
3409
  // src/plugins/webpack-stats-plugin.ts
3367
- import { relative as relative3 } from "node:path";
3368
-
3369
- // ../../../node_modules/slash/index.js
3370
- function slash(path3) {
3371
- return path3.startsWith("\\\\?\\") ? path3 : path3.replace(/\\/g, "/");
3372
- }
3373
-
3374
- // src/plugins/webpack-stats-plugin.ts
3375
- function stripQueryParams(filePath) {
3376
- return filePath.split("?")[0];
3377
- }
3378
- function isUserCode(moduleName) {
3379
- return moduleName ? Object.values(SB_VIRTUAL_FILES).includes(getOriginalVirtualModuleId(moduleName)) ? !0 : !moduleName.startsWith("vite/") && !moduleName.startsWith("\0") && moduleName !== "react/jsx-runtime" : !1;
3410
+ var ROLLUP_VIRTUAL_PREFIX = "\0";
3411
+ function splitQuery(id) {
3412
+ let queryIndex = id.indexOf("?");
3413
+ return queryIndex === -1 ? [id, ""] : [id.slice(0, queryIndex), id.slice(queryIndex)];
3414
+ }
3415
+ function createNormalizer(workingDir, ids) {
3416
+ let filePaths = /* @__PURE__ */ new Set();
3417
+ for (let id of ids)
3418
+ id.startsWith(ROLLUP_VIRTUAL_PREFIX) || filePaths.add(splitQuery(id)[0]);
3419
+ return function(id) {
3420
+ let virtualPrefix = id.startsWith(ROLLUP_VIRTUAL_PREFIX) ? ROLLUP_VIRTUAL_PREFIX : "", unprefixed = id.slice(virtualPrefix.length);
3421
+ if (unprefixed.startsWith("virtual:"))
3422
+ return `/${unprefixed}`;
3423
+ let [path3, query] = splitQuery(unprefixed);
3424
+ return !isAbsolute(path3) || virtualPrefix && !filePaths.has(path3) ? id : `${virtualPrefix}./${relative(workingDir, path3)}${query}`;
3425
+ };
3380
3426
  }
3381
3427
  function pluginWebpackStats({ workingDir }) {
3382
- function normalize3(filename2) {
3383
- if (filename2.startsWith("virtual:"))
3384
- return `/${filename2}`;
3385
- if (Object.values(SB_VIRTUAL_FILES).includes(getOriginalVirtualModuleId(filename2)))
3386
- return `/${getOriginalVirtualModuleId(filename2)}`;
3387
- {
3388
- let relativePath = relative3(workingDir, stripQueryParams(filename2));
3389
- return `./${slash(relativePath)}`;
3390
- }
3428
+ let importersById = /* @__PURE__ */ new Map();
3429
+ function record(id, importer) {
3430
+ let importers = importersById.get(id);
3431
+ importers || (importers = /* @__PURE__ */ new Set(), importersById.set(id, importers)), importer !== void 0 && importers.add(importer);
3391
3432
  }
3392
- function createReasons(importers) {
3393
- return (importers || []).map((i) => ({ moduleName: normalize3(i) }));
3394
- }
3395
- function createStatsMapModule(filename2, importers) {
3396
- return {
3397
- id: filename2,
3398
- name: filename2,
3399
- reasons: createReasons(importers)
3400
- };
3401
- }
3402
- let statsMap = /* @__PURE__ */ new Map();
3403
3433
  return {
3404
3434
  name: "storybook:rollup-plugin-webpack-stats",
3405
3435
  // We want this to run after the vite build plugins (https://vitejs.dev/guide/api-plugin.html#plugin-ordering)
3406
3436
  enforce: "post",
3407
- moduleParsed: function(mod) {
3408
- isUserCode(mod.id) && mod.importedIds.concat(mod.dynamicallyImportedIds).filter((name) => isUserCode(name)).forEach((depIdUnsafe) => {
3409
- let depId = normalize3(depIdUnsafe);
3410
- if (!statsMap.has(depId)) {
3411
- statsMap.set(depId, createStatsMapModule(depId, [mod.id]));
3412
- return;
3413
- }
3414
- let m = statsMap.get(depId);
3415
- m && (m.reasons = (m.reasons ?? []).concat(createReasons([mod.id])).filter((r) => r.moduleName !== depId), statsMap.set(depId, m));
3416
- });
3437
+ moduleParsed(mod) {
3438
+ record(mod.id);
3439
+ for (let depId of mod.importedIds.concat(mod.dynamicallyImportedIds))
3440
+ record(depId, mod.id);
3417
3441
  },
3418
3442
  storybookGetStats() {
3419
- let stats = { modules: Array.from(statsMap.values()) };
3443
+ let normalize3 = createNormalizer(workingDir, importersById.keys()), importerNamesByName = /* @__PURE__ */ new Map();
3444
+ for (let [id, importers] of importersById) {
3445
+ let name = normalize3(id), importerNames = importerNamesByName.get(name) ?? /* @__PURE__ */ new Set();
3446
+ for (let importer of importers)
3447
+ importerNames.add(normalize3(importer));
3448
+ importerNames.delete(name), importerNamesByName.set(name, importerNames);
3449
+ }
3450
+ let stats = { modules: Array.from(importerNamesByName, ([name, importerNames]) => ({
3451
+ id: name,
3452
+ name,
3453
+ reasons: Array.from(importerNames, (moduleName) => ({ moduleName }))
3454
+ })) };
3420
3455
  return { ...stats, toJson: () => stats };
3421
3456
  }
3422
3457
  };
@@ -3446,34 +3481,6 @@ function writable(path3) {
3446
3481
  return ok(path3, constants.W_OK);
3447
3482
  }
3448
3483
 
3449
- // ../../../node_modules/empathic/find.mjs
3450
- import { join as join4 } from "node:path";
3451
- import { existsSync, statSync } from "node:fs";
3452
-
3453
- // ../../../node_modules/empathic/walk.mjs
3454
- import { dirname as dirname3 } from "node:path";
3455
-
3456
- // ../../../node_modules/empathic/resolve.mjs
3457
- import { isAbsolute as isAbsolute3, join as join3, resolve as resolve3 } from "node:path";
3458
- function absolute(input, root) {
3459
- return isAbsolute3(input) ? input : resolve3(root || ".", input);
3460
- }
3461
-
3462
- // ../../../node_modules/empathic/walk.mjs
3463
- function up(base, options) {
3464
- let { last, cwd: cwd2 } = options || {}, tmp = absolute(base, cwd2), root = absolute(last || "/", cwd2), prev, arr = [];
3465
- for (; prev !== root && (arr.push(tmp), tmp = dirname3(prev = tmp), tmp !== prev); )
3466
- ;
3467
- return arr;
3468
- }
3469
-
3470
- // ../../../node_modules/empathic/find.mjs
3471
- function up2(name, options) {
3472
- let dir, tmp, start = options && options.cwd || "";
3473
- for (dir of up(start, options))
3474
- if (tmp = join4(dir, name), existsSync(tmp)) return tmp;
3475
- }
3476
-
3477
3484
  // ../../../node_modules/empathic/package.mjs
3478
3485
  function up3(options) {
3479
3486
  return up2("package.json", options);
@@ -3592,17 +3599,48 @@ var configEnvServe = {
3592
3599
  mode: "production",
3593
3600
  command: "build",
3594
3601
  isSsrBuild: !1
3595
- };
3602
+ }, DEFAULT_VITE_CONFIG_FILES = [
3603
+ "vite.config.js",
3604
+ "vite.config.mjs",
3605
+ "vite.config.ts",
3606
+ "vite.config.cjs",
3607
+ "vite.config.mts",
3608
+ "vite.config.cts"
3609
+ ], warnOnce = once("warn");
3610
+ function reportUnloadedUserViteConfig(configDir, projectRoot) {
3611
+ let root = getProjectRoot();
3612
+ if (relative3(root, projectRoot).startsWith(".."))
3613
+ return;
3614
+ let found = any(DEFAULT_VITE_CONFIG_FILES, {
3615
+ cwd: projectRoot,
3616
+ last: root
3617
+ });
3618
+ if (!found)
3619
+ return;
3620
+ let unloadedConfig = normalize(found);
3621
+ warnOnce(
3622
+ dedent4`
3623
+ No user Vite config was loaded: Storybook auto-discovers a Vite config file in "${projectRoot}" (the directory above your Storybook config dir "${configDir}"), and none was found there.
3624
+ A Vite config was found at "${unloadedConfig}", but it is outside of that directory and was not loaded.
3625
+ To load it, point the "viteConfigPath" builder option at it, e.g. core: { builder: { options: { viteConfigPath: '${unloadedConfig}' } } }.
3626
+ To keep it unloaded and silence this warning, set "viteConfigPath" to null, e.g. core: { builder: { options: { viteConfigPath: null } } }.
3627
+ See: https://storybook.js.org/docs/builders/vite#override-the-default-configuration
3628
+ `
3629
+ );
3630
+ }
3596
3631
  async function loadUserViteConfig(options, type) {
3597
3632
  let configEnv = type === "development" ? configEnvServe : configEnvBuild, { loadConfigFromFile } = await import("vite"), { viteConfigPath, configLoader } = await getBuilderOptions(options), projectRoot = resolve4(options.configDir, "..");
3598
- return (await loadConfigFromFile(
3633
+ if (viteConfigPath === null)
3634
+ return {};
3635
+ let loaded = await loadConfigFromFile(
3599
3636
  configEnv,
3600
3637
  viteConfigPath,
3601
3638
  projectRoot,
3602
3639
  void 0,
3603
3640
  void 0,
3604
3641
  configLoader
3605
- ))?.config ?? {};
3642
+ );
3643
+ return !loaded && viteConfigPath === void 0 && reportUnloadedUserViteConfig(options.configDir, projectRoot), loaded?.config ?? {};
3606
3644
  }
3607
3645
  async function resolveVitePublicDir(options, type) {
3608
3646
  let { publicDir } = await loadUserViteConfig(options, type);
package/dist/index.d.ts CHANGED
@@ -11,7 +11,13 @@ type StorybookConfigVite = {
11
11
  viteFinal?: ViteFinal;
12
12
  };
13
13
  type BuilderOptions = {
14
- /** Path to `vite.config` file, relative to `process.cwd()`. */viteConfigPath?: string;
14
+ /**
15
+ * Path to `vite.config` file, relative to `process.cwd()`.
16
+ *
17
+ * Set to `null` to not load any Vite config file. Use this to keep a config file that
18
+ * Storybook's auto-discovery does not see unloaded, and to silence the matching warning.
19
+ */
20
+ viteConfigPath?: string | null;
15
21
  /**
16
22
  * How Vite loads the config file. Equivalent to Vite's `--configLoader` CLI flag and the
17
23
  * `configLoader` option of `loadConfigFromFile`.
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
- import CJS_COMPAT_NODE_URL_w6355p49d7o from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_w6355p49d7o from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_w6355p49d7o from "node:module";
1
+ import CJS_COMPAT_NODE_URL_lkeljefac2 from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_lkeljefac2 from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_lkeljefac2 from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_w6355p49d7o.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_w6355p49d7o.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_w6355p49d7o.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_lkeljefac2.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_lkeljefac2.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_lkeljefac2.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
@@ -15,7 +15,7 @@ import {
15
15
  bundlerOptionsKey,
16
16
  commonConfig,
17
17
  normalize
18
- } from "./_node-chunks/chunk-2QMODMN7.js";
18
+ } from "./_node-chunks/chunk-SSNOXIF7.js";
19
19
 
20
20
  // ../../../node_modules/picocolors/picocolors.js
21
21
  var require_picocolors = __commonJS({
package/dist/preset.js CHANGED
@@ -1,10 +1,10 @@
1
- import CJS_COMPAT_NODE_URL_w6355p49d7o from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_w6355p49d7o from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_w6355p49d7o from "node:module";
1
+ import CJS_COMPAT_NODE_URL_lkeljefac2 from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_lkeljefac2 from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_lkeljefac2 from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_w6355p49d7o.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_w6355p49d7o.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_w6355p49d7o.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_lkeljefac2.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_lkeljefac2.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_lkeljefac2.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
@@ -13,7 +13,7 @@ import {
13
13
  optimizeViteDeps,
14
14
  staticDirs,
15
15
  viteCorePlugins
16
- } from "./_node-chunks/chunk-2QMODMN7.js";
16
+ } from "./_node-chunks/chunk-SSNOXIF7.js";
17
17
  export {
18
18
  optimizeViteDeps,
19
19
  staticDirs,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/builder-vite",
3
- "version": "11.0.0-alpha.7",
3
+ "version": "11.0.0-alpha.9",
4
4
  "description": "A Storybook builder to dev and build with Vite",
5
5
  "keywords": [
6
6
  "storybook",
@@ -57,11 +57,10 @@
57
57
  "knitwork": "^1.1.0",
58
58
  "magic-string": "^1.1.0",
59
59
  "pathe": "^1.1.2",
60
- "slash": "^5.0.0",
61
60
  "vite": "^7.0.4"
62
61
  },
63
62
  "peerDependencies": {
64
- "storybook": "^11.0.0-alpha.7",
63
+ "storybook": "^11.0.0-alpha.9",
65
64
  "vite": "^6.3.0 || ^7.0.0 || ^8.0.0"
66
65
  },
67
66
  "publishConfig": {