fix: dev command loading snapshot (#1735)
This commit is contained in:
+27
-3
@@ -1,8 +1,13 @@
|
||||
import { updateCheck } from "./update_check.ts";
|
||||
import { DAY, dirname, fromFileUrl, join } from "./deps.ts";
|
||||
import { FreshOptions } from "../server/mod.ts";
|
||||
import { DAY, dirname, fromFileUrl, fs, join, toFileUrl } from "./deps.ts";
|
||||
import {
|
||||
FreshOptions,
|
||||
Manifest as ServerManifest,
|
||||
ServerContext,
|
||||
} from "../server/mod.ts";
|
||||
import { build } from "./build.ts";
|
||||
import { collect, ensureMinDenoVersion, generate, Manifest } from "./mod.ts";
|
||||
import { startFromContext } from "../server/boot.ts";
|
||||
|
||||
export async function dev(
|
||||
base: string,
|
||||
@@ -34,9 +39,28 @@ export async function dev(
|
||||
|
||||
if (manifestChanged) await generate(dir, newManifest);
|
||||
|
||||
if (Deno.args.includes("build")) {
|
||||
const manifest = (await import(toFileUrl(join(dir, "fresh.gen.ts")).href))
|
||||
.default as ServerManifest;
|
||||
|
||||
const outDir = join(dir, "_fresh");
|
||||
|
||||
const isBuild = Deno.args.includes("build");
|
||||
const ctx = await ServerContext.fromManifest(manifest, {
|
||||
...options,
|
||||
skipSnapshot: true,
|
||||
dev: !isBuild,
|
||||
});
|
||||
|
||||
if (isBuild) {
|
||||
// Ensure that build dir is empty
|
||||
await fs.emptyDir(outDir);
|
||||
await build(join(dir, "fresh.gen.ts"), options);
|
||||
} else if (options) {
|
||||
await startFromContext(ctx, options);
|
||||
} else {
|
||||
// Legacy entry point: Back then `dev.ts` would call `main.ts` but
|
||||
// this causes duplicate plugin instantiation if both `dev.ts` and
|
||||
// `main.ts` instantiate plugins.
|
||||
await import(entrypoint);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user