From c922c6a3f4d4e463cce4713d9cf8f61c13b3fac8 Mon Sep 17 00:00:00 2001 From: matamatanot <39780486+matamatanot@users.noreply.github.com> Date: Fri, 4 Jun 2021 23:30:52 +0900 Subject: [PATCH] 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. --- bench/capture-trace.js | 8 ++++---- bench/package.json | 4 ++-- bench/readdir/glob.js | 7 ++++--- bench/readdir/recursive-readdir.js | 4 ++-- bench/recursive-copy/run.js | 20 ++++++++------------ bench/recursive-delete/recursive-delete.js | 4 ++-- bench/recursive-delete/rimraf.js | 9 +++++---- 7 files changed, 27 insertions(+), 29 deletions(-) diff --git a/bench/capture-trace.js b/bench/capture-trace.js index 52ef690bff76b..d7419745c3a0e 100644 --- a/bench/capture-trace.js +++ b/bench/capture-trace.js @@ -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' @@ -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) } diff --git a/bench/package.json b/bench/package.json index eb3c593c98f8c..d311332afdefa 100644 --- a/bench/package.json +++ b/bench/package.json @@ -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" } } diff --git a/bench/readdir/glob.js b/bench/readdir/glob.js index 1c409ad384ba5..170f4fb050eb5 100644 --- a/bench/readdir/glob.js +++ b/bench/readdir/glob.js @@ -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', '**/*') diff --git a/bench/readdir/recursive-readdir.js b/bench/readdir/recursive-readdir.js index 871256707ddb6..2167f30336553 100644 --- a/bench/readdir/recursive-readdir.js +++ b/bench/readdir/recursive-readdir.js @@ -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() { diff --git a/bench/recursive-copy/run.js b/bench/recursive-copy/run.js index c4bad36c88df3..ab12258004724 100644 --- a/bench/recursive-copy/run.js +++ b/bench/recursive-copy/run.js @@ -1,18 +1,14 @@ -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) @@ -20,7 +16,7 @@ const createSrcFolder = async () => { 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) { @@ -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) } @@ -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() diff --git a/bench/recursive-delete/recursive-delete.js b/bench/recursive-delete/recursive-delete.js index 8989739c9039f..e23ed3e6f26a6 100644 --- a/bench/recursive-delete/recursive-delete.js +++ b/bench/recursive-delete/recursive-delete.js @@ -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() { diff --git a/bench/recursive-delete/rimraf.js b/bench/recursive-delete/rimraf.js index 2b5d50457a13c..827cdaae77484 100644 --- a/bench/recursive-delete/rimraf.js +++ b/bench/recursive-delete/rimraf.js @@ -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()