From 7502cb37094824ef9f57c6784d5bd95c6f524fe2 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Sun, 10 Sep 2023 09:35:52 +0100 Subject: [PATCH] perf: use `node:` prefix to bypass require.cache call for builtins (#210) See https://github.com/fastify/fastify-static/pull/407 --- benchmark/bench.js | 2 +- lib/idGenerator.js | 2 +- lib/session.js | 2 +- lib/store.js | 4 ++-- test/fastifySession.checkOptions.test.js | 2 +- test/memorystore.test.js | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/benchmark/bench.js b/benchmark/bench.js index 46a5f0c..b30ad32 100644 --- a/benchmark/bench.js +++ b/benchmark/bench.js @@ -4,7 +4,7 @@ const redisStoreFactory = require('connect-redis') const Fastify = require('fastify') const Redis = require('ioredis') const fileStoreFactory = require('session-file-store') -const { isMainThread } = require('worker_threads') +const { isMainThread } = require('node:worker_threads') const fastifySession = require('..') const fastifyCookie = require('@fastify/cookie') diff --git a/lib/idGenerator.js b/lib/idGenerator.js index d4e351d..e0d4cc7 100644 --- a/lib/idGenerator.js +++ b/lib/idGenerator.js @@ -1,6 +1,6 @@ 'use strict' -const randomBytes = require('crypto').randomBytes +const randomBytes = require('node:crypto').randomBytes const cacheSize = 24 << 7 let pos = 0 diff --git a/lib/session.js b/lib/session.js index 5fd1d5a..26247ad 100644 --- a/lib/session.js +++ b/lib/session.js @@ -1,6 +1,6 @@ 'use strict' -const crypto = require('crypto') +const crypto = require('node:crypto') const Cookie = require('./cookie') const { configure: configureStringifier } = require('safe-stable-stringify') diff --git a/lib/store.js b/lib/store.js index 818f5b9..c05d534 100644 --- a/lib/store.js +++ b/lib/store.js @@ -1,7 +1,7 @@ 'use strict' -const EventEmitter = require('events').EventEmitter -const util = require('util') +const EventEmitter = require('node:events').EventEmitter +const util = require('node:util') function Store (storeMap = new Map()) { this.store = storeMap diff --git a/test/fastifySession.checkOptions.test.js b/test/fastifySession.checkOptions.test.js index bdd1b2e..d11868c 100644 --- a/test/fastifySession.checkOptions.test.js +++ b/test/fastifySession.checkOptions.test.js @@ -4,7 +4,7 @@ const test = require('tap').test const Fastify = require('fastify') const fastifyCookie = require('@fastify/cookie') const fastifySession = require('..') -const crypto = require('crypto') +const crypto = require('node:crypto') test('fastifySession.checkOptions: register should fail if no secret is specified', async t => { t.plan(1) diff --git a/test/memorystore.test.js b/test/memorystore.test.js index e9dc093..25fc838 100644 --- a/test/memorystore.test.js +++ b/test/memorystore.test.js @@ -2,7 +2,7 @@ const test = require('tap').test const { MemoryStore } = require('../lib/store') -const { EventEmitter } = require('stream') +const { EventEmitter } = require('node:stream') test('MemoryStore.constructor: created MemoryStore should be an EventEmitter', (t) => { t.plan(2)