MCPcopy
hub / github.com/vitejs/vite / transformGlobImport

Function transformGlobImport

packages/vite/src/node/plugins/importMetaGlob.ts:418–604  ·  view source on GitHub ↗
(
  code: string,
  id: string,
  root: string,
  resolveId: IdResolver,
  restoreQueryExtension = false,
  logger?: Logger,
)

Source from the content-addressed store, hash-verified

416 * @param optimizeExport for dynamicImportVar plugin don't need to optimize export.
417 */
418export async function transformGlobImport(
419 code: string,
420 id: string,
421 root: string,
422 resolveId: IdResolver,
423 restoreQueryExtension = false,
424 logger?: Logger,
425): Promise<TransformGlobImportResult | null> {
426 id = slash(id)
427 root = slash(root)
428 const isVirtual = isVirtualModule(id)
429 const dir = isVirtual ? undefined : dirname(id)
430 const matches = await parseImportGlob(
431 code,
432 isVirtual ? undefined : id,
433 root,
434 resolveId,
435 logger,
436 )
437 const matchedFiles = new Set<string>()
438
439 if (!matches.length) return null
440
441 const s = new MagicString(code)
442
443 const staticImports = (
444 await Promise.all(
445 matches.map(
446 async ({
447 globsResolved,
448 isRelative,
449 options,
450 index,
451 start,
452 end,
453 onlyKeys,
454 onlyValues,
455 }) => {
456 if (!dir && !options.base && isRelative) {
457 throw new Error("In virtual modules, all globs must start with '/'")
458 }
459
460 const cwd = getCommonBase(globsResolved) ?? root
461 const files = (
462 await glob(globsResolved, {
463 absolute: true,
464 cwd,
465 dot: !!options.exhaustive,
466 expandDirectories: false,
467 caseSensitiveMatch: options.caseSensitive ?? true,
468 ignore: options.exhaustive ? [] : ['**/node_modules/**'],
469 extglob: false,
470 })
471 )
472 .filter((file) => file !== id)
473 .sort()
474
475 const objectProps: string[] = []

Callers 4

fixture.spec.tsFile · 0.90
getTransformedLineCountFunction · 0.90
doTransformGlobImportFunction · 0.90
handlerFunction · 0.85

Calls 7

slashFunction · 0.90
isVirtualModuleFunction · 0.85
parseImportGlobFunction · 0.85
getCommonBaseFunction · 0.85
globFunction · 0.85
resolvePathsFunction · 0.85
addMethod · 0.80

Tested by 1

getTransformedLineCountFunction · 0.72