Turbopack: import.meta.glob docs + edge case support#92729
Conversation
Merging this PR will improve performance by 3.51%
Performance Changes
Comparing Footnotes
|
Stats from current PR🟢 1 improvement
📊 All Metrics📖 Metrics GlossaryDev Server Metrics:
Build Metrics:
Change Thresholds:
⚡ Dev Server
📦 Dev Server (Webpack) (Legacy)📦 Dev Server (Webpack)
⚡ Production Builds
📦 Production Builds (Webpack) (Legacy)📦 Production Builds (Webpack)
📦 Bundle SizesBundle Sizes⚡ TurbopackClient Main Bundles
Server Middleware
Build DetailsBuild Manifests
📦 WebpackClient Main Bundles
Polyfills
Pages
Server Edge SSR
Middleware
Build DetailsBuild Manifests
Build Cache
🔄 Shared (bundler-independent)Runtimes
📝 Changed Files (25 files)Files with changes:
View diffsapp-page-exp..ntime.dev.jsfailed to diffapp-page-exp..time.prod.jsfailed to diffapp-page-tur..ntime.dev.jsfailed to diffapp-page-tur..time.prod.jsfailed to diffapp-page-tur..ntime.dev.jsfailed to diffapp-page-tur..time.prod.jsfailed to diffapp-page.runtime.dev.jsfailed to diffapp-page.runtime.prod.jsfailed to diffapp-route-ex..ntime.dev.jsDiff too large to display app-route-ex..time.prod.jsDiff too large to display app-route-tu..ntime.dev.jsDiff too large to display app-route-tu..time.prod.jsDiff too large to display app-route-tu..ntime.dev.jsDiff too large to display app-route-tu..time.prod.jsDiff too large to display app-route.runtime.dev.jsDiff too large to display app-route.ru..time.prod.jsDiff too large to display pages-api-tu..ntime.dev.jsDiff too large to display pages-api-tu..time.prod.jsDiff too large to display pages-api.runtime.dev.jsDiff too large to display pages-api.ru..time.prod.jsDiff too large to display pages-turbo...ntime.dev.jsDiff too large to display pages-turbo...time.prod.jsDiff too large to display pages.runtime.dev.jsDiff too large to display pages.runtime.prod.jsDiff too large to display server.runtime.prod.jsDiff too large to display 📎 Tarball URL |
Failing test suitesCommit: f9b9ac5 | About building and testing Next.js
Expand output● rewrites manual href/as › development mode › should allow manual href/as on index page ● rewrites manual href/as › production mode › should allow manual href/as on index page |
| glob( | ||
| pattern: string | string[], | ||
| options: ImportMetaGlobOptions & { eager: true } | ||
| ): Record<string, unknown> |
There was a problem hiding this comment.
We do know it is a namespace object, would setting the type to object be slightly more useful?
f9b9ac5 to
dfee998
Compare
Documents the Vite-compatible import.meta.glob API in the Turbopack reference page (lazy/eager loading, named imports, query strings, multiple patterns, negation, options table) and adds a migration note in the from-Vite guide. Co-Authored-By: Claude <noreply@anthropic.com>
… dotfile exclusion
- `import: '*'` is treated as a namespace import (whole module), same as
omitting the import option entirely.
- `query` option now accepts object literals (e.g. `{ bar: 'foo', raw: true }`)
which are serialized to a query string (`?bar=foo&raw=true`).
- Dotfiles and dot-directories (e.g. `.git`, `.foo`) are excluded from glob
results, matching Vite's behavior.
- Added execution tests for all new features and error cases (no args, too many
args, non-string pattern, non-object options).
Co-Authored-By: Claude <noreply@anthropic.com>
…ilters, error on bad options arg
- URL-encode query object keys and values using the `urlencoding` crate,
matching Vite's behavior (e.g. { query: { 'foo bar': 'baz' } } →
'?foo%20bar=baz').
- Remove manual dotfile/dot-directory filtering from `flatten_read_glob`;
the underlying glob pattern already handles this correctly.
- Promoting "second argument must be an object literal" from warning to
error and return None, since the options cannot be safely defaulted.
- Fix test: explicit dotfile pattern `./.foo/*.js` correctly includes
dotfile entries; wildcard `**` also includes them now.
Co-Authored-By: Claude <noreply@anthropic.com>
…ormat - Add ImportMetaGlobOptions interface and overloaded glob() signatures to ImportMeta in global.d.ts, with correct return types for eager vs lazy. - Document the object form of the query option (auto-serialized to query string). - Add a TypeScript section explaining the types and eager/lazy return differences. Co-Authored-By: Claude <noreply@anthropic.com>
dfee998 to
7540b1b
Compare
14e39ed to
b6916be
Compare
Tests PassedCommit: b6916be |
What?
Adds documentation and TypeScript types for
import.meta.globin Turbopack, and implements additional edge cases for Vite compatibility.Documentation
## import.meta.globsection in the Turbopack reference page covering: lazy/eager loading, named imports, query strings (including the object form), multiple patterns, negation, TypeScript types, and a full options table.import.meta.globrow added to the Module Resolution feature table.import.meta.globworks out of the box with Turbopack, with before/after for the deprecatedas→querymigration.TypeScript types
ImportMetaGlobOptionsinterface and overloadedglob()signatures toImportMetainpackages/next/types/global.d.ts.Record<string, unknown>wheneager: trueis passed andRecord<string, () => Promise<unknown>>otherwise.Implementation (edge cases)
import: '*'(namespace import): Treated the same as omitting theimportoption (returns the whole module namespace), matching Vite semantics. Previously would have generated brokenmodule["*"]access.queryas object literal:{ query: { bar: 'foo', raw: true } }is now supported. Keys and values are URL-encoded and joined into a query string (?bar=foo&raw=true).import.meta.glob('./*.js', 'eager')) is now a compile-time error instead of a warning, since the options cannot be safely defaulted.Tests
import: '*', query object, combining query with negation, explicit dotfile patterns.import-meta-glob-errorsexecution test with issue snapshots covering: too many arguments, non-string pattern, and non-object options argument.Why?
import: '*') and query objects. These gaps would cause subtle behavioral differences for users migrating from Vite.How?
Docs & types
docs/01-app/03-api-reference/08-turbopack.mdx— new section, table row, TypeScript subsectiondocs/01-app/02-guides/migrating/from-vite.mdx— migration notepackages/next/types/global.d.ts—ImportMetaGlobOptions+ImportMeta.glob()overloadsImplementation
turbopack/crates/turbopack-ecmascript/src/references/import_meta_glob.rs:parse_import_meta_glob():import: '*'normalized toNone; query object parsing viaurlencoding::encode(); non-object options argument now emits an error and returnsNone.turbopack/crates/turbopack-ecmascript/Cargo.toml: addedurlencodingworkspace dep.Note: dotfile/dot-directory filtering is not needed in
import.meta.globitself — the underlyingGlobpattern engine andread_glob_internalalready handle dotfile semantics correctly (explicit./.foo/*.jsmatches, wildcards include them).Tests
turbopack-tests/tests/execution/turbopack/resolving/import-meta-glob/— new cases forimport: '*', query object, query + negation, explicit dotfile pattern, wildcard including dotfilesturbopack-tests/tests/execution/turbopack/resolving/import-meta-glob-errors/— new test suite for fatal parse errors with issue snapshotsChecklist
pnpm prettier-fix/cargo fmtruncargo test -p turbopack-tests --test execution -- "import_meta_glob")cargo clippycleanpnpm --filter=next typespasses