From 12f056bc67a6b1863ccb68046c9182959f3e763f Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Tue, 12 Sep 2023 18:07:35 +0100 Subject: [PATCH] perf: use `node:` prefix to bypass require.cache call for builtins --- benchmarks/node/speed-benchmark.js | 2 +- examples/node/detect.js | 2 +- examples/node/download-pdf.js | 4 ++-- examples/node/image-processing.js | 4 ++-- examples/node/recognize.js | 2 +- scripts/server.js | 2 +- scripts/test-helper.js | 4 ++-- scripts/webpack.config.dev.js | 2 +- scripts/webpack.config.prod.js | 2 +- src/worker-script/node/cache.js | 4 ++-- src/worker-script/node/gunzip.js | 2 +- src/worker-script/node/index.js | 2 +- src/worker/node/defaultOptions.js | 2 +- src/worker/node/loadImage.js | 4 ++-- src/worker/node/spawnWorker.js | 2 +- 15 files changed, 20 insertions(+), 20 deletions(-) diff --git a/benchmarks/node/speed-benchmark.js b/benchmarks/node/speed-benchmark.js index 28d3fe725..68ebd29c1 100644 --- a/benchmarks/node/speed-benchmark.js +++ b/benchmarks/node/speed-benchmark.js @@ -1,5 +1,5 @@ #!/usr/bin/env node -const path = require('path'); +const path = require('node:path'); const { createWorker } = require('../../'); (async () => { diff --git a/examples/node/detect.js b/examples/node/detect.js index a3e112a18..8f11608e2 100755 --- a/examples/node/detect.js +++ b/examples/node/detect.js @@ -1,5 +1,5 @@ #!/usr/bin/env node -const path = require('path'); +const path = require('node:path'); const Tesseract = require('../../'); const [,, imagePath] = process.argv; diff --git a/examples/node/download-pdf.js b/examples/node/download-pdf.js index 3c459973f..f12d81747 100755 --- a/examples/node/download-pdf.js +++ b/examples/node/download-pdf.js @@ -1,6 +1,6 @@ #!/usr/bin/env node -const path = require('path'); -const fs = require('fs'); +const path = require('node:path'); +const fs = require('node:fs'); const { createWorker } = require('../../'); const [,, imagePath] = process.argv; diff --git a/examples/node/image-processing.js b/examples/node/image-processing.js index e4297a9f2..9de7d9ab4 100755 --- a/examples/node/image-processing.js +++ b/examples/node/image-processing.js @@ -1,6 +1,6 @@ #!/usr/bin/env node -const path = require('path'); -const fs = require('fs'); +const path = require('node:path'); +const fs = require('node:fs'); const { createWorker } = require('../../'); const [,, imagePath] = process.argv; diff --git a/examples/node/recognize.js b/examples/node/recognize.js index 082ffa0ce..a01b333e6 100755 --- a/examples/node/recognize.js +++ b/examples/node/recognize.js @@ -1,5 +1,5 @@ #!/usr/bin/env node -const path = require('path'); +const path = require('node:path'); const { createWorker } = require('../../'); const [,, imagePath] = process.argv; diff --git a/scripts/server.js b/scripts/server.js index 8e857f5f8..a53052a09 100644 --- a/scripts/server.js +++ b/scripts/server.js @@ -1,7 +1,7 @@ const webpack = require('webpack'); const middleware = require('webpack-dev-middleware'); const express = require('express'); -const path = require('path'); +const path = require('node:path'); const cors = require('cors'); const webpackConfig = require('./webpack.config.dev'); diff --git a/scripts/test-helper.js b/scripts/test-helper.js index 027b30062..3a2b39758 100644 --- a/scripts/test-helper.js +++ b/scripts/test-helper.js @@ -1,7 +1,7 @@ const constants = require('../tests/constants'); global.expect = require('expect.js'); -global.fs = require('fs'); -global.path = require('path'); +global.fs = require('node:fs'); +global.path = require('node:path'); global.Tesseract = require('../src'); Object.keys(constants).forEach((key) => { diff --git a/scripts/webpack.config.dev.js b/scripts/webpack.config.dev.js index e807f43df..d218c55a3 100644 --- a/scripts/webpack.config.dev.js +++ b/scripts/webpack.config.dev.js @@ -1,4 +1,4 @@ -const path = require('path'); +const path = require('node:path'); const webpack = require('webpack'); const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer'); const common = require('./webpack.config.common'); diff --git a/scripts/webpack.config.prod.js b/scripts/webpack.config.prod.js index e581df7ab..b92d5e3ad 100644 --- a/scripts/webpack.config.prod.js +++ b/scripts/webpack.config.prod.js @@ -1,4 +1,4 @@ -const path = require('path'); +const path = require('node:path'); const common = require('./webpack.config.common'); const webpack = require('webpack'); diff --git a/src/worker-script/node/cache.js b/src/worker-script/node/cache.js index e04809e2b..fd6bab6b9 100644 --- a/src/worker-script/node/cache.js +++ b/src/worker-script/node/cache.js @@ -1,5 +1,5 @@ -const util = require('util'); -const fs = require('fs'); +const util = require('node:util'); +const fs = require('node:fs'); module.exports = { readCache: util.promisify(fs.readFile), diff --git a/src/worker-script/node/gunzip.js b/src/worker-script/node/gunzip.js index 4f2e0e0c9..40f329499 100644 --- a/src/worker-script/node/gunzip.js +++ b/src/worker-script/node/gunzip.js @@ -1 +1 @@ -module.exports = require('zlib').gunzipSync; +module.exports = require('node:zlib').gunzipSync; diff --git a/src/worker-script/node/index.js b/src/worker-script/node/index.js index c00dba735..fb187b05e 100644 --- a/src/worker-script/node/index.js +++ b/src/worker-script/node/index.js @@ -9,7 +9,7 @@ */ const fetch = require('node-fetch'); -const { parentPort } = require('worker_threads'); +const { parentPort } = require('node:worker_threads'); const worker = require('..'); const getCore = require('./getCore'); const gunzip = require('./gunzip'); diff --git a/src/worker/node/defaultOptions.js b/src/worker/node/defaultOptions.js index 053c1e3e3..498714c4c 100644 --- a/src/worker/node/defaultOptions.js +++ b/src/worker/node/defaultOptions.js @@ -1,4 +1,4 @@ -const path = require('path'); +const path = require('node:path'); const defaultOptions = require('../../constants/defaultOptions'); /* diff --git a/src/worker/node/loadImage.js b/src/worker/node/loadImage.js index 0b5a660fd..07d684e88 100644 --- a/src/worker/node/loadImage.js +++ b/src/worker/node/loadImage.js @@ -1,5 +1,5 @@ -const util = require('util'); -const fs = require('fs'); +const util = require('node:util'); +const fs = require('node:fs'); const fetch = require('node-fetch'); const isURL = require('is-url'); diff --git a/src/worker/node/spawnWorker.js b/src/worker/node/spawnWorker.js index 9723c183c..c26537d13 100644 --- a/src/worker/node/spawnWorker.js +++ b/src/worker/node/spawnWorker.js @@ -1,4 +1,4 @@ -const { Worker } = require('worker_threads'); +const { Worker } = require('node:worker_threads'); /** * spawnWorker