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

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