Skip to content

Commit

Permalink
perf: use node: prefix to bypass require.cache call for builtins (#407
Browse files Browse the repository at this point in the history
)

* perf: use `node:` prefix to bypass require.cache call for builtins

* fix test

---------

Co-authored-by: Uzlopak <aras.abbasi@googlemail.com>
  • Loading branch information
Fdawgs and Uzlopak committed Sep 8, 2023
1 parent b923bef commit 4e213cb
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 21 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Plugin for serving static files as fast as possible. Supports Fastify version `4

```js
const fastify = require('fastify')({logger: true})
const path = require('path')
const path = require('node:path')

fastify.register(require('@fastify/static'), {
root: path.join(__dirname, 'public'),
Expand Down Expand Up @@ -57,7 +57,7 @@ fastify.listen({ port: 3000 }, (err, address) => {
```js
const fastify = require('fastify')()
const fastifyStatic = require('@fastify/static')
const path = require('path')
const path = require('node:path')
// first plugin
fastify.register(fastifyStatic, {
root: path.join(__dirname, 'public')
Expand All @@ -76,7 +76,7 @@ fastify.register(fastifyStatic, {

```js
const fastify = require('fastify')()
const path = require('path')
const path = require('node:path')

fastify.register(require('@fastify/static'), {
root: path.join(__dirname, 'public'),
Expand Down
2 changes: 1 addition & 1 deletion example/server-compress.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const path = require('path')
const path = require('node:path')
const fastify = require('fastify')({ logger: { level: 'trace' } })

fastify
Expand Down
2 changes: 1 addition & 1 deletion example/server-dir-list.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const path = require('path')
const path = require('node:path')
const Handlebars = require('handlebars')

const fastify = require('fastify')({ logger: { level: 'trace' } })
Expand Down
2 changes: 1 addition & 1 deletion example/server-hidden-file.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const path = require('path')
const path = require('node:path')
const fastify = require('fastify')({ logger: { level: 'trace' } })

fastify
Expand Down
2 changes: 1 addition & 1 deletion example/server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const path = require('path')
const path = require('node:path')
const fastify = require('fastify')({ logger: { level: 'trace' } })

fastify
Expand Down
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict'

const path = require('path')
const { fileURLToPath } = require('url')
const { statSync } = require('fs')
const { promisify } = require('util')
const path = require('node:path')
const { fileURLToPath } = require('node:url')
const { statSync } = require('node:fs')
const { promisify } = require('node:util')
const glob = require('glob')
const globPromise = promisify(glob)
const { PassThrough } = require('readable-stream')
Expand Down
4 changes: 2 additions & 2 deletions lib/dirList.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const path = require('path')
const fs = require('fs').promises
const path = require('node:path')
const fs = require('node:fs/promises')
const pLimit = require('p-limit')

const dirList = {
Expand Down
2 changes: 1 addition & 1 deletion test/content-type.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/* eslint n/no-deprecated-api: "off" */

const path = require('path')
const path = require('node:path')
const { test } = require('tap')
const simple = require('simple-get')
const Fastify = require('fastify')
Expand Down
4 changes: 2 additions & 2 deletions test/dir-list.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

/* eslint n/no-deprecated-api: "off" */

const fs = require('fs')
const path = require('path')
const fs = require('node:fs')
const path = require('node:path')
const t = require('tap')
const simple = require('simple-get')
const Fastify = require('fastify')
Expand Down
10 changes: 5 additions & 5 deletions test/static.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

/* eslint n/no-deprecated-api: "off" */

const path = require('path')
const fs = require('fs')
const url = require('url')
const http = require('http')
const path = require('node:path')
const fs = require('node:fs')
const url = require('node:url')
const http = require('node:http')
const t = require('tap')
const simple = require('simple-get')
const Fastify = require('fastify')
Expand Down Expand Up @@ -2823,7 +2823,7 @@ t.test(
'register with rootpath that causes statSync to fail with non-ENOENT code',
(t) => {
const fastifyStatic = proxyquire('../', {
fs: {
'node:fs': {
statSync: function statSyncStub (path) {
throw new Error({ code: 'MOCK' })
}
Expand Down

0 comments on commit 4e213cb

Please sign in to comment.