feat: update for Deno 2 (#2655)

Co-authored-by: Luca Casonato <hello@lcas.dev>
This commit is contained in:
Marvin Hagemeister
2024-09-30 18:30:30 +02:00
committed by GitHub
co-authored by Luca Casonato
parent b5389f69a3
commit de8f1b0c59
32 changed files with 3836 additions and 3194 deletions
+1 -2
View File
@@ -1,8 +1,7 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
# Check for updates to GitHub Actions every week
interval: "weekly"
interval: "weekly"
+8 -8
View File
@@ -14,15 +14,15 @@ jobs:
strategy:
fail-fast: false
matrix:
deno: ["canary", "v1.x"]
deno: ["canary", "rc"]
os: [macOS-latest, windows-latest, ubuntu-latest]
include:
- os: ubuntu-latest
cache_path: ~/.cache/deno/
- os: macos-latest
cache_path: ~/Library/Caches/deno/
- os: windows-latest
cache_path: ~\AppData\Local\deno\
- os: ubuntu-latest
cache_path: ~/.cache/deno/
- os: macos-latest
cache_path: ~/Library/Caches/deno/
- os: windows-latest
cache_path: ~\AppData\Local\deno\
steps:
- name: Checkout repo
@@ -44,7 +44,7 @@ jobs:
- name: Spell-check
if: startsWith(matrix.os, 'ubuntu') && matrix.deno == 'v1.x'
uses: crate-ci/typos@master
- name: Type check project
run: deno task check:types
+1 -1
View File
@@ -21,7 +21,7 @@ jobs:
- name: Install Deno
uses: denoland/setup-deno@v1
with:
deno-version: v1.x
deno-version: rc
- name: Build step
working-directory: ./www
+2 -2
View File
@@ -18,8 +18,8 @@ jobs:
- name: Install Deno
uses: denoland/setup-deno@v1
with:
deno-version: v1.x
deno-version: rc
- name: Publish Fresh
run: deno publish
+10 -9
View File
@@ -33,8 +33,7 @@
},
"imports": {
"$ga4": "https://raw.githubusercontent.com/denoland/ga4/main/mod.ts",
"$marked-mangle": "https://esm.sh/marked-mangle@1.0.1",
"@astral/astral": "jsr:@astral/astral@^0.4.0",
"@astral/astral": "jsr:@astral/astral@^0.4.6",
"@fresh/plugin-tailwind": "./plugin-tailwindcss/src/mod.ts",
"@luca/esbuild-deno-loader": "jsr:@luca/esbuild-deno-loader@^0.10.3",
"@marvinh-test/fresh-island": "jsr:@marvinh-test/fresh-island@^0.0.1",
@@ -56,21 +55,23 @@
"@std/streams": "jsr:@std/streams@^0.224.3",
"autoprefixer": "npm:autoprefixer@10.4.17",
"cssnano": "npm:cssnano@6.0.3",
"esbuild": "npm:esbuild@0.20.2",
"esbuild-wasm": "npm:esbuild-wasm@0.20.2",
"esbuild": "npm:esbuild@0.23.1",
"esbuild-wasm": "npm:esbuild-wasm@0.23.1",
"fresh": "./src/mod.ts",
"fresh/compat": "./src/compat/mod.ts",
"fresh/dev": "./src/dev/mod.ts",
"fresh/runtime": "./src/runtime/shared.ts",
"github-slugger": "npm:github-slugger@^2.0.0",
"linkedom": "npm:linkedom@^0.16.11",
"marked": "npm:marked@^14.1.2",
"marked-mangle": "npm:marked-mangle@^1.1.9",
"postcss": "npm:postcss@8.4.35",
"preact": "npm:preact@^10.22.0",
"preact-render-to-string": "npm:preact-render-to-string@^6.4.2",
"preact": "npm:preact@^10.24.0",
"preact-render-to-string": "npm:preact-render-to-string@^6.5.11",
"prismjs": "npm:prismjs@^1.29.0",
"tailwindcss": "npm:tailwindcss@^3.4.1",
"tailwindcss/plugin": "npm:/tailwindcss@^3.4.1/plugin.js",
"ts-morph": "npm:ts-morph@^22.0.0",
"twind": "https://esm.sh/twind@0.16.19",
"twind/": "https://esm.sh/twind@0.16.19/"
"ts-morph": "npm:ts-morph@^22.0.0"
},
"compilerOptions": {
"lib": ["dom", "dom.asynciterable", "deno.ns"],
Generated
+1445 -1653
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -21,12 +21,12 @@ providing a native way to visually differentiate the active link.
```css
/* Give links pointing to the current page a green color */
a[aria-current='page'] {
a[aria-current="page"] {
color: green;
}
/* Color all ancestor links of the current page */
a[aria-current='true'] {
a[aria-current="true"] {
color: peachpuff;
}
```
@@ -75,12 +75,12 @@ export default {
5. Update your `deno.json` file and add the following `tailwindcss` imports. To
make the
[vscode Tailwind CSS extension](https://marketplace.visualstudio.com/items?itemName=bradlc.vscode-tailwindcss)
work, we also need to set `"nodeModulesDir": true`. This will create a
work, we also need to set `"nodeModulesDir": "auto"`. This will create a
`node_modules` directory in your project folder:
```diff deno.json
{
+ "nodeModulesDir": true,
+ "nodeModulesDir": "auto",
"imports": {
"$fresh/": "https://deno.land/x/fresh@1.5.2/",
"preact": "https://esm.sh/preact@10.22.0",
@@ -106,7 +106,7 @@ That's it! Now you can use Tailwind CSS in your project.
> [info]: If you're a vscode user, be sure to install the
> [official Tailwind CSS extension](https://marketplace.visualstudio.com/items?itemName=bradlc.vscode-tailwindcss)
> to get full intellisense support. For it to work you also need to set
> `"nodeModulesDir": true` in your `deno.json`.
> `"nodeModulesDir": "auto"` in your `deno.json`.
> [warn]: Tailwind CSS doesn't support the grouping syntax from twind:
> `text(lg uppercase gray-100)`. These need to be rewritten to their expanded
+49 -18
View File
@@ -15,6 +15,18 @@ export const enum InitStep {
Docker = "Docker",
}
function css(strs: TemplateStringsArray, ...exprs: string[]): string {
let out = "";
for (let i = 0; i < exprs.length; i++) {
out += strs[i];
out += String(exprs[i]);
}
out += strs.at(-1) ?? "";
return out;
}
export class InitError extends Error {}
function error(tty: MockTTY, message: string): never {
@@ -203,15 +215,17 @@ export default {
await writeFile("tailwind.config.ts", TAILWIND_CONFIG_TS);
}
const GRADIENT_CSS = `
.fresh-gradient {
background-color: rgb(134, 239, 172);
background-image: linear-gradient(to right bottom, rgb(219, 234, 254), rgb(187, 247, 208), rgb(254, 249, 195));
}
`;
const GRADIENT_CSS = css`.fresh-gradient {
background-color: rgb(134, 239, 172);
background-image: linear-gradient(
to right bottom,
rgb(219, 234, 254),
rgb(187, 247, 208),
rgb(254, 249, 195)
);
}`;
const NO_TAILWIND_STYLES = `
*,
const NO_TAILWIND_STYLES = css`*,
*::before,
*::after {
box-sizing: border-box;
@@ -226,8 +240,15 @@ button, [role="button"] {
cursor: pointer;
}
code {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
"Liberation Mono", "Courier New", monospace;
font-family:
ui-monospace,
SFMono-Regular,
Menlo,
Monaco,
Consolas,
"Liberation Mono",
"Courier New",
monospace;
font-size: 1em;
}
img,
@@ -243,9 +264,21 @@ video {
html {
line-height: 1.5;
-webkit-text-size-adjust: 100%;
font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif,
"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
font-family:
ui-sans-serif,
system-ui,
-apple-system,
BlinkMacSystemFont,
"Segoe UI",
Roboto,
"Helvetica Neue",
Arial,
"Noto Sans",
sans-serif,
"Apple Color Emoji",
"Segoe UI Emoji",
"Segoe UI Symbol",
"Noto Color Emoji";
}
.transition-colors {
transition-property: background-color, border-color, color, fill, stroke;
@@ -340,14 +373,12 @@ html {
font-variant-numeric: tabular-nums;
}
${GRADIENT_CSS}
`;
${GRADIENT_CSS}`;
const TAILWIND_CSS = `@tailwind base;
const TAILWIND_CSS = css`@tailwind base;
@tailwind components;
@tailwind utilities;
${GRADIENT_CSS}
`;
${GRADIENT_CSS}`;
const cssStyles = useTailwind ? TAILWIND_CSS : NO_TAILWIND_STYLES;
await writeFile("static/styles.css", cssStyles);
+23 -9
View File
@@ -35,9 +35,15 @@ const DEFAULT_NOT_ALLOWED_METHOD = () => {
throw new HttpError(405);
};
export type ListenOptions = Partial<Deno.ServeTlsOptions> & {
remoteAddress?: string;
};
export type ListenOptions =
& Partial<
Deno.ServeTcpOptions & Deno.TlsCertifiedKeyPem
>
& {
remoteAddress?: string;
};
Deno.serve;
export let getRouter: <State>(app: App<State>) => Router<MiddlewareFn<State>>;
// deno-lint-ignore no-explicit-any
@@ -186,8 +192,7 @@ export class App<State> {
return async (
req: Request,
conn: Deno.ServeHandlerInfo | Deno.ServeUnixHandlerInfo =
DEFAULT_CONN_INFO,
conn: Deno.ServeHandlerInfo = DEFAULT_CONN_INFO,
) => {
const url = new URL(req.url);
// Prevent open redirect attacks
@@ -237,11 +242,20 @@ export class App<State> {
if (!options.onListen) {
options.onListen = (params) => {
const pathname = (this.config.basePath) + "/";
const protocol = options.key && options.cert ? "https:" : "http:";
const protocol = "key" in options && options.key && options.cert
? "https:"
: "http:";
let hostname = params.hostname;
// Windows being windows...
if (
Deno.build.os === "windows" &&
(hostname === "0.0.0.0" || hostname === "::")
) {
hostname = "localhost";
}
// Work around https://github.com/denoland/deno/issues/23650
const hostname = params.hostname.startsWith("::")
? `[${params.hostname}]`
: params.hostname;
hostname = hostname.startsWith("::") ? `[${hostname}]` : hostname;
const address = colors.cyan(
`${protocol}//${hostname}:${params.port}${pathname}`,
);
+3 -3
View File
@@ -42,7 +42,7 @@ export interface FreshContext<State = unknown> {
readonly url: URL;
readonly params: Record<string, string>;
readonly error: unknown;
readonly info: Deno.ServeHandlerInfo | Deno.ServeUnixHandlerInfo;
readonly info: Deno.ServeHandlerInfo;
/**
* Return a redirect response to the specified path. This is the
* preferred way to do redirects in Fresh.
@@ -95,7 +95,7 @@ export class FreshReqContext<State>
state: State = {} as State;
data: unknown = undefined;
error: unknown | null = null;
info: Deno.ServeHandlerInfo | Deno.ServeUnixHandlerInfo;
info: Deno.ServeHandlerInfo | Deno.ServeHandlerInfo;
next: FreshContext<State>["next"];
@@ -112,7 +112,7 @@ export class FreshReqContext<State>
constructor(
req: Request,
url: URL,
info: Deno.ServeHandlerInfo | Deno.ServeUnixHandlerInfo,
info: Deno.ServeHandlerInfo,
params: Record<string, string>,
config: ResolvedFreshConfig,
next: FreshContext<State>["next"],
+6
View File
@@ -40,6 +40,8 @@ Deno.test({
expect(logs).toEqual(["A", "B", "C"]);
},
sanitizeOps: false,
sanitizeResources: false,
});
Deno.test({
@@ -64,6 +66,8 @@ Deno.test({
);
expect(css).toContain('body { background: url("/foo.jpg?__frsh_c=');
},
sanitizeOps: false,
sanitizeResources: false,
});
Deno.test({
@@ -87,4 +91,6 @@ Deno.test({
);
expect(code).toContain('"remote-island"');
},
sanitizeOps: false,
sanitizeResources: false,
});
+6 -15
View File
@@ -131,20 +131,6 @@ export async function bundleJs(
}
if (!options.dev) {
// deno-lint-ignore no-deprecated-deno-api
const children = Object.values(Deno.resources())
.filter((name) => name === "child").length;
await esbuild!.stop();
// To work around a bug in ESBuild, where it doesn't wait for the child
// process to shut down before exiting, we manually wait for the process to
// exit before continuing.
while (
// deno-lint-ignore no-deprecated-deno-api
Object.values(Deno.resources())
.filter((name) => name === "child").length >= children
) {
await new Promise((r) => setTimeout(r, 100));
}
esbuild = null;
}
@@ -155,12 +141,17 @@ export async function bundleJs(
};
}
let initialized = false;
export async function startEsbuild() {
esbuild = Deno.env.get("FRESH_ESBUILD_LOADER") === "portable"
? await import("esbuild-wasm")
: await import("esbuild");
await esbuild.initialize({});
if (!initialized) {
await esbuild.initialize({});
initialized = true;
}
}
function buildIdPlugin(buildId: string): EsbuildPlugin {
+2 -1
View File
@@ -105,10 +105,11 @@ export async function updateCheck(
checkFile.latest_version = await getLatestVersion();
checkFile.last_checked = new Date().toISOString();
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
// Update check is optional and shouldn't abort the program.
// deno-lint-ignore no-console
console.error(
colors.red(` Update check failed: `) + err.message,
colors.red(` Update check failed: `) + message,
);
return;
}
+6 -4
View File
@@ -15,6 +15,11 @@ export type AsyncAnyComponent<P> = {
defaultProps?: Partial<P> | undefined;
};
// deno-lint-ignore no-explicit-any
export function isAsyncAnyComponent(fn: any): fn is AsyncAnyComponent<any> {
return typeof fn === "function" && fn.constructor.name === "AsyncFunction";
}
export function renderMiddleware<State>(
components: Array<
| AnyComponent<PageProps<unknown, State>>
@@ -50,10 +55,7 @@ export function renderMiddleware<State>(
const fn = components[i];
if (
typeof fn === "function" &&
fn.constructor.name === "AsyncFunction"
) {
if (isAsyncAnyComponent(fn)) {
const result = (await fn(props)) as VNode | Response;
if (result instanceof Response) {
return result;
+1 -1
View File
@@ -60,7 +60,7 @@ export const ACTIVE_PARTIALS = new Map<string, PartialComp>();
export class PartialComp extends Component<
{ children?: ComponentChildren; mode: PartialMode; name: string }
> {
componentDidMount() {
override componentDidMount() {
ACTIVE_PARTIALS.set(this.props.name, this);
}
+57 -50
View File
@@ -33,62 +33,67 @@ function testApp<T>(): App<T> {
return app;
}
Deno.test("active links - without client nav", async () => {
function View() {
return (
<Doc>
<div>
<h1>nav</h1>
<p>
<a href="/active_nav/foo/bar">/active_nav/foo/bar</a>
</p>
<p>
<a href="/active_nav/foo">/active_nav/foo</a>
</p>
<p>
<a href="/active_nav">/active_nav</a>
</p>
<p>
<a href="/">/</a>
</p>
</div>
</Doc>
);
}
Deno.test({
name: "active links - without client nav",
fn: async () => {
function View() {
return (
<Doc>
<div>
<h1>nav</h1>
<p>
<a href="/active_nav/foo/bar">/active_nav/foo/bar</a>
</p>
<p>
<a href="/active_nav/foo">/active_nav/foo</a>
</p>
<p>
<a href="/active_nav">/active_nav</a>
</p>
<p>
<a href="/">/</a>
</p>
</div>
</Doc>
);
}
const app = testApp()
.get("/active_nav/foo", (ctx) => {
return ctx.render(<View />);
})
.get("/active_nav", (ctx) => {
return ctx.render(<View />);
});
const app = testApp()
.get("/active_nav/foo", (ctx) => {
return ctx.render(<View />);
})
.get("/active_nav", (ctx) => {
return ctx.render(<View />);
});
const server = new FakeServer(await app.handler());
let res = await server.get("/active_nav");
let doc = parseHtml(await res.text());
const server = new FakeServer(await app.handler());
let res = await server.get("/active_nav");
let doc = parseHtml(await res.text());
assertSelector(doc, "a[href='/'][data-ancestor]");
assertSelector(doc, "a[href='/'][data-ancestor]");
// Current
assertNotSelector(doc, "a[href='/active_nav'][data-ancestor]");
assertSelector(doc, "a[href='/active_nav'][data-current]");
assertSelector(doc, `a[href='/active_nav'][aria-current="page"]`);
// Current
assertNotSelector(doc, "a[href='/active_nav'][data-ancestor]");
assertSelector(doc, "a[href='/active_nav'][data-current]");
assertSelector(doc, `a[href='/active_nav'][aria-current="page"]`);
// Unrelated links
assertNotSelector(doc, "a[href='/active_nav/foo'][data-ancestor]");
assertNotSelector(doc, "a[href='/active_nav/foo'][aria-current]");
assertNotSelector(doc, "a[href='/active_nav/foo/bar'][data-ancestor]");
assertNotSelector(doc, "a[href='/active_nav/foo/bar'][aria-current]");
// Unrelated links
assertNotSelector(doc, "a[href='/active_nav/foo'][data-ancestor]");
assertNotSelector(doc, "a[href='/active_nav/foo'][aria-current]");
assertNotSelector(doc, "a[href='/active_nav/foo/bar'][data-ancestor]");
assertNotSelector(doc, "a[href='/active_nav/foo/bar'][aria-current]");
res = await server.get(`/active_nav/foo`);
doc = parseHtml(await res.text());
assertSelector(doc, "a[href='/active_nav/foo'][data-current]");
assertSelector(doc, `a[href='/active_nav/foo'][aria-current="page"]`);
assertSelector(doc, "a[href='/active_nav'][data-ancestor]");
assertSelector(doc, `a[href='/active_nav'][aria-current="true"]`);
assertSelector(doc, "a[href='/'][data-ancestor]");
assertSelector(doc, `a[href='/'][aria-current="true"]`);
res = await server.get(`/active_nav/foo`);
doc = parseHtml(await res.text());
assertSelector(doc, "a[href='/active_nav/foo'][data-current]");
assertSelector(doc, `a[href='/active_nav/foo'][aria-current="page"]`);
assertSelector(doc, "a[href='/active_nav'][data-ancestor]");
assertSelector(doc, `a[href='/active_nav'][aria-current="true"]`);
assertSelector(doc, "a[href='/'][data-ancestor]");
assertSelector(doc, `a[href='/'][aria-current="true"]`);
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -171,4 +176,6 @@ Deno.test({
assertSelector(doc, `a[href='/'][aria-current="true"]`);
});
},
sanitizeResources: false,
sanitizeOps: false,
});
+1 -1
View File
@@ -10,7 +10,7 @@ export function NodeProcess() {
}, []);
// @ts-ignore bundling
// deno-lint-ignore no-node-globals
// deno-lint-ignore no-process-globals
const value = IS_BROWSER ? process.env.NODE_ENV : "no";
return (
+40
View File
@@ -64,6 +64,8 @@ Deno.test({
await waitForText(page, ".output", "4");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -94,6 +96,8 @@ Deno.test({
await waitForText(page, "#multiple-2 .output", "1");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -123,6 +127,8 @@ Deno.test({
await waitForText(page, "#counter-2 .output", "1");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -151,6 +157,8 @@ Deno.test({
expect(json).toEqual({ foo: 123 });
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -174,6 +182,8 @@ Deno.test({
await page.locator(".ready").wait();
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -204,6 +214,8 @@ Deno.test({
expect(html).not.toContain("import { Counter }");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -232,6 +244,8 @@ Deno.test({
expect(doc.querySelector(".children")!.childNodes.length).toEqual(0);
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -262,6 +276,8 @@ Deno.test({
expect(JSON.parse(text)).toEqual({ jsx: true, children: true });
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -297,6 +313,8 @@ Deno.test({
expect(childText).toEqual("foobar");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -329,6 +347,8 @@ Deno.test({
await waitForText(page, ".output", "1");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -372,6 +392,8 @@ Deno.test({
await waitForText(page, ".children .output", "1");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -415,6 +437,8 @@ Deno.test({
await waitForText(page, ".children .output", "1");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -489,6 +513,8 @@ Deno.test({
expect(radio2).toEqual(true);
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -519,6 +545,8 @@ Deno.test({
expect(text).toEqual("it works");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -548,6 +576,8 @@ Deno.test({
expect(text).toEqual("it works");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -576,6 +606,8 @@ Deno.test({
expect(text).toEqual("value: production");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -601,6 +633,8 @@ Deno.test({
await waitForText(page, ".output", "1");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -631,6 +665,8 @@ Deno.test({
expect(falsy).toEqual("false");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -659,6 +695,8 @@ Deno.test({
expect(text).toEqual("it works");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -685,4 +723,6 @@ Deno.test({
/<\/fresh-runtime\.js\?__frsh_c=[^>]+>; rel="modulepreload"; as="script", <\/SelfCounter\.js\?__frsh_c=[^>]+>; rel="modulepreload"; as="script"/,
);
},
sanitizeResources: false,
sanitizeOps: false,
});
+92
View File
@@ -74,6 +74,8 @@ Deno.test({
await waitForText(page, ".output", "partial update");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -115,6 +117,8 @@ Deno.test({
assertNotSelector(doc, ".init");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -155,6 +159,8 @@ Deno.test({
);
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -193,6 +199,8 @@ Deno.test({
// TODO: Check error overlay
},
sanitizeResources: false,
sanitizeOps: false,
});
// See https://github.com/denoland/fresh/issues/2254
@@ -236,6 +244,8 @@ Deno.test({
expect(didError).toEqual(false);
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -274,6 +284,8 @@ Deno.test({
await page.locator(".ready").wait();
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -307,6 +319,8 @@ Deno.test({
// TODO: Test error overlay
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -347,6 +361,8 @@ Deno.test({
});
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -391,6 +407,8 @@ Deno.test({
expect(counter).toEqual("1");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -437,6 +455,8 @@ Deno.test({
assertNotSelector(doc, ".output");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -476,6 +496,8 @@ Deno.test({
await page.locator(".inner-update").wait();
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -527,6 +549,8 @@ Deno.test({
await page.locator(".sib-3-update").wait();
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -586,6 +610,8 @@ Deno.test({
await waitForText(page, "#c .output", "3");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -658,6 +684,8 @@ Deno.test({
await waitForText(page, "#c .output", "3");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -730,6 +758,8 @@ Deno.test({
await waitForText(page, "#c .output", "3");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -795,6 +825,8 @@ Deno.test({
await waitForText(page, "#c .output", "3");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -862,6 +894,8 @@ Deno.test({
assertNotSelector(doc, ".done-0");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -910,6 +944,8 @@ Deno.test({
assertNotSelector(doc, ".done-0");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -956,6 +992,8 @@ Deno.test({
expect(doc.querySelector(".content")!.textContent).toEqual("init01");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -1005,6 +1043,8 @@ Deno.test({
expect(doc.querySelector(".content")!.textContent).toEqual("init01");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -1050,6 +1090,8 @@ Deno.test({
expect(doc.querySelector(".content")!.textContent).toEqual("10init");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -1099,6 +1141,8 @@ Deno.test({
expect(doc.querySelector(".content")!.textContent).toEqual("10init");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -1155,6 +1199,8 @@ Deno.test({
});
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -1210,6 +1256,8 @@ Deno.test({
});
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -1275,6 +1323,8 @@ Deno.test({
});
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -1340,6 +1390,8 @@ Deno.test({
});
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -1396,6 +1448,8 @@ Deno.test({
expect(scroll.scrollY > 100).toEqual(true);
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -1443,6 +1497,8 @@ Deno.test({
await page.locator(".done-foo-sub").wait();
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -1493,6 +1549,8 @@ Deno.test({
expect(pathname).toEqual("/foo");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -1541,6 +1599,8 @@ Deno.test({
await page.locator(".done-foo-sub").wait();
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -1595,6 +1655,8 @@ Deno.test({
expect(pathname).toEqual("/done");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -1654,6 +1716,8 @@ Deno.test({
await page.locator(".done-foo-sub").wait();
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -1714,6 +1778,8 @@ Deno.test({
await page.locator(".done-foo-sub").wait();
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -1782,6 +1848,8 @@ Deno.test({
assertNotSelector(doc, "button");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -1840,6 +1908,8 @@ Deno.test({
await page.locator(".done-a-b-c").wait();
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -1868,6 +1938,8 @@ Deno.test({
expect(logs).toEqual([]);
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -1903,6 +1975,8 @@ Deno.test({
expect(scroll > 0).toEqual(true);
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -1948,6 +2022,8 @@ Deno.test({
expect(logs[0]).toMatch(/Found no partials/);
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -2044,6 +2120,8 @@ Deno.test({
expect(textColor).toEqual("rgb(0, 128, 0)");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -2131,6 +2209,8 @@ Deno.test({
).toEqual(true);
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -2171,6 +2251,8 @@ Deno.test({
await page.locator(".status-refreshed").wait();
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -2222,6 +2304,8 @@ Deno.test({
await waitForText(page, "#inner .output", "1");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -2258,6 +2342,8 @@ Deno.test({
await page.locator(".done").wait();
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -2293,6 +2379,8 @@ Deno.test({
await page.locator(".error-404").wait();
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -2331,6 +2419,8 @@ Deno.test({
expect(title).toEqual("after update");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
@@ -2374,4 +2464,6 @@ Deno.test({
expect(`${url.pathname}${url.search}`).toEqual("/");
});
},
sanitizeResources: false,
sanitizeOps: false,
});
+13 -2
View File
@@ -91,7 +91,7 @@ export async function withBrowserApp(
}, await app.handler());
const browser = await launch({
args: ["--no-sandbox"],
args: ["--window-size=1280,720"],
headless: !Deno.args.includes("--headful"),
});
@@ -112,7 +112,7 @@ export async function withBrowser(fn: (page: Page) => void | Promise<void>) {
const aborter = new AbortController();
try {
const browser = await launch({
args: ["--no-sandbox"],
args: ["--window-size=1280,720"],
headless: !Deno.args.includes("--headful"),
});
@@ -120,6 +120,17 @@ export async function withBrowser(fn: (page: Page) => void | Promise<void>) {
// page.setDefaultTimeout(1000000);
try {
await fn(page);
} catch (err) {
try {
const raw = await page.content();
const doc = parseHtml(raw);
const html = prettyDom(doc);
// deno-lint-ignore no-console
console.log(html);
} catch {
// Ignore
}
throw err;
} finally {
await page.close();
await browser.close();
+1 -1
View File
@@ -1,4 +1,4 @@
import Prism from "https://esm.sh/prismjs@1.29.0";
import Prism from "prismjs";
export function CodeBlock(
{ code, lang }: { code: string; lang: "js" | "ts" | "jsx" | "md" | "bash" },
+2 -2
View File
@@ -19,10 +19,10 @@ export default function NavigationBar(
];
const isHome = props.active == "/";
return (
<nav class={"flex " + props.class ?? ""} f-client-nav={false}>
<nav class={"flex " + (props.class ?? "")} f-client-nav={false}>
<ul class="flex items-center gap-x-2 sm:gap-4 mx-4 my-2 sm:my-6 flex-wrap lg:mx-8 2xl:mr-0">
{items.map((item) => (
<li>
<li key={item.name}>
<a
href={item.href}
class={`p-1 sm:p-2 ${
+9 -6
View File
@@ -7,10 +7,9 @@
},
"imports": {
"$ga4": "https://raw.githubusercontent.com/denoland/ga4/main/mod.ts",
"$marked-mangle": "https://esm.sh/marked-mangle@1.1.7",
"@fresh/plugin-tailwind": "../plugin-tailwindcss/src/mod.ts",
"@luca/esbuild-deno-loader": "jsr:@luca/esbuild-deno-loader@^0.10.3",
"@preact/signals": "npm:@preact/signals@^1.2.3",
"@preact/signals": "npm:@preact/signals@^1.3.0",
"@std/crypto": "jsr:@std/crypto",
"@std/datetime": "jsr:@std/datetime@^0.224.0",
"@std/encoding": "jsr:@std/encoding",
@@ -24,15 +23,19 @@
"@std/semver": "jsr:@std/semver@^0.224.0",
"autoprefixer": "npm:autoprefixer@10.4.17",
"cssnano": "npm:cssnano@6.0.3",
"esbuild": "npm:esbuild@0.20.2",
"esbuild-wasm": "npm:esbuild-wasm@0.20.2",
"esbuild": "npm:esbuild@0.23.1",
"esbuild-wasm": "npm:esbuild-wasm@0.23.1",
"fresh": "../src/mod.ts",
"fresh/compat": "../src/compat/mod.ts",
"fresh/dev": "../src/dev/mod.ts",
"fresh/runtime": "../src/runtime/shared.ts",
"github-slugger": "npm:github-slugger@^2.0.0",
"marked": "npm:marked@^14.1.2",
"marked-mangle": "npm:marked-mangle@^1.1.9",
"postcss": "npm:postcss@8.4.35",
"preact": "npm:preact@^10.22.0",
"preact-render-to-string": "npm:preact-render-to-string@^6.4.2",
"preact": "npm:preact@^10.24.0",
"preact-render-to-string": "npm:preact-render-to-string@^6.5.11",
"prismjs": "npm:prismjs@^1.29.0",
"tailwindcss": "npm:tailwindcss@3.4.1",
"tailwindcss/plugin": "npm:/tailwindcss@3.4.1/plugin.js"
},
Generated
+1263 -1354
View File
File diff suppressed because it is too large Load Diff
+2 -1
View File
@@ -15,8 +15,9 @@ export default function CopyArea(props: { code: string }) {
copied.value = true;
} catch (error) {
copied.value = false;
const message = error instanceof Error ? error.message : String(error);
// deno-lint-ignore no-console
console.error((error && error.message) || "Copy failed");
console.error(message || "Copy failed");
}
}
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1 +1 @@
google-site-verification: google40caa9e535ae39e9.html
google-site-verification: google40caa9e535ae39e9.html
+9 -2
View File
@@ -756,8 +756,15 @@ ol.nested li:before {
border-top-right-radius: 0 !important;
}
.fenced-code-title {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
"Liberation Mono", "Courier New", monospace;
font-family:
ui-monospace,
SFMono-Regular,
Menlo,
Monaco,
Consolas,
"Liberation Mono",
"Courier New",
monospace;
font-size: 0.8125rem;
line-height: 1;
}
+83 -1
View File
@@ -1,3 +1,85 @@
/* PrismJS 1.29.0
https://prismjs.com/download.html#themes=prism-okaidia&languages=markup+css+clike+javascript */
code[class*=language-],pre[class*=language-]{color:#f8f8f2;background:0 0;text-shadow:0 1px rgba(0,0,0,.3);font-family:Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;font-size:1em;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none}pre[class*=language-]{padding:1em;margin:.5em 0;overflow:auto;border-radius:.3em}:not(pre)>code[class*=language-],pre[class*=language-]{background:#272822}:not(pre)>code[class*=language-]{padding:.1em;border-radius:.3em;white-space:normal}.token.cdata,.token.comment,.token.doctype,.token.prolog{color:#8292a2}.token.punctuation{color:#f8f8f2}.token.namespace{opacity:.7}.token.constant,.token.deleted,.token.property,.token.symbol,.token.tag{color:#f92672}.token.boolean,.token.number{color:#ae81ff}.token.attr-name,.token.builtin,.token.char,.token.inserted,.token.selector,.token.string{color:#a6e22e}.language-css .token.string,.style .token.string,.token.entity,.token.operator,.token.url,.token.variable{color:#f8f8f2}.token.atrule,.token.attr-value,.token.class-name,.token.function{color:#e6db74}.token.keyword{color:#66d9ef}.token.important,.token.regex{color:#fd971f}.token.bold,.token.important{font-weight:700}.token.italic{font-style:italic}.token.entity{cursor:help}
code[class*="language-"], pre[class*="language-"] {
color: #f8f8f2;
background: 0 0;
text-shadow: 0 1px rgba(0, 0, 0, 0.3);
font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace;
font-size: 1em;
text-align: left;
white-space: pre;
word-spacing: normal;
word-break: normal;
word-wrap: normal;
line-height: 1.5;
-moz-tab-size: 4;
-o-tab-size: 4;
tab-size: 4;
-webkit-hyphens: none;
-moz-hyphens: none;
-ms-hyphens: none;
hyphens: none;
}
pre[class*="language-"] {
padding: 1em;
margin: 0.5em 0;
overflow: auto;
border-radius: 0.3em;
}
:not(pre) > code[class*="language-"], pre[class*="language-"] {
background: #272822;
}
:not(pre) > code[class*="language-"] {
padding: 0.1em;
border-radius: 0.3em;
white-space: normal;
}
.token.cdata, .token.comment, .token.doctype, .token.prolog {
color: #8292a2;
}
.token.punctuation {
color: #f8f8f2;
}
.token.namespace {
opacity: 0.7;
}
.token.constant, .token.deleted, .token.property, .token.symbol, .token.tag {
color: #f92672;
}
.token.boolean, .token.number {
color: #ae81ff;
}
.token.attr-name,
.token.builtin,
.token.char,
.token.inserted,
.token.selector,
.token.string {
color: #a6e22e;
}
.language-css .token.string,
.style .token.string,
.token.entity,
.token.operator,
.token.url,
.token.variable {
color: #f8f8f2;
}
.token.atrule, .token.attr-value, .token.class-name, .token.function {
color: #e6db74;
}
.token.keyword {
color: #66d9ef;
}
.token.important, .token.regex {
color: #fd971f;
}
.token.bold, .token.important {
font-weight: 700;
}
.token.italic {
font-style: italic;
}
.token.entity {
cursor: help;
}
+13 -2
View File
@@ -19,8 +19,19 @@
}
body {
font-family: Fixel, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
font-family:
Fixel,
system-ui,
-apple-system,
BlinkMacSystemFont,
"Segoe UI",
Roboto,
Oxygen,
Ubuntu,
Cantarell,
"Open Sans",
"Helvetica Neue",
sans-serif;
font-weight: 450;
font-size: 1.125rem;
line-height: 1.5;
+43 -36
View File
@@ -1,17 +1,20 @@
import Prism from "https://esm.sh/prismjs@1.29.0";
import "https://esm.sh/prismjs@1.29.0/components/prism-jsx.js?no-check";
import "https://esm.sh/prismjs@1.29.0/components/prism-typescript.js?no-check";
import "https://esm.sh/prismjs@1.29.0/components/prism-tsx.js?no-check";
import "https://esm.sh/prismjs@1.29.0/components/prism-diff.js?no-check";
import "https://esm.sh/prismjs@1.29.0/components/prism-json.js?no-check";
import "https://esm.sh/prismjs@1.29.0/components/prism-bash.js?no-check";
import "https://esm.sh/prismjs@1.29.0/components/prism-yaml.js?no-check";
import Prism from "prismjs";
import "prismjs/components/prism-jsx.js";
import "prismjs/components/prism-typescript.js";
import "prismjs/components/prism-tsx.js";
import "prismjs/components/prism-diff.js";
import "prismjs/components/prism-json.js";
import "prismjs/components/prism-bash.js";
import "prismjs/components/prism-yaml.js";
export { extractYaml as frontMatter } from "@std/front-matter";
import * as Marked from "https://esm.sh/marked@7.0.2";
import * as Marked from "marked";
import { escape as escapeHtml } from "@std/html";
import { mangle } from "$marked-mangle";
import { mangle } from "marked-mangle";
import GitHubSlugger from "github-slugger";
const slugger = new GitHubSlugger();
Marked.marked.use(mangle());
@@ -25,7 +28,16 @@ export interface MarkdownHeading {
class DefaultRenderer extends Marked.Renderer {
headings: MarkdownHeading[] = [];
text(text: string): string {
override text(
token: Marked.Tokens.Text | Marked.Tokens.Escape | Marked.Tokens.Tag,
): string {
let text = token.text;
if (
token.type === "text" && "tokens" in token && token.tokens !== undefined
) {
text = this.parser.parseInline(token.tokens);
}
// Smartypants typography enhancement
return text
.replaceAll("...", "&#8230;")
@@ -39,37 +51,32 @@ class DefaultRenderer extends Marked.Renderer {
.replaceAll(/['](.*?)[']/g, "&#8216;$1&#8217;");
}
heading(
text: string,
level: 1 | 2 | 3 | 4 | 5 | 6,
raw: string,
slugger: Marked.Slugger,
): string {
override heading({
tokens,
depth,
raw,
}: Marked.Tokens.Heading): string {
const slug = slugger.slug(raw);
const text = this.parser.parseInline(tokens);
this.headings.push({ id: slug, html: text });
return `<h${level} id="${slug}"><a class="md-anchor" tabindex="-1" href="#${slug}">${text}<span aria-hidden="true">#</span></a></h${level}>`;
return `<h${depth} id="${slug}"><a class="md-anchor" tabindex="-1" href="#${slug}">${text}<span aria-hidden="true">#</span></a></h${depth}>`;
}
link(href: string, title: string | null, text: string) {
override link({ href, title, tokens }: Marked.Tokens.Link) {
const text = this.parser.parseInline(tokens);
const titleAttr = title ? ` title="${title}"` : "";
if (href.startsWith("#")) {
return `<a href="${href}"${titleAttr}>${text}</a>`;
}
if (this.options.baseUrl) {
try {
href = new URL(href, this.options.baseUrl).href;
} catch (_) {
//
}
}
return `<a href="${href}"${titleAttr} rel="noopener noreferrer">${text}</a>`;
}
image(src: string, title: string | null, alt: string | null) {
return `<img src="${src}" alt="${alt ?? ""}" title="${title ?? ""}" />`;
override image({ href, text, title }: Marked.Tokens.Image) {
return `<img src="${href}" alt="${text ?? ""}" title="${title ?? ""}" />`;
}
code(code: string, info: string | undefined): string {
override code({ lang: info, text }: Marked.Tokens.Code): string {
// format: tsx
// format: tsx my/file.ts
// format: tsx "This is my title"
@@ -96,9 +103,9 @@ class DefaultRenderer extends Marked.Renderer {
: undefined;
if (grammar === undefined) {
out += `<pre><code class="notranslate">${escapeHtml(code)}</code></pre>`;
out += `<pre><code class="notranslate">${escapeHtml(text)}</code></pre>`;
} else {
const html = Prism.highlight(code, grammar, lang);
const html = Prism.highlight(text, grammar, lang);
out +=
`<pre class="highlight highlight-source-${lang} notranslate lang-${lang}"><code>${html}</code></pre>`;
}
@@ -107,8 +114,8 @@ class DefaultRenderer extends Marked.Renderer {
return out;
}
blockquote(quote: string): string {
const match = quote.match(ADMISSION_REG);
override blockquote({ text }: Marked.Tokens.Blockquote): string {
const match = text.match(ADMISSION_REG);
if (match) {
const label: Record<string, string> = {
tip: "Tip",
@@ -116,13 +123,13 @@ class DefaultRenderer extends Marked.Renderer {
info: "Info",
};
const type = match[1];
quote = quote.slice(match[0].length);
text = text.slice(match[0].length);
const icon = `<svg class="icon"><use href="/icons.svg#${type}" /></svg>`;
return `<blockquote class="admonition ${type}">\n<span class="admonition-header">${icon}${
label[type]
}</span>${quote}</blockquote>\n`;
}</span>${text}</blockquote>\n`;
}
return `<blockquote>\n${quote}</blockquote>\n`;
return `<blockquote>\n${text}</blockquote>\n`;
}
}