@tschk/moonshine-deploy-node 0.3.7 → 0.4.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.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/src/index.ts +16 -16
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tschk/moonshine-deploy-node",
3
- "version": "0.3.7",
3
+ "version": "0.4.0",
4
4
  "license": "ISC",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -15,7 +15,6 @@
15
15
  "test": "bun test"
16
16
  },
17
17
  "dependencies": {
18
- "@tschk/moonshine-adapter-conformance": "^0.3.6",
19
18
  "@tschk/moonshine-compiler": "^0.3.6",
20
19
  "@tschk/moonshine-framework": "^0.3.6",
21
20
  "@tschk/moonshine-react": "^0.3.6",
@@ -24,7 +23,8 @@
24
23
  "devDependencies": {
25
24
  "@types/bun": "1.3.14",
26
25
  "@types/node": "^22.0.0",
27
- "typescript": "7.0.2"
26
+ "typescript": "7.0.2",
27
+ "@tschk/moonshine-adapter-conformance": "^0.3.6"
28
28
  },
29
29
  "files": [
30
30
  "src"
package/src/index.ts CHANGED
@@ -10,12 +10,14 @@ import { Readable } from "node:stream";
10
10
  import {
11
11
  type DeploymentAdapter,
12
12
  type MoonshineManifest,
13
- } from "@tschk/moonshine-framework";
14
- import { isContained, resolveStaticPath } from "@tschk/moonshine-server";
15
- import {
16
13
  type Harness,
17
14
  type HarnessFactory,
18
- } from "@tschk/moonshine-adapter-conformance";
15
+ } from "@tschk/moonshine-framework";
16
+ import {
17
+ isContained,
18
+ resolveStaticPath,
19
+ staticFileHeaders,
20
+ } from "@tschk/moonshine-server";
19
21
 
20
22
  const HOP_BY_HOP = new Set([
21
23
  "connection",
@@ -64,7 +66,7 @@ async function tryServeNodeStatic(
64
66
  ): Promise<Response | null> {
65
67
  const filePath = resolveStaticPath(staticDir, pathname);
66
68
  if (!filePath) return null;
67
- let stats;
69
+ let stats = null;
68
70
  try {
69
71
  stats = await stat(filePath);
70
72
  } catch {
@@ -78,12 +80,10 @@ async function tryServeNodeStatic(
78
80
  }
79
81
  const type = MIME[extOf(filePath)] ?? "application/octet-stream";
80
82
  const stream = createReadStream(filePath);
83
+ const headers = staticFileHeaders(type);
84
+ headers.set("content-length", String(stats.size));
81
85
  return new Response(Readable.toWeb(stream) as unknown as ReadableStream, {
82
- headers: {
83
- "content-type": type,
84
- "content-length": String(stats.size),
85
- "x-content-type-options": "nosniff",
86
- },
86
+ headers,
87
87
  });
88
88
  }
89
89
 
@@ -248,11 +248,12 @@ export const nodeAdapter: DeploymentAdapter = {
248
248
  capabilities: ["streaming", "islands", "revalidation"],
249
249
  build: async (manifest, outDir) => {
250
250
  await mkdir(outDir, { recursive: true });
251
- const assets: MoonshineManifest["assets"] = [];
252
- for (const asset of manifest.assets) {
253
- const file = await copyAsset(asset, outDir);
254
- assets.push({ ...asset, file });
255
- }
251
+ const assets = await Promise.all(
252
+ manifest.assets.map(async (asset) => {
253
+ const file = await copyAsset(asset, outDir);
254
+ return { ...asset, file };
255
+ }),
256
+ );
256
257
  const builtManifest: MoonshineManifest = { ...manifest, assets };
257
258
  await writeFile(
258
259
  resolve(outDir, "manifest.json"),
@@ -290,7 +291,6 @@ const server = createServer(createNodeHandler({ fetch, staticDir: import.meta.di
290
291
  server.listen(Number(process.env.PORT) || 0, () => {
291
292
  const address = server.address();
292
293
  const port = typeof address === "object" && address ? address.port : 0;
293
- console.log("http://localhost:" + port + "/");
294
294
  });
295
295
  `;
296
296
  await writeFile(resolve(outDir, "server.ts"), entry);