From 2eeb4cb28e8b8f1b24e44747693e418e88c49fef Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Sun, 15 Dec 2024 16:25:52 +0000 Subject: [PATCH] perf: use `node:` prefix to bypass require.cache call for builtins (#785) --- templates/app-esm/app.js | 4 ++-- templates/app-esm/test/helper.js | 4 ++-- templates/app-ts-esm/src/app.ts | 4 ++-- templates/app-ts-esm/test/helper.ts | 4 ++-- templates/app-ts/src/app.ts | 2 +- templates/app-ts/test/helper.ts | 2 +- test/esm/util.test.js | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/templates/app-esm/app.js b/templates/app-esm/app.js index d5c3cb32..b13f0f78 100644 --- a/templates/app-esm/app.js +++ b/templates/app-esm/app.js @@ -1,6 +1,6 @@ -import path from 'path' +import path from 'node:path' import AutoLoad from '@fastify/autoload' -import { fileURLToPath } from 'url' +import { fileURLToPath } from 'node:url' const __filename = fileURLToPath(import.meta.url) const __dirname = path.dirname(__filename) diff --git a/templates/app-esm/test/helper.js b/templates/app-esm/test/helper.js index 6fb94119..3751f95b 100644 --- a/templates/app-esm/test/helper.js +++ b/templates/app-esm/test/helper.js @@ -2,8 +2,8 @@ // between our tests. import helper from 'fastify-cli/helper.js' -import path from 'path' -import { fileURLToPath } from 'url' +import path from 'node:path' +import { fileURLToPath } from 'node:url' const __filename = fileURLToPath(import.meta.url) const __dirname = path.dirname(__filename) diff --git a/templates/app-ts-esm/src/app.ts b/templates/app-ts-esm/src/app.ts index 1aa38221..a39a8071 100644 --- a/templates/app-ts-esm/src/app.ts +++ b/templates/app-ts-esm/src/app.ts @@ -1,7 +1,7 @@ -import * as path from 'path'; +import * as path from 'node:path'; import AutoLoad, {AutoloadPluginOptions} from '@fastify/autoload'; import { FastifyPluginAsync } from 'fastify'; -import { fileURLToPath } from 'url' +import { fileURLToPath } from 'node:url' const __filename = fileURLToPath(import.meta.url) const __dirname = path.dirname(__filename) diff --git a/templates/app-ts-esm/test/helper.ts b/templates/app-ts-esm/test/helper.ts index 253bcf92..33201e66 100644 --- a/templates/app-ts-esm/test/helper.ts +++ b/templates/app-ts-esm/test/helper.ts @@ -1,8 +1,8 @@ // This file contains code that we reuse between our tests. import helper from 'fastify-cli/helper.js' import * as test from 'node:test' -import * as path from 'path' -import { fileURLToPath } from 'url' +import * as path from 'node:path' +import { fileURLToPath } from 'node:url' export type TestContext = { after: typeof test.after diff --git a/templates/app-ts/src/app.ts b/templates/app-ts/src/app.ts index be51f922..e68fa353 100644 --- a/templates/app-ts/src/app.ts +++ b/templates/app-ts/src/app.ts @@ -1,4 +1,4 @@ -import { join } from 'path'; +import { join } from 'node:path'; import AutoLoad, {AutoloadPluginOptions} from '@fastify/autoload'; import { FastifyPluginAsync, FastifyServerOptions } from 'fastify'; diff --git a/templates/app-ts/test/helper.ts b/templates/app-ts/test/helper.ts index 70451775..2f3dc1aa 100644 --- a/templates/app-ts/test/helper.ts +++ b/templates/app-ts/test/helper.ts @@ -1,6 +1,6 @@ // This file contains code that we reuse between our tests. const helper = require('fastify-cli/helper.js') -import * as path from 'path' +import * as path from 'node:path' import * as test from 'node:test' export type TestContext = { diff --git a/test/esm/util.test.js b/test/esm/util.test.js index 33472c9b..b55f3a7c 100644 --- a/test/esm/util.test.js +++ b/test/esm/util.test.js @@ -1,7 +1,7 @@ import { requireModule } from '../../util.js' import { resolve, join } from 'node:path' import t from 'tap' -import * as url from 'url' +import * as url from 'node:url' const test = t.test