@storyblok/astro 10.0.1 → 10.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/index.js CHANGED
@@ -113,13 +113,15 @@ function C(e, t, n, r) {
113
113
  };
114
114
  }
115
115
  function w(e, t, n) {
116
+ let r = `${s(e)}/storyblok/**/*.astro`, i = [...n];
117
+ t && i.push(t);
118
+ let a = i.map((e) => e.importStatement), o = i.map((e) => e.wrapperDefinition), c = i.map((e) => e.registrationCall);
116
119
  return `
117
- // Import utilities and fallback component
118
120
  import { toCamelCase } from '@storyblok/astro';
121
+ ${a.join("\n ")}
122
+
123
+ const modules = import.meta.glob('${r}', { eager: true });
119
124
 
120
- // Dynamically import all Storyblok components using Vite's glob import
121
- const modules = import.meta.glob('${`${s(e)}/storyblok/**/*.astro`}', { eager: true });
122
- // Process imported modules into a components object
123
125
  const storyblokComponents = {};
124
126
  const createComponentLoader = (module) => {
125
127
  return async () => module?.default ?? module;
@@ -131,25 +133,24 @@ function w(e, t, n) {
131
133
  get: () => createComponentLoader(component),
132
134
  });
133
135
  };
136
+
134
137
  for (const filePath in modules) {
135
- // Extract component name from file path (remove extension)
136
138
  const fileName = filePath.split('/').pop();
137
- const componentName = toCamelCase(fileName?.replace(/\.[^/.]+$/, '') ?? '');
139
+ const componentName = toCamelCase(fileName?.replace(/\\.[^/.]+$/, '') ?? '');
138
140
  if (componentName) {
139
141
  registerComponent(componentName, modules[filePath]);
140
142
  }
141
143
  }
142
-
143
- // Manual components
144
- ${n.join("\n\n")}
145
- // Add fallback component if enabled
146
- ${t}
147
- // Export the components object for use in Storyblok initialization
144
+
145
+ ${o.join("\n ")}
146
+
147
+ ${c.join("\n ")}
148
+
148
149
  export { storyblokComponents };
149
150
  `.trim();
150
151
  }
151
152
  async function ee(e, t, n, r) {
152
- if (!n) return "";
153
+ if (!n) return null;
153
154
  if (!r) return D({
154
155
  componentName: "FallbackComponent",
155
156
  importPath: "@storyblok/astro/FallbackComponent.astro"
@@ -181,10 +182,12 @@ function E(e, t) {
181
182
  return o(`${s(e)}${s(t)}`);
182
183
  }
183
184
  function D({ componentName: e, importPath: t }) {
184
- return `
185
- import ${e} from '${t}';
186
- registerComponent('${e}', ${e});
187
- `.trim();
185
+ let n = `__${e}_component__`, r = `__${e}_wrapper__`;
186
+ return {
187
+ importStatement: `import ${n} from '${t}';`,
188
+ wrapperDefinition: `const ${r} = { get default() { return ${n}; } };`,
189
+ registrationCall: `registerComponent('${e}', ${r});`
190
+ };
188
191
  }
189
192
  //#endregion
190
193
  //#region src/lib/storyblok-integration.ts
@@ -1,8 +1,32 @@
1
1
  import { Plugin } from 'vite';
2
2
  /**
3
- * Vite plugin that automatically imports Storyblok components from a specified directory
4
- * and merges them with optional user-provided component mappings.
5
- *
6
- * @returns Vite plugin object
3
+ * Vite plugin that auto-imports Storyblok components from a directory
4
+ * and merges them with user-provided component mappings.
7
5
  */
8
6
  export declare function vitePluginImportStoryblokComponents(components: Record<string, string>, componentsDir: string, enableFallbackComponent: boolean, customFallbackComponent?: string): Plugin;
7
+ export interface ComponentRegistrationParts {
8
+ importStatement: string;
9
+ wrapperDefinition: string;
10
+ registrationCall: string;
11
+ }
12
+ /**
13
+ * Generates the virtual module code with:
14
+ * - Static imports at the top for proper hoisting
15
+ * - Glob-imported components from storyblok folder
16
+ * - Manual and fallback component registrations
17
+ */
18
+ export declare function generateModuleCode(componentsDir: string, fallbackRegistration: ComponentRegistrationParts | null, manualRegistrations: ComponentRegistrationParts[]): string;
19
+ interface CreateComponentRegistrationPartsOptions {
20
+ componentName: string;
21
+ importPath: string;
22
+ }
23
+ /**
24
+ * Generates structured registration parts for a component.
25
+ *
26
+ * Uses a getter wrapper to avoid TDZ (Temporal Dead Zone) errors.
27
+ * When Vite bundles modules, direct references to imported components
28
+ * can cause "Cannot access 'X' before initialization" errors.
29
+ * The getter defers access until the component is actually needed.
30
+ */
31
+ export declare function createComponentRegistrationParts({ componentName, importPath, }: CreateComponentRegistrationPartsOptions): ComponentRegistrationParts;
32
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@storyblok/astro",
3
3
  "type": "module",
4
- "version": "10.0.1",
4
+ "version": "10.1.0",
5
5
  "private": false,
6
6
  "description": "Official Astro integration for the Storyblok Headless CMS",
7
7
  "author": "Storyblok",
@@ -51,8 +51,8 @@
51
51
  "dependencies": {
52
52
  "camelcase": "^8.0.0",
53
53
  "morphdom": "^2.7.8",
54
- "@storyblok/richtext": "5.0.1",
55
- "@storyblok/js": "6.0.1"
54
+ "@storyblok/richtext": "5.1.0",
55
+ "@storyblok/js": "6.1.0"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@cypress/vite-dev-server": "^6.0.3",
@@ -73,7 +73,7 @@
73
73
  "vite-plugin-dts": "^4.5.3",
74
74
  "vite-plugin-static-copy": "^4.1.1",
75
75
  "vitest": "^3.1.3",
76
- "@storyblok/eslint-config": "0.5.1"
76
+ "@storyblok/eslint-config": "0.6.0"
77
77
  },
78
78
  "eslintConfig": {
79
79
  "env": {