From 7903e050e6cf0a7b8b5f7cbd64f0d1e88a894540 Mon Sep 17 00:00:00 2001 From: Elliot Winkler Date: Wed, 3 Jul 2024 15:20:52 -0600 Subject: [PATCH] json-rpc-engine: Wildcard exports -> named exports (#4462) Using wildcard exports makes it difficult to understand what a package exports and makes it possible for new exports to get added accidentally. This commit updates the `@metamask/json-rpc-engine` package to use named exports instead of wildcard exports, and adds a test to verify non-type exports following other packages. --- packages/json-rpc-engine/src/index.test.ts | 16 +++++++++++++++ packages/json-rpc-engine/src/index.ts | 24 ++++++++++++++++------ 2 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 packages/json-rpc-engine/src/index.test.ts diff --git a/packages/json-rpc-engine/src/index.test.ts b/packages/json-rpc-engine/src/index.test.ts new file mode 100644 index 0000000000..2c72ee9dd4 --- /dev/null +++ b/packages/json-rpc-engine/src/index.test.ts @@ -0,0 +1,16 @@ +import * as allExports from '.'; + +describe('@metamask/json-rpc-engine', () => { + it('has expected JavaScript exports', () => { + expect(Object.keys(allExports)).toMatchInlineSnapshot(` + Array [ + "createAsyncMiddleware", + "createScaffoldMiddleware", + "getUniqueId", + "createIdRemapMiddleware", + "JsonRpcEngine", + "mergeMiddleware", + ] + `); + }); +}); diff --git a/packages/json-rpc-engine/src/index.ts b/packages/json-rpc-engine/src/index.ts index d7644d58c9..14fb822b6b 100644 --- a/packages/json-rpc-engine/src/index.ts +++ b/packages/json-rpc-engine/src/index.ts @@ -1,6 +1,18 @@ -export * from './createAsyncMiddleware'; -export * from './createScaffoldMiddleware'; -export * from './getUniqueId'; -export * from './idRemapMiddleware'; -export * from './JsonRpcEngine'; -export * from './mergeMiddleware'; +export type { + AsyncJsonRpcEngineNextCallback, + AsyncJsonrpcMiddleware, +} from './createAsyncMiddleware'; +export { createAsyncMiddleware } from './createAsyncMiddleware'; +export { createScaffoldMiddleware } from './createScaffoldMiddleware'; +export { getUniqueId } from './getUniqueId'; +export { createIdRemapMiddleware } from './idRemapMiddleware'; +export type { + JsonRpcEngineCallbackError, + JsonRpcEngineReturnHandler, + JsonRpcEngineNextCallback, + JsonRpcEngineEndCallback, + JsonRpcMiddleware, + JsonRpcNotificationHandler, +} from './JsonRpcEngine'; +export { JsonRpcEngine } from './JsonRpcEngine'; +export { mergeMiddleware } from './mergeMiddleware';