@kasperpeulen/vitest-plugin-nextjs 0.0.0-stage → 0.1.0-alpha.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/README.md +249 -2
- package/dist/_virtual/_rolldown/runtime.js +14 -0
- package/dist/action-ids.d.ts +18 -0
- package/dist/action-ids.js +44 -0
- package/dist/adapter.d.ts +8 -0
- package/dist/adapter.js +12 -0
- package/dist/app-requests.d.ts +63 -0
- package/dist/app-requests.js +253 -0
- package/dist/browser-context.d.ts +24 -0
- package/dist/browser-context.js +157 -0
- package/dist/build-output.d.ts +68 -0
- package/dist/build-output.js +216 -0
- package/dist/build.d.ts +26 -0
- package/dist/build.js +39 -0
- package/dist/built-files.d.ts +9 -0
- package/dist/built-files.js +22 -0
- package/dist/cache.d.ts +44 -0
- package/dist/cache.js +99 -0
- package/dist/client-components.d.ts +3 -0
- package/dist/client-components.js +4 -0
- package/dist/client-file-key.d.ts +5 -0
- package/dist/client-file-key.js +5 -0
- package/dist/client-files.d.ts +83 -0
- package/dist/client-files.js +186 -0
- package/dist/client-graph.d.ts +94 -0
- package/dist/client-graph.js +266 -0
- package/dist/client-modules.d.ts +10 -0
- package/dist/client-modules.js +43 -0
- package/dist/client.d.ts +42 -0
- package/dist/client.js +263 -0
- package/dist/commonjs.d.ts +44 -0
- package/dist/commonjs.js +111 -0
- package/dist/compat/browser/client.d.ts +19 -0
- package/dist/compat/browser/client.js +13 -0
- package/dist/compat/build.d.ts +145 -0
- package/dist/compat/build.js +149 -0
- package/dist/compat/checks.d.ts +16 -0
- package/dist/compat/checks.js +148 -0
- package/dist/compat/patches.d.ts +13 -0
- package/dist/compat/patches.js +30 -0
- package/dist/compat/paths.d.ts +74 -0
- package/dist/compat/paths.js +160 -0
- package/dist/compat/rsc/handlers.d.ts +2 -0
- package/dist/compat/rsc/handlers.js +2 -0
- package/dist/compat/rsc/prerender.d.ts +10 -0
- package/dist/compat/rsc/prerender.js +9 -0
- package/dist/compat/server/headers.d.ts +3 -0
- package/dist/compat/server/headers.js +3 -0
- package/dist/compat/ssr/build-output.d.ts +4 -0
- package/dist/compat/ssr/build-output.js +3 -0
- package/dist/compat/ssr/cache.d.ts +6 -0
- package/dist/compat/ssr/cache.js +6 -0
- package/dist/compat/ssr/handler.d.ts +8 -0
- package/dist/compat/ssr/handler.js +8 -0
- package/dist/compat/ssr/node-server.d.ts +5 -0
- package/dist/compat/ssr/node-server.js +4 -0
- package/dist/compat/ssr/render-errors.d.ts +4 -0
- package/dist/compat/ssr/render-errors.js +4 -0
- package/dist/compat/ssr/senders.d.ts +6 -0
- package/dist/compat/ssr/senders.js +6 -0
- package/dist/compat/types.d.ts +8 -0
- package/dist/compat/types.js +1 -0
- package/dist/compile.d.ts +31 -0
- package/dist/compile.js +140 -0
- package/dist/disk.d.ts +16 -0
- package/dist/disk.js +13 -0
- package/dist/document-loads.d.ts +15 -0
- package/dist/document-loads.js +53 -0
- package/dist/document.d.ts +79 -0
- package/dist/document.js +328 -0
- package/dist/downloads.d.ts +15 -0
- package/dist/downloads.js +71 -0
- package/dist/esm-require.d.ts +11 -0
- package/dist/esm-require.js +32 -0
- package/dist/fast-crypto/index.js +1093 -0
- package/dist/fast-crypto.d.ts +20 -0
- package/dist/fast-crypto.js +151 -0
- package/dist/flight.d.ts +19 -0
- package/dist/flight.js +42 -0
- package/dist/form-submission.d.ts +15 -0
- package/dist/form-submission.js +27 -0
- package/dist/from-page.d.ts +5 -0
- package/dist/from-page.js +44 -0
- package/dist/globals.d.ts +1 -0
- package/dist/globals.js +197 -0
- package/dist/host-document.d.ts +26 -0
- package/dist/host-document.js +34 -0
- package/dist/index.d.ts +280 -0
- package/dist/index.js +281 -0
- package/dist/internal.d.ts +2 -0
- package/dist/internal.js +3 -0
- package/dist/leftovers.d.ts +11 -0
- package/dist/leftovers.js +55 -0
- package/dist/mode.d.ts +169 -0
- package/dist/mode.js +31 -0
- package/dist/node/LICENSES.md +3540 -0
- package/dist/node/assert/strict.js +29 -0
- package/dist/node/assert.js +3044 -0
- package/dist/node/buffer.js +1499 -0
- package/dist/node/child_process.js +45 -0
- package/dist/node/cluster.js +85 -0
- package/dist/node/console.js +96 -0
- package/dist/node/constants.js +495 -0
- package/dist/node/crypto.js +1388 -0
- package/dist/node/dgram.js +78 -0
- package/dist/node/diagnostics_channel.js +122 -0
- package/dist/node/dns/promises.js +129 -0
- package/dist/node/dns.js +137 -0
- package/dist/node/domain.js +43 -0
- package/dist/node/events.js +1155 -0
- package/dist/node/fs/promises.js +40 -0
- package/dist/node/fs.js +10375 -0
- package/dist/node/http.js +326 -0
- package/dist/node/http2.js +305 -0
- package/dist/node/https.js +57 -0
- package/dist/node/inspector/promises.js +66 -0
- package/dist/node/inspector.js +76 -0
- package/dist/node/module.js +205 -0
- package/dist/node/net.js +392 -0
- package/dist/node/os.js +259 -0
- package/dist/node/path/posix.js +25 -0
- package/dist/node/path/win32.js +25 -0
- package/dist/node/path.js +384 -0
- package/dist/node/perf_hooks.js +313 -0
- package/dist/node/process.js +452 -0
- package/dist/node/punycode.js +178 -0
- package/dist/node/querystring.js +934 -0
- package/dist/node/readline/promises.js +71 -0
- package/dist/node/readline.js +56 -0
- package/dist/node/repl.js +44 -0
- package/dist/node/sqlite.js +22 -0
- package/dist/node/stream/consumers.js +47 -0
- package/dist/node/stream/promises.js +6 -0
- package/dist/node/stream/web.js +52 -0
- package/dist/node/stream.js +4323 -0
- package/dist/node/string_decoder.js +276 -0
- package/dist/node/sys.js +6 -0
- package/dist/node/timers/promises.js +71 -0
- package/dist/node/timers.js +133 -0
- package/dist/node/tls.js +122 -0
- package/dist/node/trace_events.js +23 -0
- package/dist/node/tty.js +69 -0
- package/dist/node/url.js +1426 -0
- package/dist/node/util/types.js +1456 -0
- package/dist/node/util.js +4807 -0
- package/dist/node/v8.js +160 -0
- package/dist/node/vm.js +88 -0
- package/dist/node/wasi.js +16 -0
- package/dist/node/worker_threads.js +123 -0
- package/dist/node/zlib.js +1396 -0
- package/dist/node-builtins.d.ts +40 -0
- package/dist/node-builtins.js +74 -0
- package/dist/node-on-page.d.ts +46 -0
- package/dist/node-on-page.js +101 -0
- package/dist/node-platform.d.ts +36 -0
- package/dist/node-platform.js +152 -0
- package/dist/node-rendered.d.ts +21 -0
- package/dist/node-rendered.js +26 -0
- package/dist/node-server.d.ts +46 -0
- package/dist/node-server.js +193 -0
- package/dist/optimizer-cache-key.d.ts +26 -0
- package/dist/optimizer-cache-key.js +73 -0
- package/dist/own-package.d.ts +1 -0
- package/dist/own-package.js +6 -0
- package/dist/page-store.d.ts +33 -0
- package/dist/page-store.js +80 -0
- package/dist/page-timers.d.ts +22 -0
- package/dist/page-timers.js +47 -0
- package/dist/page.d.ts +112 -0
- package/dist/page.js +549 -0
- package/dist/paths.d.ts +13 -0
- package/dist/paths.js +47 -0
- package/dist/plugin.d.ts +22 -0
- package/dist/plugin.js +995 -0
- package/dist/prerender-verdict.d.ts +8 -0
- package/dist/prerender-verdict.js +67 -0
- package/dist/project/context.d.ts +546 -0
- package/dist/project/context.js +111 -0
- package/dist/project/entries.d.ts +42 -0
- package/dist/project/entries.js +189 -0
- package/dist/project/env-worker.d.ts +1 -0
- package/dist/project/env-worker.js +9 -0
- package/dist/project/env.d.ts +36 -0
- package/dist/project/env.js +82 -0
- package/dist/project/layers.d.ts +31 -0
- package/dist/project/layers.js +150 -0
- package/dist/project/loaders.d.ts +71 -0
- package/dist/project/loaders.js +300 -0
- package/dist/project/metadata.d.ts +8 -0
- package/dist/project/metadata.js +34 -0
- package/dist/project/module-exports.d.ts +29 -0
- package/dist/project/module-exports.js +77 -0
- package/dist/project/routes.d.ts +19 -0
- package/dist/project/routes.js +92 -0
- package/dist/project/routing.d.ts +46 -0
- package/dist/project/routing.js +280 -0
- package/dist/project/transform.d.ts +8 -0
- package/dist/project/transform.js +110 -0
- package/dist/project/webpack.d.ts +46 -0
- package/dist/project/webpack.js +160 -0
- package/dist/project.d.ts +264 -0
- package/dist/project.js +58 -0
- package/dist/registry-global.d.ts +5 -0
- package/dist/registry-global.js +5 -0
- package/dist/registry.d.ts +241 -0
- package/dist/registry.js +30 -0
- package/dist/route-chunks.d.ts +13 -0
- package/dist/route-chunks.js +32 -0
- package/dist/route-lookup.d.ts +34 -0
- package/dist/route-lookup.js +207 -0
- package/dist/routes-ahead-shared.d.ts +17 -0
- package/dist/routes-ahead-shared.js +9 -0
- package/dist/routes-ahead.d.ts +10 -0
- package/dist/routes-ahead.js +54 -0
- package/dist/rsc.d.ts +19 -0
- package/dist/rsc.js +171 -0
- package/dist/server-action.d.ts +9 -0
- package/dist/server-action.js +15 -0
- package/dist/server-code.d.ts +176 -0
- package/dist/server-code.js +357 -0
- package/dist/server-in-front.d.ts +37 -0
- package/dist/server-in-front.js +90 -0
- package/dist/server-layers.d.ts +22 -0
- package/dist/server-layers.js +33 -0
- package/dist/setup-browser.d.ts +1 -0
- package/dist/setup-browser.js +8 -0
- package/dist/setup-node.d.ts +1 -0
- package/dist/setup-node.js +6 -0
- package/dist/setup.d.ts +8 -0
- package/dist/setup.js +62 -0
- package/dist/speed-features.d.ts +13 -0
- package/dist/speed-features.js +95 -0
- package/dist/ssr.d.ts +70 -0
- package/dist/ssr.js +480 -0
- package/dist/static-build.d.ts +36 -0
- package/dist/static-build.js +92 -0
- package/dist/storage.d.ts +31 -0
- package/dist/storage.js +94 -0
- package/dist/styles-shared.d.ts +137 -0
- package/dist/styles-shared.js +124 -0
- package/dist/styles.d.ts +102 -0
- package/dist/styles.js +730 -0
- package/dist/stylesheet-versions.d.ts +17 -0
- package/dist/stylesheet-versions.js +43 -0
- package/dist/tester.html +10 -0
- package/dist/use-cache.d.ts +15 -0
- package/dist/use-cache.js +93 -0
- package/dist/vitest-version.d.ts +6 -0
- package/dist/vitest-version.js +12 -0
- package/package.json +125 -3
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { NextBuild } from "./build.js";
|
|
2
|
+
import { RoutesManifest } from "./compat/types.js";
|
|
3
|
+
import { FlightEntry } from "./flight.js";
|
|
4
|
+
import { PageEnv } from "./project/env.js";
|
|
5
|
+
import { NewExport } from "./node-platform.js";
|
|
6
|
+
import { WebpackRule } from "./project/webpack.js";
|
|
7
|
+
import { ResolveRoutesParams } from "@next/routing";
|
|
8
|
+
import * as _$vite from "vite";
|
|
9
|
+
import { IncomingMessage, ServerResponse } from "node:http";
|
|
10
|
+
|
|
11
|
+
//#region src/project.d.ts
|
|
12
|
+
/** The layers Next compiles an App Router app into, each with its own React. */
|
|
13
|
+
type NextLayer = "rsc" | "ssr" | "browser";
|
|
14
|
+
type NextRoute = {
|
|
15
|
+
/** What serves the route: a `page.tsx` with its layouts, or a `route.ts`. */kind: "page" | "route"; /** App page name, e.g. `/notes/[id]/page` or `/api/notes/[id]/route`. */
|
|
16
|
+
page: string; /** Routable pathname, e.g. `/notes/[id]`. */
|
|
17
|
+
pathname: string; /** `private-next-app-dir/...`, or an absolute path for Next's builtin pages. */
|
|
18
|
+
pagePath: string; /** The pages of the route: `page`, and those of its parallel routes. */
|
|
19
|
+
appPaths: string[];
|
|
20
|
+
};
|
|
21
|
+
/** A route of a node, see `NextProject.componentRoutes`. */
|
|
22
|
+
type ComponentRoute = {
|
|
23
|
+
kind: "page";
|
|
24
|
+
/**
|
|
25
|
+
* Its page name, e.g. `/notes/[id]/page`, from which Next takes its params
|
|
26
|
+
* and the tags of its path. `revalidatePath("/notes/[id]", "page")` expires
|
|
27
|
+
* the cached reads with those tags. A page of the app can have the same
|
|
28
|
+
* name.
|
|
29
|
+
*/
|
|
30
|
+
page: string; /** Routable pathname, e.g. `/notes/[id]`. */
|
|
31
|
+
pathname: string; /** What its modules are listed by, which no page of the app has as its name. */
|
|
32
|
+
component: string;
|
|
33
|
+
/**
|
|
34
|
+
* With the layouts of the app's route `page`: the node is the page of that
|
|
35
|
+
* route, in its layouts and with its `loading`, `error` and `not-found`.
|
|
36
|
+
*/
|
|
37
|
+
layouts?: true;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* What the server in front of the app goes by: the routes that Next's build
|
|
41
|
+
* hands a deployment adapter, as `resolveRoutes()` of `@next/routing` takes
|
|
42
|
+
* them.
|
|
43
|
+
*/
|
|
44
|
+
type NextRouting = Pick<ResolveRoutesParams, "routes" | "basePath" | "buildId"> & {
|
|
45
|
+
/**
|
|
46
|
+
* What the build has to answer a request with, by the pathname Next serves
|
|
47
|
+
* it at, like `/notes/[id]`: the page name of its route.
|
|
48
|
+
*/
|
|
49
|
+
outputs: Record<string, string>;
|
|
50
|
+
/**
|
|
51
|
+
* The routes of the app alone, without the server in front of it: no
|
|
52
|
+
* redirect, rewrite or header of `next.config`, and no middleware. What is
|
|
53
|
+
* left is Next's own: the routes of the app, its interception routes, and
|
|
54
|
+
* the headers it adds once it has a route.
|
|
55
|
+
*/
|
|
56
|
+
appRoutes: ResolveRoutesParams["routes"];
|
|
57
|
+
};
|
|
58
|
+
type NextProject = {
|
|
59
|
+
root: string;
|
|
60
|
+
appDir: string; /** Directory of the installed `next` package. */
|
|
61
|
+
nextDir: string; /** Version of the installed `next` package. */
|
|
62
|
+
version: string;
|
|
63
|
+
routes: NextRoute[];
|
|
64
|
+
/**
|
|
65
|
+
* The routes `renderServer(<Node />, { url })` renders a node in: one for
|
|
66
|
+
* each pathname of the app, so that a URL has the params of the app's route,
|
|
67
|
+
* and one for `/`, for a node without a url or with a URL of no route.
|
|
68
|
+
*/
|
|
69
|
+
componentRoutes: ComponentRoute[]; /** The route files of the app that ask for Next's edge runtime, which they do not get. */
|
|
70
|
+
edgeRouteFiles: string[];
|
|
71
|
+
/**
|
|
72
|
+
* The dynamic routes that `resolveRoutes()` does not find for a request: the
|
|
73
|
+
* ones under a folder with a name that a URL percent-encodes.
|
|
74
|
+
*/
|
|
75
|
+
unmatchedRoutes: string[];
|
|
76
|
+
/**
|
|
77
|
+
* The exports of Next's modules that their stand-ins in node-platform.ts
|
|
78
|
+
* have not, by the stand-in: new in the installed Next.
|
|
79
|
+
*/
|
|
80
|
+
newExports: Record<string, NewExport[]>; /** The `proxy.ts` of the app, or its `middleware.ts`: its file, if it has one. */
|
|
81
|
+
middlewareFile: string | undefined; /** What the server does with a request before a route gets it. */
|
|
82
|
+
routing: NextRouting;
|
|
83
|
+
/**
|
|
84
|
+
* The page name of the route the server answers a URL with, as nothing has
|
|
85
|
+
* run, without headers or cookies: with `proxy`, after the redirects and
|
|
86
|
+
* rewrites of `next.config`, and the middleware takes every request on as it
|
|
87
|
+
* is. Nothing for a URL of no route, or one that a redirect sends to another
|
|
88
|
+
* origin.
|
|
89
|
+
*/
|
|
90
|
+
pageOf(url: URL, options: {
|
|
91
|
+
proxy: boolean;
|
|
92
|
+
}): Promise<string | undefined>; /** What a build writes to `.next/routes-manifest.json`, which Next's route module reads. */
|
|
93
|
+
routesManifest: RoutesManifest; /** The keys of draft mode, which a build makes and writes to `.next/`. */
|
|
94
|
+
preview: {
|
|
95
|
+
previewModeId: string;
|
|
96
|
+
previewModeSigningKey: string;
|
|
97
|
+
previewModeEncryptionKey: string;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* The `paths` of the app's tsconfig or jsconfig, as Next's build reads
|
|
101
|
+
* them, and the directory they are from. Nothing for an app without either.
|
|
102
|
+
*/
|
|
103
|
+
paths: {
|
|
104
|
+
baseUrl: string;
|
|
105
|
+
explicitBaseUrl: boolean;
|
|
106
|
+
patterns: Record<string, string[]>;
|
|
107
|
+
} | undefined; /** What the page's `process.env` gets: see project/env.ts. */
|
|
108
|
+
env: PageEnv; /** The env again, after a change of an env file. */
|
|
109
|
+
loadEnv: () => Promise<PageEnv>; /** The resolved `next.config`, as far as it serializes. */
|
|
110
|
+
config: Record<string, unknown>; /** Next's compile-time constants per layer, as code strings. */
|
|
111
|
+
defines: Record<NextLayer, Record<string, string>>; /** Next's compiler aliases per layer, in webpack's notation: `$` ends an exact match. */
|
|
112
|
+
aliases: Record<NextLayer, Record<string, string | false>>;
|
|
113
|
+
/**
|
|
114
|
+
* Entries that the app's code, and not Next's own files, gets in place of
|
|
115
|
+
* those of `aliases`: React's for Node.js. Exact matches, `$`.
|
|
116
|
+
*/
|
|
117
|
+
appAliases: Record<NextLayer, Record<string, string>>;
|
|
118
|
+
/**
|
|
119
|
+
* The exports of each entry of the Flight codec that the rsc layer imports
|
|
120
|
+
* as `react-server-dom-webpack/<entry>`.
|
|
121
|
+
*/
|
|
122
|
+
flightExports: Record<FlightEntry, string[]>;
|
|
123
|
+
/**
|
|
124
|
+
* The rsc-layer module of a route, from Next's app loader, with this
|
|
125
|
+
* package's runtime where Next's code names its bundler. For a page: its
|
|
126
|
+
* loader tree and `entry-base`. For a route handler: its route module.
|
|
127
|
+
*
|
|
128
|
+
* For a route of a node: Next's page template around a loader tree that has
|
|
129
|
+
* the segments of the pathname, and the node as its page. Nothing of the app.
|
|
130
|
+
*/
|
|
131
|
+
loadRouteEntry(route: NextRoute | ComponentRoute): Promise<{
|
|
132
|
+
code: string;
|
|
133
|
+
watchFiles: string[];
|
|
134
|
+
/**
|
|
135
|
+
* The files of the segments of a page route, as its entry imports them:
|
|
136
|
+
* its layouts, pages and boundaries. Not the node of the route of a node,
|
|
137
|
+
* which is no file: its name in the loader tree is `componentPagePath`.
|
|
138
|
+
*/
|
|
139
|
+
segments: RouteSegment[];
|
|
140
|
+
}>;
|
|
141
|
+
/**
|
|
142
|
+
* Next's request handler of the middleware: its template around the file.
|
|
143
|
+
* Nothing for an app without one.
|
|
144
|
+
*/
|
|
145
|
+
loadMiddlewareEntry(): Promise<string | undefined>;
|
|
146
|
+
/**
|
|
147
|
+
* Next's SWC transform of a module of the app, for a layer. Nothing for a
|
|
148
|
+
* client module in the rsc layer: Vite RSC turns it into references.
|
|
149
|
+
*/
|
|
150
|
+
compile(code: string, file: string, layer: NextLayer): Promise<Compiled | undefined>;
|
|
151
|
+
/**
|
|
152
|
+
* The options of that transform for a dependency of a layer, like a package
|
|
153
|
+
* that calls `next/font`: from `next.config` and the app's tsconfig. For the
|
|
154
|
+
* key of the optimizer's cache, which compiles such a package.
|
|
155
|
+
*/
|
|
156
|
+
dependencyCompileOptions: Record<NextLayer, unknown>;
|
|
157
|
+
/**
|
|
158
|
+
* The rule of the `webpack` function in `next.config` for a file, like the
|
|
159
|
+
* one of `@next/mdx` for an `.mdx` file: see project/webpack.ts.
|
|
160
|
+
*/
|
|
161
|
+
webpackRuleOf(file: string, layer: NextLayer): WebpackRule | undefined; /** What the loaders of that rule make of the file. Nothing for a file without one. */
|
|
162
|
+
loadWithWebpackRule(file: string, layer: NextLayer): Promise<string | undefined>; /** The candidates of an alias of the `webpack` function for an import, in order. */
|
|
163
|
+
webpackAliasOf(source: string, layer: NextLayer): string[] | undefined; /** The packages among those candidates, to pre-bundle. */
|
|
164
|
+
webpackPackages: Record<NextLayer, string[]>; /** What of the `webpack` function does not apply, to say when a run starts. */
|
|
165
|
+
webpackDifferences: string[];
|
|
166
|
+
/**
|
|
167
|
+
* Whether an import is Next's inline request for one of its metadata
|
|
168
|
+
* loaders, which its app loader asks for a metadata file of the app with.
|
|
169
|
+
*/
|
|
170
|
+
isMetadataRequest(source: string): boolean;
|
|
171
|
+
/**
|
|
172
|
+
* What a metadata loader makes of a file: for a page, the data of an image
|
|
173
|
+
* it links in its head, like `icon.png`; for a route, its route module.
|
|
174
|
+
*/
|
|
175
|
+
loadMetadata(request: string): Promise<{
|
|
176
|
+
code: string;
|
|
177
|
+
watchFiles: string[];
|
|
178
|
+
}>;
|
|
179
|
+
/**
|
|
180
|
+
* The query with which the module of a generated image, like `icon.tsx`,
|
|
181
|
+
* is imported for what it says of the image: its `size`, `alt`,
|
|
182
|
+
* `contentType` and `generateImageMetadata`.
|
|
183
|
+
*/
|
|
184
|
+
metadataImageMeta: string; /** Whether Next's build imports a file as an image: `next-image-loader`. */
|
|
185
|
+
isImage(file: string): boolean; /** The module of an image: what `next-image-loader` makes of the file. */
|
|
186
|
+
loadImage(file: string): Promise<string>;
|
|
187
|
+
/**
|
|
188
|
+
* A call of a `next/font` function, by the import the SWC transform turns it
|
|
189
|
+
* into: the CSS of the font, what the call returns, and its font files,
|
|
190
|
+
* under `/_next/` (`static/media/…`). Next preloads a file whose name has
|
|
191
|
+
* `.p.`, which the loader gives it for a font with `preload` on.
|
|
192
|
+
*/
|
|
193
|
+
loadFont(request: string): Promise<{
|
|
194
|
+
css: string;
|
|
195
|
+
exports: Record<string, unknown>;
|
|
196
|
+
files: string[];
|
|
197
|
+
}>;
|
|
198
|
+
/**
|
|
199
|
+
* What Next's rules for CSS decide that is not bundling: its PostCSS
|
|
200
|
+
* plugins and the class names of a CSS module, as Vite's options.
|
|
201
|
+
*/
|
|
202
|
+
loadCssOptions(): Promise<{
|
|
203
|
+
options: _$vite.CSSOptions; /** What is done otherwise than Next's build does it, to say when a run starts. */
|
|
204
|
+
differences: string[];
|
|
205
|
+
}>;
|
|
206
|
+
/**
|
|
207
|
+
* Where the browser asks for the files of the app: `/_next/`, after an
|
|
208
|
+
* asset prefix that is a path.
|
|
209
|
+
*/
|
|
210
|
+
assetPath: string; /** A file the loaders emitted for the browser, by the path the browser asks for. */
|
|
211
|
+
readEmittedFile(pathname: string): {
|
|
212
|
+
body: Buffer;
|
|
213
|
+
contentType: string;
|
|
214
|
+
} | undefined; /** The files the loaders have emitted so far, for a static build to write. */
|
|
215
|
+
emittedFiles(): {
|
|
216
|
+
pathname: string;
|
|
217
|
+
body: Buffer;
|
|
218
|
+
}[];
|
|
219
|
+
/**
|
|
220
|
+
* Answers a request for `/_next/image` with Next's image optimizer, as
|
|
221
|
+
* `next start` does, and resolves with whether it was one. `serveFile`
|
|
222
|
+
* answers the request for an image of the app.
|
|
223
|
+
*/
|
|
224
|
+
optimizeImage(request: IncomingMessage, response: ServerResponse, serveFile: ServeFile): Promise<boolean>; /** The module that Next's build makes of `next/root-params`, for the app. */
|
|
225
|
+
loadRootParams(): Promise<string>;
|
|
226
|
+
};
|
|
227
|
+
/** A file of a segment of a page route: see `loadRouteEntry()`. */
|
|
228
|
+
type RouteSegment = {
|
|
229
|
+
/** The file, by its absolute path, which the entry imports. */file: string;
|
|
230
|
+
/**
|
|
231
|
+
* What Next looks up the stylesheets of the segment by: the name the loader
|
|
232
|
+
* tree has for the file, without its extension. The name is the path from
|
|
233
|
+
* the root of the project, the same on every machine and with a dev server
|
|
234
|
+
* or a build: see `nameInLoaderTree()` in project/entries.ts.
|
|
235
|
+
*/
|
|
236
|
+
stylesheetsKey: string;
|
|
237
|
+
};
|
|
238
|
+
/**
|
|
239
|
+
* What Next's compiler makes of a module. `refused` where it stops at the
|
|
240
|
+
* module, as `next build` does, like a client hook in a Server Component:
|
|
241
|
+
* then the code throws Next's error.
|
|
242
|
+
*/
|
|
243
|
+
type Compiled = {
|
|
244
|
+
code: string;
|
|
245
|
+
map?: string;
|
|
246
|
+
refused?: true;
|
|
247
|
+
};
|
|
248
|
+
/** Answers a request the way the server does: what Next calls for an image of the app. */
|
|
249
|
+
type ServeFile = (request: IncomingMessage, response: ServerResponse) => Promise<void>;
|
|
250
|
+
type NextProjectOptions = {
|
|
251
|
+
/** The code that Next's runtime and React run: see build.ts. */build?: NextBuild;
|
|
252
|
+
/**
|
|
253
|
+
* For a static build, which has no server next to the browser: what the server
|
|
254
|
+
* outside the browser does, the app does without. That is Next's image
|
|
255
|
+
* optimizer, so `next/image` asks for the image itself.
|
|
256
|
+
*/
|
|
257
|
+
static?: boolean;
|
|
258
|
+
};
|
|
259
|
+
declare function loadNextProject(root: string, projectRequire?: NodeJS.Require, {
|
|
260
|
+
build,
|
|
261
|
+
static: isStatic
|
|
262
|
+
}?: NextProjectOptions): Promise<NextProject>;
|
|
263
|
+
//#endregion
|
|
264
|
+
export { Compiled, ComponentRoute, NextLayer, NextProject, NextProjectOptions, NextRoute, NextRouting, RouteSegment, ServeFile, loadNextProject };
|
package/dist/project.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { openNextProject } from "./project/context.js";
|
|
2
|
+
import { routeEntries } from "./project/entries.js";
|
|
3
|
+
import { layerTables } from "./project/layers.js";
|
|
4
|
+
import { createLoaders } from "./project/loaders.js";
|
|
5
|
+
import { createMetadataLoaders } from "./project/metadata.js";
|
|
6
|
+
import { discoverAppRoutes } from "./project/routes.js";
|
|
7
|
+
import { buildRouting, findMiddleware } from "./project/routing.js";
|
|
8
|
+
import { checkRuntime } from "./compat/checks.js";
|
|
9
|
+
import { createCompiler } from "./project/transform.js";
|
|
10
|
+
import { createWebpackRules } from "./project/webpack.js";
|
|
11
|
+
import { createRequire } from "node:module";
|
|
12
|
+
import path from "node:path";
|
|
13
|
+
import { fileURLToPath } from "node:url";
|
|
14
|
+
//#region src/project.ts
|
|
15
|
+
const adapterPath = fileURLToPath(new URL(`./adapter${path.extname(import.meta.url)}`, import.meta.url));
|
|
16
|
+
const envWorker = fileURLToPath(new URL(`./project/env-worker${path.extname(import.meta.url)}`, import.meta.url));
|
|
17
|
+
async function loadNextProject(root, projectRequire = createRequire(path.join(root, "package.json")), { build = "development", static: isStatic = false } = {}) {
|
|
18
|
+
const context = await openNextProject(root, projectRequire, {
|
|
19
|
+
static: isStatic,
|
|
20
|
+
envWorker
|
|
21
|
+
});
|
|
22
|
+
const app = await discoverAppRoutes(context);
|
|
23
|
+
const middleware = await findMiddleware(context);
|
|
24
|
+
const { routing, routesManifest, unmatchedRoutes, pageOf } = await buildRouting(context, app, middleware, adapterPath);
|
|
25
|
+
const { builtinBoundaries, newExports } = checkRuntime(context);
|
|
26
|
+
const layers = await layerTables(context, build);
|
|
27
|
+
const compiler = await createCompiler(context);
|
|
28
|
+
const { runLoader, ...loaders } = createLoaders(context, build);
|
|
29
|
+
return {
|
|
30
|
+
root,
|
|
31
|
+
appDir: context.appDir,
|
|
32
|
+
nextDir: context.nextDir,
|
|
33
|
+
version: context.version,
|
|
34
|
+
routes: app.routes,
|
|
35
|
+
edgeRouteFiles: app.edgeRouteFiles,
|
|
36
|
+
unmatchedRoutes,
|
|
37
|
+
newExports,
|
|
38
|
+
middlewareFile: middleware.middlewareFile,
|
|
39
|
+
routing,
|
|
40
|
+
pageOf,
|
|
41
|
+
routesManifest,
|
|
42
|
+
preview: context.previewProps,
|
|
43
|
+
env: context.env,
|
|
44
|
+
loadEnv: context.loadEnv,
|
|
45
|
+
config: JSON.parse(JSON.stringify({
|
|
46
|
+
...context.config,
|
|
47
|
+
env: Object.fromEntries(Object.keys(context.config.env).map((name) => [name, context.env.values[name]]))
|
|
48
|
+
})),
|
|
49
|
+
...layers,
|
|
50
|
+
...routeEntries(context, app, middleware, builtinBoundaries, runLoader),
|
|
51
|
+
...compiler,
|
|
52
|
+
...loaders,
|
|
53
|
+
...createWebpackRules(context, runLoader),
|
|
54
|
+
...createMetadataLoaders(context, runLoader)
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
export { loadNextProject };
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { Stylesheets } from "./styles-shared.js";
|
|
2
|
+
import { SpeedFeatures } from "./mode.js";
|
|
3
|
+
import { SequentialAsyncLocalStorage } from "@kasperpeulen/vitest-plugin-rsc/internal/async-local-storage";
|
|
4
|
+
|
|
5
|
+
//#region src/registry.d.ts
|
|
6
|
+
type ServerRequest = {
|
|
7
|
+
url: string;
|
|
8
|
+
method: string;
|
|
9
|
+
headers: Headers;
|
|
10
|
+
body?: ReadableStream<Uint8Array> | Uint8Array | null;
|
|
11
|
+
signal?: AbortSignal;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* The request handler Next's build makes for a route, for Node.js: it takes
|
|
15
|
+
* an `http.IncomingMessage` and writes to an `http.ServerResponse`.
|
|
16
|
+
*/
|
|
17
|
+
type RequestHandler = (req: unknown, res: unknown, context: {
|
|
18
|
+
waitUntil?: (promise: Promise<unknown>) => void;
|
|
19
|
+
requestMeta?: object;
|
|
20
|
+
}) => Promise<unknown>;
|
|
21
|
+
/**
|
|
22
|
+
* The request handler Next's build makes for the middleware of an app, its
|
|
23
|
+
* `proxy.ts`: it takes a `Request` and answers with a `Response`, on Node.js
|
|
24
|
+
* too.
|
|
25
|
+
*/
|
|
26
|
+
type MiddlewareHandler = (request: ServerRequest, context: {
|
|
27
|
+
waitUntil?: (promise: Promise<unknown>) => void;
|
|
28
|
+
signal?: AbortSignal;
|
|
29
|
+
}) => Promise<Response>;
|
|
30
|
+
type AnyFunction = (...args: any[]) => any;
|
|
31
|
+
/**
|
|
32
|
+
* Which pathnames of a route `next build` prerenders, from its
|
|
33
|
+
* `generateStaticParams`, before it renders one: see prerender-verdict.ts.
|
|
34
|
+
*/
|
|
35
|
+
type PrerenderVerdict = {
|
|
36
|
+
/** The pathnames the build prerenders. */pathnames: string[];
|
|
37
|
+
/**
|
|
38
|
+
* For a route with params: what Next does for a pathname not among them,
|
|
39
|
+
* the `fallback` of its prerender manifest. `null` prerenders it at its
|
|
40
|
+
* first request, `false` answers that it is not found.
|
|
41
|
+
*/
|
|
42
|
+
fallback?: null | false;
|
|
43
|
+
};
|
|
44
|
+
/** See `NextRegistry.opened`. */
|
|
45
|
+
type Opened = {
|
|
46
|
+
pathname: string; /** Whether the server in front of the app takes the request: proxy.ts and `next.config`. */
|
|
47
|
+
proxy: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* With `files`: the files of the host that render the node, `hostFiles` of
|
|
50
|
+
* `renderServer()`. With `version`: which render of it the server sends,
|
|
51
|
+
* which `rerender()` counts up, and the page says it has committed. The
|
|
52
|
+
* server reads both as it renders, after `rerender()` has set them.
|
|
53
|
+
*/
|
|
54
|
+
node?: {
|
|
55
|
+
ui: unknown;
|
|
56
|
+
layouts: boolean;
|
|
57
|
+
files: string[];
|
|
58
|
+
version?: number;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Whether Next renders the page a Server Action redirects to, into the
|
|
62
|
+
* response of the action, as Next's router shows that page next. Not for
|
|
63
|
+
* `runInServerAction()`, which shows no page. Read from `openedByRequest`.
|
|
64
|
+
*/
|
|
65
|
+
rendersRedirect?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* `false`: Next renders no HTML of the page, see `RenderServerOptions.ssr`.
|
|
68
|
+
* Read from `openedByRequest`.
|
|
69
|
+
*/
|
|
70
|
+
ssr?: boolean;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* When a request of the page reached the server, started, was answered and
|
|
74
|
+
* was done, by `performance.now()`: see `NextRegistry.requestTimings`.
|
|
75
|
+
*/
|
|
76
|
+
type RequestTiming = {
|
|
77
|
+
method: string;
|
|
78
|
+
url: string;
|
|
79
|
+
/**
|
|
80
|
+
* Whether it is a Server Action, a request of Next's router for Flight, or
|
|
81
|
+
* a page load: of a document, or of a page of the kept app by its Flight
|
|
82
|
+
* payload, with `flightLoads`.
|
|
83
|
+
*/
|
|
84
|
+
kind: "action" | "flight" | "page";
|
|
85
|
+
queued: number;
|
|
86
|
+
started?: number;
|
|
87
|
+
answered?: number;
|
|
88
|
+
finished?: number;
|
|
89
|
+
};
|
|
90
|
+
type NextRegistry = {
|
|
91
|
+
/** The speed features that are on, `mode` and the options of the features resolved: see speed-features.ts. */speedFeatures?: SpeedFeatures;
|
|
92
|
+
/**
|
|
93
|
+
* For a profile of a test run: set to an array, the server adds the timing
|
|
94
|
+
* of each request of the page to it, in the order they reached it.
|
|
95
|
+
*/
|
|
96
|
+
requestTimings?: RequestTiming[]; /** A `Request` and `Response` that keep the headers a browser drops. */
|
|
97
|
+
Request: typeof Request;
|
|
98
|
+
Response: typeof Response; /** The `Headers` of those. */
|
|
99
|
+
Headers: typeof Headers; /** The server's `fetch`: its network, which is not the browser's. */
|
|
100
|
+
fetch: typeof fetch; /** The network itself: no request of it is the app's, and Next caches none. */
|
|
101
|
+
network: typeof fetch; /** Node's, for Next's server: a task after the microtasks. Not globals. */
|
|
102
|
+
setImmediate(callback: (...args: any[]) => void, ...args: unknown[]): unknown;
|
|
103
|
+
clearImmediate(id: unknown): void; /** The `setTimeout` and `clearTimeout` of server code: see globals.ts. */
|
|
104
|
+
setTimeout(callback: unknown, delay?: number, ...args: unknown[]): unknown;
|
|
105
|
+
clearTimeout(id: unknown): void; /** Starts the scope of one request, see `enterAmbientScope`. Returns its end. */
|
|
106
|
+
enterRequestScope(): () => void; /** What an async function of server code is compiled to call: server-code.ts. */
|
|
107
|
+
asyncFunctionHooks: object; /** The server's `queueMicrotask`: the callback has the stores of the code that queued it. */
|
|
108
|
+
queueMicrotask(callback: () => void): void; /** Does a step of a render of React's Flight server, with the stores of its first step. */
|
|
109
|
+
performWork(request: object, performWork: (request: object) => void): void; /** Changes when the caches are reset. A part of every key of a cache, see cache.ts. */
|
|
110
|
+
cacheGeneration(): number; /** The rsc layer's Flight codec, behind the signatures Next calls. */
|
|
111
|
+
flightServer: Record<string, AnyFunction>;
|
|
112
|
+
flightStatic: Record<string, AnyFunction>;
|
|
113
|
+
flightClient: Record<string, AnyFunction>; /** Loads the rsc-layer module of a route, into `appPages`. */
|
|
114
|
+
loadAppPage(page: string): Promise<unknown>;
|
|
115
|
+
appPages: Record<string, unknown>;
|
|
116
|
+
/**
|
|
117
|
+
* Asks the plugin for the stylesheets of a page route, by the name of its
|
|
118
|
+
* modules, and for the route of a node with `files`, the files of the host
|
|
119
|
+
* that render the node, `hostFiles` of `renderServer()`: see styles.ts.
|
|
120
|
+
* The dev server answers; a static build reads them from a file of its
|
|
121
|
+
* own (rsc.ts).
|
|
122
|
+
*/
|
|
123
|
+
loadStylesheets(entry: string, inline: boolean, files: string[]): Promise<Stylesheets>;
|
|
124
|
+
/**
|
|
125
|
+
* Has the browser start the files of a page route at once, for a page load
|
|
126
|
+
* that the plugin opens, by what `loadStylesheets()` takes: its modules and
|
|
127
|
+
* its stylesheets (rsc.ts). They go with the page (document.ts), and none
|
|
128
|
+
* come once `signal`, the request's, has aborted: the page is gone. Only a
|
|
129
|
+
* static build has them: a dev server serves a module where it is asked for.
|
|
130
|
+
* Resolves once they are in the document, before the route loads: Vite
|
|
131
|
+
* preloads a module that is imported, for good, unless a link has it.
|
|
132
|
+
*/
|
|
133
|
+
preloadRoute(entry: string, files: string[], signal: AbortSignal | undefined): Promise<void>;
|
|
134
|
+
/**
|
|
135
|
+
* Internal, not an API: the Vitest default behind `hostFiles` of
|
|
136
|
+
* `renderServer()`, the files of the host that render a node when it is
|
|
137
|
+
* not passed. The setup files and the test file, which the plugin's setup
|
|
138
|
+
* file sets before every test file (setup.ts). Another host passes
|
|
139
|
+
* `hostFiles`; without it a node has no stylesheets of the host's files.
|
|
140
|
+
*/
|
|
141
|
+
nodeFiles?(): string[];
|
|
142
|
+
/**
|
|
143
|
+
* Internal, not an API: tells the dev server that the test file of the
|
|
144
|
+
* tab opened a route, by the name of its modules, which it compiles ahead
|
|
145
|
+
* when the file runs again (routes-ahead.ts). Set by the plugin's setup
|
|
146
|
+
* file (setup.ts): another host has no test files.
|
|
147
|
+
*/
|
|
148
|
+
routeOpened?(entry: string): void; /** The directory of the build on the server's disk, of this generation: see cache.ts. */
|
|
149
|
+
buildDir(): string;
|
|
150
|
+
/**
|
|
151
|
+
* The directory of the server's own files, which the page's host has:
|
|
152
|
+
* `""` in a browser, a temporary directory in Node.js (page-host.ts).
|
|
153
|
+
*/
|
|
154
|
+
serverDir(): string;
|
|
155
|
+
/**
|
|
156
|
+
* Next's build's verdict on a route of the app, by its page name and its
|
|
157
|
+
* pathname, in the rsc layer: nothing for a route it renders at every
|
|
158
|
+
* request.
|
|
159
|
+
*/
|
|
160
|
+
prerenderVerdict(route: {
|
|
161
|
+
kind: "page" | "route";
|
|
162
|
+
page: string;
|
|
163
|
+
pathname: string;
|
|
164
|
+
}): Promise<PrerenderVerdict | undefined>; /** Whether an error is the one Next's handler of a route throws for a pathname it does not serve. */
|
|
165
|
+
isNoFallbackError(error: unknown): boolean; /** Loads the request handler of a route handler, which is in the rsc layer. */
|
|
166
|
+
loadRouteHandler(page: string): Promise<RequestHandler>; /** Loads the request handler of the middleware of the app, which is in the rsc layer. */
|
|
167
|
+
loadMiddleware(): Promise<MiddlewareHandler>; /** Whether an id names a Server Action of the app, in the rsc layer. */
|
|
168
|
+
hasServerAction(id: string): Promise<boolean>;
|
|
169
|
+
/**
|
|
170
|
+
* The id of the plugin's own Server Action, which every app here has: the
|
|
171
|
+
* one of `runInServerAction()`, in the rsc layer.
|
|
172
|
+
*/
|
|
173
|
+
ownServerAction?: Promise<string | undefined>; /** What the Server Action of `runInServerAction()` runs, by the number it is called with. */
|
|
174
|
+
serverActions: Map<number, () => Promise<void>>;
|
|
175
|
+
/**
|
|
176
|
+
* What a request opened, for as long as it is handled: what it brings for
|
|
177
|
+
* itself, like the route of a node of `runInServerAction()`, or else
|
|
178
|
+
* `opened` at its URL (`openedAt()`). The page of the route of a node reads
|
|
179
|
+
* it, and else `opened`. The server's `fetch` reads its `rendersRedirect`,
|
|
180
|
+
* and Next's renderer its `ssr`.
|
|
181
|
+
*/
|
|
182
|
+
openedByRequest: SequentialAsyncLocalStorage<Opened | undefined>;
|
|
183
|
+
/**
|
|
184
|
+
* What `renderServer()` opened, for as long as it is open: the pathname of
|
|
185
|
+
* its URL, and how the server takes a request to that pathname. Without
|
|
186
|
+
* `proxy` it goes straight to the app's route for it. With a `node`, that
|
|
187
|
+
* pathname is the node's route, or with `layouts` the app's route with the
|
|
188
|
+
* node as its page.
|
|
189
|
+
*/
|
|
190
|
+
opened: Opened | undefined; /** Loads a Client Component by its module id, in the ssr layer. */
|
|
191
|
+
loadSsrModule(id: string): Promise<unknown>;
|
|
192
|
+
/**
|
|
193
|
+
* `__webpack_require__` for the Flight client of the browser layer: loads a
|
|
194
|
+
* Client Component by its module id, in that layer. One for every page.
|
|
195
|
+
*/
|
|
196
|
+
browserRequire(id: string): Promise<unknown>;
|
|
197
|
+
/**
|
|
198
|
+
* Loads a Client Component by its module id, in the browser layer: the
|
|
199
|
+
* loader of the page that started last, until it is left.
|
|
200
|
+
*/
|
|
201
|
+
loadBrowserModule?(id: string): Promise<unknown>;
|
|
202
|
+
/**
|
|
203
|
+
* Set while the browser layer gives the router of the kept app of `keepApp`
|
|
204
|
+
* the state of its next page, which Next's patched router reads: see
|
|
205
|
+
* `nextPatches` in compat/patches.ts.
|
|
206
|
+
*/
|
|
207
|
+
replacingRouter?: boolean;
|
|
208
|
+
/**
|
|
209
|
+
* Next's route module for a page, loaded in the ssr layer, for the rsc
|
|
210
|
+
* layer: its class, its renderer, and the contexts of its
|
|
211
|
+
* `*.shared-runtime` modules.
|
|
212
|
+
*/
|
|
213
|
+
ssr: {
|
|
214
|
+
AppPageRouteModule: new (options: unknown) => unknown;
|
|
215
|
+
vendored: Record<string, unknown>;
|
|
216
|
+
renderToHTMLOrFlight: AnyFunction;
|
|
217
|
+
prerenderToHTMLOrFlight: AnyFunction;
|
|
218
|
+
}; /** For Next's Node.js server: what stands in for the files of a build. */
|
|
219
|
+
node: Record<string, AnyFunction>;
|
|
220
|
+
};
|
|
221
|
+
declare const registry: NextRegistry;
|
|
222
|
+
/**
|
|
223
|
+
* What the browser layer loads with no page to load it in: nothing, ever, as
|
|
224
|
+
* the closed runner of a page that was left.
|
|
225
|
+
*/
|
|
226
|
+
declare const loadsNothing: () => Promise<never>;
|
|
227
|
+
/**
|
|
228
|
+
* What `renderServer()` opened, at a URL that belongs to it: one with its
|
|
229
|
+
* pathname. That is the document, and what the page sends there while it is
|
|
230
|
+
* open: a Server Action, `router.refresh()`, a change of search params. A URL
|
|
231
|
+
* with another pathname is the app's, as always. The server and the browser
|
|
232
|
+
* layer both ask, so they agree on it.
|
|
233
|
+
*/
|
|
234
|
+
declare function openedAt(url: URL): Opened | undefined;
|
|
235
|
+
/**
|
|
236
|
+
* Next's build gives the module of a Server Action an id. Here the id of the
|
|
237
|
+
* action already says where it is, so the module id is the action id, marked.
|
|
238
|
+
*/
|
|
239
|
+
declare const actionModulePrefix = "action:";
|
|
240
|
+
//#endregion
|
|
241
|
+
export { MiddlewareHandler, NextRegistry, Opened, PrerenderVerdict, RequestHandler, RequestTiming, ServerRequest, actionModulePrefix, loadsNothing, openedAt, registry };
|
package/dist/registry.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { registryGlobal } from "./registry-global.js";
|
|
2
|
+
//#region src/registry.ts
|
|
3
|
+
const scope = globalThis;
|
|
4
|
+
const registry = scope[registryGlobal] ??= {
|
|
5
|
+
appPages: {},
|
|
6
|
+
serverActions: /* @__PURE__ */ new Map()
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* What the browser layer loads with no page to load it in: nothing, ever, as
|
|
10
|
+
* the closed runner of a page that was left.
|
|
11
|
+
*/
|
|
12
|
+
const loadsNothing = () => new Promise(() => {});
|
|
13
|
+
/**
|
|
14
|
+
* What `renderServer()` opened, at a URL that belongs to it: one with its
|
|
15
|
+
* pathname. That is the document, and what the page sends there while it is
|
|
16
|
+
* open: a Server Action, `router.refresh()`, a change of search params. A URL
|
|
17
|
+
* with another pathname is the app's, as always. The server and the browser
|
|
18
|
+
* layer both ask, so they agree on it.
|
|
19
|
+
*/
|
|
20
|
+
function openedAt(url) {
|
|
21
|
+
const { opened } = registry;
|
|
22
|
+
return opened?.pathname === url.pathname ? opened : void 0;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Next's build gives the module of a Server Action an id. Here the id of the
|
|
26
|
+
* action already says where it is, so the module id is the action id, marked.
|
|
27
|
+
*/
|
|
28
|
+
const actionModulePrefix = "action:";
|
|
29
|
+
//#endregion
|
|
30
|
+
export { actionModulePrefix, loadsNothing, openedAt, registry };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Rolldown } from "vite";
|
|
2
|
+
|
|
3
|
+
//#region src/route-chunks.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* For each route, by the ids of the modules it loads first, its entry and
|
|
6
|
+
* what its loader tree imports: the files of their chunks, the entry's first,
|
|
7
|
+
* and of every chunk those import, but none that `lists` and what they import
|
|
8
|
+
* are in, which the page has before it loads a route. Not the chunk of a
|
|
9
|
+
* module that one of them imports with `import()`: that is the app's to load.
|
|
10
|
+
*/
|
|
11
|
+
declare function routeChunksOf(bundle: Rolldown.OutputBundle, lists: string[], routes: Iterable<[route: string, ids: string[]]>): Map<string, string[]>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { routeChunksOf };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//#region src/route-chunks.ts
|
|
2
|
+
/**
|
|
3
|
+
* For each route, by the ids of the modules it loads first, its entry and
|
|
4
|
+
* what its loader tree imports: the files of their chunks, the entry's first,
|
|
5
|
+
* and of every chunk those import, but none that `lists` and what they import
|
|
6
|
+
* are in, which the page has before it loads a route. Not the chunk of a
|
|
7
|
+
* module that one of them imports with `import()`: that is the app's to load.
|
|
8
|
+
*/
|
|
9
|
+
function routeChunksOf(bundle, lists, routes) {
|
|
10
|
+
const chunkOf = /* @__PURE__ */ new Map();
|
|
11
|
+
for (const output of Object.values(bundle)) {
|
|
12
|
+
if (output.type !== "chunk") continue;
|
|
13
|
+
for (const id of output.moduleIds) chunkOf.set(id, output);
|
|
14
|
+
}
|
|
15
|
+
const chunksOf = (ids, had = /* @__PURE__ */ new Set()) => {
|
|
16
|
+
const loaded = /* @__PURE__ */ new Set();
|
|
17
|
+
const visit = (chunk) => {
|
|
18
|
+
if (!chunk || had.has(chunk.fileName) || loaded.has(chunk.fileName)) return;
|
|
19
|
+
loaded.add(chunk.fileName);
|
|
20
|
+
for (const fileName of chunk.imports) {
|
|
21
|
+
const imported = bundle[fileName];
|
|
22
|
+
if (imported?.type === "chunk") visit(imported);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
ids.forEach((id) => visit(chunkOf.get(id)));
|
|
26
|
+
return loaded;
|
|
27
|
+
};
|
|
28
|
+
const had = chunksOf(lists);
|
|
29
|
+
return new Map(Array.from(routes, ([route, ids]) => [route, [...chunksOf(ids, had)]]));
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { routeChunksOf };
|