@skafform/vite-plugin 0.1.5 → 0.1.6

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.
Files changed (2) hide show
  1. package/dist/index.js +9 -6
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -245,7 +245,7 @@ ${lightVars}
245
245
  const basename = absPath.split("/").pop().replace(/\.[^.]+$/, "");
246
246
  const varName = `wr_${i++}`;
247
247
  imports.push(`import * as ${varName} from ${JSON.stringify(absPath)}`);
248
- items.push(` { brick: ${JSON.stringify(w.brick)}, basename: ${JSON.stringify(basename)}, Component: ${varName}.default }`);
248
+ items.push(` { brick: ${JSON.stringify(w.brick)}, basename: ${JSON.stringify(basename)}, Component: ${varName}.default, schema: ${varName}.schema ?? [] }`);
249
249
  }
250
250
  entries.push(` ${JSON.stringify(zone)}: [
251
251
  ${items.join(",\n")}
@@ -268,7 +268,7 @@ ${entries.join(",\n")}
268
268
  const absPath = norm(resolve(root, widget.component));
269
269
  const basename = absPath.split("/").pop().replace(/\.[^.]+$/, "");
270
270
  const key = `${widget.zone}:${brickName}:${basename}`;
271
- widgets.push({ key, absPath, varName: `wl_${i++}` });
271
+ widgets.push({ key, absPath, varName: `wl_${i++}`, brickName, basename });
272
272
  }
273
273
  }
274
274
  if (widgets.length === 0) {
@@ -277,13 +277,16 @@ ${entries.join(",\n")}
277
277
  return [
278
278
  ...widgets.map((w) => `import * as ${w.varName} from ${JSON.stringify(w.absPath)}`),
279
279
  `const _loaders = [`,
280
- ...widgets.map((w) => ` { key: ${JSON.stringify(w.key)}, fn: ${w.varName}.loader ?? null },`),
280
+ ...widgets.map((w) => ` { key: ${JSON.stringify(w.key)}, brick: ${JSON.stringify(w.brickName)}, basename: ${JSON.stringify(w.basename)}, fn: ${w.varName}.loader ?? null },`),
281
281
  `]`,
282
- `export async function runWidgetLoaders(request) {`,
282
+ `export async function runWidgetLoaders(request, dbWidgets) {`,
283
+ ` const _all = Object.values(dbWidgets ?? {}).flat()`,
283
284
  ` const results = {}`,
284
285
  ` await Promise.all(`,
285
- ` _loaders.filter(w => w.fn !== null).map(async ({ key, fn }) => {`,
286
- ` try { results[key] = await fn({ request }) } catch { results[key] = null }`,
286
+ ` _loaders.filter(w => w.fn !== null).map(async ({ key, fn, brick, basename }) => {`,
287
+ ` const _inst = _all.find(w => w.brick === brick && w.component.split('/').pop()?.replace(/\\.[^.]+$/, '') === basename)`,
288
+ ` const _config = _inst?.config ?? {}`,
289
+ ` try { results[key] = await fn({ request, config: _config }) } catch { results[key] = null }`,
287
290
  ` })`,
288
291
  ` )`,
289
292
  ` return results`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skafform/vite-plugin",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {