@rsc-kit/core 0.7.0 → 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.
- package/README.md +4 -4
- package/dist/action.d.ts +0 -1
- package/dist/action.js.map +1 -1
- package/dist/build-rsc-vite.d.ts +0 -1
- package/dist/build-rsc-vite.js.map +1 -1
- package/dist/cache.d.ts +0 -1
- package/dist/cache.js.map +1 -1
- package/dist/devServer.d.ts +0 -1
- package/dist/devServer.js.map +1 -1
- package/dist/devUrls.d.ts +0 -1
- package/dist/devUrls.js.map +1 -1
- package/dist/embed.d.ts +0 -1
- package/dist/embed.js.map +1 -1
- package/dist/errors.d.ts +0 -1
- package/dist/errors.js.map +1 -1
- package/dist/export.d.ts +0 -1
- package/dist/export.js.map +1 -1
- package/dist/files.d.ts +0 -1
- package/dist/files.js.map +1 -1
- package/dist/headers.d.ts +0 -1
- package/dist/headers.js.map +1 -1
- package/dist/host.d.ts +0 -1
- package/dist/host.js.map +1 -1
- package/dist/hostCalls.d.ts +0 -1
- package/dist/hostCalls.js.map +1 -1
- package/dist/js/ActivityRouter.d.ts +0 -1
- package/dist/js/ActivityRouter.js.map +1 -1
- package/dist/js/DocumentTitle.d.ts +0 -1
- package/dist/js/DocumentTitle.js.map +1 -1
- package/dist/js/Form.d.ts +0 -1
- package/dist/js/Form.js.map +1 -1
- package/dist/js/Link.d.ts +0 -1
- package/dist/js/Link.js.map +1 -1
- package/dist/js/PathnameProvider.d.ts +0 -1
- package/dist/js/PathnameProvider.js.map +1 -1
- package/dist/js/RedirectBoundary.d.ts +0 -1
- package/dist/js/RedirectBoundary.js.map +1 -1
- package/dist/js/SegmentBoundary.d.ts +0 -1
- package/dist/js/SegmentBoundary.js.map +1 -1
- package/dist/js/SlotBoundary.d.ts +0 -1
- package/dist/js/SlotBoundary.js.map +1 -1
- package/dist/js/createViteRscApp.d.ts +0 -1
- package/dist/js/createViteRscApp.js.map +1 -1
- package/dist/js/errors.d.ts +0 -1
- package/dist/js/errors.js.map +1 -1
- package/dist/js/navigate.d.ts +0 -1
- package/dist/js/navigate.js.map +1 -1
- package/dist/js/onlineStore.d.ts +0 -1
- package/dist/js/onlineStore.js.map +1 -1
- package/dist/js/pagePayload.d.ts +0 -1
- package/dist/js/pagePayload.js.map +1 -1
- package/dist/js/router.d.ts +0 -1
- package/dist/js/router.js.map +1 -1
- package/dist/js/section.d.ts +0 -1
- package/dist/js/section.js.map +1 -1
- package/dist/js/segmentStore.d.ts +0 -1
- package/dist/js/segmentStore.js.map +1 -1
- package/dist/js/slotStore.d.ts +0 -1
- package/dist/js/slotStore.js.map +1 -1
- package/dist/js/standardSchema.d.ts +0 -1
- package/dist/js/standardSchema.js.map +1 -1
- package/dist/js/useForm.d.ts +0 -1
- package/dist/js/useForm.js.map +1 -1
- package/dist/js/useLinkStatus.d.ts +0 -1
- package/dist/js/useLinkStatus.js.map +1 -1
- package/dist/js/useOnline.d.ts +0 -1
- package/dist/js/useOnline.js.map +1 -1
- package/dist/js/usePathname.d.ts +0 -1
- package/dist/js/usePathname.js.map +1 -1
- package/dist/js/useSearchParams.d.ts +0 -1
- package/dist/js/useSearchParams.js.map +1 -1
- package/dist/manifest.d.ts +0 -1
- package/dist/manifest.js.map +1 -1
- package/dist/nondeterminism.d.ts +0 -1
- package/dist/nondeterminism.js.map +1 -1
- package/dist/prerender.d.ts +0 -1
- package/dist/prerender.js.map +1 -1
- package/dist/redirect.d.ts +0 -1
- package/dist/redirect.js.map +1 -1
- package/dist/redirectDigest.d.ts +0 -1
- package/dist/redirectDigest.js.map +1 -1
- package/dist/request.d.ts +0 -1
- package/dist/request.js.map +1 -1
- package/dist/revalidate.d.ts +0 -1
- package/dist/revalidate.js.map +1 -1
- package/dist/routes.d.ts +0 -1
- package/dist/routes.js.map +1 -1
- package/dist/routing.d.ts +0 -1
- package/dist/routing.js.map +1 -1
- package/dist/runtime.d.ts +0 -1
- package/dist/runtime.js.map +1 -1
- package/dist/safeUrl.d.ts +0 -1
- package/dist/safeUrl.js.map +1 -1
- package/dist/vite.d.ts +0 -1
- package/dist/vite.js +73 -9
- package/dist/vite.js.map +1 -1
- package/package.json +1 -5
- package/dist/action.d.ts.map +0 -1
- package/dist/build-rsc-vite.d.ts.map +0 -1
- package/dist/cache.d.ts.map +0 -1
- package/dist/cli.d.ts +0 -2
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js +0 -84
- package/dist/cli.js.map +0 -1
- package/dist/devServer.d.ts.map +0 -1
- package/dist/devUrls.d.ts.map +0 -1
- package/dist/embed.d.ts.map +0 -1
- package/dist/errors.d.ts.map +0 -1
- package/dist/export.d.ts.map +0 -1
- package/dist/files.d.ts.map +0 -1
- package/dist/headers.d.ts.map +0 -1
- package/dist/host.d.ts.map +0 -1
- package/dist/hostCalls.d.ts.map +0 -1
- package/dist/js/ActivityRouter.d.ts.map +0 -1
- package/dist/js/DocumentTitle.d.ts.map +0 -1
- package/dist/js/Form.d.ts.map +0 -1
- package/dist/js/Link.d.ts.map +0 -1
- package/dist/js/PathnameProvider.d.ts.map +0 -1
- package/dist/js/RedirectBoundary.d.ts.map +0 -1
- package/dist/js/SegmentBoundary.d.ts.map +0 -1
- package/dist/js/SlotBoundary.d.ts.map +0 -1
- package/dist/js/createViteRscApp.d.ts.map +0 -1
- package/dist/js/errors.d.ts.map +0 -1
- package/dist/js/navigate.d.ts.map +0 -1
- package/dist/js/onlineStore.d.ts.map +0 -1
- package/dist/js/pagePayload.d.ts.map +0 -1
- package/dist/js/router.d.ts.map +0 -1
- package/dist/js/section.d.ts.map +0 -1
- package/dist/js/segmentStore.d.ts.map +0 -1
- package/dist/js/slotStore.d.ts.map +0 -1
- package/dist/js/standardSchema.d.ts.map +0 -1
- package/dist/js/useForm.d.ts.map +0 -1
- package/dist/js/useLinkStatus.d.ts.map +0 -1
- package/dist/js/useOnline.d.ts.map +0 -1
- package/dist/js/usePathname.d.ts.map +0 -1
- package/dist/js/useSearchParams.d.ts.map +0 -1
- package/dist/manifest.d.ts.map +0 -1
- package/dist/nondeterminism.d.ts.map +0 -1
- package/dist/prerender.d.ts.map +0 -1
- package/dist/redirect.d.ts.map +0 -1
- package/dist/redirectDigest.d.ts.map +0 -1
- package/dist/request.d.ts.map +0 -1
- package/dist/revalidate.d.ts.map +0 -1
- package/dist/routes.d.ts.map +0 -1
- package/dist/routing.d.ts.map +0 -1
- package/dist/runtime.d.ts.map +0 -1
- package/dist/safeUrl.d.ts.map +0 -1
- 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
|
-
*
|
|
386
|
-
*
|
|
387
|
-
* relative path,
|
|
388
|
-
*
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
-
|
|
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' +
|