@smallpen/local-package 0.1.0-alpha.12 → 0.1.0-alpha.14

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.
@@ -39,7 +39,7 @@ export async function inspectProjection(product, projection, options = {}) {
39
39
  ].includes(error.code)
40
40
  )
41
41
  throw error;
42
- failure = { code: error.code, message: error.message };
42
+ failure = { code: error.code, message: error.message, ...(error.details ? { details: error.details } : {}) };
43
43
  }
44
44
  const origin = {
45
45
  x: (root?.x ?? 0) + (options.crop?.x ?? 0),
@@ -84,7 +84,9 @@ export async function inspectProjection(product, projection, options = {}) {
84
84
  };
85
85
  update(tree.root);
86
86
  const diagnostics = failure
87
- ? [failure]
87
+ ? [failure, ...(failure.details?.nodes ?? []).map(({ nodeId, path, ...details }) => ({
88
+ code: failure.code, message: failure.message, nodeId, path, details,
89
+ }))]
88
90
  : (render?.diagnostics ?? []).filter(
89
91
  (item) => item.code !== "layout_projection_partial",
90
92
  );
@@ -4,7 +4,7 @@ import { join, dirname } from "node:path";
4
4
  import { fileURLToPath, pathToFileURL } from "node:url";
5
5
  import { provisionFonts } from "./render-fonts.mjs";
6
6
  import { inspectMedia } from "./media-inspect.mjs";
7
- import { SmallPenError, stableRuntimeUuid } from "@smallpen/core";
7
+ import { SmallPenError, stableRuntimeUuid, elementPath } from "@smallpen/core";
8
8
 
9
9
  const runtime = join(dirname(fileURLToPath(import.meta.url)), "..", "runtime");
10
10
  let initialized;
@@ -121,6 +121,19 @@ async function resources(engine, product, options) {
121
121
  return { fonts, fontFamilies, images };
122
122
  }
123
123
 
124
+ // Nodes have already resolved their components and Tokens. The App node
125
+ // projector only needs asset metadata and resource identities here. Sending
126
+ // every page and variant made each native measurement convert the entire
127
+ // package to Clojure data twice, even for a single button.
128
+ function renderSnapshot(snapshot) {
129
+ const assets = snapshot.manifest.entries.assets;
130
+ return {
131
+ manifest: { packageId: snapshot.manifest.packageId, entries: { assets } },
132
+ entries: Object.fromEntries(assets.map(entry => [entry, snapshot.entries[entry]])),
133
+ runtime: { file: snapshot.runtime.file, fonts: snapshot.runtime.fonts, media: snapshot.runtime.media },
134
+ };
135
+ }
136
+
124
137
  export async function renderAppProjection(product, projection, options = {}) {
125
138
  if (projection.fallbackUsed)
126
139
  throw new SmallPenError(
@@ -169,6 +182,7 @@ export async function renderAppProjection(product, projection, options = {}) {
169
182
  initialized = undefined;
170
183
  throw error;
171
184
  }));
185
+ let sourceIds = {};
172
186
  try {
173
187
  const assets = await resources(engine, product, options);
174
188
  let nodes = projection.nodes,
@@ -214,16 +228,10 @@ export async function renderAppProjection(product, projection, options = {}) {
214
228
  );
215
229
  const request = {
216
230
  snapshot: {
217
- manifest: product.manifest,
218
- entries: product.entries,
219
- runtime: product.runtime,
231
+ ...renderSnapshot(product),
220
232
  libraries: [options.foundation, ...(options.libraries ?? [])]
221
233
  .filter(Boolean)
222
- .map((snapshot) => ({
223
- manifest: snapshot.manifest,
224
- entries: snapshot.entries,
225
- runtime: snapshot.runtime,
226
- })),
234
+ .map(renderSnapshot),
227
235
  },
228
236
  nodes,
229
237
  nodeIds,
@@ -234,7 +242,7 @@ export async function renderAppProjection(product, projection, options = {}) {
234
242
  forExport: options.forExport === true,
235
243
  fontFamilies: assets.fontFamilies,
236
244
  };
237
- const sourceIds = Object.fromEntries(
245
+ sourceIds = Object.fromEntries(
238
246
  Object.entries(nodeIds).map(([id, uuid]) => [uuid, id]),
239
247
  );
240
248
  const described = engine.renderer.describe(request);
@@ -356,6 +364,10 @@ export async function renderAppProjection(product, projection, options = {}) {
356
364
  // A native panic invalidates the module. A later request can reload it.
357
365
  if (error instanceof WebAssembly.RuntimeError) initialized = undefined;
358
366
  const details = engine.renderer.errorDetails(error) ?? {};
367
+ if (details.nodes) details.nodes = details.nodes.map(node => {
368
+ const nodeId = sourceIds[node.nodeId] ?? node.nodeId;
369
+ return { ...node, nodeId, path: elementPath(projection.nodes, projection.rootId, nodeId) };
370
+ });
359
371
  throw new SmallPenError(
360
372
  details.code?.replaceAll("-", "_") ?? "shared_render_failed",
361
373
  error.message ?? "Shared App renderer failed",