Skip to content

Commit c922c6a

Browse files
authored
Replace 'require' with 'import' in bench files and update dependancies (#25775)
## Feature - [ ] Telemetry added. In case of a feature if it's used or not. ### Replace 'require' with 'import' in bench files Node.js 12 allows you to use `import`. ### Update dependancies https://github.com/jprichardson/node-fs-extra/blob/master/CHANGELOG.md#breaking-changes > Require Node.js v12+ For #25761, Node.js 12 is required. Therefore, there is no problem updating it. For benchmarking purposes, it would be reasonable to update to the latest version.
1 parent dfc5907 commit c922c6a

File tree

7 files changed

+27
-29
lines changed

7 files changed

+27
-29
lines changed

bench/capture-trace.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const http = require('http')
2-
const fs = require('fs')
1+
import { createServer } from 'http'
2+
import { writeFileSync } from 'fs'
33

44
const PORT = 9411
55
const HOST = '0.0.0.0'
@@ -53,11 +53,11 @@ const main = () => {
5353

5454
process.on('SIGINT', () => {
5555
console.log(`\nSaving to ${outFile}...`)
56-
fs.writeFileSync(outFile, JSON.stringify(traces, null, 2))
56+
writeFileSync(outFile, JSON.stringify(traces, null, 2))
5757
process.exit()
5858
})
5959

60-
const server = http.createServer(onRequest)
60+
const server = createServer(onRequest)
6161
server.listen(PORT, HOST, onReady)
6262
}
6363

bench/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"bench:recursive-copy": "node recursive-copy/run"
99
},
1010
"dependencies": {
11-
"fs-extra": "7.0.1",
12-
"recursive-copy": "2.0.10"
11+
"fs-extra": "10.0.0",
12+
"recursive-copy": "2.0.11"
1313
}
1414
}

bench/readdir/glob.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
const { join } = require('path')
2-
const { promisify } = require('util')
3-
const globMod = require('glob')
1+
import { join } from 'path'
2+
import { promisify } from 'util'
3+
import globMod from 'glob'
4+
45
const glob = promisify(globMod)
56
const resolveDataDir = join(__dirname, 'fixtures', '**/*')
67

bench/readdir/recursive-readdir.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const { join } = require('path')
2-
const { recursiveReadDir } = require('next/dist/lib/recursive-readdir')
1+
import { join } from 'path'
2+
import { recursiveReadDir } from 'next/dist/lib/recursive-readdir'
33
const resolveDataDir = join(__dirname, 'fixtures')
44

55
async function test() {

bench/recursive-copy/run.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
1-
const { join } = require('path')
2-
const fs = require('fs-extra')
3-
4-
const recursiveCopyNpm = require('recursive-copy')
5-
6-
const {
7-
recursiveCopy: recursiveCopyCustom,
8-
} = require('next/dist/lib/recursive-copy')
1+
import { join } from 'path'
2+
import { ensureDir, outputFile, remove } from 'fs-extra'
3+
import recursiveCopyNpm from 'recursive-copy'
4+
import { recursiveCopy as recursiveCopyCustom } from 'next/dist/lib/recursive-copy'
95

106
const fixturesDir = join(__dirname, 'fixtures')
117
const srcDir = join(fixturesDir, 'src')
128
const destDir = join(fixturesDir, 'dest')
139

1410
const createSrcFolder = async () => {
15-
await fs.ensureDir(srcDir)
11+
await ensureDir(srcDir)
1612

1713
const files = new Array(100)
1814
.fill(undefined)
1915
.map((x, i) =>
2016
join(srcDir, `folder${i % 5}`, `folder${i + (1 % 5)}`, `file${i}`)
2117
)
2218

23-
await Promise.all(files.map((file) => fs.outputFile(file, 'hello')))
19+
await Promise.all(files.map((file) => outputFile(file, 'hello')))
2420
}
2521

2622
async function run(fn) {
@@ -38,7 +34,7 @@ async function run(fn) {
3834

3935
for (let i = 0; i < 10; i++) {
4036
const t = await test()
41-
await fs.remove(destDir)
37+
await remove(destDir)
4238
ts.push(t)
4339
}
4440

@@ -57,7 +53,7 @@ async function main() {
5753
console.log('test recursive-copy custom implementation')
5854
await run(recursiveCopyCustom)
5955

60-
await fs.remove(fixturesDir)
56+
await remove(fixturesDir)
6157
}
6258

6359
main()

bench/recursive-delete/recursive-delete.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const { join } = require('path')
2-
const { recursiveDelete } = require('next/dist/lib/recursive-delete')
1+
import { join } from 'path'
2+
import { recursiveDelete } from 'next/dist/lib/recursive-delete'
33
const resolveDataDir = join(__dirname, `fixtures-${process.argv[2]}`)
44

55
async function test() {

bench/recursive-delete/rimraf.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
const { join } = require('path')
2-
const { promisify } = require('util')
3-
const rimrafMod = require('rimraf')
4-
const resolveDataDir = join(__dirname, `fixtures-${process.argv[2]}`, '**/*')
1+
import { join } from 'path'
2+
import { promisify } from 'util'
3+
import rimrafMod from 'rimraf'
4+
55
const rimraf = promisify(rimrafMod)
6+
const resolveDataDir = join(__dirname, `fixtures-${process.argv[2]}`, '**/*')
67

78
async function test() {
89
const time = process.hrtime()

0 commit comments

Comments
 (0)