@thexjs/core 1.2.4 → 1.3.1

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/adapter.d.ts CHANGED
@@ -39,6 +39,11 @@ interface AdapterOptions {
39
39
  images?: {
40
40
  remoteHosts?: string[];
41
41
  };
42
+ /** Client build output dir. Server-mode routes' island bundles are emitted
43
+ * into `<islandsDir>/_islands/` here so adapters can ship them as static
44
+ * assets. Undefined skips island bundling (server HTML ships no island
45
+ * script tags). */
46
+ islandsDir?: string;
42
47
  }
43
48
  /** A single file that needs to be transpiled from .ts/.tsx source into a
44
49
  * Node-runnable .mjs module and given a stable import identifier so the
@@ -60,6 +65,9 @@ interface ResolvedRoute {
60
65
  route: CompiledModuleRef;
61
66
  layoutChain: CompiledModuleRef[];
62
67
  middlewareChain: CompiledModuleRef[];
68
+ /** Public script URLs for the pre-bundled island hydration chunks this
69
+ * route needs. Empty/omitted when the route uses no islands. */
70
+ islandScripts?: string[];
63
71
  }
64
72
  interface ResolvedAction {
65
73
  parentPath: string;
package/dist/adapter.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import {
2
+ bundleRouteIslandsToDisk,
2
3
  findLayoutChain,
3
4
  findMiddlewareChain,
4
5
  scanApiDir,
@@ -8,7 +9,7 @@ import {
8
9
  scanNotFound,
9
10
  scanPages,
10
11
  scanRoutes
11
- } from "./chunk-O6SIM7EF.js";
12
+ } from "./chunk-MYYP67KQ.js";
12
13
 
13
14
  // src/adapter/bundle.ts
14
15
  import { mkdirSync, rmSync, writeFileSync } from "fs";
@@ -131,7 +132,7 @@ function generateAdapterEntry(manifest, entryDir) {
131
132
  ` module: ${r.route.identifier},`,
132
133
  ` layoutModules: [${layoutMods}].filter(Boolean),`,
133
134
  ` middlewareModules: [${mwMods}].filter(Boolean),`,
134
- " islandScripts: [],",
135
+ ` islandScripts: ${JSON.stringify(r.islandScripts ?? [])},`,
135
136
  " },"
136
137
  );
137
138
  }
@@ -206,6 +207,26 @@ async function resolveBuildManifest(options, scratchDir) {
206
207
  const nestedLayouts = existsSync(pagesDir) ? scanLayouts(pagesDir) : [];
207
208
  const layouts = [...dedicatedLayouts, ...nestedLayouts];
208
209
  const middlewareEntries = existsSync(pagesDir) ? scanMiddleware(pagesDir) : [];
210
+ const islandsDir = options.islandsDir;
211
+ const actions = [];
212
+ const actionModules = /* @__PURE__ */ new Map();
213
+ if (actionsDir && existsSync(actionsDir)) {
214
+ for (const actionFile of scanRoutes(actionsDir)) {
215
+ const segments = actionFile.routePath.split("/").filter(Boolean);
216
+ const fileName = segments[segments.length - 1] ?? "";
217
+ const parentPath = fileName === "index" || !fileName ? actionFile.routePath : `/${segments.slice(0, -1).join("/")}`;
218
+ actions.push({
219
+ parentPath,
220
+ paramNames: actionFile.paramNames,
221
+ module: registry.ref(actionFile.filePath, "action")
222
+ });
223
+ const actionMod = await import(actionFile.filePath);
224
+ actionModules.set(actionFile.filePath, {
225
+ parentPath,
226
+ fnNames: Object.keys(actionMod).filter((k) => k !== "default")
227
+ });
228
+ }
229
+ }
209
230
  const routes = [];
210
231
  for (const entry of found) {
211
232
  if (entry.isApi) {
@@ -229,6 +250,25 @@ async function resolveBuildManifest(options, scratchDir) {
229
250
  );
230
251
  if (missingDedicated.length > 0) layoutChain.unshift(...missingDedicated);
231
252
  const mwChain = findMiddlewareChain(entry.filePath, middlewareEntries, pagesDir);
253
+ let islandScripts;
254
+ if (islandsDir) {
255
+ const islandNames = /* @__PURE__ */ new Set();
256
+ if (mod.islands) for (const key of Object.keys(mod.islands)) islandNames.add(key);
257
+ for (const layout of layoutChain) {
258
+ const layoutMod = await import(layout.filePath);
259
+ if (layoutMod.islands)
260
+ for (const key of Object.keys(layoutMod.islands)) islandNames.add(key);
261
+ }
262
+ if (islandNames.size > 0) {
263
+ islandScripts = await bundleRouteIslandsToDisk(
264
+ entry.filePath,
265
+ layoutChain.map((l) => l.filePath),
266
+ [...islandNames],
267
+ join2(islandsDir, "_islands"),
268
+ actionModules
269
+ );
270
+ }
271
+ }
232
272
  routes.push({
233
273
  routePath: entry.routePath,
234
274
  paramNames: entry.paramNames,
@@ -237,22 +277,10 @@ async function resolveBuildManifest(options, scratchDir) {
237
277
  ...mod.revalidate !== void 0 ? { revalidate: mod.revalidate } : {},
238
278
  route: registry.ref(entry.filePath, "page"),
239
279
  layoutChain: layoutChain.map((l) => registry.ref(l.filePath, "layout")),
240
- middlewareChain: mwChain.map((m) => registry.ref(m.filePath, "mw"))
280
+ middlewareChain: mwChain.map((m) => registry.ref(m.filePath, "mw")),
281
+ ...islandScripts ? { islandScripts } : {}
241
282
  });
242
283
  }
243
- const actions = [];
244
- if (actionsDir && existsSync(actionsDir)) {
245
- for (const actionFile of scanRoutes(actionsDir)) {
246
- const segments = actionFile.routePath.split("/").filter(Boolean);
247
- const fileName = segments[segments.length - 1] ?? "";
248
- const parentPath = fileName === "index" || !fileName ? actionFile.routePath : `/${segments.slice(0, -1).join("/")}`;
249
- actions.push({
250
- parentPath,
251
- paramNames: actionFile.paramNames,
252
- module: registry.ref(actionFile.filePath, "action")
253
- });
254
- }
255
- }
256
284
  const notFoundEntry = existsSync(pagesDir) ? scanNotFound(pagesDir) : null;
257
285
  const notFound = notFoundEntry ? registry.ref(notFoundEntry.filePath, "notfound") : void 0;
258
286
  const rootLayoutEntry = dedicatedLayouts[0] ?? layouts.find((l) => l.dirPath === pagesDir);