Skip to content

Commit

Permalink
benchmark: convert to esm
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Oct 4, 2024
1 parent a5f6405 commit 3109214
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 35 deletions.
2 changes: 0 additions & 2 deletions benchmark/.npmrc

This file was deleted.

10 changes: 5 additions & 5 deletions benchmark/create-fixture.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const { writeFile: writeFile_ } = require('fs')
import { writeFile as writeFile_ } from 'fs'
const writeFile = async (path, data) =>
new Promise((res, rej) =>
writeFile_(path, data, er => (er ? rej(er) : res())),
)
const { mkdirp } = require('mkdirp')
const { resolve } = require('path')
import { mkdirp } from 'mkdirp'
import { resolve } from 'path'

const create = async (path, start, end, maxDepth, depth = 0) => {
await mkdirp(path)
Expand All @@ -19,7 +19,7 @@ const create = async (path, start, end, maxDepth, depth = 0) => {
return path
}

module.exports = async ({ start, end, depth, name }) => {
const path = resolve(__dirname, 'fixtures', name, 'test')
export default async ({ start, end, depth, name }) => {
const path = resolve(import.meta.dirname, 'fixtures', name, 'test')
return await create(path, start.charCodeAt(0), end.charCodeAt(0), depth)
}
19 changes: 6 additions & 13 deletions benchmark/index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
const { spawnSync } = require('child_process')
const { existsSync } = require('fs')
const { resolve } = require('path')
const cases = require('./rimrafs.js')
const runTest = require('./run-test.js')
const print = require('./print-results.js')
import cases from './rimrafs.js'
import runTest from './run-test.js'
import print from './print-results.js'

if (!existsSync(resolve(__dirname, 'node_modules'))) {
spawnSync('npm', ['install'], { cwd: __dirname })
}

const rimraf = require('rimraf')
import * as rimraf from '../dist/esm/index.js'
const main = async () => {
// cleanup first. since the windows impl works on all platforms,
// use that. it's only relevant if the folder exists anyway.
rimraf.sync(__dirname + '/fixtures')
rimraf.sync(import.meta.dirname + '/fixtures')
const results = {}
for (const name of Object.keys(cases)) {
results[name] = await runTest(name)
}
rimraf.sync(__dirname + '/fixtures')
rimraf.sync(import.meta.dirname + '/fixtures')
return results
}

Expand Down
6 changes: 0 additions & 6 deletions benchmark/package.json

This file was deleted.

2 changes: 1 addition & 1 deletion benchmark/print-results.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ const print = results => {
console.table(table(results))
}

module.exports = print
export default print
11 changes: 6 additions & 5 deletions benchmark/rimrafs.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// just disable the glob option, and promisify it, for apples-to-apples comp
import { promisify } from 'util'
import { createRequire } from 'module'
const oldRimraf = () => {
const { promisify } = require('util')
const oldRimraf = require('./old-rimraf')
const oldRimraf = createRequire(import.meta.filename)('./old-rimraf')
const pOldRimraf = promisify(oldRimraf)
const rimraf = path => pOldRimraf(path, { disableGlob: true })
const sync = path => oldRimraf.sync(path, { disableGlob: true })
return Object.assign(rimraf, { sync })
}

const { spawn, spawnSync } = require('child_process')
import { spawn, spawnSync } from 'child_process'
const systemRmRf = () => {
const rimraf = path =>
new Promise((res, rej) => {
Expand All @@ -31,8 +32,8 @@ const systemRmRf = () => {
return rimraf
}

const { native, posix, windows } = require('rimraf')
module.exports = {
import { native, posix, windows } from 'rimraf'
export default {
native,
posix,
windows,
Expand Down
6 changes: 3 additions & 3 deletions benchmark/run-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ const END = process.env.RIMRAF_TEST_END_CHAR || 'f'
const DEPTH = +process.env.RIMRAF_TEST_DEPTH || 5
const N = +process.env.RIMRAF_TEST_ITERATIONS || 7

const cases = require('./rimrafs.js')
import cases from './rimrafs.js'

const create = require('./create-fixture.js')
import create from './create-fixture.js'

const hrToMS = hr => Math.round(hr[0] * 1e9 + hr[1]) / 1e6

Expand Down Expand Up @@ -102,4 +102,4 @@ const runTest = async type => {
}))
}

module.exports = runTest
export default runTest

0 comments on commit 3109214

Please sign in to comment.