@rsc-kit/core 0.7.1 → 0.7.2

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 (148) hide show
  1. package/README.md +4 -4
  2. package/dist/action.d.ts +0 -1
  3. package/dist/action.js.map +1 -1
  4. package/dist/build-rsc-vite.d.ts +0 -1
  5. package/dist/build-rsc-vite.js.map +1 -1
  6. package/dist/cache.d.ts +0 -1
  7. package/dist/cache.js.map +1 -1
  8. package/dist/devServer.d.ts +0 -1
  9. package/dist/devServer.js.map +1 -1
  10. package/dist/devUrls.d.ts +0 -1
  11. package/dist/devUrls.js.map +1 -1
  12. package/dist/embed.d.ts +0 -1
  13. package/dist/embed.js.map +1 -1
  14. package/dist/errors.d.ts +0 -1
  15. package/dist/errors.js.map +1 -1
  16. package/dist/export.d.ts +0 -1
  17. package/dist/export.js.map +1 -1
  18. package/dist/files.d.ts +0 -1
  19. package/dist/files.js.map +1 -1
  20. package/dist/headers.d.ts +0 -1
  21. package/dist/headers.js.map +1 -1
  22. package/dist/host.d.ts +0 -1
  23. package/dist/host.js.map +1 -1
  24. package/dist/hostCalls.d.ts +0 -1
  25. package/dist/hostCalls.js.map +1 -1
  26. package/dist/js/ActivityRouter.d.ts +0 -1
  27. package/dist/js/ActivityRouter.js.map +1 -1
  28. package/dist/js/DocumentTitle.d.ts +0 -1
  29. package/dist/js/DocumentTitle.js.map +1 -1
  30. package/dist/js/Form.d.ts +0 -1
  31. package/dist/js/Form.js.map +1 -1
  32. package/dist/js/Link.d.ts +0 -1
  33. package/dist/js/Link.js.map +1 -1
  34. package/dist/js/PathnameProvider.d.ts +0 -1
  35. package/dist/js/PathnameProvider.js.map +1 -1
  36. package/dist/js/RedirectBoundary.d.ts +0 -1
  37. package/dist/js/RedirectBoundary.js.map +1 -1
  38. package/dist/js/SegmentBoundary.d.ts +0 -1
  39. package/dist/js/SegmentBoundary.js.map +1 -1
  40. package/dist/js/SlotBoundary.d.ts +0 -1
  41. package/dist/js/SlotBoundary.js.map +1 -1
  42. package/dist/js/createViteRscApp.d.ts +0 -1
  43. package/dist/js/createViteRscApp.js.map +1 -1
  44. package/dist/js/errors.d.ts +0 -1
  45. package/dist/js/errors.js.map +1 -1
  46. package/dist/js/navigate.d.ts +0 -1
  47. package/dist/js/navigate.js.map +1 -1
  48. package/dist/js/onlineStore.d.ts +0 -1
  49. package/dist/js/onlineStore.js.map +1 -1
  50. package/dist/js/pagePayload.d.ts +0 -1
  51. package/dist/js/pagePayload.js.map +1 -1
  52. package/dist/js/router.d.ts +0 -1
  53. package/dist/js/router.js.map +1 -1
  54. package/dist/js/section.d.ts +0 -1
  55. package/dist/js/section.js.map +1 -1
  56. package/dist/js/segmentStore.d.ts +0 -1
  57. package/dist/js/segmentStore.js.map +1 -1
  58. package/dist/js/slotStore.d.ts +0 -1
  59. package/dist/js/slotStore.js.map +1 -1
  60. package/dist/js/standardSchema.d.ts +0 -1
  61. package/dist/js/standardSchema.js.map +1 -1
  62. package/dist/js/useForm.d.ts +0 -1
  63. package/dist/js/useForm.js.map +1 -1
  64. package/dist/js/useLinkStatus.d.ts +0 -1
  65. package/dist/js/useLinkStatus.js.map +1 -1
  66. package/dist/js/useOnline.d.ts +0 -1
  67. package/dist/js/useOnline.js.map +1 -1
  68. package/dist/js/usePathname.d.ts +0 -1
  69. package/dist/js/usePathname.js.map +1 -1
  70. package/dist/js/useSearchParams.d.ts +0 -1
  71. package/dist/js/useSearchParams.js.map +1 -1
  72. package/dist/manifest.d.ts +0 -1
  73. package/dist/manifest.js.map +1 -1
  74. package/dist/nondeterminism.d.ts +0 -1
  75. package/dist/nondeterminism.js.map +1 -1
  76. package/dist/prerender.d.ts +0 -1
  77. package/dist/prerender.js.map +1 -1
  78. package/dist/redirect.d.ts +0 -1
  79. package/dist/redirect.js.map +1 -1
  80. package/dist/redirectDigest.d.ts +0 -1
  81. package/dist/redirectDigest.js.map +1 -1
  82. package/dist/request.d.ts +0 -1
  83. package/dist/request.js.map +1 -1
  84. package/dist/revalidate.d.ts +0 -1
  85. package/dist/revalidate.js.map +1 -1
  86. package/dist/routes.d.ts +0 -1
  87. package/dist/routes.js.map +1 -1
  88. package/dist/routing.d.ts +0 -1
  89. package/dist/routing.js.map +1 -1
  90. package/dist/runtime.d.ts +0 -1
  91. package/dist/runtime.js.map +1 -1
  92. package/dist/safeUrl.d.ts +0 -1
  93. package/dist/safeUrl.js.map +1 -1
  94. package/dist/vite.d.ts +0 -1
  95. package/dist/vite.js +73 -9
  96. package/dist/vite.js.map +1 -1
  97. package/package.json +1 -5
  98. package/dist/action.d.ts.map +0 -1
  99. package/dist/build-rsc-vite.d.ts.map +0 -1
  100. package/dist/cache.d.ts.map +0 -1
  101. package/dist/cli.d.ts +0 -2
  102. package/dist/cli.d.ts.map +0 -1
  103. package/dist/cli.js +0 -84
  104. package/dist/cli.js.map +0 -1
  105. package/dist/devServer.d.ts.map +0 -1
  106. package/dist/devUrls.d.ts.map +0 -1
  107. package/dist/embed.d.ts.map +0 -1
  108. package/dist/errors.d.ts.map +0 -1
  109. package/dist/export.d.ts.map +0 -1
  110. package/dist/files.d.ts.map +0 -1
  111. package/dist/headers.d.ts.map +0 -1
  112. package/dist/host.d.ts.map +0 -1
  113. package/dist/hostCalls.d.ts.map +0 -1
  114. package/dist/js/ActivityRouter.d.ts.map +0 -1
  115. package/dist/js/DocumentTitle.d.ts.map +0 -1
  116. package/dist/js/Form.d.ts.map +0 -1
  117. package/dist/js/Link.d.ts.map +0 -1
  118. package/dist/js/PathnameProvider.d.ts.map +0 -1
  119. package/dist/js/RedirectBoundary.d.ts.map +0 -1
  120. package/dist/js/SegmentBoundary.d.ts.map +0 -1
  121. package/dist/js/SlotBoundary.d.ts.map +0 -1
  122. package/dist/js/createViteRscApp.d.ts.map +0 -1
  123. package/dist/js/errors.d.ts.map +0 -1
  124. package/dist/js/navigate.d.ts.map +0 -1
  125. package/dist/js/onlineStore.d.ts.map +0 -1
  126. package/dist/js/pagePayload.d.ts.map +0 -1
  127. package/dist/js/router.d.ts.map +0 -1
  128. package/dist/js/section.d.ts.map +0 -1
  129. package/dist/js/segmentStore.d.ts.map +0 -1
  130. package/dist/js/slotStore.d.ts.map +0 -1
  131. package/dist/js/standardSchema.d.ts.map +0 -1
  132. package/dist/js/useForm.d.ts.map +0 -1
  133. package/dist/js/useLinkStatus.d.ts.map +0 -1
  134. package/dist/js/useOnline.d.ts.map +0 -1
  135. package/dist/js/usePathname.d.ts.map +0 -1
  136. package/dist/js/useSearchParams.d.ts.map +0 -1
  137. package/dist/manifest.d.ts.map +0 -1
  138. package/dist/nondeterminism.d.ts.map +0 -1
  139. package/dist/prerender.d.ts.map +0 -1
  140. package/dist/redirect.d.ts.map +0 -1
  141. package/dist/redirectDigest.d.ts.map +0 -1
  142. package/dist/request.d.ts.map +0 -1
  143. package/dist/revalidate.d.ts.map +0 -1
  144. package/dist/routes.d.ts.map +0 -1
  145. package/dist/routing.d.ts.map +0 -1
  146. package/dist/runtime.d.ts.map +0 -1
  147. package/dist/safeUrl.d.ts.map +0 -1
  148. package/dist/vite.d.ts.map +0 -1
package/dist/vite.js CHANGED
@@ -27,6 +27,8 @@ let outDir;
27
27
  let appDir;
28
28
  let genDir;
29
29
  let publicAssetsDir;
30
+ /** Where generated ambient declarations go — `.rsc-kit` at the project root. */
31
+ let typesDir;
30
32
  let hotFile;
31
33
  let hostCallOptions;
32
34
  let packageDir;
@@ -168,6 +170,7 @@ function resolvePaths(options) {
168
170
  // Vite's own default. Nitro overrides it with .output/public, which is why
169
171
  // there is nothing here to configure.
170
172
  publicAssetsDir = resolve(join(projectRoot, 'dist/client'));
173
+ typesDir = join(projectRoot, '.rsc-kit');
171
174
  hotFile = options.hotFile || process.env.RSC_HOT_FILE || '';
172
175
  hostCallOptions = options.hostCall;
173
176
  packageDir = resolve(options.packageDir || process.env.RSC_PACKAGE_DIR || thisDir());
@@ -378,14 +381,57 @@ function routeManifest() {
378
381
  intercepts,
379
382
  };
380
383
  }
384
+ /**
385
+ * Say so when the typechecker cannot see the declarations just written.
386
+ *
387
+ * Moving them out of the source directory buys a tidy `src/` and costs this:
388
+ * `include` used to cover them by accident, and now it has to name `.rsc-kit`.
389
+ * A project that does not is not broken in any way it can notice — every file
390
+ * is written, every build passes, and `Link` quietly takes `string` again
391
+ * instead of the route union, so a link to a page that does not exist compiles
392
+ * and 404s in the browser.
393
+ *
394
+ * A guess, deliberately, and only ever a warning: `include` is one of several
395
+ * ways a tsconfig can reach a file, `extends` can supply it, and a project
396
+ * with no tsconfig at all is not doing this checking anyway. Wrong here costs
397
+ * a line of output; silent costs the types.
398
+ */
399
+ function warnIfTypesUnreachable() {
400
+ const config = join(projectRoot, 'tsconfig.json');
401
+ if (!existsSync(config))
402
+ return;
403
+ try {
404
+ // Comments are legal in a tsconfig and JSON.parse does not take them.
405
+ const text = readFileSync(config, 'utf-8').replace(/\/\*[\s\S]*?\*\/|(^|\s)\/\/.*$/gm, '$1');
406
+ const include = JSON.parse(text).include;
407
+ if (!Array.isArray(include))
408
+ return;
409
+ if (include.some((entry) => typeof entry === 'string' && entry.includes('.rsc-kit')))
410
+ return;
411
+ log(`tsconfig.json does not include .rsc-kit, where the generated types are written.\n` +
412
+ ` Add ".rsc-kit/**/*" to "include", or typed routes and rpc() fall back to string.`);
413
+ }
414
+ catch {
415
+ // An unparseable tsconfig is the project's own problem, not this one's.
416
+ }
417
+ }
381
418
  // ── What the app imports ─────────────────────────────────────────────────────
382
419
  /**
383
420
  * Write the modules the app's source imports but nobody writes by hand.
384
421
  *
385
- * All three land in the source directory because that is where the app's own
386
- * imports and its typechecker can reach them: the stubs are imported by
387
- * relative path, and an ambient declaration is only ambient if it is inside
388
- * the project. The build owns that path, which is why it owns this.
422
+ * Two destinations, and the difference is whether anything imports the file.
423
+ *
424
+ * The stubs are imported by relative path, so they have to sit in the source
425
+ * directory — that path is the app's, and only the build knows it.
426
+ *
427
+ * The declarations are not imported by anything. They are ambient, which needs
428
+ * them inside the project and nothing more, so they go in `.rsc-kit/` at the
429
+ * root: four generated files in `src/` sat among the app's own and had to be
430
+ * gitignored one by one, and every one of them was noise beside the pages.
431
+ *
432
+ * Ambient still means the typechecker has to be told the directory exists —
433
+ * see the warning below, because a tsconfig that does not include it turns
434
+ * every one of these into a file nobody reads.
389
435
  *
390
436
  * Rewritten on every run. The failure they prevent is invisible at build
391
437
  * time — a stale stub calls a global that has since been renamed, and only
@@ -393,26 +439,28 @@ function routeManifest() {
393
439
  */
394
440
  function writeHostBindings(manifest) {
395
441
  mkdirSync(sourceDir, { recursive: true });
442
+ mkdirSync(typesDir, { recursive: true });
396
443
  // The global is installed at runtime, so nothing in app source declares it
397
444
  // and a typecheck cannot see it. Written whether or not there are actions:
398
445
  // server components call it directly too.
399
- writeFileSync(join(sourceDir, 'rsc-env.d.ts'), renderHostGlobalTypes());
446
+ writeFileSync(join(typesDir, 'rsc-env.d.ts'), renderHostGlobalTypes());
400
447
  // The engine's own ambient types, copied where the app's typechecker will
401
448
  // see them. Deliberately a separate file from the one above: this one is
402
449
  // the engine's and identical everywhere, that one is generated from how
403
450
  // this host is configured.
404
451
  // The urls this build found, so a link to a page that does not exist fails
405
452
  // the typecheck instead of the browser.
406
- writeFileSync(join(sourceDir, 'rsc-routes.d.ts'), renderRouteTypes(manifest));
453
+ writeFileSync(join(typesDir, 'rsc-routes.d.ts'), renderRouteTypes(manifest));
407
454
  // The bundle the host imports is generated, so nothing declares it. Written
408
455
  // here rather than left to the app: every app needs the identical file, and
409
456
  // an app-authored one goes stale — the first version named only RscEngine,
410
457
  // which typechecks a server and fails a prerender script.
411
- writeFileSync(join(sourceDir, 'rsc-engine.d.ts'), ENGINE_TYPES);
458
+ writeFileSync(join(typesDir, 'rsc-engine.d.ts'), ENGINE_TYPES);
412
459
  const engineTypes = join(packageDir, 'types.d.ts');
413
460
  if (existsSync(engineTypes)) {
414
- writeFileSync(join(sourceDir, 'rsc-types.d.ts'), readFileSync(engineTypes, 'utf-8'));
461
+ writeFileSync(join(typesDir, 'rsc-types.d.ts'), readFileSync(engineTypes, 'utf-8'));
415
462
  }
463
+ warnIfTypesUnreachable();
416
464
  const target = join(sourceDir, 'server-actions.generated.ts');
417
465
  // A host with no functions of its own leaves no file behind: kept, its
418
466
  // stubs would go on naming targets the host has stopped answering for.
@@ -2384,7 +2432,23 @@ export function rscKit(options = {}) {
2384
2432
  }
2385
2433
  components.clear();
2386
2434
  discover(appDir);
2387
- log(`Discovered ${components.size} route components:`, [...components.keys()].join(', '));
2435
+ // Silent when it worked. The names were printed on every dev start and
2436
+ // every build — thirty of them for a middling app, above the output that
2437
+ // actually says something, and the build's classification table lists
2438
+ // every route anyway.
2439
+ //
2440
+ // Nothing found is the case worth a word, because the app still builds:
2441
+ // a server with no routes answers 404 to everything, which reads as a
2442
+ // routing bug rather than as an empty directory. Fatal for a build,
2443
+ // said out loud for a dev server — where deleting the last page while
2444
+ // editing is a state to pass through, not to be thrown out of.
2445
+ if (components.size === 0) {
2446
+ const message = `No routes under ${appDir}. A directory with a page.tsx in it is a route; ` +
2447
+ 'without one there is nothing to serve.';
2448
+ if (env.command === 'build')
2449
+ throw new Error(`[rsc-kit] ${message}`);
2450
+ log(message);
2451
+ }
2388
2452
  const loadingErrors = validateLoadingBoundaries();
2389
2453
  if (loadingErrors.length) {
2390
2454
  throw new Error('[rsc-kit] A page that blocks before it can paint needs a loading.tsx boundary.\n\n' +