@sanity/cli-build 1.0.1 → 1.0.3
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 +1 -1
- package/dist/actions/build/getEntryModule.js +1 -1
- package/dist/actions/build/getEntryModule.js.map +1 -1
- package/dist/actions/build/getViteConfig.js +1 -1
- package/dist/actions/build/getViteConfig.js.map +1 -1
- package/dist/actions/build/writeSanityRuntime.js.map +1 -1
- package/dist/telemetry/extractSchema.telemetry.js +1 -1
- package/dist/telemetry/extractSchema.telemetry.js.map +1 -1
- package/package.json +14 -14
|
@@ -40,7 +40,7 @@ export function getEntryModule(options) {
|
|
|
40
40
|
return appEntryModule.replace(/%ENTRY%/, JSON.stringify(entry || './src/App'));
|
|
41
41
|
}
|
|
42
42
|
const sourceModule = relativeConfigLocation ? entryModule : noConfigEntryModule;
|
|
43
|
-
return sourceModule.replace(/%STUDIO_REACT_STRICT_MODE%/, JSON.stringify(
|
|
43
|
+
return sourceModule.replace(/%STUDIO_REACT_STRICT_MODE%/, reactStrictMode === undefined ? 'undefined' : JSON.stringify(reactStrictMode)).replace(/%STUDIO_CONFIG_LOCATION%/, JSON.stringify(relativeConfigLocation)).replace(/%STUDIO_BASE_PATH%/, JSON.stringify(basePath || '/'));
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
//# sourceMappingURL=getEntryModule.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/build/getEntryModule.ts"],"sourcesContent":["const entryModule = `\n// This file is auto-generated on 'sanity dev'\n// Modifications to this file is automatically discarded\nimport {renderStudio} from \"sanity\"\nimport studioConfig from %STUDIO_CONFIG_LOCATION%\n\nrenderStudio(\n document.getElementById(\"sanity\"),\n studioConfig,\n {reactStrictMode: %STUDIO_REACT_STRICT_MODE%, basePath: %STUDIO_BASE_PATH%}\n)\n`\n\nconst noConfigEntryModule = `\n// This file is auto-generated on 'sanity dev'\n// Modifications to this file is automatically discarded\nimport {renderStudio} from \"sanity\"\n\nconst studioConfig = {missingConfigFile: true}\n\nrenderStudio(\n document.getElementById(\"sanity\"),\n studioConfig,\n {reactStrictMode: %STUDIO_REACT_STRICT_MODE%, basePath: %STUDIO_BASE_PATH%}\n)\n`\n\nconst appEntryModule = `\n// This file is auto-generated on 'sanity dev'\n// Modifications to this file is automatically discarded\nimport {createRoot} from 'react-dom/client'\nimport {createElement} from 'react'\nimport App from %ENTRY%\n\nconst root = createRoot(document.getElementById('root'))\nconst element = createElement(App)\nroot.render(element)\n`\n\nexport function getEntryModule(options: {\n basePath?: string\n entry?: string\n isApp?: boolean\n reactStrictMode: boolean\n relativeConfigLocation: string | null\n}): string {\n const {basePath, entry, isApp, reactStrictMode, relativeConfigLocation} = options\n\n if (isApp) {\n return appEntryModule.replace(/%ENTRY%/, JSON.stringify(entry || './src/App'))\n }\n\n const sourceModule = relativeConfigLocation ? entryModule : noConfigEntryModule\n\n return sourceModule\n .replace(/%STUDIO_REACT_STRICT_MODE
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/build/getEntryModule.ts"],"sourcesContent":["const entryModule = `\n// This file is auto-generated on 'sanity dev'\n// Modifications to this file is automatically discarded\nimport {renderStudio} from \"sanity\"\nimport studioConfig from %STUDIO_CONFIG_LOCATION%\n\nrenderStudio(\n document.getElementById(\"sanity\"),\n studioConfig,\n {reactStrictMode: %STUDIO_REACT_STRICT_MODE%, basePath: %STUDIO_BASE_PATH%}\n)\n`\n\nconst noConfigEntryModule = `\n// This file is auto-generated on 'sanity dev'\n// Modifications to this file is automatically discarded\nimport {renderStudio} from \"sanity\"\n\nconst studioConfig = {missingConfigFile: true}\n\nrenderStudio(\n document.getElementById(\"sanity\"),\n studioConfig,\n {reactStrictMode: %STUDIO_REACT_STRICT_MODE%, basePath: %STUDIO_BASE_PATH%}\n)\n`\n\nconst appEntryModule = `\n// This file is auto-generated on 'sanity dev'\n// Modifications to this file is automatically discarded\nimport {createRoot} from 'react-dom/client'\nimport {createElement} from 'react'\nimport App from %ENTRY%\n\nconst root = createRoot(document.getElementById('root'))\nconst element = createElement(App)\nroot.render(element)\n`\n\nexport function getEntryModule(options: {\n basePath?: string\n entry?: string\n isApp?: boolean\n reactStrictMode: boolean | undefined\n relativeConfigLocation: string | null\n}): string {\n const {basePath, entry, isApp, reactStrictMode, relativeConfigLocation} = options\n\n if (isApp) {\n return appEntryModule.replace(/%ENTRY%/, JSON.stringify(entry || './src/App'))\n }\n\n const sourceModule = relativeConfigLocation ? entryModule : noConfigEntryModule\n\n return sourceModule\n .replace(\n /%STUDIO_REACT_STRICT_MODE%/,\n reactStrictMode === undefined ? 'undefined' : JSON.stringify(reactStrictMode),\n )\n .replace(/%STUDIO_CONFIG_LOCATION%/, JSON.stringify(relativeConfigLocation))\n .replace(/%STUDIO_BASE_PATH%/, JSON.stringify(basePath || '/'))\n}\n"],"names":["entryModule","noConfigEntryModule","appEntryModule","getEntryModule","options","basePath","entry","isApp","reactStrictMode","relativeConfigLocation","replace","JSON","stringify","sourceModule","undefined"],"mappings":"AAAA,MAAMA,cAAc,CAAC;;;;;;;;;;;AAWrB,CAAC;AAED,MAAMC,sBAAsB,CAAC;;;;;;;;;;;;AAY7B,CAAC;AAED,MAAMC,iBAAiB,CAAC;;;;;;;;;;AAUxB,CAAC;AAED,OAAO,SAASC,eAAeC,OAM9B;IACC,MAAM,EAACC,QAAQ,EAAEC,KAAK,EAAEC,KAAK,EAAEC,eAAe,EAAEC,sBAAsB,EAAC,GAAGL;IAE1E,IAAIG,OAAO;QACT,OAAOL,eAAeQ,OAAO,CAAC,WAAWC,KAAKC,SAAS,CAACN,SAAS;IACnE;IAEA,MAAMO,eAAeJ,yBAAyBT,cAAcC;IAE5D,OAAOY,aACJH,OAAO,CACN,8BACAF,oBAAoBM,YAAY,cAAcH,KAAKC,SAAS,CAACJ,kBAE9DE,OAAO,CAAC,4BAA4BC,KAAKC,SAAS,CAACH,yBACnDC,OAAO,CAAC,sBAAsBC,KAAKC,SAAS,CAACP,YAAY;AAC9D"}
|
|
@@ -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 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 Rolldown,\n} from 'vite'\n\nimport {SANITY_CACHE_DIR} from '../../constants.js'\nimport {sanitySchemaExtractionPlugin} from '../schema/vite/plugin-schema-extraction.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 {getDefaultFaviconsPath} from './writeFavicons.js'\n\ninterface ViteOptions {\n /**\n * Root path of the studio/sanity app\n */\n cwd: string\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 * CSS URLs for auto-updated packages (loaded via module server)\n */\n autoUpdatesCssUrls?: string[]\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 importMap?: {imports?: Record<string, string>}\n\n isApp?: 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 * Schema extraction configuration\n */\n schemaExtraction?: CliConfig['schemaExtraction']\n /**\n * HTTP development server configuration\n */\n server?: {host?: string; port?: number}\n /**\n * Whether or not to enable source maps\n */\n sourceMap?: boolean\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 autoUpdatesCssUrls,\n basePath: rawBasePath = '/',\n cwd,\n importMap,\n isApp,\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 } = 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 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 ...viteReact(),\n ...(reactCompiler ? [babel({presets: [reactCompilerPreset(reactCompiler)]})] : []),\n sanityFaviconsPlugin({customFaviconsPath, defaultFaviconsPath, staticUrlPath: staticPath}),\n sanityRuntimeRewritePlugin(),\n sanityBuildEntries({autoUpdatesCssUrls, basePath, cwd, importMap, isApp}),\n // Add schema extraction when enabled\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 ...(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 // Only enable strict port for studio,\n // since apps can run on any port\n strictPort: isApp ? false : true,\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 if (mode === 'production') {\n // For auto-updating studios the import map externalizes react/react-dom/etc.\n // Hand those externals to `esmExternalRequirePlugin` rather than\n // `rolldownOptions.external`, so any bundled CommonJS `require()` of an external\n // is rewritten to an ESM import instead of a runtime `require` shim that throws\n // in the browser. The plugin both marks them external AND converts the requires;\n // also setting `rolldownOptions.external` would short-circuit that conversion.\n // With no import map (auto-updates off) the external list is empty and this is a\n // no-op (everything is bundled, so requires resolve internally).\n viteConfig.plugins!.push(\n esmExternalRequirePlugin({external: createExternalFromImportMap(importMap)}),\n )\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 },\n onwarn: onRolldownWarn,\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 * Ensure Sanity entry chunk is always loaded\n *\n * @param config - User-modified configuration\n * @returns Merged configuration\n * @internal\n */\nexport async function finalizeViteConfig(config: InlineConfig): 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: {\n input: {\n sanity: path.join(config.root, '.sanity', 'runtime', 'app.js'),\n },\n },\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","viteReact","reactCompilerPreset","debug","esmExternalRequirePlugin","mergeConfig","SANITY_CACHE_DIR","sanitySchemaExtractionPlugin","createExternalFromImportMap","normalizeBasePath","sanityBuildEntries","sanityFaviconsPlugin","sanityRuntimeRewritePlugin","getDefaultFaviconsPath","getViteConfig","options","additionalPlugins","autoUpdatesCssUrls","basePath","rawBasePath","cwd","importMap","isApp","minify","mode","outputDir","reactCompiler","schemaExtraction","server","sourceMap","configPath","customFaviconsPath","join","defaultFaviconsPath","staticPath","envVars","getEnvironmentVariables","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","presets","staticUrlPath","enabled","additionalPatterns","watchPatterns","enforceRequiredFields","outputPath","telemetryLogger","workDir","workspaceName","workspace","dedupe","tsconfigPaths","root","host","port","strictPort","warmup","clientFiles","push","external","assetsDir","emptyOutDir","rolldownOptions","input","sanity","onwarn","onRolldownWarn","warning","warn","suppressUnusedImport","code","names","includes","filter","n","length","ids","every","id","finalizeViteConfig","config","TypeError","Error","extendViteConfigWithUserConfig","defaultConfig","userConfig"],"mappings":"AAAA,OAAOA,UAAU,YAAW;AAE5B,OAAOC,WAAW,yBAAwB;AAC1C,SAEEC,eAAe,EACfC,eAAe,QAEV,mBAAkB;AACzB,OAAOC,aAAYC,mBAAmB,QAAO,uBAAsB;AAEnE,OAAOC,WAAW,QAAO;AACzB,SAEEC,wBAAwB,EAExBC,WAAW,QAGN,OAAM;AAEb,SAAQC,gBAAgB,QAAO,qBAAoB;AACnD,SAAQC,4BAA4B,QAAO,6CAA4C;AACvF,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,sBAAsB,QAAO,qBAAoB;AA+DzD;;;;CAIC,GACD,OAAO,eAAeC,cAAcC,OAAoB;IACtD,MAAM,EACJC,iBAAiB,EACjBC,kBAAkB,EAClBC,UAAUC,cAAc,GAAG,EAC3BC,GAAG,EACHC,SAAS,EACTC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,SAAS,EACTC,aAAa,EACbC,gBAAgB,EAChBC,MAAM,EACN,4CAA4C;IAC5CC,YAAYd,QAAQS,IAAI,KAAK,aAAa,EAC3C,GAAGT;IAEJ,MAAMG,WAAWT,kBAAkBU;IAEnC,MAAMW,aAAa,AAAC,CAAA,MAAM/B,gBAAgBqB,IAAG,EAAGvB,IAAI;IAEpD,MAAMkC,qBAAqBlC,KAAKmC,IAAI,CAACZ,KAAK;IAC1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zC;IAEA,mFAAmF;IACnF,IAAIR,QAAQS,GAAG,EAAEC,MAAM,CAACC,KAAOA,GAAGN,QAAQ,CAAC,qBAAqBM,GAAGN,QAAQ,CAAC,sBAC1E,OAAO;IAET,OAAO;AACT;AAEA;;;;;;CAMC,GACD,OAAO,eAAeO,mBAAmBC,MAAoB;IAC3D,IAAI,OAAOA,OAAO7D,KAAK,EAAE2C,iBAAiBC,UAAU,UAAU;QAC5D,MAAM,IAAIkB,UACR;IAEJ;IAEA,IAAI,CAACD,OAAO5B,IAAI,EAAE;QAChB,MAAM,IAAI8B,MACR;IAEJ;IAEA,OAAOjG,YAAY+F,QAAQ;QACzB7D,OAAO;YACL2C,iBAAiB;gBACfC,OAAO;oBACLC,QAAQvF,KAAKmC,IAAI,CAACoE,OAAO5B,IAAI,EAAE,WAAW,WAAW;gBACvD;YACF;QACF;IACF;AACF;AAEA;;;;;;;CAOC,GACD,OAAO,eAAe+B,+BACpBlD,GAAc,EACdmD,aAA2B,EAC3BC,UAA0B;IAE1B,IAAIL,SAASI;IAEb,IAAI,OAAOC,eAAe,YAAY;QACpCtG,MAAM;QACNiG,SAAS,MAAMK,WAAWL,QAAQ/C;IACpC,OAAO,IAAI,OAAOoD,eAAe,UAAU;QACzCtG,MAAM;QACNiG,SAAS/F,YAAY+F,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 {\n type CliConfig,\n findProjectRoot,\n getCliTelemetry,\n type UserViteConfig,\n} from '@sanity/cli-core'\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 Rolldown,\n} from 'vite'\n\nimport {SANITY_CACHE_DIR} from '../../constants.js'\nimport {sanitySchemaExtractionPlugin} from '../schema/vite/plugin-schema-extraction.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 {getDefaultFaviconsPath} from './writeFavicons.js'\n\ninterface ViteOptions {\n /**\n * Root path of the studio/sanity app\n */\n cwd: string\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 * CSS URLs for auto-updated packages (loaded via module server)\n */\n autoUpdatesCssUrls?: string[]\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 importMap?: {imports?: Record<string, string>}\n\n isApp?: 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 * Schema extraction configuration\n */\n schemaExtraction?: CliConfig['schemaExtraction']\n /**\n * HTTP development server configuration\n */\n server?: {host?: string; port?: number}\n /**\n * Whether or not to enable source maps\n */\n sourceMap?: boolean\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 autoUpdatesCssUrls,\n basePath: rawBasePath = '/',\n cwd,\n importMap,\n isApp,\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 } = 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 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 viteReact(),\n ...(reactCompiler ? [babel({presets: [reactCompilerPreset(reactCompiler)]})] : []),\n sanityFaviconsPlugin({customFaviconsPath, defaultFaviconsPath, staticUrlPath: staticPath}),\n sanityRuntimeRewritePlugin(),\n sanityBuildEntries({autoUpdatesCssUrls, basePath, cwd, importMap, isApp}),\n // Add schema extraction when enabled\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 ...(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 // Only enable strict port for studio,\n // since apps can run on any port\n strictPort: isApp ? false : true,\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 if (mode === 'production') {\n // For auto-updating studios the import map externalizes react/react-dom/etc.\n // Hand those externals to `esmExternalRequirePlugin` rather than\n // `rolldownOptions.external`, so any bundled CommonJS `require()` of an external\n // is rewritten to an ESM import instead of a runtime `require` shim that throws\n // in the browser. The plugin both marks them external AND converts the requires;\n // also setting `rolldownOptions.external` would short-circuit that conversion.\n // With no import map (auto-updates off) the external list is empty and this is a\n // no-op (everything is bundled, so requires resolve internally).\n viteConfig.plugins!.push(\n esmExternalRequirePlugin({external: createExternalFromImportMap(importMap)}),\n )\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 },\n onwarn: onRolldownWarn,\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 * Ensure Sanity entry chunk is always loaded\n *\n * @param config - User-modified configuration\n * @returns Merged configuration\n * @internal\n */\nexport async function finalizeViteConfig(config: InlineConfig): 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: {\n input: {\n sanity: path.join(config.root, '.sanity', 'runtime', 'app.js'),\n },\n },\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","viteReact","reactCompilerPreset","debug","esmExternalRequirePlugin","mergeConfig","SANITY_CACHE_DIR","sanitySchemaExtractionPlugin","createExternalFromImportMap","normalizeBasePath","sanityBuildEntries","sanityFaviconsPlugin","sanityRuntimeRewritePlugin","getDefaultFaviconsPath","getViteConfig","options","additionalPlugins","autoUpdatesCssUrls","basePath","rawBasePath","cwd","importMap","isApp","minify","mode","outputDir","reactCompiler","schemaExtraction","server","sourceMap","configPath","customFaviconsPath","join","defaultFaviconsPath","staticPath","envVars","getEnvironmentVariables","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","presets","staticUrlPath","enabled","additionalPatterns","watchPatterns","enforceRequiredFields","outputPath","telemetryLogger","workDir","workspaceName","workspace","dedupe","tsconfigPaths","root","host","port","strictPort","warmup","clientFiles","push","external","assetsDir","emptyOutDir","rolldownOptions","input","sanity","onwarn","onRolldownWarn","warning","warn","suppressUnusedImport","code","names","includes","filter","n","length","ids","every","id","finalizeViteConfig","config","TypeError","Error","extendViteConfigWithUserConfig","defaultConfig","userConfig"],"mappings":"AAAA,OAAOA,UAAU,YAAW;AAE5B,OAAOC,WAAW,yBAAwB;AAC1C,SAEEC,eAAe,EACfC,eAAe,QAEV,mBAAkB;AACzB,OAAOC,aAAYC,mBAAmB,QAAO,uBAAsB;AAEnE,OAAOC,WAAW,QAAO;AACzB,SAEEC,wBAAwB,E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,QAAQvF,KAAKmC,IAAI,CAACoE,OAAO5B,IAAI,EAAE,WAAW,WAAW;gBACvD;YACF;QACF;IACF;AACF;AAEA;;;;;;;CAOC,GACD,OAAO,eAAe+B,+BACpBlD,GAAc,EACdmD,aAA2B,EAC3BC,UAA0B;IAE1B,IAAIL,SAASI;IAEb,IAAI,OAAOC,eAAe,YAAY;QACpCtG,MAAM;QACNiG,SAAS,MAAMK,WAAWL,QAAQ/C;IACpC,OAAO,IAAI,OAAOoD,eAAe,UAAU;QACzCtG,MAAM;QACNiG,SAAS/F,YAAY+F,QAAQK;IAC/B;IAEA,OAAOL;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/build/writeSanityRuntime.ts"],"sourcesContent":["import fs from 'node:fs/promises'\nimport path from 'node:path'\n\nimport {tryFindStudioConfigPath} from '@sanity/cli-core'\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\n watch: boolean\n\n appTitle?: string\n basePath?: string\n entry?: string\n isApp?: 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<FSWatcher | undefined> {\n const {appTitle, basePath, cwd, entry, isApp, reactStrictMode, watch} = options\n const runtimeDir = path.join(cwd, '.sanity', 'runtime')\n\n buildDebug('Making runtime directory')\n await fs.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 fs.writeFile(path.join(runtimeDir, 'index.html'), indexHtml)\n }\n\n let watcher: FSWatcher | undefined\n\n if (watch) {\n watcher = chokidarWatch(getPossibleDocumentComponentLocations(cwd)).on('all', () =>\n renderAndWriteDocument(),\n )\n }\n\n await renderAndWriteDocument()\n\n buildDebug('Writing app.js to runtime directory')\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 const relativeEntry = toForwardSlashes(\n path.relative(runtimeDir, path.resolve(cwd, entry || './src/App')),\n )\n const appJsContent = getEntryModule({\n basePath,\n entry: relativeEntry,\n isApp,\n reactStrictMode,\n relativeConfigLocation,\n })\n await fs.writeFile(path.join(runtimeDir, 'app.js'), appJsContent)\n\n return watcher\n}\n\nfunction toForwardSlashes(filePath: string): string {\n return filePath.replaceAll('\\\\', '/')\n}\n"],"names":["fs","path","tryFindStudioConfigPath","watch","chokidarWatch","buildDebug","decorateIndexWithAutoGeneratedWarning","decorateIndexWithBridgeScript","decorateIndexWithStagingScript","getEntryModule","getPossibleDocumentComponentLocations","renderDocument","writeSanityRuntime","options","appTitle","basePath","cwd","entry","isApp","reactStrictMode","runtimeDir","join","mkdir","recursive","renderAndWriteDocument","indexHtml","props","entryPath","toForwardSlashes","relative","title","studioRootPath","writeFile","watcher","on","rel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AAW;IACX,IAAI8B,yBAAwC;IAC5C,IAAI,CAACjB,OAAO;QACV,MAAMkB,mBAAmB,MAAMlC,wBAAwBc;QACvDmB,yBAAyBC,mBACrBR,iBAAiB3B,KAAK4B,QAAQ,CAACT,YAAYgB,qBAC3C;IACN;IAEA,MAAMC,gBAAgBT,iBACpB3B,KAAK4B,QAAQ,CAACT,YAAYnB,KAAKqC,OAAO,CAACtB,KAAKC,SAAS;IAEvD,MAAMsB,eAAe9B,eAAe;QAClCM;QACAE,OAAOoB;QACPnB;QACAC;QACAgB;IACF;IACA,MAAMnC,GAAGgC,SAAS,CAAC/B,KAAKoB,IAAI,CAACD,YAAY,WAAWmB;IAEpD,OAAON;AACT;AAEA,SAASL,iBAAiBY,QAAgB;IACxC,OAAOA,SAASC,UAAU,CAAC,MAAM;AACnC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/build/writeSanityRuntime.ts"],"sourcesContent":["import fs from 'node:fs/promises'\nimport path from 'node:path'\n\nimport {tryFindStudioConfigPath} from '@sanity/cli-core'\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}\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<FSWatcher | undefined> {\n const {appTitle, basePath, cwd, entry, isApp, reactStrictMode, watch} = options\n const runtimeDir = path.join(cwd, '.sanity', 'runtime')\n\n buildDebug('Making runtime directory')\n await fs.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 fs.writeFile(path.join(runtimeDir, 'index.html'), indexHtml)\n }\n\n let watcher: FSWatcher | undefined\n\n if (watch) {\n watcher = chokidarWatch(getPossibleDocumentComponentLocations(cwd)).on('all', () =>\n renderAndWriteDocument(),\n )\n }\n\n await renderAndWriteDocument()\n\n buildDebug('Writing app.js to runtime directory')\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 const relativeEntry = toForwardSlashes(\n path.relative(runtimeDir, path.resolve(cwd, entry || './src/App')),\n )\n const appJsContent = getEntryModule({\n basePath,\n entry: relativeEntry,\n isApp,\n reactStrictMode,\n relativeConfigLocation,\n })\n await fs.writeFile(path.join(runtimeDir, 'app.js'), appJsContent)\n\n return watcher\n}\n\nfunction toForwardSlashes(filePath: string): string {\n return filePath.replaceAll('\\\\', '/')\n}\n"],"names":["fs","path","tryFindStudioConfigPath","watch","chokidarWatch","buildDebug","decorateIndexWithAutoGeneratedWarning","decorateIndexWithBridgeScript","decorateIndexWithStagingScript","getEntryModule","getPossibleDocumentComponentLocations","renderDocument","writeSanityRuntime","options","appTitle","basePath","cwd","entry","isApp","reactStrictMode","runtimeDir","join","mkdir","recursive","renderAndWriteDocument","indexHtml","props","entryPath","toForwardSlashes","relative","title","studioRootPath","writeFile","watcher","on","relativeConfigLocation","studioConfigPath","relativeEntry","resolve","appJsContent","filePath","replaceAll"],"mappings":"AAAA,OAAOA,QAAQ,mBAAkB;AACjC,OAAOC,UAAU,YAAW;AAE5B,SAAQC,uBAAuB,QAAO,mBAAkB;AACxD,SAAQC,SAASC,aAAa,QAAuB,WAAU;AAE/D,SAAQC,UAAU,QAAO,kBAAiB;AAC1C,SAAQC,qCAAqC,QAAO,6CAA4C;AAChG,SAAQC,6BAA6B,QAAO,qCAAoC;AAChF,SAAQC,8BAA8B,QAAO,sCAAqC;AAClF,SAAQC,cAAc,QAAO,sBAAqB;AAClD,SAAQC,qCAAqC,QAAO,6CAA4C;AAChG,SAAQC,cAAc,QAAO,sBAAqB;AAalD;;;;;;;CAOC,GACD,OAAO,eAAeC,mBAAmBC,OAAuB;IAC9D,MAAM,EAACC,QAAQ,EAAEC,QAAQ,EAAEC,GAAG,EAAEC,KAAK,EAAEC,KAAK,EAAEC,eAAe,EAAEhB,KAAK,EAAC,GAAGU;IACxE,MAAMO,aAAanB,KAAKoB,IAAI,CAACL,KAAK,WAAW;IAE7CX,WAAW;IACX,MAAML,GAAGsB,KAAK,CAACF,YAAY;QAACG,WAAW;IAAI;IAE3C,eAAeC;QACbnB,WAAW;QACX,MAAMoB,YAAYjB,+BAChBD,8BACED,sCACE,MAAMK,eAAe;YACnBO;YACAQ,OAAO;gBACLX,UAAUA,YAAY;gBACtBY,WAAW,CAAC,CAAC,EAAEC,iBAAiB3B,KAAK4B,QAAQ,CAACb,KAAKf,KAAKoB,IAAI,CAACD,YAAY,aAAa;gBACtFU,OAAOhB;YACT;YACAiB,gBAAgBf;QAClB;QAKNX,WAAW;QACX,MAAML,GAAGgC,SAAS,CAAC/B,KAAKoB,IAAI,CAACD,YAAY,eAAeK;IAC1D;IAEA,IAAIQ;IAEJ,IAAI9B,OAAO;QACT8B,UAAU7B,cAAcM,sCAAsCM,MAAMkB,EAAE,CAAC,OAAO,IAC5EV;IAEJ;IAEA,MAAMA;IAENnB,WAAW;IACX,IAAI8B,yBAAwC;IAC5C,IAAI,CAACjB,OAAO;QACV,MAAMkB,mBAAmB,MAAMlC,wBAAwBc;QACvDmB,yBAAyBC,mBACrBR,iBAAiB3B,KAAK4B,QAAQ,CAACT,YAAYgB,qBAC3C;IACN;IAEA,MAAMC,gBAAgBT,iBACpB3B,KAAK4B,QAAQ,CAACT,YAAYnB,KAAKqC,OAAO,CAACtB,KAAKC,SAAS;IAEvD,MAAMsB,eAAe9B,eAAe;QAClCM;QACAE,OAAOoB;QACPnB;QACAC;QACAgB;IACF;IACA,MAAMnC,GAAGgC,SAAS,CAAC/B,KAAKoB,IAAI,CAACD,YAAY,WAAWmB;IAEpD,OAAON;AACT;AAEA,SAASL,iBAAiBY,QAAgB;IACxC,OAAOA,SAASC,UAAU,CAAC,MAAM;AACnC"}
|
|
@@ -11,7 +11,7 @@ export const SchemaExtractionWatchModeTrace = defineTrace({
|
|
|
11
11
|
});
|
|
12
12
|
export const SchemaDeploy = defineTrace({
|
|
13
13
|
description: 'Schema deploy action was executed, either via sanity schema deploy or as sanity deploy',
|
|
14
|
-
name: 'Schema
|
|
14
|
+
name: 'Schema Deployed',
|
|
15
15
|
version: 1
|
|
16
16
|
});
|
|
17
17
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/telemetry/extractSchema.telemetry.ts"],"sourcesContent":["import {defineTrace} from '@sanity/telemetry'\n\ninterface SchemaExtractedTraceAttributes {\n enforceRequiredFields: boolean\n schemaAllTypesCount: number\n schemaDocumentTypesCount: number\n\n schemaFormat: string\n schemaTypesCount: number\n}\n\ntype SchemaExtractionWatchModeAttributes =\n | {\n averageExtractionDuration: number\n extractionFailedCount: number\n extractionSuccessfulCount: number\n step: 'stopped'\n watcherDuration: number\n }\n | {\n enforceRequiredFields: boolean\n schemaFormat: string\n step: 'started'\n }\n\ninterface SchemaDeployTraceData {\n manifestDir: string\n schemaRequired: boolean\n\n extractManifest?: boolean\n}\n\nexport const SchemaExtractedTrace = defineTrace<SchemaExtractedTraceAttributes>({\n description: 'Trace emitted when extracting schema',\n name: 'Schema Extracted',\n version: 0,\n})\n\nexport const SchemaExtractionWatchModeTrace = defineTrace<SchemaExtractionWatchModeAttributes>({\n description: 'Trace emitted when schema extraction watch mode is run',\n name: 'Schema Extraction Watch Mode',\n version: 0,\n})\n\nexport const SchemaDeploy = defineTrace<SchemaDeployTraceData>({\n description:\n 'Schema deploy action was executed, either via sanity schema deploy or as sanity deploy',\n name: 'Schema
|
|
1
|
+
{"version":3,"sources":["../../src/telemetry/extractSchema.telemetry.ts"],"sourcesContent":["import {defineTrace} from '@sanity/telemetry'\n\ninterface SchemaExtractedTraceAttributes {\n enforceRequiredFields: boolean\n schemaAllTypesCount: number\n schemaDocumentTypesCount: number\n\n schemaFormat: string\n schemaTypesCount: number\n}\n\ntype SchemaExtractionWatchModeAttributes =\n | {\n averageExtractionDuration: number\n extractionFailedCount: number\n extractionSuccessfulCount: number\n step: 'stopped'\n watcherDuration: number\n }\n | {\n enforceRequiredFields: boolean\n schemaFormat: string\n step: 'started'\n }\n\ninterface SchemaDeployTraceData {\n manifestDir: string\n schemaRequired: boolean\n\n extractManifest?: boolean\n}\n\nexport const SchemaExtractedTrace = defineTrace<SchemaExtractedTraceAttributes>({\n description: 'Trace emitted when extracting schema',\n name: 'Schema Extracted',\n version: 0,\n})\n\nexport const SchemaExtractionWatchModeTrace = defineTrace<SchemaExtractionWatchModeAttributes>({\n description: 'Trace emitted when schema extraction watch mode is run',\n name: 'Schema Extraction Watch Mode',\n version: 0,\n})\n\nexport const SchemaDeploy = defineTrace<SchemaDeployTraceData>({\n description:\n 'Schema deploy action was executed, either via sanity schema deploy or as sanity deploy',\n name: 'Schema Deployed',\n version: 1,\n})\n"],"names":["defineTrace","SchemaExtractedTrace","description","name","version","SchemaExtractionWatchModeTrace","SchemaDeploy"],"mappings":"AAAA,SAAQA,WAAW,QAAO,oBAAmB;AAgC7C,OAAO,MAAMC,uBAAuBD,YAA4C;IAC9EE,aAAa;IACbC,MAAM;IACNC,SAAS;AACX,GAAE;AAEF,OAAO,MAAMC,iCAAiCL,YAAiD;IAC7FE,aAAa;IACbC,MAAM;IACNC,SAAS;AACX,GAAE;AAEF,OAAO,MAAME,eAAeN,YAAmC;IAC7DE,aACE;IACFC,MAAM;IACNC,SAAS;AACX,GAAE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/cli-build",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Internal Sanity package for building studios and apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -45,9 +45,9 @@
|
|
|
45
45
|
"@oclif/core": "^4.11.4",
|
|
46
46
|
"@rolldown/plugin-babel": "^0.2.3",
|
|
47
47
|
"@sanity/generate-help-url": "^4.0.0",
|
|
48
|
-
"@sanity/schema": "^5.
|
|
48
|
+
"@sanity/schema": "^5.31.1",
|
|
49
49
|
"@sanity/telemetry": "^1.1.0",
|
|
50
|
-
"@sanity/types": "^5.
|
|
50
|
+
"@sanity/types": "^5.31.1",
|
|
51
51
|
"@vitejs/plugin-react": "^6.0.2",
|
|
52
52
|
"chokidar": "^5.0.0",
|
|
53
53
|
"cjs-module-lexer": "^2.2.0",
|
|
@@ -55,19 +55,19 @@
|
|
|
55
55
|
"lodash-es": "^4.18.1",
|
|
56
56
|
"node-html-parser": "^7.1.0",
|
|
57
57
|
"picomatch": "^4.0.4",
|
|
58
|
-
"react": "^19.2.
|
|
59
|
-
"react-dom": "^19.2.
|
|
58
|
+
"react": "^19.2.7",
|
|
59
|
+
"react-dom": "^19.2.7",
|
|
60
60
|
"read-package-up": "^12.0.0",
|
|
61
61
|
"semver": "^7.8.1",
|
|
62
62
|
"vite": "^8.0.16",
|
|
63
|
-
"zod": "^4.3
|
|
64
|
-
"@sanity/cli-core": "^2.0.
|
|
63
|
+
"zod": "^4.4.3",
|
|
64
|
+
"@sanity/cli-core": "^2.0.1"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@eslint/compat": "^2.0
|
|
68
|
-
"@sanity/pkg-utils": "^10.5.
|
|
67
|
+
"@eslint/compat": "^2.1.0",
|
|
68
|
+
"@sanity/pkg-utils": "^10.5.3",
|
|
69
69
|
"@swc/cli": "^0.8.1",
|
|
70
|
-
"@swc/core": "^1.15.
|
|
70
|
+
"@swc/core": "^1.15.40",
|
|
71
71
|
"@types/debug": "^4.1.13",
|
|
72
72
|
"@types/jsdom": "^28.0.3",
|
|
73
73
|
"@types/lodash-es": "^4.17.12",
|
|
@@ -78,18 +78,18 @@
|
|
|
78
78
|
"@types/semver": "^7.7.1",
|
|
79
79
|
"@vitest/coverage-istanbul": "^4.1.8",
|
|
80
80
|
"babel-plugin-react-compiler": "^1.0.0",
|
|
81
|
-
"eslint": "^10.
|
|
81
|
+
"eslint": "^10.4.1",
|
|
82
82
|
"jsdom": "^29.1.1",
|
|
83
83
|
"magic-string": "^0.30.21",
|
|
84
84
|
"publint": "^0.3.21",
|
|
85
|
-
"sanity": "^5.
|
|
85
|
+
"sanity": "^5.31.1",
|
|
86
86
|
"styled-components": "^6.4.2",
|
|
87
87
|
"typescript": "^5.9.3",
|
|
88
88
|
"vitest": "^4.1.8",
|
|
89
89
|
"@repo/package.config": "0.0.1",
|
|
90
90
|
"@repo/tsconfig": "3.70.0",
|
|
91
|
-
"@sanity/cli-test": "1.0.
|
|
92
|
-
"@sanity/eslint-config-cli": "^1.1.
|
|
91
|
+
"@sanity/cli-test": "1.0.1",
|
|
92
|
+
"@sanity/eslint-config-cli": "^1.1.2"
|
|
93
93
|
},
|
|
94
94
|
"peerDependencies": {
|
|
95
95
|
"babel-plugin-react-compiler": "*"
|