Skip to content

Commit

Permalink
refactor(glob)!: remove import.meta.globEager (#14118)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored Aug 21, 2023
1 parent f97ef58 commit fdfb61f
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 45 deletions.
1 change: 0 additions & 1 deletion packages/vite/src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ export type {
} from 'types/customEvent'
export type {
ImportGlobFunction,
ImportGlobEagerFunction,
ImportGlobOptions,
GeneralImportGlobOptions,
KnownAsTypeMap,
Expand Down
17 changes: 1 addition & 16 deletions packages/vite/src/node/plugins/importMetaGlob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,11 @@ import { isCSSRequest, isModuleCSSRequest } from './css'
const { isMatch, scan } = micromatch

export interface ParsedImportGlob {
match: RegExpMatchArray
index: number
globs: string[]
globsResolved: string[]
isRelative: boolean
options: GeneralImportGlobOptions
type: string
start: number
end: number
}
Expand Down Expand Up @@ -111,8 +109,7 @@ export function importGlobPlugin(config: ResolvedConfig): Plugin {
}
}

const importGlobRE =
/\bimport\.meta\.(glob|globEager|globEagerDefault)(?:<\w+>)?\s*\(/g
const importGlobRE = /\bimport\.meta\.glob(?:<\w+>)?\s*\(/g

const knownOptions = {
as: ['string'],
Expand Down Expand Up @@ -212,7 +209,6 @@ export async function parseImportGlob(
const matches = Array.from(cleanCode.matchAll(importGlobRE))

const tasks = matches.map(async (match, index) => {
const type = match[1]
const start = match.index!

const err = (msg: string) => {
Expand Down Expand Up @@ -319,13 +315,11 @@ export async function parseImportGlob(
const isRelative = globs.every((i) => '.!'.includes(i[0]))

return {
match,
index,
globs,
globsResolved,
isRelative,
options,
type,
start,
end,
}
Expand Down Expand Up @@ -385,15 +379,6 @@ export async function transformGlobImport(
)
const matchedFiles = new Set<string>()

// TODO: backwards compatibility
matches.forEach((i) => {
if (i.type === 'globEager') i.options.eager = true
if (i.type === 'globEagerDefault') {
i.options.eager = true
i.options.import = 'default'
}
})

if (!matches.length) return null

const s = new MagicString(code)
Expand Down
24 changes: 0 additions & 24 deletions packages/vite/types/importGlob.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,27 +71,3 @@ export interface ImportGlobFunction {
options: ImportGlobOptions<true, string>,
): Record<string, M>
}

export interface ImportGlobEagerFunction {
/**
* Eagerly import a list of files with a glob pattern.
*
* Overload 1: No generic provided, infer the type from `as`
*/
<
As extends string,
T = As extends keyof KnownAsTypeMap ? KnownAsTypeMap[As] : unknown,
>(
glob: string | string[],
options?: Omit<ImportGlobOptions<boolean, As>, 'eager'>,
): Record<string, T>
/**
* Eagerly import a list of files with a glob pattern.
*
* Overload 2: Module generic provided
*/
<M>(
glob: string | string[],
options?: Omit<ImportGlobOptions<boolean, string>, 'eager'>,
): Record<string, M>
}
4 changes: 0 additions & 4 deletions packages/vite/types/importMeta.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,4 @@ interface ImportMeta {
readonly env: ImportMetaEnv

glob: import('./importGlob').ImportGlobFunction
/**
* @deprecated Use `import.meta.glob('*', { eager: true })` instead
*/
globEager: import('./importGlob').ImportGlobEagerFunction
}

0 comments on commit fdfb61f

Please sign in to comment.