@sanity/workbench-cli 2.9.0 → 2.10.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/_exports/build.d.ts +2 -2
- package/dist/_exports/build.js +1 -1
- package/dist/_exports/build.js.map +1 -1
- package/dist/_exports/deploy.d.ts +2 -2
- package/dist/_exports/{resolveWorkbenchConfig-s3msa3Hu.d.ts → resolveWorkbenchConfig-DEttN7ks.d.ts} +7 -2
- package/dist/_exports/{summarizeInterfaces-C0TCOa0J.d.ts → summarizeInterfaces-Co97VU2z.d.ts} +2 -2
- package/dist/_exports/undeploy.d.ts +2 -2
- package/dist/actions/build/artifact.js +3 -3
- package/dist/actions/build/artifact.js.map +1 -1
- package/dist/actions/build/configs/artifact.js +70 -5
- package/dist/actions/build/configs/artifact.js.map +1 -1
- package/dist/actions/build/configs/configApp.js +15 -0
- package/dist/actions/build/configs/configApp.js.map +1 -0
- package/dist/actions/build/configs/mediaLibraryIslandRuntime.js +25 -0
- package/dist/actions/build/configs/mediaLibraryIslandRuntime.js.map +1 -0
- package/dist/actions/build/vite/optimize-deps.js +11 -1
- package/dist/actions/build/vite/optimize-deps.js.map +1 -1
- package/dist/actions/build/vite/plugin.js +15 -1
- package/dist/actions/build/vite/plugin.js.map +1 -1
- package/dist/actions/build/vite/plugins/plugin-strip-sui-global-reset.js +82 -0
- package/dist/actions/build/vite/plugins/plugin-strip-sui-global-reset.js.map +1 -0
- package/dist/actions/build/vite/workbench-vite-plugins.js +13 -2
- package/dist/actions/build/vite/workbench-vite-plugins.js.map +1 -1
- package/dist/resolveWorkbenchApp.js +16 -0
- package/dist/resolveWorkbenchApp.js.map +1 -1
- package/package.json +3 -3
package/dist/_exports/build.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as resolveAppEntry, i as WorkbenchExposes, n as resolveWorkbenchConfig, o as resolveWorkbenchApp, r as ResolvedWorkbenchApp, t as ResolvedMediaLibraryConfig } from "./resolveWorkbenchConfig-DEttN7ks.js";
|
|
2
2
|
import { InlineConfig, PluginOption } from "vite";
|
|
3
3
|
/**
|
|
4
4
|
* Resource bindings ride in a dedicated module in the app's bundle rather than an
|
|
@@ -114,5 +114,5 @@ declare function workbenchVitePlugins(options: WorkbenchViteOptions): Promise<Pl
|
|
|
114
114
|
* its own id from the applications API.
|
|
115
115
|
*/
|
|
116
116
|
declare function buildAppId(app: ResolvedWorkbenchApp): Promise<string>;
|
|
117
|
-
export { RESOURCE_BINDINGS_CHUNK_NAME, RESOURCE_BINDINGS_ENTRY_IMPORT, RESOURCE_BINDINGS_FILENAME, RESOURCE_BINDINGS_MODULE_SOURCE, RESOURCE_BINDINGS_TOKEN, type ResolvedMediaLibraryConfig, type WorkbenchExposes, buildAppId, buildFederatedApp, resolveWorkbenchApp, resolveWorkbenchConfig, resourceBindingsChunkFileName, resourceBindingsCodeSplittingGroup, workbenchOptimizeDeps, workbenchVitePlugins };
|
|
117
|
+
export { RESOURCE_BINDINGS_CHUNK_NAME, RESOURCE_BINDINGS_ENTRY_IMPORT, RESOURCE_BINDINGS_FILENAME, RESOURCE_BINDINGS_MODULE_SOURCE, RESOURCE_BINDINGS_TOKEN, type ResolvedMediaLibraryConfig, type WorkbenchExposes, buildAppId, buildFederatedApp, resolveAppEntry, resolveWorkbenchApp, resolveWorkbenchConfig, resourceBindingsChunkFileName, resourceBindingsCodeSplittingGroup, workbenchOptimizeDeps, workbenchVitePlugins };
|
|
118
118
|
//# sourceMappingURL=build.d.ts.map
|
package/dist/_exports/build.js
CHANGED
|
@@ -8,7 +8,7 @@ export { buildFederatedApp } from '../actions/build/vite/discover-shared-depende
|
|
|
8
8
|
export { workbenchOptimizeDeps } from '../actions/build/vite/optimize-deps.js';
|
|
9
9
|
export { workbenchVitePlugins } from '../actions/build/vite/workbench-vite-plugins.js';
|
|
10
10
|
export { buildAppId } from '../appId.js';
|
|
11
|
-
export { resolveWorkbenchApp } from '../resolveWorkbenchApp.js';
|
|
11
|
+
export { resolveAppEntry, resolveWorkbenchApp } from '../resolveWorkbenchApp.js';
|
|
12
12
|
export { resolveWorkbenchConfig } from '../resolveWorkbenchConfig.js';
|
|
13
13
|
|
|
14
14
|
//# sourceMappingURL=build.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/_exports/build.ts"],"sourcesContent":["// Node-only build entry: the module-federation Vite plugins that\n// `@sanity/cli-build`'s `getViteConfig` swaps in for a workbench app, plus the\n// resolver the build reads declared views/web workers from. The build needs no\n// deploy-time guards, so it takes the bare `resolveWorkbenchApp` — the guarded\n// view (`getWorkbench`) is the deploy entry's export.\n\nexport {\n RESOURCE_BINDINGS_CHUNK_NAME,\n RESOURCE_BINDINGS_ENTRY_IMPORT,\n RESOURCE_BINDINGS_FILENAME,\n RESOURCE_BINDINGS_MODULE_SOURCE,\n RESOURCE_BINDINGS_TOKEN,\n resourceBindingsChunkFileName,\n resourceBindingsCodeSplittingGroup,\n} from '../actions/build/resource-bindings.js'\nexport {buildFederatedApp} from '../actions/build/vite/discover-shared-dependencies.js'\nexport {workbenchOptimizeDeps} from '../actions/build/vite/optimize-deps.js'\nexport {workbenchVitePlugins} from '../actions/build/vite/workbench-vite-plugins.js'\nexport {buildAppId} from '../appId.js'\nexport {resolveWorkbenchApp
|
|
1
|
+
{"version":3,"sources":["../../src/_exports/build.ts"],"sourcesContent":["// Node-only build entry: the module-federation Vite plugins that\n// `@sanity/cli-build`'s `getViteConfig` swaps in for a workbench app, plus the\n// resolver the build reads declared views/web workers from. The build needs no\n// deploy-time guards, so it takes the bare `resolveWorkbenchApp` — the guarded\n// view (`getWorkbench`) is the deploy entry's export.\n\nexport {\n RESOURCE_BINDINGS_CHUNK_NAME,\n RESOURCE_BINDINGS_ENTRY_IMPORT,\n RESOURCE_BINDINGS_FILENAME,\n RESOURCE_BINDINGS_MODULE_SOURCE,\n RESOURCE_BINDINGS_TOKEN,\n resourceBindingsChunkFileName,\n resourceBindingsCodeSplittingGroup,\n} from '../actions/build/resource-bindings.js'\nexport {buildFederatedApp} from '../actions/build/vite/discover-shared-dependencies.js'\nexport {workbenchOptimizeDeps} from '../actions/build/vite/optimize-deps.js'\nexport {workbenchVitePlugins} from '../actions/build/vite/workbench-vite-plugins.js'\nexport {buildAppId} from '../appId.js'\nexport {\n resolveAppEntry,\n resolveWorkbenchApp,\n type WorkbenchExposes,\n} from '../resolveWorkbenchApp.js'\nexport {type ResolvedMediaLibraryConfig, resolveWorkbenchConfig} from '../resolveWorkbenchConfig.js'\n"],"names":["RESOURCE_BINDINGS_CHUNK_NAME","RESOURCE_BINDINGS_ENTRY_IMPORT","RESOURCE_BINDINGS_FILENAME","RESOURCE_BINDINGS_MODULE_SOURCE","RESOURCE_BINDINGS_TOKEN","resourceBindingsChunkFileName","resourceBindingsCodeSplittingGroup","buildFederatedApp","workbenchOptimizeDeps","workbenchVitePlugins","buildAppId","resolveAppEntry","resolveWorkbenchApp","resolveWorkbenchConfig"],"mappings":"AAAA,iEAAiE;AACjE,+EAA+E;AAC/E,+EAA+E;AAC/E,+EAA+E;AAC/E,sDAAsD;AAEtD,SACEA,4BAA4B,EAC5BC,8BAA8B,EAC9BC,0BAA0B,EAC1BC,+BAA+B,EAC/BC,uBAAuB,EACvBC,6BAA6B,EAC7BC,kCAAkC,QAC7B,wCAAuC;AAC9C,SAAQC,iBAAiB,QAAO,wDAAuD;AACvF,SAAQC,qBAAqB,QAAO,yCAAwC;AAC5E,SAAQC,oBAAoB,QAAO,kDAAiD;AACpF,SAAQC,UAAU,QAAO,cAAa;AACtC,SACEC,eAAe,EACfC,mBAAmB,QAEd,4BAA2B;AAClC,SAAyCC,sBAAsB,QAAO,+BAA8B"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "./contract-D_HnLQtT.js";
|
|
2
|
-
import { n as resolveWorkbenchConfig, t as ResolvedMediaLibraryConfig } from "./resolveWorkbenchConfig-
|
|
3
|
-
import { a as DeployableWorkbenchApp, i as summarizeInterfaces, n as DeployedView, o as getWorkbench, r as DeployedWebWorker, t as DeployedInterface } from "./summarizeInterfaces-
|
|
2
|
+
import { n as resolveWorkbenchConfig, t as ResolvedMediaLibraryConfig } from "./resolveWorkbenchConfig-DEttN7ks.js";
|
|
3
|
+
import { a as DeployableWorkbenchApp, i as summarizeInterfaces, n as DeployedView, o as getWorkbench, r as DeployedWebWorker, t as DeployedInterface } from "./summarizeInterfaces-Co97VU2z.js";
|
|
4
4
|
import { AppVisibility, CliConfig, Output } from "@sanity/cli-core";
|
|
5
5
|
import "node:zlib";
|
|
6
6
|
/**
|
package/dist/_exports/{resolveWorkbenchConfig-s3msa3Hu.d.ts → resolveWorkbenchConfig-DEttN7ks.d.ts}
RENAMED
|
@@ -37,6 +37,11 @@ interface ResolvedWorkbenchApp {
|
|
|
37
37
|
/** Dashboard visibility declared by the app; `undefined` when unset. */
|
|
38
38
|
readonly visibility?: AppVisibility;
|
|
39
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* The module behind the app's `./App` expose. `entry` is shorthand for a window view.
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
declare function resolveAppEntry(app: CliConfig['app']): string | undefined;
|
|
40
45
|
/**
|
|
41
46
|
* Resolve the workbench app for a CLI config, or `null` for a plain project or a
|
|
42
47
|
* config (which is not an app — read it with `resolveWorkbenchConfig`).
|
|
@@ -59,5 +64,5 @@ interface ResolvedMediaLibraryConfig {
|
|
|
59
64
|
* @public
|
|
60
65
|
*/
|
|
61
66
|
declare function resolveWorkbenchConfig(cliConfig: CliConfig | null | undefined): ResolvedMediaLibraryConfig | null;
|
|
62
|
-
export {
|
|
63
|
-
//# sourceMappingURL=resolveWorkbenchConfig-
|
|
67
|
+
export { resolveAppEntry as a, WorkbenchExposes as i, resolveWorkbenchConfig as n, resolveWorkbenchApp as o, ResolvedWorkbenchApp as r, ResolvedMediaLibraryConfig as t };
|
|
68
|
+
//# sourceMappingURL=resolveWorkbenchConfig-DEttN7ks.d.ts.map
|
package/dist/_exports/{summarizeInterfaces-C0TCOa0J.d.ts → summarizeInterfaces-Co97VU2z.d.ts}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { _ as ViewSurface, u as ServiceType } from "./contract-D_HnLQtT.js";
|
|
2
|
-
import { i as WorkbenchExposes, r as ResolvedWorkbenchApp } from "./resolveWorkbenchConfig-
|
|
2
|
+
import { i as WorkbenchExposes, r as ResolvedWorkbenchApp } from "./resolveWorkbenchConfig-DEttN7ks.js";
|
|
3
3
|
import { z } from "zod/mini";
|
|
4
4
|
import { CliConfig } from "@sanity/cli-core";
|
|
5
5
|
/**
|
|
@@ -62,4 +62,4 @@ declare function summarizeInterfaces({ views, webWorkers }: WorkbenchExposes): {
|
|
|
62
62
|
views: DeployedView[];
|
|
63
63
|
};
|
|
64
64
|
export { DeployableWorkbenchApp as a, summarizeInterfaces as i, DeployedView as n, getWorkbench as o, DeployedWebWorker as r, DeployedInterface as t };
|
|
65
|
-
//# sourceMappingURL=summarizeInterfaces-
|
|
65
|
+
//# sourceMappingURL=summarizeInterfaces-Co97VU2z.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as ResolvedMediaLibraryConfig } from "./resolveWorkbenchConfig-
|
|
2
|
-
import { a as DeployableWorkbenchApp, n as DeployedView, r as DeployedWebWorker } from "./summarizeInterfaces-
|
|
1
|
+
import { t as ResolvedMediaLibraryConfig } from "./resolveWorkbenchConfig-DEttN7ks.js";
|
|
2
|
+
import { a as DeployableWorkbenchApp, n as DeployedView, r as DeployedWebWorker } from "./summarizeInterfaces-Co97VU2z.js";
|
|
3
3
|
import "node:zlib";
|
|
4
4
|
import { UndeployAdapter, UndeployApplicationTarget, UndeployConfigTarget } from "@sanity/cli-core/undeploy";
|
|
5
5
|
interface ConfigSnapshot {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { mediaLibraryConfigArtifacts } from './configs/artifact.js';
|
|
2
2
|
import { serviceArtifacts } from './services/artifact.js';
|
|
3
3
|
import { viewArtifacts } from './views/artifact.js';
|
|
4
4
|
/**
|
|
@@ -19,11 +19,11 @@ import { viewArtifacts } from './views/artifact.js';
|
|
|
19
19
|
* Expand what the app exposes into the flat artifact set the federation build
|
|
20
20
|
* writes — the single place that composes the per-type expanders, so the expose
|
|
21
21
|
* mapping and the file writing read from one expansion.
|
|
22
|
-
*/ export function workbenchArtifacts(exposes) {
|
|
22
|
+
*/ export function workbenchArtifacts(exposes, configOptions = {}) {
|
|
23
23
|
return [
|
|
24
24
|
...viewArtifacts(exposes.views ?? []),
|
|
25
25
|
...serviceArtifacts(exposes.webWorkers ?? []),
|
|
26
|
-
...
|
|
26
|
+
...mediaLibraryConfigArtifacts(exposes.config, configOptions)
|
|
27
27
|
];
|
|
28
28
|
}
|
|
29
29
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/build/artifact.ts"],"sourcesContent":["import {type WorkbenchExposes} from '../../resolveWorkbenchApp.js'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/build/artifact.ts"],"sourcesContent":["import {type WorkbenchExposes} from '../../resolveWorkbenchApp.js'\nimport {\n type MediaLibraryConfigArtifactOptions,\n mediaLibraryConfigArtifacts,\n} from './configs/artifact.js'\nimport {serviceArtifacts} from './services/artifact.js'\nimport {viewArtifacts} from './views/artifact.js'\n\n/**\n * What a {@link GeneratedArtifact.source} builder receives from the build — the\n * one thing it can't compute on its own, since only the build knows where the\n * runtime dir sits relative to the app's `src`.\n */\ninterface ArtifactContext {\n /** Import specifier for an app `src` file, relative to this artifact. */\n resolveImport: (src: string) => string\n\n isolateStyles?: boolean\n}\n\n/**\n * One file the federation build generates into the runtime dir for a declared\n * interface. Each interface type — views, web workers — expands its declarations\n * into a flat list of these; the build then writes them and maps the ones the\n * host loads directly into the module-federation manifest.\n *\n * Adding an interface type is adding a builder that returns\n * `GeneratedArtifact[]` — the write loop and the expose mapping never change.\n */\nexport interface GeneratedArtifact {\n /** Path relative to the federation runtime dir, e.g. `views/feed/panel.js`. */\n path: string\n /** Build the file's contents. */\n source: (context: ArtifactContext) => string\n\n /**\n * Module-federation expose key when the host loads this artifact directly —\n * a view component `./views/feed/panel`, a service loader `./services/unread`.\n * Omitted for a file the host never loads on its own, like a worker bundle\n * (reached through its sibling loader).\n */\n expose?: string\n}\n\n/**\n * Map the artifacts the host loads directly (those with an `expose`) to their\n * runtime-dir paths, for the module-federation `exposes` field. `toExposePath`\n * turns a runtime-relative artifact path into the value federation wants — the\n * caller owns the runtime-dir location and any entry resolution.\n */\nexport function artifactExposes(\n artifacts: readonly GeneratedArtifact[],\n toExposePath: (artifactPath: string) => string,\n): Record<string, string> {\n const exposes: Record<string, string> = {}\n for (const artifact of artifacts) {\n if (artifact.expose) {\n exposes[artifact.expose] = toExposePath(artifact.path)\n }\n }\n return exposes\n}\n\n/**\n * Expand what the app exposes into the flat artifact set the federation build\n * writes — the single place that composes the per-type expanders, so the expose\n * mapping and the file writing read from one expansion.\n */\nexport function workbenchArtifacts(\n exposes: WorkbenchExposes,\n configOptions: MediaLibraryConfigArtifactOptions = {},\n): GeneratedArtifact[] {\n return [\n ...viewArtifacts(exposes.views ?? []),\n ...serviceArtifacts(exposes.webWorkers ?? []),\n ...mediaLibraryConfigArtifacts(exposes.config, configOptions),\n ]\n}\n"],"names":["mediaLibraryConfigArtifacts","serviceArtifacts","viewArtifacts","artifactExposes","artifacts","toExposePath","exposes","artifact","expose","path","workbenchArtifacts","configOptions","views","webWorkers","config"],"mappings":"AACA,SAEEA,2BAA2B,QACtB,wBAAuB;AAC9B,SAAQC,gBAAgB,QAAO,yBAAwB;AACvD,SAAQC,aAAa,QAAO,sBAAqB;AAsCjD;;;;;CAKC,GACD,OAAO,SAASC,gBACdC,SAAuC,EACvCC,YAA8C;IAE9C,MAAMC,UAAkC,CAAC;IACzC,KAAK,MAAMC,YAAYH,UAAW;QAChC,IAAIG,SAASC,MAAM,EAAE;YACnBF,OAAO,CAACC,SAASC,MAAM,CAAC,GAAGH,aAAaE,SAASE,IAAI;QACvD;IACF;IACA,OAAOH;AACT;AAEA;;;;CAIC,GACD,OAAO,SAASI,mBACdJ,OAAyB,EACzBK,gBAAmD,CAAC,CAAC;IAErD,OAAO;WACFT,cAAcI,QAAQM,KAAK,IAAI,EAAE;WACjCX,iBAAiBK,QAAQO,UAAU,IAAI,EAAE;WACzCb,4BAA4BM,QAAQQ,MAAM,EAAEH;KAChD;AACH"}
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { INSTALLATION_CONFIG_TYPE, MEDIA_LIBRARY_CONFIG_CONTRACT_VERSION } from '../../../contract.js';
|
|
2
|
+
import { MEDIA_LIBRARY_ISLAND_RUNTIME_MODULE } from './mediaLibraryIslandRuntime.js';
|
|
2
3
|
const CONFIGS_DIR_NAME = 'configs';
|
|
3
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* Expand the Media Library config into its federation modules: one aggregating
|
|
6
|
+
* all fields (so the host imports one live config value), plus — when the
|
|
7
|
+
* installed `sanity` ships it — the island-mount runtime the host uses to
|
|
8
|
+
* render custom field inputs in isolated React roots.
|
|
9
|
+
*
|
|
10
|
+
* Everything here is Media Library-specific (the one config type today);
|
|
11
|
+
* a second config type gets its own expander next to this one.
|
|
12
|
+
*/ export function mediaLibraryConfigArtifacts(config, options = {}) {
|
|
4
13
|
if (!config) return [];
|
|
5
14
|
return [
|
|
6
15
|
{
|
|
@@ -10,7 +19,14 @@ const CONFIGS_DIR_NAME = 'configs';
|
|
|
10
19
|
config,
|
|
11
20
|
resolveImport
|
|
12
21
|
})
|
|
13
|
-
}
|
|
22
|
+
},
|
|
23
|
+
...options.islandRuntime ? [
|
|
24
|
+
{
|
|
25
|
+
expose: './media-library-island-runtime',
|
|
26
|
+
path: `${CONFIGS_DIR_NAME}/media_library_island_runtime.js`,
|
|
27
|
+
source: ()=>mediaLibraryIslandRuntimeSource()
|
|
28
|
+
}
|
|
29
|
+
] : []
|
|
14
30
|
];
|
|
15
31
|
}
|
|
16
32
|
/**
|
|
@@ -34,11 +50,60 @@ ${entries}
|
|
|
34
50
|
],
|
|
35
51
|
}
|
|
36
52
|
|
|
53
|
+
// Dev-only HMR handle. In dev the Media Library host loads this module into
|
|
54
|
+
// its own page through Module Federation, which keeps returning the first
|
|
55
|
+
// evaluation — the host cannot re-import its way to fresh code. So the host
|
|
56
|
+
// registers a listener here instead: on every hot update the outgoing module
|
|
57
|
+
// hands its live listener set to the incoming module, then replays the
|
|
58
|
+
// listeners with the fresh namespace, and the host re-applies the field
|
|
59
|
+
// config in place (the same pattern view remotes use). When nobody is
|
|
60
|
+
// listening — or a listener fails to apply — invalidate() escalates to
|
|
61
|
+
// Vite's native full reload, so the page can never keep rendering from
|
|
62
|
+
// stale config.
|
|
63
|
+
let listeners = new Set()
|
|
64
|
+
export function subscribe(listener) {
|
|
65
|
+
listeners.add(listener)
|
|
66
|
+
return () => listeners.delete(listener)
|
|
67
|
+
}
|
|
68
|
+
// Internal to the hot chain: the set object travels across updates so the
|
|
69
|
+
// unsubscribe closures handed out by any module generation keep deleting
|
|
70
|
+
// from the one live set (a copy would orphan them after the first update).
|
|
71
|
+
export function _adoptListeners(shared) {
|
|
72
|
+
listeners = shared
|
|
73
|
+
}
|
|
74
|
+
|
|
37
75
|
if (import.meta.hot) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
76
|
+
import.meta.hot.accept((next) => {
|
|
77
|
+
if (!next || typeof next._adoptListeners !== 'function' || listeners.size === 0) {
|
|
78
|
+
import.meta.hot.invalidate()
|
|
79
|
+
return
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
next._adoptListeners(listeners)
|
|
83
|
+
// Notify a snapshot: a listener may unsubscribe and re-subscribe on the
|
|
84
|
+
// fresh namespace, which (post-adoption) mutates this very set — and a
|
|
85
|
+
// Set iterator revisits re-added entries, so iterating live would loop
|
|
86
|
+
// forever. Entries added mid-loop subscribed to the already-current
|
|
87
|
+
// namespace and need no notification for this update.
|
|
88
|
+
for (const listener of [...listeners]) {
|
|
89
|
+
listener(next)
|
|
90
|
+
}
|
|
91
|
+
} catch {
|
|
92
|
+
import.meta.hot.invalidate()
|
|
93
|
+
}
|
|
94
|
+
})
|
|
95
|
+
}
|
|
96
|
+
`;
|
|
41
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* One line on purpose: the runtime implementation lives in the `sanity`
|
|
100
|
+
* package and is bundled into the remote from the app's own install, so the
|
|
101
|
+
* runtime always matches the `sanity` version field modules compile against.
|
|
102
|
+
*/ function mediaLibraryIslandRuntimeSource() {
|
|
103
|
+
return `\
|
|
104
|
+
// This file is auto-generated on 'sanity build' / 'sanity dev'
|
|
105
|
+
// Modifications to this file are automatically discarded
|
|
106
|
+
export * from ${JSON.stringify(MEDIA_LIBRARY_ISLAND_RUNTIME_MODULE)}
|
|
42
107
|
`;
|
|
43
108
|
}
|
|
44
109
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/actions/build/configs/artifact.ts"],"sourcesContent":["import {INSTALLATION_CONFIG_TYPE, MEDIA_LIBRARY_CONFIG_CONTRACT_VERSION} from '../../../contract.js'\nimport {type GeneratedArtifact} from '../artifact.js'\n\nconst CONFIGS_DIR_NAME = 'configs'\n\n/**\n * The config to generate a module for.\n * @internal\n */\nexport interface
|
|
1
|
+
{"version":3,"sources":["../../../../src/actions/build/configs/artifact.ts"],"sourcesContent":["import {INSTALLATION_CONFIG_TYPE, MEDIA_LIBRARY_CONFIG_CONTRACT_VERSION} from '../../../contract.js'\nimport {type GeneratedArtifact} from '../artifact.js'\nimport {MEDIA_LIBRARY_ISLAND_RUNTIME_MODULE} from './mediaLibraryIslandRuntime.js'\n\nconst CONFIGS_DIR_NAME = 'configs'\n\n/**\n * The Media Library config to generate a module for.\n * @internal\n */\nexport interface MediaLibraryConfigArtifact {\n fields: {name: string; public?: boolean; src: string; title: string}[]\n}\n\n/** Build-time capabilities that gate optional Media Library config artifacts. */\nexport interface MediaLibraryConfigArtifactOptions {\n /**\n * Whether the app's installed `sanity` ships the Media Library island-mount\n * runtime ({@link MEDIA_LIBRARY_ISLAND_RUNTIME_MODULE}). Gates the\n * `./media-library-island-runtime` expose — emitting it against an older\n * `sanity` would fail the build on an unresolvable import.\n */\n islandRuntime?: boolean\n}\n\n/**\n * Expand the Media Library config into its federation modules: one aggregating\n * all fields (so the host imports one live config value), plus — when the\n * installed `sanity` ships it — the island-mount runtime the host uses to\n * render custom field inputs in isolated React roots.\n *\n * Everything here is Media Library-specific (the one config type today);\n * a second config type gets its own expander next to this one.\n */\nexport function mediaLibraryConfigArtifacts(\n config: MediaLibraryConfigArtifact | undefined,\n options: MediaLibraryConfigArtifactOptions = {},\n): GeneratedArtifact[] {\n if (!config) return []\n return [\n {\n expose: `./${CONFIGS_DIR_NAME}/${INSTALLATION_CONFIG_TYPE}`,\n path: `${CONFIGS_DIR_NAME}/${INSTALLATION_CONFIG_TYPE}.js`,\n source: ({resolveImport}) => mediaLibraryConfigSource({config, resolveImport}),\n },\n ...(options.islandRuntime\n ? [\n {\n expose: './media-library-island-runtime',\n path: `${CONFIGS_DIR_NAME}/media_library_island_runtime.js`,\n source: () => mediaLibraryIslandRuntimeSource(),\n },\n ]\n : []),\n ]\n}\n\n/**\n * Emits `export const config`: each field's serializable `{name, title, public}`\n * plus its live `defineField` value, the one thing the wire can't carry.\n * `appType` stays off the module — the host assigns it from the wire record.\n */\nfunction mediaLibraryConfigSource(input: {\n config: MediaLibraryConfigArtifact\n resolveImport: (src: string) => string\n}): string {\n const {config, resolveImport} = input\n const imports = config.fields\n .map((field, index) => `import field_${index} from ${JSON.stringify(resolveImport(field.src))}`)\n .join('\\n')\n const entries = config.fields\n .map(\n (field, index) =>\n ` {name: ${JSON.stringify(field.name)}, title: ${JSON.stringify(field.title)}, ` +\n `public: ${JSON.stringify(Boolean(field.public))}, config: field_${index}},`,\n )\n .join('\\n')\n return `\\\n// This file is auto-generated on 'sanity build' / 'sanity dev'\n// Modifications to this file are automatically discarded\n${imports}\n\nexport const type = ${JSON.stringify(INSTALLATION_CONFIG_TYPE)}\nexport const version = ${MEDIA_LIBRARY_CONFIG_CONTRACT_VERSION}\nexport const config = {\n fields: [\n${entries}\n ],\n}\n\n// Dev-only HMR handle. In dev the Media Library host loads this module into\n// its own page through Module Federation, which keeps returning the first\n// evaluation — the host cannot re-import its way to fresh code. So the host\n// registers a listener here instead: on every hot update the outgoing module\n// hands its live listener set to the incoming module, then replays the\n// listeners with the fresh namespace, and the host re-applies the field\n// config in place (the same pattern view remotes use). When nobody is\n// listening — or a listener fails to apply — invalidate() escalates to\n// Vite's native full reload, so the page can never keep rendering from\n// stale config.\nlet listeners = new Set()\nexport function subscribe(listener) {\n listeners.add(listener)\n return () => listeners.delete(listener)\n}\n// Internal to the hot chain: the set object travels across updates so the\n// unsubscribe closures handed out by any module generation keep deleting\n// from the one live set (a copy would orphan them after the first update).\nexport function _adoptListeners(shared) {\n listeners = shared\n}\n\nif (import.meta.hot) {\n import.meta.hot.accept((next) => {\n if (!next || typeof next._adoptListeners !== 'function' || listeners.size === 0) {\n import.meta.hot.invalidate()\n return\n }\n try {\n next._adoptListeners(listeners)\n // Notify a snapshot: a listener may unsubscribe and re-subscribe on the\n // fresh namespace, which (post-adoption) mutates this very set — and a\n // Set iterator revisits re-added entries, so iterating live would loop\n // forever. Entries added mid-loop subscribed to the already-current\n // namespace and need no notification for this update.\n for (const listener of [...listeners]) {\n listener(next)\n }\n } catch {\n import.meta.hot.invalidate()\n }\n })\n}\n`\n}\n\n/**\n * One line on purpose: the runtime implementation lives in the `sanity`\n * package and is bundled into the remote from the app's own install, so the\n * runtime always matches the `sanity` version field modules compile against.\n */\nfunction mediaLibraryIslandRuntimeSource(): string {\n return `\\\n// This file is auto-generated on 'sanity build' / 'sanity dev'\n// Modifications to this file are automatically discarded\nexport * from ${JSON.stringify(MEDIA_LIBRARY_ISLAND_RUNTIME_MODULE)}\n`\n}\n"],"names":["INSTALLATION_CONFIG_TYPE","MEDIA_LIBRARY_CONFIG_CONTRACT_VERSION","MEDIA_LIBRARY_ISLAND_RUNTIME_MODULE","CONFIGS_DIR_NAME","mediaLibraryConfigArtifacts","config","options","expose","path","source","resolveImport","mediaLibraryConfigSource","islandRuntime","mediaLibraryIslandRuntimeSource","input","imports","fields","map","field","index","JSON","stringify","src","join","entries","name","title","Boolean","public"],"mappings":"AAAA,SAAQA,wBAAwB,EAAEC,qCAAqC,QAAO,uBAAsB;AAEpG,SAAQC,mCAAmC,QAAO,iCAAgC;AAElF,MAAMC,mBAAmB;AAqBzB;;;;;;;;CAQC,GACD,OAAO,SAASC,4BACdC,MAA8C,EAC9CC,UAA6C,CAAC,CAAC;IAE/C,IAAI,CAACD,QAAQ,OAAO,EAAE;IACtB,OAAO;QACL;YACEE,QAAQ,CAAC,EAAE,EAAEJ,iBAAiB,CAAC,EAAEH,0BAA0B;YAC3DQ,MAAM,GAAGL,iBAAiB,CAAC,EAAEH,yBAAyB,GAAG,CAAC;YAC1DS,QAAQ,CAAC,EAACC,aAAa,EAAC,GAAKC,yBAAyB;oBAACN;oBAAQK;gBAAa;QAC9E;WACIJ,QAAQM,aAAa,GACrB;YACE;gBACEL,QAAQ;gBACRC,MAAM,GAAGL,iBAAiB,gCAAgC,CAAC;gBAC3DM,QAAQ,IAAMI;YAChB;SACD,GACD,EAAE;KACP;AACH;AAEA;;;;CAIC,GACD,SAASF,yBAAyBG,KAGjC;IACC,MAAM,EAACT,MAAM,EAAEK,aAAa,EAAC,GAAGI;IAChC,MAAMC,UAAUV,OAAOW,MAAM,CAC1BC,GAAG,CAAC,CAACC,OAAOC,QAAU,CAAC,aAAa,EAAEA,MAAM,MAAM,EAAEC,KAAKC,SAAS,CAACX,cAAcQ,MAAMI,GAAG,IAAI,EAC9FC,IAAI,CAAC;IACR,MAAMC,UAAUnB,OAAOW,MAAM,CAC1BC,GAAG,CACF,CAACC,OAAOC,QACN,CAAC,WAAW,EAAEC,KAAKC,SAAS,CAACH,MAAMO,IAAI,EAAE,SAAS,EAAEL,KAAKC,SAAS,CAACH,MAAMQ,KAAK,EAAE,EAAE,CAAC,GACnF,CAAC,QAAQ,EAAEN,KAAKC,SAAS,CAACM,QAAQT,MAAMU,MAAM,GAAG,gBAAgB,EAAET,MAAM,EAAE,CAAC,EAE/EI,IAAI,CAAC;IACR,OAAO,CAAC;;;AAGV,EAAER,QAAQ;;oBAEU,EAAEK,KAAKC,SAAS,CAACrB,0BAA0B;uBACxC,EAAEC,sCAAsC;;;AAG/D,EAAEuB,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CV,CAAC;AACD;AAEA;;;;CAIC,GACD,SAASX;IACP,OAAO,CAAC;;;cAGI,EAAEO,KAAKC,SAAS,CAACnB,qCAAqC;AACpE,CAAC;AACD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether this build is a Media Library config app — an app whose manifest
|
|
3
|
+
* declares a `config` expose of `appType: 'media-library'` (aspect field
|
|
4
|
+
* definitions the Media Library host loads through Module Federation).
|
|
5
|
+
*
|
|
6
|
+
* The one predicate the shared build code branches on for Media Library
|
|
7
|
+
* behavior (the island-runtime expose, the sui reset strip, fields HMR);
|
|
8
|
+
* everything behind the branch lives under `configs/`. Keyed on the config's
|
|
9
|
+
* `appType` discriminant, so a future second config type adds its own
|
|
10
|
+
* predicate instead of silently matching this one.
|
|
11
|
+
*/ export function isMediaLibraryConfigApp(exposes) {
|
|
12
|
+
return exposes?.config?.appType === 'media-library';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=configApp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/actions/build/configs/configApp.ts"],"sourcesContent":["import {type WorkbenchExposes} from '../../../resolveWorkbenchApp.js'\n\n/**\n * Whether this build is a Media Library config app — an app whose manifest\n * declares a `config` expose of `appType: 'media-library'` (aspect field\n * definitions the Media Library host loads through Module Federation).\n *\n * The one predicate the shared build code branches on for Media Library\n * behavior (the island-runtime expose, the sui reset strip, fields HMR);\n * everything behind the branch lives under `configs/`. Keyed on the config's\n * `appType` discriminant, so a future second config type adds its own\n * predicate instead of silently matching this one.\n */\nexport function isMediaLibraryConfigApp(exposes: WorkbenchExposes | undefined): boolean {\n return exposes?.config?.appType === 'media-library'\n}\n"],"names":["isMediaLibraryConfigApp","exposes","config","appType"],"mappings":"AAEA;;;;;;;;;;CAUC,GACD,OAAO,SAASA,wBAAwBC,OAAqC;IAC3E,OAAOA,SAASC,QAAQC,YAAY;AACtC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
/**
|
|
4
|
+
* The `sanity` package entry carrying the Media Library island-mount runtime
|
|
5
|
+
* (`mountIsland`). The generated `./media-library-island-runtime` federation
|
|
6
|
+
* expose re-exports it, so the runtime is bundled into the config app's
|
|
7
|
+
* remote from the app's own `sanity` install — whichever version the app
|
|
8
|
+
* installs brings a matching runtime.
|
|
9
|
+
*/ export const MEDIA_LIBRARY_ISLAND_RUNTIME_MODULE = 'sanity/media-library-island-runtime';
|
|
10
|
+
/**
|
|
11
|
+
* Whether the config app's installed `sanity` ships the island runtime entry.
|
|
12
|
+
* Older `sanity` versions don't; exposing a module whose import can never
|
|
13
|
+
* resolve would fail the whole build, so the expose is skipped (with a
|
|
14
|
+
* warning) and the Media Library host falls back to its degraded rendering
|
|
15
|
+
* for custom inputs.
|
|
16
|
+
*/ export function hasMediaLibraryIslandRuntime(appRoot) {
|
|
17
|
+
try {
|
|
18
|
+
createRequire(path.join(appRoot, 'package.json')).resolve(MEDIA_LIBRARY_ISLAND_RUNTIME_MODULE);
|
|
19
|
+
return true;
|
|
20
|
+
} catch {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=mediaLibraryIslandRuntime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/actions/build/configs/mediaLibraryIslandRuntime.ts"],"sourcesContent":["import {createRequire} from 'node:module'\nimport path from 'node:path'\n\n/**\n * The `sanity` package entry carrying the Media Library island-mount runtime\n * (`mountIsland`). The generated `./media-library-island-runtime` federation\n * expose re-exports it, so the runtime is bundled into the config app's\n * remote from the app's own `sanity` install — whichever version the app\n * installs brings a matching runtime.\n */\nexport const MEDIA_LIBRARY_ISLAND_RUNTIME_MODULE = 'sanity/media-library-island-runtime'\n\n/**\n * Whether the config app's installed `sanity` ships the island runtime entry.\n * Older `sanity` versions don't; exposing a module whose import can never\n * resolve would fail the whole build, so the expose is skipped (with a\n * warning) and the Media Library host falls back to its degraded rendering\n * for custom inputs.\n */\nexport function hasMediaLibraryIslandRuntime(appRoot: string): boolean {\n try {\n createRequire(path.join(appRoot, 'package.json')).resolve(MEDIA_LIBRARY_ISLAND_RUNTIME_MODULE)\n return true\n } catch {\n return false\n }\n}\n"],"names":["createRequire","path","MEDIA_LIBRARY_ISLAND_RUNTIME_MODULE","hasMediaLibraryIslandRuntime","appRoot","join","resolve"],"mappings":"AAAA,SAAQA,aAAa,QAAO,cAAa;AACzC,OAAOC,UAAU,YAAW;AAE5B;;;;;;CAMC,GACD,OAAO,MAAMC,sCAAsC,sCAAqC;AAExF;;;;;;CAMC,GACD,OAAO,SAASC,6BAA6BC,OAAe;IAC1D,IAAI;QACFJ,cAAcC,KAAKI,IAAI,CAACD,SAAS,iBAAiBE,OAAO,CAACJ;QAC1D,OAAO;IACT,EAAE,OAAM;QACN,OAAO;IACT;AACF"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
import { isMediaLibraryConfigApp } from '../configs/configApp.js';
|
|
4
|
+
import { hasMediaLibraryIslandRuntime, MEDIA_LIBRARY_ISLAND_RUNTIME_MODULE } from '../configs/mediaLibraryIslandRuntime.js';
|
|
3
5
|
/**
|
|
4
6
|
* React APIs only the generated render-contract modules import — the SPA
|
|
5
7
|
* bootstrap (`getEntryModule`) and every render artifact (`renderRemote`)
|
|
@@ -71,12 +73,20 @@ import path from 'node:path';
|
|
|
71
73
|
const resolved = resolveSourceFile(absPath);
|
|
72
74
|
return path.relative(cwd, resolved).split(path.sep).join('/');
|
|
73
75
|
});
|
|
76
|
+
// The generated `./island-runtime` expose imports this entry, but the file is
|
|
77
|
+
// codegen (never in `entries`), so the startup scan misses it. Only when the
|
|
78
|
+
// installed `sanity` ships the entry — an unresolvable `include` name crashes
|
|
79
|
+
// the dev server, and the expose is skipped in that case anyway.
|
|
80
|
+
const islandRuntimeDeps = isMediaLibraryConfigApp(exposes) && hasMediaLibraryIslandRuntime(cwd) ? [
|
|
81
|
+
MEDIA_LIBRARY_ISLAND_RUNTIME_MODULE
|
|
82
|
+
] : [];
|
|
74
83
|
return {
|
|
75
84
|
entries: [
|
|
76
85
|
...new Set(entries)
|
|
77
86
|
],
|
|
78
87
|
include: [
|
|
79
|
-
...RENDER_CONTRACT_DEPS
|
|
88
|
+
...RENDER_CONTRACT_DEPS,
|
|
89
|
+
...islandRuntimeDeps
|
|
80
90
|
]
|
|
81
91
|
};
|
|
82
92
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/actions/build/vite/optimize-deps.ts"],"sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\n\nimport {type WorkbenchExposes} from '../../../resolveWorkbenchApp.js'\n\n/**\n * React APIs only the generated render-contract modules import — the SPA\n * bootstrap (`getEntryModule`) and every render artifact (`renderRemote`)\n * `createRoot` from `react-dom/client` and `createElement` from `react`. No\n * app/interface source imports `react-dom/client` itself, so scanning `entries`\n * never surfaces it; every workbench app depends on react/react-dom, so both\n * always resolve.\n */\nconst RENDER_CONTRACT_DEPS = ['react', 'react-dom/client']\n\n/** Extensions an import-style source path may omit, in resolution order. */\nconst SOURCE_EXTENSIONS = ['.tsx', '.ts', '.jsx', '.js', '.mjs', '.cjs']\n\n/**\n * Resolve an import-style source path to the file on disk. The app `entry`\n * defaults to the extensionless `./src/App` (and a user may omit the extension\n * anywhere), which the runtime imports fine through Vite's resolver — but\n * `optimizeDeps.entries` is matched against the filesystem, so an extensionless\n * path never matches and its deps go unscanned. Try the path as-is, then the\n * common source extensions; fall back to the input so an already-resolved path\n * (or a genuinely missing one) passes through unchanged.\n */\nfunction resolveSourceFile(absPath: string): string {\n if (fs.existsSync(absPath) && fs.statSync(absPath).isFile()) return absPath\n for (const extension of SOURCE_EXTENSIONS) {\n if (fs.existsSync(`${absPath}${extension}`)) return `${absPath}${extension}`\n }\n return absPath\n}\n\n/**\n * Dep pre-bundling inputs for a workbench app's dev server.\n *\n * Vite's dep scanner crawls from the app's HTML entry, which reaches only the\n * app's `entry` (or a studio's config) — never the federation `exposes` (dock\n * views, web workers, media-library config fields), which the host loads\n * dynamically at runtime. So a dep imported only by an exposed module (e.g.\n * `sanity/workbench` in a service or view) escapes the startup scan; Vite\n * discovers it on first request, re-optimizes, and full-page reloads — which\n * flakes Playwright in e2e.\n *\n * Point `entries` at the source of every interface: the app `entry` (or, for a\n * studio, its config), plus each view, service, and installation-config source.\n * `entries` follows real import statements, so it covers whatever those sources\n * transitively use — correct subpaths and all — with no hand-maintained dep\n * list, and never crashes on an unresolvable name the way a bad `include` entry\n * does. Each source is resolved to its on-disk file so an extensionless path\n * (like the default `./src/App`) still matches `entries`' filesystem glob.\n *\n * @param cwd - Project root; `entries` are returned relative to it.\n * @param appSources - Absolute paths to the app's `entry` and/or studio config.\n * @param exposes - The app's declared views/web workers/config.\n * @internal\n */\nexport function workbenchOptimizeDeps(options: {\n appSources: readonly string[]\n cwd: string\n exposes?: WorkbenchExposes\n}): {entries: string[]; include: string[]} {\n const {appSources, cwd, exposes} = options\n\n const interfaceSources = [\n ...(exposes?.views ?? []).map((view) => view.src),\n ...(exposes?.webWorkers ?? []).map((webWorker) => webWorker.src),\n ...(exposes?.config?.fields ?? []).map((field) => field.src),\n ].map((src) => path.resolve(cwd, src))\n\n const entries = [...appSources, ...interfaceSources].map((absPath) => {\n const resolved = resolveSourceFile(absPath)\n return path.relative(cwd, resolved).split(path.sep).join('/')\n })\n\n return {\n entries: [...new Set(entries)],\n include: [...RENDER_CONTRACT_DEPS],\n }\n}\n"],"names":["fs","path","RENDER_CONTRACT_DEPS","SOURCE_EXTENSIONS","resolveSourceFile","absPath","existsSync","statSync","isFile","extension","workbenchOptimizeDeps","options","appSources","cwd","exposes","interfaceSources","views","map","view","src","webWorkers","webWorker","config","fields","field","resolve","entries","resolved","relative","split","sep","join","Set","include"],"mappings":"AAAA,OAAOA,QAAQ,UAAS;AACxB,OAAOC,UAAU,YAAW;
|
|
1
|
+
{"version":3,"sources":["../../../../src/actions/build/vite/optimize-deps.ts"],"sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\n\nimport {type WorkbenchExposes} from '../../../resolveWorkbenchApp.js'\nimport {isMediaLibraryConfigApp} from '../configs/configApp.js'\nimport {\n hasMediaLibraryIslandRuntime,\n MEDIA_LIBRARY_ISLAND_RUNTIME_MODULE,\n} from '../configs/mediaLibraryIslandRuntime.js'\n\n/**\n * React APIs only the generated render-contract modules import — the SPA\n * bootstrap (`getEntryModule`) and every render artifact (`renderRemote`)\n * `createRoot` from `react-dom/client` and `createElement` from `react`. No\n * app/interface source imports `react-dom/client` itself, so scanning `entries`\n * never surfaces it; every workbench app depends on react/react-dom, so both\n * always resolve.\n */\nconst RENDER_CONTRACT_DEPS = ['react', 'react-dom/client']\n\n/** Extensions an import-style source path may omit, in resolution order. */\nconst SOURCE_EXTENSIONS = ['.tsx', '.ts', '.jsx', '.js', '.mjs', '.cjs']\n\n/**\n * Resolve an import-style source path to the file on disk. The app `entry`\n * defaults to the extensionless `./src/App` (and a user may omit the extension\n * anywhere), which the runtime imports fine through Vite's resolver — but\n * `optimizeDeps.entries` is matched against the filesystem, so an extensionless\n * path never matches and its deps go unscanned. Try the path as-is, then the\n * common source extensions; fall back to the input so an already-resolved path\n * (or a genuinely missing one) passes through unchanged.\n */\nfunction resolveSourceFile(absPath: string): string {\n if (fs.existsSync(absPath) && fs.statSync(absPath).isFile()) return absPath\n for (const extension of SOURCE_EXTENSIONS) {\n if (fs.existsSync(`${absPath}${extension}`)) return `${absPath}${extension}`\n }\n return absPath\n}\n\n/**\n * Dep pre-bundling inputs for a workbench app's dev server.\n *\n * Vite's dep scanner crawls from the app's HTML entry, which reaches only the\n * app's `entry` (or a studio's config) — never the federation `exposes` (dock\n * views, web workers, media-library config fields), which the host loads\n * dynamically at runtime. So a dep imported only by an exposed module (e.g.\n * `sanity/workbench` in a service or view) escapes the startup scan; Vite\n * discovers it on first request, re-optimizes, and full-page reloads — which\n * flakes Playwright in e2e.\n *\n * Point `entries` at the source of every interface: the app `entry` (or, for a\n * studio, its config), plus each view, service, and installation-config source.\n * `entries` follows real import statements, so it covers whatever those sources\n * transitively use — correct subpaths and all — with no hand-maintained dep\n * list, and never crashes on an unresolvable name the way a bad `include` entry\n * does. Each source is resolved to its on-disk file so an extensionless path\n * (like the default `./src/App`) still matches `entries`' filesystem glob.\n *\n * @param cwd - Project root; `entries` are returned relative to it.\n * @param appSources - Absolute paths to the app's `entry` and/or studio config.\n * @param exposes - The app's declared views/web workers/config.\n * @internal\n */\nexport function workbenchOptimizeDeps(options: {\n appSources: readonly string[]\n cwd: string\n exposes?: WorkbenchExposes\n}): {entries: string[]; include: string[]} {\n const {appSources, cwd, exposes} = options\n\n const interfaceSources = [\n ...(exposes?.views ?? []).map((view) => view.src),\n ...(exposes?.webWorkers ?? []).map((webWorker) => webWorker.src),\n ...(exposes?.config?.fields ?? []).map((field) => field.src),\n ].map((src) => path.resolve(cwd, src))\n\n const entries = [...appSources, ...interfaceSources].map((absPath) => {\n const resolved = resolveSourceFile(absPath)\n return path.relative(cwd, resolved).split(path.sep).join('/')\n })\n\n // The generated `./island-runtime` expose imports this entry, but the file is\n // codegen (never in `entries`), so the startup scan misses it. Only when the\n // installed `sanity` ships the entry — an unresolvable `include` name crashes\n // the dev server, and the expose is skipped in that case anyway.\n const islandRuntimeDeps =\n isMediaLibraryConfigApp(exposes) && hasMediaLibraryIslandRuntime(cwd)\n ? [MEDIA_LIBRARY_ISLAND_RUNTIME_MODULE]\n : []\n\n return {\n entries: [...new Set(entries)],\n include: [...RENDER_CONTRACT_DEPS, ...islandRuntimeDeps],\n }\n}\n"],"names":["fs","path","isMediaLibraryConfigApp","hasMediaLibraryIslandRuntime","MEDIA_LIBRARY_ISLAND_RUNTIME_MODULE","RENDER_CONTRACT_DEPS","SOURCE_EXTENSIONS","resolveSourceFile","absPath","existsSync","statSync","isFile","extension","workbenchOptimizeDeps","options","appSources","cwd","exposes","interfaceSources","views","map","view","src","webWorkers","webWorker","config","fields","field","resolve","entries","resolved","relative","split","sep","join","islandRuntimeDeps","Set","include"],"mappings":"AAAA,OAAOA,QAAQ,UAAS;AACxB,OAAOC,UAAU,YAAW;AAG5B,SAAQC,uBAAuB,QAAO,0BAAyB;AAC/D,SACEC,4BAA4B,EAC5BC,mCAAmC,QAC9B,0CAAyC;AAEhD;;;;;;;CAOC,GACD,MAAMC,uBAAuB;IAAC;IAAS;CAAmB;AAE1D,0EAA0E,GAC1E,MAAMC,oBAAoB;IAAC;IAAQ;IAAO;IAAQ;IAAO;IAAQ;CAAO;AAExE;;;;;;;;CAQC,GACD,SAASC,kBAAkBC,OAAe;IACxC,IAAIR,GAAGS,UAAU,CAACD,YAAYR,GAAGU,QAAQ,CAACF,SAASG,MAAM,IAAI,OAAOH;IACpE,KAAK,MAAMI,aAAaN,kBAAmB;QACzC,IAAIN,GAAGS,UAAU,CAAC,GAAGD,UAAUI,WAAW,GAAG,OAAO,GAAGJ,UAAUI,WAAW;IAC9E;IACA,OAAOJ;AACT;AAEA;;;;;;;;;;;;;;;;;;;;;;;CAuBC,GACD,OAAO,SAASK,sBAAsBC,OAIrC;IACC,MAAM,EAACC,UAAU,EAAEC,GAAG,EAAEC,OAAO,EAAC,GAAGH;IAEnC,MAAMI,mBAAmB;WACpB,AAACD,CAAAA,SAASE,SAAS,EAAE,AAAD,EAAGC,GAAG,CAAC,CAACC,OAASA,KAAKC,GAAG;WAC7C,AAACL,CAAAA,SAASM,cAAc,EAAE,AAAD,EAAGH,GAAG,CAAC,CAACI,YAAcA,UAAUF,GAAG;WAC5D,AAACL,CAAAA,SAASQ,QAAQC,UAAU,EAAE,AAAD,EAAGN,GAAG,CAAC,CAACO,QAAUA,MAAML,GAAG;KAC5D,CAACF,GAAG,CAAC,CAACE,MAAQrB,KAAK2B,OAAO,CAACZ,KAAKM;IAEjC,MAAMO,UAAU;WAAId;WAAeG;KAAiB,CAACE,GAAG,CAAC,CAACZ;QACxD,MAAMsB,WAAWvB,kBAAkBC;QACnC,OAAOP,KAAK8B,QAAQ,CAACf,KAAKc,UAAUE,KAAK,CAAC/B,KAAKgC,GAAG,EAAEC,IAAI,CAAC;IAC3D;IAEA,8EAA8E;IAC9E,6EAA6E;IAC7E,8EAA8E;IAC9E,iEAAiE;IACjE,MAAMC,oBACJjC,wBAAwBe,YAAYd,6BAA6Ba,OAC7D;QAACZ;KAAoC,GACrC,EAAE;IAER,OAAO;QACLyB,SAAS;eAAI,IAAIO,IAAIP;SAAS;QAC9BQ,SAAS;eAAIhC;eAAyB8B;SAAkB;IAC1D;AACF"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { artifactExposes, workbenchArtifacts } from '../artifact.js';
|
|
3
|
+
import { isMediaLibraryConfigApp } from '../configs/configApp.js';
|
|
4
|
+
import { hasMediaLibraryIslandRuntime, MEDIA_LIBRARY_ISLAND_RUNTIME_MODULE } from '../configs/mediaLibraryIslandRuntime.js';
|
|
3
5
|
import { FEDERATION_FILE_NAME, RUNTIME_DIR } from './constants.js';
|
|
4
6
|
import { sanityFederationHost } from './plugins/plugin-federation-host.js';
|
|
5
7
|
import { sanityModuleFederation } from './plugins/plugin-module-federation.js';
|
|
@@ -26,11 +28,23 @@ import { sanityFederationRuntime } from './plugins/plugin-sanity-federation-runt
|
|
|
26
28
|
return resolvedPath;
|
|
27
29
|
}
|
|
28
30
|
const entryPath = resolveEntryPath(generatedEntry);
|
|
31
|
+
// A Media Library config's `./island-runtime` expose re-exports the mount
|
|
32
|
+
// runtime from the app's installed `sanity`; skip it (the host falls back to
|
|
33
|
+
// degraded rendering for custom inputs) when that version predates the entry,
|
|
34
|
+
// since an unresolvable import would fail the whole build.
|
|
35
|
+
const isConfigApp = isMediaLibraryConfigApp(exposes);
|
|
36
|
+
const islandRuntime = isConfigApp && hasMediaLibraryIslandRuntime(workDir);
|
|
37
|
+
if (isConfigApp && !islandRuntime) {
|
|
38
|
+
// eslint-disable-next-line no-console -- build-time warning for the app developer
|
|
39
|
+
console.warn(`The installed sanity version does not ship ${MEDIA_LIBRARY_ISLAND_RUNTIME_MODULE}; ` + 'custom field inputs will not render in the Media Library until sanity is upgraded.');
|
|
40
|
+
}
|
|
29
41
|
// Each view component (`./views/<view>/<component>`) and each service loader
|
|
30
42
|
// (`./services/<name>`) is exposed straight to the host, pointing at the file
|
|
31
43
|
// the extension-artifacts plugin generates under RUNTIME_DIR. A service's
|
|
32
44
|
// worker bundle carries no expose — the host reaches it through its loader.
|
|
33
|
-
const artifacts = workbenchArtifacts(exposes ?? {}
|
|
45
|
+
const artifacts = workbenchArtifacts(exposes ?? {}, {
|
|
46
|
+
islandRuntime
|
|
47
|
+
});
|
|
34
48
|
const artifactModuleExposes = artifactExposes(artifacts, (artifactPath)=>resolveEntryPath(`./${RUNTIME_DIR}/${artifactPath}`));
|
|
35
49
|
// A dock-only app (`isApp` with no `appEntry`) has no navigable full-page
|
|
36
50
|
// view, so it exposes no `./App` — only its views. Studios and apps with an
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/actions/build/vite/plugin.ts"],"sourcesContent":["import path from 'node:path'\n\nimport {type ModuleFederationOptions} from '@module-federation/vite'\nimport {type PackageJson} from '@sanity/cli-core'\nimport {type PluginOption} from 'vite'\n\nimport {type WorkbenchExposes} from '../../../resolveWorkbenchApp.js'\nimport {artifactExposes, workbenchArtifacts} from '../artifact.js'\nimport {FEDERATION_FILE_NAME, RUNTIME_DIR} from './constants.js'\nimport {sanityFederationHost} from './plugins/plugin-federation-host.js'\nimport {type FederationOptions, sanityModuleFederation} from './plugins/plugin-module-federation.js'\nimport {sanityEnvironmentPlugin} from './plugins/plugin-sanity-environment.js'\nimport {sanityExtensionArtifacts} from './plugins/plugin-sanity-extension-artifacts.js'\nimport {\n type FederationRuntimeOptions,\n sanityFederationRuntime,\n} from './plugins/plugin-sanity-federation-runtime.js'\n\ninterface FederationPluginOptionsBase extends Omit<Partial<FederationOptions>, 'exposes'> {\n exposes?: WorkbenchExposes\n /** Blueprints build (via `@sanity/runtime-cli`) — emit the resource-bindings module. */\n isBlueprints?: boolean\n pkgJson?: PackageJson\n /**\n * Current working directory to read package.json from, defaults to process.cwd()\n */\n workDir?: string\n}\n\ninterface AppFederationPluginOptions extends FederationPluginOptionsBase {\n isApp: true\n\n /**\n * Relative path to the App entry from the runtime directory, e.g.\n * `../../src/App.tsx`. Omit it for a dock-only app that declares no `entry`:\n * no `./App` is exposed and the remote serves only its views.\n */\n appEntry?: string\n studioConfigPath?: never\n}\n\ninterface StudioFederationPluginOptions extends FederationPluginOptionsBase {\n /** relative path to the Studio config file from the runtime directory (e.g. `../../sanity.config.ts`). */\n studioConfigPath: string\n\n appEntry?: never\n /** @defaultValue false */\n isApp?: false\n}\n\n/**\n * Plugin options for the federation vite plugin.\n *\n * Discriminated on `isApp`:\n * - `isApp: true` → requires `appEntry`\n * - `isApp: false` (default) → requires `studioConfigPath`\n *\n * @internal\n */\ntype FederationPluginOptions = AppFederationPluginOptions | StudioFederationPluginOptions\n\n/**\n * @internal\n */\nexport const federation = (options: FederationPluginOptions): PluginOption => {\n const {exposes, isBlueprints, name: defaultName, pkgJson, workDir = process.cwd()} = options\n\n let name = defaultName\n\n if (!name) {\n name = pkgJson?.name\n }\n\n if (!name) {\n throw new Error('\"name\" option is required but could not be inferred from package.json')\n }\n\n const generatedEntry = `./${RUNTIME_DIR}/${FEDERATION_FILE_NAME}.jsx`\n\n function resolveEntryPath(entry: string) {\n const resolvedPath = path.resolve(workDir, entry)\n\n if (!resolvedPath) {\n throw new Error(\n `Could not resolve path for entry \"${entry}\". Please check that the file exists and the path is correct.`,\n )\n }\n\n return resolvedPath\n }\n\n const entryPath = resolveEntryPath(generatedEntry)\n\n // Each view component (`./views/<view>/<component>`) and each service loader\n // (`./services/<name>`) is exposed straight to the host, pointing at the file\n // the extension-artifacts plugin generates under RUNTIME_DIR. A service's\n // worker bundle carries no expose — the host reaches it through its loader.\n const artifacts = workbenchArtifacts(exposes ?? {})\n const artifactModuleExposes = artifactExposes(artifacts, (artifactPath) =>\n resolveEntryPath(`./${RUNTIME_DIR}/${artifactPath}`),\n )\n\n // A dock-only app (`isApp` with no `appEntry`) has no navigable full-page\n // view, so it exposes no `./App` — only its views. Studios and apps with an\n // entry expose `./App` (the generated render entry).\n const exposesApp = !options.isApp || options.appEntry !== undefined\n\n const federationExposes: NonNullable<ModuleFederationOptions['exposes']> = {\n ...(exposesApp ? {'./App': entryPath} : {}),\n ...artifactModuleExposes,\n }\n\n const runtimeOptions: FederationRuntimeOptions = options.isApp\n ? {appEntry: options.appEntry, isApp: true, isBlueprints}\n : {isApp: false, isBlueprints, studioConfigPath: options.studioConfigPath}\n\n // Every federated app and studio also serves itself standalone. Whenever there's\n // an `./App` to mount (never for a dock-only app), build the SPA client\n // environment from the runtime bootstrap cli-build writes.\n const clientInput = exposesApp ? path.join(workDir, '.sanity', 'runtime', 'app.js') : undefined\n\n return [\n sanityEnvironmentPlugin({clientInput, input: entryPath, isBlueprints}),\n sanityFederationRuntime(runtimeOptions),\n sanityExtensionArtifacts({artifacts}),\n sanityModuleFederation({exposes: federationExposes, name}),\n sanityFederationHost(),\n ]\n}\n"],"names":["path","artifactExposes","workbenchArtifacts","FEDERATION_FILE_NAME","RUNTIME_DIR","sanityFederationHost","sanityModuleFederation","sanityEnvironmentPlugin","sanityExtensionArtifacts","sanityFederationRuntime","federation","options","exposes","isBlueprints","name","defaultName","pkgJson","workDir","process","cwd","Error","generatedEntry","resolveEntryPath","entry","resolvedPath","resolve","entryPath","artifacts","artifactModuleExposes","artifactPath","exposesApp","isApp","appEntry","undefined","federationExposes","runtimeOptions","studioConfigPath","clientInput","join","input"],"mappings":"AAAA,OAAOA,UAAU,YAAW;AAO5B,SAAQC,eAAe,EAAEC,kBAAkB,QAAO,iBAAgB;AAClE,SAAQC,oBAAoB,EAAEC,WAAW,QAAO,iBAAgB;AAChE,SAAQC,oBAAoB,QAAO,sCAAqC;AACxE,SAAgCC,sBAAsB,QAAO,wCAAuC;AACpG,SAAQC,uBAAuB,QAAO,yCAAwC;AAC9E,SAAQC,wBAAwB,QAAO,iDAAgD;AACvF,SAEEC,uBAAuB,QAClB,gDAA+C;AA6CtD;;CAEC,GACD,OAAO,MAAMC,aAAa,CAACC;IACzB,MAAM,EAACC,OAAO,EAAEC,YAAY,EAAEC,MAAMC,WAAW,EAAEC,OAAO,EAAEC,UAAUC,QAAQC,GAAG,EAAE,EAAC,GAAGR;IAErF,IAAIG,OAAOC;IAEX,IAAI,CAACD,MAAM;QACTA,OAAOE,SAASF;IAClB;IAEA,IAAI,CAACA,MAAM;QACT,MAAM,IAAIM,MAAM;IAClB;IAEA,MAAMC,iBAAiB,CAAC,EAAE,EAAEjB,YAAY,CAAC,EAAED,qBAAqB,IAAI,CAAC;IAErE,SAASmB,iBAAiBC,KAAa;QACrC,MAAMC,
|
|
1
|
+
{"version":3,"sources":["../../../../src/actions/build/vite/plugin.ts"],"sourcesContent":["import path from 'node:path'\n\nimport {type ModuleFederationOptions} from '@module-federation/vite'\nimport {type PackageJson} from '@sanity/cli-core'\nimport {type PluginOption} from 'vite'\n\nimport {type WorkbenchExposes} from '../../../resolveWorkbenchApp.js'\nimport {artifactExposes, workbenchArtifacts} from '../artifact.js'\nimport {isMediaLibraryConfigApp} from '../configs/configApp.js'\nimport {\n hasMediaLibraryIslandRuntime,\n MEDIA_LIBRARY_ISLAND_RUNTIME_MODULE,\n} from '../configs/mediaLibraryIslandRuntime.js'\nimport {FEDERATION_FILE_NAME, RUNTIME_DIR} from './constants.js'\nimport {sanityFederationHost} from './plugins/plugin-federation-host.js'\nimport {type FederationOptions, sanityModuleFederation} from './plugins/plugin-module-federation.js'\nimport {sanityEnvironmentPlugin} from './plugins/plugin-sanity-environment.js'\nimport {sanityExtensionArtifacts} from './plugins/plugin-sanity-extension-artifacts.js'\nimport {\n type FederationRuntimeOptions,\n sanityFederationRuntime,\n} from './plugins/plugin-sanity-federation-runtime.js'\n\ninterface FederationPluginOptionsBase extends Omit<Partial<FederationOptions>, 'exposes'> {\n exposes?: WorkbenchExposes\n /** Blueprints build (via `@sanity/runtime-cli`) — emit the resource-bindings module. */\n isBlueprints?: boolean\n pkgJson?: PackageJson\n /**\n * Current working directory to read package.json from, defaults to process.cwd()\n */\n workDir?: string\n}\n\ninterface AppFederationPluginOptions extends FederationPluginOptionsBase {\n isApp: true\n\n /**\n * Relative path to the App entry from the runtime directory, e.g.\n * `../../src/App.tsx`. Omit it for a dock-only app that declares no `entry`:\n * no `./App` is exposed and the remote serves only its views.\n */\n appEntry?: string\n studioConfigPath?: never\n}\n\ninterface StudioFederationPluginOptions extends FederationPluginOptionsBase {\n /** relative path to the Studio config file from the runtime directory (e.g. `../../sanity.config.ts`). */\n studioConfigPath: string\n\n appEntry?: never\n /** @defaultValue false */\n isApp?: false\n}\n\n/**\n * Plugin options for the federation vite plugin.\n *\n * Discriminated on `isApp`:\n * - `isApp: true` → requires `appEntry`\n * - `isApp: false` (default) → requires `studioConfigPath`\n *\n * @internal\n */\ntype FederationPluginOptions = AppFederationPluginOptions | StudioFederationPluginOptions\n\n/**\n * @internal\n */\nexport const federation = (options: FederationPluginOptions): PluginOption => {\n const {exposes, isBlueprints, name: defaultName, pkgJson, workDir = process.cwd()} = options\n\n let name = defaultName\n\n if (!name) {\n name = pkgJson?.name\n }\n\n if (!name) {\n throw new Error('\"name\" option is required but could not be inferred from package.json')\n }\n\n const generatedEntry = `./${RUNTIME_DIR}/${FEDERATION_FILE_NAME}.jsx`\n\n function resolveEntryPath(entry: string) {\n const resolvedPath = path.resolve(workDir, entry)\n\n if (!resolvedPath) {\n throw new Error(\n `Could not resolve path for entry \"${entry}\". Please check that the file exists and the path is correct.`,\n )\n }\n\n return resolvedPath\n }\n\n const entryPath = resolveEntryPath(generatedEntry)\n\n // A Media Library config's `./island-runtime` expose re-exports the mount\n // runtime from the app's installed `sanity`; skip it (the host falls back to\n // degraded rendering for custom inputs) when that version predates the entry,\n // since an unresolvable import would fail the whole build.\n const isConfigApp = isMediaLibraryConfigApp(exposes)\n const islandRuntime = isConfigApp && hasMediaLibraryIslandRuntime(workDir)\n if (isConfigApp && !islandRuntime) {\n // eslint-disable-next-line no-console -- build-time warning for the app developer\n console.warn(\n `The installed sanity version does not ship ${MEDIA_LIBRARY_ISLAND_RUNTIME_MODULE}; ` +\n 'custom field inputs will not render in the Media Library until sanity is upgraded.',\n )\n }\n\n // Each view component (`./views/<view>/<component>`) and each service loader\n // (`./services/<name>`) is exposed straight to the host, pointing at the file\n // the extension-artifacts plugin generates under RUNTIME_DIR. A service's\n // worker bundle carries no expose — the host reaches it through its loader.\n const artifacts = workbenchArtifacts(exposes ?? {}, {islandRuntime})\n const artifactModuleExposes = artifactExposes(artifacts, (artifactPath) =>\n resolveEntryPath(`./${RUNTIME_DIR}/${artifactPath}`),\n )\n\n // A dock-only app (`isApp` with no `appEntry`) has no navigable full-page\n // view, so it exposes no `./App` — only its views. Studios and apps with an\n // entry expose `./App` (the generated render entry).\n const exposesApp = !options.isApp || options.appEntry !== undefined\n\n const federationExposes: NonNullable<ModuleFederationOptions['exposes']> = {\n ...(exposesApp ? {'./App': entryPath} : {}),\n ...artifactModuleExposes,\n }\n\n const runtimeOptions: FederationRuntimeOptions = options.isApp\n ? {appEntry: options.appEntry, isApp: true, isBlueprints}\n : {isApp: false, isBlueprints, studioConfigPath: options.studioConfigPath}\n\n // Every federated app and studio also serves itself standalone. Whenever there's\n // an `./App` to mount (never for a dock-only app), build the SPA client\n // environment from the runtime bootstrap cli-build writes.\n const clientInput = exposesApp ? path.join(workDir, '.sanity', 'runtime', 'app.js') : undefined\n\n return [\n sanityEnvironmentPlugin({clientInput, input: entryPath, isBlueprints}),\n sanityFederationRuntime(runtimeOptions),\n sanityExtensionArtifacts({artifacts}),\n sanityModuleFederation({exposes: federationExposes, name}),\n sanityFederationHost(),\n ]\n}\n"],"names":["path","artifactExposes","workbenchArtifacts","isMediaLibraryConfigApp","hasMediaLibraryIslandRuntime","MEDIA_LIBRARY_ISLAND_RUNTIME_MODULE","FEDERATION_FILE_NAME","RUNTIME_DIR","sanityFederationHost","sanityModuleFederation","sanityEnvironmentPlugin","sanityExtensionArtifacts","sanityFederationRuntime","federation","options","exposes","isBlueprints","name","defaultName","pkgJson","workDir","process","cwd","Error","generatedEntry","resolveEntryPath","entry","resolvedPath","resolve","entryPath","isConfigApp","islandRuntime","console","warn","artifacts","artifactModuleExposes","artifactPath","exposesApp","isApp","appEntry","undefined","federationExposes","runtimeOptions","studioConfigPath","clientInput","join","input"],"mappings":"AAAA,OAAOA,UAAU,YAAW;AAO5B,SAAQC,eAAe,EAAEC,kBAAkB,QAAO,iBAAgB;AAClE,SAAQC,uBAAuB,QAAO,0BAAyB;AAC/D,SACEC,4BAA4B,EAC5BC,mCAAmC,QAC9B,0CAAyC;AAChD,SAAQC,oBAAoB,EAAEC,WAAW,QAAO,iBAAgB;AAChE,SAAQC,oBAAoB,QAAO,sCAAqC;AACxE,SAAgCC,sBAAsB,QAAO,wCAAuC;AACpG,SAAQC,uBAAuB,QAAO,yCAAwC;AAC9E,SAAQC,wBAAwB,QAAO,iDAAgD;AACvF,SAEEC,uBAAuB,QAClB,gDAA+C;AA6CtD;;CAEC,GACD,OAAO,MAAMC,aAAa,CAACC;IACzB,MAAM,EAACC,OAAO,EAAEC,YAAY,EAAEC,MAAMC,WAAW,EAAEC,OAAO,EAAEC,UAAUC,QAAQC,GAAG,EAAE,EAAC,GAAGR;IAErF,IAAIG,OAAOC;IAEX,IAAI,CAACD,MAAM;QACTA,OAAOE,SAASF;IAClB;IAEA,IAAI,CAACA,MAAM;QACT,MAAM,IAAIM,MAAM;IAClB;IAEA,MAAMC,iBAAiB,CAAC,EAAE,EAAEjB,YAAY,CAAC,EAAED,qBAAqB,IAAI,CAAC;IAErE,SAASmB,iBAAiBC,KAAa;QACrC,MAAMC,eAAe3B,KAAK4B,OAAO,CAACR,SAASM;QAE3C,IAAI,CAACC,cAAc;YACjB,MAAM,IAAIJ,MACR,CAAC,kCAAkC,EAAEG,MAAM,6DAA6D,CAAC;QAE7G;QAEA,OAAOC;IACT;IAEA,MAAME,YAAYJ,iBAAiBD;IAEnC,0EAA0E;IAC1E,6EAA6E;IAC7E,8EAA8E;IAC9E,2DAA2D;IAC3D,MAAMM,cAAc3B,wBAAwBY;IAC5C,MAAMgB,gBAAgBD,eAAe1B,6BAA6BgB;IAClE,IAAIU,eAAe,CAACC,eAAe;QACjC,kFAAkF;QAClFC,QAAQC,IAAI,CACV,CAAC,2CAA2C,EAAE5B,oCAAoC,EAAE,CAAC,GACnF;IAEN;IAEA,6EAA6E;IAC7E,8EAA8E;IAC9E,0EAA0E;IAC1E,4EAA4E;IAC5E,MAAM6B,YAAYhC,mBAAmBa,WAAW,CAAC,GAAG;QAACgB;IAAa;IAClE,MAAMI,wBAAwBlC,gBAAgBiC,WAAW,CAACE,eACxDX,iBAAiB,CAAC,EAAE,EAAElB,YAAY,CAAC,EAAE6B,cAAc;IAGrD,0EAA0E;IAC1E,4EAA4E;IAC5E,qDAAqD;IACrD,MAAMC,aAAa,CAACvB,QAAQwB,KAAK,IAAIxB,QAAQyB,QAAQ,KAAKC;IAE1D,MAAMC,oBAAqE;QACzE,GAAIJ,aAAa;YAAC,SAASR;QAAS,IAAI,CAAC,CAAC;QAC1C,GAAGM,qBAAqB;IAC1B;IAEA,MAAMO,iBAA2C5B,QAAQwB,KAAK,GAC1D;QAACC,UAAUzB,QAAQyB,QAAQ;QAAED,OAAO;QAAMtB;IAAY,IACtD;QAACsB,OAAO;QAAOtB;QAAc2B,kBAAkB7B,QAAQ6B,gBAAgB;IAAA;IAE3E,iFAAiF;IACjF,wEAAwE;IACxE,2DAA2D;IAC3D,MAAMC,cAAcP,aAAarC,KAAK6C,IAAI,CAACzB,SAAS,WAAW,WAAW,YAAYoB;IAEtF,OAAO;QACL9B,wBAAwB;YAACkC;YAAaE,OAAOjB;YAAWb;QAAY;QACpEJ,wBAAwB8B;QACxB/B,yBAAyB;YAACuB;QAAS;QACnCzB,uBAAuB;YAACM,SAAS0B;YAAmBxB;QAAI;QACxDT;KACD;AACH,EAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@sanity/ui` v5's cascade-layer namespace. Its stylesheet (which the
|
|
3
|
+
* `sanity` root barrel side-effect imports under the `ui5` npm alias) keeps
|
|
4
|
+
* all component styles in class-scoped rules under `@layer sui`, and its
|
|
5
|
+
* document-wide reset (`*{margin:0;padding:0;...}` and friends) in
|
|
6
|
+
* `@layer sui.global` blocks.
|
|
7
|
+
*/ const SUI_GLOBAL_LAYER = '@layer sui.global';
|
|
8
|
+
/**
|
|
9
|
+
* Remove every `@layer sui.global { ... }` block, keeping the rest of the
|
|
10
|
+
* stylesheet. Layer *statements* (`@layer sui;` / `@layer sui.global;`),
|
|
11
|
+
* which only declare ordering, are left alone.
|
|
12
|
+
*
|
|
13
|
+
* The scanner brace-counts from each block's opening brace; it does not
|
|
14
|
+
* tokenize strings/urls, which is fine for the known content of these blocks
|
|
15
|
+
* (a reset and a font-face) — and a miscount would only under- or over-strip
|
|
16
|
+
* dev styling, never break the build.
|
|
17
|
+
*/ export function stripSuiGlobalLayer(css) {
|
|
18
|
+
let out = css;
|
|
19
|
+
let from = 0;
|
|
20
|
+
for(;;){
|
|
21
|
+
const at = out.indexOf(SUI_GLOBAL_LAYER, from);
|
|
22
|
+
if (at === -1) return out;
|
|
23
|
+
// The layer name must end here (not `sui.globalish`), and the at-rule
|
|
24
|
+
// must open a block — otherwise it is an ordering statement; skip it.
|
|
25
|
+
let cursor = at + SUI_GLOBAL_LAYER.length;
|
|
26
|
+
while(cursor < out.length && /\s/.test(out[cursor]))cursor += 1;
|
|
27
|
+
const boundary = out[at + SUI_GLOBAL_LAYER.length];
|
|
28
|
+
if (out[cursor] !== '{' || boundary !== undefined && !/[\s{,;]/.test(boundary)) {
|
|
29
|
+
from = at + SUI_GLOBAL_LAYER.length;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
let depth = 0;
|
|
33
|
+
let end = -1;
|
|
34
|
+
for(let index = cursor; index < out.length; index += 1){
|
|
35
|
+
if (out[index] === '{') depth += 1;
|
|
36
|
+
else if (out[index] === '}') {
|
|
37
|
+
depth -= 1;
|
|
38
|
+
if (depth === 0) {
|
|
39
|
+
end = index;
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (end === -1) return out // unbalanced: leave the rest untouched
|
|
45
|
+
;
|
|
46
|
+
out = out.slice(0, at) + out.slice(end + 1);
|
|
47
|
+
from = at;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Why strip anything: Media Library config apps bundle the `sanity` barrel
|
|
52
|
+
* (field modules and the island runtime import it), and the barrel
|
|
53
|
+
* side-effect imports `@sanity/ui` v5's stylesheet. Its `@layer sui.global`
|
|
54
|
+
* reset is document-wide, and in dev the config app's modules execute inside
|
|
55
|
+
* the Media Library host's page — so the reset restyles the host (strips
|
|
56
|
+
* body padding etc.). The class-scoped component styles in the same file are
|
|
57
|
+
* harmless to the host and *needed* by islands: `renderDefault` leaf inputs
|
|
58
|
+
* render Studio components that increasingly carry `sui-*` classes. So keep
|
|
59
|
+
* the component styles, drop only the global layer.
|
|
60
|
+
*
|
|
61
|
+
* Why match on content (the `@layer sui.global` marker) rather than the
|
|
62
|
+
* import specifier or file path: the `ui5` alias is the `sanity` package's
|
|
63
|
+
* internal name for `@sanity/ui` v5 and can be renamed or re-pathed in any
|
|
64
|
+
* sanity release; the layer name is the stylesheet's own public CSS surface
|
|
65
|
+
* and travels with the file wherever it resolves from.
|
|
66
|
+
*/ export function stripSuiGlobalReset() {
|
|
67
|
+
return {
|
|
68
|
+
enforce: 'pre',
|
|
69
|
+
name: 'sanity/strip-sui-global-reset',
|
|
70
|
+
transform (code, id) {
|
|
71
|
+
if (!id.split('?', 1)[0].endsWith('.css')) return null;
|
|
72
|
+
if (!code.includes(SUI_GLOBAL_LAYER)) return null;
|
|
73
|
+
const next = stripSuiGlobalLayer(code);
|
|
74
|
+
return next === code ? null : {
|
|
75
|
+
code: next,
|
|
76
|
+
map: null
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
//# sourceMappingURL=plugin-strip-sui-global-reset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/actions/build/vite/plugins/plugin-strip-sui-global-reset.ts"],"sourcesContent":["import {type Plugin} from 'vite'\n\n/**\n * `@sanity/ui` v5's cascade-layer namespace. Its stylesheet (which the\n * `sanity` root barrel side-effect imports under the `ui5` npm alias) keeps\n * all component styles in class-scoped rules under `@layer sui`, and its\n * document-wide reset (`*{margin:0;padding:0;...}` and friends) in\n * `@layer sui.global` blocks.\n */\nconst SUI_GLOBAL_LAYER = '@layer sui.global'\n\n/**\n * Remove every `@layer sui.global { ... }` block, keeping the rest of the\n * stylesheet. Layer *statements* (`@layer sui;` / `@layer sui.global;`),\n * which only declare ordering, are left alone.\n *\n * The scanner brace-counts from each block's opening brace; it does not\n * tokenize strings/urls, which is fine for the known content of these blocks\n * (a reset and a font-face) — and a miscount would only under- or over-strip\n * dev styling, never break the build.\n */\nexport function stripSuiGlobalLayer(css: string): string {\n let out = css\n let from = 0\n for (;;) {\n const at = out.indexOf(SUI_GLOBAL_LAYER, from)\n if (at === -1) return out\n // The layer name must end here (not `sui.globalish`), and the at-rule\n // must open a block — otherwise it is an ordering statement; skip it.\n let cursor = at + SUI_GLOBAL_LAYER.length\n while (cursor < out.length && /\\s/.test(out[cursor])) cursor += 1\n const boundary = out[at + SUI_GLOBAL_LAYER.length]\n if (out[cursor] !== '{' || (boundary !== undefined && !/[\\s{,;]/.test(boundary))) {\n from = at + SUI_GLOBAL_LAYER.length\n continue\n }\n let depth = 0\n let end = -1\n for (let index = cursor; index < out.length; index += 1) {\n if (out[index] === '{') depth += 1\n else if (out[index] === '}') {\n depth -= 1\n if (depth === 0) {\n end = index\n break\n }\n }\n }\n if (end === -1) return out // unbalanced: leave the rest untouched\n out = out.slice(0, at) + out.slice(end + 1)\n from = at\n }\n}\n\n/**\n * Why strip anything: Media Library config apps bundle the `sanity` barrel\n * (field modules and the island runtime import it), and the barrel\n * side-effect imports `@sanity/ui` v5's stylesheet. Its `@layer sui.global`\n * reset is document-wide, and in dev the config app's modules execute inside\n * the Media Library host's page — so the reset restyles the host (strips\n * body padding etc.). The class-scoped component styles in the same file are\n * harmless to the host and *needed* by islands: `renderDefault` leaf inputs\n * render Studio components that increasingly carry `sui-*` classes. So keep\n * the component styles, drop only the global layer.\n *\n * Why match on content (the `@layer sui.global` marker) rather than the\n * import specifier or file path: the `ui5` alias is the `sanity` package's\n * internal name for `@sanity/ui` v5 and can be renamed or re-pathed in any\n * sanity release; the layer name is the stylesheet's own public CSS surface\n * and travels with the file wherever it resolves from.\n */\nexport function stripSuiGlobalReset(): Plugin {\n return {\n enforce: 'pre',\n name: 'sanity/strip-sui-global-reset',\n transform(code, id) {\n if (!id.split('?', 1)[0].endsWith('.css')) return null\n if (!code.includes(SUI_GLOBAL_LAYER)) return null\n const next = stripSuiGlobalLayer(code)\n return next === code ? null : {code: next, map: null}\n },\n }\n}\n"],"names":["SUI_GLOBAL_LAYER","stripSuiGlobalLayer","css","out","from","at","indexOf","cursor","length","test","boundary","undefined","depth","end","index","slice","stripSuiGlobalReset","enforce","name","transform","code","id","split","endsWith","includes","next","map"],"mappings":"AAEA;;;;;;CAMC,GACD,MAAMA,mBAAmB;AAEzB;;;;;;;;;CASC,GACD,OAAO,SAASC,oBAAoBC,GAAW;IAC7C,IAAIC,MAAMD;IACV,IAAIE,OAAO;IACX,OAAS;QACP,MAAMC,KAAKF,IAAIG,OAAO,CAACN,kBAAkBI;QACzC,IAAIC,OAAO,CAAC,GAAG,OAAOF;QACtB,sEAAsE;QACtE,sEAAsE;QACtE,IAAII,SAASF,KAAKL,iBAAiBQ,MAAM;QACzC,MAAOD,SAASJ,IAAIK,MAAM,IAAI,KAAKC,IAAI,CAACN,GAAG,CAACI,OAAO,EAAGA,UAAU;QAChE,MAAMG,WAAWP,GAAG,CAACE,KAAKL,iBAAiBQ,MAAM,CAAC;QAClD,IAAIL,GAAG,CAACI,OAAO,KAAK,OAAQG,aAAaC,aAAa,CAAC,UAAUF,IAAI,CAACC,WAAY;YAChFN,OAAOC,KAAKL,iBAAiBQ,MAAM;YACnC;QACF;QACA,IAAII,QAAQ;QACZ,IAAIC,MAAM,CAAC;QACX,IAAK,IAAIC,QAAQP,QAAQO,QAAQX,IAAIK,MAAM,EAAEM,SAAS,EAAG;YACvD,IAAIX,GAAG,CAACW,MAAM,KAAK,KAAKF,SAAS;iBAC5B,IAAIT,GAAG,CAACW,MAAM,KAAK,KAAK;gBAC3BF,SAAS;gBACT,IAAIA,UAAU,GAAG;oBACfC,MAAMC;oBACN;gBACF;YACF;QACF;QACA,IAAID,QAAQ,CAAC,GAAG,OAAOV,IAAI,uCAAuC;;QAClEA,MAAMA,IAAIY,KAAK,CAAC,GAAGV,MAAMF,IAAIY,KAAK,CAACF,MAAM;QACzCT,OAAOC;IACT;AACF;AAEA;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,SAASW;IACd,OAAO;QACLC,SAAS;QACTC,MAAM;QACNC,WAAUC,IAAI,EAAEC,EAAE;YAChB,IAAI,CAACA,GAAGC,KAAK,CAAC,KAAK,EAAE,CAAC,EAAE,CAACC,QAAQ,CAAC,SAAS,OAAO;YAClD,IAAI,CAACH,KAAKI,QAAQ,CAACxB,mBAAmB,OAAO;YAC7C,MAAMyB,OAAOxB,oBAAoBmB;YACjC,OAAOK,SAASL,OAAO,OAAO;gBAACA,MAAMK;gBAAMC,KAAK;YAAI;QACtD;IACF;AACF"}
|
|
@@ -6,8 +6,10 @@
|
|
|
6
6
|
// live here next to `federation` — the build package just hands over its inputs.
|
|
7
7
|
import path from 'node:path';
|
|
8
8
|
import { readPackageJson } from '@sanity/cli-core';
|
|
9
|
+
import { isMediaLibraryConfigApp } from '../configs/configApp.js';
|
|
9
10
|
import { federation } from './plugin.js';
|
|
10
11
|
import { sanityAppId } from './plugins/plugin-sanity-app-id.js';
|
|
12
|
+
import { stripSuiGlobalReset } from './plugins/plugin-strip-sui-global-reset.js';
|
|
11
13
|
/**
|
|
12
14
|
* A workbench studio renders from its `sanity.config.*`, so the build needs one.
|
|
13
15
|
* An explicit `applicationType: 'studio'` wins over detection, so a studio can
|
|
@@ -39,9 +41,18 @@ import { sanityAppId } from './plugins/plugin-sanity-app-id.js';
|
|
|
39
41
|
pkgJson,
|
|
40
42
|
workDir: cwd
|
|
41
43
|
});
|
|
42
|
-
|
|
44
|
+
// Media Library config apps run their modules inside the host's page, so
|
|
45
|
+
// the `sanity` barrel's document-wide CSS reset must not travel with the
|
|
46
|
+
// bundle (see the plugin for the full why).
|
|
47
|
+
const configAppPlugins = isMediaLibraryConfigApp(exposes) ? [
|
|
48
|
+
stripSuiGlobalReset()
|
|
49
|
+
] : [];
|
|
50
|
+
return [
|
|
51
|
+
...configAppPlugins,
|
|
43
52
|
federationPlugin,
|
|
44
|
-
|
|
53
|
+
...appId === undefined ? [] : [
|
|
54
|
+
sanityAppId(appId)
|
|
55
|
+
]
|
|
45
56
|
];
|
|
46
57
|
}
|
|
47
58
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/actions/build/vite/workbench-vite-plugins.ts"],"sourcesContent":["// The build-facing entry of the workbench federation stack: turn a workbench\n// app's build inputs into the Vite plugins that produce its module-federation\n// remote. `@sanity/cli-build`'s `getViteConfig` calls this instead of\n// assembling `federation`'s options itself, so the discriminated app-vs-studio\n// option shape, the no-app-view rule, and the studio-config requirement all\n// live here next to `federation` — the build package just hands over its inputs.\n\nimport path from 'node:path'\n\nimport {readPackageJson} from '@sanity/cli-core'\nimport {type PluginOption} from 'vite'\n\nimport {type WorkbenchExposes} from '../../../resolveWorkbenchApp.js'\nimport {federation} from './plugin.js'\nimport {sanityAppId} from './plugins/plugin-sanity-app-id.js'\n\ninterface WorkbenchViteOptions {\n /** Project root — read for the federation remote name, and the plugin workDir. */\n cwd: string\n /**\n * Build entry paths relative to the federation runtime dir. `relativeEntry` is\n * the app's `entry` (null for a dock-only app with no app view);\n * `relativeConfigLocation` is the studio's `sanity.config.*` (null when absent).\n */\n entries: {relativeConfigLocation: string | null; relativeEntry: string | null}\n\n /** The app's bus identity, stamped into its modules for `@sanity/runtime`. */\n appId?: string\n\n exposes?: WorkbenchExposes\n /** App (vs studio) build — selects the discriminated federation option shape. */\n isApp?: boolean\n /** Blueprints build (via `@sanity/runtime-cli`) — emit the resource-bindings module. */\n isBlueprints?: boolean\n}\n\n/**\n * A workbench studio renders from its `sanity.config.*`, so the build needs one.\n * An explicit `applicationType: 'studio'` wins over detection, so a studio can\n * reach here with no config file — fail with the fix rather than a cryptic build\n * error downstream.\n */\nfunction requireStudioConfigPath(relativeConfigLocation: string | null): string {\n if (relativeConfigLocation === null) {\n throw new Error(\n 'Dashboard studios need a sanity.config.js or sanity.config.ts file. ' +\n \"Add one, or remove `applicationType: 'studio'` from `defineApplication` \" +\n 'to let the CLI infer the application type.',\n )\n }\n return relativeConfigLocation\n}\n\n/** Build the Vite plugins for a workbench app's module-federation remote. */\nexport async function workbenchVitePlugins(options: WorkbenchViteOptions): Promise<PluginOption> {\n const {appId, cwd, entries, exposes, isApp, isBlueprints} = options\n const pkgJson = await readPackageJson(path.join(cwd, 'package.json'))\n\n const federationPlugin = federation({\n ...(isApp\n ? {\n // `null` relativeEntry (a branded app with no `entry`) → omit `appEntry`,\n // so the remote exposes no `./App`, only its views.\n ...(entries.relativeEntry ? {appEntry: entries.relativeEntry} : {}),\n isApp: true as const,\n }\n : {\n isApp: false as const,\n studioConfigPath: requireStudioConfigPath(entries.relativeConfigLocation),\n }),\n exposes,\n isBlueprints,\n pkgJson,\n workDir: cwd,\n })\n\n return appId === undefined ?
|
|
1
|
+
{"version":3,"sources":["../../../../src/actions/build/vite/workbench-vite-plugins.ts"],"sourcesContent":["// The build-facing entry of the workbench federation stack: turn a workbench\n// app's build inputs into the Vite plugins that produce its module-federation\n// remote. `@sanity/cli-build`'s `getViteConfig` calls this instead of\n// assembling `federation`'s options itself, so the discriminated app-vs-studio\n// option shape, the no-app-view rule, and the studio-config requirement all\n// live here next to `federation` — the build package just hands over its inputs.\n\nimport path from 'node:path'\n\nimport {readPackageJson} from '@sanity/cli-core'\nimport {type PluginOption} from 'vite'\n\nimport {type WorkbenchExposes} from '../../../resolveWorkbenchApp.js'\nimport {isMediaLibraryConfigApp} from '../configs/configApp.js'\nimport {federation} from './plugin.js'\nimport {sanityAppId} from './plugins/plugin-sanity-app-id.js'\nimport {stripSuiGlobalReset} from './plugins/plugin-strip-sui-global-reset.js'\n\ninterface WorkbenchViteOptions {\n /** Project root — read for the federation remote name, and the plugin workDir. */\n cwd: string\n /**\n * Build entry paths relative to the federation runtime dir. `relativeEntry` is\n * the app's `entry` (null for a dock-only app with no app view);\n * `relativeConfigLocation` is the studio's `sanity.config.*` (null when absent).\n */\n entries: {relativeConfigLocation: string | null; relativeEntry: string | null}\n\n /** The app's bus identity, stamped into its modules for `@sanity/runtime`. */\n appId?: string\n\n exposes?: WorkbenchExposes\n /** App (vs studio) build — selects the discriminated federation option shape. */\n isApp?: boolean\n /** Blueprints build (via `@sanity/runtime-cli`) — emit the resource-bindings module. */\n isBlueprints?: boolean\n}\n\n/**\n * A workbench studio renders from its `sanity.config.*`, so the build needs one.\n * An explicit `applicationType: 'studio'` wins over detection, so a studio can\n * reach here with no config file — fail with the fix rather than a cryptic build\n * error downstream.\n */\nfunction requireStudioConfigPath(relativeConfigLocation: string | null): string {\n if (relativeConfigLocation === null) {\n throw new Error(\n 'Dashboard studios need a sanity.config.js or sanity.config.ts file. ' +\n \"Add one, or remove `applicationType: 'studio'` from `defineApplication` \" +\n 'to let the CLI infer the application type.',\n )\n }\n return relativeConfigLocation\n}\n\n/** Build the Vite plugins for a workbench app's module-federation remote. */\nexport async function workbenchVitePlugins(options: WorkbenchViteOptions): Promise<PluginOption> {\n const {appId, cwd, entries, exposes, isApp, isBlueprints} = options\n const pkgJson = await readPackageJson(path.join(cwd, 'package.json'))\n\n const federationPlugin = federation({\n ...(isApp\n ? {\n // `null` relativeEntry (a branded app with no `entry`) → omit `appEntry`,\n // so the remote exposes no `./App`, only its views.\n ...(entries.relativeEntry ? {appEntry: entries.relativeEntry} : {}),\n isApp: true as const,\n }\n : {\n isApp: false as const,\n studioConfigPath: requireStudioConfigPath(entries.relativeConfigLocation),\n }),\n exposes,\n isBlueprints,\n pkgJson,\n workDir: cwd,\n })\n\n // Media Library config apps run their modules inside the host's page, so\n // the `sanity` barrel's document-wide CSS reset must not travel with the\n // bundle (see the plugin for the full why).\n const configAppPlugins: PluginOption[] = isMediaLibraryConfigApp(exposes)\n ? [stripSuiGlobalReset()]\n : []\n\n return [\n ...configAppPlugins,\n federationPlugin,\n ...(appId === undefined ? [] : [sanityAppId(appId)]),\n ]\n}\n"],"names":["path","readPackageJson","isMediaLibraryConfigApp","federation","sanityAppId","stripSuiGlobalReset","requireStudioConfigPath","relativeConfigLocation","Error","workbenchVitePlugins","options","appId","cwd","entries","exposes","isApp","isBlueprints","pkgJson","join","federationPlugin","relativeEntry","appEntry","studioConfigPath","workDir","configAppPlugins","undefined"],"mappings":"AAAA,6EAA6E;AAC7E,8EAA8E;AAC9E,sEAAsE;AACtE,+EAA+E;AAC/E,4EAA4E;AAC5E,iFAAiF;AAEjF,OAAOA,UAAU,YAAW;AAE5B,SAAQC,eAAe,QAAO,mBAAkB;AAIhD,SAAQC,uBAAuB,QAAO,0BAAyB;AAC/D,SAAQC,UAAU,QAAO,cAAa;AACtC,SAAQC,WAAW,QAAO,oCAAmC;AAC7D,SAAQC,mBAAmB,QAAO,6CAA4C;AAsB9E;;;;;CAKC,GACD,SAASC,wBAAwBC,sBAAqC;IACpE,IAAIA,2BAA2B,MAAM;QACnC,MAAM,IAAIC,MACR,yEACE,6EACA;IAEN;IACA,OAAOD;AACT;AAEA,2EAA2E,GAC3E,OAAO,eAAeE,qBAAqBC,OAA6B;IACtE,MAAM,EAACC,KAAK,EAAEC,GAAG,EAAEC,OAAO,EAAEC,OAAO,EAAEC,KAAK,EAAEC,YAAY,EAAC,GAAGN;IAC5D,MAAMO,UAAU,MAAMhB,gBAAgBD,KAAKkB,IAAI,CAACN,KAAK;IAErD,MAAMO,mBAAmBhB,WAAW;QAClC,GAAIY,QACA;YACE,0EAA0E;YAC1E,oDAAoD;YACpD,GAAIF,QAAQO,aAAa,GAAG;gBAACC,UAAUR,QAAQO,aAAa;YAAA,IAAI,CAAC,CAAC;YAClEL,OAAO;QACT,IACA;YACEA,OAAO;YACPO,kBAAkBhB,wBAAwBO,QAAQN,sBAAsB;QAC1E,CAAC;QACLO;QACAE;QACAC;QACAM,SAASX;IACX;IAEA,yEAAyE;IACzE,yEAAyE;IACzE,4CAA4C;IAC5C,MAAMY,mBAAmCtB,wBAAwBY,WAC7D;QAACT;KAAsB,GACvB,EAAE;IAEN,OAAO;WACFmB;QACHL;WACIR,UAAUc,YAAY,EAAE,GAAG;YAACrB,YAAYO;SAAO;KACpD;AACH"}
|
|
@@ -4,8 +4,24 @@
|
|
|
4
4
|
// is not an app. The build and deploy accessors (actions/build, actions/deploy)
|
|
5
5
|
// each build their command-specific view on top of this one brand-check +
|
|
6
6
|
// extraction, so the discrimination lives in exactly one place.
|
|
7
|
+
import { defineWindowView } from './contract.js';
|
|
7
8
|
import { isWorkbenchApp } from './defineApp.js';
|
|
8
9
|
import { formatWorkbenchAppErrors, validateWorkbenchApp } from './validateWorkbenchApp.js';
|
|
10
|
+
/**
|
|
11
|
+
* The module behind the app's `./App` expose. `entry` is shorthand for a window view.
|
|
12
|
+
* @internal
|
|
13
|
+
*/ export function resolveAppEntry(app) {
|
|
14
|
+
if (!isWorkbenchApp(app)) return app?.entry;
|
|
15
|
+
const views = app.entry === undefined ? app.views ?? [] : [
|
|
16
|
+
defineWindowView({
|
|
17
|
+
name: app.name ?? app.slug,
|
|
18
|
+
src: app.entry,
|
|
19
|
+
title: app.title
|
|
20
|
+
}),
|
|
21
|
+
...app.views ?? []
|
|
22
|
+
];
|
|
23
|
+
return views.find((view)=>view.surface === 'window')?.src;
|
|
24
|
+
}
|
|
9
25
|
/**
|
|
10
26
|
* Resolve the workbench app for a CLI config, or `null` for a plain project or a
|
|
11
27
|
* config (which is not an app — read it with `resolveWorkbenchConfig`).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/resolveWorkbenchApp.ts"],"sourcesContent":["// Package-internal shared resolver: turn a CLI config's branded\n// `defineApplication` app into its declared interfaces, or `null` for a plain\n// project — and for a config (a branded `unstable_defineMediaLibrary`), which\n// is not an app. The build and deploy accessors (actions/build, actions/deploy)\n// each build their command-specific view on top of this one brand-check +\n// extraction, so the discrimination lives in exactly one place.\n\nimport {type AppVisibility, type CliConfig} from '@sanity/cli-core'\n\nimport {type WorkbenchConfigValue} from './contract.js'\nimport {type DefineAppInput, isWorkbenchApp} from './defineApp.js'\nimport {formatWorkbenchAppErrors, validateWorkbenchApp} from './validateWorkbenchApp.js'\n\n/**\n * Bundled so adding a declaration family touches this type and the artifact\n * expanders, not every hop of build/dev plumbing in between. `config` is sourced\n * from `resolveWorkbenchConfig` (a config is not an app), not from this resolver.\n * @internal\n */\nexport interface WorkbenchExposes {\n config?: WorkbenchConfigValue\n views?: DefineAppInput['views']\n webWorkers?: DefineAppInput['webWorkers']\n}\n\n/** @public */\nexport interface ResolvedWorkbenchApp {\n /**\n * Stable identity, distinct from the `slug` address. Defaults to `slug`, and is\n * what every identity key (build id, interface ids) is built from.\n */\n readonly name: string\n /** Organization that owns the app — part of its build-id identity. */\n readonly organizationId: string\n readonly slug: string\n\n /** Views the app declares. */\n readonly views: NonNullable<DefineAppInput['views']>\n\n /** Background web workers the app declares. */\n readonly webWorkers: NonNullable<DefineAppInput['webWorkers']>\n\n /** Resolved app kind — `studio` or one of the SDK app types. */\n readonly applicationType?: string\n /** SDK app-view entrypoint, when declared. */\n readonly entry?: string\n /** Path to the app's icon SVG, resolved and shipped to Brett on deploy. */\n readonly icon?: string\n /** Explicit singleton flag for Sanity-owned apps. */\n readonly isSingleton?: boolean\n /** Dashboard visibility declared by the app; `undefined` when unset. */\n readonly visibility?: AppVisibility\n}\n\n/**\n * Resolve the workbench app for a CLI config, or `null` for a plain project or a\n * config (which is not an app — read it with `resolveWorkbenchConfig`).\n * @public\n */\nexport function resolveWorkbenchApp(\n cliConfig: CliConfig | null | undefined,\n): ResolvedWorkbenchApp | null {\n const app = cliConfig?.app\n // A config carries a distinct brand, so `isWorkbenchApp` is false for it — it\n // resolves to `null` here, like a plain project.\n if (!isWorkbenchApp(app)) return null\n\n const errors = validateWorkbenchApp(app)\n if (errors.length > 0) throw new Error(formatWorkbenchAppErrors(errors))\n\n return {\n applicationType: app.applicationType,\n entry: app.entry,\n icon: app.icon,\n ...(app.isSingleton === undefined ? {} : {isSingleton: app.isSingleton}),\n // Identity defaults to the address, so existing apps behave identically.\n name: app.name ?? app.slug,\n organizationId: app.organizationId,\n slug: app.slug,\n views: app.views ?? [],\n visibility: app.visibility,\n webWorkers: app.webWorkers ?? [],\n }\n}\n"],"names":["isWorkbenchApp","formatWorkbenchAppErrors","validateWorkbenchApp","
|
|
1
|
+
{"version":3,"sources":["../src/resolveWorkbenchApp.ts"],"sourcesContent":["// Package-internal shared resolver: turn a CLI config's branded\n// `defineApplication` app into its declared interfaces, or `null` for a plain\n// project — and for a config (a branded `unstable_defineMediaLibrary`), which\n// is not an app. The build and deploy accessors (actions/build, actions/deploy)\n// each build their command-specific view on top of this one brand-check +\n// extraction, so the discrimination lives in exactly one place.\n\nimport {type AppVisibility, type CliConfig} from '@sanity/cli-core'\n\nimport {defineWindowView, type WorkbenchConfigValue} from './contract.js'\nimport {type DefineAppInput, isWorkbenchApp} from './defineApp.js'\nimport {formatWorkbenchAppErrors, validateWorkbenchApp} from './validateWorkbenchApp.js'\n\n/**\n * Bundled so adding a declaration family touches this type and the artifact\n * expanders, not every hop of build/dev plumbing in between. `config` is sourced\n * from `resolveWorkbenchConfig` (a config is not an app), not from this resolver.\n * @internal\n */\nexport interface WorkbenchExposes {\n config?: WorkbenchConfigValue\n views?: DefineAppInput['views']\n webWorkers?: DefineAppInput['webWorkers']\n}\n\n/** @public */\nexport interface ResolvedWorkbenchApp {\n /**\n * Stable identity, distinct from the `slug` address. Defaults to `slug`, and is\n * what every identity key (build id, interface ids) is built from.\n */\n readonly name: string\n /** Organization that owns the app — part of its build-id identity. */\n readonly organizationId: string\n readonly slug: string\n\n /** Views the app declares. */\n readonly views: NonNullable<DefineAppInput['views']>\n\n /** Background web workers the app declares. */\n readonly webWorkers: NonNullable<DefineAppInput['webWorkers']>\n\n /** Resolved app kind — `studio` or one of the SDK app types. */\n readonly applicationType?: string\n /** SDK app-view entrypoint, when declared. */\n readonly entry?: string\n /** Path to the app's icon SVG, resolved and shipped to Brett on deploy. */\n readonly icon?: string\n /** Explicit singleton flag for Sanity-owned apps. */\n readonly isSingleton?: boolean\n /** Dashboard visibility declared by the app; `undefined` when unset. */\n readonly visibility?: AppVisibility\n}\n\n/**\n * The module behind the app's `./App` expose. `entry` is shorthand for a window view.\n * @internal\n */\nexport function resolveAppEntry(app: CliConfig['app']): string | undefined {\n if (!isWorkbenchApp(app)) return app?.entry\n\n const views =\n app.entry === undefined\n ? (app.views ?? [])\n : [\n defineWindowView({name: app.name ?? app.slug, src: app.entry, title: app.title}),\n ...(app.views ?? []),\n ]\n\n return views.find((view) => view.surface === 'window')?.src\n}\n\n/**\n * Resolve the workbench app for a CLI config, or `null` for a plain project or a\n * config (which is not an app — read it with `resolveWorkbenchConfig`).\n * @public\n */\nexport function resolveWorkbenchApp(\n cliConfig: CliConfig | null | undefined,\n): ResolvedWorkbenchApp | null {\n const app = cliConfig?.app\n // A config carries a distinct brand, so `isWorkbenchApp` is false for it — it\n // resolves to `null` here, like a plain project.\n if (!isWorkbenchApp(app)) return null\n\n const errors = validateWorkbenchApp(app)\n if (errors.length > 0) throw new Error(formatWorkbenchAppErrors(errors))\n\n return {\n applicationType: app.applicationType,\n entry: app.entry,\n icon: app.icon,\n ...(app.isSingleton === undefined ? {} : {isSingleton: app.isSingleton}),\n // Identity defaults to the address, so existing apps behave identically.\n name: app.name ?? app.slug,\n organizationId: app.organizationId,\n slug: app.slug,\n views: app.views ?? [],\n visibility: app.visibility,\n webWorkers: app.webWorkers ?? [],\n }\n}\n"],"names":["defineWindowView","isWorkbenchApp","formatWorkbenchAppErrors","validateWorkbenchApp","resolveAppEntry","app","entry","views","undefined","name","slug","src","title","find","view","surface","resolveWorkbenchApp","cliConfig","errors","length","Error","applicationType","icon","isSingleton","organizationId","visibility","webWorkers"],"mappings":"AAAA,gEAAgE;AAChE,8EAA8E;AAC9E,8EAA8E;AAC9E,gFAAgF;AAChF,0EAA0E;AAC1E,gEAAgE;AAIhE,SAAQA,gBAAgB,QAAkC,gBAAe;AACzE,SAA6BC,cAAc,QAAO,iBAAgB;AAClE,SAAQC,wBAAwB,EAAEC,oBAAoB,QAAO,4BAA2B;AA2CxF;;;CAGC,GACD,OAAO,SAASC,gBAAgBC,GAAqB;IACnD,IAAI,CAACJ,eAAeI,MAAM,OAAOA,KAAKC;IAEtC,MAAMC,QACJF,IAAIC,KAAK,KAAKE,YACTH,IAAIE,KAAK,IAAI,EAAE,GAChB;QACEP,iBAAiB;YAACS,MAAMJ,IAAII,IAAI,IAAIJ,IAAIK,IAAI;YAAEC,KAAKN,IAAIC,KAAK;YAAEM,OAAOP,IAAIO,KAAK;QAAA;WAC1EP,IAAIE,KAAK,IAAI,EAAE;KACpB;IAEP,OAAOA,MAAMM,IAAI,CAAC,CAACC,OAASA,KAAKC,OAAO,KAAK,WAAWJ;AAC1D;AAEA;;;;CAIC,GACD,OAAO,SAASK,oBACdC,SAAuC;IAEvC,MAAMZ,MAAMY,WAAWZ;IACvB,8EAA8E;IAC9E,iDAAiD;IACjD,IAAI,CAACJ,eAAeI,MAAM,OAAO;IAEjC,MAAMa,SAASf,qBAAqBE;IACpC,IAAIa,OAAOC,MAAM,GAAG,GAAG,MAAM,IAAIC,MAAMlB,yBAAyBgB;IAEhE,OAAO;QACLG,iBAAiBhB,IAAIgB,eAAe;QACpCf,OAAOD,IAAIC,KAAK;QAChBgB,MAAMjB,IAAIiB,IAAI;QACd,GAAIjB,IAAIkB,WAAW,KAAKf,YAAY,CAAC,IAAI;YAACe,aAAalB,IAAIkB,WAAW;QAAA,CAAC;QACvE,yEAAyE;QACzEd,MAAMJ,IAAII,IAAI,IAAIJ,IAAIK,IAAI;QAC1Bc,gBAAgBnB,IAAImB,cAAc;QAClCd,MAAML,IAAIK,IAAI;QACdH,OAAOF,IAAIE,KAAK,IAAI,EAAE;QACtBkB,YAAYpB,IAAIoB,UAAU;QAC1BC,YAAYrB,IAAIqB,UAAU,IAAI,EAAE;IAClC;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/workbench-cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.10.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",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"dependencies": {
|
|
64
64
|
"@module-federation/runtime": "2.9.2",
|
|
65
65
|
"@module-federation/vite": "1.23.4",
|
|
66
|
-
"@sanity/cli-core": "^3.9.
|
|
66
|
+
"@sanity/cli-core": "^3.9.2",
|
|
67
67
|
"@sanity/sdk": "^3.8.0",
|
|
68
68
|
"@sanity/types": "^6.17.0",
|
|
69
69
|
"@vitejs/plugin-react": "^6.1.2",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"@eslint/compat": "^2.1.0",
|
|
79
79
|
"@repo/package.config": "0.0.1",
|
|
80
80
|
"@repo/tsconfig": "3.70.0",
|
|
81
|
-
"@sanity/cli-test": "19.0.
|
|
81
|
+
"@sanity/cli-test": "19.0.2",
|
|
82
82
|
"@sanity/eslint-config-cli": "^1.1.3",
|
|
83
83
|
"@sanity/pkg-utils": "^12.3.4",
|
|
84
84
|
"@swc/cli": "^0.8.1",
|