@storybook-astro/framework 1.6.0 → 1.7.0-canary.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.
- package/dist/{chunk-RERWLIIN.js → chunk-5POAXNWB.js} +96 -107
- package/dist/chunk-5POAXNWB.js.map +1 -0
- package/dist/chunk-NOQVUQ7R.js +107 -0
- package/dist/chunk-NOQVUQ7R.js.map +1 -0
- package/dist/{chunk-6RIGYMZP.js → chunk-UIGE5653.js} +1 -1
- package/dist/chunk-UIGE5653.js.map +1 -0
- package/dist/chunk-YRG32BBU.js +15 -0
- package/dist/chunk-YRG32BBU.js.map +1 -0
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/middleware.js +4 -2
- package/dist/middleware.js.map +1 -1
- package/dist/preset.js +78 -42
- package/dist/preset.js.map +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +39 -15
- package/dist/testing.js.map +1 -1
- package/dist/vitest/index.js +1 -1
- package/package.json +17 -13
- package/src/astroRenderHandler.ts +39 -2
- package/src/index.ts +8 -1
- package/src/lib/astro-component-marker.test.ts +48 -0
- package/src/lib/reconstruct-component-args.test.ts +97 -0
- package/src/lib/reconstruct-component-args.ts +155 -0
- package/src/lib/separate-story-slots.ts +20 -0
- package/src/preset.ts +60 -12
- package/src/productionRenderRuntime.test.ts +97 -0
- package/src/productionRenderRuntime.ts +46 -29
- package/src/storySsrVite.ts +23 -6
- package/src/testing/astro-runtime.ts +52 -21
- package/src/vitePluginAstroComponentMarker.ts +6 -1
- package/dist/chunk-6RIGYMZP.js.map +0 -1
- package/dist/chunk-RERWLIIN.js.map +0 -1
package/dist/preset.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
vitePluginAstroComponentMarker
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-UIGE5653.js";
|
|
4
4
|
import {
|
|
5
|
-
createAstroRenderHandler,
|
|
6
5
|
ensureAstroPassthroughImageService,
|
|
7
|
-
resolveAliasedIsland
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
resolveAliasedIsland
|
|
7
|
+
} from "./chunk-NOQVUQ7R.js";
|
|
8
|
+
import {
|
|
9
|
+
separateStorySlots
|
|
10
|
+
} from "./chunk-YRG32BBU.js";
|
|
11
11
|
import {
|
|
12
12
|
createVirtualModule,
|
|
13
13
|
loadUserAstroFonts,
|
|
@@ -26,6 +26,11 @@ import {
|
|
|
26
26
|
import {
|
|
27
27
|
importAstroConfig
|
|
28
28
|
} from "./chunk-PUTCAN6X.js";
|
|
29
|
+
import {
|
|
30
|
+
createAstroRenderHandler,
|
|
31
|
+
resolveSanitizationOptions,
|
|
32
|
+
serializeSanitizationOptions
|
|
33
|
+
} from "./chunk-5POAXNWB.js";
|
|
29
34
|
import "./chunk-ZIDMHD4S.js";
|
|
30
35
|
import {
|
|
31
36
|
resolveStoryModuleMock
|
|
@@ -34,6 +39,7 @@ import "./chunk-G3PMV62Z.js";
|
|
|
34
39
|
|
|
35
40
|
// src/preset.ts
|
|
36
41
|
import { dirname as dirname4 } from "path";
|
|
42
|
+
import { version as viteVersion } from "vite";
|
|
37
43
|
|
|
38
44
|
// src/viteStorybookRendererFallbackPlugin.ts
|
|
39
45
|
function viteStorybookRendererFallbackPlugin(integrations) {
|
|
@@ -567,18 +573,26 @@ function isRecord(value) {
|
|
|
567
573
|
return typeof value === "object" && value !== null;
|
|
568
574
|
}
|
|
569
575
|
function createStorybookBrowserStubPlugin() {
|
|
576
|
+
const STUBBED_SPECIFIERS = /* @__PURE__ */ new Set([
|
|
577
|
+
"@storybook/addon-docs",
|
|
578
|
+
"@storybook/addon-docs/blocks",
|
|
579
|
+
"@storybook/blocks"
|
|
580
|
+
]);
|
|
570
581
|
const STUB_ID = "\0storybook-astro-browser-stub";
|
|
571
582
|
return {
|
|
572
583
|
name: "storybook-astro:storybook-browser-stubs",
|
|
584
|
+
// Must run before Astro's resolvers, which would otherwise resolve these
|
|
585
|
+
// bare specifiers to their real (browser-only) files before we can stub them.
|
|
586
|
+
enforce: "pre",
|
|
573
587
|
resolveId(id) {
|
|
574
|
-
if (id
|
|
588
|
+
if (STUBBED_SPECIFIERS.has(id)) {
|
|
575
589
|
return STUB_ID;
|
|
576
590
|
}
|
|
577
591
|
return null;
|
|
578
592
|
},
|
|
579
593
|
load(id) {
|
|
580
594
|
if (id === STUB_ID) {
|
|
581
|
-
return "export {};";
|
|
595
|
+
return "export default () => ({});";
|
|
582
596
|
}
|
|
583
597
|
return null;
|
|
584
598
|
}
|
|
@@ -642,21 +656,19 @@ async function renderProductionStoryToHtml(options) {
|
|
|
642
656
|
const storyModulePath = resolveProjectImportPath(options.story.importPath, options.resolveFrom);
|
|
643
657
|
const componentPath = resolveProjectImportPath(options.story.componentPath, options.resolveFrom);
|
|
644
658
|
const storyModule = await options.runtime.loadModule(storyModulePath);
|
|
645
|
-
const
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
659
|
+
const { metaComponent, metaArgs, storyComponent, storyLevelArgs } = resolveStoryAnnotations(
|
|
660
|
+
storyModule,
|
|
661
|
+
options.story.exportName
|
|
662
|
+
);
|
|
663
|
+
if (typeof metaComponent !== "function") {
|
|
649
664
|
throw new Error(
|
|
650
|
-
`Unable to prerender story "${options.story.id}". Missing
|
|
665
|
+
`Unable to prerender story "${options.story.id}". Missing component in ${options.story.importPath}.`
|
|
651
666
|
);
|
|
652
667
|
}
|
|
653
|
-
if (
|
|
668
|
+
if (storyComponent && storyComponent !== metaComponent) {
|
|
654
669
|
return void 0;
|
|
655
670
|
}
|
|
656
|
-
const storyArgs = mergeMetaArgsWithStoryArgs(
|
|
657
|
-
toRecord(defaultStoryMeta.args),
|
|
658
|
-
toRecord(selectedStoryExport.args)
|
|
659
|
-
);
|
|
671
|
+
const storyArgs = mergeMetaArgsWithStoryArgs(metaArgs, storyLevelArgs);
|
|
660
672
|
const { componentArgs, storySlots } = separateStorySlots(storyArgs);
|
|
661
673
|
return options.runtime.renderAstroStory({
|
|
662
674
|
component: componentPath,
|
|
@@ -669,6 +681,28 @@ async function renderProductionStoryToHtml(options) {
|
|
|
669
681
|
}
|
|
670
682
|
});
|
|
671
683
|
}
|
|
684
|
+
function resolveStoryAnnotations(storyModule, exportName) {
|
|
685
|
+
const rawStoryExport = storyModule[exportName];
|
|
686
|
+
if (isRecord2(rawStoryExport) && rawStoryExport._tag === "Story") {
|
|
687
|
+
const storyInput = toRecord(rawStoryExport.input) ?? {};
|
|
688
|
+
const meta = isRecord2(rawStoryExport.meta) ? rawStoryExport.meta : {};
|
|
689
|
+
const metaInput = toRecord(meta.input) ?? {};
|
|
690
|
+
return {
|
|
691
|
+
metaComponent: metaInput.component,
|
|
692
|
+
metaArgs: toRecord(metaInput.args),
|
|
693
|
+
storyComponent: storyInput.component,
|
|
694
|
+
storyLevelArgs: toRecord(storyInput.args)
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
const defaultStoryMeta = isRecord2(storyModule.default) ? storyModule.default : {};
|
|
698
|
+
const selectedStoryExport = isRecord2(rawStoryExport) ? rawStoryExport : {};
|
|
699
|
+
return {
|
|
700
|
+
metaComponent: defaultStoryMeta.component,
|
|
701
|
+
metaArgs: toRecord(defaultStoryMeta.args),
|
|
702
|
+
storyComponent: selectedStoryExport.component,
|
|
703
|
+
storyLevelArgs: toRecord(selectedStoryExport.args)
|
|
704
|
+
};
|
|
705
|
+
}
|
|
672
706
|
function resolveProjectImportPath(importPath, resolveFrom) {
|
|
673
707
|
if (importPath.startsWith("./") || importPath.startsWith("../")) {
|
|
674
708
|
return resolve2(resolveFrom, importPath);
|
|
@@ -681,21 +715,6 @@ function mergeMetaArgsWithStoryArgs(metaArgs, storyArgs) {
|
|
|
681
715
|
...storyArgs ?? {}
|
|
682
716
|
};
|
|
683
717
|
}
|
|
684
|
-
function separateStorySlots(storyArgs) {
|
|
685
|
-
const componentArgs = { ...storyArgs };
|
|
686
|
-
const storySlots = componentArgs.slots;
|
|
687
|
-
delete componentArgs.slots;
|
|
688
|
-
if (!isRecord2(storySlots)) {
|
|
689
|
-
return {
|
|
690
|
-
componentArgs,
|
|
691
|
-
storySlots: {}
|
|
692
|
-
};
|
|
693
|
-
}
|
|
694
|
-
return {
|
|
695
|
-
componentArgs,
|
|
696
|
-
storySlots
|
|
697
|
-
};
|
|
698
|
-
}
|
|
699
718
|
function isRecord2(value) {
|
|
700
719
|
return typeof value === "object" && value !== null;
|
|
701
720
|
}
|
|
@@ -1553,15 +1572,18 @@ var viteFinal = async (config, storybookOptions) => {
|
|
|
1553
1572
|
"astro:preact:opts",
|
|
1554
1573
|
"astro:toolbar:internal"
|
|
1555
1574
|
];
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1575
|
+
const viteMajor = Number.parseInt(viteVersion, 10);
|
|
1576
|
+
if (viteMajor < 8) {
|
|
1577
|
+
if (!finalConfig.optimizeDeps.esbuildOptions) {
|
|
1578
|
+
finalConfig.optimizeDeps.esbuildOptions = {};
|
|
1579
|
+
}
|
|
1580
|
+
if (!finalConfig.optimizeDeps.esbuildOptions.external) {
|
|
1581
|
+
finalConfig.optimizeDeps.esbuildOptions.external = [];
|
|
1582
|
+
}
|
|
1583
|
+
for (const mod of integrationVirtualModules) {
|
|
1584
|
+
if (!finalConfig.optimizeDeps.esbuildOptions.external.includes(mod)) {
|
|
1585
|
+
finalConfig.optimizeDeps.esbuildOptions.external.push(mod);
|
|
1586
|
+
}
|
|
1565
1587
|
}
|
|
1566
1588
|
}
|
|
1567
1589
|
const optimizeDepsMut = finalConfig.optimizeDeps;
|
|
@@ -1570,6 +1592,20 @@ var viteFinal = async (config, storybookOptions) => {
|
|
|
1570
1592
|
/* @__PURE__ */ new Set([...rolldownOpts.external ?? [], ...integrationVirtualModules])
|
|
1571
1593
|
);
|
|
1572
1594
|
optimizeDepsMut.rolldownOptions = rolldownOpts;
|
|
1595
|
+
if (configType === "DEVELOPMENT" && viteMajor >= 8) {
|
|
1596
|
+
const stripReactRefreshWrapper = (plugins) => plugins.map((plugin) => Array.isArray(plugin) ? stripReactRefreshWrapper(plugin) : plugin).filter(
|
|
1597
|
+
(plugin) => !(plugin && typeof plugin === "object" && plugin.name === "vite:react:refresh-wrapper")
|
|
1598
|
+
);
|
|
1599
|
+
finalConfig.plugins = stripReactRefreshWrapper(
|
|
1600
|
+
finalConfig.plugins ?? []
|
|
1601
|
+
);
|
|
1602
|
+
const entryPreviews = integrations.map((integration) => integration.storybookEntryPreview).filter((specifier) => Boolean(specifier));
|
|
1603
|
+
for (const specifier of entryPreviews) {
|
|
1604
|
+
if (!finalConfig.optimizeDeps.exclude.includes(specifier)) {
|
|
1605
|
+
finalConfig.optimizeDeps.exclude.push(specifier);
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1573
1609
|
return finalConfig;
|
|
1574
1610
|
};
|
|
1575
1611
|
function mergeEnvPrefixes(existing, additionalPrefix) {
|