From fdfb61f2a9ab596dc9b6bc09a6c52645aca18ef4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Mon, 21 Aug 2023 17:42:25 +0900 Subject: [PATCH] refactor(glob)!: remove `import.meta.globEager` (#14118) --- packages/vite/src/node/index.ts | 1 - .../vite/src/node/plugins/importMetaGlob.ts | 17 +------------ packages/vite/types/importGlob.d.ts | 24 ------------------- packages/vite/types/importMeta.d.ts | 4 ---- 4 files changed, 1 insertion(+), 45 deletions(-) diff --git a/packages/vite/src/node/index.ts b/packages/vite/src/node/index.ts index e62cd179b61b3e..c4afbd2bd4812d 100644 --- a/packages/vite/src/node/index.ts +++ b/packages/vite/src/node/index.ts @@ -117,7 +117,6 @@ export type { } from 'types/customEvent' export type { ImportGlobFunction, - ImportGlobEagerFunction, ImportGlobOptions, GeneralImportGlobOptions, KnownAsTypeMap, diff --git a/packages/vite/src/node/plugins/importMetaGlob.ts b/packages/vite/src/node/plugins/importMetaGlob.ts index 60172e0de3a143..c76ab9f495196d 100644 --- a/packages/vite/src/node/plugins/importMetaGlob.ts +++ b/packages/vite/src/node/plugins/importMetaGlob.ts @@ -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 } @@ -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'], @@ -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) => { @@ -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, } @@ -385,15 +379,6 @@ export async function transformGlobImport( ) const matchedFiles = new Set() - // 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) diff --git a/packages/vite/types/importGlob.d.ts b/packages/vite/types/importGlob.d.ts index 98786bbdd9efa5..b9ba52ec1ca881 100644 --- a/packages/vite/types/importGlob.d.ts +++ b/packages/vite/types/importGlob.d.ts @@ -71,27 +71,3 @@ export interface ImportGlobFunction { options: ImportGlobOptions, ): Record } - -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, 'eager'>, - ): Record - /** - * Eagerly import a list of files with a glob pattern. - * - * Overload 2: Module generic provided - */ - ( - glob: string | string[], - options?: Omit, 'eager'>, - ): Record -} diff --git a/packages/vite/types/importMeta.d.ts b/packages/vite/types/importMeta.d.ts index e9047a78117d82..bd4418379951b3 100644 --- a/packages/vite/types/importMeta.d.ts +++ b/packages/vite/types/importMeta.d.ts @@ -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 }