Skip to content

Commit 721c2e2

Browse files
committed
fs: implement glob natively
Signed-off-by: avivkeller <me@aviv.sh>
1 parent 55e4ca3 commit 721c2e2

97 files changed

Lines changed: 6016 additions & 13544 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/tools.yml‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ on:
2929
- libffi
3030
- libuv
3131
- llhttp
32-
- minimatch
3332
- nbytes
3433
- nixpkgs-unstable
3534
- nghttp2
@@ -187,14 +186,6 @@ jobs:
187186
cat temp-output
188187
tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
189188
rm temp-output
190-
- id: minimatch
191-
subsystem: deps
192-
label: dependencies
193-
run: |
194-
./tools/dep_updaters/update-minimatch.sh > temp-output
195-
cat temp-output
196-
tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
197-
rm temp-output
198189
- id: nbytes
199190
subsystem: deps
200191
label: dependencies

‎LICENSE‎

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2058,65 +2058,6 @@ The externally maintained libraries used by Node.js are:
20582058
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20592059
"""
20602060

2061-
- minimatch, located at deps/minimatch, is licensed as follows:
2062-
"""
2063-
# Blue Oak Model License
2064-
2065-
Version 1.0.0
2066-
2067-
## Purpose
2068-
2069-
This license gives everyone as much permission to work with
2070-
this software as possible, while protecting contributors
2071-
from liability.
2072-
2073-
## Acceptance
2074-
2075-
In order to receive this license, you must agree to its
2076-
rules. The rules of this license are both obligations
2077-
under that agreement and conditions to your license.
2078-
You must not do anything with this software that triggers
2079-
a rule that you cannot or will not follow.
2080-
2081-
## Copyright
2082-
2083-
Each contributor licenses you to do everything with this
2084-
software that would otherwise infringe that contributor's
2085-
copyright in it.
2086-
2087-
## Notices
2088-
2089-
You must ensure that everyone who gets a copy of
2090-
any part of this software from you, with or without
2091-
changes, also gets the text of this license or a link to
2092-
<https://blueoakcouncil.org/license/1.0.0>.
2093-
2094-
## Excuse
2095-
2096-
If anyone notifies you in writing that you have not
2097-
complied with [Notices](#notices), you can keep your
2098-
license by taking all practical steps to comply within 30
2099-
days after the notice. If you do not do so, your license
2100-
ends immediately.
2101-
2102-
## Patent
2103-
2104-
Each contributor licenses you to do everything with this
2105-
software that would otherwise infringe any patent claims
2106-
they can license or become able to license.
2107-
2108-
## Reliability
2109-
2110-
No contributor can revoke this license.
2111-
2112-
## No Liability
2113-
2114-
**_As far as the law allows, this software comes as is,
2115-
without any warranty or condition, and no contributor
2116-
will be liable to anyone for any damages related to this
2117-
software or this license, under any kind of legal claim._**
2118-
"""
2119-
21202061
- npm, located at deps/npm, is licensed as follows:
21212062
"""
21222063
The npm application

‎benchmark/fs/bench-glob-options.js‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const {
5+
glob,
6+
globSync,
7+
promises: { glob: globAsync },
8+
} = require('fs');
9+
const path = require('path');
10+
const assert = require('node:assert');
11+
12+
const benchmarkDirectory = path.resolve(__dirname, '..', '..');
13+
14+
const configs = {
15+
n: [1e3],
16+
dir: ['lib'],
17+
pattern: ['**/*.js'],
18+
mode: ['sync', 'promise', 'callback'],
19+
options: ['none', 'withFileTypes', 'exclude-pattern', 'exclude-callback'],
20+
};
21+
22+
const bench = common.createBenchmark(main, configs);
23+
24+
function buildOptions(config) {
25+
const options = { cwd: path.resolve(benchmarkDirectory, config.dir) };
26+
switch (config.options) {
27+
case 'none':
28+
break;
29+
case 'withFileTypes':
30+
options.withFileTypes = true;
31+
break;
32+
case 'exclude-pattern':
33+
options.exclude = ['**/internal/**'];
34+
break;
35+
case 'exclude-callback':
36+
// Excludes nothing: measures the per-entry callback overhead alone.
37+
options.exclude = () => false;
38+
break;
39+
default:
40+
throw new Error(`Unknown options: ${config.options}`);
41+
}
42+
return options;
43+
}
44+
45+
async function main(config) {
46+
const { pattern, mode, n } = config;
47+
const options = buildOptions(config);
48+
49+
let noDead;
50+
bench.start();
51+
52+
for (let i = 0; i < n; i++) {
53+
switch (mode) {
54+
case 'sync':
55+
noDead = globSync(pattern, options);
56+
break;
57+
case 'promise':
58+
noDead = await Array.fromAsync(globAsync(pattern, options));
59+
break;
60+
case 'callback':
61+
noDead = await new Promise((resolve, reject) => {
62+
glob(pattern, options, (err, matches) => {
63+
if (err) {
64+
reject(err);
65+
} else {
66+
resolve(matches);
67+
}
68+
});
69+
});
70+
break;
71+
default:
72+
throw new Error(`Unknown mode: ${mode}`);
73+
}
74+
}
75+
76+
bench.end(n);
77+
assert.ok(noDead.length > 0);
78+
}

‎benchmark/fs/bench-glob.js‎

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,46 +14,43 @@ const benchmarkDirectory = path.resolve(__dirname, '..', '..');
1414
const configs = {
1515
n: [1e3],
1616
dir: ['lib'],
17-
pattern: ['**/*', '*.js', '**/**.js'],
17+
pattern: ['**/*', '*.js', '**/*.js', '**/*.{js,json}'],
1818
mode: ['sync', 'promise', 'callback'],
19-
recursive: ['true', 'false'],
2019
};
2120

2221
const bench = common.createBenchmark(main, configs);
2322

2423
async function main(config) {
25-
const fullPath = path.resolve(benchmarkDirectory, config.dir);
26-
const { pattern, recursive, mode } = config;
27-
const options = { cwd: fullPath, recursive };
28-
const callback = (resolve, reject) => {
29-
glob(pattern, options, (err, matches) => {
30-
if (err) {
31-
reject(err);
32-
} else {
33-
resolve(matches);
34-
}
35-
});
36-
};
24+
const { pattern, mode, n } = config;
25+
const options = { cwd: path.resolve(benchmarkDirectory, config.dir) };
3726

3827
let noDead;
3928
bench.start();
4029

41-
for (let i = 0; i < config.n; i++) {
30+
for (let i = 0; i < n; i++) {
4231
switch (mode) {
4332
case 'sync':
4433
noDead = globSync(pattern, options);
4534
break;
4635
case 'promise':
47-
noDead = await globAsync(pattern, options);
36+
noDead = await Array.fromAsync(globAsync(pattern, options));
4837
break;
4938
case 'callback':
50-
noDead = await new Promise(callback);
39+
noDead = await new Promise((resolve, reject) => {
40+
glob(pattern, options, (err, matches) => {
41+
if (err) {
42+
reject(err);
43+
} else {
44+
resolve(matches);
45+
}
46+
});
47+
});
5148
break;
5249
default:
5350
throw new Error(`Unknown mode: ${mode}`);
5451
}
5552
}
5653

57-
bench.end(config.n);
58-
assert.ok(noDead);
54+
bench.end(n);
55+
assert.ok(noDead.length > 0);
5956
}

‎benchmark/path/matchesGlob-posix.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ const bench = common.createBenchmark(main, {
1010
'src/foo/bar/biz/baz/index.test.ts',
1111
],
1212
pattern: [
13+
'src/index.ts',
14+
'**/*.ts',
15+
'**/*.{ts,js}',
1316
'src/**/baz/*.test.ts',
1417
'src/**/baz/*.ts',
18+
'src/**/index.@(test|spec).ts',
1519
'test/**/*.ts',
1620
],
1721
n: [1e5],
@@ -24,5 +28,5 @@ function main({ path, pattern, n }) {
2428
a = posix.matchesGlob(path, pattern);
2529
}
2630
bench.end(n);
27-
assert(a + 'a');
31+
assert.strictEqual(typeof a, 'boolean');
2832
}

‎benchmark/path/matchesGlob-win32.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ const bench = common.createBenchmark(main, {
1111
'src\\foo\\bar\\biz\\baz\\index.test.ts',
1212
],
1313
pattern: [
14+
'src/index.ts',
15+
'**/*.ts',
16+
'**/*.{ts,js}',
1417
'src/**/baz/*.test.ts',
1518
'src/**/baz/*.ts',
19+
'src/**/index.@(test|spec).ts',
1620
'test/**/*.ts',
1721
],
1822
n: [1e5],
@@ -25,5 +29,5 @@ function main({ path, pattern, n }) {
2529
a = win32.matchesGlob(path, pattern);
2630
}
2731
bench.end(n);
28-
assert(a + 'a');
32+
assert.strictEqual(typeof a, 'boolean');
2933
}

‎deps/minimatch/LICENSE.md‎

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)