@sanity/workbench-cli 2.6.0 → 2.7.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.
- package/dist/actions/build/render-remote.js +40 -52
- package/dist/actions/build/render-remote.js.map +1 -1
- package/dist/actions/build/vite/plugins/plugin-sanity-federation-runtime.js +2 -0
- package/dist/actions/build/vite/plugins/plugin-sanity-federation-runtime.js.map +1 -1
- package/package.json +5 -1
|
@@ -1,48 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Every entry
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* module from a `preamble` (its imports), the `app` expression, and, optionally,
|
|
11
|
-
* the shared HMR snippet.
|
|
12
|
-
*
|
|
13
|
-
* The render contract is
|
|
14
|
-
* `render(rootElement, props, renderOptions?: {reactStrictMode?: boolean; moduleId?: string; rootOptions?: import('react-dom/client').RootOptions})`.
|
|
15
|
-
* `rootOptions` (React's `createRoot` options — `onUncaughtError`, `onCaughtError`,
|
|
16
|
-
* `onRecoverableError`, `identifierPrefix`) is forwarded verbatim to `createRoot`
|
|
17
|
-
* and only applies when the root is first created (reused roots in `rootMap` keep
|
|
18
|
-
* the options they were created with).
|
|
19
|
-
* `moduleId` is the host's canonical federation module id (e.g. `favorites/App`,
|
|
20
|
-
* `favorites/views/list/panel`, `favorites/workers/sync`). It is provided to
|
|
21
|
-
* `App` through a `React.Context<string | undefined>` keyed per React copy (by
|
|
22
|
-
* `React.createContext`) on a global slot (`Symbol.for('sanity.os.module')`),
|
|
23
|
-
* which the SDK reads via `getDashboardModuleContext()`.
|
|
24
|
-
*/ /**
|
|
25
|
-
* Hot-reload: on an update, re-render every live root through the new module —
|
|
26
|
-
* so whatever it now binds `App` to (a recompiled component, a new studio
|
|
27
|
-
* config) takes effect without a full page reload. Stripped from prod builds.
|
|
28
|
-
*/ const HMR_REMOUNT = `if (import.meta.hot) {
|
|
2
|
+
* Every generated entry (studio, SDK app, view artifacts) shares one render body
|
|
3
|
+
* so the host can drive them all the same way; only the `App` they bind differs.
|
|
4
|
+
* The workbench host depends on `render`'s signature and return shape, so change
|
|
5
|
+
* them together.
|
|
6
|
+
*/ // Re-renders through the new module so edits apply without a page reload. The
|
|
7
|
+
// new module mounts in the foreground, so reapply the host's lifecycle. The host
|
|
8
|
+
// still holds this module's controller, so it forwards to the new one.
|
|
9
|
+
const HMR_REMOUNT = `if (import.meta.hot) {
|
|
29
10
|
import.meta.hot.accept((next) => {
|
|
30
11
|
if (!next) return
|
|
31
12
|
for (const [rootElement, args] of renderArgs) {
|
|
32
13
|
rootMap.get(rootElement)?.unmount()
|
|
33
14
|
rootMap.delete(rootElement)
|
|
34
|
-
next.render(rootElement, args.props, args.renderOptions)
|
|
15
|
+
args.next = next.render(rootElement, args.props, args.renderOptions)
|
|
16
|
+
args.next.setLifecycle(args.lifecycle)
|
|
35
17
|
}
|
|
36
18
|
})
|
|
37
19
|
}`;
|
|
38
20
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* - `app` is the expression bound to `App`; omit it when the preamble imports an
|
|
43
|
-
* `App` directly (the SDK-app entry).
|
|
44
|
-
* - `version` is an expression the host reads to check contract compatibility;
|
|
45
|
-
* omit it when the module carries no version (the studio/app entries).
|
|
21
|
+
* - `app`: omit when the preamble imports `App` itself (the SDK-app entry).
|
|
22
|
+
* - `version`: lets the host check view/service contract compatibility.
|
|
46
23
|
*/ export function renderRemote({ app, hmr = false, isolateStyles = false, preamble, version }) {
|
|
47
24
|
// Keep apps without styled-components buildable; the unused branch is removed from their bundle.
|
|
48
25
|
const stylesheetImport = isolateStyles ? "import { StyleSheetManager } from 'styled-components'" : 'const StyleSheetManager = undefined';
|
|
@@ -54,13 +31,9 @@ import { createRoot } from 'react-dom/client'
|
|
|
54
31
|
${stylesheetImport}
|
|
55
32
|
${preamble}
|
|
56
33
|
${app ? `\nconst App = ${app}\n` : ''}${version ? `\nexport const version = ${version}\n` : ''}
|
|
57
|
-
//
|
|
58
|
-
//
|
|
59
|
-
//
|
|
60
|
-
// a contract. The key is React.createContext rather than the React namespace:
|
|
61
|
-
// bundler interop (esbuild's __toESM in Vite dev pre-bundling) can hand two
|
|
62
|
-
// importers of the same React copy different namespace objects, whereas the
|
|
63
|
-
// createContext function is the same reference in both.
|
|
34
|
+
// The SDK reads this slot via getDashboardModuleContext(), so its symbol, key and
|
|
35
|
+
// value are a contract. Keyed by createContext, not the React namespace: Vite dev
|
|
36
|
+
// pre-bundling can give two importers of one React copy different namespaces.
|
|
64
37
|
const moduleSlot = (globalThis[Symbol.for('sanity.os.module')] ??= new WeakMap())
|
|
65
38
|
if (!moduleSlot.has(React.createContext)) moduleSlot.set(React.createContext, React.createContext(undefined))
|
|
66
39
|
const ModuleContext = moduleSlot.get(React.createContext)
|
|
@@ -83,21 +56,36 @@ function mount(rootElement, args) {
|
|
|
83
56
|
}
|
|
84
57
|
let element = React.createElement(ModuleContext.Provider, { value: args?.renderOptions?.moduleId }, React.createElement(App, args.props))
|
|
85
58
|
if (StyleSheetManager) element = React.createElement(StyleSheetManager, { target: styleTargets.get(rootElement) }, element)
|
|
86
|
-
|
|
59
|
+
// The host's React can't pause this root, so the host pauses the app through this Activity.
|
|
60
|
+
// Keep it inside StrictMode: outside, it stops StrictMode double-invoking effects.
|
|
61
|
+
element = React.createElement(React.Activity, { mode: args.lifecycle === 'background' ? 'hidden' : 'visible' }, element)
|
|
62
|
+
if (args?.renderOptions?.reactStrictMode) element = React.createElement(React.StrictMode, null, element)
|
|
63
|
+
root.render(element)
|
|
87
64
|
}
|
|
88
65
|
|
|
89
66
|
export function render(rootElement, props, renderOptions) {
|
|
90
|
-
const args = { props, renderOptions }
|
|
67
|
+
const args = { lifecycle: 'foreground', props, renderOptions }
|
|
91
68
|
renderArgs.set(rootElement, args)
|
|
92
69
|
mount(rootElement, args)
|
|
93
|
-
return
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
70
|
+
return {
|
|
71
|
+
dispose() {
|
|
72
|
+
const current = renderArgs.get(rootElement)
|
|
73
|
+
renderArgs.delete(rootElement)
|
|
74
|
+
if (current?.next) return current.next.dispose()
|
|
75
|
+
const root = rootMap.get(rootElement)
|
|
76
|
+
rootMap.delete(rootElement)
|
|
77
|
+
root?.unmount()
|
|
78
|
+
// Unmount first so effect cleanup can still reach this root's stylesheet.
|
|
79
|
+
styleTargets.get(rootElement)?.remove()
|
|
80
|
+
styleTargets.delete(rootElement)
|
|
81
|
+
},
|
|
82
|
+
setLifecycle(state) {
|
|
83
|
+
const current = renderArgs.get(rootElement)
|
|
84
|
+
if (!current) return
|
|
85
|
+
if (current.next) return current.next.setLifecycle(state)
|
|
86
|
+
current.lifecycle = state
|
|
87
|
+
mount(rootElement, current)
|
|
88
|
+
},
|
|
101
89
|
}
|
|
102
90
|
}${hmr ? `\n\n${HMR_REMOUNT}` : ''}
|
|
103
91
|
`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/build/render-remote.ts"],"sourcesContent":["/**\n * Every entry
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/build/render-remote.ts"],"sourcesContent":["/**\n * Every generated entry (studio, SDK app, view artifacts) shares one render body\n * so the host can drive them all the same way; only the `App` they bind differs.\n * The workbench host depends on `render`'s signature and return shape, so change\n * them together.\n */\n\n// Re-renders through the new module so edits apply without a page reload. The\n// new module mounts in the foreground, so reapply the host's lifecycle. The host\n// still holds this module's controller, so it forwards to the new one.\nconst HMR_REMOUNT = `if (import.meta.hot) {\n import.meta.hot.accept((next) => {\n if (!next) return\n for (const [rootElement, args] of renderArgs) {\n rootMap.get(rootElement)?.unmount()\n rootMap.delete(rootElement)\n args.next = next.render(rootElement, args.props, args.renderOptions)\n args.next.setLifecycle(args.lifecycle)\n }\n })\n}`\n\n/**\n * - `app`: omit when the preamble imports `App` itself (the SDK-app entry).\n * - `version`: lets the host check view/service contract compatibility.\n */\nexport function renderRemote({\n app,\n hmr = false,\n isolateStyles = false,\n preamble,\n version,\n}: {\n app?: string\n hmr?: boolean\n isolateStyles?: boolean\n preamble: string\n version?: string\n}): string {\n // Keep apps without styled-components buildable; the unused branch is removed from their bundle.\n const stylesheetImport = isolateStyles\n ? \"import { StyleSheetManager } from 'styled-components'\"\n : 'const StyleSheetManager = undefined'\n\n return `\\\n// This file is auto-generated on 'sanity build' / 'sanity dev'\n// Modifications to this file are automatically discarded\nimport * as React from 'react'\nimport { createRoot } from 'react-dom/client'\n${stylesheetImport}\n${preamble}\n${app ? `\\nconst App = ${app}\\n` : ''}${version ? `\\nexport const version = ${version}\\n` : ''}\n// The SDK reads this slot via getDashboardModuleContext(), so its symbol, key and\n// value are a contract. Keyed by createContext, not the React namespace: Vite dev\n// pre-bundling can give two importers of one React copy different namespaces.\nconst moduleSlot = (globalThis[Symbol.for('sanity.os.module')] ??= new WeakMap())\nif (!moduleSlot.has(React.createContext)) moduleSlot.set(React.createContext, React.createContext(undefined))\nconst ModuleContext = moduleSlot.get(React.createContext)\nconst rootMap = new Map()\n// A shared default sheet can overwrite another app's global rules; each root needs its own sheet.\nconst styleTargets = new Map()\nconst renderArgs = new Map()\n\nfunction mount(rootElement, args) {\n let root = rootMap.get(rootElement)\n if (!root) {\n root = createRoot(rootElement, args?.renderOptions?.rootOptions)\n rootMap.set(rootElement, root)\n if (StyleSheetManager) {\n const target = rootElement.ownerDocument.createElement('sanity-styles')\n // React can replace the mount node's contents; keep its stylesheet outside that node.\n rootElement.ownerDocument.head.appendChild(target)\n styleTargets.set(rootElement, target)\n }\n }\n let element = React.createElement(ModuleContext.Provider, { value: args?.renderOptions?.moduleId }, React.createElement(App, args.props))\n if (StyleSheetManager) element = React.createElement(StyleSheetManager, { target: styleTargets.get(rootElement) }, element)\n // The host's React can't pause this root, so the host pauses the app through this Activity.\n // Keep it inside StrictMode: outside, it stops StrictMode double-invoking effects.\n element = React.createElement(React.Activity, { mode: args.lifecycle === 'background' ? 'hidden' : 'visible' }, element)\n if (args?.renderOptions?.reactStrictMode) element = React.createElement(React.StrictMode, null, element)\n root.render(element)\n}\n\nexport function render(rootElement, props, renderOptions) {\n const args = { lifecycle: 'foreground', props, renderOptions }\n renderArgs.set(rootElement, args)\n mount(rootElement, args)\n return {\n dispose() {\n const current = renderArgs.get(rootElement)\n renderArgs.delete(rootElement)\n if (current?.next) return current.next.dispose()\n const root = rootMap.get(rootElement)\n rootMap.delete(rootElement)\n root?.unmount()\n // Unmount first so effect cleanup can still reach this root's stylesheet.\n styleTargets.get(rootElement)?.remove()\n styleTargets.delete(rootElement)\n },\n setLifecycle(state) {\n const current = renderArgs.get(rootElement)\n if (!current) return\n if (current.next) return current.next.setLifecycle(state)\n current.lifecycle = state\n mount(rootElement, current)\n },\n }\n}${hmr ? `\\n\\n${HMR_REMOUNT}` : ''}\n`\n}\n"],"names":["HMR_REMOUNT","renderRemote","app","hmr","isolateStyles","preamble","version","stylesheetImport"],"mappings":"AAAA;;;;;CAKC,GAED,8EAA8E;AAC9E,iFAAiF;AACjF,uEAAuE;AACvE,MAAMA,cAAc,CAAC;;;;;;;;;;CAUpB,CAAC;AAEF;;;CAGC,GACD,OAAO,SAASC,aAAa,EAC3BC,GAAG,EACHC,MAAM,KAAK,EACXC,gBAAgB,KAAK,EACrBC,QAAQ,EACRC,OAAO,EAOR;IACC,iGAAiG;IACjG,MAAMC,mBAAmBH,gBACrB,0DACA;IAEJ,OAAO,CAAC;;;;;AAKV,EAAEG,iBAAiB;AACnB,EAAEF,SAAS;AACX,EAAEH,MAAM,CAAC,cAAc,EAAEA,IAAI,EAAE,CAAC,GAAG,KAAKI,UAAU,CAAC,yBAAyB,EAAEA,QAAQ,EAAE,CAAC,GAAG,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyD9F,EAAEH,MAAM,CAAC,IAAI,EAAEH,aAAa,GAAG,GAAG;AACnC,CAAC;AACD"}
|
|
@@ -25,6 +25,8 @@ const appEntry = (isolateStyles)=>renderRemote({
|
|
|
25
25
|
// has no navigable full-page view, so there's no `App` to import. The runtime
|
|
26
26
|
// still needs a valid module for the federation build input, but it exposes no
|
|
27
27
|
// `./App` (see `plugin.ts`) — its `render` is unreachable and throws if reached.
|
|
28
|
+
// It renders no React tree, so it carries no lifecycle controller: there is
|
|
29
|
+
// nothing to pause.
|
|
28
30
|
const HEADLESS_APP_ENTRY = `\
|
|
29
31
|
// This file is auto-generated on 'sanity dev'
|
|
30
32
|
// Modifications to this file are automatically discarded
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/actions/build/vite/plugins/plugin-sanity-federation-runtime.ts"],"sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\n\nimport {type EnvironmentModuleNode, type Plugin} from 'vite'\n\nimport {renderRemote} from '../../render-remote.js'\nimport {\n RESOURCE_BINDINGS_ENTRY_IMPORT,\n RESOURCE_BINDINGS_FILENAME,\n RESOURCE_BINDINGS_MODULE_SOURCE,\n} from '../../resource-bindings.js'\nimport {FEDERATION_FILE_NAME, RUNTIME_DIR} from '../constants.js'\nimport {getFederationApi} from './plugin-module-federation.js'\n\nconst REMOTE_ENTRY_FILE = `${FEDERATION_FILE_NAME}.jsx`\n\n// The studio wraps `Studio` with the user's config; HMR re-renders through the\n// new module so a config edit takes effect. The `%RESOURCE_BINDINGS_IMPORT%`\n// placeholder is filled in per-build (Blueprints only — see below).\nconst studioEntry = (isolateStyles: boolean) =>\n renderRemote({\n app: `(props) => React.createElement(Studio, { config, ...props })`,\n hmr: true,\n isolateStyles,\n preamble: `%RESOURCE_BINDINGS_IMPORT%import { Studio } from 'sanity'\nimport config from %STUDIO_CONFIG%`,\n })\n\n// An SDK app's default export is the component; it Fast-Refreshes through its\n// own dev server, so the wrapper needs no HMR boundary.\nconst appEntry = (isolateStyles: boolean) =>\n renderRemote({\n isolateStyles,\n preamble: `%RESOURCE_BINDINGS_IMPORT%import App from %APP_ENTRY%`,\n })\n\n// A branded app that declares no `entry` (e.g. a dock-only panel/worker app)\n// has no navigable full-page view, so there's no `App` to import. The runtime\n// still needs a valid module for the federation build input, but it exposes no\n// `./App` (see `plugin.ts`) — its `render` is unreachable and throws if reached.\nconst HEADLESS_APP_ENTRY = `\\\n// This file is auto-generated on 'sanity dev'\n// Modifications to this file are automatically discarded\n// This application declares no app view (no \\`entry\\`): it isn't navigable as a\n// full-page app, only its panels/web workers are exposed.\n%RESOURCE_BINDINGS_IMPORT%export function render() {\n throw new Error('This application has no app view: it declares no \\`entry\\`.')\n}\n`\n\nexport type FederationRuntimeOptions =\n | {appEntry?: string; isApp: true; isBlueprints?: boolean}\n | {isApp: false; isBlueprints?: boolean; studioConfigPath: string}\n\nfunction renderEntry(options: FederationRuntimeOptions, isolateStyles: boolean): string {\n const {isBlueprints} = options\n\n let content: string\n if (options.isApp) {\n content = options.appEntry\n ? appEntry(isolateStyles).replace(/%APP_ENTRY%/, JSON.stringify(options.appEntry))\n : HEADLESS_APP_ENTRY\n } else {\n content = studioEntry(isolateStyles).replace(\n /%STUDIO_CONFIG%/,\n JSON.stringify(options.studioConfigPath),\n )\n }\n\n // Blueprints only: the remote entry statically imports the resource-bindings\n // module first, so bindings evaluate before app code. Off Blueprints the\n // placeholder resolves to nothing and the module is neither imported nor\n // written below.\n return content.replace(\n /%RESOURCE_BINDINGS_IMPORT%/,\n isBlueprints ? `${RESOURCE_BINDINGS_ENTRY_IMPORT}\\n` : '',\n )\n}\n\nexport function sanityFederationRuntime(options: FederationRuntimeOptions): Plugin {\n const {isBlueprints} = options\n let entryFileAbsPath = ''\n\n return {\n configResolved(config) {\n const dir = path.resolve(config.root, RUNTIME_DIR)\n entryFileAbsPath = path.join(dir, REMOTE_ENTRY_FILE)\n\n fs.mkdirSync(dir, {recursive: true})\n const isolateStyles = getFederationApi(config.plugins)?.isolateStyles ?? false\n fs.writeFileSync(entryFileAbsPath, renderEntry(options, isolateStyles))\n\n if (isBlueprints) {\n // Brett bakes the resolved values into this module at deploy.\n fs.writeFileSync(\n path.join(dir, RESOURCE_BINDINGS_FILENAME),\n RESOURCE_BINDINGS_MODULE_SOURCE,\n )\n }\n },\n hotUpdate({file, modules, timestamp}) {\n if (options.isApp) return\n if (this.environment.name !== 'client') return\n\n const {moduleGraph} = this.environment\n const studioMods = moduleGraph.getModulesByFile(entryFileAbsPath)\n if (!studioMods?.size) return\n\n // Is the changed file reachable from the studio entry?\n const visited = new Set<EnvironmentModuleNode>()\n const queue: EnvironmentModuleNode[] = [...studioMods]\n while (queue.length > 0) {\n const mod = queue.pop()!\n if (visited.has(mod)) continue\n visited.add(mod)\n if (mod.file === file) {\n // The walk from `file` up through importers dead-ends at federation\n // gaps, so invalidate changed modules ourselves and route HMR to the\n // self-accepting studio entry.\n const seen = new Set<EnvironmentModuleNode>()\n for (const m of modules) {\n moduleGraph.invalidateModule(m, seen, timestamp, true)\n }\n return [...studioMods]\n }\n for (const dep of mod.importedModules) queue.push(dep)\n }\n },\n name: 'sanity/federation-runtime',\n }\n}\n"],"names":["fs","path","renderRemote","RESOURCE_BINDINGS_ENTRY_IMPORT","RESOURCE_BINDINGS_FILENAME","RESOURCE_BINDINGS_MODULE_SOURCE","FEDERATION_FILE_NAME","RUNTIME_DIR","getFederationApi","REMOTE_ENTRY_FILE","studioEntry","isolateStyles","app","hmr","preamble","appEntry","HEADLESS_APP_ENTRY","renderEntry","options","isBlueprints","content","isApp","replace","JSON","stringify","studioConfigPath","sanityFederationRuntime","entryFileAbsPath","configResolved","config","dir","resolve","root","join","mkdirSync","recursive","plugins","writeFileSync","hotUpdate","file","modules","timestamp","environment","name","moduleGraph","studioMods","getModulesByFile","size","visited","Set","queue","length","mod","pop","has","add","seen","m","invalidateModule","dep","importedModules","push"],"mappings":"AAAA,OAAOA,QAAQ,UAAS;AACxB,OAAOC,UAA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AI,CAACF;YACpD;QACF;QACAhB,MAAM;IACR;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/actions/build/vite/plugins/plugin-sanity-federation-runtime.ts"],"sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\n\nimport {type EnvironmentModuleNode, type Plugin} from 'vite'\n\nimport {renderRemote} from '../../render-remote.js'\nimport {\n RESOURCE_BINDINGS_ENTRY_IMPORT,\n RESOURCE_BINDINGS_FILENAME,\n RESOURCE_BINDINGS_MODULE_SOURCE,\n} from '../../resource-bindings.js'\nimport {FEDERATION_FILE_NAME, RUNTIME_DIR} from '../constants.js'\nimport {getFederationApi} from './plugin-module-federation.js'\n\nconst REMOTE_ENTRY_FILE = `${FEDERATION_FILE_NAME}.jsx`\n\n// The studio wraps `Studio` with the user's config; HMR re-renders through the\n// new module so a config edit takes effect. The `%RESOURCE_BINDINGS_IMPORT%`\n// placeholder is filled in per-build (Blueprints only — see below).\nconst studioEntry = (isolateStyles: boolean) =>\n renderRemote({\n app: `(props) => React.createElement(Studio, { config, ...props })`,\n hmr: true,\n isolateStyles,\n preamble: `%RESOURCE_BINDINGS_IMPORT%import { Studio } from 'sanity'\nimport config from %STUDIO_CONFIG%`,\n })\n\n// An SDK app's default export is the component; it Fast-Refreshes through its\n// own dev server, so the wrapper needs no HMR boundary.\nconst appEntry = (isolateStyles: boolean) =>\n renderRemote({\n isolateStyles,\n preamble: `%RESOURCE_BINDINGS_IMPORT%import App from %APP_ENTRY%`,\n })\n\n// A branded app that declares no `entry` (e.g. a dock-only panel/worker app)\n// has no navigable full-page view, so there's no `App` to import. The runtime\n// still needs a valid module for the federation build input, but it exposes no\n// `./App` (see `plugin.ts`) — its `render` is unreachable and throws if reached.\n// It renders no React tree, so it carries no lifecycle controller: there is\n// nothing to pause.\nconst HEADLESS_APP_ENTRY = `\\\n// This file is auto-generated on 'sanity dev'\n// Modifications to this file are automatically discarded\n// This application declares no app view (no \\`entry\\`): it isn't navigable as a\n// full-page app, only its panels/web workers are exposed.\n%RESOURCE_BINDINGS_IMPORT%export function render() {\n throw new Error('This application has no app view: it declares no \\`entry\\`.')\n}\n`\n\nexport type FederationRuntimeOptions =\n | {appEntry?: string; isApp: true; isBlueprints?: boolean}\n | {isApp: false; isBlueprints?: boolean; studioConfigPath: string}\n\nfunction renderEntry(options: FederationRuntimeOptions, isolateStyles: boolean): string {\n const {isBlueprints} = options\n\n let content: string\n if (options.isApp) {\n content = options.appEntry\n ? appEntry(isolateStyles).replace(/%APP_ENTRY%/, JSON.stringify(options.appEntry))\n : HEADLESS_APP_ENTRY\n } else {\n content = studioEntry(isolateStyles).replace(\n /%STUDIO_CONFIG%/,\n JSON.stringify(options.studioConfigPath),\n )\n }\n\n // Blueprints only: the remote entry statically imports the resource-bindings\n // module first, so bindings evaluate before app code. Off Blueprints the\n // placeholder resolves to nothing and the module is neither imported nor\n // written below.\n return content.replace(\n /%RESOURCE_BINDINGS_IMPORT%/,\n isBlueprints ? `${RESOURCE_BINDINGS_ENTRY_IMPORT}\\n` : '',\n )\n}\n\nexport function sanityFederationRuntime(options: FederationRuntimeOptions): Plugin {\n const {isBlueprints} = options\n let entryFileAbsPath = ''\n\n return {\n configResolved(config) {\n const dir = path.resolve(config.root, RUNTIME_DIR)\n entryFileAbsPath = path.join(dir, REMOTE_ENTRY_FILE)\n\n fs.mkdirSync(dir, {recursive: true})\n const isolateStyles = getFederationApi(config.plugins)?.isolateStyles ?? false\n fs.writeFileSync(entryFileAbsPath, renderEntry(options, isolateStyles))\n\n if (isBlueprints) {\n // Brett bakes the resolved values into this module at deploy.\n fs.writeFileSync(\n path.join(dir, RESOURCE_BINDINGS_FILENAME),\n RESOURCE_BINDINGS_MODULE_SOURCE,\n )\n }\n },\n hotUpdate({file, modules, timestamp}) {\n if (options.isApp) return\n if (this.environment.name !== 'client') return\n\n const {moduleGraph} = this.environment\n const studioMods = moduleGraph.getModulesByFile(entryFileAbsPath)\n if (!studioMods?.size) return\n\n // Is the changed file reachable from the studio entry?\n const visited = new Set<EnvironmentModuleNode>()\n const queue: EnvironmentModuleNode[] = [...studioMods]\n while (queue.length > 0) {\n const mod = queue.pop()!\n if (visited.has(mod)) continue\n visited.add(mod)\n if (mod.file === file) {\n // The walk from `file` up through importers dead-ends at federation\n // gaps, so invalidate changed modules ourselves and route HMR to the\n // self-accepting studio entry.\n const seen = new Set<EnvironmentModuleNode>()\n for (const m of modules) {\n moduleGraph.invalidateModule(m, seen, timestamp, true)\n }\n return [...studioMods]\n }\n for (const dep of mod.importedModules) queue.push(dep)\n }\n },\n name: 'sanity/federation-runtime',\n }\n}\n"],"names":["fs","path","renderRemote","RESOURCE_BINDINGS_ENTRY_IMPORT","RESOURCE_BINDINGS_FILENAME","RESOURCE_BINDINGS_MODULE_SOURCE","FEDERATION_FILE_NAME","RUNTIME_DIR","getFederationApi","REMOTE_ENTRY_FILE","studioEntry","isolateStyles","app","hmr","preamble","appEntry","HEADLESS_APP_ENTRY","renderEntry","options","isBlueprints","content","isApp","replace","JSON","stringify","studioConfigPath","sanityFederationRuntime","entryFileAbsPath","configResolved","config","dir","resolve","root","join","mkdirSync","recursive","plugins","writeFileSync","hotUpdate","file","modules","timestamp","environment","name","moduleGraph","studioMods","getModulesByFile","size","visited","Set","queue","length","mod","pop","has","add","seen","m","invalidateModule","dep","importedModules","push"],"mappings":"AAAA,OAAOA,QAAQ,UAAS;AACxB,OAAOC,UAAU,YAAW;AAI5B,SAAQC,YAAY,QAAO,yBAAwB;AACnD,SACEC,8BAA8B,EAC9BC,0BAA0B,EAC1BC,+BAA+B,QAC1B,6BAA4B;AACnC,SAAQC,oBAAoB,EAAEC,WAAW,QAAO,kBAAiB;AACjE,SAAQC,gBAAgB,QAAO,gCAA+B;AAE9D,MAAMC,oBAAoB,GAAGH,qBAAqB,IAAI,CAAC;AAEvD,+EAA+E;AAC/E,6EAA6E;AAC7E,oEAAoE;AACpE,MAAMI,cAAc,CAACC,gBACnBT,aAAa;QACXU,KAAK,CAAC,4DAA4D,CA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c;gBAChB,8DAA8D;gBAC9DnB,GAAGqC,aAAa,CACdpC,KAAKgC,IAAI,CAACH,KAAK1B,6BACfC;YAEJ;QACF;QACAiC,WAAU,EAACC,IAAI,EAAEC,OAAO,EAAEC,SAAS,EAAC;YAClC,IAAIvB,QAAQG,KAAK,EAAE;YACnB,IAAI,IAAI,CAACqB,WAAW,CAACC,IAAI,KAAK,UAAU;YAExC,MAAM,EAACC,WAAW,EAAC,GAAG,IAAI,CAACF,WAAW;YACtC,MAAMG,aAAaD,YAAYE,gBAAgB,CAACnB;YAChD,IAAI,CAACkB,YAAYE,MAAM;YAEvB,uDAAuD;YACvD,MAAMC,UAAU,IAAIC;YACpB,MAAMC,QAAiC;mBAAIL;aAAW;YACtD,MAAOK,MAAMC,MAAM,GAAG,EAAG;gBACvB,MAAMC,MAAMF,MAAMG,GAAG;gBACrB,IAAIL,QAAQM,GAAG,CAACF,MAAM;gBACtBJ,QAAQO,GAAG,CAACH;gBACZ,IAAIA,IAAIb,IAAI,KAAKA,MAAM;oBACrB,oEAAoE;oBACpE,qEAAqE;oBACrE,+BAA+B;oBAC/B,MAAMiB,OAAO,IAAIP;oBACjB,KAAK,MAAMQ,KAAKjB,QAAS;wBACvBI,YAAYc,gBAAgB,CAACD,GAAGD,MAAMf,WAAW;oBACnD;oBACA,OAAO;2BAAII;qBAAW;gBACxB;gBACA,KAAK,MAAMc,OAAOP,IAAIQ,eAAe,CAAEV,MAAMW,IAAI,CAACF;YACpD;QACF;QACAhB,MAAM;IACR;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/workbench-cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0",
|
|
4
4
|
"description": "Internal implementation detail of the Sanity CLI's unstable workbench support. Not intended for direct use.",
|
|
5
5
|
"homepage": "https://github.com/sanity-io/cli",
|
|
6
6
|
"bugs": "https://github.com/sanity-io/cli/issues",
|
|
@@ -79,10 +79,14 @@
|
|
|
79
79
|
"@swc/cli": "^0.8.1",
|
|
80
80
|
"@swc/core": "^1.15.43",
|
|
81
81
|
"@types/node": "^22.20.0",
|
|
82
|
+
"@types/react": "^19.2.17",
|
|
82
83
|
"@types/semver": "^7.7.1",
|
|
83
84
|
"@vitest/coverage-istanbul": "^4.1.11",
|
|
84
85
|
"eslint": "^10.7.0",
|
|
86
|
+
"jsdom": "^29.1.1",
|
|
85
87
|
"publint": "^0.3.21",
|
|
88
|
+
"react": "^19.2.7",
|
|
89
|
+
"react-dom": "^19.2.7",
|
|
86
90
|
"typescript": "^6.0.3",
|
|
87
91
|
"vitest": "^4.1.11"
|
|
88
92
|
},
|