Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shorthand for IS_BUILD_MODE #2268

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
8 changes: 6 additions & 2 deletions src/dev/dev_command.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { updateCheck } from "./update_check.ts";
import { DAY, dirname, fromFileUrl, join, toFileUrl } from "./deps.ts";
import { FreshConfig, Manifest as ServerManifest } from "../server/mod.ts";
import {
FreshConfig,
IS_BUILD_MODE,
Manifest as ServerManifest,
} from "../server/mod.ts";
import { build } from "./build.ts";
import { collect, ensureMinDenoVersion, generate, Manifest } from "./mod.ts";
import { startServer } from "../server/boot.ts";
Expand Down Expand Up @@ -38,7 +42,7 @@ export async function dev(
const manifest = (await import(toFileUrl(join(dir, "fresh.gen.ts")).href))
.default as ServerManifest;

if (Deno.args.includes("build")) {
if (IS_BUILD_MODE) {
const state = await getInternalFreshState(
manifest,
config ?? {},
Expand Down
1 change: 1 addition & 0 deletions src/server/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export type {
export { RenderContext } from "./render.ts";
export type { InnerRenderFunction } from "./render.ts";
export type { DestinationKind } from "./router.ts";
export { IS_BUILD_MODE } from "./utils.ts";

export interface Manifest {
routes: Record<
Expand Down
17 changes: 17 additions & 0 deletions src/server/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Returns true when the current process deno run process is building. This is used to guard build-dependent code.
* Shorthand for the following:
* `Deno.args.includes("build")`
*
* @example
* ```
* if (IS_BUILD_MODE) {
* console.log('This is code run during build!');
* } else {
* console.log('This is code run without build!');
* }
* ```
*
* Use this to restrict aspects of code from running during ahead of time builds.
*/
export const IS_BUILD_MODE = Deno.args.includes("build");
Loading