Skip to content

Commit b32cd3e

Browse files
committed
chore - deno 2
1 parent 402d574 commit b32cd3e

18 files changed

Lines changed: 94 additions & 30 deletions

File tree

src/command/render/pandoc.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ import { isWindows } from "../../deno_ral/platform.ts";
207207
import { appendToCombinedLuaProfile } from "../../core/performance/perfetto-utils.ts";
208208
import { makeTimedFunctionAsync } from "../../core/performance/function-times.ts";
209209
import { walkJson } from "../../core/json.ts";
210+
import { call } from "../../deno_ral/process.ts";
210211

211212
// in case we are running multiple pandoc processes
212213
// we need to make sure we capture all of the trace files
@@ -1572,9 +1573,9 @@ async function resolveExtras(
15721573
};
15731574
const woff2ttf = async (url: string) => {
15741575
const path = url_to_path(url);
1575-
await Deno.run({ cmd: ["ttx", join(font_cache, path)] });
1576-
await Deno.run({
1577-
cmd: ["ttx", join(font_cache, path.replace(/woff2?$/, "ttx"))],
1576+
await call("ttx", { args: [join(font_cache, path)] });
1577+
await call("ttx", {
1578+
args: [join(font_cache, path.replace(/woff2?$/, "ttx"))],
15781579
});
15791580
};
15801581
const ttf_urls2: Array<string> = [], woff_urls2: Array<string> = [];

src/command/render/render-files.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ import {
115115
import { NotebookContext } from "../../render/notebook/notebook-types.ts";
116116
import { setExecuteEnvironment } from "../../execute/environment.ts";
117117
import { safeCloneDeep } from "../../core/safe-clone-deep.ts";
118+
import { warn } from "log";
118119

119120
export async function renderExecute(
120121
context: RenderContext,
@@ -346,6 +347,10 @@ export async function renderFiles(
346347

347348
return await pandocRenderer.onComplete(false, options.flags?.quiet);
348349
} catch (error) {
350+
if (!(error instanceof Error)) {
351+
warn("Should not have arrived here:", error);
352+
throw error;
353+
}
349354
return {
350355
files: (await pandocRenderer.onComplete(true)).files,
351356
error: error || new Error(),
@@ -399,6 +404,10 @@ export async function renderFile(
399404
}
400405
return await pandocRenderer.onComplete(false, options.flags?.quiet);
401406
} catch (error) {
407+
if (!(error instanceof Error)) {
408+
warn("Should not have arrived here:", error);
409+
throw error;
410+
}
402411
return {
403412
files: (await pandocRenderer.onComplete(true)).files,
404413
error: error || new Error(),

src/core/cri/cri.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
registerForExitCleanup,
2222
unregisterForExitCleanup,
2323
} from "../process.ts";
24+
import { assert } from "testing/asserts";
2425

2526
async function waitForServer(port: number, timeout = 3000) {
2627
const interval = 50;
@@ -87,8 +88,7 @@ export async function criClient(appPath?: string, port?: number) {
8788
// Allow to adapt the headless mode depending on the Chrome version
8889
const headlessMode = getenv("QUARTO_CHROMIUM_HEADLESS_MODE", "none");
8990

90-
const cmd = [
91-
app,
91+
const args = [
9292
// TODO: Chrome v128 changed the default from --headless=old to --headless=new
9393
// in 2024-08. Old headless mode was effectively a separate browser render,
9494
// and while more performant did not share the same browser implementation as
@@ -106,19 +106,27 @@ export async function criClient(appPath?: string, port?: number) {
106106
"--renderer-process-limit=1",
107107
`--remote-debugging-port=${port}`,
108108
];
109-
const browser = Deno.run({ cmd, stdout: "piped", stderr: "piped" });
109+
const browser = new Deno.Command(app, {
110+
args,
111+
stdout: "piped",
112+
stderr: "piped",
113+
});
110114

115+
const cmd = browser.spawn();
111116
// Register for cleanup inside exitWithCleanup() in case something goes wrong
112-
const thisProcessId = registerForExitCleanup(browser);
117+
const thisProcessId = registerForExitCleanup(cmd);
113118

114119
if (!(await waitForServer(port as number))) {
115120
let msg = "Couldn't find open server.";
116121
// Printing more error information if chrome process errored
117-
if (!(await browser.status()).success) {
122+
if (!(await cmd.status).success) {
118123
debug(`[CHROMIUM path] : ${app}`);
119124
debug(`[CHROMIUM cmd] : ${cmd}`);
120-
const rawError = await browser.stderrOutput();
121-
const errorString = new TextDecoder().decode(rawError);
125+
const rawError = await cmd.stderr;
126+
const reader = rawError.getReader();
127+
const readerResult = await reader.read();
128+
assert(readerResult.done);
129+
const errorString = new TextDecoder().decode(readerResult.value!);
122130
msg = msg + "\n" + `Chrome process error: ${errorString}`;
123131
}
124132

@@ -135,8 +143,7 @@ export async function criClient(appPath?: string, port?: number) {
135143
// We have a bug where `client.close()` doesn't return properly and we don't go below
136144
// meaning the `browser` process is not killed here, and it will be handled in exitWithCleanup().
137145

138-
browser.kill(); // Chromium headless won't terminate on its own, so we need to send kill signal
139-
browser.close(); // Closing the browser Deno process
146+
cmd.kill(); // Chromium headless won't terminate on its own, so we need to send kill signal
140147
unregisterForExitCleanup(thisProcessId); // All went well so not need to cleanup on quarto exit
141148
},
142149

src/core/deno-dom.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ export async function initDenoDom() {
166166
return;
167167
}
168168
} catch (e) {
169+
if (!(e instanceof Error)) {
170+
throw e;
171+
}
169172
debug("Error loading deno-dom-native: " + e.message);
170173
}
171174
}

src/core/deno/monkey-patch.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ function withAttempts<T>(callable: () => T) {
2727
try {
2828
return callable();
2929
} catch (err) {
30+
if (!(err instanceof Error)) {
31+
throw err;
32+
}
3033
if (err.message) {
3134
debug("Error attempting to create temp file: " + err.message);
3235
if (i === maxAttempts - 1) {
@@ -43,6 +46,9 @@ function withAttempts<T>(callable: () => T) {
4346
function withAttemptsAsync<T>(callable: () => Promise<T>) {
4447
const inner = (attempt: number): Promise<T> => {
4548
return callable().catch((err) => {
49+
if (!(err instanceof Error)) {
50+
throw err;
51+
}
4652
if (err.message) {
4753
debug("Error attempting to create temp file: " + err.message);
4854
}
@@ -91,6 +97,9 @@ Deno.readTextFile = async (
9197
const result = await oldReadTextFile(path, options);
9298
return result;
9399
} catch (err) {
100+
if (!(err instanceof Error)) {
101+
throw err;
102+
}
94103
if (err.message) {
95104
err.message = err.message + "\n" + "Path: " + path;
96105
}
@@ -103,6 +112,9 @@ Deno.readTextFileSync = (path: string | URL) => {
103112
const result = oldReadTextFileSync(path);
104113
return result;
105114
} catch (err) {
115+
if (!(err instanceof Error)) {
116+
throw err;
117+
}
106118
if (err.message) {
107119
err.message = err.message + "\n" + "Path: " + path;
108120
}

src/execute/rmd.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export const knitrEngine: ExecutionEngine = {
9797
try {
9898
metadata = readYamlFromMarkdown(markdown.value);
9999
} catch (e) {
100+
if (!(e instanceof Error)) throw e;
100101
error(`Error reading metadata from ${file}.\n${e.message}`);
101102
throw e;
102103
}
@@ -282,8 +283,8 @@ async function callR<T>(
282283
try {
283284
const result = await execProcess(
284285
{
285-
cmd: [
286-
await rBinaryPath("Rscript"),
286+
cmd: await rBinaryPath("Rscript"),
287+
args: [
287288
...rscriptArgsArray,
288289
resourcePath("rmd/rmd.R"),
289290
],
@@ -317,6 +318,9 @@ async function callR<T>(
317318
return Promise.reject();
318319
}
319320
} catch (e) {
321+
if (!(e instanceof Error)) {
322+
throw e;
323+
}
320324
if (reportError) {
321325
if (e?.message) {
322326
info("");

src/extension/extension-host.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ export async function extensionSource(
6262
};
6363
}
6464
} catch (err) {
65+
if (!(err instanceof Error)) {
66+
throw err;
67+
}
6568
err.message =
6669
`A network error occurred when attempting to inspect the extension '${target}'. Please try again.\n\n` +
6770
err.message;

src/format/reveal/format-reveal-multiplex.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ async function revealMultiplexToken(
159159
};
160160
return multiplex;
161161
} catch (e) {
162+
if (!(e instanceof Error)) {
163+
throw e;
164+
}
162165
throw Error(
163166
"Error attempting to provision multiplex token from '" + url + "': " +
164167
e.message,

src/preview/preview-server.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,23 @@ export function runExternalPreviewServer(options: {
3434
env?: { [key: string]: string };
3535
cwd?: string;
3636
}): PreviewServer {
37+
const { cmd } = options;
3738
// start the process
38-
const process = Deno.run({
39+
const denoCommand = new Deno.Command(cmd[0], {
40+
args: cmd.slice(1),
3941
...options,
4042
stdout: "piped",
4143
stderr: "piped",
4244
});
4345

46+
const process = denoCommand.spawn();
47+
4448
// merge and stream stdout and stderr
4549
const multiplexIterator = new MuxAsyncIterator<
4650
Uint8Array
4751
>();
48-
multiplexIterator.add(iterateReader(process.stdout));
49-
multiplexIterator.add(iterateReader(process.stderr));
52+
multiplexIterator.add(process.stdout);
53+
multiplexIterator.add(process.stderr);
5054

5155
// wait for ready and then return from 'start'
5256
const decoder = new TextDecoder();
@@ -65,15 +69,14 @@ export function runExternalPreviewServer(options: {
6569
for await (const chunk of multiplexIterator) {
6670
Deno.stderr.writeSync(chunk);
6771
}
68-
await process.status();
72+
await process.output();
6973
},
7074
stop: () => {
7175
if (!isWindows) {
7276
Deno.kill(-process.pid, "SIGTERM");
7377
} else {
7478
process.kill();
7579
}
76-
process.close();
7780
return Promise.resolve();
7881
},
7982
};

src/preview/preview-text.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ async function textPreviewHtml(file: string, req: Request) {
155155
);
156156
cmd.push("--standalone");
157157
const result = await execProcess({
158-
cmd,
158+
cmd: cmd[0],
159+
args: cmd.slice(1),
159160
stdout: "piped",
160161
}, markdown);
161162
if (result.success) {
@@ -244,7 +245,7 @@ async function gfmPreview(file: string, request: Request) {
244245
// Github renders math with MathJax now, so our preview mode does the same
245246
cmd.push("--mathjax");
246247
const result = await execProcess(
247-
{ cmd, stdout: "piped", stderr: "piped" },
248+
{ cmd: cmd[0], args: cmd.slice(1), stdout: "piped", stderr: "piped" },
248249
Deno.readTextFileSync(file),
249250
);
250251
if (result.success) {

0 commit comments

Comments
 (0)