@sanity/cli 6.0.0-alpha.13 → 6.0.0-alpha.14
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/README.md +17 -6
- package/dist/actions/build/buildApp.js +4 -3
- package/dist/actions/build/buildApp.js.map +1 -1
- package/dist/actions/build/buildStudio.js +1 -0
- package/dist/actions/build/buildStudio.js.map +1 -1
- package/dist/actions/build/buildVendorDependencies.js +15 -36
- package/dist/actions/build/buildVendorDependencies.js.map +1 -1
- package/dist/actions/build/checkRequiredDependencies.js +7 -5
- package/dist/actions/build/checkRequiredDependencies.js.map +1 -1
- package/dist/actions/build/checkStudioDependencyVersions.js +6 -6
- package/dist/actions/build/checkStudioDependencyVersions.js.map +1 -1
- package/dist/actions/deploy/deployApp.js +2 -2
- package/dist/actions/deploy/deployApp.js.map +1 -1
- package/dist/actions/deploy/deployStudio.js +2 -2
- package/dist/actions/deploy/deployStudio.js.map +1 -1
- package/dist/actions/dev/startStudioDevServer.js +2 -2
- package/dist/actions/dev/startStudioDevServer.js.map +1 -1
- package/dist/actions/manifest/extractManifest.js +2 -2
- package/dist/actions/manifest/extractManifest.js.map +1 -1
- package/dist/actions/schema/extractSchema.js +7 -32
- package/dist/actions/schema/extractSchema.js.map +1 -1
- package/dist/actions/schema/extractSchemaWatcher.js +126 -0
- package/dist/actions/schema/extractSchemaWatcher.js.map +1 -0
- package/dist/actions/schema/formatSchemaValidation.js +5 -1
- package/dist/actions/schema/formatSchemaValidation.js.map +1 -1
- package/dist/actions/schema/getExtractOptions.js +16 -0
- package/dist/actions/schema/getExtractOptions.js.map +1 -0
- package/dist/actions/schema/runSchemaExtraction.js +39 -0
- package/dist/actions/schema/runSchemaExtraction.js.map +1 -0
- package/dist/actions/schema/watchExtractSchema.js +71 -0
- package/dist/actions/schema/watchExtractSchema.js.map +1 -0
- package/dist/commands/schema/extract.js +32 -4
- package/dist/commands/schema/extract.js.map +1 -1
- package/dist/server/previewServer.js +2 -2
- package/dist/server/previewServer.js.map +1 -1
- package/dist/telemetry/extractSchema.telemetry.js +5 -0
- package/dist/telemetry/extractSchema.telemetry.js.map +1 -1
- package/dist/util/compareDependencyVersions.js +3 -5
- package/dist/util/compareDependencyVersions.js.map +1 -1
- package/dist/util/getLocalPackageVersion.js +30 -22
- package/dist/util/getLocalPackageVersion.js.map +1 -1
- package/dist/util/getWorkspace.js +1 -1
- package/dist/util/getWorkspace.js.map +1 -1
- package/oclif.manifest.json +187 -165
- package/package.json +3 -4
- package/dist/util/readModuleVersion.js +0 -21
- package/dist/util/readModuleVersion.js.map +0 -1
package/README.md
CHANGED
|
@@ -2758,14 +2758,17 @@ Extracts a JSON representation of a Sanity schema within a Studio context.
|
|
|
2758
2758
|
|
|
2759
2759
|
```
|
|
2760
2760
|
USAGE
|
|
2761
|
-
$ sanity schema extract [--enforce-required-fields] [--format <format>] [--path <value>] [--
|
|
2761
|
+
$ sanity schema extract [--enforce-required-fields] [--format <format>] [--path <value>] [--watch]
|
|
2762
|
+
[--watch-patterns <glob>...] [--workspace <name>]
|
|
2762
2763
|
|
|
2763
2764
|
FLAGS
|
|
2764
|
-
--enforce-required-fields
|
|
2765
|
-
--format=<format>
|
|
2766
|
-
|
|
2767
|
-
--path=<value>
|
|
2768
|
-
--
|
|
2765
|
+
--enforce-required-fields Makes the schema generated treat fields marked as required as non-optional
|
|
2766
|
+
--format=<format> [default: groq-type-nodes] Format the schema as GROQ type nodes. Only available format at
|
|
2767
|
+
the moment.
|
|
2768
|
+
--path=<value> Optional path to specify destination of the schema file
|
|
2769
|
+
--watch Enable watch mode to re-extract schema on file changes
|
|
2770
|
+
--watch-patterns=<glob>... Additional glob pattern(s) to watch (can be specified multiple times)
|
|
2771
|
+
--workspace=<name> The name of the workspace to generate a schema for
|
|
2769
2772
|
|
|
2770
2773
|
DESCRIPTION
|
|
2771
2774
|
Extracts a JSON representation of a Sanity schema within a Studio context.
|
|
@@ -2776,6 +2779,14 @@ EXAMPLES
|
|
|
2776
2779
|
Extracts schema types in a Sanity project with more than one workspace
|
|
2777
2780
|
|
|
2778
2781
|
$ sanity schema extract --workspace default
|
|
2782
|
+
|
|
2783
|
+
Watch mode - re-extract on changes
|
|
2784
|
+
|
|
2785
|
+
$ sanity schema extract --watch
|
|
2786
|
+
|
|
2787
|
+
Watch with custom glob patterns
|
|
2788
|
+
|
|
2789
|
+
$ sanity schema extract --watch --watch-patterns "lib/**/*.ts"
|
|
2779
2790
|
```
|
|
2780
2791
|
|
|
2781
2792
|
_See code: [src/commands/schema/extract.ts](https://github.com/sanity-io/cli/blob/v6.0.0-alpha.11/src/commands/schema/extract.ts)_
|
|
@@ -7,8 +7,8 @@ import semver from 'semver';
|
|
|
7
7
|
import { AppBuildTrace } from '../../telemetry/build.telemetry.js';
|
|
8
8
|
import { getAppId } from '../../util/appId.js';
|
|
9
9
|
import { compareDependencyVersions } from '../../util/compareDependencyVersions.js';
|
|
10
|
+
import { getLocalPackageVersion } from '../../util/getLocalPackageVersion.js';
|
|
10
11
|
import { formatModuleSizes, sortModulesBySize } from '../../util/moduleFormatUtils.js';
|
|
11
|
-
import { readModuleVersion } from '../../util/readModuleVersion.js';
|
|
12
12
|
import { buildDebug } from './buildDebug.js';
|
|
13
13
|
import { buildStaticFiles } from './buildStaticFiles.js';
|
|
14
14
|
import { buildVendorDependencies } from './buildVendorDependencies.js';
|
|
@@ -26,8 +26,8 @@ import { getAutoUpdatesImportMap } from './getAutoUpdatesImportMap.js';
|
|
|
26
26
|
const defaultOutputDir = path.resolve(path.join(workDir, 'dist'));
|
|
27
27
|
const outputDir = path.resolve(outDir || defaultOutputDir);
|
|
28
28
|
const appId = getAppId(cliConfig);
|
|
29
|
-
const installedSdkVersion = await
|
|
30
|
-
const installedSanityVersion = await
|
|
29
|
+
const installedSdkVersion = await getLocalPackageVersion('@sanity/sdk-react', workDir);
|
|
30
|
+
const installedSanityVersion = await getLocalPackageVersion('sanity', workDir);
|
|
31
31
|
if (!installedSdkVersion) {
|
|
32
32
|
output.error(`Failed to find installed @sanity/sdk-react version`, {
|
|
33
33
|
exit: 1
|
|
@@ -121,6 +121,7 @@ import { getAutoUpdatesImportMap } from './getAutoUpdatesImportMap.js';
|
|
|
121
121
|
...await buildVendorDependencies({
|
|
122
122
|
basePath,
|
|
123
123
|
cwd: workDir,
|
|
124
|
+
isApp: true,
|
|
124
125
|
outputDir
|
|
125
126
|
}),
|
|
126
127
|
...autoUpdatesImports
|
|
@@ -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 {getCliTelemetry, getTimer} from '@sanity/cli-core'\nimport {confirm, logSymbols, spinner, type SpinnerInstance} from '@sanity/cli-core/ux'\nimport semver from 'semver'\n\nimport {AppBuildTrace} from '../../telemetry/build.telemetry.js'\nimport {getAppId} from '../../util/appId.js'\nimport {compareDependencyVersions} from '../../util/compareDependencyVersions.js'\nimport {formatModuleSizes, sortModulesBySize} from '../../util/moduleFormatUtils.js'\nimport {readModuleVersion} from '../../util/readModuleVersion.js'\nimport {buildDebug} from './buildDebug.js'\nimport {buildStaticFiles} from './buildStaticFiles.js'\nimport {buildVendorDependencies} from './buildVendorDependencies.js'\nimport {determineBasePath} from './determineBasePath.js'\nimport {getAppEnvVars} from './getAppEnvVars.js'\nimport {getAutoUpdatesImportMap} from './getAutoUpdatesImportMap.js'\nimport {type BuildOptions} from './types.js'\n\n/**\n * Build the Sanity app.\n *\n * @internal\n */\nexport async function buildApp(options: BuildOptions): Promise<void> {\n const {autoUpdatesEnabled, cliConfig, flags, outDir, output, workDir} = options\n const unattendedMode = flags.yes\n const timer = getTimer()\n\n const defaultOutputDir = path.resolve(path.join(workDir, 'dist'))\n const outputDir = path.resolve(outDir || defaultOutputDir)\n\n const appId = getAppId(cliConfig)\n\n const installedSdkVersion = await readModuleVersion(workDir, '@sanity/sdk-react')\n const installedSanityVersion = await readModuleVersion(workDir, 'sanity')\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\n if (autoUpdatesEnabled) {\n // Get the clean version without build metadata: https://semver.org/#spec-item-10\n const cleanSDKVersion = semver.parse(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 = semver.parse(installedSanityVersion)?.version\n\n const autoUpdatedPackages = [\n {name: '@sanity/sdk', version: cleanSDKVersion},\n {name: '@sanity/sdk-react', version: cleanSDKVersion},\n ...(cleanSanityVersion ? [{name: 'sanity' as const, version: cleanSanityVersion}] : []),\n ]\n autoUpdatesImports = getAutoUpdatesImportMap(autoUpdatedPackages, {appId})\n\n output.log(`${logSymbols.info} Building with auto-updates enabled`)\n\n // Check the versions\n const result = await compareDependencyVersions(autoUpdatedPackages, workDir, {appId})\n\n // If it is in unattended mode, we don't want to prompt\n if (result?.length && !unattendedMode) {\n const shouldContinue = await confirm({\n default: false,\n message: styleText(\n 'yellow',\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 `${result.map((mod) => ` - ${mod.pkg} (local version: ${mod.installed}, runtime version: ${mod.remote})`).join('\\n')} \\n\\n` +\n `Continue anyway?`,\n ),\n })\n\n if (!shouldContinue) {\n output.error('Declined to continue with build', {exit: 1})\n return\n }\n }\n }\n\n const envVarKeys = getAppEnvVars()\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) {\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(cliConfig, 'app')\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 importMap: {imports?: Record<string, string>} | undefined\n\n if (autoUpdatesEnabled) {\n importMap = {\n imports: {\n ...(await buildVendorDependencies({basePath, cwd: workDir, outputDir})),\n ...autoUpdatesImports,\n },\n }\n }\n\n try {\n timer.start('bundleStudio')\n\n const bundle = await buildStaticFiles({\n basePath,\n cwd: workDir,\n entry: cliConfig && 'app' in cliConfig ? cliConfig.app?.entry : undefined,\n importMap,\n isApp: true,\n minify: Boolean(flags.minify),\n outputDir,\n reactCompiler:\n cliConfig && 'reactCompiler' in cliConfig ? cliConfig.reactCompiler : undefined,\n sourceMap: Boolean(flags['source-maps']),\n vite: cliConfig && 'vite' in cliConfig ? cliConfig.vite : undefined,\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 (flags.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","getCliTelemetry","getTimer","confirm","logSymbols","spinner","semver","AppBuildTrace","getAppId","compareDependencyVersions","formatModuleSizes","sortModulesBySize","readModuleVersion","buildDebug","buildStaticFiles","buildVendorDependencies","determineBasePath","getAppEnvVars","getAutoUpdatesImportMap","buildApp","options","autoUpdatesEnabled","cliConfig","flags","outDir","output","workDir","unattendedMode","yes","timer","defaultOutputDir","resolve","join","outputDir","appId","installedSdkVersion","installedSanityVersion","error","exit","autoUpdatesImports","cleanSDKVersion","parse","version","cleanSanityVersion","autoUpdatedPackages","name","log","info","result","length","shouldContinue","default","message","map","mod","pkg","installed","remote","envVarKeys","key","shouldClean","basePath","spin","start","force","recursive","cleanDuration","end","text","toFixed","succeed","trace","importMap","imports","cwd","bundle","entry","app","undefined","isApp","minify","Boolean","reactCompiler","sourceMap","vite","outputSize","chunks","flatMap","chunk","modules","renderedLength","reduce","sum","n","buildDuration","stats","slice","complete","fail","Error","String"],"mappings":"AAAA,SAAQA,EAAE,QAAO,mBAAkB;AACnC,OAAOC,UAAU,YAAW;AAC5B,SAAQC,SAAS,QAAO,YAAW;AAEnC,SAAQC,eAAe,EAAEC,QAAQ,QAAO,mBAAkB;AAC1D,SAAQC,OAAO,EAAEC,UAAU,EAAEC,OAAO,QAA6B,sBAAqB;AACtF,OAAOC,YAAY,SAAQ;AAE3B,SAAQC,aAAa,QAAO,qCAAoC;AAChE,SAAQC,QAAQ,QAAO,sBAAqB;AAC5C,SAAQC,yBAAyB,QAAO,0CAAyC;AACjF,SAAQC,iBAAiB,EAAEC,iBAAiB,QAAO,kCAAiC;AACpF,SAAQC,iBAAiB,QAAO,kCAAiC;AACjE,SAAQC,UAAU,QAAO,kBAAiB;AAC1C,SAAQC,gBAAgB,QAAO,wBAAuB;AACtD,SAAQC,uBAAuB,QAAO,+BAA8B;AACpE,SAAQC,iBAAiB,QAAO,yBAAwB;AACxD,SAAQC,aAAa,QAAO,qBAAoB;AAChD,SAAQC,uBAAuB,QAAO,+BAA8B;AAGpE;;;;CAIC,GACD,OAAO,eAAeC,SAASC,OAAqB;IAClD,MAAM,EAACC,kBAAkB,EAAEC,SAAS,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AM0B,QAAQ;IAChB,EAAE,OAAO5D,OAAO;QACdyB,KAAKoC,IAAI;QACT3B,MAAMlC,KAAK,CAACA;QACZ,MAAMe,UAAUf,iBAAiB8D,QAAQ9D,MAAMe,OAAO,GAAGgD,OAAO/D;QAChExB,WAAW,CAAC,kCAAkC,CAAC,EAAE;YAACwB;QAAK;QACvDZ,OAAOY,KAAK,CAAC,CAAC,oCAAoC,EAAEe,SAAS,EAAE;YAACd,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 {getCliTelemetry, getTimer} from '@sanity/cli-core'\nimport {confirm, logSymbols, spinner, type SpinnerInstance} from '@sanity/cli-core/ux'\nimport semver from 'semver'\n\nimport {AppBuildTrace} from '../../telemetry/build.telemetry.js'\nimport {getAppId} from '../../util/appId.js'\nimport {compareDependencyVersions} from '../../util/compareDependencyVersions.js'\nimport {getLocalPackageVersion} from '../../util/getLocalPackageVersion.js'\nimport {formatModuleSizes, sortModulesBySize} from '../../util/moduleFormatUtils.js'\nimport {buildDebug} from './buildDebug.js'\nimport {buildStaticFiles} from './buildStaticFiles.js'\nimport {buildVendorDependencies} from './buildVendorDependencies.js'\nimport {determineBasePath} from './determineBasePath.js'\nimport {getAppEnvVars} from './getAppEnvVars.js'\nimport {getAutoUpdatesImportMap} from './getAutoUpdatesImportMap.js'\nimport {type BuildOptions} from './types.js'\n\n/**\n * Build the Sanity app.\n *\n * @internal\n */\nexport async function buildApp(options: BuildOptions): Promise<void> {\n const {autoUpdatesEnabled, cliConfig, flags, outDir, output, workDir} = options\n const unattendedMode = flags.yes\n const timer = getTimer()\n\n const defaultOutputDir = path.resolve(path.join(workDir, 'dist'))\n const outputDir = path.resolve(outDir || defaultOutputDir)\n\n const appId = getAppId(cliConfig)\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\n if (autoUpdatesEnabled) {\n // Get the clean version without build metadata: https://semver.org/#spec-item-10\n const cleanSDKVersion = semver.parse(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 = semver.parse(installedSanityVersion)?.version\n\n const autoUpdatedPackages = [\n {name: '@sanity/sdk', version: cleanSDKVersion},\n {name: '@sanity/sdk-react', version: cleanSDKVersion},\n ...(cleanSanityVersion ? [{name: 'sanity' as const, version: cleanSanityVersion}] : []),\n ]\n autoUpdatesImports = getAutoUpdatesImportMap(autoUpdatedPackages, {appId})\n\n output.log(`${logSymbols.info} Building with auto-updates enabled`)\n\n // Check the versions\n const result = await compareDependencyVersions(autoUpdatedPackages, workDir, {appId})\n\n // If it is in unattended mode, we don't want to prompt\n if (result?.length && !unattendedMode) {\n const shouldContinue = await confirm({\n default: false,\n message: styleText(\n 'yellow',\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 `${result.map((mod) => ` - ${mod.pkg} (local version: ${mod.installed}, runtime version: ${mod.remote})`).join('\\n')} \\n\\n` +\n `Continue anyway?`,\n ),\n })\n\n if (!shouldContinue) {\n output.error('Declined to continue with build', {exit: 1})\n return\n }\n }\n }\n\n const envVarKeys = getAppEnvVars()\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) {\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(cliConfig, 'app')\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 importMap: {imports?: Record<string, string>} | undefined\n\n if (autoUpdatesEnabled) {\n importMap = {\n imports: {\n ...(await buildVendorDependencies({basePath, cwd: workDir, isApp: true, outputDir})),\n ...autoUpdatesImports,\n },\n }\n }\n\n try {\n timer.start('bundleStudio')\n\n const bundle = await buildStaticFiles({\n basePath,\n cwd: workDir,\n entry: cliConfig && 'app' in cliConfig ? cliConfig.app?.entry : undefined,\n importMap,\n isApp: true,\n minify: Boolean(flags.minify),\n outputDir,\n reactCompiler:\n cliConfig && 'reactCompiler' in cliConfig ? cliConfig.reactCompiler : undefined,\n sourceMap: Boolean(flags['source-maps']),\n vite: cliConfig && 'vite' in cliConfig ? cliConfig.vite : undefined,\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 (flags.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","getCliTelemetry","getTimer","confirm","logSymbols","spinner","semver","AppBuildTrace","getAppId","compareDependencyVersions","getLocalPackageVersion","formatModuleSizes","sortModulesBySize","buildDebug","buildStaticFiles","buildVendorDependencies","determineBasePath","getAppEnvVars","getAutoUpdatesImportMap","buildApp","options","autoUpdatesEnabled","cliConfig","flags","outDir","output","workDir","unattendedMode","yes","timer","defaultOutputDir","resolve","join","outputDir","appId","installedSdkVersion","installedSanityVersion","error","exit","autoUpdatesImports","cleanSDKVersion","parse","version","cleanSanityVersion","autoUpdatedPackages","name","log","info","result","length","shouldContinue","default","message","map","mod","pkg","installed","remote","envVarKeys","key","shouldClean","basePath","spin","start","force","recursive","cleanDuration","end","text","toFixed","succeed","trace","importMap","imports","cwd","isApp","bundle","entry","app","undefined","minify","Boolean","reactCompiler","sourceMap","vite","outputSize","chunks","flatMap","chunk","modules","renderedLength","reduce","sum","n","buildDuration","stats","slice","complete","fail","Error","String"],"mappings":"AAAA,SAAQA,EAAE,QAAO,mBAAkB;AACnC,OAAOC,UAAU,YAAW;AAC5B,SAAQC,SAAS,QAAO,YAAW;AAEnC,SAAQC,eAAe,EAAEC,QAAQ,QAAO,mBAAkB;AAC1D,SAAQC,OAAO,EAAEC,UAAU,EAAEC,OAAO,QAA6B,sBAAqB;AACtF,OAAOC,YAAY,SAAQ;AAE3B,SAAQC,aAAa,QAAO,qCAAoC;AAChE,SAAQC,QAAQ,QAAO,sBAAqB;AAC5C,SAAQC,yBAAyB,QAAO,0CAAyC;AACjF,SAAQC,sBAAsB,QAAO,uCAAsC;AAC3E,SAAQC,iBAAiB,EAAEC,iBAAiB,QAAO,kCAAiC;AACpF,SAAQC,UAAU,QAAO,kBAAiB;AAC1C,SAAQC,gBAAgB,QAAO,wBAAuB;AACtD,SAAQC,uBAAuB,QAAO,+BAA8B;AACpE,SAAQC,iBAAiB,QAAO,yBAAwB;AACxD,SAAQC,aAAa,QAAO,qBAAoB;AAChD,SAAQC,uBAAuB,QAAO,+BAA8B;AAGpE;;;;CAIC,GACD,OAAO,eAAeC,SAASC,OAAqB;IAClD,MAAM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,MAAM,EAAEU,KAAK,CAAC,GAAG;QACzE;QAEAzB,MAAM0B,QAAQ;IAChB,EAAE,OAAO5D,OAAO;QACdyB,KAAKoC,IAAI;QACT3B,MAAMlC,KAAK,CAACA;QACZ,MAAMe,UAAUf,iBAAiB8D,QAAQ9D,MAAMe,OAAO,GAAGgD,OAAO/D;QAChExB,WAAW,CAAC,kCAAkC,CAAC,EAAE;YAACwB;QAAK;QACvDZ,OAAOY,KAAK,CAAC,CAAC,oCAAoC,EAAEe,SAAS,EAAE;YAACd,MAAM;QAAC;IACzE;AACF"}
|
|
@@ -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 {getCliTelemetry, getTimer} from '@sanity/cli-core'\nimport {confirm, logSymbols, select, spinner, type SpinnerInstance} from '@sanity/cli-core/ux'\nimport semver from 'semver'\n\nimport {StudioBuildTrace} from '../../telemetry/build.telemetry.js'\nimport {getAppId} from '../../util/appId.js'\nimport {compareDependencyVersions} from '../../util/compareDependencyVersions.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 {buildDebug} from './buildDebug.js'\nimport {buildStaticFiles} from './buildStaticFiles.js'\nimport {buildVendorDependencies} from './buildVendorDependencies.js'\nimport {checkRequiredDependencies} from './checkRequiredDependencies.js'\nimport {checkStudioDependencyVersions} from './checkStudioDependencyVersions.js'\nimport {determineBasePath} from './determineBasePath.js'\nimport {getAutoUpdatesImportMap} from './getAutoUpdatesImportMap.js'\nimport {getStudioEnvVars} from './getStudioEnvVars.js'\nimport {shouldAutoUpdate} from './shouldAutoUpdate.js'\nimport {type BuildOptions} from './types.js'\n\n/**\n * Build the Sanity Studio.\n *\n * @internal\n */\nexport async function buildStudio(options: BuildOptions): Promise<void> {\n const timer = getTimer()\n const {cliConfig, flags, outDir, output, workDir} = options\n\n const unattendedMode = Boolean(flags.yes)\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 cliConfig,\n output,\n workDir,\n })\n\n const autoUpdatesEnabled = shouldAutoUpdate({cliConfig, flags, output})\n\n let autoUpdatesImports = {}\n\n if (autoUpdatesEnabled) {\n // Get the clean version without build metadata: https://semver.org/#spec-item-10\n const cleanSanityVersion = semver.parse(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 const projectId = cliConfig?.api?.projectId\n const appId = getAppId(cliConfig)\n\n // Warn if auto updates enabled but no appId configured\n if (!appId) {\n warnAboutMissingAppId({appType: 'studio', output, projectId})\n }\n\n const sanityDependencies = [\n {name: 'sanity', version: cleanSanityVersion},\n {name: '@sanity/vision', version: cleanSanityVersion},\n ]\n autoUpdatesImports = getAutoUpdatesImportMap(sanityDependencies, {appId})\n\n // Check the versions\n const result = await compareDependencyVersions(sanityDependencies, workDir)\n\n // If it is in unattended mode, we don't want to prompt\n if (result?.length && !unattendedMode) {\n const choice = await select({\n choices: [\n {\n name: `Upgrade and proceed with build`,\n value: 'upgrade-and-proceed',\n },\n {\n name: `Upgrade only. You will need to run the build command again`,\n value: 'upgrade',\n },\n {name: 'Cancel', value: 'cancel'},\n ],\n default: 'upgrade-and-proceed',\n message: styleText(\n 'yellow',\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 `${result.map((mod) => ` - ${mod.pkg} (local version: ${mod.installed}, runtime version: ${mod.remote})`).join('\\n')} \\n\\n` +\n `Do 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 {\n packageManager: (await getPackageManagerChoice(workDir, {interactive: false})).chosen,\n packages: result.map((res) => [res.pkg, res.remote]),\n },\n {output, workDir},\n )\n\n if (choice !== 'upgrade-and-proceed') {\n output.error('Declined to continue with build', {exit: 1})\n return\n }\n }\n }\n }\n\n const envVarKeys = getStudioEnvVars()\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) {\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(cliConfig, 'studio')\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 importMap\n\n if (autoUpdatesEnabled) {\n importMap = {\n imports: {\n ...(await buildVendorDependencies({basePath, cwd: workDir, outputDir})),\n ...autoUpdatesImports,\n },\n }\n }\n\n try {\n timer.start('bundleStudio')\n\n const bundle = await buildStaticFiles({\n basePath,\n cwd: workDir,\n importMap,\n minify: Boolean(flags.minify),\n outputDir,\n reactCompiler:\n cliConfig && 'reactCompiler' in cliConfig ? cliConfig.reactCompiler : undefined,\n sourceMap: Boolean(flags['source-maps']),\n vite: cliConfig && 'vite' in cliConfig ? cliConfig.vite : undefined,\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 (flags.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","getCliTelemetry","getTimer","confirm","logSymbols","select","spinner","semver","StudioBuildTrace","getAppId","compareDependencyVersions","formatModuleSizes","sortModulesBySize","getPackageManagerChoice","upgradePackages","warnAboutMissingAppId","buildDebug","buildStaticFiles","buildVendorDependencies","checkRequiredDependencies","checkStudioDependencyVersions","determineBasePath","getAutoUpdatesImportMap","getStudioEnvVars","shouldAutoUpdate","buildStudio","options","timer","cliConfig","flags","outDir","output","workDir","unattendedMode","Boolean","yes","defaultOutputDir","resolve","join","outputDir","installedSanityVersion","autoUpdatesEnabled","autoUpdatesImports","cleanSanityVersion","parse","version","Error","log","info","projectId","api","appId","appType","sanityDependencies","name","result","length","choice","choices","value","default","message","map","mod","pkg","installed","remote","error","exit","packageManager","interactive","chosen","packages","res","envVarKeys","key","shouldClean","basePath","spin","start","force","recursive","cleanDuration","end","text","toFixed","succeed","trace","importMap","imports","cwd","bundle","minify","reactCompiler","undefined","sourceMap","vite","outputSize","chunks","flatMap","chunk","modules","renderedLength","reduce","sum","n","buildDuration","complete","stats","slice","fail","String"],"mappings":"AAAA,SAAQA,EAAE,QAAO,mBAAkB;AACnC,OAAOC,UAAU,YAAW;AAC5B,SAAQC,SAAS,QAAO,Y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pC,kBAAkBC,kBAAkB+E,OAAOO,MAAM,EAAEW,KAAK,CAAC,GAAG;QACzE;IACF,EAAE,OAAO1C,OAAO;QACdW,KAAKgC,IAAI;QACTvB,MAAMpB,KAAK,CAACA;QACZ,MAAMN,UAAUM,iBAAiBrB,QAAQqB,MAAMN,OAAO,GAAGkD,OAAO5C;QAChEnD,WAAW,CAAC,6BAA6B,CAAC,EAAE;YAACmD;QAAK;QAClDpC,OAAOoC,KAAK,CAAC,CAAC,+BAA+B,EAAEN,SAAS,EAAE;YAACO,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 {getCliTelemetry, getTimer} from '@sanity/cli-core'\nimport {confirm, logSymbols, select, spinner, type SpinnerInstance} from '@sanity/cli-core/ux'\nimport semver from 'semver'\n\nimport {StudioBuildTrace} from '../../telemetry/build.telemetry.js'\nimport {getAppId} from '../../util/appId.js'\nimport {compareDependencyVersions} from '../../util/compareDependencyVersions.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 {buildDebug} from './buildDebug.js'\nimport {buildStaticFiles} from './buildStaticFiles.js'\nimport {buildVendorDependencies} from './buildVendorDependencies.js'\nimport {checkRequiredDependencies} from './checkRequiredDependencies.js'\nimport {checkStudioDependencyVersions} from './checkStudioDependencyVersions.js'\nimport {determineBasePath} from './determineBasePath.js'\nimport {getAutoUpdatesImportMap} from './getAutoUpdatesImportMap.js'\nimport {getStudioEnvVars} from './getStudioEnvVars.js'\nimport {shouldAutoUpdate} from './shouldAutoUpdate.js'\nimport {type BuildOptions} from './types.js'\n\n/**\n * Build the Sanity Studio.\n *\n * @internal\n */\nexport async function buildStudio(options: BuildOptions): Promise<void> {\n const timer = getTimer()\n const {cliConfig, flags, outDir, output, workDir} = options\n\n const unattendedMode = Boolean(flags.yes)\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 cliConfig,\n output,\n workDir,\n })\n\n const autoUpdatesEnabled = shouldAutoUpdate({cliConfig, flags, output})\n\n let autoUpdatesImports = {}\n\n if (autoUpdatesEnabled) {\n // Get the clean version without build metadata: https://semver.org/#spec-item-10\n const cleanSanityVersion = semver.parse(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 const projectId = cliConfig?.api?.projectId\n const appId = getAppId(cliConfig)\n\n // Warn if auto updates enabled but no appId configured\n if (!appId) {\n warnAboutMissingAppId({appType: 'studio', output, projectId})\n }\n\n const sanityDependencies = [\n {name: 'sanity', version: cleanSanityVersion},\n {name: '@sanity/vision', version: cleanSanityVersion},\n ]\n autoUpdatesImports = getAutoUpdatesImportMap(sanityDependencies, {appId})\n\n // Check the versions\n const result = await compareDependencyVersions(sanityDependencies, workDir)\n\n // If it is in unattended mode, we don't want to prompt\n if (result?.length && !unattendedMode) {\n const choice = await select({\n choices: [\n {\n name: `Upgrade and proceed with build`,\n value: 'upgrade-and-proceed',\n },\n {\n name: `Upgrade only. You will need to run the build command again`,\n value: 'upgrade',\n },\n {name: 'Cancel', value: 'cancel'},\n ],\n default: 'upgrade-and-proceed',\n message: styleText(\n 'yellow',\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 `${result.map((mod) => ` - ${mod.pkg} (local version: ${mod.installed}, runtime version: ${mod.remote})`).join('\\n')} \\n\\n` +\n `Do 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 {\n packageManager: (await getPackageManagerChoice(workDir, {interactive: false})).chosen,\n packages: result.map((res) => [res.pkg, res.remote]),\n },\n {output, workDir},\n )\n\n if (choice !== 'upgrade-and-proceed') {\n output.error('Declined to continue with build', {exit: 1})\n return\n }\n }\n }\n }\n\n const envVarKeys = getStudioEnvVars()\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) {\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(cliConfig, 'studio')\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 importMap\n\n if (autoUpdatesEnabled) {\n importMap = {\n imports: {\n ...(await buildVendorDependencies({basePath, cwd: workDir, isApp: false, outputDir})),\n ...autoUpdatesImports,\n },\n }\n }\n\n try {\n timer.start('bundleStudio')\n\n const bundle = await buildStaticFiles({\n basePath,\n cwd: workDir,\n importMap,\n minify: Boolean(flags.minify),\n outputDir,\n reactCompiler:\n cliConfig && 'reactCompiler' in cliConfig ? cliConfig.reactCompiler : undefined,\n sourceMap: Boolean(flags['source-maps']),\n vite: cliConfig && 'vite' in cliConfig ? cliConfig.vite : undefined,\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 (flags.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","getCliTelemetry","getTimer","confirm","logSymbols","select","spinner","semver","StudioBuildTrace","getAppId","compareDependencyVersions","formatModuleSizes","sortModulesBySize","getPackageManagerChoice","upgradePackages","warnAboutMissingAppId","buildDebug","buildStaticFiles","buildVendorDependencies","checkRequiredDependencies","checkStudioDependencyVersions","determineBasePath","getAutoUpdatesImportMap","getStudioEnvVars","shouldAutoUpdate","buildStudio","options","timer","cliConfig","flags","outDir","output","workDir","unattendedMode","Boolean","yes","defaultOutputDir","resolve","join","outputDir","installedSanityVersion","autoUpdatesEnabled","autoUpdatesImports","cleanSanityVersion","parse","version","Error","log","info","projectId","api","appId","appType","sanityDependencies","name","result","length","choice","choices","value","default","message","map","mod","pkg","installed","remote","error","exit","packageManager","interactive","chosen","packages","res","envVarKeys","key","shouldClean","basePath","spin","start","force","recursive","cleanDuration","end","text","toFixed","succeed","trace","importMap","imports","cwd","isApp","bundle","minify","reactCompiler","undefined","sourceMap","vite","outputSize","chunks","flatMap","chunk","modules","renderedLength","reduce","sum","n","buildDuration","complete","stats","slice","fail","String"],"mappings":"AAAA,SAAQA,EAAE,QAAO,mBAAkB;AACnC,OAAOC,UAAU,YAAW;AAC5B,SAAQC,SAAS,QAAO,YAAW;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GAAG,CAACpC,kBAAkBC,kBAAkBgF,OAAOO,MAAM,EAAEW,KAAK,CAAC,GAAG;QACzE;IACF,EAAE,OAAO3C,OAAO;QACdW,KAAKiC,IAAI;QACTxB,MAAMpB,KAAK,CAACA;QACZ,MAAMN,UAAUM,iBAAiBrB,QAAQqB,MAAMN,OAAO,GAAGmD,OAAO7C;QAChEnD,WAAW,CAAC,6BAA6B,CAAC,EAAE;YAACmD;QAAK;QAClDpC,OAAOoC,KAAK,CAAC,CAAC,+BAA+B,EAAEN,SAAS,EAAE;YAACO,MAAM;QAAC;IACpE;AACF"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import resolveFrom from 'resolve-from';
|
|
1
|
+
import path, { resolve } from 'node:path';
|
|
4
2
|
import semver from 'semver';
|
|
5
3
|
import { build } from 'vite';
|
|
4
|
+
import { getLocalPackageVersion } from '../../util/getLocalPackageVersion.js';
|
|
6
5
|
import { createExternalFromImportMap } from './createExternalFromImportMap.js';
|
|
7
6
|
// Directory where vendor packages will be stored
|
|
8
7
|
const VENDOR_DIR = 'vendor';
|
|
@@ -40,7 +39,9 @@ const VENDOR_IMPORTS = {
|
|
|
40
39
|
'./static': './cjs/react-dom-server.browser.production.js',
|
|
41
40
|
'./static.browser': './cjs/react-dom-server.browser.production.js'
|
|
42
41
|
}
|
|
43
|
-
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const STYLED_COMPONENTS_IMPORTS = {
|
|
44
45
|
'styled-components': {
|
|
45
46
|
'^6.1.0': {
|
|
46
47
|
'.': './dist/styled-components.esm.js',
|
|
@@ -51,36 +52,19 @@ const VENDOR_IMPORTS = {
|
|
|
51
52
|
/**
|
|
52
53
|
* Builds the ESM browser compatible versions of the vendor packages
|
|
53
54
|
* specified in VENDOR_IMPORTS. Returns the `imports` object of an import map.
|
|
54
|
-
*/ export async function buildVendorDependencies({ basePath, cwd, outputDir }) {
|
|
55
|
-
// normalize the CWD to a relative dir for better error messages
|
|
56
|
-
const dir = path.relative(process.cwd(), path.resolve(cwd));
|
|
55
|
+
*/ export async function buildVendorDependencies({ basePath, cwd, isApp, outputDir }) {
|
|
57
56
|
const entry = {};
|
|
58
57
|
const imports = {};
|
|
58
|
+
// If we're building an app, we don't need to build the styled-components package
|
|
59
|
+
const vendorImports = isApp ? VENDOR_IMPORTS : {
|
|
60
|
+
...VENDOR_IMPORTS,
|
|
61
|
+
...STYLED_COMPONENTS_IMPORTS
|
|
62
|
+
};
|
|
59
63
|
// Iterate over each package and its version ranges in VENDOR_IMPORTS
|
|
60
|
-
for (const [packageName, ranges] of Object.entries(
|
|
61
|
-
const
|
|
62
|
-
if (!packageJsonPath) {
|
|
63
|
-
throw new Error(`Could not find package.json for package '${packageName}' from directory '${dir}'. Is it installed?`);
|
|
64
|
-
}
|
|
65
|
-
let packageJson;
|
|
66
|
-
try {
|
|
67
|
-
// Read and parse the package.json file
|
|
68
|
-
packageJson = JSON.parse(await fs.promises.readFile(packageJsonPath, 'utf8'));
|
|
69
|
-
} catch (e) {
|
|
70
|
-
const message = `Could not read package.json for package '${packageName}' from directory '${dir}'`;
|
|
71
|
-
if (typeof e?.message === 'string') {
|
|
72
|
-
// Re-assign the error message so the stack trace is more visible
|
|
73
|
-
e.message = `${message}: ${e.message}`;
|
|
74
|
-
throw e;
|
|
75
|
-
}
|
|
76
|
-
throw new Error(message, {
|
|
77
|
-
cause: e
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
// Coerce the version to a semver-compatible version
|
|
81
|
-
const version = semver.coerce(packageJson.version)?.version;
|
|
64
|
+
for (const [packageName, ranges] of Object.entries(vendorImports)){
|
|
65
|
+
const version = await getLocalPackageVersion(packageName, cwd);
|
|
82
66
|
if (!version) {
|
|
83
|
-
throw new Error(`Could not
|
|
67
|
+
throw new Error(`Could not get version for '${packageName}'`);
|
|
84
68
|
}
|
|
85
69
|
// Sort version ranges in descending order
|
|
86
70
|
const sortedRanges = Object.keys(ranges).toSorted((range1, range2)=>{
|
|
@@ -106,14 +90,9 @@ const VENDOR_IMPORTS = {
|
|
|
106
90
|
const subpaths = ranges[matchedRange];
|
|
107
91
|
// Iterate over each subpath and its corresponding entry point
|
|
108
92
|
for (const [subpath, relativeEntryPoint] of Object.entries(subpaths)){
|
|
109
|
-
const packagePath = path.dirname(packageJsonPath);
|
|
110
|
-
const entryPoint = resolveFrom.silent(packagePath, relativeEntryPoint);
|
|
111
|
-
if (!entryPoint) {
|
|
112
|
-
throw new Error(`Failed to resolve entry point '${path.join(packageName, relativeEntryPoint)}'. `);
|
|
113
|
-
}
|
|
114
93
|
const specifier = path.posix.join(packageName, subpath);
|
|
115
94
|
const chunkName = path.posix.join(packageName, path.relative(packageName, specifier) || 'index');
|
|
116
|
-
entry[chunkName] =
|
|
95
|
+
entry[chunkName] = resolve(`node_modules/${packageName}/${relativeEntryPoint}`);
|
|
117
96
|
imports[specifier] = path.posix.join('/', basePath, VENDOR_DIR, `${chunkName}.mjs`);
|
|
118
97
|
}
|
|
119
98
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/build/buildVendorDependencies.ts"],"sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\n\nimport resolveFrom from 'resolve-from'\nimport semver from 'semver'\nimport {build} from 'vite'\n\nimport {createExternalFromImportMap} from './createExternalFromImportMap.js'\n\n// Directory where vendor packages will be stored\nconst VENDOR_DIR = 'vendor'\n\n/**\n * A type representing the imports of vendor packages, defining specific entry\n * points for various versions and subpaths of the packages.\n *\n * The `VendorImports` object is used to build ESM browser-compatible versions\n * of the specified packages. This approach ensures that the appropriate version\n * and entry points are used for each package, enabling compatibility and proper\n * functionality in the browser environment.\n *\n * ## Rationale\n *\n * The rationale for this structure is to handle different versions of the\n * packages carefully, especially major versions. Major version bumps often\n * introduce breaking changes, so the module scheme for the package needs to be\n * checked when there is a major version update. However, minor and patch\n * versions are generally backward compatible, so they are handled more\n * leniently. By assuming that new minor versions are compatible, we avoid\n * unnecessary warnings and streamline the update process.\n *\n * If a new minor version introduces an additional subpath export within the\n * package of this version range, the corresponding package can add a more\n * specific version range that includes the new subpath. This design allows for\n * flexibility and ease of maintenance, ensuring that the latest features and\n * fixes are incorporated without extensive manual intervention.\n *\n * An additional subpath export within the package of this version range that\n * could cause the build to break if that new export is used, can be treated as\n * a bug fix. It might make more sense to our users that this new subpath isn't\n * supported yet until we address it as a bug fix. This approach helps maintain\n * stability and prevents unexpected issues during the build process.\n *\n * ## Structure\n * The `VendorImports` type is a nested object where:\n * - The keys at the first level represent the package names.\n * - The keys at the second level represent the version ranges (e.g., `^19.0.0`).\n * - The keys at the third level represent the subpaths within the package (e.g., `.` for the main entry point).\n * - The values at the third level are the relative paths to the corresponding entry points within the package.\n *\n * This structure allows for precise specification of the entry points for\n * different versions and subpaths, ensuring that the correct files are used\n * during the build process.\n */\ntype VendorImports = {\n [packageName: string]: {\n [versionRange: string]: {\n [subpath: string]: string\n }\n }\n}\n\n// Define the vendor packages and their corresponding versions and entry points\nconst VENDOR_IMPORTS: VendorImports = {\n react: {\n '^18.0.0': {\n '.': './cjs/react.production.min.js',\n './jsx-dev-runtime': './cjs/react-jsx-dev-runtime.production.min.js',\n './jsx-runtime': './cjs/react-jsx-runtime.production.min.js',\n './package.json': './package.json',\n },\n '^19.0.0': {\n '.': './cjs/react.production.js',\n './compiler-runtime': './cjs/react-compiler-runtime.production.js',\n './jsx-dev-runtime': './cjs/react-jsx-dev-runtime.production.js',\n './jsx-runtime': './cjs/react-jsx-runtime.production.js',\n './package.json': './package.json',\n },\n },\n 'react-dom': {\n '^18.0.0': {\n '.': './cjs/react-dom.production.min.js',\n './client': './cjs/react-dom.production.min.js',\n './package.json': './package.json',\n './server': './cjs/react-dom-server-legacy.browser.production.min.js',\n './server.browser': './cjs/react-dom-server-legacy.browser.production.min.js',\n },\n '^19.0.0': {\n '.': './cjs/react-dom.production.js',\n './client': './cjs/react-dom-client.production.js',\n './package.json': './package.json',\n './server': './cjs/react-dom-server-legacy.browser.production.js',\n './server.browser': './cjs/react-dom-server-legacy.browser.production.js',\n './static': './cjs/react-dom-server.browser.production.js',\n './static.browser': './cjs/react-dom-server.browser.production.js',\n },\n },\n 'styled-components': {\n '^6.1.0': {\n '.': './dist/styled-components.esm.js',\n './package.json': './package.json',\n },\n },\n}\n\ninterface VendorBuildOptions {\n basePath: string\n cwd: string\n outputDir: string\n}\n\n/**\n * Builds the ESM browser compatible versions of the vendor packages\n * specified in VENDOR_IMPORTS. Returns the `imports` object of an import map.\n */\nexport async function buildVendorDependencies({\n basePath,\n cwd,\n outputDir,\n}: VendorBuildOptions): Promise<Record<string, string>> {\n // normalize the CWD to a relative dir for better error messages\n const dir = path.relative(process.cwd(), path.resolve(cwd))\n const entry: Record<string, string> = {}\n const imports: Record<string, string> = {}\n\n // Iterate over each package and its version ranges in VENDOR_IMPORTS\n for (const [packageName, ranges] of Object.entries(VENDOR_IMPORTS)) {\n const packageJsonPath = resolveFrom.silent(cwd, path.join(packageName, 'package.json'))\n if (!packageJsonPath) {\n throw new Error(\n `Could not find package.json for package '${packageName}' from directory '${dir}'. Is it installed?`,\n )\n }\n\n let packageJson\n\n try {\n // Read and parse the package.json file\n packageJson = JSON.parse(await fs.promises.readFile(packageJsonPath, 'utf8'))\n } catch (e) {\n const message = `Could not read package.json for package '${packageName}' from directory '${dir}'`\n if (typeof e?.message === 'string') {\n // Re-assign the error message so the stack trace is more visible\n e.message = `${message}: ${e.message}`\n throw e\n }\n\n throw new Error(message, {cause: e})\n }\n\n // Coerce the version to a semver-compatible version\n const version = semver.coerce(packageJson.version)?.version\n if (!version) {\n throw new Error(`Could not parse version '${packageJson.version}' from '${packageName}'`)\n }\n\n // Sort version ranges in descending order\n const sortedRanges = Object.keys(ranges).toSorted((range1, range2) => {\n const min1 = semver.minVersion(range1)\n const min2 = semver.minVersion(range2)\n\n if (!min1) throw new Error(`Could not parse range '${range1}'`)\n if (!min2) throw new Error(`Could not parse range '${range2}'`)\n\n // sort them in reverse so we can rely on array `.find` below\n return semver.rcompare(min1.version, min2.version)\n })\n\n // Find the first version range that satisfies the package version\n const matchedRange = sortedRanges.find((range) => semver.satisfies(version, range))\n\n if (!matchedRange) {\n const min = semver.minVersion(sortedRanges.at(-1)!)\n if (!min) {\n throw new Error(`Could not find a minimum version for package '${packageName}'`)\n }\n\n if (semver.gt(min.version, version)) {\n throw new Error(`Package '${packageName}' requires at least ${min.version}.`)\n }\n\n throw new Error(`Version '${version}' of package '${packageName}' is not supported yet.`)\n }\n\n const subpaths = ranges[matchedRange]\n\n // Iterate over each subpath and its corresponding entry point\n for (const [subpath, relativeEntryPoint] of Object.entries(subpaths)) {\n const packagePath = path.dirname(packageJsonPath)\n const entryPoint = resolveFrom.silent(packagePath, relativeEntryPoint)\n\n if (!entryPoint) {\n throw new Error(\n `Failed to resolve entry point '${path.join(packageName, relativeEntryPoint)}'. `,\n )\n }\n\n const specifier = path.posix.join(packageName, subpath)\n const chunkName = path.posix.join(\n packageName,\n path.relative(packageName, specifier) || 'index',\n )\n\n entry[chunkName] = entryPoint\n imports[specifier] = path.posix.join('/', basePath, VENDOR_DIR, `${chunkName}.mjs`)\n }\n }\n\n // removes the `RollupWatcher` type\n type BuildResult = Exclude<Awaited<ReturnType<typeof build>>, {close: unknown}>\n\n // Use Vite to build the packages into the output directory\n let buildResult = (await build({\n appType: 'custom',\n build: {\n commonjsOptions: {strictRequires: 'auto'},\n emptyOutDir: false, // Rely on CLI to do this\n lib: {entry, formats: ['es']},\n minify: true,\n outDir: path.join(outputDir, VENDOR_DIR),\n rollupOptions: {\n external: createExternalFromImportMap({imports}),\n output: {\n chunkFileNames: '[name]-[hash].mjs',\n entryFileNames: '[name]-[hash].mjs',\n exports: 'named',\n format: 'es',\n },\n treeshake: {preset: 'recommended'},\n },\n },\n // Define a custom cache directory so that sanity's vite cache\n // does not conflict with any potential local vite projects\n cacheDir: 'node_modules/.sanity/vite-vendor',\n configFile: false,\n define: {'process.env.NODE_ENV': JSON.stringify('production')},\n logLevel: 'silent',\n mode: 'production',\n root: cwd,\n })) as BuildResult\n\n buildResult = Array.isArray(buildResult) ? buildResult : [buildResult]\n\n // Create a map of the original import specifiers to their hashed filenames\n const hashedImports: Record<string, string> = {}\n const output = buildResult.flatMap((i) => i.output)\n\n for (const chunk of output) {\n if (chunk.type === 'asset') continue\n\n for (const [specifier, originalPath] of Object.entries(imports)) {\n if (originalPath.endsWith(`${chunk.name}.mjs`)) {\n hashedImports[specifier] = path.posix.join('/', basePath, VENDOR_DIR, chunk.fileName)\n }\n }\n }\n\n return hashedImports\n}\n"],"names":["fs","path","resolveFrom","semver","build","createExternalFromImportMap","VENDOR_DIR","VENDOR_IMPORTS","react","buildVendorDependencies","basePath","cwd","outputDir","dir","relative","process","resolve","entry","imports","packageName","ranges","Object","entries","packageJsonPath","silent","join","Error","packageJson","JSON","parse","promises","readFile","e","message","cause","version","coerce","sortedRanges","keys","toSorted","range1","range2","min1","minVersion","min2","rcompare","matchedRange","find","range","satisfies","min","at","gt","subpaths","subpath","relativeEntryPoint","packagePath","dirname","entryPoint","specifier","posix","chunkName","buildResult","appType","commonjsOptions","strictRequires","emptyOutDir","lib","formats","minify","outDir","rollupOptions","external","output","chunkFileNames","entryFileNames","exports","format","treeshake","preset","cacheDir","configFile","define","stringify","logLevel","mode","root","Array","isArray","hashedImports","flatMap","i","chunk","type","originalPath","endsWith","name","fileName"],"mappings":"AAAA,OAAOA,QAAQ,UAAS;AACxB,OAAOC,UAAU,YAAW;AAE5B,OAAOC,iBAAiB,eAAc;AACtC,OAAOC,YAAY,SAAQ;AAC3B,SAAQC,KAAK,QAAO,OAAM;AAE1B,SAAQC,2BAA2B,QAAO,mCAAkC;AAE5E,iDAAiD;AACjD,MAAMC,aAAa;AAoDnB,+EAA+E;AAC/E,MAAMC,iBAAgC;IACpCC,OAAO;QACL,WAAW;YACT,KAAK;YACL,qBAAqB;YACrB,iBAAiB;YACjB,kBAAkB;QACp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;YAAC,wBAAwBtD,KAAKuD,SAAS,CAAC;QAAa;QAC7DC,UAAU;QACVC,MAAM;QACNC,MAAM3E;IACR;IAEAmD,cAAcyB,MAAMC,OAAO,CAAC1B,eAAeA,cAAc;QAACA;KAAY;IAEtE,2EAA2E;IAC3E,MAAM2B,gBAAwC,CAAC;IAC/C,MAAMhB,SAASX,YAAY4B,OAAO,CAAC,CAACC,IAAMA,EAAElB,MAAM;IAElD,KAAK,MAAMmB,SAASnB,OAAQ;QAC1B,IAAImB,MAAMC,IAAI,KAAK,SAAS;QAE5B,KAAK,MAAM,CAAClC,WAAWmC,aAAa,IAAIzE,OAAOC,OAAO,CAACJ,SAAU;YAC/D,IAAI4E,aAAaC,QAAQ,CAAC,GAAGH,MAAMI,IAAI,CAAC,IAAI,CAAC,GAAG;gBAC9CP,aAAa,CAAC9B,UAAU,GAAG1D,KAAK2D,KAAK,CAACnC,IAAI,CAAC,KAAKf,UAAUJ,YAAYsF,MAAMK,QAAQ;YACtF;QACF;IACF;IAEA,OAAOR;AACT"}
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/build/buildVendorDependencies.ts"],"sourcesContent":["import path, {resolve} from 'node:path'\n\nimport semver from 'semver'\nimport {build} from 'vite'\n\nimport {getLocalPackageVersion} from '../../util/getLocalPackageVersion.js'\nimport {createExternalFromImportMap} from './createExternalFromImportMap.js'\n\n// Directory where vendor packages will be stored\nconst VENDOR_DIR = 'vendor'\n\n/**\n * A type representing the imports of vendor packages, defining specific entry\n * points for various versions and subpaths of the packages.\n *\n * The `VendorImports` object is used to build ESM browser-compatible versions\n * of the specified packages. This approach ensures that the appropriate version\n * and entry points are used for each package, enabling compatibility and proper\n * functionality in the browser environment.\n *\n * ## Rationale\n *\n * The rationale for this structure is to handle different versions of the\n * packages carefully, especially major versions. Major version bumps often\n * introduce breaking changes, so the module scheme for the package needs to be\n * checked when there is a major version update. However, minor and patch\n * versions are generally backward compatible, so they are handled more\n * leniently. By assuming that new minor versions are compatible, we avoid\n * unnecessary warnings and streamline the update process.\n *\n * If a new minor version introduces an additional subpath export within the\n * package of this version range, the corresponding package can add a more\n * specific version range that includes the new subpath. This design allows for\n * flexibility and ease of maintenance, ensuring that the latest features and\n * fixes are incorporated without extensive manual intervention.\n *\n * An additional subpath export within the package of this version range that\n * could cause the build to break if that new export is used, can be treated as\n * a bug fix. It might make more sense to our users that this new subpath isn't\n * supported yet until we address it as a bug fix. This approach helps maintain\n * stability and prevents unexpected issues during the build process.\n *\n * ## Structure\n * The `VendorImports` type is a nested object where:\n * - The keys at the first level represent the package names.\n * - The keys at the second level represent the version ranges (e.g., `^19.0.0`).\n * - The keys at the third level represent the subpaths within the package (e.g., `.` for the main entry point).\n * - The values at the third level are the relative paths to the corresponding entry points within the package.\n *\n * This structure allows for precise specification of the entry points for\n * different versions and subpaths, ensuring that the correct files are used\n * during the build process.\n */\ntype VendorImports = {\n [packageName: string]: {\n [versionRange: string]: {\n [subpath: string]: string\n }\n }\n}\n\n// Define the vendor packages and their corresponding versions and entry points\nconst VENDOR_IMPORTS: VendorImports = {\n react: {\n '^18.0.0': {\n '.': './cjs/react.production.min.js',\n './jsx-dev-runtime': './cjs/react-jsx-dev-runtime.production.min.js',\n './jsx-runtime': './cjs/react-jsx-runtime.production.min.js',\n './package.json': './package.json',\n },\n '^19.0.0': {\n '.': './cjs/react.production.js',\n './compiler-runtime': './cjs/react-compiler-runtime.production.js',\n './jsx-dev-runtime': './cjs/react-jsx-dev-runtime.production.js',\n './jsx-runtime': './cjs/react-jsx-runtime.production.js',\n './package.json': './package.json',\n },\n },\n 'react-dom': {\n '^18.0.0': {\n '.': './cjs/react-dom.production.min.js',\n './client': './cjs/react-dom.production.min.js',\n './package.json': './package.json',\n './server': './cjs/react-dom-server-legacy.browser.production.min.js',\n './server.browser': './cjs/react-dom-server-legacy.browser.production.min.js',\n },\n '^19.0.0': {\n '.': './cjs/react-dom.production.js',\n './client': './cjs/react-dom-client.production.js',\n './package.json': './package.json',\n './server': './cjs/react-dom-server-legacy.browser.production.js',\n './server.browser': './cjs/react-dom-server-legacy.browser.production.js',\n './static': './cjs/react-dom-server.browser.production.js',\n './static.browser': './cjs/react-dom-server.browser.production.js',\n },\n },\n}\n\nconst STYLED_COMPONENTS_IMPORTS = {\n 'styled-components': {\n '^6.1.0': {\n '.': './dist/styled-components.esm.js',\n './package.json': './package.json',\n },\n },\n}\n\ninterface VendorBuildOptions {\n basePath: string\n cwd: string\n isApp: boolean\n outputDir: string\n}\n\n/**\n * Builds the ESM browser compatible versions of the vendor packages\n * specified in VENDOR_IMPORTS. Returns the `imports` object of an import map.\n */\nexport async function buildVendorDependencies({\n basePath,\n cwd,\n isApp,\n outputDir,\n}: VendorBuildOptions): Promise<Record<string, string>> {\n const entry: Record<string, string> = {}\n const imports: Record<string, string> = {}\n\n // If we're building an app, we don't need to build the styled-components package\n const vendorImports = isApp ? VENDOR_IMPORTS : {...VENDOR_IMPORTS, ...STYLED_COMPONENTS_IMPORTS}\n\n // Iterate over each package and its version ranges in VENDOR_IMPORTS\n for (const [packageName, ranges] of Object.entries(vendorImports)) {\n const version = await getLocalPackageVersion(packageName, cwd)\n if (!version) {\n throw new Error(`Could not get version for '${packageName}'`)\n }\n\n // Sort version ranges in descending order\n const sortedRanges = Object.keys(ranges).toSorted((range1, range2) => {\n const min1 = semver.minVersion(range1)\n const min2 = semver.minVersion(range2)\n\n if (!min1) throw new Error(`Could not parse range '${range1}'`)\n if (!min2) throw new Error(`Could not parse range '${range2}'`)\n\n // sort them in reverse so we can rely on array `.find` below\n return semver.rcompare(min1.version, min2.version)\n })\n\n // Find the first version range that satisfies the package version\n const matchedRange = sortedRanges.find((range) => semver.satisfies(version, range))\n\n if (!matchedRange) {\n const min = semver.minVersion(sortedRanges.at(-1)!)\n if (!min) {\n throw new Error(`Could not find a minimum version for package '${packageName}'`)\n }\n\n if (semver.gt(min.version, version)) {\n throw new Error(`Package '${packageName}' requires at least ${min.version}.`)\n }\n\n throw new Error(`Version '${version}' of package '${packageName}' is not supported yet.`)\n }\n\n const subpaths = ranges[matchedRange]\n\n // Iterate over each subpath and its corresponding entry point\n for (const [subpath, relativeEntryPoint] of Object.entries(subpaths)) {\n const specifier = path.posix.join(packageName, subpath)\n const chunkName = path.posix.join(\n packageName,\n path.relative(packageName, specifier) || 'index',\n )\n\n entry[chunkName] = resolve(`node_modules/${packageName}/${relativeEntryPoint}`)\n imports[specifier] = path.posix.join('/', basePath, VENDOR_DIR, `${chunkName}.mjs`)\n }\n }\n\n // removes the `RollupWatcher` type\n type BuildResult = Exclude<Awaited<ReturnType<typeof build>>, {close: unknown}>\n\n // Use Vite to build the packages into the output directory\n let buildResult = (await build({\n appType: 'custom',\n build: {\n commonjsOptions: {strictRequires: 'auto'},\n emptyOutDir: false, // Rely on CLI to do this\n lib: {entry, formats: ['es']},\n minify: true,\n outDir: path.join(outputDir, VENDOR_DIR),\n rollupOptions: {\n external: createExternalFromImportMap({imports}),\n output: {\n chunkFileNames: '[name]-[hash].mjs',\n entryFileNames: '[name]-[hash].mjs',\n exports: 'named',\n format: 'es',\n },\n treeshake: {preset: 'recommended'},\n },\n },\n // Define a custom cache directory so that sanity's vite cache\n // does not conflict with any potential local vite projects\n cacheDir: 'node_modules/.sanity/vite-vendor',\n configFile: false,\n define: {'process.env.NODE_ENV': JSON.stringify('production')},\n logLevel: 'silent',\n mode: 'production',\n root: cwd,\n })) as BuildResult\n\n buildResult = Array.isArray(buildResult) ? buildResult : [buildResult]\n\n // Create a map of the original import specifiers to their hashed filenames\n const hashedImports: Record<string, string> = {}\n const output = buildResult.flatMap((i) => i.output)\n\n for (const chunk of output) {\n if (chunk.type === 'asset') continue\n\n for (const [specifier, originalPath] of Object.entries(imports)) {\n if (originalPath.endsWith(`${chunk.name}.mjs`)) {\n hashedImports[specifier] = path.posix.join('/', basePath, VENDOR_DIR, chunk.fileName)\n }\n }\n }\n\n return hashedImports\n}\n"],"names":["path","resolve","semver","build","getLocalPackageVersion","createExternalFromImportMap","VENDOR_DIR","VENDOR_IMPORTS","react","STYLED_COMPONENTS_IMPORTS","buildVendorDependencies","basePath","cwd","isApp","outputDir","entry","imports","vendorImports","packageName","ranges","Object","entries","version","Error","sortedRanges","keys","toSorted","range1","range2","min1","minVersion","min2","rcompare","matchedRange","find","range","satisfies","min","at","gt","subpaths","subpath","relativeEntryPoint","specifier","posix","join","chunkName","relative","buildResult","appType","commonjsOptions","strictRequires","emptyOutDir","lib","formats","minify","outDir","rollupOptions","external","output","chunkFileNames","entryFileNames","exports","format","treeshake","preset","cacheDir","configFile","define","JSON","stringify","logLevel","mode","root","Array","isArray","hashedImports","flatMap","i","chunk","type","originalPath","endsWith","name","fileName"],"mappings":"AAAA,OAAOA,QAAOC,OAAO,QAAO,YAAW;AAEvC,OAAOC,YAAY,SAAQ;AAC3B,SAAQC,KAAK,QAAO,OAAM;AAE1B,SAAQC,sBAAsB,QAAO,uCAAsC;AAC3E,SAAQC,2BAA2B,QAAO,mCAAkC;AAE5E,iDAAiD;AACjD,MAAMC,aAAa;AAoDnB,+EAA+E;AAC/E,MAAMC,iBAAgC;IACpCC,OAAO;QACL,WAAW;YACT,KAAK;YACL,qBAAqB;YACrB,iBAAiB;YACjB,kBAAkB;QACpB;QACA,WAAW;YACT,KAAK;YACL,sBAAsB;YACtB,qBAAqB;YACrB,iBAAiB;YACjB,kBAAkB;QACpB;IACF;IACA,aAAa;QACX,WAAW;YACT,KAAK;YACL,YAAY;YACZ,kBAAkB;YAClB,YAAY;YACZ,oBAAoB;QACtB;QACA,WAAW;YACT,KAAK;YACL,YAAY;YACZ,kBAAkB;YAClB,YAAY;YACZ,oBAAoB;YACpB,YAAY;YACZ,oBAAoB;QACtB;IACF;AACF;AAEA,MAAMC,4BAA4B;IAChC,qBAAqB;QACnB,UAAU;YACR,KAAK;YACL,kBAAkB;QACpB;IACF;AACF;AASA;;;CAGC,GACD,OAAO,eAAeC,wBAAwB,EAC5CC,QAAQ,EACRC,GAAG,EACHC,KAAK,EACLC,SAAS,EACU;IAC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IACR;IAEAoC,cAAc0B,MAAMC,OAAO,CAAC3B,eAAeA,cAAc;QAACA;KAAY;IAEtE,2EAA2E;IAC3E,MAAM4B,gBAAwC,CAAC;IAC/C,MAAMjB,SAASX,YAAY6B,OAAO,CAAC,CAACC,IAAMA,EAAEnB,MAAM;IAElD,KAAK,MAAMoB,SAASpB,OAAQ;QAC1B,IAAIoB,MAAMC,IAAI,KAAK,SAAS;QAE5B,KAAK,MAAM,CAACrC,WAAWsC,aAAa,IAAI7D,OAAOC,OAAO,CAACL,SAAU;YAC/D,IAAIiE,aAAaC,QAAQ,CAAC,GAAGH,MAAMI,IAAI,CAAC,IAAI,CAAC,GAAG;gBAC9CP,aAAa,CAACjC,UAAU,GAAG3C,KAAK4C,KAAK,CAACC,IAAI,CAAC,KAAKlC,UAAUL,YAAYyE,MAAMK,QAAQ;YACtF;QACF;IACF;IAEA,OAAOR;AACT"}
|
|
@@ -3,7 +3,7 @@ import { readPackageJson } from '@sanity/cli-core';
|
|
|
3
3
|
import { oneline } from 'oneline';
|
|
4
4
|
import semver from 'semver';
|
|
5
5
|
import { determineIsApp } from '../../util/determineIsApp.js';
|
|
6
|
-
import {
|
|
6
|
+
import { getLocalPackageVersion } from '../../util/getLocalPackageVersion.js';
|
|
7
7
|
const defaultStudioManifestProps = {
|
|
8
8
|
name: 'studio',
|
|
9
9
|
version: '1.0.0'
|
|
@@ -34,8 +34,8 @@ const styledComponentsVersionRange = '^6.1.15';
|
|
|
34
34
|
defaults: defaultStudioManifestProps,
|
|
35
35
|
skipSchemaValidation: true
|
|
36
36
|
}),
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
getLocalPackageVersion('styled-components', studioPath),
|
|
38
|
+
getLocalPackageVersion('sanity', studioPath)
|
|
39
39
|
]);
|
|
40
40
|
const wantedStyledComponentsVersionRange = styledComponentsVersionRange;
|
|
41
41
|
// Retrieve the version of the 'sanity' dependency
|
|
@@ -62,6 +62,8 @@ const styledComponentsVersionRange = '^6.1.15';
|
|
|
62
62
|
installedSanityVersion
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
|
+
// We ignore catalog identifiers since we check the actual version anyway
|
|
66
|
+
const isStyledComponentsVersionRangeInCatalog = declaredStyledComponentsVersion.startsWith('catalog:');
|
|
65
67
|
// Theoretically the version specified in package.json could be incorrect, eg `foo`
|
|
66
68
|
let minDeclaredStyledComponentsVersion = null;
|
|
67
69
|
try {
|
|
@@ -69,7 +71,7 @@ const styledComponentsVersionRange = '^6.1.15';
|
|
|
69
71
|
} catch {
|
|
70
72
|
// Intentional fall-through (variable will be left as null, throwing below)
|
|
71
73
|
}
|
|
72
|
-
if (!minDeclaredStyledComponentsVersion) {
|
|
74
|
+
if (!minDeclaredStyledComponentsVersion && !isStyledComponentsVersionRangeInCatalog) {
|
|
73
75
|
output.error(oneline`
|
|
74
76
|
Declared dependency \`styled-components\` has an invalid version range:
|
|
75
77
|
\`${declaredStyledComponentsVersion}\`.
|
|
@@ -86,7 +88,7 @@ const styledComponentsVersionRange = '^6.1.15';
|
|
|
86
88
|
// Exception: Ranges are hard to compare. `>=5.0.0 && <=5.3.2 || ^6`... Comparing this
|
|
87
89
|
// to anything is going to be challenging, so only compare "simple" ranges/versions
|
|
88
90
|
// (^x.x.x / ~x.x.x / x.x.x)
|
|
89
|
-
if (isComparableRange(declaredStyledComponentsVersion) && !semver.satisfies(minDeclaredStyledComponentsVersion, wantedStyledComponentsVersionRange)) {
|
|
91
|
+
if (!isStyledComponentsVersionRangeInCatalog && isComparableRange(declaredStyledComponentsVersion) && !semver.satisfies(minDeclaredStyledComponentsVersion, wantedStyledComponentsVersionRange)) {
|
|
90
92
|
output.warn(oneline`
|
|
91
93
|
Declared version of styled-components (${declaredStyledComponentsVersion})
|
|
92
94
|
is not compatible with the version required by sanity (${wantedStyledComponentsVersionRange}).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/build/checkRequiredDependencies.ts"],"sourcesContent":["import path from 'node:path'\n\nimport {type CliConfig, type Output, type PackageJson, readPackageJson} from '@sanity/cli-core'\nimport {oneline} from 'oneline'\nimport semver, {type SemVer} from 'semver'\n\nimport {determineIsApp} from '../../util/determineIsApp.js'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/build/checkRequiredDependencies.ts"],"sourcesContent":["import path from 'node:path'\n\nimport {type CliConfig, type Output, type PackageJson, readPackageJson} from '@sanity/cli-core'\nimport {oneline} from 'oneline'\nimport semver, {type SemVer} from 'semver'\n\nimport {determineIsApp} from '../../util/determineIsApp.js'\nimport {getLocalPackageVersion} from '../../util/getLocalPackageVersion.js'\n\nconst defaultStudioManifestProps: Partial<PackageJson> = {\n name: 'studio',\n version: '1.0.0',\n}\n\ninterface CheckResult {\n installedSanityVersion: string\n}\n\ninterface CheckRequiredDependenciesOptions {\n cliConfig: CliConfig\n output: Output\n workDir: string\n}\n\nconst styledComponentsVersionRange = '^6.1.15'\n\n/**\n * Checks that the studio has declared and installed the required dependencies\n * needed by the Sanity modules. While we generally use regular, explicit\n * dependencies in modules, there are certain dependencies that are better\n * served being peer dependencies, such as react and styled-components.\n *\n * If these dependencies are not installed/declared, we report an error\n * and instruct the user to install them manually.\n *\n * Additionally, returns the version of the 'sanity' dependency from the package.json.\n */\nexport async function checkRequiredDependencies(\n options: CheckRequiredDependenciesOptions,\n): Promise<CheckResult> {\n const {cliConfig, output, workDir: studioPath} = options\n // currently there's no check needed for core apps,\n // but this should be removed once they are more mature\n const isApp = determineIsApp(cliConfig)\n if (isApp) {\n return {installedSanityVersion: ''}\n }\n\n const [studioPackageManifest, installedStyledComponentsVersion, installedSanityVersion] =\n await Promise.all([\n readPackageJson(path.join(studioPath, 'package.json'), {\n defaults: defaultStudioManifestProps,\n skipSchemaValidation: true,\n }),\n getLocalPackageVersion('styled-components', studioPath),\n getLocalPackageVersion('sanity', studioPath),\n ])\n\n const wantedStyledComponentsVersionRange = styledComponentsVersionRange\n\n // Retrieve the version of the 'sanity' dependency\n if (!installedSanityVersion) {\n output.error('Failed to read the installed sanity version.', {exit: 1})\n return {installedSanityVersion: ''}\n }\n\n // The studio _must_ now declare `styled-components` as a dependency. If it's not there,\n // we'll want to automatically _add it_ to the manifest and tell the user to reinstall\n // dependencies before running whatever command was being run\n const declaredStyledComponentsVersion =\n studioPackageManifest.dependencies?.['styled-components'] ||\n studioPackageManifest?.devDependencies?.['styled-components']\n\n if (!declaredStyledComponentsVersion) {\n output.error(\n oneline`\n Declared dependency \\`styled-components\\` is not installed - run\n \\`npm install\\`, \\`yarn install\\` or \\`pnpm install\\` to install it before re-running this command.\n `,\n {exit: 1},\n )\n return {installedSanityVersion}\n }\n\n // We ignore catalog identifiers since we check the actual version anyway\n const isStyledComponentsVersionRangeInCatalog =\n declaredStyledComponentsVersion.startsWith('catalog:')\n // Theoretically the version specified in package.json could be incorrect, eg `foo`\n let minDeclaredStyledComponentsVersion: SemVer | null = null\n try {\n minDeclaredStyledComponentsVersion = semver.minVersion(declaredStyledComponentsVersion)\n } catch {\n // Intentional fall-through (variable will be left as null, throwing below)\n }\n\n if (!minDeclaredStyledComponentsVersion && !isStyledComponentsVersionRangeInCatalog) {\n output.error(\n oneline`\n Declared dependency \\`styled-components\\` has an invalid version range:\n \\`${declaredStyledComponentsVersion}\\`.\n `,\n {exit: 1},\n )\n return {installedSanityVersion}\n }\n\n // The declared version should be semver-compatible with the version specified as a\n // peer dependency in `sanity`. If not, we should tell the user to change it.\n //\n // Exception: Ranges are hard to compare. `>=5.0.0 && <=5.3.2 || ^6`... Comparing this\n // to anything is going to be challenging, so only compare \"simple\" ranges/versions\n // (^x.x.x / ~x.x.x / x.x.x)\n if (\n !isStyledComponentsVersionRangeInCatalog &&\n isComparableRange(declaredStyledComponentsVersion) &&\n !semver.satisfies(minDeclaredStyledComponentsVersion!, wantedStyledComponentsVersionRange)\n ) {\n output.warn(oneline`\n Declared version of styled-components (${declaredStyledComponentsVersion})\n is not compatible with the version required by sanity (${wantedStyledComponentsVersionRange}).\n This might cause problems!\n `)\n }\n\n // Ensure the studio has _installed_ a version of `styled-components`\n if (!installedStyledComponentsVersion) {\n output.error(\n oneline`\n Declared dependency \\`styled-components\\` is not installed - run\n \\`npm install\\`, \\`yarn install\\` or \\`pnpm install\\` to install it before re-running this command.\n `,\n {exit: 1},\n )\n return {installedSanityVersion}\n }\n\n // The studio should have an _installed_ version of `styled-components`, and it should\n // be semver compatible with the version specified in `sanity` peer dependencies.\n if (!semver.satisfies(installedStyledComponentsVersion, wantedStyledComponentsVersionRange)) {\n output.warn(oneline`\n Installed version of styled-components (${installedStyledComponentsVersion})\n is not compatible with the version required by sanity (${wantedStyledComponentsVersionRange}).\n This might cause problems!\n `)\n }\n\n return {installedSanityVersion}\n}\n\nfunction isComparableRange(range: string): boolean {\n return /^[\\^~]?\\d+(\\.\\d+)?(\\.\\d+)?$/.test(range)\n}\n"],"names":["path","readPackageJson","oneline","semver","determineIsApp","getLocalPackageVersion","defaultStudioManifestProps","name","version","styledComponentsVersionRange","checkRequiredDependencies","options","cliConfig","output","workDir","studioPath","isApp","installedSanityVersion","studioPackageManifest","installedStyledComponentsVersion","Promise","all","join","defaults","skipSchemaValidation","wantedStyledComponentsVersionRange","error","exit","declaredStyledComponentsVersion","dependencies","devDependencies","isStyledComponentsVersionRangeInCatalog","startsWith","minDeclaredStyledComponentsVersion","minVersion","isComparableRange","satisfies","warn","range","test"],"mappings":"AAAA,OAAOA,UAAU,YAAW;AAE5B,SAAuDC,eAAe,QAAO,mBAAkB;AAC/F,SAAQC,OAAO,QAAO,UAAS;AAC/B,OAAOC,YAA2B,SAAQ;AAE1C,SAAQC,cAAc,QAAO,+BAA8B;AAC3D,SAAQC,sBAAsB,QAAO,uCAAsC;AAE3E,MAAMC,6BAAmD;IACvDC,MAAM;IACNC,SAAS;AACX;AAYA,MAAMC,+BAA+B;AAErC;;;;;;;;;;CAUC,GACD,OAAO,eAAeC,0BACpBC,OAAyC;IAEzC,MAAM,EAACC,SAAS,EAAEC,MAAM,EAAEC,SAASC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AA4B;IAC5B,IACE,CAACc,2CACDI,kBAAkBP,oCAClB,CAACzB,OAAOiC,SAAS,CAACH,oCAAqCR,qCACvD;QACAZ,OAAOwB,IAAI,CAACnC,OAAO,CAAC;6CACqB,EAAE0B,gCAAgC;6DAClB,EAAEH,mCAAmC;;IAE9F,CAAC;IACH;IAEA,qEAAqE;IACrE,IAAI,CAACN,kCAAkC;QACrCN,OAAOa,KAAK,CACVxB,OAAO,CAAC;;;IAGV,CAAC,EACC;YAACyB,MAAM;QAAC;QAEV,OAAO;YAACV;QAAsB;IAChC;IAEA,sFAAsF;IACtF,iFAAiF;IACjF,IAAI,CAACd,OAAOiC,SAAS,CAACjB,kCAAkCM,qCAAqC;QAC3FZ,OAAOwB,IAAI,CAACnC,OAAO,CAAC;8CACsB,EAAEiB,iCAAiC;6DACpB,EAAEM,mCAAmC;;IAE9F,CAAC;IACH;IAEA,OAAO;QAACR;IAAsB;AAChC;AAEA,SAASkB,kBAAkBG,KAAa;IACtC,OAAO,8BAA8BC,IAAI,CAACD;AAC5C"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { readPackageJson } from '@sanity/cli-core';
|
|
3
|
-
import resolveFrom from 'resolve-from';
|
|
4
3
|
import semver from 'semver';
|
|
4
|
+
import { getLocalPackageVersion } from '../../util/getLocalPackageVersion.js';
|
|
5
5
|
// NOTE: when doing changes here, also remember to update versions in help docs at
|
|
6
6
|
// https://sanity.io/admin/structure/docs;helpArticle;upgrade-packages
|
|
7
|
-
const
|
|
7
|
+
const DEFAULT_PACKAGES = [
|
|
8
8
|
{
|
|
9
9
|
deprecatedBelow: null,
|
|
10
10
|
name: 'react',
|
|
@@ -35,7 +35,7 @@ const PACKAGES = [
|
|
|
35
35
|
]
|
|
36
36
|
}
|
|
37
37
|
];
|
|
38
|
-
export async function checkStudioDependencyVersions(workDir, output) {
|
|
38
|
+
export async function checkStudioDependencyVersions(workDir, output, { packages = DEFAULT_PACKAGES } = {}) {
|
|
39
39
|
const manifest = await readPackageJson(path.join(workDir, 'package.json'), {
|
|
40
40
|
skipSchemaValidation: true
|
|
41
41
|
});
|
|
@@ -43,13 +43,13 @@ export async function checkStudioDependencyVersions(workDir, output) {
|
|
|
43
43
|
...manifest?.dependencies,
|
|
44
44
|
...manifest?.devDependencies
|
|
45
45
|
};
|
|
46
|
-
const packageInfo =
|
|
46
|
+
const packageInfo = packages.map(async (pkg)=>{
|
|
47
47
|
const dependency = dependencies[pkg.name];
|
|
48
48
|
if (!dependency) {
|
|
49
49
|
return false;
|
|
50
50
|
}
|
|
51
|
-
const
|
|
52
|
-
const installed = semver.coerce(
|
|
51
|
+
const packageVersion = await getLocalPackageVersion(pkg.name, workDir);
|
|
52
|
+
const installed = semver.coerce(packageVersion ?? dependency.replaceAll(/[\D.]/g, ''));
|
|
53
53
|
if (!installed) {
|
|
54
54
|
return false;
|
|
55
55
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/build/checkStudioDependencyVersions.ts"],"sourcesContent":["import path from 'node:path'\n\nimport {type Output, readPackageJson} from '@sanity/cli-core'\nimport
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/build/checkStudioDependencyVersions.ts"],"sourcesContent":["import path from 'node:path'\n\nimport {type Output, readPackageJson} from '@sanity/cli-core'\nimport semver, {type SemVer} from 'semver'\n\nimport {getLocalPackageVersion} from '../../util/getLocalPackageVersion.js'\n\ninterface PackageInfo {\n deprecatedBelow: string | null\n installed: SemVer\n isDeprecated: boolean\n isUnsupported: boolean\n isUntested: boolean\n name: string\n supported: string[]\n}\n\ninterface TrackedPackage {\n deprecatedBelow: string | null\n name: string\n supported: string[]\n}\n\n// NOTE: when doing changes here, also remember to update versions in help docs at\n// https://sanity.io/admin/structure/docs;helpArticle;upgrade-packages\nconst DEFAULT_PACKAGES: TrackedPackage[] = [\n {deprecatedBelow: null, name: 'react', supported: ['^18 || ^19']},\n {deprecatedBelow: null, name: 'react-dom', supported: ['^18 || ^19']},\n {deprecatedBelow: null, name: 'styled-components', supported: ['^6']},\n {deprecatedBelow: null, name: '@sanity/ui', supported: ['^2', '^3']},\n]\n\nexport async function checkStudioDependencyVersions(\n workDir: string,\n output: Output,\n {packages = DEFAULT_PACKAGES}: {packages?: TrackedPackage[]} = {},\n): Promise<void> {\n const manifest = await readPackageJson(path.join(workDir, 'package.json'), {\n skipSchemaValidation: true,\n })\n const dependencies = {...manifest?.dependencies, ...manifest?.devDependencies}\n\n const packageInfo = packages.map(async (pkg): Promise<false | PackageInfo> => {\n const dependency = dependencies[pkg.name]\n if (!dependency) {\n return false\n }\n\n const packageVersion = await getLocalPackageVersion(pkg.name, workDir)\n const installed = semver.coerce(packageVersion ?? dependency.replaceAll(/[\\D.]/g, ''))\n\n if (!installed) {\n return false\n }\n\n const supported = pkg.supported.join(' || ')\n\n // \"Untested\" is usually the case where we have not upgraded the React version requirements\n // before a release, but given that is usually works in a backwards-compatible way, we want\n // to indicate that it's _untested_, not necessarily _unsupported_\n // Ex: Installed is react@19.0.0, but we've only _tested_ with react@^18\n const isUntested = !semver.satisfies(installed, supported) && semver.gtr(installed, supported)\n\n // \"Unsupported\" in that the installed version is _lower than_ the minimum version\n // Ex: Installed is react@15.0.0, but we require react@^16\n const isUnsupported = !semver.satisfies(installed, supported) && !isUntested\n\n // \"Deprecated\" in that we will stop supporting it at some point in the near future,\n // so users should be prompted to upgrade\n const isDeprecated = pkg.deprecatedBelow ? semver.ltr(installed, pkg.deprecatedBelow) : false\n\n return {\n ...pkg,\n installed,\n isDeprecated,\n isUnsupported,\n isUntested,\n }\n })\n\n const installedPackages = (await Promise.all(packageInfo)).filter(\n (inp): inp is PackageInfo => inp !== false,\n )\n const unsupported = installedPackages.filter((pkg) => pkg.isUnsupported)\n const deprecated = installedPackages.filter((pkg) => !pkg.isUnsupported && pkg.isDeprecated)\n const untested = installedPackages.filter((pkg) => pkg.isUntested)\n\n if (deprecated.length > 0) {\n output.warn(`The following package versions have been deprecated and should be upgraded:\n\n ${listPackages(deprecated)}\n\nSupport for these will be removed in a future release!\n\n ${getUpgradeInstructions(deprecated)}\n`)\n }\n\n if (untested.length > 0) {\n output.warn(`The following package versions have not yet been marked as supported:\n\n ${listPackages(untested)}\n\nYou _may_ encounter bugs while using these versions.\n\n ${getDowngradeInstructions(untested)}\n`)\n }\n\n if (unsupported.length > 0) {\n output.error(\n `The following package versions are no longer supported and needs to be upgraded:\n\n ${listPackages(unsupported)}\n\n ${getUpgradeInstructions(unsupported)}\n`,\n {exit: 1},\n )\n }\n}\n\nfunction listPackages(pkgs: PackageInfo[]) {\n return pkgs\n .map(\n (pkg) =>\n `${pkg.name} (installed: ${pkg.installed}, want: ${\n pkg.deprecatedBelow || pkg.supported.join(' || ')\n })`,\n )\n .join('\\n ')\n}\n\nfunction getUpgradeInstructions(pkgs: PackageInfo[]) {\n const inst = pkgs\n .map((pkg) => {\n const [highestSupported] = pkg.supported\n .map((version) => (semver.coerce(version) || {version: ''}).version)\n .toSorted(semver.rcompare)\n\n return `\"${pkg.name}@${highestSupported}\"`\n })\n .join(' ')\n\n return `To upgrade, run either:\n\n npm install ${inst}\n\n or\n\n yarn add ${inst}\n\n or\n\n pnpm add ${inst}\n\n\nRead more at https://www.sanity.io/docs/help/upgrade-packages`\n}\n\nfunction getDowngradeInstructions(pkgs: PackageInfo[]) {\n const inst = pkgs\n .map((pkg) => {\n const [highestSupported] = pkg.supported\n .map((version) => (semver.coerce(version) || {version: ''}).version)\n .toSorted(semver.rcompare)\n\n return `\"${pkg.name}@${highestSupported}\"`\n })\n .join(' ')\n\n return `To downgrade, run either:\n\n yarn add ${inst}\n\n or\n\n npm install ${inst}\n\n or\n\n pnpm install ${inst}`\n}\n"],"names":["path","readPackageJson","semver","getLocalPackageVersion","DEFAULT_PACKAGES","deprecatedBelow","name","supported","checkStudioDependencyVersions","workDir","output","packages","manifest","join","skipSchemaValidation","dependencies","devDependencies","packageInfo","map","pkg","dependency","packageVersion","installed","coerce","replaceAll","isUntested","satisfies","gtr","isUnsupported","isDeprecated","ltr","installedPackages","Promise","all","filter","inp","unsupported","deprecated","untested","length","warn","listPackages","getUpgradeInstructions","getDowngradeInstructions","error","exit","pkgs","inst","highestSupported","version","toSorted","rcompare"],"mappings":"AAAA,OAAOA,UAAU,YAAW;AAE5B,SAAqBC,eAAe,QAAO,mBAAkB;AAC7D,OAAOC,YAA2B,SAAQ;AAE1C,SAAQC,sBAAsB,QAAO,uCAAsC;AAkB3E,kFAAkF;AAClF,sEAAsE;AACtE,MAAMC,mBAAqC;IACzC;QAACC,iBAAiB;QAAMC,MAAM;QAASC,WAAW;YAAC;SAAa;IAAA;IAChE;QAACF,iBAAiB;QAAMC,MAAM;QAAaC,WAAW;YAAC;SAAa;IAAA;IACpE;QAACF,iBAAiB;QAAMC,MAAM;QAAqBC,WAAW;YAAC;SAAK;IAAA;IACpE;QAACF,iBAAiB;QAAMC,MAAM;QAAcC,WAAW;YAAC;YAAM;SAAK;IAAA;CACpE;AAED,OAAO,eAAeC,8BACpBC,OAAe,EACfC,MAAc,EACd,EAACC,WAAWP,gBAAgB,EAAgC,GAAG,CAAC,CAAC;IAEjE,MAAMQ,WAAW,MAAMX,gBAAgBD,KAAKa,IAAI,CAACJ,SAAS,iBAAiB;QACzEK,sBAAsB;IACxB;IACA,MAAMC,eAAe;QAAC,GAAGH,UAAUG,YAAY;QAAE,GAAGH,UAAUI,eAAe;IAAA;IAE7E,MAAMC,cAAcN,SAASO,GAAG,CAAC,OAAOC;QACtC,MAAMC,aAAaL,YAAY,CAACI,IAAIb,IAAI,CAAC;QACzC,IAAI,CAACc,YAAY;YACf,OAAO;QACT;QAEA,MAAMC,iBAAiB,MAAMlB,uBAAuBgB,IAAIb,IAAI,EAAEG;QAC9D,MAAMa,YAAYpB,OAAOqB,MAAM,CAACF,kBAAkBD,WAAWI,UAAU,CAAC,UAAU;QAElF,IAAI,CAACF,WAAW;YACd,OAAO;QACT;QAEA,MAAMf,YAAYY,IAAI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AAK;;;;cAIJ,EAAEA,KAAK;;;;eAIN,EAAEA,MAAM;AACvB"}
|
|
@@ -7,7 +7,7 @@ import { pack } from 'tar-fs';
|
|
|
7
7
|
import { createDeployment } from '../../services/userApplications.js';
|
|
8
8
|
import { getAppId } from '../../util/appId.js';
|
|
9
9
|
import { NO_ORGANIZATION_ID } from '../../util/errorMessages.js';
|
|
10
|
-
import {
|
|
10
|
+
import { getLocalPackageVersion } from '../../util/getLocalPackageVersion.js';
|
|
11
11
|
import { warnAboutMissingAppId } from '../../util/warnAboutMissingAppId.js';
|
|
12
12
|
import { buildApp } from '../build/buildApp.js';
|
|
13
13
|
import { shouldAutoUpdate } from '../build/shouldAutoUpdate.js';
|
|
@@ -29,7 +29,7 @@ import { findUserApplicationForApp } from './findUserApplicationForApp.js';
|
|
|
29
29
|
flags,
|
|
30
30
|
output
|
|
31
31
|
});
|
|
32
|
-
const installedSdkVersion = await
|
|
32
|
+
const installedSdkVersion = await getLocalPackageVersion('@sanity/sdk-react', workDir);
|
|
33
33
|
if (!installedSdkVersion) {
|
|
34
34
|
output.error(`Failed to find installed @sanity/sdk-react version`, {
|
|
35
35
|
exit: 1
|