@sanity/workbench-cli 2.14.0 → 2.14.1
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/dev.d.ts +22 -1
- package/dist/_exports/dev.js +1 -0
- package/dist/_exports/dev.js.map +1 -1
- package/dist/actions/dev/startDevManifestWatcher.js +33 -73
- package/dist/actions/dev/startDevManifestWatcher.js.map +1 -1
- package/dist/actions/dev/watchCliConfig.js +58 -0
- package/dist/actions/dev/watchCliConfig.js.map +1 -0
- package/dist/actions/dev/watchForWorkbenchOptIn.js +51 -0
- package/dist/actions/dev/watchForWorkbenchOptIn.js.map +1 -0
- package/package.json +4 -4
package/dist/_exports/dev.d.ts
CHANGED
|
@@ -52,5 +52,26 @@ interface StartWorkbenchDevOptions {
|
|
|
52
52
|
declare function startWorkbenchDev(options: StartWorkbenchDevOptions): Promise<{
|
|
53
53
|
close: () => Promise<void>;
|
|
54
54
|
}>;
|
|
55
|
-
|
|
55
|
+
interface WatchForWorkbenchOptInOptions {
|
|
56
|
+
/** Stop the plain dev server, freeing its port for the workbench. */
|
|
57
|
+
closePlainServer: () => Promise<void>;
|
|
58
|
+
output: Output;
|
|
59
|
+
startWorkbench: (cliConfig: CliConfig) => Promise<{
|
|
60
|
+
close: () => Promise<void>;
|
|
61
|
+
}>;
|
|
62
|
+
workDir: string;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Hand a running plain `sanity dev` over to the workbench once `sanity.cli.*`
|
|
66
|
+
* opts in with `defineApplication`, so upgrading doesn't need a restart.
|
|
67
|
+
*
|
|
68
|
+
* Costs one directory watch until the handover, which then stops it. A failed
|
|
69
|
+
* handover leaves the watch running so the next save retries.
|
|
70
|
+
*
|
|
71
|
+
* @returns A close for whichever servers are running.
|
|
72
|
+
*/
|
|
73
|
+
declare function watchForWorkbenchOptIn({ closePlainServer, output, startWorkbench, workDir }: WatchForWorkbenchOptInOptions): {
|
|
74
|
+
close: () => Promise<void>;
|
|
75
|
+
};
|
|
76
|
+
export { type StartWorkbenchDevOptions, startWorkbenchDev, watchForWorkbenchOptIn };
|
|
56
77
|
//# sourceMappingURL=dev.d.ts.map
|
package/dist/_exports/dev.js
CHANGED
package/dist/_exports/dev.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/_exports/dev.ts"],"sourcesContent":["export {startWorkbenchDev, type StartWorkbenchDevOptions} from '../actions/dev/startWorkbenchDev.js'\n"],"names":["startWorkbenchDev"],"mappings":"AAAA,SAAQA,iBAAiB,QAAsC,sCAAqC"}
|
|
1
|
+
{"version":3,"sources":["../../src/_exports/dev.ts"],"sourcesContent":["export {startWorkbenchDev, type StartWorkbenchDevOptions} from '../actions/dev/startWorkbenchDev.js'\nexport {watchForWorkbenchOptIn} from '../actions/dev/watchForWorkbenchOptIn.js'\n"],"names":["startWorkbenchDev","watchForWorkbenchOptIn"],"mappings":"AAAA,SAAQA,iBAAiB,QAAsC,sCAAqC;AACpG,SAAQC,sBAAsB,QAAO,2CAA0C"}
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import { watch } from 'node:fs';
|
|
2
1
|
import { basename, dirname } from 'node:path';
|
|
3
2
|
import { findProjectRoot, subdebug } from '@sanity/cli-core';
|
|
4
|
-
import {
|
|
3
|
+
import { watchCliConfig } from './watchCliConfig.js';
|
|
5
4
|
const devDebug = subdebug('dev');
|
|
6
|
-
/**
|
|
7
|
-
* Debounce window between config file events and the next manifest
|
|
8
|
-
* regeneration. Coalesces rapid saves (e.g. editor auto-save) and
|
|
9
|
-
* atomic-rename bursts emitted by tools like VS Code.
|
|
10
|
-
*/ const DEBOUNCE_MS = 250;
|
|
11
5
|
/**
|
|
12
6
|
* Generate the project manifest once and then keep it in sync with the
|
|
13
7
|
* project's config file (`sanity.config.(ts|js)` for studios,
|
|
@@ -24,79 +18,45 @@ const devDebug = subdebug('dev');
|
|
|
24
18
|
*/ export async function startDevManifestWatcher({ extract, extraWatchFilenames, output, update, workDir }) {
|
|
25
19
|
const projectRoot = await findProjectRoot(workDir);
|
|
26
20
|
const configPath = projectRoot.path;
|
|
27
|
-
let running = false;
|
|
28
|
-
let pending = false;
|
|
29
21
|
let closed = false;
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
} finally{
|
|
55
|
-
running = false;
|
|
56
|
-
if (pending && !closed) {
|
|
57
|
-
pending = false;
|
|
58
|
-
void regenerate();
|
|
22
|
+
const watcher = watchCliConfig({
|
|
23
|
+
dir: dirname(configPath),
|
|
24
|
+
filenames: [
|
|
25
|
+
basename(configPath),
|
|
26
|
+
...extraWatchFilenames ?? []
|
|
27
|
+
],
|
|
28
|
+
onChange: async ()=>{
|
|
29
|
+
try {
|
|
30
|
+
const { configs, interfaces, manifest } = await extract({
|
|
31
|
+
configPath,
|
|
32
|
+
workDir
|
|
33
|
+
});
|
|
34
|
+
if (closed) return;
|
|
35
|
+
await update({
|
|
36
|
+
configs,
|
|
37
|
+
interfaces,
|
|
38
|
+
manifest,
|
|
39
|
+
manifestUpdatedAt: new Date().toISOString()
|
|
40
|
+
});
|
|
41
|
+
} catch (err) {
|
|
42
|
+
// Extractors print their own spinner failure; log the reason here so
|
|
43
|
+
// the user sees what went wrong alongside the spinner indicator.
|
|
44
|
+
devDebug('Manifest regeneration failed: %O', err);
|
|
45
|
+
output.warn(`Could not extract manifest for the Dashboard: ${err instanceof Error ? err.message : String(err)}`);
|
|
59
46
|
}
|
|
47
|
+
},
|
|
48
|
+
onError: (err)=>{
|
|
49
|
+
devDebug('Config watcher error: %O', err);
|
|
50
|
+
output.warn(`Manifest watcher error: ${err instanceof Error ? err.message : String(err)}`);
|
|
60
51
|
}
|
|
61
|
-
};
|
|
62
|
-
// Route the initial extraction through `regenerate` too, so file-system
|
|
63
|
-
// events arriving before it finishes get coalesced rather than racing it
|
|
64
|
-
// for the shared output directory.
|
|
65
|
-
void regenerate();
|
|
66
|
-
// Watch the config file's parent directory and filter by filename.
|
|
67
|
-
// Watching the file itself is unreliable across editors that perform
|
|
68
|
-
// atomic-save (delete + rename) — the watcher loses its target once the
|
|
69
|
-
// inode changes. Directory watches survive those transitions.
|
|
70
|
-
// Canonicalize to the real long path so `fs.watch` doesn't abort on Windows
|
|
71
|
-
// short-path dirs. See `canonicalizeWatchDir`.
|
|
72
|
-
const configDir = canonicalizeWatchDir(dirname(configPath));
|
|
73
|
-
const watchFilenames = new Set([
|
|
74
|
-
basename(configPath),
|
|
75
|
-
...extraWatchFilenames ?? []
|
|
76
|
-
]);
|
|
77
|
-
let debounceTimer;
|
|
78
|
-
const onEvent = (_event, filename)=>{
|
|
79
|
-
if (!filename) return;
|
|
80
|
-
const name = typeof filename === 'string' ? filename : filename.toString('utf8');
|
|
81
|
-
if (!watchFilenames.has(name)) return;
|
|
82
|
-
clearTimeout(debounceTimer);
|
|
83
|
-
debounceTimer = setTimeout(()=>{
|
|
84
|
-
void regenerate();
|
|
85
|
-
}, DEBOUNCE_MS);
|
|
86
|
-
};
|
|
87
|
-
const watcher = watch(configDir, onEvent);
|
|
88
|
-
watcher.on('error', (err)=>{
|
|
89
|
-
devDebug('Config watcher error: %O', err);
|
|
90
|
-
output.warn(`Manifest watcher error: ${err instanceof Error ? err.message : String(err)}`);
|
|
91
52
|
});
|
|
53
|
+
// Route the initial extraction through the watcher too, so file-system events
|
|
54
|
+
// arriving before it finishes get coalesced rather than racing it for the
|
|
55
|
+
// shared output directory.
|
|
56
|
+
watcher.run();
|
|
92
57
|
return {
|
|
93
|
-
// Idempotent — a repeat close (e.g. a signal handler racing an explicit
|
|
94
|
-
// close) is a no-op, so we never clear an already-cleared timer or
|
|
95
|
-
// double-close the underlying watcher.
|
|
96
58
|
close: async ()=>{
|
|
97
|
-
if (closed) return;
|
|
98
59
|
closed = true;
|
|
99
|
-
clearTimeout(debounceTimer);
|
|
100
60
|
watcher.close();
|
|
101
61
|
}
|
|
102
62
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/dev/startDevManifestWatcher.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/dev/startDevManifestWatcher.ts"],"sourcesContent":["import {basename, dirname} from 'node:path'\n\nimport {findProjectRoot, type Output, subdebug} from '@sanity/cli-core'\n\nimport {type DevServerConfig, type DevServerInterface} from './deriveConfigs.js'\nimport {watchCliConfig} from './watchCliConfig.js'\n\nconst devDebug = subdebug('dev')\n\ninterface DevManifestWatcher {\n close: () => Promise<void>\n}\n\n/** Subset of registry fields the watcher is allowed to update. */\ninterface ManifestPatch<T> {\n manifest: T | undefined\n manifestUpdatedAt: string\n\n /** Same re-derive-don't-omit contract as `interfaces`. */\n configs?: DevServerConfig[] | undefined\n /**\n * Workbench interfaces (views/web workers/app view) re-derived from the config\n * on each change, so editing `views`/`webWorkers`/`entry` in `sanity.cli.ts`\n * re-syncs live like `title`/`icon`. `undefined` only for\n * non-branded configs — the registry patch is a shallow merge, so extractors\n * must re-derive rather than omit, or the registered set gets wiped.\n */\n interfaces?: DevServerInterface[] | undefined\n}\n\ninterface StartDevManifestWatcherOptions<T> {\n /**\n * Run the project-specific extraction and resolve to the manifest patch, which\n * the watcher stamps with `manifestUpdatedAt` before forwarding. Receives the\n * resolved config path (`sanity.config.ts` for studios, `sanity.cli.ts` for\n * core-apps) and the working directory.\n */\n extract: (params: {\n configPath: string\n workDir: string\n }) => Promise<Omit<ManifestPatch<T>, 'manifestUpdatedAt'>>\n output: Output\n /**\n * Called after every successful extraction with the inlined manifest +\n * interfaces. Awaited, so an interface-set change can rebuild the federation\n * remote before the registry is patched (which is what reloads the workbench).\n */\n update: (patch: ManifestPatch<T>) => Promise<void> | void\n workDir: string\n\n /**\n * Extra config filenames (basenames in the project root directory) that also\n * trigger a regeneration. Studios resolve their project root via\n * `sanity.config.*` but declare workbench interfaces in `sanity.cli.*`, so\n * their watcher needs to react to both files.\n */\n extraWatchFilenames?: readonly string[]\n}\n\n/**\n * Generate the project manifest once and then keep it in sync with the\n * project's config file (`sanity.config.(ts|js)` for studios,\n * `sanity.cli.(ts|js)` for core-apps) on disk. The initial generation runs\n * fire-and-forget so it doesn't block dev-server startup; subsequent\n * file-system events are coalesced behind it, so the extractor never has\n * overlapping writes to its shared output directory. Each successful\n * regeneration inlines the new manifest into the registry via the `update`\n * callback, so any running workbench rebroadcasts to its clients.\n *\n * Errors during extraction are logged as warnings and do not crash the dev\n * server — the previously extracted manifest (if any) stays in the\n * registry.\n */\nexport async function startDevManifestWatcher<T>({\n extract,\n extraWatchFilenames,\n output,\n update,\n workDir,\n}: StartDevManifestWatcherOptions<T>): Promise<DevManifestWatcher> {\n const projectRoot = await findProjectRoot(workDir)\n const configPath = projectRoot.path\n\n let closed = false\n\n const watcher = watchCliConfig({\n dir: dirname(configPath),\n filenames: [basename(configPath), ...(extraWatchFilenames ?? [])],\n onChange: async () => {\n try {\n const {configs, interfaces, manifest} = await extract({configPath, workDir})\n if (closed) return\n await update({\n configs,\n interfaces,\n manifest,\n manifestUpdatedAt: new Date().toISOString(),\n })\n } catch (err) {\n // Extractors print their own spinner failure; log the reason here so\n // the user sees what went wrong alongside the spinner indicator.\n devDebug('Manifest regeneration failed: %O', err)\n output.warn(\n `Could not extract manifest for the Dashboard: ${err instanceof Error ? err.message : String(err)}`,\n )\n }\n },\n onError: (err) => {\n devDebug('Config watcher error: %O', err)\n output.warn(`Manifest watcher error: ${err instanceof Error ? err.message : String(err)}`)\n },\n })\n\n // Route the initial extraction through the watcher too, so file-system events\n // arriving before it finishes get coalesced rather than racing it for the\n // shared output directory.\n watcher.run()\n\n return {\n close: async () => {\n closed = true\n watcher.close()\n },\n }\n}\n"],"names":["basename","dirname","findProjectRoot","subdebug","watchCliConfig","devDebug","startDevManifestWatcher","extract","extraWatchFilenames","output","update","workDir","projectRoot","configPath","path","closed","watcher","dir","filenames","onChange","configs","interfaces","manifest","manifestUpdatedAt","Date","toISOString","err","warn","Error","message","String","onError","run","close"],"mappings":"AAAA,SAAQA,QAAQ,EAAEC,OAAO,QAAO,YAAW;AAE3C,SAAQC,eAAe,EAAeC,QAAQ,QAAO,mBAAkB;AAGvE,SAAQC,cAAc,QAAO,sBAAqB;AAElD,MAAMC,WAAWF,SAAS;AAoD1B;;;;;;;;;;;;;CAaC,GACD,OAAO,eAAeG,wBAA2B,EAC/CC,OAAO,EACPC,mBAAmB,EACnBC,MAAM,EACNC,MAAM,EACNC,OAAO,EAC2B;IAClC,MAAMC,cAAc,MAAMV,gBAAgBS;IAC1C,MAAME,aAAaD,YAAYE,IAAI;IAEnC,IAAIC,SAAS;IAEb,MAAMC,UAAUZ,eAAe;QAC7Ba,KAAKhB,QAAQY;QACbK,WAAW;YAAClB,SAASa;eAAiBL,uBAAuB,EAAE;SAAE;QACjEW,UAAU;YACR,IAAI;gBACF,MAAM,EAACC,OAAO,EAAEC,UAAU,EAAEC,QAAQ,EAAC,GAAG,MAAMf,QAAQ;oBAACM;oBAAYF;gBAAO;gBAC1E,IAAII,QAAQ;gBACZ,MAAML,OAAO;oBACXU;oBACAC;oBACAC;oBACAC,mBAAmB,IAAIC,OAAOC,WAAW;gBAC3C;YACF,EAAE,OAAOC,KAAK;gBACZ,qEAAqE;gBACrE,iEAAiE;gBACjErB,SAAS,oCAAoCqB;gBAC7CjB,OAAOkB,IAAI,CACT,CAAC,8CAA8C,EAAED,eAAeE,QAAQF,IAAIG,OAAO,GAAGC,OAAOJ,MAAM;YAEvG;QACF;QACAK,SAAS,CAACL;YACRrB,SAAS,4BAA4BqB;YACrCjB,OAAOkB,IAAI,CAAC,CAAC,wBAAwB,EAAED,eAAeE,QAAQF,IAAIG,OAAO,GAAGC,OAAOJ,MAAM;QAC3F;IACF;IAEA,8EAA8E;IAC9E,0EAA0E;IAC1E,2BAA2B;IAC3BV,QAAQgB,GAAG;IAEX,OAAO;QACLC,OAAO;YACLlB,SAAS;YACTC,QAAQiB,KAAK;QACf;IACF;AACF"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { watch } from 'node:fs';
|
|
2
|
+
import { canonicalizeWatchDir } from './canonicalizeWatchDir.js';
|
|
3
|
+
/**
|
|
4
|
+
* Debounce window between config file events and the next run. Coalesces rapid
|
|
5
|
+
* saves (e.g. editor auto-save) and atomic-rename bursts emitted by tools like
|
|
6
|
+
* VS Code.
|
|
7
|
+
*/ const DEBOUNCE_MS = 250;
|
|
8
|
+
/**
|
|
9
|
+
* Run `onChange` after edits to config files, debounced and never overlapping: a
|
|
10
|
+
* change that lands mid-run queues exactly one more run once it settles.
|
|
11
|
+
*
|
|
12
|
+
* Watches the parent directory and filters by filename, because a watch on the
|
|
13
|
+
* file itself loses its target when an editor atomic-saves (delete + rename).
|
|
14
|
+
*/ export function watchCliConfig({ dir, filenames, onChange, onError }) {
|
|
15
|
+
const watchFilenames = new Set(filenames);
|
|
16
|
+
let running = false;
|
|
17
|
+
let pending = false;
|
|
18
|
+
let closed = false;
|
|
19
|
+
let debounceTimer;
|
|
20
|
+
let changedFilename;
|
|
21
|
+
const run = async ()=>{
|
|
22
|
+
if (closed) return;
|
|
23
|
+
if (running) {
|
|
24
|
+
pending = true;
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
running = true;
|
|
28
|
+
try {
|
|
29
|
+
await onChange(changedFilename);
|
|
30
|
+
} catch (err) {
|
|
31
|
+
onError(err);
|
|
32
|
+
} finally{
|
|
33
|
+
running = false;
|
|
34
|
+
if (pending && !closed) {
|
|
35
|
+
pending = false;
|
|
36
|
+
void run();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const watcher = watch(canonicalizeWatchDir(dir), (_event, filename)=>{
|
|
41
|
+
if (!filename || !watchFilenames.has(filename)) return;
|
|
42
|
+
changedFilename = filename;
|
|
43
|
+
clearTimeout(debounceTimer);
|
|
44
|
+
debounceTimer = setTimeout(()=>void run(), DEBOUNCE_MS);
|
|
45
|
+
});
|
|
46
|
+
watcher.on('error', onError);
|
|
47
|
+
return {
|
|
48
|
+
close: ()=>{
|
|
49
|
+
if (closed) return;
|
|
50
|
+
closed = true;
|
|
51
|
+
clearTimeout(debounceTimer);
|
|
52
|
+
watcher.close();
|
|
53
|
+
},
|
|
54
|
+
run: ()=>void run()
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
//# sourceMappingURL=watchCliConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/dev/watchCliConfig.ts"],"sourcesContent":["import {watch} from 'node:fs'\n\nimport {canonicalizeWatchDir} from './canonicalizeWatchDir.js'\n\n/**\n * Debounce window between config file events and the next run. Coalesces rapid\n * saves (e.g. editor auto-save) and atomic-rename bursts emitted by tools like\n * VS Code.\n */\nconst DEBOUNCE_MS = 250\n\ninterface CliConfigWatcher {\n /** Stop watching and drop any queued run. Idempotent. */\n close: () => void\n /** Run now, coalesced with config file events like any other change. */\n run: () => void\n}\n\ninterface WatchCliConfigOptions {\n dir: string\n filenames: Iterable<string>\n /** Receives the last changed filename; unset when `run()` fires before any change. */\n onChange: (filename: string | undefined) => Promise<void>\n /** Receives `fs.watch` errors and any rejection from `onChange`. */\n onError: (err: unknown) => void\n}\n\n/**\n * Run `onChange` after edits to config files, debounced and never overlapping: a\n * change that lands mid-run queues exactly one more run once it settles.\n *\n * Watches the parent directory and filters by filename, because a watch on the\n * file itself loses its target when an editor atomic-saves (delete + rename).\n */\nexport function watchCliConfig({\n dir,\n filenames,\n onChange,\n onError,\n}: WatchCliConfigOptions): CliConfigWatcher {\n const watchFilenames = new Set(filenames)\n\n let running = false\n let pending = false\n let closed = false\n let debounceTimer: ReturnType<typeof setTimeout> | undefined\n let changedFilename: string | undefined\n\n const run = async () => {\n if (closed) return\n\n if (running) {\n pending = true\n return\n }\n\n running = true\n try {\n await onChange(changedFilename)\n } catch (err) {\n onError(err)\n } finally {\n running = false\n if (pending && !closed) {\n pending = false\n void run()\n }\n }\n }\n\n const watcher = watch(canonicalizeWatchDir(dir), (_event, filename) => {\n if (!filename || !watchFilenames.has(filename)) return\n changedFilename = filename\n clearTimeout(debounceTimer)\n debounceTimer = setTimeout(() => void run(), DEBOUNCE_MS)\n })\n watcher.on('error', onError)\n\n return {\n close: () => {\n if (closed) return\n closed = true\n clearTimeout(debounceTimer)\n watcher.close()\n },\n run: () => void run(),\n }\n}\n"],"names":["watch","canonicalizeWatchDir","DEBOUNCE_MS","watchCliConfig","dir","filenames","onChange","onError","watchFilenames","Set","running","pending","closed","debounceTimer","changedFilename","run","err","watcher","_event","filename","has","clearTimeout","setTimeout","on","close"],"mappings":"AAAA,SAAQA,KAAK,QAAO,UAAS;AAE7B,SAAQC,oBAAoB,QAAO,4BAA2B;AAE9D;;;;CAIC,GACD,MAAMC,cAAc;AAkBpB;;;;;;CAMC,GACD,OAAO,SAASC,eAAe,EAC7BC,GAAG,EACHC,SAAS,EACTC,QAAQ,EACRC,OAAO,EACe;IACtB,MAAMC,iBAAiB,IAAIC,IAAIJ;IAE/B,IAAIK,UAAU;IACd,IAAIC,UAAU;IACd,IAAIC,SAAS;IACb,IAAIC;IACJ,IAAIC;IAEJ,MAAMC,MAAM;QACV,IAAIH,QAAQ;QAEZ,IAAIF,SAAS;YACXC,UAAU;YACV;QACF;QAEAD,UAAU;QACV,IAAI;YACF,MAAMJ,SAASQ;QACjB,EAAE,OAAOE,KAAK;YACZT,QAAQS;QACV,SAAU;YACRN,UAAU;YACV,IAAIC,WAAW,CAACC,QAAQ;gBACtBD,UAAU;gBACV,KAAKI;YACP;QACF;IACF;IAEA,MAAME,UAAUjB,MAAMC,qBAAqBG,MAAM,CAACc,QAAQC;QACxD,IAAI,CAACA,YAAY,CAACX,eAAeY,GAAG,CAACD,WAAW;QAChDL,kBAAkBK;QAClBE,aAAaR;QACbA,gBAAgBS,WAAW,IAAM,KAAKP,OAAOb;IAC/C;IACAe,QAAQM,EAAE,CAAC,SAAShB;IAEpB,OAAO;QACLiB,OAAO;YACL,IAAIZ,QAAQ;YACZA,SAAS;YACTS,aAAaR;YACbI,QAAQO,KAAK;QACf;QACAT,KAAK,IAAM,KAAKA;IAClB;AACF"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { getCliConfigUncached, subdebug } from '@sanity/cli-core';
|
|
2
|
+
import { isWorkbenchApp, isWorkbenchConfig } from '../../defineApp.js';
|
|
3
|
+
import { watchCliConfig } from './watchCliConfig.js';
|
|
4
|
+
const devDebug = subdebug('dev');
|
|
5
|
+
const noop = async ()=>{};
|
|
6
|
+
/**
|
|
7
|
+
* Hand a running plain `sanity dev` over to the workbench once `sanity.cli.*`
|
|
8
|
+
* opts in with `defineApplication`, so upgrading doesn't need a restart.
|
|
9
|
+
*
|
|
10
|
+
* Costs one directory watch until the handover, which then stops it. A failed
|
|
11
|
+
* handover leaves the watch running so the next save retries.
|
|
12
|
+
*
|
|
13
|
+
* @returns A close for whichever servers are running.
|
|
14
|
+
*/ export function watchForWorkbenchOptIn({ closePlainServer, output, startWorkbench, workDir }) {
|
|
15
|
+
let closeCurrent = closePlainServer;
|
|
16
|
+
const watcher = watchCliConfig({
|
|
17
|
+
dir: workDir,
|
|
18
|
+
filenames: [
|
|
19
|
+
'sanity.cli.js',
|
|
20
|
+
'sanity.cli.ts'
|
|
21
|
+
],
|
|
22
|
+
onChange: async (filename)=>{
|
|
23
|
+
// Mid-edit saves often don't load; the next save retries.
|
|
24
|
+
const cliConfig = await getCliConfigUncached(workDir).catch((err)=>{
|
|
25
|
+
devDebug('Could not load CLI config while watching for the workbench opt-in: %O', err);
|
|
26
|
+
});
|
|
27
|
+
if (!cliConfig) return;
|
|
28
|
+
if (!isWorkbenchApp(cliConfig.app) && !isWorkbenchConfig(cliConfig.app)) return;
|
|
29
|
+
output.log(`${filename} changed, restarting dev server`);
|
|
30
|
+
try {
|
|
31
|
+
await closeCurrent();
|
|
32
|
+
closeCurrent = noop;
|
|
33
|
+
const workbench = await startWorkbench(cliConfig);
|
|
34
|
+
closeCurrent = workbench.close;
|
|
35
|
+
watcher.close();
|
|
36
|
+
} catch (err) {
|
|
37
|
+
output.warn(`Failed to start dev server: ${err instanceof Error ? err.message : String(err)}`);
|
|
38
|
+
output.log(`No dev server is running. Save ${filename} to try again.`);
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
onError: (err)=>devDebug('CLI config watcher error: %O', err)
|
|
42
|
+
});
|
|
43
|
+
return {
|
|
44
|
+
close: async ()=>{
|
|
45
|
+
watcher.close();
|
|
46
|
+
await closeCurrent();
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=watchForWorkbenchOptIn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/dev/watchForWorkbenchOptIn.ts"],"sourcesContent":["import {type CliConfig, getCliConfigUncached, type Output, subdebug} from '@sanity/cli-core'\n\nimport {isWorkbenchApp, isWorkbenchConfig} from '../../defineApp.js'\nimport {watchCliConfig} from './watchCliConfig.js'\n\nconst devDebug = subdebug('dev')\n\nconst noop = async () => {}\n\ninterface WatchForWorkbenchOptInOptions {\n /** Stop the plain dev server, freeing its port for the workbench. */\n closePlainServer: () => Promise<void>\n output: Output\n startWorkbench: (cliConfig: CliConfig) => Promise<{close: () => Promise<void>}>\n workDir: string\n}\n\n/**\n * Hand a running plain `sanity dev` over to the workbench once `sanity.cli.*`\n * opts in with `defineApplication`, so upgrading doesn't need a restart.\n *\n * Costs one directory watch until the handover, which then stops it. A failed\n * handover leaves the watch running so the next save retries.\n *\n * @returns A close for whichever servers are running.\n */\nexport function watchForWorkbenchOptIn({\n closePlainServer,\n output,\n startWorkbench,\n workDir,\n}: WatchForWorkbenchOptInOptions): {close: () => Promise<void>} {\n let closeCurrent = closePlainServer\n\n const watcher = watchCliConfig({\n dir: workDir,\n filenames: ['sanity.cli.js', 'sanity.cli.ts'],\n onChange: async (filename) => {\n // Mid-edit saves often don't load; the next save retries.\n const cliConfig = await getCliConfigUncached(workDir).catch((err) => {\n devDebug('Could not load CLI config while watching for the workbench opt-in: %O', err)\n })\n if (!cliConfig) return\n if (!isWorkbenchApp(cliConfig.app) && !isWorkbenchConfig(cliConfig.app)) return\n\n output.log(`${filename} changed, restarting dev server`)\n\n try {\n await closeCurrent()\n closeCurrent = noop\n const workbench = await startWorkbench(cliConfig)\n closeCurrent = workbench.close\n watcher.close()\n } catch (err) {\n output.warn(\n `Failed to start dev server: ${err instanceof Error ? err.message : String(err)}`,\n )\n output.log(`No dev server is running. Save ${filename} to try again.`)\n }\n },\n onError: (err) => devDebug('CLI config watcher error: %O', err),\n })\n\n return {\n close: async () => {\n watcher.close()\n await closeCurrent()\n },\n }\n}\n"],"names":["getCliConfigUncached","subdebug","isWorkbenchApp","isWorkbenchConfig","watchCliConfig","devDebug","noop","watchForWorkbenchOptIn","closePlainServer","output","startWorkbench","workDir","closeCurrent","watcher","dir","filenames","onChange","filename","cliConfig","catch","err","app","log","workbench","close","warn","Error","message","String","onError"],"mappings":"AAAA,SAAwBA,oBAAoB,EAAeC,QAAQ,QAAO,mBAAkB;AAE5F,SAAQC,cAAc,EAAEC,iBAAiB,QAAO,qBAAoB;AACpE,SAAQC,cAAc,QAAO,sBAAqB;AAElD,MAAMC,WAAWJ,SAAS;AAE1B,MAAMK,OAAO,WAAa;AAU1B;;;;;;;;CAQC,GACD,OAAO,SAASC,uBAAuB,EACrCC,gBAAgB,EAChBC,MAAM,EACNC,cAAc,EACdC,OAAO,EACuB;IAC9B,IAAIC,eAAeJ;IAEnB,MAAMK,UAAUT,eAAe;QAC7BU,KAAKH;QACLI,WAAW;YAAC;YAAiB;SAAgB;QAC7CC,UAAU,OAAOC;YACf,0DAA0D;YAC1D,MAAMC,YAAY,MAAMlB,qBAAqBW,SAASQ,KAAK,CAAC,CAACC;gBAC3Df,SAAS,yEAAyEe;YACpF;YACA,IAAI,CAACF,WAAW;YAChB,IAAI,CAAChB,eAAegB,UAAUG,GAAG,KAAK,CAAClB,kBAAkBe,UAAUG,GAAG,GAAG;YAEzEZ,OAAOa,GAAG,CAAC,GAAGL,SAAS,+BAA+B,CAAC;YAEvD,IAAI;gBACF,MAAML;gBACNA,eAAeN;gBACf,MAAMiB,YAAY,MAAMb,eAAeQ;gBACvCN,eAAeW,UAAUC,KAAK;gBAC9BX,QAAQW,KAAK;YACf,EAAE,OAAOJ,KAAK;gBACZX,OAAOgB,IAAI,CACT,CAAC,4BAA4B,EAAEL,eAAeM,QAAQN,IAAIO,OAAO,GAAGC,OAAOR,MAAM;gBAEnFX,OAAOa,GAAG,CAAC,CAAC,+BAA+B,EAAEL,SAAS,cAAc,CAAC;YACvE;QACF;QACAY,SAAS,CAACT,MAAQf,SAAS,gCAAgCe;IAC7D;IAEA,OAAO;QACLI,OAAO;YACLX,QAAQW,KAAK;YACb,MAAMZ;QACR;IACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/workbench-cli",
|
|
3
|
-
"version": "2.14.
|
|
3
|
+
"version": "2.14.1",
|
|
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.5",
|
|
66
|
-
"@sanity/cli-core": "^3.
|
|
66
|
+
"@sanity/cli-core": "^3.14.0",
|
|
67
67
|
"@sanity/sdk": "^3.8.0",
|
|
68
68
|
"@sanity/types": "^6.17.0",
|
|
69
69
|
"@vitejs/plugin-react": "^6.1.2",
|
|
@@ -78,12 +78,12 @@
|
|
|
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": "
|
|
81
|
+
"@sanity/cli-test": "24.0.0",
|
|
82
82
|
"@sanity/eslint-config-cli": "^1.1.3",
|
|
83
83
|
"@sanity/pkg-utils": "^12.3.4",
|
|
84
84
|
"@swc/cli": "^0.8.1",
|
|
85
85
|
"@swc/core": "^1.15.43",
|
|
86
|
-
"@types/node": "^22.20.
|
|
86
|
+
"@types/node": "^22.20.5",
|
|
87
87
|
"@types/react": "^19.3.0",
|
|
88
88
|
"@types/semver": "^7.7.1",
|
|
89
89
|
"@vitest/coverage-istanbul": "^4.1.11",
|