@rsc-kit/core 0.35.0 → 0.37.0
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/filesManifest.d.ts +28 -4
- package/dist/filesManifest.js +117 -24
- package/dist/filesManifest.js.map +1 -1
- package/dist/host.js +15 -1
- package/dist/host.js.map +1 -1
- package/dist/vite.js +106 -17
- package/dist/vite.js.map +1 -1
- package/package.json +1 -1
package/dist/vite.js
CHANGED
|
@@ -56,6 +56,25 @@ let clientLibraryImports = [];
|
|
|
56
56
|
let nitroPreset = null;
|
|
57
57
|
/** Set by Nitro's setup of a built server, which asks for the commands before Vite has resolved. */
|
|
58
58
|
let nitroBuilding = false;
|
|
59
|
+
/**
|
|
60
|
+
* Where Nitro writes this build, from the module's setup. The preset decides
|
|
61
|
+
* it: `.output/server` on node, bun and Workers, a function directory on
|
|
62
|
+
* Vercel (`.vercel/output/functions/__server.func`) and Netlify, `_worker.js`
|
|
63
|
+
* on Cloudflare Pages. What the server reads at runtime goes in `serverDir`,
|
|
64
|
+
* because that is what the platform deploys as the server; what a deploy
|
|
65
|
+
* reads goes in `dir`. Neither is derivable from Vite's client outDir.
|
|
66
|
+
*/
|
|
67
|
+
let nitroOutput = null;
|
|
68
|
+
/**
|
|
69
|
+
* Where the build's manifests for a deploy go - rsc-kit.json, edge.json,
|
|
70
|
+
* files.json: Nitro's output directory, unless that is the public one
|
|
71
|
+
* (Cloudflare Pages serves all of `dist`), when they would be published;
|
|
72
|
+
* then `.output/` at the app root, where the docs say they are.
|
|
73
|
+
*/
|
|
74
|
+
function deployManifestDir(projectRoot, output) {
|
|
75
|
+
const inside = relative(output.publicDir, output.dir);
|
|
76
|
+
return inside === "" || (!inside.startsWith("..") && !isAbsolute(inside)) ? join(projectRoot, ".output") : output.dir;
|
|
77
|
+
}
|
|
59
78
|
/** The mode this build bakes in, for the process that runs it. See nodeEnvPlugin. */
|
|
60
79
|
let builtNodeEnv = "production";
|
|
61
80
|
/** `src/commands`, read once per build; null until asked. See buildCommands(). */
|
|
@@ -7726,6 +7745,11 @@ function clientImportsAudit() {
|
|
|
7726
7745
|
},
|
|
7727
7746
|
};
|
|
7728
7747
|
}
|
|
7748
|
+
/** `inner` as a path under `outer` - `["/x"]` - or nothing when it is not inside it. */
|
|
7749
|
+
function insideOf(outer, inner) {
|
|
7750
|
+
const path = relative(outer, inner).replace(/\\/g, "/");
|
|
7751
|
+
return path && !path.startsWith("..") && !isAbsolute(path) ? [`/${path}`] : [];
|
|
7752
|
+
}
|
|
7729
7753
|
/** Whether the app's Nitro exports `nitro/services`: the release candidate on. */
|
|
7730
7754
|
function nitroHasPublicServices(root) {
|
|
7731
7755
|
try {
|
|
@@ -7992,6 +8016,11 @@ export function rscKit(options = {}) {
|
|
|
7992
8016
|
return;
|
|
7993
8017
|
nitroPreset = nitro.options.preset ?? null;
|
|
7994
8018
|
nitroBuilding = true;
|
|
8019
|
+
nitroOutput = {
|
|
8020
|
+
dir: nitro.options.output.dir ?? dirname(nitro.options.output.serverDir),
|
|
8021
|
+
serverDir: nitro.options.output.serverDir,
|
|
8022
|
+
publicDir: nitro.options.output.publicDir ?? join(dirname(nitro.options.output.serverDir), "public"),
|
|
8023
|
+
};
|
|
7995
8024
|
// The commands that did not ask for register() are an entry of the
|
|
7996
8025
|
// rsc environment that Nitro would leave behind: it bundles the
|
|
7997
8026
|
// server from the environment's main entry only. Given to it as an
|
|
@@ -8074,16 +8103,54 @@ export function rscKit(options = {}) {
|
|
|
8074
8103
|
// Workers build copies into the public directory (the hook below)
|
|
8075
8104
|
// are read through a binding, never served: left out by name, not
|
|
8076
8105
|
// by running first.
|
|
8106
|
+
//
|
|
8107
|
+
// Written to Nitro's output directory - `.output` on node, bun and
|
|
8108
|
+
// Workers, `.vercel/output` on Vercel, `.output` at the app root when
|
|
8109
|
+
// the output directory is the public one (Cloudflare Pages) - never
|
|
8110
|
+
// beside the server bundle, which on some presets is a function
|
|
8111
|
+
// directory. A file's
|
|
8112
|
+
// path is its url: Nitro serves `<publicDir>/x` at `<baseURL>/x`, and
|
|
8113
|
+
// most presets nest the public directory under the base url, so
|
|
8114
|
+
// `root` is that directory with the base taken back off.
|
|
8077
8115
|
nitro.hooks.hook("compiled", async () => {
|
|
8078
|
-
const { filesManifest } = await import("./filesManifest.js");
|
|
8116
|
+
const { filesManifest, nitroRouteRules } = await import("./filesManifest.js");
|
|
8079
8117
|
const { ASSETS_PREFIX } = await import("./files.js");
|
|
8080
|
-
const
|
|
8081
|
-
const
|
|
8082
|
-
const
|
|
8083
|
-
|
|
8084
|
-
|
|
8118
|
+
const publicDir = nitro.options.output.publicDir ?? join(nitro.options.output.dir ?? dirname(nitro.options.output.serverDir), "public");
|
|
8119
|
+
const outputDir = deployManifestDir(projectRoot, { dir: nitro.options.output.dir ?? dirname(nitro.options.output.serverDir), publicDir });
|
|
8120
|
+
const baseURL = (nitro.options.baseURL ?? "/").replace(/\/+$/, "");
|
|
8121
|
+
const publicRoot = baseURL && publicDir.replace(/[\\/]+$/, "").replace(/\\/g, "/").endsWith(baseURL)
|
|
8122
|
+
? publicDir.replace(/[\\/]+$/, "").slice(0, -baseURL.length)
|
|
8123
|
+
: baseURL ? null : publicDir;
|
|
8124
|
+
const leftOut = [];
|
|
8125
|
+
const manifest = filesManifest(publicRoot === null ? join(outputDir, "-no-files-") : publicDir, nitro.options.routeRules, {
|
|
8126
|
+
root: relative(outputDir, publicRoot ?? publicDir).replace(/\\/g, "/") || ".",
|
|
8127
|
+
exclude: [
|
|
8128
|
+
`/${ASSETS_PREFIX(NITRO_STATIC_DIR)}`,
|
|
8129
|
+
// A platform's own configuration, which it reads and never
|
|
8130
|
+
// serves: Workers and Netlify take `_headers` and `_redirects`
|
|
8131
|
+
// from the public directory, Pages `_routes.json`.
|
|
8132
|
+
"/_headers",
|
|
8133
|
+
"/_redirects",
|
|
8134
|
+
"/_routes.json",
|
|
8135
|
+
"/.assetsignore",
|
|
8136
|
+
// The server itself, where a preset builds it inside the public
|
|
8137
|
+
// directory - Cloudflare Pages' `_worker.js`.
|
|
8138
|
+
...insideOf(publicDir, nitro.options.output.serverDir),
|
|
8139
|
+
],
|
|
8140
|
+
baseURL,
|
|
8141
|
+
resolve: await nitroRouteRules(projectRoot, nitro.options.routeRules, baseURL),
|
|
8142
|
+
onLeftOut: (path, why) => leftOut.push(`${path} (${why})`),
|
|
8085
8143
|
});
|
|
8086
|
-
|
|
8144
|
+
// A public directory not under its base url cannot be served by
|
|
8145
|
+
// joining a root and a url path: nothing is listed, and every
|
|
8146
|
+
// request goes to the app.
|
|
8147
|
+
if (publicRoot === null)
|
|
8148
|
+
log(`files.json lists no files: the public directory ${publicDir} is not under the base url ${baseURL}`);
|
|
8149
|
+
if (leftOut.length) {
|
|
8150
|
+
log(`files.json leaves ${leftOut.length} file${leftOut.length === 1 ? "" : "s"} to the app, under route rules a server in front cannot follow: ${leftOut.slice(0, 5).join(", ")}${leftOut.length > 5 ? ", ..." : ""}`);
|
|
8151
|
+
}
|
|
8152
|
+
mkdirSync(outputDir, { recursive: true });
|
|
8153
|
+
writeFileSync(join(outputDir, "files.json"), JSON.stringify(manifest, null, 2) + "\n");
|
|
8087
8154
|
});
|
|
8088
8155
|
// On Workers the stored pages ride the static assets, not the bundle.
|
|
8089
8156
|
// Copied once Nitro has listed its public files, so the copies are
|
|
@@ -8137,14 +8204,25 @@ export function rscKit(options = {}) {
|
|
|
8137
8204
|
// deploy's list against the new server, every file 404s, and the
|
|
8138
8205
|
// install fails - leaving the old worker in charge, serving the old
|
|
8139
8206
|
// documents, for as long as the browser holds the script.
|
|
8140
|
-
|
|
8141
|
-
|
|
8207
|
+
//
|
|
8208
|
+
// And the other files the build writes under a fixed name: the app's
|
|
8209
|
+
// own worker code the worker imports (src/app/sw.js, served as
|
|
8210
|
+
// /sw-app.js - kept by a heuristic it is the old code inside the new
|
|
8211
|
+
// worker), the web app manifest, and the icons, splash screens and
|
|
8212
|
+
// share images under /_app/, which hold nothing fingerprinted. Each
|
|
8213
|
+
// revalidates; its ETag makes that a 304. The app's own public/ files
|
|
8214
|
+
// are its own to decide. A rule the app set for one of these paths
|
|
8215
|
+
// keeps its headers over these.
|
|
8216
|
+
const revalidate = { "cache-control": "public, max-age=0, must-revalidate" };
|
|
8217
|
+
const rules = (nitro.options.routeRules ?? {});
|
|
8218
|
+
nitro.options.routeRules = { ...rules };
|
|
8219
|
+
for (const path of ["/sw.js", "/sw-app.js", "/manifest.webmanifest", `${ASSET_BASE}/**`]) {
|
|
8142
8220
|
// Spelled with max-age=0 rather than no-cache: a CDN's browser
|
|
8143
8221
|
// cache TTL - Cloudflare's, four hours - applies where the origin
|
|
8144
8222
|
// names no max-age, and rewrote no-cache to max-age=14400; a
|
|
8145
8223
|
// max-age of zero it leaves alone, as it leaves the documents'.
|
|
8146
|
-
|
|
8147
|
-
}
|
|
8224
|
+
nitro.options.routeRules[path] = { ...(rules[path] ?? {}), headers: { ...revalidate, ...(rules[path]?.headers ?? {}) } };
|
|
8225
|
+
}
|
|
8148
8226
|
// The names of functions survive Nitro's bundle. The pages were
|
|
8149
8227
|
// prerendered against Vite's own server bundles, where a dependency
|
|
8150
8228
|
// is loaded from node_modules under the names it was written with;
|
|
@@ -8803,10 +8881,20 @@ export function rscKit(options = {}) {
|
|
|
8803
8881
|
// else exist on the build machine and nowhere after that. They go beside
|
|
8804
8882
|
// the server bundle instead, and buildApp runs before Nitro assembles, so
|
|
8805
8883
|
// they are in place by the time it does.
|
|
8884
|
+
//
|
|
8885
|
+
// Beside the server Nitro writes, wherever the preset puts it: a
|
|
8886
|
+
// function directory on Vercel and Netlify is what the platform
|
|
8887
|
+
// deploys, and a path next to it is left on the build machine - every
|
|
8888
|
+
// page then rendered live, with nothing to say so.
|
|
8806
8889
|
const clientOut = builder?.environments?.client?.config?.build?.outDir;
|
|
8807
|
-
const staticDir =
|
|
8808
|
-
? join(
|
|
8809
|
-
:
|
|
8890
|
+
const staticDir = nitroOutput
|
|
8891
|
+
? join(nitroOutput.serverDir, NITRO_STATIC_DIR)
|
|
8892
|
+
: clientOut
|
|
8893
|
+
? join(dirname(clientOut), "server", NITRO_STATIC_DIR)
|
|
8894
|
+
: join(outDir, NITRO_STATIC_DIR);
|
|
8895
|
+
// Where a deploy reads what the build produced: Nitro's output
|
|
8896
|
+
// directory, as for files.json.
|
|
8897
|
+
const manifestDir = nitroOutput ? deployManifestDir(projectRoot, nitroOutput) : clientOut ? dirname(clientOut) : outDir;
|
|
8810
8898
|
const { frozen, results, shells, routes, pathKey: pathKeyOf, build: clientBuild } = await prerenderAfterBundles(bundle, staticDir, clientOut ?? publicAssetsDir, builder ? knownActionsOf(builder.config, projectRoot) : []);
|
|
8811
8899
|
// The edge contract's static pages, each given a payload it boots from
|
|
8812
8900
|
// without the app - before the build id, which hashes the documents
|
|
@@ -8880,7 +8968,8 @@ export function rscKit(options = {}) {
|
|
|
8880
8968
|
// compute it - or knowing where rsc-kit keeps things inside .output.
|
|
8881
8969
|
// Written by the code that decided, so it cannot disagree with it.
|
|
8882
8970
|
if (clientOut) {
|
|
8883
|
-
|
|
8971
|
+
mkdirSync(manifestDir, { recursive: true });
|
|
8972
|
+
writeFileSync(join(manifestDir, "rsc-kit.json"), JSON.stringify(output === "export"
|
|
8884
8973
|
? { version: PACKAGE_VERSION, output: "export", dir: relative(projectRoot, exportPath) }
|
|
8885
8974
|
: {
|
|
8886
8975
|
version: PACKAGE_VERSION,
|
|
@@ -8896,10 +8985,10 @@ export function rscKit(options = {}) {
|
|
|
8896
8985
|
// belong to. Written by every server build, with empty lists when
|
|
8897
8986
|
// there are none, so a platform can tell "none" from "an rsc-kit too
|
|
8898
8987
|
// old to say". Not by an export, which has no origin to answer for it.
|
|
8899
|
-
const markerFile = join(
|
|
8988
|
+
const markerFile = join(manifestDir, "edge.json");
|
|
8900
8989
|
// v1's marker, from a build before this one: an edge reading it
|
|
8901
8990
|
// would ask for endpoints that are no longer here.
|
|
8902
|
-
rmSync(join(
|
|
8991
|
+
rmSync(join(manifestDir, "ppr.json"), { force: true });
|
|
8903
8992
|
if (output !== "export" && marker) {
|
|
8904
8993
|
writeFileSync(markerFile, JSON.stringify(marker, null, 2) + "\n");
|
|
8905
8994
|
}
|