Skip to content

Commit

Permalink
Replace 'require' with 'import' in bench files and update dependancies (
Browse files Browse the repository at this point in the history
#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.
  • Loading branch information
matamatanot authored Jun 4, 2021
1 parent dfc5907 commit c922c6a
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 29 deletions.
8 changes: 4 additions & 4 deletions bench/capture-trace.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const http = require('http')
const fs = require('fs')
import { createServer } from 'http'
import { writeFileSync } from 'fs'

const PORT = 9411
const HOST = '0.0.0.0'
Expand Down Expand Up @@ -53,11 +53,11 @@ const main = () => {

process.on('SIGINT', () => {
console.log(`\nSaving to ${outFile}...`)
fs.writeFileSync(outFile, JSON.stringify(traces, null, 2))
writeFileSync(outFile, JSON.stringify(traces, null, 2))
process.exit()
})

const server = http.createServer(onRequest)
const server = createServer(onRequest)
server.listen(PORT, HOST, onReady)
}

Expand Down
4 changes: 2 additions & 2 deletions bench/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"bench:recursive-copy": "node recursive-copy/run"
},
"dependencies": {
"fs-extra": "7.0.1",
"recursive-copy": "2.0.10"
"fs-extra": "10.0.0",
"recursive-copy": "2.0.11"
}
}
7 changes: 4 additions & 3 deletions bench/readdir/glob.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { join } = require('path')
const { promisify } = require('util')
const globMod = require('glob')
import { join } from 'path'
import { promisify } from 'util'
import globMod from 'glob'

const glob = promisify(globMod)
const resolveDataDir = join(__dirname, 'fixtures', '**/*')

Expand Down
4 changes: 2 additions & 2 deletions bench/readdir/recursive-readdir.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { join } = require('path')
const { recursiveReadDir } = require('next/dist/lib/recursive-readdir')
import { join } from 'path'
import { recursiveReadDir } from 'next/dist/lib/recursive-readdir'
const resolveDataDir = join(__dirname, 'fixtures')

async function test() {
Expand Down
20 changes: 8 additions & 12 deletions bench/recursive-copy/run.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
const { join } = require('path')
const fs = require('fs-extra')

const recursiveCopyNpm = require('recursive-copy')

const {
recursiveCopy: recursiveCopyCustom,
} = require('next/dist/lib/recursive-copy')
import { join } from 'path'
import { ensureDir, outputFile, remove } from 'fs-extra'
import recursiveCopyNpm from 'recursive-copy'
import { recursiveCopy as recursiveCopyCustom } from 'next/dist/lib/recursive-copy'

const fixturesDir = join(__dirname, 'fixtures')
const srcDir = join(fixturesDir, 'src')
const destDir = join(fixturesDir, 'dest')

const createSrcFolder = async () => {
await fs.ensureDir(srcDir)
await ensureDir(srcDir)

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

await Promise.all(files.map((file) => fs.outputFile(file, 'hello')))
await Promise.all(files.map((file) => outputFile(file, 'hello')))
}

async function run(fn) {
Expand All @@ -38,7 +34,7 @@ async function run(fn) {

for (let i = 0; i < 10; i++) {
const t = await test()
await fs.remove(destDir)
await remove(destDir)
ts.push(t)
}

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

await fs.remove(fixturesDir)
await remove(fixturesDir)
}

main()
4 changes: 2 additions & 2 deletions bench/recursive-delete/recursive-delete.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { join } = require('path')
const { recursiveDelete } = require('next/dist/lib/recursive-delete')
import { join } from 'path'
import { recursiveDelete } from 'next/dist/lib/recursive-delete'
const resolveDataDir = join(__dirname, `fixtures-${process.argv[2]}`)

async function test() {
Expand Down
9 changes: 5 additions & 4 deletions bench/recursive-delete/rimraf.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const { join } = require('path')
const { promisify } = require('util')
const rimrafMod = require('rimraf')
const resolveDataDir = join(__dirname, `fixtures-${process.argv[2]}`, '**/*')
import { join } from 'path'
import { promisify } from 'util'
import rimrafMod from 'rimraf'

const rimraf = promisify(rimrafMod)
const resolveDataDir = join(__dirname, `fixtures-${process.argv[2]}`, '**/*')

async function test() {
const time = process.hrtime()
Expand Down

0 comments on commit c922c6a

Please sign in to comment.