Skip to content

test(glob-import): cover absolute base resolving to files outside root#22298

Merged
sapphi-red merged 8 commits into
mainfrom
04-22-test_import-glob_cover_absolute_base_resolving_to_files_outside_root
May 21, 2026
Merged

test(glob-import): cover absolute base resolving to files outside root#22298
sapphi-red merged 8 commits into
mainfrom
04-22-test_import-glob_cover_absolute_base_resolving_to_files_outside_root

Conversation

@shulaoda
Copy link
Copy Markdown
Member

@shulaoda shulaoda commented Apr 22, 2026

Summary

Adds an e2e regression test for import.meta.glob with base: '/' when the glob pattern matches files outside of Vite's project root.

In this scenario the generated import path must be root-relative (/<relative-to-root>), not importer-relative — otherwise the bundler resolves it against the importer and lands on a non-existent file.

Mirrors the minimal reproduction from rolldown/rolldown#9144 (fixed by rolldown/rolldown#9145), where the rolldown-native viteImportGlobPlugin was emitting an importer-relative path for files outside root.

Context

At build time, Vite's importGlobPlugin delegates to the rolldown-native plugin when config.isBundled is true (see packages/vite/src/node/plugins/importMetaGlob.ts:46), and isBundled is set whenever isBuild is true (packages/vite/src/node/config.ts:936).

So the new test case exercises the exact code path that caused the bug in the reproduction repo whenever VITE_TEST_BUILD=1 is set.

Implementation

After #22466 moved all fixtures of playground/glob-import/ into a root/ subdirectory, the playground naturally has space outside Vite's root: any sibling of root/ inside the copied playground tree is outside Vite's root but still inside the e2e temp dir. This matches the shape of the original reproduction repo (app/ + sibling external/).

The new test reuses that structure — no new playground, vite config, or npm script is required:

playground/glob-import/
├── __tests__/
│   └── glob-import.spec.ts   # adds `absolute base with files outside of root`
├── external/                 # outside Vite root, but inside the copied playground
│   ├── x.js
│   └── y.js
└── root/                     # vite root (auto-detected by the test harness)
    └── index.html            # appends an `<h2>Absolute base outside root</h2>` section
                              # with `import.meta.glob('../external/*.js', { base: '/', eager: true })`

@shulaoda shulaoda changed the title test(import-glob): cover absolute base resolving to files outside root test(glob-import): cover absolute base resolving to files outside root Apr 23, 2026
@shulaoda shulaoda marked this pull request as ready for review April 23, 2026 07:57
@shulaoda shulaoda requested a review from sapphi-red April 23, 2026 07:57
@sapphi-red
Copy link
Copy Markdown
Member

How does it look like if we add root subdirectory to glob-import playground?

@shulaoda shulaoda marked this pull request as draft April 23, 2026 12:47
@shulaoda shulaoda force-pushed the 04-22-test_import-glob_cover_absolute_base_resolving_to_files_outside_root branch from 6d042ed to a655c54 Compare April 24, 2026 04:05
@shulaoda shulaoda marked this pull request as ready for review April 24, 2026 04:07
@shulaoda
Copy link
Copy Markdown
Member Author

How does it look like if we add root subdirectory to glob-import playground?

done

@sapphi-red
Copy link
Copy Markdown
Member

I was thinking of changing the structure to put everything in root.

@shulaoda
Copy link
Copy Markdown
Member Author

I was thinking of changing the structure to put everything in root.

This approach could work, but it’s relatively complex and has a broad impact. I think it might be better to make this change after this PR.

@sapphi-red
Copy link
Copy Markdown
Member

Can we first move everything in root in a separate PR and then rebase this one on top of that?

@shulaoda shulaoda force-pushed the 04-22-test_import-glob_cover_absolute_base_resolving_to_files_outside_root branch from 174b666 to 30ef10e Compare May 21, 2026 03:55
@shulaoda shulaoda marked this pull request as ready for review May 21, 2026 04:00
Comment thread playground/glob-import/root/index.html Outdated
@shulaoda shulaoda requested a review from sapphi-red May 21, 2026 06:31
@sapphi-red sapphi-red merged commit ec64896 into main May 21, 2026
18 of 20 checks passed
@sapphi-red sapphi-red deleted the 04-22-test_import-glob_cover_absolute_base_resolving_to_files_outside_root branch May 21, 2026 06:55
@sapphi-red sapphi-red added p1-chore Doesn't change code behavior (priority) test labels May 21, 2026
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) test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants