Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 5 additions & 82 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions src/app_test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,7 @@ Deno.test.ignore("App - finish setup", async () => {
app,
await ProdBuildCache.fromSnapshot({
...app.config,
build: {
outDir: "foo",
},
buildOutDir: "foo",
}, getIslandRegistry(app).size),
);

Expand Down
2 changes: 1 addition & 1 deletion src/build_cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class ProdBuildCache implements BuildCache {
if (info === undefined) return null;

const base = info.generated
? this.#config.build.outDir
? this.#config.buildOutDir
: this.#config.staticDir;
const filePath = info.generated
? path.join(base, "static", pathname)
Expand Down
4 changes: 1 addition & 3 deletions src/build_cache_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ Deno.test({
mode: "production",
basePath: "/",
staticDir: path.join(tmp, "static"),
build: {
outDir: path.join(tmp, "dist"),
},
buildOutDir: path.join(tmp, "dist"),
};
await Deno.mkdir(path.join(tmp, "static", ".well-known"), {
recursive: true,
Expand Down
36 changes: 11 additions & 25 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ export interface FreshConfig {
* @default Deno.cwd()
*/
root?: string;
build?: {
/**
* The directory to write generated files to when `dev.ts build` is run.
*
* This can be an absolute path, a file URL or a relative path.
* Relative paths are resolved against the `root` option.
* @default "_fresh"
*/
outDir?: string;
};
/**
* The directory to write generated files to when `dev.ts build` is run.
*
* This can be an absolute path, a file URL or a relative path.
* Relative paths are resolved against the `root` option.
* @default "_fresh"
*/
buildOutDir?: string;
/**
* Serve fresh from a base path instead of from the root.
* "/foo/bar" -> http://localhost:8000/foo/bar
Expand All @@ -38,17 +36,7 @@ export interface FreshConfig {
/**
* The final resolved Fresh configuration where fields the user didn't specify are set to the default values.
*/
export interface ResolvedFreshConfig {
root: string;
build: {
outDir: string;
};
/**
* Serve fresh from a base path instead of from the root.
* "/foo/bar" -> http://localhost:8000/foo/bar
*/
basePath: string;
staticDir: string;
export interface ResolvedFreshConfig extends Required<FreshConfig> {
/**
* The mode Fresh can run in.
*/
Expand Down Expand Up @@ -92,15 +80,13 @@ export function normalizeConfig(options: FreshConfig): ResolvedFreshConfig {

return {
root,
build: {
outDir: parseDirPath(options.build?.outDir ?? "_fresh", root),
},
buildOutDir: parseDirPath(options.buildOutDir ?? "_fresh", root),
basePath: options.basePath ?? "",
staticDir: parseDirPath(options.staticDir ?? "static", root),
mode: "production",
};
}

export function getSnapshotPath(config: ResolvedFreshConfig): string {
return path.join(config.build.outDir, "snapshot.json");
return path.join(config.buildOutDir, "snapshot.json");
}
13 changes: 6 additions & 7 deletions src/config_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,30 +49,29 @@ Deno.test("normalizeConfig - root", () => {

Deno.test("normalizeConfig - build.outDir", () => {
const cwd = Deno.cwd().replaceAll("\\", "/");
const outDir = (options: FreshConfig) =>
normalizeConfig(options).build.outDir;
const outDir = (options: FreshConfig) => normalizeConfig(options).buildOutDir;

// Default outDir
expect(outDir({ root: "./src" })).toEqual(`${cwd}/src/_fresh`);
expect(outDir({ root: "/src" })).toEqual("/src/_fresh");
expect(outDir({ root: "file:///src" })).toEqual("/src/_fresh");

// Relative outDir
expect(outDir({ root: "/src", build: { outDir: "dist" } })).toEqual(
expect(outDir({ root: "/src", buildOutDir: "dist" })).toEqual(
"/src/dist",
);
expect(outDir({ root: "/src", build: { outDir: "./dist" } })).toEqual(
expect(outDir({ root: "/src", buildOutDir: "./dist" })).toEqual(
"/src/dist",
);

// Absolute outDir
expect(outDir({ root: "/src", build: { outDir: "/dist" } })).toEqual(
expect(outDir({ root: "/src", buildOutDir: "/dist" })).toEqual(
"/dist",
);
expect(outDir({ root: "/src", build: { outDir: "/dist/fresh" } })).toEqual(
expect(outDir({ root: "/src", buildOutDir: "/dist/fresh" })).toEqual(
"/dist/fresh",
);
expect(outDir({ root: "/src", build: { outDir: "file:///dist" } })).toEqual(
expect(outDir({ root: "/src", buildOutDir: "file:///dist" })).toEqual(
"/dist",
);
});
Expand Down
6 changes: 3 additions & 3 deletions src/dev/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ export class Builder {
}

async #build<T>(app: App<T>, dev: boolean): Promise<void> {
const { build } = app.config;
const staticOutDir = path.join(build.outDir, "static");
const { buildOutDir } = app.config;
const staticOutDir = path.join(buildOutDir, "static");

if (!this.#addedInternalTransforms) {
this.#addedInternalTransforms = true;
Expand Down Expand Up @@ -209,7 +209,7 @@ export class Builder {
if (!dev) {
// deno-lint-ignore no-console
console.log(
`Assets written to: ${colors.cyan(build.outDir)}`,
`Assets written to: ${colors.cyan(buildOutDir)}`,
);
}
}
Expand Down
Loading
Loading