From 30723112e3bd0ab4863ce517cd2c1671fc890422 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Sun, 10 Sep 2023 08:31:37 +0100 Subject: [PATCH] perf: use `node:` prefix to bypass require.cache call for builtins See https://github.com/fastify/fastify-static/pull/407 --- index.js | 6 +++--- scripts/unit-typescript-esbuild.js | 2 +- scripts/unit-typescript-esm.js | 2 +- scripts/unit-typescript-swc-node-register.js | 2 +- scripts/unit-typescript-swc.js | 2 +- scripts/unit-typescript-tsm.js | 2 +- scripts/unit-typescript-tsx.js | 2 +- scripts/unit.js | 2 +- test/commonjs/autohooks/basic.js | 2 +- test/commonjs/autohooks/cascade.js | 2 +- test/commonjs/autohooks/disabled.js | 2 +- test/commonjs/autohooks/overwrite.js | 2 +- test/commonjs/babel-node.js | 2 +- test/commonjs/basic/app.js | 4 ++-- test/commonjs/cyclic-dependency/app.js | 2 +- test/commonjs/deep/app.js | 2 +- test/commonjs/dependency/app.js | 2 +- test/commonjs/graph-dependency/app.js | 2 +- test/commonjs/index-error/app.js | 2 +- test/commonjs/module-error/app.js | 2 +- test/commonjs/non-plugin/app.js | 2 +- test/commonjs/options/app.js | 2 +- test/commonjs/route-parameters/basic.js | 2 +- test/commonjs/route-parameters/disabled.js | 2 +- test/commonjs/syntax-error/app.js | 2 +- test/commonjs/ts-error/app.js | 2 +- 26 files changed, 29 insertions(+), 29 deletions(-) diff --git a/index.js b/index.js index fe684112..6173c897 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,8 @@ 'use strict' -const path = require('path') -const url = require('url') -const { readdir } = require('fs').promises +const path = require('node:path') +const url = require('node:url') +const { readdir } = require('node:fs').promises const pkgUp = require('pkg-up') const isTsNode = (Symbol.for('ts-node.register.instance') in process) || !!process.env.TS_NODE_DEV diff --git a/scripts/unit-typescript-esbuild.js b/scripts/unit-typescript-esbuild.js index 432499b2..ba270bb3 100644 --- a/scripts/unit-typescript-esbuild.js +++ b/scripts/unit-typescript-esbuild.js @@ -1,6 +1,6 @@ 'use strict' -const { exec } = require('child_process') +const { exec } = require('node:child_process') const args = [ 'node', diff --git a/scripts/unit-typescript-esm.js b/scripts/unit-typescript-esm.js index 537e043a..d9d6caec 100644 --- a/scripts/unit-typescript-esm.js +++ b/scripts/unit-typescript-esm.js @@ -1,6 +1,6 @@ 'use strict' -const { exec } = require('child_process') +const { exec } = require('node:child_process') const args = [ 'tap', diff --git a/scripts/unit-typescript-swc-node-register.js b/scripts/unit-typescript-swc-node-register.js index db763bae..2fbf7738 100644 --- a/scripts/unit-typescript-swc-node-register.js +++ b/scripts/unit-typescript-swc-node-register.js @@ -1,6 +1,6 @@ 'use strict' -const { exec } = require('child_process') +const { exec } = require('node:child_process') const args = [ 'tap', diff --git a/scripts/unit-typescript-swc.js b/scripts/unit-typescript-swc.js index 94cd3664..4648e021 100644 --- a/scripts/unit-typescript-swc.js +++ b/scripts/unit-typescript-swc.js @@ -1,6 +1,6 @@ 'use strict' -const { exec } = require('child_process') +const { exec } = require('node:child_process') const args = [ 'tap', diff --git a/scripts/unit-typescript-tsm.js b/scripts/unit-typescript-tsm.js index 8c6c1c21..f2eb48bc 100644 --- a/scripts/unit-typescript-tsm.js +++ b/scripts/unit-typescript-tsm.js @@ -1,6 +1,6 @@ 'use strict' -const { exec } = require('child_process') +const { exec } = require('node:child_process') const args = [ 'tap', diff --git a/scripts/unit-typescript-tsx.js b/scripts/unit-typescript-tsx.js index ede6e820..7774f3ac 100644 --- a/scripts/unit-typescript-tsx.js +++ b/scripts/unit-typescript-tsx.js @@ -1,6 +1,6 @@ 'use strict' -const { exec } = require('child_process') +const { exec } = require('node:child_process') const args = [ 'npx', diff --git a/scripts/unit.js b/scripts/unit.js index 9a53edc8..dd9f74c5 100644 --- a/scripts/unit.js +++ b/scripts/unit.js @@ -1,6 +1,6 @@ 'use strict' -const { exec } = require('child_process') +const { exec } = require('node:child_process') const child = exec('npm run unit:with-modules') diff --git a/test/commonjs/autohooks/basic.js b/test/commonjs/autohooks/basic.js index 6b6a70b1..be177fb9 100644 --- a/test/commonjs/autohooks/basic.js +++ b/test/commonjs/autohooks/basic.js @@ -1,6 +1,6 @@ 'use strict' -const path = require('path') +const path = require('node:path') const autoLoad = require('../../../') module.exports = function (fastify, opts, next) { diff --git a/test/commonjs/autohooks/cascade.js b/test/commonjs/autohooks/cascade.js index 1019a95b..e8602b9c 100644 --- a/test/commonjs/autohooks/cascade.js +++ b/test/commonjs/autohooks/cascade.js @@ -1,6 +1,6 @@ 'use strict' -const path = require('path') +const path = require('node:path') const autoLoad = require('../../../') module.exports = function (fastify, opts, next) { diff --git a/test/commonjs/autohooks/disabled.js b/test/commonjs/autohooks/disabled.js index bde48cd4..596e6ad3 100644 --- a/test/commonjs/autohooks/disabled.js +++ b/test/commonjs/autohooks/disabled.js @@ -1,6 +1,6 @@ 'use strict' -const path = require('path') +const path = require('node:path') const autoLoad = require('../../../') module.exports = function (fastify, opts, next) { diff --git a/test/commonjs/autohooks/overwrite.js b/test/commonjs/autohooks/overwrite.js index e1c040c2..7e80da59 100644 --- a/test/commonjs/autohooks/overwrite.js +++ b/test/commonjs/autohooks/overwrite.js @@ -1,6 +1,6 @@ 'use strict' -const path = require('path') +const path = require('node:path') const autoLoad = require('../../../') module.exports = function (fastify, opts, next) { diff --git a/test/commonjs/babel-node.js b/test/commonjs/babel-node.js index d050dbb8..11750344 100644 --- a/test/commonjs/babel-node.js +++ b/test/commonjs/babel-node.js @@ -3,7 +3,7 @@ const t = require('tap') const Fastify = require('fastify') const AutoLoad = require('../../') -const { join } = require('path') +const { join } = require('node:path') t.plan(7) diff --git a/test/commonjs/basic/app.js b/test/commonjs/basic/app.js index 9b15b548..e3073c84 100644 --- a/test/commonjs/basic/app.js +++ b/test/commonjs/basic/app.js @@ -1,7 +1,7 @@ 'use strict' -const fs = require('fs') -const path = require('path') +const fs = require('node:fs') +const path = require('node:path') const autoLoad = require('../../../') module.exports = function (fastify, opts, next) { diff --git a/test/commonjs/cyclic-dependency/app.js b/test/commonjs/cyclic-dependency/app.js index 6e0f26e2..04acc140 100644 --- a/test/commonjs/cyclic-dependency/app.js +++ b/test/commonjs/cyclic-dependency/app.js @@ -1,6 +1,6 @@ 'use strict' -const path = require('path') +const path = require('node:path') const AutoLoad = require('../../../') module.exports = function (fastify, opts, next) { diff --git a/test/commonjs/deep/app.js b/test/commonjs/deep/app.js index c3dde701..ac83ae55 100644 --- a/test/commonjs/deep/app.js +++ b/test/commonjs/deep/app.js @@ -1,6 +1,6 @@ 'use strict' -const path = require('path') +const path = require('node:path') const autoLoad = require('../../../') module.exports = function (fastify, opts, next) { diff --git a/test/commonjs/dependency/app.js b/test/commonjs/dependency/app.js index 28c0b203..0eaa1ec6 100644 --- a/test/commonjs/dependency/app.js +++ b/test/commonjs/dependency/app.js @@ -1,6 +1,6 @@ 'use strict' -const path = require('path') +const path = require('node:path') const fastifyUrlData = require('@fastify/url-data') const AutoLoad = require('../../../') diff --git a/test/commonjs/graph-dependency/app.js b/test/commonjs/graph-dependency/app.js index 6e0f26e2..04acc140 100644 --- a/test/commonjs/graph-dependency/app.js +++ b/test/commonjs/graph-dependency/app.js @@ -1,6 +1,6 @@ 'use strict' -const path = require('path') +const path = require('node:path') const AutoLoad = require('../../../') module.exports = function (fastify, opts, next) { diff --git a/test/commonjs/index-error/app.js b/test/commonjs/index-error/app.js index 80d9e5a7..65a222ba 100644 --- a/test/commonjs/index-error/app.js +++ b/test/commonjs/index-error/app.js @@ -1,6 +1,6 @@ 'use strict' -const path = require('path') +const path = require('node:path') const AutoLoad = require('../../../') module.exports = function (fastify, opts, next) { diff --git a/test/commonjs/module-error/app.js b/test/commonjs/module-error/app.js index 6e0f26e2..04acc140 100644 --- a/test/commonjs/module-error/app.js +++ b/test/commonjs/module-error/app.js @@ -1,6 +1,6 @@ 'use strict' -const path = require('path') +const path = require('node:path') const AutoLoad = require('../../../') module.exports = function (fastify, opts, next) { diff --git a/test/commonjs/non-plugin/app.js b/test/commonjs/non-plugin/app.js index 6e0f26e2..04acc140 100644 --- a/test/commonjs/non-plugin/app.js +++ b/test/commonjs/non-plugin/app.js @@ -1,6 +1,6 @@ 'use strict' -const path = require('path') +const path = require('node:path') const AutoLoad = require('../../../') module.exports = function (fastify, opts, next) { diff --git a/test/commonjs/options/app.js b/test/commonjs/options/app.js index f24d4efe..cc1f0f5b 100644 --- a/test/commonjs/options/app.js +++ b/test/commonjs/options/app.js @@ -1,6 +1,6 @@ 'use strict' -const path = require('path') +const path = require('node:path') const fastifyUrlData = require('@fastify/url-data') const AutoLoad = require('../../../') diff --git a/test/commonjs/route-parameters/basic.js b/test/commonjs/route-parameters/basic.js index bc4de541..7fba1174 100644 --- a/test/commonjs/route-parameters/basic.js +++ b/test/commonjs/route-parameters/basic.js @@ -1,6 +1,6 @@ 'use strict' -const path = require('path') +const path = require('node:path') const autoLoad = require('../../../') module.exports = function (fastify, opts, next) { diff --git a/test/commonjs/route-parameters/disabled.js b/test/commonjs/route-parameters/disabled.js index baa88f5a..b5194628 100644 --- a/test/commonjs/route-parameters/disabled.js +++ b/test/commonjs/route-parameters/disabled.js @@ -1,6 +1,6 @@ 'use strict' -const path = require('path') +const path = require('node:path') const autoLoad = require('../../../') module.exports = function (fastify, opts, next) { diff --git a/test/commonjs/syntax-error/app.js b/test/commonjs/syntax-error/app.js index 6e0f26e2..04acc140 100644 --- a/test/commonjs/syntax-error/app.js +++ b/test/commonjs/syntax-error/app.js @@ -1,6 +1,6 @@ 'use strict' -const path = require('path') +const path = require('node:path') const AutoLoad = require('../../../') module.exports = function (fastify, opts, next) { diff --git a/test/commonjs/ts-error/app.js b/test/commonjs/ts-error/app.js index 6e0f26e2..04acc140 100644 --- a/test/commonjs/ts-error/app.js +++ b/test/commonjs/ts-error/app.js @@ -1,6 +1,6 @@ 'use strict' -const path = require('path') +const path = require('node:path') const AutoLoad = require('../../../') module.exports = function (fastify, opts, next) {