@storybook/builder-vite 10.3.0-beta.2 → 10.3.0
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
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_d8hah9p1hm from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_d8hah9p1hm from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_d8hah9p1hm from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_d8hah9p1hm.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_d8hah9p1hm.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_d8hah9p1hm.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
@@ -70,6 +70,7 @@ function storybookConfigPlugin(options) {
|
|
|
70
70
|
|
|
71
71
|
// src/plugins/storybook-optimize-deps-plugin.ts
|
|
72
72
|
import { loadPreviewOrConfigFile } from "storybook/internal/common";
|
|
73
|
+
import { babelParser, extractMockCalls, findMockRedirect } from "storybook/internal/mocking-utils";
|
|
73
74
|
|
|
74
75
|
// ../../../node_modules/pathe/dist/shared/pathe.ff20891b.mjs
|
|
75
76
|
var _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
|
|
@@ -163,6 +164,13 @@ function getUniqueImportPaths(index) {
|
|
|
163
164
|
function escapeGlobPath(filePath) {
|
|
164
165
|
return filePath.replace(/[()[\]{}!*?|+@]/g, "\\$&");
|
|
165
166
|
}
|
|
167
|
+
function getMockRedirectIncludeEntries(mockCalls) {
|
|
168
|
+
return Array.from(
|
|
169
|
+
new Set(
|
|
170
|
+
mockCalls.map((mockCall) => mockCall.redirectPath).filter((redirectPath) => redirectPath !== null).map(escapeGlobPath)
|
|
171
|
+
)
|
|
172
|
+
);
|
|
173
|
+
}
|
|
166
174
|
function storybookOptimizeDepsPlugin(options) {
|
|
167
175
|
return {
|
|
168
176
|
name: "storybook:optimize-deps-plugin",
|
|
@@ -173,7 +181,18 @@ function storybookOptimizeDepsPlugin(options) {
|
|
|
173
181
|
options.presets.apply("optimizeViteDeps", []),
|
|
174
182
|
options.presets.apply("storyIndexGenerator"),
|
|
175
183
|
options.presets.apply("previewAnnotations", [], options)
|
|
176
|
-
]), index = await storyIndexGenerator.getIndex(), previewOrConfigFile = loadPreviewOrConfigFile({ configDir: options.configDir }),
|
|
184
|
+
]), index = await storyIndexGenerator.getIndex(), previewOrConfigFile = loadPreviewOrConfigFile({ configDir: options.configDir }), mockRedirectIncludeEntries = previewOrConfigFile ? getMockRedirectIncludeEntries(
|
|
185
|
+
extractMockCalls(
|
|
186
|
+
{
|
|
187
|
+
previewConfigPath: previewOrConfigFile,
|
|
188
|
+
coreOptions: { disableTelemetry: !0 },
|
|
189
|
+
configDir: options.configDir
|
|
190
|
+
},
|
|
191
|
+
babelParser,
|
|
192
|
+
projectRoot,
|
|
193
|
+
findMockRedirect
|
|
194
|
+
)
|
|
195
|
+
) : [], previewAnnotationEntries = [...previewAnnotations, previewOrConfigFile].filter((path2) => path2 !== void 0).map((path2) => processPreviewAnnotation(path2, projectRoot));
|
|
177
196
|
return {
|
|
178
197
|
optimizeDeps: {
|
|
179
198
|
// Story files + preview annotation files as entry points for the dep optimizer.
|
|
@@ -183,6 +202,7 @@ function storybookOptimizeDepsPlugin(options) {
|
|
|
183
202
|
// group directories) are treated as literal characters, not glob syntax.
|
|
184
203
|
entries: [
|
|
185
204
|
...typeof config.optimizeDeps?.entries == "string" ? [config.optimizeDeps.entries] : config.optimizeDeps?.entries ?? [],
|
|
205
|
+
...mockRedirectIncludeEntries,
|
|
186
206
|
...getUniqueImportPaths(index).map(escapeGlobPath),
|
|
187
207
|
...previewAnnotationEntries.map(escapeGlobPath)
|
|
188
208
|
],
|
|
@@ -196,7 +216,6 @@ function storybookOptimizeDepsPlugin(options) {
|
|
|
196
216
|
|
|
197
217
|
// src/codegen-project-annotations.ts
|
|
198
218
|
import { getFrameworkName, loadPreviewOrConfigFile as loadPreviewOrConfigFile2 } from "storybook/internal/common";
|
|
199
|
-
import { STORY_HOT_UPDATED } from "storybook/internal/core-events";
|
|
200
219
|
import { isCsfFactoryPreview, readConfig } from "storybook/internal/csf-tools";
|
|
201
220
|
|
|
202
221
|
// ../../../node_modules/knitwork/dist/index.mjs
|
|
@@ -370,8 +389,6 @@ function generateProjectAnnotationsCodeFromPreviews(options) {
|
|
|
370
389
|
|
|
371
390
|
if (import.meta.hot) {
|
|
372
391
|
import.meta.hot.accept([${JSON.stringify(previewFileURL)}], (previewAnnotationModules) => {
|
|
373
|
-
// Cancel any running play function before patching in the new getProjectAnnotations
|
|
374
|
-
window?.__STORYBOOK_PREVIEW__?.channel?.emit('${STORY_HOT_UPDATED}');
|
|
375
392
|
// getProjectAnnotations has changed so we need to patch the new one in
|
|
376
393
|
window?.__STORYBOOK_PREVIEW__?.onGetProjectAnnotationsChanged({
|
|
377
394
|
getProjectAnnotations: () => getProjectAnnotations(previewAnnotationModules),
|
|
@@ -399,8 +416,6 @@ function generateProjectAnnotationsCodeFromPreviews(options) {
|
|
|
399
416
|
|
|
400
417
|
if (import.meta.hot) {
|
|
401
418
|
import.meta.hot.accept(${JSON.stringify(previewAnnotationURLs)}, (previewAnnotationModules) => {
|
|
402
|
-
// Cancel any running play function before patching in the new getProjectAnnotations
|
|
403
|
-
window?.__STORYBOOK_PREVIEW__?.channel?.emit('${STORY_HOT_UPDATED}');
|
|
404
419
|
// getProjectAnnotations has changed so we need to patch the new one in
|
|
405
420
|
window?.__STORYBOOK_PREVIEW__?.onGetProjectAnnotationsChanged({
|
|
406
421
|
getProjectAnnotations: () => getProjectAnnotations(previewAnnotationModules),
|
|
@@ -521,9 +536,9 @@ var ENTRY_PATH = "/vite-inject-mocker-entry.js", viteInjectMockerRuntime = (opti
|
|
|
521
536
|
// src/plugins/vite-mock/plugin.ts
|
|
522
537
|
import { readFileSync } from "node:fs";
|
|
523
538
|
import {
|
|
524
|
-
babelParser,
|
|
525
|
-
extractMockCalls,
|
|
526
|
-
findMockRedirect,
|
|
539
|
+
babelParser as babelParser2,
|
|
540
|
+
extractMockCalls as extractMockCalls2,
|
|
541
|
+
findMockRedirect as findMockRedirect2,
|
|
527
542
|
getAutomockCode,
|
|
528
543
|
getRealPath,
|
|
529
544
|
rewriteSbMockImportCalls
|
|
@@ -549,13 +564,13 @@ function viteMockPlugin(options) {
|
|
|
549
564
|
viteConfig = config;
|
|
550
565
|
},
|
|
551
566
|
buildStart() {
|
|
552
|
-
mockCalls =
|
|
567
|
+
mockCalls = extractMockCalls2(options, babelParser2, viteConfig.root, findMockRedirect2);
|
|
553
568
|
},
|
|
554
569
|
configureServer(server) {
|
|
555
570
|
async function invalidateAffectedFiles(file) {
|
|
556
571
|
if (file === options.previewConfigPath || file.includes("__mocks__")) {
|
|
557
572
|
let oldMockCalls = mockCalls;
|
|
558
|
-
mockCalls =
|
|
573
|
+
mockCalls = extractMockCalls2(options, babelParser2, viteConfig.root, findMockRedirect2);
|
|
559
574
|
let previewMod = server.moduleGraph.getModuleById(options.previewConfigPath);
|
|
560
575
|
previewMod && server.moduleGraph.invalidateModule(previewMod);
|
|
561
576
|
for (let call of mockCalls)
|
|
@@ -593,7 +608,7 @@ function viteMockPlugin(options) {
|
|
|
593
608
|
}
|
|
594
609
|
try {
|
|
595
610
|
if (!call.redirectPath) {
|
|
596
|
-
let automockedCode = getAutomockCode(code, call.spy,
|
|
611
|
+
let automockedCode = getAutomockCode(code, call.spy, babelParser2);
|
|
597
612
|
return {
|
|
598
613
|
code: automockedCode.toString(),
|
|
599
614
|
map: automockedCode.generateMap()
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Options, Builder } from 'storybook/internal/types';
|
|
2
|
+
import { InlineConfig, UserConfig, PluginOption } from 'vite';
|
|
3
3
|
|
|
4
4
|
type ViteStats = {
|
|
5
5
|
toJson: () => any;
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_d8hah9p1hm from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_d8hah9p1hm from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_d8hah9p1hm from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_d8hah9p1hm.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_d8hah9p1hm.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_d8hah9p1hm.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
normalize,
|
|
25
25
|
relative,
|
|
26
26
|
viteCorePlugins
|
|
27
|
-
} from "./_node-chunks/chunk-
|
|
27
|
+
} from "./_node-chunks/chunk-MBCPTYXX.js";
|
|
28
28
|
|
|
29
29
|
// ../../../node_modules/picocolors/picocolors.js
|
|
30
30
|
var require_picocolors = __commonJS({
|
|
@@ -323,9 +323,11 @@ async function generateModernIframeScriptCodeFromPreviews(options) {
|
|
|
323
323
|
import.meta.hot.decline();
|
|
324
324
|
}`.trim() : dedent2`
|
|
325
325
|
if (import.meta.hot) {
|
|
326
|
-
import.meta.hot.
|
|
327
|
-
// Cancel any running play function before patching in the new importFn
|
|
326
|
+
import.meta.hot.on('vite:afterUpdate', () => {
|
|
328
327
|
window.__STORYBOOK_PREVIEW__.channel.emit('${STORY_HOT_UPDATED}');
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
import.meta.hot.accept('${SB_VIRTUAL_FILES.VIRTUAL_STORIES_FILE}', (newModule) => {
|
|
329
331
|
// importFn has changed so we need to patch the new one in
|
|
330
332
|
window.__STORYBOOK_PREVIEW__.onStoriesChanged({ importFn: newModule.importFn });
|
|
331
333
|
});
|
package/dist/preset.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_d8hah9p1hm from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_d8hah9p1hm from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_d8hah9p1hm from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_d8hah9p1hm.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_d8hah9p1hm.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_d8hah9p1hm.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
@@ -12,7 +12,7 @@ var require = CJS_COMPAT_NODE_MODULE_5g492wkm9aw.createRequire(import.meta.url);
|
|
|
12
12
|
import {
|
|
13
13
|
optimizeViteDeps,
|
|
14
14
|
viteCorePlugins
|
|
15
|
-
} from "./_node-chunks/chunk-
|
|
15
|
+
} from "./_node-chunks/chunk-MBCPTYXX.js";
|
|
16
16
|
export {
|
|
17
17
|
optimizeViteDeps,
|
|
18
18
|
viteCorePlugins
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/builder-vite",
|
|
3
|
-
"version": "10.3.0
|
|
3
|
+
"version": "10.3.0",
|
|
4
4
|
"description": "A Storybook builder to dev and build with Vite",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storybook",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"!src/**/*"
|
|
48
48
|
],
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@storybook/csf-plugin": "10.3.0
|
|
50
|
+
"@storybook/csf-plugin": "10.3.0",
|
|
51
51
|
"ts-dedent": "^2.0.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"vite": "^7.0.4"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
|
-
"storybook": "^10.3.0
|
|
65
|
+
"storybook": "^10.3.0",
|
|
66
66
|
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
|
|
67
67
|
},
|
|
68
68
|
"publishConfig": {
|