Skip to content

Commit

Permalink
perf: use node: prefix to bypass require.cache call for builtins (#274
Browse files Browse the repository at this point in the history
)

* perf: use `node:` prefix to bypass require.cache call for builtins

See fastify/fastify-static#407

* try to fix

---------

Co-authored-by: Uzlopak <aras.abbasi@googlemail.com>
  • Loading branch information
Fdawgs and Uzlopak authored Sep 10, 2023
1 parent fb45df9 commit 00b36e6
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion lib/commands/publish.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const assert = require('assert').strict
const assert = require('node:assert').strict
const pino = require('pino')
const { validate } = require('../validation')
const draft = require('./draft')
Expand Down
6 changes: 3 additions & 3 deletions lib/editor.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict'

const fs = require('fs')
const { promisify } = require('util')
const fs = require('node:fs')
const { promisify } = require('node:util')
const open = require('open-editor')
const tempWrite = require('temp-write')
const { spawn } = require('child_process')
const { spawn } = require('node:child_process')

const readFile = promisify(fs.readFile)

Expand Down
6 changes: 3 additions & 3 deletions lib/git-directory.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'

const { join } = require('path')
const { readFileSync } = require('fs')
const { promisify } = require('util')
const { join } = require('node:path')
const { readFileSync } = require('node:fs')
const { promisify } = require('node:util')
const SimpleGit = require('simple-git')

module.exports = function gitDirectory (path) {
Expand Down
4 changes: 2 additions & 2 deletions lib/man.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const path = require('path')
const { readFileSync } = require('fs')
const path = require('node:path')
const { readFileSync } = require('node:fs')

module.exports.needToShowHelp = function (file, opts) {
if (opts.help || opts._.length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion lib/npm.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

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

function runSpawn (cwd, cmd, args) {
return new Promise((resolve, reject) => {
Expand Down
2 changes: 1 addition & 1 deletion test/command-config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const t = require('tap')
const h = require('./helper')
const fs = require('fs')
const fs = require('node:fs')

const cmd = h.buildProxyCommand('../lib/commands/config')
const LocalConf = require('../lib/local-conf')
Expand Down
2 changes: 1 addition & 1 deletion test/command-draft.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const t = require('tap')
const { join } = require('path')
const { join } = require('node:path')
const h = require('./helper')

const cmd = h.buildProxyCommand('../lib/commands/draft', {
Expand Down
12 changes: 6 additions & 6 deletions test/command-publish.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'

const { EventEmitter } = require('events')
const { EventEmitter } = require('node:events')
const t = require('tap')
const { join } = require('path')
const { join } = require('node:path')
const proxyquire = require('proxyquire')
const h = require('./helper')

Expand Down Expand Up @@ -467,14 +467,14 @@ test('publish a module minor editing the release message', async t => {
return { arguments: [] }
}
},
child_process: {
'node:child_process': {
spawn: () => {
const e = new EventEmitter()
setImmediate(() => { e.emit('exit', 0) })
return e
}
},
fs: {
'node:fs': {
readFile (tmpFile, opts, cb) {
t.equal(tmpFile, fakeFile)
cb(null, 'my message')
Expand Down Expand Up @@ -524,14 +524,14 @@ test('editor error', t => {
return { arguments: [] }
}
},
child_process: {
'node:child_process': {
spawn: () => {
const e = new EventEmitter()
setImmediate(() => { e.emit('exit', 1) })
return e
}
},
fs: {
'node:fs': {
readFile () { t.fail('The file has not been edited') }
}
})
Expand Down
8 changes: 4 additions & 4 deletions test/helper.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'

const { spawn } = require('child_process')
const fs = require('fs')
const path = require('path')
const { spawn } = require('node:child_process')
const fs = require('node:fs')
const path = require('node:path')
const proxyquire = require('proxyquire')

const factorySimpleGit = require('./proxy/simple-git-proxy')
Expand Down Expand Up @@ -30,7 +30,7 @@ function buildProxyCommand (commandPath, opts = {}) {
'@octokit/rest': factoryOctokit(opts.github)
}),
'../npm': proxyquire('../lib/npm', {
child_process: factoryNpm(opts.npm)
'node:child_process': factoryNpm(opts.npm)
}),
...opts.external
})
Expand Down

0 comments on commit 00b36e6

Please sign in to comment.