Skip to content

refactor: match import glob common base by path segment correctly - #22558

Merged
sapphi-red merged 4 commits into
vitejs:mainfrom
jiyujie2006:fix-import-glob-common-base-prefix
Jun 3, 2026
Merged

sapphi-red merged 4 commits into
vitejs:mainfrom
jiyujie2006:fix-import-glob-common-base-prefix

Conversation

@jiyujie2006

Copy link
Copy Markdown
Contributor

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

@sapphi-red sapphi-red left a comment

Copy link
Copy Markdown
Member

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
@sapphi-red

Copy link
Copy Markdown
Member

Ok, so getCommonBase is only used for cwd and the cwd is only used for optimization when absolute: true is set, which means the e2e test does not actually test anything. I've reverted that commit.

@sapphi-red sapphi-red changed the title fix: match import glob common base by path segment refactor: match import glob common base by path segment correctly Jun 3, 2026
@sapphi-red sapphi-red added p1-chore Doesn't change code behavior (priority) and removed p2-edge-case Bug, but has workaround or limited in scope (priority) labels Jun 3, 2026
@sapphi-red
sapphi-red enabled auto-merge (squash) June 3, 2026 03:53
@sapphi-red
sapphi-red merged commit eb12604 into vitejs:main Jun 3, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p1-chore Doesn't change code behavior (priority)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants