Commit b8be99c
authored
fix(perps-controller): restore webpackIgnore comment stripped by ts-bridge (#8424)
## Explanation
When `@metamask/perps-controller` v2.0.0 is consumed by the MetaMask
extension, webpack throws a hard `MODULE_NOT_FOUND` error on the
MYXProvider dynamic import.
**Root cause:** `ts-bridge`'s `getDynamicImportExtensionTransformer`
creates new AST nodes (`factory.createStringLiteral`) that discard
leading comments from the original source. The `/* webpackIgnore: true
*/` magic comment added in #8398 is present in TypeScript source but
stripped from the compiled `.mjs`/`.cjs` output.
**Fix:** Extract the import path into a local variable. `ts-bridge` only
transforms string literal arguments in `import()` calls, so a variable
reference is left untouched — preserving both the magic comment and the
original path. This avoids needing post-build scripts or build system
modifications (which would violate monorepo yarn constraints).
**Long-term:** The proper fix is upstream in `@ts-bridge/cli` — the
transformer should copy leading comments from original nodes to
synthesized ones via `ts.setSyntheticLeadingComments()`. Once that's
fixed, this workaround can be reverted.
## References
- Fixes the webpack error in MetaMask/metamask-extension#41356
- Follow-up to #8398
## Changelog
### `@metamask/perps-controller`
#### Fixed
- Preserve `/* webpackIgnore: true */` magic comment in built dist files
by using a variable for the MYXProvider dynamic import path, preventing
ts-bridge from rewriting the AST node and stripping the comment
## Checklist
- [x] I've updated the changelog
- [x] I've verified the fix: `dist/PerpsController.mjs` and
`dist/PerpsController.cjs` both contain `/* webpackIgnore: true */`
- [x] Tests pass
- [x] Changelog validates
- [x] Yarn constraints pass
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Low Risk**
> Low risk change limited to how `MYXProvider` is dynamically imported
and documented in the changelog. Main risk is unintended bundler
behavior if the import path variable affects tree-shaking/code-splitting
in consuming builds.
>
> **Overview**
> Ensures the `MYXProvider` dynamic import retains the `/*
webpackIgnore: true */` magic comment in compiled output by moving the
import specifier to a `myxModulePath` variable, avoiding `ts-bridge`
rewriting that strips the comment.
>
> Updates the perps-controller changelog to document this fix.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
dff83af. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent d148dd7 commit b8be99c
2 files changed
Lines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
| 90 | + | |
90 | 91 | | |
91 | 92 | | |
92 | 93 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1694 | 1694 | | |
1695 | 1695 | | |
1696 | 1696 | | |
| 1697 | + | |
| 1698 | + | |
| 1699 | + | |
1697 | 1700 | | |
1698 | | - | |
| 1701 | + | |
1699 | 1702 | | |
1700 | 1703 | | |
1701 | 1704 | | |
| |||
0 commit comments