From 09723d81860ad38bfdb86995a0aeca3729d16312 Mon Sep 17 00:00:00 2001 From: Carolina Gonzalez Date: Tue, 4 Feb 2025 08:27:05 -0500 Subject: [PATCH] refactor: switch ternary to isCoreApp --- .../init-project/bootstrapLocalTemplate.ts | 24 +++++++++---------- ...emplate.ts => determineCoreAppTemplate.ts} | 6 ++--- .../src/actions/init-project/initProject.ts | 11 ++++----- .../actions/init-project/templates/coreApp.ts | 4 +--- packages/@sanity/cli/test/init.test.ts | 4 ++-- .../cli/actions/build/buildAction.ts | 8 +++---- .../_internal/cli/actions/dev/devAction.ts | 8 +++---- .../cli/commands/start/startCommand.ts | 4 ++-- .../_internal/cli/server/buildStaticFiles.ts | 8 +++---- .../src/_internal/cli/server/devServer.ts | 10 ++++---- .../_internal/cli/server/getEntryModule.ts | 12 +++------- .../src/_internal/cli/server/getViteConfig.ts | 8 +++---- .../src/_internal/cli/server/previewServer.ts | 8 +++---- .../_internal/cli/server/renderDocument.tsx | 23 +++++++----------- .../src/_internal/cli/server/runtime.ts | 10 ++++---- .../vite/plugin-sanity-build-entries.ts | 6 ++--- .../cli/util/checkRequiredDependencies.ts | 7 ++++++ .../sanity/src/_internal/cli/util/servers.ts | 6 ++--- 18 files changed, 79 insertions(+), 88 deletions(-) rename packages/@sanity/cli/src/actions/init-project/{determineStudioTemplate.ts => determineCoreAppTemplate.ts} (62%) diff --git a/packages/@sanity/cli/src/actions/init-project/bootstrapLocalTemplate.ts b/packages/@sanity/cli/src/actions/init-project/bootstrapLocalTemplate.ts index e2bf0135851..6572eb537d6 100644 --- a/packages/@sanity/cli/src/actions/init-project/bootstrapLocalTemplate.ts +++ b/packages/@sanity/cli/src/actions/init-project/bootstrapLocalTemplate.ts @@ -13,7 +13,7 @@ import {createCliConfig} from './createCliConfig' import {createCoreAppCliConfig} from './createCoreAppCliConfig' import {createPackageManifest} from './createPackageManifest' import {createStudioConfig, type GenerateConfigOptions} from './createStudioConfig' -import {determineStudioTemplate} from './determineStudioTemplate' +import {determineCoreAppTemplate} from './determineCoreAppTemplate' import {type ProjectTemplate} from './initProject' import templates from './templates' import {updateInitialTemplateMetadata} from './updateInitialTemplateMetadata' @@ -40,7 +40,7 @@ export async function bootstrapLocalTemplate( const {outputPath, templateName, useTypeScript, packageName, variables} = opts const sourceDir = path.join(templatesDir, templateName) const sharedDir = path.join(templatesDir, 'shared') - const isStudioTemplate = determineStudioTemplate(templateName) + const isCoreAppTemplate = determineCoreAppTemplate(templateName) // Check that we have a template info file (dependencies, plugins etc) const template = templates[templateName] @@ -83,8 +83,8 @@ export async function bootstrapLocalTemplate( // Resolve latest versions of Sanity-dependencies spinner = output.spinner('Resolving latest module versions').start() const dependencyVersions = await resolveLatestVersions({ - ...(isStudioTemplate ? studioDependencies.dependencies : {}), - ...(isStudioTemplate ? studioDependencies.devDependencies : {}), + ...(isCoreAppTemplate ? {} : studioDependencies.dependencies), + ...(isCoreAppTemplate ? {} : studioDependencies.devDependencies), ...(template.dependencies || {}), ...(template.devDependencies || {}), }) @@ -92,7 +92,7 @@ export async function bootstrapLocalTemplate( // Use the resolved version for the given dependency const dependencies = Object.keys({ - ...(isStudioTemplate ? studioDependencies.dependencies : {}), + ...(isCoreAppTemplate ? {} : studioDependencies.dependencies), ...template.dependencies, }).reduce( (deps, dependency) => { @@ -103,7 +103,7 @@ export async function bootstrapLocalTemplate( ) const devDependencies = Object.keys({ - ...(isStudioTemplate ? studioDependencies.devDependencies : {}), + ...(isCoreAppTemplate ? {} : studioDependencies.devDependencies), ...template.devDependencies, }).reduce( (deps, dependency) => { @@ -128,22 +128,22 @@ export async function bootstrapLocalTemplate( }) // ...and a CLI config (`sanity.cli.[ts|js]`) - const cliConfig = isStudioTemplate - ? createCliConfig({ + const cliConfig = isCoreAppTemplate + ? createCoreAppCliConfig({appLocation: template.appLocation!}) + : createCliConfig({ projectId: variables.projectId, dataset: variables.dataset, autoUpdates: variables.autoUpdates, }) - : createCoreAppCliConfig({appLocation: template.appLocation!}) // Write non-template files to disc const codeExt = useTypeScript ? 'ts' : 'js' await Promise.all( [ ...[ - isStudioTemplate - ? writeFileIfNotExists(`sanity.config.${codeExt}`, studioConfig) - : Promise.resolve(null), + isCoreAppTemplate + ? Promise.resolve(null) + : writeFileIfNotExists(`sanity.config.${codeExt}`, studioConfig), ], writeFileIfNotExists(`sanity.cli.${codeExt}`, cliConfig), writeFileIfNotExists('package.json', packageManifest), diff --git a/packages/@sanity/cli/src/actions/init-project/determineStudioTemplate.ts b/packages/@sanity/cli/src/actions/init-project/determineCoreAppTemplate.ts similarity index 62% rename from packages/@sanity/cli/src/actions/init-project/determineStudioTemplate.ts rename to packages/@sanity/cli/src/actions/init-project/determineCoreAppTemplate.ts index 7135788a8b8..7ae7b42886d 100644 --- a/packages/@sanity/cli/src/actions/init-project/determineStudioTemplate.ts +++ b/packages/@sanity/cli/src/actions/init-project/determineCoreAppTemplate.ts @@ -1,4 +1,4 @@ -const nonStudioTemplates = ['core-app'] +const coreAppTemplates = ['core-app'] /** * Determine if a given template is a studio template. @@ -8,6 +8,6 @@ const nonStudioTemplates = ['core-app'] * @param templateName - Name of the template * @returns boolean indicating if the template is a studio template */ -export function determineStudioTemplate(templateName: string): boolean { - return !nonStudioTemplates.includes(templateName) +export function determineCoreAppTemplate(templateName: string): boolean { + return coreAppTemplates.includes(templateName) } diff --git a/packages/@sanity/cli/src/actions/init-project/initProject.ts b/packages/@sanity/cli/src/actions/init-project/initProject.ts index 824b1d3eea0..b419dd74311 100644 --- a/packages/@sanity/cli/src/actions/init-project/initProject.ts +++ b/packages/@sanity/cli/src/actions/init-project/initProject.ts @@ -49,7 +49,7 @@ import {createProject} from '../project/createProject' import {bootstrapLocalTemplate} from './bootstrapLocalTemplate' import {bootstrapRemoteTemplate} from './bootstrapRemoteTemplate' import {type GenerateConfigOptions} from './createStudioConfig' -import {determineStudioTemplate} from './determineStudioTemplate' +import {determineCoreAppTemplate} from './determineCoreAppTemplate' import {absolutify, validateEmptyPath} from './fsUtils' import {tryGitInit} from './git' import {promptForDatasetName} from './promptForDatasetName' @@ -274,7 +274,7 @@ export default async function initSanity( const flags = await prepareFlags() // skip project / dataset prompting - const isStudioTemplate = cliFlags.template ? determineStudioTemplate(cliFlags.template) : true // Default to true + const isCoreAppTemplate = cliFlags.template ? determineCoreAppTemplate(cliFlags.template) : false // Default to false // We're authenticated, now lets select or create a project const {projectId, displayName, isFirstProject, datasetName, schemaUrl} = await getProjectDetails() @@ -661,13 +661,13 @@ export default async function initSanity( if (isCurrentDir) { print(`\n${chalk.green('Success!')} Now, use this command to continue:\n`) print( - `${chalk.cyan(devCommand)} - to run ${isStudioTemplate ? 'Sanity Studio' : 'your Sanity application'}\n`, + `${chalk.cyan(devCommand)} - to run ${isCoreAppTemplate ? 'your Sanity application' : 'Sanity Studio'}\n`, ) } else { print(`\n${chalk.green('Success!')} Now, use these commands to continue:\n`) print(`First: ${chalk.cyan(`cd ${outputPath}`)} - to enter project’s directory`) print( - `Then: ${chalk.cyan(devCommand)} -to run ${isStudioTemplate ? 'Sanity Studio' : 'your Sanity application'}\n`, + `Then: ${chalk.cyan(devCommand)} -to run ${isCoreAppTemplate ? 'your Sanity application' : 'Sanity Studio'}\n`, ) } @@ -729,8 +729,7 @@ export default async function initSanity( return data } - // For non-studio templates, return empty strings but maintain the structure - if (!isStudioTemplate) { + if (isCoreAppTemplate) { return { projectId: '', displayName: '', diff --git a/packages/@sanity/cli/src/actions/init-project/templates/coreApp.ts b/packages/@sanity/cli/src/actions/init-project/templates/coreApp.ts index 11c89bc99e7..d87fa06ba83 100644 --- a/packages/@sanity/cli/src/actions/init-project/templates/coreApp.ts +++ b/packages/@sanity/cli/src/actions/init-project/templates/coreApp.ts @@ -13,13 +13,11 @@ const coreAppTemplate: ProjectTemplate = { * eslint.config generation will be a fast follow */ '@sanity/eslint-config-studio': '^5.0.1', - 'sanity': '^3', - '@vitejs/plugin-react': '^4.3.4', '@types/react': '^18.0.25', 'eslint': '^9.9.0', 'prettier': '^3.0.2', + 'sanity': '^3', 'typescript': '^5.1.6', - 'vite': '^6', }, appLocation: './src/App.tsx', } diff --git a/packages/@sanity/cli/test/init.test.ts b/packages/@sanity/cli/test/init.test.ts index 69469bb5b85..22b8255c339 100644 --- a/packages/@sanity/cli/test/init.test.ts +++ b/packages/@sanity/cli/test/init.test.ts @@ -3,14 +3,14 @@ import path from 'node:path' import {describe, expect} from 'vitest' -import {determineStudioTemplate} from '../src/actions/init-project/determineStudioTemplate' +import {determineCoreAppTemplate} from '../src/actions/init-project/determineCoreAppTemplate' import templates from '../src/actions/init-project/templates' import {describeCliTest, testConcurrent} from './shared/describe' import {baseTestPath, cliProjectId, getTestRunArgs, runSanityCmdCommand} from './shared/environment' describeCliTest('CLI: `sanity init v3`', () => { // filter out non-studio apps for now, until we add things they can auto-update - describe.each(Object.keys(templates).filter(determineStudioTemplate))( + describe.each(Object.keys(templates).filter((template) => !determineCoreAppTemplate(template)))( 'for template %s', (template) => { testConcurrent('adds autoUpdates: true to cli config', async () => { diff --git a/packages/sanity/src/_internal/cli/actions/build/buildAction.ts b/packages/sanity/src/_internal/cli/actions/build/buildAction.ts index d7829c951af..d63dc19d70a 100644 --- a/packages/sanity/src/_internal/cli/actions/build/buildAction.ts +++ b/packages/sanity/src/_internal/cli/actions/build/buildAction.ts @@ -46,6 +46,7 @@ export default async function buildSanityStudio( const unattendedMode = Boolean(flags.yes || flags.y) const defaultOutputDir = path.resolve(path.join(workDir, 'dist')) const outputDir = path.resolve(args.argsWithoutOptions[0] || defaultOutputDir) + const isCoreApp = cliConfig && '__experimental_coreAppConfiguration' in cliConfig await checkStudioDependencyVersions(workDir) @@ -57,7 +58,6 @@ export default async function buildSanityStudio( } const autoUpdatesEnabled = shouldAutoUpdate({flags, cliConfig}) - const isStudioApp = !(cliConfig && '__experimental_coreAppConfiguration' in cliConfig) // Get the version without any tags if any const coercedSanityVersion = semver.coerce(installedSanityVersion)?.version @@ -147,7 +147,7 @@ export default async function buildSanityStudio( spin.succeed() } - spin = output.spinner(`Build Sanity ${isStudioApp ? 'Studio' : 'application'}`).start() + spin = output.spinner(`Build Sanity ${isCoreApp ? 'application' : 'Studio'}`).start() const trace = telemetry.trace(BuildTrace) trace.start() @@ -180,7 +180,7 @@ export default async function buildSanityStudio( cliConfig && '__experimental_coreAppConfiguration' in cliConfig ? cliConfig.__experimental_coreAppConfiguration?.appLocation : undefined, - isStudioApp, + isCoreApp, }) trace.log({ @@ -190,7 +190,7 @@ export default async function buildSanityStudio( }) const buildDuration = timer.end('bundleStudio') - spin.text = `Build Sanity ${isStudioApp ? 'Studio' : 'application'} (${buildDuration.toFixed()}ms)` + spin.text = `Build Sanity ${isCoreApp ? 'application' : 'Studio'} (${buildDuration.toFixed()}ms)` spin.succeed() trace.complete() diff --git a/packages/sanity/src/_internal/cli/actions/dev/devAction.ts b/packages/sanity/src/_internal/cli/actions/dev/devAction.ts index 5098b6378e8..8d16d114350 100644 --- a/packages/sanity/src/_internal/cli/actions/dev/devAction.ts +++ b/packages/sanity/src/_internal/cli/actions/dev/devAction.ts @@ -31,11 +31,9 @@ export default async function startSanityDevServer( timers.end('checkStudioDependencyVersions') // If the check resulted in a dependency install, the CLI command will be re-run, - // thus we want to exit early (only for studios) - if (!(cliConfig && '__experimental_coreAppConfiguration' in cliConfig)) { - if ((await checkRequiredDependencies(context)).didInstall) { - return - } + // thus we want to exit early + if ((await checkRequiredDependencies(context)).didInstall) { + return } // Try to load CLI configuration from sanity.cli.(js|ts) diff --git a/packages/sanity/src/_internal/cli/commands/start/startCommand.ts b/packages/sanity/src/_internal/cli/commands/start/startCommand.ts index d571c0d3dfe..7c00a348911 100644 --- a/packages/sanity/src/_internal/cli/commands/start/startCommand.ts +++ b/packages/sanity/src/_internal/cli/commands/start/startCommand.ts @@ -33,11 +33,11 @@ const startCommand: CliCommandDefinition = { const {output, chalk, prompt} = context const previewAction = await getPreviewAction() const {cliConfig} = context - const isStudioApp = !(cliConfig && '__experimental_coreAppConfiguration' in cliConfig) + const isCoreApp = cliConfig && '__experimental_coreAppConfiguration' in cliConfig const warn = (msg: string) => output.warn(chalk.yellow.bgBlack(msg)) const error = (msg: string) => output.warn(chalk.red.bgBlack(msg)) - if (isStudioApp) { + if (!isCoreApp) { warn('╭───────────────────────────────────────────────────────────╮') warn('│ │') warn("│ You're running Sanity Studio v3. In this version the │") diff --git a/packages/sanity/src/_internal/cli/server/buildStaticFiles.ts b/packages/sanity/src/_internal/cli/server/buildStaticFiles.ts index 1ab61852bc1..b109f6e95ac 100644 --- a/packages/sanity/src/_internal/cli/server/buildStaticFiles.ts +++ b/packages/sanity/src/_internal/cli/server/buildStaticFiles.ts @@ -35,7 +35,7 @@ export interface StaticBuildOptions { vite?: UserViteConfig reactCompiler: ReactCompilerConfig | undefined appLocation?: string - isStudioApp?: boolean + isCoreApp?: boolean } export async function buildStaticFiles( @@ -51,7 +51,7 @@ export async function buildStaticFiles( importMap, reactCompiler, appLocation, - isStudioApp = true, + isCoreApp, } = options debug('Writing Sanity runtime files') @@ -61,7 +61,7 @@ export async function buildStaticFiles( watch: false, basePath, appLocation, - isStudioApp, + isCoreApp, }) debug('Resolving vite config') @@ -75,7 +75,7 @@ export async function buildStaticFiles( mode, importMap, reactCompiler, - isStudioApp, + isCoreApp, }) // Extend Vite configuration with user-provided config diff --git a/packages/sanity/src/_internal/cli/server/devServer.ts b/packages/sanity/src/_internal/cli/server/devServer.ts index fce0cb2f806..1c8a7e9160d 100644 --- a/packages/sanity/src/_internal/cli/server/devServer.ts +++ b/packages/sanity/src/_internal/cli/server/devServer.ts @@ -18,7 +18,7 @@ export interface DevServerOptions { reactCompiler: ReactCompilerConfig | undefined vite?: UserViteConfig appLocation?: string - isStudioApp?: boolean + isCoreApp?: boolean } export interface DevServer { @@ -35,12 +35,12 @@ export async function startDevServer(options: DevServerOptions): Promise} reactCompiler: ReactCompilerConfig | undefined - isStudioApp?: boolean + isCoreApp?: boolean } /** @@ -73,7 +73,7 @@ export async function getViteConfig(options: ViteOptions): Promise basePath: rawBasePath = '/', importMap, reactCompiler, - isStudioApp = true, + isCoreApp, } = options const monorepo = await loadSanityMonorepo(cwd) @@ -112,9 +112,9 @@ export async function getViteConfig(options: ViteOptions): Promise ), sanityFaviconsPlugin({defaultFaviconsPath, customFaviconsPath, staticUrlPath: staticPath}), sanityRuntimeRewritePlugin(), - sanityBuildEntries({basePath, cwd, monorepo, importMap, isStudioApp}), + sanityBuildEntries({basePath, cwd, monorepo, importMap, isCoreApp}), ], - envPrefix: isStudioApp ? 'SANITY_STUDIO_' : 'VITE_', + envPrefix: isCoreApp ? 'VITE_' : 'SANITY_STUDIO_', logLevel: mode === 'production' ? 'silent' : 'info', resolve: { alias: monorepo?.path diff --git a/packages/sanity/src/_internal/cli/server/previewServer.ts b/packages/sanity/src/_internal/cli/server/previewServer.ts index 1fed6386150..1fda0e7843a 100644 --- a/packages/sanity/src/_internal/cli/server/previewServer.ts +++ b/packages/sanity/src/_internal/cli/server/previewServer.ts @@ -24,11 +24,11 @@ export interface PreviewServerOptions { httpHost?: string vite?: UserViteConfig - isStudioApp?: boolean + isCoreApp?: boolean } export async function startPreviewServer(options: PreviewServerOptions): Promise { - const {httpPort, httpHost, root, vite: extendViteConfig, isStudioApp = true} = options + const {httpPort, httpHost, root, vite: extendViteConfig, isCoreApp = true} = options const startTime = Date.now() const indexPath = path.join(root, 'index.html') @@ -42,7 +42,7 @@ export async function startPreviewServer(options: PreviewServerOptions): Promise } const error = new Error( - `Could not find a production build in the '${root}' directory.\nTry building your ${isStudioApp ? 'studio ' : ''}app with 'sanity build' before starting the preview server.`, + `Could not find a production build in the '${root}' directory.\nTry building your ${isCoreApp ? '' : 'studio '}app with 'sanity build' before starting the preview server.`, ) error.name = 'BUILD_NOT_FOUND' throw error @@ -91,7 +91,7 @@ export async function startPreviewServer(options: PreviewServerOptions): Promise const startupDuration = Date.now() - startTime info( - `Sanity ${isStudioApp ? 'Studio' : 'application'} ` + + `Sanity ${isCoreApp ? 'application' : 'Studio'} ` + `using ${chalk.cyan(`vite@${require('vite/package.json').version}`)} ` + `ready in ${chalk.cyan(`${Math.ceil(startupDuration)}ms`)} ` + `and running at ${chalk.cyan(url)} (production preview mode)`, diff --git a/packages/sanity/src/_internal/cli/server/renderDocument.tsx b/packages/sanity/src/_internal/cli/server/renderDocument.tsx index 9049e366d9b..edafdb9f6b7 100644 --- a/packages/sanity/src/_internal/cli/server/renderDocument.tsx +++ b/packages/sanity/src/_internal/cli/server/renderDocument.tsx @@ -48,7 +48,7 @@ interface RenderDocumentOptions { importMap?: { imports?: Record } - isStudioApp?: boolean + isCoreApp?: boolean } export function renderDocument(options: RenderDocumentOptions): Promise { @@ -59,7 +59,7 @@ export function renderDocument(options: RenderDocumentOptions): Promise options.studioRootPath, options.props, options.importMap, - options.isStudioApp, + options.isCoreApp, ), ) return @@ -158,13 +158,8 @@ function renderDocumentFromWorkerData() { throw new Error('Must be used as a Worker with a valid options object in worker data') } - const { - monorepo, - studioRootPath, - props, - importMap, - isStudioApp = true, - }: RenderDocumentOptions = workerData || {} + const {monorepo, studioRootPath, props, importMap, isCoreApp}: RenderDocumentOptions = + workerData || {} if (workerData?.dev) { // Define `__DEV__` in the worker thread as well @@ -214,7 +209,7 @@ function renderDocumentFromWorkerData() { loader: 'jsx', }) - const html = getDocumentHtml(studioRootPath, props, importMap, isStudioApp) + const html = getDocumentHtml(studioRootPath, props, importMap, isCoreApp) parentPort.postMessage({type: 'result', html}) @@ -227,9 +222,9 @@ function getDocumentHtml( studioRootPath: string, props?: DocumentProps, importMap?: {imports?: Record}, - isStudioApp = true, + isCoreApp?: boolean, ): string { - const Document = getDocumentComponent(studioRootPath, isStudioApp) + const Document = getDocumentComponent(studioRootPath, isCoreApp) // NOTE: Validate the list of CSS paths so implementers of `_document.tsx` don't have to // - If the path is not a full URL, check if it starts with `/` @@ -285,7 +280,7 @@ export function addTimestampedImportMapScriptToHtml( return root.outerHTML } -function getDocumentComponent(studioRootPath: string, isStudioApp = true) { +function getDocumentComponent(studioRootPath: string, isCoreApp?: boolean) { debug('Loading default document component from `sanity` module') const {BasicDocument} = __DEV__ @@ -296,7 +291,7 @@ function getDocumentComponent(studioRootPath: string, isStudioApp = true) { ? require('../../../core/components/DefaultDocument') : require('sanity') - const Document = isStudioApp ? DefaultDocument : BasicDocument + const Document = isCoreApp ? BasicDocument : DefaultDocument debug('Attempting to load user-defined document component from %s', studioRootPath) const userDefined = tryLoadDocumentComponent(studioRootPath) diff --git a/packages/sanity/src/_internal/cli/server/runtime.ts b/packages/sanity/src/_internal/cli/server/runtime.ts index 0ca2a251117..8c3bcf508d9 100644 --- a/packages/sanity/src/_internal/cli/server/runtime.ts +++ b/packages/sanity/src/_internal/cli/server/runtime.ts @@ -21,7 +21,7 @@ export interface RuntimeOptions { watch: boolean basePath?: string appLocation?: string - isStudioApp?: boolean + isCoreApp?: boolean } /** @@ -37,7 +37,7 @@ export async function writeSanityRuntime({ watch, basePath, appLocation, - isStudioApp = true, + isCoreApp, }: RuntimeOptions): Promise { debug('Resolving Sanity monorepo information') const monorepo = await loadSanityMonorepo(cwd) @@ -56,7 +56,7 @@ export async function writeSanityRuntime({ entryPath: `/${path.relative(cwd, path.join(runtimeDir, 'app.js'))}`, basePath: basePath || '/', }, - isStudioApp, + isCoreApp, }), ) @@ -74,7 +74,7 @@ export async function writeSanityRuntime({ debug('Writing app.js to runtime directory') let relativeConfigLocation: string | null = null - if (isStudioApp) { + if (!isCoreApp) { const studioConfigPath = await getSanityStudioConfigPath(cwd) relativeConfigLocation = studioConfigPath ? path.relative(runtimeDir, studioConfigPath) : null } @@ -85,7 +85,7 @@ export async function writeSanityRuntime({ relativeConfigLocation, basePath, appLocation: relativeAppLocation, - isStudioApp, + isCoreApp, }) await fs.writeFile(path.join(runtimeDir, 'app.js'), appJsContent) } diff --git a/packages/sanity/src/_internal/cli/server/vite/plugin-sanity-build-entries.ts b/packages/sanity/src/_internal/cli/server/vite/plugin-sanity-build-entries.ts index e6b6feead0c..42b6fc2b1b0 100644 --- a/packages/sanity/src/_internal/cli/server/vite/plugin-sanity-build-entries.ts +++ b/packages/sanity/src/_internal/cli/server/vite/plugin-sanity-build-entries.ts @@ -29,9 +29,9 @@ export function sanityBuildEntries(options: { monorepo: SanityMonorepo | undefined basePath: string importMap?: {imports?: Record} - isStudioApp?: boolean + isCoreApp?: boolean }): Plugin { - const {cwd, monorepo, basePath, importMap, isStudioApp = true} = options + const {cwd, monorepo, basePath, importMap, isCoreApp} = options return { name: 'sanity/server/build-entries', @@ -95,7 +95,7 @@ export function sanityBuildEntries(options: { entryPath, css, }, - isStudioApp, + isCoreApp, }), }) }, diff --git a/packages/sanity/src/_internal/cli/util/checkRequiredDependencies.ts b/packages/sanity/src/_internal/cli/util/checkRequiredDependencies.ts index 258c6fa8a22..5781a1b0a0e 100644 --- a/packages/sanity/src/_internal/cli/util/checkRequiredDependencies.ts +++ b/packages/sanity/src/_internal/cli/util/checkRequiredDependencies.ts @@ -31,6 +31,13 @@ interface CheckResult { * Additionally, returns the version of the 'sanity' dependency from the package.json. */ export async function checkRequiredDependencies(context: CliCommandContext): Promise { + // currently there's no check needed for core apps, + // but this should be removed once they are more mature + const isCoreApp = context.cliConfig && '__experimental_coreAppConfiguration' in context.cliConfig + if (isCoreApp) { + return {didInstall: false, installedSanityVersion: ''} + } + const {workDir: studioPath, output} = context const [studioPackageManifest, installedStyledComponentsVersion, installedSanityVersion] = await Promise.all([ diff --git a/packages/sanity/src/_internal/cli/util/servers.ts b/packages/sanity/src/_internal/cli/util/servers.ts index 9b3daa0907a..bee79446864 100644 --- a/packages/sanity/src/_internal/cli/util/servers.ts +++ b/packages/sanity/src/_internal/cli/util/servers.ts @@ -49,7 +49,7 @@ export function getSharedServerConfig({ basePath: string vite: CliConfig['vite'] appLocation?: string - isStudioApp: boolean + isCoreApp?: boolean } { // Order of preference: CLI flags, environment variables, user build config, default config const env = process.env // eslint-disable-line no-process-env @@ -66,7 +66,7 @@ export function getSharedServerConfig({ env.SANITY_STUDIO_BASEPATH ?? (cliConfig?.project?.basePath || '/'), ) - const isStudioApp = !(cliConfig && '__experimental_coreAppConfiguration' in cliConfig) + const isCoreApp = cliConfig && '__experimental_coreAppConfiguration' in cliConfig const appLocation = cliConfig?.__experimental_coreAppConfiguration?.appLocation return { @@ -76,7 +76,7 @@ export function getSharedServerConfig({ basePath, vite: cliConfig?.vite, appLocation, - isStudioApp, + isCoreApp, } }