From d9574cc562ac454173503caa7b4a328d69ec5b32 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Sun, 10 Sep 2023 08:31:35 +0100 Subject: [PATCH 1/3] perf: use `node:` prefix to bypass require.cache call for builtins See https://github.com/fastify/fastify-static/pull/407 --- benchmark/index.js | 6 +++--- index.js | 2 +- test/secret.test.js | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) 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/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..ff06b1a 100644 --- a/test/secret.test.js +++ b/test/secret.test.js @@ -80,7 +80,7 @@ test('Tokens.secret: should handle error, Promise', t => { randomBytes: (_size, cb) => { cb(new Error('oh no')) }, - createHash: require('crypto').createHash + createHash: require('node:crypto').createHash } }) @@ -98,7 +98,7 @@ test('Tokens.secret: should handle error, callback', t => { randomBytes: (size, cb) => { cb(new Error('oh no')) }, - createHash: require('crypto').createHash + createHash: require('node:crypto').createHash } }) From 08a212c031b7bee4b752d0d43371917433cd96d4 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Fri, 15 Sep 2023 09:16:21 +0100 Subject: [PATCH 2/3] chore: fix linting --- benchmark/create.js | 1 - benchmark/secret.js | 1 - benchmark/verify.js | 1 - 3 files changed, 3 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/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. */ From 2eafa9b38afe885edb2762c75d32b461a2eb65d4 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Fri, 15 Sep 2023 09:17:43 +0100 Subject: [PATCH 3/3] test: fix tests --- test/secret.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/secret.test.js b/test/secret.test.js index ff06b1a..b402a55 100644 --- a/test/secret.test.js +++ b/test/secret.test.js @@ -76,7 +76,7 @@ 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')) }, @@ -94,7 +94,7 @@ 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')) },