chore: remove debug trace logs (#2545)
This commit is contained in:
@@ -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",
|
||||
}],
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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];
|
||||
|
||||
@@ -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<string>;
|
||||
runtime: Set<string>;
|
||||
compat: Set<string>;
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user