|
1 | 1 | import path from 'node:path'
|
2 |
| -import glob from 'fast-glob' |
3 | 2 | import micromatch from 'micromatch'
|
| 3 | +import { globSync } from 'tinyglobby' |
4 | 4 | import type { ResolvedConfig } from '../config'
|
5 | 5 | import { escapeRegex, getNpmPackageName } from '../utils'
|
6 | 6 | import { resolvePackageData } from '../packages'
|
@@ -81,27 +81,24 @@ export function expandGlobIds(id: string, config: ResolvedConfig): string[] {
|
81 | 81 |
|
82 | 82 | // "./dist/glob/*-browser/*.js" => "./dist/glob/**/*-browser/**/*.js"
|
83 | 83 | // NOTE: in some cases, this could expand to consecutive /**/*/**/* etc
|
84 |
| - // but it's fine since fast-glob handles it the same. |
| 84 | + // but it's fine since `tinyglobby` handles it the same. |
85 | 85 | const exportValuePattern = exportsValue.replace(/\*/g, '**/*')
|
86 | 86 | // "./dist/glob/*-browser/*.js" => /dist\/glob\/(.*)-browser\/(.*)\.js/
|
87 | 87 | const exportsValueGlobRe = new RegExp(
|
88 | 88 | exportsValue.split('*').map(escapeRegex).join('(.*)'),
|
89 | 89 | )
|
90 | 90 |
|
91 | 91 | possibleExportPaths.push(
|
92 |
| - ...glob |
93 |
| - .sync(exportValuePattern, { |
94 |
| - cwd: pkgData.dir, |
95 |
| - ignore: ['node_modules'], |
96 |
| - }) |
| 92 | + ...globSync(exportValuePattern, { |
| 93 | + cwd: pkgData.dir, |
| 94 | + expandDirectories: false, |
| 95 | + ignore: ['node_modules'], |
| 96 | + }) |
97 | 97 | .map((filePath) => {
|
98 |
| - // ensure "./" prefix for inconsistent fast-glob result |
99 |
| - // glob.sync("./some-dir/**/*") -> "./some-dir/some-file" |
100 |
| - // glob.sync("./**/*") -> "some-dir/some-file" |
101 |
| - if ( |
102 |
| - exportsValue.startsWith('./') && |
103 |
| - !filePath.startsWith('./') |
104 |
| - ) { |
| 98 | + // `tinyglobby` returns paths as they are formatted by the underlying `fdir`. |
| 99 | + // Both `globSync("./some-dir/**/*")` and `globSync("./**/*")` result in |
| 100 | + // `"some-dir/somefile"` being returned, so we ensure the correct prefix manually. |
| 101 | + if (exportsValue.startsWith('./')) { |
105 | 102 | filePath = './' + filePath
|
106 | 103 | }
|
107 | 104 |
|
@@ -146,9 +143,11 @@ export function expandGlobIds(id: string, config: ResolvedConfig): string[] {
|
146 | 143 | return matched
|
147 | 144 | } else {
|
148 | 145 | // for packages without exports, we can do a simple glob
|
149 |
| - const matched = glob |
150 |
| - .sync(pattern, { cwd: pkgData.dir, ignore: ['node_modules'] }) |
151 |
| - .map((match) => path.posix.join(pkgName, slash(match))) |
| 146 | + const matched = globSync(pattern, { |
| 147 | + cwd: pkgData.dir, |
| 148 | + expandDirectories: false, |
| 149 | + ignore: ['node_modules'], |
| 150 | + }).map((match) => path.posix.join(pkgName, slash(match))) |
152 | 151 | matched.unshift(pkgName)
|
153 | 152 | return matched
|
154 | 153 | }
|
|
0 commit comments