resuxjs 0.2.6 → 0.2.9

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/README.md CHANGED
@@ -8,19 +8,7 @@ This is an MVP, not a production-ready framework.
8
8
 
9
9
  ## Create App
10
10
 
11
- Resux is published as one npm package. After publishing, users can scaffold an app with the same package they install in the app:
12
-
13
- ```sh
14
- npm create resuxjs@latest
15
- ```
16
-
17
- With a project directory:
18
-
19
- ```sh
20
- npm create resuxjs@latest my-app
21
- ```
22
-
23
- Equivalent direct package command:
11
+ Create a new app with the latest published Resux package:
24
12
 
25
13
  ```sh
26
14
  npx resuxjs@latest init
@@ -43,7 +31,7 @@ Generated apps use a single Resux dependency, similar to Nuxt apps installing `n
43
31
  ```json
44
32
  {
45
33
  "dependencies": {
46
- "resuxjs": "^0.1.0"
34
+ "resuxjs": "^0.2.9"
47
35
  }
48
36
  }
49
37
  ```
@@ -93,24 +81,6 @@ npm run pack:check
93
81
 
94
82
  This builds, tests, and dry-runs npm packing for the single `resuxjs` package.
95
83
 
96
- ## Publishing
97
-
98
- Publish the single package:
99
-
100
- ```sh
101
- npm publish --access public
102
- ```
103
-
104
- After `resuxjs` is published, users can run `npx resuxjs@latest init`.
105
-
106
- ## Compatibility Policy
107
-
108
- Resux follows npm semver starting with the `0.1.x` release line.
109
-
110
- - Patch releases, such as `0.1.1`, preserve compatibility for documented APIs, generated starter structure, CLI commands, config keys, file-based routing conventions, and runtime payload formats.
111
- - Minor releases before `1.0.0`, such as `0.2.0`, may include breaking changes, but they must be documented in release notes and migration guidance before publishing.
112
- - Experimental or undocumented internals, including generated files under `.resux`, may change between releases unless they are explicitly documented as public API.
113
-
114
84
  ## CLI
115
85
 
116
86
  The `resux` CLI supports:
@@ -154,12 +124,17 @@ Generated apps include `env.d.ts` and `tsconfig.json` wired to `resuxjs/globals`
154
124
  ```ts
155
125
  const count = useState("count", () => 0)
156
126
  const route = useRoute()
127
+ const router = useRouter()
157
128
  useSeoMeta({
158
129
  title: "My App",
159
130
  description: "My app description",
160
131
  ogTitle: "My App"
161
132
  })
162
133
 
134
+ function openAbout() {
135
+ router.push("/about")
136
+ }
137
+
163
138
  export default defineResuxConfig({
164
139
  app: {
165
140
  head: {
@@ -174,7 +149,7 @@ export default defineResuxConfig({
174
149
  Resux uses Vite in both main app commands:
175
150
 
176
151
  - `resux dev` emits Resux client modules into `.resux/vite-client` and serves the resume runtime plus handler modules through Vite middleware.
177
- - `resux dev` also opens a dev-only update channel at `/__resux/dev-events`; when source files change, Resux rebuilds, re-imports active client component modules with a cache-busting revision, and patches active resumable scopes without a full document reload.
152
+ - `resux dev` also opens a dev-only update channel at `/__resux/dev-events`; when source files change, Resux rebuilds and reloads the browser so route, template, and style changes are visible without restarting the dev server.
178
153
  - `resux build` uses Vite production bundling for the resume runtime, handler chunks, and server manifest, then writes optimized output into `.resux/client` and `.resux/server-bundle` before producing a Nitro `.output` server.
179
154
 
180
155
  The generated starter keeps Resux-style scripts:
@@ -238,11 +213,6 @@ Resux supports first-party and third-party build-time modules in `resux.config.t
238
213
  ```ts
239
214
  export default defineResuxConfig({
240
215
  modules: [
241
- ["resux:seo", {
242
- title: "My App",
243
- description: "A Resux application.",
244
- themeColor: "#2563eb"
245
- }],
246
216
  "resux:security",
247
217
  ["resux:performance", { assetMaxAge: 31536000 }],
248
218
  ["./modules/security.ts", { header: "enabled" }]
@@ -256,7 +226,6 @@ export default defineResuxConfig({
256
226
 
257
227
  Built-in modules:
258
228
 
259
- - `resux:seo`: adds title, description, Open Graph, Twitter card, theme color, and optional link tags.
260
229
  - `resux:security`: adds default production hardening headers and optional custom headers or CSP through route rules.
261
230
  - `resux:performance`: adds immutable cache rules for built Resux runtime/handler assets and `no-store` for route payloads.
262
231
 
@@ -303,6 +272,7 @@ Server middleware can continue by returning nothing, end the Node response direc
303
272
  - `.vue`-style SFC files with `<template>` and `<script setup lang="ts">`.
304
273
  - File-based routing from `pages/`.
305
274
  - Dynamic route params like `pages/post/[id].vue`.
275
+ - Catch-all route params like `pages/docs/[...slug].vue`.
306
276
  - `app.vue` with `<ResuxPage />`.
307
277
  - Layouts with `<ResuxLayout>`, `<slot />`, and `definePageMeta({ layout })`.
308
278
  - `<ResuxLink to="...">` rendered as an `<a href="...">` and intercepted for client-side navigation.
@@ -322,15 +292,15 @@ Server middleware can continue by returning nothing, end the Node response direc
322
292
  - Route rules for redirects, response headers, status codes, cache headers, and CORS headers.
323
293
  - Default production security headers with an opt-out flag.
324
294
  - Vite-powered dev serving, production client/server bundling, and minification for the resume runtime and handler chunks.
325
- - Component-level dev hot updates after successful rebuilds, without adding Vue hydration.
295
+ - Dev rebuilds with automatic browser reloads, without adding Vue hydration.
326
296
  - `resux inspect` and `resux inspect --json` for route and build diagnostics.
327
297
  - `resux deploy --preset node|docker|nitro` for deployment file generation.
328
298
  - Serialized route, state, and async data payloads.
329
299
  - Resumable event handlers such as `@click="increment"`.
330
300
  - Lazy client handler chunks loaded on first interaction.
331
301
  - Client-side navigation, persistent same-layout DOM, built-in route transition progress, and hover/focus route payload prefetch for same-origin links.
332
- - MVP composables: `useState`, `useAsyncData`, `useRoute`, `useHead`, `useSeoMeta`, `useRuntimeConfig`, `useResuxApp`, `useFetch`, `$fetch`, and `onMounted`.
333
- - `useAsyncData` returns a resource with reactive `data`, `pending`, and `error` refs, plus `value` as a data alias for compatibility. It still works with `await` when you want to block setup.
302
+ - MVP composables: `useState`, `useAsyncData`, `useRoute`, `useRouter`, `useHead`, `useSeoMeta`, `useRuntimeConfig`, `useResuxApp`, `apiURL`, `useFetch`, `$fetch`, and `onMounted`.
303
+ - `useAsyncData` returns a resource with reactive `data`, `pending`, and `error` refs, plus `value` as a data alias for compatibility. Use `await useAsyncData(...)` when you want SSR to fetch before rendering the page; omit `await` when you intentionally want an SSR skeleton that resumes in the browser.
334
304
 
335
305
  ## Component Syntax
336
306
 
@@ -345,7 +315,7 @@ function increment() {
345
315
 
346
316
  <template>
347
317
  <button @click="increment">
348
- Count: {{ count.value }}
318
+ Count: {{ count }}
349
319
  </button>
350
320
  </template>
351
321
  ```
@@ -356,6 +326,22 @@ In the browser, Resux installs a tiny delegated event listener. The component ha
356
326
 
357
327
  ## Async Data Skeletons
358
328
 
329
+ To fetch during SSR and render the resolved data in the first HTML response, await the call:
330
+
331
+ ```vue
332
+ <script setup lang="ts">
333
+ const { data, pending, error } = await useAsyncData("stats", async () => {
334
+ return { response: "14 ms" }
335
+ })
336
+ </script>
337
+
338
+ <template>
339
+ <p v-if="pending">Loading</p>
340
+ <p v-if="error">{{ error.message }}</p>
341
+ <strong v-if="data">{{ data.response }}</strong>
342
+ </template>
343
+ ```
344
+
359
345
  For a Next-style loading skeleton, call `useAsyncData` without `await` and branch on `pending`:
360
346
 
361
347
  ```vue
@@ -367,13 +353,41 @@ const { data, pending } = useAsyncData("stats", async () => {
367
353
  </script>
368
354
 
369
355
  <template>
370
- <div v-if="pending.value" class="skeleton"></div>
371
- <strong v-if="!pending.value">{{ data.value.response }}</strong>
356
+ <div v-if="pending" class="skeleton"></div>
357
+ <strong v-if="!pending && data">{{ data.response }}</strong>
372
358
  </template>
373
359
  ```
374
360
 
375
361
  Resux serializes the pending state, renders the skeleton immediately, resumes only scopes with pending async data in the browser, and patches the marked DOM blocks after the data resolves.
376
362
 
363
+ Templates auto-unwrap refs returned from `useState`, `useAsyncData`, `useFetch`, Vue `ref`, and `computed`, so template examples use `count`, `pending`, and `data.response`. In `<script setup>`, keep using `.value` when mutating refs, such as `count.value++`.
364
+
365
+ ## Server API Fetches
366
+
367
+ Browser-only fetches can use relative API URLs:
368
+
369
+ ```ts
370
+ await fetch("/api/test")
371
+ ```
372
+
373
+ Code that can run during SSR should use `apiURL()` or `$fetch()` so Node receives an absolute URL:
374
+
375
+ ```vue
376
+ <script setup lang="ts">
377
+ const { data, pending, error } = useAsyncData("test", () => {
378
+ return $fetch(apiURL("/api/test"))
379
+ })
380
+ </script>
381
+
382
+ <template>
383
+ <p v-if="pending">Loading</p>
384
+ <p v-if="error">{{ error.message }}</p>
385
+ <pre v-if="data">{{ data }}</pre>
386
+ </template>
387
+ ```
388
+
389
+ On the server, `apiURL("/api/test")` uses the current request origin, then configured public origins such as `runtimeConfig.public.appOrigin`, and finally `http://localhost:3000`. In the browser it returns the original path, so client fetch behavior stays relative.
390
+
377
391
  ## Supported Syntax
378
392
 
379
393
  The MVP compiler supports:
@@ -384,7 +398,7 @@ The MVP compiler supports:
384
398
  - Dynamic attributes: `:class="className"`.
385
399
  - Dynamic class arrays/objects and style objects for `:class` and `:style`.
386
400
  - Plain named events: `@click="increment"`.
387
- - Inline event expressions that only capture resumable values, such as `@click="count.value++"`.
401
+ - Inline event expressions that only capture resumable values, plus named handlers such as `@click="increment"`.
388
402
  - Resumability-safe event modifiers: `.prevent`, `.stop`, `.self`, `.once`, system/mouse modifiers, and key filters such as `.enter`.
389
403
  - `v-if`.
390
404
  - `v-show`.
@@ -399,8 +413,11 @@ The MVP compiler supports:
399
413
  - `<ResuxLink to="/path">`.
400
414
  - `defineProps()` in components.
401
415
  - `definePageMeta({ layout, middleware, title, meta })`.
416
+ - `useRoute()` for the current path, params, and query.
417
+ - `useRouter().push("/path")`, `replace`, `back`, `forward`, and `go`.
402
418
  - `useHead({ title, meta, link })`.
403
419
  - `useSeoMeta({ title, description, ogTitle, ogImage, twitterCard })`.
420
+ - `apiURL("/api/path")` for SSR-safe API fetch URLs.
404
421
  - `onMounted()`, run when the component scope is first resumed in the browser.
405
422
  - Vue runtime islands via `<VueIsland name="CounterIsland" :props="{ start: 1 }" />` and files in `islands/vue`.
406
423
 
@@ -417,6 +434,14 @@ Resux intentionally rejects or does not support many advanced framework/Vue feat
417
434
 
418
435
  Unsupported resumability patterns should fail at compile time instead of silently hydrating.
419
436
 
437
+ ## Troubleshooting
438
+
439
+ - `Failed to parse URL from /api/...` during SSR: use `apiURL("/api/...")` or `$fetch("/api/...")` from Resux setup code so server-side fetches get an absolute URL.
440
+ - Skeletons that never disappear: render `error` from `useAsyncData` and guard success UI with `!pending && !error && data`.
441
+ - Dev edits do not appear: keep `resux dev .` running and make sure the browser is connected to `/__resux/dev-events`; Resux reloads the page after successful rebuilds.
442
+ - Port already in use: pass another port, for example `resux dev --port 4000`.
443
+ - Handler capture compile errors: move non-serializable values out of resumable handlers or store resumable state with `useState`.
444
+
420
445
  ## Architecture
421
446
 
422
447
  Resux is one package with four internal parts:
@@ -445,7 +470,7 @@ The tests cover:
445
470
  - Compile errors for unsupported resumability captures.
446
471
  - Sanitized `v-html`, `v-model`, inline handlers, and mounted resume hooks.
447
472
  - SSR payload serialization.
448
- - Dynamic route params.
473
+ - Dynamic route params and catch-all params.
449
474
  - Layout rendering.
450
475
  - Head/meta rendering.
451
476
  - Runtime config and plugin provides.
@@ -248,7 +248,8 @@ export function compileVueSource(source, options) {
248
248
  throw new ResuxCompileError("Resux components need a <template> block.", locationFromOffset(options.file, source, 0));
249
249
  }
250
250
  const script = descriptor.scriptSetup?.content ?? "";
251
- const template = compileTemplate(descriptor.template.content, options.file);
251
+ const templateRefBindings = inferTemplateRefBindings(script, options.file);
252
+ const template = compileTemplate(descriptor.template.content, options.file, templateRefBindings);
252
253
  const analysis = analyzeScript(script, options.file, template.inlineHandlers);
253
254
  validateTemplateHandlers(template.handlers, analysis, options.file, source);
254
255
  const serverSource = createComponentModuleSource({
@@ -296,6 +297,11 @@ export function createRouteManifest(root, files, idByFile, compiledByFile) {
296
297
  const routeParts = parts
297
298
  .filter((part, partIndex) => !(part === "index" && partIndex === parts.length - 1))
298
299
  .map((part) => {
300
+ const catchAllMatch = /^\[\.\.\.([A-Za-z0-9_]+)\]$/.exec(part);
301
+ if (catchAllMatch) {
302
+ params.push(catchAllMatch[1]);
303
+ return `:${catchAllMatch[1]}*`;
304
+ }
299
305
  const match = /^\[([A-Za-z0-9_]+)\]$/.exec(part);
300
306
  if (match) {
301
307
  params.push(match[1]);
@@ -315,10 +321,11 @@ export function createRouteManifest(root, files, idByFile, compiledByFile) {
315
321
  })
316
322
  .sort((a, b) => routeScore(b.path) - routeScore(a.path) || a.path.localeCompare(b.path));
317
323
  }
318
- function compileTemplate(template, file) {
324
+ function compileTemplate(template, file, templateRefBindings = new Set()) {
319
325
  const ast = parseTemplate(template, { comments: false });
320
326
  const state = {
321
327
  file,
328
+ templateRefBindings,
322
329
  bindingIndex: 0,
323
330
  inlineHandlerIndex: 0,
324
331
  handlers: [],
@@ -340,7 +347,7 @@ function compileTemplateNode(node, state) {
340
347
  if (node.type === NodeTypes.INTERPOLATION) {
341
348
  return {
342
349
  type: "interpolation",
343
- expression: node.content.content,
350
+ expression: transformTemplateExpression(node.content.content, state.templateRefBindings, state.file, node),
344
351
  bindingId: nextBindingId(state)
345
352
  };
346
353
  }
@@ -377,7 +384,7 @@ function compileTemplateNode(node, state) {
377
384
  attrs.push({
378
385
  kind: "dynamic",
379
386
  name: arg,
380
- value: expression,
387
+ value: transformTemplateExpression(expression, state.templateRefBindings, state.file, prop),
381
388
  bindingId: nextBindingId(state)
382
389
  });
383
390
  continue;
@@ -407,7 +414,7 @@ function compileTemplateNode(node, state) {
407
414
  throw new ResuxCompileError("v-if needs an expression.", locationFromVueNode(state.file, prop));
408
415
  }
409
416
  element.if = {
410
- expression,
417
+ expression: transformTemplateExpression(expression, state.templateRefBindings, state.file, prop),
411
418
  blockId: nextBindingId(state)
412
419
  };
413
420
  continue;
@@ -418,6 +425,7 @@ function compileTemplateNode(node, state) {
418
425
  throw new ResuxCompileError("v-for needs an expression.", locationFromVueNode(state.file, prop));
419
426
  }
420
427
  element.for = parseForExpression(expression, state.file, prop, state);
428
+ element.for.source = transformTemplateExpression(element.for.source, state.templateRefBindings, state.file, prop);
421
429
  continue;
422
430
  }
423
431
  if (prop.name === "show") {
@@ -428,7 +436,7 @@ function compileTemplateNode(node, state) {
428
436
  attrs.push({
429
437
  kind: "dynamic",
430
438
  name: "hidden",
431
- value: `!(${expression})`,
439
+ value: `!(${transformTemplateExpression(expression, state.templateRefBindings, state.file, prop)})`,
432
440
  bindingId: nextBindingId(state)
433
441
  });
434
442
  continue;
@@ -440,7 +448,7 @@ function compileTemplateNode(node, state) {
440
448
  }
441
449
  element.children = [{
442
450
  type: "interpolation",
443
- expression,
451
+ expression: transformTemplateExpression(expression, state.templateRefBindings, state.file, prop),
444
452
  bindingId: nextBindingId(state)
445
453
  }];
446
454
  continue;
@@ -451,7 +459,7 @@ function compileTemplateNode(node, state) {
451
459
  throw new ResuxCompileError("v-html needs an expression.", locationFromVueNode(state.file, prop));
452
460
  }
453
461
  element.html = {
454
- expression,
462
+ expression: transformTemplateExpression(expression, state.templateRefBindings, state.file, prop),
455
463
  bindingId: nextBindingId(state)
456
464
  };
457
465
  element.children = [];
@@ -469,7 +477,7 @@ function compileTemplateNode(node, state) {
469
477
  attrs.push({
470
478
  kind: "dynamic",
471
479
  name: model.attribute,
472
- value: model.value,
480
+ value: transformTemplateExpression(model.value, state.templateRefBindings, state.file, prop),
473
481
  bindingId: nextBindingId(state)
474
482
  });
475
483
  const event = {
@@ -499,9 +507,10 @@ function createModelBinding(tag, props, expression, state) {
499
507
  const isCheckbox = inputType === "checkbox";
500
508
  const handler = nextInlineHandlerName(state);
501
509
  const target = "$event.target";
510
+ const assignmentExpression = state.templateRefBindings.has(expression.trim()) ? `${expression.trim()}.value` : expression;
502
511
  const assignment = isCheckbox
503
- ? `${expression} = Boolean(${target} && ${target}.checked)`
504
- : `${expression} = ${target} ? ${target}.value : ""`;
512
+ ? `${assignmentExpression} = Boolean(${target} && ${target}.checked)`
513
+ : `${assignmentExpression} = ${target} ? ${target}.value : ""`;
505
514
  state.inlineHandlers.push({
506
515
  name: handler,
507
516
  source: `function ${handler}($event) {\n${assignment}\n}`
@@ -517,6 +526,55 @@ function staticAttributeValue(props, name) {
517
526
  const attr = props.find((prop) => prop.type === NodeTypes.ATTRIBUTE && prop.name === name);
518
527
  return attr?.value?.content;
519
528
  }
529
+ function transformTemplateExpression(expression, templateRefBindings, file, node) {
530
+ if (templateRefBindings.size === 0) {
531
+ return expression;
532
+ }
533
+ const wrapped = `(${expression})`;
534
+ const sourceFile = ts.createSourceFile(`${file}?template-expression`, wrapped, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);
535
+ if ((sourceFile.parseDiagnostics ?? []).length > 0) {
536
+ throw new ResuxCompileError("Template expression is not valid JavaScript.", locationFromVueNode(file, node));
537
+ }
538
+ const insertions = [];
539
+ const visit = (current) => {
540
+ if (ts.isIdentifier(current) && templateRefBindings.has(current.text) && shouldAutoUnwrapTemplateIdentifier(current)) {
541
+ const position = current.end - 1;
542
+ if (position >= 0 && position <= expression.length) {
543
+ insertions.push(position);
544
+ }
545
+ }
546
+ ts.forEachChild(current, visit);
547
+ };
548
+ visit(sourceFile);
549
+ if (insertions.length === 0) {
550
+ return expression;
551
+ }
552
+ const uniqueInsertions = [...new Set(insertions)].sort((a, b) => b - a);
553
+ let transformed = expression;
554
+ for (const position of uniqueInsertions) {
555
+ transformed = `${transformed.slice(0, position)}.value${transformed.slice(position)}`;
556
+ }
557
+ return transformed;
558
+ }
559
+ function shouldAutoUnwrapTemplateIdentifier(node) {
560
+ const parent = node.parent;
561
+ if (!parent) {
562
+ return true;
563
+ }
564
+ if (ts.isPropertyAccessExpression(parent)) {
565
+ if (parent.expression === node && parent.name.text === "value") {
566
+ return false;
567
+ }
568
+ return parent.name !== node;
569
+ }
570
+ if (ts.isPropertyAssignment(parent) && parent.name === node) {
571
+ return false;
572
+ }
573
+ if (ts.isShorthandPropertyAssignment(parent) || ts.isBindingElement(parent)) {
574
+ return false;
575
+ }
576
+ return true;
577
+ }
520
578
  function isAssignableExpression(expression) {
521
579
  return /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\[[^\]]+\])*$/.test(expression.trim());
522
580
  }
@@ -579,6 +637,7 @@ function analyzeScript(script, file, inlineHandlers = []) {
579
637
  const bindings = new Set();
580
638
  const handlerNames = new Set();
581
639
  const resumableBindings = new Set();
640
+ const templateRefBindings = inferTemplateRefBindings(script, file);
582
641
  const handlers = new Map();
583
642
  let pageMeta;
584
643
  for (const statement of sourceFile.statements) {
@@ -633,11 +692,60 @@ function analyzeScript(script, file, inlineHandlers = []) {
633
692
  bindings: [...bindings],
634
693
  handlerNames,
635
694
  resumableBindings,
695
+ templateRefBindings,
636
696
  handlers,
637
697
  sourceFile,
638
698
  pageMeta
639
699
  };
640
700
  }
701
+ function inferTemplateRefBindings(script, file) {
702
+ const sourceFile = ts.createSourceFile(file, script, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);
703
+ const bindings = new Set();
704
+ for (const statement of sourceFile.statements) {
705
+ if (!ts.isVariableStatement(statement)) {
706
+ continue;
707
+ }
708
+ for (const declaration of statement.declarationList.declarations) {
709
+ const initializer = unwrapAwaitExpression(declaration.initializer);
710
+ if (!initializer || !ts.isCallExpression(initializer)) {
711
+ continue;
712
+ }
713
+ const callee = initializer.expression;
714
+ const calleeName = ts.isIdentifier(callee)
715
+ ? callee.text
716
+ : ts.isPropertyAccessExpression(callee) && ts.isIdentifier(callee.name)
717
+ ? callee.name.text
718
+ : "";
719
+ if (ts.isIdentifier(declaration.name) && isTemplateRefFactory(calleeName)) {
720
+ bindings.add(declaration.name.text);
721
+ continue;
722
+ }
723
+ if (ts.isObjectBindingPattern(declaration.name) && isAsyncDataFactory(calleeName)) {
724
+ for (const element of declaration.name.elements) {
725
+ if (!ts.isBindingElement(element) || !ts.isIdentifier(element.name)) {
726
+ continue;
727
+ }
728
+ const propertyName = element.propertyName && ts.isIdentifier(element.propertyName)
729
+ ? element.propertyName.text
730
+ : element.name.text;
731
+ if (["data", "pending", "error", "value"].includes(propertyName)) {
732
+ bindings.add(element.name.text);
733
+ }
734
+ }
735
+ }
736
+ }
737
+ }
738
+ return bindings;
739
+ }
740
+ function unwrapAwaitExpression(node) {
741
+ return node && ts.isAwaitExpression(node) ? node.expression : node;
742
+ }
743
+ function isTemplateRefFactory(name) {
744
+ return ["ref", "computed", "shallowRef", "useState", "useAsyncData", "useFetch"].includes(name);
745
+ }
746
+ function isAsyncDataFactory(name) {
747
+ return ["useAsyncData", "useFetch"].includes(name);
748
+ }
641
749
  function isDefinePageMetaStatement(statement) {
642
750
  return ts.isExpressionStatement(statement)
643
751
  && ts.isCallExpression(statement.expression)
@@ -710,7 +818,7 @@ function validateTemplateHandlers(events, analysis, file, fullSource) {
710
818
  }
711
819
  function findUnsupportedCapture(node, handlerName, analysis) {
712
820
  const locals = new Set([handlerName, "event"]);
713
- const allowedGlobals = new Set(["Math", "Number", "String", "Boolean", "Array", "Object", "Date", "JSON", "console", "undefined"]);
821
+ const allowedGlobals = new Set(["Math", "Number", "String", "Boolean", "Array", "Object", "Date", "JSON", "console", "undefined", "apiURL"]);
714
822
  const allowedTopLevel = new Set([...analysis.resumableBindings]);
715
823
  function registerPattern(name) {
716
824
  for (const binding of collectBindingNames(name)) {
@@ -774,7 +882,7 @@ function isResumableInitializer(node) {
774
882
  return false;
775
883
  }
776
884
  if (ts.isCallExpression(node) && ts.isIdentifier(node.expression)) {
777
- return ["useState", "useAsyncData", "useRoute", "useRuntimeConfig", "useResuxApp", "defineProps"].includes(node.expression.text);
885
+ return ["useState", "useAsyncData", "useRoute", "useRouter", "useRuntimeConfig", "useResuxApp", "defineProps"].includes(node.expression.text);
778
886
  }
779
887
  if (ts.isAwaitExpression(node) && ts.isCallExpression(node.expression) && ts.isIdentifier(node.expression.expression)) {
780
888
  return ["useAsyncData", "useFetch"].includes(node.expression.expression.text);
@@ -801,7 +909,7 @@ function createComponentModuleSource(options) {
801
909
  options.analysis.imports,
802
910
  `const __template = ${JSON.stringify(options.template, null, 2)};`,
803
911
  `async function __rx_setup(__ctx) {`,
804
- `const { useState, useAsyncData, useRoute, useHead, useSeoMeta, useRuntimeConfig, useResuxApp, useFetch, $fetch, onMounted, definePageMeta, defineProps } = __ctx;`,
912
+ `const { useState, useAsyncData, useRoute, useRouter, useHead, useSeoMeta, useRuntimeConfig, useResuxApp, apiURL, useFetch, $fetch, onMounted, definePageMeta, defineProps } = __ctx;`,
805
913
  options.analysis.setupBody,
806
914
  `return { ${options.analysis.bindings.join(", ")} };`,
807
915
  `}`,
@@ -841,11 +949,12 @@ function relativeImportPath(fromDir, file) {
841
949
  return relative.startsWith(".") ? relative : `./${relative}`;
842
950
  }
843
951
  function createServerManifestSource(routes, components, layouts, plugins, middleware, serverMiddleware, serverHandlers, vueIslands, app, error, runtimeConfig = {}, buildOptions = {}) {
844
- const imports = components.map((component) => `import ${component.id} from "./${component.id}.mjs";`).join("\n");
845
- const pluginImports = plugins.map((plugin) => `import ${plugin.id} from "./plugins/${plugin.id}.mjs";`).join("\n");
846
- const middlewareImports = middleware.map((entry) => `import ${entry.id} from "./middleware/${entry.id}.mjs";`).join("\n");
847
- const serverMiddlewareImports = serverMiddleware.map((entry) => `import ${entry.id} from "./request-middleware/${entry.id}.mjs";`).join("\n");
848
- const handlerImports = serverHandlers.map((handler) => `import ${handler.id} from "./handlers/${handler.id}.mjs";`).join("\n");
952
+ const importSuffix = buildOptions.vite === "dev" ? `?t=${Date.now()}` : "";
953
+ const imports = components.map((component) => `import ${component.id} from "./${component.id}.mjs${importSuffix}";`).join("\n");
954
+ const pluginImports = plugins.map((plugin) => `import ${plugin.id} from "./plugins/${plugin.id}.mjs${importSuffix}";`).join("\n");
955
+ const middlewareImports = middleware.map((entry) => `import ${entry.id} from "./middleware/${entry.id}.mjs${importSuffix}";`).join("\n");
956
+ const serverMiddlewareImports = serverMiddleware.map((entry) => `import ${entry.id} from "./request-middleware/${entry.id}.mjs${importSuffix}";`).join("\n");
957
+ const handlerImports = serverHandlers.map((handler) => `import ${handler.id} from "./handlers/${handler.id}.mjs${importSuffix}";`).join("\n");
849
958
  const componentEntries = components.map((component) => `${JSON.stringify(component.name)}: ${component.id}`).join(",\n");
850
959
  const layoutEntries = layouts.map((layout) => `${JSON.stringify(layoutNameFromFile(layout.file))}: ${layout.id}`).join(",\n");
851
960
  const moduleEntries = components
@@ -955,24 +1064,28 @@ export function matchServerHandler(pathname) {
955
1064
  }
956
1065
  return null;
957
1066
  }
958
- function createMatcher(pattern) {
959
- const names = [];
960
- const source = pattern === "/" ? "^/$" : "^" + pattern.split("/").map((part) => {
961
- if (!part) return "";
962
- if (part.startsWith(":")) {
963
- names.push(part.slice(1));
964
- return "/([^/]+)";
1067
+ function createMatcher(pattern) {
1068
+ const names = [];
1069
+ const source = pattern === "/" ? "^/$" : "^" + pattern.split("/").map((part) => {
1070
+ if (!part) return "";
1071
+ if (part.startsWith(":") && part.endsWith("*")) {
1072
+ names.push(part.slice(1, -1));
1073
+ return "(?:/(.*))?";
1074
+ }
1075
+ if (part.startsWith(":")) {
1076
+ names.push(part.slice(1));
1077
+ return "/([^/]+)";
965
1078
  }
966
1079
  return "/" + part.replace(/[.*+?^${"${"}}()|[\\]\\\\]/g, "\\\\$&");
967
1080
  }).join("") + "$";
968
1081
  const regex = new RegExp(source);
969
1082
  return (pathname) => {
970
1083
  const match = regex.exec(pathname);
971
- if (!match) return null;
972
- const params = {};
973
- names.forEach((name, index) => {
974
- params[name] = decodeURIComponent(match[index + 1]);
975
- });
1084
+ if (!match) return null;
1085
+ const params = {};
1086
+ names.forEach((name, index) => {
1087
+ params[name] = decodeURIComponent(match[index + 1] ?? "");
1088
+ });
976
1089
  return params;
977
1090
  };
978
1091
  }
@@ -1279,42 +1392,6 @@ function resolveBuiltinModule(specifier) {
1279
1392
  return builtinModules[normalized] ?? null;
1280
1393
  }
1281
1394
  const builtinModules = {
1282
- seo: {
1283
- defaults: {},
1284
- setup(options, resux) {
1285
- const input = isPlainObject(options) ? options : {};
1286
- const meta = [];
1287
- const title = firstString(input.title);
1288
- const description = firstString(input.description);
1289
- const image = firstString(input.image);
1290
- const themeColor = firstString(input.themeColor);
1291
- const twitterCard = firstString(input.twitterCard) ?? "summary_large_image";
1292
- if (description) {
1293
- meta.push({ name: "description", content: description });
1294
- meta.push({ property: "og:description", content: description });
1295
- meta.push({ name: "twitter:description", content: description });
1296
- }
1297
- if (title) {
1298
- meta.push({ property: "og:title", content: title });
1299
- meta.push({ name: "twitter:title", content: title });
1300
- }
1301
- if (image) {
1302
- meta.push({ property: "og:image", content: image });
1303
- meta.push({ name: "twitter:image", content: image });
1304
- }
1305
- if (themeColor) {
1306
- meta.push({ name: "theme-color", content: themeColor });
1307
- }
1308
- if (twitterCard) {
1309
- meta.push({ name: "twitter:card", content: twitterCard });
1310
- }
1311
- resux.addHead({
1312
- ...(title ? { title } : {}),
1313
- ...(meta.length ? { meta } : {}),
1314
- ...(Array.isArray(input.link) ? { link: input.link.filter(isPlainObject) } : {})
1315
- });
1316
- }
1317
- },
1318
1395
  security: {
1319
1396
  defaults: {
1320
1397
  route: "/**",
@@ -1564,6 +1641,7 @@ function normalizeRoutePath(value) {
1564
1641
  const normalized = value
1565
1642
  .replaceAll("\\", "/")
1566
1643
  .replace(/\.[cm]?[tj]s$/, "")
1644
+ .replace(/\[\.\.\.([A-Za-z0-9_]+)\]/g, ":$1*")
1567
1645
  .replace(/\[([A-Za-z0-9_]+)\]/g, ":$1")
1568
1646
  .replace(/\/index$/, "");
1569
1647
  return (`/${normalized}`.replace(/\/+/g, "/").replace(/\/$/, "")) || "/";
@@ -1572,7 +1650,7 @@ function collectRouteParams(routePath) {
1572
1650
  return routePath
1573
1651
  .split("/")
1574
1652
  .filter((part) => part.startsWith(":"))
1575
- .map((part) => part.slice(1));
1653
+ .map((part) => part.slice(1).replace(/\*$/, ""));
1576
1654
  }
1577
1655
  function locationFromVueNode(file, node) {
1578
1656
  return {