@sanity/cli 7.4.1 → 7.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/build/buildApp.js +1 -3
- package/dist/actions/build/buildApp.js.map +1 -1
- package/dist/actions/build/buildStudio.js +1 -3
- package/dist/actions/build/buildStudio.js.map +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +6 -6
- package/dist/actions/build/buildStaticFiles.js +0 -144
- package/dist/actions/build/buildStaticFiles.js.map +0 -1
- package/dist/util/formatSize.js +0 -10
- package/dist/util/formatSize.js.map +0 -1
- package/dist/util/moduleFormatUtils.js +0 -18
- package/dist/util/moduleFormatUtils.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { rm } from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { styleText } from 'node:util';
|
|
4
|
-
import { AppBuildTrace, buildDebug, getAutoUpdatesCssUrls, getAutoUpdatesImportMap, resolveVendorBuildConfig } from '@sanity/cli-build/_internal/build';
|
|
4
|
+
import { AppBuildTrace, buildDebug, buildStaticFiles, formatModuleSizes, getAutoUpdatesCssUrls, getAutoUpdatesImportMap, resolveVendorBuildConfig, sortModulesBySize } from '@sanity/cli-build/_internal/build';
|
|
5
5
|
import { getAppEnvironmentVariables } from '@sanity/cli-build/_internal/env';
|
|
6
6
|
import { getCliTelemetry, getLocalPackageVersion, getTimer, isInteractive } from '@sanity/cli-core';
|
|
7
7
|
import { confirm, logSymbols, spinner } from '@sanity/cli-core/ux';
|
|
@@ -9,9 +9,7 @@ import { resolveWorkbenchApp } from '@sanity/workbench-cli/build';
|
|
|
9
9
|
import { parse as semverParse } from 'semver';
|
|
10
10
|
import { getAppId } from '../../util/appId.js';
|
|
11
11
|
import { compareDependencyVersions } from '../../util/compareDependencyVersions.js';
|
|
12
|
-
import { formatModuleSizes, sortModulesBySize } from '../../util/moduleFormatUtils.js';
|
|
13
12
|
import { warnAboutMissingAppId } from '../../util/warnAboutMissingAppId.js';
|
|
14
|
-
import { buildStaticFiles } from './buildStaticFiles.js';
|
|
15
13
|
import { determineBasePath } from './determineBasePath.js';
|
|
16
14
|
import { handlePrereleaseVersions } from './handlePrereleaseVersions.js';
|
|
17
15
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/build/buildApp.ts"],"sourcesContent":["import {rm} from 'node:fs/promises'\nimport path from 'node:path'\nimport {styleText} from 'node:util'\n\nimport {\n AppBuildTrace,\n buildDebug,\n getAutoUpdatesCssUrls,\n getAutoUpdatesImportMap,\n resolveVendorBuildConfig,\n} from '@sanity/cli-build/_internal/build'\nimport {getAppEnvironmentVariables} from '@sanity/cli-build/_internal/env'\nimport {\n type CliConfig,\n getCliTelemetry,\n getLocalPackageVersion,\n getTimer,\n isInteractive,\n type Output,\n UserViteConfig,\n} from '@sanity/cli-core'\nimport {confirm, logSymbols, spinner, type SpinnerInstance} from '@sanity/cli-core/ux'\nimport {type DefineAppInput} from '@sanity/workbench-cli'\nimport {resolveWorkbenchApp} from '@sanity/workbench-cli/build'\nimport {parse as semverParse} from 'semver'\n\nimport {getAppId} from '../../util/appId.js'\nimport {\n compareDependencyVersions,\n CompareDependencyVersionsResult,\n} from '../../util/compareDependencyVersions.js'\nimport {formatModuleSizes, sortModulesBySize} from '../../util/moduleFormatUtils.js'\nimport {warnAboutMissingAppId} from '../../util/warnAboutMissingAppId.js'\nimport {buildStaticFiles} from './buildStaticFiles.js'\nimport {determineBasePath} from './determineBasePath.js'\nimport {handlePrereleaseVersions} from './handlePrereleaseVersions.js'\nimport {type BuildOptions} from './types.js'\n\ninterface InternalBuildOptions {\n appId: string | undefined\n appTitle: string | undefined\n autoUpdatesEnabled: boolean\n checkAppId: () => void\n compareDependencyVersions: (\n packages: {name: string; version: string}[],\n ) => Promise<CompareDependencyVersionsResult>\n determineBasePath: () => string\n entry: string | undefined\n isWorkbenchApp: boolean\n minify: boolean\n outDir: string | undefined\n output: Output\n reactCompiler: CliConfig['reactCompiler']\n schemaExtraction: CliConfig['schemaExtraction']\n services: DefineAppInput['services']\n sourceMap: boolean\n stats: boolean\n unattendedMode: boolean\n views: DefineAppInput['views']\n vite: UserViteConfig | undefined\n workDir: string\n}\n\n/**\n * Build the Sanity app.\n *\n * @internal\n */\nexport async function buildApp(options: BuildOptions): Promise<void> {\n const {cliConfig, flags, outDir, output, workDir} = options\n\n const app = cliConfig && 'app' in cliConfig ? cliConfig.app : undefined\n // `views`/`services` live on the branded `unstable_defineApp` result, not the\n // legacy `app` config object — resolve the workbench capability to read them.\n const workbench = resolveWorkbenchApp(cliConfig)\n\n const appId = getAppId(cliConfig)\n\n await internalBuildApp({\n appId,\n appTitle: app?.title,\n autoUpdatesEnabled: options.autoUpdatesEnabled,\n checkAppId: () => {\n // Warn if auto updates enabled but no appId configured.\n // Skip when called from deploy, since deploy handles appId itself\n // (prompts the user and tells them to add it to config).\n if (!appId && !options.calledFromDeploy) {\n warnAboutMissingAppId({appType: 'app', output})\n }\n },\n compareDependencyVersions: (packages) => compareDependencyVersions(packages, workDir, {appId}),\n determineBasePath: () => determineBasePath(cliConfig, 'app', output),\n entry: app?.entry,\n isWorkbenchApp: !!workbench,\n minify: flags.minify,\n outDir,\n output,\n reactCompiler: cliConfig && 'reactCompiler' in cliConfig ? cliConfig.reactCompiler : undefined,\n schemaExtraction: cliConfig?.schemaExtraction,\n services: workbench?.services,\n sourceMap: Boolean(flags['source-maps']),\n stats: flags.stats,\n unattendedMode: flags.yes,\n views: workbench?.views,\n vite: cliConfig.vite,\n workDir,\n })\n}\n\n/**\n * Internal build app that avoids depending on flags for CLI config.\n * @param options - options for the build\n */\nasync function internalBuildApp(options: InternalBuildOptions): Promise<void> {\n buildDebug(`Building app`)\n\n const {appId, determineBasePath, outDir, output, workDir} = options\n let {autoUpdatesEnabled} = options\n const unattendedMode = options.unattendedMode\n\n const timer = getTimer()\n\n const defaultOutputDir = path.resolve(path.join(workDir, 'dist'))\n const outputDir = path.resolve(outDir || defaultOutputDir)\n\n const installedSdkVersion = await getLocalPackageVersion('@sanity/sdk-react', workDir)\n const installedSanityVersion = await getLocalPackageVersion('sanity', workDir)\n\n if (!installedSdkVersion) {\n output.error(`Failed to find installed @sanity/sdk-react version`, {exit: 1})\n return\n }\n\n let autoUpdatesImports = {}\n let autoUpdatesCssUrls: string[] = []\n\n if (autoUpdatesEnabled) {\n // Get the clean version without build metadata: https://semver.org/#spec-item-10\n const cleanSDKVersion = semverParse(installedSdkVersion)?.version\n if (!cleanSDKVersion) {\n output.error(`Failed to parse installed SDK version: ${installedSdkVersion}`, {exit: 1})\n return\n }\n\n // Sanity might not be installed, but if it is, we want to auto update it.\n const cleanSanityVersion = semverParse(installedSanityVersion)?.version\n\n const autoUpdatedPackages = [\n {name: '@sanity/sdk', version: cleanSDKVersion},\n {name: '@sanity/sdk-react', version: cleanSDKVersion},\n ...(cleanSanityVersion\n ? [{cssFile: 'index.css', name: 'sanity' as const, version: cleanSanityVersion}]\n : []),\n ]\n autoUpdatesImports = getAutoUpdatesImportMap(autoUpdatedPackages, {appId})\n autoUpdatesCssUrls = getAutoUpdatesCssUrls(autoUpdatedPackages, {appId})\n\n output.log(`${logSymbols.info} Building with auto-updates enabled`)\n\n // Warn if auto updates enabled but no appId configured.\n options.checkAppId()\n\n // Check the versions\n const {mismatched, unresolvedPrerelease} =\n await options.compareDependencyVersions(autoUpdatedPackages)\n\n if (unresolvedPrerelease.length > 0) {\n await handlePrereleaseVersions({output, unattendedMode, unresolvedPrerelease})\n autoUpdatesImports = {}\n autoUpdatesCssUrls = []\n autoUpdatesEnabled = false\n }\n\n if (mismatched.length > 0 && autoUpdatesEnabled) {\n const versionMismatchWarning =\n `The following local package versions are different from the versions currently served at runtime.\\n` +\n `When using auto updates, we recommend that you test locally with the same versions before deploying. \\n\\n` +\n `${mismatched.map((mod) => ` - ${mod.pkg} (local version: ${mod.installed}, runtime version: ${mod.remote})`).join('\\n')}`\n\n // If it is non-interactive or in unattended mode, we don't want to prompt\n if (isInteractive() && !unattendedMode) {\n const shouldContinue = await confirm({\n default: false,\n message: styleText('yellow', `${versionMismatchWarning} \\n\\nContinue anyway?`),\n })\n\n if (!shouldContinue) {\n output.error('Declined to continue with build', {exit: 1})\n return\n }\n } else {\n // if non-interactive or unattended, just show the warning\n output.warn(versionMismatchWarning)\n }\n }\n }\n\n const envVarKeys = Object.keys(getAppEnvironmentVariables())\n if (envVarKeys.length > 0) {\n output.log('\\nIncluding the following environment variables as part of the JavaScript bundle:')\n for (const key of envVarKeys) output.log(`- ${key}`)\n output.log('')\n }\n\n let shouldClean = true\n if (outputDir !== defaultOutputDir && !unattendedMode && isInteractive()) {\n shouldClean = await confirm({\n default: true,\n message: `Do you want to delete the existing directory (${outputDir}) first?`,\n })\n }\n\n const basePath = determineBasePath()\n\n let spin: SpinnerInstance\n if (shouldClean) {\n timer.start('cleanOutputFolder')\n spin = spinner('Clean output folder').start()\n await rm(outputDir, {force: true, recursive: true})\n const cleanDuration = timer.end('cleanOutputFolder')\n spin.text = `Clean output folder (${cleanDuration.toFixed(0)}ms)`\n spin.succeed()\n }\n\n spin = spinner(`Building Sanity application`).start()\n\n const trace = getCliTelemetry().trace(AppBuildTrace)\n trace.start()\n\n let autoUpdates\n if (autoUpdatesEnabled && !options.isWorkbenchApp) {\n autoUpdates = {\n cssUrls: autoUpdatesCssUrls,\n imports: autoUpdatesImports,\n vendor: await resolveVendorBuildConfig({cwd: workDir, isApp: true}),\n }\n }\n\n try {\n timer.start('bundleStudio')\n\n const bundle = await buildStaticFiles({\n appTitle: options.appTitle,\n autoUpdates,\n basePath,\n cwd: workDir,\n entry: options.entry,\n isApp: true,\n isWorkbenchApp: options.isWorkbenchApp,\n minify: options.minify,\n outputDir,\n reactCompiler: options.reactCompiler,\n schemaExtraction: options.schemaExtraction,\n services: options.services,\n sourceMap: options.sourceMap,\n views: options.views,\n vite: options.vite,\n })\n\n trace.log({\n outputSize: bundle.chunks\n .flatMap((chunk) => chunk.modules.flatMap((mod) => mod.renderedLength))\n .reduce((sum, n) => sum + n, 0),\n })\n const buildDuration = timer.end('bundleStudio')\n\n spin.text = `Build Sanity application (${buildDuration.toFixed(0)}ms)`\n spin.succeed()\n\n if (options.stats) {\n output.log('\\nLargest module files:')\n output.log(formatModuleSizes(sortModulesBySize(bundle.chunks).slice(0, 15)))\n }\n\n trace.complete()\n } catch (error) {\n spin.fail()\n trace.error(error)\n const message = error instanceof Error ? error.message : String(error)\n buildDebug(`Failed to build Sanity application`, {error})\n output.error(`Failed to build Sanity application: ${message}`, {exit: 1})\n }\n}\n"],"names":["rm","path","styleText","AppBuildTrace","buildDebug","getAutoUpdatesCssUrls","getAutoUpdatesImportMap","resolveVendorBuildConfig","getAppEnvironmentVariables","getCliTelemetry","getLocalPackageVersion","getTimer","isInteractive","confirm","logSymbols","spinner","resolveWorkbenchApp","parse","semverParse","getAppId","compareDependencyVersions","formatModuleSizes","sortModulesBySize","warnAboutMissingAppId","buildStaticFiles","determineBasePath","handlePrereleaseVersions","buildApp","options","cliConfig","flags","outDir","output","workDir","app","undefined","workbench","appId","internalBuildApp","appTitle","title","autoUpdatesEnabled","checkAppId","calledFromDeploy","appType","packages","entry","isWorkbenchApp","minify","reactCompiler","schemaExtraction","services","sourceMap","Boolean","stats","unattendedMode","yes","views","vite","timer","defaultOutputDir","resolve","join","outputDir","installedSdkVersion","installedSanityVersion","error","exit","autoUpdatesImports","autoUpdatesCssUrls","cleanSDKVersion","version","cleanSanityVersion","autoUpdatedPackages","name","cssFile","log","info","mismatched","unresolvedPrerelease","length","versionMismatchWarning","map","mod","pkg","installed","remote","shouldContinue","default","message","warn","envVarKeys","Object","keys","key","shouldClean","basePath","spin","start","force","recursive","cleanDuration","end","text","toFixed","succeed","trace","autoUpdates","cssUrls","imports","vendor","cwd","isApp","bundle","outputSize","chunks","flatMap","chunk","modules","renderedLength","reduce","sum","n","buildDuration","slice","complete","fail","Error","String"],"mappings":"AAAA,SAAQA,E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,UAAUvB,iBAAiB6D,QAAQ7D,MAAMuB,OAAO,GAAGuC,OAAO9D;QAChE9D,WAAW,CAAC,kCAAkC,CAAC,EAAE;YAAC8D;QAAK;QACvDlC,OAAOkC,KAAK,CAAC,CAAC,oCAAoC,EAAEuB,SAAS,EAAE;YAACtB,MAAM;QAAC;IACzE;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/build/buildApp.ts"],"sourcesContent":["import {rm} from 'node:fs/promises'\nimport path from 'node:path'\nimport {styleText} from 'node:util'\n\nimport {\n AppBuildTrace,\n buildDebug,\n buildStaticFiles,\n formatModuleSizes,\n getAutoUpdatesCssUrls,\n getAutoUpdatesImportMap,\n resolveVendorBuildConfig,\n sortModulesBySize,\n} from '@sanity/cli-build/_internal/build'\nimport {getAppEnvironmentVariables} from '@sanity/cli-build/_internal/env'\nimport {\n type CliConfig,\n getCliTelemetry,\n getLocalPackageVersion,\n getTimer,\n isInteractive,\n type Output,\n UserViteConfig,\n} from '@sanity/cli-core'\nimport {confirm, logSymbols, spinner, type SpinnerInstance} from '@sanity/cli-core/ux'\nimport {type DefineAppInput} from '@sanity/workbench-cli'\nimport {resolveWorkbenchApp} from '@sanity/workbench-cli/build'\nimport {parse as semverParse} from 'semver'\n\nimport {getAppId} from '../../util/appId.js'\nimport {\n compareDependencyVersions,\n CompareDependencyVersionsResult,\n} from '../../util/compareDependencyVersions.js'\nimport {warnAboutMissingAppId} from '../../util/warnAboutMissingAppId.js'\nimport {determineBasePath} from './determineBasePath.js'\nimport {handlePrereleaseVersions} from './handlePrereleaseVersions.js'\nimport {type BuildOptions} from './types.js'\n\ninterface InternalBuildOptions {\n appId: string | undefined\n appTitle: string | undefined\n autoUpdatesEnabled: boolean\n checkAppId: () => void\n compareDependencyVersions: (\n packages: {name: string; version: string}[],\n ) => Promise<CompareDependencyVersionsResult>\n determineBasePath: () => string\n entry: string | undefined\n isWorkbenchApp: boolean\n minify: boolean\n outDir: string | undefined\n output: Output\n reactCompiler: CliConfig['reactCompiler']\n schemaExtraction: CliConfig['schemaExtraction']\n services: DefineAppInput['services']\n sourceMap: boolean\n stats: boolean\n unattendedMode: boolean\n views: DefineAppInput['views']\n vite: UserViteConfig | undefined\n workDir: string\n}\n\n/**\n * Build the Sanity app.\n *\n * @internal\n */\nexport async function buildApp(options: BuildOptions): Promise<void> {\n const {cliConfig, flags, outDir, output, workDir} = options\n\n const app = cliConfig && 'app' in cliConfig ? cliConfig.app : undefined\n // `views`/`services` live on the branded `unstable_defineApp` result, not the\n // legacy `app` config object — resolve the workbench capability to read them.\n const workbench = resolveWorkbenchApp(cliConfig)\n\n const appId = getAppId(cliConfig)\n\n await internalBuildApp({\n appId,\n appTitle: app?.title,\n autoUpdatesEnabled: options.autoUpdatesEnabled,\n checkAppId: () => {\n // Warn if auto updates enabled but no appId configured.\n // Skip when called from deploy, since deploy handles appId itself\n // (prompts the user and tells them to add it to config).\n if (!appId && !options.calledFromDeploy) {\n warnAboutMissingAppId({appType: 'app', output})\n }\n },\n compareDependencyVersions: (packages) => compareDependencyVersions(packages, workDir, {appId}),\n determineBasePath: () => determineBasePath(cliConfig, 'app', output),\n entry: app?.entry,\n isWorkbenchApp: !!workbench,\n minify: flags.minify,\n outDir,\n output,\n reactCompiler: cliConfig && 'reactCompiler' in cliConfig ? cliConfig.reactCompiler : undefined,\n schemaExtraction: cliConfig?.schemaExtraction,\n services: workbench?.services,\n sourceMap: Boolean(flags['source-maps']),\n stats: flags.stats,\n unattendedMode: flags.yes,\n views: workbench?.views,\n vite: cliConfig.vite,\n workDir,\n })\n}\n\n/**\n * Internal build app that avoids depending on flags for CLI config.\n * @param options - options for the build\n */\nasync function internalBuildApp(options: InternalBuildOptions): Promise<void> {\n buildDebug(`Building app`)\n\n const {appId, determineBasePath, outDir, output, workDir} = options\n let {autoUpdatesEnabled} = options\n const unattendedMode = options.unattendedMode\n\n const timer = getTimer()\n\n const defaultOutputDir = path.resolve(path.join(workDir, 'dist'))\n const outputDir = path.resolve(outDir || defaultOutputDir)\n\n const installedSdkVersion = await getLocalPackageVersion('@sanity/sdk-react', workDir)\n const installedSanityVersion = await getLocalPackageVersion('sanity', workDir)\n\n if (!installedSdkVersion) {\n output.error(`Failed to find installed @sanity/sdk-react version`, {exit: 1})\n return\n }\n\n let autoUpdatesImports = {}\n let autoUpdatesCssUrls: string[] = []\n\n if (autoUpdatesEnabled) {\n // Get the clean version without build metadata: https://semver.org/#spec-item-10\n const cleanSDKVersion = semverParse(installedSdkVersion)?.version\n if (!cleanSDKVersion) {\n output.error(`Failed to parse installed SDK version: ${installedSdkVersion}`, {exit: 1})\n return\n }\n\n // Sanity might not be installed, but if it is, we want to auto update it.\n const cleanSanityVersion = semverParse(installedSanityVersion)?.version\n\n const autoUpdatedPackages = [\n {name: '@sanity/sdk', version: cleanSDKVersion},\n {name: '@sanity/sdk-react', version: cleanSDKVersion},\n ...(cleanSanityVersion\n ? [{cssFile: 'index.css', name: 'sanity' as const, version: cleanSanityVersion}]\n : []),\n ]\n autoUpdatesImports = getAutoUpdatesImportMap(autoUpdatedPackages, {appId})\n autoUpdatesCssUrls = getAutoUpdatesCssUrls(autoUpdatedPackages, {appId})\n\n output.log(`${logSymbols.info} Building with auto-updates enabled`)\n\n // Warn if auto updates enabled but no appId configured.\n options.checkAppId()\n\n // Check the versions\n const {mismatched, unresolvedPrerelease} =\n await options.compareDependencyVersions(autoUpdatedPackages)\n\n if (unresolvedPrerelease.length > 0) {\n await handlePrereleaseVersions({output, unattendedMode, unresolvedPrerelease})\n autoUpdatesImports = {}\n autoUpdatesCssUrls = []\n autoUpdatesEnabled = false\n }\n\n if (mismatched.length > 0 && autoUpdatesEnabled) {\n const versionMismatchWarning =\n `The following local package versions are different from the versions currently served at runtime.\\n` +\n `When using auto updates, we recommend that you test locally with the same versions before deploying. \\n\\n` +\n `${mismatched.map((mod) => ` - ${mod.pkg} (local version: ${mod.installed}, runtime version: ${mod.remote})`).join('\\n')}`\n\n // If it is non-interactive or in unattended mode, we don't want to prompt\n if (isInteractive() && !unattendedMode) {\n const shouldContinue = await confirm({\n default: false,\n message: styleText('yellow', `${versionMismatchWarning} \\n\\nContinue anyway?`),\n })\n\n if (!shouldContinue) {\n output.error('Declined to continue with build', {exit: 1})\n return\n }\n } else {\n // if non-interactive or unattended, just show the warning\n output.warn(versionMismatchWarning)\n }\n }\n }\n\n const envVarKeys = Object.keys(getAppEnvironmentVariables())\n if (envVarKeys.length > 0) {\n output.log('\\nIncluding the following environment variables as part of the JavaScript bundle:')\n for (const key of envVarKeys) output.log(`- ${key}`)\n output.log('')\n }\n\n let shouldClean = true\n if (outputDir !== defaultOutputDir && !unattendedMode && isInteractive()) {\n shouldClean = await confirm({\n default: true,\n message: `Do you want to delete the existing directory (${outputDir}) first?`,\n })\n }\n\n const basePath = determineBasePath()\n\n let spin: SpinnerInstance\n if (shouldClean) {\n timer.start('cleanOutputFolder')\n spin = spinner('Clean output folder').start()\n await rm(outputDir, {force: true, recursive: true})\n const cleanDuration = timer.end('cleanOutputFolder')\n spin.text = `Clean output folder (${cleanDuration.toFixed(0)}ms)`\n spin.succeed()\n }\n\n spin = spinner(`Building Sanity application`).start()\n\n const trace = getCliTelemetry().trace(AppBuildTrace)\n trace.start()\n\n let autoUpdates\n if (autoUpdatesEnabled && !options.isWorkbenchApp) {\n autoUpdates = {\n cssUrls: autoUpdatesCssUrls,\n imports: autoUpdatesImports,\n vendor: await resolveVendorBuildConfig({cwd: workDir, isApp: true}),\n }\n }\n\n try {\n timer.start('bundleStudio')\n\n const bundle = await buildStaticFiles({\n appTitle: options.appTitle,\n autoUpdates,\n basePath,\n cwd: workDir,\n entry: options.entry,\n isApp: true,\n isWorkbenchApp: options.isWorkbenchApp,\n minify: options.minify,\n outputDir,\n reactCompiler: options.reactCompiler,\n schemaExtraction: options.schemaExtraction,\n services: options.services,\n sourceMap: options.sourceMap,\n views: options.views,\n vite: options.vite,\n })\n\n trace.log({\n outputSize: bundle.chunks\n .flatMap((chunk) => chunk.modules.flatMap((mod) => mod.renderedLength))\n .reduce((sum, n) => sum + n, 0),\n })\n const buildDuration = timer.end('bundleStudio')\n\n spin.text = `Build Sanity application (${buildDuration.toFixed(0)}ms)`\n spin.succeed()\n\n if (options.stats) {\n output.log('\\nLargest module files:')\n output.log(formatModuleSizes(sortModulesBySize(bundle.chunks).slice(0, 15)))\n }\n\n trace.complete()\n } catch (error) {\n spin.fail()\n trace.error(error)\n const message = error instanceof Error ? error.message : String(error)\n buildDebug(`Failed to build Sanity application`, {error})\n output.error(`Failed to build Sanity application: ${message}`, {exit: 1})\n }\n}\n"],"names":["rm","path","styleText","AppBuildTrace","buildDebug","buildStaticFiles","formatModuleSizes","getAutoUpdatesCssUrls","getAutoUpdatesImportMap","resolveVendorBuildConfig","sortModulesBySize","getAppEnvironmentVariables","getCliTelemetry","getLocalPackageVersion","getTimer","isInteractive","confirm","logSymbols","spinner","resolveWorkbenchApp","parse","semverParse","getAppId","compareDependencyVersions","warnAboutMissingAppId","determineBasePath","handlePrereleaseVersions","buildApp","options","cliConfig","flags","outDir","output","workDir","app","undefined","workbench","appId","internalBuildApp","appTitle","title","autoUpdatesEnabled","checkAppId","calledFromDeploy","appType","packages","entry","isWorkbenchApp","minify","reactCompiler","schemaExtraction","services","sourceMap","Boolean","stats","unattendedMode","yes","views","vite","timer","defaultOutputDir","resolve","join","outputDir","installedSdkVersion","installedSanityVersion","error","exit","autoUpdatesImports","autoUpdatesCssUrls","cleanSDKVersion","version","cleanSanityVersion","autoUpdatedPackages","name","cssFile","log","info","mismatched","unresolvedPrerelease","length","versionMismatchWarning","map","mod","pkg","installed","remote","shouldContinue","default","message","warn","envVarKeys","Object","keys","key","shouldClean","basePath","spin","start","force","recursive","cleanDuration","end","text","toFixed","succeed","trace","autoUpdates","cssUrls","imports","vendor","cwd","isApp","bundle","outputSize","chunks","flatMap","chunk","modules","renderedLength","reduce","sum","n","buildDuration","slice","complete","fail","Error","String"],"mappings":"AAAA,SAAQA,EAAE,QAAO,mBAAkB;AACnC,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E9D,WAAW,CAAC,kCAAkC,CAAC,EAAE;YAAC8D;QAAK;QACvDlC,OAAOkC,KAAK,CAAC,CAAC,oCAAoC,EAAEuB,SAAS,EAAE;YAACtB,MAAM;QAAC;IACzE;AACF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { rm } from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { styleText } from 'node:util';
|
|
4
|
-
import { buildDebug, checkRequiredDependencies, checkStudioDependencyVersions, getAutoUpdatesCssUrls, getAutoUpdatesImportMap, resolveVendorBuildConfig, StudioBuildTrace } from '@sanity/cli-build/_internal/build';
|
|
4
|
+
import { buildDebug, buildStaticFiles, checkRequiredDependencies, checkStudioDependencyVersions, formatModuleSizes, getAutoUpdatesCssUrls, getAutoUpdatesImportMap, resolveVendorBuildConfig, sortModulesBySize, StudioBuildTrace } from '@sanity/cli-build/_internal/build';
|
|
5
5
|
import { getStudioEnvironmentVariables } from '@sanity/cli-build/_internal/env';
|
|
6
6
|
import { getCliTelemetry, getLocalPackageVersion, getTimer, isInteractive } from '@sanity/cli-core';
|
|
7
7
|
import { confirm, logSymbols, select, spinner } from '@sanity/cli-core/ux';
|
|
@@ -10,11 +10,9 @@ import { parse as semverParse } from 'semver';
|
|
|
10
10
|
import { getAppId } from '../../util/appId.js';
|
|
11
11
|
import { compareDependencyVersions } from '../../util/compareDependencyVersions.js';
|
|
12
12
|
import { determineIsApp } from '../../util/determineIsApp.js';
|
|
13
|
-
import { formatModuleSizes, sortModulesBySize } from '../../util/moduleFormatUtils.js';
|
|
14
13
|
import { getPackageManagerChoice } from '../../util/packageManager/packageManagerChoice.js';
|
|
15
14
|
import { upgradePackages } from '../../util/packageManager/upgradePackages.js';
|
|
16
15
|
import { warnAboutMissingAppId } from '../../util/warnAboutMissingAppId.js';
|
|
17
|
-
import { buildStaticFiles } from './buildStaticFiles.js';
|
|
18
16
|
import { determineBasePath } from './determineBasePath.js';
|
|
19
17
|
import { handlePrereleaseVersions } from './handlePrereleaseVersions.js';
|
|
20
18
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/build/buildStudio.ts"],"sourcesContent":["import {rm} from 'node:fs/promises'\nimport path from 'node:path'\nimport {styleText} from 'node:util'\n\nimport {\n buildDebug,\n checkRequiredDependencies,\n checkStudioDependencyVersions,\n getAutoUpdatesCssUrls,\n getAutoUpdatesImportMap,\n resolveVendorBuildConfig,\n StudioBuildTrace,\n} from '@sanity/cli-build/_internal/build'\nimport {getStudioEnvironmentVariables} from '@sanity/cli-build/_internal/env'\nimport {\n type CliConfig,\n getCliTelemetry,\n getLocalPackageVersion,\n getTimer,\n isInteractive,\n type Output,\n UserViteConfig,\n} from '@sanity/cli-core'\nimport {confirm, logSymbols, select, spinner, type SpinnerInstance} from '@sanity/cli-core/ux'\nimport {type DefineAppInput} from '@sanity/workbench-cli'\nimport {resolveWorkbenchApp} from '@sanity/workbench-cli/build'\nimport {parse as semverParse} from 'semver'\n\nimport {getAppId} from '../../util/appId.js'\nimport {\n compareDependencyVersions,\n CompareDependencyVersionsResult,\n} from '../../util/compareDependencyVersions.js'\nimport {determineIsApp} from '../../util/determineIsApp.js'\nimport {formatModuleSizes, sortModulesBySize} from '../../util/moduleFormatUtils.js'\nimport {getPackageManagerChoice} from '../../util/packageManager/packageManagerChoice.js'\nimport {upgradePackages} from '../../util/packageManager/upgradePackages.js'\nimport {warnAboutMissingAppId} from '../../util/warnAboutMissingAppId.js'\nimport {buildStaticFiles} from './buildStaticFiles.js'\nimport {determineBasePath} from './determineBasePath.js'\nimport {handlePrereleaseVersions} from './handlePrereleaseVersions.js'\nimport {type BuildOptions} from './types.js'\n\ninterface InternalBuildOptions {\n appId: string | undefined\n autoUpdatesEnabled: boolean\n checkAppId: () => void\n compareDependencyVersions: (\n packages: {name: string; version: string}[],\n ) => Promise<CompareDependencyVersionsResult>\n determineBasePath: () => string\n isApp: boolean\n isWorkbenchApp: boolean\n minify: boolean\n outDir: string | undefined\n output: Output\n reactCompiler: CliConfig['reactCompiler']\n schemaExtraction: CliConfig['schemaExtraction']\n services: DefineAppInput['services']\n sourceMap: boolean\n stats: boolean\n unattendedMode: boolean\n upgradePackages(options: {packages: [name: string, version: string][]}): Promise<void>\n views: DefineAppInput['views']\n vite: UserViteConfig | undefined\n workDir: string\n}\n\n/**\n * Build the Sanity Studio.\n *\n * @internal\n */\nexport async function buildStudio(options: BuildOptions): Promise<void> {\n const {calledFromDeploy, cliConfig, flags, outDir, output, workDir} = options\n\n // `views`/`services` live on the branded `unstable_defineApp` result — resolve\n // the workbench capability so it's gated on the brand, like the app build.\n const workbench = resolveWorkbenchApp(cliConfig)\n\n const appId = getAppId(cliConfig)\n\n const upgradePkgs = async (options: {\n packages: [name: string, version: string][]\n }): Promise<void> => {\n await upgradePackages(\n {\n packageManager: (await getPackageManagerChoice(workDir, {interactive: false})).chosen,\n packages: options.packages,\n },\n {output, workDir},\n )\n }\n\n await internalBuildStudio({\n appId,\n autoUpdatesEnabled: options.autoUpdatesEnabled,\n checkAppId: () => {\n // Warn if auto updates enabled but no appId configured.\n // Skip when called from deploy, since deploy handles appId itself\n // (prompts the user and tells them to add it to config).\n if (!appId && !calledFromDeploy) {\n warnAboutMissingAppId({appType: 'studio', output, projectId: cliConfig?.api?.projectId})\n }\n },\n compareDependencyVersions: (packages) => compareDependencyVersions(packages, workDir, {appId}),\n determineBasePath: () => determineBasePath(cliConfig, 'studio', output),\n isApp: determineIsApp(cliConfig),\n isWorkbenchApp: !!workbench,\n minify: Boolean(flags.minify),\n outDir,\n output,\n reactCompiler: cliConfig.reactCompiler,\n schemaExtraction: cliConfig.schemaExtraction,\n services: workbench?.services,\n sourceMap: Boolean(flags['source-maps']),\n stats: flags.stats,\n unattendedMode: Boolean(flags.yes),\n upgradePackages: upgradePkgs,\n views: workbench?.views,\n vite: cliConfig.vite,\n workDir,\n })\n}\n\n/**\n * Internal build studio that avoids depending on flags for CLI config.\n * @param options - options for the build\n */\nasync function internalBuildStudio(options: InternalBuildOptions): Promise<void> {\n buildDebug(`Building studio`)\n\n const timer = getTimer()\n const {\n appId,\n determineBasePath,\n isApp,\n minify,\n outDir,\n output,\n reactCompiler,\n schemaExtraction,\n services,\n sourceMap,\n stats,\n unattendedMode,\n upgradePackages,\n views,\n vite,\n workDir,\n } = options\n const defaultOutputDir = path.resolve(path.join(workDir, 'dist'))\n const outputDir = path.resolve(outDir || defaultOutputDir)\n\n await checkStudioDependencyVersions(workDir, output)\n\n // If the check resulted in a dependency install, the CLI command will be re-run,\n // thus we want to exit early\n const {installedSanityVersion} = await checkRequiredDependencies({\n isApp,\n output,\n workDir,\n })\n\n let autoUpdatesEnabled = options.autoUpdatesEnabled\n\n let autoUpdatesImports = {}\n let autoUpdatesCssUrls: string[] = []\n\n if (autoUpdatesEnabled) {\n // Get the clean version without build metadata: https://semver.org/#spec-item-10\n const cleanSanityVersion = semverParse(installedSanityVersion)?.version\n if (!cleanSanityVersion) {\n throw new Error(`Failed to parse installed Sanity version: ${installedSanityVersion}`)\n }\n\n output.log(`${logSymbols.info} Building with auto-updates enabled`)\n\n // Warn if auto updates enabled but no appId configured\n options.checkAppId()\n\n const installedVisionVersion = await getLocalPackageVersion('@sanity/vision', workDir)\n const cleanVisionVersion = installedVisionVersion\n ? semverParse(installedVisionVersion)?.version\n : undefined\n\n const sanityDependencies = [\n {cssFile: 'index.css', name: 'sanity', version: cleanSanityVersion},\n ...(cleanVisionVersion\n ? [{cssFile: 'index.css', name: '@sanity/vision' as const, version: cleanVisionVersion}]\n : [{name: '@sanity/vision' as const, version: cleanSanityVersion}]),\n ]\n autoUpdatesImports = getAutoUpdatesImportMap(sanityDependencies, {appId})\n\n autoUpdatesCssUrls = getAutoUpdatesCssUrls(sanityDependencies, {appId})\n\n // Check the versions\n const {mismatched, unresolvedPrerelease} =\n await options.compareDependencyVersions(sanityDependencies)\n\n if (unresolvedPrerelease.length > 0) {\n await handlePrereleaseVersions({output, unattendedMode, unresolvedPrerelease})\n autoUpdatesImports = {}\n autoUpdatesCssUrls = []\n autoUpdatesEnabled = false\n }\n\n if (mismatched.length > 0 && autoUpdatesEnabled) {\n const versionMismatchWarning =\n `The following local package versions are different from the versions currently served at runtime.\\n` +\n `When using auto updates, we recommend that you test locally with the same versions before deploying. \\n\\n` +\n `${mismatched.map((mod) => ` - ${mod.pkg} (local version: ${mod.installed}, runtime version: ${mod.remote})`).join('\\n')}`\n\n // If it is non-interactive or in unattended mode, we don't want to prompt\n if (isInteractive() && !unattendedMode) {\n const choice = await select({\n choices: [\n {\n name: `Upgrade local versions (recommended). You will need to run the build command again`,\n value: 'upgrade',\n },\n {\n name: `Upgrade and proceed with build`,\n value: 'upgrade-and-proceed',\n },\n {\n name: `Continue anyway`,\n value: 'continue',\n },\n {name: 'Cancel', value: 'cancel'},\n ],\n default: 'upgrade',\n message: styleText(\n 'yellow',\n `${logSymbols.warning} ${versionMismatchWarning}\\n\\nDo you want to upgrade local versions before deploying?`,\n ),\n })\n\n if (choice === 'cancel') {\n output.error('Declined to continue with build', {exit: 1})\n return\n }\n\n if (choice === 'upgrade' || choice === 'upgrade-and-proceed') {\n await upgradePackages({\n packages: mismatched.map((res) => [res.pkg, res.remote]),\n })\n\n if (choice === 'upgrade') {\n return\n }\n }\n } else {\n // if non-interactive or unattended, just show the warning\n output.warn(versionMismatchWarning)\n }\n }\n }\n\n const envVarKeys = Object.keys(getStudioEnvironmentVariables())\n if (envVarKeys.length > 0) {\n output.log('\\nIncluding the following environment variables as part of the JavaScript bundle:')\n for (const key of envVarKeys) {\n output.log(`- ${key}`)\n }\n output.log('')\n }\n\n let shouldClean = true\n if (outputDir !== defaultOutputDir && !unattendedMode && isInteractive()) {\n shouldClean = await confirm({\n default: true,\n message: `Do you want to delete the existing directory (${outputDir}) first?`,\n })\n }\n\n // Determine base path for built studio\n const basePath = determineBasePath()\n\n if (schemaExtraction?.enabled) {\n output.log(`${logSymbols.info} Building with schema extraction enabled`)\n }\n\n let spin: SpinnerInstance\n if (shouldClean) {\n timer.start('cleanOutputFolder')\n spin = spinner('Clean output folder').start()\n await rm(outputDir, {force: true, recursive: true})\n const cleanDuration = timer.end('cleanOutputFolder')\n spin.text = `Clean output folder (${cleanDuration.toFixed(0)}ms)`\n spin.succeed()\n }\n\n spin = spinner(`Build Sanity Studio`).start()\n\n const trace = getCliTelemetry().trace(StudioBuildTrace)\n trace.start()\n\n let autoUpdates\n if (autoUpdatesEnabled && !options.isWorkbenchApp) {\n autoUpdates = {\n cssUrls: autoUpdatesCssUrls,\n imports: autoUpdatesImports,\n vendor: await resolveVendorBuildConfig({cwd: workDir, isApp: false}),\n }\n }\n\n try {\n timer.start('bundleStudio')\n\n const bundle = await buildStaticFiles({\n autoUpdates,\n basePath,\n cwd: workDir,\n isWorkbenchApp: options.isWorkbenchApp,\n minify,\n outputDir,\n reactCompiler,\n schemaExtraction,\n services,\n sourceMap,\n views,\n vite,\n })\n\n trace.log({\n outputSize: bundle.chunks\n .flatMap((chunk) => chunk.modules.flatMap((mod) => mod.renderedLength))\n .reduce((sum, n) => sum + n, 0),\n })\n const buildDuration = timer.end('bundleStudio')\n\n spin.text = `Build Sanity Studio (${buildDuration.toFixed(0)}ms)`\n spin.succeed()\n\n trace.complete()\n if (stats) {\n output.log('\\nLargest module files:')\n output.log(formatModuleSizes(sortModulesBySize(bundle.chunks).slice(0, 15)))\n }\n } catch (error) {\n spin.fail()\n trace.error(error)\n const message = error instanceof Error ? error.message : String(error)\n buildDebug(`Failed to build Sanity Studio`, {error})\n output.error(`Failed to build Sanity Studio: ${message}`, {exit: 1})\n }\n}\n"],"names":["rm","path","styleText","buildDebug","checkRequiredDependencies","checkStudioDependencyVersions","getAutoUpdatesCssUrls","getAutoUpdatesImportMap","resolveVendorBuildConfig","StudioBuildTrace","getStudioEnvironmentVariables","getCliTelemetry","getLocalPackageVersion","getTimer","isInteractive","confirm","logSymbols","select","spinner","resolveWorkbenchApp","parse","semverParse","getAppId","compareDependencyVersions","determineIsApp","formatModuleSizes","sortModulesBySize","getPackageManagerChoice","upgradePackages","warnAboutMissingAppId","buildStaticFiles","determineBasePath","handlePrereleaseVersions","buildStudio","options","calledFromDeploy","cliConfig","flags","outDir","output","workDir","workbench","appId","upgradePkgs","packageManager","interactive","chosen","packages","internalBuildStudio","autoUpdatesEnabled","checkAppId","appType","projectId","api","isApp","isWorkbenchApp","minify","Boolean","reactCompiler","schemaExtraction","services","sourceMap","stats","unattendedMode","yes","views","vite","timer","defaultOutputDir","resolve","join","outputDir","installedSanityVersion","autoUpdatesImports","autoUpdatesCssUrls","cleanSanityVersion","version","Error","log","info","installedVisionVersion","cleanVisionVersion","undefined","sanityDependencies","cssFile","name","mismatched","unresolvedPrerelease","length","versionMismatchWarning","map","mod","pkg","installed","remote","choice","choices","value","default","message","warning","error","exit","res","warn","envVarKeys","Object","keys","key","shouldClean","basePath","enabled","spin","start","force","recursive","cleanDuration","end","text","toFixed","succeed","trace","autoUpdates","cssUrls","imports","vendor","cwd","bundle","outputSize","chunks","flatMap","chunk","modules","renderedLength","reduce","sum","n","buildDuration","complete","slice","fail","String"],"mappings":"AAAA,SAAQA,EAAE,QAAO,mBAAkB;AACnC,OAAOC,UAAU,YAAW;AAC5B,SAAQC,SAAS,QAAO,YAAW;AAEnC,SACEC,UAAU,EACVC,yBAAyB,EACzBC,6BAA6B,EAC7BC,qBAAqB,EACrBC,uBAAuB,EACvBC,wBAAwB,EACxBC,gBAAgB,QACX,oCAAmC;AAC1C,SAAQC,6BAA6B,QAAO,kCAAiC;AAC7E,SAEEC,eAAe,EACfC,sBAAsB,EACtBC,QAAQ,EACRC,aAAa,QAGR,mBAAkB;AACzB,SAAQC,OAAO,EAAEC,UAAU,EAAEC,MAAM,EAAEC,OAAO,QAA6B,sBAAqB;AAE9F,SAAQC,mBAAmB,QAAO,8BAA6B;AAC/D,SAAQC,SAASC,WAAW,QAAO,SAAQ;AAE3C,SAAQC,QAAQ,QAAO,sBAAqB;AAC5C,SACEC,yBAAyB,QA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QACd,IAAI5E,OAAO;YACTvB,OAAOuC,GAAG,CAAC;YACXvC,OAAOuC,GAAG,CAACrD,kBAAkBC,kBAAkBqG,OAAOE,MAAM,EAAEU,KAAK,CAAC,GAAG;QACzE;IACF,EAAE,OAAOtC,OAAO;QACdW,KAAK4B,IAAI;QACTnB,MAAMpB,KAAK,CAACA;QACZ,MAAMF,UAAUE,iBAAiBxB,QAAQwB,MAAMF,OAAO,GAAG0C,OAAOxC;QAChElG,WAAW,CAAC,6BAA6B,CAAC,EAAE;YAACkG;QAAK;QAClD9D,OAAO8D,KAAK,CAAC,CAAC,+BAA+B,EAAEF,SAAS,EAAE;YAACG,MAAM;QAAC;IACpE;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/build/buildStudio.ts"],"sourcesContent":["import {rm} from 'node:fs/promises'\nimport path from 'node:path'\nimport {styleText} from 'node:util'\n\nimport {\n buildDebug,\n buildStaticFiles,\n checkRequiredDependencies,\n checkStudioDependencyVersions,\n formatModuleSizes,\n getAutoUpdatesCssUrls,\n getAutoUpdatesImportMap,\n resolveVendorBuildConfig,\n sortModulesBySize,\n StudioBuildTrace,\n} from '@sanity/cli-build/_internal/build'\nimport {getStudioEnvironmentVariables} from '@sanity/cli-build/_internal/env'\nimport {\n type CliConfig,\n getCliTelemetry,\n getLocalPackageVersion,\n getTimer,\n isInteractive,\n type Output,\n UserViteConfig,\n} from '@sanity/cli-core'\nimport {confirm, logSymbols, select, spinner, type SpinnerInstance} from '@sanity/cli-core/ux'\nimport {type DefineAppInput} from '@sanity/workbench-cli'\nimport {resolveWorkbenchApp} from '@sanity/workbench-cli/build'\nimport {parse as semverParse} from 'semver'\n\nimport {getAppId} from '../../util/appId.js'\nimport {\n compareDependencyVersions,\n CompareDependencyVersionsResult,\n} from '../../util/compareDependencyVersions.js'\nimport {determineIsApp} from '../../util/determineIsApp.js'\nimport {getPackageManagerChoice} from '../../util/packageManager/packageManagerChoice.js'\nimport {upgradePackages} from '../../util/packageManager/upgradePackages.js'\nimport {warnAboutMissingAppId} from '../../util/warnAboutMissingAppId.js'\nimport {determineBasePath} from './determineBasePath.js'\nimport {handlePrereleaseVersions} from './handlePrereleaseVersions.js'\nimport {type BuildOptions} from './types.js'\n\ninterface InternalBuildOptions {\n appId: string | undefined\n autoUpdatesEnabled: boolean\n checkAppId: () => void\n compareDependencyVersions: (\n packages: {name: string; version: string}[],\n ) => Promise<CompareDependencyVersionsResult>\n determineBasePath: () => string\n isApp: boolean\n isWorkbenchApp: boolean\n minify: boolean\n outDir: string | undefined\n output: Output\n reactCompiler: CliConfig['reactCompiler']\n schemaExtraction: CliConfig['schemaExtraction']\n services: DefineAppInput['services']\n sourceMap: boolean\n stats: boolean\n unattendedMode: boolean\n upgradePackages(options: {packages: [name: string, version: string][]}): Promise<void>\n views: DefineAppInput['views']\n vite: UserViteConfig | undefined\n workDir: string\n}\n\n/**\n * Build the Sanity Studio.\n *\n * @internal\n */\nexport async function buildStudio(options: BuildOptions): Promise<void> {\n const {calledFromDeploy, cliConfig, flags, outDir, output, workDir} = options\n\n // `views`/`services` live on the branded `unstable_defineApp` result — resolve\n // the workbench capability so it's gated on the brand, like the app build.\n const workbench = resolveWorkbenchApp(cliConfig)\n\n const appId = getAppId(cliConfig)\n\n const upgradePkgs = async (options: {\n packages: [name: string, version: string][]\n }): Promise<void> => {\n await upgradePackages(\n {\n packageManager: (await getPackageManagerChoice(workDir, {interactive: false})).chosen,\n packages: options.packages,\n },\n {output, workDir},\n )\n }\n\n await internalBuildStudio({\n appId,\n autoUpdatesEnabled: options.autoUpdatesEnabled,\n checkAppId: () => {\n // Warn if auto updates enabled but no appId configured.\n // Skip when called from deploy, since deploy handles appId itself\n // (prompts the user and tells them to add it to config).\n if (!appId && !calledFromDeploy) {\n warnAboutMissingAppId({appType: 'studio', output, projectId: cliConfig?.api?.projectId})\n }\n },\n compareDependencyVersions: (packages) => compareDependencyVersions(packages, workDir, {appId}),\n determineBasePath: () => determineBasePath(cliConfig, 'studio', output),\n isApp: determineIsApp(cliConfig),\n isWorkbenchApp: !!workbench,\n minify: Boolean(flags.minify),\n outDir,\n output,\n reactCompiler: cliConfig.reactCompiler,\n schemaExtraction: cliConfig.schemaExtraction,\n services: workbench?.services,\n sourceMap: Boolean(flags['source-maps']),\n stats: flags.stats,\n unattendedMode: Boolean(flags.yes),\n upgradePackages: upgradePkgs,\n views: workbench?.views,\n vite: cliConfig.vite,\n workDir,\n })\n}\n\n/**\n * Internal build studio that avoids depending on flags for CLI config.\n * @param options - options for the build\n */\nasync function internalBuildStudio(options: InternalBuildOptions): Promise<void> {\n buildDebug(`Building studio`)\n\n const timer = getTimer()\n const {\n appId,\n determineBasePath,\n isApp,\n minify,\n outDir,\n output,\n reactCompiler,\n schemaExtraction,\n services,\n sourceMap,\n stats,\n unattendedMode,\n upgradePackages,\n views,\n vite,\n workDir,\n } = options\n const defaultOutputDir = path.resolve(path.join(workDir, 'dist'))\n const outputDir = path.resolve(outDir || defaultOutputDir)\n\n await checkStudioDependencyVersions(workDir, output)\n\n // If the check resulted in a dependency install, the CLI command will be re-run,\n // thus we want to exit early\n const {installedSanityVersion} = await checkRequiredDependencies({\n isApp,\n output,\n workDir,\n })\n\n let autoUpdatesEnabled = options.autoUpdatesEnabled\n\n let autoUpdatesImports = {}\n let autoUpdatesCssUrls: string[] = []\n\n if (autoUpdatesEnabled) {\n // Get the clean version without build metadata: https://semver.org/#spec-item-10\n const cleanSanityVersion = semverParse(installedSanityVersion)?.version\n if (!cleanSanityVersion) {\n throw new Error(`Failed to parse installed Sanity version: ${installedSanityVersion}`)\n }\n\n output.log(`${logSymbols.info} Building with auto-updates enabled`)\n\n // Warn if auto updates enabled but no appId configured\n options.checkAppId()\n\n const installedVisionVersion = await getLocalPackageVersion('@sanity/vision', workDir)\n const cleanVisionVersion = installedVisionVersion\n ? semverParse(installedVisionVersion)?.version\n : undefined\n\n const sanityDependencies = [\n {cssFile: 'index.css', name: 'sanity', version: cleanSanityVersion},\n ...(cleanVisionVersion\n ? [{cssFile: 'index.css', name: '@sanity/vision' as const, version: cleanVisionVersion}]\n : [{name: '@sanity/vision' as const, version: cleanSanityVersion}]),\n ]\n autoUpdatesImports = getAutoUpdatesImportMap(sanityDependencies, {appId})\n\n autoUpdatesCssUrls = getAutoUpdatesCssUrls(sanityDependencies, {appId})\n\n // Check the versions\n const {mismatched, unresolvedPrerelease} =\n await options.compareDependencyVersions(sanityDependencies)\n\n if (unresolvedPrerelease.length > 0) {\n await handlePrereleaseVersions({output, unattendedMode, unresolvedPrerelease})\n autoUpdatesImports = {}\n autoUpdatesCssUrls = []\n autoUpdatesEnabled = false\n }\n\n if (mismatched.length > 0 && autoUpdatesEnabled) {\n const versionMismatchWarning =\n `The following local package versions are different from the versions currently served at runtime.\\n` +\n `When using auto updates, we recommend that you test locally with the same versions before deploying. \\n\\n` +\n `${mismatched.map((mod) => ` - ${mod.pkg} (local version: ${mod.installed}, runtime version: ${mod.remote})`).join('\\n')}`\n\n // If it is non-interactive or in unattended mode, we don't want to prompt\n if (isInteractive() && !unattendedMode) {\n const choice = await select({\n choices: [\n {\n name: `Upgrade local versions (recommended). You will need to run the build command again`,\n value: 'upgrade',\n },\n {\n name: `Upgrade and proceed with build`,\n value: 'upgrade-and-proceed',\n },\n {\n name: `Continue anyway`,\n value: 'continue',\n },\n {name: 'Cancel', value: 'cancel'},\n ],\n default: 'upgrade',\n message: styleText(\n 'yellow',\n `${logSymbols.warning} ${versionMismatchWarning}\\n\\nDo you want to upgrade local versions before deploying?`,\n ),\n })\n\n if (choice === 'cancel') {\n output.error('Declined to continue with build', {exit: 1})\n return\n }\n\n if (choice === 'upgrade' || choice === 'upgrade-and-proceed') {\n await upgradePackages({\n packages: mismatched.map((res) => [res.pkg, res.remote]),\n })\n\n if (choice === 'upgrade') {\n return\n }\n }\n } else {\n // if non-interactive or unattended, just show the warning\n output.warn(versionMismatchWarning)\n }\n }\n }\n\n const envVarKeys = Object.keys(getStudioEnvironmentVariables())\n if (envVarKeys.length > 0) {\n output.log('\\nIncluding the following environment variables as part of the JavaScript bundle:')\n for (const key of envVarKeys) {\n output.log(`- ${key}`)\n }\n output.log('')\n }\n\n let shouldClean = true\n if (outputDir !== defaultOutputDir && !unattendedMode && isInteractive()) {\n shouldClean = await confirm({\n default: true,\n message: `Do you want to delete the existing directory (${outputDir}) first?`,\n })\n }\n\n // Determine base path for built studio\n const basePath = determineBasePath()\n\n if (schemaExtraction?.enabled) {\n output.log(`${logSymbols.info} Building with schema extraction enabled`)\n }\n\n let spin: SpinnerInstance\n if (shouldClean) {\n timer.start('cleanOutputFolder')\n spin = spinner('Clean output folder').start()\n await rm(outputDir, {force: true, recursive: true})\n const cleanDuration = timer.end('cleanOutputFolder')\n spin.text = `Clean output folder (${cleanDuration.toFixed(0)}ms)`\n spin.succeed()\n }\n\n spin = spinner(`Build Sanity Studio`).start()\n\n const trace = getCliTelemetry().trace(StudioBuildTrace)\n trace.start()\n\n let autoUpdates\n if (autoUpdatesEnabled && !options.isWorkbenchApp) {\n autoUpdates = {\n cssUrls: autoUpdatesCssUrls,\n imports: autoUpdatesImports,\n vendor: await resolveVendorBuildConfig({cwd: workDir, isApp: false}),\n }\n }\n\n try {\n timer.start('bundleStudio')\n\n const bundle = await buildStaticFiles({\n autoUpdates,\n basePath,\n cwd: workDir,\n isWorkbenchApp: options.isWorkbenchApp,\n minify,\n outputDir,\n reactCompiler,\n schemaExtraction,\n services,\n sourceMap,\n views,\n vite,\n })\n\n trace.log({\n outputSize: bundle.chunks\n .flatMap((chunk) => chunk.modules.flatMap((mod) => mod.renderedLength))\n .reduce((sum, n) => sum + n, 0),\n })\n const buildDuration = timer.end('bundleStudio')\n\n spin.text = `Build Sanity Studio (${buildDuration.toFixed(0)}ms)`\n spin.succeed()\n\n trace.complete()\n if (stats) {\n output.log('\\nLargest module files:')\n output.log(formatModuleSizes(sortModulesBySize(bundle.chunks).slice(0, 15)))\n }\n } catch (error) {\n spin.fail()\n trace.error(error)\n const message = error instanceof Error ? error.message : String(error)\n buildDebug(`Failed to build Sanity Studio`, {error})\n output.error(`Failed to build Sanity Studio: ${message}`, {exit: 1})\n }\n}\n"],"names":["rm","path","styleText","buildDebug","buildStaticFiles","checkRequiredDependencies","checkStudioDependencyVersions","formatModuleSizes","getAutoUpdatesCssUrls","getAutoUpdatesImportMap","resolveVendorBuildConfig","sortModulesBySize","StudioBuildTrace","getStudioEnvironmentVariables","getCliTelemetry","getLocalPackageVersion","getTimer","isInteractive","confirm","logSymbols","select","spinner","resolveWorkbenchApp","parse","semverParse","getAppId","compareDependencyVersions","determineIsApp","getPackageManagerChoice","upgradePackages","warnAboutMissingAppId","determineBasePath","handlePrereleaseVersions","buildStudio","options","calledFromDeploy","cliConfig","flags","outDir","output","workDir","workbench","appId","upgradePkgs","packageManager","interactive","chosen","packages","internalBuildStudio","autoUpdatesEnabled","checkAppId","appType","projectId","api","isApp","isWorkbenchApp","minify","Boolean","reactCompiler","schemaExtraction","services","sourceMap","stats","unattendedMode","yes","views","vite","timer","defaultOutputDir","resolve","join","outputDir","installedSanityVersion","autoUpdatesImports","autoUpdatesCssUrls","cleanSanityVersion","version","Error","log","info","installedVisionVersion","cleanVisionVersion","undefined","sanityDependencies","cssFile","name","mismatched","unresolvedPrerelease","length","versionMismatchWarning","map","mod","pkg","installed","remote","choice","choices","value","default","message","warning","error","exit","res","warn","envVarKeys","Object","keys","key","shouldClean","basePath","enabled","spin","start","force","recursive","cleanDuration","end","text","toFixed","succeed","trace","autoUpdates","cssUrls","imports","vendor","cwd","bundle","outputSize","chunks","flatMap","chunk","modules","renderedLength","reduce","sum","n","buildDuration","complete","slice","fail","String"],"mappings":"AAAA,SAAQA,EAAE,QAAO,mBAAkB;AACnC,OAAOC,UAAU,YAAW;AAC5B,SAAQC,SAAS,QAAO,YAAW;AAEnC,SACEC,UAAU,EACVC,gBAAgB,EAChBC,yBAAyB,EACzBC,6BAA6B,EAC7BC,iBAAiB,EACjBC,qBAAqB,EACrBC,uBAAuB,EACvBC,wBAA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,CAACF,OAAO,CAAC,CAACvC,MAAQA,IAAI0C,cAAc,GACpEC,MAAM,CAAC,CAACC,KAAKC,IAAMD,MAAMC,GAAG;QACjC;QACA,MAAMC,gBAAgBtE,MAAMkD,GAAG,CAAC;QAEhCL,KAAKM,IAAI,GAAG,CAAC,qBAAqB,EAAEmB,cAAclB,OAAO,CAAC,GAAG,GAAG,CAAC;QACjEP,KAAKQ,OAAO;QAEZC,MAAMiB,QAAQ;QACd,IAAI5E,OAAO;YACTvB,OAAOuC,GAAG,CAAC;YACXvC,OAAOuC,GAAG,CAACvE,kBAAkBI,kBAAkBoH,OAAOE,MAAM,EAAEU,KAAK,CAAC,GAAG;QACzE;IACF,EAAE,OAAOtC,OAAO;QACdW,KAAK4B,IAAI;QACTnB,MAAMpB,KAAK,CAACA;QACZ,MAAMF,UAAUE,iBAAiBxB,QAAQwB,MAAMF,OAAO,GAAG0C,OAAOxC;QAChElG,WAAW,CAAC,6BAA6B,CAAC,EAAE;YAACkG;QAAK;QAClD9D,OAAO8D,KAAK,CAAC,CAAC,+BAA+B,EAAEF,SAAS,EAAE;YAACG,MAAM;QAAC;IACpE;AACF"}
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/cli",
|
|
3
|
-
"version": "7.4.
|
|
3
|
+
"version": "7.4.2",
|
|
4
4
|
"description": "Sanity CLI tool for managing Sanity projects and organizations",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -114,13 +114,13 @@
|
|
|
114
114
|
"tinyglobby": "^0.2.17",
|
|
115
115
|
"tsx": "^4.22.4",
|
|
116
116
|
"typeid-js": "^1.2.0",
|
|
117
|
-
"vite": "
|
|
117
|
+
"vite": "8.1.0",
|
|
118
118
|
"which": "^6.0.1",
|
|
119
119
|
"yaml": "^2.9.0",
|
|
120
120
|
"zod": "^4.4.3",
|
|
121
|
-
"@sanity/
|
|
122
|
-
"@sanity/cli-core": "^2.1.
|
|
123
|
-
"@sanity/cli
|
|
121
|
+
"@sanity/cli-build": "^2.0.0",
|
|
122
|
+
"@sanity/cli-core": "^2.1.2",
|
|
123
|
+
"@sanity/workbench-cli": "^1.1.2"
|
|
124
124
|
},
|
|
125
125
|
"devDependencies": {
|
|
126
126
|
"@eslint/compat": "^2.1.0",
|
|
@@ -156,7 +156,7 @@
|
|
|
156
156
|
"vitest": "^4.1.9",
|
|
157
157
|
"@repo/package.config": "0.0.1",
|
|
158
158
|
"@repo/tsconfig": "3.70.0",
|
|
159
|
-
"@sanity/cli-test": "2.0.
|
|
159
|
+
"@sanity/cli-test": "2.0.2",
|
|
160
160
|
"@sanity/eslint-config-cli": "1.1.2"
|
|
161
161
|
},
|
|
162
162
|
"peerDependencies": {
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { buildDebug, copyDir, extendViteConfigWithUserConfig, finalizeViteConfig, getViteConfig, resolveEntries, writeFavicons, writeSanityRuntime } from '@sanity/cli-build/_internal/build';
|
|
3
|
-
import { getAppEnvironmentVariables, getStudioEnvironmentVariables } from '@sanity/cli-build/_internal/env';
|
|
4
|
-
import { build, createBuilder } from 'vite';
|
|
5
|
-
/**
|
|
6
|
-
* Builds static files
|
|
7
|
-
*
|
|
8
|
-
* @internal
|
|
9
|
-
*/ export async function buildStaticFiles(options) {
|
|
10
|
-
const { appTitle, autoUpdates, basePath, cwd, entry, isApp, isWorkbenchApp, minify = true, outputDir, reactCompiler, schemaExtraction, services, sourceMap = false, views, vite: extendViteConfig } = options;
|
|
11
|
-
const mode = 'production';
|
|
12
|
-
/* Federation builds only produce the federation environment
|
|
13
|
-
* (remote-entry, mf-manifest) — skip client-specific steps like
|
|
14
|
-
* runtime generation, static file copies, and favicons.
|
|
15
|
-
*/ if (isWorkbenchApp) {
|
|
16
|
-
buildDebug('Resolving entries for federation build');
|
|
17
|
-
const entries = await resolveEntries({
|
|
18
|
-
cwd,
|
|
19
|
-
entry,
|
|
20
|
-
isApp,
|
|
21
|
-
isWorkbenchApp
|
|
22
|
-
});
|
|
23
|
-
buildDebug('Resolving vite config (federation)');
|
|
24
|
-
let viteConfig = await getViteConfig({
|
|
25
|
-
basePath,
|
|
26
|
-
cwd,
|
|
27
|
-
entries,
|
|
28
|
-
getEnvironmentVariables,
|
|
29
|
-
isApp,
|
|
30
|
-
isWorkbenchApp,
|
|
31
|
-
minify,
|
|
32
|
-
mode,
|
|
33
|
-
outputDir,
|
|
34
|
-
reactCompiler,
|
|
35
|
-
// Schema extraction is a build-time artifact, not a client-specific step,
|
|
36
|
-
// so a federated studio extracts its schema like the legacy studio build.
|
|
37
|
-
schemaExtraction,
|
|
38
|
-
services,
|
|
39
|
-
sourceMap,
|
|
40
|
-
views
|
|
41
|
-
});
|
|
42
|
-
// Apply the user's Vite config so plugins like `@vanilla-extract/vite-plugin`
|
|
43
|
-
// transform source files before the federation environment is bundled.
|
|
44
|
-
// `finalizeViteConfig` is intentionally skipped: the federation environment
|
|
45
|
-
// has its own entry and does not use `.sanity/runtime/app.js`.
|
|
46
|
-
if (extendViteConfig) {
|
|
47
|
-
viteConfig = await extendViteConfigWithUserConfig({
|
|
48
|
-
command: 'build',
|
|
49
|
-
mode
|
|
50
|
-
}, viteConfig, extendViteConfig);
|
|
51
|
-
}
|
|
52
|
-
buildDebug('Bundling federation environment');
|
|
53
|
-
const builder = await createBuilder(viteConfig);
|
|
54
|
-
await builder.buildApp();
|
|
55
|
-
buildDebug('Bundling complete');
|
|
56
|
-
// TODO: add stats here
|
|
57
|
-
return {
|
|
58
|
-
chunks: []
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
buildDebug('Writing Sanity runtime files');
|
|
62
|
-
const { entries } = await writeSanityRuntime({
|
|
63
|
-
appTitle,
|
|
64
|
-
basePath,
|
|
65
|
-
cwd,
|
|
66
|
-
entry,
|
|
67
|
-
isApp,
|
|
68
|
-
isWorkbenchApp,
|
|
69
|
-
reactStrictMode: false,
|
|
70
|
-
watch: false
|
|
71
|
-
});
|
|
72
|
-
function getEnvironmentVariables() {
|
|
73
|
-
return isApp ? getAppEnvironmentVariables({
|
|
74
|
-
jsonEncode: true,
|
|
75
|
-
prefix: 'process.env.'
|
|
76
|
-
}) : getStudioEnvironmentVariables({
|
|
77
|
-
jsonEncode: true,
|
|
78
|
-
prefix: 'process.env.'
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
buildDebug('Resolving vite config');
|
|
82
|
-
let viteConfig = await getViteConfig({
|
|
83
|
-
autoUpdates,
|
|
84
|
-
basePath,
|
|
85
|
-
cwd,
|
|
86
|
-
entries,
|
|
87
|
-
getEnvironmentVariables,
|
|
88
|
-
isApp,
|
|
89
|
-
isWorkbenchApp,
|
|
90
|
-
minify,
|
|
91
|
-
mode,
|
|
92
|
-
outputDir,
|
|
93
|
-
reactCompiler,
|
|
94
|
-
schemaExtraction,
|
|
95
|
-
sourceMap
|
|
96
|
-
});
|
|
97
|
-
if (extendViteConfig) {
|
|
98
|
-
const defaultViteConfig = viteConfig;
|
|
99
|
-
viteConfig = await extendViteConfigWithUserConfig({
|
|
100
|
-
command: 'build',
|
|
101
|
-
mode
|
|
102
|
-
}, viteConfig, extendViteConfig);
|
|
103
|
-
viteConfig = await finalizeViteConfig(viteConfig, defaultViteConfig);
|
|
104
|
-
}
|
|
105
|
-
const fromPath = path.join(cwd, 'static');
|
|
106
|
-
// Copy files placed in /static to the built /static
|
|
107
|
-
buildDebug(`Copying static files from ${fromPath} to output dir`);
|
|
108
|
-
const staticPath = path.join(outputDir, 'static');
|
|
109
|
-
await copyDir(fromPath, staticPath);
|
|
110
|
-
// Write favicons, not overwriting ones that already exist, to static folder
|
|
111
|
-
buildDebug('Writing favicons to output dir');
|
|
112
|
-
const faviconBasePath = `${basePath.replace(/\/+$/, '')}/static`;
|
|
113
|
-
await writeFavicons(faviconBasePath, staticPath);
|
|
114
|
-
buildDebug('Bundling using vite');
|
|
115
|
-
const bundle = await build(viteConfig);
|
|
116
|
-
buildDebug('Bundling complete');
|
|
117
|
-
// For typescript only - this shouldn't ever be the case given we're not watching
|
|
118
|
-
if (Array.isArray(bundle) || !('output' in bundle)) {
|
|
119
|
-
return {
|
|
120
|
-
chunks: []
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
const stats = [];
|
|
124
|
-
for (const chunk of bundle.output){
|
|
125
|
-
if (chunk.type !== 'chunk') {
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
128
|
-
stats.push({
|
|
129
|
-
modules: Object.entries(chunk.modules).map(([rawFilePath, chunkModule])=>{
|
|
130
|
-
const filePath = rawFilePath.startsWith('\u0000') ? rawFilePath.slice('\u0000'.length) : rawFilePath;
|
|
131
|
-
return {
|
|
132
|
-
name: path.isAbsolute(filePath) ? path.relative(cwd, filePath) : filePath,
|
|
133
|
-
renderedLength: chunkModule.renderedLength
|
|
134
|
-
};
|
|
135
|
-
}),
|
|
136
|
-
name: chunk.name
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
return {
|
|
140
|
-
chunks: stats
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
//# sourceMappingURL=buildStaticFiles.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/build/buildStaticFiles.ts"],"sourcesContent":["import path from 'node:path'\n\nimport {\n type AutoUpdatesBuildConfig,\n buildDebug,\n copyDir,\n extendViteConfigWithUserConfig,\n finalizeViteConfig,\n getViteConfig,\n resolveEntries,\n writeFavicons,\n writeSanityRuntime,\n} from '@sanity/cli-build/_internal/build'\nimport {\n getAppEnvironmentVariables,\n getStudioEnvironmentVariables,\n} from '@sanity/cli-build/_internal/env'\nimport {type CliConfig, type UserViteConfig} from '@sanity/cli-core'\nimport {type DefineAppInput} from '@sanity/workbench-cli'\nimport {type PluginOptions as ReactCompilerConfig} from 'babel-plugin-react-compiler'\nimport {build, createBuilder} from 'vite'\n\nexport interface ChunkModule {\n name: string\n renderedLength: number\n}\n\nexport interface ChunkStats {\n modules: ChunkModule[]\n name: string\n}\n\ninterface StaticBuildOptions {\n basePath: string\n cwd: string\n outputDir: string\n\n appTitle?: string\n autoUpdates?: AutoUpdatesBuildConfig\n entry?: string\n isApp?: boolean\n /** Workbench app (opted in via `unstable_defineApp`) — drives the federation build. */\n isWorkbenchApp?: boolean\n minify?: boolean\n profile?: boolean\n reactCompiler?: ReactCompilerConfig\n schemaExtraction?: CliConfig['schemaExtraction']\n services?: DefineAppInput['services']\n sourceMap?: boolean\n views?: DefineAppInput['views']\n vite?: UserViteConfig\n}\n\n/**\n * Builds static files\n *\n * @internal\n */\nexport async function buildStaticFiles(\n options: StaticBuildOptions,\n): Promise<{chunks: ChunkStats[]}> {\n const {\n appTitle,\n autoUpdates,\n basePath,\n cwd,\n entry,\n isApp,\n isWorkbenchApp,\n minify = true,\n outputDir,\n reactCompiler,\n schemaExtraction,\n services,\n sourceMap = false,\n views,\n vite: extendViteConfig,\n } = options\n\n const mode = 'production'\n\n /* Federation builds only produce the federation environment\n * (remote-entry, mf-manifest) — skip client-specific steps like\n * runtime generation, static file copies, and favicons.\n */\n if (isWorkbenchApp) {\n buildDebug('Resolving entries for federation build')\n const entries = await resolveEntries({cwd, entry, isApp, isWorkbenchApp})\n\n buildDebug('Resolving vite config (federation)')\n let viteConfig = await getViteConfig({\n basePath,\n cwd,\n entries,\n getEnvironmentVariables,\n isApp,\n isWorkbenchApp,\n minify,\n mode,\n outputDir,\n reactCompiler,\n // Schema extraction is a build-time artifact, not a client-specific step,\n // so a federated studio extracts its schema like the legacy studio build.\n schemaExtraction,\n services,\n sourceMap,\n views,\n })\n\n // Apply the user's Vite config so plugins like `@vanilla-extract/vite-plugin`\n // transform source files before the federation environment is bundled.\n // `finalizeViteConfig` is intentionally skipped: the federation environment\n // has its own entry and does not use `.sanity/runtime/app.js`.\n if (extendViteConfig) {\n viteConfig = await extendViteConfigWithUserConfig(\n {command: 'build', mode},\n viteConfig,\n extendViteConfig,\n )\n }\n\n buildDebug('Bundling federation environment')\n const builder = await createBuilder(viteConfig)\n await builder.buildApp()\n buildDebug('Bundling complete')\n // TODO: add stats here\n return {chunks: []}\n }\n\n buildDebug('Writing Sanity runtime files')\n const {entries} = await writeSanityRuntime({\n appTitle,\n basePath,\n cwd,\n entry,\n isApp,\n isWorkbenchApp,\n reactStrictMode: false,\n watch: false,\n })\n\n function getEnvironmentVariables() {\n return isApp\n ? getAppEnvironmentVariables({jsonEncode: true, prefix: 'process.env.'})\n : getStudioEnvironmentVariables({jsonEncode: true, prefix: 'process.env.'})\n }\n\n buildDebug('Resolving vite config')\n let viteConfig = await getViteConfig({\n autoUpdates,\n basePath,\n cwd,\n entries,\n getEnvironmentVariables,\n isApp,\n isWorkbenchApp,\n minify,\n mode,\n outputDir,\n reactCompiler,\n schemaExtraction,\n sourceMap,\n })\n\n if (extendViteConfig) {\n const defaultViteConfig = viteConfig\n viteConfig = await extendViteConfigWithUserConfig(\n {command: 'build', mode},\n viteConfig,\n extendViteConfig,\n )\n viteConfig = await finalizeViteConfig(viteConfig, defaultViteConfig)\n }\n\n const fromPath = path.join(cwd, 'static')\n // Copy files placed in /static to the built /static\n buildDebug(`Copying static files from ${fromPath} to output dir`)\n const staticPath = path.join(outputDir, 'static')\n await copyDir(fromPath, staticPath)\n\n // Write favicons, not overwriting ones that already exist, to static folder\n buildDebug('Writing favicons to output dir')\n const faviconBasePath = `${basePath.replace(/\\/+$/, '')}/static`\n await writeFavicons(faviconBasePath, staticPath)\n\n buildDebug('Bundling using vite')\n const bundle = await build(viteConfig)\n buildDebug('Bundling complete')\n\n // For typescript only - this shouldn't ever be the case given we're not watching\n if (Array.isArray(bundle) || !('output' in bundle)) {\n return {chunks: []}\n }\n\n const stats: ChunkStats[] = []\n for (const chunk of bundle.output) {\n if (chunk.type !== 'chunk') {\n continue\n }\n\n stats.push({\n modules: Object.entries(chunk.modules).map(([rawFilePath, chunkModule]) => {\n const filePath = rawFilePath.startsWith('\\u0000')\n ? rawFilePath.slice('\\u0000'.length)\n : rawFilePath\n\n return {\n name: path.isAbsolute(filePath) ? path.relative(cwd, filePath) : filePath,\n renderedLength: chunkModule.renderedLength,\n }\n }),\n name: chunk.name,\n })\n }\n\n return {chunks: stats}\n}\n"],"names":["path","buildDebug","copyDir","extendViteConfigWithUserConfig","finalizeViteConfig","getViteConfig","resolveEntries","writeFavicons","writeSanityRuntime","getAppEnvironmentVariables","getStudioEnvironmentVariables","build","createBuilder","buildStaticFiles","options","appTitle","autoUpdates","basePath","cwd","entry","isApp","isWorkbenchApp","minify","outputDir","reactCompiler","schemaExtraction","services","sourceMap","views","vite","extendViteConfig","mode","entries","viteConfig","getEnvironmentVariables","command","builder","buildApp","chunks","reactStrictMode","watch","jsonEncode","prefix","defaultViteConfig","fromPath","join","staticPath","faviconBasePath","replace","bundle","Array","isArray","stats","chunk","output","type","push","modules","Object","map","rawFilePath","chunkModule","filePath","startsWith","slice","length","name","isAbsolute","relative","renderedLength"],"mappings":"AAAA,OAAOA,UAAU,YAAW;AAE5B,SAEEC,UAAU,EACVC,OAAO,EACPC,8BAA8B,EAC9BC,kBAAkB,EAClBC,aAAa,EACbC,cAAc,EACdC,aAAa,EACbC,kBAAkB,QACb,oCAAmC;AAC1C,SACEC,0BAA0B,EAC1BC,6BAA6B,QACxB,kCAAiC;AAIxC,SAAQC,KAAK,EAAEC,aAAa,QAAO,OAAM;AAiCzC;;;;CAIC,GACD,OAAO,eAAeC,iBACpBC,OAA2B;IAE3B,MAAM,EACJC,QAAQ,EACRC,WAAW,EACXC,QAAQ,EACRC,GAAG,EACHC,KAAK,EACLC,KAAK,EACLC,cAAc,EACdC,SAAS,IAAI,EACbC,SAAS,EACTC,aAAa,EACbC,gBAAgB,EAChBC,QAAQ,EACRC,YAAY,KAAK,EACjBC,KAAK,EACLC,MAAMC,gBAAgB,EACvB,GAAGhB;IAEJ,MAAMiB,OAAO;IAEb;;;GAGC,GACD,IAAIV,gB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C,SAAS,cAAc,CAAC;IAChE,MAAME,aAAa9C,KAAK6C,IAAI,CAACtB,WAAW;IACxC,MAAMrB,QAAQ0C,UAAUE;IAExB,4EAA4E;IAC5E7C,WAAW;IACX,MAAM8C,kBAAkB,GAAG9B,SAAS+B,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC;IAChE,MAAMzC,cAAcwC,iBAAiBD;IAErC7C,WAAW;IACX,MAAMgD,SAAS,MAAMtC,MAAMsB;IAC3BhC,WAAW;IAEX,iFAAiF;IACjF,IAAIiD,MAAMC,OAAO,CAACF,WAAW,CAAE,CAAA,YAAYA,MAAK,GAAI;QAClD,OAAO;YAACX,QAAQ,EAAE;QAAA;IACpB;IAEA,MAAMc,QAAsB,EAAE;IAC9B,KAAK,MAAMC,SAASJ,OAAOK,MAAM,CAAE;QACjC,IAAID,MAAME,IAAI,KAAK,SAAS;YAC1B;QACF;QAEAH,MAAMI,IAAI,CAAC;YACTC,SAASC,OAAO1B,OAAO,CAACqB,MAAMI,OAAO,EAAEE,GAAG,CAAC,CAAC,CAACC,aAAaC,YAAY;gBACpE,MAAMC,WAAWF,YAAYG,UAAU,CAAC,YACpCH,YAAYI,KAAK,CAAC,SAASC,MAAM,IACjCL;gBAEJ,OAAO;oBACLM,MAAMlE,KAAKmE,UAAU,CAACL,YAAY9D,KAAKoE,QAAQ,CAAClD,KAAK4C,YAAYA;oBACjEO,gBAAgBR,YAAYQ,cAAc;gBAC5C;YACF;YACAH,MAAMb,MAAMa,IAAI;QAClB;IACF;IAEA,OAAO;QAAC5B,QAAQc;IAAK;AACvB"}
|
package/dist/util/formatSize.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/util/formatSize.ts"],"sourcesContent":["import {styleText} from 'node:util'\n\n/**\n * Formats bytes to kB\n *\n * @internal\n */\nexport function formatSize(bytes: number): string {\n return styleText('cyan', `${(bytes / 1024).toFixed(0)} kB`)\n}\n"],"names":["styleText","formatSize","bytes","toFixed"],"mappings":"AAAA,SAAQA,SAAS,QAAO,YAAW;AAEnC;;;;CAIC,GACD,OAAO,SAASC,WAAWC,KAAa;IACtC,OAAOF,UAAU,QAAQ,GAAG,AAACE,CAAAA,QAAQ,IAAG,EAAGC,OAAO,CAAC,GAAG,GAAG,CAAC;AAC5D"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { formatSize } from './formatSize.js';
|
|
2
|
-
export function formatModuleSizes(modules) {
|
|
3
|
-
const lines = [];
|
|
4
|
-
for (const mod of modules){
|
|
5
|
-
lines.push(` - ${formatModuleName(mod.name)} (${formatSize(mod.renderedLength)})`);
|
|
6
|
-
}
|
|
7
|
-
return lines.join('\n');
|
|
8
|
-
}
|
|
9
|
-
function formatModuleName(modName) {
|
|
10
|
-
const delimiter = '/node_modules/';
|
|
11
|
-
const nodeIndex = modName.lastIndexOf(delimiter);
|
|
12
|
-
return nodeIndex === -1 ? modName : modName.slice(nodeIndex + delimiter.length);
|
|
13
|
-
}
|
|
14
|
-
export function sortModulesBySize(chunks) {
|
|
15
|
-
return chunks.flatMap((chunk)=>chunk.modules).toSorted((modA, modB)=>modB.renderedLength - modA.renderedLength);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
//# sourceMappingURL=moduleFormatUtils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/util/moduleFormatUtils.ts"],"sourcesContent":["import {type ChunkModule, type ChunkStats} from '../actions/build/buildStaticFiles.js'\nimport {formatSize} from './formatSize.js'\n\nexport function formatModuleSizes(modules: ChunkModule[]): string {\n const lines: string[] = []\n for (const mod of modules) {\n lines.push(` - ${formatModuleName(mod.name)} (${formatSize(mod.renderedLength)})`)\n }\n\n return lines.join('\\n')\n}\n\nfunction formatModuleName(modName: string): string {\n const delimiter = '/node_modules/'\n const nodeIndex = modName.lastIndexOf(delimiter)\n return nodeIndex === -1 ? modName : modName.slice(nodeIndex + delimiter.length)\n}\n\nexport function sortModulesBySize(chunks: ChunkStats[]): ChunkModule[] {\n return chunks\n .flatMap((chunk) => chunk.modules)\n .toSorted((modA, modB) => modB.renderedLength - modA.renderedLength)\n}\n"],"names":["formatSize","formatModuleSizes","modules","lines","mod","push","formatModuleName","name","renderedLength","join","modName","delimiter","nodeIndex","lastIndexOf","slice","length","sortModulesBySize","chunks","flatMap","chunk","toSorted","modA","modB"],"mappings":"AACA,SAAQA,UAAU,QAAO,kBAAiB;AAE1C,OAAO,SAASC,kBAAkBC,OAAsB;IACtD,MAAMC,QAAkB,EAAE;IAC1B,KAAK,MAAMC,OAAOF,QAAS;QACzBC,MAAME,IAAI,CAAC,CAAC,GAAG,EAAEC,iBAAiBF,IAAIG,IAAI,EAAE,EAAE,EAAEP,WAAWI,IAAII,cAAc,EAAE,CAAC,CAAC;IACnF;IAEA,OAAOL,MAAMM,IAAI,CAAC;AACpB;AAEA,SAASH,iBAAiBI,OAAe;IACvC,MAAMC,YAAY;IAClB,MAAMC,YAAYF,QAAQG,WAAW,CAACF;IACtC,OAAOC,cAAc,CAAC,IAAIF,UAAUA,QAAQI,KAAK,CAACF,YAAYD,UAAUI,MAAM;AAChF;AAEA,OAAO,SAASC,kBAAkBC,MAAoB;IACpD,OAAOA,OACJC,OAAO,CAAC,CAACC,QAAUA,MAAMjB,OAAO,EAChCkB,QAAQ,CAAC,CAACC,MAAMC,OAASA,KAAKd,cAAc,GAAGa,KAAKb,cAAc;AACvE"}
|