Skip to content

Commit 6a43321

Browse files
committed
BREAKING(core): merge FreshConfig and ResolvedFreshConfig
1 parent 56a82ee commit 6a43321

10 files changed

Lines changed: 31 additions & 40 deletions

File tree

docs/latest/concepts/plugins.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,8 @@ This hook is run at the start of the Fresh
133133
[ahead-of-time build task](/docs/concepts/ahead-of-time-builds). It may be
134134
synchronous or asynchronous.
135135

136-
The build start hook is called with the
137-
[`ResolvedFreshConfig`](https://deno.land/x/fresh/src/server/types.ts?s=ResolvedFreshConfig)
138-
object, which contains the full Fresh configuration.
136+
The build start hook is called with the `FreshConfig` object, which contains the
137+
full Fresh configuration.
139138

140139
This hook may be used to generate precompiled static assets. Any files saved to
141140
the `static` subfolder of `config.build.outDir` (typically `_fresh`) will be

plugin-tailwindcss/src/compiler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import postcss from "postcss";
33
import autoprefixer from "autoprefixer";
44
import * as path from "@std/path";
55
import type { TailwindPluginOptions } from "./types.ts";
6-
import type { ResolvedFreshConfig } from "fresh";
6+
import type { FreshConfig } from "fresh";
77

88
const CONFIG_EXTENSIONS = ["ts", "js", "mjs"];
99

@@ -37,7 +37,7 @@ async function findTailwindConfigFile(directory: string): Promise<string> {
3737
}
3838

3939
export async function initTailwind(
40-
config: ResolvedFreshConfig,
40+
config: FreshConfig,
4141
options: TailwindPluginOptions,
4242
): Promise<postcss.Processor> {
4343
const root = path.dirname(config.staticDir);

src/app.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ import {
1313
type Router,
1414
UrlPatternRouter,
1515
} from "./router.ts";
16-
import {
17-
type FreshConfig,
18-
normalizeConfig,
19-
type ResolvedFreshConfig,
20-
} from "./config.ts";
16+
import { type FreshConfig, normalizeConfig } from "./config.ts";
2117
import { type BuildCache, ProdBuildCache } from "./build_cache.ts";
2218
import type { ServerIslandRegistry } from "./context.ts";
2319
import { FinishSetup, ForgotBuild } from "./finish_setup.tsx";
@@ -73,9 +69,9 @@ export class App<State> {
7369
/**
7470
* The final resolved Fresh configuration.
7571
*/
76-
config: ResolvedFreshConfig;
72+
config: FreshConfig;
7773

78-
constructor(config: FreshConfig = {}) {
74+
constructor(config: Partial<FreshConfig> = {}) {
7975
this.config = normalizeConfig(config);
8076
}
8177

src/build_cache.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as path from "@std/path";
2-
import { getSnapshotPath, type ResolvedFreshConfig } from "./config.ts";
2+
import { type FreshConfig, getSnapshotPath } from "./config.ts";
33
import { DENO_DEPLOYMENT_ID, setBuildId } from "./runtime/build_id.ts";
44
import * as colors from "@std/fmt/colors";
55

@@ -29,7 +29,7 @@ export interface BuildCache {
2929
}
3030

3131
export class ProdBuildCache implements BuildCache {
32-
static async fromSnapshot(config: ResolvedFreshConfig, islandCount: number) {
32+
static async fromSnapshot(config: FreshConfig, islandCount: number) {
3333
const snapshotPath = getSnapshotPath(config);
3434

3535
const staticFiles = new Map<string, FileSnapshot>();
@@ -86,10 +86,10 @@ export class ProdBuildCache implements BuildCache {
8686

8787
#islands: Map<string, string>;
8888
#fileInfo: Map<string, FileSnapshot>;
89-
#config: ResolvedFreshConfig;
89+
#config: FreshConfig;
9090

9191
constructor(
92-
config: ResolvedFreshConfig,
92+
config: FreshConfig,
9393
islands: Map<string, string>,
9494
files: Map<string, FileSnapshot>,
9595
public hasSnapshot: boolean,

src/config.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,19 @@ import * as path from "@std/path";
22
import type { Mode } from "./runtime/server/mod.ts";
33

44
export interface FreshConfig {
5-
root?: string;
5+
root: string;
66
/**
77
* The directory to write generated files to when `dev.ts build` is run.
88
* This can be an absolute path, a file URL or a relative path.
99
*/
10-
buildOutDir?: string;
10+
buildOutDir: string;
1111
/**
1212
* Serve fresh from a base path instead of from the root.
1313
* "/foo/bar" -> http://localhost:8000/foo/bar
1414
* @default {undefined}
1515
*/
16-
basePath?: string;
17-
staticDir?: string;
18-
}
19-
20-
/**
21-
* The final resolved Fresh configuration where fields the user didn't specify are set to the default values.
22-
*/
23-
export interface ResolvedFreshConfig extends Required<FreshConfig> {
16+
basePath: string;
17+
staticDir: string;
2418
/**
2519
* Tells you in which mode Fresh is currently running in.
2620
*/
@@ -45,7 +39,9 @@ export function parseRootPath(root: string, cwd: string): string {
4539
return root;
4640
}
4741

48-
export function normalizeConfig(options: FreshConfig): ResolvedFreshConfig {
42+
export function normalizeConfig(
43+
options: Partial<FreshConfig>,
44+
): FreshConfig {
4945
const root = options.root
5046
? parseRootPath(options.root, Deno.cwd())
5147
: Deno.cwd();
@@ -59,6 +55,6 @@ export function normalizeConfig(options: FreshConfig): ResolvedFreshConfig {
5955
};
6056
}
6157

62-
export function getSnapshotPath(config: ResolvedFreshConfig): string {
58+
export function getSnapshotPath(config: FreshConfig): string {
6359
return path.join(config.buildOutDir, "snapshot.json");
6460
}

src/context.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from "preact";
88
import { renderToString } from "preact-render-to-string";
99
import { SpanStatusCode } from "@opentelemetry/api";
10-
import type { ResolvedFreshConfig } from "./config.ts";
10+
import type { FreshConfig } from "./config.ts";
1111
import type { BuildCache } from "./build_cache.ts";
1212
import {
1313
FreshScripts,
@@ -32,7 +32,7 @@ export type ServerIslandRegistry = Map<ComponentType, Island>;
3232
*/
3333
export interface FreshContext<State = unknown> {
3434
/** Reference to the resolved Fresh configuration */
35-
readonly config: ResolvedFreshConfig;
35+
readonly config: FreshConfig;
3636
readonly state: State;
3737
/** The original incoming `Request` object` */
3838
readonly req: Request;
@@ -90,7 +90,7 @@ export let getBuildCache: (ctx: FreshContext<unknown>) => BuildCache;
9090

9191
export class FreshReqContext<State>
9292
implements FreshContext<State>, PageProps<unknown, State> {
93-
config: ResolvedFreshConfig;
93+
config: FreshConfig;
9494
url: URL;
9595
req: Request;
9696
params: Record<string, string>;
@@ -116,7 +116,7 @@ export class FreshReqContext<State>
116116
url: URL,
117117
info: Deno.ServeHandlerInfo,
118118
params: Record<string, string>,
119-
config: ResolvedFreshConfig,
119+
config: FreshConfig,
120120
next: FreshContext<State>["next"],
121121
islandRegistry: ServerIslandRegistry,
122122
buildCache: BuildCache,

src/dev/dev_build_cache.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { BuildCache, StaticFile } from "../build_cache.ts";
22
import * as path from "@std/path";
33
import { SEPARATOR as WINDOWS_SEPARATOR } from "@std/path/windows/constants";
4-
import { getSnapshotPath, type ResolvedFreshConfig } from "../config.ts";
4+
import { type FreshConfig, getSnapshotPath } from "../config.ts";
55
import type { BuildSnapshot } from "../build_cache.ts";
66
import { encodeHex } from "@std/encoding/hex";
77
import { crypto } from "@std/crypto";
@@ -36,7 +36,7 @@ export class MemoryBuildCache implements DevBuildCache {
3636
#ready = Promise.withResolvers<void>();
3737

3838
constructor(
39-
public config: ResolvedFreshConfig,
39+
public config: FreshConfig,
4040
public buildId: string,
4141
public transformer: FreshFileTransformer,
4242
public target: string | string[],
@@ -160,7 +160,7 @@ export class DiskBuildCache implements DevBuildCache {
160160
#target: string | string[];
161161

162162
constructor(
163-
public config: ResolvedFreshConfig,
163+
public config: FreshConfig,
164164
public buildId: string,
165165
transformer: FreshFileTransformer,
166166
target: string | string[],

src/mod.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export type { RouteConfig } from "./types.ts";
1313
export type { Middleware, MiddlewareFn } from "./middlewares/mod.ts";
1414
export { staticFiles } from "./middlewares/static_files.ts";
1515
export type { Mode } from "./runtime/server/mod.ts";
16-
export type { FreshConfig, ResolvedFreshConfig } from "./config.ts";
16+
export type { FreshConfig } from "./config.ts";
1717
export type { FreshContext, Island, PageProps } from "./context.ts";
1818
export { createDefine, type Define } from "./define.ts";
1919
export type { Method } from "./router.ts";

src/test_utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { FreshReqContext } from "./context.ts";
22
import type { FsAdapter } from "./fs.ts";
33
import { type BuildCache, ProdBuildCache } from "./build_cache.ts";
4-
import type { ResolvedFreshConfig } from "./config.ts";
4+
import type { FreshConfig } from "./config.ts";
55
import type { WalkEntry } from "@std/fs/walk";
66
import { DEFAULT_CONN_INFO } from "./app.ts";
77

@@ -51,7 +51,7 @@ export class FakeServer {
5151
}
5252
}
5353

54-
const DEFAULT_CONFIG: ResolvedFreshConfig = {
54+
const DEFAULT_CONFIG: FreshConfig = {
5555
buildOutDir: "",
5656
mode: "production",
5757
basePath: "",
@@ -62,7 +62,7 @@ const DEFAULT_CONFIG: ResolvedFreshConfig = {
6262
export function serveMiddleware<T>(
6363
middleware: (ctx: FreshReqContext<T>) => Response | Promise<Response>,
6464
options: {
65-
config?: ResolvedFreshConfig;
65+
config?: FreshConfig;
6666
buildCache?: BuildCache;
6767
next?: () => Promise<Response>;
6868
} = {},

tests/islands_test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import { FakeServer } from "../src/test_utils.ts";
3434

3535
await buildProd(allIslandApp);
3636

37-
function testApp(config?: FreshConfig) {
37+
function testApp(config?: Partial<FreshConfig>) {
3838
const app = new App(config);
3939
setBuildCache(app, getBuildCache(allIslandApp));
4040
return app;

0 commit comments

Comments
 (0)