@tschk/moonshine-compiler 0.3.1 → 0.3.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tschk/moonshine-compiler",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "license": "ISC",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -15,8 +15,8 @@
15
15
  "test": "bun test"
16
16
  },
17
17
  "dependencies": {
18
- "@tschk/moonshine-framework": "^0.3.1",
19
- "@tschk/moonshine-router": "^0.3.1"
18
+ "@tschk/moonshine-framework": "^0.3.2",
19
+ "@tschk/moonshine-router": "^0.3.2"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@types/bun": "1.3.14",
package/src/build.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { mkdir, writeFile } from "node:fs/promises";
2
2
  import { join, relative, resolve } from "node:path";
3
- import type { RouteArtifact } from "@tschk/moonshine-framework";
3
+ import { PUBLIC_DIR, type RouteArtifact } from "@tschk/moonshine-framework";
4
4
  import { toPosix } from "./path.js";
5
5
 
6
6
  export type BundleAsset = {
@@ -125,13 +125,14 @@ function toOutRelative(outDir: string, outputPath: string): string {
125
125
  async function buildBundleAssets(
126
126
  outDir: string,
127
127
  outputPaths: string[],
128
+ urlBase?: string,
128
129
  ): Promise<BundleAsset[]> {
129
130
  const assets: BundleAsset[] = [];
130
131
  for (const outputPath of outputPaths) {
131
132
  const file = toOutRelative(outDir, outputPath);
132
133
  assets.push({
133
134
  file,
134
- path: `/${file}`,
135
+ path: `/${toOutRelative(urlBase ?? outDir, outputPath)}`,
135
136
  integrity: await hashFile(outputPath),
136
137
  });
137
138
  }
@@ -159,6 +160,11 @@ export async function buildBundles(options: {
159
160
  const distDir = resolve(options.outDir, "dist");
160
161
  await mkdir(distDir, { recursive: true });
161
162
 
163
+ // Client output goes in its own directory because that directory is what the
164
+ // server exposes over HTTP; the server bundle must never sit inside it.
165
+ const publicDir = resolve(options.outDir, PUBLIC_DIR);
166
+ await mkdir(publicDir, { recursive: true });
167
+
162
168
  const serverOutputs = await runBuild(
163
169
  serverEntry,
164
170
  distDir,
@@ -166,11 +172,15 @@ export async function buildBundles(options: {
166
172
  "bun",
167
173
  );
168
174
  const clientOutputs = clientEntry
169
- ? await runBuild(clientEntry, distDir, options.root, "browser")
175
+ ? await runBuild(clientEntry, publicDir, options.root, "browser")
170
176
  : [];
171
177
 
172
178
  const serverAssets = await buildBundleAssets(options.outDir, serverOutputs);
173
- const clientAssets = await buildBundleAssets(options.outDir, clientOutputs);
179
+ const clientAssets = await buildBundleAssets(
180
+ options.outDir,
181
+ clientOutputs,
182
+ publicDir,
183
+ );
174
184
 
175
185
  return {
176
186
  server: serverAssets,
@@ -48,14 +48,19 @@ describe("buildProject", () => {
48
48
  ]);
49
49
  expect(manifest.routes.every((r) => r.runtime === "bun")).toBe(true);
50
50
  expect(manifest.entries.server).toBe("dist/server.js");
51
- expect(manifest.entries.client).toBe("/dist/client.js");
51
+ expect(manifest.entries.client).toBe("/client.js");
52
52
  expect(manifest.capabilities).toEqual(["islands", "streaming"]);
53
+ // Client assets build into public/ because that is the only directory the
54
+ // server exposes; the server bundle must stay outside it.
53
55
  expect(manifest.assets.map((a) => a.file)).toEqual([
54
- "dist/client.js",
55
56
  "dist/server.js",
57
+ "public/client.js",
56
58
  ]);
57
59
  for (const asset of manifest.assets) {
58
- expect(asset.path).toBe(`/${asset.file}`);
60
+ const served = asset.file.startsWith("public/");
61
+ expect(asset.path).toBe(
62
+ served ? `/${asset.file.slice("public/".length)}` : `/${asset.file}`,
63
+ );
59
64
  expect(asset.integrity).toMatch(/^sha256-[A-Za-z0-9+/]+=?$/);
60
65
  }
61
66