Skip to content

Commit 0c18faf

Browse files
committed
Use fast-glob instead of tinyglobby, add streams helper parallelMap, and rename globLicenses to globStreamLicenses
1 parent d669d85 commit 0c18faf

File tree

11 files changed

+235
-25
lines changed

11 files changed

+235
-25
lines changed

package-lock.json

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

registry/lib/globs.d.ts

Lines changed: 142 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,144 @@
1-
import { GlobOptions as TinyGlobOptions } from 'tinyglobby'
2-
1+
/// <reference types="node" />
32
import { Remap } from './objects'
43

4+
declare type Pattern = string
5+
declare type FastGlobOptions = {
6+
/**
7+
* Return the absolute path for entries.
8+
*
9+
* @default false
10+
*/
11+
absolute?: boolean
12+
/**
13+
* If set to `true`, then patterns without slashes will be matched against
14+
* the basename of the path if it contains slashes.
15+
*
16+
* @default false
17+
*/
18+
baseNameMatch?: boolean
19+
/**
20+
* Enables Bash-like brace expansion.
21+
*
22+
* @default true
23+
*/
24+
braceExpansion?: boolean
25+
/**
26+
* Enables a case-sensitive mode for matching files.
27+
*
28+
* @default true
29+
*/
30+
caseSensitiveMatch?: boolean
31+
/**
32+
* Specifies the maximum number of concurrent requests from a reader to read
33+
* directories.
34+
*
35+
* @default os.cpus().length
36+
*/
37+
concurrency?: number
38+
/**
39+
* The current working directory in which to search.
40+
*
41+
* @default process.cwd()
42+
*/
43+
cwd?: string
44+
/**
45+
* Specifies the maximum depth of a read directory relative to the start
46+
* directory.
47+
*
48+
* @default Infinity
49+
*/
50+
deep?: number
51+
/**
52+
* Allow patterns to match entries that begin with a period (`.`).
53+
*
54+
* @default false
55+
*/
56+
dot?: boolean
57+
/**
58+
* Enables Bash-like `extglob` functionality.
59+
*
60+
* @default true
61+
*/
62+
extglob?: boolean
63+
/**
64+
* Indicates whether to traverse descendants of symbolic link directories.
65+
*
66+
* @default true
67+
*/
68+
followSymbolicLinks?: boolean
69+
/**
70+
* Custom implementation of methods for working with the file system.
71+
*
72+
* @default fs.*
73+
*/
74+
fs?: any
75+
/**
76+
* Enables recursively repeats a pattern containing `**`.
77+
* If `false`, `**` behaves exactly like `*`.
78+
*
79+
* @default true
80+
*/
81+
globstar?: boolean
82+
/**
83+
* An array of glob patterns to exclude matches.
84+
* This is an alternative way to use negative patterns.
85+
*
86+
* @default []
87+
*/
88+
ignore?: Pattern[]
89+
/**
90+
* Mark the directory path with the final slash.
91+
*
92+
* @default false
93+
*/
94+
markDirectories?: boolean
95+
/**
96+
* Returns objects (instead of strings) describing entries.
97+
*
98+
* @default false
99+
*/
100+
objectMode?: boolean
101+
/**
102+
* Return only directories.
103+
*
104+
* @default false
105+
*/
106+
onlyDirectories?: boolean
107+
/**
108+
* Return only files.
109+
*
110+
* @default true
111+
*/
112+
onlyFiles?: boolean
113+
/**
114+
* Enables an object mode (`objectMode`) with an additional `stats` field.
115+
*
116+
* @default false
117+
*/
118+
stats?: boolean
119+
/**
120+
* By default this package suppress only `ENOENT` errors.
121+
* Set to `true` to suppress any error.
122+
*
123+
* @default false
124+
*/
125+
suppressErrors?: boolean
126+
/**
127+
* Throw an error when symbolic link is broken if `true` or safely
128+
* return `lstat` call if `false`.
129+
*
130+
* @default false
131+
*/
132+
throwErrorOnBrokenSymbolicLink?: boolean
133+
/**
134+
* Ensures that the returned entries are unique.
135+
*
136+
* @default true
137+
*/
138+
unique?: boolean
139+
}
5140
declare type GlobOptions = Remap<
6-
TinyGlobOptions & {
141+
FastGlobOptions & {
7142
ignoreOriginals?: boolean | undefined
8143
recursive?: boolean | undefined
9144
}
@@ -13,7 +148,10 @@ declare const Globs: {
13148
glob: string | string[] | readonly string[],
14149
options?: object | undefined
15150
) => (path: string) => boolean
16-
globLicenses(dirname: string, options?: GlobOptions): Promise<string[]>
151+
globStreamLicenses(
152+
dirname: string,
153+
options?: GlobOptions
154+
): Promise<NodeJS.ReadableStream>
17155
}
18156
declare namespace Globs {
19157
export { GlobOptions }

registry/lib/globs.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ function getPicomatch() {
1010
return _picomatch
1111
}
1212

13-
let _tinyGlobby
13+
let _fastGlob
1414
/*@__NO_SIDE_EFFECTS__*/
15-
function getTinyGlobby() {
16-
if (_tinyGlobby === undefined) {
17-
_tinyGlobby = /*@__PURE__*/ require('../external/tinyglobby')
15+
function getFastGlob() {
16+
if (_fastGlob === undefined) {
17+
_fastGlob = /*@__PURE__*/ require('../external/fast-glob')
1818
}
19-
return _tinyGlobby
19+
return _fastGlob
2020
}
2121

2222
/*@__NO_SIDE_EFFECTS__*/
23-
async function globLicenses(dirname, options) {
23+
async function globStreamLicenses(dirname, options) {
2424
const {
2525
ignore: ignoreOpt,
2626
ignoreOriginals,
@@ -36,8 +36,8 @@ async function globLicenses(dirname, options) {
3636
/*@__PURE__*/ require('./constants/license-original-glob-recursive')
3737
)
3838
}
39-
const tinyGlobby = getTinyGlobby()
40-
return await tinyGlobby.glob(
39+
const fastGlob = getFastGlob()
40+
return fastGlob.globStream(
4141
[
4242
recursive
4343
? /*@__PURE__*/ require('./constants/license-glob-recursive')
@@ -76,5 +76,5 @@ function getGlobMatcher(glob, options) {
7676

7777
module.exports = {
7878
getGlobMatcher,
79-
globLicenses
79+
globStreamLicenses
8080
}

registry/lib/streams.d.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
declare type AnyIterable<T> = Iterable<T> | AsyncIterable<T>
2+
declare const Streams: {
3+
parallelMap<T, R>(
4+
concurrency: number
5+
): {
6+
(
7+
func: (data: T) => R | Promise<R>,
8+
iterable: AnyIterable<T>
9+
): AsyncIterableIterator<R>
10+
(
11+
func: (data: T) => R | Promise<R>
12+
): (iterable: AnyIterable<T>) => AsyncIterableIterator<R>
13+
}
14+
parallelMap<T, R>(
15+
concurrency: number,
16+
func: (data: T) => R | Promise<R>
17+
): (iterable: AnyIterable<T>) => AsyncIterableIterator<R>
18+
parallelMap<T, R>(
19+
concurrency: number,
20+
func: (data: T) => R | Promise<R>,
21+
iterable: AnyIterable<T>
22+
): AsyncIterableIterator<R>
23+
}
24+
declare namespace Promises {
25+
export { AnyIterable }
26+
}
27+
export = Streams

registry/lib/streams.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict'
2+
3+
let _streamingIterables
4+
/*@__NO_SIDE_EFFECTS__*/
5+
function getStreamingIterables() {
6+
if (_streamingIterables === undefined) {
7+
_streamingIterables = /*@__PURE__*/ require('../external/streaming-iterables')
8+
}
9+
return _streamingIterables
10+
}
11+
12+
/*@__NO_SIDE_EFFECTS__*/
13+
function parallelMap(concurrency, func) {
14+
const streamingIterables = getStreamingIterables()
15+
return streamingIterables.parallelMap(concurrency, func)
16+
}
17+
18+
module.exports = {
19+
parallelMap
20+
}

registry/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,10 @@
581581
"types": "./lib/spinner.d.ts",
582582
"default": "./lib/spinner.js"
583583
},
584+
"./lib/streams": {
585+
"types": "./lib/streams.d.ts",
586+
"default": "./lib/streams.js"
587+
},
584588
"./lib/strings": {
585589
"types": "./lib/strings.d.ts",
586590
"default": "./lib/strings.js"
@@ -639,6 +643,7 @@
639643
"del-cli": "6.0.0",
640644
"dev-null-cli": "2.0.0",
641645
"eslint": "9.32.0",
646+
"fast-glob": "^3.3.3",
642647
"fast-sort": "3.4.1",
643648
"libnpmpack": "9.0.6",
644649
"make-fetch-happen": "14.0.3",
@@ -653,7 +658,7 @@
653658
"signal-exit": "4.1.0",
654659
"spdx-correct": "3.2.0",
655660
"spdx-expression-parse": "4.0.0",
656-
"tinyglobby": "0.2.14",
661+
"streaming-iterables": "^8.0.1",
657662
"validate-npm-package-name": "6.0.2",
658663
"which": "5.0.0",
659664
"yoctocolors-cjs": "2.1.2"

registry/scripts/rollup/build-external.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const path = require('node:path')
44

55
const { rollup } = require('rollup')
6-
const { glob: tinyGlob } = require('tinyglobby')
6+
const { glob } = require('fast-glob')
77

88
const scriptsPath = path.join(__dirname, '..')
99
const rootPath = path.join(scriptsPath, '..')
@@ -13,7 +13,7 @@ const srcExternalPath = path.join(srcPath, 'external')
1313

1414
const getConfig = require(path.join(configPath, 'rollup.base.config.js'))
1515
;(async () => {
16-
const filepaths = await tinyGlob(['**/*.js'], {
16+
const filepaths = await glob(['**/*.js'], {
1717
absolute: true,
1818
cwd: srcExternalPath
1919
})

registry/src/external/fast-glob.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from 'fast-glob'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { parallelMap } from 'streaming-iterables'

registry/src/external/tinyglobby.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)