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

deno: move from std node polyfills to node: specifier #771

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 2 additions & 4 deletions cjs/src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,8 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
lifeTimer.cancel()
connectTimer.cancel()

if (socket.encrypted) {
socket.removeAllListeners()
socket = null
}
socket.removeAllListeners()
socket = null

if (initial)
return reconnect()
Expand Down
189 changes: 0 additions & 189 deletions deno/polyfills.js

This file was deleted.

2 changes: 1 addition & 1 deletion deno/src/bytes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Buffer } from 'https://deno.land/[email protected]/node/buffer.ts'
import { Buffer } from 'node:buffer'
const size = 256
let buffer = Buffer.allocUnsafe(size)

Expand Down
21 changes: 9 additions & 12 deletions deno/src/connection.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { HmacSha256 } from 'https://deno.land/[email protected]/hash/sha256.ts'
import { Buffer } from 'https://deno.land/[email protected]/node/buffer.ts'
import { setImmediate, clearImmediate } from '../polyfills.js'
import { net } from '../polyfills.js'
import { tls } from '../polyfills.js'
import crypto from 'https://deno.land/[email protected]/node/crypto.ts'
import Stream from 'https://deno.land/[email protected]/node/stream.ts'
import { Buffer } from 'node:buffer'
import { setImmediate, clearImmediate } from 'node:timers'
import net from 'node:net'
import tls from 'node:tls'
import crypto from 'node:crypto'
import Stream from 'node:stream'


import { stringify, handleValue, arrayParser, arraySerializer } from './types.js'
Expand Down Expand Up @@ -432,10 +431,8 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
lifeTimer.cancel()
connectTimer.cancel()

if (socket.encrypted) {
socket.removeAllListeners()
socket = null
}
socket.removeAllListeners()
socket = null

if (initial)
return reconnect()
Expand Down Expand Up @@ -1003,7 +1000,7 @@ function md5(x) {
}

function hmac(key, x) {
return Buffer.from(new HmacSha256(key).update(x).digest())
return crypto.createHmac('sha256', key).update(x).digest()
}

function sha256(x) {
Expand Down
6 changes: 3 additions & 3 deletions deno/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import process from 'https://deno.land/[email protected]/node/process.ts'
import os from 'https://deno.land/[email protected]/node/os.ts'
import fs from 'https://deno.land/[email protected]/node/fs.ts'
import process from 'node:process'
import os from 'node:os'
import fs from 'node:fs'

import {
mergeUserTypes,
Expand Down
2 changes: 1 addition & 1 deletion deno/src/large.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Stream from 'https://deno.land/[email protected]/node/stream.ts'
import Stream from 'node:stream'

export default function largeObject(sql, oid, mode = 0x00020000 | 0x00040000) {
return new Promise(async(resolve, reject) => {
Expand Down
2 changes: 1 addition & 1 deletion deno/src/subscribe.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Buffer } from 'https://deno.land/[email protected]/node/buffer.ts'
import { Buffer } from 'node:buffer'
const noop = () => { /* noop */ }

export default function Subscribe(postgres, options) {
Expand Down
2 changes: 1 addition & 1 deletion deno/src/types.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Buffer } from 'https://deno.land/[email protected]/node/buffer.ts'
import { Buffer } from 'node:buffer'
import { Query } from './query.js'
import { Errors } from './errors.js'

Expand Down
2 changes: 1 addition & 1 deletion deno/tests/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { spawn } from 'https://deno.land/[email protected]/node/child_process.ts'
import { spawn } from 'node:child_process'

await exec('dropdb', ['postgres_js_test'])

Expand Down
10 changes: 5 additions & 5 deletions deno/tests/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Buffer } from 'https://deno.land/[email protected]/node/buffer.ts'
import process from 'https://deno.land/[email protected]/node/process.ts'
import { Buffer } from 'node:buffer'
import process from 'node:process'
import { exec } from './bootstrap.js'

import { t, nt, ot } from './test.js' // eslint-disable-line
import { net } from '../polyfills.js'
import fs from 'https://deno.land/[email protected]/node/fs.ts'
import crypto from 'https://deno.land/[email protected]/node/crypto.ts'
import net from 'node:net'
import fs from 'node:fs'
import crypto from 'node:crypto'

import postgres from '../src/index.js'
const delay = ms => new Promise(r => setTimeout(r, ms))
Expand Down
4 changes: 2 additions & 2 deletions deno/tests/test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import process from 'https://deno.land/[email protected]/node/process.ts'
import process from 'node:process'
/* eslint no-console: 0 */

import util from 'https://deno.land/[email protected]/node/util.ts'
import util from 'node:util'

let done = 0
let only = false
Expand Down
6 changes: 3 additions & 3 deletions deno/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Buffer } from 'https://deno.land/[email protected]/node/buffer.ts'
import process from 'https://deno.land/[email protected]/node/process.ts'
import { Readable, Writable } from 'https://deno.land/[email protected]/node/stream.ts'
import { Buffer } from 'node:buffer'
import process from 'node:process'
import { Readable, Writable } from 'node:stream'

/**
* Establish a connection to a PostgreSQL server.
Expand Down
26 changes: 7 additions & 19 deletions transpile.deno.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import fs from 'fs'
import path from 'path'

const std = 'https://deno.land/[email protected]/'
, empty = x => fs.readdirSync(x).forEach(f => fs.unlinkSync(path.join(x, f)))
const empty = x => fs.readdirSync(x).forEach(f => fs.unlinkSync(path.join(x, f)))
, ensureEmpty = x => !fs.existsSync(x) ? fs.mkdirSync(x) : empty(x)
, root = 'deno'
, src = path.join(root, 'src')
Expand All @@ -21,7 +20,7 @@ fs.writeFileSync(
fs.writeFileSync(
path.join(root, 'README.md'),
fs.readFileSync('README.md', 'utf8')
.replace(/### Installation(\n.*){4}/, '')
.replace(/### Installation[\s\S]*?(?=\n##)/m, '')
.replace(
'import postgres from \'postgres\'',
'import postgres from \'https://deno.land/x/postgresjs/mod.js\''
Expand Down Expand Up @@ -59,34 +58,23 @@ function transpile(x, name, folder) {
}

const buffer = x.includes('Buffer')
? 'import { Buffer } from \'' + std + 'node/buffer.ts\'\n'
? 'import { Buffer } from \'node:buffer\'\n'
: ''

const process = x.includes('process.')
? 'import process from \'' + std + 'node/process.ts\'\n'
? 'import process from \'node:process\'\n'
: ''

const timers = x.includes('setImmediate')
? 'import { setImmediate, clearImmediate } from \'../polyfills.js\'\n'
? 'import { setImmediate, clearImmediate } from \'node:timers\'\n'
: ''

const hmac = x.includes('createHmac')
? 'import { HmacSha256 } from \'' + std + 'hash/sha256.ts\'\n'
: ''

return hmac + buffer + process + timers + x
.replace(
'crypto.createHmac(\'sha256\', key).update(x).digest()',
'Buffer.from(new HmacSha256(key).update(x).digest())'
)
return buffer + process + timers + x
.replace(
'query.writable.push({ chunk, callback })',
'(query.writable.push({ chunk }), callback())'
)
.replace('socket.setKeepAlive(true, 1000 * keep_alive)', 'socket.setKeepAlive(true)')
.replace('node:stream', std + 'node/stream.ts')
.replace('import net from \'net\'', 'import { net } from \'../polyfills.js\'')
.replace('import tls from \'tls\'', 'import { tls } from \'../polyfills.js\'')
.replace('import { performance } from \'perf_hooks\'', '')
.replace(/ from '([a-z_]+)'/g, ' from \'' + std + 'node/$1.ts\'')
.replace(/ from '([a-z_]+)'/g, ' from \'node:$1\'')
}