diff --git a/src/command/render/output-tex.ts b/src/command/render/output-tex.ts index c7f5957458b..43a195ea22c 100644 --- a/src/command/render/output-tex.ts +++ b/src/command/render/output-tex.ts @@ -99,7 +99,6 @@ export function texToPdfOutputRecipe( // Clean the output directory if it is empty if (pdfOutputDir) { - console.log({ pdfOutputDir }); try { // Remove the outputDir if it is empty safeRemoveSync(pdfOutputDir, { recursive: false }); diff --git a/src/command/render/pandoc.ts b/src/command/render/pandoc.ts index 76dbf458b1a..feb97020dfa 100644 --- a/src/command/render/pandoc.ts +++ b/src/command/render/pandoc.ts @@ -1483,7 +1483,7 @@ async function resolveExtras( } } else if (source === "bunny") { const font = Zod.BrandFontBunny.parse(_font); - console.log( + info( "Font bunny is not yet supported for Typst, skipping", font.family, ); @@ -1528,7 +1528,7 @@ async function resolveExtras( } } if (!found) { - console.log( + info( "skipping", family, "\nnot currently able to use formats", diff --git a/src/core/deno/debug.ts b/src/core/deno/debug.ts index 1c910df059a..d614729d136 100644 --- a/src/core/deno/debug.ts +++ b/src/core/deno/debug.ts @@ -7,6 +7,7 @@ */ import * as colors from "fmt/colors"; +import { warn } from "../../deno_ral/log.ts"; type StackEntry = { pos: string; @@ -47,7 +48,7 @@ export const getStackAsArray = ( /^.*at async (.*)src\/quarto.ts:\d+:\d+$/, ); if (!m) { - console.log( + warn( "Could not find quarto.ts in stack trace, is QUARTO_DENO_V8_OPTIONS set with a sufficiently-large stack size?", ); } @@ -184,12 +185,15 @@ export const getStack = (format?: "json" | "raw" | "ansi", offset?: number) => { getStackAsArray(format, offset ? offset + 1 : 3).join("\n"); }; -// use debugPrint instead of console.log so it's easy to find stray print statements +// use debugPrint instead of console["log"] so it's easier to find stray print statements // on our codebase // // deno-lint-ignore no-explicit-any export const debugPrint = (...data: any[]) => { - console.log(...data); + // use console["log"] here instead of dot notation + // to allow us to lint for the dot notation usage which + // we want to disallow throughout the codebase + console["log"](...data); }; export const debugLogWithStack = async (...data: unknown[]) => { diff --git a/src/core/handlers/dot.ts b/src/core/handlers/dot.ts index 2473528010e..4a266739451 100644 --- a/src/core/handlers/dot.ts +++ b/src/core/handlers/dot.ts @@ -62,22 +62,21 @@ const dotHandler: LanguageHandler = { toFileUrl(resourcePath(join("js", "graphviz-wasm.js"))).href ); let svg; - const oldConsoleLog = console.log; - const oldConsoleWarn = console.warn; - console.log = () => {}; - console.warn = () => {}; + // use console["log"] here instead of dot notation + // to allow us to lint for the dot notation usage which + // we want to disallow throughout the codebase + const oldConsoleLog = console["log"]; + const oldConsoleWarn = console["warn"]; + console["log"] = () => {}; + console["warn"] = () => {}; try { svg = await graphvizModule.graphviz().layout( cellContent.value, "svg", options["graph-layout"], ); - console.log = oldConsoleLog; - console.warn = oldConsoleWarn; } catch (e) { if (!(e instanceof Error)) throw e; - console.log = oldConsoleLog; - console.warn = oldConsoleWarn; const m = (e.message as string).match( /(.*)syntax error in line (\d+)(.*)/, ); @@ -94,10 +93,11 @@ const dotHandler: LanguageHandler = { mapResult!.originalString.fileName }, line ${line + 1}${m[3]}`, ); - throw e; - } else { - throw e; } + throw e; + } finally { + console["log"] = oldConsoleLog; + console["warn"] = oldConsoleWarn; } const makeFigLink = ( diff --git a/src/core/handlers/mermaid.ts b/src/core/handlers/mermaid.ts index 489879d9890..2108ca207ed 100644 --- a/src/core/handlers/mermaid.ts +++ b/src/core/handlers/mermaid.ts @@ -454,7 +454,6 @@ mermaid.initialize(${JSON.stringify(mermaidOpts)}); 0, ); warning(error.message); - console.log(""); return await makeDefault(); } else { if (isRevealjsOutput(handlerContext.options.context.format.pandoc)) { @@ -467,7 +466,6 @@ mermaid.initialize(${JSON.stringify(mermaidOpts)}); 0, ); warning(error.message); - console.log(""); } return await makeJs(); } diff --git a/src/core/lib/external/colors.ts b/src/core/lib/external/colors.ts index 05d151d6544..b9783c83aa2 100644 --- a/src/core/lib/external/colors.ts +++ b/src/core/lib/external/colors.ts @@ -12,7 +12,7 @@ /** * ```ts * import { bgBlue, red, bold } from "https://deno.land/std@$STD_VERSION/fmt/colors"; - * console.log(bgBlue(red(bold("Hello world!")))); + * console["log"](bgBlue(red(bold("Hello world!")))); * ``` * * This module supports `NO_COLOR` environmental variable disabling any coloring diff --git a/src/core/lib/yaml-intelligence/yaml-intelligence.ts b/src/core/lib/yaml-intelligence/yaml-intelligence.ts index 6ef9b902d99..d46adc97465 100644 --- a/src/core/lib/yaml-intelligence/yaml-intelligence.ts +++ b/src/core/lib/yaml-intelligence/yaml-intelligence.ts @@ -1231,7 +1231,7 @@ export async function getCompletions( await init(context); return await getAutomation("completions", context); } catch (e) { - console.log("Error found during autocomplete", e); + console["log"]("Error found during autocomplete", e); exportSmokeTest("completions", context); return null; } @@ -1245,7 +1245,7 @@ export async function getLint( await init(context); return await getAutomation("validation", context); } catch (e) { - console.log("Error found during linting", e); + console["log"]("Error found during linting", e); exportSmokeTest("validation", context); return null; } @@ -1259,7 +1259,7 @@ export async function getHover( await init(context); return hover(context); } catch (e) { - console.log("Error found during hover", e); + console["log"]("Error found during hover", e); exportSmokeTest("hover", context); return null; } diff --git a/src/core/main.ts b/src/core/main.ts index 5dc1d94f5c6..7f3a3cc5632 100644 --- a/src/core/main.ts +++ b/src/core/main.ts @@ -18,6 +18,7 @@ import { import { makeTimedFunctionAsync } from "./performance/function-times.ts"; import { isWindows } from "../deno_ral/platform.ts"; import { convertCombinedLuaProfileToCSV } from "./performance/perfetto-utils.ts"; +import { info } from "../deno_ral/log.ts"; type Runner = (args: Args) => Promise; export async function mainRunner(runner: Runner) { @@ -48,8 +49,8 @@ export async function mainRunner(runner: Runner) { // if profiling, wait for 10 seconds before quitting if (Deno.env.get("QUARTO_TS_PROFILE") !== undefined) { - console.log("Program finished. Turn off the Chrome profiler now!"); - console.log("Waiting for 10 seconds ..."); + info("Program finished. Turn off the Chrome profiler now!"); + info("Waiting for 10 seconds ..."); await new Promise((resolve) => setTimeout(resolve, 10000)); } diff --git a/src/core/performance/metrics.ts b/src/core/performance/metrics.ts index 8bb50375364..8d3cb1c1d3d 100644 --- a/src/core/performance/metrics.ts +++ b/src/core/performance/metrics.ts @@ -4,6 +4,7 @@ * Copyright (C) 2020-2023 Posit Software, PBC */ +import { info } from "../../deno_ral/log.ts"; import { inputTargetIndexCacheMetrics } from "../../project/project-index.ts"; import { functionTimes } from "./function-times.ts"; import { Stats } from "./stats.ts"; @@ -64,9 +65,12 @@ export function reportPerformanceMetrics(keys?: MetricsKeys[]) { if (outFile) { Deno.writeTextFileSync(outFile, content); } else { - console.log("---"); - console.log("Performance metrics"); - console.log("Quarto:"); - console.log(content); + const msg = [ + "---", + "Performance metrics", + "Quarto:", + content, + ]; + info(msg.join("\n")); } } diff --git a/src/core/puppeteer.ts b/src/core/puppeteer.ts index a86b694bf7e..34a611a147c 100644 --- a/src/core/puppeteer.ts +++ b/src/core/puppeteer.ts @@ -132,7 +132,7 @@ export async function withPuppeteerBrowserAndPage( (allowedErrorMessages.indexOf(error.message) !== -1) && (attempts < maxAttempts) ) { - console.log( + error( `\nEncountered a bad error message from puppeteer: "${error.message}"\n Retrying ${attempts}/${maxAttempts}`, ); } else { @@ -174,7 +174,7 @@ export async function inPuppeteer( (allowedErrorMessages.indexOf(error.message) !== -1) && (attempts < maxAttempts) ) { - console.log( + error( `\nEncountered a bad error message from puppeteer: "${error.message}"\n Retrying ${attempts}/${maxAttempts}`, ); } else { diff --git a/src/core/sass/analyzer/declaration-types.ts b/src/core/sass/analyzer/declaration-types.ts index a3b742bb5f7..d2ed1441dfa 100644 --- a/src/core/sass/analyzer/declaration-types.ts +++ b/src/core/sass/analyzer/declaration-types.ts @@ -1,3 +1,5 @@ +import { warn } from "../../../deno_ral/log.ts"; + export const propagateDeclarationTypes = (ast: any) => { const declarationsToTrack = new Map(); @@ -81,12 +83,12 @@ export const propagateDeclarationTypes = (ast: any) => { // let's not be this loud // // else { - // console.log(Deno.env.get("QUARTO_DEBUG")); - // console.log( + // info(Deno.env.get("QUARTO_DEBUG")); + // info( // "Warning: variable redeclaration with conflicting default settings", // ); - // console.log("variable: ", varName); - // console.log("lines ", prevDeclaration?.line, node?.line); + // info("variable: ", varName); + // info("lines ", prevDeclaration?.line, node?.line); // } } } else { @@ -180,8 +182,8 @@ export const propagateDeclarationTypes = (ast: any) => { !declarationsToTrack.has(nodeVariableName) && !namesToIgnore.has(nodeVariableName) ) { - console.log("Warning: variable used before declaration"); - console.log("variable: ", nodeVariableName, valueNode.line); + warn("Warning: variable used before declaration"); + warn(`variable: ${nodeVariableName} ${valueNode.line}`); return undefined; } else { const valueType = declarationsToTrack.get(nodeVariableName)?.valueType; @@ -213,15 +215,15 @@ export const propagateDeclarationTypes = (ast: any) => { // // now warn about variables with unknown types // for (const [name, node] of declarationsToTrack) { // if (node.valueType === "color") { - // console.log(name, node.line) + // warn(name, node.line) // } // if (!node.valueType && node.value.value.length === 1) { // // ignore unknown types for multi-value declarations, assume they're arrays which we don't care about. // if (node.value.value[0]?.type === "parentheses") { // continue; // } - // console.log("Warning: variable with unknown type"); - // console.log("variable: ", name, node); + // warn("Warning: variable with unknown type"); + // warn("variable: ", name, node); // } // } }; diff --git a/src/core/sass/analyzer/get-dependencies.ts b/src/core/sass/analyzer/get-dependencies.ts index 7247937a5d5..9bfcfc74766 100644 --- a/src/core/sass/analyzer/get-dependencies.ts +++ b/src/core/sass/analyzer/get-dependencies.ts @@ -1,36 +1,40 @@ +import { error } from "../../../deno_ral/log.ts"; import { walk } from "./ast-utils.ts"; // import { assert } from "jsr:@std/assert"; +// deno-lint-ignore no-explicit-any const assert = (condition: any) => { if (!condition) { throw new Error("Assertion failed"); } -} +}; export const getVariableDependencies = (declarations: Map) => { const dependencies = new Map + // deno-lint-ignore no-explicit-any + node: any; + dependencies: Set; }>(); for (const [name, node] of declarations) { assert(node?.type === "declaration"); const varName = node?.property?.variable?.value; assert(varName === name); if (!dependencies.has(varName)) { - dependencies.set(varName, {node: node, dependencies: new Set()}); + dependencies.set(varName, { node: node, dependencies: new Set() }); } const varValue = node?.value; + // deno-lint-ignore no-explicit-any walk(varValue, (inner: any) => { if (inner?.type === "variable") { const innerName = inner?.value; if (!innerName) { - console.log(inner); - throw new Error("stop") + error(inner); + throw new Error("stop"); } - dependencies.get(varName)!.dependencies.add(innerName); + dependencies.get(varName)!.dependencies.add(innerName); } return true; }); } return dependencies; -} \ No newline at end of file +}; diff --git a/src/core/schema/json-schema-from-schema.ts b/src/core/schema/json-schema-from-schema.ts index 081a2f3a2db..b250a1a146d 100644 --- a/src/core/schema/json-schema-from-schema.ts +++ b/src/core/schema/json-schema-from-schema.ts @@ -14,6 +14,7 @@ import { JsonObject, SchemaSchema, } from "../../resources/types/schema-schema-types.ts"; +import { error } from "../../deno_ral/log.ts"; // https://json-schema.org/draft/2020-12/json-schema-core#name-json-schema-documents type JsonSchema = JsonObject | boolean; @@ -129,8 +130,8 @@ const convertSchemaToJSONSchema = (_schema: SchemaSchema): JsonSchema => { }; } } else { - console.log({ schema }); - console.log(typeof schema); + error({ schema }); + error(typeof schema); throw new Error(`fallthrough?`); } } else { @@ -140,7 +141,7 @@ const convertSchemaToJSONSchema = (_schema: SchemaSchema): JsonSchema => { }; } } - console.log(JSON.stringify(schema, null, 2)); + error(JSON.stringify(schema, null, 2)); throw new Error("Not implemented"); }; @@ -152,8 +153,8 @@ export const generateJsonSchemasFromSchemas = async (resourcePath: string) => { try { acc[name] = convertSchemaToJSONSchema(schema); } catch (e) { - console.log("Outermost failing schema:"); - console.log(JSON.stringify(schema)); + error("Outermost failing schema:"); + error(JSON.stringify(schema)); throw e; } return acc; diff --git a/src/core/typst.ts b/src/core/typst.ts index 09e95cab994..b24e6023ec8 100644 --- a/src/core/typst.ts +++ b/src/core/typst.ts @@ -167,7 +167,7 @@ export async function typstWatch( typstProgressDone(); } child.status.then((status) => { - console.log(`typst exited with status ${status.code}`); + error(`typst exited with status ${status.code}`); }); break; } diff --git a/src/deno_ral/log.ts b/src/deno_ral/log.ts index 5a9d6623fc5..4bea86d5d1a 100644 --- a/src/deno_ral/log.ts +++ b/src/deno_ral/log.ts @@ -11,6 +11,7 @@ export { info, LogLevels, setup, + warn, warn as warning, } from "log"; diff --git a/src/execute/ojs/extract-resources.ts b/src/execute/ojs/extract-resources.ts index 9bacb1a89d3..c492ab18cc7 100644 --- a/src/execute/ojs/extract-resources.ts +++ b/src/execute/ojs/extract-resources.ts @@ -362,7 +362,7 @@ async function resolveImport( ) !== -1 ); - console.log(errorLines); + error(errorLines); const errorCountRe = /^Found (\d+) errors.$/; const errorCount = Number( (errorLines.filter((x) => (x.trim().match(errorCountRe)))[0] ?? @@ -377,14 +377,14 @@ async function resolveImport( if (m === null) { // this is an internal error, but we do the best we can by simply printing out the // error as we know it - console.log(errStr); + error(errStr); throw new InternalError("Internal error in deno ojs cell compilation."); } const badFile = fromFileUrl(m[1]); const badContents = Deno.readTextFileSync(badFile); if (!badContents.startsWith("/** @jsxImportSource quarto-tsx */")) { - console.log(` + error(` File ${colors.red(badFile)} must start with ${colors.yellow("/** @jsxImportSource quarto-tsx */")} @@ -394,7 +394,7 @@ We apologize for the inconvenience; this is a temporary workaround for an upstre } if (denoBugErrorLines.length !== errorCount) { - console.log(`Other compilation errors follow below.\n`); + error(`Other compilation errors follow below.\n`); let colorErrorLines = lines(errStr); for (let i = denoBugErrorLines.length - 1; i >= 0; i--) { @@ -411,7 +411,7 @@ We apologize for the inconvenience; this is a temporary workaround for an upstre } throw new Error(); } - console.log(errStr); + error(errStr); throw new Error(); } diff --git a/src/format/html/format-html.ts b/src/format/html/format-html.ts index e2bfc2a9830..b69a9663da1 100644 --- a/src/format/html/format-html.ts +++ b/src/format/html/format-html.ts @@ -148,7 +148,7 @@ function recursiveModuleDependencies( }); const analysis = esbuildCachedAnalysis(inpRelPath); - // console.log(JSON.stringify(analysis, null, 2)); + // info(JSON.stringify(analysis, null, 2)); for (const [_key, value] of Object.entries(analysis.outputs)) { for (const imp of value.imports) { if (imp.external) { diff --git a/src/resources/scripts/check-usage.ts b/src/resources/scripts/check-usage.ts index 4b367c81b93..2ddd67774f7 100644 --- a/src/resources/scripts/check-usage.ts +++ b/src/resources/scripts/check-usage.ts @@ -18,7 +18,7 @@ if (import.meta.main) { } else if (size.endsWith("B")) { sizeNo = Number(size.slice(0, -1)); } else { - console.log(`Don't know how to read ${size}`); + console["log"](`Don't know how to read ${size}`); continue; } if ( @@ -34,8 +34,8 @@ if (import.meta.main) { sizedEntriesArray.sort((a, b) => a[1] - b[1]); let sum = 0; for (const entry of sizedEntriesArray) { - console.log(`${entry[0]} ${entry[1]}`); + console["log"](`${entry[0]} ${entry[1]}`); sum += entry[1]; } - console.log(`Overall: ${sum}`); + console["log"](`Overall: ${sum}`); } diff --git a/src/resources/scripts/empty.ts b/src/resources/scripts/empty.ts index dc39c5fcd94..c38aa92ddad 100644 --- a/src/resources/scripts/empty.ts +++ b/src/resources/scripts/empty.ts @@ -1,3 +1,3 @@ if (import.meta.main) { - console.log("you ran an essentially empty script."); + console["log"]("you ran an essentially empty script."); } diff --git a/src/resources/scripts/juice.ts b/src/resources/scripts/juice.ts index 93a1359a979..1b4810aa992 100644 --- a/src/resources/scripts/juice.ts +++ b/src/resources/scripts/juice.ts @@ -1,7 +1,7 @@ import juice from "stdlib/juice"; const input = await Deno.readTextFile(Deno.args[0]); -console.log(juice(input)); +console["log"](juice(input)); // not available in skypack version -// juice.juiceResources(input, {}, (err, output) => console.log(output)) +// juice.juiceResources(input, {}, (err, output) => console["log"](output))