Skip to content

fix: match import glob common base by path segment#22558

Open
jiyujie2006 wants to merge 2 commits into
vitejs:mainfrom
jiyujie2006:fix-import-glob-common-base-prefix
Open

fix: match import glob common base by path segment#22558
jiyujie2006 wants to merge 2 commits into
vitejs:mainfrom
jiyujie2006:fix-import-glob-common-base-prefix

Conversation

@jiyujie2006
Copy link
Copy Markdown

Description

getCommonBase currently checks common directories with startsWith, so /a/foo is treated as a common base for /a/foo and /a/foobar. This can pass a too-narrow cwd to glob matching when directory names share a string prefix.

This changes the check to require a full path segment match, and adds coverage for the prefix case.

Additional context

Verified with:

  • pnpm --filter vite build
  • pnpm exec vitest run packages/vite/src/node/__tests__/plugins/importGlob/utils.spec.ts
  • pnpm exec eslint --no-cache packages/vite/src/node/plugins/importMetaGlob.ts packages/vite/src/node/__tests__/plugins/importGlob/utils.spec.ts

@jiyujie2006 jiyujie2006 changed the title Fix import glob common base matching fix: match import glob common base by path segment May 31, 2026
Copy link
Copy Markdown
Member

@sapphi-red sapphi-red left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sapphi-red sapphi-red added the p2-edge-case Bug, but has workaround or limited in scope (priority) label Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p2-edge-case Bug, but has workaround or limited in scope (priority)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants