From 488ce573bb1a43046c455d398055a48305eb483b Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Fri, 15 Sep 2023 09:44:03 +0100 Subject: [PATCH] perf: use `node:` prefix to bypass require.cache call for builtins (#56) * perf: use `node:` prefix to bypass require.cache call for builtins See https://github.com/fastify/fastify-static/pull/407 * chore: fix linting * test: fix tests --- benchmark/create.js | 1 - benchmark/index.js | 6 +++--- benchmark/secret.js | 1 - benchmark/verify.js | 1 - index.js | 2 +- test/secret.test.js | 8 ++++---- 6 files changed, 8 insertions(+), 11 deletions(-) diff --git a/benchmark/create.js b/benchmark/create.js index b1aa6da..c2e6948 100644 --- a/benchmark/create.js +++ b/benchmark/create.js @@ -1,4 +1,3 @@ - /** * Module dependencies. */ diff --git a/benchmark/index.js b/benchmark/index.js index fb820ca..56c0fe3 100644 --- a/benchmark/index.js +++ b/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() diff --git a/benchmark/secret.js b/benchmark/secret.js index 7b33f74..37b2681 100644 --- a/benchmark/secret.js +++ b/benchmark/secret.js @@ -1,4 +1,3 @@ - /** * Module dependencies. */ diff --git a/benchmark/verify.js b/benchmark/verify.js index d5e1657..34ef99d 100644 --- a/benchmark/verify.js +++ b/benchmark/verify.js @@ -1,4 +1,3 @@ - /** * Module dependencies. */ diff --git a/index.js b/index.js index 40c45a3..9ca4edd 100644 --- a/index.js +++ b/index.js @@ -8,7 +8,7 @@ * MIT Licensed */ -const crypto = require('crypto') +const crypto = require('node:crypto') /** * Token generation/verification class. diff --git a/test/secret.test.js b/test/secret.test.js index ca50ddc..b402a55 100644 --- a/test/secret.test.js +++ b/test/secret.test.js @@ -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 } }) @@ -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 } })