GeezerVison is showing github.com — fs: implement glob natively · nodejs/node@a8f2bf0
File treeExpand file treeCollapse file tree Open diff view settings Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .github/workflows/tools.yml -9Lines changed: 0 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 29 | 29 | - libffi | 30 | 30 | - libuv | 31 | 31 | - llhttp | 32 | | - - minimatch | 33 | 32 | - nbytes | 34 | 33 | - nixpkgs-unstable | 35 | 34 | - nghttp2 | @@ -187,14 +186,6 @@ jobs: | 187 | 186 | cat temp-output | 188 | 187 | tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true | 189 | 188 | 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 | 198 | 189 | - id: nbytes | 199 | 190 | subsystem: deps | 200 | 191 | label: dependencies | |
Collapse file Copy file name to clipboardExpand all lines: LICENSE -59Lines changed: 0 additions & 59 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2058,65 +2058,6 @@ The externally maintained libraries used by Node.js are: | 2058 | 2058 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | 2059 | 2059 | """ | 2060 | 2060 |
| 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 | | - | 2120 | 2061 | - npm, located at deps/npm, is licensed as follows: | 2121 | 2062 | """ | 2122 | 2063 | The npm application | |
Collapse file Copy file name to clipboard +78Lines changed: 78 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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 | +} |
Collapse file Copy file name to clipboardExpand all lines: benchmark/fs/bench-glob.js +16-22Lines changed: 16 additions & 22 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -14,53 +14,47 @@ const benchmarkDirectory = path.resolve(__dirname, '..', '..'); | 14 | 14 | const configs = { | 15 | 15 | n: [1e3], | 16 | 16 | dir: ['lib'], | 17 | | - pattern: ['**/*', '*.js', '**/**.js'], | | 17 | + pattern: ['**/*', '*.js', '**/*.js', '**/*.{js,json}'], | 18 | 18 | mode: ['sync', 'promise', 'callback'], | 19 | 19 | maxDepth: ['default', '2'], | 20 | | - recursive: ['true', 'false'], | 21 | 20 | }; | 22 | 21 |
| 23 | 22 | const bench = common.createBenchmark(main, configs); | 24 | 23 |
| 25 | 24 | async function main(config) { | 26 | | - const fullPath = path.resolve(benchmarkDirectory, config.dir); | 27 | | - const { pattern, recursive, mode, maxDepth } = config; | 28 | | - const options = { cwd: fullPath, recursive }; | | 25 | + const { pattern, mode, n, maxDepth } = config; | | 26 | + const options = { cwd: path.resolve(benchmarkDirectory, config.dir) }; | 29 | 27 | if (maxDepth !== 'default') { | 30 | 28 | options.maxDepth = Number(maxDepth); | 31 | 29 | } | 32 | | - const callback = (resolve, reject) => { | 33 | | - glob(pattern, options, (err, matches) => { | 34 | | - if (err) { | 35 | | - reject(err); | 36 | | - } else { | 37 | | - resolve(matches); | 38 | | - } | 39 | | - }); | 40 | | - }; | 41 | 30 |
| 42 | 31 | let noDead; | 43 | 32 | bench.start(); | 44 | 33 |
| 45 | | - for (let i = 0; i < config.n; i++) { | | 34 | + for (let i = 0; i < n; i++) { | 46 | 35 | switch (mode) { | 47 | 36 | case 'sync': | 48 | 37 | noDead = globSync(pattern, options); | 49 | 38 | break; | 50 | 39 | case 'promise': | 51 | | - noDead = []; | 52 | | - for await (const match of globAsync(pattern, options)) { | 53 | | - noDead.push(match); | 54 | | - } | | 40 | + noDead = await Array.fromAsync(globAsync(pattern, options)); | 55 | 41 | break; | 56 | 42 | case 'callback': | 57 | | - noDead = await new Promise(callback); | | 43 | + noDead = await new Promise((resolve, reject) => { | | 44 | + glob(pattern, options, (err, matches) => { | | 45 | + if (err) { | | 46 | + reject(err); | | 47 | + } else { | | 48 | + resolve(matches); | | 49 | + } | | 50 | + }); | | 51 | + }); | 58 | 52 | break; | 59 | 53 | default: | 60 | 54 | throw new Error(`Unknown mode: ${mode}`); | 61 | 55 | } | 62 | 56 | } | 63 | 57 |
| 64 | | - bench.end(config.n); | 65 | | - assert.ok(noDead); | | 58 | + bench.end(n); | | 59 | + assert.ok(noDead.length > 0); | 66 | 60 | } |
Collapse file Copy file name to clipboardExpand all lines: benchmark/path/matchesGlob-posix.js +5-1Lines changed: 5 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -10,8 +10,12 @@ const bench = common.createBenchmark(main, { | 10 | 10 | 'src/foo/bar/biz/baz/index.test.ts', | 11 | 11 | ], | 12 | 12 | pattern: [ | | 13 | + 'src/index.ts', | | 14 | + '**/*.ts', | | 15 | + '**/*.{ts,js}', | 13 | 16 | 'src/**/baz/*.test.ts', | 14 | 17 | 'src/**/baz/*.ts', | | 18 | + 'src/**/index.@(test|spec).ts', | 15 | 19 | 'test/**/*.ts', | 16 | 20 | ], | 17 | 21 | n: [1e5], | @@ -24,5 +28,5 @@ function main({ path, pattern, n }) { | 24 | 28 | a = posix.matchesGlob(path, pattern); | 25 | 29 | } | 26 | 30 | bench.end(n); | 27 | | - assert(a + 'a'); | | 31 | + assert.strictEqual(typeof a, 'boolean'); | 28 | 32 | } |
Collapse file Copy file name to clipboardExpand all lines: benchmark/path/matchesGlob-win32.js +5-1Lines changed: 5 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -11,8 +11,12 @@ const bench = common.createBenchmark(main, { | 11 | 11 | 'src\\foo\\bar\\biz\\baz\\index.test.ts', | 12 | 12 | ], | 13 | 13 | pattern: [ | | 14 | + 'src/index.ts', | | 15 | + '**/*.ts', | | 16 | + '**/*.{ts,js}', | 14 | 17 | 'src/**/baz/*.test.ts', | 15 | 18 | 'src/**/baz/*.ts', | | 19 | + 'src/**/index.@(test|spec).ts', | 16 | 20 | 'test/**/*.ts', | 17 | 21 | ], | 18 | 22 | n: [1e5], | @@ -25,5 +29,5 @@ function main({ path, pattern, n }) { | 25 | 29 | a = win32.matchesGlob(path, pattern); | 26 | 30 | } | 27 | 31 | bench.end(n); | 28 | | - assert(a + 'a'); | | 32 | + assert.strictEqual(typeof a, 'boolean'); | 29 | 33 | } |
Collapse file Copy file name to clipboardExpand all lines: deps/minimatch/LICENSE.md -55Lines changed: 0 additions & 55 deletions
|