Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix deprecated Deno APIs "Deno.stderr.rid" "Deno.isatty()" "Deno.run()" #3610

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions lib/deno/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,21 +184,26 @@ let ensureServiceIsRunning = (): Promise<Service> => {
if (!longLivedService) {
longLivedService = (async (): Promise<Service> => {
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
Expand All @@ -211,10 +216,9 @@ let ensureServiceIsRunning = (): Promise<Service> => {
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()
})
}
Expand All @@ -229,12 +233,11 @@ let ensureServiceIsRunning = (): Promise<Service> => {
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 => {
Expand Down Expand Up @@ -331,13 +334,14 @@ let ensureServiceIsRunning = (): Promise<Service> => {

// 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)
})
}
5 changes: 4 additions & 1 deletion scripts/deno-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down