Skip to content

Commit

Permalink
chore: use 'node:'-prefix for requiring node core modules (#2662)
Browse files Browse the repository at this point in the history
* chore: use 'node:'-prefix for require

* add core modules with underscore in name
  • Loading branch information
Uzlopak authored Jan 29, 2024
1 parent 189e572 commit b04d65c
Show file tree
Hide file tree
Showing 181 changed files with 371 additions and 371 deletions.
14 changes: 7 additions & 7 deletions benchmarks/benchmark-http2.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict'

const { connect } = require('http2')
const { createSecureContext } = require('tls')
const os = require('os')
const path = require('path')
const { readFileSync } = require('fs')
const { Writable } = require('stream')
const { isMainThread } = require('worker_threads')
const { connect } = require('node:http2')
const { createSecureContext } = require('node:tls')
const os = require('node:os')
const path = require('node:path')
const { readFileSync } = require('node:fs')
const { Writable } = require('node:stream')
const { isMainThread } = require('node:worker_threads')

const { Pool, Client, fetch, Agent, setGlobalDispatcher } = require('..')

Expand Down
12 changes: 6 additions & 6 deletions benchmarks/benchmark-https.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict'

const https = require('https')
const os = require('os')
const path = require('path')
const { readFileSync } = require('fs')
const { Writable } = require('stream')
const { isMainThread } = require('worker_threads')
const https = require('node:https')
const os = require('node:os')
const path = require('node:path')
const { readFileSync } = require('node:fs')
const { Writable } = require('node:stream')
const { isMainThread } = require('node:worker_threads')

const { Pool, Client, fetch, Agent, setGlobalDispatcher } = require('..')

Expand Down
12 changes: 6 additions & 6 deletions benchmarks/benchmark.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
'use strict'

const http = require('http')
const os = require('os')
const path = require('path')
const { Writable } = require('stream')
const { isMainThread } = require('worker_threads')
const http = require('node:http')
const os = require('node:os')
const path = require('node:path')
const { Writable } = require('node:stream')
const { isMainThread } = require('node:worker_threads')

const { Pool, Client, fetch, Agent, setGlobalDispatcher } = require('..')

let nodeFetch
const axios = require('axios')
let got

const util = require('util')
const util = require('node:util')
const _request = require('request')
const request = util.promisify(_request)

Expand Down
10 changes: 5 additions & 5 deletions benchmarks/server-http2.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict'

const { unlinkSync, readFileSync } = require('fs')
const { createSecureServer } = require('http2')
const os = require('os')
const path = require('path')
const cluster = require('cluster')
const { unlinkSync, readFileSync } = require('node:fs')
const { createSecureServer } = require('node:http2')
const os = require('node:os')
const path = require('node:path')
const cluster = require('node:cluster')

const key = readFileSync(path.join(__dirname, '..', 'test', 'fixtures', 'key.pem'), 'utf8')
const cert = readFileSync(path.join(__dirname, '..', 'test', 'fixtures', 'cert.pem'), 'utf8')
Expand Down
10 changes: 5 additions & 5 deletions benchmarks/server-https.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict'

const { unlinkSync, readFileSync } = require('fs')
const { createServer } = require('https')
const os = require('os')
const path = require('path')
const cluster = require('cluster')
const { unlinkSync, readFileSync } = require('node:fs')
const { createServer } = require('node:https')
const os = require('node:os')
const path = require('node:path')
const cluster = require('node:cluster')

const key = readFileSync(path.join(__dirname, '..', 'test', 'fixtures', 'key.pem'), 'utf8')
const cert = readFileSync(path.join(__dirname, '..', 'test', 'fixtures', 'cert.pem'), 'utf8')
Expand Down
10 changes: 5 additions & 5 deletions benchmarks/server.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict'

const { unlinkSync } = require('fs')
const { createServer } = require('http')
const os = require('os')
const path = require('path')
const cluster = require('cluster')
const { unlinkSync } = require('node:fs')
const { createServer } = require('node:http')
const os = require('node:os')
const path = require('node:path')
const cluster = require('node:cluster')

const socketPath = path.join(os.tmpdir(), 'undici.sock')

Expand Down
4 changes: 2 additions & 2 deletions benchmarks/wait.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const os = require('os')
const path = require('path')
const os = require('node:os')
const path = require('node:path')
const waitOn = require('wait-on')

const socketPath = path.join(os.tmpdir(), 'undici.sock')
Expand Down
6 changes: 3 additions & 3 deletions build/wasm.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'

const { execSync } = require('child_process')
const { writeFileSync, readFileSync } = require('fs')
const { join, resolve, basename } = require('path')
const { execSync } = require('node:child_process')
const { writeFileSync, readFileSync } = require('node:fs')
const { join, resolve, basename } = require('node:path')

const ROOT = resolve(__dirname, '../')
const WASM_SRC = resolve(__dirname, '../deps/llhttp')
Expand Down
6 changes: 3 additions & 3 deletions docs/best-practices/client-certificate.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ The server option `rejectUnauthorized: false` allows us to handle any invalid ce
### Client Certificate Authentication

```js
const { readFileSync } = require('fs')
const { join } = require('path')
const { createServer } = require('https')
const { readFileSync } = require('node:fs')
const { join } = require('node:path')
const { createServer } = require('node:https')
const { Client } = require('undici')

const serverOptions = {
Expand Down
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async function postJSONRequest (port = 3001) {
const { request } = require('undici')
async function postFormRequest (port = 3001) {
// Make a URL-encoded form POST request:
const qs = require('querystring')
const qs = require('node:querystring')

const requestBody = {
hello: 'URL Encoded Example body'
Expand Down
4 changes: 2 additions & 2 deletions examples/ca-fingerprint/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const crypto = require('crypto')
const https = require('https')
const crypto = require('node:crypto')
const https = require('node:https')
const { Client, buildConnector } = require('../..')
const pem = require('https-pem')

Expand Down
2 changes: 1 addition & 1 deletion examples/eventsource.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { randomBytes } = require('crypto')
const { randomBytes } = require('node:crypto')
const { EventSource } = require('../')

async function main () {
Expand Down
2 changes: 1 addition & 1 deletion examples/proxy/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { Pool, Client } = require('../../')
const http = require('http')
const http = require('node:http')
const proxy = require('./proxy')

const pool = new Pool('http://localhost:4001', {
Expand Down
4 changes: 2 additions & 2 deletions examples/proxy/proxy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const net = require('net')
const { pipeline } = require('stream')
const net = require('node:net')
const { pipeline } = require('node:stream')
const createError = require('http-errors')

module.exports = async function proxy (ctx, client) {
Expand Down
2 changes: 1 addition & 1 deletion examples/proxy/websocket.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { Pool, Client } = require('../../')
const http = require('http')
const http = require('node:http')
const proxy = require('./proxy')
const WebSocket = require('ws')

Expand Down
2 changes: 1 addition & 1 deletion examples/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async function postJSONRequest (port = 3001) {

async function postFormRequest (port = 3001) {
// Make a URL-encoded form POST request:
const qs = require('querystring')
const qs = require('node:querystring')

const requestBody = {
hello: 'URL Encoded Example body'
Expand Down
2 changes: 1 addition & 1 deletion lib/api/api-connect.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { AsyncResource } = require('async_hooks')
const { AsyncResource } = require('node:async_hooks')
const { InvalidArgumentError, RequestAbortedError, SocketError } = require('../core/errors')
const util = require('../core/util')
const { addSignal, removeSignal } = require('./abort-signal')
Expand Down
6 changes: 3 additions & 3 deletions lib/api/api-pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ const {
Readable,
Duplex,
PassThrough
} = require('stream')
} = require('node:stream')
const {
InvalidArgumentError,
InvalidReturnValueError,
RequestAbortedError
} = require('../core/errors')
const util = require('../core/util')
const { AsyncResource } = require('async_hooks')
const { AsyncResource } = require('node:async_hooks')
const { addSignal, removeSignal } = require('./abort-signal')
const assert = require('assert')
const assert = require('node:assert')

const kResume = Symbol('resume')

Expand Down
2 changes: 1 addition & 1 deletion lib/api/api-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const {
} = require('../core/errors')
const util = require('../core/util')
const { getResolveErrorBodyCallback } = require('./util')
const { AsyncResource } = require('async_hooks')
const { AsyncResource } = require('node:async_hooks')
const { addSignal, removeSignal } = require('./abort-signal')

class RequestHandler extends AsyncResource {
Expand Down
4 changes: 2 additions & 2 deletions lib/api/api-stream.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
'use strict'

const { finished, PassThrough } = require('stream')
const { finished, PassThrough } = require('node:stream')
const {
InvalidArgumentError,
InvalidReturnValueError,
RequestAbortedError
} = require('../core/errors')
const util = require('../core/util')
const { getResolveErrorBodyCallback } = require('./util')
const { AsyncResource } = require('async_hooks')
const { AsyncResource } = require('node:async_hooks')
const { addSignal, removeSignal } = require('./abort-signal')

class StreamHandler extends AsyncResource {
Expand Down
4 changes: 2 additions & 2 deletions lib/api/api-upgrade.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict'

const { InvalidArgumentError, RequestAbortedError, SocketError } = require('../core/errors')
const { AsyncResource } = require('async_hooks')
const { AsyncResource } = require('node:async_hooks')
const util = require('../core/util')
const { addSignal, removeSignal } = require('./abort-signal')
const assert = require('assert')
const assert = require('node:assert')

class UpgradeHandler extends AsyncResource {
constructor (opts, callback) {
Expand Down
4 changes: 2 additions & 2 deletions lib/api/readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

'use strict'

const assert = require('assert')
const { Readable } = require('stream')
const assert = require('node:assert')
const { Readable } = require('node:stream')
const { RequestAbortedError, NotSupportedError, InvalidArgumentError, AbortError } = require('../core/errors')
const util = require('../core/util')
const { ReadableStreamFrom } = require('../core/util')
Expand Down
2 changes: 1 addition & 1 deletion lib/api/util.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('assert')
const assert = require('node:assert')
const {
ResponseStatusCodeError
} = require('../core/errors')
Expand Down
2 changes: 1 addition & 1 deletion lib/cache/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { Request, fromInnerRequest } = require('../fetch/request')
const { kState } = require('../fetch/symbols')
const { fetching } = require('../fetch/index')
const { urlIsHttpHttpsScheme, createDeferredPromise, readAllBytes } = require('../fetch/util')
const assert = require('assert')
const assert = require('node:assert')
const { getGlobalDispatcher } = require('../global')

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/cache/util.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const assert = require('assert')
const assert = require('node:assert')
const { URLSerializer } = require('../fetch/dataURL')
const { isValidHeaderName } = require('../fetch/util')

Expand Down
10 changes: 5 additions & 5 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

/* global WebAssembly */

const assert = require('assert')
const net = require('net')
const http = require('http')
const { pipeline } = require('stream')
const assert = require('node:assert')
const net = require('node:net')
const http = require('node:http')
const { pipeline } = require('node:stream')
const util = require('./core/util')
const { channels } = require('./core/diagnostics')
const timers = require('./timers')
Expand Down Expand Up @@ -84,7 +84,7 @@ const {
/** @type {import('http2')} */
let http2
try {
http2 = require('http2')
http2 = require('node:http2')
} catch {
// @ts-ignore
http2 = { constants: {} }
Expand Down
2 changes: 1 addition & 1 deletion lib/cookies/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const { maxNameValuePairSize, maxAttributeValueSize } = require('./constants')
const { isCTLExcludingHtab } = require('./util')
const { collectASequenceOfCodePointsFast } = require('../fetch/dataURL')
const assert = require('assert')
const assert = require('node:assert')

/**
* @description Parses the field-value attributes of a set-cookie header string.
Expand Down
2 changes: 1 addition & 1 deletion lib/cookies/util.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const assert = require('assert')
const assert = require('node:assert')
const { kHeadersList } = require('../core/symbols')

function isCTLExcludingHtab (value) {
Expand Down
6 changes: 3 additions & 3 deletions lib/core/connect.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const net = require('net')
const assert = require('assert')
const net = require('node:net')
const assert = require('node:assert')
const util = require('./util')
const { InvalidArgumentError, ConnectTimeoutError } = require('./errors')

Expand Down Expand Up @@ -86,7 +86,7 @@ function buildConnector ({ allowH2, maxCachedSessions, socketPath, timeout, ...o
let socket
if (protocol === 'https:') {
if (!tls) {
tls = require('tls')
tls = require('node:tls')
}
servername = servername || options.servername || util.getServerName(host) || null

Expand Down
4 changes: 2 additions & 2 deletions lib/core/diagnostics.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'
const diagnosticsChannel = require('diagnostics_channel')
const util = require('util')
const diagnosticsChannel = require('node:diagnostics_channel')
const util = require('node:util')

const undiciDebugLog = util.debuglog('undici')
const fetchDebuglog = util.debuglog('fetch')
Expand Down
2 changes: 1 addition & 1 deletion lib/core/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const {
InvalidArgumentError,
NotSupportedError
} = require('./errors')
const assert = require('assert')
const assert = require('node:assert')
const { kHTTP2BuildRequest, kHTTP2CopyHeaders, kHTTP1BuildRequest } = require('./symbols')
const util = require('./util')
const { channels } = require('./diagnostics.js')
Expand Down
Loading

0 comments on commit b04d65c

Please sign in to comment.