Skip to content

Commit

Permalink
perf: use node: prefix to bypass require.cache call for builtins
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdawgs committed Sep 12, 2023
1 parent c4996a2 commit 145d562
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 30 deletions.
6 changes: 3 additions & 3 deletions bin/mssql
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env node
const { Command } = require('commander')
const { version } = require('../package.json')
const { resolve: resolvePath } = require('path')
const { constants: { R_OK } } = require('fs')
const { resolve: resolvePath } = require('node:path')
const { constants: { R_OK } } = require('node:fs')
const { ConnectionPool } = require('../')
const { lstat, access, readFile } = require('fs').promises
const { lstat, access, readFile } = require('node:fs/promises')
Buffer.prototype.toJSON = () => {
return `0x${this.toString('hex')}`
}
Expand Down
2 changes: 1 addition & 1 deletion lib/base/connection-pool.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { EventEmitter } = require('events')
const { EventEmitter } = require('node:events')
const debug = require('debug')('mssql:base')
const { parseSqlConnectionString } = require('@tediousjs/connection-string')
const tarn = require('tarn')
Expand Down
2 changes: 1 addition & 1 deletion lib/base/prepared-statement.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const debug = require('debug')('mssql:base')
const { EventEmitter } = require('events')
const { EventEmitter } = require('node:events')
const { IDS, objectHasProperty } = require('../utils')
const globalConnection = require('../global-connection')
const { TransactionError, PreparedStatementError } = require('../error')
Expand Down
4 changes: 2 additions & 2 deletions lib/base/request.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'

const debug = require('debug')('mssql:base')
const { EventEmitter } = require('events')
const { Readable } = require('stream')
const { EventEmitter } = require('node:events')
const { Readable } = require('node:stream')
const { IDS, objectHasProperty } = require('../utils')
const globalConnection = require('../global-connection')
const { RequestError, ConnectionError } = require('../error')
Expand Down
2 changes: 1 addition & 1 deletion lib/base/transaction.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const debug = require('debug')('mssql:base')
const { EventEmitter } = require('events')
const { EventEmitter } = require('node:events')
const { IDS } = require('../utils')
const globalConnection = require('../global-connection')
const { TransactionError } = require('../error')
Expand Down
2 changes: 1 addition & 1 deletion lib/msnodesqlv8/connection-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const BaseConnectionPool = require('../base/connection-pool')
const { IDS, INCREMENT } = require('../utils')
const shared = require('../shared')
const ConnectionError = require('../error/connection-error')
const { platform } = require('os')
const { platform } = require('node:os')
const { buildConnectionString } = require('@tediousjs/connection-string')

const CONNECTION_DRIVER = ['darwin', 'linux'].includes(platform()) ? 'ODBC Driver 17 for SQL Server' : 'SQL Server Native Client 11.0'
Expand Down
6 changes: 3 additions & 3 deletions test/common/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

/* globals describe, it */

const assert = require('assert')
const { join } = require('path')
const assert = require('node:assert')
const { join } = require('node:path')
const { spawn } = require('child_process')

const config = function () {
const cfg = JSON.parse(require('fs').readFileSync(join(__dirname, '../.mssql.json')))
const cfg = JSON.parse(require('node:fs').readFileSync(join(__dirname, '../.mssql.json')))
cfg.driver = 'tedious'
return cfg
}
Expand Down
2 changes: 1 addition & 1 deletion test/common/templatestring.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')

module.exports = (sql, driver) => {
return {
Expand Down
8 changes: 4 additions & 4 deletions test/common/tests.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict'

const assert = require('assert')
const stream = require('stream')
const { join } = require('path')
const { format } = require('util')
const assert = require('node:assert')
const stream = require('node:stream')
const { join } = require('node:path')
const { format } = require('node:util')
const ISOLATION_LEVELS = require('../../lib/isolationlevel')
const BaseTransaction = require('../../lib/base/transaction')
const versionHelper = require('./versionhelper')
Expand Down
2 changes: 1 addition & 1 deletion test/common/times.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')

module.exports = (sql, driver) => {
return {
Expand Down
2 changes: 1 addition & 1 deletion test/common/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* globals describe, it, afterEach */

const sql = require('../../')
const assert = require('assert')
const assert = require('node:assert')
const udt = require('../../lib/udt')
const BasePool = require('../../lib/base/connection-pool')
const ConnectionPool = require('../../lib/tedious/connection-pool')
Expand Down
10 changes: 5 additions & 5 deletions test/msnodesqlv8/msnodesqlv8.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

/* globals describe, it, before, after, afterEach */

const { join } = require('path')
const { join } = require('node:path')
const sql = require('../../msnodesqlv8')

const TESTS = require('../common/tests.js')(sql, 'msnodesqlv8')
const TIMES = require('../common/times.js')(sql, 'msnodesqlv8')
const versionHelper = require('../common/versionhelper')

const config = function () {
const cfg = JSON.parse(require('fs').readFileSync(join(__dirname, '../.mssql.json')))
const cfg = JSON.parse(require('node:fs').readFileSync(join(__dirname, '../.mssql.json')))
cfg.driver = 'msnodesqlv8'
return cfg
}
Expand All @@ -24,11 +24,11 @@ describe('msnodesqlv8', function () {
if (err) return done(err)

let req = new sql.Request()
req.batch(require('fs').readFileSync(join(__dirname, '../cleanup.sql'), 'utf8'), function (err) {
req.batch(require('node:fs').readFileSync(join(__dirname, '../cleanup.sql'), 'utf8'), function (err) {
if (err) return done(err)

req = new sql.Request()
req.batch(require('fs').readFileSync(join(__dirname, '../prepare.sql'), 'utf8'), function (err) {
req.batch(require('node:fs').readFileSync(join(__dirname, '../prepare.sql'), 'utf8'), function (err) {
if (err) return done(err)

sql.close(done)
Expand Down Expand Up @@ -245,7 +245,7 @@ describe('msnodesqlv8', function () {
if (err) return done(err)

const req = new sql.Request()
req.query(require('fs').readFileSync(join(__dirname, '../cleanup.sql'), 'utf8'), function (err) {
req.query(require('node:fs').readFileSync(join(__dirname, '../cleanup.sql'), 'utf8'), function (err) {
if (err) return done(err)

sql.close(done)
Expand Down
12 changes: 6 additions & 6 deletions test/tedious/tedious.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/* globals describe, it, before, after, afterEach */

const sql = require('../../tedious.js')
const assert = require('assert')
const { join } = require('path')
const assert = require('node:assert')
const { join } = require('node:path')

const TESTS = require('../common/tests.js')(sql, 'tedious')
const TIMES = require('../common/times.js')(sql, 'tedious')
Expand All @@ -16,7 +16,7 @@ if (parseInt(process.version.match(/^v(\d+)\./)[1]) > 0) {
}

const config = function () {
const cfg = JSON.parse(require('fs').readFileSync(join(__dirname, '../.mssql.json')))
const cfg = JSON.parse(require('node:fs').readFileSync(join(__dirname, '../.mssql.json')))
cfg.driver = 'tedious'
return cfg
}
Expand All @@ -30,11 +30,11 @@ describe('tedious', () => {
if (err) return done(err)

let req = new sql.Request()
req.query(require('fs').readFileSync(join(__dirname, '../cleanup.sql'), 'utf8'), err => {
req.query(require('node:fs').readFileSync(join(__dirname, '../cleanup.sql'), 'utf8'), err => {
if (err) return done(err)

req = new sql.Request()
req.query(require('fs').readFileSync(join(__dirname, '../prepare.sql'), 'utf8'), err => {
req.query(require('node:fs').readFileSync(join(__dirname, '../prepare.sql'), 'utf8'), err => {
if (err) return done(err)

sql.close(done)
Expand Down Expand Up @@ -345,7 +345,7 @@ describe('tedious', () => {
if (err) return done(err)

const req = new sql.Request()
req.query(require('fs').readFileSync(join(__dirname, '../cleanup.sql'), 'utf8'), function (err) {
req.query(require('node:fs').readFileSync(join(__dirname, '../cleanup.sql'), 'utf8'), function (err) {
if (err) return done(err)

sql.close(done)
Expand Down

0 comments on commit 145d562

Please sign in to comment.