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

Function getCommonBase

packages/vite/src/node/plugins/importMetaGlob.ts:692–720  ·  view source on GitHub ↗
(globsResolved: string[])

Source from the content-addressed store, hash-verified

690}
691
692export function getCommonBase(globsResolved: string[]): null | string {
693 const bases = globsResolved
694 .filter((g) => g[0] !== '!')
695 .map((glob) => {
696 let { base } = picomatch.scan(glob)
697 // `scan('a/foo.js')` returns `base: 'a/foo.js'`
698 if (posix.basename(base).includes('.')) base = posix.dirname(base)
699
700 return base
701 })
702
703 if (!bases.length) return null
704
705 let commonAncestor = ''
706 const dirS = bases[0].split('/')
707 for (let i = 0; i < dirS.length; i++) {
708 const candidate = dirS.slice(0, i + 1).join('/')
709 if (
710 bases.every(
711 (base) => base === candidate || base.startsWith(`${candidate}/`),
712 )
713 )
714 commonAncestor = candidate
715 else break
716 }
717 if (!commonAncestor) commonAncestor = '/'
718
719 return commonAncestor
720}
721
722export function isVirtualModule(id: string): boolean {
723 // https://vite.dev/guide/api-plugin.html#virtual-modules-convention

Callers 2

utils.spec.tsFile · 0.90
transformGlobImportFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected