Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove debug trace logs #2545

Merged
merged 2 commits into from
Jun 25, 2024
Merged
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
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@
"jsxPrecompileSkipElements": ["a", "img", "source", "body", "html", "head"]
},
"lint": {
"rules": { "exclude": ["no-window"] }
"rules": { "exclude": ["no-window"], "include": ["no-console"] }
}
}
2 changes: 2 additions & 0 deletions init/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
};
Expand Down
6 changes: 6 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,13 @@ export class App<State> {
} 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 });
}
Expand All @@ -243,16 +245,20 @@ export class App<State> {

// 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`);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/dev/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`,
);
Expand Down
3 changes: 0 additions & 3 deletions src/dev/builder_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
},
);
Expand Down
1 change: 0 additions & 1 deletion src/dev/dev_build_cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ export class MemoryBuildCache implements DevBuildCache {

// deno-lint-ignore require-await
async flush(): Promise<void> {
console.log("FLUSH MEMORY CACHE");
this.#ready.resolve();
}
}
Expand Down
1 change: 1 addition & 0 deletions src/dev/middlewares/error_overlay/middleware.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export function devErrorOverlay<T>(): MiddlewareFn<T> {
}

// At this point we're pretty sure to have a server error
// deno-lint-ignore no-console
console.error(err);

return ctx.render(<FreshScripts />, init);
Expand Down
4 changes: 4 additions & 0 deletions src/dev/update_check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand All @@ -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();
}

Expand Down
2 changes: 2 additions & 0 deletions src/runtime/client/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/runtime/client/partials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/runtime/shared_internal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions tests/fixture_precompile/valid/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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());
1 change: 1 addition & 0 deletions tests/fixture_update_check/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
3 changes: 3 additions & 0 deletions tests/test_utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down Expand Up @@ -284,6 +285,7 @@ export function assertMetaContent(
}

if (el === null) {
// deno-lint-ignore no-console
console.log(prettyDom(doc));
throw new Error(
`No <meta>-tag found with content "${expected}"`,
Expand Down Expand Up @@ -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}`,
);
Expand Down
5 changes: 5 additions & 0 deletions tools/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <major|minor|patch|...>
`);
}

function exitError(msg: string): never {
// deno-lint-ignore no-console
console.error(cl.red(msg));
showHelp();
Deno.exit(1);
Expand Down Expand Up @@ -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?")) {
Expand Down
105 changes: 105 additions & 0 deletions update/src/maybePrependReqVar.ts
Original file line number Diff line number Diff line change
@@ -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",
}],
});
}
}
}
}
}
4 changes: 4 additions & 0 deletions update/src/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
6 changes: 4 additions & 2 deletions update/src/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<string>;
runtime: Set<string>;
compat: Set<string>;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions update/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Loading
Loading