diff options
author | Kristóf Marussy <kristof@marussy.com> | 2022-01-27 03:14:27 +0100 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2022-02-08 21:43:17 +0100 |
commit | 383a692042ef50be32518cff94dac9172bfb4829 (patch) | |
tree | 5b5b95bbefdc68c3c44c36f8902ad052f760fe65 /packages/shared | |
parent | refactor: Extract config handling (diff) | |
download | sophie-383a692042ef50be32518cff94dac9172bfb4829.tar.gz sophie-383a692042ef50be32518cff94dac9172bfb4829.tar.zst sophie-383a692042ef50be32518cff94dac9172bfb4829.zip |
chore: Annotate shared packages for purity
Enabled better tree shaking and smaller bundle sizes by excluding
mobx-state-tree and zod dependencies whenever possible.
Signed-off-by: Kristóf Marussy <kristof@marussy.com>
Diffstat (limited to 'packages/shared')
-rw-r--r-- | packages/shared/esbuild.config.js | 2 | ||||
-rw-r--r-- | packages/shared/src/schemas.ts | 58 | ||||
-rw-r--r-- | packages/shared/src/stores/GlobalSettings.ts | 10 | ||||
-rw-r--r-- | packages/shared/src/stores/Profile.ts | 9 | ||||
-rw-r--r-- | packages/shared/src/stores/ProfileSettings.ts | 7 | ||||
-rw-r--r-- | packages/shared/src/stores/Service.ts | 29 | ||||
-rw-r--r-- | packages/shared/src/stores/ServiceSettings.ts | 13 | ||||
-rw-r--r-- | packages/shared/src/stores/SharedStore.ts | 19 |
8 files changed, 76 insertions, 71 deletions
diff --git a/packages/shared/esbuild.config.js b/packages/shared/esbuild.config.js index 7a79ce6..e8dcc2f 100644 --- a/packages/shared/esbuild.config.js +++ b/packages/shared/esbuild.config.js | |||
@@ -10,6 +10,8 @@ export default getEsbuildConfig({ | |||
10 | // The package that includes this one will have a header comment, | 10 | // The package that includes this one will have a header comment, |
11 | // no need to have an additional one here. | 11 | // no need to have an additional one here. |
12 | banner: {}, | 12 | banner: {}, |
13 | // Keep @__PURE__ annotations intact. | ||
14 | minify: false, | ||
13 | platform: 'node', | 15 | platform: 'node', |
14 | target: [chrome, node], | 16 | target: [chrome, node], |
15 | external: ['mobx', 'mobx-state-tree', 'zod'], | 17 | external: ['mobx', 'mobx-state-tree', 'zod'], |
diff --git a/packages/shared/src/schemas.ts b/packages/shared/src/schemas.ts index edf3741..1e734b2 100644 --- a/packages/shared/src/schemas.ts +++ b/packages/shared/src/schemas.ts | |||
@@ -20,17 +20,13 @@ | |||
20 | 20 | ||
21 | import { z } from 'zod'; | 21 | import { z } from 'zod'; |
22 | 22 | ||
23 | const SetSelectedServiceId = z.object({ | 23 | export const BrowserViewBounds = /* @__PURE__ */ (() => |
24 | action: z.literal('set-selected-service-id'), | 24 | z.object({ |
25 | serviceId: z.string(), | 25 | x: z.number().int().nonnegative(), |
26 | }); | 26 | y: z.number().int().nonnegative(), |
27 | 27 | width: z.number().int().nonnegative(), | |
28 | export const BrowserViewBounds = z.object({ | 28 | height: z.number().int().nonnegative(), |
29 | x: z.number().int().nonnegative(), | 29 | }))(); |
30 | y: z.number().int().nonnegative(), | ||
31 | width: z.number().int().nonnegative(), | ||
32 | height: z.number().int().nonnegative(), | ||
33 | }); | ||
34 | 30 | ||
35 | /* | 31 | /* |
36 | eslint-disable-next-line @typescript-eslint/no-redeclare -- | 32 | eslint-disable-next-line @typescript-eslint/no-redeclare -- |
@@ -38,12 +34,7 @@ export const BrowserViewBounds = z.object({ | |||
38 | */ | 34 | */ |
39 | export type BrowserViewBounds = z.infer<typeof BrowserViewBounds>; | 35 | export type BrowserViewBounds = z.infer<typeof BrowserViewBounds>; |
40 | 36 | ||
41 | const SetBrowserViewBoundsAction = z.object({ | 37 | export const ThemeSource = /* @__PURE__ */ z.enum(['system', 'light', 'dark']); |
42 | action: z.literal('set-browser-view-bounds'), | ||
43 | browserViewBounds: BrowserViewBounds, | ||
44 | }); | ||
45 | |||
46 | export const ThemeSource = z.enum(['system', 'light', 'dark']); | ||
47 | 38 | ||
48 | /* | 39 | /* |
49 | eslint-disable-next-line @typescript-eslint/no-redeclare -- | 40 | eslint-disable-next-line @typescript-eslint/no-redeclare -- |
@@ -51,21 +42,24 @@ export const ThemeSource = z.enum(['system', 'light', 'dark']); | |||
51 | */ | 42 | */ |
52 | export type ThemeSource = z.infer<typeof ThemeSource>; | 43 | export type ThemeSource = z.infer<typeof ThemeSource>; |
53 | 44 | ||
54 | const SetThemeSourceAction = z.object({ | 45 | export const Action = /* @__PURE__ */ (() => |
55 | action: z.literal('set-theme-source'), | 46 | z.union([ |
56 | themeSource: ThemeSource, | 47 | z.object({ |
57 | }); | 48 | action: z.literal('set-selected-service-id'), |
58 | 49 | serviceId: z.string(), | |
59 | const ReloadAllServicesAction = z.object({ | 50 | }), |
60 | action: z.literal('reload-all-services'), | 51 | z.object({ |
61 | }); | 52 | action: z.literal('set-browser-view-bounds'), |
62 | 53 | browserViewBounds: BrowserViewBounds, | |
63 | export const Action = z.union([ | 54 | }), |
64 | SetSelectedServiceId, | 55 | z.object({ |
65 | SetBrowserViewBoundsAction, | 56 | action: z.literal('set-theme-source'), |
66 | SetThemeSourceAction, | 57 | themeSource: ThemeSource, |
67 | ReloadAllServicesAction, | 58 | }), |
68 | ]); | 59 | z.object({ |
60 | action: z.literal('reload-all-services'), | ||
61 | }), | ||
62 | ]))(); | ||
69 | 63 | ||
70 | /* | 64 | /* |
71 | eslint-disable-next-line @typescript-eslint/no-redeclare -- | 65 | eslint-disable-next-line @typescript-eslint/no-redeclare -- |
diff --git a/packages/shared/src/stores/GlobalSettings.ts b/packages/shared/src/stores/GlobalSettings.ts index 3a813b8..1c6d7f3 100644 --- a/packages/shared/src/stores/GlobalSettings.ts +++ b/packages/shared/src/stores/GlobalSettings.ts | |||
@@ -22,9 +22,13 @@ import { Instance, types, SnapshotIn, SnapshotOut } from 'mobx-state-tree'; | |||
22 | 22 | ||
23 | import { ThemeSource } from '../schemas'; | 23 | import { ThemeSource } from '../schemas'; |
24 | 24 | ||
25 | const GlobalSettings = types.model('GlobalSettings', { | 25 | const GlobalSettings = /* @__PURE__ */ (() => |
26 | themeSource: types.optional(types.enumeration(ThemeSource.options), 'system'), | 26 | types.model('GlobalSettings', { |
27 | }); | 27 | themeSource: types.optional( |
28 | types.enumeration(ThemeSource.options), | ||
29 | 'system', | ||
30 | ), | ||
31 | }))(); | ||
28 | 32 | ||
29 | /* | 33 | /* |
30 | eslint-disable-next-line @typescript-eslint/no-redeclare -- | 34 | eslint-disable-next-line @typescript-eslint/no-redeclare -- |
diff --git a/packages/shared/src/stores/Profile.ts b/packages/shared/src/stores/Profile.ts index 256c33e..49c5195 100644 --- a/packages/shared/src/stores/Profile.ts +++ b/packages/shared/src/stores/Profile.ts | |||
@@ -22,10 +22,11 @@ import { Instance, types } from 'mobx-state-tree'; | |||
22 | 22 | ||
23 | import ProfileSettings from './ProfileSettings'; | 23 | import ProfileSettings from './ProfileSettings'; |
24 | 24 | ||
25 | const Profile = types.model('Profile', { | 25 | const Profile = /* @__PURE__ */ (() => |
26 | id: types.identifier, | 26 | types.model('Profile', { |
27 | settings: ProfileSettings, | 27 | id: types.identifier, |
28 | }); | 28 | settings: ProfileSettings, |
29 | }))(); | ||
29 | 30 | ||
30 | /* | 31 | /* |
31 | eslint-disable-next-line @typescript-eslint/no-redeclare -- | 32 | eslint-disable-next-line @typescript-eslint/no-redeclare -- |
diff --git a/packages/shared/src/stores/ProfileSettings.ts b/packages/shared/src/stores/ProfileSettings.ts index 9f2b27c..2ce5d73 100644 --- a/packages/shared/src/stores/ProfileSettings.ts +++ b/packages/shared/src/stores/ProfileSettings.ts | |||
@@ -20,9 +20,10 @@ | |||
20 | 20 | ||
21 | import { Instance, types, SnapshotIn, SnapshotOut } from 'mobx-state-tree'; | 21 | import { Instance, types, SnapshotIn, SnapshotOut } from 'mobx-state-tree'; |
22 | 22 | ||
23 | const ProfileSettings = types.model('ProfileSettings', { | 23 | const ProfileSettings = /* @__PURE__ */ (() => |
24 | name: types.string, | 24 | types.model('ProfileSettings', { |
25 | }); | 25 | name: types.string, |
26 | }))(); | ||
26 | 27 | ||
27 | /* | 28 | /* |
28 | eslint-disable-next-line @typescript-eslint/no-redeclare -- | 29 | eslint-disable-next-line @typescript-eslint/no-redeclare -- |
diff --git a/packages/shared/src/stores/Service.ts b/packages/shared/src/stores/Service.ts index 4a7334d..a4e3c92 100644 --- a/packages/shared/src/stores/Service.ts +++ b/packages/shared/src/stores/Service.ts | |||
@@ -22,20 +22,21 @@ import { Instance, types } from 'mobx-state-tree'; | |||
22 | 22 | ||
23 | import ServiceSettings from './ServiceSettings'; | 23 | import ServiceSettings from './ServiceSettings'; |
24 | 24 | ||
25 | const Service = types.model('Service', { | 25 | const Service = /* @__PURE__ */ (() => |
26 | id: types.identifier, | 26 | types.model('Service', { |
27 | settings: ServiceSettings, | 27 | id: types.identifier, |
28 | currentUrl: types.maybe(types.string), | 28 | settings: ServiceSettings, |
29 | canGoBack: false, | 29 | currentUrl: types.maybe(types.string), |
30 | canGoForward: false, | 30 | canGoBack: false, |
31 | title: types.maybe(types.string), | 31 | canGoForward: false, |
32 | state: types.optional( | 32 | title: types.maybe(types.string), |
33 | types.enumeration('ServiceState', ['loading', 'loaded', 'crashed']), | 33 | state: types.optional( |
34 | 'loading', | 34 | types.enumeration('ServiceState', ['loading', 'loaded', 'crashed']), |
35 | ), | 35 | 'loading', |
36 | directMessageCount: 0, | 36 | ), |
37 | indirectMessageCount: 0, | 37 | directMessageCount: 0, |
38 | }); | 38 | indirectMessageCount: 0, |
39 | }))(); | ||
39 | 40 | ||
40 | /* | 41 | /* |
41 | eslint-disable-next-line @typescript-eslint/no-redeclare -- | 42 | eslint-disable-next-line @typescript-eslint/no-redeclare -- |
diff --git a/packages/shared/src/stores/ServiceSettings.ts b/packages/shared/src/stores/ServiceSettings.ts index 6ba1dfa..a5811f5 100644 --- a/packages/shared/src/stores/ServiceSettings.ts +++ b/packages/shared/src/stores/ServiceSettings.ts | |||
@@ -22,12 +22,13 @@ import { Instance, types, SnapshotIn, SnapshotOut } from 'mobx-state-tree'; | |||
22 | 22 | ||
23 | import Profile from './Profile'; | 23 | import Profile from './Profile'; |
24 | 24 | ||
25 | const ServiceSettings = types.model('ServiceSettings', { | 25 | const ServiceSettings = /* @__PURE__ */ (() => |
26 | name: types.string, | 26 | types.model('ServiceSettings', { |
27 | profile: types.reference(Profile), | 27 | name: types.string, |
28 | // TODO: Remove this once recipes are added. | 28 | profile: types.reference(Profile), |
29 | url: types.string, | 29 | // TODO: Remove this once recipes are added. |
30 | }); | 30 | url: types.string, |
31 | }))(); | ||
31 | 32 | ||
32 | /* | 33 | /* |
33 | eslint-disable-next-line @typescript-eslint/no-redeclare -- | 34 | eslint-disable-next-line @typescript-eslint/no-redeclare -- |
diff --git a/packages/shared/src/stores/SharedStore.ts b/packages/shared/src/stores/SharedStore.ts index 0cac3a5..4e064c6 100644 --- a/packages/shared/src/stores/SharedStore.ts +++ b/packages/shared/src/stores/SharedStore.ts | |||
@@ -30,15 +30,16 @@ import GlobalSettings from './GlobalSettings'; | |||
30 | import Profile from './Profile'; | 30 | import Profile from './Profile'; |
31 | import Service from './Service'; | 31 | import Service from './Service'; |
32 | 32 | ||
33 | const SharedStore = types.model('SharedStore', { | 33 | const SharedStore = /* @__PURE__ */ (() => |
34 | settings: types.optional(GlobalSettings, {}), | 34 | types.model('SharedStore', { |
35 | profilesById: types.map(Profile), | 35 | settings: types.optional(GlobalSettings, {}), |
36 | profiles: types.array(types.reference(Profile)), | 36 | profilesById: types.map(Profile), |
37 | servicesById: types.map(Service), | 37 | profiles: types.array(types.reference(Profile)), |
38 | services: types.array(types.reference(Service)), | 38 | servicesById: types.map(Service), |
39 | selectedService: types.safeReference(Service), | 39 | services: types.array(types.reference(Service)), |
40 | shouldUseDarkColors: false, | 40 | selectedService: types.safeReference(Service), |
41 | }); | 41 | shouldUseDarkColors: false, |
42 | }))(); | ||
42 | 43 | ||
43 | /* | 44 | /* |
44 | eslint-disable-next-line @typescript-eslint/no-redeclare -- | 45 | eslint-disable-next-line @typescript-eslint/no-redeclare -- |