Skip to content

Commit

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

* 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
  • Loading branch information
Fdawgs authored Sep 10, 2023
1 parent a3e4618 commit 4073e5b
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ The standalone mode is used to compile the code that can be directly run by `nod
itself. You need to have `fast-json-stringify` installed for the standalone code to work.

```js
const fs = require('fs')
const fs = require('node:fs')
const code = fastJson({
title: 'default string',
type: 'object',
Expand Down
2 changes: 1 addition & 1 deletion benchmark/bench-cmp-branch.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { spawn } = require('child_process')
const { spawn } = require('node:child_process')

const cliSelect = require('cli-select')
const simpleGit = require('simple-git')
Expand Down
2 changes: 1 addition & 1 deletion benchmark/bench-thread.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { workerData: benchmark, parentPort } = require('worker_threads')
const { workerData: benchmark, parentPort } = require('node:worker_threads')

const Benchmark = require('benchmark')
Benchmark.options.minSamples = 100
Expand Down
4 changes: 2 additions & 2 deletions benchmark/bench.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const path = require('path')
const { Worker } = require('worker_threads')
const path = require('node:path')
const { Worker } = require('node:worker_threads')

const BENCH_THREAD_PATH = path.join(__dirname, 'bench-thread.js')

Expand Down
4 changes: 2 additions & 2 deletions build/build-schema-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
const Ajv = require('ajv')
const standaloneCode = require('ajv/dist/standalone').default
const ajvFormats = require('ajv-formats')
const fs = require('fs')
const path = require('path')
const fs = require('node:fs')
const path = require('node:path')

const ajv = new Ajv({
addUsedSchema: false,
Expand Down
2 changes: 1 addition & 1 deletion examples/server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const http = require('http')
const http = require('node:http')

const stringify = require('fast-json-stringify')({
type: 'object',
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

const merge = require('@fastify/deepmerge')()
const clone = require('rfdc')({ proto: true })
const { randomUUID } = require('crypto')
const { randomUUID } = require('node:crypto')

const validate = require('./lib/schema-validator')
const Serializer = require('./lib/serializer')
Expand Down
4 changes: 2 additions & 2 deletions test/standalone-mode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

const test = require('tap').test
const fjs = require('..')
const fs = require('fs')
const path = require('path')
const fs = require('node:fs')
const path = require('node:path')

function build (opts, schema) {
return fjs(schema || {
Expand Down
2 changes: 1 addition & 1 deletion test/webpack.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const test = require('tap').test
const webpack = require('webpack')
const path = require('path')
const path = require('node:path')

test('the library should work with webpack', async (t) => {
t.plan(1)
Expand Down

0 comments on commit 4073e5b

Please sign in to comment.