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

fix: $fresh ref in import sources #2340

Merged
merged 14 commits into from
Mar 12, 2024
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
2 changes: 1 addition & 1 deletion src/server/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import { loadAotSnapshot } from "../build/aot_snapshot.ts";
import { ErrorOverlay } from "./error_overlay.tsx";
import { withBase } from "./router.ts";
import { PARTIAL_SEARCH_PARAM } from "../constants.ts";
import TailwindErrorPage from "$fresh/src/server/tailwind_aot_error_page.tsx";
import TailwindErrorPage from "./tailwind_aot_error_page.tsx";

const DEFAULT_CONN_INFO: ServeHandlerInfo = {
localAddr: { transport: "tcp", hostname: "localhost", port: 8080 },
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
2 changes: 1 addition & 1 deletion src/server/rendering/template.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from "preact";
import { HEAD_CONTEXT } from "../../runtime/head.ts";
import { CSP_CONTEXT } from "../../runtime/csp.ts";
import { withBase } from "$fresh/src/server/router.ts";
import { withBase } from "../router.ts";

export function renderHtml(state: RenderState) {
setRenderState(state);
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