Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
bb41a72
Replace `ts-bridge` with `tsc` for building packages
Mrtenz Jul 16, 2026
8771c2e
Update package exports to ESM-only
Mrtenz Jul 16, 2026
8d6ce27
Add `"type": "module"` to all packages
Mrtenz Jul 16, 2026
797f510
Add ESLint rules to enforce .js extensions in ESM imports
Mrtenz Jul 16, 2026
9e5910d
Replace `__dirname` with `import.meta.dirname` in all packages
Mrtenz Jul 16, 2026
05dd3f8
Convert Jest configuration to ESM
Mrtenz Jul 16, 2026
13aa234
Add `ts-jest` to root devDependencies
Mrtenz Jul 16, 2026
2bc0c37
Work around TypeScript ESM named-import issue in messenger-cli
Mrtenz Jul 16, 2026
a774a32
Fix remaining `__dirname`
Mrtenz Jul 16, 2026
0bdef05
Remove erroneous `uuid` entry from Jest `moduleNameMapper`
Mrtenz Jul 16, 2026
db9f64f
Fix ESLint errors for `build-utils`
Mrtenz Jul 16, 2026
657bf94
Fix ESLint errors for `controller-utils`
Mrtenz Jul 16, 2026
8d2e69c
Fix ESLint errors for `messenger`
Mrtenz Jul 16, 2026
766f78c
Fix ESLint errors for `base-controller`
Mrtenz Jul 16, 2026
9b8ef11
Fix ESLint errors for `json-rpc-engine`
Mrtenz Jul 16, 2026
f1bb9d1
Fix ESLint errors for `storage-service`
Mrtenz Jul 16, 2026
a2d4836
Add Jest custom resolver and fix ESM global import hoisting
Mrtenz Jul 16, 2026
5b2d5db
Fix ESLint errors for `address-book-controller`
Mrtenz Jul 16, 2026
6d92538
Fix ESLint errors for `ai-controllers`
Mrtenz Jul 16, 2026
77101c3
Fix ESLint errors for `analytics-controller`
Mrtenz Jul 16, 2026
319f261
Fix ESLint errors for `analytics-data-regulation-controller`
Mrtenz Jul 16, 2026
b9b501f
Fix ESLint errors for `announcement-controller`
Mrtenz Jul 16, 2026
59cfbd1
Fix ESLint errors for `app-metadata-controller`
Mrtenz Jul 16, 2026
118a276
Fix ESLint errors for `approval-controller`
Mrtenz Jul 16, 2026
fa72778
Fix ESLint errors for `client-controller`
Mrtenz Jul 16, 2026
f9b820d
Fix ESLint errors for `compliance-controller`
Mrtenz Jul 16, 2026
d18f420
Fix ESLint errors for `connectivity-controller`
Mrtenz Jul 16, 2026
76f5c0d
Fix ESLint errors for `geolocation-controller`
Mrtenz Jul 16, 2026
6ac0021
Fix ESLint errors for `keyring-controller`
Mrtenz Jul 16, 2026
e4d865d
Fix ESLint errors for `logging-controller`
Mrtenz Jul 16, 2026
1859f3e
Fix ESLint errors for `message-manager`
Mrtenz Jul 16, 2026
b4d06ae
Fix ESLint errors for `name-controller`
Mrtenz Jul 16, 2026
5b9fb70
Fix ESLint errors for `passkey-controller`
Mrtenz Jul 16, 2026
944b1e3
Fix ESLint errors for `preferences-controller`
Mrtenz Jul 16, 2026
14baab0
Fix ESLint errors for `rate-limit-controller`
Mrtenz Jul 16, 2026
d3f5e53
Fix ESLint errors for `remote-feature-flag-controller`
Mrtenz Jul 16, 2026
c01f310
Fix ESLint errors for `composable-controller`
Mrtenz Jul 16, 2026
e613b0c
Fix ESLint errors for `eth-json-rpc-provider`
Mrtenz Jul 16, 2026
735b3a9
Fix ESLint errors for `json-rpc-middleware-stream`
Mrtenz Jul 16, 2026
ff66651
Fix ESLint errors for `permission-log-controller`
Mrtenz Jul 16, 2026
90e19ed
Fix ESLint errors for `base-data-service`
Mrtenz Jul 16, 2026
f5c270a
Fix ESLint errors for `permission-controller`
Mrtenz Jul 16, 2026
a24356d
ESLint fix and `jest` global import for eth-block-tracker
Mrtenz Jul 16, 2026
c0dd2a9
ESLint fix and `jest` global import for eip1193-permission-middleware
Mrtenz Jul 16, 2026
512ef3e
ESLint fix and `jest` global import for snap-account-service
Mrtenz Jul 16, 2026
e0563bc
ESLint fix and `jest` global import for chain-agnostic-permission
Mrtenz Jul 16, 2026
96aae36
ESLint fix and `jest` global import for multichain-network-controller
Mrtenz Jul 16, 2026
0c276a5
ESLint fix and `jest` global import for network-controller
Mrtenz Jul 16, 2026
d7ea999
ESLint fix and `jest` global import for accounts-controller
Mrtenz Jul 16, 2026
bd20f54
ESLint fix and `jest` global import for notification-services-controller
Mrtenz Jul 16, 2026
06c6c09
ESLint fix and `jest` global import for eip-5792-middleware
Mrtenz Jul 16, 2026
8914b8a
ESLint fix and `jest` global import for shield-controller
Mrtenz Jul 16, 2026
70aa492
ESLint fix and `jest` global import for smart-transactions-controller
Mrtenz Jul 16, 2026
5882c8e
ESLint fix and `jest` global import for user-operation-controller
Mrtenz Jul 16, 2026
8099cdc
ESLint fix and `jest` global import for transaction-controller
Mrtenz Jul 16, 2026
f65c844
ESLint fix and `jest` global import for assets-controller
Mrtenz Jul 16, 2026
1c07c25
ESLint fix and `jest` global import for assets-controllers
Mrtenz Jul 16, 2026
93dac95
ESLint fix and `jest` global import for bridge-controller
Mrtenz Jul 16, 2026
5fda52c
ESLint fix and `jest` global import for bridge-status-controller
Mrtenz Jul 16, 2026
7803d02
ESLint fix and `jest` global import for signature-controller
Mrtenz Jul 16, 2026
c25b97a
ESLint fix and `jest` global import for transaction-pay-controller
Mrtenz Jul 16, 2026
4b744b8
ESLint fix and `jest` global import for account-tree-controller
Mrtenz Jul 16, 2026
186a9b0
ESLint fix and `jest` global import for ens-controller
Mrtenz Jul 16, 2026
706c5eb
ESLint fix and `jest` global import for gas-fee-controller
Mrtenz Jul 16, 2026
29eebf1
ESLint fix and `jest` global import for polling-controller
Mrtenz Jul 16, 2026
46ef8c3
ESLint fix and `jest` global import for phishing-controller
Mrtenz Jul 16, 2026
d2817f5
ESLint fix and `jest` global import for selected-network-controller
Mrtenz Jul 16, 2026
7d3ba3a
ESLint fix and `jest` global import for profile-sync-controller
Mrtenz Jul 16, 2026
c31338d
ESLint fix and `jest` global import for multichain-transactions-contr…
Mrtenz Jul 16, 2026
9ffd0cc
ESLint fix and `jest` global import for multichain-account-service
Mrtenz Jul 16, 2026
5c75380
ESLint fix and `jest` global import for authenticated-user-storage
Mrtenz Jul 16, 2026
895e45a
ESLint fix and `jest` global import for chomp-api-service
Mrtenz Jul 16, 2026
15eec4b
ESLint fix and `jest` global import for claims-controller
Mrtenz Jul 16, 2026
62494fd
ESLint fix and `jest` global import for client-utils
Mrtenz Jul 16, 2026
b030053
ESLint fix and `jest` global import for delegation-controller
Mrtenz Jul 16, 2026
4b41f53
ESLint fix and `jest` global import for earn-controller
Mrtenz Jul 16, 2026
7e03e86
ESLint fix and `jest` global import for multichain-api-middleware
Mrtenz Jul 16, 2026
44a7d5c
ESLint fix and `jest` global import for eth-json-rpc-middleware
Mrtenz Jul 16, 2026
a9a967c
ESLint fix and `jest` global import for config-registry-controller
Mrtenz Jul 16, 2026
569c730
ESLint fix and `jest` global import for core-backend
Mrtenz Jul 16, 2026
96d913e
ESLint fix and `jest` global import for gator-permissions-controller
Mrtenz Jul 16, 2026
562119c
ESLint fix and `jest` global import for network-connection-banner-con…
Mrtenz Jul 16, 2026
62808e4
ESLint fix and `jest` global import for network-enablement-controller
Mrtenz Jul 16, 2026
1160c7d
ESLint fix and `jest` global import for perps-controller
Mrtenz Jul 16, 2026
9bce415
ESLint fix and `jest` global import for profile-metrics-controller
Mrtenz Jul 16, 2026
9a47694
ESLint fix and `jest` global import for subscription-controller
Mrtenz Jul 16, 2026
a990202
ESLint fix and `jest` global import for ramps-controller
Mrtenz Jul 16, 2026
30c47db
ESLint fix and `jest` global import for sample-controllers
Mrtenz Jul 16, 2026
f2c3a87
ESLint fix and `jest` global import for seedless-onboarding-controller
Mrtenz Jul 16, 2026
45ff0fe
ESLint fix and `jest` global import for social-controllers
Mrtenz Jul 16, 2026
57fae7a
ESLint fix and `jest` global import for wallet
Mrtenz Jul 16, 2026
e3a8a52
ESLint fix and `jest` global import for money-account-controller
Mrtenz Jul 16, 2026
c452c33
ESLint fix and `jest` global import for money-account-api-data-service
Mrtenz Jul 16, 2026
aa1e5ec
ESLint fix and `jest` global import for money-account-balance-service
Mrtenz Jul 16, 2026
0d5dee0
ESLint fix and `jest` global import for money-account-upgrade-controller
Mrtenz Jul 16, 2026
ce26321
ESLint fix and `jest` global import for react-data-query
Mrtenz Jul 16, 2026
4c0c49f
ESLint fix and `jest` global import for sentinel-api-service
Mrtenz Jul 16, 2026
1a25811
ESLint fix and `jest` global import for eip-7702-internal-rpc-middleware
Mrtenz Jul 16, 2026
5266c7f
ESLint fix and `jest` global import for local-node-utils
Mrtenz Jul 16, 2026
c72ee8f
ESLint fix and `jest` global import for messenger-cli
Mrtenz Jul 16, 2026
07f3e3d
ESLint fix and `jest` global import for wallet-cli
Mrtenz Jul 16, 2026
1227353
ESLint fix and `jest` global import for bitcoin-regtest-up
Mrtenz Jul 16, 2026
71df4ef
ESLint fix and `jest` global import for foundryup
Mrtenz Jul 16, 2026
bd51526
ESLint fix and `jest` global import for java-tron-up
Mrtenz Jul 16, 2026
42aa1be
ESLint fix and `jest` global import for platform-api-docs
Mrtenz Jul 16, 2026
4fff069
ESLint fix and `jest` global import for solana-test-validator-up
Mrtenz Jul 16, 2026
10a3e0f
ESLint fix and `jest` global import for stellar-quickstart-up
Mrtenz Jul 16, 2026
27d9814
ESLint fix and `jest` global import for create-package script
Mrtenz Jul 16, 2026
45e4d88
Fix .js import extensions and `isomorphic-fetch` hoisting in shared t…
Mrtenz Jul 16, 2026
53aef75
Remove resolved suppressions from eslint-suppressions.json
Mrtenz Jul 16, 2026
e813e6f
ESM lint fixes: jest shadow, no-void, CJS unambiguous, JSON extensions
Mrtenz Jul 16, 2026
419ffdc
Add `@jest/globals` to root devDependencies; prune resolved suppressions
Mrtenz Jul 16, 2026
5325200
patch: add `dist/esm/index.d.mts` to `@metamask/safe-event-emitter`
Mrtenz Jul 16, 2026
21eb378
Remove `tsconfig.buildinfo` in `build:only-clean` command
Mrtenz Jul 20, 2026
2438c87
Include file extension in messenger CLI generated files
Mrtenz Jul 20, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
diff --git a/dist/esm/index.d.mts b/dist/esm/index.d.mts
new file mode 100644
index 0000000000000000000000000000000000000000..d48ab7ade4e48f566f3ca48c60636368919b1044
--- /dev/null
+++ b/dist/esm/index.d.mts
@@ -0,0 +1,5 @@
+/// <reference types="node" />
+import { EventEmitter } from 'events';
+export default class SafeEventEmitter extends EventEmitter {
+ emit(type: string, ...args: any[]): boolean;
+}
diff --git a/package.json b/package.json
index 87ca2f6363c43d2f9d45be268e8ba03c1669c02c..72211f17fe3976ef8dac7d8512d60a6de1275fbd 100644
--- a/package.json
+++ b/package.json
@@ -8,7 +8,7 @@
"exports": {
".": {
"import": {
- "types": "./dist/esm/index.d.ts",
+ "types": "./dist/esm/index.d.mts",
"default": "./dist/esm/index.mjs"
},
"require": {
1 change: 0 additions & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ npmPreapprovedPackages:
- "@metamask/*"
- "@metamask-previews/*"
- "@lavamoat/*"
- "@ts-bridge/*"

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-allow-scripts.cjs
Expand Down
2 changes: 0 additions & 2 deletions docs/processes/building.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Building packages

[`ts-bridge`](https://github.com/ts-bridge/ts-bridge) is used to build packages in both CommonJS- and ESM-compatible formats.

Built files show up in the `dist/` directory in each package. These are the files which will ultimately be published to NPM.

- Run `yarn build` to build all packages in the monorepo.
Expand Down
40 changes: 1 addition & 39 deletions eslint-suppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
"@typescript-eslint/explicit-function-return-type": {
"count": 7
},
"@typescript-eslint/prefer-nullish-coalescing": {
"count": 1
},
"no-negated-condition": {
"count": 3
},
Expand Down Expand Up @@ -251,9 +248,6 @@
"packages/assets-controllers/src/DeFiPositionsController/DeFiPositionsController.ts": {
"@typescript-eslint/explicit-function-return-type": {
"count": 2
},
"@typescript-eslint/no-misused-promises": {
"count": 2
}
},
"packages/assets-controllers/src/DeFiPositionsController/group-defi-positions.ts": {
Expand Down Expand Up @@ -289,9 +283,6 @@
}
},
"packages/assets-controllers/src/MultichainBalancesController/MultichainBalancesController.ts": {
"@typescript-eslint/no-misused-promises": {
"count": 1
},
"no-restricted-syntax": {
"count": 2
}
Expand All @@ -311,12 +302,6 @@
"@typescript-eslint/naming-convention": {
"count": 5
},
"@typescript-eslint/no-misused-promises": {
"count": 2
},
"@typescript-eslint/prefer-nullish-coalescing": {
"count": 6
},
"@typescript-eslint/prefer-optional-chain": {
"count": 1
},
Expand Down Expand Up @@ -475,9 +460,6 @@
"@typescript-eslint/no-unused-vars": {
"count": 1
},
"@typescript-eslint/prefer-optional-chain": {
"count": 3
},
"id-length": {
"count": 1
},
Expand Down Expand Up @@ -601,9 +583,6 @@
"@typescript-eslint/explicit-function-return-type": {
"count": 25
},
"@typescript-eslint/prefer-nullish-coalescing": {
"count": 1
},
"no-negated-condition": {
"count": 1
}
Expand Down Expand Up @@ -1288,9 +1267,6 @@
"@typescript-eslint/explicit-function-return-type": {
"count": 1
},
"@typescript-eslint/prefer-nullish-coalescing": {
"count": 2
},
"id-denylist": {
"count": 1
}
Expand Down Expand Up @@ -1377,9 +1353,6 @@
"@typescript-eslint/explicit-function-return-type": {
"count": 4
},
"@typescript-eslint/no-misused-promises": {
"count": 2
},
"no-restricted-syntax": {
"count": 1
}
Expand Down Expand Up @@ -1739,9 +1712,6 @@
"@typescript-eslint/explicit-function-return-type": {
"count": 4
},
"@typescript-eslint/prefer-nullish-coalescing": {
"count": 4
},
"id-length": {
"count": 2
},
Expand Down Expand Up @@ -2105,9 +2075,6 @@
"@typescript-eslint/explicit-function-return-type": {
"count": 7
},
"@typescript-eslint/no-base-to-string": {
"count": 1
},
"@typescript-eslint/no-unused-vars": {
"count": 2
},
Expand All @@ -2131,7 +2098,7 @@
"count": 10
},
"@typescript-eslint/no-floating-promises": {
"count": 4
"count": 3
},
"no-restricted-syntax": {
"count": 4
Expand Down Expand Up @@ -2240,11 +2207,6 @@
"count": 2
}
},
"packages/transaction-pay-controller/src/strategy/bridge/bridge-submit.ts": {
"no-restricted-syntax": {
"count": 1
}
},
"packages/transaction-pay-controller/src/strategy/relay/hyperliquid-withdraw.ts": {
"no-restricted-syntax": {
"count": 1
Expand Down
53 changes: 52 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import base, { createConfig } from '@metamask/eslint-config';
import jest from '@metamask/eslint-config-jest';
import nodejs from '@metamask/eslint-config-nodejs';
import typescript from '@metamask/eslint-config-typescript';
import node from 'eslint-plugin-n';

const NODE_LTS_VERSION = 22;

Expand Down Expand Up @@ -94,6 +95,9 @@ const config = createConfig([
// Handled by Oxfmt.
'prettier/prettier': 'off',
'import-x/order': 'off',
// Allow `void somePromise()` to explicitly mark ignored promises
// (required by `no-floating-promises`).
'no-void': ['error', { allowAsStatement: true }],
},
},
{
Expand Down Expand Up @@ -125,7 +129,7 @@ const config = createConfig([
{
files: ['**/*.{js,cjs}'],
languageOptions: {
sourceType: 'script',
sourceType: 'module',
ecmaVersion: 2020,
},
},
Expand Down Expand Up @@ -179,6 +183,13 @@ const config = createConfig([
'jest/no-alias-methods': 'error',
'jest/no-commented-out-tests': 'error',
'jest/no-disabled-tests': 'error',

// Some package types are wrong (e.g., nock).
'import-x/no-named-as-default-member': 'off',

// `import { jest } from '@jest/globals'` is required in ESM test files
// and intentionally shadows the Jest-injected global.
'@typescript-eslint/no-shadow': ['error', { allow: ['jest'] }],
},
settings: {
node: {
Expand Down Expand Up @@ -218,6 +229,19 @@ const config = createConfig([
'n/hashbang': 'off',
},
},
{
files: [
'**/*.cjs',
'**/.prettierrc.js',
'**/.eslintrc.js',
'**/jest.config*.js',
'**/jest.environment.js',
],
rules: {
// CJS config files have no import/export statements.
'import-x/unambiguous': 'off',
},
},
{
files: ['**/jest.environment.js'],
rules: {
Expand Down Expand Up @@ -373,6 +397,33 @@ const config = createConfig([
'n/no-process-env': 'off',
},
},

// ESM-specific configuration. We should port this to
// `@metamask/eslint-config` at some point.
{
plugins: { n: node },
rules: {
// `import-x/extensions` doesn't support using ".js" for TypeScript
// files(?), so we load the `n` plugin and use
// `n/file-extension-in-import` instead.
'n/file-extension-in-import': ['error', 'always'],
'import-x/extensions': [
'error',
{
js: 'ignorePackages',
ts: 'never',
tsx: 'never',
json: 'always',
},
],
'import-x/no-useless-path-segments': [
'error',
{
noUselessIndex: false,
},
],
},
},
]);

export default config;
36 changes: 22 additions & 14 deletions jest.config.packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@
* https://jestjs.io/docs/configuration
*/

module.exports = {
import { fileURLToPath } from 'node:url';
import { createDefaultEsmPreset } from 'ts-jest';

const presetConfig = createDefaultEsmPreset({
tsconfig: '<rootDir>/tsconfig.json',
});

const config = {
...presetConfig,

// All imported modules in your tests should be mocked automatically
// automock: false,

Expand Down Expand Up @@ -77,20 +86,17 @@ module.exports = {
// ],

// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
// Here we ensure that Jest resolves `@metamask/*` imports to the uncompiled source code for packages that live in this repo.
// NOTE: This must be synchronized with the `paths` option in `tsconfig.base.json`.
// NOTE: Monorepo `@metamask/*` packages are resolved to TypeScript source by `jest.resolver.cjs`.
// External `@metamask/*` packages are resolved by Jest's default resolver, which honours `exports` fields.
// NOTE: The `'^(\\..+)\\.js$'` entry must be synchronized with the `paths` option in `tsconfig.base.json`.
moduleNameMapper: {
'^(\\..+)\\.js$': '$1',
'^@metamask/json-rpc-engine/v2$': [
'<rootDir>/../json-rpc-engine/src/v2/index.ts',
],
'^@metamask/utils/node$': require.resolve('@metamask/utils/node'),
'^@metamask/(.+)$': [
'<rootDir>/../$1/src',
// Some @metamask/* packages we are referencing aren't in this monorepo,
// so in that case use their published versions
'<rootDir>/../../node_modules/@metamask/$1',
],
'^uuid$': require.resolve('uuid'),
'^@metamask/utils/node$': fileURLToPath(
import.meta.resolve('@metamask/utils/node'),
),
},

// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
Expand All @@ -103,11 +109,11 @@ module.exports = {
// notifyMode: "failure-change",

// A preset that is used as a base for Jest's configuration
preset: 'ts-jest',
// preset: 'ts-jest',

// The path to the Prettier executable used to format snapshots
// Jest doesn't support Prettier 3 yet, so we use Prettier 2
prettierPath: require.resolve('prettier-2'),
prettierPath: fileURLToPath(import.meta.resolve('prettier-2')),

// Run tests from one or more projects
// projects: undefined
Expand All @@ -123,7 +129,7 @@ module.exports = {
// resetModules: false,

// A path to a custom resolver
// resolver: undefined,
resolver: '../../jest.resolver.cjs',

// "restoreMocks" restores all mocks created using jest.spyOn to their
// original implementations, between each test. It does not affect mocked
Expand Down Expand Up @@ -208,3 +214,5 @@ module.exports = {
// Whether to use watchman for file crawling
// watchman: true,
};

export default config;
52 changes: 52 additions & 0 deletions jest.resolver.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* eslint-disable import-x/unambiguous, n/no-sync */
'use strict';

const { join, resolve } = require('path');
const { existsSync, statSync } = require('fs');

const REPO_ROOT = resolve(__dirname);
const PACKAGES_DIR = join(REPO_ROOT, 'packages');

/**
* Custom Jest resolver that redirects `@metamask/*` imports to monorepo source
* when the package exists locally, and falls back to default resolution (which
* honours the package `exports` field) for external packages.
*
* Without this, the `moduleNameMapper` fallback returns a directory path for
* external `@metamask/*` packages. Jest then uses `main` (CJS) rather than
* `exports.import` (ESM), causing class-inheritance failures at runtime.
*
* @param {string} moduleName - The module name to resolve.
* @param {object} options - Jest resolver options including `defaultResolver`.
* @returns {string} The resolved module path.
*/
module.exports = function resolver(moduleName, options) {
const { basedir, defaultResolver } = options;

// Skip the monorepo redirect when the import originates from an external
// package in node_modules. Those packages use CJS require() and cannot load
// ESM TypeScript source files — they must resolve against published dist.
const isFromNodeModules =
basedir !== undefined && basedir.includes('/node_modules/');

const match =
!isFromNodeModules && /^@metamask\/([^/]+)(\/.*)?$/u.exec(moduleName);

if (match) {
const [, pkgName, subPath = ''] = match;
const srcDir = join(PACKAGES_DIR, pkgName, 'src');

if (existsSync(srcDir)) {
let target = subPath ? join(srcDir, subPath) : join(srcDir, 'index.ts');
// If the resolved target is a directory, look for its index file.
if (existsSync(target) && statSync(target).isDirectory()) {
target = join(target, 'index.ts');
}

return defaultResolver(target, options);
}
}

// External package — use default resolver, which honours `exports` fields.
return defaultResolver(moduleName, options);
};
1 change: 1 addition & 0 deletions knip.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ const config: KnipConfig = {
// follow-up.
'@metamask/providers',
'webextension-polyfill',
'@jest/globals',
],
};

Expand Down
Loading
Loading