aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2022-01-27 03:14:27 +0100
committerLibravatar Kristóf Marussy <kristof@marussy.com>2022-02-08 21:43:17 +0100
commit383a692042ef50be32518cff94dac9172bfb4829 (patch)
tree5b5b95bbefdc68c3c44c36f8902ad052f760fe65
parentrefactor: Extract config handling (diff)
downloadsophie-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>
-rw-r--r--packages/service-shared/esbuild.config.js2
-rw-r--r--packages/service-shared/src/schemas.ts18
-rw-r--r--packages/shared/esbuild.config.js2
-rw-r--r--packages/shared/src/schemas.ts58
-rw-r--r--packages/shared/src/stores/GlobalSettings.ts10
-rw-r--r--packages/shared/src/stores/Profile.ts9
-rw-r--r--packages/shared/src/stores/ProfileSettings.ts7
-rw-r--r--packages/shared/src/stores/Service.ts29
-rw-r--r--packages/shared/src/stores/ServiceSettings.ts13
-rw-r--r--packages/shared/src/stores/SharedStore.ts19
10 files changed, 88 insertions, 79 deletions
diff --git a/packages/service-shared/esbuild.config.js b/packages/service-shared/esbuild.config.js
index 62e3d2a..6f639e3 100644
--- a/packages/service-shared/esbuild.config.js
+++ b/packages/service-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: ['zod'], 17 external: ['zod'],
diff --git a/packages/service-shared/src/schemas.ts b/packages/service-shared/src/schemas.ts
index 0b31eb7..bb1926f 100644
--- a/packages/service-shared/src/schemas.ts
+++ b/packages/service-shared/src/schemas.ts
@@ -20,10 +20,11 @@
20 20
21import { z } from 'zod'; 21import { z } from 'zod';
22 22
23export const UnreadCount = z.object({ 23export const UnreadCount = /* @__PURE__ */ (() =>
24 direct: z.number().nonnegative().optional(), 24 z.object({
25 indirect: z.number().nonnegative().optional(), 25 direct: z.number().nonnegative().optional(),
26}); 26 indirect: z.number().nonnegative().optional(),
27 }))();
27 28
28/* 29/*
29 eslint-disable-next-line @typescript-eslint/no-redeclare -- 30 eslint-disable-next-line @typescript-eslint/no-redeclare --
@@ -31,10 +32,11 @@ export const UnreadCount = z.object({
31*/ 32*/
32export type UnreadCount = z.infer<typeof UnreadCount>; 33export type UnreadCount = z.infer<typeof UnreadCount>;
33 34
34export const WebSource = z.object({ 35export const WebSource = /* @__PURE__ */ (() =>
35 code: z.string(), 36 z.object({
36 url: z.string().nonempty(), 37 code: z.string(),
37}); 38 url: z.string().nonempty(),
39 }))();
38 40
39/* 41/*
40 eslint-disable-next-line @typescript-eslint/no-redeclare -- 42 eslint-disable-next-line @typescript-eslint/no-redeclare --
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
21import { z } from 'zod'; 21import { z } from 'zod';
22 22
23const SetSelectedServiceId = z.object({ 23export 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(),
28export 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*/
39export type BrowserViewBounds = z.infer<typeof BrowserViewBounds>; 35export type BrowserViewBounds = z.infer<typeof BrowserViewBounds>;
40 36
41const SetBrowserViewBoundsAction = z.object({ 37export const ThemeSource = /* @__PURE__ */ z.enum(['system', 'light', 'dark']);
42 action: z.literal('set-browser-view-bounds'),
43 browserViewBounds: BrowserViewBounds,
44});
45
46export 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*/
52export type ThemeSource = z.infer<typeof ThemeSource>; 43export type ThemeSource = z.infer<typeof ThemeSource>;
53 44
54const SetThemeSourceAction = z.object({ 45export 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(),
59const 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,
63export 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
23import { ThemeSource } from '../schemas'; 23import { ThemeSource } from '../schemas';
24 24
25const GlobalSettings = types.model('GlobalSettings', { 25const 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
23import ProfileSettings from './ProfileSettings'; 23import ProfileSettings from './ProfileSettings';
24 24
25const Profile = types.model('Profile', { 25const 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
21import { Instance, types, SnapshotIn, SnapshotOut } from 'mobx-state-tree'; 21import { Instance, types, SnapshotIn, SnapshotOut } from 'mobx-state-tree';
22 22
23const ProfileSettings = types.model('ProfileSettings', { 23const 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
23import ServiceSettings from './ServiceSettings'; 23import ServiceSettings from './ServiceSettings';
24 24
25const Service = types.model('Service', { 25const 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
23import Profile from './Profile'; 23import Profile from './Profile';
24 24
25const ServiceSettings = types.model('ServiceSettings', { 25const 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';
30import Profile from './Profile'; 30import Profile from './Profile';
31import Service from './Service'; 31import Service from './Service';
32 32
33const SharedStore = types.model('SharedStore', { 33const 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 --