@squide/firefly 10.0.1 → 12.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/dist/AppRouter.d.ts +2 -1
  3. package/dist/AppRouter.js +29 -14
  4. package/dist/AppRouter.js.map +1 -1
  5. package/dist/AppRouterReducer.d.ts +3 -1
  6. package/dist/AppRouterReducer.js +12 -10
  7. package/dist/AppRouterReducer.js.map +1 -1
  8. package/dist/AppRouterStore.d.ts +13 -0
  9. package/dist/AppRouterStore.js +158 -0
  10. package/dist/AppRouterStore.js.map +1 -0
  11. package/dist/FireflyProvider.d.ts +6 -0
  12. package/dist/FireflyProvider.js +21 -0
  13. package/dist/FireflyProvider.js.map +1 -0
  14. package/dist/FireflyRuntime.d.ts +2 -0
  15. package/dist/FireflyRuntime.js +9 -0
  16. package/dist/FireflyRuntime.js.map +1 -1
  17. package/dist/index.d.ts +4 -1
  18. package/dist/index.js +7 -1
  19. package/dist/index.js.map +1 -1
  20. package/dist/initializeFirefly.d.ts +15 -0
  21. package/dist/initializeFirefly.js +78 -0
  22. package/dist/initializeFirefly.js.map +1 -0
  23. package/dist/useCanFetchProtectedData.d.ts +2 -0
  24. package/dist/useCanFetchProtectedData.js +10 -5
  25. package/dist/useCanFetchProtectedData.js.map +1 -1
  26. package/dist/useIsBootstrapping.d.ts +1 -1
  27. package/dist/useIsBootstrapping.js +3 -3
  28. package/dist/useIsBootstrapping.js.map +1 -1
  29. package/dist/useProtectedDataHandler.d.ts +1 -0
  30. package/dist/useProtectedDataHandler.js +25 -0
  31. package/dist/useProtectedDataHandler.js.map +1 -0
  32. package/dist/usePublicDataHandler.d.ts +1 -0
  33. package/dist/usePublicDataHandler.js +25 -0
  34. package/dist/usePublicDataHandler.js.map +1 -0
  35. package/package.json +5 -5
  36. package/src/AppRouter.tsx +31 -13
  37. package/src/AppRouterReducer.ts +16 -10
  38. package/src/AppRouterStore.ts +171 -0
  39. package/src/FireflyProvider.tsx +19 -0
  40. package/src/FireflyRuntime.tsx +8 -0
  41. package/src/index.ts +4 -1
  42. package/src/initializeFirefly.ts +95 -0
  43. package/src/useCanFetchProtectedData.ts +28 -12
  44. package/src/useIsBootstrapping.ts +2 -2
  45. package/src/useProtectedDataHandler.ts +12 -0
  46. package/src/usePublicDataHandler.ts +12 -0
  47. package/dist/boostrap.d.ts +0 -15
  48. package/dist/boostrap.js +0 -54
  49. package/dist/boostrap.js.map +0 -1
  50. package/src/boostrap.ts +0 -62
@@ -0,0 +1,171 @@
1
+ // This file is a low cost port of the AppRouterReducer to a non-React store. It allows, non-React parts of the library to get
2
+ // access to the state and ease the integration with third-party libraries such as the Platform Widgets.
3
+ // Eventually, AppRouterReducer should be deprecated in favor of this new AppRouterStore.
4
+
5
+ import type { RuntimeLogger } from "@squide/core";
6
+ import type { AppRouterAction, AppRouterState } from "./AppRouterReducer.ts";
7
+
8
+ export type AppRouterStoreState = Omit<AppRouterState, "waitForMsw" | "waitForPublicData" | "waitForProtectedData">;
9
+
10
+ export type AppRouterStoreListenerFunction = (store: AppRouterStore, unsuscribe: () => void) => void;
11
+
12
+ export class AppRouterStore {
13
+ #state: AppRouterStoreState;
14
+
15
+ readonly #listeners = new Set<AppRouterStoreListenerFunction>();
16
+ readonly #logger?: RuntimeLogger;
17
+
18
+ constructor(initialialState: AppRouterStoreState, logger: RuntimeLogger) {
19
+ this.#state = initialialState;
20
+ this.#logger = logger;
21
+ }
22
+
23
+ subscribe(listener: AppRouterStoreListenerFunction) {
24
+ this.#listeners.add(listener);
25
+
26
+ return () => {
27
+ this.unsuscribe(listener);
28
+ };
29
+ }
30
+
31
+ unsuscribe(listener: AppRouterStoreListenerFunction) {
32
+ this.#listeners.delete(listener);
33
+ }
34
+
35
+ dispatch(action: AppRouterAction) {
36
+ const newState = this.#reducer({ ...this.#state }, action);
37
+
38
+ this.#logger?.debug("[squide] The AppRouterStore state has been updated to:", newState);
39
+ this.#state = newState;
40
+
41
+ // Creating a copy of the listeners in case some are removed during the looping.
42
+ // To be honest, it might not be necessary, I simply don't know.
43
+ new Set(this.#listeners).forEach(x => {
44
+ x(this, () => {
45
+ this.unsuscribe(x);
46
+ });
47
+ });
48
+ }
49
+
50
+ #reducer(state: AppRouterStoreState, action: AppRouterAction) {
51
+ let newState = state;
52
+
53
+ switch (action.type) {
54
+ case "modules-registered": {
55
+ newState = {
56
+ ...newState,
57
+ areModulesRegistered: true
58
+ };
59
+
60
+ break;
61
+ }
62
+ case "modules-ready": {
63
+ newState = {
64
+ ...newState,
65
+ areModulesReady: true,
66
+ // Will be set even if the app is not using deferred registrations.
67
+ deferredRegistrationsUpdatedAt: Date.now()
68
+ };
69
+
70
+ break;
71
+ }
72
+ case "msw-ready": {
73
+ newState = {
74
+ ...newState,
75
+ isMswReady: true
76
+ };
77
+
78
+ break;
79
+ }
80
+ case "public-data-ready": {
81
+ newState = {
82
+ ...newState,
83
+ isPublicDataReady: true,
84
+ publicDataUpdatedAt: Date.now()
85
+ };
86
+
87
+ break;
88
+ }
89
+ case "protected-data-ready": {
90
+ newState = {
91
+ ...newState,
92
+ isProtectedDataReady: true,
93
+ protectedDataUpdatedAt: Date.now()
94
+ };
95
+
96
+ break;
97
+ }
98
+ case "public-data-updated": {
99
+ newState = {
100
+ ...newState,
101
+ publicDataUpdatedAt: Date.now()
102
+ };
103
+
104
+ break;
105
+ }
106
+ case "protected-data-updated": {
107
+ newState = {
108
+ ...newState,
109
+ protectedDataUpdatedAt: Date.now()
110
+ };
111
+
112
+ break;
113
+ }
114
+ case "deferred-registrations-updated": {
115
+ newState = {
116
+ ...newState,
117
+ deferredRegistrationsUpdatedAt: Date.now()
118
+ };
119
+
120
+ break;
121
+ }
122
+ case "active-route-is-public": {
123
+ newState = {
124
+ ...newState,
125
+ activeRouteVisibility: "public"
126
+ };
127
+
128
+ break;
129
+ }
130
+ case "active-route-is-protected": {
131
+ newState = {
132
+ ...newState,
133
+ activeRouteVisibility: "protected"
134
+ };
135
+
136
+ break;
137
+ }
138
+ case "is-unauthorized": {
139
+ newState = {
140
+ ...newState,
141
+ isUnauthorized: true
142
+ };
143
+
144
+ break;
145
+ }
146
+ default: {
147
+ throw new Error(`[squide] The AppRouterStore state reducer doesn't support action type "${action.type}".`);
148
+ }
149
+ }
150
+
151
+ return newState;
152
+ }
153
+
154
+ get state() {
155
+ return this.#state;
156
+ }
157
+ }
158
+
159
+ export function createAppRouterStore(logger: RuntimeLogger) {
160
+ const initialState: AppRouterStoreState = {
161
+ areModulesRegistered: false,
162
+ areModulesReady: false,
163
+ isMswReady: false,
164
+ isPublicDataReady: false,
165
+ isProtectedDataReady: false,
166
+ activeRouteVisibility: "unknown",
167
+ isUnauthorized: false
168
+ };
169
+
170
+ return new AppRouterStore(initialState, logger);
171
+ }
@@ -0,0 +1,19 @@
1
+ import { type Runtime, RuntimeContext } from "@squide/core";
2
+ import type { PropsWithChildren } from "react";
3
+
4
+ export interface FireflyProviderProps extends PropsWithChildren {
5
+ runtime: Runtime;
6
+ }
7
+
8
+ export function FireflyProvider(props: FireflyProviderProps) {
9
+ const {
10
+ runtime,
11
+ children
12
+ } = props;
13
+
14
+ return (
15
+ <RuntimeContext.Provider value={runtime}>
16
+ {children}
17
+ </RuntimeContext.Provider>
18
+ );
19
+ }
@@ -3,12 +3,14 @@ import { MswPlugin, MswPluginName } from "@squide/msw";
3
3
  import { ReactRouterRuntime, type Route } from "@squide/react-router";
4
4
  import type { RequestHandler } from "msw";
5
5
  import { getAreModulesRegistered } from "./AppRouterReducer.ts";
6
+ import { type AppRouterStore, createAppRouterStore } from "./AppRouterStore.ts";
6
7
 
7
8
  export interface FireflyRuntimeOptions extends RuntimeOptions {
8
9
  useMsw?: boolean;
9
10
  }
10
11
 
11
12
  export class FireflyRuntime extends ReactRouterRuntime {
13
+ readonly #appRouterStore: AppRouterStore;
12
14
  readonly #useMsw: boolean;
13
15
 
14
16
  constructor({ plugins, useMsw, ...options }: FireflyRuntimeOptions = {}) {
@@ -30,6 +32,8 @@ export class FireflyRuntime extends ReactRouterRuntime {
30
32
 
31
33
  this.#useMsw = false;
32
34
  }
35
+
36
+ this.#appRouterStore = createAppRouterStore(this._logger);
33
37
  }
34
38
 
35
39
  registerRequestHandlers(handlers: RequestHandler[]) {
@@ -65,6 +69,10 @@ export class FireflyRuntime extends ReactRouterRuntime {
65
69
  super.registerRoute(route, options);
66
70
  }
67
71
 
72
+ get appRouterStore() {
73
+ return this.#appRouterStore;
74
+ }
75
+
68
76
  get isMswEnabled() {
69
77
  return this.#useMsw;
70
78
  }
package/src/index.ts CHANGED
@@ -3,6 +3,7 @@ export * from "@squide/module-federation";
3
3
  export * from "@squide/msw";
4
4
  export * from "@squide/react-router";
5
5
 
6
+ export * from "./FireflyProvider.tsx";
6
7
  export * from "./FireflyRuntime.tsx";
7
8
 
8
9
  export * from "./AppRouter.tsx";
@@ -18,11 +19,13 @@ export * from "./useDeferredRegistrations.ts";
18
19
  export * from "./useIsActiveRouteProtected.ts";
19
20
  export * from "./useIsBootstrapping.ts";
20
21
  export * from "./useNavigationItems.ts";
22
+ export * from "./useProtectedDataHandler.ts";
21
23
  export * from "./useProtectedDataQueries.ts";
24
+ export * from "./usePublicDataHandler.ts";
22
25
  export * from "./usePublicDataQueries.ts";
23
26
  export * from "./useRegisterDeferredRegistrations.ts";
24
27
  export * from "./useStrictRegistrationMode.ts";
25
28
  export * from "./useUpdateDeferredRegistrations.ts";
26
29
 
27
- export * from "./boostrap.ts";
30
+ export * from "./initializeFirefly.ts";
28
31
 
@@ -0,0 +1,95 @@
1
+ import { isFunction, registerLocalModules, type ModuleRegisterFunction, type RegisterModulesOptions } from "@squide/core";
2
+ import { registerRemoteModules, type RemoteDefinition } from "@squide/module-federation";
3
+ import { setMswAsReady } from "@squide/msw";
4
+ import { FireflyRuntime, type FireflyRuntimeOptions } from "./FireflyRuntime.tsx";
5
+
6
+ export const ApplicationBootstrappingStartedEvent = "squide-app-bootstrapping-started";
7
+
8
+ export type OnInitializationErrorFunction = (error: unknown) => void;
9
+
10
+ export type StartMswFunction<TRuntime = FireflyRuntime> = (runtime: TRuntime) => Promise<void>;
11
+
12
+ export interface InitializeFireflyOptions<TRuntime extends FireflyRuntime, TContext = unknown, TData = unknown> extends RegisterModulesOptions<TContext>, FireflyRuntimeOptions {
13
+ localModules?: ModuleRegisterFunction<TRuntime, TContext, TData>[];
14
+ remotes?: RemoteDefinition[];
15
+ startMsw?: StartMswFunction<FireflyRuntime>;
16
+ onError?: OnInitializationErrorFunction;
17
+ }
18
+
19
+ function propagateRegistrationErrors(results: PromiseSettledResult<unknown[]>, onError: OnInitializationErrorFunction) {
20
+ if (results) {
21
+ if (results.status === "fulfilled") {
22
+ results.value.forEach(x => {
23
+ onError(x);
24
+ });
25
+ }
26
+ }
27
+ }
28
+
29
+ export function bootstrap<TRuntime extends FireflyRuntime = FireflyRuntime, TContext = unknown, TData = unknown>(runtime: TRuntime, options: InitializeFireflyOptions<TRuntime, TContext, TData> = {}) {
30
+ const {
31
+ localModules = [],
32
+ remotes = [],
33
+ startMsw,
34
+ onError,
35
+ context
36
+ } = options;
37
+
38
+ runtime.eventBus.dispatch(ApplicationBootstrappingStartedEvent);
39
+
40
+ Promise.allSettled([
41
+ registerLocalModules<TRuntime, TContext, TData>(localModules, runtime, { context }),
42
+ registerRemoteModules(remotes, runtime, { context })
43
+ ]).then(results => {
44
+ if (runtime.isMswEnabled) {
45
+ if (!isFunction(startMsw)) {
46
+ throw new Error("[squide] When MSW is enabled, the \"startMsw\" function must be provided.");
47
+ }
48
+
49
+ startMsw(runtime)
50
+ .then(() => {
51
+ setMswAsReady();
52
+ })
53
+ .catch((error: unknown) => {
54
+ runtime.logger.debug("[squide] An error occured while starting MSW.", error);
55
+ });
56
+ }
57
+
58
+ if (onError) {
59
+ propagateRegistrationErrors(results[0], onError);
60
+ propagateRegistrationErrors(results[1], onError);
61
+ }
62
+ });
63
+ }
64
+
65
+ let hasExecuted = false;
66
+
67
+ export function initializeFirefly<TContext = unknown, TData = unknown>(options: InitializeFireflyOptions<FireflyRuntime, TContext, TData> = {}) {
68
+ const {
69
+ mode,
70
+ useMsw,
71
+ loggers,
72
+ plugins
73
+ } = options;
74
+
75
+ if (hasExecuted) {
76
+ throw new Error("[squide] A squide application can only be initialized once. Did you call the \"initializeSquide\" function twice?");
77
+ }
78
+
79
+ hasExecuted = true;
80
+
81
+ const runtime = new FireflyRuntime({
82
+ mode,
83
+ useMsw,
84
+ loggers,
85
+ plugins
86
+ });
87
+
88
+ bootstrap(runtime, options);
89
+
90
+ return runtime;
91
+ }
92
+
93
+ export function __resetHasExecuteGuard() {
94
+ hasExecuted = false;
95
+ }
@@ -1,4 +1,25 @@
1
1
  import { useAppRouterState } from "./AppRouterContext.ts";
2
+ import type { ActiveRouteVisiblity } from "./AppRouterReducer.ts";
3
+
4
+ // This function is exported for external integration, like the integration
5
+ // with the Platform Widgets. Do not remove.
6
+ export function canFetchProtectedData(
7
+ waitForMsw: boolean,
8
+ areModulesRegistered: boolean,
9
+ areModulesReady: boolean,
10
+ activeRouteVisibility: ActiveRouteVisiblity,
11
+ isMswReady: boolean
12
+ ) {
13
+ return (
14
+ // Wait until the modules has been registered, but do not wait for the deferred registrations to be registered as they will probably
15
+ // depends on the protected data.
16
+ (areModulesRegistered || areModulesReady)
17
+ // Only fetch the protected data for protected routes, aka do not fetch the protected data for public routes.
18
+ && activeRouteVisibility === "protected"
19
+ // Wait for MSW since the endpoints for the protected data might be an MSW endpoint when in development.
20
+ && (!waitForMsw || isMswReady)
21
+ );
22
+ }
2
23
 
3
24
  export function useCanFetchProtectedData() {
4
25
  const {
@@ -10,17 +31,12 @@ export function useCanFetchProtectedData() {
10
31
  activeRouteVisibility
11
32
  } = useAppRouterState();
12
33
 
13
- return (
14
- // Always return true when the protected data has already been fetched sucessfully so TanStack Query can update the data in the background.
15
- isProtectedDataReady
16
- || (
17
- // Wait until the modules has been registered, but do not wait for the deferred registrations to be registered as they will probably
18
- // depends on the protected data.
19
- (areModulesRegistered || areModulesReady)
20
- // Only fetch the protected data for protected routes, aka do not fetch the protected data for public routes.
21
- && activeRouteVisibility === "protected"
22
- // Wait for MSW since the endpoints for the protected data might be an MSW endpoint when in development.
23
- && (!waitForMsw || isMswReady)
24
- )
34
+ // Always return true when the protected data has already been fetched sucessfully so TanStack Query can update the data in the background.
35
+ return isProtectedDataReady || canFetchProtectedData(
36
+ waitForMsw,
37
+ areModulesRegistered,
38
+ areModulesReady,
39
+ activeRouteVisibility,
40
+ isMswReady
25
41
  );
26
42
  }
@@ -4,10 +4,10 @@ import type { AppRouterState } from "./AppRouterReducer.ts";
4
4
  export function useIsBootstrapping() {
5
5
  const state = useAppRouterState();
6
6
 
7
- return isApplicationBootstrapping(state);
7
+ return isBootstrapping(state);
8
8
  }
9
9
 
10
- export function isApplicationBootstrapping(state: AppRouterState) {
10
+ export function isBootstrapping(state: AppRouterState) {
11
11
  const {
12
12
  waitForMsw,
13
13
  waitForPublicData,
@@ -0,0 +1,12 @@
1
+ import { useEffect } from "react";
2
+ import { useCanFetchProtectedData } from "./useCanFetchProtectedData.ts";
3
+
4
+ export function useProtectedDataHandler(handler: () => void) {
5
+ const canFetchProtectedData = useCanFetchProtectedData();
6
+
7
+ useEffect(() => {
8
+ if (canFetchProtectedData) {
9
+ handler();
10
+ }
11
+ }, [canFetchProtectedData, handler]);
12
+ }
@@ -0,0 +1,12 @@
1
+ import { useEffect } from "react";
2
+ import { useCanFetchPublicData } from "./useCanFetchPublicData.ts";
3
+
4
+ export function usePublicDataHandler(handler: () => void) {
5
+ const canFetchPublicData = useCanFetchPublicData();
6
+
7
+ useEffect(() => {
8
+ if (canFetchPublicData) {
9
+ handler();
10
+ }
11
+ }, [canFetchPublicData, handler]);
12
+ }
@@ -1,15 +0,0 @@
1
- import { type ModuleRegisterFunction, type ModuleRegistrationError, type RegisterModulesOptions } from "@squide/core";
2
- import { type RemoteDefinition, type RemoteModuleRegistrationError } from "@squide/module-federation";
3
- import type { FireflyRuntime } from "./FireflyRuntime.tsx";
4
- export declare const ApplicationBootstrappingStartedEvent = "squide-app-bootstrapping-started";
5
- export type StartMswFunction<TRuntime = FireflyRuntime> = (runtime: TRuntime) => Promise<void>;
6
- export interface BootstrapAppOptions<TRuntime extends FireflyRuntime = FireflyRuntime, TContext = unknown, TData = unknown> extends RegisterModulesOptions<TContext> {
7
- localModules?: ModuleRegisterFunction<TRuntime, TContext, TData>[];
8
- remotes?: RemoteDefinition[];
9
- startMsw?: StartMswFunction<TRuntime>;
10
- }
11
- export declare function bootstrap<TRuntime extends FireflyRuntime = FireflyRuntime, TContext = unknown, TData = unknown>(runtime: TRuntime, options?: BootstrapAppOptions<TRuntime, TContext, TData>): Promise<{
12
- localModuleErrors: ModuleRegistrationError[];
13
- remoteModuleErrors: RemoteModuleRegistrationError[];
14
- }>;
15
- export declare function __resetHasExecuteGuard(): void;
package/dist/boostrap.js DELETED
@@ -1,54 +0,0 @@
1
- import * as __WEBPACK_EXTERNAL_MODULE__squide_core_7a405b8f__ from "@squide/core";
2
- import * as __WEBPACK_EXTERNAL_MODULE__squide_module_federation_054d2ec6__ from "@squide/module-federation";
3
- import * as __WEBPACK_EXTERNAL_MODULE__squide_msw_9f7e76df__ from "@squide/msw";
4
-
5
- ;// CONCATENATED MODULE: external "@squide/core"
6
-
7
- ;// CONCATENATED MODULE: external "@squide/module-federation"
8
-
9
- ;// CONCATENATED MODULE: external "@squide/msw"
10
-
11
- ;// CONCATENATED MODULE: ./src/boostrap.ts?__rslib_entry__
12
-
13
-
14
-
15
- const ApplicationBootstrappingStartedEvent = "squide-app-bootstrapping-started";
16
- let hasExecuted = false;
17
- async function bootstrap(runtime, options = {}) {
18
- const { localModules = [], remotes = [], context, startMsw } = options;
19
- if (hasExecuted) {
20
- throw new Error("[squide] A squide application can only be bootstrapped once. Did you call the \"bootstrap\" function twice?");
21
- }
22
- hasExecuted = true;
23
- runtime.eventBus.dispatch(ApplicationBootstrappingStartedEvent);
24
- let localModuleErrors = [];
25
- let remoteModuleErrors = [];
26
- localModuleErrors = await (0,__WEBPACK_EXTERNAL_MODULE__squide_core_7a405b8f__.registerLocalModules)(localModules, runtime, {
27
- context
28
- });
29
- remoteModuleErrors = await (0,__WEBPACK_EXTERNAL_MODULE__squide_module_federation_054d2ec6__.registerRemoteModules)(remotes, runtime, {
30
- context
31
- });
32
- if (runtime.isMswEnabled) {
33
- if (!(0,__WEBPACK_EXTERNAL_MODULE__squide_core_7a405b8f__.isFunction)(startMsw)) {
34
- throw new Error("[squide] When MSW is enabled, the \"startMsw\" function must be provided.");
35
- }
36
- try {
37
- await startMsw(runtime);
38
- (0,__WEBPACK_EXTERNAL_MODULE__squide_msw_9f7e76df__.setMswAsReady)();
39
- } catch (error) {
40
- runtime.logger.debug("[squide] An error occured while starting MSW.", error);
41
- }
42
- }
43
- return {
44
- localModuleErrors,
45
- remoteModuleErrors
46
- };
47
- }
48
- function __resetHasExecuteGuard() {
49
- hasExecuted = false;
50
- }
51
-
52
- export { ApplicationBootstrappingStartedEvent, __resetHasExecuteGuard, bootstrap };
53
-
54
- //# sourceMappingURL=boostrap.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"boostrap.js","sources":["webpack://@squide/firefly/./src/boostrap.ts"],"sourcesContent":["import { isFunction, registerLocalModules, type ModuleRegisterFunction, type ModuleRegistrationError, type RegisterModulesOptions } from \"@squide/core\";\nimport { registerRemoteModules, type RemoteDefinition, type RemoteModuleRegistrationError } from \"@squide/module-federation\";\nimport { setMswAsReady } from \"@squide/msw\";\nimport type { FireflyRuntime } from \"./FireflyRuntime.tsx\";\n\nexport const ApplicationBootstrappingStartedEvent = \"squide-app-bootstrapping-started\";\n\nexport type StartMswFunction<TRuntime = FireflyRuntime> = (runtime: TRuntime) => Promise<void>;\n\nexport interface BootstrapAppOptions<TRuntime extends FireflyRuntime = FireflyRuntime, TContext = unknown, TData = unknown> extends RegisterModulesOptions<TContext> {\n localModules?: ModuleRegisterFunction<TRuntime, TContext, TData>[];\n remotes?: RemoteDefinition[];\n startMsw?: StartMswFunction<TRuntime>;\n}\n\nlet hasExecuted = false;\n\nexport async function bootstrap<TRuntime extends FireflyRuntime = FireflyRuntime, TContext = unknown, TData = unknown>(runtime: TRuntime, options: BootstrapAppOptions<TRuntime, TContext, TData> = {}) {\n const {\n localModules = [],\n remotes = [],\n context,\n startMsw\n } = options;\n\n if (hasExecuted) {\n throw new Error(\"[squide] A squide application can only be bootstrapped once. Did you call the \\\"bootstrap\\\" function twice?\");\n }\n\n hasExecuted = true;\n\n runtime.eventBus.dispatch(ApplicationBootstrappingStartedEvent);\n\n let localModuleErrors: ModuleRegistrationError[] = [];\n let remoteModuleErrors: RemoteModuleRegistrationError[] = [];\n\n localModuleErrors = await registerLocalModules<TRuntime, TContext, TData>(localModules, runtime, { context });\n remoteModuleErrors = await registerRemoteModules(remotes, runtime, { context });\n\n if (runtime.isMswEnabled) {\n if (!isFunction(startMsw)) {\n throw new Error(\"[squide] When MSW is enabled, the \\\"startMsw\\\" function must be provided.\");\n }\n\n try {\n await startMsw(runtime);\n\n setMswAsReady();\n } catch (error: unknown) {\n runtime.logger.debug(\"[squide] An error occured while starting MSW.\", error);\n }\n }\n\n return {\n localModuleErrors,\n remoteModuleErrors\n };\n}\n\nexport function __resetHasExecuteGuard() {\n hasExecuted = false;\n}\n"],"names":["isFunction","registerLocalModules","registerRemoteModules","setMswAsReady","ApplicationBootstrappingStartedEvent","hasExecuted","bootstrap","runtime","options","localModules","remotes","context","startMsw","Error","localModuleErrors","remoteModuleErrors","error","__resetHasExecuteGuard"],"mappings":";;;;;;;;;;;AAAwJ;AAC3B;AACjF;AAGrC,MAAMI,uCAAuC,mCAAmC;AAUvF,IAAIC,cAAc;AAEX,eAAeC,UAAiGC,OAAiB,EAAEC,UAA0D,CAAC,CAAC;IAClM,MAAM,EACFC,eAAe,EAAE,EACjBC,UAAU,EAAE,EACZC,OAAO,EACPC,QAAQ,EACX,GAAGJ;IAEJ,IAAIH,aAAa;QACb,MAAM,IAAIQ,MAAM;IACpB;IAEAR,cAAc;IAEdE,QAAQ,QAAQ,CAAC,QAAQ,CAACH;IAE1B,IAAIU,oBAA+C,EAAE;IACrD,IAAIC,qBAAsD,EAAE;IAE5DD,oBAAoB,MAAMb,0EAAoBA,CAA4BQ,cAAcF,SAAS;QAAEI;IAAQ;IAC3GI,qBAAqB,MAAMb,wFAAqBA,CAACQ,SAASH,SAAS;QAAEI;IAAQ;IAE7E,IAAIJ,QAAQ,YAAY,EAAE;QACtB,IAAI,CAACP,gEAAUA,CAACY,WAAW;YACvB,MAAM,IAAIC,MAAM;QACpB;QAEA,IAAI;YACA,MAAMD,SAASL;YAEfJ,kEAAaA;QACjB,EAAE,OAAOa,OAAgB;YACrBT,QAAQ,MAAM,CAAC,KAAK,CAAC,iDAAiDS;QAC1E;IACJ;IAEA,OAAO;QACHF;QACAC;IACJ;AACJ;AAEO,SAASE;IACZZ,cAAc;AAClB"}
package/src/boostrap.ts DELETED
@@ -1,62 +0,0 @@
1
- import { isFunction, registerLocalModules, type ModuleRegisterFunction, type ModuleRegistrationError, type RegisterModulesOptions } from "@squide/core";
2
- import { registerRemoteModules, type RemoteDefinition, type RemoteModuleRegistrationError } from "@squide/module-federation";
3
- import { setMswAsReady } from "@squide/msw";
4
- import type { FireflyRuntime } from "./FireflyRuntime.tsx";
5
-
6
- export const ApplicationBootstrappingStartedEvent = "squide-app-bootstrapping-started";
7
-
8
- export type StartMswFunction<TRuntime = FireflyRuntime> = (runtime: TRuntime) => Promise<void>;
9
-
10
- export interface BootstrapAppOptions<TRuntime extends FireflyRuntime = FireflyRuntime, TContext = unknown, TData = unknown> extends RegisterModulesOptions<TContext> {
11
- localModules?: ModuleRegisterFunction<TRuntime, TContext, TData>[];
12
- remotes?: RemoteDefinition[];
13
- startMsw?: StartMswFunction<TRuntime>;
14
- }
15
-
16
- let hasExecuted = false;
17
-
18
- export async function bootstrap<TRuntime extends FireflyRuntime = FireflyRuntime, TContext = unknown, TData = unknown>(runtime: TRuntime, options: BootstrapAppOptions<TRuntime, TContext, TData> = {}) {
19
- const {
20
- localModules = [],
21
- remotes = [],
22
- context,
23
- startMsw
24
- } = options;
25
-
26
- if (hasExecuted) {
27
- throw new Error("[squide] A squide application can only be bootstrapped once. Did you call the \"bootstrap\" function twice?");
28
- }
29
-
30
- hasExecuted = true;
31
-
32
- runtime.eventBus.dispatch(ApplicationBootstrappingStartedEvent);
33
-
34
- let localModuleErrors: ModuleRegistrationError[] = [];
35
- let remoteModuleErrors: RemoteModuleRegistrationError[] = [];
36
-
37
- localModuleErrors = await registerLocalModules<TRuntime, TContext, TData>(localModules, runtime, { context });
38
- remoteModuleErrors = await registerRemoteModules(remotes, runtime, { context });
39
-
40
- if (runtime.isMswEnabled) {
41
- if (!isFunction(startMsw)) {
42
- throw new Error("[squide] When MSW is enabled, the \"startMsw\" function must be provided.");
43
- }
44
-
45
- try {
46
- await startMsw(runtime);
47
-
48
- setMswAsReady();
49
- } catch (error: unknown) {
50
- runtime.logger.debug("[squide] An error occured while starting MSW.", error);
51
- }
52
- }
53
-
54
- return {
55
- localModuleErrors,
56
- remoteModuleErrors
57
- };
58
- }
59
-
60
- export function __resetHasExecuteGuard() {
61
- hasExecuted = false;
62
- }