diff --git a/libraries/access-token-encryptor/lib/js/AccessTokenEncryptor.js b/libraries/access-token-encryptor/lib/js/AccessTokenEncryptor.js index d5ad31905f..aa8078ceed 100644 --- a/libraries/access-token-encryptor/lib/js/AccessTokenEncryptor.js +++ b/libraries/access-token-encryptor/lib/js/AccessTokenEncryptor.js @@ -1,5 +1,5 @@ -const { promisify } = require('util') -const crypto = require('crypto') +const { promisify } = require('node:util') +const crypto = require('node:crypto') const ALGORITHM = 'aes-256-ctr' diff --git a/libraries/access-token-encryptor/test/setup.js b/libraries/access-token-encryptor/test/setup.js index 09068185a8..9af82f6236 100644 --- a/libraries/access-token-encryptor/test/setup.js +++ b/libraries/access-token-encryptor/test/setup.js @@ -1,4 +1,13 @@ const chai = require('chai') const chaiAsPromised = require('chai-as-promised') +const SandboxedModule = require('sandboxed-module') chai.use(chaiAsPromised) + +SandboxedModule.configure({ + sourceTransformers: { + removeNodePrefix: function (source) { + return source.replace(/require\(['"]node:/g, "require('") + }, + }, +}) diff --git a/libraries/fetch-utils/index.js b/libraries/fetch-utils/index.js index 2167e9f407..f5073e826d 100644 --- a/libraries/fetch-utils/index.js +++ b/libraries/fetch-utils/index.js @@ -1,9 +1,9 @@ const _ = require('lodash') -const { Readable } = require('stream') +const { Readable } = require('node:stream') const OError = require('@overleaf/o-error') const fetch = require('node-fetch') -const http = require('http') -const https = require('https') +const http = require('node:http') +const https = require('node:https') /** * @import { Response } from 'node-fetch' diff --git a/libraries/fetch-utils/test/unit/FetchUtilsTests.js b/libraries/fetch-utils/test/unit/FetchUtilsTests.js index 03c9fe8642..f08614cd8e 100644 --- a/libraries/fetch-utils/test/unit/FetchUtilsTests.js +++ b/libraries/fetch-utils/test/unit/FetchUtilsTests.js @@ -1,7 +1,7 @@ const { expect } = require('chai') const { FetchError, AbortError } = require('node-fetch') -const { Readable } = require('stream') -const { once } = require('events') +const { Readable } = require('node:stream') +const { once } = require('node:events') const { TestServer } = require('./helpers/TestServer') const selfsigned = require('selfsigned') const { @@ -24,7 +24,7 @@ const pems = selfsigned.generate(attrs, { days: 365 }) const PRIVATE_KEY = pems.private const PUBLIC_CERT = pems.cert -const dns = require('dns') +const dns = require('node:dns') const _originalLookup = dns.lookup // Custom DNS resolver function dns.lookup = (hostname, options, callback) => { diff --git a/libraries/fetch-utils/test/unit/helpers/TestServer.js b/libraries/fetch-utils/test/unit/helpers/TestServer.js index 094664d061..49727772ce 100644 --- a/libraries/fetch-utils/test/unit/helpers/TestServer.js +++ b/libraries/fetch-utils/test/unit/helpers/TestServer.js @@ -1,9 +1,9 @@ const express = require('express') const bodyParser = require('body-parser') -const { EventEmitter } = require('events') -const http = require('http') -const https = require('https') -const { promisify } = require('util') +const { EventEmitter } = require('node:events') +const http = require('node:http') +const https = require('node:https') +const { promisify } = require('node:util') class TestServer { constructor() { diff --git a/libraries/logger/log-level-checker.js b/libraries/logger/log-level-checker.js index b1b041d037..fd2f984042 100644 --- a/libraries/logger/log-level-checker.js +++ b/libraries/logger/log-level-checker.js @@ -1,5 +1,5 @@ const { fetchString } = require('@overleaf/fetch-utils') -const fs = require('fs') +const fs = require('node:fs') class LogLevelChecker { constructor(logger, defaultLevel) { diff --git a/libraries/logger/logging-manager.js b/libraries/logger/logging-manager.js index 7268fd258a..1dac0bc2a3 100644 --- a/libraries/logger/logging-manager.js +++ b/libraries/logger/logging-manager.js @@ -1,4 +1,4 @@ -const Stream = require('stream') +const Stream = require('node:stream') const bunyan = require('bunyan') const GCPManager = require('./gcp-manager') const SentryManager = require('./sentry-manager') diff --git a/libraries/logger/test/setup.js b/libraries/logger/test/setup.js index 78e563f853..eb16fac2c4 100644 --- a/libraries/logger/test/setup.js +++ b/libraries/logger/test/setup.js @@ -8,4 +8,9 @@ chai.use(sinonChai) SandboxedModule.configure({ globals: { Buffer, JSON, console, process }, + sourceTransformers: { + removeNodePrefix: function (source) { + return source.replace(/require\(['"]node:/g, "require('") + }, + }, }) diff --git a/libraries/logger/test/unit/log-level-checker-tests.js b/libraries/logger/test/unit/log-level-checker-tests.js index b26be378eb..64ae6d9d86 100644 --- a/libraries/logger/test/unit/log-level-checker-tests.js +++ b/libraries/logger/test/unit/log-level-checker-tests.js @@ -1,5 +1,5 @@ -const Path = require('path') -const { promisify } = require('util') +const Path = require('node:path') +const { promisify } = require('node:util') const SandboxedModule = require('sandboxed-module') const sinon = require('sinon') const { expect } = require('chai') diff --git a/libraries/logger/test/unit/logging-manager-tests.js b/libraries/logger/test/unit/logging-manager-tests.js index 378de57345..f920255a01 100644 --- a/libraries/logger/test/unit/logging-manager-tests.js +++ b/libraries/logger/test/unit/logging-manager-tests.js @@ -1,7 +1,7 @@ const SandboxedModule = require('sandboxed-module') const bunyan = require('bunyan') const { expect } = require('chai') -const path = require('path') +const path = require('node:path') const sinon = require('sinon') const MODULE_PATH = path.join(__dirname, '../../logging-manager.js') diff --git a/libraries/logger/test/unit/sentry-manager-tests.js b/libraries/logger/test/unit/sentry-manager-tests.js index d00c10ca4d..5bd2578734 100644 --- a/libraries/logger/test/unit/sentry-manager-tests.js +++ b/libraries/logger/test/unit/sentry-manager-tests.js @@ -1,4 +1,4 @@ -const Path = require('path') +const Path = require('node:path') const SandboxedModule = require('sandboxed-module') const { expect } = require('chai') const sinon = require('sinon') diff --git a/libraries/metrics/initialize.js b/libraries/metrics/initialize.js index 63be4e5d2e..1028ee06c3 100644 --- a/libraries/metrics/initialize.js +++ b/libraries/metrics/initialize.js @@ -88,7 +88,7 @@ function initializeProfileAgent() { } function initializePrometheus() { - const os = require('os') + const os = require('node:os') const promClient = require('prom-client') promClient.register.setDefaultLabels({ app: APP_NAME, host: os.hostname() }) promClient.collectDefaultMetrics({ timeout: 5000, prefix: '' }) diff --git a/libraries/metrics/leaked_sockets.js b/libraries/metrics/leaked_sockets.js index cdfb16822b..d250fc4052 100644 --- a/libraries/metrics/leaked_sockets.js +++ b/libraries/metrics/leaked_sockets.js @@ -6,8 +6,8 @@ * logged along with the corresponding information from /proc/net/tcp. */ -const fs = require('fs') -const diagnosticsChannel = require('diagnostics_channel') +const fs = require('node:fs') +const diagnosticsChannel = require('node:diagnostics_channel') const SOCKET_MONITOR_INTERVAL = 60 * 1000 // set the threshold for logging leaked sockets in minutes, defaults to 15 diff --git a/libraries/metrics/open_sockets.js b/libraries/metrics/open_sockets.js index eb120bcf91..da7241d46c 100644 --- a/libraries/metrics/open_sockets.js +++ b/libraries/metrics/open_sockets.js @@ -11,13 +11,13 @@ const seconds = 1000 // In Node 0.10 the default is 5, which means only 5 open connections at one. // Node 0.12 has a default of Infinity. Make sure we have no limit set, // regardless of Node version. -require('http').globalAgent.maxSockets = Infinity -require('https').globalAgent.maxSockets = Infinity +require('node:http').globalAgent.maxSockets = Infinity +require('node:https').globalAgent.maxSockets = Infinity -const SOCKETS_HTTP = require('http').globalAgent.sockets -const SOCKETS_HTTPS = require('https').globalAgent.sockets -const FREE_SOCKETS_HTTP = require('http').globalAgent.freeSockets -const FREE_SOCKETS_HTTPS = require('https').globalAgent.freeSockets +const SOCKETS_HTTP = require('node:http').globalAgent.sockets +const SOCKETS_HTTPS = require('node:https').globalAgent.sockets +const FREE_SOCKETS_HTTP = require('node:http').globalAgent.freeSockets +const FREE_SOCKETS_HTTPS = require('node:https').globalAgent.freeSockets // keep track of set gauges and reset them in the next collection cycle const SEEN_HOSTS_HTTP = new Set() diff --git a/libraries/metrics/test/acceptance/metrics_tests.js b/libraries/metrics/test/acceptance/metrics_tests.js index 307cabc56c..5b13571e13 100644 --- a/libraries/metrics/test/acceptance/metrics_tests.js +++ b/libraries/metrics/test/acceptance/metrics_tests.js @@ -1,6 +1,6 @@ -const { promisify } = require('util') -const os = require('os') -const http = require('http') +const { promisify } = require('node:util') +const os = require('node:os') +const http = require('node:http') const { expect } = require('chai') const Metrics = require('../..') diff --git a/libraries/metrics/test/unit/js/event_loop.js b/libraries/metrics/test/unit/js/event_loop.js index a5fb8f7d4e..97b9fddf42 100644 --- a/libraries/metrics/test/unit/js/event_loop.js +++ b/libraries/metrics/test/unit/js/event_loop.js @@ -5,7 +5,7 @@ */ const chai = require('chai') const { expect } = chai -const path = require('path') +const path = require('node:path') const modulePath = path.join(__dirname, '../../../event_loop.js') const SandboxedModule = require('sandboxed-module') const sinon = require('sinon') diff --git a/libraries/metrics/test/unit/js/http.js b/libraries/metrics/test/unit/js/http.js index f049f293fd..7b6bb309e7 100644 --- a/libraries/metrics/test/unit/js/http.js +++ b/libraries/metrics/test/unit/js/http.js @@ -1,4 +1,4 @@ -const Path = require('path') +const Path = require('node:path') const SandboxedModule = require('sandboxed-module') const sinon = require('sinon') diff --git a/libraries/o-error/doc/demo.js b/libraries/o-error/doc/demo.js index 845a2bf671..9ebef2db56 100644 --- a/libraries/o-error/doc/demo.js +++ b/libraries/o-error/doc/demo.js @@ -70,7 +70,7 @@ sayHi3(43, (err, result) => { } }) -const promisify = require('util').promisify +const promisify = require('node:util').promisify demoDatabase.findUserAsync = promisify(demoDatabase.findUser) async function sayHi4NoHandling(userId) { diff --git a/libraries/o-error/test/o-error-util.test.js b/libraries/o-error/test/o-error-util.test.js index c13f032541..c86cec44a2 100644 --- a/libraries/o-error/test/o-error-util.test.js +++ b/libraries/o-error/test/o-error-util.test.js @@ -1,5 +1,5 @@ const { expect } = require('chai') -const { promisify } = require('util') +const { promisify } = require('node:util') const OError = require('..') diff --git a/libraries/o-error/test/support/index.js b/libraries/o-error/test/support/index.js index 93bd846631..00d9dbb392 100644 --- a/libraries/o-error/test/support/index.js +++ b/libraries/o-error/test/support/index.js @@ -23,7 +23,7 @@ exports.expectError = function OErrorExpectError(e, expected) { ).to.be.true expect( - require('util').types.isNativeError(e), + require('node:util').types.isNativeError(e), 'error should be recognised by util.types.isNativeError' ).to.be.true diff --git a/libraries/object-persistor/src/FSPersistor.js b/libraries/object-persistor/src/FSPersistor.js index df2c82b1bc..f9c20b12be 100644 --- a/libraries/object-persistor/src/FSPersistor.js +++ b/libraries/object-persistor/src/FSPersistor.js @@ -1,11 +1,11 @@ -const crypto = require('crypto') -const fs = require('fs') -const fsPromises = require('fs/promises') +const crypto = require('node:crypto') +const fs = require('node:fs') +const fsPromises = require('node:fs/promises') const globCallbacks = require('glob') -const Path = require('path') -const { PassThrough } = require('stream') -const { pipeline } = require('stream/promises') -const { promisify } = require('util') +const Path = require('node:path') +const { PassThrough } = require('node:stream') +const { pipeline } = require('node:stream/promises') +const { promisify } = require('node:util') const AbstractPersistor = require('./AbstractPersistor') const { ReadError, WriteError, NotImplementedError } = require('./Errors') diff --git a/libraries/object-persistor/src/GcsPersistor.js b/libraries/object-persistor/src/GcsPersistor.js index ebe9f92ebc..90c02ee886 100644 --- a/libraries/object-persistor/src/GcsPersistor.js +++ b/libraries/object-persistor/src/GcsPersistor.js @@ -1,6 +1,6 @@ -const fs = require('fs') -const { pipeline } = require('stream/promises') -const { PassThrough } = require('stream') +const fs = require('node:fs') +const { pipeline } = require('node:stream/promises') +const { PassThrough } = require('node:stream') const { Storage, IdempotencyStrategy } = require('@google-cloud/storage') const { WriteError, ReadError, NotFoundError } = require('./Errors') const asyncPool = require('tiny-async-pool') diff --git a/libraries/object-persistor/src/MigrationPersistor.js b/libraries/object-persistor/src/MigrationPersistor.js index 3f44c38cee..0cb665fa00 100644 --- a/libraries/object-persistor/src/MigrationPersistor.js +++ b/libraries/object-persistor/src/MigrationPersistor.js @@ -1,8 +1,8 @@ const AbstractPersistor = require('./AbstractPersistor') const Logger = require('@overleaf/logger') const Metrics = require('@overleaf/metrics') -const Stream = require('stream') -const { pipeline } = require('stream/promises') +const Stream = require('node:stream') +const { pipeline } = require('node:stream/promises') const { NotFoundError, WriteError } = require('./Errors') // Persistor that wraps two other persistors. Talks to the 'primary' by default, diff --git a/libraries/object-persistor/src/PerProjectEncryptedS3Persistor.js b/libraries/object-persistor/src/PerProjectEncryptedS3Persistor.js index 865f303c5b..17c1fca995 100644 --- a/libraries/object-persistor/src/PerProjectEncryptedS3Persistor.js +++ b/libraries/object-persistor/src/PerProjectEncryptedS3Persistor.js @@ -1,8 +1,8 @@ // @ts-check -const Crypto = require('crypto') -const Stream = require('stream') -const fs = require('fs') -const { promisify } = require('util') +const Crypto = require('node:crypto') +const Stream = require('node:stream') +const fs = require('node:fs') +const { promisify } = require('node:util') const { WritableBuffer } = require('@overleaf/stream-utils') const { S3Persistor, SSECOptions } = require('./S3Persistor.js') const { @@ -13,7 +13,7 @@ const { ReadError, } = require('./Errors') const logger = require('@overleaf/logger') -const Path = require('path') +const Path = require('node:path') const generateKey = promisify(Crypto.generateKey) const hkdf = promisify(Crypto.hkdf) diff --git a/libraries/object-persistor/src/PersistorHelper.js b/libraries/object-persistor/src/PersistorHelper.js index d54d6985a0..28b8c0c2aa 100644 --- a/libraries/object-persistor/src/PersistorHelper.js +++ b/libraries/object-persistor/src/PersistorHelper.js @@ -1,6 +1,6 @@ -const Crypto = require('crypto') -const Stream = require('stream') -const { pipeline } = require('stream/promises') +const Crypto = require('node:crypto') +const Stream = require('node:stream') +const { pipeline } = require('node:stream/promises') const Logger = require('@overleaf/logger') const Metrics = require('@overleaf/metrics') const { WriteError, NotFoundError, AlreadyWrittenError } = require('./Errors') diff --git a/libraries/object-persistor/src/S3Persistor.js b/libraries/object-persistor/src/S3Persistor.js index b34afcf1e9..d31f5831d1 100644 --- a/libraries/object-persistor/src/S3Persistor.js +++ b/libraries/object-persistor/src/S3Persistor.js @@ -1,6 +1,6 @@ // @ts-check -const http = require('http') -const https = require('https') +const http = require('node:http') +const https = require('node:https') if (http.globalAgent.maxSockets < 300) { http.globalAgent.maxSockets = 300 } @@ -8,15 +8,15 @@ if (https.globalAgent.maxSockets < 300) { https.globalAgent.maxSockets = 300 } -const Crypto = require('crypto') +const Crypto = require('node:crypto') const Metrics = require('@overleaf/metrics') const AbstractPersistor = require('./AbstractPersistor') const PersistorHelper = require('./PersistorHelper') -const { pipeline, PassThrough } = require('stream') -const fs = require('fs') +const { pipeline, PassThrough } = require('node:stream') +const fs = require('node:fs') const S3 = require('aws-sdk/clients/s3') -const { URL } = require('url') +const { URL } = require('node:url') const { WriteError, ReadError, NotFoundError } = require('./Errors') /** diff --git a/libraries/object-persistor/test/Init.js b/libraries/object-persistor/test/Init.js index 3fe772b36b..2721d2f7c5 100644 --- a/libraries/object-persistor/test/Init.js +++ b/libraries/object-persistor/test/Init.js @@ -25,4 +25,9 @@ SandboxedModule.configure({ }, }, globals: { Buffer, Math, console, process, URL }, + sourceTransformers: { + removeNodePrefix: function (source) { + return source.replace(/require\(['"]node:/g, "require('") + }, + }, }) diff --git a/libraries/object-persistor/test/unit/FSPersistorTests.js b/libraries/object-persistor/test/unit/FSPersistorTests.js index 804de81849..dc7a5c50d7 100644 --- a/libraries/object-persistor/test/unit/FSPersistorTests.js +++ b/libraries/object-persistor/test/unit/FSPersistorTests.js @@ -1,10 +1,10 @@ -const crypto = require('crypto') +const crypto = require('node:crypto') const { expect } = require('chai') const mockFs = require('mock-fs') -const fs = require('fs') -const fsPromises = require('fs/promises') -const Path = require('path') -const StreamPromises = require('stream/promises') +const fs = require('node:fs') +const fsPromises = require('node:fs/promises') +const Path = require('node:path') +const StreamPromises = require('node:stream/promises') const SandboxedModule = require('sandboxed-module') const Errors = require('../../src/Errors') diff --git a/libraries/object-persistor/test/unit/GcsPersistorTests.js b/libraries/object-persistor/test/unit/GcsPersistorTests.js index 6a2b10f1e8..f9b31fa72b 100644 --- a/libraries/object-persistor/test/unit/GcsPersistorTests.js +++ b/libraries/object-persistor/test/unit/GcsPersistorTests.js @@ -1,4 +1,4 @@ -const { EventEmitter } = require('events') +const { EventEmitter } = require('node:events') const sinon = require('sinon') const chai = require('chai') const { expect } = chai diff --git a/libraries/object-persistor/test/unit/PersistorFactoryTests.js b/libraries/object-persistor/test/unit/PersistorFactoryTests.js index 0a41b92cd0..7f71be89e5 100644 --- a/libraries/object-persistor/test/unit/PersistorFactoryTests.js +++ b/libraries/object-persistor/test/unit/PersistorFactoryTests.js @@ -1,7 +1,7 @@ const chai = require('chai') const { expect } = chai const SandboxedModule = require('sandboxed-module') -const StreamPromises = require('stream/promises') +const StreamPromises = require('node:stream/promises') const MODULE_PATH = '../../src/PersistorFactory.js' diff --git a/libraries/object-persistor/test/unit/S3PersistorTests.js b/libraries/object-persistor/test/unit/S3PersistorTests.js index 37c21c0050..0012839169 100644 --- a/libraries/object-persistor/test/unit/S3PersistorTests.js +++ b/libraries/object-persistor/test/unit/S3PersistorTests.js @@ -3,7 +3,7 @@ const chai = require('chai') const { expect } = chai const SandboxedModule = require('sandboxed-module') const Errors = require('../../src/Errors') -const { EventEmitter } = require('events') +const { EventEmitter } = require('node:events') const MODULE_PATH = '../../src/S3Persistor.js' diff --git a/libraries/promise-utils/index.js b/libraries/promise-utils/index.js index 043bd43630..370a1c2441 100644 --- a/libraries/promise-utils/index.js +++ b/libraries/promise-utils/index.js @@ -1,4 +1,4 @@ -const { promisify, callbackify } = require('util') +const { promisify, callbackify } = require('node:util') const pLimit = require('p-limit') module.exports = { diff --git a/libraries/redis-wrapper/.mocharc.json b/libraries/redis-wrapper/.mocharc.json new file mode 100644 index 0000000000..dc3280aa96 --- /dev/null +++ b/libraries/redis-wrapper/.mocharc.json @@ -0,0 +1,3 @@ +{ + "require": "test/setup.js" +} diff --git a/libraries/redis-wrapper/RedisLocker.js b/libraries/redis-wrapper/RedisLocker.js index 9185927887..b819ad2188 100644 --- a/libraries/redis-wrapper/RedisLocker.js +++ b/libraries/redis-wrapper/RedisLocker.js @@ -1,8 +1,8 @@ -const { promisify } = require('util') +const { promisify } = require('node:util') const metrics = require('@overleaf/metrics') const logger = require('@overleaf/logger') -const os = require('os') -const crypto = require('crypto') +const os = require('node:os') +const crypto = require('node:crypto') const HOST = os.hostname() const PID = process.pid diff --git a/libraries/redis-wrapper/RedisWebLocker.js b/libraries/redis-wrapper/RedisWebLocker.js index aebf7dfeaf..dac315b64b 100644 --- a/libraries/redis-wrapper/RedisWebLocker.js +++ b/libraries/redis-wrapper/RedisWebLocker.js @@ -1,8 +1,8 @@ -const { callbackify, promisify } = require('util') +const { callbackify, promisify } = require('node:util') const metrics = require('@overleaf/metrics') const logger = require('@overleaf/logger') -const os = require('os') -const crypto = require('crypto') +const os = require('node:os') +const crypto = require('node:crypto') const async = require('async') const HOST = os.hostname() diff --git a/libraries/redis-wrapper/index.js b/libraries/redis-wrapper/index.js index 8d7c45a746..2e16014490 100644 --- a/libraries/redis-wrapper/index.js +++ b/libraries/redis-wrapper/index.js @@ -1,6 +1,6 @@ -const crypto = require('crypto') -const os = require('os') -const { promisify } = require('util') +const crypto = require('node:crypto') +const os = require('node:os') +const { promisify } = require('node:util') const Redis = require('ioredis') diff --git a/libraries/redis-wrapper/test/setup.js b/libraries/redis-wrapper/test/setup.js new file mode 100644 index 0000000000..6369c6374c --- /dev/null +++ b/libraries/redis-wrapper/test/setup.js @@ -0,0 +1,9 @@ +const SandboxedModule = require('sandboxed-module') + +SandboxedModule.configure({ + sourceTransformers: { + removeNodePrefix: function (source) { + return source.replace(/require\(['"]node:/g, "require('") + }, + }, +}) diff --git a/libraries/redis-wrapper/test/unit/src/test.js b/libraries/redis-wrapper/test/unit/src/test.js index 03d42217ae..a71dcf0230 100644 --- a/libraries/redis-wrapper/test/unit/src/test.js +++ b/libraries/redis-wrapper/test/unit/src/test.js @@ -6,8 +6,8 @@ */ require('chai').should() const SandboxedModule = require('sandboxed-module') -const assert = require('assert') -const path = require('path') +const assert = require('node:assert') +const path = require('node:path') const sinon = require('sinon') const modulePath = path.join(__dirname, './../../../index.js') const redisLockerModulePath = path.join(__dirname, './../../../RedisLocker.js') diff --git a/libraries/settings/Settings.js b/libraries/settings/Settings.js index 02f5af763c..3a5f31c33c 100644 --- a/libraries/settings/Settings.js +++ b/libraries/settings/Settings.js @@ -1,6 +1,6 @@ /* eslint-disable no-console */ -const fs = require('fs') -const Path = require('path') +const fs = require('node:fs') +const Path = require('node:path') const { merge } = require('./merge') const CWD = process.cwd() diff --git a/libraries/stream-utils/index.js b/libraries/stream-utils/index.js index cdd8dcb5cf..e4c7d60c94 100644 --- a/libraries/stream-utils/index.js +++ b/libraries/stream-utils/index.js @@ -1,4 +1,4 @@ -const { Writable, Readable, PassThrough, Transform } = require('stream') +const { Writable, Readable, PassThrough, Transform } = require('node:stream') /** * A writable stream that stores all data written to it in a node Buffer. diff --git a/package-lock.json b/package-lock.json index 7a3f54451e..d807ee23ac 100644 --- a/package-lock.json +++ b/package-lock.json @@ -51,6 +51,7 @@ "eslint-plugin-node": "^11.1.0", "eslint-plugin-prettier": "^4.0.0", "eslint-plugin-promise": "^6.0.0", + "eslint-plugin-unicorn": "^56.0.0", "prettier": "3.3.3", "typescript": "^5.5.4" } @@ -39877,6 +39878,7 @@ "eslint-config-prettier": "^8.5.0", "eslint-config-standard": "^16.0.3", "eslint-plugin-react": "^7.32.2", + "eslint-plugin-unicorn": "^56.0.0", "expect": "^1.15.2", "file-loader": "^6.2.0", "jsdom": "^20.0.0", @@ -66149,6 +66151,7 @@ "eslint-config-prettier": "^8.5.0", "eslint-config-standard": "^16.0.3", "eslint-plugin-react": "^7.32.2", + "eslint-plugin-unicorn": "^56.0.0", "expect": "^1.15.2", "express": "^4.21.0", "express-basic-auth": "^1.2.0", diff --git a/package.json b/package.json index ac49094af7..911817b882 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "eslint-plugin-node": "^11.1.0", "eslint-plugin-prettier": "^4.0.0", "eslint-plugin-promise": "^6.0.0", + "eslint-plugin-unicorn": "^56.0.0", "prettier": "3.3.3", "typescript": "^5.5.4" }, diff --git a/server-ce/.eslintrc b/server-ce/.eslintrc index 3a2bb3247c..fc58ef3e98 100644 --- a/server-ce/.eslintrc +++ b/server-ce/.eslintrc @@ -4,6 +4,9 @@ "standard", "prettier" ], + "plugins": [ + "unicorn" + ], "parserOptions": { "ecmaVersion": 2020 }, @@ -12,7 +15,8 @@ }, "rules": { // Do not allow importing of implicit dependencies. - "import/no-extraneous-dependencies": "error" + "import/no-extraneous-dependencies": "error", + "unicorn/prefer-node-protocol": "error" }, "overrides": [ // Extra rules for Cypress tests diff --git a/services/chat/app/js/server.js b/services/chat/app/js/server.js index aa4ea42482..80970fc22e 100644 --- a/services/chat/app/js/server.js +++ b/services/chat/app/js/server.js @@ -1,10 +1,10 @@ -import http from 'http' +import http from 'node:http' import metrics from '@overleaf/metrics' import logger from '@overleaf/logger' import express from 'express' import exegesisExpress from 'exegesis-express' -import path from 'path' -import { fileURLToPath } from 'url' +import path from 'node:path' +import { fileURLToPath } from 'node:url' import * as messagesController from './Features/Messages/MessageHttpController.js' const __dirname = fileURLToPath(new URL('.', import.meta.url)) diff --git a/services/chat/test/acceptance/js/helpers/ChatApp.js b/services/chat/test/acceptance/js/helpers/ChatApp.js index 7116ea36f6..3a0baf5ce0 100644 --- a/services/chat/test/acceptance/js/helpers/ChatApp.js +++ b/services/chat/test/acceptance/js/helpers/ChatApp.js @@ -1,5 +1,5 @@ import { createServer } from '../../../../app/js/server.js' -import { promisify } from 'util' +import { promisify } from 'node:util' export { db } from '../../../../app/js/mongodb.js' diff --git a/services/clsi/app.js b/services/clsi/app.js index bcf89aaaf9..07d4eddd4e 100644 --- a/services/clsi/app.js +++ b/services/clsi/app.js @@ -16,7 +16,7 @@ const ContentTypeMapper = require('./app/js/ContentTypeMapper') const Errors = require('./app/js/Errors') const { createOutputZip } = require('./app/js/OutputController') -const Path = require('path') +const Path = require('node:path') Metrics.open_sockets.monitor(true) Metrics.memory.monitor(logger) @@ -316,8 +316,8 @@ app.use(function (error, req, res, next) { } }) -const net = require('net') -const os = require('os') +const net = require('node:net') +const os = require('node:os') let STATE = 'up' diff --git a/services/clsi/app/js/CompileManager.js b/services/clsi/app/js/CompileManager.js index 9d1981263d..292be201f7 100644 --- a/services/clsi/app/js/CompileManager.js +++ b/services/clsi/app/js/CompileManager.js @@ -1,7 +1,7 @@ -const fsPromises = require('fs/promises') -const os = require('os') -const Path = require('path') -const { callbackify } = require('util') +const fsPromises = require('node:fs/promises') +const os = require('node:os') +const Path = require('node:path') +const { callbackify } = require('node:util') const Settings = require('@overleaf/settings') const logger = require('@overleaf/logger') diff --git a/services/clsi/app/js/ContentCacheManager.js b/services/clsi/app/js/ContentCacheManager.js index 016b264b86..5457c0dce0 100644 --- a/services/clsi/app/js/ContentCacheManager.js +++ b/services/clsi/app/js/ContentCacheManager.js @@ -2,10 +2,10 @@ * ContentCacheManager - maintains a cache of stream hashes from a PDF file */ -const { callbackify } = require('util') -const fs = require('fs') -const crypto = require('crypto') -const Path = require('path') +const { callbackify } = require('node:util') +const fs = require('node:fs') +const crypto = require('node:crypto') +const Path = require('node:path') const Settings = require('@overleaf/settings') const OError = require('@overleaf/o-error') const pLimit = require('p-limit') diff --git a/services/clsi/app/js/ContentCacheMetrics.js b/services/clsi/app/js/ContentCacheMetrics.js index 0337876feb..1e2b598286 100644 --- a/services/clsi/app/js/ContentCacheMetrics.js +++ b/services/clsi/app/js/ContentCacheMetrics.js @@ -1,6 +1,6 @@ const logger = require('@overleaf/logger') const Metrics = require('./Metrics') -const os = require('os') +const os = require('node:os') let CACHED_LOAD = { expires: -1, diff --git a/services/clsi/app/js/ContentController.js b/services/clsi/app/js/ContentController.js index b154bea175..96eba613ed 100644 --- a/services/clsi/app/js/ContentController.js +++ b/services/clsi/app/js/ContentController.js @@ -1,4 +1,4 @@ -const Path = require('path') +const Path = require('node:path') const send = require('send') const Settings = require('@overleaf/settings') const OutputCacheManager = require('./OutputCacheManager') diff --git a/services/clsi/app/js/ContentTypeMapper.js b/services/clsi/app/js/ContentTypeMapper.js index 6301dce489..5bf0c31423 100644 --- a/services/clsi/app/js/ContentTypeMapper.js +++ b/services/clsi/app/js/ContentTypeMapper.js @@ -4,7 +4,7 @@ // TODO: This file was created by bulk-decaffeinate. // Fix any style issues and re-enable lint. let ContentTypeMapper -const Path = require('path') +const Path = require('node:path') // here we coerce html, css and js to text/plain, // otherwise choose correct mime type based on file extension, diff --git a/services/clsi/app/js/DockerRunner.js b/services/clsi/app/js/DockerRunner.js index c1f08c26e7..7aac613db4 100644 --- a/services/clsi/app/js/DockerRunner.js +++ b/services/clsi/app/js/DockerRunner.js @@ -1,13 +1,13 @@ -const { promisify } = require('util') +const { promisify } = require('node:util') const Settings = require('@overleaf/settings') const logger = require('@overleaf/logger') const Docker = require('dockerode') const dockerode = new Docker() -const crypto = require('crypto') +const crypto = require('node:crypto') const async = require('async') const LockManager = require('./DockerLockManager') -const fs = require('fs') -const Path = require('path') +const fs = require('node:fs') +const Path = require('node:path') const _ = require('lodash') const ONE_HOUR_IN_MS = 60 * 60 * 1000 diff --git a/services/clsi/app/js/DraftModeManager.js b/services/clsi/app/js/DraftModeManager.js index a5b26348e6..cf8ababc47 100644 --- a/services/clsi/app/js/DraftModeManager.js +++ b/services/clsi/app/js/DraftModeManager.js @@ -1,5 +1,5 @@ -const fsPromises = require('fs/promises') -const { callbackify } = require('util') +const fsPromises = require('node:fs/promises') +const { callbackify } = require('node:util') const logger = require('@overleaf/logger') async function injectDraftMode(filename) { diff --git a/services/clsi/app/js/LatexRunner.js b/services/clsi/app/js/LatexRunner.js index d956ee4949..beefa002ab 100644 --- a/services/clsi/app/js/LatexRunner.js +++ b/services/clsi/app/js/LatexRunner.js @@ -1,9 +1,9 @@ -const Path = require('path') -const { promisify } = require('util') +const Path = require('node:path') +const { promisify } = require('node:util') const Settings = require('@overleaf/settings') const logger = require('@overleaf/logger') const CommandRunner = require('./CommandRunner') -const fs = require('fs') +const fs = require('node:fs') const ProcessTable = {} // table of currently running jobs (pids or docker container names) diff --git a/services/clsi/app/js/LocalCommandRunner.js b/services/clsi/app/js/LocalCommandRunner.js index d909ec601c..bac7d39400 100644 --- a/services/clsi/app/js/LocalCommandRunner.js +++ b/services/clsi/app/js/LocalCommandRunner.js @@ -12,8 +12,8 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ let CommandRunner -const { spawn } = require('child_process') -const { promisify } = require('util') +const { spawn } = require('node:child_process') +const { promisify } = require('node:util') const _ = require('lodash') const logger = require('@overleaf/logger') diff --git a/services/clsi/app/js/OutputCacheManager.js b/services/clsi/app/js/OutputCacheManager.js index 13aad1bc74..1cad933c2d 100644 --- a/services/clsi/app/js/OutputCacheManager.js +++ b/services/clsi/app/js/OutputCacheManager.js @@ -1,12 +1,12 @@ let OutputCacheManager -const { callbackify, promisify } = require('util') +const { callbackify, promisify } = require('node:util') const async = require('async') -const fs = require('fs') -const Path = require('path') +const fs = require('node:fs') +const Path = require('node:path') const logger = require('@overleaf/logger') const _ = require('lodash') const Settings = require('@overleaf/settings') -const crypto = require('crypto') +const crypto = require('node:crypto') const Metrics = require('./Metrics') const OutputFileOptimiser = require('./OutputFileOptimiser') diff --git a/services/clsi/app/js/OutputFileFinder.js b/services/clsi/app/js/OutputFileFinder.js index 8ca13183dc..e62038c614 100644 --- a/services/clsi/app/js/OutputFileFinder.js +++ b/services/clsi/app/js/OutputFileFinder.js @@ -1,5 +1,5 @@ -const Path = require('path') -const fs = require('fs') +const Path = require('node:path') +const fs = require('node:fs') const { callbackifyMultiResult } = require('@overleaf/promise-utils') async function walkFolder(compileDir, d, files, allEntries) { diff --git a/services/clsi/app/js/OutputFileOptimiser.js b/services/clsi/app/js/OutputFileOptimiser.js index c97ef7ffdc..0548defc21 100644 --- a/services/clsi/app/js/OutputFileOptimiser.js +++ b/services/clsi/app/js/OutputFileOptimiser.js @@ -13,9 +13,9 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ let OutputFileOptimiser -const fs = require('fs') -const Path = require('path') -const { spawn } = require('child_process') +const fs = require('node:fs') +const Path = require('node:path') +const { spawn } = require('node:child_process') const logger = require('@overleaf/logger') const Metrics = require('./Metrics') const _ = require('lodash') diff --git a/services/clsi/app/js/ProjectPersistenceManager.js b/services/clsi/app/js/ProjectPersistenceManager.js index 4dbe8b636e..66c6be5108 100644 --- a/services/clsi/app/js/ProjectPersistenceManager.js +++ b/services/clsi/app/js/ProjectPersistenceManager.js @@ -15,9 +15,9 @@ const logger = require('@overleaf/logger') const oneDay = 24 * 60 * 60 * 1000 const Settings = require('@overleaf/settings') const diskusage = require('diskusage') -const { callbackify } = require('util') -const Path = require('path') -const fs = require('fs') +const { callbackify } = require('node:util') +const Path = require('node:path') +const fs = require('node:fs') // projectId -> timestamp mapping. const LAST_ACCESS = new Map() diff --git a/services/clsi/app/js/ResourceStateManager.js b/services/clsi/app/js/ResourceStateManager.js index dbfb3c9fc4..a5f747e1cd 100644 --- a/services/clsi/app/js/ResourceStateManager.js +++ b/services/clsi/app/js/ResourceStateManager.js @@ -1,5 +1,5 @@ -const Path = require('path') -const fs = require('fs') +const Path = require('node:path') +const fs = require('node:fs') const logger = require('@overleaf/logger') const Errors = require('./Errors') const SafeReader = require('./SafeReader') diff --git a/services/clsi/app/js/ResourceWriter.js b/services/clsi/app/js/ResourceWriter.js index 11fb4500f4..c6ff0caf26 100644 --- a/services/clsi/app/js/ResourceWriter.js +++ b/services/clsi/app/js/ResourceWriter.js @@ -13,10 +13,10 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ let ResourceWriter -const { promisify } = require('util') +const { promisify } = require('node:util') const UrlCache = require('./UrlCache') -const Path = require('path') -const fs = require('fs') +const Path = require('node:path') +const fs = require('node:fs') const async = require('async') const OutputFileFinder = require('./OutputFileFinder') const ResourceStateManager = require('./ResourceStateManager') diff --git a/services/clsi/app/js/SafeReader.js b/services/clsi/app/js/SafeReader.js index 756747af47..8b1b5abb54 100644 --- a/services/clsi/app/js/SafeReader.js +++ b/services/clsi/app/js/SafeReader.js @@ -12,7 +12,7 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ let SafeReader -const fs = require('fs') +const fs = require('node:fs') const logger = require('@overleaf/logger') module.exports = SafeReader = { diff --git a/services/clsi/app/js/StaticServerForbidSymlinks.js b/services/clsi/app/js/StaticServerForbidSymlinks.js index 219408eb11..a5ec774396 100644 --- a/services/clsi/app/js/StaticServerForbidSymlinks.js +++ b/services/clsi/app/js/StaticServerForbidSymlinks.js @@ -13,8 +13,8 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ let ForbidSymlinks -const Path = require('path') -const fs = require('fs') +const Path = require('node:path') +const fs = require('node:fs') const Settings = require('@overleaf/settings') const logger = require('@overleaf/logger') diff --git a/services/clsi/app/js/SynctexOutputParser.js b/services/clsi/app/js/SynctexOutputParser.js index e54add65ae..5b2d237825 100644 --- a/services/clsi/app/js/SynctexOutputParser.js +++ b/services/clsi/app/js/SynctexOutputParser.js @@ -1,4 +1,4 @@ -const Path = require('path') +const Path = require('node:path') /** * Parse output from the `synctex view` command diff --git a/services/clsi/app/js/TikzManager.js b/services/clsi/app/js/TikzManager.js index 7d5f6c1b81..ca9db6b005 100644 --- a/services/clsi/app/js/TikzManager.js +++ b/services/clsi/app/js/TikzManager.js @@ -11,9 +11,9 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ let TikzManager -const fs = require('fs') -const Path = require('path') -const { promisify } = require('util') +const fs = require('node:fs') +const Path = require('node:path') +const { promisify } = require('node:util') const ResourceWriter = require('./ResourceWriter') const SafeReader = require('./SafeReader') const logger = require('@overleaf/logger') diff --git a/services/clsi/app/js/UrlCache.js b/services/clsi/app/js/UrlCache.js index ae8eae6b2a..65a0f21b46 100644 --- a/services/clsi/app/js/UrlCache.js +++ b/services/clsi/app/js/UrlCache.js @@ -12,9 +12,9 @@ */ const UrlFetcher = require('./UrlFetcher') const Settings = require('@overleaf/settings') -const fs = require('fs') -const Path = require('path') -const { callbackify } = require('util') +const fs = require('node:fs') +const Path = require('node:path') +const { callbackify } = require('node:util') const Metrics = require('./Metrics') const PENDING_DOWNLOADS = new Map() diff --git a/services/clsi/app/js/UrlFetcher.js b/services/clsi/app/js/UrlFetcher.js index 8d604d267b..2f48dc306a 100644 --- a/services/clsi/app/js/UrlFetcher.js +++ b/services/clsi/app/js/UrlFetcher.js @@ -1,4 +1,4 @@ -const fs = require('fs') +const fs = require('node:fs') const logger = require('@overleaf/logger') const Settings = require('@overleaf/settings') const { @@ -6,8 +6,8 @@ const { CustomHttpsAgent, fetchStream, } = require('@overleaf/fetch-utils') -const { URL } = require('url') -const { pipeline } = require('stream/promises') +const { URL } = require('node:url') +const { pipeline } = require('node:stream/promises') const Metrics = require('./Metrics') const MAX_CONNECT_TIME = 1000 diff --git a/services/clsi/app/js/XrefParser.js b/services/clsi/app/js/XrefParser.js index 76636acfe9..5f2d154679 100644 --- a/services/clsi/app/js/XrefParser.js +++ b/services/clsi/app/js/XrefParser.js @@ -1,5 +1,5 @@ const { NoXrefTableError } = require('./Errors') -const fs = require('fs') +const fs = require('node:fs') const { O_RDONLY, O_NOFOLLOW } = fs.constants const MAX_XREF_FILE_SIZE = 1024 * 1024 diff --git a/services/clsi/config/settings.defaults.js b/services/clsi/config/settings.defaults.js index 934ef6d8c8..9ac08c8f1f 100644 --- a/services/clsi/config/settings.defaults.js +++ b/services/clsi/config/settings.defaults.js @@ -1,5 +1,5 @@ -const Path = require('path') -const os = require('os') +const Path = require('node:path') +const os = require('node:os') const isPreEmptible = os.hostname().includes('pre-emp') @@ -131,7 +131,7 @@ if (process.env.DOCKER_RUNNER) { try { seccompProfilePath = Path.resolve(__dirname, '../seccomp/clsi-profile.json') module.exports.clsi.docker.seccomp_profile = JSON.stringify( - JSON.parse(require('fs').readFileSync(seccompProfilePath)) + JSON.parse(require('node:fs').readFileSync(seccompProfilePath)) ) } catch (error) { console.error( diff --git a/services/clsi/scripts/demo-pdfjs-Xref.js b/services/clsi/scripts/demo-pdfjs-Xref.js index 149e55ee9e..1f55c571a7 100644 --- a/services/clsi/scripts/demo-pdfjs-Xref.js +++ b/services/clsi/scripts/demo-pdfjs-Xref.js @@ -1,4 +1,4 @@ -const fs = require('fs') +const fs = require('node:fs') const { parseXrefTable } = require('../app/lib/pdfjs/parseXrefTable') const pdfPath = process.argv[2] diff --git a/services/clsi/test/acceptance/js/ExampleDocumentTests.js b/services/clsi/test/acceptance/js/ExampleDocumentTests.js index 404f8c4e90..b463584501 100644 --- a/services/clsi/test/acceptance/js/ExampleDocumentTests.js +++ b/services/clsi/test/acceptance/js/ExampleDocumentTests.js @@ -14,19 +14,19 @@ */ const Client = require('./helpers/Client') const fetch = require('node-fetch') -const { pipeline } = require('stream') -const fs = require('fs') -const ChildProcess = require('child_process') +const { pipeline } = require('node:stream') +const fs = require('node:fs') +const ChildProcess = require('node:child_process') const ClsiApp = require('./helpers/ClsiApp') const logger = require('@overleaf/logger') -const Path = require('path') +const Path = require('node:path') const fixturePath = path => { if (path.slice(0, 3) === 'tmp') { return '/tmp/clsi_acceptance_tests' + path.slice(3) } return Path.join(__dirname, '../fixtures/', path) } -const process = require('process') +const process = require('node:process') console.log( process.pid, process.ppid, diff --git a/services/clsi/test/acceptance/js/SynctexTests.js b/services/clsi/test/acceptance/js/SynctexTests.js index 899898b5b2..5ba5bb5b5f 100644 --- a/services/clsi/test/acceptance/js/SynctexTests.js +++ b/services/clsi/test/acceptance/js/SynctexTests.js @@ -13,7 +13,7 @@ const Client = require('./helpers/Client') const request = require('request') const { expect } = require('chai') const ClsiApp = require('./helpers/ClsiApp') -const crypto = require('crypto') +const crypto = require('node:crypto') describe('Syncing', function () { before(function (done) { diff --git a/services/clsi/test/acceptance/js/UrlCachingTests.js b/services/clsi/test/acceptance/js/UrlCachingTests.js index 424f1ad1b7..e1f70b655c 100644 --- a/services/clsi/test/acceptance/js/UrlCachingTests.js +++ b/services/clsi/test/acceptance/js/UrlCachingTests.js @@ -10,7 +10,7 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ const express = require('express') -const Path = require('path') +const Path = require('node:path') const Client = require('./helpers/Client') const sinon = require('sinon') const ClsiApp = require('./helpers/ClsiApp') diff --git a/services/clsi/test/acceptance/js/WordcountTests.js b/services/clsi/test/acceptance/js/WordcountTests.js index d3fa7d2b94..626b5d7034 100644 --- a/services/clsi/test/acceptance/js/WordcountTests.js +++ b/services/clsi/test/acceptance/js/WordcountTests.js @@ -12,8 +12,8 @@ const Client = require('./helpers/Client') const request = require('request') const { expect } = require('chai') -const path = require('path') -const fs = require('fs') +const path = require('node:path') +const fs = require('node:fs') const ClsiApp = require('./helpers/ClsiApp') describe('Syncing', function () { diff --git a/services/clsi/test/acceptance/js/helpers/Client.js b/services/clsi/test/acceptance/js/helpers/Client.js index 389a26201e..a0bdce734f 100644 --- a/services/clsi/test/acceptance/js/helpers/Client.js +++ b/services/clsi/test/acceptance/js/helpers/Client.js @@ -13,7 +13,7 @@ let Client const express = require('express') const request = require('request') -const fs = require('fs') +const fs = require('node:fs') const Settings = require('@overleaf/settings') module.exports = Client = { diff --git a/services/clsi/test/bench/hashbench.js b/services/clsi/test/bench/hashbench.js index 652ad39c7d..1e19af6a35 100644 --- a/services/clsi/test/bench/hashbench.js +++ b/services/clsi/test/bench/hashbench.js @@ -1,8 +1,8 @@ const ContentCacheManager = require('../../app/js/ContentCacheManager') -const fs = require('fs') -const crypto = require('crypto') -const path = require('path') -const os = require('os') +const fs = require('node:fs') +const crypto = require('node:crypto') +const path = require('node:path') +const os = require('node:os') const async = require('async') const _createHash = crypto.createHash diff --git a/services/clsi/test/load/js/loadTest.js b/services/clsi/test/load/js/loadTest.js index 196d8579ca..506b51bf6f 100644 --- a/services/clsi/test/load/js/loadTest.js +++ b/services/clsi/test/load/js/loadTest.js @@ -9,7 +9,7 @@ const request = require('request') const Settings = require('@overleaf/settings') const async = require('async') -const fs = require('fs') +const fs = require('node:fs') const _ = require('lodash') const concurentCompiles = 5 const totalCompiles = 50 diff --git a/services/clsi/test/setup.js b/services/clsi/test/setup.js index 653a8a69b2..19e1ae7165 100644 --- a/services/clsi/test/setup.js +++ b/services/clsi/test/setup.js @@ -21,4 +21,9 @@ SandboxedModule.configure({ }, }, globals: { Buffer, console, process, URL }, + sourceTransformers: { + removeNodePrefix: function (source) { + return source.replace(/require\(['"]node:/g, "require('") + }, + }, }) diff --git a/services/clsi/test/unit/js/CompileControllerTests.js b/services/clsi/test/unit/js/CompileControllerTests.js index ac807d212e..d97e433f29 100644 --- a/services/clsi/test/unit/js/CompileControllerTests.js +++ b/services/clsi/test/unit/js/CompileControllerTests.js @@ -1,7 +1,7 @@ const SandboxedModule = require('sandboxed-module') const sinon = require('sinon') const { expect } = require('chai') -const modulePath = require('path').join( +const modulePath = require('node:path').join( __dirname, '../../../app/js/CompileController' ) diff --git a/services/clsi/test/unit/js/CompileManagerTests.js b/services/clsi/test/unit/js/CompileManagerTests.js index 6f5b5baf64..8d7aff4910 100644 --- a/services/clsi/test/unit/js/CompileManagerTests.js +++ b/services/clsi/test/unit/js/CompileManagerTests.js @@ -1,9 +1,9 @@ -const Path = require('path') +const Path = require('node:path') const SandboxedModule = require('sandboxed-module') const { expect } = require('chai') const sinon = require('sinon') -const MODULE_PATH = require('path').join( +const MODULE_PATH = require('node:path').join( __dirname, '../../../app/js/CompileManager' ) diff --git a/services/clsi/test/unit/js/ContentCacheManagerTests.js b/services/clsi/test/unit/js/ContentCacheManagerTests.js index be2d17039d..df3bce212b 100644 --- a/services/clsi/test/unit/js/ContentCacheManagerTests.js +++ b/services/clsi/test/unit/js/ContentCacheManagerTests.js @@ -1,5 +1,5 @@ -const fs = require('fs') -const Path = require('path') +const fs = require('node:fs') +const Path = require('node:path') const { expect } = require('chai') const MODULE_PATH = '../../../app/js/ContentCacheManager' diff --git a/services/clsi/test/unit/js/ContentTypeMapperTests.js b/services/clsi/test/unit/js/ContentTypeMapperTests.js index a80ef991ca..a413337153 100644 --- a/services/clsi/test/unit/js/ContentTypeMapperTests.js +++ b/services/clsi/test/unit/js/ContentTypeMapperTests.js @@ -11,7 +11,7 @@ */ const SandboxedModule = require('sandboxed-module') const sinon = require('sinon') -const modulePath = require('path').join( +const modulePath = require('node:path').join( __dirname, '../../../app/js/ContentTypeMapper' ) diff --git a/services/clsi/test/unit/js/DockerLockManagerTests.js b/services/clsi/test/unit/js/DockerLockManagerTests.js index 5708faf292..c494a85c66 100644 --- a/services/clsi/test/unit/js/DockerLockManagerTests.js +++ b/services/clsi/test/unit/js/DockerLockManagerTests.js @@ -11,7 +11,7 @@ */ const SandboxedModule = require('sandboxed-module') const sinon = require('sinon') -const modulePath = require('path').join( +const modulePath = require('node:path').join( __dirname, '../../../app/js/DockerLockManager' ) diff --git a/services/clsi/test/unit/js/DockerRunnerTests.js b/services/clsi/test/unit/js/DockerRunnerTests.js index 8ff9c6107b..6c377d102b 100644 --- a/services/clsi/test/unit/js/DockerRunnerTests.js +++ b/services/clsi/test/unit/js/DockerRunnerTests.js @@ -15,11 +15,11 @@ const SandboxedModule = require('sandboxed-module') const sinon = require('sinon') const { expect } = require('chai') -const modulePath = require('path').join( +const modulePath = require('node:path').join( __dirname, '../../../app/js/DockerRunner' ) -const Path = require('path') +const Path = require('node:path') describe('DockerRunner', function () { beforeEach(function () { diff --git a/services/clsi/test/unit/js/DraftModeManagerTests.js b/services/clsi/test/unit/js/DraftModeManagerTests.js index acaae0f10a..eda83380e7 100644 --- a/services/clsi/test/unit/js/DraftModeManagerTests.js +++ b/services/clsi/test/unit/js/DraftModeManagerTests.js @@ -1,5 +1,5 @@ -const Path = require('path') -const fsPromises = require('fs/promises') +const Path = require('node:path') +const fsPromises = require('node:fs/promises') const { expect } = require('chai') const mockFs = require('mock-fs') const SandboxedModule = require('sandboxed-module') diff --git a/services/clsi/test/unit/js/LatexRunnerTests.js b/services/clsi/test/unit/js/LatexRunnerTests.js index ca36d7308f..0d250dd517 100644 --- a/services/clsi/test/unit/js/LatexRunnerTests.js +++ b/services/clsi/test/unit/js/LatexRunnerTests.js @@ -2,7 +2,7 @@ const SandboxedModule = require('sandboxed-module') const sinon = require('sinon') const { expect } = require('chai') -const MODULE_PATH = require('path').join( +const MODULE_PATH = require('node:path').join( __dirname, '../../../app/js/LatexRunner' ) diff --git a/services/clsi/test/unit/js/LockManagerTests.js b/services/clsi/test/unit/js/LockManagerTests.js index cd0d34cd4a..64238ea0c6 100644 --- a/services/clsi/test/unit/js/LockManagerTests.js +++ b/services/clsi/test/unit/js/LockManagerTests.js @@ -1,7 +1,7 @@ const { expect } = require('chai') const sinon = require('sinon') const SandboxedModule = require('sandboxed-module') -const modulePath = require('path').join( +const modulePath = require('node:path').join( __dirname, '../../../app/js/LockManager' ) diff --git a/services/clsi/test/unit/js/OutputControllerTests.js b/services/clsi/test/unit/js/OutputControllerTests.js index 33367af26a..ee5c9c2a7a 100644 --- a/services/clsi/test/unit/js/OutputControllerTests.js +++ b/services/clsi/test/unit/js/OutputControllerTests.js @@ -1,6 +1,6 @@ const SandboxedModule = require('sandboxed-module') const sinon = require('sinon') -const MODULE_PATH = require('path').join( +const MODULE_PATH = require('node:path').join( __dirname, '../../../app/js/OutputController' ) @@ -19,7 +19,7 @@ describe('OutputController', function () { './OutputFileArchiveManager': { archiveFilesForBuild: this.archiveFilesForBuild, }, - 'node:stream/promises': { + 'stream/promises': { pipeline: this.pipeline, }, }, diff --git a/services/clsi/test/unit/js/OutputFileArchiveManagerTests.js b/services/clsi/test/unit/js/OutputFileArchiveManagerTests.js index bd62b00825..d6817f3559 100644 --- a/services/clsi/test/unit/js/OutputFileArchiveManagerTests.js +++ b/services/clsi/test/unit/js/OutputFileArchiveManagerTests.js @@ -2,7 +2,7 @@ const SandboxedModule = require('sandboxed-module') const sinon = require('sinon') const { assert, expect } = require('chai') -const MODULE_PATH = require('path').join( +const MODULE_PATH = require('node:path').join( __dirname, '../../../app/js/OutputFileArchiveManager' ) @@ -50,7 +50,7 @@ describe('OutputFileArchiveManager', function () { './OutputFileFinder': this.OutputFileFinder, './OutputCacheManager': this.OutputCacheManger, archiver: this.archiver, - 'node:fs/promises': this.fs, + 'fs/promises': this.fs, '@overleaf/settings': { path: { outputDir: this.outputDir, diff --git a/services/clsi/test/unit/js/OutputFileFinderTests.js b/services/clsi/test/unit/js/OutputFileFinderTests.js index cf596a6271..c9e1b443be 100644 --- a/services/clsi/test/unit/js/OutputFileFinderTests.js +++ b/services/clsi/test/unit/js/OutputFileFinderTests.js @@ -1,6 +1,6 @@ const SandboxedModule = require('sandboxed-module') const sinon = require('sinon') -const modulePath = require('path').join( +const modulePath = require('node:path').join( __dirname, '../../../app/js/OutputFileFinder' ) diff --git a/services/clsi/test/unit/js/OutputFileOptimiserTests.js b/services/clsi/test/unit/js/OutputFileOptimiserTests.js index d74c6a3534..1dd1a751b9 100644 --- a/services/clsi/test/unit/js/OutputFileOptimiserTests.js +++ b/services/clsi/test/unit/js/OutputFileOptimiserTests.js @@ -12,13 +12,13 @@ */ const SandboxedModule = require('sandboxed-module') const sinon = require('sinon') -const modulePath = require('path').join( +const modulePath = require('node:path').join( __dirname, '../../../app/js/OutputFileOptimiser' ) -const path = require('path') +const path = require('node:path') const { expect } = require('chai') -const { EventEmitter } = require('events') +const { EventEmitter } = require('node:events') describe('OutputFileOptimiser', function () { beforeEach(function () { diff --git a/services/clsi/test/unit/js/ProjectPersistenceManagerTests.js b/services/clsi/test/unit/js/ProjectPersistenceManagerTests.js index c5f30b1ea9..b36b9245e4 100644 --- a/services/clsi/test/unit/js/ProjectPersistenceManagerTests.js +++ b/services/clsi/test/unit/js/ProjectPersistenceManagerTests.js @@ -13,7 +13,7 @@ const SandboxedModule = require('sandboxed-module') const sinon = require('sinon') const assert = require('chai').assert -const modulePath = require('path').join( +const modulePath = require('node:path').join( __dirname, '../../../app/js/ProjectPersistenceManager' ) diff --git a/services/clsi/test/unit/js/RequestParserTests.js b/services/clsi/test/unit/js/RequestParserTests.js index 4cf31a2b37..5fdae7ed3d 100644 --- a/services/clsi/test/unit/js/RequestParserTests.js +++ b/services/clsi/test/unit/js/RequestParserTests.js @@ -1,7 +1,7 @@ const SandboxedModule = require('sandboxed-module') const sinon = require('sinon') const { expect } = require('chai') -const modulePath = require('path').join( +const modulePath = require('node:path').join( __dirname, '../../../app/js/RequestParser' ) diff --git a/services/clsi/test/unit/js/ResourceStateManagerTests.js b/services/clsi/test/unit/js/ResourceStateManagerTests.js index 0a97d7b705..823c81616f 100644 --- a/services/clsi/test/unit/js/ResourceStateManagerTests.js +++ b/services/clsi/test/unit/js/ResourceStateManagerTests.js @@ -12,11 +12,11 @@ const SandboxedModule = require('sandboxed-module') const sinon = require('sinon') const { expect } = require('chai') -const modulePath = require('path').join( +const modulePath = require('node:path').join( __dirname, '../../../app/js/ResourceStateManager' ) -const Path = require('path') +const Path = require('node:path') const Errors = require('../../../app/js/Errors') describe('ResourceStateManager', function () { diff --git a/services/clsi/test/unit/js/ResourceWriterTests.js b/services/clsi/test/unit/js/ResourceWriterTests.js index 3b18a3b195..c7db8b98f2 100644 --- a/services/clsi/test/unit/js/ResourceWriterTests.js +++ b/services/clsi/test/unit/js/ResourceWriterTests.js @@ -13,11 +13,11 @@ const SandboxedModule = require('sandboxed-module') const sinon = require('sinon') const { expect } = require('chai') -const modulePath = require('path').join( +const modulePath = require('node:path').join( __dirname, '../../../app/js/ResourceWriter' ) -const path = require('path') +const path = require('node:path') describe('ResourceWriter', function () { beforeEach(function () { diff --git a/services/clsi/test/unit/js/StaticServerForbidSymlinksTests.js b/services/clsi/test/unit/js/StaticServerForbidSymlinksTests.js index 0a3806a1e6..53507fe3f2 100644 --- a/services/clsi/test/unit/js/StaticServerForbidSymlinksTests.js +++ b/services/clsi/test/unit/js/StaticServerForbidSymlinksTests.js @@ -10,8 +10,8 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ const SandboxedModule = require('sandboxed-module') -const assert = require('assert') -const path = require('path') +const assert = require('node:assert') +const path = require('node:path') const sinon = require('sinon') const modulePath = path.join( __dirname, diff --git a/services/clsi/test/unit/js/SynctexOutputParserTests.js b/services/clsi/test/unit/js/SynctexOutputParserTests.js index 19bf2f6d37..b999a6adb1 100644 --- a/services/clsi/test/unit/js/SynctexOutputParserTests.js +++ b/services/clsi/test/unit/js/SynctexOutputParserTests.js @@ -1,4 +1,4 @@ -const Path = require('path') +const Path = require('node:path') const SandboxedModule = require('sandboxed-module') const { expect } = require('chai') diff --git a/services/clsi/test/unit/js/TikzManager.js b/services/clsi/test/unit/js/TikzManager.js index 8e01194955..ee651f6b1d 100644 --- a/services/clsi/test/unit/js/TikzManager.js +++ b/services/clsi/test/unit/js/TikzManager.js @@ -10,7 +10,7 @@ */ const SandboxedModule = require('sandboxed-module') const sinon = require('sinon') -const modulePath = require('path').join( +const modulePath = require('node:path').join( __dirname, '../../../app/js/TikzManager' ) diff --git a/services/clsi/test/unit/js/UrlCacheTests.js b/services/clsi/test/unit/js/UrlCacheTests.js index a5c1e60c0a..7a3a8f6f00 100644 --- a/services/clsi/test/unit/js/UrlCacheTests.js +++ b/services/clsi/test/unit/js/UrlCacheTests.js @@ -13,7 +13,10 @@ const SandboxedModule = require('sandboxed-module') const sinon = require('sinon') const { expect } = require('chai') -const modulePath = require('path').join(__dirname, '../../../app/js/UrlCache') +const modulePath = require('node:path').join( + __dirname, + '../../../app/js/UrlCache' +) describe('UrlCache', function () { beforeEach(function () { diff --git a/services/clsi/test/unit/js/pdfjsTests.js b/services/clsi/test/unit/js/pdfjsTests.js index ef85ccc704..bc8b775b43 100644 --- a/services/clsi/test/unit/js/pdfjsTests.js +++ b/services/clsi/test/unit/js/pdfjsTests.js @@ -1,5 +1,5 @@ -const fs = require('fs') -const Path = require('path') +const fs = require('node:fs') +const Path = require('node:path') const { expect } = require('chai') const { parseXrefTable } = require('../../../app/js/XrefParser') const { NoXrefTableError } = require('../../../app/js/Errors') diff --git a/services/docstore/app.js b/services/docstore/app.js index 51ad785065..b4a26fc24a 100644 --- a/services/docstore/app.js +++ b/services/docstore/app.js @@ -1,7 +1,7 @@ // Metrics must be initialized before importing anything else require('@overleaf/metrics/initialize') -const Events = require('events') +const Events = require('node:events') const Metrics = require('@overleaf/metrics') const Settings = require('@overleaf/settings') const logger = require('@overleaf/logger') diff --git a/services/docstore/app/js/DocArchiveManager.js b/services/docstore/app/js/DocArchiveManager.js index 035448f4a1..238672e711 100644 --- a/services/docstore/app/js/DocArchiveManager.js +++ b/services/docstore/app/js/DocArchiveManager.js @@ -1,9 +1,9 @@ -const { callbackify } = require('util') +const { callbackify } = require('node:util') const MongoManager = require('./MongoManager').promises const Errors = require('./Errors') const logger = require('@overleaf/logger') const Settings = require('@overleaf/settings') -const crypto = require('crypto') +const crypto = require('node:crypto') const { ReadableString } = require('@overleaf/stream-utils') const RangeManager = require('./RangeManager') const PersistorManager = require('./PersistorManager') diff --git a/services/docstore/app/js/DocManager.js b/services/docstore/app/js/DocManager.js index 80e8ae4527..a9ed99425c 100644 --- a/services/docstore/app/js/DocManager.js +++ b/services/docstore/app/js/DocManager.js @@ -6,7 +6,7 @@ const DocArchive = require('./DocArchiveManager') const RangeManager = require('./RangeManager') const Settings = require('@overleaf/settings') const { callbackifyAll } = require('@overleaf/promise-utils') -const { setTimeout } = require('timers/promises') +const { setTimeout } = require('node:timers/promises') /** * @import { Document } from 'mongodb' diff --git a/services/docstore/app/js/HealthChecker.js b/services/docstore/app/js/HealthChecker.js index 65dc92cbba..34cd5c973c 100644 --- a/services/docstore/app/js/HealthChecker.js +++ b/services/docstore/app/js/HealthChecker.js @@ -10,7 +10,7 @@ const { db, ObjectId } = require('./mongodb') const request = require('request') const async = require('async') const _ = require('lodash') -const crypto = require('crypto') +const crypto = require('node:crypto') const settings = require('@overleaf/settings') const { port } = settings.internal.docstore const logger = require('@overleaf/logger') diff --git a/services/docstore/app/js/MongoManager.js b/services/docstore/app/js/MongoManager.js index 87d8af8a1b..ad1a2d2b40 100644 --- a/services/docstore/app/js/MongoManager.js +++ b/services/docstore/app/js/MongoManager.js @@ -1,7 +1,7 @@ const { db, ObjectId } = require('./mongodb') const Settings = require('@overleaf/settings') const Errors = require('./Errors') -const { callbackify } = require('util') +const { callbackify } = require('node:util') const ARCHIVING_LOCK_DURATION_MS = Settings.archivingLockDurationMs diff --git a/services/docstore/config/settings.defaults.js b/services/docstore/config/settings.defaults.js index b91cdc87ec..817fb69451 100644 --- a/services/docstore/config/settings.defaults.js +++ b/services/docstore/config/settings.defaults.js @@ -1,4 +1,4 @@ -const http = require('http') +const http = require('node:http') http.globalAgent.maxSockets = 300 const Settings = { diff --git a/services/docstore/test/acceptance/js/ArchiveDocsTests.js b/services/docstore/test/acceptance/js/ArchiveDocsTests.js index f85b845a18..d9228103b6 100644 --- a/services/docstore/test/acceptance/js/ArchiveDocsTests.js +++ b/services/docstore/test/acceptance/js/ArchiveDocsTests.js @@ -399,7 +399,7 @@ describe('Archiving', function () { this.project_id = new ObjectId() this.timeout(1000 * 30) const quarterMegInBytes = 250000 - const bigLine = require('crypto') + const bigLine = require('node:crypto') .randomBytes(quarterMegInBytes) .toString('hex') this.doc = { diff --git a/services/docstore/test/setup.js b/services/docstore/test/setup.js index 809624a2ee..92b86c9384 100644 --- a/services/docstore/test/setup.js +++ b/services/docstore/test/setup.js @@ -3,7 +3,7 @@ const sinon = require('sinon') const sinonChai = require('sinon-chai') const chaiAsPromised = require('chai-as-promised') const SandboxedModule = require('sandboxed-module') -const timersPromises = require('timers/promises') +const timersPromises = require('node:timers/promises') // ensure every ObjectId has the id string as a property for correct comparisons require('mongodb-legacy').ObjectId.cacheHexString = true @@ -37,6 +37,11 @@ SandboxedModule.configure({ 'mongodb-legacy': require('mongodb-legacy'), }, globals: { Buffer, JSON, Math, console, process }, + sourceTransformers: { + removeNodePrefix: function (source) { + return source.replace(/require\(['"]node:/g, "require('") + }, + }, }) exports.mochaHooks = { diff --git a/services/docstore/test/unit/js/DocManagerTests.js b/services/docstore/test/unit/js/DocManagerTests.js index be833f4b3f..8405520e6e 100644 --- a/services/docstore/test/unit/js/DocManagerTests.js +++ b/services/docstore/test/unit/js/DocManagerTests.js @@ -1,7 +1,10 @@ const SandboxedModule = require('sandboxed-module') const sinon = require('sinon') const { expect } = require('chai') -const modulePath = require('path').join(__dirname, '../../../app/js/DocManager') +const modulePath = require('node:path').join( + __dirname, + '../../../app/js/DocManager' +) const { ObjectId } = require('mongodb-legacy') const Errors = require('../../../app/js/Errors') diff --git a/services/docstore/test/unit/js/HttpControllerTests.js b/services/docstore/test/unit/js/HttpControllerTests.js index 2ed46a9d70..bf78696890 100644 --- a/services/docstore/test/unit/js/HttpControllerTests.js +++ b/services/docstore/test/unit/js/HttpControllerTests.js @@ -1,7 +1,7 @@ const SandboxedModule = require('sandboxed-module') const sinon = require('sinon') const { assert, expect } = require('chai') -const modulePath = require('path').join( +const modulePath = require('node:path').join( __dirname, '../../../app/js/HttpController' ) diff --git a/services/docstore/test/unit/js/MongoManagerTests.js b/services/docstore/test/unit/js/MongoManagerTests.js index da8f59ae07..4f8467db76 100644 --- a/services/docstore/test/unit/js/MongoManagerTests.js +++ b/services/docstore/test/unit/js/MongoManagerTests.js @@ -1,6 +1,6 @@ const SandboxedModule = require('sandboxed-module') const sinon = require('sinon') -const modulePath = require('path').join( +const modulePath = require('node:path').join( __dirname, '../../../app/js/MongoManager' ) diff --git a/services/docstore/test/unit/js/RangeManagerTests.js b/services/docstore/test/unit/js/RangeManagerTests.js index 0d2a353558..7a2de7352e 100644 --- a/services/docstore/test/unit/js/RangeManagerTests.js +++ b/services/docstore/test/unit/js/RangeManagerTests.js @@ -12,7 +12,7 @@ const SandboxedModule = require('sandboxed-module') const sinon = require('sinon') const { assert, expect } = require('chai') -const modulePath = require('path').join( +const modulePath = require('node:path').join( __dirname, '../../../app/js/RangeManager' ) diff --git a/services/document-updater/app/js/PersistenceManager.js b/services/document-updater/app/js/PersistenceManager.js index 484b9bab2a..b08994ae41 100644 --- a/services/document-updater/app/js/PersistenceManager.js +++ b/services/document-updater/app/js/PersistenceManager.js @@ -1,4 +1,4 @@ -const { promisify } = require('util') +const { promisify } = require('node:util') const { promisifyMultiResult } = require('@overleaf/promise-utils') const Settings = require('@overleaf/settings') const Errors = require('./Errors') diff --git a/services/document-updater/app/js/RealTimeRedisManager.js b/services/document-updater/app/js/RealTimeRedisManager.js index 9f7465acb8..08bf132dec 100644 --- a/services/document-updater/app/js/RealTimeRedisManager.js +++ b/services/document-updater/app/js/RealTimeRedisManager.js @@ -20,8 +20,8 @@ const pubsubClient = require('@overleaf/redis-wrapper').createClient( ) const Keys = Settings.redis.documentupdater.key_schema const logger = require('@overleaf/logger') -const os = require('os') -const crypto = require('crypto') +const os = require('node:os') +const crypto = require('node:crypto') const metrics = require('./Metrics') const HOST = os.hostname() diff --git a/services/document-updater/app/js/RedisManager.js b/services/document-updater/app/js/RedisManager.js index 0d2dad1047..f8e97f38b4 100644 --- a/services/document-updater/app/js/RedisManager.js +++ b/services/document-updater/app/js/RedisManager.js @@ -7,7 +7,7 @@ const OError = require('@overleaf/o-error') const { promisifyAll } = require('@overleaf/promise-utils') const metrics = require('./Metrics') const Errors = require('./Errors') -const crypto = require('crypto') +const crypto = require('node:crypto') const async = require('async') const { docIsTooLarge } = require('./Limits') diff --git a/services/document-updater/app/js/ShareJsUpdateManager.js b/services/document-updater/app/js/ShareJsUpdateManager.js index edac3700b7..933ded1ce1 100644 --- a/services/document-updater/app/js/ShareJsUpdateManager.js +++ b/services/document-updater/app/js/ShareJsUpdateManager.js @@ -16,10 +16,10 @@ const logger = require('@overleaf/logger') const Settings = require('@overleaf/settings') const { promisifyAll } = require('@overleaf/promise-utils') const Keys = require('./UpdateKeys') -const { EventEmitter } = require('events') -const util = require('util') +const { EventEmitter } = require('node:events') +const util = require('node:util') const RealTimeRedisManager = require('./RealTimeRedisManager') -const crypto = require('crypto') +const crypto = require('node:crypto') const metrics = require('./Metrics') const Errors = require('./Errors') diff --git a/services/document-updater/app/js/mongodb.js b/services/document-updater/app/js/mongodb.js index 6c4415adcc..6e38993bc4 100644 --- a/services/document-updater/app/js/mongodb.js +++ b/services/document-updater/app/js/mongodb.js @@ -24,5 +24,5 @@ module.exports = { db, ObjectId, mongoClient, - healthCheck: require('util').callbackify(healthCheck), + healthCheck: require('node:util').callbackify(healthCheck), } diff --git a/services/document-updater/app/js/sharejs/server/model.js b/services/document-updater/app/js/sharejs/server/model.js index 370208cc37..a646b22492 100644 --- a/services/document-updater/app/js/sharejs/server/model.js +++ b/services/document-updater/app/js/sharejs/server/model.js @@ -22,7 +22,7 @@ // Actual storage is handled by the database wrappers in db/*, wrapped by DocCache let Model -const { EventEmitter } = require('events') +const { EventEmitter } = require('node:events') const queue = require('./syncqueue') const types = require('../types') diff --git a/services/document-updater/app/js/sharejs/types/model.js b/services/document-updater/app/js/sharejs/types/model.js index d927811895..af9fd0ad18 100644 --- a/services/document-updater/app/js/sharejs/types/model.js +++ b/services/document-updater/app/js/sharejs/types/model.js @@ -22,7 +22,7 @@ // Actual storage is handled by the database wrappers in db/*, wrapped by DocCache let Model -const { EventEmitter } = require('events') +const { EventEmitter } = require('node:events') const queue = require('./syncqueue') const types = require('../types') diff --git a/services/document-updater/scripts/check_redis_mongo_sync_state.js b/services/document-updater/scripts/check_redis_mongo_sync_state.js index 0ca2bb4e8b..08209400aa 100644 --- a/services/document-updater/scripts/check_redis_mongo_sync_state.js +++ b/services/document-updater/scripts/check_redis_mongo_sync_state.js @@ -1,5 +1,5 @@ -const fs = require('fs') -const Path = require('path') +const fs = require('node:fs') +const Path = require('node:path') const _ = require('lodash') const logger = require('@overleaf/logger') const OError = require('@overleaf/o-error') diff --git a/services/document-updater/scripts/fix_docs_with_empty_pathnames.js b/services/document-updater/scripts/fix_docs_with_empty_pathnames.js index abbfb01ba7..e3e034157b 100644 --- a/services/document-updater/scripts/fix_docs_with_empty_pathnames.js +++ b/services/document-updater/scripts/fix_docs_with_empty_pathnames.js @@ -6,7 +6,7 @@ const rclient = require('@overleaf/redis-wrapper').createClient( const keys = Settings.redis.documentupdater.key_schema const ProjectFlusher = require('app/js/ProjectFlusher') const DocumentManager = require('app/js/DocumentManager') -const util = require('util') +const util = require('node:util') const flushAndDeleteDocWithLock = util.promisify( DocumentManager.flushAndDeleteDocWithLock ) diff --git a/services/document-updater/scripts/fix_docs_with_missing_project.js b/services/document-updater/scripts/fix_docs_with_missing_project.js index 0a9a05eaaa..d3022127b3 100644 --- a/services/document-updater/scripts/fix_docs_with_missing_project.js +++ b/services/document-updater/scripts/fix_docs_with_missing_project.js @@ -7,7 +7,7 @@ const keys = Settings.redis.documentupdater.key_schema const ProjectFlusher = require('../app/js/ProjectFlusher') const DocumentManager = require('../app/js/DocumentManager') const { mongoClient, db, ObjectId } = require('../app/js/mongodb') -const util = require('util') +const util = require('node:util') const flushAndDeleteDocWithLock = util.promisify( DocumentManager.flushAndDeleteDocWithLock ) diff --git a/services/document-updater/scripts/remove_deleted_docs.js b/services/document-updater/scripts/remove_deleted_docs.js index 1d0844872e..a69807119f 100644 --- a/services/document-updater/scripts/remove_deleted_docs.js +++ b/services/document-updater/scripts/remove_deleted_docs.js @@ -7,7 +7,7 @@ const keys = Settings.redis.documentupdater.key_schema const ProjectFlusher = require('../app/js/ProjectFlusher') const RedisManager = require('../app/js/RedisManager') const { mongoClient, db, ObjectId } = require('../app/js/mongodb') -const util = require('util') +const util = require('node:util') const getDoc = util.promisify((projectId, docId, cb) => RedisManager.getDoc(projectId, docId, (err, ...args) => cb(err, args)) ) diff --git a/services/document-updater/test/acceptance/js/CheckRedisMongoSyncStateTests.js b/services/document-updater/test/acceptance/js/CheckRedisMongoSyncStateTests.js index cd4f07bde7..ebbc015a58 100644 --- a/services/document-updater/test/acceptance/js/CheckRedisMongoSyncStateTests.js +++ b/services/document-updater/test/acceptance/js/CheckRedisMongoSyncStateTests.js @@ -1,12 +1,12 @@ const MockWebApi = require('./helpers/MockWebApi') const DocUpdaterClient = require('./helpers/DocUpdaterClient') const DocUpdaterApp = require('./helpers/DocUpdaterApp') -const { promisify } = require('util') -const { exec } = require('child_process') +const { promisify } = require('node:util') +const { exec } = require('node:child_process') const { expect } = require('chai') const Settings = require('@overleaf/settings') -const fs = require('fs') -const Path = require('path') +const fs = require('node:fs') +const Path = require('node:path') const MockDocstoreApi = require('./helpers/MockDocstoreApi') const sinon = require('sinon') diff --git a/services/document-updater/test/setup.js b/services/document-updater/test/setup.js index f7d47e7b75..1099724329 100644 --- a/services/document-updater/test/setup.js +++ b/services/document-updater/test/setup.js @@ -33,6 +33,11 @@ SandboxedModule.configure({ 'mongodb-legacy': require('mongodb-legacy'), // for ObjectId comparisons }, globals: { Buffer, JSON, Math, console, process }, + sourceTransformers: { + removeNodePrefix: function (source) { + return source.replace(/require\(['"]node:/g, "require('") + }, + }, }) // Mocha hooks diff --git a/services/document-updater/test/stress/js/run.js b/services/document-updater/test/stress/js/run.js index 4d2614eac4..1bda73c1aa 100644 --- a/services/document-updater/test/stress/js/run.js +++ b/services/document-updater/test/stress/js/run.js @@ -15,7 +15,7 @@ */ const DocUpdaterClient = require('../../acceptance/js/helpers/DocUpdaterClient') // MockWebApi = require "../../acceptance/js/helpers/MockWebApi" -const assert = require('assert') +const assert = require('node:assert') const async = require('async') const insert = function (string, pos, content) { diff --git a/services/document-updater/test/unit/js/HistoryManager/HistoryManagerTests.js b/services/document-updater/test/unit/js/HistoryManager/HistoryManagerTests.js index ce98c4eaa8..d0ac6cb9e0 100644 --- a/services/document-updater/test/unit/js/HistoryManager/HistoryManagerTests.js +++ b/services/document-updater/test/unit/js/HistoryManager/HistoryManagerTests.js @@ -3,7 +3,7 @@ */ const SandboxedModule = require('sandboxed-module') const sinon = require('sinon') -const modulePath = require('path').join( +const modulePath = require('node:path').join( __dirname, '../../../../app/js/HistoryManager' ) diff --git a/services/document-updater/test/unit/js/LockManager/CheckingTheLock.js b/services/document-updater/test/unit/js/LockManager/CheckingTheLock.js index eb5b44532a..575ed90702 100644 --- a/services/document-updater/test/unit/js/LockManager/CheckingTheLock.js +++ b/services/document-updater/test/unit/js/LockManager/CheckingTheLock.js @@ -10,8 +10,8 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ const sinon = require('sinon') -const assert = require('assert') -const path = require('path') +const assert = require('node:assert') +const path = require('node:path') const modulePath = path.join(__dirname, '../../../../app/js/LockManager.js') const projectId = 1234 const docId = 5678 diff --git a/services/document-updater/test/unit/js/LockManager/ReleasingTheLock.js b/services/document-updater/test/unit/js/LockManager/ReleasingTheLock.js index 0413e268d6..a39a3b4fff 100644 --- a/services/document-updater/test/unit/js/LockManager/ReleasingTheLock.js +++ b/services/document-updater/test/unit/js/LockManager/ReleasingTheLock.js @@ -11,8 +11,8 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ const sinon = require('sinon') -const assert = require('assert') -const path = require('path') +const assert = require('node:assert') +const path = require('node:path') const modulePath = path.join(__dirname, '../../../../app/js/LockManager.js') const projectId = 1234 const docId = 5678 diff --git a/services/document-updater/test/unit/js/RedisManager/RedisManagerTests.js b/services/document-updater/test/unit/js/RedisManager/RedisManagerTests.js index e23964eaba..125dd3d08c 100644 --- a/services/document-updater/test/unit/js/RedisManager/RedisManagerTests.js +++ b/services/document-updater/test/unit/js/RedisManager/RedisManagerTests.js @@ -2,7 +2,7 @@ const sinon = require('sinon') const { expect } = require('chai') const SandboxedModule = require('sandboxed-module') const Errors = require('../../../../app/js/Errors') -const crypto = require('crypto') +const crypto = require('node:crypto') const tk = require('timekeeper') const MODULE_PATH = '../../../../app/js/RedisManager.js' diff --git a/services/document-updater/test/unit/js/ShareJsUpdateManager/ShareJsUpdateManagerTests.js b/services/document-updater/test/unit/js/ShareJsUpdateManager/ShareJsUpdateManagerTests.js index 347ac7dea6..e699439a74 100644 --- a/services/document-updater/test/unit/js/ShareJsUpdateManager/ShareJsUpdateManagerTests.js +++ b/services/document-updater/test/unit/js/ShareJsUpdateManager/ShareJsUpdateManagerTests.js @@ -12,7 +12,7 @@ const sinon = require('sinon') const modulePath = '../../../../app/js/ShareJsUpdateManager.js' const SandboxedModule = require('sandboxed-module') -const crypto = require('crypto') +const crypto = require('node:crypto') describe('ShareJsUpdateManager', function () { beforeEach(function () { diff --git a/services/filestore/app.js b/services/filestore/app.js index 74b5fff246..9c28b47c16 100644 --- a/services/filestore/app.js +++ b/services/filestore/app.js @@ -1,7 +1,7 @@ // Metrics must be initialized before importing anything else require('@overleaf/metrics/initialize') -const Events = require('events') +const Events = require('node:events') const Metrics = require('@overleaf/metrics') const logger = require('@overleaf/logger') diff --git a/services/filestore/app/js/FileController.js b/services/filestore/app/js/FileController.js index 55aea5e264..127bbcc20f 100644 --- a/services/filestore/app/js/FileController.js +++ b/services/filestore/app/js/FileController.js @@ -2,7 +2,7 @@ const FileHandler = require('./FileHandler') const metrics = require('@overleaf/metrics') const parseRange = require('range-parser') const Errors = require('./Errors') -const { pipeline } = require('stream') +const { pipeline } = require('node:stream') const maxSizeInBytes = 1024 * 1024 * 1024 // 1GB diff --git a/services/filestore/app/js/FileConverter.js b/services/filestore/app/js/FileConverter.js index cb21a482e3..ac3dccec1f 100644 --- a/services/filestore/app/js/FileConverter.js +++ b/services/filestore/app/js/FileConverter.js @@ -1,6 +1,6 @@ const metrics = require('@overleaf/metrics') const Settings = require('@overleaf/settings') -const { callbackify } = require('util') +const { callbackify } = require('node:util') const safeExec = require('./SafeExec').promises const { ConversionError } = require('./Errors') diff --git a/services/filestore/app/js/FileHandler.js b/services/filestore/app/js/FileHandler.js index f3e4f86590..2ed28bd435 100644 --- a/services/filestore/app/js/FileHandler.js +++ b/services/filestore/app/js/FileHandler.js @@ -1,6 +1,6 @@ const Settings = require('@overleaf/settings') -const { callbackify } = require('util') -const fs = require('fs') +const { callbackify } = require('node:util') +const fs = require('node:fs') let PersistorManager = require('./PersistorManager') const LocalFileWriter = require('./LocalFileWriter') const FileConverter = require('./FileConverter') diff --git a/services/filestore/app/js/HealthCheckController.js b/services/filestore/app/js/HealthCheckController.js index fb296513b5..e9b739a971 100644 --- a/services/filestore/app/js/HealthCheckController.js +++ b/services/filestore/app/js/HealthCheckController.js @@ -1,9 +1,9 @@ -const fs = require('fs') -const path = require('path') +const fs = require('node:fs') +const path = require('node:path') const Settings = require('@overleaf/settings') const { WritableBuffer } = require('@overleaf/stream-utils') -const { promisify } = require('util') -const Stream = require('stream') +const { promisify } = require('node:util') +const Stream = require('node:stream') const pipeline = promisify(Stream.pipeline) const fsCopy = promisify(fs.copyFile) diff --git a/services/filestore/app/js/ImageOptimiser.js b/services/filestore/app/js/ImageOptimiser.js index a46a2857e1..6ed29e1c6d 100644 --- a/services/filestore/app/js/ImageOptimiser.js +++ b/services/filestore/app/js/ImageOptimiser.js @@ -1,6 +1,6 @@ const logger = require('@overleaf/logger') const metrics = require('@overleaf/metrics') -const { callbackify } = require('util') +const { callbackify } = require('node:util') const safeExec = require('./SafeExec').promises module.exports = { diff --git a/services/filestore/app/js/LocalFileWriter.js b/services/filestore/app/js/LocalFileWriter.js index c5b8ea41f1..fe55bdc138 100644 --- a/services/filestore/app/js/LocalFileWriter.js +++ b/services/filestore/app/js/LocalFileWriter.js @@ -1,8 +1,8 @@ -const fs = require('fs') -const crypto = require('crypto') -const path = require('path') -const Stream = require('stream') -const { callbackify, promisify } = require('util') +const fs = require('node:fs') +const crypto = require('node:crypto') +const path = require('node:path') +const Stream = require('node:stream') +const { callbackify, promisify } = require('node:util') const metrics = require('@overleaf/metrics') const Settings = require('@overleaf/settings') const { WriteError } = require('./Errors') diff --git a/services/filestore/app/js/SafeExec.js b/services/filestore/app/js/SafeExec.js index 63177b8057..16ebcf126b 100644 --- a/services/filestore/app/js/SafeExec.js +++ b/services/filestore/app/js/SafeExec.js @@ -1,5 +1,5 @@ const lodashOnce = require('lodash.once') -const childProcess = require('child_process') +const childProcess = require('node:child_process') const Settings = require('@overleaf/settings') const { ConversionsDisabledError, FailedCommandError } = require('./Errors') diff --git a/services/filestore/config/settings.defaults.js b/services/filestore/config/settings.defaults.js index 08fa66408f..7d762afb72 100644 --- a/services/filestore/config/settings.defaults.js +++ b/services/filestore/config/settings.defaults.js @@ -1,4 +1,4 @@ -const Path = require('path') +const Path = require('node:path') // environment variables renamed for consistency // use AWS_ACCESS_KEY_ID-style going forward diff --git a/services/filestore/test/acceptance/js/FilestoreApp.js b/services/filestore/test/acceptance/js/FilestoreApp.js index f6df01cc29..afcebb4c95 100644 --- a/services/filestore/test/acceptance/js/FilestoreApp.js +++ b/services/filestore/test/acceptance/js/FilestoreApp.js @@ -1,7 +1,7 @@ const logger = require('@overleaf/logger') const ObjectPersistor = require('@overleaf/object-persistor') const Settings = require('@overleaf/settings') -const { promisify } = require('util') +const { promisify } = require('node:util') const App = require('../../../app') const FileHandler = require('../../../app/js/FileHandler') diff --git a/services/filestore/test/acceptance/js/FilestoreTests.js b/services/filestore/test/acceptance/js/FilestoreTests.js index 2317fd515f..af67afe20b 100644 --- a/services/filestore/test/acceptance/js/FilestoreTests.js +++ b/services/filestore/test/acceptance/js/FilestoreTests.js @@ -1,18 +1,18 @@ const chai = require('chai') const { expect } = chai -const fs = require('fs') -const Stream = require('stream') +const fs = require('node:fs') +const Stream = require('node:stream') const Settings = require('@overleaf/settings') -const Path = require('path') +const Path = require('node:path') const FilestoreApp = require('./FilestoreApp') const TestHelper = require('./TestHelper') const fetch = require('node-fetch') -const { promisify } = require('util') +const { promisify } = require('node:util') const { Storage } = require('@google-cloud/storage') const streamifier = require('streamifier') chai.use(require('chai-as-promised')) const { ObjectId } = require('mongodb') -const ChildProcess = require('child_process') +const ChildProcess = require('node:child_process') const fsWriteFile = promisify(fs.writeFile) const fsStat = promisify(fs.stat) @@ -43,7 +43,7 @@ const { RootKeyEncryptionKey, } = require('@overleaf/object-persistor/src/PerProjectEncryptedS3Persistor') const { S3Persistor } = require('@overleaf/object-persistor/src/S3Persistor') -const crypto = require('crypto') +const crypto = require('node:crypto') describe('Filestore', function () { this.timeout(1000 * 10) diff --git a/services/filestore/test/acceptance/js/TestConfig.js b/services/filestore/test/acceptance/js/TestConfig.js index dfedad7dcf..cd0f601c8d 100644 --- a/services/filestore/test/acceptance/js/TestConfig.js +++ b/services/filestore/test/acceptance/js/TestConfig.js @@ -1,6 +1,6 @@ -const fs = require('fs') -const Path = require('path') -const crypto = require('crypto') +const fs = require('node:fs') +const Path = require('node:path') +const crypto = require('node:crypto') const { RootKeyEncryptionKey, } = require('@overleaf/object-persistor/src/PerProjectEncryptedS3Persistor') diff --git a/services/filestore/test/setup.js b/services/filestore/test/setup.js index 57a462390f..744ab9130f 100644 --- a/services/filestore/test/setup.js +++ b/services/filestore/test/setup.js @@ -21,6 +21,11 @@ SandboxedModule.configure({ requires: { '@overleaf/logger': stubs.logger, }, + sourceTransformers: { + removeNodePrefix: function (source) { + return source.replace(/require\(['"]node:/g, "require('") + }, + }, }) exports.mochaHooks = { diff --git a/services/history-v1/api/controllers/projects.js b/services/history-v1/api/controllers/projects.js index 3e00035d39..0370872348 100644 --- a/services/history-v1/api/controllers/projects.js +++ b/services/history-v1/api/controllers/projects.js @@ -1,11 +1,11 @@ 'use strict' const _ = require('lodash') -const Path = require('path') -const Stream = require('stream') +const Path = require('node:path') +const Stream = require('node:stream') const HTTPStatus = require('http-status') -const fs = require('fs') -const { promisify } = require('util') +const fs = require('node:fs') +const { promisify } = require('node:util') const config = require('config') const logger = require('@overleaf/logger') diff --git a/services/history-v1/api/controllers/stream_size_limit.js b/services/history-v1/api/controllers/stream_size_limit.js index fbb2ab8030..f3a14959f6 100644 --- a/services/history-v1/api/controllers/stream_size_limit.js +++ b/services/history-v1/api/controllers/stream_size_limit.js @@ -1,4 +1,4 @@ -const stream = require('stream') +const stream = require('node:stream') /** * Transform stream that stops passing bytes through after some threshold has diff --git a/services/history-v1/api/controllers/with_tmp_dir.js b/services/history-v1/api/controllers/with_tmp_dir.js index ab2279ce17..a9c2e9fb47 100644 --- a/services/history-v1/api/controllers/with_tmp_dir.js +++ b/services/history-v1/api/controllers/with_tmp_dir.js @@ -1,8 +1,8 @@ -const fs = require('fs') +const fs = require('node:fs') const fsExtra = require('fs-extra') const logger = require('@overleaf/logger') -const os = require('os') -const path = require('path') +const os = require('node:os') +const path = require('node:path') /** * Create a temporary directory before executing a function and cleaning up diff --git a/services/history-v1/app.js b/services/history-v1/app.js index a10d69eba6..c96a2f5ac3 100644 --- a/services/history-v1/app.js +++ b/services/history-v1/app.js @@ -6,7 +6,7 @@ require('@overleaf/metrics/initialize') const config = require('config') -const Events = require('events') +const Events = require('node:events') const BPromise = require('bluebird') const express = require('express') const helmet = require('helmet') @@ -19,7 +19,7 @@ const swaggerDoc = require('./api/swagger') const security = require('./api/app/security') const healthChecks = require('./api/controllers/health_checks') const { mongodb, loadGlobalBlobs } = require('./storage') -const path = require('path') +const path = require('node:path') Events.setMaxListeners(20) const app = express() diff --git a/services/history-v1/benchmarks/blob_store.js b/services/history-v1/benchmarks/blob_store.js index 2efb90ffb2..9efad8747f 100644 --- a/services/history-v1/benchmarks/blob_store.js +++ b/services/history-v1/benchmarks/blob_store.js @@ -1,4 +1,4 @@ -const crypto = require('crypto') +const crypto = require('node:crypto') const benny = require('benny') const { Blob } = require('overleaf-editor-core') const mongoBackend = require('../storage/lib/blob_store/mongo') diff --git a/services/history-v1/storage/lib/blob_hash.js b/services/history-v1/storage/lib/blob_hash.js index 5c2edac14f..6309637d08 100644 --- a/services/history-v1/storage/lib/blob_hash.js +++ b/services/history-v1/storage/lib/blob_hash.js @@ -2,9 +2,9 @@ 'use strict' const BPromise = require('bluebird') -const fs = BPromise.promisifyAll(require('fs')) -const crypto = require('crypto') -const { pipeline } = require('stream') +const fs = BPromise.promisifyAll(require('node:fs')) +const crypto = require('node:crypto') +const { pipeline } = require('node:stream') const assert = require('./assert') function getGitBlobHeader(byteLength) { diff --git a/services/history-v1/storage/lib/blob_store/index.js b/services/history-v1/storage/lib/blob_store/index.js index 1e9c9c6758..fc9a1ab5d1 100644 --- a/services/history-v1/storage/lib/blob_store/index.js +++ b/services/history-v1/storage/lib/blob_store/index.js @@ -1,7 +1,7 @@ 'use strict' const config = require('config') -const fs = require('fs') +const fs = require('node:fs') const isValidUtf8 = require('utf-8-validate') const { ReadableString } = require('@overleaf/stream-utils') diff --git a/services/history-v1/storage/lib/history_store.js b/services/history-v1/storage/lib/history_store.js index 0e7c11ffb5..e9d6fe1043 100644 --- a/services/history-v1/storage/lib/history_store.js +++ b/services/history-v1/storage/lib/history_store.js @@ -4,7 +4,7 @@ const BPromise = require('bluebird') const core = require('overleaf-editor-core') const config = require('config') -const path = require('path') +const path = require('node:path') const OError = require('@overleaf/o-error') const objectPersistor = require('@overleaf/object-persistor') diff --git a/services/history-v1/storage/lib/project_archive.js b/services/history-v1/storage/lib/project_archive.js index d6680ae33c..0d70fea5ea 100644 --- a/services/history-v1/storage/lib/project_archive.js +++ b/services/history-v1/storage/lib/project_archive.js @@ -8,8 +8,8 @@ const Archive = require('archiver') const BPromise = require('bluebird') -const fs = require('fs') -const { pipeline } = require('stream') +const fs = require('node:fs') +const { pipeline } = require('node:stream') const core = require('overleaf-editor-core') diff --git a/services/history-v1/storage/lib/project_key.js b/services/history-v1/storage/lib/project_key.js index e84f024e06..d4b03783aa 100644 --- a/services/history-v1/storage/lib/project_key.js +++ b/services/history-v1/storage/lib/project_key.js @@ -1,5 +1,5 @@ const _ = require('lodash') -const path = require('path') +const path = require('node:path') // // The advice in http://docs.aws.amazon.com/AmazonS3/latest/dev/ diff --git a/services/history-v1/storage/lib/streams.js b/services/history-v1/storage/lib/streams.js index 9e216c3f97..c30e2d0e09 100644 --- a/services/history-v1/storage/lib/streams.js +++ b/services/history-v1/storage/lib/streams.js @@ -6,9 +6,9 @@ 'use strict' const BPromise = require('bluebird') -const zlib = require('zlib') +const zlib = require('node:zlib') const { WritableBuffer, ReadableString } = require('@overleaf/stream-utils') -const { pipeline } = require('stream') +const { pipeline } = require('node:stream') /** * Pipe a read stream to a write stream. The promise resolves when the write diff --git a/services/history-v1/storage/lib/temp.js b/services/history-v1/storage/lib/temp.js index 719e0767a6..1aab3c1df4 100644 --- a/services/history-v1/storage/lib/temp.js +++ b/services/history-v1/storage/lib/temp.js @@ -7,7 +7,7 @@ */ const BPromise = require('bluebird') -const fs = BPromise.promisifyAll(require('fs')) +const fs = BPromise.promisifyAll(require('node:fs')) const temp = BPromise.promisifyAll(require('temp')) exports.open = function (affixes) { diff --git a/services/history-v1/storage/lib/zip_store.js b/services/history-v1/storage/lib/zip_store.js index b3cf7c2663..0741829303 100644 --- a/services/history-v1/storage/lib/zip_store.js +++ b/services/history-v1/storage/lib/zip_store.js @@ -2,8 +2,8 @@ const BPromise = require('bluebird') const config = require('config') -const fs = require('fs') -const path = require('path') +const fs = require('node:fs') +const path = require('node:path') const OError = require('@overleaf/o-error') const objectPersistor = require('@overleaf/object-persistor') diff --git a/services/history-v1/storage/scripts/recover_doc_versions.js b/services/history-v1/storage/scripts/recover_doc_versions.js index 53f9ace299..f121c60afd 100644 --- a/services/history-v1/storage/scripts/recover_doc_versions.js +++ b/services/history-v1/storage/scripts/recover_doc_versions.js @@ -1,4 +1,4 @@ -const fsPromises = require('fs/promises') +const fsPromises = require('node:fs/promises') const { ObjectId } = require('mongodb') const BPromise = require('bluebird') const logger = require('@overleaf/logger') @@ -8,7 +8,7 @@ const rclient = require('@overleaf/redis-wrapper').createClient( ) const mongodb = require('../lib/mongodb') const { chunkStore } = require('..') -const Events = require('events') +const Events = require('node:events') // Silence warning. Events.setMaxListeners(20) diff --git a/services/history-v1/storage/scripts/recover_zip.js b/services/history-v1/storage/scripts/recover_zip.js index 9f5e4adaee..91872c0fbd 100644 --- a/services/history-v1/storage/scripts/recover_zip.js +++ b/services/history-v1/storage/scripts/recover_zip.js @@ -13,14 +13,14 @@ * only 24h, to match the lifecycle rule on the zip bucket. */ -const fs = require('fs') -const os = require('os') -const path = require('path') -const util = require('util') +const fs = require('node:fs') +const os = require('node:os') +const path = require('node:path') +const util = require('node:util') // Something is registering 11 listeners, over the limit of 10, which generates // a lot of warning noise. -require('events').EventEmitter.defaultMaxListeners = 11 +require('node:events').EventEmitter.defaultMaxListeners = 11 const config = require('config') // We depend on this via object-persistor. diff --git a/services/history-v1/storage/tasks/backfill_start_version.js b/services/history-v1/storage/tasks/backfill_start_version.js index c79bcb5a79..fd6d624a70 100644 --- a/services/history-v1/storage/tasks/backfill_start_version.js +++ b/services/history-v1/storage/tasks/backfill_start_version.js @@ -1,6 +1,6 @@ const commandLineArgs = require('command-line-args') const BPromise = require('bluebird') -const timersPromises = require('timers/promises') +const timersPromises = require('node:timers/promises') const { knex, historyStore } = require('..') diff --git a/services/history-v1/storage/tasks/compress_changes.js b/services/history-v1/storage/tasks/compress_changes.js index 05f2132ad9..9ae7ade807 100644 --- a/services/history-v1/storage/tasks/compress_changes.js +++ b/services/history-v1/storage/tasks/compress_changes.js @@ -8,7 +8,7 @@ * where CSV_FILE contains a list of project ids in the first column */ -const fs = require('fs') +const fs = require('node:fs') const BPromise = require('bluebird') const { History } = require('overleaf-editor-core') const { historyStore, chunkStore } = require('..') diff --git a/services/history-v1/storage/tasks/copy_project_blobs.js b/services/history-v1/storage/tasks/copy_project_blobs.js index 630af2927b..c3511bf95c 100755 --- a/services/history-v1/storage/tasks/copy_project_blobs.js +++ b/services/history-v1/storage/tasks/copy_project_blobs.js @@ -1,11 +1,11 @@ #!/usr/bin/env node -const { promisify } = require('util') +const { promisify } = require('node:util') const BPromise = require('bluebird') const commandLineArgs = require('command-line-args') const config = require('config') -const fs = require('fs') -const readline = require('readline') +const fs = require('node:fs') +const readline = require('node:readline') const { History } = require('overleaf-editor-core') const { knex, historyStore, persistor } = require('..') const projectKey = require('../lib/project_key') diff --git a/services/history-v1/test/acceptance/js/api/end_to_end.test.js b/services/history-v1/test/acceptance/js/api/end_to_end.test.js index c93cd6a533..f3ad144335 100644 --- a/services/history-v1/test/acceptance/js/api/end_to_end.test.js +++ b/services/history-v1/test/acceptance/js/api/end_to_end.test.js @@ -4,7 +4,7 @@ const BPromise = require('bluebird') const { expect } = require('chai') const HTTPStatus = require('http-status') const fetch = require('node-fetch') -const fs = BPromise.promisifyAll(require('fs')) +const fs = BPromise.promisifyAll(require('node:fs')) const cleanup = require('../storage/support/cleanup') const fixtures = require('../storage/support/fixtures') diff --git a/services/history-v1/test/acceptance/js/api/project_blobs.test.js b/services/history-v1/test/acceptance/js/api/project_blobs.test.js index acf4a349c7..2a3eb806b1 100644 --- a/services/history-v1/test/acceptance/js/api/project_blobs.test.js +++ b/services/history-v1/test/acceptance/js/api/project_blobs.test.js @@ -1,6 +1,6 @@ const { expect } = require('chai') const config = require('config') -const fs = require('fs') +const fs = require('node:fs') const fetch = require('node-fetch') const HTTPStatus = require('http-status') diff --git a/services/history-v1/test/acceptance/js/api/project_import.test.js b/services/history-v1/test/acceptance/js/api/project_import.test.js index 3da3b5f8c2..216fb527fa 100644 --- a/services/history-v1/test/acceptance/js/api/project_import.test.js +++ b/services/history-v1/test/acceptance/js/api/project_import.test.js @@ -4,7 +4,7 @@ const BPromise = require('bluebird') const { expect } = require('chai') const HTTPStatus = require('http-status') const fetch = require('node-fetch') -const fs = BPromise.promisifyAll(require('fs')) +const fs = BPromise.promisifyAll(require('node:fs')) const cleanup = require('../storage/support/cleanup') const fixtures = require('../storage/support/fixtures') diff --git a/services/history-v1/test/acceptance/js/api/project_updates.test.js b/services/history-v1/test/acceptance/js/api/project_updates.test.js index 3a9ad2460e..a248930cba 100644 --- a/services/history-v1/test/acceptance/js/api/project_updates.test.js +++ b/services/history-v1/test/acceptance/js/api/project_updates.test.js @@ -1,6 +1,6 @@ const BPromise = require('bluebird') const { expect } = require('chai') -const fs = BPromise.promisifyAll(require('fs')) +const fs = BPromise.promisifyAll(require('node:fs')) const HTTPStatus = require('http-status') const fetch = require('node-fetch') diff --git a/services/history-v1/test/acceptance/js/api/projects.test.js b/services/history-v1/test/acceptance/js/api/projects.test.js index e533626d90..ade51e418c 100644 --- a/services/history-v1/test/acceptance/js/api/projects.test.js +++ b/services/history-v1/test/acceptance/js/api/projects.test.js @@ -1,7 +1,7 @@ 'use strict' const { expect } = require('chai') -const fs = require('fs') +const fs = require('node:fs') const HTTPStatus = require('http-status') const fetch = require('node-fetch') const sinon = require('sinon') diff --git a/services/history-v1/test/acceptance/js/api/support/test_server.js b/services/history-v1/test/acceptance/js/api/support/test_server.js index 470a60a4ce..ac6550b5ab 100644 --- a/services/history-v1/test/acceptance/js/api/support/test_server.js +++ b/services/history-v1/test/acceptance/js/api/support/test_server.js @@ -8,7 +8,7 @@ const BPromise = require('bluebird') const config = require('config') -const http = require('http') +const http = require('node:http') const jwt = require('jsonwebtoken') const Swagger = require('swagger-client') diff --git a/services/history-v1/test/acceptance/js/storage/blob_store.test.js b/services/history-v1/test/acceptance/js/storage/blob_store.test.js index 8f624881fa..4fd29ac103 100644 --- a/services/history-v1/test/acceptance/js/storage/blob_store.test.js +++ b/services/history-v1/test/acceptance/js/storage/blob_store.test.js @@ -3,11 +3,11 @@ const _ = require('lodash') const { expect } = require('chai') const config = require('config') -const fs = require('fs') -const path = require('path') -const { Readable } = require('stream') +const fs = require('node:fs') +const path = require('node:path') +const { Readable } = require('node:stream') const temp = require('temp').track() -const { promisify } = require('util') +const { promisify } = require('node:util') const cleanup = require('./support/cleanup') const testFiles = require('./support/test_files') diff --git a/services/history-v1/test/acceptance/js/storage/project_archive.test.js b/services/history-v1/test/acceptance/js/storage/project_archive.test.js index a41c9f6732..bfc77a6a96 100644 --- a/services/history-v1/test/acceptance/js/storage/project_archive.test.js +++ b/services/history-v1/test/acceptance/js/storage/project_archive.test.js @@ -3,9 +3,9 @@ const _ = require('lodash') const BPromise = require('bluebird') const { expect } = require('chai') -const fs = BPromise.promisifyAll(require('fs')) +const fs = BPromise.promisifyAll(require('node:fs')) const sinon = require('sinon') -const stream = require('stream') +const stream = require('node:stream') const temp = require('temp') const cleanup = require('./support/cleanup') diff --git a/services/history-v1/test/acceptance/js/storage/support/test_files.js b/services/history-v1/test/acceptance/js/storage/support/test_files.js index 86d9062435..c28443c4c8 100644 --- a/services/history-v1/test/acceptance/js/storage/support/test_files.js +++ b/services/history-v1/test/acceptance/js/storage/support/test_files.js @@ -1,4 +1,4 @@ -const path = require('path') +const path = require('node:path') exports.path = function (pathname) { return path.join(__dirname, '..', 'files', pathname) diff --git a/services/history-v1/test/acceptance/js/storage/zip_store.test.js b/services/history-v1/test/acceptance/js/storage/zip_store.test.js index 367fb6a946..255751a4d8 100644 --- a/services/history-v1/test/acceptance/js/storage/zip_store.test.js +++ b/services/history-v1/test/acceptance/js/storage/zip_store.test.js @@ -2,7 +2,7 @@ const BPromise = require('bluebird') const { expect } = require('chai') -const fs = BPromise.promisifyAll(require('fs')) +const fs = BPromise.promisifyAll(require('node:fs')) const temp = require('temp') const cleanup = require('./support/cleanup') diff --git a/services/notifications/test/setup.js b/services/notifications/test/setup.js index 0dbbb918c2..0560fc5451 100644 --- a/services/notifications/test/setup.js +++ b/services/notifications/test/setup.js @@ -22,4 +22,9 @@ SandboxedModule.configure({ 'mongodb-legacy': require('mongodb-legacy'), // for ObjectId comparisons }, globals: { Buffer, JSON, console, process }, + sourceTransformers: { + removeNodePrefix: function (source) { + return source.replace(/require\(['"]node:/g, "require('") + }, + }, }) diff --git a/services/notifications/test/unit/js/NotificationsControllerTest.js b/services/notifications/test/unit/js/NotificationsControllerTest.js index eefeb994f2..4c0626d0b9 100644 --- a/services/notifications/test/unit/js/NotificationsControllerTest.js +++ b/services/notifications/test/unit/js/NotificationsControllerTest.js @@ -12,7 +12,7 @@ const sinon = require('sinon') const modulePath = '../../../app/js/NotificationsController.js' const SandboxedModule = require('sandboxed-module') -const assert = require('assert') +const assert = require('node:assert') const userId = '51dc93e6fb625a261300003b' const notificationId = 'fb625a26f09d' diff --git a/services/notifications/test/unit/js/NotificationsTests.js b/services/notifications/test/unit/js/NotificationsTests.js index c5e48433ba..fb485bb7a4 100644 --- a/services/notifications/test/unit/js/NotificationsTests.js +++ b/services/notifications/test/unit/js/NotificationsTests.js @@ -14,7 +14,7 @@ const sinon = require('sinon') const { expect } = require('chai') const modulePath = '../../../app/js/Notifications.js' const SandboxedModule = require('sandboxed-module') -const assert = require('assert') +const assert = require('node:assert') const { ObjectId } = require('mongodb-legacy') const userId = '51dc93e6fb625a261300003b' diff --git a/services/project-history/app/js/ErrorRecorder.js b/services/project-history/app/js/ErrorRecorder.js index 2366394a6f..3c0570f822 100644 --- a/services/project-history/app/js/ErrorRecorder.js +++ b/services/project-history/app/js/ErrorRecorder.js @@ -1,4 +1,4 @@ -import { callbackify } from 'util' +import { callbackify } from 'node:util' import logger from '@overleaf/logger' import metrics from '@overleaf/metrics' import { db } from './mongodb.js' diff --git a/services/project-history/app/js/HashManager.js b/services/project-history/app/js/HashManager.js index f1d3b0a6bc..91e77ba389 100644 --- a/services/project-history/app/js/HashManager.js +++ b/services/project-history/app/js/HashManager.js @@ -10,11 +10,11 @@ * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ -import { promisify } from 'util' -import fs from 'fs' -import crypto from 'crypto' +import { promisify } from 'node:util' +import fs from 'node:fs' +import crypto from 'node:crypto' import OError from '@overleaf/o-error' -import { pipeline } from 'stream' +import { pipeline } from 'node:stream' export function _getBlobHashFromString(string) { const byteLength = Buffer.byteLength(string) diff --git a/services/project-history/app/js/HistoryStoreManager.js b/services/project-history/app/js/HistoryStoreManager.js index 9686840b9e..1e74912ed3 100644 --- a/services/project-history/app/js/HistoryStoreManager.js +++ b/services/project-history/app/js/HistoryStoreManager.js @@ -1,10 +1,10 @@ -import { promisify } from 'util' -import fs from 'fs' +import { promisify } from 'node:util' +import fs from 'node:fs' import request from 'request' -import stream from 'stream' +import stream from 'node:stream' import logger from '@overleaf/logger' import _ from 'lodash' -import { URL } from 'url' +import { URL } from 'node:url' import OError from '@overleaf/o-error' import Settings from '@overleaf/settings' import { diff --git a/services/project-history/app/js/HttpController.js b/services/project-history/app/js/HttpController.js index 91cb297289..aa8d1c84ce 100644 --- a/services/project-history/app/js/HttpController.js +++ b/services/project-history/app/js/HttpController.js @@ -15,7 +15,7 @@ import * as LabelsManager from './LabelsManager.js' import * as HistoryApiManager from './HistoryApiManager.js' import * as RetryManager from './RetryManager.js' import * as FlushManager from './FlushManager.js' -import { pipeline } from 'stream' +import { pipeline } from 'node:stream' const ONE_DAY_IN_SECONDS = 24 * 60 * 60 diff --git a/services/project-history/app/js/LargeFileManager.js b/services/project-history/app/js/LargeFileManager.js index b8a44f6d4d..dfdc994966 100644 --- a/services/project-history/app/js/LargeFileManager.js +++ b/services/project-history/app/js/LargeFileManager.js @@ -9,9 +9,9 @@ * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ -import fs from 'fs' -import { randomUUID } from 'crypto' -import Path from 'path' +import fs from 'node:fs' +import { randomUUID } from 'node:crypto' +import Path from 'node:path' import logger from '@overleaf/logger' import OError from '@overleaf/o-error' import metrics from '@overleaf/metrics' diff --git a/services/project-history/app/js/LocalFileWriter.js b/services/project-history/app/js/LocalFileWriter.js index 967dde3acd..3629a55d64 100644 --- a/services/project-history/app/js/LocalFileWriter.js +++ b/services/project-history/app/js/LocalFileWriter.js @@ -9,10 +9,10 @@ * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ -import fs from 'fs' -import { pipeline } from 'stream' -import { randomUUID } from 'crypto' -import path from 'path' +import fs from 'node:fs' +import { pipeline } from 'node:stream' +import { randomUUID } from 'node:crypto' +import path from 'node:path' import _ from 'lodash' import logger from '@overleaf/logger' import metrics from '@overleaf/metrics' diff --git a/services/project-history/app/js/LockManager.js b/services/project-history/app/js/LockManager.js index a48af1398a..088111b08b 100644 --- a/services/project-history/app/js/LockManager.js +++ b/services/project-history/app/js/LockManager.js @@ -7,13 +7,13 @@ * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ -import { promisify } from 'util' +import { promisify } from 'node:util' import async from 'async' import metrics from '@overleaf/metrics' import Settings from '@overleaf/settings' import redis from '@overleaf/redis-wrapper' -import os from 'os' -import crypto from 'crypto' +import os from 'node:os' +import crypto from 'node:crypto' import logger from '@overleaf/logger' import OError from '@overleaf/o-error' diff --git a/services/project-history/app/js/RetryManager.js b/services/project-history/app/js/RetryManager.js index db22a51194..4ae6ce22fc 100644 --- a/services/project-history/app/js/RetryManager.js +++ b/services/project-history/app/js/RetryManager.js @@ -1,5 +1,5 @@ import _ from 'lodash' -import { promisify, callbackify } from 'util' +import { promisify, callbackify } from 'node:util' import logger from '@overleaf/logger' import OError from '@overleaf/o-error' import * as UpdatesProcessor from './UpdatesProcessor.js' diff --git a/services/project-history/app/js/SnapshotManager.js b/services/project-history/app/js/SnapshotManager.js index 04d3de0360..4dce9673b2 100644 --- a/services/project-history/app/js/SnapshotManager.js +++ b/services/project-history/app/js/SnapshotManager.js @@ -1,8 +1,8 @@ // @ts-check -import { callbackify } from 'util' +import { callbackify } from 'node:util' import Core from 'overleaf-editor-core' -import { Readable as StringStream } from 'stream' +import { Readable as StringStream } from 'node:stream' import OError from '@overleaf/o-error' import * as HistoryStoreManager from './HistoryStoreManager.js' import * as WebApiManager from './WebApiManager.js' diff --git a/services/project-history/app/js/SyncManager.js b/services/project-history/app/js/SyncManager.js index ad4584009b..0a596be393 100644 --- a/services/project-history/app/js/SyncManager.js +++ b/services/project-history/app/js/SyncManager.js @@ -1,7 +1,7 @@ // @ts-check import _ from 'lodash' -import { callbackify, promisify } from 'util' +import { callbackify, promisify } from 'node:util' import { callbackifyMultiResult } from '@overleaf/promise-utils' import Settings from '@overleaf/settings' import logger from '@overleaf/logger' diff --git a/services/project-history/app/js/UpdatesProcessor.js b/services/project-history/app/js/UpdatesProcessor.js index 3b1be3c22d..df9ccf11ea 100644 --- a/services/project-history/app/js/UpdatesProcessor.js +++ b/services/project-history/app/js/UpdatesProcessor.js @@ -1,4 +1,4 @@ -import { promisify } from 'util' +import { promisify } from 'node:util' import logger from '@overleaf/logger' import async from 'async' import metrics from '@overleaf/metrics' diff --git a/services/project-history/app/js/WebApiManager.js b/services/project-history/app/js/WebApiManager.js index b95e7fddeb..dc1c366892 100644 --- a/services/project-history/app/js/WebApiManager.js +++ b/services/project-history/app/js/WebApiManager.js @@ -1,5 +1,5 @@ -import { callbackify } from 'util' -import { setTimeout } from 'timers/promises' +import { callbackify } from 'node:util' +import { setTimeout } from 'node:timers/promises' import logger from '@overleaf/logger' import Metrics from '@overleaf/metrics' import Settings from '@overleaf/settings' diff --git a/services/project-history/scripts/debug_translate_updates.js b/services/project-history/scripts/debug_translate_updates.js index ce75df4a7a..b3fdc31bd9 100755 --- a/services/project-history/scripts/debug_translate_updates.js +++ b/services/project-history/scripts/debug_translate_updates.js @@ -5,7 +5,7 @@ * endpoint and feeds it to the update translator to how updates are transfomed * into changes sent to v1 history. */ -import fs from 'fs' +import fs from 'node:fs' import * as UpdateTranslator from '../app/js/UpdateTranslator.js' import * as SyncManager from '../app/js/SyncManager.js' import * as HistoryStoreManager from '../app/js/HistoryStoreManager.js' diff --git a/services/project-history/test/acceptance/js/DiffTests.js b/services/project-history/test/acceptance/js/DiffTests.js index 095063cca7..b62e32d3aa 100644 --- a/services/project-history/test/acceptance/js/DiffTests.js +++ b/services/project-history/test/acceptance/js/DiffTests.js @@ -1,6 +1,6 @@ import { expect } from 'chai' import request from 'request' -import crypto from 'crypto' +import crypto from 'node:crypto' import mongodb from 'mongodb-legacy' import nock from 'nock' import * as ProjectHistoryClient from './helpers/ProjectHistoryClient.js' diff --git a/services/project-history/test/acceptance/js/DiscardingUpdatesTests.js b/services/project-history/test/acceptance/js/DiscardingUpdatesTests.js index 1fd6f1e874..c5436af974 100644 --- a/services/project-history/test/acceptance/js/DiscardingUpdatesTests.js +++ b/services/project-history/test/acceptance/js/DiscardingUpdatesTests.js @@ -14,7 +14,7 @@ import async from 'async' import sinon from 'sinon' import { expect } from 'chai' import Settings from '@overleaf/settings' -import assert from 'assert' +import assert from 'node:assert' import mongodb from 'mongodb-legacy' import nock from 'nock' import * as ProjectHistoryClient from './helpers/ProjectHistoryClient.js' diff --git a/services/project-history/test/acceptance/js/FileTreeDiffTests.js b/services/project-history/test/acceptance/js/FileTreeDiffTests.js index ae29ff9354..1b43dc1971 100644 --- a/services/project-history/test/acceptance/js/FileTreeDiffTests.js +++ b/services/project-history/test/acceptance/js/FileTreeDiffTests.js @@ -14,9 +14,9 @@ import sinon from 'sinon' import { expect } from 'chai' import Settings from '@overleaf/settings' import request from 'request' -import assert from 'assert' -import Path from 'path' -import crypto from 'crypto' +import assert from 'node:assert' +import Path from 'node:path' +import crypto from 'node:crypto' import mongodb from 'mongodb-legacy' import nock from 'nock' import * as ProjectHistoryClient from './helpers/ProjectHistoryClient.js' diff --git a/services/project-history/test/acceptance/js/FlushManagerTests.js b/services/project-history/test/acceptance/js/FlushManagerTests.js index 01082f2fbd..d11346d9a3 100644 --- a/services/project-history/test/acceptance/js/FlushManagerTests.js +++ b/services/project-history/test/acceptance/js/FlushManagerTests.js @@ -2,7 +2,7 @@ import async from 'async' import nock from 'nock' import { expect } from 'chai' import request from 'request' -import assert from 'assert' +import assert from 'node:assert' import mongodb from 'mongodb-legacy' import * as ProjectHistoryClient from './helpers/ProjectHistoryClient.js' import * as ProjectHistoryApp from './helpers/ProjectHistoryApp.js' diff --git a/services/project-history/test/acceptance/js/RetryTests.js b/services/project-history/test/acceptance/js/RetryTests.js index aea3a68324..1fa356e6f4 100644 --- a/services/project-history/test/acceptance/js/RetryTests.js +++ b/services/project-history/test/acceptance/js/RetryTests.js @@ -2,7 +2,7 @@ import async from 'async' import nock from 'nock' import { expect } from 'chai' import request from 'request' -import assert from 'assert' +import assert from 'node:assert' import mongodb from 'mongodb-legacy' import * as ProjectHistoryClient from './helpers/ProjectHistoryClient.js' import * as ProjectHistoryApp from './helpers/ProjectHistoryApp.js' diff --git a/services/project-history/test/acceptance/js/SendingUpdatesTests.js b/services/project-history/test/acceptance/js/SendingUpdatesTests.js index ee58c13665..c4e0c990e4 100644 --- a/services/project-history/test/acceptance/js/SendingUpdatesTests.js +++ b/services/project-history/test/acceptance/js/SendingUpdatesTests.js @@ -1,8 +1,8 @@ import { expect } from 'chai' import Settings from '@overleaf/settings' -import assert from 'assert' +import assert from 'node:assert' import async from 'async' -import crypto from 'crypto' +import crypto from 'node:crypto' import mongodb from 'mongodb-legacy' import nock from 'nock' import * as ProjectHistoryClient from './helpers/ProjectHistoryClient.js' diff --git a/services/project-history/test/acceptance/js/SummarisedUpdatesTests.js b/services/project-history/test/acceptance/js/SummarisedUpdatesTests.js index f1abf9f24e..5e8b57e822 100644 --- a/services/project-history/test/acceptance/js/SummarisedUpdatesTests.js +++ b/services/project-history/test/acceptance/js/SummarisedUpdatesTests.js @@ -14,7 +14,7 @@ import sinon from 'sinon' import { expect } from 'chai' import Settings from '@overleaf/settings' import request from 'request' -import assert from 'assert' +import assert from 'node:assert' import mongodb from 'mongodb-legacy' import nock from 'nock' import * as ProjectHistoryClient from './helpers/ProjectHistoryClient.js' diff --git a/services/project-history/test/acceptance/js/SyncTests.js b/services/project-history/test/acceptance/js/SyncTests.js index e284674a9d..27db3434b4 100644 --- a/services/project-history/test/acceptance/js/SyncTests.js +++ b/services/project-history/test/acceptance/js/SyncTests.js @@ -2,7 +2,7 @@ import async from 'async' import nock from 'nock' import { expect } from 'chai' import request from 'request' -import assert from 'assert' +import assert from 'node:assert' import mongodb from 'mongodb-legacy' import * as ProjectHistoryClient from './helpers/ProjectHistoryClient.js' import * as ProjectHistoryApp from './helpers/ProjectHistoryApp.js' diff --git a/services/project-history/test/unit/js/HistoryStoreManager/HistoryStoreManagerTests.js b/services/project-history/test/unit/js/HistoryStoreManager/HistoryStoreManagerTests.js index b6c79b7787..f8b560a56f 100644 --- a/services/project-history/test/unit/js/HistoryStoreManager/HistoryStoreManagerTests.js +++ b/services/project-history/test/unit/js/HistoryStoreManager/HistoryStoreManagerTests.js @@ -1,7 +1,7 @@ import sinon from 'sinon' import { expect } from 'chai' import { strict as esmock } from 'esmock' -import EventEmitter from 'events' +import EventEmitter from 'node:events' import { RequestFailedError } from '@overleaf/fetch-utils' import * as Errors from '../../../../app/js/Errors.js' diff --git a/services/real-time/app.js b/services/real-time/app.js index 2679e143f0..88250d5175 100644 --- a/services/real-time/app.js +++ b/services/real-time/app.js @@ -27,7 +27,7 @@ const DrainManager = require('./app/js/DrainManager') const HealthCheckManager = require('./app/js/HealthCheckManager') const DeploymentManager = require('./app/js/DeploymentManager') -const Path = require('path') +const Path = require('node:path') // NOTE: debug is invoked for every blob that is put on the wire const socketIoLogger = { @@ -48,7 +48,7 @@ DeploymentManager.initialise() // Set up socket.io server const app = express() -const server = require('http').createServer(app) +const server = require('node:http').createServer(app) server.keepAliveTimeout = Settings.keepAliveTimeoutMs const io = require('socket.io').listen(server, { logger: socketIoLogger, diff --git a/services/real-time/app/js/DeploymentManager.js b/services/real-time/app/js/DeploymentManager.js index d4910c4baf..58c1618676 100644 --- a/services/real-time/app/js/DeploymentManager.js +++ b/services/real-time/app/js/DeploymentManager.js @@ -1,6 +1,6 @@ const logger = require('@overleaf/logger') const settings = require('@overleaf/settings') -const fs = require('fs') +const fs = require('node:fs') // Monitor a status file (e.g. /etc/real_time_status) periodically and close the // service if the file contents don't contain the matching deployment colour. diff --git a/services/real-time/app/js/HealthCheckManager.js b/services/real-time/app/js/HealthCheckManager.js index 5ad11872e3..4ced9e04e2 100644 --- a/services/real-time/app/js/HealthCheckManager.js +++ b/services/real-time/app/js/HealthCheckManager.js @@ -1,7 +1,7 @@ const metrics = require('@overleaf/metrics') const logger = require('@overleaf/logger') -const os = require('os') +const os = require('node:os') const HOST = os.hostname() const PID = process.pid let COUNT = 0 diff --git a/services/real-time/app/js/RoomManager.js b/services/real-time/app/js/RoomManager.js index 81c8d209e1..47302d5ddb 100644 --- a/services/real-time/app/js/RoomManager.js +++ b/services/real-time/app/js/RoomManager.js @@ -1,6 +1,6 @@ const logger = require('@overleaf/logger') const metrics = require('@overleaf/metrics') -const { EventEmitter } = require('events') +const { EventEmitter } = require('node:events') const OError = require('@overleaf/o-error') const IdMap = new Map() // keep track of whether ids are from projects or docs diff --git a/services/real-time/app/js/Router.js b/services/real-time/app/js/Router.js index 8fad93542b..8aaad2a164 100644 --- a/services/real-time/app/js/Router.js +++ b/services/real-time/app/js/Router.js @@ -10,7 +10,7 @@ const base64id = require('base64id') const { UnexpectedArgumentsError } = require('./Errors') const Joi = require('joi') -const HOSTNAME = require('os').hostname() +const HOSTNAME = require('node:os').hostname() const JOI_OBJECT_ID = Joi.string() .required() diff --git a/services/real-time/app/js/SessionSockets.js b/services/real-time/app/js/SessionSockets.js index ddec2056bc..c454ccbc75 100644 --- a/services/real-time/app/js/SessionSockets.js +++ b/services/real-time/app/js/SessionSockets.js @@ -1,6 +1,6 @@ const metrics = require('@overleaf/metrics') const OError = require('@overleaf/o-error') -const { EventEmitter } = require('events') +const { EventEmitter } = require('node:events') const { MissingSessionError } = require('./Errors') module.exports = function (io, sessionStore, cookieParser, cookieName) { diff --git a/services/real-time/test/acceptance/js/helpers/FixturesManager.js b/services/real-time/test/acceptance/js/helpers/FixturesManager.js index 3fffe18d30..1db0c684c1 100644 --- a/services/real-time/test/acceptance/js/helpers/FixturesManager.js +++ b/services/real-time/test/acceptance/js/helpers/FixturesManager.js @@ -147,7 +147,7 @@ module.exports = FixturesManager = { }, getRandomId() { - return require('crypto') + return require('node:crypto') .createHash('sha1') .update(Math.random().toString()) .digest('hex') diff --git a/services/real-time/test/acceptance/libs/XMLHttpRequest.js b/services/real-time/test/acceptance/libs/XMLHttpRequest.js index a6705b2fee..3586f44963 100644 --- a/services/real-time/test/acceptance/libs/XMLHttpRequest.js +++ b/services/real-time/test/acceptance/libs/XMLHttpRequest.js @@ -11,17 +11,17 @@ * @license MIT */ -const { URL } = require('url') -const spawn = require('child_process').spawn -const fs = require('fs') +const { URL } = require('node:url') +const spawn = require('node:child_process').spawn +const fs = require('node:fs') exports.XMLHttpRequest = function () { /** * Private variables */ const self = this - const http = require('http') - const https = require('https') + const http = require('node:http') + const https = require('node:https') // Holds http.js objects let request diff --git a/services/real-time/test/setup.js b/services/real-time/test/setup.js index 1bee8e2fde..c213049d84 100644 --- a/services/real-time/test/setup.js +++ b/services/real-time/test/setup.js @@ -28,6 +28,11 @@ SandboxedModule.configure({ '@overleaf/logger': stubs.logger, }, globals: { Buffer, JSON, console, process }, + sourceTransformers: { + removeNodePrefix: function (source) { + return source.replace(/require\(['"]node:/g, "require('") + }, + }, }) // Mocha hooks diff --git a/services/real-time/test/unit/js/AuthorizationManagerTests.js b/services/real-time/test/unit/js/AuthorizationManagerTests.js index 422ce8d15d..e2d296624a 100644 --- a/services/real-time/test/unit/js/AuthorizationManagerTests.js +++ b/services/real-time/test/unit/js/AuthorizationManagerTests.js @@ -12,7 +12,7 @@ const { expect } = require('chai') const sinon = require('sinon') const SandboxedModule = require('sandboxed-module') -const path = require('path') +const path = require('node:path') const modulePath = '../../../app/js/AuthorizationManager' describe('AuthorizationManager', function () { diff --git a/services/real-time/test/unit/js/ConnectedUsersManagerTests.js b/services/real-time/test/unit/js/ConnectedUsersManagerTests.js index d876b3b4a1..9026d0bb42 100644 --- a/services/real-time/test/unit/js/ConnectedUsersManagerTests.js +++ b/services/real-time/test/unit/js/ConnectedUsersManagerTests.js @@ -11,8 +11,8 @@ */ const SandboxedModule = require('sandboxed-module') -const assert = require('assert') -const path = require('path') +const assert = require('node:assert') +const path = require('node:path') const sinon = require('sinon') const modulePath = path.join(__dirname, '../../../app/js/ConnectedUsersManager') const { expect } = require('chai') diff --git a/services/real-time/test/unit/js/DocumentUpdaterControllerTests.js b/services/real-time/test/unit/js/DocumentUpdaterControllerTests.js index 31846f65b4..dd34c62715 100644 --- a/services/real-time/test/unit/js/DocumentUpdaterControllerTests.js +++ b/services/real-time/test/unit/js/DocumentUpdaterControllerTests.js @@ -11,7 +11,7 @@ */ const SandboxedModule = require('sandboxed-module') const sinon = require('sinon') -const modulePath = require('path').join( +const modulePath = require('node:path').join( __dirname, '../../../app/js/DocumentUpdaterController' ) diff --git a/services/real-time/test/unit/js/DocumentUpdaterManagerTests.js b/services/real-time/test/unit/js/DocumentUpdaterManagerTests.js index 91f271df02..6dea5401f0 100644 --- a/services/real-time/test/unit/js/DocumentUpdaterManagerTests.js +++ b/services/real-time/test/unit/js/DocumentUpdaterManagerTests.js @@ -11,7 +11,7 @@ */ const sinon = require('sinon') const SandboxedModule = require('sandboxed-module') -const path = require('path') +const path = require('node:path') const modulePath = '../../../app/js/DocumentUpdaterManager' const _ = require('lodash') diff --git a/services/real-time/test/unit/js/DrainManagerTests.js b/services/real-time/test/unit/js/DrainManagerTests.js index 9d4a41bc0e..facdc5670d 100644 --- a/services/real-time/test/unit/js/DrainManagerTests.js +++ b/services/real-time/test/unit/js/DrainManagerTests.js @@ -11,7 +11,7 @@ */ const sinon = require('sinon') const SandboxedModule = require('sandboxed-module') -const path = require('path') +const path = require('node:path') const modulePath = path.join(__dirname, '../../../app/js/DrainManager') describe('DrainManager', function () { diff --git a/services/real-time/test/unit/js/SessionSocketsTests.js b/services/real-time/test/unit/js/SessionSocketsTests.js index e296ca00d3..c2a9ad3b7a 100644 --- a/services/real-time/test/unit/js/SessionSocketsTests.js +++ b/services/real-time/test/unit/js/SessionSocketsTests.js @@ -8,7 +8,7 @@ * DS102: Remove unnecessary code created because of implicit returns * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ -const { EventEmitter } = require('events') +const { EventEmitter } = require('node:events') const { expect } = require('chai') const SandboxedModule = require('sandboxed-module') const modulePath = '../../../app/js/SessionSockets' diff --git a/services/real-time/test/unit/js/WebsocketAddressManagerTests.js b/services/real-time/test/unit/js/WebsocketAddressManagerTests.js index 62cffcb85f..89d4598abf 100644 --- a/services/real-time/test/unit/js/WebsocketAddressManagerTests.js +++ b/services/real-time/test/unit/js/WebsocketAddressManagerTests.js @@ -1,6 +1,6 @@ const SandboxedModule = require('sandboxed-module') const { expect } = require('chai') -const modulePath = require('path').join( +const modulePath = require('node:path').join( __dirname, '../../../app/js/WebsocketAddressManager' ) diff --git a/services/real-time/test/unit/js/WebsocketLoadBalancerTests.js b/services/real-time/test/unit/js/WebsocketLoadBalancerTests.js index 85bd9a5cd9..574ab6528a 100644 --- a/services/real-time/test/unit/js/WebsocketLoadBalancerTests.js +++ b/services/real-time/test/unit/js/WebsocketLoadBalancerTests.js @@ -12,7 +12,7 @@ const SandboxedModule = require('sandboxed-module') const sinon = require('sinon') const expect = require('chai').expect -const modulePath = require('path').join( +const modulePath = require('node:path').join( __dirname, '../../../app/js/WebsocketLoadBalancer' ) diff --git a/services/spelling/test/acceptance/js/helpers/request.js b/services/spelling/test/acceptance/js/helpers/request.js index 3a16934767..5798f78bdd 100644 --- a/services/spelling/test/acceptance/js/helpers/request.js +++ b/services/spelling/test/acceptance/js/helpers/request.js @@ -1,4 +1,4 @@ -import { promisify } from 'util' +import { promisify } from 'node:util' import Request from 'request' export const PORT = 3005 diff --git a/services/spelling/test/unit/js/ASpellWorkerTests.js b/services/spelling/test/unit/js/ASpellWorkerTests.js index b10507289f..410fe3fb86 100644 --- a/services/spelling/test/unit/js/ASpellWorkerTests.js +++ b/services/spelling/test/unit/js/ASpellWorkerTests.js @@ -1,7 +1,7 @@ import sinon from 'sinon' import { expect } from 'chai' import esmock from 'esmock' -import EventEmitter from 'events' +import EventEmitter from 'node:events' describe('ASpellWorker', function () { beforeEach(async function () { diff --git a/services/web/test/unit/bootstrap.js b/services/web/test/unit/bootstrap.js index 1e636166a7..fa2a7a5b76 100644 --- a/services/web/test/unit/bootstrap.js +++ b/services/web/test/unit/bootstrap.js @@ -60,6 +60,11 @@ SandboxedModule.configure({ TextEncoder, TextDecoder, }, + sourceTransformers: { + removeNodePrefix: function (source) { + return source.replace(/require\(['"]node:/g, "require('") + }, + }, }) function getSandboxedModuleRequires() {