@storybook-astro/framework 1.2.0 → 1.3.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/{base-IRZo3zgK.d.ts → base-DT67T5pi.d.ts} +1 -0
- package/dist/{chunk-T7NWIO5S.js → chunk-2EABPTOY.js} +5 -5
- package/dist/{chunk-PJEDXZVN.js → chunk-7YBE4TTI.js} +2 -1
- package/dist/chunk-7YBE4TTI.js.map +1 -0
- package/dist/{chunk-POHTFYST.js → chunk-AYYMNFI6.js} +104 -6
- package/dist/chunk-AYYMNFI6.js.map +1 -0
- package/dist/{chunk-OUEDTRBO.js → chunk-B454DGX6.js} +259 -67
- package/dist/chunk-B454DGX6.js.map +1 -0
- package/dist/chunk-B5HHF6FC.js +116 -0
- package/dist/chunk-B5HHF6FC.js.map +1 -0
- package/dist/chunk-CU57AJUW.js +1402 -0
- package/dist/chunk-CU57AJUW.js.map +1 -0
- package/dist/{chunk-DNGQBPT7.js → chunk-PUTCAN6X.js} +5 -2
- package/dist/{chunk-DNGQBPT7.js.map → chunk-PUTCAN6X.js.map} +1 -1
- package/dist/{chunk-4SWPVM6R.js → chunk-WUTCMEF5.js} +2 -2
- package/dist/index.d.ts +17 -7
- package/dist/index.js +6 -5
- package/dist/index.js.map +1 -1
- package/dist/integrations/index.d.ts +2 -1
- package/dist/integrations/index.js +1 -1
- package/dist/middleware.js +18 -131
- package/dist/middleware.js.map +1 -1
- package/dist/{types-C-jan6Px.d.ts → preset-BvgHg2of.d.ts} +8 -11
- package/dist/preset.d.ts +2 -10
- package/dist/preset.js +5 -4
- package/dist/renderer/renderer-dev.js +62 -0
- package/dist/renderer/renderer-dev.js.map +1 -0
- package/dist/renderer/renderer-server.js +92 -0
- package/dist/renderer/renderer-server.js.map +1 -0
- package/dist/renderer/renderer-static.js +54 -0
- package/dist/renderer/renderer-static.js.map +1 -0
- package/dist/testing.js +12 -11
- package/dist/testing.js.map +1 -1
- package/dist/{viteStorybookAstroMiddlewarePlugin-2EFKTECT.js → viteStorybookAstroMiddlewarePlugin-UB6ZLJ4B.js} +4 -3
- package/dist/vitest/global-setup.js +6 -5
- package/dist/vitest/global-setup.js.map +1 -1
- package/dist/vitest/index.d.ts +1 -1
- package/dist/vitest/index.js +3 -3
- package/package.json +14 -43
- package/src/astroImageService.ts +57 -0
- package/src/astroRenderHandler.ts +205 -0
- package/src/importAstroConfig.ts +1 -1
- package/src/index.ts +2 -0
- package/src/integrations/alpine.ts +1 -0
- package/src/integrations/base.ts +6 -0
- package/src/lib/revive-dates.test.ts +106 -0
- package/src/lib/revive-dates.ts +51 -0
- package/src/middleware.ts +29 -200
- package/src/module-mocks.ts +153 -5
- package/src/preset.ts +38 -8
- package/src/productionRenderRuntime.ts +187 -0
- package/src/rules.test.ts +52 -4
- package/src/rules.ts +54 -7
- package/src/server/index.ts +101 -31
- package/src/storyRulesRuntime.ts +34 -0
- package/src/storySsrVite.ts +240 -0
- package/src/types.ts +0 -9
- package/src/virtual.d.ts +17 -3
- package/src/vite/{astroFilesVirtualModulePlugin.ts → astroFilesPlugin.ts} +4 -4
- package/src/vite/sanitizeConfigPlugin.ts +18 -0
- package/src/vite/{storybookAstroServerAuthConfigVirtualModulePlugin.test.ts → serverAuthPlugin.test.ts} +7 -10
- package/src/vite/{storybookAstroServerAuthConfigVirtualModulePlugin.ts → serverAuthPlugin.ts} +6 -9
- package/src/vite/serverRuntimePlugin.ts +109 -0
- package/src/vite/{storybookAstroRulesConfigVirtualModulePlugin.ts → storyRulesPlugin.ts} +6 -7
- package/src/vite/{createVirtualModulePlugin.test.ts → virtualModulePlugin.test.ts} +5 -5
- package/src/vite/{createVirtualModulePlugin.ts → virtualModulePlugin.ts} +2 -2
- package/src/viteAstroContainerRenderersPlugin.ts +72 -2
- package/src/vitePluginAstroBuildPrerender.ts +75 -646
- package/src/vitePluginAstroBuildServer.ts +217 -165
- package/src/vitePluginAstroBuildShared.test.ts +87 -0
- package/src/vitePluginAstroBuildShared.ts +465 -0
- package/src/vitePluginStoryModuleMocks.ts +29 -0
- package/src/viteStorybookAstroMiddlewarePlugin.ts +8 -0
- package/src/viteStorybookAstroRendererPlugin.ts +13 -6
- package/src/viteStorybookRendererFallbackPlugin.ts +2 -2
- package/dist/chunk-OUEDTRBO.js.map +0 -1
- package/dist/chunk-PBISP7PA.js +0 -1137
- package/dist/chunk-PBISP7PA.js.map +0 -1
- package/dist/chunk-PJEDXZVN.js.map +0 -1
- package/dist/chunk-POHTFYST.js.map +0 -1
- package/dist/node/index.d.ts +0 -10
- package/dist/node/index.js +0 -10
- package/dist/node/index.js.map +0 -1
- package/src/vite/storybookAstroSanitizationConfigVirtualModulePlugin.ts +0 -21
- /package/dist/{chunk-T7NWIO5S.js.map → chunk-2EABPTOY.js.map} +0 -0
- /package/dist/{chunk-4SWPVM6R.js.map → chunk-WUTCMEF5.js.map} +0 -0
- /package/dist/{viteStorybookAstroMiddlewarePlugin-2EFKTECT.js.map → viteStorybookAstroMiddlewarePlugin-UB6ZLJ4B.js.map} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Integration } from './integrations/index.ts';
|
|
2
|
-
import {
|
|
2
|
+
import { createVirtualModule } from './vite/virtualModulePlugin.ts';
|
|
3
3
|
|
|
4
4
|
type PluginOptions = {
|
|
5
5
|
mode?: 'development' | 'production';
|
|
@@ -14,11 +14,15 @@ export function viteAstroContainerRenderersPlugin(
|
|
|
14
14
|
const mode = options.mode ?? 'development';
|
|
15
15
|
const staticModuleMap = options.staticModuleMap ?? {};
|
|
16
16
|
|
|
17
|
-
return
|
|
17
|
+
return createVirtualModule({
|
|
18
18
|
pluginName: 'storybook-astro:container-renderers',
|
|
19
19
|
virtualModuleId: 'virtual:astro-container-renderers',
|
|
20
20
|
load() {
|
|
21
21
|
const importStatements = buildImportStatements(safeIntegrations);
|
|
22
|
+
const browserModuleResolverHelpers =
|
|
23
|
+
mode === 'development' ? buildBrowserModuleResolverHelpers() : '';
|
|
24
|
+
const clientModuleEntrypoints =
|
|
25
|
+
mode === 'development' ? buildClientModuleEntrypoints(safeIntegrations) : '[]';
|
|
22
26
|
const clientResolvers =
|
|
23
27
|
mode === 'development'
|
|
24
28
|
? safeIntegrations
|
|
@@ -31,12 +35,14 @@ export function viteAstroContainerRenderersPlugin(
|
|
|
31
35
|
|
|
32
36
|
return `
|
|
33
37
|
${importStatements}
|
|
38
|
+
${browserModuleResolverHelpers}
|
|
34
39
|
|
|
35
40
|
export function addRenderers(container) {
|
|
36
41
|
${safeIntegrations.map((integration) => buildServerRenderer(integration) + '\n' + buildClientRenderer(integration)).join('\n')}
|
|
37
42
|
}
|
|
38
43
|
|
|
39
44
|
const staticClientModules = ${JSON.stringify(staticModuleMap, null, 2)};
|
|
45
|
+
const clientModuleEntrypoints = ${clientModuleEntrypoints};
|
|
40
46
|
|
|
41
47
|
const clientModulesResolvers = [
|
|
42
48
|
${clientResolvers}
|
|
@@ -53,6 +59,12 @@ export function viteAstroContainerRenderersPlugin(
|
|
|
53
59
|
return staticClientModules[normalizedSpecifier];
|
|
54
60
|
}
|
|
55
61
|
|
|
62
|
+
for (const entrypoint of clientModuleEntrypoints) {
|
|
63
|
+
if (normalizedSpecifier === entrypoint || normalizedSpecifier.startsWith(entrypoint)) {
|
|
64
|
+
return storybookAstroResolveBrowserModulePath(normalizedSpecifier);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
56
68
|
for (const resolver of clientModulesResolvers) {
|
|
57
69
|
const resolution = resolver(specifier);
|
|
58
70
|
|
|
@@ -66,6 +78,64 @@ export function viteAstroContainerRenderersPlugin(
|
|
|
66
78
|
});
|
|
67
79
|
}
|
|
68
80
|
|
|
81
|
+
function buildClientModuleEntrypoints(integrations: Integration[]) {
|
|
82
|
+
return JSON.stringify(
|
|
83
|
+
Array.from(
|
|
84
|
+
new Set(
|
|
85
|
+
integrations
|
|
86
|
+
.map((integration) => integration.renderer.client?.entrypoint)
|
|
87
|
+
.filter((entrypoint): entrypoint is string => Boolean(entrypoint))
|
|
88
|
+
)
|
|
89
|
+
)
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function buildBrowserModuleResolverHelpers() {
|
|
94
|
+
return `
|
|
95
|
+
import path from 'node:path';
|
|
96
|
+
import { createRequire } from 'node:module';
|
|
97
|
+
import { pathToFileURL } from 'node:url';
|
|
98
|
+
|
|
99
|
+
function storybookAstroToFileHref(filePath) {
|
|
100
|
+
return pathToFileURL(filePath).href;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function storybookAstroResolveFrom(moduleName, fromDirectory) {
|
|
104
|
+
const fromFile = path.join(fromDirectory, '__storybook_astro_resolve__.js');
|
|
105
|
+
|
|
106
|
+
return createRequire(storybookAstroToFileHref(fromFile)).resolve(moduleName);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function storybookAstroResolveFromCandidates(moduleName, primaryDirectory) {
|
|
110
|
+
const directories = [primaryDirectory, process.env.INIT_CWD].filter(Boolean);
|
|
111
|
+
const visited = new Set();
|
|
112
|
+
let lastError;
|
|
113
|
+
|
|
114
|
+
for (const directory of directories) {
|
|
115
|
+
if (visited.has(directory)) {
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
visited.add(directory);
|
|
120
|
+
|
|
121
|
+
try {
|
|
122
|
+
return storybookAstroResolveFrom(moduleName, directory);
|
|
123
|
+
} catch (error) {
|
|
124
|
+
lastError = error;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
throw lastError;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function storybookAstroResolveBrowserModulePath(moduleName, resolveFrom = process.cwd()) {
|
|
132
|
+
const resolvedPath = storybookAstroResolveFromCandidates(moduleName, resolveFrom).replace(/\\\\/g, '/');
|
|
133
|
+
|
|
134
|
+
return '/@fs/' + resolvedPath;
|
|
135
|
+
}
|
|
136
|
+
`;
|
|
137
|
+
}
|
|
138
|
+
|
|
69
139
|
function buildImportStatements(integrations: Integration[]) {
|
|
70
140
|
return integrations
|
|
71
141
|
.filter((integration) => integration.renderer.server)
|