@sanity/cli-core 1.1.0 → 1.1.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/index.d.ts CHANGED
@@ -980,6 +980,52 @@ export declare function resolveLocalPackage<T = unknown>(
980
980
  workDir: string,
981
981
  ): Promise<T>;
982
982
 
983
+ /**
984
+ * Resolves and imports a package relative to another resolved module URL.
985
+ * Useful for resolving transitive dependencies that may not be directly
986
+ * accessible from the project root (e.g., in pnpm strict mode).
987
+ *
988
+ * @param packageName - The name of the package to resolve
989
+ * @param parentUrl - The URL of the parent module to resolve from
990
+ * @returns The imported module
991
+ * @throws If the package cannot be resolved or imported
992
+ *
993
+ * @example
994
+ * ```ts
995
+ * const sanityUrl = resolveLocalPackagePath('sanity', workDir)
996
+ * const ui = await resolveLocalPackageFrom<typeof import('@sanity/ui')>('@sanity/ui', sanityUrl)
997
+ * ```
998
+ *
999
+ * @internal
1000
+ */
1001
+ export declare function resolveLocalPackageFrom<T = unknown>(
1002
+ packageName: string,
1003
+ parentUrl: URL,
1004
+ ): Promise<T>;
1005
+
1006
+ /**
1007
+ * Resolves the URL of a package from the local project's node_modules,
1008
+ * relative to the given working directory, without importing it.
1009
+ *
1010
+ * @param packageName - The name of the package to resolve (e.g., 'sanity')
1011
+ * @param workDir - The working directory to resolve the package from
1012
+ * @returns The resolved URL of the package entry point
1013
+ * @throws If the package cannot be resolved
1014
+ *
1015
+ * @example
1016
+ * ```ts
1017
+ * // Resolve a transitive dependency via its parent package:
1018
+ * const sanityUrl = resolveLocalPackagePath('sanity', workDir)
1019
+ * const uiUrl = resolveLocalPackagePathFrom('@sanity/ui', sanityUrl)
1020
+ * ```
1021
+ *
1022
+ * @internal
1023
+ */
1024
+ export declare function resolveLocalPackagePath(
1025
+ packageName: string,
1026
+ workDir: string,
1027
+ ): URL;
1028
+
983
1029
  /**
984
1030
  * `structuredClone()`, but doesn't throw on non-clonable values - instead it drops them.
985
1031
  *
@@ -1,4 +1,6 @@
1
+ import { dirname, resolve as resolvePath } from 'node:path';
1
2
  import { isMainThread } from 'node:worker_threads';
3
+ import { getTsconfig } from 'get-tsconfig';
2
4
  import { createServer, loadEnv, mergeConfig } from 'vite';
3
5
  import { ViteNodeRunner } from 'vite-node/client';
4
6
  import { ViteNodeServer } from 'vite-node/server';
@@ -35,6 +37,34 @@ try {
35
37
  console.warn('[warn] Failed to load CLI config:', err);
36
38
  }
37
39
  }
40
+ /**
41
+ * Reads tsconfig.json `paths` and converts them to Vite `resolve.alias` entries.
42
+ * This allows studio projects using path aliases (e.g. `"@/*": ["./src/*"]`) to work
43
+ * with CLI worker commands without requiring the user to manually add `vite-tsconfig-paths`.
44
+ */ function getTsconfigPathAliases(studioRootPath) {
45
+ const tsconfig = getTsconfig(studioRootPath);
46
+ if (!tsconfig) return {};
47
+ const { baseUrl, paths } = tsconfig.config.compilerOptions ?? {};
48
+ if (!paths) return {};
49
+ const tsconfigDir = dirname(tsconfig.path);
50
+ const base = baseUrl ? resolvePath(tsconfigDir, baseUrl) : tsconfigDir;
51
+ const aliases = {};
52
+ for (const [pattern, targets] of Object.entries(paths)){
53
+ if (!targets || targets.length === 0) continue;
54
+ // Only the first target is used — multiple fallback targets are not supported
55
+ const target = targets[0];
56
+ if (pattern.endsWith('/*') && target.endsWith('/*')) {
57
+ // Wildcard: "@/*" => "./src/*" becomes "@" => "/abs/path/src"
58
+ aliases[pattern.slice(0, -2)] = resolvePath(base, target.slice(0, -2));
59
+ } else {
60
+ // Exact: "@utils" => "./src/utils/index"
61
+ aliases[pattern] = resolvePath(base, target);
62
+ }
63
+ }
64
+ // Sort by key length descending so more-specific aliases take precedence
65
+ // (e.g. "@lib" is matched before "@" when both exist)
66
+ return Object.fromEntries(Object.entries(aliases).toSorted(([a], [b])=>b.length - a.length));
67
+ }
38
68
  /**
39
69
  * Fetches and caches modules from HTTP/HTTPS URLs.
40
70
  * Vite's SSR transform treats `https://` imports as external and bypasses the plugin
@@ -61,6 +91,12 @@ async function fetchHttpModule(url) {
61
91
  function isHttpsUrl(id) {
62
92
  return id.startsWith('https://');
63
93
  }
94
+ let tsconfigAliases = {};
95
+ try {
96
+ tsconfigAliases = getTsconfigPathAliases(rootPath);
97
+ } catch (err) {
98
+ debug('Failed to read tsconfig paths: %o', err);
99
+ }
64
100
  const defaultViteConfig = {
65
101
  build: {
66
102
  target: 'node'
@@ -80,6 +116,9 @@ const defaultViteConfig = {
80
116
  include: undefined,
81
117
  noDiscovery: true
82
118
  },
119
+ resolve: {
120
+ alias: tsconfigAliases
121
+ },
83
122
  root: rootPath,
84
123
  server: {
85
124
  hmr: false,
@@ -1 +1 @@
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 {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'\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,\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 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\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// 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.\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","isNotFoundError","getStudioEnvironmentVariables","setupBrowserStubs","isRecord","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;AACvC,SAAQC,eAAe,QAAO,gCAA+B;AAC7D,SAAQC,6BAA6B,QAAO,0DAAyD;AACrG,SAAQC,iBAAiB,QAAO,8CAA6C;AAC7E,SAAQC,QAAQ,QAAO,yBAAwB;AAE/C,IAAIZ,cAAc;IAChB,MAAM,IAAIa,MAAM;AAClB;AAEA,MAAMC,WAAWC,QAAQC,GAAG,CAACC,8BAA8B;AAC3D,IAAI,CAACH,UAAU;IACb,MAAM,IAAID,MAAM;AAClB;AA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AAsC;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"}
1
+ {"version":3,"sources":["../../../src/loaders/studio/studioWorkerLoader.worker.ts"],"sourcesContent":["import {dirname, resolve as resolvePath} from 'node:path'\nimport {isMainThread} from 'node:worker_threads'\n\nimport {getTsconfig} from 'get-tsconfig'\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 {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'\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 * Reads tsconfig.json `paths` and converts them to Vite `resolve.alias` entries.\n * This allows studio projects using path aliases (e.g. `\"@/*\": [\"./src/*\"]`) to work\n * with CLI worker commands without requiring the user to manually add `vite-tsconfig-paths`.\n */\nfunction getTsconfigPathAliases(studioRootPath: string): Record<string, string> {\n const tsconfig = getTsconfig(studioRootPath)\n if (!tsconfig) return {}\n\n const {baseUrl, paths} = tsconfig.config.compilerOptions ?? {}\n if (!paths) return {}\n\n const tsconfigDir = dirname(tsconfig.path)\n const base = baseUrl ? resolvePath(tsconfigDir, baseUrl) : tsconfigDir\n\n const aliases: Record<string, string> = {}\n for (const [pattern, targets] of Object.entries(paths)) {\n if (!targets || targets.length === 0) continue\n // Only the first target is used — multiple fallback targets are not supported\n const target = targets[0]\n\n if (pattern.endsWith('/*') && target.endsWith('/*')) {\n // Wildcard: \"@/*\" => \"./src/*\" becomes \"@\" => \"/abs/path/src\"\n aliases[pattern.slice(0, -2)] = resolvePath(base, target.slice(0, -2))\n } else {\n // Exact: \"@utils\" => \"./src/utils/index\"\n aliases[pattern] = resolvePath(base, target)\n }\n }\n // Sort by key length descending so more-specific aliases take precedence\n // (e.g. \"@lib\" is matched before \"@\" when both exist)\n return Object.fromEntries(Object.entries(aliases).toSorted(([a], [b]) => b.length - a.length))\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\nlet tsconfigAliases: Record<string, string> = {}\ntry {\n tsconfigAliases = getTsconfigPathAliases(rootPath)\n} catch (err) {\n debug('Failed to read tsconfig paths: %o', err)\n}\n\nconst defaultViteConfig: InlineConfig = {\n build: {target: 'node'},\n configFile: false,\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 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 alias: tsconfigAliases,\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// 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.\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":["dirname","resolve","resolvePath","isMainThread","getTsconfig","createServer","loadEnv","mergeConfig","ViteNodeRunner","ViteNodeServer","installSourcemapsSupport","getCliConfig","subdebug","isNotFoundError","getStudioEnvironmentVariables","setupBrowserStubs","isRecord","Error","rootPath","process","env","STUDIO_WORKER_STUDIO_ROOT_PATH","debug","workerScriptPath","STUDIO_WORKER_TASK_FILE","studioEnvVars","cliConfig","err","console","warn","getTsconfigPathAliases","studioRootPath","tsconfig","baseUrl","paths","config","compilerOptions","tsconfigDir","path","base","aliases","pattern","targets","Object","entries","length","target","endsWith","slice","fromEntries","toSorted","a","b","httpModuleCache","Map","fetchHttpModule","url","cached","get","code","response","fetch","signal","AbortSignal","timeout","ok","status","statusText","text","set","isHttpsUrl","id","startsWith","tsconfigAliases","defaultViteConfig","build","configFile","define","map","key","value","JSON","stringify","envPrefix","esbuild","jsx","logLevel","optimizeDeps","include","undefined","noDiscovery","alias","root","server","hmr","watch","ssr","noExternal","viteConfig","vite","command","isSsrBuild","mode","pluginContainer","buildStart","envDir","node","getSourceMap","source","runner","fetchModule","rawCode","result","ssrTransform","resolveId","importer","URL","href","executeId"],"mappings":"AAAA,SAAQA,OAAO,EAAEC,WAAWC,WAAW,QAAO,YAAW;AACzD,SAAQC,YAAY,QAAO,sBAAqB;AAEhD,SAAQC,WAAW,QAAO,eAAc;AACxC,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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AAEhC,mEAAmE;AACnEnF,yBAAyB;IACvBiG,cAAc,CAACC,SAAWF,KAAKC,YAAY,CAACC;AAC9C;AAEA,MAAMC,SAAS,IAAIrG,eAAe;IAChC+B,MAAMsD,OAAO1D,MAAM,CAACI,IAAI;IACxB,MAAMuE,aAAYvC,EAAE;QAClB,2EAA2E;QAC3E,6EAA6E;QAC7E,wEAAwE;QACxE,sCAAsC;QACtC,IAAID,WAAWC,KAAK;YAClB,MAAM,EAACZ,MAAMoD,OAAO,EAAC,GAAG,MAAMxD,gBAAgBgB;YAC9C,MAAMyC,SAAS,MAAMnB,OAAOoB,YAAY,CAACF,SAAS,MAAMxC;YACxD,OAAO;gBAACZ,MAAMqD,QAAQrD,QAAQoD;YAAO;QACvC;QACA,OAAOL,KAAKI,WAAW,CAACvC;IAC1B;IACA2C,WAAU3C,EAAE,EAAE4C,QAAQ;QACpB,6EAA6E;QAC7E,IAAI7C,WAAWC,KAAK,OAAO;YAACA;QAAE;QAC9B,2EAA2E;QAC3E,kEAAkE;QAClE,IAAI4C,YAAY7C,WAAW6C,WAAW;YACpC,OAAO;gBAAC5C,IAAI,IAAI6C,IAAI7C,IAAI4C,UAAUE,IAAI;YAAA;QACxC;QACA,OAAOX,KAAKQ,SAAS,CAAC3C,IAAI4C;IAC5B;IACAvB,MAAMC,OAAO1D,MAAM,CAACyD,IAAI;AAC1B;AAEA,kFAAkF;AAClF,iFAAiF;AACjF,6EAA6E;AAC7E,MAAMiB,OAAOS,SAAS,CAAC;AAEvB,MAAMT,OAAOS,SAAS,CAAC/F"}
@@ -1,4 +1,4 @@
1
- import * as stubs from './stubs.js';
1
+ import { getBrowserStubs } from './stubs.js';
2
2
  /**
3
3
  * Sets up browser globals (window, document, etc.) in the global scope.
4
4
  *
@@ -14,12 +14,12 @@ import * as stubs from './stubs.js';
14
14
  /* intentional noop - already mocked */ };
15
15
  }
16
16
  // Inject browser stubs into global scope
17
- const mockStubs = stubs;
17
+ const stubs = getBrowserStubs();
18
18
  const mockedGlobalThis = globalThis;
19
19
  const stubbedKeys = [];
20
- for(const key in stubs){
20
+ for (const key of Object.keys(stubs)){
21
21
  if (!(key in mockedGlobalThis)) {
22
- mockedGlobalThis[key] = mockStubs[key];
22
+ mockedGlobalThis[key] = stubs[key];
23
23
  stubbedKeys.push(key);
24
24
  }
25
25
  }
@@ -30,13 +30,13 @@ import * as stubs from './stubs.js';
30
30
  }
31
31
  // Return cleanup function
32
32
  return ()=>{
33
- for (const key of stubbedKeys){
34
- delete mockedGlobalThis[key];
35
- }
36
- // Remove marker
33
+ // Remove marker before deleting window
37
34
  if (globalThis.window) {
38
35
  delete globalThis.window.__mockedBySanity;
39
36
  }
37
+ for (const key of stubbedKeys){
38
+ delete mockedGlobalThis[key];
39
+ }
40
40
  };
41
41
  }
42
42
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/util/environment/setupBrowserStubs.ts"],"sourcesContent":["import * as stubs from './stubs.js'\n\n/**\n * Sets up browser globals (window, document, etc.) in the global scope.\n *\n * This is used by both mockBrowserEnvironment (for child processes) and\n * studioWorkerLoader (for worker threads) to provide a browser-like environment.\n *\n * @returns A cleanup function that removes the injected globals\n * @internal\n */\nexport async function setupBrowserStubs(): Promise<() => void> {\n // Guard against double-registering\n if (globalThis.window && '__mockedBySanity' in globalThis.window) {\n return () => {\n /* intentional noop - already mocked */\n }\n }\n\n // Inject browser stubs into global scope\n const mockStubs = stubs as unknown as Record<string, unknown>\n const mockedGlobalThis: Record<string, unknown> = globalThis\n const stubbedKeys: string[] = []\n\n for (const key in stubs) {\n if (!(key in mockedGlobalThis)) {\n mockedGlobalThis[key] = mockStubs[key]\n stubbedKeys.push(key)\n }\n }\n\n // Add marker to window to detect double-mocking\n if (globalThis.window) {\n ;(globalThis.window as unknown as Record<string, unknown>).__mockedBySanity = true\n }\n\n // Return cleanup function\n return () => {\n for (const key of stubbedKeys) {\n delete mockedGlobalThis[key]\n }\n\n // Remove marker\n if (globalThis.window) {\n delete (globalThis.window as unknown as Record<string, unknown>).__mockedBySanity\n }\n }\n}\n"],"names":["stubs","setupBrowserStubs","globalThis","window","mockStubs","mockedGlobalThis","stubbedKeys","key","push","__mockedBySanity"],"mappings":"AAAA,YAAYA,WAAW,aAAY;AAEnC;;;;;;;;CAQC,GACD,OAAO,eAAeC;IACpB,mCAAmC;IACnC,IAAIC,WAAWC,MAAM,IAAI,sBAAsBD,WAAWC,MAAM,EAAE;QAChE,OAAO;QACL,qCAAqC,GACvC;IACF;IAEA,yCAAyC;IACzC,MAAMC,YAAYJ;IAClB,MAAMK,mBAA4CH;IAClD,MAAMI,cAAwB,EAAE;IAEhC,IAAK,MAAMC,OAAOP,MAAO;QACvB,IAAI,CAAEO,CAAAA,OAAOF,gBAAe,GAAI;YAC9BA,gBAAgB,CAACE,IAAI,GAAGH,SAAS,CAACG,IAAI;YACtCD,YAAYE,IAAI,CAACD;QACnB;IACF;IAEA,gDAAgD;IAChD,IAAIL,WAAWC,MAAM,EAAE;;QACnBD,WAAWC,MAAM,CAAwCM,gBAAgB,GAAG;IAChF;IAEA,0BAA0B;IAC1B,OAAO;QACL,KAAK,MAAMF,OAAOD,YAAa;YAC7B,OAAOD,gBAAgB,CAACE,IAAI;QAC9B;QAEA,gBAAgB;QAChB,IAAIL,WAAWC,MAAM,EAAE;YACrB,OAAO,AAACD,WAAWC,MAAM,CAAwCM,gBAAgB;QACnF;IACF;AACF"}
1
+ {"version":3,"sources":["../../../src/util/environment/setupBrowserStubs.ts"],"sourcesContent":["import {getBrowserStubs} from './stubs.js'\n\n/**\n * Sets up browser globals (window, document, etc.) in the global scope.\n *\n * This is used by both mockBrowserEnvironment (for child processes) and\n * studioWorkerLoader (for worker threads) to provide a browser-like environment.\n *\n * @returns A cleanup function that removes the injected globals\n * @internal\n */\nexport async function setupBrowserStubs(): Promise<() => void> {\n // Guard against double-registering\n if (globalThis.window && '__mockedBySanity' in globalThis.window) {\n return () => {\n /* intentional noop - already mocked */\n }\n }\n\n // Inject browser stubs into global scope\n const stubs = getBrowserStubs()\n const mockedGlobalThis: Record<string, unknown> = globalThis\n const stubbedKeys: string[] = []\n\n for (const key of Object.keys(stubs)) {\n if (!(key in mockedGlobalThis)) {\n mockedGlobalThis[key] = stubs[key]\n stubbedKeys.push(key)\n }\n }\n\n // Add marker to window to detect double-mocking\n if (globalThis.window) {\n ;(globalThis.window as unknown as Record<string, unknown>).__mockedBySanity = true\n }\n\n // Return cleanup function\n return () => {\n // Remove marker before deleting window\n if (globalThis.window) {\n delete (globalThis.window as unknown as Record<string, unknown>).__mockedBySanity\n }\n\n for (const key of stubbedKeys) {\n delete mockedGlobalThis[key]\n }\n }\n}\n"],"names":["getBrowserStubs","setupBrowserStubs","globalThis","window","stubs","mockedGlobalThis","stubbedKeys","key","Object","keys","push","__mockedBySanity"],"mappings":"AAAA,SAAQA,eAAe,QAAO,aAAY;AAE1C;;;;;;;;CAQC,GACD,OAAO,eAAeC;IACpB,mCAAmC;IACnC,IAAIC,WAAWC,MAAM,IAAI,sBAAsBD,WAAWC,MAAM,EAAE;QAChE,OAAO;QACL,qCAAqC,GACvC;IACF;IAEA,yCAAyC;IACzC,MAAMC,QAAQJ;IACd,MAAMK,mBAA4CH;IAClD,MAAMI,cAAwB,EAAE;IAEhC,KAAK,MAAMC,OAAOC,OAAOC,IAAI,CAACL,OAAQ;QACpC,IAAI,CAAEG,CAAAA,OAAOF,gBAAe,GAAI;YAC9BA,gBAAgB,CAACE,IAAI,GAAGH,KAAK,CAACG,IAAI;YAClCD,YAAYI,IAAI,CAACH;QACnB;IACF;IAEA,gDAAgD;IAChD,IAAIL,WAAWC,MAAM,EAAE;;QACnBD,WAAWC,MAAM,CAAwCQ,gBAAgB,GAAG;IAChF;IAEA,0BAA0B;IAC1B,OAAO;QACL,uCAAuC;QACvC,IAAIT,WAAWC,MAAM,EAAE;YACrB,OAAO,AAACD,WAAWC,MAAM,CAAwCQ,gBAAgB;QACnF;QAEA,KAAK,MAAMJ,OAAOD,YAAa;YAC7B,OAAOD,gBAAgB,CAACE,IAAI;QAC9B;IACF;AACF"}
@@ -4,254 +4,103 @@ const html = `<!doctype html>
4
4
  <head><meta charset="utf-8"></head>
5
5
  <body></body>
6
6
  </html>`;
7
- const dom = new JSDOM(html, {
8
- pretendToBeVisual: true,
9
- url: 'http://localhost:3333/'
10
- });
11
- // Special handling of certain globals
12
- if (typeof dom.window.document.execCommand !== 'function') {
13
- // Crashes ace editor without this :/
14
- dom.window.document.execCommand = function execCommand(// Provide the right arity for the function, even if unused
15
- _commandName, _showDefaultUI, _valueArgument) {
16
- // Return false to indicate "unsupported"
17
- return false;
18
- };
7
+ /**
8
+ * Creates a JSDOM instance and applies polyfills for missing browser globals.
9
+ */ function createBrowserDom() {
10
+ const dom = new JSDOM(html, {
11
+ pretendToBeVisual: true,
12
+ url: 'http://localhost:3333/'
13
+ });
14
+ // Special handling of certain globals
15
+ if (typeof dom.window.document.execCommand !== 'function') {
16
+ // Crashes ace editor without this :/
17
+ dom.window.document.execCommand = function execCommand(// Provide the right arity for the function, even if unused
18
+ _commandName, _showDefaultUI, _valueArgument) {
19
+ // Return false to indicate "unsupported"
20
+ return false;
21
+ };
22
+ }
23
+ if (dom.window.requestIdleCallback === undefined) {
24
+ dom.window.requestIdleCallback = (cb)=>setTimeout(cb, 10);
25
+ }
26
+ if (dom.window.cancelIdleCallback === undefined) {
27
+ dom.window.cancelIdleCallback = (id)=>clearTimeout(id);
28
+ }
29
+ if (dom.window.ResizeObserver === undefined) {
30
+ dom.window.ResizeObserver = class ResizeObserver {
31
+ // eslint-disable-next-line @typescript-eslint/no-useless-constructor
32
+ constructor(_callback){}
33
+ disconnect() {}
34
+ observe(_target, _options) {}
35
+ unobserve(_target) {}
36
+ };
37
+ }
38
+ if (dom.window.IntersectionObserver === undefined) {
39
+ dom.window.IntersectionObserver = class IntersectionObserver {
40
+ options;
41
+ constructor(_callback, options){
42
+ this.options = options || {};
43
+ }
44
+ get root() {
45
+ return this.options.root || null;
46
+ }
47
+ get rootMargin() {
48
+ return this.options.rootMargin || '';
49
+ }
50
+ get thresholds() {
51
+ return Array.isArray(this.options.threshold) ? this.options.threshold : [
52
+ this.options.threshold || 0
53
+ ];
54
+ }
55
+ disconnect() {}
56
+ observe(_el) {}
57
+ takeRecords() {
58
+ return [];
59
+ }
60
+ unobserve(_el) {}
61
+ };
62
+ }
63
+ if (dom.window.matchMedia === undefined) {
64
+ dom.window.matchMedia = (_qs)=>({
65
+ matches: false,
66
+ media: '',
67
+ onchange: null
68
+ });
69
+ }
70
+ return dom;
19
71
  }
20
- if (dom.window.requestIdleCallback === undefined) {
21
- dom.window.requestIdleCallback = (cb)=>setTimeout(cb, 10);
72
+ /**
73
+ * Collects all browser globals from the JSDOM window that should be injected
74
+ * into the Node.js global scope to emulate a browser environment.
75
+ *
76
+ * This dynamically iterates over all own properties of the JSDOM window,
77
+ * skipping internal JSDOM properties (prefixed with `_`) and properties that
78
+ * already exist in Node.js globals to avoid conflicts.
79
+ *
80
+ * This approach ensures that any new properties added by JSDOM upgrades are
81
+ * automatically included, preventing "missing global" bugs (e.g. `Element`,
82
+ * `HTMLElement`, `SVGElement` needed by libraries like styled-components).
83
+ */ function collectBrowserStubs() {
84
+ const dom = createBrowserDom();
85
+ const stubs = Object.create(null);
86
+ const nodeGlobals = new Set(Object.getOwnPropertyNames(globalThis));
87
+ for (const key of Object.getOwnPropertyNames(dom.window)){
88
+ // Skip internal JSDOM properties
89
+ if (key.startsWith('_')) continue;
90
+ // Skip numeric indices (e.g. '0' for window[0])
91
+ if (/^\d+$/.test(key)) continue;
92
+ // Skip properties that Node.js already provides to avoid conflicts
93
+ if (nodeGlobals.has(key)) continue;
94
+ stubs[key] = dom.window[key];
95
+ }
96
+ return stubs;
22
97
  }
23
- if (dom.window.cancelIdleCallback === undefined) {
24
- dom.window.cancelIdleCallback = (id)=>clearTimeout(id);
98
+ let browserStubs;
99
+ export function getBrowserStubs() {
100
+ if (!browserStubs) {
101
+ browserStubs = collectBrowserStubs();
102
+ }
103
+ return browserStubs;
25
104
  }
26
- if (dom.window.ResizeObserver === undefined) {
27
- dom.window.ResizeObserver = class ResizeObserver {
28
- // eslint-disable-next-line @typescript-eslint/no-useless-constructor
29
- constructor(_callback){}
30
- disconnect() {}
31
- observe(_target, _options) {}
32
- unobserve(_target) {}
33
- };
34
- }
35
- if (dom.window.IntersectionObserver === undefined) {
36
- dom.window.IntersectionObserver = class IntersectionObserver {
37
- options;
38
- constructor(_callback, options){
39
- this.options = options || {};
40
- }
41
- get root() {
42
- return this.options.root || null;
43
- }
44
- get rootMargin() {
45
- return this.options.rootMargin || '';
46
- }
47
- get thresholds() {
48
- return Array.isArray(this.options.threshold) ? this.options.threshold : [
49
- this.options.threshold || 0
50
- ];
51
- }
52
- disconnect() {}
53
- observe(_el) {}
54
- takeRecords() {
55
- return [];
56
- }
57
- unobserve(_el) {}
58
- };
59
- }
60
- if (dom.window.matchMedia === undefined) {
61
- dom.window.matchMedia = (_qs)=>({
62
- matches: false,
63
- media: '',
64
- onchange: null
65
- });
66
- }
67
- // Generic jsdom 1:1
68
- export const alert = dom.window.alert;
69
- export const atob = dom.window.atob;
70
- export const blur = dom.window.blur;
71
- export const btoa = dom.window.btoa;
72
- export const cancelAnimationFrame = dom.window.cancelAnimationFrame;
73
- export const captureEvents = dom.window.captureEvents;
74
- export const clearInterval = dom.window.clearInterval;
75
- export const clearTimeout = dom.window.clearTimeout;
76
- export const close = dom.window.close;
77
- export const confirm = dom.window.confirm;
78
- export const console = dom.window.console;
79
- export const crypto = dom.window.crypto;
80
- export const CSSImportRule = dom.window.CSSImportRule;
81
- export const CSSMediaRule = dom.window.CSSMediaRule;
82
- export const CSSRule = dom.window.CSSRule;
83
- export const CSSStyleDeclaration = dom.window.CSSStyleDeclaration;
84
- export const CSSStyleRule = dom.window.CSSStyleRule;
85
- export const CSSStyleSheet = dom.window.CSSStyleSheet;
86
- export const customElements = dom.window.customElements;
87
- export const devicePixelRatio = dom.window.devicePixelRatio;
88
- export const document = dom.window.document;
89
- export const event = dom.window.event;
90
- export const external = dom.window.external;
91
- export const focus = dom.window.focus;
92
- export const frameElement = dom.window.frameElement;
93
- export const frames = dom.window.frames;
94
- export const getComputedStyle = dom.window.getComputedStyle;
95
- export const getSelection = dom.window.getSelection;
96
- export const history = dom.window.history;
97
- export const innerHeight = dom.window.innerHeight;
98
- export const innerWidth = dom.window.innerWidth;
99
- export const length = dom.window.length;
100
- export const localStorage = dom.window.localStorage;
101
- export const location = dom.window.location;
102
- export const locationbar = dom.window.locationbar;
103
- export const MediaList = dom.window.MediaList;
104
- export const menubar = dom.window.menubar;
105
- export const moveBy = dom.window.moveBy;
106
- export const moveTo = dom.window.moveTo;
107
- export const name = dom.window.name;
108
- export const navigator = dom.window.navigator;
109
- export const onabort = dom.window.onabort;
110
- export const onafterprint = dom.window.onafterprint;
111
- export const onautocomplete = dom.window.onautocomplete;
112
- export const onautocompleteerror = dom.window.onautocompleteerror;
113
- export const onauxclick = dom.window.onauxclick;
114
- export const onbeforeinput = dom.window.onbeforeinput;
115
- export const onbeforematch = dom.window.onbeforematch;
116
- export const onbeforeprint = dom.window.onbeforeprint;
117
- export const onbeforetoggle = dom.window.onbeforetoggle;
118
- export const onbeforeunload = dom.window.onbeforeunload;
119
- export const onblur = dom.window.onblur;
120
- export const oncancel = dom.window.oncancel;
121
- export const oncanplay = dom.window.oncanplay;
122
- export const oncanplaythrough = dom.window.oncanplaythrough;
123
- export const onchange = dom.window.onchange;
124
- export const onclick = dom.window.onclick;
125
- export const onclose = dom.window.onclose;
126
- export const oncontextlost = dom.window.oncontextlost;
127
- export const oncontextmenu = dom.window.oncontextmenu;
128
- export const oncontextrestored = dom.window.oncontextrestored;
129
- export const oncopy = dom.window.oncopy;
130
- export const oncuechange = dom.window.oncuechange;
131
- export const oncut = dom.window.oncut;
132
- export const ondblclick = dom.window.ondblclick;
133
- export const ondrag = dom.window.ondrag;
134
- export const ondragend = dom.window.ondragend;
135
- export const ondragenter = dom.window.ondragenter;
136
- export const ondragleave = dom.window.ondragleave;
137
- export const ondragover = dom.window.ondragover;
138
- export const ondragstart = dom.window.ondragstart;
139
- export const ondrop = dom.window.ondrop;
140
- export const ondurationchange = dom.window.ondurationchange;
141
- export const onemptied = dom.window.onemptied;
142
- export const onended = dom.window.onended;
143
- export const onerror = dom.window.onerror;
144
- export const onfocus = dom.window.onfocus;
145
- export const onformdata = dom.window.onformdata;
146
- export const onhashchange = dom.window.onhashchange;
147
- export const oninput = dom.window.oninput;
148
- export const oninvalid = dom.window.oninvalid;
149
- export const onkeydown = dom.window.onkeydown;
150
- export const onkeypress = dom.window.onkeypress;
151
- export const onkeyup = dom.window.onkeyup;
152
- export const onlanguagechange = dom.window.onlanguagechange;
153
- export const onload = dom.window.onload;
154
- export const onloadeddata = dom.window.onloadeddata;
155
- export const onloadedmetadata = dom.window.onloadedmetadata;
156
- export const onloadstart = dom.window.onloadstart;
157
- export const onmessage = dom.window.onmessage;
158
- export const onmessageerror = dom.window.onmessageerror;
159
- export const onmousedown = dom.window.onmousedown;
160
- export const onmouseenter = dom.window.onmouseenter;
161
- export const onmouseleave = dom.window.onmouseleave;
162
- export const onmousemove = dom.window.onmousemove;
163
- export const onmouseout = dom.window.onmouseout;
164
- export const onmouseover = dom.window.onmouseover;
165
- export const onmouseup = dom.window.onmouseup;
166
- export const onoffline = dom.window.onoffline;
167
- export const ononline = dom.window.ononline;
168
- export const onpagehide = dom.window.onpagehide;
169
- export const onpageshow = dom.window.onpageshow;
170
- export const onpaste = dom.window.onpaste;
171
- export const onpause = dom.window.onpause;
172
- export const onplay = dom.window.onplay;
173
- export const onplaying = dom.window.onplaying;
174
- export const onpopstate = dom.window.onpopstate;
175
- export const onprogress = dom.window.onprogress;
176
- export const onratechange = dom.window.onratechange;
177
- export const onrejectionhandled = dom.window.onrejectionhandled;
178
- export const onreset = dom.window.onreset;
179
- export const onresize = dom.window.onresize;
180
- export const onscroll = dom.window.onscroll;
181
- export const onscrollend = dom.window.onscrollend;
182
- export const onsecuritypolicyviolation = dom.window.onsecuritypolicyviolation;
183
- export const onseeked = dom.window.onseeked;
184
- export const onseeking = dom.window.onseeking;
185
- export const onselect = dom.window.onselect;
186
- export const onslotchange = dom.window.onslotchange;
187
- export const onsort = dom.window.onsort;
188
- export const onstalled = dom.window.onstalled;
189
- export const onstorage = dom.window.onstorage;
190
- export const onsubmit = dom.window.onsubmit;
191
- export const onsuspend = dom.window.onsuspend;
192
- export const ontimeupdate = dom.window.ontimeupdate;
193
- export const ontoggle = dom.window.ontoggle;
194
- export const ontouchcancel = dom.window.ontouchcancel;
195
- export const ontouchend = dom.window.ontouchend;
196
- export const ontouchmove = dom.window.ontouchmove;
197
- export const ontouchstart = dom.window.ontouchstart;
198
- export const onunhandledrejection = dom.window.onunhandledrejection;
199
- export const onunload = dom.window.onunload;
200
- export const onvolumechange = dom.window.onvolumechange;
201
- export const onwaiting = dom.window.onwaiting;
202
- export const onwebkitanimationend = dom.window.onwebkitanimationend;
203
- export const onwebkitanimationiteration = dom.window.onwebkitanimationiteration;
204
- export const onwebkitanimationstart = dom.window.onwebkitanimationstart;
205
- export const onwebkittransitionend = dom.window.onwebkittransitionend;
206
- export const onwheel = dom.window.onwheel;
207
- export const open = dom.window.open;
208
- export const origin = dom.window.origin;
209
- export const outerHeight = dom.window.outerHeight;
210
- export const outerWidth = dom.window.outerWidth;
211
- export const pageXOffset = dom.window.pageXOffset;
212
- export const pageYOffset = dom.window.pageYOffset;
213
- export const parent = dom.window.parent;
214
- export const performance = dom.window.performance;
215
- export const personalbar = dom.window.personalbar;
216
- export const postMessage = dom.window.postMessage;
217
- export const print = dom.window.print;
218
- export const prompt = dom.window.prompt;
219
- export const queueMicrotask = dom.window.queueMicrotask;
220
- export const releaseEvents = dom.window.releaseEvents;
221
- export const requestAnimationFrame = dom.window.requestAnimationFrame;
222
- export const resizeBy = dom.window.resizeBy;
223
- export const resizeTo = dom.window.resizeTo;
224
- export const screen = dom.window.screen;
225
- export const screenLeft = dom.window.screenLeft;
226
- export const screenTop = dom.window.screenTop;
227
- export const screenX = dom.window.screenX;
228
- export const screenY = dom.window.screenY;
229
- export const scroll = dom.window.scroll;
230
- export const scrollbars = dom.window.scrollbars;
231
- export const scrollBy = dom.window.scrollBy;
232
- export const scrollTo = dom.window.scrollTo;
233
- export const scrollX = dom.window.scrollX;
234
- export const scrollY = dom.window.scrollY;
235
- export const self = dom.window.self;
236
- export const sessionStorage = dom.window.sessionStorage;
237
- export const setInterval = dom.window.setInterval;
238
- export const setTimeout = dom.window.setTimeout;
239
- export const status = dom.window.status;
240
- export const statusbar = dom.window.statusbar;
241
- export const stop = dom.window.stop;
242
- export const StyleSheet = dom.window.StyleSheet;
243
- export const toolbar = dom.window.toolbar;
244
- export const top = dom.window.top;
245
- export const window = dom.window;
246
- export const XPathEvaluator = dom.window.XPathEvaluator;
247
- export const XPathException = dom.window.XPathException;
248
- export const XPathExpression = dom.window.XPathExpression;
249
- export const XPathResult = dom.window.XPathResult;
250
- // Extended properties
251
- export const requestIdleCallback = dom.window.requestIdleCallback;
252
- export const cancelIdleCallback = dom.window.cancelIdleCallback;
253
- export const ResizeObserver = dom.window.ResizeObserver;
254
- export const IntersectionObserver = dom.window.IntersectionObserver;
255
- export const matchMedia = dom.window.matchMedia;
256
105
 
257
106
  //# sourceMappingURL=stubs.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/util/environment/stubs.ts"],"sourcesContent":["import {JSDOM} from 'jsdom'\n\nconst html = `<!doctype html>\n<html>\n <head><meta charset=\"utf-8\"></head>\n <body></body>\n</html>`\n\nconst dom = new JSDOM(html, {\n pretendToBeVisual: true,\n url: 'http://localhost:3333/',\n})\n\n// Special handling of certain globals\nif (typeof dom.window.document.execCommand !== 'function') {\n // Crashes ace editor without this :/\n dom.window.document.execCommand = function execCommand(\n // Provide the right arity for the function, even if unused\n _commandName: string,\n _showDefaultUI: boolean,\n _valueArgument: unknown,\n ) {\n // Return false to indicate \"unsupported\"\n return false\n }\n}\n\nif (dom.window.requestIdleCallback === undefined) {\n dom.window.requestIdleCallback = (cb: IdleRequestCallback) => setTimeout(cb, 10)\n}\n\nif (dom.window.cancelIdleCallback === undefined) {\n dom.window.cancelIdleCallback = (id: number) => clearTimeout(id)\n}\n\nif (dom.window.ResizeObserver === undefined) {\n dom.window.ResizeObserver = class ResizeObserver {\n // eslint-disable-next-line @typescript-eslint/no-useless-constructor\n constructor(_callback: unknown) {}\n disconnect() {}\n observe(_target: unknown, _options: unknown) {}\n unobserve(_target: unknown) {}\n }\n}\n\nif (dom.window.IntersectionObserver === undefined) {\n dom.window.IntersectionObserver = class IntersectionObserver {\n options: {root?: unknown; rootMargin?: string; threshold?: number}\n constructor(\n _callback: unknown,\n options?: {root?: unknown; rootMargin?: string; threshold?: number},\n ) {\n this.options = options || {}\n }\n get root() {\n return this.options.root || null\n }\n get rootMargin() {\n return this.options.rootMargin || ''\n }\n get thresholds() {\n return Array.isArray(this.options.threshold)\n ? this.options.threshold\n : [this.options.threshold || 0]\n }\n\n disconnect() {}\n observe(_el: unknown) {}\n takeRecords() {\n return []\n }\n unobserve(_el: unknown) {}\n }\n}\n\nif (dom.window.matchMedia === undefined) {\n dom.window.matchMedia = (_qs: unknown) =>\n ({\n matches: false,\n media: '',\n onchange: null,\n }) as MediaQueryList\n}\n\n// Generic jsdom 1:1\nexport const alert = dom.window.alert\nexport const atob = dom.window.atob\nexport const blur = dom.window.blur\nexport const btoa = dom.window.btoa\nexport const cancelAnimationFrame = dom.window.cancelAnimationFrame\nexport const captureEvents = dom.window.captureEvents\nexport const clearInterval = dom.window.clearInterval\nexport const clearTimeout = dom.window.clearTimeout\nexport const close = dom.window.close\nexport const confirm = dom.window.confirm\nexport const console = dom.window.console\nexport const crypto = dom.window.crypto\nexport const CSSImportRule = dom.window.CSSImportRule\nexport const CSSMediaRule = dom.window.CSSMediaRule\nexport const CSSRule = dom.window.CSSRule\nexport const CSSStyleDeclaration = dom.window.CSSStyleDeclaration\nexport const CSSStyleRule = dom.window.CSSStyleRule\nexport const CSSStyleSheet = dom.window.CSSStyleSheet\nexport const customElements = dom.window.customElements\nexport const devicePixelRatio = dom.window.devicePixelRatio\nexport const document = dom.window.document\nexport const event = dom.window.event\nexport const external = dom.window.external\nexport const focus = dom.window.focus\nexport const frameElement = dom.window.frameElement\nexport const frames = dom.window.frames\nexport const getComputedStyle = dom.window.getComputedStyle\nexport const getSelection = dom.window.getSelection\nexport const history = dom.window.history\nexport const innerHeight = dom.window.innerHeight\nexport const innerWidth = dom.window.innerWidth\nexport const length = dom.window.length\nexport const localStorage = dom.window.localStorage\nexport const location = dom.window.location\nexport const locationbar = dom.window.locationbar\nexport const MediaList = dom.window.MediaList\nexport const menubar = dom.window.menubar\nexport const moveBy = dom.window.moveBy\nexport const moveTo = dom.window.moveTo\nexport const name = dom.window.name\nexport const navigator = dom.window.navigator\nexport const onabort = dom.window.onabort\nexport const onafterprint = dom.window.onafterprint\nexport const onautocomplete = dom.window.onautocomplete\nexport const onautocompleteerror = dom.window.onautocompleteerror\nexport const onauxclick = dom.window.onauxclick\nexport const onbeforeinput = dom.window.onbeforeinput\nexport const onbeforematch = dom.window.onbeforematch\nexport const onbeforeprint = dom.window.onbeforeprint\nexport const onbeforetoggle = dom.window.onbeforetoggle\nexport const onbeforeunload = dom.window.onbeforeunload\nexport const onblur = dom.window.onblur\nexport const oncancel = dom.window.oncancel\nexport const oncanplay = dom.window.oncanplay\nexport const oncanplaythrough = dom.window.oncanplaythrough\nexport const onchange = dom.window.onchange\nexport const onclick = dom.window.onclick\nexport const onclose = dom.window.onclose\nexport const oncontextlost = dom.window.oncontextlost\nexport const oncontextmenu = dom.window.oncontextmenu\nexport const oncontextrestored = dom.window.oncontextrestored\nexport const oncopy = dom.window.oncopy\nexport const oncuechange = dom.window.oncuechange\nexport const oncut = dom.window.oncut\nexport const ondblclick = dom.window.ondblclick\nexport const ondrag = dom.window.ondrag\nexport const ondragend = dom.window.ondragend\nexport const ondragenter = dom.window.ondragenter\nexport const ondragleave = dom.window.ondragleave\nexport const ondragover = dom.window.ondragover\nexport const ondragstart = dom.window.ondragstart\nexport const ondrop = dom.window.ondrop\nexport const ondurationchange = dom.window.ondurationchange\nexport const onemptied = dom.window.onemptied\nexport const onended = dom.window.onended\nexport const onerror = dom.window.onerror\nexport const onfocus = dom.window.onfocus\nexport const onformdata = dom.window.onformdata\nexport const onhashchange = dom.window.onhashchange\nexport const oninput = dom.window.oninput\nexport const oninvalid = dom.window.oninvalid\nexport const onkeydown = dom.window.onkeydown\nexport const onkeypress = dom.window.onkeypress\nexport const onkeyup = dom.window.onkeyup\nexport const onlanguagechange = dom.window.onlanguagechange\nexport const onload = dom.window.onload\nexport const onloadeddata = dom.window.onloadeddata\nexport const onloadedmetadata = dom.window.onloadedmetadata\nexport const onloadstart = dom.window.onloadstart\nexport const onmessage = dom.window.onmessage\nexport const onmessageerror = dom.window.onmessageerror\nexport const onmousedown = dom.window.onmousedown\nexport const onmouseenter = dom.window.onmouseenter\nexport const onmouseleave = dom.window.onmouseleave\nexport const onmousemove = dom.window.onmousemove\nexport const onmouseout = dom.window.onmouseout\nexport const onmouseover = dom.window.onmouseover\nexport const onmouseup = dom.window.onmouseup\nexport const onoffline = dom.window.onoffline\nexport const ononline = dom.window.ononline\nexport const onpagehide = dom.window.onpagehide\nexport const onpageshow = dom.window.onpageshow\nexport const onpaste = dom.window.onpaste\nexport const onpause = dom.window.onpause\nexport const onplay = dom.window.onplay\nexport const onplaying = dom.window.onplaying\nexport const onpopstate = dom.window.onpopstate\nexport const onprogress = dom.window.onprogress\nexport const onratechange = dom.window.onratechange\nexport const onrejectionhandled = dom.window.onrejectionhandled\nexport const onreset = dom.window.onreset\nexport const onresize = dom.window.onresize\nexport const onscroll = dom.window.onscroll\nexport const onscrollend = dom.window.onscrollend\nexport const onsecuritypolicyviolation = dom.window.onsecuritypolicyviolation\nexport const onseeked = dom.window.onseeked\nexport const onseeking = dom.window.onseeking\nexport const onselect = dom.window.onselect\nexport const onslotchange = dom.window.onslotchange\nexport const onsort = dom.window.onsort\nexport const onstalled = dom.window.onstalled\nexport const onstorage = dom.window.onstorage\nexport const onsubmit = dom.window.onsubmit\nexport const onsuspend = dom.window.onsuspend\nexport const ontimeupdate = dom.window.ontimeupdate\nexport const ontoggle = dom.window.ontoggle\nexport const ontouchcancel = dom.window.ontouchcancel\nexport const ontouchend = dom.window.ontouchend\nexport const ontouchmove = dom.window.ontouchmove\nexport const ontouchstart = dom.window.ontouchstart\nexport const onunhandledrejection = dom.window.onunhandledrejection\nexport const onunload = dom.window.onunload\nexport const onvolumechange = dom.window.onvolumechange\nexport const onwaiting = dom.window.onwaiting\nexport const onwebkitanimationend = dom.window.onwebkitanimationend\nexport const onwebkitanimationiteration = dom.window.onwebkitanimationiteration\nexport const onwebkitanimationstart = dom.window.onwebkitanimationstart\nexport const onwebkittransitionend = dom.window.onwebkittransitionend\nexport const onwheel = dom.window.onwheel\nexport const open = dom.window.open\nexport const origin = dom.window.origin\nexport const outerHeight = dom.window.outerHeight\nexport const outerWidth = dom.window.outerWidth\nexport const pageXOffset = dom.window.pageXOffset\nexport const pageYOffset = dom.window.pageYOffset\nexport const parent = dom.window.parent\nexport const performance = dom.window.performance\nexport const personalbar = dom.window.personalbar\nexport const postMessage = dom.window.postMessage\nexport const print = dom.window.print\nexport const prompt = dom.window.prompt\nexport const queueMicrotask = dom.window.queueMicrotask\nexport const releaseEvents = dom.window.releaseEvents\nexport const requestAnimationFrame = dom.window.requestAnimationFrame\nexport const resizeBy = dom.window.resizeBy\nexport const resizeTo = dom.window.resizeTo\nexport const screen = dom.window.screen\nexport const screenLeft = dom.window.screenLeft\nexport const screenTop = dom.window.screenTop\nexport const screenX = dom.window.screenX\nexport const screenY = dom.window.screenY\nexport const scroll = dom.window.scroll\nexport const scrollbars = dom.window.scrollbars\nexport const scrollBy = dom.window.scrollBy\nexport const scrollTo = dom.window.scrollTo\nexport const scrollX = dom.window.scrollX\nexport const scrollY = dom.window.scrollY\nexport const self = dom.window.self\nexport const sessionStorage = dom.window.sessionStorage\nexport const setInterval = dom.window.setInterval\nexport const setTimeout = dom.window.setTimeout\nexport const status = dom.window.status\nexport const statusbar = dom.window.statusbar\nexport const stop = dom.window.stop\nexport const StyleSheet = dom.window.StyleSheet\nexport const toolbar = dom.window.toolbar\nexport const top = dom.window.top\nexport const window = dom.window\nexport const XPathEvaluator = dom.window.XPathEvaluator\nexport const XPathException = dom.window.XPathException\nexport const XPathExpression = dom.window.XPathExpression\nexport const XPathResult = dom.window.XPathResult\n\n// Extended properties\nexport const requestIdleCallback = dom.window.requestIdleCallback\nexport const cancelIdleCallback = dom.window.cancelIdleCallback\nexport const ResizeObserver = dom.window.ResizeObserver\nexport const IntersectionObserver = dom.window.IntersectionObserver\nexport const matchMedia = dom.window.matchMedia\n"],"names":["JSDOM","html","dom","pretendToBeVisual","url","window","document","execCommand","_commandName","_showDefaultUI","_valueArgument","requestIdleCallback","undefined","cb","setTimeout","cancelIdleCallback","id","clearTimeout","ResizeObserver","_callback","disconnect","observe","_target","_options","unobserve","IntersectionObserver","options","root","rootMargin","thresholds","Array","isArray","threshold","_el","takeRecords","matchMedia","_qs","matches","media","onchange","alert","atob","blur","btoa","cancelAnimationFrame","captureEvents","clearInterval","close","confirm","console","crypto","CSSImportRule","CSSMediaRule","CSSRule","CSSStyleDeclaration","CSSStyleRule","CSSStyleSheet","customElements","devicePixelRatio","event","external","focus","frameElement","frames","getComputedStyle","getSelection","history","innerHeight","innerWidth","length","localStorage","location","locationbar","MediaList","menubar","moveBy","moveTo","name","navigator","onabort","onafterprint","onautocomplete","onautocompleteerror","onauxclick","onbeforeinput","onbeforematch","onbeforeprint","onbeforetoggle","onbeforeunload","onblur","oncancel","oncanplay","oncanplaythrough","onclick","onclose","oncontextlost","oncontextmenu","oncontextrestored","oncopy","oncuechange","oncut","ondblclick","ondrag","ondragend","ondragenter","ondragleave","ondragover","ondragstart","ondrop","ondurationchange","onemptied","onended","onerror","onfocus","onformdata","onhashchange","oninput","oninvalid","onkeydown","onkeypress","onkeyup","onlanguagechange","onload","onloadeddata","onloadedmetadata","onloadstart","onmessage","onmessageerror","onmousedown","onmouseenter","onmouseleave","onmousemove","onmouseout","onmouseover","onmouseup","onoffline","ononline","onpagehide","onpageshow","onpaste","onpause","onplay","onplaying","onpopstate","onprogress","onratechange","onrejectionhandled","onreset","onresize","onscroll","onscrollend","onsecuritypolicyviolation","onseeked","onseeking","onselect","onslotchange","onsort","onstalled","onstorage","onsubmit","onsuspend","ontimeupdate","ontoggle","ontouchcancel","ontouchend","ontouchmove","ontouchstart","onunhandledrejection","onunload","onvolumechange","onwaiting","onwebkitanimationend","onwebkitanimationiteration","onwebkitanimationstart","onwebkittransitionend","onwheel","open","origin","outerHeight","outerWidth","pageXOffset","pageYOffset","parent","performance","personalbar","postMessage","print","prompt","queueMicrotask","releaseEvents","requestAnimationFrame","resizeBy","resizeTo","screen","screenLeft","screenTop","screenX","screenY","scroll","scrollbars","scrollBy","scrollTo","scrollX","scrollY","self","sessionStorage","setInterval","status","statusbar","stop","StyleSheet","toolbar","top","XPathEvaluator","XPathException","XPathExpression","XPathResult"],"mappings":"AAAA,SAAQA,KAAK,QAAO,QAAO;AAE3B,MAAMC,OAAO,CAAC;;;;OAIP,CAAC;AAER,MAAMC,MAAM,IAAIF,MAAMC,MAAM;IAC1BE,mBAAmB;IACnBC,KAAK;AACP;AAEA,sCAAsC;AACtC,IAAI,OAAOF,IAAIG,MAAM,CAACC,QAAQ,CAACC,WAAW,KAAK,YAAY;IACzD,qCAAqC;IACrCL,IAAIG,MAAM,CAACC,QAAQ,CAACC,WAAW,GAAG,SAASA,YACzC,2DAA2D;IAC3DC,YAAoB,EACpBC,cAAuB,EACvBC,cAAuB;QAEvB,yCAAyC;QACzC,OAAO;IACT;AACF;AAEA,IAAIR,IAAIG,MAAM,CAACM,mBAAmB,KAAKC,WAAW;IAChDV,IAAIG,MAAM,CAACM,mBAAmB,GAAG,CAACE,KAA4BC,WAAWD,IAAI;AAC/E;AAEA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AAc,CAAA;AACvD,OAAO,MAAMC,kBAAkBrN,IAAIG,MAAM,CAACkN,eAAe,CAAA;AACzD,OAAO,MAAMC,cAActN,IAAIG,MAAM,CAACmN,WAAW,CAAA;AAEjD,sBAAsB;AACtB,OAAO,MAAM7M,sBAAsBT,IAAIG,MAAM,CAACM,mBAAmB,CAAA;AACjE,OAAO,MAAMI,qBAAqBb,IAAIG,MAAM,CAACU,kBAAkB,CAAA;AAC/D,OAAO,MAAMG,iBAAiBhB,IAAIG,MAAM,CAACa,cAAc,CAAA;AACvD,OAAO,MAAMO,uBAAuBvB,IAAIG,MAAM,CAACoB,oBAAoB,CAAA;AACnE,OAAO,MAAMU,aAAajC,IAAIG,MAAM,CAAC8B,UAAU,CAAA"}
1
+ {"version":3,"sources":["../../../src/util/environment/stubs.ts"],"sourcesContent":["import {JSDOM} from 'jsdom'\n\nconst html = `<!doctype html>\n<html>\n <head><meta charset=\"utf-8\"></head>\n <body></body>\n</html>`\n\n/**\n * Creates a JSDOM instance and applies polyfills for missing browser globals.\n */\nfunction createBrowserDom(): JSDOM {\n const dom = new JSDOM(html, {\n pretendToBeVisual: true,\n url: 'http://localhost:3333/',\n })\n\n // Special handling of certain globals\n if (typeof dom.window.document.execCommand !== 'function') {\n // Crashes ace editor without this :/\n dom.window.document.execCommand = function execCommand(\n // Provide the right arity for the function, even if unused\n _commandName: string,\n _showDefaultUI: boolean,\n _valueArgument: unknown,\n ) {\n // Return false to indicate \"unsupported\"\n return false\n }\n }\n\n if (dom.window.requestIdleCallback === undefined) {\n dom.window.requestIdleCallback = (cb: IdleRequestCallback) => setTimeout(cb, 10)\n }\n\n if (dom.window.cancelIdleCallback === undefined) {\n dom.window.cancelIdleCallback = (id: number) => clearTimeout(id)\n }\n\n if (dom.window.ResizeObserver === undefined) {\n dom.window.ResizeObserver = class ResizeObserver {\n // eslint-disable-next-line @typescript-eslint/no-useless-constructor\n constructor(_callback: unknown) {}\n disconnect() {}\n observe(_target: unknown, _options: unknown) {}\n unobserve(_target: unknown) {}\n }\n }\n\n if (dom.window.IntersectionObserver === undefined) {\n dom.window.IntersectionObserver = class IntersectionObserver {\n options: {root?: unknown; rootMargin?: string; threshold?: number}\n constructor(\n _callback: unknown,\n options?: {root?: unknown; rootMargin?: string; threshold?: number},\n ) {\n this.options = options || {}\n }\n get root() {\n return this.options.root || null\n }\n get rootMargin() {\n return this.options.rootMargin || ''\n }\n get thresholds() {\n return Array.isArray(this.options.threshold)\n ? this.options.threshold\n : [this.options.threshold || 0]\n }\n\n disconnect() {}\n observe(_el: unknown) {}\n takeRecords() {\n return []\n }\n unobserve(_el: unknown) {}\n }\n }\n\n if (dom.window.matchMedia === undefined) {\n dom.window.matchMedia = (_qs: unknown) =>\n ({\n matches: false,\n media: '',\n onchange: null,\n }) as MediaQueryList\n }\n\n return dom\n}\n\n/**\n * Collects all browser globals from the JSDOM window that should be injected\n * into the Node.js global scope to emulate a browser environment.\n *\n * This dynamically iterates over all own properties of the JSDOM window,\n * skipping internal JSDOM properties (prefixed with `_`) and properties that\n * already exist in Node.js globals to avoid conflicts.\n *\n * This approach ensures that any new properties added by JSDOM upgrades are\n * automatically included, preventing \"missing global\" bugs (e.g. `Element`,\n * `HTMLElement`, `SVGElement` needed by libraries like styled-components).\n */\nfunction collectBrowserStubs(): Record<string, unknown> {\n const dom = createBrowserDom()\n const stubs: Record<string, unknown> = Object.create(null)\n const nodeGlobals = new Set(Object.getOwnPropertyNames(globalThis))\n\n for (const key of Object.getOwnPropertyNames(dom.window)) {\n // Skip internal JSDOM properties\n if (key.startsWith('_')) continue\n\n // Skip numeric indices (e.g. '0' for window[0])\n if (/^\\d+$/.test(key)) continue\n\n // Skip properties that Node.js already provides to avoid conflicts\n if (nodeGlobals.has(key)) continue\n\n stubs[key] = (dom.window as Record<string, unknown>)[key]\n }\n\n return stubs\n}\n\nlet browserStubs: Record<string, unknown> | undefined\n\nexport function getBrowserStubs(): Record<string, unknown> {\n if (!browserStubs) {\n browserStubs = collectBrowserStubs()\n }\n return browserStubs\n}\n"],"names":["JSDOM","html","createBrowserDom","dom","pretendToBeVisual","url","window","document","execCommand","_commandName","_showDefaultUI","_valueArgument","requestIdleCallback","undefined","cb","setTimeout","cancelIdleCallback","id","clearTimeout","ResizeObserver","_callback","disconnect","observe","_target","_options","unobserve","IntersectionObserver","options","root","rootMargin","thresholds","Array","isArray","threshold","_el","takeRecords","matchMedia","_qs","matches","media","onchange","collectBrowserStubs","stubs","Object","create","nodeGlobals","Set","getOwnPropertyNames","globalThis","key","startsWith","test","has","browserStubs","getBrowserStubs"],"mappings":"AAAA,SAAQA,KAAK,QAAO,QAAO;AAE3B,MAAMC,OAAO,CAAC;;;;OAIP,CAAC;AAER;;CAEC,GACD,SAASC;IACP,MAAMC,MAAM,IAAIH,MAAMC,MAAM;QAC1BG,mBAAmB;QACnBC,KAAK;IACP;IAEA,sCAAsC;IACtC,IAAI,OAAOF,IAAIG,MAAM,CAACC,QAAQ,CAACC,WAAW,KAAK,YAAY;QACzD,qCAAqC;QACrCL,IAAIG,MAAM,CAACC,QAAQ,CAACC,WAAW,GAAG,SAASA,YACzC,2DAA2D;QAC3DC,YAAoB,EACpBC,cAAuB,EACvBC,cAAuB;YAEvB,yCAAyC;YACzC,OAAO;QACT;IACF;IAEA,IAAIR,IAAIG,MAAM,CAACM,mBAAmB,KAAKC,WAAW;QAChDV,IAAIG,MAAM,CAACM,mBAAmB,GAAG,CAACE,KAA4BC,WAAWD,IAAI;IAC/E;IAEA,IAAIX,IAAIG,MAAM,CAACU,kBAAkB,KAAKH,WAAW;QAC/CV,IAAIG,MAAM,CAACU,kBAAkB,GAAG,CAACC,KAAeC,aAAaD;IAC/D;IAEA,IAAId,IAAIG,MAAM,CAACa,cAAc,KAAKN,WAAW;QAC3CV,IAAIG,MAAM,CAACa,cAAc,GAAG,MAAMA;YAChC,qEAAqE;YACrE,YAAYC,SAAkB,CAAE,CAAC;YACjCC,aAAa,CAAC;YACdC,QAAQC,OAAgB,EAAEC,QAAi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C,IAAI,CAACF,MAAM;QAEvB,mEAAmE;QACnE,IAAIJ,YAAYO,GAAG,CAACH,MAAM;QAE1BP,KAAK,CAACO,IAAI,GAAG,AAAC9C,IAAIG,MAAM,AAA4B,CAAC2C,IAAI;IAC3D;IAEA,OAAOP;AACT;AAEA,IAAIW;AAEJ,OAAO,SAASC;IACd,IAAI,CAACD,cAAc;QACjBA,eAAeZ;IACjB;IACA,OAAOY;AACT"}
@@ -19,15 +19,59 @@ import { doImport } from './doImport.js';
19
19
  *
20
20
  * @internal
21
21
  */ export async function resolveLocalPackage(packageName, workDir) {
22
- // Create a fake cli config URL - doesn't have to be correct, just need the root path
23
- // This ensures we resolve packages relative to the user's repo, not the CLI package
22
+ const packageUrl = resolveLocalPackagePath(packageName, workDir);
23
+ const module = await doImport(packageUrl.href);
24
+ return module;
25
+ }
26
+ /**
27
+ * Resolves the URL of a package from the local project's node_modules,
28
+ * relative to the given working directory, without importing it.
29
+ *
30
+ * @param packageName - The name of the package to resolve (e.g., 'sanity')
31
+ * @param workDir - The working directory to resolve the package from
32
+ * @returns The resolved URL of the package entry point
33
+ * @throws If the package cannot be resolved
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * // Resolve a transitive dependency via its parent package:
38
+ * const sanityUrl = resolveLocalPackagePath('sanity', workDir)
39
+ * const uiUrl = resolveLocalPackagePathFrom('@sanity/ui', sanityUrl)
40
+ * ```
41
+ *
42
+ * @internal
43
+ */ export function resolveLocalPackagePath(packageName, workDir) {
24
44
  const fakeCliConfigUrl = pathToFileURL(resolve(workDir, 'sanity.cli.mjs'));
25
45
  try {
26
- const packageUrl = moduleResolve(packageName, fakeCliConfigUrl);
46
+ return moduleResolve(packageName, fakeCliConfigUrl);
47
+ } catch (error) {
48
+ throw new Error(`Failed to resolve package "${packageName}" from "${workDir}": ${error instanceof Error ? error.message : String(error)}`);
49
+ }
50
+ }
51
+ /**
52
+ * Resolves and imports a package relative to another resolved module URL.
53
+ * Useful for resolving transitive dependencies that may not be directly
54
+ * accessible from the project root (e.g., in pnpm strict mode).
55
+ *
56
+ * @param packageName - The name of the package to resolve
57
+ * @param parentUrl - The URL of the parent module to resolve from
58
+ * @returns The imported module
59
+ * @throws If the package cannot be resolved or imported
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * const sanityUrl = resolveLocalPackagePath('sanity', workDir)
64
+ * const ui = await resolveLocalPackageFrom<typeof import('@sanity/ui')>('@sanity/ui', sanityUrl)
65
+ * ```
66
+ *
67
+ * @internal
68
+ */ export async function resolveLocalPackageFrom(packageName, parentUrl) {
69
+ try {
70
+ const packageUrl = moduleResolve(packageName, parentUrl);
27
71
  const module = await doImport(packageUrl.href);
28
72
  return module;
29
73
  } catch (error) {
30
- throw new Error(`Failed to resolve package "${packageName}" from "${workDir}": ${error instanceof Error ? error.message : String(error)}`);
74
+ throw new Error(`Failed to resolve package "${packageName}" from "${parentUrl.href}": ${error instanceof Error ? error.message : String(error)}`);
31
75
  }
32
76
  }
33
77
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/util/resolveLocalPackage.ts"],"sourcesContent":["import {resolve} from 'node:path'\nimport {pathToFileURL} from 'node:url'\n\nimport {moduleResolve} from 'import-meta-resolve'\n\nimport {doImport} from './doImport.js'\n\n/**\n * Resolves and imports a package from the local project's node_modules,\n * relative to the given working directory. This avoids circular dependencies\n * and ensures the correct version of the package is used.\n *\n * @param packageName - The name of the package to resolve (e.g., 'sanity')\n * @param workDir - The working directory to resolve the package from\n * @returns The imported module\n * @throws If the package cannot be resolved or imported\n *\n * @example\n * ```ts\n * const {createSchema} = await resolveLocalPackage('sanity', workDir)\n * ```\n *\n * @internal\n */\nexport async function resolveLocalPackage<T = unknown>(\n packageName: string,\n workDir: string,\n): Promise<T> {\n // Create a fake cli config URL - doesn't have to be correct, just need the root path\n // This ensures we resolve packages relative to the user's repo, not the CLI package\n const fakeCliConfigUrl = pathToFileURL(resolve(workDir, 'sanity.cli.mjs'))\n\n try {\n const packageUrl = moduleResolve(packageName, fakeCliConfigUrl)\n const module = await doImport(packageUrl.href)\n return module as T\n } catch (error) {\n throw new Error(\n `Failed to resolve package \"${packageName}\" from \"${workDir}\": ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n}\n"],"names":["resolve","pathToFileURL","moduleResolve","doImport","resolveLocalPackage","packageName","workDir","fakeCliConfigUrl","packageUrl","module","href","error","Error","message","String"],"mappings":"AAAA,SAAQA,OAAO,QAAO,YAAW;AACjC,SAAQC,aAAa,QAAO,WAAU;AAEtC,SAAQC,aAAa,QAAO,sBAAqB;AAEjD,SAAQC,QAAQ,QAAO,gBAAe;AAEtC;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,eAAeC,oBACpBC,WAAmB,EACnBC,OAAe;IAEf,qFAAqF;IACrF,oFAAoF;IACpF,MAAMC,mBAAmBN,cAAcD,QAAQM,SAAS;IAExD,IAAI;QACF,MAAME,aAAaN,cAAcG,aAAaE;QAC9C,MAAME,SAAS,MAAMN,SAASK,WAAWE,IAAI;QAC7C,OAAOD;IACT,EAAE,OAAOE,OAAO;QACd,MAAM,IAAIC,MACR,CAAC,2BAA2B,EAAEP,YAAY,QAAQ,EAAEC,QAAQ,GAAG,EAAEK,iBAAiBC,QAAQD,MAAME,OAAO,GAAGC,OAAOH,QAAQ;IAE7H;AACF"}
1
+ {"version":3,"sources":["../../src/util/resolveLocalPackage.ts"],"sourcesContent":["import {resolve} from 'node:path'\nimport {pathToFileURL} from 'node:url'\n\nimport {moduleResolve} from 'import-meta-resolve'\n\nimport {doImport} from './doImport.js'\n\n/**\n * Resolves and imports a package from the local project's node_modules,\n * relative to the given working directory. This avoids circular dependencies\n * and ensures the correct version of the package is used.\n *\n * @param packageName - The name of the package to resolve (e.g., 'sanity')\n * @param workDir - The working directory to resolve the package from\n * @returns The imported module\n * @throws If the package cannot be resolved or imported\n *\n * @example\n * ```ts\n * const {createSchema} = await resolveLocalPackage('sanity', workDir)\n * ```\n *\n * @internal\n */\nexport async function resolveLocalPackage<T = unknown>(\n packageName: string,\n workDir: string,\n): Promise<T> {\n const packageUrl = resolveLocalPackagePath(packageName, workDir)\n const module = await doImport(packageUrl.href)\n return module as T\n}\n\n/**\n * Resolves the URL of a package from the local project's node_modules,\n * relative to the given working directory, without importing it.\n *\n * @param packageName - The name of the package to resolve (e.g., 'sanity')\n * @param workDir - The working directory to resolve the package from\n * @returns The resolved URL of the package entry point\n * @throws If the package cannot be resolved\n *\n * @example\n * ```ts\n * // Resolve a transitive dependency via its parent package:\n * const sanityUrl = resolveLocalPackagePath('sanity', workDir)\n * const uiUrl = resolveLocalPackagePathFrom('@sanity/ui', sanityUrl)\n * ```\n *\n * @internal\n */\nexport function resolveLocalPackagePath(packageName: string, workDir: string): URL {\n const fakeCliConfigUrl = pathToFileURL(resolve(workDir, 'sanity.cli.mjs'))\n\n try {\n return moduleResolve(packageName, fakeCliConfigUrl)\n } catch (error) {\n throw new Error(\n `Failed to resolve package \"${packageName}\" from \"${workDir}\": ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n}\n\n/**\n * Resolves and imports a package relative to another resolved module URL.\n * Useful for resolving transitive dependencies that may not be directly\n * accessible from the project root (e.g., in pnpm strict mode).\n *\n * @param packageName - The name of the package to resolve\n * @param parentUrl - The URL of the parent module to resolve from\n * @returns The imported module\n * @throws If the package cannot be resolved or imported\n *\n * @example\n * ```ts\n * const sanityUrl = resolveLocalPackagePath('sanity', workDir)\n * const ui = await resolveLocalPackageFrom<typeof import('@sanity/ui')>('@sanity/ui', sanityUrl)\n * ```\n *\n * @internal\n */\nexport async function resolveLocalPackageFrom<T = unknown>(\n packageName: string,\n parentUrl: URL,\n): Promise<T> {\n try {\n const packageUrl = moduleResolve(packageName, parentUrl)\n const module = await doImport(packageUrl.href)\n return module as T\n } catch (error) {\n throw new Error(\n `Failed to resolve package \"${packageName}\" from \"${parentUrl.href}\": ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n}\n"],"names":["resolve","pathToFileURL","moduleResolve","doImport","resolveLocalPackage","packageName","workDir","packageUrl","resolveLocalPackagePath","module","href","fakeCliConfigUrl","error","Error","message","String","resolveLocalPackageFrom","parentUrl"],"mappings":"AAAA,SAAQA,OAAO,QAAO,YAAW;AACjC,SAAQC,aAAa,QAAO,WAAU;AAEtC,SAAQC,aAAa,QAAO,sBAAqB;AAEjD,SAAQC,QAAQ,QAAO,gBAAe;AAEtC;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,eAAeC,oBACpBC,WAAmB,EACnBC,OAAe;IAEf,MAAMC,aAAaC,wBAAwBH,aAAaC;IACxD,MAAMG,SAAS,MAAMN,SAASI,WAAWG,IAAI;IAC7C,OAAOD;AACT;AAEA;;;;;;;;;;;;;;;;;CAiBC,GACD,OAAO,SAASD,wBAAwBH,WAAmB,EAAEC,OAAe;IAC1E,MAAMK,mBAAmBV,cAAcD,QAAQM,SAAS;IAExD,IAAI;QACF,OAAOJ,cAAcG,aAAaM;IACpC,EAAE,OAAOC,OAAO;QACd,MAAM,IAAIC,MACR,CAAC,2BAA2B,EAAER,YAAY,QAAQ,EAAEC,QAAQ,GAAG,EAAEM,iBAAiBC,QAAQD,MAAME,OAAO,GAAGC,OAAOH,QAAQ;IAE7H;AACF;AAEA;;;;;;;;;;;;;;;;;CAiBC,GACD,OAAO,eAAeI,wBACpBX,WAAmB,EACnBY,SAAc;IAEd,IAAI;QACF,MAAMV,aAAaL,cAAcG,aAAaY;QAC9C,MAAMR,SAAS,MAAMN,SAASI,WAAWG,IAAI;QAC7C,OAAOD;IACT,EAAE,OAAOG,OAAO;QACd,MAAM,IAAIC,MACR,CAAC,2BAA2B,EAAER,YAAY,QAAQ,EAAEY,UAAUP,IAAI,CAAC,GAAG,EAAEE,iBAAiBC,QAAQD,MAAME,OAAO,GAAGC,OAAOH,QAAQ;IAEpI;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/cli-core",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "Sanity CLI core package",
5
5
  "keywords": [
6
6
  "cli",
@@ -51,7 +51,7 @@
51
51
  },
52
52
  "dependencies": {
53
53
  "@inquirer/prompts": "^8.3.0",
54
- "@oclif/core": "^4.8.3",
54
+ "@oclif/core": "^4.8.4",
55
55
  "@rexxars/jiti": "^2.6.2",
56
56
  "@sanity/client": "^7.17.0",
57
57
  "babel-plugin-react-compiler": "^1.0.0",
@@ -74,7 +74,7 @@
74
74
  },
75
75
  "devDependencies": {
76
76
  "@eslint/compat": "^2.0.3",
77
- "@sanity/pkg-utils": "^10.4.8",
77
+ "@sanity/pkg-utils": "^10.4.9",
78
78
  "@sanity/telemetry": "^0.8.1",
79
79
  "@swc/cli": "^0.8.0",
80
80
  "@swc/core": "^1.15.18",
@@ -83,12 +83,12 @@
83
83
  "@types/node": "^20.19.37",
84
84
  "eslint": "^9.39.4",
85
85
  "publint": "^0.3.18",
86
- "sanity": "^5.14.1",
86
+ "sanity": "^5.15.0",
87
87
  "typescript": "^5.9.3",
88
88
  "vitest": "^4.0.18",
89
89
  "@repo/package.config": "0.0.1",
90
- "@sanity/eslint-config-cli": "1.0.0",
91
- "@repo/tsconfig": "3.70.0"
90
+ "@repo/tsconfig": "3.70.0",
91
+ "@sanity/eslint-config-cli": "1.0.0"
92
92
  },
93
93
  "peerDependencies": {
94
94
  "@sanity/telemetry": ">=0.8.1 <0.9.0"