-
-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require Node.js 12.20 and move to ESM (#181)
- Loading branch information
1 parent
94e192c
commit 5c32b4a
Showing
11 changed files
with
347 additions
and
334 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +1,100 @@ | ||
'use strict'; | ||
/* global after, before, bench, suite */ | ||
const fs = require('fs'); | ||
const rimraf = require('rimraf'); | ||
const globbyMainBranch = require('globby'); | ||
const gs = require('glob-stream'); | ||
const fastGlob = require('fast-glob'); | ||
const globby = require('.'); | ||
import fs from 'node:fs'; | ||
import path from 'node:path'; | ||
import {fileURLToPath} from 'node:url'; | ||
import rimraf from 'rimraf'; | ||
import globbyMainBranch from 'globby'; | ||
import gs from 'glob-stream'; | ||
import fastGlob from 'fast-glob'; | ||
import {globby, globbySync} from './index.js'; | ||
|
||
const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
const BENCH_DIR = 'bench'; | ||
|
||
const runners = [{ | ||
name: 'globby async (working directory)', | ||
run: async (patterns, callback) => { | ||
await globby(patterns); | ||
callback(); | ||
} | ||
}, | ||
}, { | ||
name: 'globby async (upstream/main)', | ||
run: async (patterns, callback) => { | ||
await globbyMainBranch(patterns); | ||
callback(); | ||
} | ||
}, | ||
}, { | ||
name: 'globby sync (working directory)', | ||
run: patterns => { | ||
globby.sync(patterns); | ||
} | ||
globbySync(patterns); | ||
}, | ||
}, { | ||
name: 'globby sync (upstream/main)', | ||
run: patterns => { | ||
globbyMainBranch.sync(patterns); | ||
} | ||
}, | ||
}, { | ||
name: 'glob-stream', | ||
run: (patterns, cb) => { | ||
gs(patterns).on('data', () => {}).on('end', cb); | ||
} | ||
}, | ||
}, { | ||
name: 'fast-glob async', | ||
run: async (patterns, callback) => { | ||
await fastGlob(patterns); | ||
callback(); | ||
} | ||
}, | ||
}, { | ||
name: 'fast-glob sync', | ||
run: patterns => { | ||
fastGlob.sync(patterns); | ||
} | ||
}, | ||
}]; | ||
const benchs = [{ | ||
name: 'negative globs (some files inside dir)', | ||
patterns: [ | ||
'a/*', | ||
'!a/c*' | ||
] | ||
'!a/c*', | ||
], | ||
}, { | ||
name: 'negative globs (whole dir)', | ||
patterns: [ | ||
'a/*', | ||
'!a/**' | ||
] | ||
'!a/**', | ||
], | ||
}, { | ||
name: 'multiple positive globs', | ||
patterns: [ | ||
'a/*', | ||
'b/*' | ||
] | ||
'b/*', | ||
], | ||
}]; | ||
|
||
before(() => { | ||
process.chdir(__dirname); | ||
rimraf.sync(BENCH_DIR); | ||
fs.mkdirSync(BENCH_DIR); | ||
process.chdir(BENCH_DIR); | ||
['a', 'b'] | ||
.map(directory => `${directory}/`) | ||
.forEach(directory => { | ||
fs.mkdirSync(directory); | ||
for (let i = 0; i < 500; i++) { | ||
fs.writeFileSync(directory + (i < 100 ? 'c' : 'd') + i, ''); | ||
} | ||
}); | ||
const directories = ['a', 'b'] | ||
.map(directory => `${directory}/`); | ||
|
||
for (const directory of directories) { | ||
fs.mkdirSync(directory); | ||
for (let i = 0; i < 500; i++) { | ||
fs.writeFileSync(directory + (i < 100 ? 'c' : 'd') + i, ''); | ||
} | ||
} | ||
}); | ||
|
||
after(() => { | ||
process.chdir(__dirname); | ||
rimraf.sync(BENCH_DIR); | ||
}); | ||
|
||
benchs.forEach(benchmark => { | ||
for (const benchmark of benchs) { | ||
suite(benchmark.name, () => { | ||
runners.forEach(runner => bench(runner.name, runner.run.bind(null, benchmark.patterns))); | ||
for (const runner of runners) { | ||
bench(runner.name, runner.run.bind(null, benchmark.patterns)); | ||
} | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.