@sanity/cli-build 3.0.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_exports/_internal/build.d.ts +54 -28
- package/dist/_exports/_internal/build.js +1 -1
- package/dist/_exports/_internal/build.js.map +1 -1
- package/dist/_exports/_internal/extract.d.ts +1 -1
- package/dist/actions/build/buildApp.js +4 -2
- package/dist/actions/build/buildApp.js.map +1 -1
- package/dist/actions/build/buildDebug.js +1 -1
- package/dist/actions/build/buildDebug.js.map +1 -1
- package/dist/actions/build/buildStaticFiles.js.map +1 -1
- package/dist/actions/build/buildStudio.js +4 -2
- package/dist/actions/build/buildStudio.js.map +1 -1
- package/dist/actions/build/checkRequiredDependencies.js +1 -1
- package/dist/actions/build/checkRequiredDependencies.js.map +1 -1
- package/dist/actions/build/checkStudioDependencyVersions.js +1 -1
- package/dist/actions/build/checkStudioDependencyVersions.js.map +1 -1
- package/dist/actions/build/decorateIndexWithStagingScript.js +1 -1
- package/dist/actions/build/decorateIndexWithStagingScript.js.map +1 -1
- package/dist/actions/build/getViteConfig.js +2 -1
- package/dist/actions/build/getViteConfig.js.map +1 -1
- package/dist/actions/build/handlePrereleaseVersions.js +1 -1
- package/dist/actions/build/handlePrereleaseVersions.js.map +1 -1
- package/dist/actions/build/renderDocument.js +1 -1
- package/dist/actions/build/renderDocument.js.map +1 -1
- package/dist/actions/build/renderDocumentWorker/tryLoadDocumentComponent.js +1 -1
- package/dist/actions/build/renderDocumentWorker/tryLoadDocumentComponent.js.map +1 -1
- package/dist/actions/build/resolveVendorBuildConfig.js +1 -1
- package/dist/actions/build/resolveVendorBuildConfig.js.map +1 -1
- package/dist/actions/build/writeFavicons.js +3 -3
- package/dist/actions/build/writeFavicons.js.map +1 -1
- package/dist/actions/build/writeSanityRuntime.js +5 -5
- package/dist/actions/build/writeSanityRuntime.js.map +1 -1
- package/dist/actions/schema/extractSanitySchema.worker.js +1 -1
- package/dist/actions/schema/extractSanitySchema.worker.js.map +1 -1
- package/dist/actions/schema/getExtractOptions.js.map +1 -1
- package/dist/actions/schema/runSchemaExtraction.js +1 -1
- package/dist/actions/schema/runSchemaExtraction.js.map +1 -1
- package/dist/actions/schema/utils/extractValidationFromSchemaError.js +1 -1
- package/dist/actions/schema/utils/extractValidationFromSchemaError.js.map +1 -1
- package/dist/actions/schema/vite/plugin-schema-extraction.js.map +1 -1
- package/dist/util/compareDependencyVersions.js +110 -0
- package/dist/util/compareDependencyVersions.js.map +1 -0
- package/package.json +5 -7
- package/dist/util/compareDependencyVersions.d.js +0 -3
- package/dist/util/compareDependencyVersions.d.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/build/getViteConfig.ts"],"sourcesContent":["import path from 'node:path'\n\nimport babel from '@rolldown/plugin-babel'\nimport {\n type CliConfig,\n findProjectRoot,\n getCliTelemetry,\n type UserViteConfig,\n} from '@sanity/cli-core'\nimport {type WorkbenchExposes, workbenchVitePlugins} from '@sanity/workbench-cli/build'\nimport viteReact, {reactCompilerPreset} from '@vitejs/plugin-react'\nimport {type PluginOptions as ReactCompilerConfig} from 'babel-plugin-react-compiler'\nimport debug from 'debug'\nimport {\n type ConfigEnv,\n esmExternalRequirePlugin,\n type InlineConfig,\n mergeConfig,\n type Plugin,\n type PluginOption,\n type Rolldown,\n} from 'vite'\n\nimport {SANITY_CACHE_DIR} from '../../constants.js'\nimport {sanitySchemaExtractionPlugin} from '../schema/vite/plugin-schema-extraction.js'\nimport {type AutoUpdatesBuildConfig} from './autoUpdates.js'\nimport {VENDOR_DIR} from './constants.js'\nimport {createExternalFromImportMap} from './createExternalFromImportMap.js'\nimport {normalizeBasePath} from './normalizeBasePath.js'\nimport {sanityBuildEntries} from './vite/plugin-sanity-build-entries.js'\nimport {sanityFaviconsPlugin} from './vite/plugin-sanity-favicons.js'\nimport {sanityRuntimeRewritePlugin} from './vite/plugin-sanity-runtime-rewrite.js'\nimport {createVendorNamedExportsPlugin} from './vite/plugin-sanity-vendor-named-exports.js'\nimport {getDefaultFaviconsPath} from './writeFavicons.js'\n\ninterface ViteOptions {\n /**\n * Root path of the studio/sanity app\n */\n cwd: string\n\n entries: {\n relativeConfigLocation: string | null\n // `null` when a branded app declares no `entry` (sanity-io/workbench spec 002-workbench-extension-api, US5) — no app view.\n relativeEntry: string | null\n }\n\n /**\n * Returns the environment variables to be injected into the config.\n */\n getEnvironmentVariables(): Record<string, string>\n\n /**\n * Mode to run vite in - eg development or production\n */\n mode: 'development' | 'production'\n\n reactCompiler: ReactCompilerConfig | undefined\n\n /**\n * Additional plugins when configured, eg. typegen\n */\n additionalPlugins?: Plugin[]\n\n /**\n * Auto-updates configuration (production builds only). When set, vendor\n * packages are emitted as hashed ESM chunks by this build and the import map\n * in `index.html` is derived from the build output.\n */\n autoUpdates?: AutoUpdatesBuildConfig\n\n /**\n * Base path (eg under where to serve the app - `/studio` or similar)\n * Will be normalized to ensure it starts and ends with a `/`\n */\n basePath?: string\n\n exposes?: WorkbenchExposes\n\n isApp?: boolean\n\n /**\n * Whether this is a workbench app (opted in via `unstable_defineApp`). Drives\n * the module-federation build.\n */\n isWorkbenchApp?: boolean\n\n /**\n * Whether or not to minify the output (only used in `mode: 'production'`)\n */\n minify?: boolean\n\n /**\n * Output directory (eg where to place the built files, if any)\n */\n outputDir?: string\n\n /**\n * Schema extraction configuration\n */\n schemaExtraction?: CliConfig['schemaExtraction']\n\n /**\n * HTTP development server configuration\n */\n server?: {host?: string; port?: number}\n\n /**\n * Whether or not to enable source maps\n */\n sourceMap?: boolean\n\n /**\n * The workbench app's bus identity, stamped into its modules as\n * `__SANITY_APP_ID__` for `@sanity/runtime`. Only read for workbench apps.\n */\n workbenchAppId?: string\n}\n\n/**\n * Get a configuration object for Vite based on the passed options\n *\n * @internal Only meant for consumption inside of Sanity modules, do not depend on this externally\n */\nexport async function getViteConfig(options: ViteOptions): Promise<InlineConfig> {\n const {\n additionalPlugins,\n autoUpdates,\n basePath: rawBasePath = '/',\n cwd,\n entries,\n exposes,\n isApp,\n isWorkbenchApp,\n minify,\n mode,\n outputDir,\n reactCompiler,\n schemaExtraction,\n server,\n // default to `true` when `mode=development`\n sourceMap = options.mode === 'development',\n workbenchAppId,\n } = options\n\n const basePath = normalizeBasePath(rawBasePath)\n\n const configPath = (await findProjectRoot(cwd)).path\n\n const customFaviconsPath = path.join(cwd, 'static')\n const defaultFaviconsPath = await getDefaultFaviconsPath()\n const staticPath = `${basePath}static`\n\n const envVars = options.getEnvironmentVariables()\n\n const sharedPlugins: PluginOption = [\n viteReact(),\n ...(reactCompiler ? [babel({presets: [reactCompilerPreset(reactCompiler)]})] : []),\n ...(schemaExtraction?.enabled\n ? [\n sanitySchemaExtractionPlugin({\n additionalPatterns: schemaExtraction.watchPatterns,\n configPath,\n enforceRequiredFields: schemaExtraction.enforceRequiredFields,\n outputPath: schemaExtraction.path,\n telemetryLogger: getCliTelemetry(),\n workDir: cwd,\n workspaceName: schemaExtraction.workspace,\n }),\n ]\n : []),\n ]\n\n const viteConfig: InlineConfig = {\n base: basePath,\n build: {\n outDir: outputDir || path.resolve(cwd, 'dist'),\n sourcemap: sourceMap,\n },\n // Define a custom cache directory so that sanity's vite cache\n // does not conflict with any potential local vite projects\n cacheDir: `${SANITY_CACHE_DIR}/vite`,\n configFile: false,\n define: {\n __SANITY_BUILD_TIMESTAMP__: JSON.stringify(Date.now()),\n __SANITY_STAGING__: process.env.SANITY_INTERNAL_ENV === 'staging',\n 'process.env.MODE': JSON.stringify(mode),\n 'process.env.PKG_BUILD_VERSION': JSON.stringify(process.env.PKG_BUILD_VERSION),\n /**\n * Yes, double negatives are confusing.\n * The default value of `SC_DISABLE_SPEEDY` is `process.env.NODE_ENV === 'production'`: https://github.com/styled-components/styled-components/blob/99c02f52d69e8e509c0bf012cadee7f8e819a6dd/packages/styled-components/src/constants.ts#L34\n * Which means that in production, use the much faster way of inserting CSS rules, based on the CSSStyleSheet API (https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/insertRule)\n * while in dev mode, use the slower way of inserting CSS rules, which appends text nodes to the `<style>` tag: https://github.com/styled-components/styled-components/blob/99c02f52d69e8e509c0bf012cadee7f8e819a6dd/packages/styled-components/src/sheet/Tag.ts#L74-L76\n * There are historical reasons for this, primarily that browsers initially did not support editing CSS rules in the DevTools inspector if `CSSStyleSheet.insetRule` were used.\n * However, that's no longer the case (since Chrome 81 back in April 2020: https://developer.chrome.com/docs/css-ui/css-in-js), the latest version of FireFox also supports it,\n * and there is no longer any reason to use the much slower method in dev mode.\n */\n 'process.env.SC_DISABLE_SPEEDY': JSON.stringify('false'),\n ...envVars,\n },\n envPrefix: isApp ? 'SANITY_APP_' : 'SANITY_STUDIO_',\n logLevel: mode === 'production' ? 'silent' : 'info',\n mode,\n plugins: [\n // Federation builds only need the federation plugin — skip client-specific\n // plugins (favicons, runtime rewrite, build entries)\n ...(isWorkbenchApp\n ? [\n ...sharedPlugins,\n await workbenchVitePlugins({appId: workbenchAppId, cwd, entries, exposes, isApp}),\n ]\n : [\n ...sharedPlugins,\n sanityFaviconsPlugin({\n customFaviconsPath,\n defaultFaviconsPath,\n staticUrlPath: staticPath,\n }),\n sanityRuntimeRewritePlugin(),\n sanityBuildEntries({autoUpdates, basePath, cwd, isApp}),\n ]),\n // Caller-provided plugins (e.g. typegen in dev) aren't client-specific,\n // so they apply to federation builds too.\n ...(additionalPlugins || []),\n ],\n resolve: {\n dedupe: ['react', 'react-dom', 'sanity', 'styled-components'],\n // Honor the studio's tsconfig `paths`, consistent with studioWorkerLoader.worker.ts.\n tsconfigPaths: true,\n },\n root: cwd,\n server: {\n host: server?.host,\n port: server?.port || 3333,\n // Apps drift to a free port (the reported URL embeds whichever port was\n // claimed), and workbench runs stack servers on adjacent ports — both\n // need the fallback. Studios fail fast on a busy port.\n strictPort: !isApp && !isWorkbenchApp,\n\n /**\n * Significantly speed up startup time,\n * and most importantly eliminates the `new dependencies optimized: foobar. optimized dependencies changed. reloading`\n * types of initial reload loops that otherwise happen as vite discovers deps that need to be optimized.\n * This option starts the traversal up front, and warms up the dep tree required to render the userland sanity.config.ts file,\n * and thus avoids frustrating reload loops.\n */\n warmup: {\n clientFiles: ['./.sanity/runtime/app.js'],\n },\n },\n }\n\n // Federation builds don't produce a client bundle — the federation\n // plugin configures its own environment and build entry point.\n if (mode === 'production' && !isWorkbenchApp) {\n if (autoUpdates) {\n viteConfig.plugins!.push(\n // Re-expose CommonJS named exports (react, react-dom) as real ESM exports\n // on the emitted vendor chunks; Rolldown only emits `export default` for a\n // CommonJS entry.\n createVendorNamedExportsPlugin(autoUpdates.vendor.namesByChunkName),\n // The import map and vendor specifiers are externals of the studio/app\n // bundle, resolved by the browser at runtime. They are handed to\n // `esmExternalRequirePlugin` rather than `rolldownOptions.external`: the\n // plugin both marks them external AND rewrites bundled CommonJS\n // `require()` calls of an external (e.g. react-dom requiring react) into\n // ESM imports, while `rolldownOptions.external` would short-circuit that\n // rewrite and leave a runtime `require` shim that throws in the browser.\n esmExternalRequirePlugin({\n external: createExternalFromImportMap({\n imports: {\n ...autoUpdates.imports,\n ...Object.fromEntries(\n Object.values(autoUpdates.vendor.specifiersByChunkName).map((specifier) => [\n specifier,\n '',\n ]),\n ),\n },\n }),\n }),\n )\n }\n\n const vendorChunkNames = autoUpdates\n ? new Set(Object.keys(autoUpdates.vendor.specifiersByChunkName))\n : null\n\n viteConfig.build = {\n ...viteConfig.build,\n\n assetsDir: 'static',\n emptyOutDir: false, // Rely on CLI to do this\n minify: minify ? 'oxc' : false,\n\n rolldownOptions: {\n input: {\n sanity: path.join(cwd, '.sanity', 'runtime', 'app.js'),\n ...autoUpdates?.vendor.entries,\n },\n onwarn: onRolldownWarn,\n ...(autoUpdates\n ? {\n // Expose Rolldown's native MagicString on `renderChunk`'s `meta` so\n // the vendor named-exports plugin can edit chunks without a JS\n // dependency.\n experimental: {nativeMagicString: true},\n output: {\n entryFileNames: (chunk) =>\n vendorChunkNames!.has(chunk.name)\n ? `${VENDOR_DIR}/[name]-[hash].mjs`\n : 'static/[name]-[hash].js',\n exports: 'named',\n },\n // App-style builds default to `preserveEntrySignatures: false`, which\n // treeshakes the exports off entry chunks. Vendor chunks are loaded by\n // the browser via the import map, so their exports must survive (e.g.\n // styled-components' native ESM exports). `exports-only` keeps exports\n // for entries that have them, while the export-less `sanity` app entry\n // still bundles as before.\n preserveEntrySignatures: 'exports-only',\n }\n : {}),\n },\n }\n }\n\n return viteConfig\n}\n\nfunction onRolldownWarn(warning: Rolldown.RolldownLog, warn: Rolldown.LoggingFunction) {\n if (suppressUnusedImport(warning)) {\n return\n }\n\n warn(warning)\n}\n\nfunction suppressUnusedImport(warning: Rolldown.RolldownLog & {ids?: string[]}): boolean {\n if (warning.code !== 'UNUSED_EXTERNAL_IMPORT') return false\n\n // Suppress:\n // ```\n // \"useDebugValue\" is imported from external module \"react\"…\n // ```\n if (warning.names?.includes('useDebugValue')) {\n warning.names = warning.names.filter((n) => n !== 'useDebugValue')\n if (warning.names.length === 0) return true\n }\n\n // If some library does something unexpected, we suppress since it isn't actionable\n if (warning.ids?.every((id) => id.includes('/node_modules/') || id.includes('\\\\node_modules\\\\')))\n return true\n\n return false\n}\n\n/**\n * Re-asserts the critical parts of the default config after a userland vite\n * config (`vite` in `sanity.cli.ts`) has been applied.\n *\n * Everything `getViteConfig` sets under `build.rolldownOptions` is load-bearing:\n * the `input` entries (the studio entry plus, for auto-updating studios/apps,\n * the vendor entries), `preserveEntrySignatures`, the `experimental` flags the\n * vendor plugins rely on, and the `output` chunk naming. A userland config that\n * returns a brand-new object for any of these would silently break the build\n * (e.g. vendor chunks never emitted while the bundle still treats them as\n * external), so the default `rolldownOptions` are deep-merged back over the\n * userland config: userland additions survive, replacements of critical\n * options are healed.\n *\n * @param config - User-modified configuration\n * @param defaultConfig - The configuration produced by `getViteConfig`, before the userland config was applied\n * @returns Merged configuration\n * @internal\n */\nexport async function finalizeViteConfig(\n config: InlineConfig,\n defaultConfig: InlineConfig,\n): Promise<InlineConfig> {\n if (typeof config.build?.rolldownOptions?.input !== 'object') {\n throw new TypeError(\n 'Vite config must contain `build.rolldownOptions.input`, and it must be an object',\n )\n }\n\n if (!config.root) {\n throw new Error(\n 'Vite config must contain `root` property, and must point to the Sanity root directory',\n )\n }\n\n return mergeConfig(config, {\n build: {\n rolldownOptions: defaultConfig.build?.rolldownOptions ?? {},\n },\n })\n}\n\n/**\n * Merge user-provided Vite configuration object or function\n *\n * @param defaultConfig - Default configuration object\n * @param userConfig - User-provided configuration object or function\n * @returns Merged configuration\n * @internal\n */\nexport async function extendViteConfigWithUserConfig(\n env: ConfigEnv,\n defaultConfig: InlineConfig,\n userConfig: UserViteConfig,\n): Promise<InlineConfig> {\n let config = defaultConfig\n\n if (typeof userConfig === 'function') {\n debug('Extending vite config using user-specified function')\n config = await userConfig(config, env)\n } else if (typeof userConfig === 'object') {\n debug('Merging vite config using user-specified object')\n config = mergeConfig(config, userConfig)\n }\n\n return config\n}\n"],"names":["path","babel","findProjectRoot","getCliTelemetry","workbenchVitePlugins","viteReact","reactCompilerPreset","debug","esmExternalRequirePlugin","mergeConfig","SANITY_CACHE_DIR","sanitySchemaExtractionPlugin","VENDOR_DIR","createExternalFromImportMap","normalizeBasePath","sanityBuildEntries","sanityFaviconsPlugin","sanityRuntimeRewritePlugin","createVendorNamedExportsPlugin","getDefaultFaviconsPath","getViteConfig","options","additionalPlugins","autoUpdates","basePath","rawBasePath","cwd","entries","exposes","isApp","isWorkbenchApp","minify","mode","outputDir","reactCompiler","schemaExtraction","server","sourceMap","workbenchAppId","configPath","customFaviconsPath","join","defaultFaviconsPath","staticPath","envVars","getEnvironmentVariables","sharedPlugins","presets","enabled","additionalPatterns","watchPatterns","enforceRequiredFields","outputPath","telemetryLogger","workDir","workspaceName","workspace","viteConfig","base","build","outDir","resolve","sourcemap","cacheDir","configFile","define","__SANITY_BUILD_TIMESTAMP__","JSON","stringify","Date","now","__SANITY_STAGING__","process","env","SANITY_INTERNAL_ENV","PKG_BUILD_VERSION","envPrefix","logLevel","plugins","appId","staticUrlPath","dedupe","tsconfigPaths","root","host","port","strictPort","warmup","clientFiles","push","vendor","namesByChunkName","external","imports","Object","fromEntries","values","specifiersByChunkName","map","specifier","vendorChunkNames","Set","keys","assetsDir","emptyOutDir","rolldownOptions","input","sanity","onwarn","onRolldownWarn","experimental","nativeMagicString","output","entryFileNames","chunk","has","name","exports","preserveEntrySignatures","warning","warn","suppressUnusedImport","code","names","includes","filter","n","length","ids","every","id","finalizeViteConfig","config","defaultConfig","TypeError","Error","extendViteConfigWithUserConfig","userConfig"],"mappings":"AAAA,OAAOA,UAAU,YAAW;AAE5B,OAAOC,WAAW,yBAAwB;AAC1C,SAEEC,eAAe,EACfC,eAAe,QAEV,mBAAkB;AACzB,SAA+BC,oBAAoB,QAAO,8BAA6B;AACvF,OAAOC,aAAYC,mBAAmB,QAAO,uBAAsB;AAEnE,OAAOC,WAAW,QAAO;AACzB,SAEEC,wBAAwB,EAExBC,WAAW,QAIN,OAAM;AAEb,SAAQC,gBAAgB,QAAO,qBAAoB;AACnD,SAAQC,4BAA4B,QAAO,6CAA4C;AAEvF,SAAQC,UAAU,QAAO,iBAAgB;AACzC,SAAQC,2BAA2B,QAAO,mCAAkC;AAC5E,SAAQC,iBAAiB,QAAO,yBAAwB;AACxD,SAAQC,kBAAkB,QAAO,wCAAuC;AACxE,SAAQC,oBAAoB,QAAO,mCAAkC;AACrE,SAAQC,0BAA0B,QAAO,0CAAyC;AAClF,SAAQC,8BAA8B,QAAO,+CAA8C;AAC3F,SAAQC,sBAAsB,QAAO,qBAAoB;AAsFzD;;;;CAIC,GACD,OAAO,eAAeC,cAAcC,OAAoB;IACtD,MAAM,EACJC,iBAAiB,EACjBC,WAAW,EACXC,UAAUC,cAAc,GAAG,EAC3BC,GAAG,EACHC,OAAO,EACPC,OAAO,EACPC,KAAK,EACLC,cAAc,EACdC,MAAM,EACNC,IAAI,EACJC,SAAS,EACTC,aAAa,EACbC,gB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M,CAAC,CAACC,IAAMA,MAAM;QAClD,IAAIP,QAAQI,KAAK,CAACI,MAAM,KAAK,GAAG,OAAO;IACzC;IAEA,mFAAmF;IACnF,IAAIR,QAAQS,GAAG,EAAEC,MAAM,CAACC,KAAOA,GAAGN,QAAQ,CAAC,qBAAqBM,GAAGN,QAAQ,CAAC,sBAC1E,OAAO;IAET,OAAO;AACT;AAEA;;;;;;;;;;;;;;;;;;CAkBC,GACD,OAAO,eAAeO,mBACpBC,MAAoB,EACpBC,aAA2B;IAE3B,IAAI,OAAOD,OAAOzE,KAAK,EAAE8C,iBAAiBC,UAAU,UAAU;QAC5D,MAAM,IAAI4B,UACR;IAEJ;IAEA,IAAI,CAACF,OAAOjD,IAAI,EAAE;QAChB,MAAM,IAAIoD,MACR;IAEJ;IAEA,OAAO9H,YAAY2H,QAAQ;QACzBzE,OAAO;YACL8C,iBAAiB4B,cAAc1E,KAAK,EAAE8C,mBAAmB,CAAC;QAC5D;IACF;AACF;AAEA;;;;;;;CAOC,GACD,OAAO,eAAe+B,+BACpB/D,GAAc,EACd4D,aAA2B,EAC3BI,UAA0B;IAE1B,IAAIL,SAASC;IAEb,IAAI,OAAOI,eAAe,YAAY;QACpClI,MAAM;QACN6H,SAAS,MAAMK,WAAWL,QAAQ3D;IACpC,OAAO,IAAI,OAAOgE,eAAe,UAAU;QACzClI,MAAM;QACN6H,SAAS3H,YAAY2H,QAAQK;IAC/B;IAEA,OAAOL;AACT"}
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/build/getViteConfig.ts"],"sourcesContent":["import path from 'node:path'\n\nimport babel from '@rolldown/plugin-babel'\nimport {findProjectRoot} from '@sanity/cli-core/config'\nimport {getCliTelemetry} from '@sanity/cli-core/telemetry'\nimport {type CliConfig, type UserViteConfig} from '@sanity/cli-core/types'\nimport {type WorkbenchExposes, workbenchVitePlugins} from '@sanity/workbench-cli/build'\nimport viteReact, {reactCompilerPreset} from '@vitejs/plugin-react'\nimport {type PluginOptions as ReactCompilerConfig} from 'babel-plugin-react-compiler'\nimport debug from 'debug'\nimport {\n type ConfigEnv,\n esmExternalRequirePlugin,\n type InlineConfig,\n mergeConfig,\n type Plugin,\n type PluginOption,\n type Rolldown,\n} from 'vite'\n\nimport {SANITY_CACHE_DIR} from '../../constants.js'\nimport {sanitySchemaExtractionPlugin} from '../schema/vite/plugin-schema-extraction.js'\nimport {type AutoUpdatesBuildConfig} from './autoUpdates.js'\nimport {VENDOR_DIR} from './constants.js'\nimport {createExternalFromImportMap} from './createExternalFromImportMap.js'\nimport {normalizeBasePath} from './normalizeBasePath.js'\nimport {sanityBuildEntries} from './vite/plugin-sanity-build-entries.js'\nimport {sanityFaviconsPlugin} from './vite/plugin-sanity-favicons.js'\nimport {sanityRuntimeRewritePlugin} from './vite/plugin-sanity-runtime-rewrite.js'\nimport {createVendorNamedExportsPlugin} from './vite/plugin-sanity-vendor-named-exports.js'\nimport {getDefaultFaviconsPath} from './writeFavicons.js'\n\ninterface ViteOptions {\n /**\n * Root path of the studio/sanity app\n */\n cwd: string\n\n entries: {\n relativeConfigLocation: string | null\n // `null` when a branded app declares no `entry` (sanity-io/workbench spec 002-workbench-extension-api, US5) — no app view.\n relativeEntry: string | null\n }\n\n /**\n * Returns the environment variables to be injected into the config.\n */\n getEnvironmentVariables(): Record<string, string>\n\n /**\n * Mode to run vite in - eg development or production\n */\n mode: 'development' | 'production'\n\n reactCompiler: ReactCompilerConfig | undefined\n\n /**\n * Additional plugins when configured, eg. typegen\n */\n additionalPlugins?: Plugin[]\n\n /**\n * Auto-updates configuration (production builds only). When set, vendor\n * packages are emitted as hashed ESM chunks by this build and the import map\n * in `index.html` is derived from the build output.\n */\n autoUpdates?: AutoUpdatesBuildConfig\n\n /**\n * Base path (eg under where to serve the app - `/studio` or similar)\n * Will be normalized to ensure it starts and ends with a `/`\n */\n basePath?: string\n\n exposes?: WorkbenchExposes\n\n isApp?: boolean\n\n /**\n * Whether this is a workbench app (opted in via `unstable_defineApp`). Drives\n * the module-federation build.\n */\n isWorkbenchApp?: boolean\n\n /**\n * Whether or not to minify the output (only used in `mode: 'production'`)\n */\n minify?: boolean\n\n /**\n * Output directory (eg where to place the built files, if any)\n */\n outputDir?: string\n\n /**\n * Schema extraction configuration\n */\n schemaExtraction?: CliConfig['schemaExtraction']\n\n /**\n * HTTP development server configuration\n */\n server?: {host?: string; port?: number}\n\n /**\n * Whether or not to enable source maps\n */\n sourceMap?: boolean\n\n /**\n * The workbench app's bus identity, stamped into its modules as\n * `__SANITY_APP_ID__` for `@sanity/runtime`. Only read for workbench apps.\n */\n workbenchAppId?: string\n}\n\n/**\n * Get a configuration object for Vite based on the passed options\n *\n * @internal Only meant for consumption inside of Sanity modules, do not depend on this externally\n */\nexport async function getViteConfig(options: ViteOptions): Promise<InlineConfig> {\n const {\n additionalPlugins,\n autoUpdates,\n basePath: rawBasePath = '/',\n cwd,\n entries,\n exposes,\n isApp,\n isWorkbenchApp,\n minify,\n mode,\n outputDir,\n reactCompiler,\n schemaExtraction,\n server,\n // default to `true` when `mode=development`\n sourceMap = options.mode === 'development',\n workbenchAppId,\n } = options\n\n const basePath = normalizeBasePath(rawBasePath)\n\n const configPath = (await findProjectRoot(cwd)).path\n\n const customFaviconsPath = path.join(cwd, 'static')\n const defaultFaviconsPath = await getDefaultFaviconsPath()\n const staticPath = `${basePath}static`\n\n const envVars = options.getEnvironmentVariables()\n\n const sharedPlugins: PluginOption = [\n viteReact(),\n ...(reactCompiler ? [babel({presets: [reactCompilerPreset(reactCompiler)]})] : []),\n ...(schemaExtraction?.enabled\n ? [\n sanitySchemaExtractionPlugin({\n additionalPatterns: schemaExtraction.watchPatterns,\n configPath,\n enforceRequiredFields: schemaExtraction.enforceRequiredFields,\n outputPath: schemaExtraction.path,\n telemetryLogger: getCliTelemetry(),\n workDir: cwd,\n workspaceName: schemaExtraction.workspace,\n }),\n ]\n : []),\n ]\n\n const viteConfig: InlineConfig = {\n base: basePath,\n build: {\n outDir: outputDir || path.resolve(cwd, 'dist'),\n sourcemap: sourceMap,\n },\n // Define a custom cache directory so that sanity's vite cache\n // does not conflict with any potential local vite projects\n cacheDir: `${SANITY_CACHE_DIR}/vite`,\n configFile: false,\n define: {\n __SANITY_BUILD_TIMESTAMP__: JSON.stringify(Date.now()),\n __SANITY_STAGING__: process.env.SANITY_INTERNAL_ENV === 'staging',\n 'process.env.MODE': JSON.stringify(mode),\n 'process.env.PKG_BUILD_VERSION': JSON.stringify(process.env.PKG_BUILD_VERSION),\n /**\n * Yes, double negatives are confusing.\n * The default value of `SC_DISABLE_SPEEDY` is `process.env.NODE_ENV === 'production'`: https://github.com/styled-components/styled-components/blob/99c02f52d69e8e509c0bf012cadee7f8e819a6dd/packages/styled-components/src/constants.ts#L34\n * Which means that in production, use the much faster way of inserting CSS rules, based on the CSSStyleSheet API (https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/insertRule)\n * while in dev mode, use the slower way of inserting CSS rules, which appends text nodes to the `<style>` tag: https://github.com/styled-components/styled-components/blob/99c02f52d69e8e509c0bf012cadee7f8e819a6dd/packages/styled-components/src/sheet/Tag.ts#L74-L76\n * There are historical reasons for this, primarily that browsers initially did not support editing CSS rules in the DevTools inspector if `CSSStyleSheet.insetRule` were used.\n * However, that's no longer the case (since Chrome 81 back in April 2020: https://developer.chrome.com/docs/css-ui/css-in-js), the latest version of FireFox also supports it,\n * and there is no longer any reason to use the much slower method in dev mode.\n */\n 'process.env.SC_DISABLE_SPEEDY': JSON.stringify('false'),\n ...envVars,\n },\n envPrefix: isApp ? 'SANITY_APP_' : 'SANITY_STUDIO_',\n logLevel: mode === 'production' ? 'silent' : 'info',\n mode,\n plugins: [\n // Federation builds only need the federation plugin — skip client-specific\n // plugins (favicons, runtime rewrite, build entries)\n ...(isWorkbenchApp\n ? [\n ...sharedPlugins,\n await workbenchVitePlugins({appId: workbenchAppId, cwd, entries, exposes, isApp}),\n ]\n : [\n ...sharedPlugins,\n sanityFaviconsPlugin({\n customFaviconsPath,\n defaultFaviconsPath,\n staticUrlPath: staticPath,\n }),\n sanityRuntimeRewritePlugin(),\n sanityBuildEntries({autoUpdates, basePath, cwd, isApp}),\n ]),\n // Caller-provided plugins (e.g. typegen in dev) aren't client-specific,\n // so they apply to federation builds too.\n ...(additionalPlugins || []),\n ],\n resolve: {\n dedupe: ['react', 'react-dom', 'sanity', 'styled-components'],\n // Honor the studio's tsconfig `paths`, consistent with studioWorkerLoader.worker.ts.\n tsconfigPaths: true,\n },\n root: cwd,\n server: {\n host: server?.host,\n port: server?.port || 3333,\n // Apps drift to a free port (the reported URL embeds whichever port was\n // claimed), and workbench runs stack servers on adjacent ports — both\n // need the fallback. Studios fail fast on a busy port.\n strictPort: !isApp && !isWorkbenchApp,\n\n /**\n * Significantly speed up startup time,\n * and most importantly eliminates the `new dependencies optimized: foobar. optimized dependencies changed. reloading`\n * types of initial reload loops that otherwise happen as vite discovers deps that need to be optimized.\n * This option starts the traversal up front, and warms up the dep tree required to render the userland sanity.config.ts file,\n * and thus avoids frustrating reload loops.\n */\n warmup: {\n clientFiles: ['./.sanity/runtime/app.js'],\n },\n },\n }\n\n // Federation builds don't produce a client bundle — the federation\n // plugin configures its own environment and build entry point.\n if (mode === 'production' && !isWorkbenchApp) {\n if (autoUpdates) {\n viteConfig.plugins!.push(\n // Re-expose CommonJS named exports (react, react-dom) as real ESM exports\n // on the emitted vendor chunks; Rolldown only emits `export default` for a\n // CommonJS entry.\n createVendorNamedExportsPlugin(autoUpdates.vendor.namesByChunkName),\n // The import map and vendor specifiers are externals of the studio/app\n // bundle, resolved by the browser at runtime. They are handed to\n // `esmExternalRequirePlugin` rather than `rolldownOptions.external`: the\n // plugin both marks them external AND rewrites bundled CommonJS\n // `require()` calls of an external (e.g. react-dom requiring react) into\n // ESM imports, while `rolldownOptions.external` would short-circuit that\n // rewrite and leave a runtime `require` shim that throws in the browser.\n esmExternalRequirePlugin({\n external: createExternalFromImportMap({\n imports: {\n ...autoUpdates.imports,\n ...Object.fromEntries(\n Object.values(autoUpdates.vendor.specifiersByChunkName).map((specifier) => [\n specifier,\n '',\n ]),\n ),\n },\n }),\n }),\n )\n }\n\n const vendorChunkNames = autoUpdates\n ? new Set(Object.keys(autoUpdates.vendor.specifiersByChunkName))\n : null\n\n viteConfig.build = {\n ...viteConfig.build,\n\n assetsDir: 'static',\n emptyOutDir: false, // Rely on CLI to do this\n minify: minify ? 'oxc' : false,\n\n rolldownOptions: {\n input: {\n sanity: path.join(cwd, '.sanity', 'runtime', 'app.js'),\n ...autoUpdates?.vendor.entries,\n },\n onwarn: onRolldownWarn,\n ...(autoUpdates\n ? {\n // Expose Rolldown's native MagicString on `renderChunk`'s `meta` so\n // the vendor named-exports plugin can edit chunks without a JS\n // dependency.\n experimental: {nativeMagicString: true},\n output: {\n entryFileNames: (chunk) =>\n vendorChunkNames!.has(chunk.name)\n ? `${VENDOR_DIR}/[name]-[hash].mjs`\n : 'static/[name]-[hash].js',\n exports: 'named',\n },\n // App-style builds default to `preserveEntrySignatures: false`, which\n // treeshakes the exports off entry chunks. Vendor chunks are loaded by\n // the browser via the import map, so their exports must survive (e.g.\n // styled-components' native ESM exports). `exports-only` keeps exports\n // for entries that have them, while the export-less `sanity` app entry\n // still bundles as before.\n preserveEntrySignatures: 'exports-only',\n }\n : {}),\n },\n }\n }\n\n return viteConfig\n}\n\nfunction onRolldownWarn(warning: Rolldown.RolldownLog, warn: Rolldown.LoggingFunction) {\n if (suppressUnusedImport(warning)) {\n return\n }\n\n warn(warning)\n}\n\nfunction suppressUnusedImport(warning: Rolldown.RolldownLog & {ids?: string[]}): boolean {\n if (warning.code !== 'UNUSED_EXTERNAL_IMPORT') return false\n\n // Suppress:\n // ```\n // \"useDebugValue\" is imported from external module \"react\"…\n // ```\n if (warning.names?.includes('useDebugValue')) {\n warning.names = warning.names.filter((n) => n !== 'useDebugValue')\n if (warning.names.length === 0) return true\n }\n\n // If some library does something unexpected, we suppress since it isn't actionable\n if (warning.ids?.every((id) => id.includes('/node_modules/') || id.includes('\\\\node_modules\\\\')))\n return true\n\n return false\n}\n\n/**\n * Re-asserts the critical parts of the default config after a userland vite\n * config (`vite` in `sanity.cli.ts`) has been applied.\n *\n * Everything `getViteConfig` sets under `build.rolldownOptions` is load-bearing:\n * the `input` entries (the studio entry plus, for auto-updating studios/apps,\n * the vendor entries), `preserveEntrySignatures`, the `experimental` flags the\n * vendor plugins rely on, and the `output` chunk naming. A userland config that\n * returns a brand-new object for any of these would silently break the build\n * (e.g. vendor chunks never emitted while the bundle still treats them as\n * external), so the default `rolldownOptions` are deep-merged back over the\n * userland config: userland additions survive, replacements of critical\n * options are healed.\n *\n * @param config - User-modified configuration\n * @param defaultConfig - The configuration produced by `getViteConfig`, before the userland config was applied\n * @returns Merged configuration\n * @internal\n */\nexport async function finalizeViteConfig(\n config: InlineConfig,\n defaultConfig: InlineConfig,\n): Promise<InlineConfig> {\n if (typeof config.build?.rolldownOptions?.input !== 'object') {\n throw new TypeError(\n 'Vite config must contain `build.rolldownOptions.input`, and it must be an object',\n )\n }\n\n if (!config.root) {\n throw new Error(\n 'Vite config must contain `root` property, and must point to the Sanity root directory',\n )\n }\n\n return mergeConfig(config, {\n build: {\n rolldownOptions: defaultConfig.build?.rolldownOptions ?? {},\n },\n })\n}\n\n/**\n * Merge user-provided Vite configuration object or function\n *\n * @param defaultConfig - Default configuration object\n * @param userConfig - User-provided configuration object or function\n * @returns Merged configuration\n * @internal\n */\nexport async function extendViteConfigWithUserConfig(\n env: ConfigEnv,\n defaultConfig: InlineConfig,\n userConfig: UserViteConfig,\n): Promise<InlineConfig> {\n let config = defaultConfig\n\n if (typeof userConfig === 'function') {\n debug('Extending vite config using user-specified function')\n config = await userConfig(config, env)\n } else if (typeof userConfig === 'object') {\n debug('Merging vite config using user-specified object')\n config = mergeConfig(config, userConfig)\n }\n\n return config\n}\n"],"names":["path","babel","findProjectRoot","getCliTelemetry","workbenchVitePlugins","viteReact","reactCompilerPreset","debug","esmExternalRequirePlugin","mergeConfig","SANITY_CACHE_DIR","sanitySchemaExtractionPlugin","VENDOR_DIR","createExternalFromImportMap","normalizeBasePath","sanityBuildEntries","sanityFaviconsPlugin","sanityRuntimeRewritePlugin","createVendorNamedExportsPlugin","getDefaultFaviconsPath","getViteConfig","options","additionalPlugins","autoUpdates","basePath","rawBasePath","cwd","entries","exposes","isApp","isWorkbenchApp","minify","mode","outputDir","reactCompiler","schemaExtraction","server","sourceMap","workbenchAppId","configPath","customFaviconsPath","join","defaultFaviconsPath","staticPath","envVars","getEnvironmentVariables","sharedPlugins","presets","enabled","additionalPatterns","watchPatterns","enforceRequiredFields","outputPath","telemetryLogger","workDir","workspaceName","workspace","viteConfig","base","build","outDir","resolve","sourcemap","cacheDir","configFile","define","__SANITY_BUILD_TIMESTAMP__","JSON","stringify","Date","now","__SANITY_STAGING__","process","env","SANITY_INTERNAL_ENV","PKG_BUILD_VERSION","envPrefix","logLevel","plugins","appId","staticUrlPath","dedupe","tsconfigPaths","root","host","port","strictPort","warmup","clientFiles","push","vendor","namesByChunkName","external","imports","Object","fromEntries","values","specifiersByChunkName","map","specifier","vendorChunkNames","Set","keys","assetsDir","emptyOutDir","rolldownOptions","input","sanity","onwarn","onRolldownWarn","experimental","nativeMagicString","output","entryFileNames","chunk","has","name","exports","preserveEntrySignatures","warning","warn","suppressUnusedImport","code","names","includes","filter","n","length","ids","every","id","finalizeViteConfig","config","defaultConfig","TypeError","Error","extendViteConfigWithUserConfig","userConfig"],"mappings":"AAAA,OAAOA,UAAU,YAAW;AAE5B,OAAOC,WAAW,yBAAwB;AAC1C,SAAQC,eAAe,QAAO,0BAAyB;AACvD,SAAQC,eAAe,QAAO,6BAA4B;AAE1D,SAA+BC,oBAAoB,QAAO,8BAA6B;AACvF,OAAOC,aAAYC,mBAAmB,QAAO,uBAAsB;AAEnE,OAAOC,WAAW,QAAO;AACzB,SAEEC,wBAAwB,EAExBC,WAAW,QAIN,OAAM;AAEb,SAAQC,gBAAgB,QAAO,qBAAoB;AACnD,SAAQC,4BAA4B,Q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1B,IAAIL,SAASC;IAEb,IAAI,OAAOI,eAAe,YAAY;QACpClI,MAAM;QACN6H,SAAS,MAAMK,WAAWL,QAAQ3D;IACpC,OAAO,IAAI,OAAOgE,eAAe,UAAU;QACzClI,MAAM;QACN6H,SAAS3H,YAAY2H,QAAQK;IAC/B;IAEA,OAAOL;AACT"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { styleText } from 'node:util';
|
|
2
|
-
import { isInteractive } from '@sanity/cli-core';
|
|
2
|
+
import { isInteractive } from '@sanity/cli-core/util';
|
|
3
3
|
import { select } from '@sanity/cli-core/ux';
|
|
4
4
|
/**
|
|
5
5
|
* Handle prerelease versions that cannot be resolved by the auto-updates CDN.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/build/handlePrereleaseVersions.ts"],"sourcesContent":["import {styleText} from 'node:util'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/build/handlePrereleaseVersions.ts"],"sourcesContent":["import {styleText} from 'node:util'\n\nimport {type Output} from '@sanity/cli-core/types'\nimport {isInteractive} from '@sanity/cli-core/util'\nimport {select} from '@sanity/cli-core/ux'\n\nimport {type UnresolvedPrerelease} from '../../util/compareDependencyVersions.js'\n\n/**\n * Handle prerelease versions that cannot be resolved by the auto-updates CDN.\n *\n * In unattended or non-interactive mode, exits with an error. In interactive mode,\n * prompts the user to either disable auto-updates for this build or cancel.\n *\n * Does not return if the build should be cancelled (exits via `output.error`).\n */\nexport async function handlePrereleaseVersions({\n output,\n unattendedMode,\n unresolvedPrerelease,\n}: {\n output: Output\n unattendedMode: boolean\n unresolvedPrerelease: UnresolvedPrerelease[]\n}): Promise<void> {\n const prereleaseMessage =\n `The following packages are using prerelease versions not yet available on the auto-updates CDN:\\n\\n` +\n `${unresolvedPrerelease.map((mod) => ` - ${mod.pkg} (${mod.version})`).join('\\n')}\\n\\n` +\n `Auto-updates cannot be used with prerelease versions. To re-enable auto-updates later, ` +\n `switch to a non-prerelease version locally and deploy again.`\n\n if (unattendedMode || !isInteractive()) {\n output.error(\n `${prereleaseMessage}\\n\\n` +\n `Cannot build with auto-updates in unattended mode when using prerelease versions. ` +\n `Either switch to a non-prerelease version, or use --no-auto-updates to build without auto-updates.`,\n {exit: 1},\n )\n // output.error with exit: 1 throws, but TypeScript doesn't know that\n return\n }\n\n const choice = await select({\n choices: [\n {\n name: 'Disable auto-updates for this build and continue',\n value: 'disable-auto-updates',\n },\n {name: 'Cancel build', value: 'cancel'},\n ],\n default: 'disable-auto-updates',\n message: styleText('yellow', prereleaseMessage),\n })\n\n if (choice === 'cancel') {\n output.error('Declined to continue with build', {exit: 1})\n // output.error with exit: 1 throws, but TypeScript doesn't know that\n return\n }\n\n output.warn('Auto-updates disabled for this build')\n}\n"],"names":["styleText","isInteractive","select","handlePrereleaseVersions","output","unattendedMode","unresolvedPrerelease","prereleaseMessage","map","mod","pkg","version","join","error","exit","choice","choices","name","value","default","message","warn"],"mappings":"AAAA,SAAQA,SAAS,QAAO,YAAW;AAGnC,SAAQC,aAAa,QAAO,wBAAuB;AACnD,SAAQC,MAAM,QAAO,sBAAqB;AAI1C;;;;;;;CAOC,GACD,OAAO,eAAeC,yBAAyB,EAC7CC,MAAM,EACNC,cAAc,EACdC,oBAAoB,EAKrB;IACC,MAAMC,oBACJ,CAAC,mGAAmG,CAAC,GACrG,GAAGD,qBAAqBE,GAAG,CAAC,CAACC,MAAQ,CAAC,GAAG,EAAEA,IAAIC,GAAG,CAAC,EAAE,EAAED,IAAIE,OAAO,CAAC,CAAC,CAAC,EAAEC,IAAI,CAAC,MAAM,IAAI,CAAC,GACvF,CAAC,uFAAuF,CAAC,GACzF,CAAC,4DAA4D,CAAC;IAEhE,IAAIP,kBAAkB,CAACJ,iBAAiB;QACtCG,OAAOS,KAAK,CACV,GAAGN,kBAAkB,IAAI,CAAC,GACxB,CAAC,kFAAkF,CAAC,GACpF,CAAC,kGAAkG,CAAC,EACtG;YAACO,MAAM;QAAC;QAEV,qEAAqE;QACrE;IACF;IAEA,MAAMC,SAAS,MAAMb,OAAO;QAC1Bc,SAAS;YACP;gBACEC,MAAM;gBACNC,OAAO;YACT;YACA;gBAACD,MAAM;gBAAgBC,OAAO;YAAQ;SACvC;QACDC,SAAS;QACTC,SAASpB,UAAU,UAAUO;IAC/B;IAEA,IAAIQ,WAAW,UAAU;QACvBX,OAAOS,KAAK,CAAC,mCAAmC;YAACC,MAAM;QAAC;QACxD,qEAAqE;QACrE;IACF;IAEAV,OAAOiB,IAAI,CAAC;AACd"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ux } from '@oclif/core';
|
|
2
|
-
import { tsxWorkerTask } from '@sanity/cli-core';
|
|
2
|
+
import { tsxWorkerTask } from '@sanity/cli-core/tasks';
|
|
3
3
|
import { buildDebug } from './buildDebug.js';
|
|
4
4
|
const hasWarnedAbout = new Set();
|
|
5
5
|
export async function renderDocument(options) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/build/renderDocument.ts"],"sourcesContent":["import {ux} from '@oclif/core'\nimport {tsxWorkerTask} from '@sanity/cli-core'\n\nimport {buildDebug} from './buildDebug.js'\n\ninterface DocumentProps {\n basePath: string\n\n css?: string[]\n entryPath?: string\n title?: string\n}\n\ninterface RenderDocumentOptions {\n studioRootPath: string\n\n autoUpdatesCssUrls?: string[]\n importMap?: {\n imports?: Record<string, string>\n }\n isApp?: boolean\n props?: DocumentProps\n}\n\nconst hasWarnedAbout = new Set<string>()\n\ninterface RenderDocumentWorkerResult {\n type: 'error' | 'result' | 'warning'\n\n html?: string\n message?: string | string[]\n warnKey?: string\n}\n\nexport async function renderDocument(options: RenderDocumentOptions): Promise<string> {\n buildDebug('Starting worker thread for %s', import.meta.url)\n try {\n const msg = await tsxWorkerTask<RenderDocumentWorkerResult>(\n new URL(`renderDocument.worker.js`, import.meta.url),\n {\n name: 'renderDocument',\n rootPath: options.studioRootPath,\n workerData: {...options, shouldWarn: true},\n },\n )\n\n if (msg.type === 'warning') {\n if (msg.warnKey && hasWarnedAbout.has(msg.warnKey)) {\n return ''\n }\n\n if (Array.isArray(msg.message)) {\n for (const warning of msg.message) {\n ux.warn(warning)\n }\n } else if (msg.message) {\n ux.warn(msg.message)\n }\n\n if (msg.warnKey) {\n hasWarnedAbout.add(msg.warnKey)\n }\n return ''\n }\n\n if (msg.type === 'error') {\n buildDebug('Error from worker: %s', msg.message || 'Unknown error')\n throw new Error(\n Array.isArray(msg.message)\n ? msg.message.join('\\n')\n : msg.message || 'Document rendering worker stopped with an unknown error',\n )\n }\n\n if (msg.type === 'result') {\n if (!msg.html) {\n throw new Error('Document rendering worker stopped with an unknown error')\n }\n\n buildDebug('Document HTML rendered, %d bytes', msg.html.length)\n return msg.html\n }\n\n throw new Error('Unknown message type')\n } catch (err) {\n buildDebug('Worker errored: %s', err.message)\n throw err\n }\n}\n"],"names":["ux","tsxWorkerTask","buildDebug","hasWarnedAbout","Set","renderDocument","options","url","msg","URL","name","rootPath","studioRootPath","workerData","shouldWarn","type","warnKey","has","Array","isArray","message","warning","warn","add","Error","join","html","length","err"],"mappings":"AAAA,SAAQA,EAAE,QAAO,cAAa;AAC9B,SAAQC,aAAa,QAAO,
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/build/renderDocument.ts"],"sourcesContent":["import {ux} from '@oclif/core'\nimport {tsxWorkerTask} from '@sanity/cli-core/tasks'\n\nimport {buildDebug} from './buildDebug.js'\n\ninterface DocumentProps {\n basePath: string\n\n css?: string[]\n entryPath?: string\n title?: string\n}\n\ninterface RenderDocumentOptions {\n studioRootPath: string\n\n autoUpdatesCssUrls?: string[]\n importMap?: {\n imports?: Record<string, string>\n }\n isApp?: boolean\n props?: DocumentProps\n}\n\nconst hasWarnedAbout = new Set<string>()\n\ninterface RenderDocumentWorkerResult {\n type: 'error' | 'result' | 'warning'\n\n html?: string\n message?: string | string[]\n warnKey?: string\n}\n\nexport async function renderDocument(options: RenderDocumentOptions): Promise<string> {\n buildDebug('Starting worker thread for %s', import.meta.url)\n try {\n const msg = await tsxWorkerTask<RenderDocumentWorkerResult>(\n new URL(`renderDocument.worker.js`, import.meta.url),\n {\n name: 'renderDocument',\n rootPath: options.studioRootPath,\n workerData: {...options, shouldWarn: true},\n },\n )\n\n if (msg.type === 'warning') {\n if (msg.warnKey && hasWarnedAbout.has(msg.warnKey)) {\n return ''\n }\n\n if (Array.isArray(msg.message)) {\n for (const warning of msg.message) {\n ux.warn(warning)\n }\n } else if (msg.message) {\n ux.warn(msg.message)\n }\n\n if (msg.warnKey) {\n hasWarnedAbout.add(msg.warnKey)\n }\n return ''\n }\n\n if (msg.type === 'error') {\n buildDebug('Error from worker: %s', msg.message || 'Unknown error')\n throw new Error(\n Array.isArray(msg.message)\n ? msg.message.join('\\n')\n : msg.message || 'Document rendering worker stopped with an unknown error',\n )\n }\n\n if (msg.type === 'result') {\n if (!msg.html) {\n throw new Error('Document rendering worker stopped with an unknown error')\n }\n\n buildDebug('Document HTML rendered, %d bytes', msg.html.length)\n return msg.html\n }\n\n throw new Error('Unknown message type')\n } catch (err) {\n buildDebug('Worker errored: %s', err.message)\n throw err\n }\n}\n"],"names":["ux","tsxWorkerTask","buildDebug","hasWarnedAbout","Set","renderDocument","options","url","msg","URL","name","rootPath","studioRootPath","workerData","shouldWarn","type","warnKey","has","Array","isArray","message","warning","warn","add","Error","join","html","length","err"],"mappings":"AAAA,SAAQA,EAAE,QAAO,cAAa;AAC9B,SAAQC,aAAa,QAAO,yBAAwB;AAEpD,SAAQC,UAAU,QAAO,kBAAiB;AAqB1C,MAAMC,iBAAiB,IAAIC;AAU3B,OAAO,eAAeC,eAAeC,OAA8B;IACjEJ,WAAW,iCAAiC,YAAYK,GAAG;IAC3D,IAAI;QACF,MAAMC,MAAM,MAAMP,cAChB,IAAIQ,IAAI,CAAC,wBAAwB,CAAC,EAAE,YAAYF,GAAG,GACnD;YACEG,MAAM;YACNC,UAAUL,QAAQM,cAAc;YAChCC,YAAY;gBAAC,GAAGP,OAAO;gBAAEQ,YAAY;YAAI;QAC3C;QAGF,IAAIN,IAAIO,IAAI,KAAK,WAAW;YAC1B,IAAIP,IAAIQ,OAAO,IAAIb,eAAec,GAAG,CAACT,IAAIQ,OAAO,GAAG;gBAClD,OAAO;YACT;YAEA,IAAIE,MAAMC,OAAO,CAACX,IAAIY,OAAO,GAAG;gBAC9B,KAAK,MAAMC,WAAWb,IAAIY,OAAO,CAAE;oBACjCpB,GAAGsB,IAAI,CAACD;gBACV;YACF,OAAO,IAAIb,IAAIY,OAAO,EAAE;gBACtBpB,GAAGsB,IAAI,CAACd,IAAIY,OAAO;YACrB;YAEA,IAAIZ,IAAIQ,OAAO,EAAE;gBACfb,eAAeoB,GAAG,CAACf,IAAIQ,OAAO;YAChC;YACA,OAAO;QACT;QAEA,IAAIR,IAAIO,IAAI,KAAK,SAAS;YACxBb,WAAW,yBAAyBM,IAAIY,OAAO,IAAI;YACnD,MAAM,IAAII,MACRN,MAAMC,OAAO,CAACX,IAAIY,OAAO,IACrBZ,IAAIY,OAAO,CAACK,IAAI,CAAC,QACjBjB,IAAIY,OAAO,IAAI;QAEvB;QAEA,IAAIZ,IAAIO,IAAI,KAAK,UAAU;YACzB,IAAI,CAACP,IAAIkB,IAAI,EAAE;gBACb,MAAM,IAAIF,MAAM;YAClB;YAEAtB,WAAW,oCAAoCM,IAAIkB,IAAI,CAACC,MAAM;YAC9D,OAAOnB,IAAIkB,IAAI;QACjB;QAEA,MAAM,IAAIF,MAAM;IAClB,EAAE,OAAOI,KAAK;QACZ1B,WAAW,sBAAsB0B,IAAIR,OAAO;QAC5C,MAAMQ;IACR;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
|
-
import { doImport } from '@sanity/cli-core';
|
|
2
|
+
import { doImport } from '@sanity/cli-core/util';
|
|
3
3
|
import { buildDebug } from '../buildDebug.js';
|
|
4
4
|
import { getPossibleDocumentComponentLocations } from '../getPossibleDocumentComponentLocations.js';
|
|
5
5
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/actions/build/renderDocumentWorker/tryLoadDocumentComponent.ts"],"sourcesContent":["import fs from 'node:fs'\n\nimport {doImport} from '@sanity/cli-core'\n\nimport {buildDebug} from '../buildDebug.js'\nimport {getPossibleDocumentComponentLocations} from '../getPossibleDocumentComponentLocations.js'\n\n/**\n * @internal\n */\nexport async function tryLoadDocumentComponent(studioRootPath: string) {\n const locations = getPossibleDocumentComponentLocations(studioRootPath)\n\n for (const componentPath of locations) {\n buildDebug('Trying to load document component from %s', componentPath)\n try {\n const component = await doImport(componentPath)\n\n return {\n component,\n modified: Math.floor(fs.statSync(componentPath)?.mtimeMs),\n path: componentPath,\n }\n } catch (err) {\n // Allow \"not found\" errors\n if (err.code !== 'ERR_MODULE_NOT_FOUND') {\n buildDebug('Failed to load document component: %s', err.message)\n throw err\n }\n\n buildDebug('Document component not found at %s', componentPath)\n }\n }\n\n return null\n}\n"],"names":["fs","doImport","buildDebug","getPossibleDocumentComponentLocations","tryLoadDocumentComponent","studioRootPath","locations","componentPath","component","modified","Math","floor","statSync","mtimeMs","path","err","code","message"],"mappings":"AAAA,OAAOA,QAAQ,UAAS;AAExB,SAAQC,QAAQ,QAAO,
|
|
1
|
+
{"version":3,"sources":["../../../../src/actions/build/renderDocumentWorker/tryLoadDocumentComponent.ts"],"sourcesContent":["import fs from 'node:fs'\n\nimport {doImport} from '@sanity/cli-core/util'\n\nimport {buildDebug} from '../buildDebug.js'\nimport {getPossibleDocumentComponentLocations} from '../getPossibleDocumentComponentLocations.js'\n\n/**\n * @internal\n */\nexport async function tryLoadDocumentComponent(studioRootPath: string) {\n const locations = getPossibleDocumentComponentLocations(studioRootPath)\n\n for (const componentPath of locations) {\n buildDebug('Trying to load document component from %s', componentPath)\n try {\n const component = await doImport(componentPath)\n\n return {\n component,\n modified: Math.floor(fs.statSync(componentPath)?.mtimeMs),\n path: componentPath,\n }\n } catch (err) {\n // Allow \"not found\" errors\n if (err.code !== 'ERR_MODULE_NOT_FOUND') {\n buildDebug('Failed to load document component: %s', err.message)\n throw err\n }\n\n buildDebug('Document component not found at %s', componentPath)\n }\n }\n\n return null\n}\n"],"names":["fs","doImport","buildDebug","getPossibleDocumentComponentLocations","tryLoadDocumentComponent","studioRootPath","locations","componentPath","component","modified","Math","floor","statSync","mtimeMs","path","err","code","message"],"mappings":"AAAA,OAAOA,QAAQ,UAAS;AAExB,SAAQC,QAAQ,QAAO,wBAAuB;AAE9C,SAAQC,UAAU,QAAO,mBAAkB;AAC3C,SAAQC,qCAAqC,QAAO,8CAA6C;AAEjG;;CAEC,GACD,OAAO,eAAeC,yBAAyBC,cAAsB;IACnE,MAAMC,YAAYH,sCAAsCE;IAExD,KAAK,MAAME,iBAAiBD,UAAW;QACrCJ,WAAW,6CAA6CK;QACxD,IAAI;YACF,MAAMC,YAAY,MAAMP,SAASM;YAEjC,OAAO;gBACLC;gBACAC,UAAUC,KAAKC,KAAK,CAACX,GAAGY,QAAQ,CAACL,gBAAgBM;gBACjDC,MAAMP;YACR;QACF,EAAE,OAAOQ,KAAK;YACZ,2BAA2B;YAC3B,IAAIA,IAAIC,IAAI,KAAK,wBAAwB;gBACvCd,WAAW,yCAAyCa,IAAIE,OAAO;gBAC/D,MAAMF;YACR;YAEAb,WAAW,sCAAsCK;QACnD;IACF;IAEA,OAAO;AACT"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import { getLocalPackageDir, getLocalPackageVersion } from '@sanity/cli-core';
|
|
3
|
+
import { getLocalPackageDir, getLocalPackageVersion } from '@sanity/cli-core/package-manager';
|
|
4
4
|
import { gt, minVersion, rcompare, satisfies } from 'semver';
|
|
5
5
|
import { getCjsNamedExports } from './getCjsNamedExports.js';
|
|
6
6
|
// Define the vendor packages and their corresponding versions and entry points
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/build/resolveVendorBuildConfig.ts"],"sourcesContent":["import {readFile} from 'node:fs/promises'\nimport path from 'node:path'\n\nimport {getLocalPackageDir, getLocalPackageVersion} from '@sanity/cli-core'\nimport {gt, minVersion, rcompare, satisfies} from 'semver'\n\nimport {getCjsNamedExports} from './getCjsNamedExports.js'\n\n/**\n * A type representing the imports of vendor packages, defining specific entry\n * points for various versions and subpaths of the packages.\n */\ntype VendorImports = {\n [packageName: string]: {\n [versionRange: string]: {\n [subpath: string]: string\n }\n }\n}\n\n// Define the vendor packages and their corresponding versions and entry points\nconst VENDOR_IMPORTS: VendorImports = {\n react: {\n '^19.2.0': {\n '.': './cjs/react.production.js',\n './compiler-runtime': './cjs/react-compiler-runtime.production.js',\n './jsx-dev-runtime': './cjs/react-jsx-dev-runtime.production.js',\n './jsx-runtime': './cjs/react-jsx-runtime.production.js',\n './package.json': './package.json',\n },\n },\n 'react-dom': {\n '^19.2.0': {\n '.': './cjs/react-dom.production.js',\n './client': './cjs/react-dom-client.production.js',\n './package.json': './package.json',\n './server': './cjs/react-dom-server-legacy.browser.production.js',\n './server.browser': './cjs/react-dom-server-legacy.browser.production.js',\n './static': './cjs/react-dom-server.browser.production.js',\n './static.browser': './cjs/react-dom-server.browser.production.js',\n },\n },\n}\n\nconst STYLED_COMPONENTS_IMPORTS = {\n 'styled-components': {\n '^6.1.0': {\n '.': './dist/styled-components.browser.esm.js',\n './package.json': './package.json',\n },\n },\n}\n\nexport interface VendorBuildConfig {\n /** Rolldown entry name -\\> absolute path to the package entry file. */\n entries: Record<string, string>\n /** Named exports each CommonJS entry must re-expose as ESM, keyed by chunk name. */\n namesByChunkName: Record<string, readonly string[]>\n /** Rolldown entry chunk name -\\> bare import specifier (e.g. `react`, `react-dom/client`). */\n specifiersByChunkName: Record<string, string>\n}\n\ninterface ResolveVendorBuildConfigOptions {\n cwd: string\n isApp: boolean\n}\n\n/**\n * Resolves vendor package entry points and metadata for a combined studio/app build.\n * Does not run a build — callers add `entries` to the main Vite/Rolldown input and\n * derive the import map from emitted vendor chunks after the single `vite.build`.\n *\n * @internal\n */\nexport async function resolveVendorBuildConfig({\n cwd,\n isApp,\n}: ResolveVendorBuildConfigOptions): Promise<VendorBuildConfig> {\n const entries: Record<string, string> = {}\n const namesByChunkName: Record<string, readonly string[]> = {}\n const specifiersByChunkName: Record<string, string> = {}\n\n const vendorImports = isApp ? VENDOR_IMPORTS : {...VENDOR_IMPORTS, ...STYLED_COMPONENTS_IMPORTS}\n\n for (const [packageName, ranges] of Object.entries(vendorImports)) {\n const version = await getLocalPackageVersion(packageName, cwd)\n if (!version) {\n throw new Error(`Could not get version for '${packageName}'`)\n }\n\n const sortedRanges = Object.keys(ranges).toSorted((range1, range2) => {\n const min1 = minVersion(range1)\n const min2 = minVersion(range2)\n\n if (!min1) throw new Error(`Could not parse range '${range1}'`)\n if (!min2) throw new Error(`Could not parse range '${range2}'`)\n\n return rcompare(min1.version, min2.version)\n })\n\n const matchedRange = sortedRanges.find((range) => satisfies(version, range))\n\n if (!matchedRange) {\n const min = minVersion(sortedRanges.at(-1)!)\n if (!min) {\n throw new Error(`Could not find a minimum version for package '${packageName}'`)\n }\n\n if (gt(min.version, version)) {\n throw new Error(`Package '${packageName}' requires at least ${min.version}.`)\n }\n\n throw new Error(`Version '${version}' of package '${packageName}' is not supported yet.`)\n }\n\n const subpaths = ranges[matchedRange]\n const packageDir = getLocalPackageDir(packageName, cwd)\n\n for (const [subpath, relativeEntryPoint] of Object.entries(subpaths)) {\n const specifier = path.posix.join(packageName, subpath)\n const chunkName = path.posix.join(\n packageName,\n path.relative(packageName, specifier) || 'index',\n )\n\n const entryPath = path.join(packageDir, relativeEntryPoint)\n entries[chunkName] = entryPath\n specifiersByChunkName[chunkName] = specifier\n\n if (packageName in VENDOR_IMPORTS && subpath !== './package.json') {\n const source = await readFile(entryPath, 'utf8')\n namesByChunkName[chunkName] = await getCjsNamedExports(source, chunkName)\n }\n }\n }\n\n return {entries, namesByChunkName, specifiersByChunkName}\n}\n"],"names":["readFile","path","getLocalPackageDir","getLocalPackageVersion","gt","minVersion","rcompare","satisfies","getCjsNamedExports","VENDOR_IMPORTS","react","STYLED_COMPONENTS_IMPORTS","resolveVendorBuildConfig","cwd","isApp","entries","namesByChunkName","specifiersByChunkName","vendorImports","packageName","ranges","Object","version","Error","sortedRanges","keys","toSorted","range1","range2","min1","min2","matchedRange","find","range","min","at","subpaths","packageDir","subpath","relativeEntryPoint","specifier","posix","join","chunkName","relative","entryPath","source"],"mappings":"AAAA,SAAQA,QAAQ,QAAO,mBAAkB;AACzC,OAAOC,UAAU,YAAW;AAE5B,SAAQC,kBAAkB,EAAEC,sBAAsB,QAAO,
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/build/resolveVendorBuildConfig.ts"],"sourcesContent":["import {readFile} from 'node:fs/promises'\nimport path from 'node:path'\n\nimport {getLocalPackageDir, getLocalPackageVersion} from '@sanity/cli-core/package-manager'\nimport {gt, minVersion, rcompare, satisfies} from 'semver'\n\nimport {getCjsNamedExports} from './getCjsNamedExports.js'\n\n/**\n * A type representing the imports of vendor packages, defining specific entry\n * points for various versions and subpaths of the packages.\n */\ntype VendorImports = {\n [packageName: string]: {\n [versionRange: string]: {\n [subpath: string]: string\n }\n }\n}\n\n// Define the vendor packages and their corresponding versions and entry points\nconst VENDOR_IMPORTS: VendorImports = {\n react: {\n '^19.2.0': {\n '.': './cjs/react.production.js',\n './compiler-runtime': './cjs/react-compiler-runtime.production.js',\n './jsx-dev-runtime': './cjs/react-jsx-dev-runtime.production.js',\n './jsx-runtime': './cjs/react-jsx-runtime.production.js',\n './package.json': './package.json',\n },\n },\n 'react-dom': {\n '^19.2.0': {\n '.': './cjs/react-dom.production.js',\n './client': './cjs/react-dom-client.production.js',\n './package.json': './package.json',\n './server': './cjs/react-dom-server-legacy.browser.production.js',\n './server.browser': './cjs/react-dom-server-legacy.browser.production.js',\n './static': './cjs/react-dom-server.browser.production.js',\n './static.browser': './cjs/react-dom-server.browser.production.js',\n },\n },\n}\n\nconst STYLED_COMPONENTS_IMPORTS = {\n 'styled-components': {\n '^6.1.0': {\n '.': './dist/styled-components.browser.esm.js',\n './package.json': './package.json',\n },\n },\n}\n\nexport interface VendorBuildConfig {\n /** Rolldown entry name -\\> absolute path to the package entry file. */\n entries: Record<string, string>\n /** Named exports each CommonJS entry must re-expose as ESM, keyed by chunk name. */\n namesByChunkName: Record<string, readonly string[]>\n /** Rolldown entry chunk name -\\> bare import specifier (e.g. `react`, `react-dom/client`). */\n specifiersByChunkName: Record<string, string>\n}\n\ninterface ResolveVendorBuildConfigOptions {\n cwd: string\n isApp: boolean\n}\n\n/**\n * Resolves vendor package entry points and metadata for a combined studio/app build.\n * Does not run a build — callers add `entries` to the main Vite/Rolldown input and\n * derive the import map from emitted vendor chunks after the single `vite.build`.\n *\n * @internal\n */\nexport async function resolveVendorBuildConfig({\n cwd,\n isApp,\n}: ResolveVendorBuildConfigOptions): Promise<VendorBuildConfig> {\n const entries: Record<string, string> = {}\n const namesByChunkName: Record<string, readonly string[]> = {}\n const specifiersByChunkName: Record<string, string> = {}\n\n const vendorImports = isApp ? VENDOR_IMPORTS : {...VENDOR_IMPORTS, ...STYLED_COMPONENTS_IMPORTS}\n\n for (const [packageName, ranges] of Object.entries(vendorImports)) {\n const version = await getLocalPackageVersion(packageName, cwd)\n if (!version) {\n throw new Error(`Could not get version for '${packageName}'`)\n }\n\n const sortedRanges = Object.keys(ranges).toSorted((range1, range2) => {\n const min1 = minVersion(range1)\n const min2 = minVersion(range2)\n\n if (!min1) throw new Error(`Could not parse range '${range1}'`)\n if (!min2) throw new Error(`Could not parse range '${range2}'`)\n\n return rcompare(min1.version, min2.version)\n })\n\n const matchedRange = sortedRanges.find((range) => satisfies(version, range))\n\n if (!matchedRange) {\n const min = minVersion(sortedRanges.at(-1)!)\n if (!min) {\n throw new Error(`Could not find a minimum version for package '${packageName}'`)\n }\n\n if (gt(min.version, version)) {\n throw new Error(`Package '${packageName}' requires at least ${min.version}.`)\n }\n\n throw new Error(`Version '${version}' of package '${packageName}' is not supported yet.`)\n }\n\n const subpaths = ranges[matchedRange]\n const packageDir = getLocalPackageDir(packageName, cwd)\n\n for (const [subpath, relativeEntryPoint] of Object.entries(subpaths)) {\n const specifier = path.posix.join(packageName, subpath)\n const chunkName = path.posix.join(\n packageName,\n path.relative(packageName, specifier) || 'index',\n )\n\n const entryPath = path.join(packageDir, relativeEntryPoint)\n entries[chunkName] = entryPath\n specifiersByChunkName[chunkName] = specifier\n\n if (packageName in VENDOR_IMPORTS && subpath !== './package.json') {\n const source = await readFile(entryPath, 'utf8')\n namesByChunkName[chunkName] = await getCjsNamedExports(source, chunkName)\n }\n }\n }\n\n return {entries, namesByChunkName, specifiersByChunkName}\n}\n"],"names":["readFile","path","getLocalPackageDir","getLocalPackageVersion","gt","minVersion","rcompare","satisfies","getCjsNamedExports","VENDOR_IMPORTS","react","STYLED_COMPONENTS_IMPORTS","resolveVendorBuildConfig","cwd","isApp","entries","namesByChunkName","specifiersByChunkName","vendorImports","packageName","ranges","Object","version","Error","sortedRanges","keys","toSorted","range1","range2","min1","min2","matchedRange","find","range","min","at","subpaths","packageDir","subpath","relativeEntryPoint","specifier","posix","join","chunkName","relative","entryPath","source"],"mappings":"AAAA,SAAQA,QAAQ,QAAO,mBAAkB;AACzC,OAAOC,UAAU,YAAW;AAE5B,SAAQC,kBAAkB,EAAEC,sBAAsB,QAAO,mCAAkC;AAC3F,SAAQC,EAAE,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,SAAS,QAAO,SAAQ;AAE1D,SAAQC,kBAAkB,QAAO,0BAAyB;AAc1D,+EAA+E;AAC/E,MAAMC,iBAAgC;IACpCC,OAAO;QACL,WAAW;YACT,KAAK;YACL,sBAAsB;YACtB,qBAAqB;YACrB,iBAAiB;YACjB,kBAAkB;QACpB;IACF;IACA,aAAa;QACX,WAAW;YACT,KAAK;YACL,YAAY;YACZ,kBAAkB;YAClB,YAAY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If,GAAG8B,IAAIZ,OAAO,EAAEA,UAAU;gBAC5B,MAAM,IAAIC,MAAM,CAAC,SAAS,EAAEJ,YAAY,oBAAoB,EAAEe,IAAIZ,OAAO,CAAC,CAAC,CAAC;YAC9E;YAEA,MAAM,IAAIC,MAAM,CAAC,SAAS,EAAED,QAAQ,cAAc,EAAEH,YAAY,uBAAuB,CAAC;QAC1F;QAEA,MAAMiB,WAAWhB,MAAM,CAACW,aAAa;QACrC,MAAMM,aAAanC,mBAAmBiB,aAAaN;QAEnD,KAAK,MAAM,CAACyB,SAASC,mBAAmB,IAAIlB,OAAON,OAAO,CAACqB,UAAW;YACpE,MAAMI,YAAYvC,KAAKwC,KAAK,CAACC,IAAI,CAACvB,aAAamB;YAC/C,MAAMK,YAAY1C,KAAKwC,KAAK,CAACC,IAAI,CAC/BvB,aACAlB,KAAK2C,QAAQ,CAACzB,aAAaqB,cAAc;YAG3C,MAAMK,YAAY5C,KAAKyC,IAAI,CAACL,YAAYE;YACxCxB,OAAO,CAAC4B,UAAU,GAAGE;YACrB5B,qBAAqB,CAAC0B,UAAU,GAAGH;YAEnC,IAAIrB,eAAeV,kBAAkB6B,YAAY,kBAAkB;gBACjE,MAAMQ,SAAS,MAAM9C,SAAS6C,WAAW;gBACzC7B,gBAAgB,CAAC2B,UAAU,GAAG,MAAMnC,mBAAmBsC,QAAQH;YACjE;QACF;IACF;IAEA,OAAO;QAAC5B;QAASC;QAAkBC;IAAqB;AAC1D"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import {
|
|
3
|
+
import { up as packageUp } from 'empathic/package';
|
|
4
4
|
import { copyDir } from '../../util/copyDir.js';
|
|
5
5
|
import { writeWebManifest } from './writeWebManifest.js';
|
|
6
6
|
/**
|
|
7
7
|
* @internal
|
|
8
8
|
*/ export async function getDefaultFaviconsPath() {
|
|
9
|
-
const sanityCliPkgPath = (
|
|
9
|
+
const sanityCliPkgPath = packageUp({
|
|
10
10
|
cwd: import.meta.dirname
|
|
11
|
-
})
|
|
11
|
+
});
|
|
12
12
|
if (!sanityCliPkgPath) {
|
|
13
13
|
throw new Error('Unable to resolve `@sanity/cli-build` module root');
|
|
14
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/build/writeFavicons.ts"],"sourcesContent":["import fs from 'node:fs/promises'\nimport path from 'node:path'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/build/writeFavicons.ts"],"sourcesContent":["import fs from 'node:fs/promises'\nimport path from 'node:path'\n\nimport {up as packageUp} from 'empathic/package'\n\nimport {copyDir} from '../../util/copyDir.js'\nimport {writeWebManifest} from './writeWebManifest.js'\n\n/**\n * @internal\n */\nexport async function getDefaultFaviconsPath(): Promise<string> {\n const sanityCliPkgPath = packageUp({cwd: import.meta.dirname})\n if (!sanityCliPkgPath) {\n throw new Error('Unable to resolve `@sanity/cli-build` module root')\n }\n\n return path.join(path.dirname(sanityCliPkgPath), 'static', 'favicons')\n}\n\n/**\n * @internal\n */\nexport async function writeFavicons(basePath: string, destDir: string): Promise<void> {\n const faviconsPath = await getDefaultFaviconsPath()\n\n await fs.mkdir(destDir, {recursive: true})\n await copyDir(faviconsPath, destDir, true)\n await writeWebManifest(basePath, destDir)\n\n // Copy the /static/favicon.ico to /favicon.ico as well, because some tools/browsers\n // blindly expects it to be there before requesting the HTML containing the actual path\n await fs.copyFile(path.join(destDir, 'favicon.ico'), path.join(destDir, '..', 'favicon.ico'))\n}\n"],"names":["fs","path","up","packageUp","copyDir","writeWebManifest","getDefaultFaviconsPath","sanityCliPkgPath","cwd","dirname","Error","join","writeFavicons","basePath","destDir","faviconsPath","mkdir","recursive","copyFile"],"mappings":"AAAA,OAAOA,QAAQ,mBAAkB;AACjC,OAAOC,UAAU,YAAW;AAE5B,SAAQC,MAAMC,SAAS,QAAO,mBAAkB;AAEhD,SAAQC,OAAO,QAAO,wBAAuB;AAC7C,SAAQC,gBAAgB,QAAO,wBAAuB;AAEtD;;CAEC,GACD,OAAO,eAAeC;IACpB,MAAMC,mBAAmBJ,UAAU;QAACK,KAAK,YAAYC,OAAO;IAAA;IAC5D,IAAI,CAACF,kBAAkB;QACrB,MAAM,IAAIG,MAAM;IAClB;IAEA,OAAOT,KAAKU,IAAI,CAACV,KAAKQ,OAAO,CAACF,mBAAmB,UAAU;AAC7D;AAEA;;CAEC,GACD,OAAO,eAAeK,cAAcC,QAAgB,EAAEC,OAAe;IACnE,MAAMC,eAAe,MAAMT;IAE3B,MAAMN,GAAGgB,KAAK,CAACF,SAAS;QAACG,WAAW;IAAI;IACxC,MAAMb,QAAQW,cAAcD,SAAS;IACrC,MAAMT,iBAAiBQ,UAAUC;IAEjC,oFAAoF;IACpF,uFAAuF;IACvF,MAAMd,GAAGkB,QAAQ,CAACjB,KAAKU,IAAI,CAACG,SAAS,gBAAgBb,KAAKU,IAAI,CAACG,SAAS,MAAM;AAChF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { mkdir, writeFile } from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import { tryFindStudioConfigPath } from '@sanity/cli-core';
|
|
3
|
+
import { tryFindStudioConfigPath } from '@sanity/cli-core/config';
|
|
4
4
|
import { watch as chokidarWatch } from 'chokidar';
|
|
5
5
|
import { buildDebug } from './buildDebug.js';
|
|
6
6
|
import { decorateIndexWithAutoGeneratedWarning } from './decorateIndexWithAutoGeneratedWarning.js';
|
|
@@ -20,7 +20,7 @@ import { renderDocument } from './renderDocument.js';
|
|
|
20
20
|
const { appTitle, basePath, cwd, entry, isApp, isWorkbenchApp, reactStrictMode, watch } = options;
|
|
21
21
|
const runtimeDir = path.join(cwd, '.sanity', 'runtime');
|
|
22
22
|
buildDebug('Making runtime directory');
|
|
23
|
-
await
|
|
23
|
+
await mkdir(runtimeDir, {
|
|
24
24
|
recursive: true
|
|
25
25
|
});
|
|
26
26
|
async function renderAndWriteDocument() {
|
|
@@ -35,7 +35,7 @@ import { renderDocument } from './renderDocument.js';
|
|
|
35
35
|
studioRootPath: cwd
|
|
36
36
|
}))));
|
|
37
37
|
buildDebug('Writing index.html to runtime directory');
|
|
38
|
-
await
|
|
38
|
+
await writeFile(path.join(runtimeDir, 'index.html'), indexHtml);
|
|
39
39
|
}
|
|
40
40
|
let watcher;
|
|
41
41
|
if (watch) {
|
|
@@ -60,7 +60,7 @@ import { renderDocument } from './renderDocument.js';
|
|
|
60
60
|
reactStrictMode,
|
|
61
61
|
relativeConfigLocation
|
|
62
62
|
});
|
|
63
|
-
await
|
|
63
|
+
await writeFile(path.join(runtimeDir, 'app.js'), appJsContent);
|
|
64
64
|
return {
|
|
65
65
|
entries: {
|
|
66
66
|
relativeConfigLocation,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/build/writeSanityRuntime.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/build/writeSanityRuntime.ts"],"sourcesContent":["import {mkdir, writeFile} from 'node:fs/promises'\nimport path from 'node:path'\n\nimport {tryFindStudioConfigPath} from '@sanity/cli-core/config'\nimport {watch as chokidarWatch, type FSWatcher} from 'chokidar'\n\nimport {buildDebug} from './buildDebug.js'\nimport {decorateIndexWithAutoGeneratedWarning} from './decorateIndexWithAutoGeneratedWarning.js'\nimport {decorateIndexWithBridgeScript} from './decorateIndexWithBridgeScript.js'\nimport {decorateIndexWithStagingScript} from './decorateIndexWithStagingScript.js'\nimport {getEntryModule} from './getEntryModule.js'\nimport {getPossibleDocumentComponentLocations} from './getPossibleDocumentComponentLocations.js'\nimport {renderDocument} from './renderDocument.js'\n\ninterface RuntimeOptions {\n cwd: string\n reactStrictMode: boolean | undefined\n watch: boolean\n\n appTitle?: string\n basePath?: string\n entry?: string\n isApp?: boolean\n isWorkbenchApp?: boolean\n}\n\n/**\n * Generates the `.sanity/runtime` directory, and optionally watches for custom\n * document files, rebuilding when they change\n *\n * @param options - Current working directory (Sanity root dir), and whether or not to watch\n * @returns A watcher instance if watch is enabled, undefined otherwise\n * @internal\n */\nexport async function writeSanityRuntime(options: RuntimeOptions): Promise<{\n entries: {relativeConfigLocation: string | null; relativeEntry: string | null}\n watcher: FSWatcher | undefined\n}> {\n const {appTitle, basePath, cwd, entry, isApp, isWorkbenchApp, reactStrictMode, watch} = options\n const runtimeDir = path.join(cwd, '.sanity', 'runtime')\n\n buildDebug('Making runtime directory')\n await mkdir(runtimeDir, {recursive: true})\n\n async function renderAndWriteDocument() {\n buildDebug('Rendering document template')\n const indexHtml = decorateIndexWithStagingScript(\n decorateIndexWithBridgeScript(\n decorateIndexWithAutoGeneratedWarning(\n await renderDocument({\n isApp,\n props: {\n basePath: basePath || '/',\n entryPath: `/${toForwardSlashes(path.relative(cwd, path.join(runtimeDir, 'app.js')))}`,\n title: appTitle,\n },\n studioRootPath: cwd,\n }),\n ),\n ),\n )\n\n buildDebug('Writing index.html to runtime directory')\n await writeFile(path.join(runtimeDir, 'index.html'), indexHtml)\n }\n\n let watcher: FSWatcher | undefined\n\n if (watch) {\n // Skip the initial scan; the explicit renderAndWriteDocument() below handles first generation.\n watcher = chokidarWatch(getPossibleDocumentComponentLocations(cwd), {ignoreInitial: true}).on(\n 'all',\n () => renderAndWriteDocument(),\n )\n }\n\n await renderAndWriteDocument()\n\n buildDebug('Writing app.js to runtime directory')\n const {relativeConfigLocation, relativeEntry} = await resolveEntries({\n cwd,\n entry,\n isApp,\n isWorkbenchApp,\n runtimeDir,\n })\n const appJsContent = getEntryModule({\n basePath,\n entry: relativeEntry ?? undefined,\n isApp,\n reactStrictMode,\n relativeConfigLocation,\n })\n await writeFile(path.join(runtimeDir, 'app.js'), appJsContent)\n\n return {\n entries: {\n relativeConfigLocation,\n relativeEntry,\n },\n watcher,\n }\n}\n\n/**\n * Resolves the relative entry paths for a Sanity project without writing any\n * runtime files to disk. Used by federation builds that skip the full runtime\n * generation but still need entry metadata for the vite plugin.\n */\nexport async function resolveEntries(options: {\n cwd: string\n entry?: string\n isApp?: boolean\n isWorkbenchApp?: boolean\n runtimeDir?: string\n}): Promise<{relativeConfigLocation: string | null; relativeEntry: string | null}> {\n const {cwd, entry, isApp, isWorkbenchApp} = options\n const runtimeDir = options.runtimeDir ?? path.join(cwd, '.sanity', 'runtime')\n\n let relativeConfigLocation: string | null = null\n if (!isApp) {\n const studioConfigPath = await tryFindStudioConfigPath(cwd)\n relativeConfigLocation = studioConfigPath\n ? toForwardSlashes(path.relative(runtimeDir, studioConfigPath))\n : null\n }\n\n // Only a *branded* app (`unstable_defineApp`) that declares no `entry` has no\n // navigable app view (sanity-io/workbench spec 002-workbench-extension-api,\n // US5): `null` entry tells the runtime/federation to skip the `./App` render\n // path. Non-branded (legacy SDK) apps keep the historical `./src/App` default,\n // and studios ignore `relativeEntry` — so gating on `isApp` here would regress\n // non-opted-in apps to the dock-only stub.\n const relativeEntry =\n isWorkbenchApp && !entry\n ? null\n : toForwardSlashes(path.relative(runtimeDir, path.resolve(cwd, entry || './src/App')))\n\n return {relativeConfigLocation, relativeEntry}\n}\n\nfunction toForwardSlashes(filePath: string): string {\n return filePath.replaceAll('\\\\', '/')\n}\n"],"names":["mkdir","writeFile","path","tryFindStudioConfigPath","watch","chokidarWatch","buildDebug","decorateIndexWithAutoGeneratedWarning","decorateIndexWithBridgeScript","decorateIndexWithStagingScript","getEntryModule","getPossibleDocumentComponentLocations","renderDocument","writeSanityRuntime","options","appTitle","basePath","cwd","entry","isApp","isWorkbenchApp","reactStrictMode","runtimeDir","join","recursive","renderAndWriteDocument","indexHtml","props","entryPath","toForwardSlashes","relative","title","studioRootPath","watcher","ignoreInitial","on","relativeConfigLocation","relativeEntry","resolveEntries","appJsContent","undefined","entries","studioConfigPath","resolve","filePath","replaceAll"],"mappings":"AAAA,SAAQA,KAAK,EAAEC,SAAS,QAAO,mBAAkB;AACjD,OAAOC,UAAU,YAAW;AAE5B,SAAQC,uBAA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MAAMiB,eAAe7B,eAAe;QAClCM;QACAE,OAAOmB,iBAAiBG;QACxBrB;QACAE;QACAe;IACF;IACA,MAAMnC,UAAUC,KAAKqB,IAAI,CAACD,YAAY,WAAWiB;IAEjD,OAAO;QACLE,SAAS;YACPL;YACAC;QACF;QACAJ;IACF;AACF;AAEA;;;;CAIC,GACD,OAAO,eAAeK,eAAexB,OAMpC;IACC,MAAM,EAACG,GAAG,EAAEC,KAAK,EAAEC,KAAK,EAAEC,cAAc,EAAC,GAAGN;IAC5C,MAAMQ,aAAaR,QAAQQ,UAAU,IAAIpB,KAAKqB,IAAI,CAACN,KAAK,WAAW;IAEnE,IAAImB,yBAAwC;IAC5C,IAAI,CAACjB,OAAO;QACV,MAAMuB,mBAAmB,MAAMvC,wBAAwBc;QACvDmB,yBAAyBM,mBACrBb,iBAAiB3B,KAAK4B,QAAQ,CAACR,YAAYoB,qBAC3C;IACN;IAEA,8EAA8E;IAC9E,4EAA4E;IAC5E,6EAA6E;IAC7E,+EAA+E;IAC/E,+EAA+E;IAC/E,2CAA2C;IAC3C,MAAML,gBACJjB,kBAAkB,CAACF,QACf,OACAW,iBAAiB3B,KAAK4B,QAAQ,CAACR,YAAYpB,KAAKyC,OAAO,CAAC1B,KAAKC,SAAS;IAE5E,OAAO;QAACkB;QAAwBC;IAAa;AAC/C;AAEA,SAASR,iBAAiBe,QAAgB;IACxC,OAAOA,SAASC,UAAU,CAAC,MAAM;AACnC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isMainThread, parentPort, workerData } from 'node:worker_threads';
|
|
2
|
-
import { getStudioWorkspaces, getWorkspace } from '@sanity/cli-core';
|
|
2
|
+
import { getStudioWorkspaces, getWorkspace } from '@sanity/cli-core/config';
|
|
3
3
|
import { extractSchema } from '@sanity/schema/_internal';
|
|
4
4
|
import { extractSchemaWorkerData } from './types.js';
|
|
5
5
|
import { extractValidationFromSchemaError } from './utils/extractValidationFromSchemaError.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/schema/extractSanitySchema.worker.ts"],"sourcesContent":["import {isMainThread, parentPort, workerData} from 'node:worker_threads'\n\nimport {getStudioWorkspaces, getWorkspace} from '@sanity/cli-core'\nimport {extractSchema} from '@sanity/schema/_internal'\n\nimport {extractSchemaWorkerData} from './types.js'\nimport {extractValidationFromSchemaError} from './utils/extractValidationFromSchemaError.js'\n\nif (isMainThread || !parentPort) {\n throw new Error('Should only be run in a worker!')\n}\n\nconst {configPath, enforceRequiredFields, workDir, workspaceName} =\n extractSchemaWorkerData.parse(workerData)\n\ntry {\n const workspaces = await getStudioWorkspaces(configPath)\n if (workspaces.length === 0) {\n throw new Error('Failed to resolve configuration')\n }\n\n const workspace = getWorkspace(workspaces, workspaceName)\n const schema = extractSchema(workspace.schema, {\n enforceRequiredFields,\n })\n\n parentPort.postMessage({\n schema,\n type: 'success',\n })\n} catch (error) {\n const validation = await extractValidationFromSchemaError(error, workDir)\n parentPort.postMessage({\n error: error instanceof Error ? error.message : String(error),\n type: 'error',\n validation,\n })\n}\n"],"names":["isMainThread","parentPort","workerData","getStudioWorkspaces","getWorkspace","extractSchema","extractSchemaWorkerData","extractValidationFromSchemaError","Error","configPath","enforceRequiredFields","workDir","workspaceName","parse","workspaces","length","workspace","schema","postMessage","type","error","validation","message","String"],"mappings":"AAAA,SAAQA,YAAY,EAAEC,UAAU,EAAEC,UAAU,QAAO,sBAAqB;AAExE,SAAQC,mBAAmB,EAAEC,YAAY,QAAO,
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/schema/extractSanitySchema.worker.ts"],"sourcesContent":["import {isMainThread, parentPort, workerData} from 'node:worker_threads'\n\nimport {getStudioWorkspaces, getWorkspace} from '@sanity/cli-core/config'\nimport {extractSchema} from '@sanity/schema/_internal'\n\nimport {extractSchemaWorkerData} from './types.js'\nimport {extractValidationFromSchemaError} from './utils/extractValidationFromSchemaError.js'\n\nif (isMainThread || !parentPort) {\n throw new Error('Should only be run in a worker!')\n}\n\nconst {configPath, enforceRequiredFields, workDir, workspaceName} =\n extractSchemaWorkerData.parse(workerData)\n\ntry {\n const workspaces = await getStudioWorkspaces(configPath)\n if (workspaces.length === 0) {\n throw new Error('Failed to resolve configuration')\n }\n\n const workspace = getWorkspace(workspaces, workspaceName)\n const schema = extractSchema(workspace.schema, {\n enforceRequiredFields,\n })\n\n parentPort.postMessage({\n schema,\n type: 'success',\n })\n} catch (error) {\n const validation = await extractValidationFromSchemaError(error, workDir)\n parentPort.postMessage({\n error: error instanceof Error ? error.message : String(error),\n type: 'error',\n validation,\n })\n}\n"],"names":["isMainThread","parentPort","workerData","getStudioWorkspaces","getWorkspace","extractSchema","extractSchemaWorkerData","extractValidationFromSchemaError","Error","configPath","enforceRequiredFields","workDir","workspaceName","parse","workspaces","length","workspace","schema","postMessage","type","error","validation","message","String"],"mappings":"AAAA,SAAQA,YAAY,EAAEC,UAAU,EAAEC,UAAU,QAAO,sBAAqB;AAExE,SAAQC,mBAAmB,EAAEC,YAAY,QAAO,0BAAyB;AACzE,SAAQC,aAAa,QAAO,2BAA0B;AAEtD,SAAQC,uBAAuB,QAAO,aAAY;AAClD,SAAQC,gCAAgC,QAAO,8CAA6C;AAE5F,IAAIP,gBAAgB,CAACC,YAAY;IAC/B,MAAM,IAAIO,MAAM;AAClB;AAEA,MAAM,EAACC,UAAU,EAAEC,qBAAqB,EAAEC,OAAO,EAAEC,aAAa,EAAC,GAC/DN,wBAAwBO,KAAK,CAACX;AAEhC,IAAI;IACF,MAAMY,aAAa,MAAMX,oBAAoBM;IAC7C,IAAIK,WAAWC,MAAM,KAAK,GAAG;QAC3B,MAAM,IAAIP,MAAM;IAClB;IAEA,MAAMQ,YAAYZ,aAAaU,YAAYF;IAC3C,MAAMK,SAASZ,cAAcW,UAAUC,MAAM,EAAE;QAC7CP;IACF;IAEAT,WAAWiB,WAAW,CAAC;QACrBD;QACAE,MAAM;IACR;AACF,EAAE,OAAOC,OAAO;IACd,MAAMC,aAAa,MAAMd,iCAAiCa,OAAOT;IACjEV,WAAWiB,WAAW,CAAC;QACrBE,OAAOA,iBAAiBZ,QAAQY,MAAME,OAAO,GAAGC,OAAOH;QACvDD,MAAM;QACNE;IACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/schema/getExtractOptions.ts"],"sourcesContent":["import {existsSync, statSync} from 'node:fs'\nimport {extname, join, resolve} from 'node:path'\n\nimport {type ProjectRootResult} from '@sanity/cli-core'\n\nexport interface ExtractOptions {\n configPath: string\n enforceRequiredFields: boolean\n format: string\n outputPath: string\n watchPatterns: string[]\n workspace: string | undefined\n}\n\ninterface GetExtractOptions {\n enforceRequiredFields: boolean | undefined\n format: string | undefined\n path: string | undefined\n projectRoot: ProjectRootResult\n watchPatterns: string[] | undefined\n workspace: string | undefined\n}\n\nexport function getExtractOptions(options: GetExtractOptions): ExtractOptions {\n const {\n enforceRequiredFields,\n format,\n path: pathFlag,\n projectRoot,\n watchPatterns,\n workspace,\n } = options\n let outputPath: string\n if (pathFlag) {\n const resolved = resolve(join(projectRoot.directory, pathFlag))\n const isExistingDirectory = existsSync(resolved) && statSync(resolved).isDirectory()\n\n outputPath =\n isExistingDirectory || !extname(resolved) ? join(resolved, 'schema.json') : resolved\n } else {\n outputPath = resolve(join(projectRoot.directory, 'schema.json'))\n }\n\n return {\n configPath: projectRoot.path,\n enforceRequiredFields: enforceRequiredFields ?? false,\n format: format ?? 'groq-type-nodes',\n outputPath,\n watchPatterns: watchPatterns ?? [],\n workspace,\n }\n}\n"],"names":["existsSync","statSync","extname","join","resolve","getExtractOptions","options","enforceRequiredFields","format","path","pathFlag","projectRoot","watchPatterns","workspace","outputPath","resolved","directory","isExistingDirectory","isDirectory","configPath"],"mappings":"AAAA,SAAQA,UAAU,EAAEC,QAAQ,QAAO,UAAS;AAC5C,SAAQC,OAAO,EAAEC,IAAI,EAAEC,OAAO,QAAO,YAAW;AAsBhD,OAAO,SAASC,kBAAkBC,OAA0B;IAC1D,MAAM,EACJC,qBAAqB,EACrBC,MAAM,EACNC,MAAMC,QAAQ,EACdC,WAAW,EACXC,aAAa,EACbC,SAAS,EACV,GAAGP;IACJ,IAAIQ;IACJ,IAAIJ,UAAU;QACZ,MAAMK,WAAWX,QAAQD,KAAKQ,YAAYK,SAAS,EAAEN;QACrD,MAAMO,sBAAsBjB,WAAWe,aAAad,SAASc,UAAUG,WAAW;QAElFJ,aACEG,uBAAuB,CAACf,QAAQa,YAAYZ,KAAKY,UAAU,iBAAiBA;IAChF,OAAO;QACLD,aAAaV,QAAQD,KAAKQ,YAAYK,SAAS,EAAE;IACnD;IAEA,OAAO;QACLG,YAAYR,YAAYF,IAAI;QAC5BF,uBAAuBA,yBAAyB;QAChDC,QAAQA,UAAU;QAClBM;QACAF,eAAeA,iBAAiB,EAAE;QAClCC;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/schema/getExtractOptions.ts"],"sourcesContent":["import {existsSync, statSync} from 'node:fs'\nimport {extname, join, resolve} from 'node:path'\n\nimport {type ProjectRootResult} from '@sanity/cli-core/types'\n\nexport interface ExtractOptions {\n configPath: string\n enforceRequiredFields: boolean\n format: string\n outputPath: string\n watchPatterns: string[]\n workspace: string | undefined\n}\n\ninterface GetExtractOptions {\n enforceRequiredFields: boolean | undefined\n format: string | undefined\n path: string | undefined\n projectRoot: ProjectRootResult\n watchPatterns: string[] | undefined\n workspace: string | undefined\n}\n\nexport function getExtractOptions(options: GetExtractOptions): ExtractOptions {\n const {\n enforceRequiredFields,\n format,\n path: pathFlag,\n projectRoot,\n watchPatterns,\n workspace,\n } = options\n let outputPath: string\n if (pathFlag) {\n const resolved = resolve(join(projectRoot.directory, pathFlag))\n const isExistingDirectory = existsSync(resolved) && statSync(resolved).isDirectory()\n\n outputPath =\n isExistingDirectory || !extname(resolved) ? join(resolved, 'schema.json') : resolved\n } else {\n outputPath = resolve(join(projectRoot.directory, 'schema.json'))\n }\n\n return {\n configPath: projectRoot.path,\n enforceRequiredFields: enforceRequiredFields ?? false,\n format: format ?? 'groq-type-nodes',\n outputPath,\n watchPatterns: watchPatterns ?? [],\n workspace,\n }\n}\n"],"names":["existsSync","statSync","extname","join","resolve","getExtractOptions","options","enforceRequiredFields","format","path","pathFlag","projectRoot","watchPatterns","workspace","outputPath","resolved","directory","isExistingDirectory","isDirectory","configPath"],"mappings":"AAAA,SAAQA,UAAU,EAAEC,QAAQ,QAAO,UAAS;AAC5C,SAAQC,OAAO,EAAEC,IAAI,EAAEC,OAAO,QAAO,YAAW;AAsBhD,OAAO,SAASC,kBAAkBC,OAA0B;IAC1D,MAAM,EACJC,qBAAqB,EACrBC,MAAM,EACNC,MAAMC,QAAQ,EACdC,WAAW,EACXC,aAAa,EACbC,SAAS,EACV,GAAGP;IACJ,IAAIQ;IACJ,IAAIJ,UAAU;QACZ,MAAMK,WAAWX,QAAQD,KAAKQ,YAAYK,SAAS,EAAEN;QACrD,MAAMO,sBAAsBjB,WAAWe,aAAad,SAASc,UAAUG,WAAW;QAElFJ,aACEG,uBAAuB,CAACf,QAAQa,YAAYZ,KAAKY,UAAU,iBAAiBA;IAChF,OAAO;QACLD,aAAaV,QAAQD,KAAKQ,YAAYK,SAAS,EAAE;IACnD;IAEA,OAAO;QACLG,YAAYR,YAAYF,IAAI;QAC5BF,uBAAuBA,yBAAyB;QAChDC,QAAQA,UAAU;QAClBM;QACAF,eAAeA,iBAAiB,EAAE;QAClCC;IACF;AACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { mkdir, writeFile } from 'node:fs/promises';
|
|
2
2
|
import { dirname } from 'node:path';
|
|
3
|
-
import { studioWorkerTask } from '@sanity/cli-core';
|
|
3
|
+
import { studioWorkerTask } from '@sanity/cli-core/tasks';
|
|
4
4
|
import { SchemaExtractionError } from './utils/SchemaExtractionError.js';
|
|
5
5
|
/**
|
|
6
6
|
* Core schema extraction logic.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/schema/runSchemaExtraction.ts"],"sourcesContent":["import {mkdir, writeFile} from 'node:fs/promises'\nimport {dirname} from 'node:path'\n\nimport {studioWorkerTask} from '@sanity/cli-core'\nimport {type extractSchema as extractSchemaInternal} from '@sanity/schema/_internal'\n\nimport {type ExtractOptions} from './getExtractOptions.js'\nimport {type ExtractSchemaWorkerData, type ExtractSchemaWorkerError} from './types.js'\nimport {SchemaExtractionError} from './utils/SchemaExtractionError.js'\n\ninterface ExtractSchemaWorkerResult {\n schema: ReturnType<typeof extractSchemaInternal>\n type: 'success'\n}\n\ntype ExtractSchemaWorkerMessage = ExtractSchemaWorkerError | ExtractSchemaWorkerResult\n\n/**\n * Core schema extraction logic.\n * Performs the extraction via worker and writes to file.\n * Throws SchemaExtractionError on failure.\n */\nexport async function runSchemaExtraction(\n extractOptions: Omit<ExtractOptions, 'watchPatterns'>,\n): Promise<ReturnType<typeof extractSchemaInternal>> {\n const {configPath, enforceRequiredFields, format, outputPath, workspace} = extractOptions\n\n if (format !== 'groq-type-nodes') {\n throw new Error(`Unsupported format: \"${format}\"`)\n }\n\n const workDir = dirname(configPath)\n const outputDir = dirname(outputPath)\n\n const result = await studioWorkerTask<ExtractSchemaWorkerMessage>(\n new URL('extractSanitySchema.worker.js', import.meta.url),\n {\n name: 'extractSanitySchema',\n studioRootPath: workDir,\n workerData: {\n configPath,\n enforceRequiredFields,\n workDir,\n workspaceName: workspace,\n } satisfies ExtractSchemaWorkerData,\n },\n )\n\n if (result.type === 'error') {\n throw new SchemaExtractionError(result.error, result.validation)\n }\n\n const schema = result.schema\n\n // Ensure output directory exists\n await mkdir(outputDir, {recursive: true})\n\n // Write schema to file\n await writeFile(outputPath, `${JSON.stringify(schema, null, 2)}\\n`)\n\n return schema\n}\n"],"names":["mkdir","writeFile","dirname","studioWorkerTask","SchemaExtractionError","runSchemaExtraction","extractOptions","configPath","enforceRequiredFields","format","outputPath","workspace","Error","workDir","outputDir","result","URL","url","name","studioRootPath","workerData","workspaceName","type","error","validation","schema","recursive","JSON","stringify"],"mappings":"AAAA,SAAQA,KAAK,EAAEC,SAAS,QAAO,mBAAkB;AACjD,SAAQC,OAAO,QAAO,YAAW;AAEjC,SAAQC,gBAAgB,QAAO,
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/schema/runSchemaExtraction.ts"],"sourcesContent":["import {mkdir, writeFile} from 'node:fs/promises'\nimport {dirname} from 'node:path'\n\nimport {studioWorkerTask} from '@sanity/cli-core/tasks'\nimport {type extractSchema as extractSchemaInternal} from '@sanity/schema/_internal'\n\nimport {type ExtractOptions} from './getExtractOptions.js'\nimport {type ExtractSchemaWorkerData, type ExtractSchemaWorkerError} from './types.js'\nimport {SchemaExtractionError} from './utils/SchemaExtractionError.js'\n\ninterface ExtractSchemaWorkerResult {\n schema: ReturnType<typeof extractSchemaInternal>\n type: 'success'\n}\n\ntype ExtractSchemaWorkerMessage = ExtractSchemaWorkerError | ExtractSchemaWorkerResult\n\n/**\n * Core schema extraction logic.\n * Performs the extraction via worker and writes to file.\n * Throws SchemaExtractionError on failure.\n */\nexport async function runSchemaExtraction(\n extractOptions: Omit<ExtractOptions, 'watchPatterns'>,\n): Promise<ReturnType<typeof extractSchemaInternal>> {\n const {configPath, enforceRequiredFields, format, outputPath, workspace} = extractOptions\n\n if (format !== 'groq-type-nodes') {\n throw new Error(`Unsupported format: \"${format}\"`)\n }\n\n const workDir = dirname(configPath)\n const outputDir = dirname(outputPath)\n\n const result = await studioWorkerTask<ExtractSchemaWorkerMessage>(\n new URL('extractSanitySchema.worker.js', import.meta.url),\n {\n name: 'extractSanitySchema',\n studioRootPath: workDir,\n workerData: {\n configPath,\n enforceRequiredFields,\n workDir,\n workspaceName: workspace,\n } satisfies ExtractSchemaWorkerData,\n },\n )\n\n if (result.type === 'error') {\n throw new SchemaExtractionError(result.error, result.validation)\n }\n\n const schema = result.schema\n\n // Ensure output directory exists\n await mkdir(outputDir, {recursive: true})\n\n // Write schema to file\n await writeFile(outputPath, `${JSON.stringify(schema, null, 2)}\\n`)\n\n return schema\n}\n"],"names":["mkdir","writeFile","dirname","studioWorkerTask","SchemaExtractionError","runSchemaExtraction","extractOptions","configPath","enforceRequiredFields","format","outputPath","workspace","Error","workDir","outputDir","result","URL","url","name","studioRootPath","workerData","workspaceName","type","error","validation","schema","recursive","JSON","stringify"],"mappings":"AAAA,SAAQA,KAAK,EAAEC,SAAS,QAAO,mBAAkB;AACjD,SAAQC,OAAO,QAAO,YAAW;AAEjC,SAAQC,gBAAgB,QAAO,yBAAwB;AAKvD,SAAQC,qBAAqB,QAAO,mCAAkC;AAStE;;;;CAIC,GACD,OAAO,eAAeC,oBACpBC,cAAqD;IAErD,MAAM,EAACC,UAAU,EAAEC,qBAAqB,EAAEC,MAAM,EAAEC,UAAU,EAAEC,SAAS,EAAC,GAAGL;IAE3E,IAAIG,WAAW,mBAAmB;QAChC,MAAM,IAAIG,MAAM,CAAC,qBAAqB,EAAEH,OAAO,CAAC,CAAC;IACnD;IAEA,MAAMI,UAAUX,QAAQK;IACxB,MAAMO,YAAYZ,QAAQQ;IAE1B,MAAMK,SAAS,MAAMZ,iBACnB,IAAIa,IAAI,iCAAiC,YAAYC,GAAG,GACxD;QACEC,MAAM;QACNC,gBAAgBN;QAChBO,YAAY;YACVb;YACAC;YACAK;YACAQ,eAAeV;QACjB;IACF;IAGF,IAAII,OAAOO,IAAI,KAAK,SAAS;QAC3B,MAAM,IAAIlB,sBAAsBW,OAAOQ,KAAK,EAAER,OAAOS,UAAU;IACjE;IAEA,MAAMC,SAASV,OAAOU,MAAM;IAE5B,iCAAiC;IACjC,MAAMzB,MAAMc,WAAW;QAACY,WAAW;IAAI;IAEvC,uBAAuB;IACvB,MAAMzB,UAAUS,YAAY,GAAGiB,KAAKC,SAAS,CAACH,QAAQ,MAAM,GAAG,EAAE,CAAC;IAElE,OAAOA;AACT"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { resolveLocalPackage } from '@sanity/cli-core';
|
|
1
|
+
import { resolveLocalPackage } from '@sanity/cli-core/package-manager';
|
|
2
2
|
/**
|
|
3
3
|
* Extracts validation problem groups from a SchemaError.
|
|
4
4
|
*/ export async function extractValidationFromSchemaError(error, workDir) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/actions/schema/utils/extractValidationFromSchemaError.ts"],"sourcesContent":["import {resolveLocalPackage} from '@sanity/cli-core'\nimport {type SchemaValidationProblemGroup} from '@sanity/types'\n\n/**\n * Extracts validation problem groups from a SchemaError.\n */\nexport async function extractValidationFromSchemaError(\n error: unknown,\n workDir: string,\n): Promise<SchemaValidationProblemGroup[] | undefined> {\n const {SchemaError} = await resolveLocalPackage<typeof import('sanity')>('sanity', workDir)\n\n if (error instanceof SchemaError) {\n return error.schema._validation\n }\n\n return undefined\n}\n"],"names":["resolveLocalPackage","extractValidationFromSchemaError","error","workDir","SchemaError","schema","_validation","undefined"],"mappings":"AAAA,SAAQA,mBAAmB,QAAO,
|
|
1
|
+
{"version":3,"sources":["../../../../src/actions/schema/utils/extractValidationFromSchemaError.ts"],"sourcesContent":["import {resolveLocalPackage} from '@sanity/cli-core/package-manager'\nimport {type SchemaValidationProblemGroup} from '@sanity/types'\n\n/**\n * Extracts validation problem groups from a SchemaError.\n */\nexport async function extractValidationFromSchemaError(\n error: unknown,\n workDir: string,\n): Promise<SchemaValidationProblemGroup[] | undefined> {\n const {SchemaError} = await resolveLocalPackage<typeof import('sanity')>('sanity', workDir)\n\n if (error instanceof SchemaError) {\n return error.schema._validation\n }\n\n return undefined\n}\n"],"names":["resolveLocalPackage","extractValidationFromSchemaError","error","workDir","SchemaError","schema","_validation","undefined"],"mappings":"AAAA,SAAQA,mBAAmB,QAAO,mCAAkC;AAGpE;;CAEC,GACD,OAAO,eAAeC,iCACpBC,KAAc,EACdC,OAAe;IAEf,MAAM,EAACC,WAAW,EAAC,GAAG,MAAMJ,oBAA6C,UAAUG;IAEnF,IAAID,iBAAiBE,aAAa;QAChC,OAAOF,MAAMG,MAAM,CAACC,WAAW;IACjC;IAEA,OAAOC;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/actions/schema/vite/plugin-schema-extraction.ts"],"sourcesContent":["import path, {isAbsolute} from 'node:path'\n\nimport {type CLITelemetryStore} from '@sanity/cli-core'\nimport {logSymbols} from '@sanity/cli-core/ux'\nimport debounce from 'lodash-es/debounce.js'\nimport mean from 'lodash-es/mean.js'\nimport once from 'lodash-es/once.js'\nimport {type Plugin} from 'vite'\n\nimport {\n SchemaExtractedTrace,\n SchemaExtractionWatchModeTrace,\n} from '../../../telemetry/extractSchema.telemetry.js'\nimport {formatSchemaValidation} from '../formatSchemaValidation.js'\nimport {createSchemaPatternMatcher} from '../matchSchemaPattern.js'\nimport {runSchemaExtraction} from '../runSchemaExtraction.js'\nimport {SchemaExtractionError} from '../utils/SchemaExtractionError.js'\n\n/**\n * Default glob patterns to watch for schema changes.\n * Covers the sanity config file and common schema directory naming conventions.\n */\nconst DEFAULT_SCHEMA_PATTERNS = [\n 'sanity.config.{js,jsx,ts,tsx,mjs}',\n 'schema*/**/*.{js,jsx,ts,tsx,mjs}',\n]\n\n/** Default debounce delay in milliseconds */\nconst DEFAULT_DEBOUNCE_MS = 1000\n\n/**\n * Delay before initial extraction to allow Vite to finish startup\n * and avoid race conditions with module resolution.\n */\nconst INITIAL_EXTRACTION_DELAY_MS = 1000\n\n/**\n * Options for the Sanity schema extraction Vite plugin.\n *\n * @public\n */\ninterface SchemaExtractionPluginOptions {\n /**\n * Name of sanity config file\n * @example sanity.config.ts\n */\n configPath: string\n\n /**\n * Additional glob patterns to watch for schema changes.\n * These are merged with the default patterns.\n * @example `['lib/custom-types/**\\/*.ts', 'shared/schemas/**\\/*.ts']`\n */\n additionalPatterns?: string[]\n\n /**\n * Debounce delay in milliseconds before triggering extraction\n * after a file change. Helps prevent excessive extractions\n * during rapid file saves.\n * @defaultValue 1000\n */\n debounceMs?: number\n\n /**\n * When true, marks all fields as required in the extracted schema\n * unless they are explicitly marked as optional.\n * @defaultValue false\n */\n enforceRequiredFields?: boolean\n\n /**\n * Format of schema export. groq-type-nodes is the only avilable format at the moment\n */\n format?: string\n\n /**\n * Logger for output messages. Must implement `log`, `info`, and `error` methods.\n * @defaultValue `console`\n */\n output?: Pick<Console, 'error' | 'info' | 'log'>\n\n /**\n * Path where the extracted schema JSON will be written.\n * Can be absolute or relative to the working directory.\n * @defaultValue `path.join(workDir, 'schema.json')`\n */\n outputPath?: string\n\n /**\n * Telemetry logger for the Sanity CLI tooling. If no logger is provided no telemetry\n * is sent. Also, no telemetry will be sent if telemetry is disabled in the sanity CLI.\n */\n telemetryLogger?: CLITelemetryStore\n\n /**\n * Working directory containing the Sanity configuration.\n * This should be the root of your Sanity Studio project where\n * `sanity.config.ts` is located.\n * @defaultValue Vite's project root (`config.root`)\n */\n workDir?: string\n\n /**\n * Workspace name for multi-workspace Sanity configurations.\n * Required when your `sanity.config.ts` exports multiple workspaces\n * and you want to extract schema from a specific one.\n */\n workspaceName?: string\n}\n\n/**\n * Creates a Vite plugin that automatically extracts Sanity schema during development and build.\n *\n * **During development:**\n * The plugin performs an initial extraction when the dev server starts, then watches\n * for file changes and re-extracts the schema when relevant files are modified.\n *\n * **During build:**\n * The plugin extracts the schema once at the end of the build process, ensuring\n * the schema is always up-to-date when deploying.\n *\n * **How it works in dev mode:**\n * 1. Registers watch patterns with Vite's built-in file watcher\n * 2. Performs initial schema extraction when the server starts\n * 3. On file changes matching the patterns, triggers a debounced extraction\n * 4. Uses concurrency control to prevent overlapping extractions\n *\n * @param options - Configuration options for the plugin\n * @returns A Vite plugin configured for schema extraction\n *\n * @internal\n */\nexport function sanitySchemaExtractionPlugin(options: SchemaExtractionPluginOptions) {\n const {\n additionalPatterns = [],\n configPath,\n debounceMs = DEFAULT_DEBOUNCE_MS,\n enforceRequiredFields = false,\n format = 'groq-type-nodes',\n output = console,\n outputPath: outputPathOption = 'schema.json',\n telemetryLogger,\n workDir: workDirOption,\n workspaceName,\n } = options\n\n const watchPatterns = [...DEFAULT_SCHEMA_PATTERNS, ...additionalPatterns]\n\n // Resolved after Vite config is available\n let resolvedWorkDir: string\n let resolvedOutputPath: string\n\n // State for concurrency control\n let isExtracting = false\n let pendingExtraction = false\n\n // Stats for telemetry\n const startTime = Date.now()\n const stats: {failedCount: number; successfulDurations: number[]} = {\n failedCount: 0,\n successfulDurations: [],\n }\n\n const extractSchema = () =>\n runSchemaExtraction({\n configPath,\n enforceRequiredFields,\n format,\n outputPath: resolvedOutputPath,\n workspace: workspaceName,\n })\n\n /**\n * Runs extraction with concurrency control.\n * If extraction is already running, queues one more extraction to run after completion.\n */\n async function runExtraction(isBuilding = false): Promise<void> {\n if (isExtracting) {\n pendingExtraction = true\n return\n }\n\n isExtracting = true\n pendingExtraction = false\n\n const extractionStartTime = Date.now()\n try {\n await extractSchema()\n if (isBuilding) {\n // TODO: Remove when we have better control over progress reporting in build\n output.log('')\n }\n output.log(logSymbols.success, `Extracted schema to ${outputPathOption}`)\n\n // add stats for the successful extraction run to use later for telemetry\n stats.successfulDurations.push(Date.now() - extractionStartTime)\n } catch (err) {\n output.error(\n logSymbols.error,\n `Extraction failed: ${err instanceof Error ? err.message : String(err)}`,\n )\n if (err instanceof SchemaExtractionError && err.validation && err.validation.length > 0) {\n output.error(logSymbols.error, formatSchemaValidation(err.validation))\n }\n\n // track the failed extraction\n stats.failedCount++\n } finally {\n isExtracting = false\n\n // If a change came in during extraction, run again\n if (pendingExtraction) {\n pendingExtraction = false\n await runExtraction()\n }\n }\n }\n\n const debouncedExtract = debounce(() => {\n void runExtraction()\n }, debounceMs)\n\n const {isMatch} = createSchemaPatternMatcher(watchPatterns)\n\n const handleChange = (filePath: string) => {\n if (isMatch(filePath, resolvedWorkDir)) {\n debouncedExtract()\n }\n }\n\n return {\n name: 'sanity/schema-extraction',\n\n configResolved(config) {\n // Resolve workDir from option or Vite's project root\n resolvedWorkDir = workDirOption ?? config.root\n\n resolvedOutputPath = isAbsolute(outputPathOption)\n ? outputPathOption\n : path.join(resolvedWorkDir, outputPathOption)\n },\n\n configureServer(server) {\n const trace = telemetryLogger?.trace(SchemaExtractionWatchModeTrace)\n trace?.start()\n\n trace?.log({enforceRequiredFields, schemaFormat: format, step: 'started'})\n\n // Add schema patterns to Vite's watcher\n const absolutePatterns = watchPatterns.map((pattern) => path.join(resolvedWorkDir, pattern))\n server.watcher.add(absolutePatterns)\n\n // Prepare function to log \"stopped\" event to trace and complete the trace\n const onClose = once(() => {\n // Cancel any pending debounced extractions\n debouncedExtract.cancel()\n\n // Log telemetry if available\n if (trace) {\n trace.log({\n averageExtractionDuration: mean(stats.successfulDurations) || 0,\n extractionFailedCount: stats.failedCount,\n extractionSuccessfulCount: stats.successfulDurations.length,\n step: 'stopped',\n watcherDuration: Date.now() - startTime,\n })\n trace.complete()\n }\n\n // Clean up process listeners (must always run, not just when trace exists)\n process.off('SIGTERM', onClose)\n process.off('SIGINT', onClose)\n })\n\n server.watcher.on('change', handleChange)\n server.watcher.on('add', handleChange)\n server.watcher.on('unlink', handleChange)\n\n // call the watcherClosed method when watcher is closed or when process is stopped/killed\n server.watcher.on('close', onClose)\n process.on('SIGTERM', onClose)\n process.on('SIGINT', onClose)\n\n // Run initial extraction after server is ready\n const startExtraction = () => {\n setTimeout(() => {\n // Notify about schema extraction enabled\n output.info(logSymbols.info, 'Schema extraction enabled. Watching:')\n for (const pattern of watchPatterns) {\n output.info(` - ${pattern}`)\n }\n\n // Perform first extraction\n void runExtraction()\n }, INITIAL_EXTRACTION_DELAY_MS)\n }\n\n if (server.httpServer) {\n server.httpServer.once('listening', startExtraction)\n } else {\n // Middleware mode - no HTTP server, run extraction immediately\n startExtraction()\n }\n },\n\n async buildEnd() {\n const trace = telemetryLogger?.trace(SchemaExtractedTrace)\n trace?.start()\n\n try {\n const start = Date.now()\n const schema = await extractSchema()\n output.log(\n logSymbols.success,\n `Extracted schema to ${outputPathOption} (${Date.now() - start}ms)`,\n )\n\n trace?.log({\n enforceRequiredFields,\n schemaAllTypesCount: schema.length,\n schemaDocumentTypesCount: schema.filter((type) => type.type === 'document').length,\n schemaFormat: format,\n schemaTypesCount: schema.filter((type) => type.type === 'type').length,\n })\n } catch (err) {\n trace?.error(err)\n throw err\n } finally {\n trace?.complete()\n }\n },\n } satisfies Plugin\n}\n"],"names":["path","isAbsolute","logSymbols","debounce","mean","once","SchemaExtractedTrace","SchemaExtractionWatchModeTrace","formatSchemaValidation","createSchemaPatternMatcher","runSchemaExtraction","SchemaExtractionError","DEFAULT_SCHEMA_PATTERNS","DEFAULT_DEBOUNCE_MS","INITIAL_EXTRACTION_DELAY_MS","sanitySchemaExtractionPlugin","options","additionalPatterns","configPath","debounceMs","enforceRequiredFields","format","output","console","outputPath","outputPathOption","telemetryLogger","workDir","workDirOption","workspaceName","watchPatterns","resolvedWorkDir","resolvedOutputPath","isExtracting","pendingExtraction","startTime","Date","now","stats","failedCount","successfulDurations","extractSchema","workspace","runExtraction","isBuilding","extractionStartTime","log","success","push","err","error","Error","message","String","validation","length","debouncedExtract","isMatch","handleChange","filePath","name","configResolved","config","root","join","configureServer","server","trace","start","schemaFormat","step","absolutePatterns","map","pattern","watcher","add","onClose","cancel","averageExtractionDuration","extractionFailedCount","extractionSuccessfulCount","watcherDuration","complete","process","off","on","startExtraction","setTimeout","info","httpServer","buildEnd","schema","schemaAllTypesCount","schemaDocumentTypesCount","filter","type","schemaTypesCount"],"mappings":"AAAA,OAAOA,QAAOC,UAAU,QAAO,YAAW;AAG1C,SAAQC,UAAU,QAAO,sBAAqB;AAC9C,OAAOC,cAAc,wBAAuB;AAC5C,OAAOC,UAAU,oBAAmB;AACpC,OAAOC,UAAU,oBAAmB;AAGpC,SACEC,oBAAoB,EACpBC,8BAA8B,QACzB,gDAA+C;AACtD,SAAQC,sBAAsB,QAAO,+BAA8B;AACnE,SAAQC,0BAA0B,QAAO,2BAA0B;AACnE,SAAQC,mBAAmB,QAAO,4BAA2B;AAC7D,SAAQC,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AEtB,iBAAiB,EAAE,EAAEW,KAAKC,GAAG,KAAK+B,MAAM,GAAG,CAAC;gBAGrED,OAAOrB,IAAI;oBACT1B;oBACAwE,qBAAqBD,OAAOpC,MAAM;oBAClCsC,0BAA0BF,OAAOG,MAAM,CAAC,CAACC,OAASA,KAAKA,IAAI,KAAK,YAAYxC,MAAM;oBAClFc,cAAchD;oBACd2E,kBAAkBL,OAAOG,MAAM,CAAC,CAACC,OAASA,KAAKA,IAAI,KAAK,QAAQxC,MAAM;gBACxE;YACF,EAAE,OAAON,KAAK;gBACZkB,OAAOjB,MAAMD;gBACb,MAAMA;YACR,SAAU;gBACRkB,OAAOe;YACT;QACF;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/actions/schema/vite/plugin-schema-extraction.ts"],"sourcesContent":["import path, {isAbsolute} from 'node:path'\n\nimport {type CLITelemetryStore} from '@sanity/cli-core/types'\nimport {logSymbols} from '@sanity/cli-core/ux'\nimport debounce from 'lodash-es/debounce.js'\nimport mean from 'lodash-es/mean.js'\nimport once from 'lodash-es/once.js'\nimport {type Plugin} from 'vite'\n\nimport {\n SchemaExtractedTrace,\n SchemaExtractionWatchModeTrace,\n} from '../../../telemetry/extractSchema.telemetry.js'\nimport {formatSchemaValidation} from '../formatSchemaValidation.js'\nimport {createSchemaPatternMatcher} from '../matchSchemaPattern.js'\nimport {runSchemaExtraction} from '../runSchemaExtraction.js'\nimport {SchemaExtractionError} from '../utils/SchemaExtractionError.js'\n\n/**\n * Default glob patterns to watch for schema changes.\n * Covers the sanity config file and common schema directory naming conventions.\n */\nconst DEFAULT_SCHEMA_PATTERNS = [\n 'sanity.config.{js,jsx,ts,tsx,mjs}',\n 'schema*/**/*.{js,jsx,ts,tsx,mjs}',\n]\n\n/** Default debounce delay in milliseconds */\nconst DEFAULT_DEBOUNCE_MS = 1000\n\n/**\n * Delay before initial extraction to allow Vite to finish startup\n * and avoid race conditions with module resolution.\n */\nconst INITIAL_EXTRACTION_DELAY_MS = 1000\n\n/**\n * Options for the Sanity schema extraction Vite plugin.\n *\n * @public\n */\ninterface SchemaExtractionPluginOptions {\n /**\n * Name of sanity config file\n * @example sanity.config.ts\n */\n configPath: string\n\n /**\n * Additional glob patterns to watch for schema changes.\n * These are merged with the default patterns.\n * @example `['lib/custom-types/**\\/*.ts', 'shared/schemas/**\\/*.ts']`\n */\n additionalPatterns?: string[]\n\n /**\n * Debounce delay in milliseconds before triggering extraction\n * after a file change. Helps prevent excessive extractions\n * during rapid file saves.\n * @defaultValue 1000\n */\n debounceMs?: number\n\n /**\n * When true, marks all fields as required in the extracted schema\n * unless they are explicitly marked as optional.\n * @defaultValue false\n */\n enforceRequiredFields?: boolean\n\n /**\n * Format of schema export. groq-type-nodes is the only avilable format at the moment\n */\n format?: string\n\n /**\n * Logger for output messages. Must implement `log`, `info`, and `error` methods.\n * @defaultValue `console`\n */\n output?: Pick<Console, 'error' | 'info' | 'log'>\n\n /**\n * Path where the extracted schema JSON will be written.\n * Can be absolute or relative to the working directory.\n * @defaultValue `path.join(workDir, 'schema.json')`\n */\n outputPath?: string\n\n /**\n * Telemetry logger for the Sanity CLI tooling. If no logger is provided no telemetry\n * is sent. Also, no telemetry will be sent if telemetry is disabled in the sanity CLI.\n */\n telemetryLogger?: CLITelemetryStore\n\n /**\n * Working directory containing the Sanity configuration.\n * This should be the root of your Sanity Studio project where\n * `sanity.config.ts` is located.\n * @defaultValue Vite's project root (`config.root`)\n */\n workDir?: string\n\n /**\n * Workspace name for multi-workspace Sanity configurations.\n * Required when your `sanity.config.ts` exports multiple workspaces\n * and you want to extract schema from a specific one.\n */\n workspaceName?: string\n}\n\n/**\n * Creates a Vite plugin that automatically extracts Sanity schema during development and build.\n *\n * **During development:**\n * The plugin performs an initial extraction when the dev server starts, then watches\n * for file changes and re-extracts the schema when relevant files are modified.\n *\n * **During build:**\n * The plugin extracts the schema once at the end of the build process, ensuring\n * the schema is always up-to-date when deploying.\n *\n * **How it works in dev mode:**\n * 1. Registers watch patterns with Vite's built-in file watcher\n * 2. Performs initial schema extraction when the server starts\n * 3. On file changes matching the patterns, triggers a debounced extraction\n * 4. Uses concurrency control to prevent overlapping extractions\n *\n * @param options - Configuration options for the plugin\n * @returns A Vite plugin configured for schema extraction\n *\n * @internal\n */\nexport function sanitySchemaExtractionPlugin(options: SchemaExtractionPluginOptions) {\n const {\n additionalPatterns = [],\n configPath,\n debounceMs = DEFAULT_DEBOUNCE_MS,\n enforceRequiredFields = false,\n format = 'groq-type-nodes',\n output = console,\n outputPath: outputPathOption = 'schema.json',\n telemetryLogger,\n workDir: workDirOption,\n workspaceName,\n } = options\n\n const watchPatterns = [...DEFAULT_SCHEMA_PATTERNS, ...additionalPatterns]\n\n // Resolved after Vite config is available\n let resolvedWorkDir: string\n let resolvedOutputPath: string\n\n // State for concurrency control\n let isExtracting = false\n let pendingExtraction = false\n\n // Stats for telemetry\n const startTime = Date.now()\n const stats: {failedCount: number; successfulDurations: number[]} = {\n failedCount: 0,\n successfulDurations: [],\n }\n\n const extractSchema = () =>\n runSchemaExtraction({\n configPath,\n enforceRequiredFields,\n format,\n outputPath: resolvedOutputPath,\n workspace: workspaceName,\n })\n\n /**\n * Runs extraction with concurrency control.\n * If extraction is already running, queues one more extraction to run after completion.\n */\n async function runExtraction(isBuilding = false): Promise<void> {\n if (isExtracting) {\n pendingExtraction = true\n return\n }\n\n isExtracting = true\n pendingExtraction = false\n\n const extractionStartTime = Date.now()\n try {\n await extractSchema()\n if (isBuilding) {\n // TODO: Remove when we have better control over progress reporting in build\n output.log('')\n }\n output.log(logSymbols.success, `Extracted schema to ${outputPathOption}`)\n\n // add stats for the successful extraction run to use later for telemetry\n stats.successfulDurations.push(Date.now() - extractionStartTime)\n } catch (err) {\n output.error(\n logSymbols.error,\n `Extraction failed: ${err instanceof Error ? err.message : String(err)}`,\n )\n if (err instanceof SchemaExtractionError && err.validation && err.validation.length > 0) {\n output.error(logSymbols.error, formatSchemaValidation(err.validation))\n }\n\n // track the failed extraction\n stats.failedCount++\n } finally {\n isExtracting = false\n\n // If a change came in during extraction, run again\n if (pendingExtraction) {\n pendingExtraction = false\n await runExtraction()\n }\n }\n }\n\n const debouncedExtract = debounce(() => {\n void runExtraction()\n }, debounceMs)\n\n const {isMatch} = createSchemaPatternMatcher(watchPatterns)\n\n const handleChange = (filePath: string) => {\n if (isMatch(filePath, resolvedWorkDir)) {\n debouncedExtract()\n }\n }\n\n return {\n name: 'sanity/schema-extraction',\n\n configResolved(config) {\n // Resolve workDir from option or Vite's project root\n resolvedWorkDir = workDirOption ?? config.root\n\n resolvedOutputPath = isAbsolute(outputPathOption)\n ? outputPathOption\n : path.join(resolvedWorkDir, outputPathOption)\n },\n\n configureServer(server) {\n const trace = telemetryLogger?.trace(SchemaExtractionWatchModeTrace)\n trace?.start()\n\n trace?.log({enforceRequiredFields, schemaFormat: format, step: 'started'})\n\n // Add schema patterns to Vite's watcher\n const absolutePatterns = watchPatterns.map((pattern) => path.join(resolvedWorkDir, pattern))\n server.watcher.add(absolutePatterns)\n\n // Prepare function to log \"stopped\" event to trace and complete the trace\n const onClose = once(() => {\n // Cancel any pending debounced extractions\n debouncedExtract.cancel()\n\n // Log telemetry if available\n if (trace) {\n trace.log({\n averageExtractionDuration: mean(stats.successfulDurations) || 0,\n extractionFailedCount: stats.failedCount,\n extractionSuccessfulCount: stats.successfulDurations.length,\n step: 'stopped',\n watcherDuration: Date.now() - startTime,\n })\n trace.complete()\n }\n\n // Clean up process listeners (must always run, not just when trace exists)\n process.off('SIGTERM', onClose)\n process.off('SIGINT', onClose)\n })\n\n server.watcher.on('change', handleChange)\n server.watcher.on('add', handleChange)\n server.watcher.on('unlink', handleChange)\n\n // call the watcherClosed method when watcher is closed or when process is stopped/killed\n server.watcher.on('close', onClose)\n process.on('SIGTERM', onClose)\n process.on('SIGINT', onClose)\n\n // Run initial extraction after server is ready\n const startExtraction = () => {\n setTimeout(() => {\n // Notify about schema extraction enabled\n output.info(logSymbols.info, 'Schema extraction enabled. Watching:')\n for (const pattern of watchPatterns) {\n output.info(` - ${pattern}`)\n }\n\n // Perform first extraction\n void runExtraction()\n }, INITIAL_EXTRACTION_DELAY_MS)\n }\n\n if (server.httpServer) {\n server.httpServer.once('listening', startExtraction)\n } else {\n // Middleware mode - no HTTP server, run extraction immediately\n startExtraction()\n }\n },\n\n async buildEnd() {\n const trace = telemetryLogger?.trace(SchemaExtractedTrace)\n trace?.start()\n\n try {\n const start = Date.now()\n const schema = await extractSchema()\n output.log(\n logSymbols.success,\n `Extracted schema to ${outputPathOption} (${Date.now() - start}ms)`,\n )\n\n trace?.log({\n enforceRequiredFields,\n schemaAllTypesCount: schema.length,\n schemaDocumentTypesCount: schema.filter((type) => type.type === 'document').length,\n schemaFormat: format,\n schemaTypesCount: schema.filter((type) => type.type === 'type').length,\n })\n } catch (err) {\n trace?.error(err)\n throw err\n } finally {\n trace?.complete()\n }\n },\n } satisfies Plugin\n}\n"],"names":["path","isAbsolute","logSymbols","debounce","mean","once","SchemaExtractedTrace","SchemaExtractionWatchModeTrace","formatSchemaValidation","createSchemaPatternMatcher","runSchemaExtraction","SchemaExtractionError","DEFAULT_SCHEMA_PATTERNS","DEFAULT_DEBOUNCE_MS","INITIAL_EXTRACTION_DELAY_MS","sanitySchemaExtractionPlugin","options","additionalPatterns","configPath","debounceMs","enforceRequiredFields","format","output","console","outputPath","outputPathOption","telemetryLogger","workDir","workDirOption","workspaceName","watchPatterns","resolvedWorkDir","resolvedOutputPath","isExtracting","pendingExtraction","startTime","Date","now","stats","failedCount","successfulDurations","extractSchema","workspace","runExtraction","isBuilding","extractionStartTime","log","success","push","err","error","Error","message","String","validation","length","debouncedExtract","isMatch","handleChange","filePath","name","configResolved","config","root","join","configureServer","server","trace","start","schemaFormat","step","absolutePatterns","map","pattern","watcher","add","onClose","cancel","averageExtractionDuration","extractionFailedCount","extractionSuccessfulCount","watcherDuration","complete","process","off","on","startExtraction","setTimeout","info","httpServer","buildEnd","schema","schemaAllTypesCount","schemaDocumentTypes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