From ecb96d65eb2dd6d0c01e5f38a8b8904600a5b831 Mon Sep 17 00:00:00 2001 From: Prithpal Sooriya Date: Mon, 2 Sep 2024 13:43:22 +0100 Subject: [PATCH] refactor: add multiple file exports for notifications controllers (#4604) ## Explanation This adds multiple exports to the `@metamask/profile-sync-controller` and `@metamask/notification-services-controller`. This will allow classes, functions, variables to be imported more naturally compared to the named exports. This will _potentially_ help with tree shaking. List of all imports: ```ts // Profile Sync Controller import {} from '@metamask/profile-sync-controller' import {} from '@metamask/profile-sync-controller/auth' import {} from '@metamask/profile-sync-controller/auth/mocks' import {} from '@metamask/profile-sync-controller/user-storage' import {} from '@metamask/profile-sync-controller/user-storage/mocks' import {} from '@metamask/profile-sync-controller/sdk' // Notification Services import {} from '@metamask/notification-services-controller' import {} from '@metamask/notification-services-controller/notification-services' import {} from '@metamask/notification-services-controller/notification-services/types' import {} from '@metamask/notification-services-controller/notification-services/processors' import {} from '@metamask/notification-services-controller/notification-services/constants' import {} from '@metamask/notification-services-controller/notification-services/ui' import {} from '@metamask/notification-services-controller/notification-services/mocks' import {} from '@metamask/notification-services-controller/push-services' import {} from '@metamask/notification-services-controller/push-services/types' import {} from '@metamask/notification-services-controller/push-services/utils' import {} from '@metamask/notification-services-controller/push-services/mocks' ``` NOTE - we will keep backwards compatibility with named exports. I think we'll also probably export all (e.g `export * ...`) to flatten the named exports structure. ## References N/A ## Changelog ### `@metamask/package-a` - ****: Your change here - ****: Your change here ### `@metamask/package-b` - ****: Your change here - ****: Your change here ## 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 highlighted breaking changes using the "BREAKING" category above as appropriate --- .../constants/package.json | 9 ++++ .../notification-services/mocks/package.json | 9 ++++ .../notification-services/package.json | 9 ++++ .../processors/package.json | 9 ++++ .../notification-services/types/package.json | 9 ++++ .../notification-services/ui/package.json | 9 ++++ .../package.json | 54 ++++++++++++++++++- .../push-services/mocks/package.json | 9 ++++ .../push-services/package.json | 9 ++++ .../push-services/types/package.json | 9 ++++ .../push-services/utils/package.json | 9 ++++ .../NotificationServicesController/index.ts | 2 + .../index.ts | 2 + .../utils/get-notification-message.test.ts | 11 ++-- .../auth/mocks/package.json | 9 ++++ .../profile-sync-controller/auth/package.json | 9 ++++ packages/profile-sync-controller/package.json | 29 +++++++++- .../profile-sync-controller/sdk/package.json | 9 ++++ .../src/controllers/authentication/index.ts | 2 + .../controllers/authentication/services.ts | 2 +- .../src/controllers/user-storage/index.ts | 2 + .../src/controllers/user-storage/services.ts | 2 +- .../user-storage/mocks/package.json | 9 ++++ .../user-storage/package.json | 9 ++++ 24 files changed, 231 insertions(+), 10 deletions(-) create mode 100644 packages/notification-services-controller/notification-services/constants/package.json create mode 100644 packages/notification-services-controller/notification-services/mocks/package.json create mode 100644 packages/notification-services-controller/notification-services/package.json create mode 100644 packages/notification-services-controller/notification-services/processors/package.json create mode 100644 packages/notification-services-controller/notification-services/types/package.json create mode 100644 packages/notification-services-controller/notification-services/ui/package.json create mode 100644 packages/notification-services-controller/push-services/mocks/package.json create mode 100644 packages/notification-services-controller/push-services/package.json create mode 100644 packages/notification-services-controller/push-services/types/package.json create mode 100644 packages/notification-services-controller/push-services/utils/package.json create mode 100644 packages/profile-sync-controller/auth/mocks/package.json create mode 100644 packages/profile-sync-controller/auth/package.json create mode 100644 packages/profile-sync-controller/sdk/package.json create mode 100644 packages/profile-sync-controller/user-storage/mocks/package.json create mode 100644 packages/profile-sync-controller/user-storage/package.json diff --git a/packages/notification-services-controller/notification-services/constants/package.json b/packages/notification-services-controller/notification-services/constants/package.json new file mode 100644 index 0000000000..bf2dcc4dd4 --- /dev/null +++ b/packages/notification-services-controller/notification-services/constants/package.json @@ -0,0 +1,9 @@ +{ + "name": "@metamask/notification-services-controller", + "version": "1.0.0", + "description": "", + "license": "MIT", + "sideEffects": false, + "main": "../../dist/NotificationServicesController/constants/index.js", + "types": "../../dist/types/NotificationServicesController/constants/index.d.ts" +} diff --git a/packages/notification-services-controller/notification-services/mocks/package.json b/packages/notification-services-controller/notification-services/mocks/package.json new file mode 100644 index 0000000000..3f34e9911f --- /dev/null +++ b/packages/notification-services-controller/notification-services/mocks/package.json @@ -0,0 +1,9 @@ +{ + "name": "@metamask/notification-services-controller", + "version": "1.0.0", + "description": "", + "license": "MIT", + "sideEffects": false, + "main": "../../dist/NotificationServicesController/__fixtures__/index.js", + "types": "../../dist/types/NotificationServicesController/__fixtures__/index.d.ts" +} diff --git a/packages/notification-services-controller/notification-services/package.json b/packages/notification-services-controller/notification-services/package.json new file mode 100644 index 0000000000..741335458f --- /dev/null +++ b/packages/notification-services-controller/notification-services/package.json @@ -0,0 +1,9 @@ +{ + "name": "@metamask/notification-services-controller", + "version": "1.0.0", + "description": "", + "license": "MIT", + "sideEffects": false, + "main": "../dist/NotificationServicesController/index.js", + "types": "../dist/types/NotificationServicesController/index.d.ts" +} diff --git a/packages/notification-services-controller/notification-services/processors/package.json b/packages/notification-services-controller/notification-services/processors/package.json new file mode 100644 index 0000000000..68ad2f09f1 --- /dev/null +++ b/packages/notification-services-controller/notification-services/processors/package.json @@ -0,0 +1,9 @@ +{ + "name": "@metamask/notification-services-controller", + "version": "1.0.0", + "description": "", + "license": "MIT", + "sideEffects": false, + "main": "../../dist/NotificationServicesController/processors/index.js", + "types": "../../dist/types/NotificationServicesController/processors/index.d.ts" +} diff --git a/packages/notification-services-controller/notification-services/types/package.json b/packages/notification-services-controller/notification-services/types/package.json new file mode 100644 index 0000000000..43101f9622 --- /dev/null +++ b/packages/notification-services-controller/notification-services/types/package.json @@ -0,0 +1,9 @@ +{ + "name": "@metamask/notification-services-controller", + "version": "1.0.0", + "description": "", + "license": "MIT", + "sideEffects": false, + "main": "../../dist/NotificationServicesController/types/index.js", + "types": "../../dist/types/NotificationServicesController/types/index.d.ts" +} diff --git a/packages/notification-services-controller/notification-services/ui/package.json b/packages/notification-services-controller/notification-services/ui/package.json new file mode 100644 index 0000000000..28736d4f3c --- /dev/null +++ b/packages/notification-services-controller/notification-services/ui/package.json @@ -0,0 +1,9 @@ +{ + "name": "@metamask/notification-services-controller", + "version": "1.0.0", + "description": "", + "license": "MIT", + "sideEffects": false, + "main": "../../dist/NotificationServicesController/ui/index.js", + "types": "../../dist/types/NotificationServicesController/ui/index.d.ts" +} diff --git a/packages/notification-services-controller/package.json b/packages/notification-services-controller/package.json index 5f473862e4..43c330151e 100644 --- a/packages/notification-services-controller/package.json +++ b/packages/notification-services-controller/package.json @@ -22,12 +22,64 @@ "require": "./dist/index.js", "types": "./dist/types/index.d.ts" }, + "./notification-services": { + "import": "./dist/NotificationServicesController/index.mjs", + "require": "./dist/NotificationServicesController/index.js", + "types": "./dist/types/NotificationServicesController/index.d.ts" + }, + "./notification-services/types": { + "import": "./dist/NotificationServicesController/types/index.mjs", + "require": "./dist/NotificationServicesController/types/index.js", + "types": "./dist/types/NotificationServicesController/types/index.d.ts" + }, + "./notification-services/processors": { + "import": "./dist/NotificationServicesController/processors/index.mjs", + "require": "./dist/NotificationServicesController/processors/index.js", + "types": "./dist/types/NotificationServicesController/processors/index.d.ts" + }, + "./notification-services/constants": { + "import": "./dist/NotificationServicesController/constants/index.mjs", + "require": "./dist/NotificationServicesController/constants/index.js", + "types": "./dist/types/NotificationServicesController/constants/index.d.ts" + }, + "./notification-services/ui": { + "import": "./dist/NotificationServicesController/ui/index.mjs", + "require": "./dist/NotificationServicesController/ui/index.js", + "types": "./dist/types/NotificationServicesController/ui/index.d.ts" + }, + "./notification-services/mocks": { + "import": "./dist/NotificationServicesController/__fixtures__/index.mjs", + "require": "./dist/NotificationServicesController/__fixtures__/index.js", + "types": "./dist/types/NotificationServicesController/__fixtures__/index.d.ts" + }, + "./push-services": { + "import": "./dist/NotificationServicesPushController/index.mjs", + "require": "./dist/NotificationServicesPushController/index.js", + "types": "./dist/types/NotificationServicesPushController/index.d.ts" + }, + "./push-services/types": { + "import": "./dist/NotificationServicesPushController/types/index.mjs", + "require": "./dist/NotificationServicesPushController/types/index.js", + "types": "./dist/types/NotificationServicesPushController/types/index.d.ts" + }, + "./push-services/utils": { + "import": "./dist/NotificationServicesPushController/utils/index.mjs", + "require": "./dist/NotificationServicesPushController/utils/index.js", + "types": "./dist/types/NotificationServicesPushController/utils/index.d.ts" + }, + "./push-services/mocks": { + "import": "./dist/NotificationServicesPushController/__fixtures__/index.mjs", + "require": "./dist/NotificationServicesPushController/__fixtures__/index.js", + "types": "./dist/types/NotificationServicesPushController/__fixtures__/index.d.ts" + }, "./package.json": "./package.json" }, "main": "./dist/index.js", "types": "./dist/types/index.d.ts", "files": [ - "dist/" + "dist/", + "notification-services/", + "push-services/" ], "scripts": { "build": "tsup --config ../../tsup.config.ts --tsconfig ./tsconfig.build.json --clean", diff --git a/packages/notification-services-controller/push-services/mocks/package.json b/packages/notification-services-controller/push-services/mocks/package.json new file mode 100644 index 0000000000..f4fe0ab552 --- /dev/null +++ b/packages/notification-services-controller/push-services/mocks/package.json @@ -0,0 +1,9 @@ +{ + "name": "@metamask/notification-services-controller", + "version": "1.0.0", + "description": "", + "license": "MIT", + "sideEffects": false, + "main": "../../dist/NotificationServicesPushController/__fixtures__/index.js", + "types": "../../dist/types/NotificationServicesPushController/__fixtures__/index.d.ts" +} diff --git a/packages/notification-services-controller/push-services/package.json b/packages/notification-services-controller/push-services/package.json new file mode 100644 index 0000000000..0004da66d8 --- /dev/null +++ b/packages/notification-services-controller/push-services/package.json @@ -0,0 +1,9 @@ +{ + "name": "@metamask/notification-services-controller", + "version": "1.0.0", + "description": "", + "license": "MIT", + "sideEffects": false, + "main": "../dist/NotificationServicesPushController/index.js", + "types": "../dist/types/NotificationServicesPushController/index.d.ts" +} diff --git a/packages/notification-services-controller/push-services/types/package.json b/packages/notification-services-controller/push-services/types/package.json new file mode 100644 index 0000000000..052f970a68 --- /dev/null +++ b/packages/notification-services-controller/push-services/types/package.json @@ -0,0 +1,9 @@ +{ + "name": "@metamask/notification-services-controller", + "version": "1.0.0", + "description": "", + "license": "MIT", + "sideEffects": false, + "main": "../../dist/NotificationServicesPushController/types/index.js", + "types": "../../dist/types/NotificationServicesPushController/types/index.d.ts" +} diff --git a/packages/notification-services-controller/push-services/utils/package.json b/packages/notification-services-controller/push-services/utils/package.json new file mode 100644 index 0000000000..c5159726fd --- /dev/null +++ b/packages/notification-services-controller/push-services/utils/package.json @@ -0,0 +1,9 @@ +{ + "name": "@metamask/notification-services-controller", + "version": "1.0.0", + "description": "", + "license": "MIT", + "sideEffects": false, + "main": "../../dist/NotificationServicesPushController/utils/index.js", + "types": "../../dist/types/NotificationServicesPushController/utils/index.d.ts" +} diff --git a/packages/notification-services-controller/src/NotificationServicesController/index.ts b/packages/notification-services-controller/src/NotificationServicesController/index.ts index f94a1255fc..6ba00e9912 100644 --- a/packages/notification-services-controller/src/NotificationServicesController/index.ts +++ b/packages/notification-services-controller/src/NotificationServicesController/index.ts @@ -1,6 +1,8 @@ import Controller from './NotificationServicesController'; +const NotificationServicesController = Controller; export { Controller }; +export default NotificationServicesController; export * from './NotificationServicesController'; export * as Types from './types'; export * as Mocks from './__fixtures__'; diff --git a/packages/notification-services-controller/src/NotificationServicesPushController/index.ts b/packages/notification-services-controller/src/NotificationServicesPushController/index.ts index 012dd29025..ba4e7252a9 100644 --- a/packages/notification-services-controller/src/NotificationServicesPushController/index.ts +++ b/packages/notification-services-controller/src/NotificationServicesPushController/index.ts @@ -1,6 +1,8 @@ import Controller from './NotificationServicesPushController'; +const NotificationServicesPushController = Controller; export { Controller }; +export default NotificationServicesPushController; export * from './NotificationServicesPushController'; export * as Types from './types'; export * as Utils from './utils'; diff --git a/packages/notification-services-controller/src/NotificationServicesPushController/utils/get-notification-message.test.ts b/packages/notification-services-controller/src/NotificationServicesPushController/utils/get-notification-message.test.ts index cceb4c66fc..21b39e9780 100644 --- a/packages/notification-services-controller/src/NotificationServicesPushController/utils/get-notification-message.test.ts +++ b/packages/notification-services-controller/src/NotificationServicesPushController/utils/get-notification-message.test.ts @@ -1,8 +1,5 @@ -import { Mocks, Processors } from '../../NotificationServicesController'; -import type { TranslationKeys } from './get-notification-message'; -import { createOnChainPushNotificationMessage } from './get-notification-message'; - -const { +import { Processors } from '../../NotificationServicesController'; +import { createMockNotificationERC1155Received, createMockNotificationERC1155Sent, createMockNotificationERC20Received, @@ -18,7 +15,9 @@ const { createMockNotificationMetaMaskSwapsCompleted, createMockNotificationRocketPoolStakeCompleted, createMockNotificationRocketPoolUnStakeCompleted, -} = Mocks; +} from '../../NotificationServicesController/__fixtures__'; +import type { TranslationKeys } from './get-notification-message'; +import { createOnChainPushNotificationMessage } from './get-notification-message'; const mockTranslations: TranslationKeys = { pushPlatformNotificationsFundsSentTitle: () => 'Funds sent', diff --git a/packages/profile-sync-controller/auth/mocks/package.json b/packages/profile-sync-controller/auth/mocks/package.json new file mode 100644 index 0000000000..345433f357 --- /dev/null +++ b/packages/profile-sync-controller/auth/mocks/package.json @@ -0,0 +1,9 @@ +{ + "name": "@metamask/profile-sync-controller", + "version": "1.0.0", + "description": "", + "license": "MIT", + "sideEffects": false, + "main": "../../dist/controllers/authentication/__fixtures__/index.js", + "types": "../../dist/types/controllers/authentication/__fixtures__/index.d.ts" +} diff --git a/packages/profile-sync-controller/auth/package.json b/packages/profile-sync-controller/auth/package.json new file mode 100644 index 0000000000..2f365b2d3d --- /dev/null +++ b/packages/profile-sync-controller/auth/package.json @@ -0,0 +1,9 @@ +{ + "name": "@metamask/profile-sync-controller", + "version": "1.0.0", + "description": "", + "license": "MIT", + "sideEffects": false, + "main": "../dist/controllers/authentication/index.js", + "types": "../dist/types/controllers/authentication/index.d.ts" +} diff --git a/packages/profile-sync-controller/package.json b/packages/profile-sync-controller/package.json index c7ea821869..533d2e5ad4 100644 --- a/packages/profile-sync-controller/package.json +++ b/packages/profile-sync-controller/package.json @@ -22,12 +22,39 @@ "require": "./dist/index.js", "types": "./dist/types/index.d.ts" }, + "./sdk": { + "import": "./dist/sdk/index.mjs", + "require": "./dist/sdk/index.js", + "types": "./dist/types/sdk/index.d.ts" + }, + "./auth": { + "import": "./dist/controllers/authentication/index.mjs", + "require": "./dist/controllers/authentication/index.js", + "types": "./dist/types/controllers/authentication/index.d.ts" + }, + "./auth/mocks": { + "import": "./dist/controllers/authentication/__fixtures__/index.mjs", + "require": "./dist/controllers/authentication/__fixtures__/index.js", + "types": "./dist/types/controllers/authentication/__fixtures__/index.d.ts" + }, + "./user-storage": { + "import": "./dist/controllers/user-storage/index.mjs", + "require": "./dist/controllers/user-storage/index.js", + "types": "./dist/types/controllers/user-storage/index.d.ts" + }, + "./user-storage/mocks": { + "import": "./dist/controllers/user-storage/__fixtures__/index.mjs", + "require": "./dist/controllers/user-storage/__fixtures__/index.js", + "types": "./dist/types/controllers/user-storage/__fixtures__/index.d.ts" + }, "./package.json": "./package.json" }, "main": "./dist/index.js", "types": "./dist/types/index.d.ts", "files": [ - "dist/" + "dist/", + "auth/", + "user-storage/" ], "scripts": { "build": "tsup --config ../../tsup.config.ts --tsconfig ./tsconfig.build.json --clean", diff --git a/packages/profile-sync-controller/sdk/package.json b/packages/profile-sync-controller/sdk/package.json new file mode 100644 index 0000000000..d95f4fa166 --- /dev/null +++ b/packages/profile-sync-controller/sdk/package.json @@ -0,0 +1,9 @@ +{ + "name": "@metamask/profile-sync-controller", + "version": "1.0.0", + "description": "", + "license": "MIT", + "sideEffects": false, + "main": "../dist/sdk/index.js", + "types": "../dist/types/sdk/index.d.ts" +} diff --git a/packages/profile-sync-controller/src/controllers/authentication/index.ts b/packages/profile-sync-controller/src/controllers/authentication/index.ts index ece95fff72..1431d890f0 100644 --- a/packages/profile-sync-controller/src/controllers/authentication/index.ts +++ b/packages/profile-sync-controller/src/controllers/authentication/index.ts @@ -1,5 +1,7 @@ import Controller from './AuthenticationController'; +const AuthenticationController = Controller; export { Controller }; +export default AuthenticationController; export * from './AuthenticationController'; export * as Mocks from './__fixtures__'; diff --git a/packages/profile-sync-controller/src/controllers/authentication/services.ts b/packages/profile-sync-controller/src/controllers/authentication/services.ts index 3c06aef88a..78222a8ccb 100644 --- a/packages/profile-sync-controller/src/controllers/authentication/services.ts +++ b/packages/profile-sync-controller/src/controllers/authentication/services.ts @@ -1,4 +1,4 @@ -import { Env, Platform, getEnvUrls, getOidcClientId } from '../../sdk'; +import { Env, Platform, getEnvUrls, getOidcClientId } from '../../sdk/env'; const ENV_URLS = getEnvUrls(Env.PRD); diff --git a/packages/profile-sync-controller/src/controllers/user-storage/index.ts b/packages/profile-sync-controller/src/controllers/user-storage/index.ts index 01c28fabab..f6b2fc8d0d 100644 --- a/packages/profile-sync-controller/src/controllers/user-storage/index.ts +++ b/packages/profile-sync-controller/src/controllers/user-storage/index.ts @@ -1,6 +1,8 @@ import Controller from './UserStorageController'; +const UserStorageController = Controller; export { Controller }; +export default UserStorageController; export * from './UserStorageController'; export * from './encryption'; export * as Mocks from './__fixtures__'; diff --git a/packages/profile-sync-controller/src/controllers/user-storage/services.ts b/packages/profile-sync-controller/src/controllers/user-storage/services.ts index 9d3104c4ea..2fb2b6feac 100644 --- a/packages/profile-sync-controller/src/controllers/user-storage/services.ts +++ b/packages/profile-sync-controller/src/controllers/user-storage/services.ts @@ -1,6 +1,6 @@ import log from 'loglevel'; -import { Env, getEnvUrls } from '../../sdk'; +import { Env, getEnvUrls } from '../../sdk/env'; import encryption from './encryption'; import type { UserStoragePathWithFeatureAndKey, diff --git a/packages/profile-sync-controller/user-storage/mocks/package.json b/packages/profile-sync-controller/user-storage/mocks/package.json new file mode 100644 index 0000000000..1dfa95b033 --- /dev/null +++ b/packages/profile-sync-controller/user-storage/mocks/package.json @@ -0,0 +1,9 @@ +{ + "name": "@metamask/profile-sync-controller", + "version": "1.0.0", + "description": "", + "license": "MIT", + "sideEffects": false, + "main": "../../dist/controllers/user-storage/__fixtures__/index.js", + "types": "../../dist/types/controllers/user-storage/__fixtures__/index.d.ts" +} diff --git a/packages/profile-sync-controller/user-storage/package.json b/packages/profile-sync-controller/user-storage/package.json new file mode 100644 index 0000000000..dfd124ae6a --- /dev/null +++ b/packages/profile-sync-controller/user-storage/package.json @@ -0,0 +1,9 @@ +{ + "name": "@metamask/profile-sync-controller", + "version": "1.0.0", + "description": "", + "license": "MIT", + "sideEffects": false, + "main": "../dist/controllers/user-storage/index.js", + "types": "../dist/types/controllers/user-storage/index.d.ts" +}