@sanity/cli-core 3.9.0 → 3.9.2
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 +5 -6
- package/dist/config/studio/getStudioWorkspaces.js.map +1 -1
- package/dist/loaders/studio/skipDependencySourcemapsPlugin.js +48 -0
- package/dist/loaders/studio/skipDependencySourcemapsPlugin.js.map +1 -0
- package/dist/loaders/studio/studioWorkerLoader.worker.js +5 -0
- package/dist/loaders/studio/studioWorkerLoader.worker.js.map +1 -1
- package/package.json +1 -1
|
@@ -24,14 +24,13 @@ const debug = subdebug('worker:getStudioWorkspaces');
|
|
|
24
24
|
configPath = await findStudioConfigPath(configPath);
|
|
25
25
|
}
|
|
26
26
|
debug('Finding studio config path %s', configPath);
|
|
27
|
-
|
|
27
|
+
const mod = await doImport(configPath);
|
|
28
|
+
// Named exports like `projectId` can make the module itself look like a config
|
|
29
|
+
const config = 'default' in mod && isStudioConfig(mod.default) ? mod.default : mod;
|
|
28
30
|
debug('Imported config %o', config);
|
|
29
31
|
if (!isStudioConfig(config)) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
throw new TypeError(`Invalid studio config format in "${configPath}"`);
|
|
33
|
-
}
|
|
34
|
-
config = config.default;
|
|
32
|
+
debug('Invalid studio config format in "%s"', configPath);
|
|
33
|
+
throw new TypeError(`Invalid studio config format in "${configPath}"`);
|
|
35
34
|
}
|
|
36
35
|
const workDir = dirname(configPath);
|
|
37
36
|
debug('Work dir %s', workDir);
|
|
@@ -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 {type Workspace} from 'sanity'\n\nimport {subdebug} from '../../_exports/debug.js'\nimport {doImport} from '../../util/doImport.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
|
|
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 {type Workspace} from 'sanity'\n\nimport {subdebug} from '../../_exports/debug.js'\nimport {doImport} from '../../util/doImport.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 const mod = await doImport(configPath)\n // Named exports like `projectId` can make the module itself look like a config\n const config = 'default' in mod && isStudioConfig(mod.default) ? mod.default : mod\n\n debug('Imported config %o', config)\n if (!isStudioConfig(config)) {\n debug('Invalid studio config format in \"%s\"', configPath)\n throw new TypeError(`Invalid studio config format in \"${configPath}\"`)\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 // Imported lazily: rxjs and `@sanity/client` are only needed here, but this\n // module is reachable from the `@sanity/cli-core` barrel that every command loads.\n const [{firstValueFrom, of}, {getEmptyAuth}] = await Promise.all([\n // eslint-disable-next-line no-restricted-syntax -- package import, not a file path\n import('rxjs'),\n // eslint-disable-next-line no-restricted-syntax -- static relative import, not a user file path\n import('../../util/getEmptyAuth.js'),\n ])\n const emptyAuth = {state: of(getEmptyAuth())}\n\n const unauthedWorkspaces = rawWorkspaces.map((workspace) => ({\n ...workspace,\n auth: emptyAuth,\n }))\n\n debug('Unauthed workspaces %o', unauthedWorkspaces)\n\n return firstValueFrom(resolveConfig(unauthedWorkspaces))\n}\n"],"names":["stat","dirname","isMainThread","subdebug","doImport","resolveLocalPackage","findStudioConfigPath","isStudioConfig","debug","getStudioWorkspaces","configPath","Error","isDirectory","mod","config","default","TypeError","workDir","resolveConfig","rawWorkspaces","Array","isArray","basePath","name","firstValueFrom","of","getEmptyAuth","Promise","all","emptyAuth","state","unauthedWorkspaces","map","workspace","auth"],"mappings":"AAAA,SAAQA,IAAI,QAAO,mBAAkB;AACrC,SAAQC,OAAO,QAAO,YAAW;AACjC,SAAQC,YAAY,QAAO,sBAAqB;AAIhD,SAAQC,QAAQ,QAAO,0BAAyB;AAChD,SAAQC,QAAQ,QAAO,yBAAwB;AAC/C,SAAQC,mBAAmB,QAAO,oCAAmC;AACrE,SAAQC,oBAAoB,QAAO,kCAAiC;AACpE,SAAQC,cAAc,QAAO,sBAAqB;AAElD,M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AAA;YAC3D,GAAGA,SAAS;YACZC,MAAML;QACR,CAAA;IAEArB,MAAM,0BAA0BuB;IAEhC,OAAOP,eAAeN,cAAca;AACtC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
const DEPENDENCY_SCRIPT_RE = /[\\/]node_modules[\\/].+\.[cm]?js$/;
|
|
3
|
+
// Mirrors the `//# sourceMappingURL=` form Vite itself strips (via `convert-source-map`)
|
|
4
|
+
const SOURCEMAP_COMMENT_RE = /^[ \t]*\/\/[#@][ \t]+sourceMappingURL=[^\s'"`]+[ \t]*$/gm;
|
|
5
|
+
/**
|
|
6
|
+
* Loads plain JavaScript files from `node_modules` without their source maps.
|
|
7
|
+
*
|
|
8
|
+
* The studio worker runs every dependency through Vite's SSR transform
|
|
9
|
+
* (`ssr.noExternal: true`). By default Vite reads each dependency's `.js.map`,
|
|
10
|
+
* combines it with the SSR transform's own map, inlines the result as a base64
|
|
11
|
+
* comment and the module runner then has Node parse it again for stack traces.
|
|
12
|
+
* For a studio that imports `sanity` this means thousands of modules and tens of
|
|
13
|
+
* megabytes of source maps, which roughly doubles the worker's peak memory.
|
|
14
|
+
*
|
|
15
|
+
* Returning `map: {mappings: ''}` from `load` tells Vite there is no source map
|
|
16
|
+
* to preserve, so none of that work happens for dependencies. User code (the
|
|
17
|
+
* studio config, schema files, plugins outside `node_modules`) keeps full source
|
|
18
|
+
* maps. Stack frames inside dependencies still name the file, through a
|
|
19
|
+
* `sourceURL` comment, but their line numbers refer to the transformed code.
|
|
20
|
+
*
|
|
21
|
+
* @internal
|
|
22
|
+
*/ export function skipDependencySourcemapsPlugin() {
|
|
23
|
+
return {
|
|
24
|
+
// Run after other plugins' `load` hooks so user plugins can still claim these files
|
|
25
|
+
enforce: 'post',
|
|
26
|
+
async load (id) {
|
|
27
|
+
if (id.startsWith('\0') || id.includes('?') || !DEPENDENCY_SCRIPT_RE.test(id)) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
let code;
|
|
31
|
+
try {
|
|
32
|
+
code = await readFile(id, 'utf8');
|
|
33
|
+
} catch {
|
|
34
|
+
// Let Vite's own loader produce its usual error
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
code: `${code.replaceAll(SOURCEMAP_COMMENT_RE, '')}\n//# sourceURL=${id.replaceAll(/\s/g, encodeURIComponent)}\n`,
|
|
39
|
+
map: {
|
|
40
|
+
mappings: ''
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
name: 'sanity:studio-worker-skip-dependency-sourcemaps'
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
//# sourceMappingURL=skipDependencySourcemapsPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/loaders/studio/skipDependencySourcemapsPlugin.ts"],"sourcesContent":["import {readFile} from 'node:fs/promises'\n\nimport {type Plugin} from 'vite'\n\nconst DEPENDENCY_SCRIPT_RE = /[\\\\/]node_modules[\\\\/].+\\.[cm]?js$/\n// Mirrors the `//# sourceMappingURL=` form Vite itself strips (via `convert-source-map`)\nconst SOURCEMAP_COMMENT_RE = /^[ \\t]*\\/\\/[#@][ \\t]+sourceMappingURL=[^\\s'\"`]+[ \\t]*$/gm\n\n/**\n * Loads plain JavaScript files from `node_modules` without their source maps.\n *\n * The studio worker runs every dependency through Vite's SSR transform\n * (`ssr.noExternal: true`). By default Vite reads each dependency's `.js.map`,\n * combines it with the SSR transform's own map, inlines the result as a base64\n * comment and the module runner then has Node parse it again for stack traces.\n * For a studio that imports `sanity` this means thousands of modules and tens of\n * megabytes of source maps, which roughly doubles the worker's peak memory.\n *\n * Returning `map: {mappings: ''}` from `load` tells Vite there is no source map\n * to preserve, so none of that work happens for dependencies. User code (the\n * studio config, schema files, plugins outside `node_modules`) keeps full source\n * maps. Stack frames inside dependencies still name the file, through a\n * `sourceURL` comment, but their line numbers refer to the transformed code.\n *\n * @internal\n */\nexport function skipDependencySourcemapsPlugin(): Plugin {\n return {\n // Run after other plugins' `load` hooks so user plugins can still claim these files\n enforce: 'post',\n async load(id) {\n if (id.startsWith('\\0') || id.includes('?') || !DEPENDENCY_SCRIPT_RE.test(id)) {\n return null\n }\n\n let code: string\n try {\n code = await readFile(id, 'utf8')\n } catch {\n // Let Vite's own loader produce its usual error\n return null\n }\n\n return {\n code: `${code.replaceAll(SOURCEMAP_COMMENT_RE, '')}\\n//# sourceURL=${id.replaceAll(/\\s/g, encodeURIComponent)}\\n`,\n map: {mappings: ''},\n }\n },\n name: 'sanity:studio-worker-skip-dependency-sourcemaps',\n }\n}\n"],"names":["readFile","DEPENDENCY_SCRIPT_RE","SOURCEMAP_COMMENT_RE","skipDependencySourcemapsPlugin","enforce","load","id","startsWith","includes","test","code","replaceAll","encodeURIComponent","map","mappings","name"],"mappings":"AAAA,SAAQA,QAAQ,QAAO,mBAAkB;AAIzC,MAAMC,uBAAuB;AAC7B,yFAAyF;AACzF,MAAMC,uBAAuB;AAE7B;;;;;;;;;;;;;;;;;CAiBC,GACD,OAAO,SAASC;IACd,OAAO;QACL,oFAAoF;QACpFC,SAAS;QACT,MAAMC,MAAKC,EAAE;YACX,IAAIA,GAAGC,UAAU,CAAC,SAASD,GAAGE,QAAQ,CAAC,QAAQ,CAACP,qBAAqBQ,IAAI,CAACH,KAAK;gBAC7E,OAAO;YACT;YAEA,IAAII;YACJ,IAAI;gBACFA,OAAO,MAAMV,SAASM,IAAI;YAC5B,EAAE,OAAM;gBACN,gDAAgD;gBAChD,OAAO;YACT;YAEA,OAAO;gBACLI,MAAM,GAAGA,KAAKC,UAAU,CAACT,sBAAsB,IAAI,gBAAgB,EAAEI,GAAGK,UAAU,CAAC,OAAOC,oBAAoB,EAAE,CAAC;gBACjHC,KAAK;oBAACC,UAAU;gBAAE;YACpB;QACF;QACAC,MAAM;IACR;AACF"}
|
|
@@ -7,6 +7,7 @@ import { isNotFoundError } from '../../errors/NotFoundError.js';
|
|
|
7
7
|
import { getStudioEnvironmentVariables } from '../../util/environment/getStudioEnvironmentVariables.js';
|
|
8
8
|
import { setupBrowserStubs } from '../../util/environment/setupBrowserStubs.js';
|
|
9
9
|
import { isRecord } from '../../util/isRecord.js';
|
|
10
|
+
import { skipDependencySourcemapsPlugin } from './skipDependencySourcemapsPlugin.js';
|
|
10
11
|
import { StudioModuleEvaluator } from './studioModuleEvaluator.js';
|
|
11
12
|
import { createOneShotWorkerLifecycle } from './studioWorkerLifecycle.js';
|
|
12
13
|
if (isMainThread) {
|
|
@@ -87,6 +88,10 @@ const defaultViteConfig = {
|
|
|
87
88
|
include: undefined,
|
|
88
89
|
noDiscovery: true
|
|
89
90
|
},
|
|
91
|
+
// Dependency source maps are the largest contributor to the worker's peak memory
|
|
92
|
+
plugins: [
|
|
93
|
+
skipDependencySourcemapsPlugin()
|
|
94
|
+
],
|
|
90
95
|
resolve: {
|
|
91
96
|
// Resolve the studio's tsconfig `paths` natively (Vite 8+), replacing the
|
|
92
97
|
// custom alias mapping and the need for a user-added `vite-tsconfig-paths`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/loaders/studio/studioWorkerLoader.worker.ts"],"sourcesContent":["import {fileURLToPath, pathToFileURL} from 'node:url'\nimport {isMainThread, parentPort} from 'node:worker_threads'\n\nimport {\n createServer,\n createServerModuleRunner,\n type InlineConfig,\n isRunnableDevEnvironment,\n loadEnv,\n mergeConfig,\n} from 'vite'\n\nimport {subdebug} from '../../_exports/debug.js'\nimport {getCliConfig} from '../../config/cli/getCliConfig.js'\nimport {type CliConfig} from '../../config/cli/types/cliConfig.js'\nimport {isNotFoundError} from '../../errors/NotFoundError.js'\nimport {getStudioEnvironmentVariables} from '../../util/environment/getStudioEnvironmentVariables.js'\nimport {setupBrowserStubs} from '../../util/environment/setupBrowserStubs.js'\nimport {isRecord} from '../../util/isRecord.js'\nimport {StudioModuleEvaluator} from './studioModuleEvaluator.js'\nimport {createOneShotWorkerLifecycle} from './studioWorkerLifecycle.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)\nconst applicationId = process.env.STUDIO_WORKER_APPLICATION_ID\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 module runner 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,\n // Inject environment variables as compile-time constants for Vite\n define: {\n // Config imports must use the same bus identity as the surrounding app bundle.\n ...(applicationId ? {__SANITY_APP_ID__: JSON.stringify(applicationId)} : {}),\n ...Object.fromEntries(\n Object.entries(studioEnvVars).map(([key, value]) => [\n `process.env.${key}`,\n JSON.stringify(value),\n ]),\n ),\n },\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 resolve: {\n // Resolve the studio's tsconfig `paths` natively (Vite 8+), replacing the\n // custom alias mapping and the need for a user-added `vite-tsconfig-paths`.\n tsconfigPaths: 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\n// Merge the CLI config's Vite config with the default Vite config\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// One-shot tasks (`studioWorkerTask`) resolve on their first message, and the\n// main thread historically terminate()d the worker right after — destroying\n// the worker's libuv loop while rolldown's native threads were still live.\n// The next `napi_call_threadsafe_function` then locked a destroyed mutex and\n// aborted the whole process (silent SIGABRT / exit code 134, reliably\n// reproduced on macOS). The lifecycle closes the Vite server BEFORE any\n// message reaches the main thread, and the main thread no longer terminates\n// one-shot workers at all (see `terminateOnSettle` in promisifyWorker).\nconst lifecycle =\n process.env.STUDIO_WORKER_ONE_SHOT === '1' && parentPort\n ? createOneShotWorkerLifecycle({\n closeServer: async () => {\n debug('Closing Vite server')\n await server.close()\n debug('Vite server closed')\n },\n onCloseError: (error) => debug('Failed to close Vite server: %o', error),\n parentPort,\n })\n : undefined\n\ntry {\n // Bit of a hack, but seems necessary based on the `node-vite` binary implementation\n await 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 // Load ALL env vars from .env files (not just studio-prefixed ones) so non-Sanity-prefixed\n // vars (e.g. NEXT_PUBLIC_*, VITE_*) are available via process.env at runtime.\n // The ??= on the next line prevents overwriting existing process.env values.\n const env = loadEnv(server.config.mode, server.config.envDir, '')\n for (const key in env) {\n process.env[key] ??= env[key]\n }\n\n const ssrEnvironment = server.environments.ssr\n if (!isRunnableDevEnvironment(ssrEnvironment)) {\n throw new Error('Expected SSR environment to be a runnable dev environment')\n }\n\n await ssrEnvironment.init()\n\n // Override fetchModule to support https:// imports and resolve relative imports from\n // remote modules (e.g. esm.sh re-exports with absolute paths).\n const defaultFetchModule = ssrEnvironment.fetchModule.bind(ssrEnvironment)\n ssrEnvironment.fetchModule = async (id, importer, options) => {\n if (importer && isHttpsUrl(importer) && !isHttpsUrl(id)) {\n id = new URL(id, importer).href\n }\n if (isHttpsUrl(id)) {\n const {code: rawCode} = await fetchHttpModule(id)\n const result = await server.ssrTransform(rawCode, null, id)\n return {\n code: result?.code || rawCode,\n file: null,\n id,\n invalidate: false,\n url: id,\n }\n }\n\n // Module Runner's fetchModule skips Vite resolve for `file://` URLs, so TypeScript\n // extension rewriting (`.js` → `.ts`/`.tsx`) never runs. vite-node always resolved\n // through `resolveId` first; restore that for absolute file imports (e.g. lazy\n // `doImport(new URL('iconResolver.js', import.meta.url))` in tests/source).\n // Keep the result as `file://` — on Windows, bare `C:/...` paths are treated as\n // package imports by Module Runner's fetchModule and fail to load.\n if (id.startsWith('file://')) {\n const resolved = await ssrEnvironment.pluginContainer.resolveId(\n fileURLToPath(id),\n importer ?? undefined,\n )\n if (resolved?.id && !resolved.id.startsWith('\\0')) {\n id = pathToFileURL(resolved.id).href\n }\n }\n\n return defaultFetchModule(id, importer, options)\n }\n\n const runner = createServerModuleRunner(ssrEnvironment, {\n evaluator: new StudioModuleEvaluator(),\n hmr: false,\n })\n\n await runner.import(workerScriptPath)\n} catch (error) {\n // Long-lived workers keep the original behavior: the error surfaces as a\n // Worker 'error' event.\n if (!lifecycle) {\n throw error\n }\n\n // One-shot workers close the server first and post a serialized error the\n // main thread rethrows, so the worker exits cleanly (code 0) and the real\n // error (e.g. a broken `sanity.config.ts`) isn't masked by a teardown abort.\n await lifecycle.postError(error)\n} finally {\n await lifecycle?.close()\n}\n"],"names":["fileURLToPath","pathToFileURL","isMainThread","parentPort","createServer","createServerModuleRunner","isRunnableDevEnvironment","loadEnv","mergeConfig","subdebug","getCliConfig","isNotFoundError","getStudioEnvironmentVariables","setupBrowserStubs","isRecord","StudioModuleEvaluator","createOneShotWorkerLifecycle","Error","rootPath","process","env","STUDIO_WORKER_STUDIO_ROOT_PATH","debug","workerScriptPath","STUDIO_WORKER_TASK_FILE","studioEnvVars","applicationId","STUDIO_WORKER_APPLICATION_ID","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","__SANITY_APP_ID__","JSON","stringify","Object","fromEntries","entries","map","key","value","envPrefix","esbuild","jsx","logLevel","optimizeDeps","include","undefined","noDiscovery","resolve","tsconfigPaths","root","server","hmr","watch","ssr","noExternal","viteConfig","vite","command","isSsrBuild","mode","lifecycle","STUDIO_WORKER_ONE_SHOT","closeServer","close","onCloseError","error","pluginContainer","buildStart","config","envDir","ssrEnvironment","environments","init","defaultFetchModule","fetchModule","bind","importer","options","URL","href","rawCode","result","ssrTransform","file","invalidate","resolved","resolveId","runner","evaluator","import","postError"],"mappings":"AAAA,SAAQA,aAAa,EAAEC,aAA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,YAAYtD,WAAWsD,aAAa,CAACtD,WAAWC,KAAK;YACvDA,KAAK,IAAIuD,IAAIvD,IAAIqD,UAAUG,IAAI;QACjC;QACA,IAAIzD,WAAWC,KAAK;YAClB,MAAM,EAACZ,MAAMqE,OAAO,EAAC,GAAG,MAAMzE,gBAAgBgB;YAC9C,MAAM0D,SAAS,MAAM/B,OAAOgC,YAAY,CAACF,SAAS,MAAMzD;YACxD,OAAO;gBACLZ,MAAMsE,QAAQtE,QAAQqE;gBACtBG,MAAM;gBACN5D;gBACA6D,YAAY;gBACZ5E,KAAKe;YACP;QACF;QAEA,mFAAmF;QACnF,mFAAmF;QACnF,+EAA+E;QAC/E,4EAA4E;QAC5E,gFAAgF;QAChF,mEAAmE;QACnE,IAAIA,GAAGC,UAAU,CAAC,YAAY;YAC5B,MAAM6D,WAAW,MAAMf,eAAeJ,eAAe,CAACoB,SAAS,CAC7DjH,cAAckD,KACdqD,YAAY/B;YAEd,IAAIwC,UAAU9D,MAAM,CAAC8D,SAAS9D,EAAE,CAACC,UAAU,CAAC,OAAO;gBACjDD,KAAKjD,cAAc+G,SAAS9D,EAAE,EAAEwD,IAAI;YACtC;QACF;QAEA,OAAON,mBAAmBlD,IAAIqD,UAAUC;IAC1C;IAEA,MAAMU,SAAS7G,yBAAyB4F,gBAAgB;QACtDkB,WAAW,IAAIpG;QACf+D,KAAK;IACP;IAEA,MAAMoC,OAAOE,MAAM,CAAC7F;AACtB,EAAE,OAAOqE,OAAO;IACd,yEAAyE;IACzE,wBAAwB;IACxB,IAAI,CAACL,WAAW;QACd,MAAMK;IACR;IAEA,0EAA0E;IAC1E,0EAA0E;IAC1E,6EAA6E;IAC7E,MAAML,UAAU8B,SAAS,CAACzB;AAC5B,SAAU;IACR,MAAML,WAAWG;AACnB"}
|
|
1
|
+
{"version":3,"sources":["../../../src/loaders/studio/studioWorkerLoader.worker.ts"],"sourcesContent":["import {fileURLToPath, pathToFileURL} from 'node:url'\nimport {isMainThread, parentPort} from 'node:worker_threads'\n\nimport {\n createServer,\n createServerModuleRunner,\n type InlineConfig,\n isRunnableDevEnvironment,\n loadEnv,\n mergeConfig,\n} from 'vite'\n\nimport {subdebug} from '../../_exports/debug.js'\nimport {getCliConfig} from '../../config/cli/getCliConfig.js'\nimport {type CliConfig} from '../../config/cli/types/cliConfig.js'\nimport {isNotFoundError} from '../../errors/NotFoundError.js'\nimport {getStudioEnvironmentVariables} from '../../util/environment/getStudioEnvironmentVariables.js'\nimport {setupBrowserStubs} from '../../util/environment/setupBrowserStubs.js'\nimport {isRecord} from '../../util/isRecord.js'\nimport {skipDependencySourcemapsPlugin} from './skipDependencySourcemapsPlugin.js'\nimport {StudioModuleEvaluator} from './studioModuleEvaluator.js'\nimport {createOneShotWorkerLifecycle} from './studioWorkerLifecycle.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)\nconst applicationId = process.env.STUDIO_WORKER_APPLICATION_ID\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 module runner 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,\n // Inject environment variables as compile-time constants for Vite\n define: {\n // Config imports must use the same bus identity as the surrounding app bundle.\n ...(applicationId ? {__SANITY_APP_ID__: JSON.stringify(applicationId)} : {}),\n ...Object.fromEntries(\n Object.entries(studioEnvVars).map(([key, value]) => [\n `process.env.${key}`,\n JSON.stringify(value),\n ]),\n ),\n },\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 // Dependency source maps are the largest contributor to the worker's peak memory\n plugins: [skipDependencySourcemapsPlugin()],\n resolve: {\n // Resolve the studio's tsconfig `paths` natively (Vite 8+), replacing the\n // custom alias mapping and the need for a user-added `vite-tsconfig-paths`.\n tsconfigPaths: 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\n// Merge the CLI config's Vite config with the default Vite config\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// One-shot tasks (`studioWorkerTask`) resolve on their first message, and the\n// main thread historically terminate()d the worker right after — destroying\n// the worker's libuv loop while rolldown's native threads were still live.\n// The next `napi_call_threadsafe_function` then locked a destroyed mutex and\n// aborted the whole process (silent SIGABRT / exit code 134, reliably\n// reproduced on macOS). The lifecycle closes the Vite server BEFORE any\n// message reaches the main thread, and the main thread no longer terminates\n// one-shot workers at all (see `terminateOnSettle` in promisifyWorker).\nconst lifecycle =\n process.env.STUDIO_WORKER_ONE_SHOT === '1' && parentPort\n ? createOneShotWorkerLifecycle({\n closeServer: async () => {\n debug('Closing Vite server')\n await server.close()\n debug('Vite server closed')\n },\n onCloseError: (error) => debug('Failed to close Vite server: %o', error),\n parentPort,\n })\n : undefined\n\ntry {\n // Bit of a hack, but seems necessary based on the `node-vite` binary implementation\n await 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 // Load ALL env vars from .env files (not just studio-prefixed ones) so non-Sanity-prefixed\n // vars (e.g. NEXT_PUBLIC_*, VITE_*) are available via process.env at runtime.\n // The ??= on the next line prevents overwriting existing process.env values.\n const env = loadEnv(server.config.mode, server.config.envDir, '')\n for (const key in env) {\n process.env[key] ??= env[key]\n }\n\n const ssrEnvironment = server.environments.ssr\n if (!isRunnableDevEnvironment(ssrEnvironment)) {\n throw new Error('Expected SSR environment to be a runnable dev environment')\n }\n\n await ssrEnvironment.init()\n\n // Override fetchModule to support https:// imports and resolve relative imports from\n // remote modules (e.g. esm.sh re-exports with absolute paths).\n const defaultFetchModule = ssrEnvironment.fetchModule.bind(ssrEnvironment)\n ssrEnvironment.fetchModule = async (id, importer, options) => {\n if (importer && isHttpsUrl(importer) && !isHttpsUrl(id)) {\n id = new URL(id, importer).href\n }\n if (isHttpsUrl(id)) {\n const {code: rawCode} = await fetchHttpModule(id)\n const result = await server.ssrTransform(rawCode, null, id)\n return {\n code: result?.code || rawCode,\n file: null,\n id,\n invalidate: false,\n url: id,\n }\n }\n\n // Module Runner's fetchModule skips Vite resolve for `file://` URLs, so TypeScript\n // extension rewriting (`.js` → `.ts`/`.tsx`) never runs. vite-node always resolved\n // through `resolveId` first; restore that for absolute file imports (e.g. lazy\n // `doImport(new URL('iconResolver.js', import.meta.url))` in tests/source).\n // Keep the result as `file://` — on Windows, bare `C:/...` paths are treated as\n // package imports by Module Runner's fetchModule and fail to load.\n if (id.startsWith('file://')) {\n const resolved = await ssrEnvironment.pluginContainer.resolveId(\n fileURLToPath(id),\n importer ?? undefined,\n )\n if (resolved?.id && !resolved.id.startsWith('\\0')) {\n id = pathToFileURL(resolved.id).href\n }\n }\n\n return defaultFetchModule(id, importer, options)\n }\n\n const runner = createServerModuleRunner(ssrEnvironment, {\n evaluator: new StudioModuleEvaluator(),\n hmr: false,\n })\n\n await runner.import(workerScriptPath)\n} catch (error) {\n // Long-lived workers keep the original behavior: the error surfaces as a\n // Worker 'error' event.\n if (!lifecycle) {\n throw error\n }\n\n // One-shot workers close the server first and post a serialized error the\n // main thread rethrows, so the worker exits cleanly (code 0) and the real\n // error (e.g. a broken `sanity.config.ts`) isn't masked by a teardown abort.\n await lifecycle.postError(error)\n} finally {\n await lifecycle?.close()\n}\n"],"names":["fileURLToPath","pathToFileURL","isMainThread","parentPort","createServer","createServerModuleRunner","isRunnableDevEnvironment","loadEnv","mergeConfig","subdebug","getCliConfig","isNotFoundError","getStudioEnvironmentVariables","setupBrowserStubs","isRecord","skipDependencySourcemapsPlugin","StudioModuleEvaluator","createOneShotWorkerLifecycle","Error","rootPath","process","env","STUDIO_WORKER_STUDIO_ROOT_PATH","debug","workerScriptPath","STUDIO_WORKER_TASK_FILE","studioEnvVars","applicationId","STUDIO_WORKER_APPLICATION_ID","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","__SANITY_APP_ID__","JSON","stringify","Object","fromEntries","entries","map","key","value","envPrefix","esbuild","jsx","logLevel","optimizeDeps","include","undefined","noDiscovery","plugins","resolve","tsconfigPaths","root","server","hmr","watch","ssr","noExternal","viteConfig","vite","command","isSsrBuild","mode","lifecycle","STUDIO_WORKER_ONE_SHOT","closeServer","close","onCloseError","error","pluginContainer","buildStart","config","envDir","ssrEnvironment","environments","init","defaultFetchModule","fetchModule","bind","importer","options","URL","href","rawCode","result","ssrTransform","file","invalidate","resolved","resolveId","runner","evaluator","import","postError"],"mappings":"AAAA,SAAQA,aAAa,EAAEC,aAAa,QAAO,WAAU;AACrD,SAAQC,YAAY,EAAEC,UAAU,QAAO,sBAAqB;AAE5D,SACEC,YAAY,EACZC,wBAAwB,EAExBC,wBAAwB,EACxBC,OAAO,EACPC,WAAW,QACN,OAAM;AAEb,SAAQC,QAAQ,QAAO,0BAAyB;AAChD,SAAQC,YAAY,QAAO,mCAAkC;AAE7D,SAAQC,eAAe,QAAO,gCAA+B;AAC7D,SAAQC,6BAA6B,QAAO,0DAAyD;AACrG,SAAQC,iBAAiB,QAAO,8CAA6C;AAC7E,SAAQC,QAAQ,QAAO,yBAAwB;AAC/C,SAAQC,8BAA8B,QAAO,sCAAqC;AAClF,SAAQC,qBAAqB,QAAO,6BAA4B;AAChE,SAAQC,4BAA4B,QAAO,6BAA4B;AAEvE,IAAIf,cAAc;IAChB,MAAM,IAAIgB,MAAM;AAClB;AAEA,MAAMC,WAAWC,QAAQC,GAAG,CAACC,8BAA8B;AAC3D,IAAI,CAACH,UAAU;IACb,MAAM,IAAID,MAAM;AAClB;AAEA,MAAMK,QAAQd,SAAS;AAEvB,MAAMe,mBAAmBJ,QAAQC,GAAG,CAACI,uBAAuB;AAC5D,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