Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace 'require' with 'import' in bench files and update dependancies #25775

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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