feat: add error messages for missing build cache (#2551)
This commit is contained in:
+4
-1
@@ -171,7 +171,10 @@ export class App<State> {
|
||||
(request: Request, info?: Deno.ServeHandlerInfo) => Promise<Response>
|
||||
> {
|
||||
if (this.#buildCache === null) {
|
||||
this.#buildCache = await ProdBuildCache.fromSnapshot(this.config);
|
||||
this.#buildCache = await ProdBuildCache.fromSnapshot(
|
||||
this.config,
|
||||
this.#islandRegistry.size,
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
import { expect } from "@std/expect";
|
||||
import { App, setBuildCache } from "./app.ts";
|
||||
import { App, getIslandRegistry, setBuildCache } from "./app.ts";
|
||||
import { FakeServer } from "./test_utils.ts";
|
||||
import { ProdBuildCache } from "./build_cache.ts";
|
||||
|
||||
@@ -429,7 +429,7 @@ Deno.test.ignore("FreshApp - finish setup", async () => {
|
||||
build: {
|
||||
outDir: "foo",
|
||||
},
|
||||
}),
|
||||
}, getIslandRegistry(app).size),
|
||||
);
|
||||
|
||||
const server = new FakeServer(await app.handler());
|
||||
|
||||
+25
-3
@@ -1,6 +1,7 @@
|
||||
import * as path from "@std/path";
|
||||
import type { ResolvedFreshConfig } from "./config.ts";
|
||||
import { setBuildId } from "./runtime/build_id.ts";
|
||||
import { DENO_DEPLOYMENT_ID, setBuildId } from "./runtime/build_id.ts";
|
||||
import * as colors from "@std/fmt/colors";
|
||||
|
||||
export interface FileSnapshot {
|
||||
generated: boolean;
|
||||
@@ -28,7 +29,7 @@ export interface BuildCache {
|
||||
}
|
||||
|
||||
export class ProdBuildCache implements BuildCache {
|
||||
static async fromSnapshot(config: ResolvedFreshConfig) {
|
||||
static async fromSnapshot(config: ResolvedFreshConfig, islandCount: number) {
|
||||
const snapshotPath = path.join(config.build.outDir, "snapshot.json");
|
||||
|
||||
const staticFiles = new Map<string, FileSnapshot>();
|
||||
@@ -53,8 +54,29 @@ export class ProdBuildCache implements BuildCache {
|
||||
const pathname = islands[i];
|
||||
islandToChunk.set(pathname, snapshot.islands[pathname]);
|
||||
}
|
||||
|
||||
if (!DENO_DEPLOYMENT_ID) {
|
||||
// deno-lint-ignore no-console
|
||||
console.log(
|
||||
`Found snapshot at ${colors.cyan(snapshotPath)}`,
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
if (!(err instanceof Deno.errors.NotFound)) {
|
||||
if ((err instanceof Deno.errors.NotFound)) {
|
||||
if (islandCount > 0) {
|
||||
throw new Error(
|
||||
`Found ${
|
||||
colors.green(`${islandCount} islands`)
|
||||
}, but did not find build snapshot at:\n${
|
||||
colors.red(snapshotPath)
|
||||
}.\n\nMaybe your forgot to run ${
|
||||
colors.cyan("deno task build")
|
||||
} before starting the production server\nor maybe you wanted to run ${
|
||||
colors.cyan("deno task dev")
|
||||
} to spin up a development server instead?\n`,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user