Skip to content

Commit 4142102

Browse files
committed
Remove vendored compiler debug logging
1 parent 1053ed0 commit 4142102

6 files changed

Lines changed: 3 additions & 77 deletions

File tree

packages/core/sdk/src/vendor/json-schema-to-typescript/generator.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type {
1111
TNamedInterface,
1212
TUnion,
1313
} from "./types/AST";
14-
import { log, toSafeString } from "./utils";
14+
import { toSafeString } from "./utils";
1515

1616
export function generate(ast: AST, options = DEFAULT_OPTIONS): string {
1717
return (
@@ -172,8 +172,6 @@ function generateTypeUnmemoized(ast: AST, options: Options): string {
172172
export const generateType = memoize(generateTypeUnmemoized);
173173

174174
function generateRawType(ast: AST, options: Options): string {
175-
log("magenta", "generator", ast);
176-
177175
if (hasStandaloneName(ast)) {
178176
return toSafeString(ast.standaloneName);
179177
}

packages/core/sdk/src/vendor/json-schema-to-typescript/index.ts

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { normalize } from "./normalizer";
66
import { optimize } from "./optimizer";
77
import { parse } from "./parser";
88
import { dereference } from "./resolver";
9-
import { error, isVerbose, log } from "./utils";
109
import { validate } from "./validator";
1110
import { link } from "./linker";
1211
import { validateOptions } from "./optionValidator";
@@ -145,47 +144,21 @@ export function compile(schema: JSONSchema4, name: string, options: Partial<Opti
145144

146145
const _options = merge({} as Options, DEFAULT_OPTIONS, options);
147146

148-
const start = Date.now();
149-
function time() {
150-
return `(${Date.now() - start}ms)`;
151-
}
152-
153147
// Initial clone to avoid mutating the input
154148
const _schema = cloneDeep(schema);
155149

156150
const { dereferencedPaths, dereferencedSchema } = dereference(_schema);
157-
if (isVerbose()) {
158-
log("green", "dereferencer", time(), "ok Result:", dereferencedSchema);
159-
}
160-
161151
const linked = link(dereferencedSchema);
162-
if (isVerbose()) {
163-
log("green", "linker", time(), "ok No change");
164-
}
165-
166152
const errors = validate(linked, name);
167153
if (errors.length) {
168-
errors.forEach((_) => error(_));
169-
throw new ValidationError();
170-
}
171-
if (isVerbose()) {
172-
log("green", "validator", time(), "ok No change");
154+
throw new ValidationError(errors.join("\n"));
173155
}
174156

175157
const normalized = normalize(linked, dereferencedPaths, name, _options);
176-
log("yellow", "normalizer", time(), "ok Result:", normalized);
177-
178158
const parsed = parse(normalized, _options);
179-
log("blue", "parser", time(), "ok Result:", parsed);
180-
181159
const optimized = optimize(parsed, _options);
182-
log("cyan", "optimizer", time(), "ok Result:", optimized);
183-
184160
const generated = generate(optimized, _options);
185-
log("magenta", "generator", time(), "ok Result:", generated);
186-
187161
const formatted = format(generated, _options);
188-
log("white", "formatter", time(), "ok Result:", formatted);
189162

190163
return formatted;
191164
}

packages/core/sdk/src/vendor/json-schema-to-typescript/optimizer.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type { Options } from ".";
33
import { generateType } from "./generator";
44
import { T_ANY, T_UNKNOWN } from "./types/AST";
55
import type { AST } from "./types/AST";
6-
import { log } from "./utils";
76

87
export function optimize(ast: AST, options: Options, processed = new Set<AST>()): AST {
98
if (processed.has(ast)) {
@@ -32,13 +31,11 @@ export function optimize(ast: AST, options: Options, processed = new Set<AST>())
3231

3332
// [A, B, C, Any] -> Any
3433
if (optimizedAST.params.some((_) => _.type === "ANY")) {
35-
log("cyan", "optimizer", "[A, B, C, Any] -> Any", optimizedAST);
3634
return T_ANY;
3735
}
3836

3937
// [A, B, C, Unknown] -> Unknown
4038
if (optimizedAST.params.some((_) => _.type === "UNKNOWN")) {
41-
log("cyan", "optimizer", "[A, B, C, Unknown] -> Unknown", optimizedAST);
4239
return T_UNKNOWN;
4340
}
4441

@@ -51,14 +48,12 @@ export function optimize(ast: AST, options: Options, processed = new Set<AST>())
5148
}) &&
5249
optimizedAST.params.some((_) => _.standaloneName !== undefined)
5350
) {
54-
log("cyan", "optimizer", "[A (named), A] -> [A (named)]", optimizedAST);
5551
optimizedAST.params = optimizedAST.params.filter((_) => _.standaloneName !== undefined);
5652
}
5753

5854
// [A, B, B] -> [A, B]
5955
const params = uniqBy(optimizedAST.params, (_) => generateType(_, options));
6056
if (params.length !== optimizedAST.params.length) {
61-
log("cyan", "optimizer", "[A, B, B] -> [A, B]", optimizedAST);
6257
optimizedAST.params = params;
6358
}
6459

packages/core/sdk/src/vendor/json-schema-to-typescript/parser.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import type {
2525
SchemaType,
2626
} from "./types/JSONSchema";
2727
import { Intersection, Types, getRootSchema, isBoolean, isPrimitive } from "./types/JSONSchema";
28-
import { generateName, log, maybeStripDefault } from "./utils";
28+
import { generateName, maybeStripDefault } from "./utils";
2929

3030
export type Processed = Map<NormalizedJSONSchema, Map<SchemaType, AST>>;
3131

@@ -66,7 +66,6 @@ export function parse(
6666
);
6767
});
6868

69-
log("blue", "parser", "Types:", [...types], "Input:", normalizedSchema, "Output:", ast);
7069
return ast;
7170
}
7271

@@ -80,7 +79,6 @@ export function parse(
8079
processed,
8180
usedNames,
8281
);
83-
log("blue", "parser", "Type:", type, "Input:", normalizedSchema, "Output:", ast);
8482
return ast;
8583
}
8684

packages/core/sdk/src/vendor/json-schema-to-typescript/resolver.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { JSONSchema } from "./types/JSONSchema";
2-
import { log } from "./utils";
32

43
export type DereferencedPaths = WeakMap<JSONSchema, string>;
54

@@ -134,7 +133,6 @@ export function dereference(schema: JSONSchema): {
134133
dereferencedPaths: DereferencedPaths;
135134
dereferencedSchema: JSONSchema;
136135
} {
137-
log("green", "dereferencer", "Dereferencing input schema:", schema);
138136
const dereferencedPaths: DereferencedPaths = new WeakMap();
139137
const dereferencedSchema = dereferenceNode(
140138
schema,

packages/core/sdk/src/vendor/json-schema-to-typescript/utils.ts

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -219,42 +219,6 @@ export function generateName(from: string, usedNames: Set<string>) {
219219
return name;
220220
}
221221

222-
export function isVerbose(): boolean {
223-
const global = globalThis as { process?: { env?: Record<string, string | undefined> } };
224-
return global.process?.env?.VERBOSE != null;
225-
}
226-
227-
export function error(...messages: any[]): void {
228-
if (!isVerbose()) {
229-
return console.error(messages);
230-
}
231-
console.error("error", ...messages);
232-
}
233-
234-
type LogStyle = "blue" | "cyan" | "green" | "magenta" | "red" | "white" | "yellow";
235-
236-
export function log(style: LogStyle, title: string, ...messages: unknown[]): void {
237-
if (!isVerbose()) {
238-
return;
239-
}
240-
let lastMessage = null;
241-
if (messages.length > 1 && typeof messages[messages.length - 1] !== "string") {
242-
lastMessage = messages.splice(messages.length - 1, 1);
243-
}
244-
console.info("debug", getStyledTextForLogging(style)?.(title), ...messages);
245-
if (lastMessage) {
246-
console.dir(lastMessage, { depth: 6, maxArrayLength: 6 });
247-
}
248-
}
249-
250-
function getStyledTextForLogging(style: LogStyle): ((text: string) => string) | undefined {
251-
if (!isVerbose()) {
252-
return;
253-
}
254-
void style;
255-
return (text) => text;
256-
}
257-
258222
/**
259223
* escape block comments in schema descriptions so that they don't unexpectedly close JSDoc comments in generated typescript interfaces
260224
*/

0 commit comments

Comments
 (0)