Add prefer-node-protocol ESLint rule (#21532)

* Add `unicorn/prefer-node-protocol`

* Fix `unicorn/prefer-node-protocol` ESLint errors

* Run `npm run format:fix`

* Add sandboxed-module sourceTransformers in mocha setups

Fix `no such file or directory, open 'node:fs'` in `sandboxed-module`

* Remove `node:` in the SandboxedModule requires

* Fix new linting errors with `node:`

GitOrigin-RevId: 68f6e31e2191fcff4cb8058dd0a6914c14f59926
This commit is contained in:
Antoine Clausse 2024-11-08 11:21:56 +01:00 committed by Copybot
parent 4563273396
commit 7f48c67512
217 changed files with 461 additions and 381 deletions

View file

@ -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'

View file

@ -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('")
},
},
})

View file

@ -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'

View file

@ -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) => {

View file

@ -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() {

View file

@ -1,5 +1,5 @@
const { fetchString } = require('@overleaf/fetch-utils')
const fs = require('fs')
const fs = require('node:fs')
class LogLevelChecker {
constructor(logger, defaultLevel) {

View file

@ -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')

View file

@ -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('")
},
},
})

View file

@ -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')

View file

@ -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')

View file

@ -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')

View file

@ -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: '' })

View file

@ -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

View file

@ -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()

View file

@ -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('../..')

View file

@ -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')

View file

@ -1,4 +1,4 @@
const Path = require('path')
const Path = require('node:path')
const SandboxedModule = require('sandboxed-module')
const sinon = require('sinon')

View file

@ -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) {

View file

@ -1,5 +1,5 @@
const { expect } = require('chai')
const { promisify } = require('util')
const { promisify } = require('node:util')
const OError = require('..')

View file

@ -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

View file

@ -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')

View file

@ -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')

View file

@ -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,

View file

@ -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)

View file

@ -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')

View file

@ -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')
/**

View file

@ -25,4 +25,9 @@ SandboxedModule.configure({
},
},
globals: { Buffer, Math, console, process, URL },
sourceTransformers: {
removeNodePrefix: function (source) {
return source.replace(/require\(['"]node:/g, "require('")
},
},
})

View file

@ -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')

View file

@ -1,4 +1,4 @@
const { EventEmitter } = require('events')
const { EventEmitter } = require('node:events')
const sinon = require('sinon')
const chai = require('chai')
const { expect } = chai

View file

@ -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'

View file

@ -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'

View file

@ -1,4 +1,4 @@
const { promisify, callbackify } = require('util')
const { promisify, callbackify } = require('node:util')
const pLimit = require('p-limit')
module.exports = {

View file

@ -0,0 +1,3 @@
{
"require": "test/setup.js"
}

View file

@ -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

View file

@ -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()

View file

@ -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')

View file

@ -0,0 +1,9 @@
const SandboxedModule = require('sandboxed-module')
SandboxedModule.configure({
sourceTransformers: {
removeNodePrefix: function (source) {
return source.replace(/require\(['"]node:/g, "require('")
},
},
})

View file

@ -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')

View file

@ -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()

View file

@ -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.

3
package-lock.json generated
View file

@ -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",

View file

@ -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"
},

View file

@ -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

View file

@ -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))

View file

@ -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'

View file

@ -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'

View file

@ -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')

View file

@ -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')

View file

@ -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,

View file

@ -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')

View file

@ -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,

View file

@ -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

View file

@ -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) {

View file

@ -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)

View file

@ -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')

View file

@ -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')

View file

@ -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) {

View file

@ -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')

View file

@ -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()

View file

@ -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')

View file

@ -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')

View file

@ -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 = {

View file

@ -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')

View file

@ -1,4 +1,4 @@
const Path = require('path')
const Path = require('node:path')
/**
* Parse output from the `synctex view` command

View file

@ -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')

View file

@ -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()

View file

@ -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

View file

@ -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

View file

@ -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(

View file

@ -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]

View file

@ -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,

View file

@ -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) {

View file

@ -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')

View file

@ -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 () {

View file

@ -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 = {

View file

@ -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

View file

@ -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

View file

@ -21,4 +21,9 @@ SandboxedModule.configure({
},
},
globals: { Buffer, console, process, URL },
sourceTransformers: {
removeNodePrefix: function (source) {
return source.replace(/require\(['"]node:/g, "require('")
},
},
})

View file

@ -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'
)

View file

@ -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'
)

View file

@ -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'

View file

@ -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'
)

View file

@ -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'
)

View file

@ -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 () {

View file

@ -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')

View file

@ -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'
)

View file

@ -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'
)

View file

@ -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,
},
},

View file

@ -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,

View file

@ -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'
)

View file

@ -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 () {

View file

@ -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'
)

View file

@ -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'
)

View file

@ -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 () {

View file

@ -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 () {

View file

@ -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,

View file

@ -1,4 +1,4 @@
const Path = require('path')
const Path = require('node:path')
const SandboxedModule = require('sandboxed-module')
const { expect } = require('chai')

View file

@ -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'
)

View file

@ -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 () {

View file

@ -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')

Some files were not shown because too many files have changed in this diff Show more