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

Function toAbsoluteGlob

packages/vite/src/node/plugins/importMetaGlob.ts:644–690  ·  view source on GitHub ↗
(
  glob: string,
  root: string,
  importer: string | undefined,
  resolveId: IdResolver,
  base?: string,
)

Source from the content-addressed store, hash-verified

642}
643
644export async function toAbsoluteGlob(
645 glob: string,
646 root: string,
647 importer: string | undefined,
648 resolveId: IdResolver,
649 base?: string,
650): Promise<string> {
651 let pre = ''
652 if (glob[0] === '!') {
653 pre = '!'
654 glob = glob.slice(1)
655 }
656 root = globSafePath(root)
657 let dir
658 if (base) {
659 if (base[0] === '/') {
660 dir = posix.join(root, base)
661 } else {
662 dir = posix.resolve(
663 importer ? globSafePath(dirname(importer)) : root,
664 base,
665 )
666 }
667 } else {
668 dir = importer ? globSafePath(dirname(importer)) : root
669 }
670
671 if (glob[0] === '/') return pre + posix.join(root, glob.slice(1))
672 if (glob.startsWith('./')) return pre + posix.join(dir, glob.slice(2))
673 if (glob.startsWith('../')) return pre + posix.join(dir, glob)
674 if (glob.startsWith('**')) return pre + glob
675
676 const isSubImportsPattern = glob[0] === '#' && glob.includes('*')
677
678 const resolved = normalizePath(
679 (await resolveId(glob, importer, {
680 custom: { 'vite:import-glob': { isSubImportsPattern } },
681 })) || glob,
682 )
683 if (isAbsolute(resolved)) {
684 return pre + globSafeResolvedPath(resolved, glob)
685 }
686
687 throw new Error(
688 `Invalid glob: "${glob}" (resolved: "${resolved}"). It must start with '/' or './'`,
689 )
690}
691
692export function getCommonBase(globsResolved: string[]): null | string {
693 const bases = globsResolved

Callers 1

parseImportGlobFunction · 0.85

Calls 5

normalizePathFunction · 0.90
globSafePathFunction · 0.85
globSafeResolvedPathFunction · 0.85
resolveIdFunction · 0.70
resolveMethod · 0.65

Tested by

no test coverage detected