Skip to content

Commit

Permalink
perf: use node: prefix to bypass require.cache call for builtins (#56)
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

* chore: fix linting

* test: fix tests
  • Loading branch information
Fdawgs committed Sep 15, 2023
1 parent 90ccc1f commit 488ce57
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 11 deletions.
1 change: 0 additions & 1 deletion benchmark/create.js
@@ -1,4 +1,3 @@

/**
* Module dependencies.
*/
Expand Down
6 changes: 3 additions & 3 deletions benchmark/index.js
@@ -1,6 +1,6 @@
const fs = require('fs')
const path = require('path')
const spawn = require('child_process').spawn
const fs = require('node:fs')
const path = require('node:path')
const spawn = require('node:child_process').spawn

const exe = process.argv[0]
const cwd = process.cwd()
Expand Down
1 change: 0 additions & 1 deletion benchmark/secret.js
@@ -1,4 +1,3 @@

/**
* Module dependencies.
*/
Expand Down
1 change: 0 additions & 1 deletion benchmark/verify.js
@@ -1,4 +1,3 @@

/**
* Module dependencies.
*/
Expand Down
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -8,7 +8,7 @@
* MIT Licensed
*/

const crypto = require('crypto')
const crypto = require('node:crypto')

/**
* Token generation/verification class.
Expand Down
8 changes: 4 additions & 4 deletions test/secret.test.js
Expand Up @@ -76,11 +76,11 @@ test('Tokens.secret: should handle error, Promise', t => {
t.plan(2)

const Tokens = mock('..', {
crypto: {
'node:crypto': {
randomBytes: (_size, cb) => {
cb(new Error('oh no'))
},
createHash: require('crypto').createHash
createHash: require('node:crypto').createHash
}
})

Expand All @@ -94,11 +94,11 @@ test('Tokens.secret: should handle error, callback', t => {
t.plan(2)

const Tokens = mock('..', {
crypto: {
'node:crypto': {
randomBytes: (size, cb) => {
cb(new Error('oh no'))
},
createHash: require('crypto').createHash
createHash: require('node:crypto').createHash
}
})

Expand Down

0 comments on commit 488ce57

Please sign in to comment.