diff --git a/deno.json b/deno.json index 1e37c087..42825728 100644 --- a/deno.json +++ b/deno.json @@ -78,6 +78,6 @@ "jsxPrecompileSkipElements": ["a", "img", "source", "body", "html", "head"] }, "lint": { - "rules": { "exclude": ["no-window"] } + "rules": { "exclude": ["no-window"], "include": ["no-console"] } } } diff --git a/init/src/init.ts b/init/src/init.ts index 3c5f5605..700332db 100644 --- a/init/src/init.ts +++ b/init/src/init.ts @@ -62,9 +62,11 @@ const realTTY: MockTTY = { return confirm(message); }, log(...args) { + // deno-lint-ignore no-console console.log(...args); }, logError(...args) { + // deno-lint-ignore no-console console.error(...args); }, }; diff --git a/src/app.ts b/src/app.ts index 68b24d30..ee9a8573 100644 --- a/src/app.ts +++ b/src/app.ts @@ -216,11 +216,13 @@ export class App { } catch (err) { if (err instanceof HttpError) { if (err.status >= 500) { + // deno-lint-ignore no-console console.error(err); } return new Response(err.message, { status: err.status }); } + // deno-lint-ignore no-console console.error(err); return new Response("Internal server error", { status: 500 }); } @@ -243,16 +245,20 @@ export class App { // Don't spam logs with this on live deployments if (!DENO_DEPLOYMENT_ID) { + // deno-lint-ignore no-console console.log(); + // deno-lint-ignore no-console console.log( colors.bgRgb8(colors.rgb8(" 🍋 Fresh ready ", 0), 121), ); const sep = options.remoteAddress ? "" : "\n"; const space = options.remoteAddress ? " " : ""; + // deno-lint-ignore no-console console.log(` ${localLabel} ${space}${address}${sep}`); if (options.remoteAddress) { const remoteLabel = colors.bold("Remote:"); const remoteAddress = colors.cyan(options.remoteAddress); + // deno-lint-ignore no-console console.log(` ${remoteLabel} ${remoteAddress}\n`); } } diff --git a/src/dev/builder.ts b/src/dev/builder.ts index fbfd4b9b..cd32bb09 100644 --- a/src/dev/builder.ts +++ b/src/dev/builder.ts @@ -199,10 +199,10 @@ export class Builder implements FreshBuilder { buildCache.islands.set(island.name, `/${chunk}`); } - console.trace("FLUSH"); await buildCache.flush(); if (!dev) { + // deno-lint-ignore no-console console.log( `Assets written to: ${colors.cyan(build.outDir)}`, ); diff --git a/src/dev/builder_test.ts b/src/dev/builder_test.ts index 0b10d4d9..8deb12ed 100644 --- a/src/dev/builder_test.ts +++ b/src/dev/builder_test.ts @@ -11,21 +11,18 @@ Deno.test({ builder.onTransformStaticFile( { pluginName: "A", filter: /\.css$/ }, () => { - console.trace(); logs.push("A"); }, ); builder.onTransformStaticFile( { pluginName: "B", filter: /\.css$/ }, () => { - console.trace(); logs.push("B"); }, ); builder.onTransformStaticFile( { pluginName: "C", filter: /\.css$/ }, () => { - console.trace(); logs.push("C"); }, ); diff --git a/src/dev/dev_build_cache.ts b/src/dev/dev_build_cache.ts index 5259475c..ba0f7f93 100644 --- a/src/dev/dev_build_cache.ts +++ b/src/dev/dev_build_cache.ts @@ -143,7 +143,6 @@ export class MemoryBuildCache implements DevBuildCache { // deno-lint-ignore require-await async flush(): Promise { - console.log("FLUSH MEMORY CACHE"); this.#ready.resolve(); } } diff --git a/src/dev/middlewares/error_overlay/middleware.tsx b/src/dev/middlewares/error_overlay/middleware.tsx index e74554b5..b4aa91ab 100644 --- a/src/dev/middlewares/error_overlay/middleware.tsx +++ b/src/dev/middlewares/error_overlay/middleware.tsx @@ -22,6 +22,7 @@ export function devErrorOverlay(): MiddlewareFn { } // At this point we're pretty sure to have a server error + // deno-lint-ignore no-console console.error(err); return ctx.render(, init); diff --git a/src/dev/update_check.ts b/src/dev/update_check.ts index 4d659629..336e5880 100644 --- a/src/dev/update_check.ts +++ b/src/dev/update_check.ts @@ -106,6 +106,7 @@ export async function updateCheck( checkFile.last_checked = new Date().toISOString(); } catch (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, ); @@ -125,12 +126,15 @@ export async function updateCheck( const current = colors.bold(colors.rgb8(checkFile.current_version, 208)); const latest = colors.bold(colors.rgb8(checkFile.latest_version, 121)); + // deno-lint-ignore no-console console.log( ` Fresh ${latest} is available. You're on ${current}`, ); + // deno-lint-ignore no-console console.log( ` To upgrade, run: deno run -A -r https://fresh.deno.dev/update`, ); + // deno-lint-ignore no-console console.log(); } diff --git a/src/runtime/client/dev.ts b/src/runtime/client/dev.ts index 99f51a7c..f0a5369c 100644 --- a/src/runtime/client/dev.ts +++ b/src/runtime/client/dev.ts @@ -33,6 +33,7 @@ function reconnect() { reconnectTimer = setTimeout(() => { if (backoffIdx === 0) { + // deno-lint-ignore no-console console.log( `%c Fresh %c Connection closed. Trying to reconnect...`, "background-color: #86efac; color: black", @@ -84,6 +85,7 @@ function handleMessage(e: MessageEvent) { switch (data.type) { case "initial-state": { if (revision === 0) { + // deno-lint-ignore no-console console.log( `%c Fresh %c Connected to development server.`, "background-color: #86efac; color: black", diff --git a/src/runtime/client/partials.ts b/src/runtime/client/partials.ts index 6537d9a3..ef3557cd 100644 --- a/src/runtime/client/partials.ts +++ b/src/runtime/client/partials.ts @@ -481,6 +481,7 @@ function revivePartials( const instance = ACTIVE_PARTIALS.get(partialName); if (instance === undefined) { + // deno-lint-ignore no-console console.warn(`Partial "${partialName}" not found. Skipping...`); // Partial doesn't exist on the current page } else { diff --git a/src/runtime/shared_internal.tsx b/src/runtime/shared_internal.tsx index 28add5e1..9ee40d76 100644 --- a/src/runtime/shared_internal.tsx +++ b/src/runtime/shared_internal.tsx @@ -74,6 +74,7 @@ export function assetInternal(path: string, buildId: string): string { url.searchParams.set(ASSET_CACHE_BUST_KEY, buildId); return url.pathname + url.search + url.hash; } catch (err) { + // deno-lint-ignore no-console console.warn( `Failed to create asset() URL, falling back to regular path ('${path}'):`, err, diff --git a/tests/fixture_precompile/valid/main.tsx b/tests/fixture_precompile/valid/main.tsx index 3b31e7e4..35ec2605 100644 --- a/tests/fixture_precompile/valid/main.tsx +++ b/tests/fixture_precompile/valid/main.tsx @@ -27,4 +27,5 @@ const app = new App({ staticDir: "./static" }).get( const handler = await app.handler(); const res = await handler(new Request("http://localhost/")); +// deno-lint-ignore no-console console.log(await res.text()); diff --git a/tests/fixture_update_check/mod.ts b/tests/fixture_update_check/mod.ts index ba3bf97a..e2c8b695 100644 --- a/tests/fixture_update_check/mod.ts +++ b/tests/fixture_update_check/mod.ts @@ -3,6 +3,7 @@ import { DAY } from "@std/datetime"; // deno-lint-ignore require-await async function getLatestVersion() { + // deno-lint-ignore no-console console.log("fetching latest version"); return Deno.env.get("LATEST_VERSION") ?? "99.99.999"; } diff --git a/tests/test_utils.tsx b/tests/test_utils.tsx index af42e35c..41e598cc 100644 --- a/tests/test_utils.tsx +++ b/tests/test_utils.tsx @@ -244,6 +244,7 @@ export function parseHtml(input: string): TestDocument { // deno-lint-ignore no-explicit-any const doc = new DOMParser().parseFromString(input, "text/html") as any; Object.defineProperty(doc, "debug", { + // deno-lint-ignore no-console value: () => console.log(prettyDom(doc)), enumerable: false, }); @@ -284,6 +285,7 @@ export function assertMetaContent( } if (el === null) { + // deno-lint-ignore no-console console.log(prettyDom(doc)); throw new Error( `No -tag found with content "${expected}"`, @@ -312,6 +314,7 @@ export async function waitForText( // deno-lint-ignore no-explicit-any const pretty = prettyDom(parseHtml(body) as any); + // deno-lint-ignore no-console console.log( `Text "${text}" not found on selector "${selector}" in html:\n\n${pretty}`, ); diff --git a/tools/release.ts b/tools/release.ts index dd400301..da548fb4 100644 --- a/tools/release.ts +++ b/tools/release.ts @@ -4,12 +4,14 @@ import type { DenoJson } from "../update/src/update.ts"; import * as semver from "@std/semver"; function showHelp() { + // deno-lint-ignore no-console console.log(` Usage: deno run -A release.ts `); } function exitError(msg: string): never { + // deno-lint-ignore no-console console.error(cl.red(msg)); showHelp(); Deno.exit(1); @@ -71,8 +73,11 @@ function formatUpgradeMsg( return ` ${nameMsg}: ${fromMsg} -> ${toMsg}`; } +// deno-lint-ignore no-console console.log(formatUpgradeMsg(denoJson.name!, current, next)); +// deno-lint-ignore no-console console.log(formatUpgradeMsg(initJson.name!, currentInit, next)); +// deno-lint-ignore no-console console.log(formatUpgradeMsg(updateJson.name!, currentUpdate, next)); if (!confirm("Proceed with update?")) { diff --git a/update/src/maybePrependReqVar.ts b/update/src/maybePrependReqVar.ts new file mode 100644 index 00000000..c9da8770 --- /dev/null +++ b/update/src/maybePrependReqVar.ts @@ -0,0 +1,105 @@ +import * as tsmorph from "ts-morph"; +import { type ImportState, SyntaxKind } from "./update.ts"; + +export function maybePrependReqVar( + method: + | tsmorph.MethodDeclaration + | tsmorph.FunctionDeclaration + | tsmorph.FunctionExpression + | tsmorph.ArrowFunction, + newImports: ImportState, + hasInferredTypes: boolean, +) { + let hasRequestVar = false; + const params = method.getParameters(); + if (params.length > 0) { + const paramName = params[0].getName(); + + // Add explicit types if the user did that + if (hasInferredTypes && params[0].getTypeNode()) { + hasInferredTypes = false; + } + + hasRequestVar = params.length > 1 || paramName === "req"; + if (hasRequestVar || paramName === "_req") { + if (hasRequestVar && params.length === 1) { + params[0].replaceWithText("ctx"); + if (!hasInferredTypes) { + newImports.core.add("FreshContext"); + params[0].setType("FreshContext"); + } + } else { + params[0].remove(); + + // Use proper type + if (params.length > 1) { + const initType = params[1].getTypeNode()?.getText(); + if (initType !== undefined && initType === "RouteContext") { + newImports.core.add("FreshContext"); + params[1].setType("FreshContext"); + } + } + } + } + const maybeObjBinding = params.length > 1 + ? params[1].getNameNode() + : undefined; + + if (method.isKind(SyntaxKind.ArrowFunction)) { + const body = method.getBody(); + if (body !== undefined && !body.isKind(SyntaxKind.Block)) { + // deno-lint-ignore no-console + console.warn(`Cannot transform arrow function`); + return; + } + } + + if ( + (maybeObjBinding === undefined || + !maybeObjBinding.isKind(SyntaxKind.ObjectBindingPattern)) && + hasRequestVar && + !paramName.startsWith("_") + ) { + method.insertVariableStatement(0, { + declarationKind: tsmorph.VariableDeclarationKind.Const, + declarations: [{ + name: paramName, + initializer: "ctx.req", + }], + }); + } + + if ( + maybeObjBinding !== undefined && + maybeObjBinding.isKind(SyntaxKind.ObjectBindingPattern) + ) { + const objBinding = maybeObjBinding as tsmorph.ObjectBindingPattern; + const bindings = objBinding.getElements(); + if (bindings.length > 0) { + let needsRemoteAddr = false; + for (let i = 0; i < bindings.length; i++) { + const binding = bindings[i]; + const name = binding.getName(); + if (name === "remoteAddr") { + binding.replaceWithText("info"); + needsRemoteAddr = true; + } + } + if (hasRequestVar && !paramName.startsWith("_")) { + const txt = maybeObjBinding.getFullText().slice(0, -2); + maybeObjBinding.replaceWithText(txt + ", req }"); + } + + if (needsRemoteAddr) { + method.insertVariableStatement(0, { + declarationKind: tsmorph.VariableDeclarationKind.Const, + declarations: [{ + name: "remoteAddr", + initializer: "info.remoteAddr", + }], + }); + } + } + } + } +} diff --git a/update/src/mod.ts b/update/src/mod.ts index 89253b1a..7a27e548 100644 --- a/update/src/mod.ts +++ b/update/src/mod.ts @@ -22,16 +22,20 @@ ensureMinDenoVersion(MIN_DENO_VERSION); const flags = parseArgs(Deno.args, {}); +// deno-lint-ignore no-console console.log(colors.bgRgb8( colors.rgb8(" 🍋 Fresh Updater ", 0), 121, )); +// deno-lint-ignore no-console console.log(); +// deno-lint-ignore no-console console.log( colors.italic( "Note: Breaking changes may require additional manual updates.", ), ); +// deno-lint-ignore no-console console.log(); let unresolvedDirectory = Deno.args[0]; diff --git a/update/src/update.ts b/update/src/update.ts index 04aa2073..e8a84def 100644 --- a/update/src/update.ts +++ b/update/src/update.ts @@ -2,7 +2,7 @@ import * as path from "@std/path"; import * as JSONC from "@std/jsonc"; import * as tsmorph from "ts-morph"; -const SyntaxKind = tsmorph.ts.SyntaxKind; +export const SyntaxKind = tsmorph.ts.SyntaxKind; export const FRESH_VERSION = "2.0.0-alpha.16"; export const PREACT_VERSION = "10.22.0"; @@ -57,7 +57,7 @@ async function updateDenoJson( throw new Error(`Could not find deno.json or deno.jsonc in: ${dir}`); } -interface ImportState { +export interface ImportState { core: Set; runtime: Set; compat: Set; @@ -101,6 +101,7 @@ export async function updateProject(dir: string) { try { return await updateFile(sourceFile); } catch (err) { + // deno-lint-ignore no-console console.error(`Could not process ${sourceFile.getFilePath()}`); throw err; } @@ -348,6 +349,7 @@ function maybePrependReqVar( if (method.isKind(SyntaxKind.ArrowFunction)) { const body = method.getBody(); if (!body.isKind(SyntaxKind.Block)) { + // deno-lint-ignore no-console console.warn(`Cannot transform arrow function`); return; } diff --git a/update/src/utils.ts b/update/src/utils.ts index bc2bb430..a90b83f1 100644 --- a/update/src/utils.ts +++ b/update/src/utils.ts @@ -25,6 +25,7 @@ export function ensureMinDenoVersion(minVersion: string) { } export function error(message: string): never { + // deno-lint-ignore no-console console.error(`%cerror%c: ${message}`, "color: red; font-weight: bold", ""); Deno.exit(1); } diff --git a/www/islands/CopyArea.tsx b/www/islands/CopyArea.tsx index 39802804..60db1355 100644 --- a/www/islands/CopyArea.tsx +++ b/www/islands/CopyArea.tsx @@ -15,6 +15,7 @@ export default function CopyArea(props: { code: string }) { copied.value = true; } catch (error) { copied.value = false; + // deno-lint-ignore no-console console.error((error && error.message) || "Copy failed"); } } diff --git a/www/routes/_middleware.ts b/www/routes/_middleware.ts index a4019fb5..d407000e 100644 --- a/www/routes/_middleware.ts +++ b/www/routes/_middleware.ts @@ -16,6 +16,7 @@ function ga4( if (GA4_MEASUREMENT_ID === undefined) { if (!showedMissingEnvWarning) { showedMissingEnvWarning = true; + // deno-lint-ignore no-console console.warn( "GA4_MEASUREMENT_ID environment variable not set. Google Analytics reporting disabled.", ); @@ -81,6 +82,7 @@ function ga4( await report.send(); }).catch((err) => { + // deno-lint-ignore no-console console.error(err); }); } diff --git a/www/utils/screenshot.ts b/www/utils/screenshot.ts index e2816eae..ed6b07e2 100644 --- a/www/utils/screenshot.ts +++ b/www/utils/screenshot.ts @@ -6,16 +6,19 @@ const url = Deno.args[0]; const id = Deno.args[1]; if (Deno.args.length == 0) { + // deno-lint-ignore no-console console.log("Usage: screenshot "); Deno.exit(0); } if (!(url.match(/^http[s]?:\/\//)) || !url) { + // deno-lint-ignore no-console console.log("Provided URL is Broken or Wrong"); Deno.exit(0); } if (!id) { + // deno-lint-ignore no-console console.log("Provide id to Process"); Deno.exit(0); } @@ -31,6 +34,7 @@ const raw = await page.screenshot(); await browser.close(); if (!(raw instanceof Uint8Array)) { + // deno-lint-ignore no-console console.log("Invalid Image"); Deno.exit(0); }