@tschk/moonshine-deploy-node 0.4.49 → 0.4.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/package.json +5 -5
- package/src/index.ts +28 -13
package/README.md
CHANGED
|
@@ -11,6 +11,10 @@ await nodeAdapter.build(manifest, ".moonshine");
|
|
|
11
11
|
- Target runtime: `node`.
|
|
12
12
|
- Capabilities: `streaming`, `islands`, `revalidation`.
|
|
13
13
|
- Output: `server.ts` using `node:http` and a `Request` / `Response` bridge.
|
|
14
|
+
- React builds with a compiler server bundle also emit a self-contained
|
|
15
|
+
`server.mjs`. Deploy it beside `public/` and run `node server.mjs` on Node 22;
|
|
16
|
+
neither source files nor runtime packages are needed. Building requires Bun.
|
|
17
|
+
Manifests without a compiler server bundle retain the legacy `server.ts` output.
|
|
14
18
|
- Native builds also emit a bundled `server.js`; deploy it beside `public/` and run
|
|
15
19
|
`node server.js`. The bundle includes its manifest and needs no runtime packages.
|
|
16
20
|
This path is verified on Node 22. Building still requires Bun.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tschk/moonshine-deploy-node",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.80",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -15,20 +15,20 @@
|
|
|
15
15
|
"test": "bun test"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@tschk/moonshine-framework": "^0.4.
|
|
19
|
-
"@tschk/moonshine-server": "^0.4.
|
|
18
|
+
"@tschk/moonshine-framework": "^0.4.80",
|
|
19
|
+
"@tschk/moonshine-server": "^0.4.80"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/bun": "1.3.14",
|
|
23
23
|
"@types/node": "^22.0.0",
|
|
24
24
|
"typescript": "7.0.2",
|
|
25
|
-
"@tschk/moonshine-adapter-conformance": "^0.4.
|
|
25
|
+
"@tschk/moonshine-adapter-conformance": "^0.4.80"
|
|
26
26
|
},
|
|
27
27
|
"files": [
|
|
28
28
|
"src"
|
|
29
29
|
],
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"@tschk/moonshine-react": "^0.4.
|
|
31
|
+
"@tschk/moonshine-react": "^0.4.80"
|
|
32
32
|
},
|
|
33
33
|
"peerDependenciesMeta": {
|
|
34
34
|
"@tschk/moonshine-react": {
|
package/src/index.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { mkdir, writeFile } from "node:fs/promises";
|
|
1
|
+
import { mkdir, rm, writeFile } from "node:fs/promises";
|
|
2
2
|
import {
|
|
3
3
|
createServer,
|
|
4
4
|
type IncomingMessage,
|
|
5
5
|
type ServerResponse,
|
|
6
6
|
} from "node:http";
|
|
7
|
+
import { existsSync } from "node:fs";
|
|
7
8
|
import { resolve } from "node:path";
|
|
8
9
|
import { Readable } from "node:stream";
|
|
10
|
+
import { fileURLToPath } from "node:url";
|
|
9
11
|
import {
|
|
10
12
|
type DeploymentAdapter,
|
|
11
13
|
type MoonshineManifest,
|
|
@@ -188,6 +190,7 @@ export const nodeAdapter: DeploymentAdapter = {
|
|
|
188
190
|
build: async (manifest, outDir) => {
|
|
189
191
|
validateRuntime(nodeAdapter, manifest);
|
|
190
192
|
await mkdir(outDir, { recursive: true });
|
|
193
|
+
await rm(resolve(outDir, "server.mjs"), { force: true });
|
|
191
194
|
const assets = await Promise.all(
|
|
192
195
|
manifest.assets.map(async (asset) => {
|
|
193
196
|
const file = await copyAsset(asset, outDir);
|
|
@@ -200,17 +203,28 @@ export const nodeAdapter: DeploymentAdapter = {
|
|
|
200
203
|
JSON.stringify(builtManifest, null, 2) + "\n",
|
|
201
204
|
);
|
|
202
205
|
const native = manifest.renderer === "native";
|
|
203
|
-
const
|
|
204
|
-
|
|
205
|
-
|
|
206
|
+
const bundled =
|
|
207
|
+
native ||
|
|
208
|
+
((manifest.renderer ?? "react") === "react" &&
|
|
209
|
+
Boolean(
|
|
210
|
+
manifest.entries.server &&
|
|
211
|
+
existsSync(resolve(outDir, manifest.entries.server)),
|
|
212
|
+
));
|
|
213
|
+
const serverEntry = manifest.entries.server ?? "dist/server.js";
|
|
214
|
+
// The bundle exports the renderer bound to its own route modules (and, for
|
|
215
|
+
// React, its own React instance).
|
|
216
|
+
const rendererImport =
|
|
217
|
+
native || (manifest.renderer ?? "react") === "react"
|
|
218
|
+
? `import { modules, renderer } from ${JSON.stringify(`./${serverEntry}`)};`
|
|
219
|
+
: 'import { modules } from "./dist/server.js";\nimport { reactRenderer as renderer } from "@tschk/moonshine-react";';
|
|
206
220
|
const entry = `import { createServer } from "node:http";
|
|
207
|
-
import { createRequestHandler } from "
|
|
208
|
-
import { createNodeHandler } from "@tschk/moonshine-deploy-node";
|
|
221
|
+
import { createRequestHandler } from ${JSON.stringify(bundled ? fileURLToPath(import.meta.resolve(`@tschk/moonshine-server${manifest.dataRequests ? "/data-http" : ""}`)) : `@tschk/moonshine-server${manifest.dataRequests ? "/data-http" : ""}`)};
|
|
222
|
+
import { createNodeHandler } from ${JSON.stringify(bundled ? fileURLToPath(import.meta.resolve("@tschk/moonshine-deploy-node")) : "@tschk/moonshine-deploy-node")};
|
|
209
223
|
import { dirname, resolve } from "node:path";
|
|
210
224
|
import { fileURLToPath } from "node:url";
|
|
211
225
|
import manifest from "./manifest.json" with { type: "json" };
|
|
212
226
|
${rendererImport}
|
|
213
|
-
${manifest.requestContext ?
|
|
227
|
+
${manifest.requestContext ? `import { requestScope } from ${JSON.stringify(`./${serverEntry}`)};` : ""}
|
|
214
228
|
|
|
215
229
|
const artifactDir = dirname(fileURLToPath(import.meta.url));
|
|
216
230
|
const projectDir = resolve(artifactDir, "..");
|
|
@@ -228,7 +242,7 @@ const resolvedManifest = {
|
|
|
228
242
|
};
|
|
229
243
|
|
|
230
244
|
const fetch = createRequestHandler({
|
|
231
|
-
manifest: ${
|
|
245
|
+
manifest: ${bundled ? "manifest" : "resolvedManifest"},
|
|
232
246
|
modules,
|
|
233
247
|
renderer,${manifest.requestContext ? "\n requestScope," : ""}
|
|
234
248
|
staticDir: artifactDir + "/public",
|
|
@@ -243,18 +257,19 @@ server.listen(Number.isInteger(envPort) && envPort >= 0 && envPort <= 65535 ? en
|
|
|
243
257
|
`;
|
|
244
258
|
const entryPath = resolve(outDir, "server.ts");
|
|
245
259
|
await writeFile(entryPath, entry);
|
|
246
|
-
if (
|
|
260
|
+
if (bundled) {
|
|
247
261
|
const result = await Bun.build({
|
|
248
262
|
entrypoints: [entryPath],
|
|
249
263
|
outdir: outDir,
|
|
264
|
+
naming: native ? "server.js" : "server.mjs",
|
|
250
265
|
target: "node",
|
|
251
266
|
packages: "bundle",
|
|
267
|
+
...(native
|
|
268
|
+
? {}
|
|
269
|
+
: { define: { "process.env.NODE_ENV": '"production"' } }),
|
|
252
270
|
});
|
|
253
271
|
if (!result.success)
|
|
254
|
-
throw new AggregateError(
|
|
255
|
-
result.logs,
|
|
256
|
-
"Native Node server bundle failed",
|
|
257
|
-
);
|
|
272
|
+
throw new AggregateError(result.logs, "Node server bundle failed");
|
|
258
273
|
}
|
|
259
274
|
},
|
|
260
275
|
};
|