refactor(perps): ignore myx with env var#8234
Conversation
|
@metamaskbot publish-previews |
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
|
@metamaskbot publish-previews |
|
@metamaskbot publish-previews |
|
@metamaskbot publish-previews |
|
@metamaskbot publish-previews |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
|
@metamaskbot publish-previews |
| # MYX support is behind a feature flag and @myx-trade/sdk adds ~1.3MB to the bundle. | ||
| # These files are built but stripped at publish time. | ||
| dist/providers/MYXProvider.* | ||
| dist/services/MYXClientService.* |
There was a problem hiding this comment.
SDK dependency still installed despite stripping provider files
Low Severity
The .npmignore strips MYXProvider.* and MYXClientService.* from the published package, but @myx-trade/sdk remains a runtime dependency in package.json. Consumers still install the ~1.3 MB SDK (and its transitive deps) even though no published code references it, partially undermining the size-reduction goal.
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
There was a problem hiding this comment.
I don't think this will work, since we use the files field instead to limit what is included. See here: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#files
You can also provide a .npmignore file in the root of your package or in subdirectories, which will keep files from being included. At the root of your package it will not override the "files" field, but in subdirectories it will.
(bold for emphasis)
Rather than moving this to a subdirectory so that it would override files, it would be simpler to add a negative pattern to files.
e.g. change this:
"files": [
"dist/"
],
to this:
"files": [
"dist/",
"!dist/providers/MYXProvider.*",
"!dist/services/MYXClientService.*"
],
|
@metamaskbot publish-previews |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
Co-authored-by: Mark Stacey <markjstacey@gmail.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
| "dist/" | ||
| "dist/", | ||
| "!dist/providers/MYXProvider*", | ||
| "!dist/services/MYXClientService*" |
There was a problem hiding this comment.
npm files negation patterns have undefined behavior
High Severity
The files field negation patterns (!dist/providers/MYXProvider* and !dist/services/MYXClientService*) are not officially supported by npm. The npm/cli wiki explicitly states that negating entries in files has "undefined consequences," and multiple npm bug reports confirm negation patterns stopped working reliably in npm v7+. This means the MYX files may still be included in the published tarball, defeating the PR's primary goal of reducing bundled package size by ~57%.
There was a problem hiding this comment.
Interesting. I did notice that it wasn't officially documented by npm. I was not aware there was advice against doing this. I know it's a fairly widespread pattern though (and that it's also broken on Yarn v1 - I was following a bug report about this).
But it does work for yarn pack / yarn npm publish on Yarn v4, which is how we publish things.
## Explanation Release **871.0.0** for the MetaMask core monorepo. ### Package release - **@metamask/perps-controller** `1.3.0` (minor) ### @metamask/perps-controller 1.3.0 - Exclude `@myx-trade/sdk` from the published package by default, reducing bundled size by ~57% ([#8234](#8234)) - MYX provider files are excluded from the tarball via `files` field negation - Static import of `MYXProvider` replaced with dynamic `import()`; missing module is handled so initialization does not fail when MYX is stripped No functional code changes in this PR; version bumps and changelog updates only. ## References - [#8234](#8234) — refactor(perps): ignore myx with env var ## Checklist - [x] I've updated the test suite for new or updated code as appropriate - [x] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [x] I've communicated my changes to consumers by updating changelogs for packages I've changed - [ ] I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them
## Explanation Mobile (`feat/perps/core-resolver`, PR MetaMask/metamask-mobile#27899) is the source of truth for perps code. The last sync to core was Feb 26 — 27 days stale. Since then, 4 commits went directly to core (#7941, #8197, #8214, #8234), all of which have been backported into the mobile branch. This PR syncs the latest mobile perps code to core using `validate-core-sync.sh`. Key changes: - **Geolocation dependency**: Added `@metamask/geolocation-controller` as a devDependency + tsconfig reference — `messenger.ts` now imports `GeolocationControllerGetGeolocationAction` for eligibility geolocation checks. - **New files**: `MYXWalletService.ts` (MYX wallet integration) and `PerpsController-method-action-types.ts` (typed action map). - **Package exclusion**: Added `!dist/services/MYXWalletService*` to `files` in `package.json` to keep MYX code out of published package. - **MYX provider**: Enhanced error handling (tightened to `error.code` check), wallet service integration, expanded config constants. - **HyperLiquid provider**: Subscription reliability improvements, order book processing, expanded event names. - **Eligibility service**: Refactored for geolocation-based region blocking via GeolocationController messenger action. - **ESLint**: 3 suppressions (1 `no-restricted-globals` for `require()` in MYX dynamic load, 2 `@typescript-eslint/no-base-to-string` in myxAdapter). Supersedes stale PR #8207 (`feat/perps/newsync`, 139 commits behind main). ## References - Supersedes #8207 - Related to MetaMask/metamask-mobile#27899 - Backported core PRs: #7941, #8197, #8214, #8234 ## Checklist - [ ] I've updated the test suite for new or updated code as appropriate - [x] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [x] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md) - [ ] I've introduced [breaking changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md) in this PR and have prepared draft pull requests for clients and consumer packages to resolve them <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Touches core Perps controller/provider logic (provider init, caching, eligibility geo-checks) and adds MYX wallet/authenticated reads, which could affect data freshness and provider availability across networks. > > **Overview** > Syncs Perps code from mobile into core, including **new MYX wallet/auth plumbing** and broader provider/config updates. > > `PerpsController` now (a) defers messenger handler registration until `init()`, (b) resolves MYX enablement via credentials/flags and dynamically imports/registers MYX with explicit auth config resolution, and (c) replaces single cached preload fields with **per-provider/per-network market+user caches** (with reinit guards and preload retriggering). > > Adds geolocation-based eligibility checking via `GeolocationController:getGeolocation`, expands analytics/event constants, and refactors exports to explicit named exports. HyperLiquid reliability is improved with better multi-DEX failure handling, asset-id repair/backfill, stale market-data fallback, configurable builder addresses, and a new `fetchHistoricalCandles`; MYX config/endpoints are updated and `MYXProvider` gains authenticated read support (positions/orders/fills/funding/history) plus candle subscription (REST + WS updates). > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit d8a453d. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->


Explanation
Exclude
@myx-trade/sdkand its MYX provider files from the publisheddist/output by default, reducing the bundled package size by ~57%.Problem
The
@myx-trade/sdkdependency was always included in the build output through the static import chainPerpsController → MYXProvider → MYXClientService → @myx-trade/sdk, even though the MYX provider is only instantiated behind a feature flag (MM_PERPS_MYX_PROVIDER_ENABLED).Changes
PerpsController.ts): Replaced the staticimport { MYXProvider }withawait import('./providers/MYXProvider.js')inside the existing feature flag check. Safe because the enclosing#performInitialization()is alreadyasync.package.json): Thebuildscript now removesMYXProvider.*andMYXClientService.*fromdist/after compilation, unlessMM_PERPS_MYX_PROVIDER_ENABLED=trueis set at build time.Usage
References
N/A
Checklist
Note
Low Risk
Low risk build/runtime refactor: MYX provider is now loaded via dynamic import and may be skipped if the module is stripped, but only when the existing MYX feature flag is enabled.
Overview
Reduces
@metamask/perps-controllerbundle size by excluding MYX implementation from the publisheddist/by default (addsfilesexcludes forMYXProvider*andMYXClientService*).Updates
PerpsControllerinitialization to remove the staticMYXProviderimport and insteadawait import('./providers/MYXProvider.js')behindMM_PERPS_MYX_PROVIDER_ENABLED, with atry/catchthat logs and continues when the module is not present. Adds an Unreleased changelog entry documenting the new build/publish behavior.Written by Cursor Bugbot for commit f7229f4. This will update automatically on new commits. Configure here.