@sanity/cli-core 0.1.0-alpha.15 → 0.1.0-alpha.16
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/config/studio/getStudioWorkspaces.js +7 -0
- package/dist/config/studio/getStudioWorkspaces.js.map +1 -1
- package/dist/config/studio/readStudioConfig.worker.js +6 -0
- package/dist/config/studio/readStudioConfig.worker.js.map +1 -1
- package/dist/loaders/studio/studioWorkerLoader.worker.js +101 -22
- package/dist/loaders/studio/studioWorkerLoader.worker.js.map +1 -1
- package/dist/util/doImport.js +2 -1
- package/dist/util/doImport.js.map +1 -1
- package/dist/util/promisifyWorker.js +1 -1
- package/dist/util/promisifyWorker.js.map +1 -1
- package/package.json +9 -8
|
@@ -2,11 +2,13 @@ import { stat } from 'node:fs/promises';
|
|
|
2
2
|
import { dirname } from 'node:path';
|
|
3
3
|
import { isMainThread } from 'node:worker_threads';
|
|
4
4
|
import { firstValueFrom, of } from 'rxjs';
|
|
5
|
+
import { subdebug } from '../../debug.js';
|
|
5
6
|
import { doImport } from '../../util/doImport.js';
|
|
6
7
|
import { getEmptyAuth } from '../../util/getEmptyAuth.js';
|
|
7
8
|
import { resolveLocalPackage } from '../../util/resolveLocalPackage.js';
|
|
8
9
|
import { findStudioConfigPath } from '../util/findStudioConfigPath.js';
|
|
9
10
|
import { isStudioConfig } from './isStudioConfig.js';
|
|
11
|
+
const debug = subdebug('worker:getStudioWorkspaces');
|
|
10
12
|
/**
|
|
11
13
|
* Resolves the workspaces from the studio config.
|
|
12
14
|
*
|
|
@@ -23,14 +25,18 @@ import { isStudioConfig } from './isStudioConfig.js';
|
|
|
23
25
|
if (isDirectory) {
|
|
24
26
|
configPath = await findStudioConfigPath(configPath);
|
|
25
27
|
}
|
|
28
|
+
debug('Finding studio config path %s', configPath);
|
|
26
29
|
let config = await doImport(configPath);
|
|
30
|
+
debug('Imported config %o', config);
|
|
27
31
|
if (!isStudioConfig(config)) {
|
|
28
32
|
if (!('default' in config) || !isStudioConfig(config.default)) {
|
|
33
|
+
debug('Invalid studio config format in "%s"', configPath);
|
|
29
34
|
throw new TypeError(`Invalid studio config format in "${configPath}"`);
|
|
30
35
|
}
|
|
31
36
|
config = config.default;
|
|
32
37
|
}
|
|
33
38
|
const workDir = dirname(configPath);
|
|
39
|
+
debug('Work dir %s', workDir);
|
|
34
40
|
const { resolveConfig } = await resolveLocalPackage('sanity', workDir);
|
|
35
41
|
if (typeof resolveConfig !== 'function') {
|
|
36
42
|
throw new TypeError('Expected `resolveConfig` from `sanity` to be a function');
|
|
@@ -50,6 +56,7 @@ import { isStudioConfig } from './isStudioConfig.js';
|
|
|
50
56
|
state: of(getEmptyAuth())
|
|
51
57
|
}
|
|
52
58
|
}));
|
|
59
|
+
debug('Unauthed workspaces %o', unauthedWorkspaces);
|
|
53
60
|
return firstValueFrom(resolveConfig(unauthedWorkspaces));
|
|
54
61
|
}
|
|
55
62
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/config/studio/getStudioWorkspaces.ts"],"sourcesContent":["import {stat} from 'node:fs/promises'\nimport {dirname} from 'node:path'\nimport {isMainThread} from 'node:worker_threads'\n\nimport {firstValueFrom, of} from 'rxjs'\nimport {type Workspace} from 'sanity'\n\nimport {doImport} from '../../util/doImport.js'\nimport {getEmptyAuth} from '../../util/getEmptyAuth.js'\nimport {resolveLocalPackage} from '../../util/resolveLocalPackage.js'\nimport {findStudioConfigPath} from '../util/findStudioConfigPath.js'\nimport {isStudioConfig} from './isStudioConfig.js'\n\n/**\n * Resolves the workspaces from the studio config.\n *\n * NOTE: This function should only be called from a worker thread.\n *\n * @param configPath - The path to the studio config\n * @returns The workspaces\n * @internal\n */\nexport async function getStudioWorkspaces(configPath: string): Promise<Workspace[]> {\n if (isMainThread) {\n throw new Error('getStudioWorkspaces should only be called from a worker thread')\n }\n const isDirectory = (await stat(configPath)).isDirectory()\n if (isDirectory) {\n configPath = await findStudioConfigPath(configPath)\n }\n let config = await doImport(configPath)\n if (!isStudioConfig(config)) {\n if (!('default' in config) || !isStudioConfig(config.default)) {\n throw new TypeError(`Invalid studio config format in \"${configPath}\"`)\n }\n\n config = config.default\n }\n\n const workDir = dirname(configPath)\n const {resolveConfig} = await resolveLocalPackage<typeof import('sanity')>('sanity', workDir)\n if (typeof resolveConfig !== 'function') {\n throw new TypeError('Expected `resolveConfig` from `sanity` to be a function')\n }\n\n // We will also want to stub out some configuration - we don't need to resolve the\n // users' logged in state, for instance - so let's disable the auth implementation.\n const rawWorkspaces = Array.isArray(config)\n ? config\n : [{...config, basePath: config.basePath || '/', name: config.name || 'default'}]\n\n const unauthedWorkspaces = rawWorkspaces.map((workspace) => ({\n ...workspace,\n auth: {state: of(getEmptyAuth())},\n }))\n\n return firstValueFrom(resolveConfig(unauthedWorkspaces))\n}\n"],"names":["stat","dirname","isMainThread","firstValueFrom","of","doImport","getEmptyAuth","resolveLocalPackage","findStudioConfigPath","isStudioConfig","getStudioWorkspaces","configPath","Error","isDirectory","config","default","TypeError","workDir","resolveConfig","rawWorkspaces","Array","isArray","basePath","name","unauthedWorkspaces","map","workspace","auth","state"],"mappings":"AAAA,SAAQA,IAAI,QAAO,mBAAkB;AACrC,SAAQC,OAAO,QAAO,YAAW;AACjC,SAAQC,YAAY,QAAO,sBAAqB;AAEhD,SAAQC,cAAc,EAAEC,EAAE,QAAO,OAAM;AAGvC,SAAQC,QAAQ,QAAO,yBAAwB;AAC/C,SAAQC,YAAY,QAAO,6BAA4B;AACvD,SAAQC,mBAAmB,QAAO,oCAAmC;AACrE,SAAQC,oBAAoB,QAAO,kCAAiC;AACpE,SAAQC,cAAc,QAAO,sBAAqB;AAElD;;;;;;;;CAQC,GACD,OAAO,
|
|
1
|
+
{"version":3,"sources":["../../../src/config/studio/getStudioWorkspaces.ts"],"sourcesContent":["import {stat} from 'node:fs/promises'\nimport {dirname} from 'node:path'\nimport {isMainThread} from 'node:worker_threads'\n\nimport {firstValueFrom, of} from 'rxjs'\nimport {type Workspace} from 'sanity'\n\nimport {subdebug} from '../../debug.js'\nimport {doImport} from '../../util/doImport.js'\nimport {getEmptyAuth} from '../../util/getEmptyAuth.js'\nimport {resolveLocalPackage} from '../../util/resolveLocalPackage.js'\nimport {findStudioConfigPath} from '../util/findStudioConfigPath.js'\nimport {isStudioConfig} from './isStudioConfig.js'\n\nconst debug = subdebug('worker:getStudioWorkspaces')\n\n/**\n * Resolves the workspaces from the studio config.\n *\n * NOTE: This function should only be called from a worker thread.\n *\n * @param configPath - The path to the studio config\n * @returns The workspaces\n * @internal\n */\nexport async function getStudioWorkspaces(configPath: string): Promise<Workspace[]> {\n if (isMainThread) {\n throw new Error('getStudioWorkspaces should only be called from a worker thread')\n }\n const isDirectory = (await stat(configPath)).isDirectory()\n if (isDirectory) {\n configPath = await findStudioConfigPath(configPath)\n }\n debug('Finding studio config path %s', configPath)\n let config = await doImport(configPath)\n\n debug('Imported config %o', config)\n if (!isStudioConfig(config)) {\n if (!('default' in config) || !isStudioConfig(config.default)) {\n debug('Invalid studio config format in \"%s\"', configPath)\n throw new TypeError(`Invalid studio config format in \"${configPath}\"`)\n }\n\n config = config.default\n }\n\n const workDir = dirname(configPath)\n debug('Work dir %s', workDir)\n const {resolveConfig} = await resolveLocalPackage<typeof import('sanity')>('sanity', workDir)\n if (typeof resolveConfig !== 'function') {\n throw new TypeError('Expected `resolveConfig` from `sanity` to be a function')\n }\n\n // We will also want to stub out some configuration - we don't need to resolve the\n // users' logged in state, for instance - so let's disable the auth implementation.\n const rawWorkspaces = Array.isArray(config)\n ? config\n : [{...config, basePath: config.basePath || '/', name: config.name || 'default'}]\n\n const unauthedWorkspaces = rawWorkspaces.map((workspace) => ({\n ...workspace,\n auth: {state: of(getEmptyAuth())},\n }))\n\n debug('Unauthed workspaces %o', unauthedWorkspaces)\n\n return firstValueFrom(resolveConfig(unauthedWorkspaces))\n}\n"],"names":["stat","dirname","isMainThread","firstValueFrom","of","subdebug","doImport","getEmptyAuth","resolveLocalPackage","findStudioConfigPath","isStudioConfig","debug","getStudioWorkspaces","configPath","Error","isDirectory","config","default","TypeError","workDir","resolveConfig","rawWorkspaces","Array","isArray","basePath","name","unauthedWorkspaces","map","workspace","auth","state"],"mappings":"AAAA,SAAQA,IAAI,QAAO,mBAAkB;AACrC,SAAQC,OAAO,QAAO,YAAW;AACjC,SAAQC,YAAY,QAAO,sBAAqB;AAEhD,SAAQC,cAAc,EAAEC,EAAE,QAAO,OAAM;AAGvC,SAAQC,QAAQ,QAAO,iBAAgB;AACvC,SAAQC,QAAQ,QAAO,yBAAwB;AAC/C,SAAQC,YAAY,QAAO,6BAA4B;AACvD,SAAQC,mBAAmB,QAAO,oCAAmC;AACrE,SAAQC,oBAAoB,QAAO,kCAAiC;AACpE,SAAQC,cAAc,QAAO,sBAAqB;AAElD,MAAMC,QAAQN,SAAS;AAEvB;;;;;;;;CAQC,GACD,OAAO,eAAeO,oBAAoBC,UAAkB;IAC1D,IAAIX,cAAc;QAChB,MAAM,IAAIY,MAAM;IAClB;IACA,MAAMC,cAAc,AAAC,CAAA,MAAMf,KAAKa,WAAU,EAAGE,WAAW;IACxD,IAAIA,aAAa;QACfF,aAAa,MAAMJ,qBAAqBI;IAC1C;IACAF,MAAM,iCAAiCE;IACvC,IAAIG,SAAS,MAAMV,SAASO;IAE5BF,MAAM,sBAAsBK;IAC5B,IAAI,CAACN,eAAeM,SAAS;QAC3B,IAAI,CAAE,CAAA,aAAaA,MAAK,KAAM,CAACN,eAAeM,OAAOC,OAAO,GAAG;YAC7DN,MAAM,wCAAwCE;YAC9C,MAAM,IAAIK,UAAU,CAAC,iCAAiC,EAAEL,WAAW,CAAC,CAAC;QACvE;QAEAG,SAASA,OAAOC,OAAO;IACzB;IAEA,MAAME,UAAUlB,QAAQY;IACxBF,MAAM,eAAeQ;IACrB,MAAM,EAACC,aAAa,EAAC,GAAG,MAAMZ,oBAA6C,UAAUW;IACrF,IAAI,OAAOC,kBAAkB,YAAY;QACvC,MAAM,IAAIF,UAAU;IACtB;IAEA,kFAAkF;IAClF,mFAAmF;IACnF,MAAMG,gBAAgBC,MAAMC,OAAO,CAACP,UAChCA,SACA;QAAC;YAAC,GAAGA,MAAM;YAAEQ,UAAUR,OAAOQ,QAAQ,IAAI;YAAKC,MAAMT,OAAOS,IAAI,IAAI;QAAS;KAAE;IAEnF,MAAMC,qBAAqBL,cAAcM,GAAG,CAAC,CAACC,YAAe,CAAA;YAC3D,GAAGA,SAAS;YACZC,MAAM;gBAACC,OAAO1B,GAAGG;YAAe;QAClC,CAAA;IAEAI,MAAM,0BAA0Be;IAEhC,OAAOvB,eAAeiB,cAAcM;AACtC"}
|
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
import { isMainThread, parentPort, workerData } from 'node:worker_threads';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
+
import { subdebug } from '../../debug.js';
|
|
3
4
|
import { doImport } from '../../util/doImport.js';
|
|
4
5
|
import { safeStructuredClone } from '../../util/safeStructuredClone.js';
|
|
5
6
|
import { getStudioWorkspaces } from './getStudioWorkspaces.js';
|
|
6
7
|
if (isMainThread || !parentPort) {
|
|
7
8
|
throw new Error('Should only be run in a worker!');
|
|
8
9
|
}
|
|
10
|
+
const debug = subdebug('readStudioConfig.worker');
|
|
9
11
|
const { configPath, resolvePlugins } = z.object({
|
|
10
12
|
configPath: z.string(),
|
|
11
13
|
resolvePlugins: z.boolean()
|
|
12
14
|
}).parse(workerData);
|
|
15
|
+
debug('Parsing config path %s', configPath);
|
|
13
16
|
let { default: config } = await doImport(configPath);
|
|
17
|
+
debug('Imported config %o', config);
|
|
14
18
|
if (resolvePlugins) {
|
|
19
|
+
debug('Resolving workspaces');
|
|
15
20
|
config = await getStudioWorkspaces(configPath);
|
|
21
|
+
debug('Resolved workspaces %o', config);
|
|
16
22
|
}
|
|
17
23
|
parentPort.postMessage(safeStructuredClone(config));
|
|
18
24
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/config/studio/readStudioConfig.worker.ts"],"sourcesContent":["import {isMainThread, parentPort, workerData} from 'node:worker_threads'\n\nimport {z} from 'zod'\n\nimport {doImport} from '../../util/doImport.js'\nimport {safeStructuredClone} from '../../util/safeStructuredClone.js'\nimport {getStudioWorkspaces} from './getStudioWorkspaces.js'\n\nif (isMainThread || !parentPort) {\n throw new Error('Should only be run in a worker!')\n}\n\nconst {configPath, resolvePlugins} = z\n .object({configPath: z.string(), resolvePlugins: z.boolean()})\n .parse(workerData)\n\nlet {default: config} = await doImport(configPath)\n\nif (resolvePlugins) {\n config = await getStudioWorkspaces(configPath)\n}\n\nparentPort.postMessage(safeStructuredClone(config))\n"],"names":["isMainThread","parentPort","workerData","z","doImport","safeStructuredClone","getStudioWorkspaces","Error","configPath","resolvePlugins","object","string","boolean","parse","default","config","postMessage"],"mappings":"AAAA,SAAQA,YAAY,EAAEC,UAAU,EAAEC,UAAU,QAAO,sBAAqB;AAExE,SAAQC,CAAC,QAAO,MAAK;AAErB,SAAQC,QAAQ,QAAO,yBAAwB;AAC/C,SAAQC,mBAAmB,QAAO,oCAAmC;AACrE,SAAQC,mBAAmB,QAAO,2BAA0B;AAE5D,
|
|
1
|
+
{"version":3,"sources":["../../../src/config/studio/readStudioConfig.worker.ts"],"sourcesContent":["import {isMainThread, parentPort, workerData} from 'node:worker_threads'\n\nimport {z} from 'zod'\n\nimport {subdebug} from '../../debug.js'\nimport {doImport} from '../../util/doImport.js'\nimport {safeStructuredClone} from '../../util/safeStructuredClone.js'\nimport {getStudioWorkspaces} from './getStudioWorkspaces.js'\n\nif (isMainThread || !parentPort) {\n throw new Error('Should only be run in a worker!')\n}\n\nconst debug = subdebug('readStudioConfig.worker')\n\nconst {configPath, resolvePlugins} = z\n .object({configPath: z.string(), resolvePlugins: z.boolean()})\n .parse(workerData)\n\ndebug('Parsing config path %s', configPath)\n\nlet {default: config} = await doImport(configPath)\n\ndebug('Imported config %o', config)\n\nif (resolvePlugins) {\n debug('Resolving workspaces')\n config = await getStudioWorkspaces(configPath)\n debug('Resolved workspaces %o', config)\n}\n\nparentPort.postMessage(safeStructuredClone(config))\n"],"names":["isMainThread","parentPort","workerData","z","subdebug","doImport","safeStructuredClone","getStudioWorkspaces","Error","debug","configPath","resolvePlugins","object","string","boolean","parse","default","config","postMessage"],"mappings":"AAAA,SAAQA,YAAY,EAAEC,UAAU,EAAEC,UAAU,QAAO,sBAAqB;AAExE,SAAQC,CAAC,QAAO,MAAK;AAErB,SAAQC,QAAQ,QAAO,iBAAgB;AACvC,SAAQC,QAAQ,QAAO,yBAAwB;AAC/C,SAAQC,mBAAmB,QAAO,oCAAmC;AACrE,SAAQC,mBAAmB,QAAO,2BAA0B;AAE5D,IAAIP,gBAAgB,CAACC,YAAY;IAC/B,MAAM,IAAIO,MAAM;AAClB;AAEA,MAAMC,QAAQL,SAAS;AAEvB,MAAM,EAACM,UAAU,EAAEC,cAAc,EAAC,GAAGR,EAClCS,MAAM,CAAC;IAACF,YAAYP,EAAEU,MAAM;IAAIF,gBAAgBR,EAAEW,OAAO;AAAE,GAC3DC,KAAK,CAACb;AAETO,MAAM,0BAA0BC;AAEhC,IAAI,EAACM,SAASC,MAAM,EAAC,GAAG,MAAMZ,SAASK;AAEvCD,MAAM,sBAAsBQ;AAE5B,IAAIN,gBAAgB;IAClBF,MAAM;IACNQ,SAAS,MAAMV,oBAAoBG;IACnCD,MAAM,0BAA0BQ;AAClC;AAEAhB,WAAWiB,WAAW,CAACZ,oBAAoBW"}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { isMainThread } from 'node:worker_threads';
|
|
2
|
-
import { createServer,
|
|
2
|
+
import { createServer, loadEnv, mergeConfig } from 'vite';
|
|
3
|
+
import { ViteNodeRunner } from 'vite-node/client';
|
|
4
|
+
import { ViteNodeServer } from 'vite-node/server';
|
|
5
|
+
import { installSourcemapsSupport } from 'vite-node/source-map';
|
|
3
6
|
import { getCliConfig } from '../../config/cli/getCliConfig.js';
|
|
7
|
+
import { subdebug } from '../../debug.js';
|
|
4
8
|
import { getStudioEnvironmentVariables } from '../../util/environment/getStudioEnvironmentVariables.js';
|
|
5
9
|
import { setupBrowserStubs } from '../../util/environment/setupBrowserStubs.js';
|
|
6
10
|
import { isRecord } from '../../util/isRecord.js';
|
|
@@ -12,12 +16,51 @@ const rootPath = process.env.STUDIO_WORKER_STUDIO_ROOT_PATH;
|
|
|
12
16
|
if (!rootPath) {
|
|
13
17
|
throw new Error('Missing `STUDIO_WORKER_STUDIO_ROOT_PATH` environment variable');
|
|
14
18
|
}
|
|
19
|
+
const debug = subdebug('studio:worker');
|
|
15
20
|
const workerScriptPath = process.env.STUDIO_WORKER_TASK_FILE;
|
|
16
21
|
if (!workerScriptPath) {
|
|
17
22
|
throw new Error('Missing `STUDIO_WORKER_TASK_FILE` environment variable');
|
|
18
23
|
}
|
|
19
24
|
await setupBrowserStubs();
|
|
20
25
|
const studioEnvVars = await getStudioEnvironmentVariables(rootPath);
|
|
26
|
+
// Allow the CLI config (`sanity.cli.(js|ts)`) to define a `vite` property which can
|
|
27
|
+
// extend/modify the default vite configuration for the studio.
|
|
28
|
+
let cliConfig;
|
|
29
|
+
try {
|
|
30
|
+
cliConfig = await getCliConfig(rootPath);
|
|
31
|
+
} catch (err) {
|
|
32
|
+
debug('Failed to load CLI config: %o', err);
|
|
33
|
+
if (!isNotFoundError(err)) {
|
|
34
|
+
// eslint-disable-next-line no-console
|
|
35
|
+
console.warn('[warn] Failed to load CLI config:', err);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Fetches and caches modules from HTTP/HTTPS URLs.
|
|
40
|
+
* Vite's SSR transform treats `https://` imports as external and bypasses the plugin
|
|
41
|
+
* resolve pipeline entirely, so we intercept them at the ViteNodeRunner level instead.
|
|
42
|
+
*/ const httpModuleCache = new Map();
|
|
43
|
+
async function fetchHttpModule(url) {
|
|
44
|
+
const cached = httpModuleCache.get(url);
|
|
45
|
+
if (cached) return {
|
|
46
|
+
code: cached
|
|
47
|
+
};
|
|
48
|
+
debug('Fetching HTTP import: %s', url);
|
|
49
|
+
const response = await fetch(url, {
|
|
50
|
+
signal: AbortSignal.timeout(30_000)
|
|
51
|
+
});
|
|
52
|
+
if (!response.ok) {
|
|
53
|
+
throw new Error(`Failed to fetch module from ${url}: ${response.status} ${response.statusText}`);
|
|
54
|
+
}
|
|
55
|
+
const code = await response.text();
|
|
56
|
+
httpModuleCache.set(url, code);
|
|
57
|
+
return {
|
|
58
|
+
code
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function isHttpsUrl(id) {
|
|
62
|
+
return id.startsWith('https://');
|
|
63
|
+
}
|
|
21
64
|
const defaultViteConfig = {
|
|
22
65
|
build: {
|
|
23
66
|
target: 'node'
|
|
@@ -28,27 +71,28 @@ const defaultViteConfig = {
|
|
|
28
71
|
`process.env.${key}`,
|
|
29
72
|
JSON.stringify(value)
|
|
30
73
|
])),
|
|
74
|
+
// TODO: Combine with `determineIsApp` from `@sanity/cli`
|
|
75
|
+
envPrefix: cliConfig && 'app' in cliConfig ? 'SANITY_APP_' : 'SANITY_STUDIO_',
|
|
76
|
+
esbuild: {
|
|
77
|
+
jsx: 'automatic'
|
|
78
|
+
},
|
|
31
79
|
logLevel: 'error',
|
|
32
80
|
optimizeDeps: {
|
|
33
|
-
|
|
81
|
+
include: undefined,
|
|
82
|
+
noDiscovery: true
|
|
34
83
|
},
|
|
35
84
|
root: rootPath,
|
|
36
85
|
server: {
|
|
37
86
|
hmr: false,
|
|
38
87
|
watch: null
|
|
88
|
+
},
|
|
89
|
+
ssr: {
|
|
90
|
+
/**
|
|
91
|
+
* We don't want to externalize any dependencies, we want everything to run thru vite.
|
|
92
|
+
* Especially for CJS compatibility, etc.
|
|
93
|
+
*/ noExternal: true
|
|
39
94
|
}
|
|
40
95
|
};
|
|
41
|
-
// Allow the CLI config (`sanity.cli.(js|ts)`) to define a `vite` property which can
|
|
42
|
-
// extend/modify the default vite configuration for the studio.
|
|
43
|
-
let cliConfig;
|
|
44
|
-
try {
|
|
45
|
-
cliConfig = await getCliConfig(rootPath);
|
|
46
|
-
} catch (err) {
|
|
47
|
-
if (!isNotFoundError(err)) {
|
|
48
|
-
// eslint-disable-next-line no-console
|
|
49
|
-
console.warn('[warn] Failed to load CLI config:', err);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
96
|
let viteConfig = defaultViteConfig;
|
|
53
97
|
if (typeof cliConfig?.vite === 'function') {
|
|
54
98
|
viteConfig = await cliConfig.vite(viteConfig, {
|
|
@@ -59,6 +103,7 @@ if (typeof cliConfig?.vite === 'function') {
|
|
|
59
103
|
} else if (isRecord(cliConfig?.vite)) {
|
|
60
104
|
viteConfig = mergeConfig(viteConfig, cliConfig.vite);
|
|
61
105
|
}
|
|
106
|
+
debug('Creating Vite server with config: %o', viteConfig);
|
|
62
107
|
// Vite will build the files we give it - targetting Node.js instead of the browser.
|
|
63
108
|
// We include the inject plugin in order to provide the stubs for the undefined global APIs.
|
|
64
109
|
const server = await createServer(viteConfig);
|
|
@@ -68,18 +113,52 @@ await server.pluginContainer.buildStart({});
|
|
|
68
113
|
// Note that Sanity also provides environment variables through `process.env.*` for compat reasons,
|
|
69
114
|
// and so we need to do the same here.
|
|
70
115
|
// @todo is this in line with sanity?
|
|
71
|
-
const env = loadEnv(server.config.mode, server.config.envDir, '');
|
|
116
|
+
const env = loadEnv(server.config.mode, server.config.envDir, viteConfig.envPrefix ?? '');
|
|
72
117
|
for(const key in env){
|
|
73
118
|
process.env[key] ??= env[key];
|
|
74
119
|
}
|
|
75
|
-
// Now we're
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
120
|
+
// Now we're providing the glue that ensures node-specific loading and execution works.
|
|
121
|
+
const node = new ViteNodeServer(server);
|
|
122
|
+
// Should make it easier to debug any crashes in the imported code…
|
|
123
|
+
installSourcemapsSupport({
|
|
124
|
+
getSourceMap: (source)=>node.getSourceMap(source)
|
|
125
|
+
});
|
|
126
|
+
const runner = new ViteNodeRunner({
|
|
127
|
+
base: server.config.base,
|
|
128
|
+
async fetchModule (id) {
|
|
129
|
+
// Vite's SSR transform externalizes https:// imports, so Node's ESM loader
|
|
130
|
+
// would reject them. We fetch the module over HTTP and run it through Vite's
|
|
131
|
+
// SSR transform to rewrite ESM export/import syntax to the __vite_ssr_*
|
|
132
|
+
// format that ViteNodeRunner expects.
|
|
133
|
+
if (isHttpsUrl(id)) {
|
|
134
|
+
const { code: rawCode } = await fetchHttpModule(id);
|
|
135
|
+
const result = await server.ssrTransform(rawCode, null, id);
|
|
136
|
+
return {
|
|
137
|
+
code: result?.code || rawCode
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
return node.fetchModule(id);
|
|
141
|
+
},
|
|
142
|
+
resolveId (id, importer) {
|
|
143
|
+
// Prevent vite-node from trying to resolve HTTP URLs through Node's resolver
|
|
144
|
+
if (isHttpsUrl(id)) return {
|
|
145
|
+
id
|
|
146
|
+
};
|
|
147
|
+
// Resolve any import from an HTTP-fetched module against the remote origin
|
|
148
|
+
// (e.g. esm.sh returns `export * from '/pkg@1.0/es2022/pkg.mjs'`)
|
|
149
|
+
if (importer && isHttpsUrl(importer)) {
|
|
150
|
+
return {
|
|
151
|
+
id: new URL(id, importer).href
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
return node.resolveId(id, importer);
|
|
155
|
+
},
|
|
156
|
+
root: server.config.root
|
|
79
157
|
});
|
|
80
|
-
//
|
|
81
|
-
|
|
82
|
-
//
|
|
83
|
-
await runner.
|
|
158
|
+
// Copied from `vite-node` - it appears that this applies the `define` config from
|
|
159
|
+
// vite, but it also takes a surprisingly long time to execute. Not clear at this
|
|
160
|
+
// point why this is, so we should investigate whether it's necessary or not.
|
|
161
|
+
await runner.executeId('/@vite/env');
|
|
162
|
+
await runner.executeId(workerScriptPath);
|
|
84
163
|
|
|
85
164
|
//# sourceMappingURL=studioWorkerLoader.worker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/loaders/studio/studioWorkerLoader.worker.ts"],"sourcesContent":["import {isMainThread} from 'node:worker_threads'\n\nimport {createServer, createServerModuleRunner, type InlineConfig, loadEnv, mergeConfig} from 'vite'\n\nimport {getCliConfig} from '../../config/cli/getCliConfig.js'\nimport {type CliConfig} from '../../config/cli/types/cliConfig.js'\nimport {getStudioEnvironmentVariables} from '../../util/environment/getStudioEnvironmentVariables.js'\nimport {setupBrowserStubs} from '../../util/environment/setupBrowserStubs.js'\nimport {isRecord} from '../../util/isRecord.js'\nimport {isNotFoundError} from '../../util/NotFoundError.js'\n\nif (isMainThread) {\n throw new Error('Should be child of thread, not the main thread')\n}\n\nconst rootPath = process.env.STUDIO_WORKER_STUDIO_ROOT_PATH\nif (!rootPath) {\n throw new Error('Missing `STUDIO_WORKER_STUDIO_ROOT_PATH` environment variable')\n}\n\nconst workerScriptPath = process.env.STUDIO_WORKER_TASK_FILE\nif (!workerScriptPath) {\n throw new Error('Missing `STUDIO_WORKER_TASK_FILE` environment variable')\n}\n\nawait setupBrowserStubs()\n\nconst studioEnvVars = await getStudioEnvironmentVariables(rootPath)\n\nconst defaultViteConfig: InlineConfig = {\n build: {target: 'node'},\n configFile: false, // @todo Should use `vite` prop from `sanity.cli.ts` (if any)\n // Inject environment variables as compile-time constants for Vite\n define: Object.fromEntries(\n Object.entries(studioEnvVars).map(([key, value]) => [\n `process.env.${key}`,\n JSON.stringify(value),\n ]),\n ),\n logLevel: 'error',\n optimizeDeps: {disabled: true}, // @todo is this necessary? cant remember why was added\n root: rootPath,\n server: {\n hmr: false,\n watch: null,\n },\n}\n\n// Allow the CLI config (`sanity.cli.(js|ts)`) to define a `vite` property which can\n// extend/modify the default vite configuration for the studio.\nlet cliConfig: CliConfig | undefined\ntry {\n cliConfig = await getCliConfig(rootPath)\n} catch (err) {\n if (!isNotFoundError(err)) {\n // eslint-disable-next-line no-console\n console.warn('[warn] Failed to load CLI config:', err)\n }\n}\n\nlet viteConfig = defaultViteConfig\nif (typeof cliConfig?.vite === 'function') {\n viteConfig = (await cliConfig.vite(viteConfig, {\n command: 'build',\n isSsrBuild: true,\n mode: 'production',\n })) as InlineConfig\n} else if (isRecord(cliConfig?.vite)) {\n viteConfig = mergeConfig(viteConfig, cliConfig.vite)\n}\n\n// Vite will build the files we give it - targetting Node.js instead of the browser.\n// We include the inject plugin in order to provide the stubs for the undefined global APIs.\nconst server = await createServer(viteConfig)\n\n// Bit of a hack, but seems necessary based on the `node-vite` binary implementation\nawait server.pluginContainer.buildStart({})\n\n// Load environment variables from `.env` files in the same way as Vite does.\n// Note that Sanity also provides environment variables through `process.env.*` for compat reasons,\n// and so we need to do the same here.\n// @todo is this in line with sanity?\nconst env = loadEnv(server.config.mode, server.config.envDir, '')\nfor (const key in env) {\n process.env[key] ??= env[key]\n}\n\n// Now we're using Vite's Module Runner (replaces vite-node in Vite 4+)\nconst runner = await createServerModuleRunner(server.environments.ssr, {\n hmr: false,\n sourcemapInterceptor: 'prepareStackTrace',\n})\n\n// Apply the `define` config from vite - imports environment variables\nawait runner.import('/@vite/env')\n\n// Execute the worker script\nawait runner.import(workerScriptPath)\n"],"names":["isMainThread","createServer","createServerModuleRunner","loadEnv","mergeConfig","getCliConfig","getStudioEnvironmentVariables","setupBrowserStubs","isRecord","isNotFoundError","Error","rootPath","process","env","STUDIO_WORKER_STUDIO_ROOT_PATH","workerScriptPath","STUDIO_WORKER_TASK_FILE","studioEnvVars","defaultViteConfig","build","target","configFile","define","Object","fromEntries","entries","map","key","value","JSON","stringify","logLevel","optimizeDeps","disabled","root","server","hmr","watch","cliConfig","err","console","warn","viteConfig","vite","command","isSsrBuild","mode","pluginContainer","buildStart","config","envDir","runner","environments","ssr","sourcemapInterceptor","import"],"mappings":"AAAA,SAAQA,YAAY,QAAO,sBAAqB;AAEhD,SAAQC,YAAY,EAAEC,wBAAwB,EAAqBC,OAAO,EAAEC,WAAW,QAAO,OAAM;AAEpG,SAAQC,YAAY,QAAO,mCAAkC;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YAAYsC,YAAYJ,UAAUK,IAAI;AACrD;AAEA,oFAAoF;AACpF,4FAA4F;AAC5F,MAAMR,SAAS,MAAMlC,aAAayC;AAElC,oFAAoF;AACpF,MAAMP,OAAOY,eAAe,CAACC,UAAU,CAAC,CAAC;AAEzC,6EAA6E;AAC7E,mGAAmG;AACnG,sCAAsC;AACtC,qCAAqC;AACrC,MAAMnC,MAAMV,QAAQgC,OAAOc,MAAM,CAACH,IAAI,EAAEX,OAAOc,MAAM,CAACC,MAAM,EAAE;AAC9D,IAAK,MAAMvB,OAAOd,IAAK;IACrBD,QAAQC,GAAG,CAACc,IAAI,KAAKd,GAAG,CAACc,IAAI;AAC/B;AAEA,uEAAuE;AACvE,MAAMwB,SAAS,MAAMjD,yBAAyBiC,OAAOiB,YAAY,CAACC,GAAG,EAAE;IACrEjB,KAAK;IACLkB,sBAAsB;AACxB;AAEA,sEAAsE;AACtE,MAAMH,OAAOI,MAAM,CAAC;AAEpB,4BAA4B;AAC5B,MAAMJ,OAAOI,MAAM,CAACxC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/loaders/studio/studioWorkerLoader.worker.ts"],"sourcesContent":["import {isMainThread} from 'node:worker_threads'\n\nimport {createServer, type InlineConfig, loadEnv, mergeConfig} from 'vite'\nimport {ViteNodeRunner} from 'vite-node/client'\nimport {ViteNodeServer} from 'vite-node/server'\nimport {installSourcemapsSupport} from 'vite-node/source-map'\n\nimport {getCliConfig} from '../../config/cli/getCliConfig.js'\nimport {type CliConfig} from '../../config/cli/types/cliConfig.js'\nimport {subdebug} from '../../debug.js'\nimport {getStudioEnvironmentVariables} from '../../util/environment/getStudioEnvironmentVariables.js'\nimport {setupBrowserStubs} from '../../util/environment/setupBrowserStubs.js'\nimport {isRecord} from '../../util/isRecord.js'\nimport {isNotFoundError} from '../../util/NotFoundError.js'\n\nif (isMainThread) {\n throw new Error('Should be child of thread, not the main thread')\n}\n\nconst rootPath = process.env.STUDIO_WORKER_STUDIO_ROOT_PATH\nif (!rootPath) {\n throw new Error('Missing `STUDIO_WORKER_STUDIO_ROOT_PATH` environment variable')\n}\n\nconst debug = subdebug('studio:worker')\n\nconst workerScriptPath = process.env.STUDIO_WORKER_TASK_FILE\nif (!workerScriptPath) {\n throw new Error('Missing `STUDIO_WORKER_TASK_FILE` environment variable')\n}\n\nawait setupBrowserStubs()\n\nconst studioEnvVars = await getStudioEnvironmentVariables(rootPath)\n\n// Allow the CLI config (`sanity.cli.(js|ts)`) to define a `vite` property which can\n// extend/modify the default vite configuration for the studio.\nlet cliConfig: CliConfig | undefined\ntry {\n cliConfig = await getCliConfig(rootPath)\n} catch (err) {\n debug('Failed to load CLI config: %o', err)\n if (!isNotFoundError(err)) {\n // eslint-disable-next-line no-console\n console.warn('[warn] Failed to load CLI config:', err)\n }\n}\n\n/**\n * Fetches and caches modules from HTTP/HTTPS URLs.\n * Vite's SSR transform treats `https://` imports as external and bypasses the plugin\n * resolve pipeline entirely, so we intercept them at the ViteNodeRunner level instead.\n */\nconst httpModuleCache = new Map<string, string>()\nasync function fetchHttpModule(url: string): Promise<{code: string}> {\n const cached = httpModuleCache.get(url)\n if (cached) return {code: cached}\n\n debug('Fetching HTTP import: %s', url)\n const response = await fetch(url, {signal: AbortSignal.timeout(30_000)})\n if (!response.ok) {\n throw new Error(`Failed to fetch module from ${url}: ${response.status} ${response.statusText}`)\n }\n\n const code = await response.text()\n httpModuleCache.set(url, code)\n return {code}\n}\n\nfunction isHttpsUrl(id: string): boolean {\n return id.startsWith('https://')\n}\n\nconst defaultViteConfig: InlineConfig = {\n build: {target: 'node'},\n configFile: false, // @todo Should use `vite` prop from `sanity.cli.ts` (if any)\n // Inject environment variables as compile-time constants for Vite\n define: Object.fromEntries(\n Object.entries(studioEnvVars).map(([key, value]) => [\n `process.env.${key}`,\n JSON.stringify(value),\n ]),\n ),\n // TODO: Combine with `determineIsApp` from `@sanity/cli`\n envPrefix: cliConfig && 'app' in cliConfig ? 'SANITY_APP_' : 'SANITY_STUDIO_',\n esbuild: {\n jsx: 'automatic',\n },\n logLevel: 'error',\n optimizeDeps: {\n include: undefined,\n noDiscovery: true,\n },\n root: rootPath,\n server: {\n hmr: false,\n watch: null,\n },\n ssr: {\n /**\n * We don't want to externalize any dependencies, we want everything to run thru vite.\n * Especially for CJS compatibility, etc.\n */\n noExternal: true,\n },\n}\n\nlet viteConfig = defaultViteConfig\nif (typeof cliConfig?.vite === 'function') {\n viteConfig = (await cliConfig.vite(viteConfig, {\n command: 'build',\n isSsrBuild: true,\n mode: 'production',\n })) as InlineConfig\n} else if (isRecord(cliConfig?.vite)) {\n viteConfig = mergeConfig(viteConfig, cliConfig.vite)\n}\n\ndebug('Creating Vite server with config: %o', viteConfig)\n// Vite will build the files we give it - targetting Node.js instead of the browser.\n// We include the inject plugin in order to provide the stubs for the undefined global APIs.\nconst server = await createServer(viteConfig)\n\n// Bit of a hack, but seems necessary based on the `node-vite` binary implementation\nawait server.pluginContainer.buildStart({})\n\n// Load environment variables from `.env` files in the same way as Vite does.\n// Note that Sanity also provides environment variables through `process.env.*` for compat reasons,\n// and so we need to do the same here.\n// @todo is this in line with sanity?\nconst env = loadEnv(server.config.mode, server.config.envDir, viteConfig.envPrefix ?? '')\nfor (const key in env) {\n process.env[key] ??= env[key]\n}\n\n// Now we're providing the glue that ensures node-specific loading and execution works.\nconst node = new ViteNodeServer(server)\n\n// Should make it easier to debug any crashes in the imported code…\ninstallSourcemapsSupport({\n getSourceMap: (source) => node.getSourceMap(source),\n})\n\nconst runner = new ViteNodeRunner({\n base: server.config.base,\n async fetchModule(id) {\n // Vite's SSR transform externalizes https:// imports, so Node's ESM loader\n // would reject them. We fetch the module over HTTP and run it through Vite's\n // SSR transform to rewrite ESM export/import syntax to the __vite_ssr_*\n // format that ViteNodeRunner expects.\n if (isHttpsUrl(id)) {\n const {code: rawCode} = await fetchHttpModule(id)\n const result = await server.ssrTransform(rawCode, null, id)\n return {code: result?.code || rawCode}\n }\n return node.fetchModule(id)\n },\n resolveId(id, importer) {\n // Prevent vite-node from trying to resolve HTTP URLs through Node's resolver\n if (isHttpsUrl(id)) return {id}\n // Resolve any import from an HTTP-fetched module against the remote origin\n // (e.g. esm.sh returns `export * from '/pkg@1.0/es2022/pkg.mjs'`)\n if (importer && isHttpsUrl(importer)) {\n return {id: new URL(id, importer).href}\n }\n return node.resolveId(id, importer)\n },\n root: server.config.root,\n})\n\n// Copied from `vite-node` - it appears that this applies the `define` config from\n// vite, but it also takes a surprisingly long time to execute. Not clear at this\n// point why this is, so we should investigate whether it's necessary or not.\nawait runner.executeId('/@vite/env')\n\nawait runner.executeId(workerScriptPath)\n"],"names":["isMainThread","createServer","loadEnv","mergeConfig","ViteNodeRunner","ViteNodeServer","installSourcemapsSupport","getCliConfig","subdebug","getStudioEnvironmentVariables","setupBrowserStubs","isRecord","isNotFoundError","Error","rootPath","process","env","STUDIO_WORKER_STUDIO_ROOT_PATH","debug","workerScriptPath","STUDIO_WORKER_TASK_FILE","studioEnvVars","cliConfig","err","console","warn","httpModuleCache","Map","fetchHttpModule","url","cached","get","code","response","fetch","signal","AbortSignal","timeout","ok","status","statusText","text","set","isHttpsUrl","id","startsWith","defaultViteConfig","build","target","configFile","define","Object","fromEntries","entries","map","key","value","JSON","stringify","envPrefix","esbuild","jsx","logLevel","optimizeDeps","include","undefined","noDiscovery","root","server","hmr","watch","ssr","noExternal","viteConfig","vite","command","isSsrBuild","mode","pluginContainer","buildStart","config","envDir","node","getSourceMap","source","runner","base","fetchModule","rawCode","result","ssrTransform","resolveId","importer","URL","href","executeId"],"mappings":"AAAA,SAAQA,YAAY,QAAO,sBAAqB;AAEhD,SAAQC,YAAY,EAAqBC,OAAO,EAAEC,WAAW,QAAO,OAAM;AAC1E,SAAQC,cAAc,QAAO,mBAAkB;AAC/C,SAAQC,cAAc,QAAO,mBAAkB;AAC/C,SAAQC,wBAAwB,QAAO,uBAAsB;AAE7D,SAAQC,YAAY,QAAO,mCAAkC;AAE7D,SAAQC,QAAQ,QAAO,iBAAgB;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CAACuC,IAAI;AAC/B;AAEA,uFAAuF;AACvF,MAAM2B,OAAO,IAAI7E,eAAe+D;AAEhC,mEAAmE;AACnE9D,yBAAyB;IACvB6E,cAAc,CAACC,SAAWF,KAAKC,YAAY,CAACC;AAC9C;AAEA,MAAMC,SAAS,IAAIjF,eAAe;IAChCkF,MAAMlB,OAAOY,MAAM,CAACM,IAAI;IACxB,MAAMC,aAAY3C,EAAE;QAClB,2EAA2E;QAC3E,6EAA6E;QAC7E,wEAAwE;QACxE,sCAAsC;QACtC,IAAID,WAAWC,KAAK;YAClB,MAAM,EAACZ,MAAMwD,OAAO,EAAC,GAAG,MAAM5D,gBAAgBgB;YAC9C,MAAM6C,SAAS,MAAMrB,OAAOsB,YAAY,CAACF,SAAS,MAAM5C;YACxD,OAAO;gBAACZ,MAAMyD,QAAQzD,QAAQwD;YAAO;QACvC;QACA,OAAON,KAAKK,WAAW,CAAC3C;IAC1B;IACA+C,WAAU/C,EAAE,EAAEgD,QAAQ;QACpB,6EAA6E;QAC7E,IAAIjD,WAAWC,KAAK,OAAO;YAACA;QAAE;QAC9B,2EAA2E;QAC3E,kEAAkE;QAClE,IAAIgD,YAAYjD,WAAWiD,WAAW;YACpC,OAAO;gBAAChD,IAAI,IAAIiD,IAAIjD,IAAIgD,UAAUE,IAAI;YAAA;QACxC;QACA,OAAOZ,KAAKS,SAAS,CAAC/C,IAAIgD;IAC5B;IACAzB,MAAMC,OAAOY,MAAM,CAACb,IAAI;AAC1B;AAEA,kFAAkF;AAClF,iFAAiF;AACjF,6EAA6E;AAC7E,MAAMkB,OAAOU,SAAS,CAAC;AAEvB,MAAMV,OAAOU,SAAS,CAAC5E"}
|
package/dist/util/doImport.js
CHANGED
|
@@ -9,8 +9,9 @@ import { pathToFileURL } from 'node:url';
|
|
|
9
9
|
// Absolute paths in windows are not valid URLs and are not supported by import().
|
|
10
10
|
// We need to convert the path to a file URL.
|
|
11
11
|
// See: https://github.com/nodejs/node/issues/31710
|
|
12
|
+
const url = /^file:\/\//.test(source) ? source : pathToFileURL(source).href;
|
|
12
13
|
// eslint-disable-next-line no-restricted-syntax
|
|
13
|
-
return import(
|
|
14
|
+
return import(/* @vite-ignore */ url);
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
//# sourceMappingURL=doImport.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/util/doImport.ts"],"sourcesContent":["// Only file that should be using dynamic import\nimport {pathToFileURL} from 'node:url'\n\n/**\n * This function is a replacement for built in dynamic import\n * This handles the case for windows file paths especially for absolute paths.\n *\n * @param source - File path\n */\nexport function doImport(source: string) {\n // Absolute paths in windows are not valid URLs and are not supported by import().\n // We need to convert the path to a file URL.\n // See: https://github.com/nodejs/node/issues/31710\n // eslint-disable-next-line no-restricted-syntax\n return import(
|
|
1
|
+
{"version":3,"sources":["../../src/util/doImport.ts"],"sourcesContent":["// Only file that should be using dynamic import\nimport {pathToFileURL} from 'node:url'\n\n/**\n * This function is a replacement for built in dynamic import\n * This handles the case for windows file paths especially for absolute paths.\n *\n * @param source - File path\n */\nexport function doImport(source: string) {\n // Absolute paths in windows are not valid URLs and are not supported by import().\n // We need to convert the path to a file URL.\n // See: https://github.com/nodejs/node/issues/31710\n const url = /^file:\\/\\//.test(source) ? source : pathToFileURL(source).href\n // eslint-disable-next-line no-restricted-syntax\n return import(\n /* @vite-ignore */\n url\n )\n}\n"],"names":["pathToFileURL","doImport","source","url","test","href"],"mappings":"AAAA,gDAAgD;AAChD,SAAQA,aAAa,QAAO,WAAU;AAEtC;;;;;CAKC,GACD,OAAO,SAASC,SAASC,MAAc;IACrC,kFAAkF;IAClF,6CAA6C;IAC7C,mDAAmD;IACnD,MAAMC,MAAM,aAAaC,IAAI,CAACF,UAAUA,SAASF,cAAcE,QAAQG,IAAI;IAC3E,gDAAgD;IAChD,OAAO,MAAM,CACX,gBAAgB,GAChBF;AAEJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/util/promisifyWorker.ts"],"sourcesContent":["import {type Worker} from 'node:worker_threads'\n\nimport {subdebug} from '../debug.js'\n\nconst debug = subdebug('worker')\n\n/**\n * Wraps a Node.js Worker in a Promise that resolves with the first message\n * the worker sends, and rejects on error, message deserialization failure,\n * or non-zero exit code. The worker is terminated after a message or error\n * is received.\n *\n * @param worker - The Worker instance to promisify\n * @returns A promise that resolves with the first message from the worker\n * @throws If the worker emits an error, a message deserialization error, or exits with a non-zero code\n * @internal\n */\nexport function promisifyWorker<T = unknown>(worker: Worker): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n let settled = false\n\n worker.addListener('error', function onWorkerError(err) {\n settled = true\n debug(`Worker error: ${err.message}`, err)\n reject(new Error(`Worker error: ${err.message}`, {cause: err}))\n cleanup()\n })\n // No cleanup() here — the worker is already dead after exiting,\n // so there is nothing to terminate or remove listeners from.\n worker.addListener('exit', function onWorkerExit(code) {\n if (code > 0) {\n debug(`Worker exited with code ${code}`)\n reject(new Error(`Worker exited with code ${code}`))\n } else if (!settled) {\n debug('Worker exited with code 0 without sending a message')\n reject(new Error('Worker exited without sending a message'))\n }\n })\n worker.addListener('messageerror', function onWorkerMessageError(err) {\n settled = true\n debug(`Worker message error: ${err.message}`, err)\n reject(new Error(`Failed to deserialize worker message: ${err}`))\n cleanup()\n })\n worker.addListener('message', function onWorkerMessage(message) {\n settled = true\n debug(
|
|
1
|
+
{"version":3,"sources":["../../src/util/promisifyWorker.ts"],"sourcesContent":["import {type Worker} from 'node:worker_threads'\n\nimport {subdebug} from '../debug.js'\n\nconst debug = subdebug('worker')\n\n/**\n * Wraps a Node.js Worker in a Promise that resolves with the first message\n * the worker sends, and rejects on error, message deserialization failure,\n * or non-zero exit code. The worker is terminated after a message or error\n * is received.\n *\n * @param worker - The Worker instance to promisify\n * @returns A promise that resolves with the first message from the worker\n * @throws If the worker emits an error, a message deserialization error, or exits with a non-zero code\n * @internal\n */\nexport function promisifyWorker<T = unknown>(worker: Worker): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n let settled = false\n\n worker.addListener('error', function onWorkerError(err) {\n settled = true\n debug(`Worker error: ${err.message}`, err)\n reject(new Error(`Worker error: ${err.message}`, {cause: err}))\n cleanup()\n })\n // No cleanup() here — the worker is already dead after exiting,\n // so there is nothing to terminate or remove listeners from.\n worker.addListener('exit', function onWorkerExit(code) {\n if (code > 0) {\n debug(`Worker exited with code ${code}`)\n reject(new Error(`Worker exited with code ${code}`))\n } else if (!settled) {\n debug('Worker exited with code 0 without sending a message')\n reject(new Error('Worker exited without sending a message'))\n }\n })\n worker.addListener('messageerror', function onWorkerMessageError(err) {\n settled = true\n debug(`Worker message error: ${err.message}`, err)\n reject(new Error(`Failed to deserialize worker message: ${err}`))\n cleanup()\n })\n worker.addListener('message', function onWorkerMessage(message) {\n settled = true\n debug('Worker message %o', message)\n resolve(message)\n cleanup()\n })\n\n function cleanup() {\n setImmediate(() => worker.terminate())\n worker.removeAllListeners()\n }\n })\n}\n"],"names":["subdebug","debug","promisifyWorker","worker","Promise","resolve","reject","settled","addListener","onWorkerError","err","message","Error","cause","cleanup","onWorkerExit","code","onWorkerMessageError","onWorkerMessage","setImmediate","terminate","removeAllListeners"],"mappings":"AAEA,SAAQA,QAAQ,QAAO,cAAa;AAEpC,MAAMC,QAAQD,SAAS;AAEvB;;;;;;;;;;CAUC,GACD,OAAO,SAASE,gBAA6BC,MAAc;IACzD,OAAO,IAAIC,QAAW,CAACC,SAASC;QAC9B,IAAIC,UAAU;QAEdJ,OAAOK,WAAW,CAAC,SAAS,SAASC,cAAcC,GAAG;YACpDH,UAAU;YACVN,MAAM,CAAC,cAAc,EAAES,IAAIC,OAAO,EAAE,EAAED;YACtCJ,OAAO,IAAIM,MAAM,CAAC,cAAc,EAAEF,IAAIC,OAAO,EAAE,EAAE;gBAACE,OAAOH;YAAG;YAC5DI;QACF;QACA,gEAAgE;QAChE,6DAA6D;QAC7DX,OAAOK,WAAW,CAAC,QAAQ,SAASO,aAAaC,IAAI;YACnD,IAAIA,OAAO,GAAG;gBACZf,MAAM,CAAC,wBAAwB,EAAEe,MAAM;gBACvCV,OAAO,IAAIM,MAAM,CAAC,wBAAwB,EAAEI,MAAM;YACpD,OAAO,IAAI,CAACT,SAAS;gBACnBN,MAAM;gBACNK,OAAO,IAAIM,MAAM;YACnB;QACF;QACAT,OAAOK,WAAW,CAAC,gBAAgB,SAASS,qBAAqBP,GAAG;YAClEH,UAAU;YACVN,MAAM,CAAC,sBAAsB,EAAES,IAAIC,OAAO,EAAE,EAAED;YAC9CJ,OAAO,IAAIM,MAAM,CAAC,sCAAsC,EAAEF,KAAK;YAC/DI;QACF;QACAX,OAAOK,WAAW,CAAC,WAAW,SAASU,gBAAgBP,OAAO;YAC5DJ,UAAU;YACVN,MAAM,qBAAqBU;YAC3BN,QAAQM;YACRG;QACF;QAEA,SAASA;YACPK,aAAa,IAAMhB,OAAOiB,SAAS;YACnCjB,OAAOkB,kBAAkB;QAC3B;IACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/cli-core",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.16",
|
|
4
4
|
"description": "Sanity CLI core package",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -50,30 +50,31 @@
|
|
|
50
50
|
"@inquirer/prompts": "^8.2.0",
|
|
51
51
|
"@oclif/core": "^4.8.0",
|
|
52
52
|
"@rexxars/jiti": "^2.6.2",
|
|
53
|
-
"@sanity/client": "^7.
|
|
54
|
-
"@sanity/types": "^5.
|
|
53
|
+
"@sanity/client": "^7.16.0",
|
|
54
|
+
"@sanity/types": "^5.12.0",
|
|
55
55
|
"babel-plugin-react-compiler": "^1.0.0",
|
|
56
56
|
"boxen": "^8.0.1",
|
|
57
57
|
"configstore": "^7.0.0",
|
|
58
58
|
"debug": "^4.4.3",
|
|
59
59
|
"get-it": "^8.7.0",
|
|
60
|
-
"read-package-up": "^12.0.0",
|
|
61
60
|
"get-tsconfig": "^4.13.6",
|
|
62
61
|
"import-meta-resolve": "^4.2.0",
|
|
63
62
|
"jsdom": "^27.4.0",
|
|
64
63
|
"json-lexer": "^1.2.0",
|
|
65
64
|
"log-symbols": "^7.0.1",
|
|
66
65
|
"ora": "^9.0.0",
|
|
66
|
+
"read-package-up": "^12.0.0",
|
|
67
67
|
"rxjs": "^7.8.2",
|
|
68
68
|
"tinyglobby": "^0.2.15",
|
|
69
69
|
"tsx": "^4.21.0",
|
|
70
70
|
"typeid-js": "^1.2.0",
|
|
71
71
|
"vite": "^7.3.1",
|
|
72
|
+
"vite-node": "^5.3.0",
|
|
72
73
|
"zod": "^4.3.6"
|
|
73
74
|
},
|
|
74
75
|
"devDependencies": {
|
|
75
76
|
"@eslint/compat": "^2.0.2",
|
|
76
|
-
"@sanity/codegen": "^5.
|
|
77
|
+
"@sanity/codegen": "^5.10.1",
|
|
77
78
|
"@sanity/pkg-utils": "^10.4.4",
|
|
78
79
|
"@sanity/telemetry": "^0.8.1",
|
|
79
80
|
"@swc/cli": "^0.8.0",
|
|
@@ -83,12 +84,12 @@
|
|
|
83
84
|
"@types/node": "^20.19.33",
|
|
84
85
|
"eslint": "^9.39.2",
|
|
85
86
|
"publint": "^0.3.17",
|
|
86
|
-
"sanity": "^5.
|
|
87
|
+
"sanity": "^5.12.0",
|
|
87
88
|
"typescript": "^5.9.3",
|
|
88
89
|
"vitest": "^4.0.18",
|
|
90
|
+
"@repo/package.config": "0.0.1",
|
|
89
91
|
"@repo/tsconfig": "3.70.0",
|
|
90
|
-
"@sanity/eslint-config-cli": "0.0.0-alpha.2"
|
|
91
|
-
"@repo/package.config": "0.0.1"
|
|
92
|
+
"@sanity/eslint-config-cli": "0.0.0-alpha.2"
|
|
92
93
|
},
|
|
93
94
|
"peerDependencies": {
|
|
94
95
|
"@sanity/telemetry": ">=0.8.1 <0.9.0"
|