@sanity/workbench 0.1.0-alpha.20 → 0.1.0-alpha.21
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.
- package/dist/_chunks-es/module-federation.js +59 -0
- package/dist/_chunks-es/module-federation.js.map +1 -0
- package/dist/_chunks-es/studio.js +34 -6
- package/dist/_chunks-es/studio.js.map +1 -1
- package/dist/_internal.js +1 -2
- package/dist/_internal.js.map +1 -1
- package/dist/core.d.ts +167 -55
- package/dist/core.js +1 -2
- package/dist/core.js.map +1 -1
- package/dist/system.d.ts +16 -1
- package/dist/system.js +1 -2
- package/dist/system.js.map +1 -1
- package/package.json +6 -5
- package/src/_internal/render.ts +1 -2
- package/src/core/applications/application.ts +12 -9
- package/src/core/applications/interface.ts +126 -0
- package/src/core/user-applications/core-app.ts +1 -1
- package/src/core/user-applications/studios/workspace.ts +5 -1
- package/src/core/user-applications/user-application.ts +2 -2
- package/src/system/load-federated-module.ts +1 -2
- package/src/system/module-federation.ts +116 -0
- package/src/system/remote.machine.ts +1 -1
- package/src/system/remotes.machine.ts +1 -1
- package/src/system/root.machine.ts +5 -5
- package/src/system/service.machine.ts +1 -1
- package/src/system/services.machine.ts +1 -1
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { createInstance as createMFInstance } from "@module-federation/runtime";
|
|
2
|
+
import type {
|
|
3
|
+
ModuleFederationRuntimePlugin,
|
|
4
|
+
UserOptions,
|
|
5
|
+
} from "@module-federation/runtime/types";
|
|
6
|
+
|
|
7
|
+
/** Make some properties of a type optional. */
|
|
8
|
+
type MakeOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export type FederationRemote = {
|
|
14
|
+
name: string;
|
|
15
|
+
entry: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
export type CreateInstanceOptions = MakeOptional<
|
|
22
|
+
Pick<UserOptions, "name" | "remotes" | "shared" | "plugins">,
|
|
23
|
+
"remotes" | "plugins"
|
|
24
|
+
>;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export interface FederationInstance {
|
|
30
|
+
registerRemotes(remotes: FederationRemote[]): void;
|
|
31
|
+
loadRemote<T>(id: string): Promise<T | null>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
export function createInstance(
|
|
38
|
+
options: CreateInstanceOptions,
|
|
39
|
+
): FederationInstance {
|
|
40
|
+
const instance = createMFInstance({
|
|
41
|
+
remotes: [],
|
|
42
|
+
...options,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
registerRemotes: (remotes) =>
|
|
47
|
+
instance.registerRemotes(remotes, { force: false }),
|
|
48
|
+
loadRemote: async <T>(id: string) => {
|
|
49
|
+
let remoteModule: T | null;
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
remoteModule = await instance.loadRemote<T>(id);
|
|
53
|
+
} catch (error) {
|
|
54
|
+
throw new Error(`Failed to load remote module "${id}"`, {
|
|
55
|
+
cause: error,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return remoteModule;
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Forward Module Federation lifecycle events to a provided logging function
|
|
66
|
+
* from workbench.
|
|
67
|
+
*
|
|
68
|
+
* @public
|
|
69
|
+
*/
|
|
70
|
+
export function log(
|
|
71
|
+
onDebug: (message: string, context?: Record<string, unknown>) => void,
|
|
72
|
+
): ModuleFederationRuntimePlugin {
|
|
73
|
+
const logEvent = (eventName: string, args: unknown) => {
|
|
74
|
+
// `origin` logs the whole instance, which is noisy
|
|
75
|
+
const { origin: _origin, ...data } =
|
|
76
|
+
typeof args === "object" && args !== null
|
|
77
|
+
? (args as Record<string, unknown>)
|
|
78
|
+
: { args };
|
|
79
|
+
|
|
80
|
+
onDebug(`[Lifecycle] ${eventName}`, data);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
name: "sanity-logger",
|
|
85
|
+
beforeInit(args) {
|
|
86
|
+
logEvent("beforeInit", args);
|
|
87
|
+
return args;
|
|
88
|
+
},
|
|
89
|
+
beforeRegisterRemote(args) {
|
|
90
|
+
logEvent("beforeRegisterRemote", args);
|
|
91
|
+
return args;
|
|
92
|
+
},
|
|
93
|
+
beforePreloadRemote(args) {
|
|
94
|
+
logEvent("beforePreloadRemote", args);
|
|
95
|
+
},
|
|
96
|
+
beforeRequest(args) {
|
|
97
|
+
logEvent("beforeRequest", args);
|
|
98
|
+
return args;
|
|
99
|
+
},
|
|
100
|
+
afterResolve(args) {
|
|
101
|
+
logEvent("afterResolve", args);
|
|
102
|
+
return args;
|
|
103
|
+
},
|
|
104
|
+
onLoad(args) {
|
|
105
|
+
logEvent("onLoad", args);
|
|
106
|
+
return args;
|
|
107
|
+
},
|
|
108
|
+
loadShare(args) {
|
|
109
|
+
logEvent("loadShare", args);
|
|
110
|
+
},
|
|
111
|
+
beforeLoadShare(args) {
|
|
112
|
+
logEvent("beforeLoadShare", args);
|
|
113
|
+
return args;
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { FederationInstance } from "@sanity/federation/runtime";
|
|
2
1
|
import { assign, fromPromise, sendParent, setup } from "xstate";
|
|
3
2
|
|
|
4
3
|
import { loadRemoteModule } from "./load-federated-module";
|
|
4
|
+
import type { FederationInstance } from "./module-federation";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @public
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type FederationInstance } from "@sanity/federation/runtime";
|
|
2
1
|
import { type ActorRefFrom, assign, setup } from "xstate";
|
|
3
2
|
|
|
3
|
+
import { type FederationInstance } from "./module-federation";
|
|
4
4
|
import { remoteLogic } from "./remote.machine";
|
|
5
5
|
|
|
6
6
|
/** The shared federation instance, supplied by the root machine. */
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createInstance,
|
|
3
|
-
type FederationInstance,
|
|
4
|
-
} from "@sanity/federation/runtime";
|
|
5
|
-
import { log } from "@sanity/federation/runtime/plugins/log";
|
|
6
1
|
import { createSanityInstance, type SanityInstance } from "@sanity/sdk";
|
|
7
2
|
import { raise, sendTo, setup, type ActorOptions } from "xstate";
|
|
8
3
|
|
|
9
4
|
import { logger } from "../core/log";
|
|
10
5
|
import { authLogic } from "./auth.machine";
|
|
11
6
|
import { inspect } from "./inspect";
|
|
7
|
+
import {
|
|
8
|
+
createInstance,
|
|
9
|
+
type FederationInstance,
|
|
10
|
+
log,
|
|
11
|
+
} from "./module-federation";
|
|
12
12
|
import { remotesLogic } from "./remotes.machine";
|
|
13
13
|
import { servicesLogic } from "./services.machine";
|
|
14
14
|
import {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { type FederationInstance } from "@sanity/federation/runtime";
|
|
2
1
|
import { assign, fromCallback, setup } from "xstate";
|
|
3
2
|
|
|
4
3
|
import { logger } from "../core/log";
|
|
4
|
+
import { type FederationInstance } from "./module-federation";
|
|
5
5
|
import {
|
|
6
6
|
remoteLogic,
|
|
7
7
|
type RemoteError,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type FederationInstance } from "@sanity/federation/runtime";
|
|
2
1
|
import { type ActorRefFrom, enqueueActions, setup } from "xstate";
|
|
3
2
|
|
|
3
|
+
import { type FederationInstance } from "./module-federation";
|
|
4
4
|
import { serviceLogic } from "./service.machine";
|
|
5
5
|
|
|
6
6
|
/** The shared federation instance, supplied by the root machine. */
|