fix(devtools): avoid direct import.meta access in rspack#349
fix(devtools): avoid direct import.meta access in rspack#349Nsttt wants to merge 3 commits intoTanStack:mainfrom
Conversation
🦋 Changeset detectedLatest commit: 796db7c The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Pull request overview
This PR fixes Rspack compatibility issues by avoiding direct import.meta access patterns that trigger Rspack parser warnings. The changes move optional chaining from import.meta itself to its properties (e.g., import.meta?.env → import.meta.env?.), maintaining the same runtime behavior while satisfying Rspack's requirement for property-only access.
Changes:
- Replaced
import.meta?.envwithimport.meta.env?.in two locations to avoid direct import.meta access - Added a regression test that scans source files and fails on forbidden patterns:
import.meta?.,typeof import.meta, and= import.meta
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/devtools/tests/import-meta-compat.test.ts | New test file that recursively scans src/ for forbidden import.meta patterns to prevent regressions |
| packages/devtools/src/core.tsx | Changed import.meta?.env?.SSR to import.meta.env?.SSR for Rspack compatibility |
| packages/devtools/src/components/source-inspector.tsx | Changed import.meta?.env?.BASE_URL to import.meta.env?.BASE_URL for Rspack compatibility |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
Closes #348
import.meta?.envusages in devtools runtime code to property access (import.meta.env?.*)import.metaparser warning pathpackages/devtools/srcand fails on directimport.metaforms (import.meta?.,typeof import.meta,= import.meta)Why
Rspack warns on direct
import.metaaccess:Critical dependency: Accessing import.meta directly is unsupported (only property access or destructuring is supported)This change hardens devtools source against those patterns.
Validation
pnpm --filter @tanstack/devtools test:eslintpnpm --filter @tanstack/devtools test:libpnpm nx run @tanstack/devtools:buildpnpm --filter @tanstack/devtools test:typespnpm --filter @tanstack/devtools test:build