|
1 | 1 | import fs from 'node:fs/promises'
|
2 | 2 | import path from 'node:path'
|
3 | 3 | import colors from 'picocolors'
|
4 |
| -import { glob } from 'tinyglobby' |
| 4 | +import { glob, isDynamicPattern } from 'tinyglobby' |
5 | 5 | import { FS_PREFIX } from '../constants'
|
6 | 6 | import { normalizePath } from '../utils'
|
7 | 7 | import type { ViteDevServer } from '../index'
|
@@ -72,10 +72,29 @@ function fileToUrl(file: string, root: string) {
|
72 | 72 |
|
73 | 73 | async function mapFiles(files: string[], root: string) {
|
74 | 74 | if (!files.length) return []
|
75 |
| - return await glob(files, { |
76 |
| - absolute: true, |
77 |
| - cwd: root, |
78 |
| - expandDirectories: false, |
79 |
| - ignore: ['**/.git/**', '**/node_modules/**'], |
80 |
| - }) |
| 75 | + |
| 76 | + const result: string[] = [] |
| 77 | + const globs: string[] = [] |
| 78 | + for (const file of files) { |
| 79 | + if (isDynamicPattern(file)) { |
| 80 | + globs.push(file) |
| 81 | + } else { |
| 82 | + if (path.isAbsolute(file)) { |
| 83 | + result.push(file) |
| 84 | + } else { |
| 85 | + result.push(path.resolve(root, file)) |
| 86 | + } |
| 87 | + } |
| 88 | + } |
| 89 | + if (globs.length) { |
| 90 | + result.push( |
| 91 | + ...(await glob(globs, { |
| 92 | + absolute: true, |
| 93 | + cwd: root, |
| 94 | + expandDirectories: false, |
| 95 | + ignore: ['**/.git/**', '**/node_modules/**'], |
| 96 | + })), |
| 97 | + ) |
| 98 | + } |
| 99 | + return result |
81 | 100 | }
|
0 commit comments