perf: use node: prefix to bypass require.cache call for builtins#407
perf: use node: prefix to bypass require.cache call for builtins#407Uzlopak merged 2 commits intofastify:masterfrom Fdawgs:perf/builtins
node: prefix to bypass require.cache call for builtins#407Conversation
|
Seem to be getting test failures locally even on |
|
It might be because of a test that modifies/mocks a built-in module |
|
Modifying t.test(
'register with rootpath that causes statSync to fail with non-ENOENT code',
(t) => {
const fastifyStatic = proxyquire('../', {
'node:fs': { // HERE: fs -> 'node:fs'
statSync: function statSyncStub (path) {
throw new Error({ code: 'MOCK' })
}
}
})
const pluginOptions = {
root: path.join(__dirname, '/static'),
wildcard: true
}
const fastify = Fastify()
fastify.register(fastifyStatic, pluginOptions)
t.teardown(fastify.close.bind(fastify))
fastify.listen({ port: 0 }, (err) => {
fastify.server.unref()
t.ok(err)
t.end()
})
}
) |
Eomm
left a comment
There was a problem hiding this comment.
I was today years old...
Core modules can be identified using the node: prefix, in which case it bypasses the require cache. For instance, require('node:http') will always return the built in HTTP module, even if there is require.cache entry by that name.
Didn't know it
LGTM on green pipeline 👍🏼
|
Happy to mass update rest of the repos with a similar PR at some point this weekend, unless @gurgunday beats me to it 😂 |
|
What about prefixing npm packages with npm:? Wouldnt we then be deno compatible? |
🤣, I just wanted to get the ones I actively use out of the way in case there is a release or something I would of course prefer if you created a script for it 😁 |
Can't find anything in node's documentation about supporting this? |
) * perf: use `node:` prefix to bypass require.cache call for builtins See fastify/fastify-static#407 * docs: use `node:` prefix to bypass require.cache call for builtins
|
@mcollina happy to update Pino repos accordingly also, wdyt? |
node: prefix to bypass require.cache call for builtins
fastify/fastify-request-context#201
See https://github.com/nodejs/node/pull/37246/files#r588397158 and https://nodejs.org/api/modules.html#core-modules
Checklist
npm run testandnpm run benchmarkand the Code of conduct