Skip to content

Commit

Permalink
refactor: add multiple file exports for notifications controllers (#4604
Browse files Browse the repository at this point in the history
)

## 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

<!--
If you're making any consumer-facing changes, list those changes here as
if you were updating a changelog, using the template below as a guide.

(CATEGORY is one of BREAKING, ADDED, CHANGED, DEPRECATED, REMOVED, or
FIXED. For security-related issues, follow the Security Advisory
process.)

Please take care to name the exact pieces of the API you've added or
changed (e.g. types, interfaces, functions, or methods).

If there are any breaking changes, make sure to offer a solution for
consumers to follow once they upgrade to the changes.

Finally, if you're only making changes to development scripts or tests,
you may replace the template below with "None".
-->

### `@metamask/package-a`

- **<CATEGORY>**: Your change here
- **<CATEGORY>**: Your change here

### `@metamask/package-b`

- **<CATEGORY>**: Your change here
- **<CATEGORY>**: 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
  • Loading branch information
Prithpal-Sooriya authored Sep 2, 2024
1 parent b43ae02 commit ecb96d6
Show file tree
Hide file tree
Showing 24 changed files with 231 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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"
}
54 changes: 53 additions & 1 deletion packages/notification-services-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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__';
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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',
Expand Down
9 changes: 9 additions & 0 deletions packages/profile-sync-controller/auth/mocks/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
9 changes: 9 additions & 0 deletions packages/profile-sync-controller/auth/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
29 changes: 28 additions & 1 deletion packages/profile-sync-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 9 additions & 0 deletions packages/profile-sync-controller/sdk/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Controller from './AuthenticationController';

const AuthenticationController = Controller;
export { Controller };
export default AuthenticationController;
export * from './AuthenticationController';
export * as Mocks from './__fixtures__';
Original file line number Diff line number Diff line change
@@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -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__';
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
9 changes: 9 additions & 0 deletions packages/profile-sync-controller/user-storage/package.json
Original file line number Diff line number Diff line change
@@ -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"
}

0 comments on commit ecb96d6

Please sign in to comment.