feat: remove MODE global (#2483)
This commit is contained in:
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
import * as path from "@std/path";
|
import * as path from "@std/path";
|
||||||
import { MODE, type Mode } from "./runtime/server/mod.ts";
|
import type { Mode } from "./runtime/server/mod.ts";
|
||||||
|
|
||||||
export interface FreshPlugin {
|
export interface FreshPlugin {
|
||||||
name: string;
|
name: string;
|
||||||
@@ -69,7 +69,7 @@ export function normalizeConfig(options: FreshConfig): ResolvedFreshConfig {
|
|||||||
},
|
},
|
||||||
basePath: options.basePath ?? "",
|
basePath: options.basePath ?? "",
|
||||||
staticDir: options.staticDir ?? path.join(root, "static"),
|
staticDir: options.staticDir ?? path.join(root, "static"),
|
||||||
mode: MODE,
|
mode: "production",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-1
@@ -70,6 +70,8 @@ export class Builder implements FreshBuilder {
|
|||||||
.use(devErrorOverlay())
|
.use(devErrorOverlay())
|
||||||
.mountApp("*", app);
|
.mountApp("*", app);
|
||||||
|
|
||||||
|
devApp.config.mode = "development";
|
||||||
|
|
||||||
setBuildCache(
|
setBuildCache(
|
||||||
devApp,
|
devApp,
|
||||||
new MemoryBuildCache(
|
new MemoryBuildCache(
|
||||||
@@ -97,6 +99,7 @@ export class Builder implements FreshBuilder {
|
|||||||
this.#options.target,
|
this.#options.target,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
return await this.#build(app, false);
|
return await this.#build(app, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,7 +120,9 @@ export class Builder implements FreshBuilder {
|
|||||||
// Ignore
|
// Ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
const buildCache = getBuildCache(app)! as MemoryBuildCache | DiskBuildCache;
|
const buildCache = getBuildCache(app)! as
|
||||||
|
| MemoryBuildCache
|
||||||
|
| DiskBuildCache;
|
||||||
|
|
||||||
const runtimePath = dev
|
const runtimePath = dev
|
||||||
? "../runtime/client/dev.ts"
|
? "../runtime/client/dev.ts"
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
import { setMode } from "../runtime/server/mod.ts";
|
|
||||||
|
|
||||||
export { Builder, type FreshBuilder } from "./builder.ts";
|
export { Builder, type FreshBuilder } from "./builder.ts";
|
||||||
export {
|
export {
|
||||||
type OnTransformArgs,
|
type OnTransformArgs,
|
||||||
type OnTransformOptions,
|
type OnTransformOptions,
|
||||||
type TransformFn,
|
type TransformFn,
|
||||||
} from "./file_transformer.ts";
|
} from "./file_transformer.ts";
|
||||||
|
|
||||||
setMode("development");
|
|
||||||
|
|||||||
@@ -1,9 +1,4 @@
|
|||||||
/**
|
/**
|
||||||
* The mode Fresh can run in.
|
* The mode Fresh can run in.
|
||||||
*/
|
*/
|
||||||
export type Mode = "development" | "build" | "production";
|
export type Mode = "development" | "production";
|
||||||
export let MODE: Mode = "production";
|
|
||||||
|
|
||||||
export function setMode(mode: Mode) {
|
|
||||||
MODE = mode;
|
|
||||||
}
|
|
||||||
|
|||||||
+51
-48
@@ -2,6 +2,7 @@ import VERSIONS from "../versions.json" with { type: "json" };
|
|||||||
import { app } from "./main.ts";
|
import { app } from "./main.ts";
|
||||||
import { buildProd, withBrowserApp } from "../tests/test_utils.tsx";
|
import { buildProd, withBrowserApp } from "../tests/test_utils.tsx";
|
||||||
import { expect } from "@std/expect";
|
import { expect } from "@std/expect";
|
||||||
|
import { retry } from "@std/async/retry";
|
||||||
|
|
||||||
const handler = await app.handler();
|
const handler = await app.handler();
|
||||||
|
|
||||||
@@ -17,62 +18,64 @@ Deno.test("CORS should not set on GET /fresh-badge.svg", async () => {
|
|||||||
Deno.test({
|
Deno.test({
|
||||||
name: "shows version selector",
|
name: "shows version selector",
|
||||||
fn: async () => {
|
fn: async () => {
|
||||||
await withBrowserApp(app, async (page, address) => {
|
await retry(async () => {
|
||||||
await page.goto(`${address}/docs`);
|
await withBrowserApp(app, async (page, address) => {
|
||||||
await page.waitForSelector("#version");
|
await page.goto(`${address}/docs`);
|
||||||
|
await page.waitForSelector("#version");
|
||||||
|
|
||||||
// Check that we redirected to the first page
|
// Check that we redirected to the first page
|
||||||
await page.waitForFunction(() => {
|
await page.waitForFunction(() => {
|
||||||
const url = new URL(window.location.href);
|
const url = new URL(window.location.href);
|
||||||
return url.pathname === "/docs/introduction";
|
return url.pathname === "/docs/introduction";
|
||||||
});
|
|
||||||
|
|
||||||
// Wait for version selector to be enabled
|
|
||||||
await page.waitForSelector("#version:not([disabled])");
|
|
||||||
|
|
||||||
const options = await page
|
|
||||||
.locator<HTMLSelectElement>("#version")
|
|
||||||
.evaluate((el) => {
|
|
||||||
return Array.from(el.options).map((option) => ({
|
|
||||||
value: option.value,
|
|
||||||
label: option.textContent,
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(options).toEqual([
|
// Wait for version selector to be enabled
|
||||||
{
|
await page.waitForSelector("#version:not([disabled])");
|
||||||
value: "canary",
|
|
||||||
label: "canary",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: "latest",
|
|
||||||
label: VERSIONS[0],
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
const selectValue = await page
|
const options = await page
|
||||||
.locator<HTMLSelectElement>("#version")
|
.locator<HTMLSelectElement>("#version")
|
||||||
.evaluate((el) => el.value);
|
.evaluate((el) => {
|
||||||
expect(selectValue).toEqual("latest");
|
return Array.from(el.options).map((option) => ({
|
||||||
|
value: option.value,
|
||||||
|
label: option.textContent,
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
// Go to canary page
|
expect(options).toEqual([
|
||||||
await page.evaluate(() => {
|
{
|
||||||
const el = document.querySelector("#version") as HTMLSelectElement;
|
value: "canary",
|
||||||
el.value = "canary";
|
label: "canary",
|
||||||
el.dispatchEvent(new Event("change"));
|
},
|
||||||
});
|
{
|
||||||
|
value: "latest",
|
||||||
|
label: VERSIONS[0],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
await new Promise((r) => setTimeout(r, 1000));
|
const selectValue = await page
|
||||||
|
.locator<HTMLSelectElement>("#version")
|
||||||
|
.evaluate((el) => el.value);
|
||||||
|
expect(selectValue).toEqual("latest");
|
||||||
|
|
||||||
await page.waitForSelector("#version:not([disabled])");
|
// Go to canary page
|
||||||
const selectValue2 = await page
|
await page.evaluate(() => {
|
||||||
.locator<HTMLSelectElement>("#version")
|
const el = document.querySelector("#version") as HTMLSelectElement;
|
||||||
.evaluate((el) => el.value);
|
el.value = "canary";
|
||||||
expect(selectValue2).toEqual("canary");
|
el.dispatchEvent(new Event("change"));
|
||||||
|
});
|
||||||
|
|
||||||
await page.waitForFunction(() => {
|
await new Promise((r) => setTimeout(r, 1000));
|
||||||
const url = new URL(window.location.href);
|
|
||||||
return url.pathname === "/docs/canary/introduction";
|
await page.waitForSelector("#version:not([disabled])");
|
||||||
|
const selectValue2 = await page
|
||||||
|
.locator<HTMLSelectElement>("#version")
|
||||||
|
.evaluate((el) => el.value);
|
||||||
|
expect(selectValue2).toEqual("canary");
|
||||||
|
|
||||||
|
await page.waitForFunction(() => {
|
||||||
|
const url = new URL(window.location.href);
|
||||||
|
return url.pathname === "/docs/canary/introduction";
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user