@eserstack/laroux-server 0.0.0-stage → 5.0.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/LICENSE +13 -0
- package/README.md +410 -2
- package/dist/adapters/react/error-chunk.d.ts +11 -0
- package/dist/adapters/react/error-chunk.js +12 -0
- package/dist/adapters/react/html-shell.d.ts +15 -0
- package/dist/adapters/react/html-shell.js +109 -0
- package/dist/adapters/react/inline-rsc-emitter.d.ts +62 -0
- package/dist/adapters/react/inline-rsc-emitter.js +120 -0
- package/dist/adapters/react/mod.d.ts +30 -0
- package/dist/adapters/react/mod.js +36 -0
- package/dist/adapters/react/render-app.d.ts +46 -0
- package/dist/adapters/react/render-app.js +44 -0
- package/dist/adapters/react/renderer.d.ts +15 -0
- package/dist/adapters/react/renderer.js +86 -0
- package/dist/adapters/react/rsc-flight-renderer.d.ts +64 -0
- package/dist/adapters/react/rsc-flight-renderer.js +623 -0
- package/dist/adapters/react/rsc-handler.d.ts +47 -0
- package/dist/adapters/react/rsc-handler.js +114 -0
- package/dist/adapters/react/script-json.d.ts +12 -0
- package/dist/adapters/react/script-json.js +18 -0
- package/dist/adapters/react/ssr-renderer.d.ts +63 -0
- package/dist/adapters/react/ssr-renderer.js +625 -0
- package/dist/bin-main.d.ts +1 -0
- package/dist/bin-main.js +18 -0
- package/dist/cli.d.ts +26 -0
- package/dist/cli.js +48 -0
- package/dist/commands/build.d.ts +78 -0
- package/dist/commands/build.js +221 -0
- package/dist/commands/dev.d.ts +50 -0
- package/dist/commands/dev.js +133 -0
- package/dist/commands/init.d.ts +29 -0
- package/dist/commands/init.js +228 -0
- package/dist/commands/serve.d.ts +47 -0
- package/dist/commands/serve.js +124 -0
- package/dist/config/load-config.d.ts +14 -0
- package/dist/config/load-config.js +67 -0
- package/dist/domain/action-registry.d.ts +83 -0
- package/dist/domain/action-registry.js +124 -0
- package/dist/domain/build-module.d.ts +30 -0
- package/dist/domain/build-module.js +50 -0
- package/dist/domain/hmr-manager.d.ts +51 -0
- package/dist/domain/hmr-manager.js +90 -0
- package/dist/domain/html-shell.d.ts +56 -0
- package/dist/domain/html-shell.js +15 -0
- package/dist/domain/middleware-dispatcher.d.ts +42 -0
- package/dist/domain/middleware-dispatcher.js +150 -0
- package/dist/domain/rebuild-handler.d.ts +52 -0
- package/dist/domain/rebuild-handler.js +52 -0
- package/dist/domain/renderer.d.ts +62 -0
- package/dist/domain/renderer.js +15 -0
- package/dist/domain/route-dispatcher.d.ts +40 -0
- package/dist/domain/route-dispatcher.js +134 -0
- package/dist/domain/server-modules.d.ts +65 -0
- package/dist/domain/server-modules.js +208 -0
- package/dist/main.d.ts +40 -0
- package/dist/main.js +256 -0
- package/dist/module.d.ts +24 -0
- package/dist/module.js +140 -0
- package/dist/options.d.ts +53 -0
- package/dist/options.js +14 -0
- package/dist/package.json +98 -0
- package/dist/proxy/types.d.ts +19 -0
- package/dist/proxy/types.js +3 -0
- package/dist/runtime/action-guard.d.ts +49 -0
- package/dist/runtime/action-guard.js +115 -0
- package/dist/runtime/html-shell.d.ts +66 -0
- package/dist/runtime/html-shell.js +246 -0
- package/dist/runtime/media-types.d.ts +13 -0
- package/dist/runtime/media-types.js +83 -0
- package/dist/runtime/path-containment.d.ts +11 -0
- package/dist/runtime/path-containment.js +27 -0
- package/dist/runtime/seo/generate-meta.d.ts +16 -0
- package/dist/runtime/seo/generate-meta.js +121 -0
- package/dist/runtime/seo/index.d.ts +5 -0
- package/dist/runtime/seo/index.js +5 -0
- package/dist/runtime/seo/types.d.ts +25 -0
- package/dist/runtime/seo/types.js +5 -0
- package/dist/runtime/server.d.ts +58 -0
- package/dist/runtime/server.js +699 -0
- package/package.json +81 -3
package/dist/main.js
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
|
|
2
|
+
/**
|
|
3
|
+
* Laroux Server
|
|
4
|
+
* Server orchestration for React Server Components
|
|
5
|
+
*
|
|
6
|
+
* The build runs in @eserstack/laroux-bundler; the CLI commands are in
|
|
7
|
+
* ./commands and mount under `eser laroux` through ./module.ts.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import * as logging from "@eserstack/logging";
|
|
12
|
+
import * as crossRuntime from "@eserstack/standards/cross-runtime";
|
|
13
|
+
import * as system from "@eserstack/laroux-bundler/system";
|
|
14
|
+
import * as prebuiltBundler from "@eserstack/laroux-bundler/adapters/prebuilt-bundler";
|
|
15
|
+
import * as loadConfig from "./config/load-config.js";
|
|
16
|
+
import * as renderer from "./domain/renderer.js";
|
|
17
|
+
import * as htmlShell from "./domain/html-shell.js";
|
|
18
|
+
import * as hmrManager from "./domain/hmr-manager.js";
|
|
19
|
+
import * as rebuildHandler from "./domain/rebuild-handler.js";
|
|
20
|
+
import * as serverModules from "./domain/server-modules.js";
|
|
21
|
+
export { VALID_LOG_LEVELS } from "./options.js";
|
|
22
|
+
/**
|
|
23
|
+
* Thrown by startServer when the build it runs before serving fails, so dev
|
|
24
|
+
* and serve never start on a stale or empty dist/. The bundler logs the
|
|
25
|
+
* failing step and its error before this is thrown.
|
|
26
|
+
*/
|
|
27
|
+
export class BuildFailedError extends Error {
|
|
28
|
+
/** Root of the app whose build failed */
|
|
29
|
+
projectRoot;
|
|
30
|
+
/**
|
|
31
|
+
* Create the error for the app at projectRoot.
|
|
32
|
+
*
|
|
33
|
+
* @param projectRoot - Root of the app whose build failed
|
|
34
|
+
* @param options - Standard error options, such as a `cause`
|
|
35
|
+
*/
|
|
36
|
+
constructor(projectRoot, options) {
|
|
37
|
+
super(`build ${projectRoot}: the bundler build failed, so the server did not start; the "Build failed" log entry above names the step and its error`, options);
|
|
38
|
+
this.name = "BuildFailedError";
|
|
39
|
+
this.projectRoot = projectRoot;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// Map our LogLevel to @eserstack/logging Severity
|
|
43
|
+
const mapLogLevel = (level) => {
|
|
44
|
+
const mapping = {
|
|
45
|
+
trace: logging.Severities.Debug,
|
|
46
|
+
debug: logging.Severities.Debug,
|
|
47
|
+
info: logging.Severities.Info,
|
|
48
|
+
warn: logging.Severities.Warning,
|
|
49
|
+
error: logging.Severities.Error,
|
|
50
|
+
fatal: logging.Severities.Critical,
|
|
51
|
+
};
|
|
52
|
+
return mapping[level];
|
|
53
|
+
};
|
|
54
|
+
// Loggers (initialized in configureLogging)
|
|
55
|
+
let serverLogger;
|
|
56
|
+
let bundlerLogger;
|
|
57
|
+
/**
|
|
58
|
+
* Configure logging with the specified level
|
|
59
|
+
*/
|
|
60
|
+
async function configureLogging(logLevel) {
|
|
61
|
+
const level = mapLogLevel(logLevel);
|
|
62
|
+
const streams = await import("@eserstack/streams");
|
|
63
|
+
const out = streams.output({
|
|
64
|
+
renderer: streams.renderers.ansi(),
|
|
65
|
+
sink: streams.sinks.stdout(),
|
|
66
|
+
});
|
|
67
|
+
await logging.config.configure({
|
|
68
|
+
sinks: {
|
|
69
|
+
console: logging.sinks.getOutputSink(out),
|
|
70
|
+
},
|
|
71
|
+
loggers: [
|
|
72
|
+
{ category: ["laroux-server"], lowestLevel: level, sinks: ["console"] },
|
|
73
|
+
{ category: ["laroux-bundler"], lowestLevel: level, sinks: ["console"] },
|
|
74
|
+
{ category: ["laroux"], lowestLevel: level, sinks: ["console"] },
|
|
75
|
+
],
|
|
76
|
+
});
|
|
77
|
+
serverLogger = logging.logger.getLogger(["laroux-server", "server"]);
|
|
78
|
+
bundlerLogger = logging.logger.getLogger(["laroux-server", "bundler"]);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Convert AppConfig to BuildConfig for the bundler
|
|
82
|
+
*/
|
|
83
|
+
function toBuildConfig(config) {
|
|
84
|
+
return {
|
|
85
|
+
projectRoot: config.projectRoot,
|
|
86
|
+
srcDir: config.srcDir,
|
|
87
|
+
distDir: config.distDir,
|
|
88
|
+
logLevel: config.logLevel,
|
|
89
|
+
fonts: config.fonts,
|
|
90
|
+
images: config.images,
|
|
91
|
+
cssModuleTypes: config.cssModuleTypes,
|
|
92
|
+
noCssModuleAutoReference: config.noCssModuleAutoReference,
|
|
93
|
+
browserShims: config.browserShims,
|
|
94
|
+
serverExternals: config.build.serverExternals,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Load the build in dist/, start watching in dev mode, and start the HTTP
|
|
99
|
+
* server
|
|
100
|
+
*/
|
|
101
|
+
async function initializeServer(deps, buildPlugins) {
|
|
102
|
+
const { config, bundler } = deps;
|
|
103
|
+
const hmr = deps.hmrManager ?? null;
|
|
104
|
+
// Fails fast when dist/ holds no build to serve
|
|
105
|
+
const bundle = await bundler.getBundle();
|
|
106
|
+
const buildId = bundle.chunkManifest.buildId;
|
|
107
|
+
bundlerLogger.debug(`Build ID: ${buildId}`);
|
|
108
|
+
const modules = new serverModules.ServerModules(config.distDir);
|
|
109
|
+
await modules.load(buildId);
|
|
110
|
+
const completeDeps = {
|
|
111
|
+
...deps,
|
|
112
|
+
getApp: (pathname) => modules.getApp(pathname),
|
|
113
|
+
getBuildId: () => modules.loadedBuildId(),
|
|
114
|
+
apiHandler: modules.apiRoutes,
|
|
115
|
+
middlewareDispatcher: modules.proxies,
|
|
116
|
+
};
|
|
117
|
+
// Watch mode rebuilds on change, with rolldown like every other build.
|
|
118
|
+
// Only a successful rebuild reaches HMR clients, after the server has
|
|
119
|
+
// loaded the rebuilt pages, API routes, proxies and server actions.
|
|
120
|
+
const isWatching = config.mode.isWatch && buildPlugins !== null;
|
|
121
|
+
if (isWatching) {
|
|
122
|
+
const buildContext = system.createBuildContext(toBuildConfig(config), {
|
|
123
|
+
...buildPlugins,
|
|
124
|
+
bundlerBackend: "rolldown",
|
|
125
|
+
});
|
|
126
|
+
system.watch(buildContext, rebuildHandler.createRebuildHandler({
|
|
127
|
+
hmr,
|
|
128
|
+
onRebuilt: (rebuiltBuildId) => modules.load(rebuiltBuildId),
|
|
129
|
+
logger: bundlerLogger,
|
|
130
|
+
}));
|
|
131
|
+
}
|
|
132
|
+
// Display mode indicator
|
|
133
|
+
let modeIndicator = "";
|
|
134
|
+
if (isWatching && hmr !== null) {
|
|
135
|
+
modeIndicator = " HMR";
|
|
136
|
+
}
|
|
137
|
+
else if (isWatching) {
|
|
138
|
+
modeIndicator = " Watch";
|
|
139
|
+
}
|
|
140
|
+
serverLogger.info(`RSC Server${modeIndicator}`);
|
|
141
|
+
// Dynamically import server module to avoid loading react-dom/server during build
|
|
142
|
+
const server = await import("./runtime/server.js");
|
|
143
|
+
const listening = await server.startHTTPServer(completeDeps);
|
|
144
|
+
serverLogger.info(` Local: http://${config.server.host}:${listening.port}`);
|
|
145
|
+
return completeDeps;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Start the development or production server
|
|
149
|
+
*
|
|
150
|
+
* @param options - Server options (with optional plugin injection)
|
|
151
|
+
* @throws {BuildFailedError} When the build that runs before serving fails;
|
|
152
|
+
* the server is not started.
|
|
153
|
+
*/
|
|
154
|
+
export async function startServer(options) {
|
|
155
|
+
const projectRoot = options.projectRoot ?? crossRuntime.runtime.process.cwd();
|
|
156
|
+
const logLevel = options.logLevel ?? "info";
|
|
157
|
+
const isDev = options.mode === "dev";
|
|
158
|
+
// Build when a framework plugin is given; the other adapters fall back to
|
|
159
|
+
// the bundler's no-op defaults when left out
|
|
160
|
+
const buildPlugins = options.frameworkPlugin !== undefined
|
|
161
|
+
? {
|
|
162
|
+
framework: options.frameworkPlugin,
|
|
163
|
+
css: options.cssPlugin,
|
|
164
|
+
cssProcessor: options.cssProcessor,
|
|
165
|
+
fontOptimizer: options.fontOptimizer,
|
|
166
|
+
imageOptimizer: options.imageOptimizer,
|
|
167
|
+
}
|
|
168
|
+
: null;
|
|
169
|
+
await configureLogging(logLevel);
|
|
170
|
+
// Load configuration
|
|
171
|
+
const baseConfig = await loadConfig.loadConfig(projectRoot);
|
|
172
|
+
const config = {
|
|
173
|
+
...baseConfig,
|
|
174
|
+
srcDir: crossRuntime.runtime.path.resolve(projectRoot, baseConfig.srcDir),
|
|
175
|
+
distDir: crossRuntime.runtime.path.resolve(projectRoot, baseConfig.distDir),
|
|
176
|
+
publicDir: crossRuntime.runtime.path.resolve(projectRoot, baseConfig.publicDir),
|
|
177
|
+
logLevel,
|
|
178
|
+
mode: {
|
|
179
|
+
isDev,
|
|
180
|
+
isBuild: false,
|
|
181
|
+
isServe: !isDev,
|
|
182
|
+
isWatch: isDev,
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
// Apply server options
|
|
186
|
+
if (options.port !== undefined) {
|
|
187
|
+
config.server.port = options.port;
|
|
188
|
+
}
|
|
189
|
+
if (options.hmr !== undefined) {
|
|
190
|
+
config.server.hmr = options.hmr;
|
|
191
|
+
}
|
|
192
|
+
else if (isDev) {
|
|
193
|
+
config.server.hmr = true; // Default HMR on for dev
|
|
194
|
+
}
|
|
195
|
+
if (options.open !== undefined) {
|
|
196
|
+
config.server.open = options.open;
|
|
197
|
+
}
|
|
198
|
+
// Dev mode adjustments
|
|
199
|
+
if (isDev) {
|
|
200
|
+
config.build.minify = false;
|
|
201
|
+
}
|
|
202
|
+
// Build before serving when a framework plugin is provided: always in dev,
|
|
203
|
+
// and in serve mode when dist/ holds no finished build or a build input
|
|
204
|
+
// changed after it. Dev and serve both bundle with rolldown.
|
|
205
|
+
if (buildPlugins !== null) {
|
|
206
|
+
const context = system.createBuildContext(toBuildConfig(config), {
|
|
207
|
+
...buildPlugins,
|
|
208
|
+
bundlerBackend: "rolldown",
|
|
209
|
+
});
|
|
210
|
+
const buildResult = isDev
|
|
211
|
+
? await system.build(context)
|
|
212
|
+
: await system.ensureBuildIsReady(context);
|
|
213
|
+
if (!buildResult.success) {
|
|
214
|
+
// Serving a stale or empty dist/ would hide the failure; the bundler
|
|
215
|
+
// has already logged the failing step and its error.
|
|
216
|
+
throw new BuildFailedError(projectRoot);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
// Set up bundler and HMR
|
|
220
|
+
const bundler = new prebuiltBundler.PrebuiltBundler({
|
|
221
|
+
distDir: config.distDir,
|
|
222
|
+
});
|
|
223
|
+
const hmr = isDev && config.server.hmr ? new hmrManager.HMRManager() : null;
|
|
224
|
+
// Start server with explicit plugin injection; the renderer and HTML shell
|
|
225
|
+
// fall back to the noop implementations when none is injected
|
|
226
|
+
await initializeServer({
|
|
227
|
+
config,
|
|
228
|
+
bundler,
|
|
229
|
+
hmrManager: hmr,
|
|
230
|
+
renderer: options.renderer ?? renderer.noopRenderer,
|
|
231
|
+
htmlShell: options.htmlShell ?? htmlShell.noopHtmlShellBuilder,
|
|
232
|
+
}, buildPlugins);
|
|
233
|
+
// Open browser if requested
|
|
234
|
+
if (options.open === true) {
|
|
235
|
+
openBrowser(`http://localhost:${config.server.port}`);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Open browser (helper function)
|
|
240
|
+
*/
|
|
241
|
+
function openBrowser(url) {
|
|
242
|
+
const commands = {
|
|
243
|
+
darwin: ["open"],
|
|
244
|
+
linux: ["xdg-open"],
|
|
245
|
+
windows: ["cmd", "/c", "start"],
|
|
246
|
+
};
|
|
247
|
+
const platform = crossRuntime.getPlatform();
|
|
248
|
+
const command = commands[platform];
|
|
249
|
+
if (command !== undefined) {
|
|
250
|
+
const [program, ...args] = command;
|
|
251
|
+
crossRuntime.runtime.exec.spawnChild(program, [...args, url], {
|
|
252
|
+
stdout: "null",
|
|
253
|
+
stderr: "null",
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
}
|
package/dist/module.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* laroux.js CLI module definition.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import * as module from "@eserstack/shell/module";
|
|
7
|
+
/** The command module type, `Module` from `@eserstack/shell/module`. */
|
|
8
|
+
export type Module = module.Module;
|
|
9
|
+
export type { ModuleConfig, SubmoduleRegistration, } from "@eserstack/shell/module";
|
|
10
|
+
export type { ArgsConfig, ArgsValidation, CliError, CliResult, Command, CommandContext, CommandHandler, CommandLike, DispatchableModule, FallbackHandler, FlagDef, FlagType, GroupOptions, LazyCommandOptions, ModuleEntry, } from "@eserstack/shell/args";
|
|
11
|
+
export type { Shell } from "@eserstack/shell/completions";
|
|
12
|
+
/**
|
|
13
|
+
* The `laroux` command group: `init`, `dev`, `build` and `serve`. A
|
|
14
|
+
* command's module loads when that command runs. The `eser` CLI mounts it as
|
|
15
|
+
* `eser laroux`, and the standalone `laroux` binary runs it as its root.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import * as larouxModule from "@eserstack/laroux-server/module";
|
|
20
|
+
*
|
|
21
|
+
* const command = larouxModule.moduleDef.toCommand("laroux", "1.0.0");
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare const moduleDef: Module;
|
package/dist/module.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
|
|
2
|
+
/**
|
|
3
|
+
* laroux.js CLI module definition.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import * as module from "@eserstack/shell/module";
|
|
8
|
+
/**
|
|
9
|
+
* The `laroux` command group: `init`, `dev`, `build` and `serve`. A
|
|
10
|
+
* command's module loads when that command runs. The `eser` CLI mounts it as
|
|
11
|
+
* `eser laroux`, and the standalone `laroux` binary runs it as its root.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import * as larouxModule from "@eserstack/laroux-server/module";
|
|
16
|
+
*
|
|
17
|
+
* const command = larouxModule.moduleDef.toCommand("laroux", "1.0.0");
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export const moduleDef = new module.Module({
|
|
21
|
+
description: "laroux.js framework commands",
|
|
22
|
+
modules: {
|
|
23
|
+
init: {
|
|
24
|
+
description: "Create a new laroux.js project",
|
|
25
|
+
load: () => import("./commands/init.js"),
|
|
26
|
+
flags: [
|
|
27
|
+
{
|
|
28
|
+
name: "template",
|
|
29
|
+
short: "t",
|
|
30
|
+
type: "string",
|
|
31
|
+
description: "Project template (minimal)",
|
|
32
|
+
default: "minimal",
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: "registry",
|
|
36
|
+
type: "string",
|
|
37
|
+
description: "Path or URL of a kit recipes.json (default: eser/stack's registry on GitHub)",
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: "force",
|
|
41
|
+
short: "f",
|
|
42
|
+
type: "boolean",
|
|
43
|
+
description: "Write the template over a folder that is not empty",
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: "no-git",
|
|
47
|
+
type: "boolean",
|
|
48
|
+
description: "Skip the template's post-install commands, as --no-install",
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: "no-install",
|
|
52
|
+
type: "boolean",
|
|
53
|
+
description: "Skip the template's post-install commands",
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
dev: {
|
|
58
|
+
description: "Start development server with hot reload",
|
|
59
|
+
load: () => import("./commands/dev.js"),
|
|
60
|
+
flags: [
|
|
61
|
+
{
|
|
62
|
+
name: "port",
|
|
63
|
+
short: "p",
|
|
64
|
+
type: "number",
|
|
65
|
+
description: "Server port",
|
|
66
|
+
default: 8000,
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: "no-hmr",
|
|
70
|
+
type: "boolean",
|
|
71
|
+
description: "Disable hot module replacement",
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: "log-level",
|
|
75
|
+
type: "string",
|
|
76
|
+
description: "Log level (debug, info, warn, error)",
|
|
77
|
+
default: "info",
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
name: "open",
|
|
81
|
+
short: "o",
|
|
82
|
+
type: "boolean",
|
|
83
|
+
description: "Open browser automatically",
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
},
|
|
87
|
+
build: {
|
|
88
|
+
description: "Build for production",
|
|
89
|
+
load: () => import("./commands/build.js"),
|
|
90
|
+
flags: [
|
|
91
|
+
{
|
|
92
|
+
name: "out-dir",
|
|
93
|
+
type: "string",
|
|
94
|
+
description: "Output directory",
|
|
95
|
+
default: "dist",
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
name: "clean",
|
|
99
|
+
type: "boolean",
|
|
100
|
+
description: "Clean output directory first",
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
name: "no-minify",
|
|
104
|
+
type: "boolean",
|
|
105
|
+
description: "Disable minification",
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
name: "analyze",
|
|
109
|
+
type: "boolean",
|
|
110
|
+
description: "Analyze bundle size",
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
name: "log-level",
|
|
114
|
+
type: "string",
|
|
115
|
+
description: "Log level (debug, info, warn, error)",
|
|
116
|
+
default: "info",
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
},
|
|
120
|
+
serve: {
|
|
121
|
+
description: "Serve production build locally",
|
|
122
|
+
load: () => import("./commands/serve.js"),
|
|
123
|
+
flags: [
|
|
124
|
+
{
|
|
125
|
+
name: "port",
|
|
126
|
+
short: "p",
|
|
127
|
+
type: "number",
|
|
128
|
+
description: "Server port",
|
|
129
|
+
default: 8000,
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
name: "log-level",
|
|
133
|
+
type: "string",
|
|
134
|
+
description: "Log level (debug, info, warn, error)",
|
|
135
|
+
default: "info",
|
|
136
|
+
},
|
|
137
|
+
],
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server Options
|
|
3
|
+
* Types for the programmatic API, used by the CLI commands
|
|
4
|
+
*/
|
|
5
|
+
import type { LogLevel } from "./config/load-config.ts";
|
|
6
|
+
import type { Renderer } from "./domain/renderer.ts";
|
|
7
|
+
import type { HtmlShellBuilder } from "./domain/html-shell.ts";
|
|
8
|
+
import type { CssPlugin, CssProcessor, FontOptimizer, FrameworkPlugin, ImageOptimizer } from "@eserstack/laroux-bundler";
|
|
9
|
+
/**
|
|
10
|
+
* Options for starting the development or production server
|
|
11
|
+
*/
|
|
12
|
+
export type ServerOptions = {
|
|
13
|
+
/** Server mode */
|
|
14
|
+
mode: "dev" | "serve";
|
|
15
|
+
/** Server port */
|
|
16
|
+
port?: number;
|
|
17
|
+
/** Enable Hot Module Replacement (dev mode only) */
|
|
18
|
+
hmr?: boolean;
|
|
19
|
+
/** Open browser automatically */
|
|
20
|
+
open?: boolean;
|
|
21
|
+
/** Project root directory (defaults to cwd) */
|
|
22
|
+
projectRoot?: string;
|
|
23
|
+
/** Log level */
|
|
24
|
+
logLevel?: LogLevel;
|
|
25
|
+
/** Framework renderer adapter (e.g., reactRenderer) */
|
|
26
|
+
renderer?: Renderer;
|
|
27
|
+
/** HTML shell builder adapter (e.g., reactHtmlShellBuilder) */
|
|
28
|
+
htmlShell?: HtmlShellBuilder;
|
|
29
|
+
/**
|
|
30
|
+
* Bundler framework plugin (e.g., reactPlugin). Without one, the server
|
|
31
|
+
* builds nothing and serves the dist/ it finds.
|
|
32
|
+
*/
|
|
33
|
+
frameworkPlugin?: FrameworkPlugin;
|
|
34
|
+
/** Bundler CSS plugin (e.g., createTailwindPlugin(...)) */
|
|
35
|
+
cssPlugin?: CssPlugin;
|
|
36
|
+
/**
|
|
37
|
+
* Transforms the global stylesheet when the CSS plugin does not compile it
|
|
38
|
+
* (e.g., lightningCssProcessor). Without one, it is written unchanged.
|
|
39
|
+
*/
|
|
40
|
+
cssProcessor?: CssProcessor;
|
|
41
|
+
/**
|
|
42
|
+
* Self-hosts the configured fonts (e.g., googleFontOptimizer). Without one,
|
|
43
|
+
* no font files are downloaded.
|
|
44
|
+
*/
|
|
45
|
+
fontOptimizer?: FontOptimizer;
|
|
46
|
+
/**
|
|
47
|
+
* Optimizes the images under public/images (e.g., sharpImageOptimizer).
|
|
48
|
+
* Without one, images are served as they are.
|
|
49
|
+
*/
|
|
50
|
+
imageOptimizer?: ImageOptimizer;
|
|
51
|
+
};
|
|
52
|
+
/** Valid log levels for validation */
|
|
53
|
+
export declare const VALID_LOG_LEVELS: LogLevel[];
|
package/dist/options.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
|
|
2
|
+
/**
|
|
3
|
+
* Server Options
|
|
4
|
+
* Types for the programmatic API, used by the CLI commands
|
|
5
|
+
*/
|
|
6
|
+
/** Valid log levels for validation */
|
|
7
|
+
export const VALID_LOG_LEVELS = [
|
|
8
|
+
"trace",
|
|
9
|
+
"debug",
|
|
10
|
+
"info",
|
|
11
|
+
"warn",
|
|
12
|
+
"error",
|
|
13
|
+
"fatal",
|
|
14
|
+
];
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@eserstack/laroux-server",
|
|
3
|
+
"version": "5.0.0",
|
|
4
|
+
"description": "Server runtime for the laroux.js framework",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/eser/stack",
|
|
10
|
+
"directory": "pkg/@eserstack/laroux-server"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist/**/*.js",
|
|
14
|
+
"dist/**/*.d.ts",
|
|
15
|
+
"dist/**/*.json"
|
|
16
|
+
],
|
|
17
|
+
"exports": {
|
|
18
|
+
".": "./main.ts",
|
|
19
|
+
"./config": "./config/load-config.ts",
|
|
20
|
+
"./adapters/react": "./adapters/react/mod.ts",
|
|
21
|
+
"./action-registry": "./domain/action-registry.ts",
|
|
22
|
+
"./module": "./module.ts",
|
|
23
|
+
"./cli": "./cli.ts",
|
|
24
|
+
"./commands/init": "./commands/init.ts",
|
|
25
|
+
"./commands/dev": "./commands/dev.ts",
|
|
26
|
+
"./commands/build": "./commands/build.ts",
|
|
27
|
+
"./commands/serve": "./commands/serve.ts"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./dist/main.d.ts",
|
|
33
|
+
"import": "./dist/main.js"
|
|
34
|
+
},
|
|
35
|
+
"./config": {
|
|
36
|
+
"types": "./dist/config/load-config.d.ts",
|
|
37
|
+
"import": "./dist/config/load-config.js"
|
|
38
|
+
},
|
|
39
|
+
"./adapters/react": {
|
|
40
|
+
"types": "./dist/adapters/react/mod.d.ts",
|
|
41
|
+
"import": "./dist/adapters/react/mod.js"
|
|
42
|
+
},
|
|
43
|
+
"./action-registry": {
|
|
44
|
+
"types": "./dist/domain/action-registry.d.ts",
|
|
45
|
+
"import": "./dist/domain/action-registry.js"
|
|
46
|
+
},
|
|
47
|
+
"./module": {
|
|
48
|
+
"types": "./dist/module.d.ts",
|
|
49
|
+
"import": "./dist/module.js"
|
|
50
|
+
},
|
|
51
|
+
"./cli": {
|
|
52
|
+
"types": "./dist/cli.d.ts",
|
|
53
|
+
"import": "./dist/cli.js"
|
|
54
|
+
},
|
|
55
|
+
"./commands/init": {
|
|
56
|
+
"types": "./dist/commands/init.d.ts",
|
|
57
|
+
"import": "./dist/commands/init.js"
|
|
58
|
+
},
|
|
59
|
+
"./commands/dev": {
|
|
60
|
+
"types": "./dist/commands/dev.d.ts",
|
|
61
|
+
"import": "./dist/commands/dev.js"
|
|
62
|
+
},
|
|
63
|
+
"./commands/build": {
|
|
64
|
+
"types": "./dist/commands/build.d.ts",
|
|
65
|
+
"import": "./dist/commands/build.js"
|
|
66
|
+
},
|
|
67
|
+
"./commands/serve": {
|
|
68
|
+
"types": "./dist/commands/serve.d.ts",
|
|
69
|
+
"import": "./dist/commands/serve.js"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
"scripts": {
|
|
74
|
+
"build": "node ../../../etc/scripts/build-library.ts"
|
|
75
|
+
},
|
|
76
|
+
"dependencies": {
|
|
77
|
+
"@eserstack/codebase": "workspace:*",
|
|
78
|
+
"@eserstack/fp": "workspace:*",
|
|
79
|
+
"@eserstack/functions": "workspace:*",
|
|
80
|
+
"@eserstack/http": "workspace:*",
|
|
81
|
+
"@eserstack/kit": "workspace:*",
|
|
82
|
+
"@eserstack/laroux": "workspace:*",
|
|
83
|
+
"@eserstack/laroux-bundler": "workspace:*",
|
|
84
|
+
"@eserstack/laroux-react": "workspace:*",
|
|
85
|
+
"@eserstack/logging": "workspace:*",
|
|
86
|
+
"@eserstack/primitives": "workspace:*",
|
|
87
|
+
"@eserstack/shell": "workspace:*",
|
|
88
|
+
"@eserstack/standards": "workspace:*",
|
|
89
|
+
"@eserstack/streams": "workspace:*",
|
|
90
|
+
"react": "^19.3.1",
|
|
91
|
+
"react-dom": "^19.3.1"
|
|
92
|
+
},
|
|
93
|
+
"devDependencies": {
|
|
94
|
+
"@eserstack/test-kit": "workspace:*",
|
|
95
|
+
"@types/react": "^19.3.0",
|
|
96
|
+
"@types/react-dom": "^19.3.0"
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type ProxyContext = {
|
|
2
|
+
request: Request;
|
|
3
|
+
pathname: string;
|
|
4
|
+
params: Record<string, string>;
|
|
5
|
+
};
|
|
6
|
+
export type ProxyResult = {
|
|
7
|
+
type: "next";
|
|
8
|
+
} | {
|
|
9
|
+
type: "response";
|
|
10
|
+
response: Response;
|
|
11
|
+
} | {
|
|
12
|
+
type: "redirect";
|
|
13
|
+
url: string;
|
|
14
|
+
status?: number;
|
|
15
|
+
} | {
|
|
16
|
+
type: "rewrite";
|
|
17
|
+
pathname: string;
|
|
18
|
+
};
|
|
19
|
+
export type Proxy = (context: ProxyContext) => ProxyResult | Promise<ProxyResult>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The largest server action request body, in bytes: 1 MiB. The body is held
|
|
3
|
+
* in memory to decode the arguments, so the limit bounds the memory one
|
|
4
|
+
* request can take. A larger body is refused with 413 before it is parsed.
|
|
5
|
+
*/
|
|
6
|
+
export declare const ACTION_MAX_BODY_BYTES = 1048576;
|
|
7
|
+
/** The server action modules one build lists, as paths under dist/server. */
|
|
8
|
+
export type ActionManifest = {
|
|
9
|
+
readonly actions: ReadonlySet<string>;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Reads `<serverDir>/actions-manifest.json`, the list of "use server" modules
|
|
13
|
+
* the build wrote. A build without the file has no actions.
|
|
14
|
+
*/
|
|
15
|
+
export declare const readActionManifest: (serverDir: string) => Promise<ActionManifest>;
|
|
16
|
+
/**
|
|
17
|
+
* Whether the module of an action id (`path/to/file#export`) is one the build
|
|
18
|
+
* lists. Checked before the module is imported, so a request can never load a
|
|
19
|
+
* server module that is not an action module.
|
|
20
|
+
*/
|
|
21
|
+
export declare const isListedActionModule: (manifest: ActionManifest, modulePath: string) => boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Whether `value` is the server action `actionId` names: a function that
|
|
24
|
+
* carries React's server reference marker with the same id. Plain exports of
|
|
25
|
+
* an action module, such as helpers, fail this check and cannot be called.
|
|
26
|
+
*/
|
|
27
|
+
export declare const isServerAction: (value: unknown, actionId: string) => boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Whether a browser sent the request from a page of the same origin.
|
|
30
|
+
*
|
|
31
|
+
* With Fetch Metadata, `Sec-Fetch-Site` must be `same-origin` or `none`.
|
|
32
|
+
* Without it, an `Origin` header must equal the request URL's origin. A
|
|
33
|
+
* request with neither header passes: browsers send at least one of them on
|
|
34
|
+
* every POST, so only non-browser clients, which cross-site request forgery
|
|
35
|
+
* cannot drive, omit both.
|
|
36
|
+
*/
|
|
37
|
+
export declare const isSameOriginRequest: (req: Request) => boolean;
|
|
38
|
+
/** The request body is over {@link ACTION_MAX_BODY_BYTES}. */
|
|
39
|
+
export declare class ActionBodyTooLargeError extends Error {
|
|
40
|
+
readonly limitBytes: number;
|
|
41
|
+
constructor(limitBytes: number);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Reads the request body into memory, failing with
|
|
45
|
+
* {@link ActionBodyTooLargeError} as soon as it is known to pass
|
|
46
|
+
* `limitBytes`: from Content-Length before any byte is read, otherwise from
|
|
47
|
+
* the bytes counted while reading.
|
|
48
|
+
*/
|
|
49
|
+
export declare const readBoundedBody: (req: Request, limitBytes?: number) => Promise<Uint8Array<ArrayBuffer>>;
|