@storybook-astro/framework 1.0.3 → 1.1.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.
- package/dist/{chunk-7GHEQUPV.js → chunk-POHTFYST.js} +46 -8
- package/dist/chunk-POHTFYST.js.map +1 -0
- package/dist/chunk-T7NWIO5S.js +220 -0
- package/dist/chunk-T7NWIO5S.js.map +1 -0
- package/dist/{chunk-C5OH4VBR.js → chunk-V76WSNSP.js} +124 -47
- package/dist/chunk-V76WSNSP.js.map +1 -0
- package/dist/{chunk-KSDXET2L.js → chunk-VPJDFGB5.js} +444 -60
- package/dist/chunk-VPJDFGB5.js.map +1 -0
- package/dist/index.d.ts +19 -9
- package/dist/index.js +10 -3
- package/dist/index.js.map +1 -1
- package/dist/middleware.js +57 -39
- package/dist/middleware.js.map +1 -1
- package/dist/node/index.d.ts +10 -0
- package/dist/node/index.js +10 -0
- package/dist/node/index.js.map +1 -0
- package/dist/preset.d.ts +1 -1
- package/dist/preset.js +3 -3
- package/dist/testing.js +12 -64
- package/dist/testing.js.map +1 -1
- package/dist/{types-CHTsRtA7.d.ts → types-Cvor6Tyi.d.ts} +21 -5
- package/dist/{viteStorybookAstroMiddlewarePlugin-NP2E52IC.js → viteStorybookAstroMiddlewarePlugin-2EFKTECT.js} +2 -2
- package/dist/vitest/global-setup.js +42 -0
- package/dist/vitest/global-setup.js.map +1 -0
- package/dist/vitest/index.js +20 -3
- package/dist/vitest/index.js.map +1 -1
- package/package.json +11 -3
- package/src/index.ts +21 -1
- package/src/lib/sanitization.ts +104 -0
- package/src/middleware.ts +76 -44
- package/src/node/index.ts +7 -0
- package/src/preset.ts +75 -15
- package/src/renderer/renderer-dev.ts +82 -0
- package/src/renderer/renderer-server.test.ts +101 -0
- package/src/renderer/renderer-server.ts +135 -0
- package/src/renderer/renderer-static.ts +62 -0
- package/src/rules.test.ts +89 -18
- package/src/rules.ts +67 -18
- package/src/server/index.ts +111 -0
- package/src/testing/renderer-daemon.ts +10 -1
- package/src/types.ts +25 -5
- package/src/virtual.d.ts +37 -0
- package/src/vite/astroFilesVirtualModulePlugin.ts +36 -0
- package/src/vite/createVirtualModulePlugin.ts +3 -3
- package/src/vite/storybookAstroRulesConfigVirtualModulePlugin.ts +37 -0
- package/src/vite/storybookAstroSanitizationConfigVirtualModulePlugin.ts +21 -0
- package/src/vite/storybookAstroServerAuthConfigVirtualModulePlugin.test.ts +71 -0
- package/src/vite/storybookAstroServerAuthConfigVirtualModulePlugin.ts +42 -0
- package/src/vitePluginAstroBuildPrerender.ts +50 -51
- package/src/vitePluginAstroBuildServer.ts +289 -0
- package/src/vitePluginAstroIntegrationOptsFallback.ts +25 -0
- package/src/viteStorybookAstroMiddlewarePlugin.ts +40 -8
- package/src/viteStorybookAstroRendererPlugin.ts +45 -0
- package/src/vitest/config.ts +45 -4
- package/src/vitest/global-setup.ts +45 -0
- package/dist/chunk-7GHEQUPV.js.map +0 -1
- package/dist/chunk-C5OH4VBR.js.map +0 -1
- package/dist/chunk-KSDXET2L.js.map +0 -1
- package/dist/middleware.d.ts +0 -26
- package/src/msw-helpers.ts +0 -1
- package/src/msw.ts +0 -58
- /package/dist/{viteStorybookAstroMiddlewarePlugin-NP2E52IC.js.map → viteStorybookAstroMiddlewarePlugin-2EFKTECT.js.map} +0 -0
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
import {
|
|
2
|
-
applyMswHandlers,
|
|
3
2
|
resolveSanitizationOptions,
|
|
4
3
|
resolveStoryModuleMock,
|
|
5
4
|
sanitizeRenderPayload,
|
|
6
5
|
selectStoryRules,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
} from "./chunk-E4LB75JN.js";
|
|
6
|
+
serializeSanitizationOptions,
|
|
7
|
+
withStoryModuleMocks,
|
|
8
|
+
withStoryRuleCleanups
|
|
9
|
+
} from "./chunk-V76WSNSP.js";
|
|
12
10
|
import {
|
|
13
11
|
createVirtualModulePlugin,
|
|
14
12
|
resolveRulesConfigFilePath,
|
|
15
13
|
ssrLoadModuleWithFsFallback,
|
|
14
|
+
viteAstroContainerRenderersPlugin,
|
|
16
15
|
vitePluginAstroFontsFallback,
|
|
16
|
+
vitePluginAstroIntegrationOptsFallback,
|
|
17
17
|
vitePluginAstroRoutesFallback,
|
|
18
18
|
vitePluginAstroVueFallback,
|
|
19
19
|
vitePluginStorybookAstroMiddleware
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-POHTFYST.js";
|
|
21
|
+
import {
|
|
22
|
+
vitePluginAstroComponentMarker
|
|
23
|
+
} from "./chunk-E4LB75JN.js";
|
|
21
24
|
import {
|
|
22
25
|
importAstroConfig
|
|
23
26
|
} from "./chunk-DNGQBPT7.js";
|
|
@@ -36,6 +39,42 @@ function viteStorybookRendererFallbackPlugin(integrations) {
|
|
|
36
39
|
});
|
|
37
40
|
}
|
|
38
41
|
|
|
42
|
+
// src/viteStorybookAstroRendererPlugin.ts
|
|
43
|
+
var packageName = "@storybook-astro/framework";
|
|
44
|
+
function viteStorybookAstroRendererPlugin(options) {
|
|
45
|
+
const pluginName = "storybook-astro:renderer-module";
|
|
46
|
+
const virtualModuleId = "virtual:storybook-astro-renderer";
|
|
47
|
+
const isProduction = options.mode === "production";
|
|
48
|
+
const isStaticMode = options.renderMode === "static";
|
|
49
|
+
return createVirtualModulePlugin({
|
|
50
|
+
pluginName,
|
|
51
|
+
virtualModuleId,
|
|
52
|
+
load() {
|
|
53
|
+
if (!isProduction) {
|
|
54
|
+
return `export * from '${packageName}/renderer/renderer-dev.ts';`;
|
|
55
|
+
}
|
|
56
|
+
if (isStaticMode) {
|
|
57
|
+
return `export * from '${packageName}/renderer/renderer-static.ts';`;
|
|
58
|
+
}
|
|
59
|
+
return [
|
|
60
|
+
`import { createServerRenderer } from '${packageName}/renderer/renderer-server.ts';`,
|
|
61
|
+
`const renderer = createServerRenderer(${JSON.stringify(
|
|
62
|
+
{
|
|
63
|
+
serverUrl: options.server?.serverUrl,
|
|
64
|
+
authToken: options.server?.authToken,
|
|
65
|
+
authHeader: options.server?.authHeader
|
|
66
|
+
},
|
|
67
|
+
null,
|
|
68
|
+
2
|
|
69
|
+
)});`,
|
|
70
|
+
"export const render = renderer.render;",
|
|
71
|
+
"export const init = renderer.init;",
|
|
72
|
+
"export const applyStyles = renderer.applyStyles;"
|
|
73
|
+
].join("\n");
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
39
78
|
// src/vitePluginAstroBuildPrerender.ts
|
|
40
79
|
import { createRequire } from "module";
|
|
41
80
|
import { mkdir, readFile, readdir, writeFile } from "fs/promises";
|
|
@@ -165,43 +204,46 @@ async function prerenderStories(options) {
|
|
|
165
204
|
const selectedRules = await selectStoryRules({
|
|
166
205
|
configModule: rulesConfigModule,
|
|
167
206
|
configFilePath: options.storyRulesConfigFilePath,
|
|
168
|
-
mode: "production",
|
|
169
207
|
story: {
|
|
170
208
|
id: story.id,
|
|
171
209
|
title: story.title,
|
|
172
210
|
name: story.name
|
|
173
211
|
}
|
|
174
212
|
});
|
|
175
|
-
await applyMswHandlers(selectedRules.mswHandlers);
|
|
176
213
|
if (selectedRules.moduleMocks.size > 0) {
|
|
177
214
|
viteServer.moduleGraph.invalidateAll();
|
|
178
215
|
}
|
|
179
|
-
const html = await
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
216
|
+
const html = await withStoryRuleCleanups(selectedRules.cleanups, async () => {
|
|
217
|
+
return withStoryModuleMocks(selectedRules.moduleMocks, async () => {
|
|
218
|
+
const modulePath = resolveImportPath(story.importPath, options.resolveFrom);
|
|
219
|
+
const storyModule = await viteServer.ssrLoadModule(modulePath);
|
|
220
|
+
const meta = isRecord(storyModule.default) ? storyModule.default : {};
|
|
221
|
+
const storyExport = isRecord(storyModule[story.exportName]) ? storyModule[story.exportName] : {};
|
|
222
|
+
if (typeof meta.component !== "function") {
|
|
223
|
+
throw new Error(
|
|
224
|
+
`Unable to prerender story "${story.id}". Missing default export component in ${story.importPath}.`
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
if (storyExport.component && storyExport.component !== meta.component) {
|
|
228
|
+
return void 0;
|
|
229
|
+
}
|
|
230
|
+
const mergedArgs = mergeStoryArgs(toRecord(meta.args), toRecord(storyExport.args));
|
|
231
|
+
const { args, slots } = separateSlots(mergedArgs);
|
|
232
|
+
const processedArgs = await processImageMetadata(args);
|
|
233
|
+
const sanitizedPayload = sanitizeRenderPayload(
|
|
234
|
+
{
|
|
235
|
+
args: processedArgs,
|
|
236
|
+
slots
|
|
237
|
+
},
|
|
238
|
+
sanitizationOptions
|
|
239
|
+
);
|
|
240
|
+
return container.renderToString(
|
|
241
|
+
patchCreateAstroCompat(meta.component),
|
|
242
|
+
{
|
|
243
|
+
props: sanitizedPayload.args,
|
|
244
|
+
slots: sanitizedPayload.slots
|
|
245
|
+
}
|
|
187
246
|
);
|
|
188
|
-
}
|
|
189
|
-
if (storyExport.component && storyExport.component !== meta.component) {
|
|
190
|
-
return void 0;
|
|
191
|
-
}
|
|
192
|
-
const mergedArgs = mergeStoryArgs(toRecord(meta.args), toRecord(storyExport.args));
|
|
193
|
-
const { args, slots } = separateSlots(mergedArgs);
|
|
194
|
-
const processedArgs = await processImageMetadata(args);
|
|
195
|
-
const sanitizedPayload = sanitizeRenderPayload(
|
|
196
|
-
{
|
|
197
|
-
args: processedArgs,
|
|
198
|
-
slots
|
|
199
|
-
},
|
|
200
|
-
sanitizationOptions
|
|
201
|
-
);
|
|
202
|
-
return container.renderToString(patchCreateAstroCompat(meta.component), {
|
|
203
|
-
props: sanitizedPayload.args,
|
|
204
|
-
slots: sanitizedPayload.slots
|
|
205
247
|
});
|
|
206
248
|
});
|
|
207
249
|
if (html !== void 0) {
|
|
@@ -214,14 +256,18 @@ async function prerenderStories(options) {
|
|
|
214
256
|
}
|
|
215
257
|
}
|
|
216
258
|
async function createStorySsrServer(integrations, trackedSpecifiers, resolveFrom) {
|
|
217
|
-
const { getViteConfig } = await importAstroConfig(resolveFrom);
|
|
259
|
+
const { getViteConfig, passthroughImageService } = await importAstroConfig(resolveFrom);
|
|
218
260
|
const astroConfig = await getViteConfig(
|
|
219
261
|
{ root: resolveFrom },
|
|
220
262
|
{
|
|
221
263
|
configFile: false,
|
|
222
264
|
integrations: await Promise.all(
|
|
223
265
|
integrations.map((integration) => integration.loadIntegration(resolveFrom))
|
|
224
|
-
)
|
|
266
|
+
),
|
|
267
|
+
// Use the passthrough image service so nested components that use <Image>
|
|
268
|
+
// from astro:assets render as plain <img> tags without triggering image
|
|
269
|
+
// optimization (which fails in the Storybook SSR context).
|
|
270
|
+
image: { service: passthroughImageService() }
|
|
225
271
|
}
|
|
226
272
|
)({
|
|
227
273
|
mode: "production",
|
|
@@ -235,6 +281,7 @@ async function createStorySsrServer(integrations, trackedSpecifiers, resolveFrom
|
|
|
235
281
|
plugins: [
|
|
236
282
|
createProjectAstroResolutionPlugin(resolveFrom),
|
|
237
283
|
vitePluginAstroFontsFallback(),
|
|
284
|
+
vitePluginAstroIntegrationOptsFallback(),
|
|
238
285
|
vitePluginAstroVueFallback(),
|
|
239
286
|
vitePluginAstroRoutesFallback(),
|
|
240
287
|
{
|
|
@@ -476,14 +523,14 @@ async function processImageMetadata(args) {
|
|
|
476
523
|
const processed = {};
|
|
477
524
|
for (const [key, value] of Object.entries(args)) {
|
|
478
525
|
if (isImageMetadata(value)) {
|
|
479
|
-
processed[key] =
|
|
526
|
+
processed[key] = value;
|
|
480
527
|
continue;
|
|
481
528
|
}
|
|
482
529
|
if (Array.isArray(value)) {
|
|
483
530
|
processed[key] = await Promise.all(
|
|
484
531
|
value.map(async (item) => {
|
|
485
532
|
if (isImageMetadata(item)) {
|
|
486
|
-
return
|
|
533
|
+
return item;
|
|
487
534
|
}
|
|
488
535
|
if (isRecord(item)) {
|
|
489
536
|
return processImageMetadata(item);
|
|
@@ -504,17 +551,6 @@ async function processImageMetadata(args) {
|
|
|
504
551
|
function isImageMetadata(value) {
|
|
505
552
|
return isRecord(value) && typeof value.src === "string" && ("width" in value || "height" in value || "format" in value);
|
|
506
553
|
}
|
|
507
|
-
function convertImageMetadataToUrl(imageMetadata) {
|
|
508
|
-
const src = imageMetadata.src;
|
|
509
|
-
const fsPath = imageMetadata.fsPath;
|
|
510
|
-
if (typeof src === "string") {
|
|
511
|
-
return src;
|
|
512
|
-
}
|
|
513
|
-
if (typeof fsPath === "string") {
|
|
514
|
-
return fsPath;
|
|
515
|
-
}
|
|
516
|
-
return String(imageMetadata);
|
|
517
|
-
}
|
|
518
554
|
function createProjectAstroResolutionPlugin(resolveFrom) {
|
|
519
555
|
const require2 = createRequire(import.meta.url);
|
|
520
556
|
return {
|
|
@@ -535,6 +571,12 @@ function createProjectAstroResolutionPlugin(resolveFrom) {
|
|
|
535
571
|
};
|
|
536
572
|
}
|
|
537
573
|
|
|
574
|
+
// src/vitePluginAstroBuildServer.ts
|
|
575
|
+
import { readdir as readdir2 } from "fs/promises";
|
|
576
|
+
import { dirname, resolve as resolve2 } from "path";
|
|
577
|
+
import { fileURLToPath } from "url";
|
|
578
|
+
import { build } from "vite";
|
|
579
|
+
|
|
538
580
|
// src/vitePluginAstro.ts
|
|
539
581
|
import { mergeConfig as mergeConfig2 } from "vite";
|
|
540
582
|
var ASTRO_PLUGINS_THAT_ARE_SUPPOSEDLY_NOT_NEEDED_IN_STORYBOOK = [
|
|
@@ -586,6 +628,310 @@ async function mergeWithAstroConfig(config, integrations = [], resolveFrom = pro
|
|
|
586
628
|
});
|
|
587
629
|
}
|
|
588
630
|
|
|
631
|
+
// src/vite/astroFilesVirtualModulePlugin.ts
|
|
632
|
+
function astroFilesVirtualModulePlugin(astroComponents) {
|
|
633
|
+
return createVirtualModulePlugin({
|
|
634
|
+
pluginName: "storybook-astro:virtual-astro-files",
|
|
635
|
+
virtualModuleId: "virtual:astro-files",
|
|
636
|
+
load() {
|
|
637
|
+
const imports = astroComponents.reduce((records, file, index) => {
|
|
638
|
+
const moduleId = `_astroFile${index}`;
|
|
639
|
+
return [
|
|
640
|
+
...records,
|
|
641
|
+
{
|
|
642
|
+
id: moduleId,
|
|
643
|
+
file,
|
|
644
|
+
importStatement: `import ${moduleId} from '${file}';`
|
|
645
|
+
}
|
|
646
|
+
];
|
|
647
|
+
}, []);
|
|
648
|
+
return [
|
|
649
|
+
imports.map(({ importStatement }) => importStatement).join("\n"),
|
|
650
|
+
"export default {",
|
|
651
|
+
imports.map(({ file, id }) => `'${file}': ${id}`).join(",\n"),
|
|
652
|
+
"};"
|
|
653
|
+
].join("\n");
|
|
654
|
+
}
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
// src/vite/storybookAstroRulesConfigVirtualModulePlugin.ts
|
|
659
|
+
var STORYBOOK_ASTRO_STORY_RULES_CONFIG_VIRTUAL_MODULE_ID = "virtual:storybook-astro-story-rules-config";
|
|
660
|
+
function storybookAstroStoryRulesConfigVirtualModulePlugin(options, resolveFrom = process.cwd()) {
|
|
661
|
+
return createVirtualModulePlugin({
|
|
662
|
+
pluginName: "storybook-astro:virtual-story-rules-config",
|
|
663
|
+
virtualModuleId: STORYBOOK_ASTRO_STORY_RULES_CONFIG_VIRTUAL_MODULE_ID,
|
|
664
|
+
load() {
|
|
665
|
+
const configFilePath = resolveRulesConfigFilePath(options, resolveFrom);
|
|
666
|
+
if (!configFilePath) {
|
|
667
|
+
return [
|
|
668
|
+
"const storybookAstroStoryRulesConfig = { rules: [] };",
|
|
669
|
+
"export default storybookAstroStoryRulesConfig;",
|
|
670
|
+
"export const storybookAstroStoryRulesConfigFilePath = undefined;"
|
|
671
|
+
].join("\n");
|
|
672
|
+
}
|
|
673
|
+
const importPath = JSON.stringify(configFilePath.replace(/\\/g, "/"));
|
|
674
|
+
const configPath = JSON.stringify(configFilePath.replace(/\\/g, "/"));
|
|
675
|
+
return [
|
|
676
|
+
`import * as storybookAstroStoryRulesConfigModule from ${importPath};`,
|
|
677
|
+
"export default storybookAstroStoryRulesConfigModule;",
|
|
678
|
+
`export const storybookAstroStoryRulesConfigFilePath = ${configPath};`
|
|
679
|
+
].join("\n");
|
|
680
|
+
}
|
|
681
|
+
});
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
// src/vite/storybookAstroSanitizationConfigVirtualModulePlugin.ts
|
|
685
|
+
var STORYBOOK_ASTRO_SANITIZATION_CONFIG_VIRTUAL_MODULE_ID = "virtual:storybook-astro-sanitization-config";
|
|
686
|
+
function storybookAstroSanitizationConfigVirtualModulePlugin(options) {
|
|
687
|
+
return createVirtualModulePlugin({
|
|
688
|
+
pluginName: "storybook-astro:virtual-sanitization-config",
|
|
689
|
+
virtualModuleId: STORYBOOK_ASTRO_SANITIZATION_CONFIG_VIRTUAL_MODULE_ID,
|
|
690
|
+
load() {
|
|
691
|
+
const serializedConfig = serializeSanitizationOptions(options);
|
|
692
|
+
return `export default ${serializedConfig};`;
|
|
693
|
+
}
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
// src/vite/storybookAstroServerAuthConfigVirtualModulePlugin.ts
|
|
698
|
+
var STORYBOOK_ASTRO_SERVER_AUTH_CONFIG_VIRTUAL_MODULE_ID = "virtual:storybook-astro-server-auth-config";
|
|
699
|
+
function storybookAstroServerAuthConfigVirtualModulePlugin(options) {
|
|
700
|
+
const authToken = normalizeOptionalString(options?.authToken);
|
|
701
|
+
const authHeader = normalizeAuthHeader(options?.authHeader);
|
|
702
|
+
return createVirtualModulePlugin({
|
|
703
|
+
pluginName: "storybook-astro:virtual-server-auth-config",
|
|
704
|
+
virtualModuleId: STORYBOOK_ASTRO_SERVER_AUTH_CONFIG_VIRTUAL_MODULE_ID,
|
|
705
|
+
load() {
|
|
706
|
+
return [
|
|
707
|
+
`export const storybookAstroServerAuthToken = ${authToken ? JSON.stringify(authToken) : "undefined"};`,
|
|
708
|
+
`export const storybookAstroServerAuthHeader = ${JSON.stringify(authHeader)};`
|
|
709
|
+
].join("\n");
|
|
710
|
+
}
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
function normalizeOptionalString(value) {
|
|
714
|
+
if (!value) {
|
|
715
|
+
return void 0;
|
|
716
|
+
}
|
|
717
|
+
const normalizedValue = value.trim();
|
|
718
|
+
return normalizedValue || void 0;
|
|
719
|
+
}
|
|
720
|
+
function normalizeAuthHeader(value) {
|
|
721
|
+
const normalizedValue = normalizeOptionalString(value);
|
|
722
|
+
return (normalizedValue ?? "authorization").toLowerCase();
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
// src/vitePluginAstroBuildServer.ts
|
|
726
|
+
var moduleRoot = resolve2(dirname(fileURLToPath(import.meta.url)), ".");
|
|
727
|
+
var packageRoot = resolve2(moduleRoot, "..");
|
|
728
|
+
function vitePluginAstroBuildServer(options) {
|
|
729
|
+
const integrations = options.integrations ?? [];
|
|
730
|
+
const resolveFrom = options.resolveFrom ?? process.cwd();
|
|
731
|
+
const storiesMap = /* @__PURE__ */ new Map();
|
|
732
|
+
const trackedSpecifiers = collectTrackedSpecifiers2(integrations);
|
|
733
|
+
const staticEntrypointRefs = /* @__PURE__ */ new Map();
|
|
734
|
+
const componentEntrypointRefs = /* @__PURE__ */ new Map();
|
|
735
|
+
let storybookStaticOutDir = resolve2(resolveFrom, "storybook-static");
|
|
736
|
+
return {
|
|
737
|
+
name: "storybook-astro:build-server",
|
|
738
|
+
apply: "build",
|
|
739
|
+
enforce: "post",
|
|
740
|
+
configResolved(config) {
|
|
741
|
+
storybookStaticOutDir = resolve2(resolveFrom, config.build.outDir ?? "storybook-static");
|
|
742
|
+
},
|
|
743
|
+
resolveId(id, importer) {
|
|
744
|
+
if (id.endsWith(".astro") && importer) {
|
|
745
|
+
const absoluteAstroPath = resolve2(dirname(importer), id);
|
|
746
|
+
if (!storiesMap.has(absoluteAstroPath)) {
|
|
747
|
+
storiesMap.set(absoluteAstroPath, /* @__PURE__ */ new Set());
|
|
748
|
+
}
|
|
749
|
+
storiesMap.get(absoluteAstroPath)?.add(importer);
|
|
750
|
+
}
|
|
751
|
+
if (id.startsWith("virtual:astro-static-module/")) {
|
|
752
|
+
return `\0${id}`;
|
|
753
|
+
}
|
|
754
|
+
if (id.startsWith("virtual:astro-component-module/")) {
|
|
755
|
+
return `\0${id}`;
|
|
756
|
+
}
|
|
757
|
+
},
|
|
758
|
+
load(id) {
|
|
759
|
+
if (id.startsWith("\0virtual:astro-static-module/")) {
|
|
760
|
+
const encodedSpecifier = id.replace("\0virtual:astro-static-module/", "");
|
|
761
|
+
const specifier = decodeURIComponent(encodedSpecifier);
|
|
762
|
+
if (isClientEntrypoint2(specifier)) {
|
|
763
|
+
return [`export { default } from '${specifier}';`, `export * from '${specifier}';`].join("\n");
|
|
764
|
+
}
|
|
765
|
+
return [`import '${specifier}';`, "export default undefined;"].join("\n");
|
|
766
|
+
}
|
|
767
|
+
if (id.startsWith("\0virtual:astro-component-module/")) {
|
|
768
|
+
const encodedSpecifier = id.replace("\0virtual:astro-component-module/", "");
|
|
769
|
+
const specifier = decodeURIComponent(encodedSpecifier);
|
|
770
|
+
return [`export { default } from '${specifier}';`, `export * from '${specifier}';`].join("\n");
|
|
771
|
+
}
|
|
772
|
+
},
|
|
773
|
+
async buildStart() {
|
|
774
|
+
integrations.forEach((integration) => {
|
|
775
|
+
const entrypoint = integration.renderer.client?.entrypoint;
|
|
776
|
+
if (entrypoint) {
|
|
777
|
+
this.addWatchFile(entrypoint);
|
|
778
|
+
}
|
|
779
|
+
});
|
|
780
|
+
trackedSpecifiers.forEach((specifier) => {
|
|
781
|
+
const fileReferenceId = this.emitFile({
|
|
782
|
+
type: "chunk",
|
|
783
|
+
id: toStaticVirtualId2(specifier)
|
|
784
|
+
});
|
|
785
|
+
staticEntrypointRefs.set(specifier, fileReferenceId);
|
|
786
|
+
});
|
|
787
|
+
const srcRoot = resolve2(resolveFrom, "src/components");
|
|
788
|
+
const specifiers = await collectHydratableSourceModules2(srcRoot);
|
|
789
|
+
specifiers.forEach((specifier) => {
|
|
790
|
+
const fileReferenceId = this.emitFile({
|
|
791
|
+
type: "chunk",
|
|
792
|
+
id: toComponentVirtualId2(specifier)
|
|
793
|
+
});
|
|
794
|
+
componentEntrypointRefs.set(specifier, fileReferenceId);
|
|
795
|
+
});
|
|
796
|
+
},
|
|
797
|
+
async writeBundle() {
|
|
798
|
+
const astroComponents = Array.from(storiesMap.keys());
|
|
799
|
+
const staticModuleMap = buildStaticModuleMap2(
|
|
800
|
+
this,
|
|
801
|
+
staticEntrypointRefs,
|
|
802
|
+
componentEntrypointRefs
|
|
803
|
+
);
|
|
804
|
+
const serverOutDir = resolve2(dirname(storybookStaticOutDir), "storybook-server");
|
|
805
|
+
await buildAstroServer({
|
|
806
|
+
astroComponents,
|
|
807
|
+
integrations,
|
|
808
|
+
sanitization: options.sanitization,
|
|
809
|
+
storyRules: options.storyRules,
|
|
810
|
+
server: options.server,
|
|
811
|
+
outDir: serverOutDir,
|
|
812
|
+
staticModuleMap,
|
|
813
|
+
resolveFrom
|
|
814
|
+
});
|
|
815
|
+
}
|
|
816
|
+
};
|
|
817
|
+
}
|
|
818
|
+
async function buildAstroServer(options) {
|
|
819
|
+
const buildConfig = {
|
|
820
|
+
root: resolve2(packageRoot, "src/server"),
|
|
821
|
+
ssr: {
|
|
822
|
+
noExternal: /(@astrojs\/.+|react|react-dom)/
|
|
823
|
+
},
|
|
824
|
+
build: {
|
|
825
|
+
ssr: true,
|
|
826
|
+
outDir: options.outDir,
|
|
827
|
+
emptyOutDir: true,
|
|
828
|
+
sourcemap: true,
|
|
829
|
+
manifest: false,
|
|
830
|
+
rollupOptions: {
|
|
831
|
+
input: resolve2(packageRoot, "src/server/index.ts"),
|
|
832
|
+
treeshake: true
|
|
833
|
+
}
|
|
834
|
+
},
|
|
835
|
+
plugins: [
|
|
836
|
+
astroFilesVirtualModulePlugin(options.astroComponents),
|
|
837
|
+
storybookAstroSanitizationConfigVirtualModulePlugin(options.sanitization),
|
|
838
|
+
storybookAstroStoryRulesConfigVirtualModulePlugin(options.storyRules, options.resolveFrom),
|
|
839
|
+
storybookAstroServerAuthConfigVirtualModulePlugin(options.server),
|
|
840
|
+
viteAstroContainerRenderersPlugin(options.integrations, {
|
|
841
|
+
mode: "production",
|
|
842
|
+
staticModuleMap: options.staticModuleMap
|
|
843
|
+
})
|
|
844
|
+
]
|
|
845
|
+
};
|
|
846
|
+
const finalConfig = await mergeWithAstroConfig(
|
|
847
|
+
buildConfig,
|
|
848
|
+
options.integrations,
|
|
849
|
+
options.resolveFrom,
|
|
850
|
+
"production",
|
|
851
|
+
"build"
|
|
852
|
+
);
|
|
853
|
+
await build(finalConfig);
|
|
854
|
+
}
|
|
855
|
+
function collectTrackedSpecifiers2(integrations) {
|
|
856
|
+
const specifiers = /* @__PURE__ */ new Set(["astro:scripts/page.js", "astro:scripts/before-hydration.js"]);
|
|
857
|
+
integrations.forEach((integration) => {
|
|
858
|
+
const entrypoint = integration.renderer.client?.entrypoint;
|
|
859
|
+
if (entrypoint) {
|
|
860
|
+
specifiers.add(entrypoint);
|
|
861
|
+
}
|
|
862
|
+
});
|
|
863
|
+
return specifiers;
|
|
864
|
+
}
|
|
865
|
+
function buildStaticModuleMap2(pluginContext, staticEntrypointRefs, componentEntrypointRefs) {
|
|
866
|
+
const map = {};
|
|
867
|
+
staticEntrypointRefs.forEach((fileReferenceId, specifier) => {
|
|
868
|
+
const fileName = pluginContext.getFileName(fileReferenceId);
|
|
869
|
+
if (fileName) {
|
|
870
|
+
map[specifier] = toPublicPath2(fileName);
|
|
871
|
+
}
|
|
872
|
+
});
|
|
873
|
+
componentEntrypointRefs.forEach((fileReferenceId, specifier) => {
|
|
874
|
+
const fileName = pluginContext.getFileName(fileReferenceId);
|
|
875
|
+
if (fileName) {
|
|
876
|
+
map[specifier] = toPublicPath2(fileName);
|
|
877
|
+
}
|
|
878
|
+
});
|
|
879
|
+
return map;
|
|
880
|
+
}
|
|
881
|
+
function toStaticVirtualId2(specifier) {
|
|
882
|
+
return `virtual:astro-static-module/${encodeURIComponent(specifier)}`;
|
|
883
|
+
}
|
|
884
|
+
function toComponentVirtualId2(specifier) {
|
|
885
|
+
return `virtual:astro-component-module/${encodeURIComponent(specifier)}`;
|
|
886
|
+
}
|
|
887
|
+
function isClientEntrypoint2(specifier) {
|
|
888
|
+
return specifier.startsWith("@astrojs/") && specifier.endsWith("/client.js");
|
|
889
|
+
}
|
|
890
|
+
function toPublicPath2(fileName) {
|
|
891
|
+
return `./${fileName}`;
|
|
892
|
+
}
|
|
893
|
+
async function collectHydratableSourceModules2(srcRoot) {
|
|
894
|
+
const modules = [];
|
|
895
|
+
async function walk(directory) {
|
|
896
|
+
let entries;
|
|
897
|
+
try {
|
|
898
|
+
entries = await readdir2(directory, { withFileTypes: true });
|
|
899
|
+
} catch {
|
|
900
|
+
return;
|
|
901
|
+
}
|
|
902
|
+
await Promise.all(
|
|
903
|
+
entries.map(async (entry) => {
|
|
904
|
+
const absolutePath = resolve2(directory, entry.name);
|
|
905
|
+
if (entry.isDirectory()) {
|
|
906
|
+
await walk(absolutePath);
|
|
907
|
+
return;
|
|
908
|
+
}
|
|
909
|
+
if (!entry.isFile()) {
|
|
910
|
+
return;
|
|
911
|
+
}
|
|
912
|
+
const normalizedPath = absolutePath.replace(/\\/g, "/");
|
|
913
|
+
if (!isHydratableSourceFile2(normalizedPath)) {
|
|
914
|
+
return;
|
|
915
|
+
}
|
|
916
|
+
if (isNonHydratableSourceFile2(normalizedPath)) {
|
|
917
|
+
return;
|
|
918
|
+
}
|
|
919
|
+
modules.push(normalizedPath);
|
|
920
|
+
})
|
|
921
|
+
);
|
|
922
|
+
}
|
|
923
|
+
await walk(srcRoot);
|
|
924
|
+
return modules;
|
|
925
|
+
}
|
|
926
|
+
function isHydratableSourceFile2(input) {
|
|
927
|
+
return /\.(jsx|tsx|vue|svelte|js|ts)$/.test(input);
|
|
928
|
+
}
|
|
929
|
+
function isNonHydratableSourceFile2(input) {
|
|
930
|
+
return /\.stories\.[jt]sx?$|\.stories\.vue$|\.stories\.svelte$|\.(spec|test)\.[jt]sx?$/.test(
|
|
931
|
+
input
|
|
932
|
+
);
|
|
933
|
+
}
|
|
934
|
+
|
|
589
935
|
// src/preset.ts
|
|
590
936
|
var core = {
|
|
591
937
|
builder: "@storybook/builder-vite",
|
|
@@ -593,25 +939,46 @@ var core = {
|
|
|
593
939
|
};
|
|
594
940
|
var viteFinal = async (config, { configType, presets }) => {
|
|
595
941
|
const options = await presets.apply("frameworkOptions");
|
|
596
|
-
const { vitePlugin: storybookAstroMiddlewarePlugin, viteConfig } = await vitePluginStorybookAstroMiddleware(options);
|
|
597
942
|
if (!config.plugins) {
|
|
598
943
|
config.plugins = [];
|
|
599
944
|
}
|
|
600
945
|
const integrations = options.integrations ?? [];
|
|
601
946
|
const resolveFrom = options.resolveFrom ?? process.cwd();
|
|
947
|
+
const renderMode = options.renderMode ?? "server";
|
|
602
948
|
const mode = configType === "DEVELOPMENT" ? "development" : "production";
|
|
603
949
|
const command = configType === "DEVELOPMENT" ? "serve" : "build";
|
|
604
950
|
resolveSanitizationOptions(options.sanitization);
|
|
951
|
+
config.envPrefix = mergeEnvPrefixes(config.envPrefix, "STORYBOOK_");
|
|
952
|
+
const { vitePlugin: storybookAstroMiddlewarePlugin, viteConfig } = await vitePluginStorybookAstroMiddleware(options);
|
|
605
953
|
config.plugins.push(
|
|
606
|
-
storybookAstroMiddlewarePlugin,
|
|
607
954
|
viteStorybookRendererFallbackPlugin(integrations),
|
|
955
|
+
viteStorybookAstroRendererPlugin({
|
|
956
|
+
mode,
|
|
957
|
+
renderMode,
|
|
958
|
+
server: options.server
|
|
959
|
+
}),
|
|
608
960
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
609
961
|
vitePluginAstroComponentMarker(),
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
vitePluginAstroVueFallback(),
|
|
613
|
-
...viteConfig.plugins
|
|
962
|
+
vitePluginAstroIntegrationOptsFallback(),
|
|
963
|
+
vitePluginAstroVueFallback()
|
|
614
964
|
);
|
|
965
|
+
if (configType === "DEVELOPMENT") {
|
|
966
|
+
config.plugins.push(storybookAstroMiddlewarePlugin, ...viteConfig.plugins);
|
|
967
|
+
} else if (renderMode === "static") {
|
|
968
|
+
config.plugins.push(vitePluginAstroBuildPrerender(options));
|
|
969
|
+
} else {
|
|
970
|
+
config.plugins.push(vitePluginAstroBuildServer(options));
|
|
971
|
+
}
|
|
972
|
+
if (configType !== "DEVELOPMENT") {
|
|
973
|
+
config.build = {
|
|
974
|
+
...config.build ?? {},
|
|
975
|
+
manifest: true
|
|
976
|
+
};
|
|
977
|
+
config.build.rollupOptions = {
|
|
978
|
+
...config.build.rollupOptions ?? {},
|
|
979
|
+
preserveEntrySignatures: "strict"
|
|
980
|
+
};
|
|
981
|
+
}
|
|
615
982
|
if (!config.resolve) {
|
|
616
983
|
config.resolve = {};
|
|
617
984
|
}
|
|
@@ -632,29 +999,46 @@ var viteFinal = async (config, { configType, presets }) => {
|
|
|
632
999
|
if (!finalConfig.optimizeDeps.exclude) {
|
|
633
1000
|
finalConfig.optimizeDeps.exclude = [];
|
|
634
1001
|
}
|
|
635
|
-
|
|
636
|
-
finalConfig.optimizeDeps.exclude.
|
|
1002
|
+
for (const pkg of ["@astrojs/vue", "@astrojs/react", "@astrojs/preact"]) {
|
|
1003
|
+
if (!finalConfig.optimizeDeps.exclude.includes(pkg)) {
|
|
1004
|
+
finalConfig.optimizeDeps.exclude.push(pkg);
|
|
1005
|
+
}
|
|
637
1006
|
}
|
|
638
1007
|
if (!finalConfig.optimizeDeps.exclude.includes("@storybook-astro/renderer")) {
|
|
639
1008
|
finalConfig.optimizeDeps.exclude.push("@storybook-astro/renderer");
|
|
640
1009
|
}
|
|
1010
|
+
const integrationVirtualModules = [
|
|
1011
|
+
"virtual:@astrojs/vue/app",
|
|
1012
|
+
"virtual:astro:vue-app",
|
|
1013
|
+
"astro:react:opts",
|
|
1014
|
+
"astro:preact:opts"
|
|
1015
|
+
];
|
|
641
1016
|
if (!finalConfig.optimizeDeps.esbuildOptions) {
|
|
642
1017
|
finalConfig.optimizeDeps.esbuildOptions = {};
|
|
643
1018
|
}
|
|
644
1019
|
if (!finalConfig.optimizeDeps.esbuildOptions.external) {
|
|
645
1020
|
finalConfig.optimizeDeps.esbuildOptions.external = [];
|
|
646
1021
|
}
|
|
647
|
-
const
|
|
648
|
-
for (const mod of vueVirtualModules) {
|
|
1022
|
+
for (const mod of integrationVirtualModules) {
|
|
649
1023
|
if (!finalConfig.optimizeDeps.esbuildOptions.external.includes(mod)) {
|
|
650
1024
|
finalConfig.optimizeDeps.esbuildOptions.external.push(mod);
|
|
651
1025
|
}
|
|
652
1026
|
}
|
|
1027
|
+
const optimizeDepsMut = finalConfig.optimizeDeps;
|
|
1028
|
+
const rolldownOpts = optimizeDepsMut.rolldownOptions ?? {};
|
|
1029
|
+
rolldownOpts.external = Array.from(
|
|
1030
|
+
/* @__PURE__ */ new Set([...rolldownOpts.external ?? [], ...integrationVirtualModules])
|
|
1031
|
+
);
|
|
1032
|
+
optimizeDepsMut.rolldownOptions = rolldownOpts;
|
|
653
1033
|
return finalConfig;
|
|
654
1034
|
};
|
|
1035
|
+
function mergeEnvPrefixes(existing, additionalPrefix) {
|
|
1036
|
+
const prefixes = Array.isArray(existing) ? existing : existing ? [existing] : [];
|
|
1037
|
+
return Array.from(/* @__PURE__ */ new Set([...prefixes, additionalPrefix]));
|
|
1038
|
+
}
|
|
655
1039
|
|
|
656
1040
|
export {
|
|
657
1041
|
core,
|
|
658
1042
|
viteFinal
|
|
659
1043
|
};
|
|
660
|
-
//# sourceMappingURL=chunk-
|
|
1044
|
+
//# sourceMappingURL=chunk-VPJDFGB5.js.map
|