Skip to content

Commit 7dae9eb

Browse files
authored
Merge pull request #707 from marp-team/tinyglobby
Replace globby with tinyglobby
2 parents 1483bd0 + 8a1e1b5 commit 7dae9eb

File tree

7 files changed

+29
-100
lines changed

7 files changed

+29
-100
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- [v4.3.0](https://github.com/marp-team/marp-core/releases/v4.3.0): Added Unicode 17 support by Twemoji
1616
- Upgrade development Node.js LTS ([#689](https://github.com/marp-team/marp-cli/pull/689), [#706](https://github.com/marp-team/marp-cli/pull/706))
1717
- Upgrade dependent packages to the latest version ([#706](https://github.com/marp-team/marp-cli/pull/706))
18+
- Replace `globby` with `tinyglobby` ([#707](https://github.com/marp-team/marp-cli/pull/707))
1819

1920
### Fixed
2021

jest.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const esModules = [
1010
'chalk',
1111
'chrome-launcher',
1212
'find-up',
13-
'globby',
1413
'import-meta-resolve',
1514
'is-docker',
1615
'is-inside-container',

package-lock.json

Lines changed: 1 addition & 74 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@
109109
"express": "^5.2.1",
110110
"fast-plist": "^0.1.3",
111111
"globals": "^17.3.0",
112-
"globby": "~14.0.2",
113112
"image-size": "^2.0.2",
114113
"import-from": "^4.0.0",
115114
"import-meta-resolve": "^4.2.0",
@@ -143,6 +142,7 @@
143142
"ts-jest": "^29.4.6",
144143
"ts-key-enum": "^3.0.13",
145144
"tslib": "^2.8.1",
145+
"tinyglobby": "^0.2.15",
146146
"typed-emitter": "^2.1.0",
147147
"typescript": "^5.9.3",
148148
"typescript-eslint": "^8.56.0",

src/file.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import fs from 'node:fs'
33
import path from 'node:path'
44
import * as url from 'node:url'
5-
import { globby, Options as GlobbyOptions } from 'globby'
5+
import { glob, GlobOptions } from 'tinyglobby'
66
import { debug } from './utils/debug'
77
import { getStdin } from './utils/stdin'
88
import { generateTmpName } from './utils/tmp'
@@ -51,6 +51,11 @@ export enum FileType {
5151
Null,
5252
}
5353

54+
export interface FindPathOptions {
55+
ignore?: GlobOptions['ignore']
56+
files: string[]
57+
}
58+
5459
export class File {
5560
buffer?: Buffer
5661
inputDir?: string
@@ -176,7 +181,7 @@ export class File {
176181
private static stdinBuffer?: Buffer
177182

178183
static async findPath(
179-
opts: GlobbyOptions,
184+
opts: FindPathOptions,
180185
...paths: string[]
181186
): Promise<string[]> {
182187
const filepaths = new Set<string>()
@@ -203,12 +208,22 @@ export class File {
203208
globs.push(p.split(path.sep).join('/'))
204209
}
205210

206-
// Find remaining path through globby
207-
const gOpts = { absolute: true, ignore: ['**/node_modules'], ...opts }
208-
;(await globby(globs, gOpts)).forEach((p) => filepaths.add(p))
211+
const { files, ignore } = opts
212+
const gOpts = {
213+
absolute: true,
214+
ignore: ['**/node_modules', ...(ignore ?? [])],
215+
} satisfies GlobOptions
216+
217+
// Find remaining path through glob patterns
218+
;(await glob(globs, gOpts)).forEach((p) => filepaths.add(p))
209219

210220
for (const cwd of dirs) {
211-
;(await globby('.', { cwd, ...gOpts })).forEach((p) => filepaths.add(p))
221+
;(
222+
await glob(
223+
files.map((pattern) => `**/${pattern}`),
224+
{ ...gOpts, cwd }
225+
)
226+
).forEach((p) => filepaths.add(p))
212227
}
213228

214229
return [...filepaths.values()].map((p) => path.normalize(p))
@@ -217,12 +232,7 @@ export class File {
217232
static async find(...paths: string[]): Promise<File[]> {
218233
return (
219234
await this.findPath(
220-
{
221-
expandDirectories: {
222-
extensions: [],
223-
files: markdownExtensions.map((ext) => `*.${ext}`),
224-
},
225-
},
235+
{ files: markdownExtensions.map((ext) => `*.${ext}`) },
226236
...paths
227237
)
228238
).map((p) => new File(p))

src/marp-cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ export const marpCli = async (
450450
// @see https://github.com/marp-team/marp-cli/issues/93
451451
const stdin = args.stdin ? await File.stdin() : undefined
452452

453-
// Regular file finding powered by globby
453+
// Regular file finding powered by glob matcher
454454
return [stdin, ...(await File.find(...config.files))].filter(
455455
(f): f is File => !!f
456456
)

src/theme.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import fs from 'node:fs'
33
import path from 'node:path'
44
import { Marpit } from '@marp-team/marpit'
5-
import { isDynamicPattern } from 'globby'
5+
import { isDynamicPattern } from 'tinyglobby'
66
import { warn } from './cli'
77
import { isError } from './error'
88
import { File } from './file'
@@ -124,7 +124,7 @@ export class ThemeSet {
124124
const fnForWatch = new Set<string>(found.map((f) => path.resolve(f)))
125125

126126
for (const f of fn) {
127-
// globby's hasMagic (backed by fast-glob) always recognizes "\\" (Windows path separator) as the escape character.
127+
// tinyglobby's dynamic pattern check expects "/" as a path separator.
128128
if (!isDynamicPattern(f.split(path.sep).join('/'))) {
129129
try {
130130
const stat: fs.Stats = await fs.promises.lstat(f)
@@ -146,15 +146,7 @@ export class ThemeSet {
146146
}
147147

148148
private static async findPath(fn: string[]): Promise<string[]> {
149-
return File.findPath(
150-
{
151-
expandDirectories: {
152-
extensions: [],
153-
files: ['*.css'],
154-
},
155-
},
156-
...fn
157-
)
149+
return File.findPath({ files: ['*.css'] }, ...fn)
158150
}
159151
}
160152

0 commit comments

Comments
 (0)