feat(warp): add trace command for platform import debugging#38455
Closed
deyaaeldeen wants to merge 4 commits into
Closed
feat(warp): add trace command for platform import debugging#38455deyaaeldeen wants to merge 4 commits into
deyaaeldeen wants to merge 4 commits into
Conversation
Add a new `warp trace` command that visualizes how #-prefixed imports resolve across different build targets. This helps catch bugs where a browser entry point accidentally imports a Node-only module, or vice versa. The command shows: - Platform Import Divergences: all #-prefixed imports that resolve differently across targets (expected for platform-specific code) - Import Graphs: full resolution chain from each entry point per target Example output shows the browser target correctly resolving to -browser.mts files while Node targets resolve to .ts files. Use `--json` for machine-readable output suitable for CI pipelines. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
672cf65 to
bd8de62
Compare
Detects when a platform-specific file (e.g., -browser.mts) directly imports a non-platform file that has a platform variant available. Shows warning:⚠️ browser: src/indexPlatform-browser.mts imports: ./policies/StorageBrowserPolicyV2.js issue: "StorageBrowserPolicyV2.js" imported directly fix: Use #platform/... to get "StorageBrowserPolicyV2-browser.mts" This catches the exact bug that caused storage-common test failures where the browser entry point accidentally imported the Node version. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
bd8de62 to
846e909
Compare
…uild) Add validatePlatformImports function for build-time validation of platform imports. Currently disabled in the build pipeline because the polyfill mechanism handles direct imports in platform-specific files (-browser.mts). The validation logic: - Scans src/ directory for platform-specific files - Checks if direct imports should use #platform/* instead - Uses package.json imports field for principled detection The trace command remains the primary tool for debugging platform import issues. Build-time validation may be enabled in the future with refinements to handle polyfill-covered cases. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… not active The polyfill mechanism handles direct imports in platform-specific files, so validation is only needed when packages rely solely on #platform imports. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Member
Author
|
Added validation instead. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a new
warp tracecommand that visualizes how#-prefixed imports resolve across different build targets. This helps catch bugs where a browser entry point accidentally imports a Node-only module, or vice versa.Motivation
Recently we had a bug in the storage-common platform imports migration where
indexPlatform-browser.mtswas accidentally importing the Node version ofStorageBrowserPolicyV2instead of the browser version. This caused browser tests to fail because the cache-busting_parameter wasn't being added to URLs.This was difficult to debug because:
The Solution
The
warp tracecommand walks the import graph from each exported entry point and shows how#-prefixed imports resolve under each target's conditions.Example output:
The divergences section shows all
#-prefixed imports that resolve differently across targets - this makes it immediately obvious which imports have platform-specific behavior.The import graphs section shows the full resolution chain from each entry point, making it easy to trace how a specific module ends up being included.
CLI Options
Files Changed
common/tools/warp/src/trace.ts- New module implementing the trace functionalitycommon/tools/warp/src/cli.ts- Added trace command to CLIcommon/tools/warp/README.md- Documentation for the new command