From 04913c3336ab5054b516fb443abbc2821786d1c9 Mon Sep 17 00:00:00 2001 From: David Bushell Date: Fri, 26 Jan 2024 04:31:36 +0000 Subject: [PATCH] fix deprecated Deno APIs "Deno.stderr.rid" "Deno.isatty()" "Deno.run()" --- lib/deno/mod.ts | 36 ++++++++++++++++++++---------------- scripts/deno-tests.js | 5 ++++- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/lib/deno/mod.ts b/lib/deno/mod.ts index 7e24f389a74..aaeff619b08 100644 --- a/lib/deno/mod.ts +++ b/lib/deno/mod.ts @@ -184,21 +184,26 @@ let ensureServiceIsRunning = (): Promise => { if (!longLivedService) { longLivedService = (async (): Promise => { const binPath = await install() - const isTTY = Deno.isatty(Deno.stderr.rid) + const isTTY = Deno.stderr.isTerminal() - const child = Deno.run({ - cmd: [binPath, `--service=${version}`], + const command = new Deno.Command(binPath, { + args: [ + `--service=${version}` + ], cwd: defaultWD, stdin: 'piped', stdout: 'piped', stderr: 'inherit', }) + const child = command.spawn() + const writer = child.stdin.getWriter() + const reader = child.stdout.getReader() stopService = () => { // Close all resources related to the subprocess. + writer.releaseLock() child.stdin.close() - child.stdout.close() - child.close() + child.kill() initializeWasCalled = false longLivedService = undefined stopService = undefined @@ -211,10 +216,9 @@ let ensureServiceIsRunning = (): Promise => { const startWriteFromQueueWorker = () => { if (isQueueLocked || writeQueue.length === 0) return isQueueLocked = true - child.stdin.write(writeQueue[0]).then(bytesWritten => { + writer.write(writeQueue[0]).then(() => { isQueueLocked = false - if (bytesWritten === writeQueue[0].length) writeQueue.shift() - else writeQueue[0] = writeQueue[0].subarray(bytesWritten) + writeQueue.shift() startWriteFromQueueWorker() }) } @@ -229,12 +233,11 @@ let ensureServiceIsRunning = (): Promise => { esbuild: ourselves, }) - const stdoutBuffer = new Uint8Array(4 * 1024 * 1024) - const readMoreStdout = () => child.stdout.read(stdoutBuffer).then(n => { - if (n === null) { + const readMoreStdout = () => reader.read().then(({done, value}) => { + if (done || !value) { afterClose(null) } else { - readFromStdout(stdoutBuffer.subarray(0, n)) + readFromStdout(value) readMoreStdout() } }).catch(e => { @@ -331,13 +334,14 @@ let ensureServiceIsRunning = (): Promise => { // If we're called as the main script, forward the CLI to the underlying executable if (import.meta.main) { - Deno.run({ - cmd: [await install()].concat(Deno.args), + const command = new Deno.Command(await install(), { + args: Deno.args, cwd: defaultWD, stdin: 'inherit', stdout: 'inherit', - stderr: 'inherit', - }).status().then(({ code }) => { + stderr:'inherit', + }) + command.output().then(({ code }) => { Deno.exit(code) }) } diff --git a/scripts/deno-tests.js b/scripts/deno-tests.js index e0748e7ba1d..c30627737f4 100644 --- a/scripts/deno-tests.js +++ b/scripts/deno-tests.js @@ -14,6 +14,8 @@ try { } Deno.mkdirSync(rootTestDir, { recursive: true }) +await esbuildNative.initialize() + function test(name, backends, fn) { const singleTest = (name, fn) => Deno.test({ name, @@ -37,7 +39,7 @@ function test(name, backends, fn) { await fn({ esbuild: esbuildNative, testDir }) await Deno.remove(testDir, { recursive: true }).catch(() => null) } finally { - esbuildNative.stop() + // esbuildNative.stop() } }) break @@ -75,6 +77,7 @@ function test(name, backends, fn) { window.addEventListener("unload", (e) => { try { + esbuildNative.stop() Deno.removeSync(rootTestDir, { recursive: true }) } catch { // root test dir possibly already removed, so ignore