@absolutejs/absolute 0.20.0-beta.179 → 0.20.0-beta.180
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/CHANGELOG.md +23 -0
- package/changelog.json +45 -0
- package/dist/angular/browser.js +2 -2
- package/dist/angular/browser.js.map +3 -3
- package/dist/angular/components/core/streamingSlotRegistrar.js +1 -1
- package/dist/angular/components/core/streamingSlotRegistry.js +2 -2
- package/dist/angular/index.js +21 -6
- package/dist/angular/index.js.map +6 -6
- package/dist/angular/server.js +21 -6
- package/dist/angular/server.js.map +6 -6
- package/dist/build.js +5357 -4945
- package/dist/build.js.map +27 -24
- package/dist/cli/build-fntmf42w.js +495 -0
- package/dist/cli/{buildDepVendor-qvsh6dsj.js → buildDepVendor-qnwfct22.js} +5 -3
- package/dist/cli/buildReactServerComponents-fq6mw10d.js +13 -0
- package/dist/cli/{compile-p5yv6ecp.js → compile-54rb8szn.js} +94 -125
- package/dist/cli/config/server.js +10 -5
- package/dist/cli/{dev-2hbcsvkp.js → dev-6s6g5tnk.js} +13 -14
- package/dist/cli/{expoProject-1qtw97js.js → expoProject-acgfaj3f.js} +2 -1
- package/dist/cli/generatedDir-239r7csr.js +9 -0
- package/dist/cli/{index-cksezef8.js → index-0gd30trc.js} +105 -851
- package/dist/cli/index-2wvysvjc.js +40 -0
- package/dist/cli/index-42xjh6gg.js +282 -0
- package/dist/cli/{index-qw98g1p6.js → index-47e8fwha.js} +4 -1
- package/dist/cli/index-65kqn88a.js +8 -0
- package/dist/cli/{index-2bxfhs32.js → index-6f448d7m.js} +0 -26
- package/dist/cli/index-972xxwgj.js +16 -0
- package/dist/cli/index-aqe25w4h.js +39 -0
- package/dist/cli/index-assqancr.js +51 -0
- package/dist/cli/{index-2shf4aya.js → index-c8rcfe5a.js} +4 -6
- package/dist/cli/index-cba1cemz.js +8 -0
- package/dist/cli/{index-3ff5ztt3.js → index-djkrb7pc.js} +1 -7
- package/dist/cli/index-dkfwkpc8.js +138 -0
- package/dist/cli/{index-92g14j47.js → index-dw44xa4x.js} +2 -1
- package/dist/cli/index-evsnq0n2.js +17 -0
- package/dist/cli/index-fxwf3n2v.js +224 -0
- package/dist/cli/{index-zyd80s3h.js → index-js2hksgv.js} +21 -295
- package/dist/cli/{index-bp60baze.js → index-jyap0bhv.js} +1 -1
- package/dist/cli/{index-9dzdbbfc.js → index-kx2d067c.js} +8 -6
- package/dist/cli/index-pb31zan6.js +9 -0
- package/dist/cli/index-sq0478b0.js +281 -0
- package/dist/cli/index-va274tsf.js +7 -0
- package/dist/cli/{index-yd672jyq.js → index-w6xsk8cv.js} +4 -1
- package/dist/cli/index-w79snsxv.js +461 -0
- package/dist/cli/index-x1vvn549.js +835 -0
- package/dist/cli/index-xf9sfr8a.js +243 -0
- package/dist/cli/index-ycqdxy55.js +754 -0
- package/dist/cli/index-z74cqxz0.js +131 -0
- package/dist/cli/index.js +10 -9
- package/dist/cli/{islands-6zgb7501.js → islands-17tfx8jf.js} +6 -17
- package/dist/cli/{ls-0hfx323m.js → ls-0wr74w0b.js} +10 -58
- package/dist/cli/{mobile-93vaawcz.js → mobile-hpqpy61f.js} +11 -8
- package/dist/cli/{prerender-010z771p.js → prerender-w65xp6h8.js} +2 -1
- package/dist/cli/{rewriteImports-z6629aww.js → rewriteImports-np2d2kvc.js} +4 -11
- package/dist/cli/rewriteImportsPlugin-c6hcb3x6.js +12 -0
- package/dist/cli/{start-asxb79rc.js → start-mbn2zgs2.js} +6 -4
- package/dist/cli/staticAnalyzeSpaRoutes-2nev05m1.js +8 -0
- package/dist/cli/staticAnalyzeSpaRoutes-6vgzp0rs.js +8 -0
- package/dist/cli/staticAnalyzeSpaRoutes-f85q9dqk.js +8 -0
- package/dist/cli/staticAnalyzeSpaRoutes-yakmg22g.js +7 -0
- package/dist/cli/{typecheck-m2j4tkdk.js → typecheck-488txsfc.js} +92 -18
- package/dist/cli/vueCompiler-8bzdmf08.js +7 -0
- package/dist/client/chunks/{react-khr6ewhr.js → react-g8r290b8.js} +37 -2
- package/dist/client/chunks/react-g8r290b8.js.map +10 -0
- package/dist/client/chunks/vue-zcpmka32.js +85 -0
- package/dist/client/chunks/vue-zcpmka32.js.map +10 -0
- package/dist/client/index.js +58 -10
- package/dist/client/index.js.map +4 -4
- package/dist/dev/client/handlers/vue.ts +116 -0
- package/dist/index.js +2472 -2058
- package/dist/index.js.map +26 -23
- package/dist/islands/browser.js +2 -2
- package/dist/islands/browser.js.map +3 -3
- package/dist/islands/index.js +2 -2
- package/dist/islands/index.js.map +3 -3
- package/dist/react/browser.js +2 -2
- package/dist/react/browser.js.map +3 -3
- package/dist/react/index.js +42 -11
- package/dist/react/index.js.map +10 -10
- package/dist/react/server.js +42 -11
- package/dist/react/server.js.map +10 -10
- package/dist/src/angular/ssrRender.d.ts +2 -2
- package/dist/src/angular/staticAnalyzeSpaRoutes.d.ts +6 -1
- package/dist/src/build/generateManifest.d.ts +15 -0
- package/dist/src/build/manifestKeys.d.ts +22 -0
- package/dist/src/cli/add/dependencies.d.ts +1 -1
- package/dist/src/cli/scripts/typecheck.d.ts +11 -0
- package/dist/src/client/hydrators/react.d.ts +10 -0
- package/dist/src/client/hydrators/vue.d.ts +13 -0
- package/dist/src/client/islandRuntime.d.ts +1 -1
- package/dist/src/core/islandManifest.d.ts +4 -0
- package/dist/src/core/islandPageContext.d.ts +8 -2
- package/dist/src/core/lookup.d.ts +16 -1
- package/dist/src/dev/importCost/instrument.d.ts +1 -1
- package/dist/src/dev/manifestKeysRefresher.d.ts +6 -0
- package/dist/src/dev/spaRouteRefresh.d.ts +13 -0
- package/dist/src/mobile/androidConformance.d.ts +1 -1
- package/dist/src/react/staticAnalyzeSpaRoutes.d.ts +6 -1
- package/dist/src/svelte/staticAnalyzeSpaRoutes.d.ts +1 -0
- package/dist/src/utils/logger.d.ts +5 -0
- package/dist/src/utils/spaRouteManifest.d.ts +1 -0
- package/dist/src/vue/components/Image.d.ts +4 -4
- package/dist/src/vue/components/StreamSlot.d.ts +1 -1
- package/dist/src/vue/components/SuspenseSlot.d.ts +2 -2
- package/dist/src/vue/staticAnalyzeSpaRoutes.d.ts +4 -0
- package/dist/svelte/browser.js +2 -2
- package/dist/svelte/browser.js.map +3 -3
- package/dist/svelte/index.js +25 -9
- package/dist/svelte/index.js.map +8 -8
- package/dist/svelte/server.js +25 -9
- package/dist/svelte/server.js.map +8 -8
- package/dist/types/globals.d.ts +4 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/island.d.ts +1 -1
- package/dist/types/manifest.d.ts +25 -0
- package/dist/vue/browser.js +2 -2
- package/dist/vue/browser.js.map +3 -3
- package/dist/vue/index.js +21 -6
- package/dist/vue/index.js.map +6 -6
- package/dist/vue/server.js +21 -6
- package/dist/vue/server.js.map +6 -6
- package/package.json +1 -1
- package/dist/client/chunks/react-khr6ewhr.js.map +0 -10
- package/dist/client/chunks/vue-db6ppn1f.js +0 -32
- package/dist/client/chunks/vue-db6ppn1f.js.map +0 -10
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
logWarn
|
|
4
|
+
} from "./index-aqe25w4h.js";
|
|
5
|
+
import {
|
|
6
|
+
REACT_SERVER_CLIENT_MANIFEST_KEY,
|
|
7
|
+
REACT_SERVER_PAGE_MANIFEST_SUFFIX,
|
|
8
|
+
REACT_SERVER_PAYLOAD_GLOBAL,
|
|
9
|
+
REACT_SERVER_RENDERER_MANIFEST_KEY,
|
|
10
|
+
REACT_SERVER_RUNTIME_FILE
|
|
11
|
+
} from "./index-x1vvn549.js";
|
|
12
|
+
import {
|
|
13
|
+
toPascal
|
|
14
|
+
} from "./index-dw44xa4x.js";
|
|
15
|
+
import {
|
|
16
|
+
normalizePath
|
|
17
|
+
} from "./index-47e8fwha.js";
|
|
18
|
+
|
|
19
|
+
// src/build/buildReactServerComponents.ts
|
|
20
|
+
import { createHash } from "crypto";
|
|
21
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
22
|
+
import { basename, dirname, extname, join, relative as relative2, resolve as resolve2 } from "path";
|
|
23
|
+
var {
|
|
24
|
+
build: bunBuild,
|
|
25
|
+
Glob,
|
|
26
|
+
Transpiler
|
|
27
|
+
} = globalThis.Bun;
|
|
28
|
+
|
|
29
|
+
// src/utils/validateSafePath.ts
|
|
30
|
+
import { resolve, relative } from "path";
|
|
31
|
+
var validateSafePath = (targetPath, baseDirectory) => {
|
|
32
|
+
const absoluteBase = resolve(baseDirectory);
|
|
33
|
+
const absoluteTarget = resolve(baseDirectory, targetPath);
|
|
34
|
+
const relativePath = normalizePath(relative(absoluteBase, absoluteTarget));
|
|
35
|
+
if (relativePath.startsWith("../") || relativePath === "..") {
|
|
36
|
+
throw new Error(`Unsafe path: ${targetPath}`);
|
|
37
|
+
}
|
|
38
|
+
return absoluteTarget;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// src/build/buildReactServerComponents.ts
|
|
42
|
+
var PAGE_PATTERN = "*.{tsx,jsx,ts,js}";
|
|
43
|
+
var SOURCE_FILTER = /\.[cm]?[jt]sx?$/;
|
|
44
|
+
var USE_CLIENT_PATTERN = /^(?:\s|\/\/[^\n]*\n|\/\*[\s\S]*?\*\/)*(['"])use client\1/;
|
|
45
|
+
var MANIFEST_NAMESPACE = "absolute-react-server";
|
|
46
|
+
var MANIFEST_SPECIFIER = "absolute-react-server:client-manifest";
|
|
47
|
+
var MODULE_ID_LENGTH = 16;
|
|
48
|
+
var loaderFor = (path) => {
|
|
49
|
+
const extension = extname(path);
|
|
50
|
+
if (extension === ".tsx")
|
|
51
|
+
return "tsx";
|
|
52
|
+
if (extension === ".ts" || extension === ".mts" || extension === ".cts")
|
|
53
|
+
return "ts";
|
|
54
|
+
if (extension === ".jsx")
|
|
55
|
+
return "jsx";
|
|
56
|
+
return "js";
|
|
57
|
+
};
|
|
58
|
+
var clientModuleId = (projectRoot, path) => createHash("sha256").update(relative2(projectRoot, path).replace(/\\/g, "/")).digest("hex").slice(0, MODULE_ID_LENGTH);
|
|
59
|
+
var isClientModuleSource = (source) => USE_CLIENT_PATTERN.test(source);
|
|
60
|
+
var scanExportNames = (path, source) => {
|
|
61
|
+
const transpiler = new Transpiler({ loader: loaderFor(path) });
|
|
62
|
+
return transpiler.scan(source).exports;
|
|
63
|
+
};
|
|
64
|
+
var clientReferenceSource = (module, flightServer) => {
|
|
65
|
+
const lines = [
|
|
66
|
+
`import { registerClientReference } from ${JSON.stringify(flightServer)};`,
|
|
67
|
+
`import { clientManifest } from ${JSON.stringify(MANIFEST_SPECIFIER)};`,
|
|
68
|
+
`const id = ${JSON.stringify(module.id)};`,
|
|
69
|
+
`clientManifest[id] = { chunks: [id, id], id, name: '' };`,
|
|
70
|
+
`const reference = (name) => registerClientReference(() => { throw new Error('Client component ' + name + ' cannot be called on the server.'); }, id, name);`
|
|
71
|
+
];
|
|
72
|
+
for (const name of module.exports) {
|
|
73
|
+
lines.push(name === "default" ? `export default reference('default');` : `export const ${name} = reference(${JSON.stringify(name)});`);
|
|
74
|
+
}
|
|
75
|
+
return `${lines.join(`
|
|
76
|
+
`)}
|
|
77
|
+
`;
|
|
78
|
+
};
|
|
79
|
+
var REACT_COMPONENTS_SPECIFIER = /^@absolutejs\/absolute\/react\/components$/;
|
|
80
|
+
var resolveReactComponentsServerEntry = (importer) => {
|
|
81
|
+
try {
|
|
82
|
+
const regularEntry = Bun.resolveSync("@absolutejs/absolute/react/components", dirname(importer));
|
|
83
|
+
const serverEntry = join(dirname(regularEntry), "server", "index.js");
|
|
84
|
+
return existsSync(serverEntry) ? serverEntry : undefined;
|
|
85
|
+
} catch {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
var createClientReferencePlugin = (projectRoot, clientModules) => {
|
|
90
|
+
const flightServer = Bun.resolveSync("react-server-dom-webpack/server.edge", projectRoot);
|
|
91
|
+
const plugin = {
|
|
92
|
+
name: "absolute-react-server-client-references",
|
|
93
|
+
setup(builder) {
|
|
94
|
+
builder.onResolve({ filter: /^absolute-react-server:/ }, (args) => ({
|
|
95
|
+
namespace: MANIFEST_NAMESPACE,
|
|
96
|
+
path: args.path
|
|
97
|
+
}));
|
|
98
|
+
builder.onLoad({ filter: /.*/, namespace: MANIFEST_NAMESPACE }, () => ({
|
|
99
|
+
contents: `export const clientManifest = {};
|
|
100
|
+
`,
|
|
101
|
+
loader: "js"
|
|
102
|
+
}));
|
|
103
|
+
builder.onResolve({ filter: REACT_COMPONENTS_SPECIFIER }, (args) => {
|
|
104
|
+
const path = resolveReactComponentsServerEntry(args.importer);
|
|
105
|
+
return path ? { path } : undefined;
|
|
106
|
+
});
|
|
107
|
+
builder.onLoad({ filter: SOURCE_FILTER }, (args) => {
|
|
108
|
+
const source = readFileSync(args.path, "utf8");
|
|
109
|
+
const loader = loaderFor(args.path);
|
|
110
|
+
if (!isClientModuleSource(source)) {
|
|
111
|
+
return { contents: source, loader };
|
|
112
|
+
}
|
|
113
|
+
const module = {
|
|
114
|
+
exports: scanExportNames(args.path, source),
|
|
115
|
+
id: clientModuleId(projectRoot, args.path),
|
|
116
|
+
path: args.path
|
|
117
|
+
};
|
|
118
|
+
clientModules.set(module.id, module);
|
|
119
|
+
return {
|
|
120
|
+
contents: clientReferenceSource(module, flightServer),
|
|
121
|
+
loader: "js"
|
|
122
|
+
};
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
return plugin;
|
|
127
|
+
};
|
|
128
|
+
var ALS_SETUP_SOURCE = `import { AsyncLocalStorage } from 'node:async_hooks';
|
|
129
|
+
// The Flight server's edge build looks for a global AsyncLocalStorage to
|
|
130
|
+
// keep per-request state (cache(), hints) across awaits.
|
|
131
|
+
if (typeof globalThis.AsyncLocalStorage !== 'function') {
|
|
132
|
+
globalThis.AsyncLocalStorage = AsyncLocalStorage;
|
|
133
|
+
}
|
|
134
|
+
`;
|
|
135
|
+
var resolvePageExport = (pagePath, pascalName) => {
|
|
136
|
+
const exports = scanExportNames(pagePath, readFileSync(pagePath, "utf8"));
|
|
137
|
+
if (exports.includes(pascalName))
|
|
138
|
+
return pascalName;
|
|
139
|
+
if (exports.includes("default"))
|
|
140
|
+
return "default";
|
|
141
|
+
throw new Error(`React Server Components page ${pagePath} must export a component named ${pascalName} (or a default export).`);
|
|
142
|
+
};
|
|
143
|
+
var pageEntrySource = (pagePath, exportName) => `import '../asyncLocalStorage';
|
|
144
|
+
export { ${exportName} as Page } from ${JSON.stringify(pagePath)};
|
|
145
|
+
export { renderToReadableStream } from 'react-server-dom-webpack/server.edge';
|
|
146
|
+
export { createElement } from 'react';
|
|
147
|
+
export { clientManifest } from ${JSON.stringify(MANIFEST_SPECIFIER)};
|
|
148
|
+
// A development Flight server: the page handler moves its debug info to a
|
|
149
|
+
// separate stream that stays on the server.
|
|
150
|
+
export const developmentFlight = process.env.NODE_ENV !== 'production';
|
|
151
|
+
`;
|
|
152
|
+
var ssrEntrySource = (modules) => {
|
|
153
|
+
const imports = modules.map((module, index) => `import * as module${index} from ${JSON.stringify(module.path)};`);
|
|
154
|
+
const entries = modules.map((module, index) => ` ${JSON.stringify(module.id)}: module${index}`);
|
|
155
|
+
return `${imports.join(`
|
|
156
|
+
`)}
|
|
157
|
+
import { createFromReadableStream } from 'react-server-dom-webpack/client.edge';
|
|
158
|
+
import { renderToReadableStream } from 'react-dom/server';
|
|
159
|
+
import { createElement, use } from 'react';
|
|
160
|
+
|
|
161
|
+
const modules = {
|
|
162
|
+
${entries.join(`,
|
|
163
|
+
`)}
|
|
164
|
+
};
|
|
165
|
+
const registry = (globalThis.__absoluteReactServerModules ??= {});
|
|
166
|
+
Object.assign(registry, modules);
|
|
167
|
+
globalThis.__webpack_require__ = (id) => globalThis.__absoluteReactServerModules[id];
|
|
168
|
+
globalThis.__webpack_chunk_load__ = () => Promise.resolve();
|
|
169
|
+
|
|
170
|
+
const moduleMap = {};
|
|
171
|
+
for (const id of Object.keys(modules)) {
|
|
172
|
+
moduleMap[id] = { '*': { chunks: [], id, name: '*' } };
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// \`debug\`: a development Flight server's debug channel. It is read here,
|
|
176
|
+
// on the server, so server-rendered errors keep their server component
|
|
177
|
+
// owners; the browser's copy of the payload carries none of it.
|
|
178
|
+
export const renderHtml = (flight, options, debug) => {
|
|
179
|
+
const root = createFromReadableStream(flight, {
|
|
180
|
+
...(debug ? { debugChannel: { readable: debug } } : {}),
|
|
181
|
+
serverConsumerManifest: {
|
|
182
|
+
moduleLoading: null,
|
|
183
|
+
moduleMap,
|
|
184
|
+
serverModuleMap: null
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
const Root = () => use(root);
|
|
188
|
+
|
|
189
|
+
return renderToReadableStream(createElement(Root), options);
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
// A fragment (a SuspenseSlot's resolved content) rendered to an HTML string.
|
|
193
|
+
export const renderStaticHtml = async (flight) => {
|
|
194
|
+
const root = createFromReadableStream(flight, {
|
|
195
|
+
serverConsumerManifest: {
|
|
196
|
+
moduleLoading: null,
|
|
197
|
+
moduleMap,
|
|
198
|
+
serverModuleMap: null
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
const Root = () => use(root);
|
|
202
|
+
const stream = await renderToReadableStream(createElement(Root));
|
|
203
|
+
await stream.allReady;
|
|
204
|
+
|
|
205
|
+
return new Response(stream).text();
|
|
206
|
+
};
|
|
207
|
+
`;
|
|
208
|
+
};
|
|
209
|
+
var clientRuntimeSource = (modules) => {
|
|
210
|
+
const loaders = modules.map((module) => ` ${JSON.stringify(module.id)}: () => import(${JSON.stringify(module.path)})`);
|
|
211
|
+
return `const loaders = {
|
|
212
|
+
${loaders.join(`,
|
|
213
|
+
`)}
|
|
214
|
+
};
|
|
215
|
+
const loaded = {};
|
|
216
|
+
const webpackRequire = (id) => loaded[id];
|
|
217
|
+
webpackRequire.u = (id) => id;
|
|
218
|
+
globalThis.__webpack_require__ = webpackRequire;
|
|
219
|
+
// Dev builds of the Flight client name each chunk's script for debug info.
|
|
220
|
+
globalThis.__webpack_get_script_filename__ = (id) => id;
|
|
221
|
+
globalThis.__webpack_chunk_load__ = (id) => {
|
|
222
|
+
const load = loaders[id];
|
|
223
|
+
if (!load) return Promise.reject(new Error('Unknown client module ' + id));
|
|
224
|
+
|
|
225
|
+
return load().then((module) => {
|
|
226
|
+
loaded[id] = module;
|
|
227
|
+
});
|
|
228
|
+
};
|
|
229
|
+
`;
|
|
230
|
+
};
|
|
231
|
+
var clientEntrySource = () => `import './ReactServerClientRuntime';
|
|
232
|
+
import { createFromReadableStream } from 'react-server-dom-webpack/client.browser';
|
|
233
|
+
import { hydrateRoot } from 'react-dom/client';
|
|
234
|
+
import { createElement, use, useEffect } from 'react';
|
|
235
|
+
|
|
236
|
+
const encoder = new TextEncoder();
|
|
237
|
+
const stream = new ReadableStream({
|
|
238
|
+
start(controller) {
|
|
239
|
+
const queue = (self.${REACT_SERVER_PAYLOAD_GLOBAL} ??= []);
|
|
240
|
+
for (const chunk of queue) controller.enqueue(encoder.encode(chunk));
|
|
241
|
+
queue.length = 0;
|
|
242
|
+
queue.push = (chunk) => {
|
|
243
|
+
controller.enqueue(encoder.encode(chunk));
|
|
244
|
+
|
|
245
|
+
return 0;
|
|
246
|
+
};
|
|
247
|
+
const close = () => controller.close();
|
|
248
|
+
if (document.readyState === 'loading') {
|
|
249
|
+
document.addEventListener('DOMContentLoaded', close, { once: true });
|
|
250
|
+
} else {
|
|
251
|
+
close();
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
const root = createFromReadableStream(stream);
|
|
256
|
+
// The page's inline bootstrap holds streamed slot content back
|
|
257
|
+
// (__ABS_SLOT_HYDRATION_PENDING__) so hydration compares against the HTML the
|
|
258
|
+
// server rendered: a slot whose fallback is a React node would otherwise
|
|
259
|
+
// mismatch, and React's client re-render would drop every patched slot.
|
|
260
|
+
const releaseStreamingSlots = () => {
|
|
261
|
+
self.__ABS_SLOT_HYDRATION_PENDING__ = false;
|
|
262
|
+
if (typeof self.__ABS_SLOT_FLUSH__ === 'function') self.__ABS_SLOT_FLUSH__();
|
|
263
|
+
};
|
|
264
|
+
const Root = () => {
|
|
265
|
+
useEffect(() => {
|
|
266
|
+
setTimeout(releaseStreamingSlots, 0);
|
|
267
|
+
}, []);
|
|
268
|
+
|
|
269
|
+
return use(root);
|
|
270
|
+
};
|
|
271
|
+
hydrateRoot(document, createElement(Root));
|
|
272
|
+
`;
|
|
273
|
+
var findOutput = (outputs, name) => outputs.find((artifact) => artifact.kind === "entry-point" && basename(artifact.path).startsWith(`${name}.`));
|
|
274
|
+
var toWebPath = (buildPath, path) => `/${relative2(buildPath, path).replace(/\\/g, "/")}`;
|
|
275
|
+
var assertFlightPackage = (projectRoot) => {
|
|
276
|
+
try {
|
|
277
|
+
Bun.resolveSync("react-server-dom-webpack/package.json", projectRoot);
|
|
278
|
+
} catch {
|
|
279
|
+
throw new Error("reactServerComponentsDirectory is set but react-server-dom-webpack is not installed. " + "Add it at the same version as react (for example `bun add react-server-dom-webpack@<your react version>`).");
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
var emptyResult = () => ({
|
|
283
|
+
logs: [],
|
|
284
|
+
manifest: {},
|
|
285
|
+
outputPaths: [],
|
|
286
|
+
success: true
|
|
287
|
+
});
|
|
288
|
+
var writeGeneratedFile = (path, contents) => {
|
|
289
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
290
|
+
writeFileSync(path, contents);
|
|
291
|
+
return path;
|
|
292
|
+
};
|
|
293
|
+
var pageEntryName = (pagePath) => toPascal(basename(pagePath, extname(pagePath)));
|
|
294
|
+
var endsWithPageSuffix = (name) => name.length > REACT_SERVER_PAGE_MANIFEST_SUFFIX.length && name.endsWith(REACT_SERVER_PAGE_MANIFEST_SUFFIX);
|
|
295
|
+
var pageManifestKeys = (name, names) => {
|
|
296
|
+
const doubled = `${name}${REACT_SERVER_PAGE_MANIFEST_SUFFIX}`;
|
|
297
|
+
if (!endsWithPageSuffix(name))
|
|
298
|
+
return { keys: [doubled] };
|
|
299
|
+
const base = name.slice(0, -REACT_SERVER_PAGE_MANIFEST_SUFFIX.length);
|
|
300
|
+
if (!names.has(base))
|
|
301
|
+
return { keys: [name, doubled] };
|
|
302
|
+
return {
|
|
303
|
+
collision: `React Server Components pages ${base} and ${name} both map to the manifest key "${name}"; ${base} keeps it and ${name} is only reachable as "${doubled}". Rename one of them.`,
|
|
304
|
+
keys: [doubled]
|
|
305
|
+
};
|
|
306
|
+
};
|
|
307
|
+
var buildReactServerComponents = async ({
|
|
308
|
+
buildPath,
|
|
309
|
+
directory,
|
|
310
|
+
isDev,
|
|
311
|
+
projectRoot
|
|
312
|
+
}) => {
|
|
313
|
+
const pagesDir = join(directory, "pages");
|
|
314
|
+
if (!existsSync(pagesDir))
|
|
315
|
+
return emptyResult();
|
|
316
|
+
const pages = [
|
|
317
|
+
...new Glob(PAGE_PATTERN).scanSync({ absolute: true, cwd: pagesDir })
|
|
318
|
+
].sort();
|
|
319
|
+
if (pages.length === 0)
|
|
320
|
+
return emptyResult();
|
|
321
|
+
assertFlightPackage(projectRoot);
|
|
322
|
+
const generatedDir = join(projectRoot, ".absolutejs", "generated", "react-server");
|
|
323
|
+
writeGeneratedFile(join(generatedDir, "asyncLocalStorage.ts"), ALS_SETUP_SOURCE);
|
|
324
|
+
const pageEntries = pages.map((pagePath) => {
|
|
325
|
+
const name = pageEntryName(pagePath);
|
|
326
|
+
return {
|
|
327
|
+
entry: writeGeneratedFile(join(generatedDir, "pages", `${name}.ts`), pageEntrySource(pagePath, resolvePageExport(pagePath, name))),
|
|
328
|
+
name
|
|
329
|
+
};
|
|
330
|
+
});
|
|
331
|
+
const sharedDefine = {
|
|
332
|
+
"process.env.NODE_ENV": JSON.stringify(isDev ? "development" : "production")
|
|
333
|
+
};
|
|
334
|
+
const serverSourcemap = isDev ? "inline" : "linked";
|
|
335
|
+
const clientModules = new Map;
|
|
336
|
+
const serverResult = await bunBuild({
|
|
337
|
+
conditions: ["react-server"],
|
|
338
|
+
define: sharedDefine,
|
|
339
|
+
entrypoints: pageEntries.map((page) => page.entry),
|
|
340
|
+
format: "esm",
|
|
341
|
+
naming: "[name].[hash].[ext]",
|
|
342
|
+
outdir: join(buildPath, "react", "server", "rsc"),
|
|
343
|
+
plugins: [createClientReferencePlugin(projectRoot, clientModules)],
|
|
344
|
+
root: generatedDir,
|
|
345
|
+
sourcemap: serverSourcemap,
|
|
346
|
+
splitting: true,
|
|
347
|
+
target: "bun",
|
|
348
|
+
throw: false
|
|
349
|
+
});
|
|
350
|
+
if (!serverResult.success) {
|
|
351
|
+
return { ...emptyResult(), logs: serverResult.logs, success: false };
|
|
352
|
+
}
|
|
353
|
+
const modules = [...clientModules.values()].sort((left, right) => left.id.localeCompare(right.id));
|
|
354
|
+
const ssrEntry = writeGeneratedFile(join(generatedDir, "ReactServerRenderer.ts"), ssrEntrySource(modules));
|
|
355
|
+
writeGeneratedFile(join(generatedDir, "ReactServerClientRuntime.ts"), clientRuntimeSource(modules));
|
|
356
|
+
const clientEntry = writeGeneratedFile(join(generatedDir, "ReactServerClient.ts"), clientEntrySource());
|
|
357
|
+
const [ssrResult, clientResult] = await Promise.all([
|
|
358
|
+
bunBuild({
|
|
359
|
+
define: sharedDefine,
|
|
360
|
+
entrypoints: [ssrEntry],
|
|
361
|
+
format: "esm",
|
|
362
|
+
naming: "[name].[hash].[ext]",
|
|
363
|
+
outdir: join(buildPath, "react", "server", "ssr"),
|
|
364
|
+
root: generatedDir,
|
|
365
|
+
sourcemap: serverSourcemap,
|
|
366
|
+
target: "bun",
|
|
367
|
+
throw: false
|
|
368
|
+
}),
|
|
369
|
+
bunBuild({
|
|
370
|
+
define: sharedDefine,
|
|
371
|
+
entrypoints: [clientEntry],
|
|
372
|
+
format: "esm",
|
|
373
|
+
minify: !isDev,
|
|
374
|
+
naming: {
|
|
375
|
+
chunk: "chunk-[hash].[ext]",
|
|
376
|
+
entry: "[name].[hash].[ext]"
|
|
377
|
+
},
|
|
378
|
+
outdir: join(buildPath, "react", "rsc"),
|
|
379
|
+
root: generatedDir,
|
|
380
|
+
splitting: true,
|
|
381
|
+
target: "browser",
|
|
382
|
+
throw: false
|
|
383
|
+
})
|
|
384
|
+
]);
|
|
385
|
+
const logs = [
|
|
386
|
+
...serverResult.logs,
|
|
387
|
+
...ssrResult.logs,
|
|
388
|
+
...clientResult.logs
|
|
389
|
+
];
|
|
390
|
+
if (!ssrResult.success || !clientResult.success) {
|
|
391
|
+
return { ...emptyResult(), logs, success: false };
|
|
392
|
+
}
|
|
393
|
+
const ssrOutput = findOutput(ssrResult.outputs, "ReactServerRenderer");
|
|
394
|
+
const clientOutput = findOutput(clientResult.outputs, "ReactServerClient");
|
|
395
|
+
if (!ssrOutput || !clientOutput) {
|
|
396
|
+
throw new Error("React Server Components build produced no entry.");
|
|
397
|
+
}
|
|
398
|
+
const clientUrl = toWebPath(buildPath, clientOutput.path);
|
|
399
|
+
const rscOutputDir = join(buildPath, "react", "server", "rsc");
|
|
400
|
+
const runtimeFile = writeGeneratedFile(join(rscOutputDir, REACT_SERVER_RUNTIME_FILE), JSON.stringify({
|
|
401
|
+
client: clientUrl,
|
|
402
|
+
ssr: relative2(rscOutputDir, ssrOutput.path).replace(/\\/g, "/")
|
|
403
|
+
}));
|
|
404
|
+
const manifest = {
|
|
405
|
+
[REACT_SERVER_CLIENT_MANIFEST_KEY]: clientUrl,
|
|
406
|
+
[REACT_SERVER_RENDERER_MANIFEST_KEY]: resolve2(ssrOutput.path)
|
|
407
|
+
};
|
|
408
|
+
const pageKeys = reactServerPageManifestKeys2(pageEntries.map((page) => page.name));
|
|
409
|
+
for (const collision of pageKeys.collisions)
|
|
410
|
+
logWarn(collision);
|
|
411
|
+
for (const page of pageEntries) {
|
|
412
|
+
const output = findOutput(serverResult.outputs, page.name);
|
|
413
|
+
if (!output)
|
|
414
|
+
continue;
|
|
415
|
+
for (const key of pageKeys.keys.get(page.name) ?? [])
|
|
416
|
+
manifest[key] = resolve2(output.path);
|
|
417
|
+
}
|
|
418
|
+
const result = {
|
|
419
|
+
logs,
|
|
420
|
+
manifest,
|
|
421
|
+
outputPaths: [
|
|
422
|
+
...serverResult.outputs.map((artifact) => artifact.path),
|
|
423
|
+
...ssrResult.outputs.map((artifact) => artifact.path),
|
|
424
|
+
...clientResult.outputs.map((artifact) => artifact.path),
|
|
425
|
+
runtimeFile
|
|
426
|
+
],
|
|
427
|
+
success: true
|
|
428
|
+
};
|
|
429
|
+
return result;
|
|
430
|
+
};
|
|
431
|
+
var buildReactServerComponentsPass2 = async ({
|
|
432
|
+
directory,
|
|
433
|
+
incrementalFiles,
|
|
434
|
+
...options
|
|
435
|
+
}) => {
|
|
436
|
+
if (!directory)
|
|
437
|
+
return;
|
|
438
|
+
const absoluteDirectory = validateSafePath(directory, options.projectRoot);
|
|
439
|
+
const directoryPrefix = `${normalizePath(absoluteDirectory)}/`;
|
|
440
|
+
const touchesDirectory = !incrementalFiles || incrementalFiles.length === 0 || incrementalFiles.some((file) => normalizePath(resolve2(file)).startsWith(directoryPrefix));
|
|
441
|
+
if (!touchesDirectory)
|
|
442
|
+
return;
|
|
443
|
+
return buildReactServerComponents({
|
|
444
|
+
...options,
|
|
445
|
+
directory: absoluteDirectory
|
|
446
|
+
});
|
|
447
|
+
};
|
|
448
|
+
var reactServerPageManifestKeys2 = (pageNames) => {
|
|
449
|
+
const names = new Set(pageNames);
|
|
450
|
+
const keys = new Map;
|
|
451
|
+
const collisions = [];
|
|
452
|
+
for (const name of pageNames) {
|
|
453
|
+
const page = pageManifestKeys(name, names);
|
|
454
|
+
keys.set(name, page.keys);
|
|
455
|
+
if (page.collision)
|
|
456
|
+
collisions.push(page.collision);
|
|
457
|
+
}
|
|
458
|
+
return { collisions, keys };
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
export { buildReactServerComponentsPass2, reactServerPageManifestKeys2 };
|