@storybook/builder-vite 10.2.0 → 10.2.2

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_bqjts07fj2 from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_bqjts07fj2 from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_bqjts07fj2 from "node:module";
1
+ import CJS_COMPAT_NODE_URL_mlnq103tfu9 from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_mlnq103tfu9 from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_mlnq103tfu9 from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_bqjts07fj2.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_bqjts07fj2.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_bqjts07fj2.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_mlnq103tfu9.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_mlnq103tfu9.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_mlnq103tfu9.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
- import CJS_COMPAT_NODE_URL_bqjts07fj2 from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_bqjts07fj2 from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_bqjts07fj2 from "node:module";
1
+ import CJS_COMPAT_NODE_URL_mlnq103tfu9 from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_mlnq103tfu9 from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_mlnq103tfu9 from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_bqjts07fj2.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_bqjts07fj2.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_bqjts07fj2.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_mlnq103tfu9.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_mlnq103tfu9.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_mlnq103tfu9.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
@@ -17,7 +17,7 @@ import {
17
17
  normalize,
18
18
  relative,
19
19
  resolve
20
- } from "./_node-chunks/chunk-VCQ7AD7F.js";
20
+ } from "./_node-chunks/chunk-OMFFRC5C.js";
21
21
 
22
22
  // ../../../node_modules/picocolors/picocolors.js
23
23
  var require_picocolors = __commonJS({
package/dist/preset.js CHANGED
@@ -1,101 +1,56 @@
1
- import CJS_COMPAT_NODE_URL_bqjts07fj2 from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_bqjts07fj2 from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_bqjts07fj2 from "node:module";
1
+ import CJS_COMPAT_NODE_URL_mlnq103tfu9 from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_mlnq103tfu9 from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_mlnq103tfu9 from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_bqjts07fj2.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_bqjts07fj2.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_bqjts07fj2.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_mlnq103tfu9.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_mlnq103tfu9.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_mlnq103tfu9.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
11
  // ------------------------------------------------------------
12
12
  import {
13
13
  normalize
14
- } from "./_node-chunks/chunk-VCQ7AD7F.js";
14
+ } from "./_node-chunks/chunk-OMFFRC5C.js";
15
15
 
16
16
  // src/preset.ts
17
17
  import { findConfigFile } from "storybook/internal/common";
18
18
 
19
19
  // src/plugins/vite-inject-mocker/plugin.ts
20
- import { readFileSync } from "node:fs";
21
- import { join } from "node:path";
22
20
  import { fileURLToPath } from "node:url";
23
- import { resolvePackageDir } from "storybook/internal/common";
24
-
25
- // ../../../node_modules/@rolldown/pluginutils/dist/index.js
26
- function exactRegex(str, flags) {
27
- return new RegExp(`^${escapeRegex(str)}$`, flags);
28
- }
29
- var escapeRegexRE = /[-/\\^$*+?.()|[\]{}]/g;
30
- function escapeRegex(str) {
31
- return str.replace(escapeRegexRE, "\\$&");
32
- }
33
-
34
- // src/plugins/vite-inject-mocker/plugin.ts
35
- import { dedent } from "ts-dedent";
36
- var entryPath = "/vite-inject-mocker-entry.js", entryCode = dedent`
37
- <script type="module" src=".${entryPath}"></script>
38
- `, server, viteInjectMockerRuntime = (options) => {
39
- let viteConfig;
21
+ var ENTRY_PATH = "/vite-inject-mocker-entry.js", viteInjectMockerRuntime = (options) => {
22
+ let mockerRuntimePath = fileURLToPath(
23
+ import.meta.resolve("storybook/internal/mocking-utils/mocker-runtime")
24
+ ), viteConfig;
40
25
  return {
41
26
  name: "vite:storybook-inject-mocker-runtime",
27
+ enforce: "pre",
42
28
  buildStart() {
43
29
  viteConfig.command === "build" && this.emitFile({
44
30
  type: "chunk",
45
- id: join(
46
- resolvePackageDir("storybook"),
47
- "assets",
48
- "server",
49
- "mocker-runtime.template.js"
50
- ),
51
- fileName: entryPath.slice(1)
31
+ id: mockerRuntimePath,
32
+ fileName: ENTRY_PATH.slice(1)
52
33
  });
53
34
  },
54
- config() {
55
- return {
56
- optimizeDeps: {
57
- include: ["@vitest/mocker", "@vitest/mocker/browser"]
58
- },
59
- resolve: {
60
- // Aliasing necessary for package managers like pnpm, since resolving modules from a virtual module
61
- // leads to errors, if the imported module is not a dependency of the project.
62
- // By resolving the module to the real path, we can avoid this issue.
63
- alias: {
64
- "@vitest/mocker/browser": fileURLToPath(import.meta.resolve("@vitest/mocker/browser")),
65
- "@vitest/mocker": fileURLToPath(import.meta.resolve("@vitest/mocker"))
66
- }
67
- }
68
- };
69
- },
70
35
  configResolved(config) {
71
36
  viteConfig = config;
72
37
  },
73
- configureServer(server_) {
74
- server = server_, options.previewConfigPath && server.watcher.on("change", (file) => {
38
+ configureServer(server) {
39
+ options.previewConfigPath && server.watcher.on("change", (file) => {
75
40
  file === options.previewConfigPath && server.ws.send({
76
41
  type: "custom",
77
42
  event: "invalidate-mocker"
78
43
  });
79
44
  });
80
45
  },
81
- resolveId: {
82
- filter: {
83
- id: [exactRegex(entryPath)]
84
- },
85
- handler(id) {
86
- return exactRegex(id).test(entryPath) ? id : null;
87
- }
88
- },
89
- async load(id) {
90
- return exactRegex(id).test(entryPath) ? readFileSync(
91
- join(resolvePackageDir("storybook"), "assets", "server", "mocker-runtime.template.js"),
92
- "utf-8"
93
- ) : null;
46
+ resolveId(source) {
47
+ if (source === ENTRY_PATH)
48
+ return mockerRuntimePath;
94
49
  },
95
50
  transformIndexHtml(html) {
96
51
  let headTag = html.match(/<head[^>]*>/);
97
52
  if (headTag) {
98
- let headTagIndex = html.indexOf(headTag[0]);
53
+ let entryCode = `<script type="module" src="${ENTRY_PATH}"></script>`, headTagIndex = html.indexOf(headTag[0]);
99
54
  return html.slice(0, headTagIndex + headTag[0].length) + entryCode + html.slice(headTagIndex + headTag[0].length);
100
55
  }
101
56
  }
@@ -103,24 +58,24 @@ var entryPath = "/vite-inject-mocker-entry.js", entryCode = dedent`
103
58
  };
104
59
 
105
60
  // src/plugins/vite-mock/plugin.ts
106
- import { readFileSync as readFileSync2 } from "node:fs";
61
+ import { readFileSync } from "node:fs";
107
62
  import {
108
63
  babelParser,
109
64
  extractMockCalls,
65
+ findMockRedirect,
110
66
  getAutomockCode,
111
67
  getRealPath,
112
68
  rewriteSbMockImportCalls
113
69
  } from "storybook/internal/mocking-utils";
114
70
  import { logger } from "storybook/internal/node-logger";
115
- import { findMockRedirect } from "@vitest/mocker/redirect";
116
71
 
117
72
  // src/plugins/vite-mock/utils.ts
118
73
  function getCleanId(id) {
119
74
  return id.replace(/^.*\/deps\//, "").replace(/\.js.*$/, "").replace(/_/g, "/");
120
75
  }
121
- function invalidateAllRelatedModules(server2, absPath, pkgName) {
122
- for (let mod of server2.moduleGraph.idToModuleMap.values())
123
- (mod.id === absPath || mod.id && getCleanId(mod.id) === pkgName) && server2.moduleGraph.invalidateModule(mod);
76
+ function invalidateAllRelatedModules(server, absPath, pkgName) {
77
+ for (let mod of server.moduleGraph.idToModuleMap.values())
78
+ (mod.id === absPath || mod.id && getCleanId(mod.id) === pkgName) && server.moduleGraph.invalidateModule(mod);
124
79
  }
125
80
 
126
81
  // src/plugins/vite-mock/plugin.ts
@@ -135,22 +90,22 @@ function viteMockPlugin(options) {
135
90
  buildStart() {
136
91
  mockCalls = extractMockCalls(options, babelParser, viteConfig.root, findMockRedirect);
137
92
  },
138
- configureServer(server2) {
93
+ configureServer(server) {
139
94
  async function invalidateAffectedFiles(file) {
140
95
  if (file === options.previewConfigPath || file.includes("__mocks__")) {
141
96
  let oldMockCalls = mockCalls;
142
97
  mockCalls = extractMockCalls(options, babelParser, viteConfig.root, findMockRedirect);
143
- let previewMod = server2.moduleGraph.getModuleById(options.previewConfigPath);
144
- previewMod && server2.moduleGraph.invalidateModule(previewMod);
98
+ let previewMod = server.moduleGraph.getModuleById(options.previewConfigPath);
99
+ previewMod && server.moduleGraph.invalidateModule(previewMod);
145
100
  for (let call of mockCalls)
146
- invalidateAllRelatedModules(server2, call.absolutePath, call.path);
101
+ invalidateAllRelatedModules(server, call.absolutePath, call.path);
147
102
  let newAbsPaths = new Set(mockCalls.map((c) => c.absolutePath));
148
103
  for (let oldCall of oldMockCalls)
149
- newAbsPaths.has(oldCall.absolutePath) || invalidateAllRelatedModules(server2, oldCall.absolutePath, oldCall.path);
150
- return server2.ws.send({ type: "full-reload" }), [];
104
+ newAbsPaths.has(oldCall.absolutePath) || invalidateAllRelatedModules(server, oldCall.absolutePath, oldCall.path);
105
+ return server.ws.send({ type: "full-reload" }), [];
151
106
  }
152
107
  }
153
- server2.watcher.on("change", invalidateAffectedFiles), server2.watcher.on("add", invalidateAffectedFiles), server2.watcher.on("unlink", invalidateAffectedFiles);
108
+ server.watcher.on("change", invalidateAffectedFiles), server.watcher.on("add", invalidateAffectedFiles), server.watcher.on("unlink", invalidateAffectedFiles);
154
109
  },
155
110
  load: {
156
111
  order: "pre",
@@ -158,7 +113,7 @@ function viteMockPlugin(options) {
158
113
  let preserveSymlinks = viteConfig.resolve.preserveSymlinks, idNorm = getRealPath(id, preserveSymlinks), cleanId = getCleanId(idNorm);
159
114
  for (let call of mockCalls)
160
115
  if (!(getRealPath(call.absolutePath, preserveSymlinks) !== idNorm && call.path !== cleanId) && call.redirectPath)
161
- return this.addWatchFile(call.redirectPath), readFileSync2(call.redirectPath, "utf-8");
116
+ return this.addWatchFile(call.redirectPath), readFileSync(call.redirectPath, "utf-8");
162
117
  return null;
163
118
  }
164
119
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/builder-vite",
3
- "version": "10.2.0",
3
+ "version": "10.2.2",
4
4
  "description": "A Storybook builder to dev and build with Vite",
5
5
  "keywords": [
6
6
  "storybook",
@@ -46,8 +46,7 @@
46
46
  "!src/**/*"
47
47
  ],
48
48
  "dependencies": {
49
- "@storybook/csf-plugin": "10.2.0",
50
- "@vitest/mocker": "3.2.4",
49
+ "@storybook/csf-plugin": "10.2.2",
51
50
  "ts-dedent": "^2.0.0"
52
51
  },
53
52
  "devDependencies": {
@@ -62,7 +61,7 @@
62
61
  "vite": "^7.0.4"
63
62
  },
64
63
  "peerDependencies": {
65
- "storybook": "^10.2.0",
64
+ "storybook": "^10.2.2",
66
65
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0"
67
66
  },
68
67
  "publishConfig": {