@storybook-astro/framework 0.1.0-beta.7 → 0.1.0-beta.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook-astro/framework",
3
- "version": "0.1.0-beta.7",
3
+ "version": "0.1.0-beta.8",
4
4
  "description": "Community-supported Storybook framework for Astro 6 components",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -147,7 +147,7 @@
147
147
  }
148
148
  },
149
149
  "dependencies": {
150
- "@storybook-astro/renderer": "0.1.0-beta.7",
150
+ "@storybook-astro/renderer": "0.1.0-beta.8",
151
151
  "vite": "^6.2.5 || ^7.0.0"
152
152
  }
153
153
  }
package/src/middleware.ts CHANGED
@@ -9,6 +9,7 @@ export type HandlerProps = {
9
9
  };
10
10
 
11
11
  export async function handlerFactory(integrations: Integration[]) {
12
+ const safeIntegrations = integrations ?? [];
12
13
  const container = await AstroContainer.create({
13
14
  // Somewhat hacky way to force client-side Storybook's Vite to resolve modules properly
14
15
  resolve: async (s) => {
@@ -16,7 +17,7 @@ export async function handlerFactory(integrations: Integration[]) {
16
17
  return `/@id/${s}`;
17
18
  }
18
19
 
19
- for (const integration of integrations) {
20
+ for (const integration of safeIntegrations) {
20
21
  const resolution = integration.resolveClient(s);
21
22
 
22
23
  if (resolution) {
@@ -1,6 +1,7 @@
1
1
  import type { Integration } from './integrations/index.ts';
2
2
 
3
3
  export function viteAstroContainerRenderersPlugin(integrations: Integration[]) {
4
+ const safeIntegrations = integrations ?? [];
4
5
  const name = 'astro-container-renderers';
5
6
  const virtualModuleId = `virtual:${name}`;
6
7
  const resolvedVirtualModuleId = `\0${virtualModuleId}`;
@@ -16,12 +17,12 @@ export function viteAstroContainerRenderersPlugin(integrations: Integration[]) {
16
17
 
17
18
  load(id: string) {
18
19
  if (id === resolvedVirtualModuleId) {
19
- const importStatements = buildImportStatements(integrations);
20
+ const importStatements = buildImportStatements(safeIntegrations);
20
21
 
21
22
  const code = `
22
23
  ${importStatements}
23
24
  export function addRenderers(container) {
24
- ${integrations.map((integration) => buildServerRenderer(integration) + '\n' + buildClientRenderer(integration)).join('\n')}
25
+ ${safeIntegrations.map((integration) => buildServerRenderer(integration) + '\n' + buildClientRenderer(integration)).join('\n')}
25
26
  }
26
27
  `;
27
28
 
@@ -26,6 +26,7 @@ import { createViteServer } from './viteStorybookAstroMiddlewarePlugin.ts';
26
26
  * - Stories that override the meta component are skipped
27
27
  */
28
28
  export function vitePluginAstroBuildPrerender(integrations: Integration[]): Plugin {
29
+ const safeIntegrations = integrations ?? [];
29
30
  let viteServer: ViteDevServer | null = null;
30
31
  let handler: ((data: HandlerProps) => Promise<string>) | null = null;
31
32
 
@@ -41,14 +42,14 @@ export function vitePluginAstroBuildPrerender(integrations: Integration[]): Plug
41
42
 
42
43
  async buildStart() {
43
44
  try {
44
- viteServer = await createViteServer(integrations);
45
+ viteServer = await createViteServer(safeIntegrations);
45
46
 
46
47
  const filePath = fileURLToPath(new URL('./middleware', import.meta.url));
47
48
  const middleware = await viteServer.ssrLoadModule(filePath, {
48
49
  fixStacktrace: true
49
50
  });
50
51
 
51
- handler = await middleware.handlerFactory(integrations);
52
+ handler = await middleware.handlerFactory(safeIntegrations);
52
53
  } catch (err) {
53
54
  console.warn(
54
55
  '[storybook-astro] Failed to create pre-render server:',
@@ -20,7 +20,7 @@ export async function vitePluginStorybookAstroMiddleware(options: FrameworkOptio
20
20
  const middleware = await viteServer.ssrLoadModule(filePath, {
21
21
  fixStacktrace: true
22
22
  });
23
- const handler = await middleware.handlerFactory(options.integrations);
23
+ const handler = await middleware.handlerFactory(options.integrations ?? []);
24
24
 
25
25
  server.ws.on('astro:render:request', async (data: RenderRequestMessage['data']) => {
26
26
  try {
@@ -93,13 +93,14 @@ return;
93
93
 
94
94
  export async function createViteServer(integrations: Integration[]) {
95
95
  const { getViteConfig } = await import('astro/config');
96
+ const safeIntegrations = integrations ?? [];
96
97
 
97
98
  const config = await getViteConfig(
98
99
  {},
99
100
  {
100
101
  configFile: false,
101
102
  integrations: await Promise.all(
102
- integrations.map((integration) => integration.loadIntegration())
103
+ safeIntegrations.map((integration) => integration.loadIntegration())
103
104
  )
104
105
  }
105
106
  )({ mode: 'development', command: 'serve' });
@@ -109,7 +110,7 @@ export async function createViteServer(integrations: Integration[]) {
109
110
  ...config,
110
111
  plugins: [
111
112
  ...(config.plugins?.filter(Boolean) ?? []),
112
- viteAstroContainerRenderersPlugin(integrations),
113
+ viteAstroContainerRenderersPlugin(safeIntegrations),
113
114
  vitePluginAstroFontsFallback()
114
115
  ]
115
116
  });
@@ -1,6 +1,7 @@
1
1
  import type { Integration } from './integrations/index.ts';
2
2
 
3
3
  export function viteStorybookRendererFallbackPlugin(integrations: Integration[]) {
4
+ const safeIntegrations = integrations ?? [];
4
5
  const name = 'storybook-renderer-fallback';
5
6
  const virtualModuleId = `virtual:${name}`;
6
7
  const resolvedVirtualModuleId = `\0${virtualModuleId}`;
@@ -16,7 +17,7 @@ export function viteStorybookRendererFallbackPlugin(integrations: Integration[])
16
17
 
17
18
  load(id: string) {
18
19
  if (id === resolvedVirtualModuleId) {
19
- return integrations
20
+ return safeIntegrations
20
21
  .filter((integration) => integration.storybookEntryPreview)
21
22
  .map(
22
23
  (integration) =>