@sanity/cli 6.6.0 → 6.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -4
- package/dist/actions/auth/login/login.js +4 -1
- package/dist/actions/auth/login/login.js.map +1 -1
- package/dist/actions/build/buildApp.js +4 -5
- package/dist/actions/build/buildApp.js.map +1 -1
- package/dist/actions/build/buildStaticFiles.js +12 -4
- package/dist/actions/build/buildStaticFiles.js.map +1 -1
- package/dist/actions/build/buildStudio.js +6 -14
- package/dist/actions/build/buildStudio.js.map +1 -1
- package/dist/actions/build/{getStudioEnvironmentVariables.js → getEnvironmentVariables.js} +15 -19
- package/dist/actions/build/getEnvironmentVariables.js.map +1 -0
- package/dist/actions/deploy/deployStudio.js +1 -2
- package/dist/actions/deploy/deployStudio.js.map +1 -1
- package/dist/actions/deploy/deployStudioSchemasAndManifests.js +1 -2
- package/dist/actions/deploy/deployStudioSchemasAndManifests.js.map +1 -1
- package/dist/actions/deploy/deployStudioSchemasAndManifests.worker.js +1 -1
- package/dist/actions/deploy/deployStudioSchemasAndManifests.worker.js.map +1 -1
- package/dist/actions/dev/startStudioDevServer.js +1 -1
- package/dist/actions/dev/startStudioDevServer.js.map +1 -1
- package/dist/actions/documents/validateDocuments.worker.js +1 -2
- package/dist/actions/documents/validateDocuments.worker.js.map +1 -1
- package/dist/actions/graphql/SchemaError.js +1 -1
- package/dist/actions/graphql/SchemaError.js.map +1 -1
- package/dist/actions/init/initAction.js +32 -1
- package/dist/actions/init/initAction.js.map +1 -1
- package/dist/actions/init/scaffoldTemplate.js +32 -18
- package/dist/actions/init/scaffoldTemplate.js.map +1 -1
- package/dist/actions/init/templates/index.js +2 -0
- package/dist/actions/init/templates/index.js.map +1 -1
- package/dist/actions/init/templates/pageBuilder.js +32 -0
- package/dist/actions/init/templates/pageBuilder.js.map +1 -0
- package/dist/actions/init/types.js +2 -1
- package/dist/actions/init/types.js.map +1 -1
- package/dist/actions/manifest/extractManifest.js +1 -1
- package/dist/actions/manifest/extractManifest.js.map +1 -1
- package/dist/actions/manifest/extractManifest.worker.js +1 -1
- package/dist/actions/manifest/extractManifest.worker.js.map +1 -1
- package/dist/actions/mcp/editorConfigs.js +51 -11
- package/dist/actions/mcp/editorConfigs.js.map +1 -1
- package/dist/actions/mcp/promptForMCPSetup.js +16 -11
- package/dist/actions/mcp/promptForMCPSetup.js.map +1 -1
- package/dist/actions/mcp/setupMCP.js +180 -61
- package/dist/actions/mcp/setupMCP.js.map +1 -1
- package/dist/actions/mcp/types.js.map +1 -1
- package/dist/actions/schema/deploySchemas.js +1 -1
- package/dist/actions/schema/deploySchemas.js.map +1 -1
- package/dist/actions/schema/extractSanityWorkspace.worker.js +1 -1
- package/dist/actions/schema/extractSanityWorkspace.worker.js.map +1 -1
- package/dist/actions/schema/extractSchema.js +1 -4
- package/dist/actions/schema/extractSchema.js.map +1 -1
- package/dist/actions/schema/extractSchemaWatcher.js +1 -4
- package/dist/actions/schema/extractSchemaWatcher.js.map +1 -1
- package/dist/actions/schema/getExtractOptions.js +8 -18
- package/dist/actions/schema/getExtractOptions.js.map +1 -1
- package/dist/actions/schema/types.js +0 -6
- package/dist/actions/schema/types.js.map +1 -1
- package/dist/actions/schema/validateAction.js +1 -1
- package/dist/actions/schema/validateAction.js.map +1 -1
- package/dist/actions/schema/validateSchema.worker.js +1 -2
- package/dist/actions/schema/validateSchema.worker.js.map +1 -1
- package/dist/actions/schema/watchExtractSchema.js +1 -1
- package/dist/actions/schema/watchExtractSchema.js.map +1 -1
- package/dist/actions/skills/readSkillState.js +54 -0
- package/dist/actions/skills/readSkillState.js.map +1 -0
- package/dist/actions/skills/setupSkills.js +73 -0
- package/dist/actions/skills/setupSkills.js.map +1 -0
- package/dist/commands/build.js +9 -22
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/cors/add.js +5 -5
- package/dist/commands/cors/add.js.map +1 -1
- package/dist/commands/datasets/export.js +9 -0
- package/dist/commands/datasets/export.js.map +1 -1
- package/dist/commands/docs/read.js +33 -12
- package/dist/commands/docs/read.js.map +1 -1
- package/dist/commands/init.js +12 -1
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/manifest/extract.js +1 -2
- package/dist/commands/manifest/extract.js.map +1 -1
- package/dist/commands/mcp/configure.js +2 -1
- package/dist/commands/mcp/configure.js.map +1 -1
- package/dist/commands/schemas/deploy.js +1 -2
- package/dist/commands/schemas/deploy.js.map +1 -1
- package/dist/exports/_internal.d.ts +2 -1
- package/dist/exports/_internal.js +1 -1
- package/dist/exports/_internal.js.map +1 -1
- package/dist/server/devServer.js +25 -4
- package/dist/server/devServer.js.map +1 -1
- package/dist/server/previewServer.js +1 -1
- package/dist/server/previewServer.js.map +1 -1
- package/dist/services/mcp.js +1 -1
- package/dist/services/mcp.js.map +1 -1
- package/dist/telemetry/init.telemetry.js.map +1 -1
- package/oclif.manifest.json +134 -118
- package/package.json +15 -16
- package/templates/page-builder/README.md +9 -0
- package/templates/page-builder/schemaTypes/hero.js +31 -0
- package/templates/page-builder/schemaTypes/index.js +19 -0
- package/templates/page-builder/static/.gitkeep +0 -0
- package/dist/actions/build/buildDebug.js +0 -4
- package/dist/actions/build/buildDebug.js.map +0 -1
- package/dist/actions/build/buildVendorDependencies.js +0 -149
- package/dist/actions/build/buildVendorDependencies.js.map +0 -1
- package/dist/actions/build/checkStudioDependencyVersions.js +0 -155
- package/dist/actions/build/checkStudioDependencyVersions.js.map +0 -1
- package/dist/actions/build/createExternalFromImportMap.js +0 -11
- package/dist/actions/build/createExternalFromImportMap.js.map +0 -1
- package/dist/actions/build/decorateIndexWithAutoGeneratedWarning.js +0 -13
- package/dist/actions/build/decorateIndexWithAutoGeneratedWarning.js.map +0 -1
- package/dist/actions/build/decorateIndexWithBridgeScript.js +0 -17
- package/dist/actions/build/decorateIndexWithBridgeScript.js.map +0 -1
- package/dist/actions/build/decorateIndexWithStagingScript.js +0 -16
- package/dist/actions/build/decorateIndexWithStagingScript.js.map +0 -1
- package/dist/actions/build/getAppEnvVars.js +0 -9
- package/dist/actions/build/getAppEnvVars.js.map +0 -1
- package/dist/actions/build/getEntryModule.js +0 -46
- package/dist/actions/build/getEntryModule.js.map +0 -1
- package/dist/actions/build/getPossibleDocumentComponentLocations.js +0 -11
- package/dist/actions/build/getPossibleDocumentComponentLocations.js.map +0 -1
- package/dist/actions/build/getStudioEnvVars.js +0 -9
- package/dist/actions/build/getStudioEnvVars.js.map +0 -1
- package/dist/actions/build/getStudioEnvironmentVariables.js.map +0 -1
- package/dist/actions/build/getViteConfig.js +0 -219
- package/dist/actions/build/getViteConfig.js.map +0 -1
- package/dist/actions/build/normalizeBasePath.js +0 -9
- package/dist/actions/build/normalizeBasePath.js.map +0 -1
- package/dist/actions/build/renderDocument.js +0 -50
- package/dist/actions/build/renderDocument.js.map +0 -1
- package/dist/actions/build/renderDocument.worker.js +0 -9
- package/dist/actions/build/renderDocument.worker.js.map +0 -1
- package/dist/actions/build/renderDocumentWorker/addTimestampImportMapScriptToHtml.js +0 -79
- package/dist/actions/build/renderDocumentWorker/addTimestampImportMapScriptToHtml.js.map +0 -1
- package/dist/actions/build/renderDocumentWorker/components/BasicDocument.js +0 -61
- package/dist/actions/build/renderDocumentWorker/components/BasicDocument.js.map +0 -1
- package/dist/actions/build/renderDocumentWorker/components/DefaultDocument.js +0 -165
- package/dist/actions/build/renderDocumentWorker/components/DefaultDocument.js.map +0 -1
- package/dist/actions/build/renderDocumentWorker/components/Favicons.js +0 -28
- package/dist/actions/build/renderDocumentWorker/components/Favicons.js.map +0 -1
- package/dist/actions/build/renderDocumentWorker/components/GlobalErrorHandler.js +0 -178
- package/dist/actions/build/renderDocumentWorker/components/GlobalErrorHandler.js.map +0 -1
- package/dist/actions/build/renderDocumentWorker/components/NoJavascript.js +0 -51
- package/dist/actions/build/renderDocumentWorker/components/NoJavascript.js.map +0 -1
- package/dist/actions/build/renderDocumentWorker/getDocumentComponent.js +0 -41
- package/dist/actions/build/renderDocumentWorker/getDocumentComponent.js.map +0 -1
- package/dist/actions/build/renderDocumentWorker/getDocumentHtml.js +0 -55
- package/dist/actions/build/renderDocumentWorker/getDocumentHtml.js.map +0 -1
- package/dist/actions/build/renderDocumentWorker/renderDocumentWorker.js +0 -31
- package/dist/actions/build/renderDocumentWorker/renderDocumentWorker.js.map +0 -1
- package/dist/actions/build/renderDocumentWorker/tryLoadDocumentComponent.js +0 -30
- package/dist/actions/build/renderDocumentWorker/tryLoadDocumentComponent.js.map +0 -1
- package/dist/actions/build/renderDocumentWorker/types.js +0 -5
- package/dist/actions/build/renderDocumentWorker/types.js.map +0 -1
- package/dist/actions/build/writeSanityRuntime.js +0 -64
- package/dist/actions/build/writeSanityRuntime.js.map +0 -1
- package/dist/actions/docs/normalizeDocsPath.js +0 -15
- package/dist/actions/docs/normalizeDocsPath.js.map +0 -1
- package/dist/actions/schema/extractSanitySchema.worker.js +0 -33
- package/dist/actions/schema/extractSanitySchema.worker.js.map +0 -1
- package/dist/actions/schema/formatSchemaValidation.js +0 -78
- package/dist/actions/schema/formatSchemaValidation.js.map +0 -1
- package/dist/actions/schema/matchSchemaPattern.js +0 -22
- package/dist/actions/schema/matchSchemaPattern.js.map +0 -1
- package/dist/actions/schema/runSchemaExtraction.js +0 -39
- package/dist/actions/schema/runSchemaExtraction.js.map +0 -1
- package/dist/actions/schema/utils/SchemaExtractionError.js +0 -10
- package/dist/actions/schema/utils/SchemaExtractionError.js.map +0 -1
- package/dist/actions/schema/utils/extractValidationFromSchemaError.js +0 -12
- package/dist/actions/schema/utils/extractValidationFromSchemaError.js.map +0 -1
- package/dist/constants.js +0 -8
- package/dist/constants.js.map +0 -1
- package/dist/server/vite/plugin-sanity-build-entries.js +0 -67
- package/dist/server/vite/plugin-sanity-build-entries.js.map +0 -1
- package/dist/server/vite/plugin-sanity-favicons.js +0 -72
- package/dist/server/vite/plugin-sanity-favicons.js.map +0 -1
- package/dist/server/vite/plugin-sanity-runtime-rewrite.js +0 -18
- package/dist/server/vite/plugin-sanity-runtime-rewrite.js.map +0 -1
- package/dist/server/vite/plugin-schema-extraction.js +0 -201
- package/dist/server/vite/plugin-schema-extraction.js.map +0 -1
- package/dist/telemetry/build.telemetry.js +0 -13
- package/dist/telemetry/build.telemetry.js.map +0 -1
- package/dist/telemetry/extractSchema.telemetry.js +0 -18
- package/dist/telemetry/extractSchema.telemetry.js.map +0 -1
- package/dist/util/getWorkspace.js +0 -18
- package/dist/util/getWorkspace.js.map +0 -1
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { getLocalPackageVersion, readPackageJson } from '@sanity/cli-core';
|
|
3
|
-
import { coerce, gtr, ltr, rcompare, satisfies } from 'semver';
|
|
4
|
-
// NOTE: when doing changes here, also remember to update versions in help docs at
|
|
5
|
-
// https://sanity.io/admin/structure/docs;helpArticle;upgrade-packages
|
|
6
|
-
const DEFAULT_PACKAGES = [
|
|
7
|
-
{
|
|
8
|
-
deprecatedBelow: null,
|
|
9
|
-
name: 'react',
|
|
10
|
-
supported: [
|
|
11
|
-
'^19.2.2'
|
|
12
|
-
]
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
deprecatedBelow: null,
|
|
16
|
-
name: 'react-dom',
|
|
17
|
-
supported: [
|
|
18
|
-
'^19.2.2'
|
|
19
|
-
]
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
deprecatedBelow: null,
|
|
23
|
-
name: 'styled-components',
|
|
24
|
-
supported: [
|
|
25
|
-
'^6'
|
|
26
|
-
]
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
deprecatedBelow: '^3',
|
|
30
|
-
name: '@sanity/ui',
|
|
31
|
-
supported: [
|
|
32
|
-
'^2',
|
|
33
|
-
'^3'
|
|
34
|
-
]
|
|
35
|
-
}
|
|
36
|
-
];
|
|
37
|
-
export async function checkStudioDependencyVersions(workDir, output, { packages = DEFAULT_PACKAGES } = {}) {
|
|
38
|
-
const manifest = await readPackageJson(path.join(workDir, 'package.json'), {
|
|
39
|
-
skipSchemaValidation: true
|
|
40
|
-
});
|
|
41
|
-
const dependencies = {
|
|
42
|
-
...manifest?.dependencies,
|
|
43
|
-
...manifest?.devDependencies
|
|
44
|
-
};
|
|
45
|
-
const packageInfo = packages.map(async (pkg)=>{
|
|
46
|
-
const dependency = dependencies[pkg.name];
|
|
47
|
-
if (!dependency) {
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
const packageVersion = await getLocalPackageVersion(pkg.name, workDir);
|
|
51
|
-
const installed = coerce(packageVersion ?? dependency.replaceAll(/[\D.]/g, ''));
|
|
52
|
-
if (!installed) {
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
const supported = pkg.supported.join(' || ');
|
|
56
|
-
// "Untested" is usually the case where we have not upgraded the React version requirements
|
|
57
|
-
// before a release, but given that is usually works in a backwards-compatible way, we want
|
|
58
|
-
// to indicate that it's _untested_, not necessarily _unsupported_
|
|
59
|
-
// Ex: Installed is react@20.0.0, but we've only _tested_ with react@^19
|
|
60
|
-
const isUntested = !satisfies(installed, supported) && gtr(installed, supported);
|
|
61
|
-
// "Unsupported" in that the installed version is _lower than_ the minimum version
|
|
62
|
-
// Ex: Installed is react@18.0.0, but we require react@^19.2
|
|
63
|
-
const isUnsupported = !satisfies(installed, supported) && !isUntested;
|
|
64
|
-
// "Deprecated" in that we will stop supporting it at some point in the near future,
|
|
65
|
-
// so users should be prompted to upgrade
|
|
66
|
-
const isDeprecated = pkg.deprecatedBelow ? ltr(installed, pkg.deprecatedBelow) : false;
|
|
67
|
-
return {
|
|
68
|
-
...pkg,
|
|
69
|
-
installed,
|
|
70
|
-
isDeprecated,
|
|
71
|
-
isUnsupported,
|
|
72
|
-
isUntested
|
|
73
|
-
};
|
|
74
|
-
});
|
|
75
|
-
const installedPackages = (await Promise.all(packageInfo)).filter((inp)=>inp !== false);
|
|
76
|
-
const unsupported = installedPackages.filter((pkg)=>pkg.isUnsupported);
|
|
77
|
-
const deprecated = installedPackages.filter((pkg)=>!pkg.isUnsupported && pkg.isDeprecated);
|
|
78
|
-
const untested = installedPackages.filter((pkg)=>pkg.isUntested);
|
|
79
|
-
if (deprecated.length > 0) {
|
|
80
|
-
output.warn(`The following package versions have been deprecated and should be upgraded:
|
|
81
|
-
|
|
82
|
-
${listPackages(deprecated)}
|
|
83
|
-
|
|
84
|
-
Support for these will be removed in a future release!
|
|
85
|
-
|
|
86
|
-
${getUpgradeInstructions(deprecated)}
|
|
87
|
-
`);
|
|
88
|
-
}
|
|
89
|
-
if (untested.length > 0) {
|
|
90
|
-
output.warn(`The following package versions have not yet been marked as supported:
|
|
91
|
-
|
|
92
|
-
${listPackages(untested)}
|
|
93
|
-
|
|
94
|
-
You _may_ encounter bugs while using these versions.
|
|
95
|
-
|
|
96
|
-
${getDowngradeInstructions(untested)}
|
|
97
|
-
`);
|
|
98
|
-
}
|
|
99
|
-
if (unsupported.length > 0) {
|
|
100
|
-
output.error(`The following package versions are no longer supported and needs to be upgraded:
|
|
101
|
-
|
|
102
|
-
${listPackages(unsupported)}
|
|
103
|
-
|
|
104
|
-
${getUpgradeInstructions(unsupported)}
|
|
105
|
-
`, {
|
|
106
|
-
exit: 1
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
function listPackages(pkgs) {
|
|
111
|
-
return pkgs.map((pkg)=>`${pkg.name} (installed: ${pkg.installed}, want: ${pkg.deprecatedBelow || pkg.supported.join(' || ')})`).join('\n ');
|
|
112
|
-
}
|
|
113
|
-
function getUpgradeInstructions(pkgs) {
|
|
114
|
-
const inst = pkgs.map((pkg)=>{
|
|
115
|
-
const [highestSupported] = pkg.supported.map((version)=>(coerce(version) || {
|
|
116
|
-
version: ''
|
|
117
|
-
}).version).toSorted(rcompare);
|
|
118
|
-
return `"${pkg.name}@^${highestSupported}"`;
|
|
119
|
-
}).join(' ');
|
|
120
|
-
return `To upgrade, run either:
|
|
121
|
-
|
|
122
|
-
npm install ${inst}
|
|
123
|
-
|
|
124
|
-
or
|
|
125
|
-
|
|
126
|
-
yarn add ${inst}
|
|
127
|
-
|
|
128
|
-
or
|
|
129
|
-
|
|
130
|
-
pnpm add ${inst}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
Read more at https://www.sanity.io/docs/help/upgrade-packages`;
|
|
134
|
-
}
|
|
135
|
-
function getDowngradeInstructions(pkgs) {
|
|
136
|
-
const inst = pkgs.map((pkg)=>{
|
|
137
|
-
const [highestSupported] = pkg.supported.map((version)=>(coerce(version) || {
|
|
138
|
-
version: ''
|
|
139
|
-
}).version).toSorted(rcompare);
|
|
140
|
-
return `"${pkg.name}@^${highestSupported}"`;
|
|
141
|
-
}).join(' ');
|
|
142
|
-
return `To downgrade, run either:
|
|
143
|
-
|
|
144
|
-
yarn add ${inst}
|
|
145
|
-
|
|
146
|
-
or
|
|
147
|
-
|
|
148
|
-
npm install ${inst}
|
|
149
|
-
|
|
150
|
-
or
|
|
151
|
-
|
|
152
|
-
pnpm install ${inst}`;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
//# sourceMappingURL=checkStudioDependencyVersions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/build/checkStudioDependencyVersions.ts"],"sourcesContent":["import path from 'node:path'\n\nimport {getLocalPackageVersion, type Output, readPackageJson} from '@sanity/cli-core'\nimport {coerce, gtr, ltr, rcompare, satisfies, type SemVer} from 'semver'\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: ['^19.2.2']},\n {deprecatedBelow: null, name: 'react-dom', supported: ['^19.2.2']},\n {deprecatedBelow: null, name: 'styled-components', supported: ['^6']},\n {deprecatedBelow: '^3', 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 = 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@20.0.0, but we've only _tested_ with react@^19\n const isUntested = !satisfies(installed, supported) && gtr(installed, supported)\n\n // \"Unsupported\" in that the installed version is _lower than_ the minimum version\n // Ex: Installed is react@18.0.0, but we require react@^19.2\n const isUnsupported = !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 ? 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) => (coerce(version) || {version: ''}).version)\n .toSorted(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) => (coerce(version) || {version: ''}).version)\n .toSorted(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","getLocalPackageVersion","readPackageJson","coerce","gtr","ltr","rcompare","satisfies","DEFAULT_PACKAGES","deprecatedBelow","name","supported","checkStudioDependencyVersions","workDir","output","packages","manifest","join","skipSchemaValidation","dependencies","devDependencies","packageInfo","map","pkg","dependency","packageVersion","installed","replaceAll","isUntested","isUnsupported","isDeprecated","installedPackages","Promise","all","filter","inp","unsupported","deprecated","untested","length","warn","listPackages","getUpgradeInstructions","getDowngradeInstructions","error","exit","pkgs","inst","highestSupported","version","toSorted"],"mappings":"AAAA,OAAOA,UAAU,YAAW;AAE5B,SAAQC,sBAAsB,EAAeC,eAAe,QAAO,mBAAkB;AACrF,SAAQC,MAAM,EAAEC,GAAG,EAAEC,GAAG,EAAEC,QAAQ,EAAEC,SAAS,QAAoB,SAAQ;AAkBzE,kFAAkF;AAClF,sEAAsE;AACtE,MAAMC,mBAAqC;IACzC;QAACC,iBAAiB;QAAMC,MAAM;QAASC,WAAW;YAAC;SAAU;IAAA;IAC7D;QAACF,iBAAiB;QAAMC,MAAM;QAAaC,WAAW;YAAC;SAAU;IAAA;IACjE;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,MAAMd,gBAAgBF,KAAKiB,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,MAAMxB,uBAAuBsB,IAAIb,IAAI,EAAEG;QAC9D,MAAMa,YAAYvB,OAAOsB,kBAAkBD,WAAWG,UAAU,CAAC,UAAU;QAE3E,IAAI,CAACD,WAAW;YACd,OAAO;QACT;QAEA,MAAMf,YAAYY,IAAIZ,SAA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-es/escapeRegExp.js';
|
|
2
|
-
/**
|
|
3
|
-
* Generates a Rollup `external` configuration array based on the provided
|
|
4
|
-
* import map. We derive externals from the import map because this ensures that
|
|
5
|
-
* modules listed in the import map are not bundled into the Rollup output so
|
|
6
|
-
* the browser can load these bare specifiers according to the import map.
|
|
7
|
-
*/ export function createExternalFromImportMap({ imports = {} } = {}) {
|
|
8
|
-
return Object.keys(imports).map((specifier)=>specifier.endsWith('/') ? new RegExp(`^${escapeRegExp(specifier)}.+`) : specifier);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
//# sourceMappingURL=createExternalFromImportMap.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/build/createExternalFromImportMap.ts"],"sourcesContent":["import escapeRegExp from 'lodash-es/escapeRegExp.js'\n\ntype ImportMap = {imports?: Record<string, string>}\n\n/**\n * Generates a Rollup `external` configuration array based on the provided\n * import map. We derive externals from the import map because this ensures that\n * modules listed in the import map are not bundled into the Rollup output so\n * the browser can load these bare specifiers according to the import map.\n */\nexport function createExternalFromImportMap({imports = {}}: ImportMap = {}): (RegExp | string)[] {\n return Object.keys(imports).map((specifier) =>\n specifier.endsWith('/') ? new RegExp(`^${escapeRegExp(specifier)}.+`) : specifier,\n )\n}\n"],"names":["escapeRegExp","createExternalFromImportMap","imports","Object","keys","map","specifier","endsWith","RegExp"],"mappings":"AAAA,OAAOA,kBAAkB,4BAA2B;AAIpD;;;;;CAKC,GACD,OAAO,SAASC,4BAA4B,EAACC,UAAU,CAAC,CAAC,EAAY,GAAG,CAAC,CAAC;IACxE,OAAOC,OAAOC,IAAI,CAACF,SAASG,GAAG,CAAC,CAACC,YAC/BA,UAAUC,QAAQ,CAAC,OAAO,IAAIC,OAAO,CAAC,CAAC,EAAER,aAAaM,WAAW,EAAE,CAAC,IAAIA;AAE5E"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
const autoGeneratedWarning = `
|
|
2
|
-
This file is auto-generated from "sanity dev".
|
|
3
|
-
Modifications to this file are automatically discarded.
|
|
4
|
-
`.trim();
|
|
5
|
-
/**
|
|
6
|
-
* Adds a warning about file being auto generated
|
|
7
|
-
*
|
|
8
|
-
* @internal
|
|
9
|
-
*/ export function decorateIndexWithAutoGeneratedWarning(template) {
|
|
10
|
-
return template.replace(/<head/, `\n<!--\n${autoGeneratedWarning}\n-->\n<head`);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
//# sourceMappingURL=decorateIndexWithAutoGeneratedWarning.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/build/decorateIndexWithAutoGeneratedWarning.ts"],"sourcesContent":["const autoGeneratedWarning = `\nThis file is auto-generated from \"sanity dev\".\nModifications to this file are automatically discarded.\n`.trim()\n\n/**\n * Adds a warning about file being auto generated\n *\n * @internal\n */\nexport function decorateIndexWithAutoGeneratedWarning(template: string): string {\n return template.replace(/<head/, `\\n<!--\\n${autoGeneratedWarning}\\n-->\\n<head`)\n}\n"],"names":["autoGeneratedWarning","trim","decorateIndexWithAutoGeneratedWarning","template","replace"],"mappings":"AAAA,MAAMA,uBAAuB,CAAC;;;AAG9B,CAAC,CAACC,IAAI;AAEN;;;;CAIC,GACD,OAAO,SAASC,sCAAsCC,QAAgB;IACpE,OAAOA,SAASC,OAAO,CAAC,SAAS,CAAC,QAAQ,EAAEJ,qBAAqB,YAAY,CAAC;AAChF"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Decorates the given HTML template with a script
|
|
3
|
-
* tag that loads the bridge component to communicate
|
|
4
|
-
* with core-ui.
|
|
5
|
-
*
|
|
6
|
-
* @internal
|
|
7
|
-
*/ export function decorateIndexWithBridgeScript(template) {
|
|
8
|
-
const sanityEnv = process.env.SANITY_INTERNAL_ENV || 'production';
|
|
9
|
-
/**
|
|
10
|
-
* The URL to the bridge script is determined by the
|
|
11
|
-
* `SANITY_INTERNAL_ENV` environment variable. So if you deploy
|
|
12
|
-
* a studio to the staging ENV then you'll get the correct script.
|
|
13
|
-
*/ const scriptURL = sanityEnv === 'production' ? 'https://core.sanity-cdn.com/bridge.js' : 'https://core.sanity-cdn.work/bridge.js';
|
|
14
|
-
return template.replace('</head>', `<script src="${scriptURL}" async type="module" data-sanity-core></script>\n</head>`);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
//# sourceMappingURL=decorateIndexWithBridgeScript.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/build/decorateIndexWithBridgeScript.ts"],"sourcesContent":["/**\n * Decorates the given HTML template with a script\n * tag that loads the bridge component to communicate\n * with core-ui.\n *\n * @internal\n */\nexport function decorateIndexWithBridgeScript(template: string): string {\n const sanityEnv = process.env.SANITY_INTERNAL_ENV || 'production'\n\n /**\n * The URL to the bridge script is determined by the\n * `SANITY_INTERNAL_ENV` environment variable. So if you deploy\n * a studio to the staging ENV then you'll get the correct script.\n */\n const scriptURL =\n sanityEnv === 'production'\n ? 'https://core.sanity-cdn.com/bridge.js'\n : 'https://core.sanity-cdn.work/bridge.js'\n\n return template.replace(\n '</head>',\n `<script src=\"${scriptURL}\" async type=\"module\" data-sanity-core></script>\\n</head>`,\n )\n}\n"],"names":["decorateIndexWithBridgeScript","template","sanityEnv","process","env","SANITY_INTERNAL_ENV","scriptURL","replace"],"mappings":"AAAA;;;;;;CAMC,GACD,OAAO,SAASA,8BAA8BC,QAAgB;IAC5D,MAAMC,YAAYC,QAAQC,GAAG,CAACC,mBAAmB,IAAI;IAErD;;;;GAIC,GACD,MAAMC,YACJJ,cAAc,eACV,0CACA;IAEN,OAAOD,SAASM,OAAO,CACrB,WACA,CAAC,aAAa,EAAED,UAAU,yDAAyD,CAAC;AAExF"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { isStaging } from '@sanity/cli-core';
|
|
2
|
-
/**
|
|
3
|
-
* Decorates the given HTML template with a script tag that sets
|
|
4
|
-
* `globalThis.__SANITY_STAGING__` to `true` when building in a
|
|
5
|
-
* staging environment. The script is injected as the first child
|
|
6
|
-
* of `<head>` so it runs before any module scripts.
|
|
7
|
-
*
|
|
8
|
-
* @internal
|
|
9
|
-
*/ export function decorateIndexWithStagingScript(template) {
|
|
10
|
-
if (!isStaging()) {
|
|
11
|
-
return template;
|
|
12
|
-
}
|
|
13
|
-
return template.replace(/<head([^>]*)>/, '<head$1>\n<script>globalThis.__SANITY_STAGING__ = true</script>');
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
//# sourceMappingURL=decorateIndexWithStagingScript.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/build/decorateIndexWithStagingScript.ts"],"sourcesContent":["import {isStaging} from '@sanity/cli-core'\n\n/**\n * Decorates the given HTML template with a script tag that sets\n * `globalThis.__SANITY_STAGING__` to `true` when building in a\n * staging environment. The script is injected as the first child\n * of `<head>` so it runs before any module scripts.\n *\n * @internal\n */\nexport function decorateIndexWithStagingScript(template: string): string {\n if (!isStaging()) {\n return template\n }\n\n return template.replace(\n /<head([^>]*)>/,\n '<head$1>\\n<script>globalThis.__SANITY_STAGING__ = true</script>',\n )\n}\n"],"names":["isStaging","decorateIndexWithStagingScript","template","replace"],"mappings":"AAAA,SAAQA,SAAS,QAAO,mBAAkB;AAE1C;;;;;;;CAOC,GACD,OAAO,SAASC,+BAA+BC,QAAgB;IAC7D,IAAI,CAACF,aAAa;QAChB,OAAOE;IACT;IAEA,OAAOA,SAASC,OAAO,CACrB,iBACA;AAEJ"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/build/getAppEnvVars.ts"],"sourcesContent":["/**\n * Get all `SANITY_APP_` prefix env vars\n *\n * @internal\n */\nexport function getAppEnvVars(env: Record<string, string | undefined> = process.env): string[] {\n return Object.keys(env).filter((key) => key.toUpperCase().startsWith('SANITY_APP_'))\n}\n"],"names":["getAppEnvVars","env","process","Object","keys","filter","key","toUpperCase","startsWith"],"mappings":"AAAA;;;;CAIC,GACD,OAAO,SAASA,cAAcC,MAA0CC,QAAQD,GAAG;IACjF,OAAOE,OAAOC,IAAI,CAACH,KAAKI,MAAM,CAAC,CAACC,MAAQA,IAAIC,WAAW,GAAGC,UAAU,CAAC;AACvE"}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
const entryModule = `
|
|
2
|
-
// This file is auto-generated on 'sanity dev'
|
|
3
|
-
// Modifications to this file is automatically discarded
|
|
4
|
-
import {renderStudio} from "sanity"
|
|
5
|
-
import studioConfig from %STUDIO_CONFIG_LOCATION%
|
|
6
|
-
|
|
7
|
-
renderStudio(
|
|
8
|
-
document.getElementById("sanity"),
|
|
9
|
-
studioConfig,
|
|
10
|
-
{reactStrictMode: %STUDIO_REACT_STRICT_MODE%, basePath: %STUDIO_BASE_PATH%}
|
|
11
|
-
)
|
|
12
|
-
`;
|
|
13
|
-
const noConfigEntryModule = `
|
|
14
|
-
// This file is auto-generated on 'sanity dev'
|
|
15
|
-
// Modifications to this file is automatically discarded
|
|
16
|
-
import {renderStudio} from "sanity"
|
|
17
|
-
|
|
18
|
-
const studioConfig = {missingConfigFile: true}
|
|
19
|
-
|
|
20
|
-
renderStudio(
|
|
21
|
-
document.getElementById("sanity"),
|
|
22
|
-
studioConfig,
|
|
23
|
-
{reactStrictMode: %STUDIO_REACT_STRICT_MODE%, basePath: %STUDIO_BASE_PATH%}
|
|
24
|
-
)
|
|
25
|
-
`;
|
|
26
|
-
const appEntryModule = `
|
|
27
|
-
// This file is auto-generated on 'sanity dev'
|
|
28
|
-
// Modifications to this file is automatically discarded
|
|
29
|
-
import {createRoot} from 'react-dom/client'
|
|
30
|
-
import {createElement} from 'react'
|
|
31
|
-
import App from %ENTRY%
|
|
32
|
-
|
|
33
|
-
const root = createRoot(document.getElementById('root'))
|
|
34
|
-
const element = createElement(App)
|
|
35
|
-
root.render(element)
|
|
36
|
-
`;
|
|
37
|
-
export function getEntryModule(options) {
|
|
38
|
-
const { basePath, entry, isApp, reactStrictMode, relativeConfigLocation } = options;
|
|
39
|
-
if (isApp) {
|
|
40
|
-
return appEntryModule.replace(/%ENTRY%/, JSON.stringify(entry || './src/App'));
|
|
41
|
-
}
|
|
42
|
-
const sourceModule = relativeConfigLocation ? entryModule : noConfigEntryModule;
|
|
43
|
-
return sourceModule.replace(/%STUDIO_REACT_STRICT_MODE%/, JSON.stringify(Boolean(reactStrictMode))).replace(/%STUDIO_CONFIG_LOCATION%/, JSON.stringify(relativeConfigLocation)).replace(/%STUDIO_BASE_PATH%/, JSON.stringify(basePath || '/'));
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
//# sourceMappingURL=getEntryModule.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/build/getEntryModule.ts"],"sourcesContent":["const entryModule = `\n// This file is auto-generated on 'sanity dev'\n// Modifications to this file is automatically discarded\nimport {renderStudio} from \"sanity\"\nimport studioConfig from %STUDIO_CONFIG_LOCATION%\n\nrenderStudio(\n document.getElementById(\"sanity\"),\n studioConfig,\n {reactStrictMode: %STUDIO_REACT_STRICT_MODE%, basePath: %STUDIO_BASE_PATH%}\n)\n`\n\nconst noConfigEntryModule = `\n// This file is auto-generated on 'sanity dev'\n// Modifications to this file is automatically discarded\nimport {renderStudio} from \"sanity\"\n\nconst studioConfig = {missingConfigFile: true}\n\nrenderStudio(\n document.getElementById(\"sanity\"),\n studioConfig,\n {reactStrictMode: %STUDIO_REACT_STRICT_MODE%, basePath: %STUDIO_BASE_PATH%}\n)\n`\n\nconst appEntryModule = `\n// This file is auto-generated on 'sanity dev'\n// Modifications to this file is automatically discarded\nimport {createRoot} from 'react-dom/client'\nimport {createElement} from 'react'\nimport App from %ENTRY%\n\nconst root = createRoot(document.getElementById('root'))\nconst element = createElement(App)\nroot.render(element)\n`\n\nexport function getEntryModule(options: {\n basePath?: string\n entry?: string\n isApp?: boolean\n reactStrictMode: boolean\n relativeConfigLocation: string | null\n}): string {\n const {basePath, entry, isApp, reactStrictMode, relativeConfigLocation} = options\n\n if (isApp) {\n return appEntryModule.replace(/%ENTRY%/, JSON.stringify(entry || './src/App'))\n }\n\n const sourceModule = relativeConfigLocation ? entryModule : noConfigEntryModule\n\n return sourceModule\n .replace(/%STUDIO_REACT_STRICT_MODE%/, JSON.stringify(Boolean(reactStrictMode)))\n .replace(/%STUDIO_CONFIG_LOCATION%/, JSON.stringify(relativeConfigLocation))\n .replace(/%STUDIO_BASE_PATH%/, JSON.stringify(basePath || '/'))\n}\n"],"names":["entryModule","noConfigEntryModule","appEntryModule","getEntryModule","options","basePath","entry","isApp","reactStrictMode","relativeConfigLocation","replace","JSON","stringify","sourceModule","Boolean"],"mappings":"AAAA,MAAMA,cAAc,CAAC;;;;;;;;;;;AAWrB,CAAC;AAED,MAAMC,sBAAsB,CAAC;;;;;;;;;;;;AAY7B,CAAC;AAED,MAAMC,iBAAiB,CAAC;;;;;;;;;;AAUxB,CAAC;AAED,OAAO,SAASC,eAAeC,OAM9B;IACC,MAAM,EAACC,QAAQ,EAAEC,KAAK,EAAEC,KAAK,EAAEC,eAAe,EAAEC,sBAAsB,EAAC,GAAGL;IAE1E,IAAIG,OAAO;QACT,OAAOL,eAAeQ,OAAO,CAAC,WAAWC,KAAKC,SAAS,CAACN,SAAS;IACnE;IAEA,MAAMO,eAAeJ,yBAAyBT,cAAcC;IAE5D,OAAOY,aACJH,OAAO,CAAC,8BAA8BC,KAAKC,SAAS,CAACE,QAAQN,mBAC7DE,OAAO,CAAC,4BAA4BC,KAAKC,SAAS,CAACH,yBACnDC,OAAO,CAAC,sBAAsBC,KAAKC,SAAS,CAACP,YAAY;AAC9D"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
/**
|
|
3
|
-
* @internal
|
|
4
|
-
*/ export function getPossibleDocumentComponentLocations(rootPath) {
|
|
5
|
-
return [
|
|
6
|
-
path.join(rootPath, '_document.js'),
|
|
7
|
-
path.join(rootPath, '_document.tsx')
|
|
8
|
-
];
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
//# sourceMappingURL=getPossibleDocumentComponentLocations.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/build/getPossibleDocumentComponentLocations.ts"],"sourcesContent":["import path from 'node:path'\n\n/**\n * @internal\n */\nexport function getPossibleDocumentComponentLocations(rootPath: string): string[] {\n return [path.join(rootPath, '_document.js'), path.join(rootPath, '_document.tsx')]\n}\n"],"names":["path","getPossibleDocumentComponentLocations","rootPath","join"],"mappings":"AAAA,OAAOA,UAAU,YAAW;AAE5B;;CAEC,GACD,OAAO,SAASC,sCAAsCC,QAAgB;IACpE,OAAO;QAACF,KAAKG,IAAI,CAACD,UAAU;QAAiBF,KAAKG,IAAI,CAACD,UAAU;KAAiB;AACpF"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get all `SANITY_STUDIO_` prefix env vars
|
|
3
|
-
*
|
|
4
|
-
* @internal
|
|
5
|
-
*/ export function getStudioEnvVars(env = process.env) {
|
|
6
|
-
return Object.keys(env).filter((key)=>key.toUpperCase().startsWith('SANITY_STUDIO_'));
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
//# sourceMappingURL=getStudioEnvVars.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/build/getStudioEnvVars.ts"],"sourcesContent":["/**\n * Get all `SANITY_STUDIO_` prefix env vars\n *\n * @internal\n */\nexport function getStudioEnvVars(env: Record<string, string | undefined> = process.env): string[] {\n return Object.keys(env).filter((key) => key.toUpperCase().startsWith('SANITY_STUDIO_'))\n}\n"],"names":["getStudioEnvVars","env","process","Object","keys","filter","key","toUpperCase","startsWith"],"mappings":"AAAA;;;;CAIC,GACD,OAAO,SAASA,iBAAiBC,MAA0CC,QAAQD,GAAG;IACpF,OAAOE,OAAOC,IAAI,CAACH,KAAKI,MAAM,CAAC,CAACC,MAAQA,IAAIC,WAAW,GAAGC,UAAU,CAAC;AACvE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/build/getStudioEnvironmentVariables.ts"],"sourcesContent":["import {loadEnv} from '../../util/loadEnv.js'\n\nconst envPrefix = 'SANITY_STUDIO_'\nconst appEnvPrefix = 'SANITY_APP_'\n\n/**\n * The params for the `getStudioEnvironmentVariables` function that gets Studio focused environment variables.\n *\n * @public\n */\nexport interface StudioEnvVariablesOptions {\n /**\n * When specified includes environment variables from dotenv files (`.env`), in the same way the studio does.\n * A `mode` must be specified, usually `development`\n * or `production`, which will load the corresponding `.env.development` or `.env.production`.\n * To specify where to look for the dotenv files, specify `options.envFile.envDir`.\n */\n envFile?: false | {envDir?: string; mode: string}\n /**\n * When specified, JSON-encodes the values, which is handy if you want to pass\n * this to a bundlers hardcoded defines, such as Vite's `define` or Webpack's `DefinePlugin`.\n */\n jsonEncode?: boolean\n /**\n * When specified adds a prefix to the environment variable keys,\n * eg: `getStudioEnvironmentVariables({prefix: 'process.env.'})`\n */\n prefix?: string\n}\n\n/**\n * Get environment variables prefixed with SANITY_STUDIO_, as an object.\n *\n * @param options - Options for the environment variable loading\n * {@link StudioEnvVariablesOptions}\n * @returns Object of studio environment variables\n *\n * @example\n * ```tsx\n * getStudioEnvironmentVariables({prefix: 'process.env.', jsonEncode: true})\n * ```\n *\n * @public\n */\nexport function getStudioEnvironmentVariables(\n options: StudioEnvVariablesOptions = {},\n): Record<string, string> {\n const {envFile = false, jsonEncode = false, prefix = ''} = options\n const fullEnv = envFile\n ? {...process.env, ...loadEnv(envFile.mode, envFile.envDir || process.cwd(), [envPrefix])}\n : process.env\n\n const studioEnv: Record<string, string> = {}\n for (const key in fullEnv) {\n if (key.startsWith(envPrefix)) {\n studioEnv[`${prefix}${key}`] = jsonEncode\n ? JSON.stringify(fullEnv[key] || '')\n : fullEnv[key] || ''\n }\n }\n return studioEnv\n}\n\n/**\n * Get environment variables prefixed with SANITY_APP_, as an object.\n *\n * @param options - Options for the environment variable loading\n * {@link StudioEnvVariablesOptions}\n * @returns Object of app environment variables\n *\n * @internal\n */\nexport function getAppEnvironmentVariables(\n options: StudioEnvVariablesOptions = {},\n): Record<string, string> {\n const {envFile = false, jsonEncode = false, prefix = ''} = options\n const fullEnv = envFile\n ? {...process.env, ...loadEnv(envFile.mode, envFile.envDir || process.cwd(), [appEnvPrefix])}\n : process.env\n\n const appEnv: Record<string, string> = {}\n for (const key in fullEnv) {\n if (key.startsWith(appEnvPrefix)) {\n appEnv[`${prefix}${key}`] = jsonEncode\n ? JSON.stringify(fullEnv[key] || '')\n : fullEnv[key] || ''\n }\n }\n return appEnv\n}\n"],"names":["loadEnv","envPrefix","appEnvPrefix","getStudioEnvironmentVariables","options","envFile","jsonEncode","prefix","fullEnv","process","env","mode","envDir","cwd","studioEnv","key","startsWith","JSON","stringify","getAppEnvironmentVariables","appEnv"],"mappings":"AAAA,SAAQA,OAAO,QAAO,wBAAuB;AAE7C,MAAMC,YAAY;AAClB,MAAMC,eAAe;AA2BrB;;;;;;;;;;;;;CAaC,GACD,OAAO,SAASC,8BACdC,UAAqC,CAAC,CAAC;IAEvC,MAAM,EAACC,UAAU,KAAK,EAAEC,aAAa,KAAK,EAAEC,SAAS,EAAE,EAAC,GAAGH;IAC3D,MAAMI,UAAUH,UACZ;QAAC,GAAGI,QAAQC,GAAG;QAAE,GAAGV,QAAQK,QAAQM,IAAI,EAAEN,QAAQO,MAAM,IAAIH,QAAQI,GAAG,IAAI;YAACZ;SAAU,CAAC;IAAA,IACvFQ,QAAQC,GAAG;IAEf,MAAMI,YAAoC,CAAC;IAC3C,IAAK,MAAMC,OAAOP,QAAS;QACzB,IAAIO,IAAIC,UAAU,CAACf,YAAY;YAC7Ba,SAAS,CAAC,GAAGP,SAASQ,KAAK,CAAC,GAAGT,aAC3BW,KAAKC,SAAS,CAACV,OAAO,CAACO,IAAI,IAAI,MAC/BP,OAAO,CAACO,IAAI,IAAI;QACtB;IACF;IACA,OAAOD;AACT;AAEA;;;;;;;;CAQC,GACD,OAAO,SAASK,2BACdf,UAAqC,CAAC,CAAC;IAEvC,MAAM,EAACC,UAAU,KAAK,EAAEC,aAAa,KAAK,EAAEC,SAAS,EAAE,EAAC,GAAGH;IAC3D,MAAMI,UAAUH,UACZ;QAAC,GAAGI,QAAQC,GAAG;QAAE,GAAGV,QAAQK,QAAQM,IAAI,EAAEN,QAAQO,MAAM,IAAIH,QAAQI,GAAG,IAAI;YAACX;SAAa,CAAC;IAAA,IAC1FO,QAAQC,GAAG;IAEf,MAAMU,SAAiC,CAAC;IACxC,IAAK,MAAML,OAAOP,QAAS;QACzB,IAAIO,IAAIC,UAAU,CAACd,eAAe;YAChCkB,MAAM,CAAC,GAAGb,SAASQ,KAAK,CAAC,GAAGT,aACxBW,KAAKC,SAAS,CAACV,OAAO,CAACO,IAAI,IAAI,MAC/BP,OAAO,CAACO,IAAI,IAAI;QACtB;IACF;IACA,OAAOK;AACT"}
|
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { getDefaultFaviconsPath } from '@sanity/cli-build/_internal';
|
|
3
|
-
import { findProjectRoot, getCliTelemetry } from '@sanity/cli-core';
|
|
4
|
-
import viteReact from '@vitejs/plugin-react';
|
|
5
|
-
import debug from 'debug';
|
|
6
|
-
import { mergeConfig } from 'vite';
|
|
7
|
-
import { SANITY_CACHE_DIR } from '../../constants.js';
|
|
8
|
-
import { sanityBuildEntries } from '../../server/vite/plugin-sanity-build-entries.js';
|
|
9
|
-
import { sanityFaviconsPlugin } from '../../server/vite/plugin-sanity-favicons.js';
|
|
10
|
-
import { sanityRuntimeRewritePlugin } from '../../server/vite/plugin-sanity-runtime-rewrite.js';
|
|
11
|
-
import { sanitySchemaExtractionPlugin } from '../../server/vite/plugin-schema-extraction.js';
|
|
12
|
-
import { sanityTypegenPlugin } from '../../server/vite/plugin-typegen.js';
|
|
13
|
-
import { createExternalFromImportMap } from './createExternalFromImportMap.js';
|
|
14
|
-
import { getAppEnvironmentVariables, getStudioEnvironmentVariables } from './getStudioEnvironmentVariables.js';
|
|
15
|
-
import { normalizeBasePath } from './normalizeBasePath.js';
|
|
16
|
-
/**
|
|
17
|
-
* Get a configuration object for Vite based on the passed options
|
|
18
|
-
*
|
|
19
|
-
* @internal Only meant for consumption inside of Sanity modules, do not depend on this externally
|
|
20
|
-
*/ export async function getViteConfig(options) {
|
|
21
|
-
const { autoUpdatesCssUrls, basePath: rawBasePath = '/', cwd, importMap, isApp, minify, mode, outputDir, reactCompiler, schemaExtraction, server, // default to `true` when `mode=development`
|
|
22
|
-
sourceMap = options.mode === 'development', typegen } = options;
|
|
23
|
-
const basePath = normalizeBasePath(rawBasePath);
|
|
24
|
-
const configPath = (await findProjectRoot(cwd)).path;
|
|
25
|
-
const customFaviconsPath = path.join(cwd, 'static');
|
|
26
|
-
const defaultFaviconsPath = await getDefaultFaviconsPath();
|
|
27
|
-
const staticPath = `${basePath}static`;
|
|
28
|
-
const envVars = isApp ? getAppEnvironmentVariables({
|
|
29
|
-
jsonEncode: true,
|
|
30
|
-
prefix: 'process.env.'
|
|
31
|
-
}) : getStudioEnvironmentVariables({
|
|
32
|
-
jsonEncode: true,
|
|
33
|
-
prefix: 'process.env.'
|
|
34
|
-
});
|
|
35
|
-
const viteConfig = {
|
|
36
|
-
base: basePath,
|
|
37
|
-
build: {
|
|
38
|
-
outDir: outputDir || path.resolve(cwd, 'dist'),
|
|
39
|
-
sourcemap: sourceMap
|
|
40
|
-
},
|
|
41
|
-
// Define a custom cache directory so that sanity's vite cache
|
|
42
|
-
// does not conflict with any potential local vite projects
|
|
43
|
-
cacheDir: `${SANITY_CACHE_DIR}/vite`,
|
|
44
|
-
configFile: false,
|
|
45
|
-
define: {
|
|
46
|
-
__SANITY_BUILD_TIMESTAMP__: JSON.stringify(Date.now()),
|
|
47
|
-
__SANITY_STAGING__: process.env.SANITY_INTERNAL_ENV === 'staging',
|
|
48
|
-
'process.env.MODE': JSON.stringify(mode),
|
|
49
|
-
'process.env.PKG_BUILD_VERSION': JSON.stringify(process.env.PKG_BUILD_VERSION),
|
|
50
|
-
/**
|
|
51
|
-
* Yes, double negatives are confusing.
|
|
52
|
-
* The default value of `SC_DISABLE_SPEEDY` is `process.env.NODE_ENV === 'production'`: https://github.com/styled-components/styled-components/blob/99c02f52d69e8e509c0bf012cadee7f8e819a6dd/packages/styled-components/src/constants.ts#L34
|
|
53
|
-
* Which means that in production, use the much faster way of inserting CSS rules, based on the CSSStyleSheet API (https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/insertRule)
|
|
54
|
-
* while in dev mode, use the slower way of inserting CSS rules, which appends text nodes to the `<style>` tag: https://github.com/styled-components/styled-components/blob/99c02f52d69e8e509c0bf012cadee7f8e819a6dd/packages/styled-components/src/sheet/Tag.ts#L74-L76
|
|
55
|
-
* There are historical reasons for this, primarily that browsers initially did not support editing CSS rules in the DevTools inspector if `CSSStyleSheet.insetRule` were used.
|
|
56
|
-
* However, that's no longer the case (since Chrome 81 back in April 2020: https://developer.chrome.com/docs/css-ui/css-in-js), the latest version of FireFox also supports it,
|
|
57
|
-
* and there is no longer any reason to use the much slower method in dev mode.
|
|
58
|
-
*/ 'process.env.SC_DISABLE_SPEEDY': JSON.stringify('false'),
|
|
59
|
-
...envVars
|
|
60
|
-
},
|
|
61
|
-
envPrefix: isApp ? 'SANITY_APP_' : 'SANITY_STUDIO_',
|
|
62
|
-
logLevel: mode === 'production' ? 'silent' : 'info',
|
|
63
|
-
mode,
|
|
64
|
-
plugins: [
|
|
65
|
-
viteReact(reactCompiler ? {
|
|
66
|
-
babel: {
|
|
67
|
-
generatorOpts: {
|
|
68
|
-
compact: true
|
|
69
|
-
},
|
|
70
|
-
plugins: [
|
|
71
|
-
[
|
|
72
|
-
'babel-plugin-react-compiler',
|
|
73
|
-
reactCompiler
|
|
74
|
-
]
|
|
75
|
-
]
|
|
76
|
-
}
|
|
77
|
-
} : {}),
|
|
78
|
-
sanityFaviconsPlugin({
|
|
79
|
-
customFaviconsPath,
|
|
80
|
-
defaultFaviconsPath,
|
|
81
|
-
staticUrlPath: staticPath
|
|
82
|
-
}),
|
|
83
|
-
sanityRuntimeRewritePlugin(),
|
|
84
|
-
sanityBuildEntries({
|
|
85
|
-
autoUpdatesCssUrls,
|
|
86
|
-
basePath,
|
|
87
|
-
cwd,
|
|
88
|
-
importMap,
|
|
89
|
-
isApp
|
|
90
|
-
}),
|
|
91
|
-
// Add schema extraction when enabled
|
|
92
|
-
...schemaExtraction?.enabled ? [
|
|
93
|
-
sanitySchemaExtractionPlugin({
|
|
94
|
-
additionalPatterns: schemaExtraction.watchPatterns,
|
|
95
|
-
configPath,
|
|
96
|
-
enforceRequiredFields: schemaExtraction.enforceRequiredFields,
|
|
97
|
-
outputPath: schemaExtraction.path,
|
|
98
|
-
telemetryLogger: getCliTelemetry(),
|
|
99
|
-
workDir: cwd,
|
|
100
|
-
workspaceName: schemaExtraction.workspace
|
|
101
|
-
})
|
|
102
|
-
] : [],
|
|
103
|
-
// Add typegen when enabled
|
|
104
|
-
...typegen?.enabled ? [
|
|
105
|
-
sanityTypegenPlugin({
|
|
106
|
-
config: typegen,
|
|
107
|
-
telemetryLogger: getCliTelemetry(),
|
|
108
|
-
workDir: cwd
|
|
109
|
-
})
|
|
110
|
-
] : []
|
|
111
|
-
],
|
|
112
|
-
resolve: {
|
|
113
|
-
dedupe: [
|
|
114
|
-
'react',
|
|
115
|
-
'react-dom',
|
|
116
|
-
'sanity',
|
|
117
|
-
'styled-components'
|
|
118
|
-
]
|
|
119
|
-
},
|
|
120
|
-
root: cwd,
|
|
121
|
-
server: {
|
|
122
|
-
host: server?.host,
|
|
123
|
-
port: server?.port || 3333,
|
|
124
|
-
// Only enable strict port for studio,
|
|
125
|
-
// since apps can run on any port
|
|
126
|
-
strictPort: isApp ? false : true,
|
|
127
|
-
/**
|
|
128
|
-
* Significantly speed up startup time,
|
|
129
|
-
* and most importantly eliminates the `new dependencies optimized: foobar. optimized dependencies changed. reloading`
|
|
130
|
-
* types of initial reload loops that otherwise happen as vite discovers deps that need to be optimized.
|
|
131
|
-
* This option starts the traversal up front, and warms up the dep tree required to render the userland sanity.config.ts file,
|
|
132
|
-
* and thus avoids frustrating reload loops.
|
|
133
|
-
*/ warmup: {
|
|
134
|
-
clientFiles: [
|
|
135
|
-
'./.sanity/runtime/app.js'
|
|
136
|
-
]
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
if (mode === 'production') {
|
|
141
|
-
viteConfig.build = {
|
|
142
|
-
...viteConfig.build,
|
|
143
|
-
assetsDir: 'static',
|
|
144
|
-
emptyOutDir: false,
|
|
145
|
-
minify: minify ? 'esbuild' : false,
|
|
146
|
-
rollupOptions: {
|
|
147
|
-
external: createExternalFromImportMap(importMap),
|
|
148
|
-
input: {
|
|
149
|
-
sanity: path.join(cwd, '.sanity', 'runtime', 'app.js')
|
|
150
|
-
},
|
|
151
|
-
onwarn: onRollupWarn
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
return viteConfig;
|
|
156
|
-
}
|
|
157
|
-
function onRollupWarn(warning, warn) {
|
|
158
|
-
if (suppressUnusedImport(warning)) {
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
warn(warning);
|
|
162
|
-
}
|
|
163
|
-
function suppressUnusedImport(warning) {
|
|
164
|
-
if (warning.code !== 'UNUSED_EXTERNAL_IMPORT') return false;
|
|
165
|
-
// Suppress:
|
|
166
|
-
// ```
|
|
167
|
-
// "useDebugValue" is imported from external module "react"…
|
|
168
|
-
// ```
|
|
169
|
-
if (warning.names?.includes('useDebugValue')) {
|
|
170
|
-
warning.names = warning.names.filter((n)=>n !== 'useDebugValue');
|
|
171
|
-
if (warning.names.length === 0) return true;
|
|
172
|
-
}
|
|
173
|
-
// If some library does something unexpected, we suppress since it isn't actionable
|
|
174
|
-
if (warning.ids?.every((id)=>id.includes('/node_modules/') || id.includes('\\node_modules\\'))) return true;
|
|
175
|
-
return false;
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Ensure Sanity entry chunk is always loaded
|
|
179
|
-
*
|
|
180
|
-
* @param config - User-modified configuration
|
|
181
|
-
* @returns Merged configuration
|
|
182
|
-
* @internal
|
|
183
|
-
*/ export async function finalizeViteConfig(config) {
|
|
184
|
-
if (typeof config.build?.rollupOptions?.input !== 'object') {
|
|
185
|
-
throw new TypeError('Vite config must contain `build.rollupOptions.input`, and it must be an object');
|
|
186
|
-
}
|
|
187
|
-
if (!config.root) {
|
|
188
|
-
throw new Error('Vite config must contain `root` property, and must point to the Sanity root directory');
|
|
189
|
-
}
|
|
190
|
-
return mergeConfig(config, {
|
|
191
|
-
build: {
|
|
192
|
-
rollupOptions: {
|
|
193
|
-
input: {
|
|
194
|
-
sanity: path.join(config.root, '.sanity', 'runtime', 'app.js')
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Merge user-provided Vite configuration object or function
|
|
202
|
-
*
|
|
203
|
-
* @param defaultConfig - Default configuration object
|
|
204
|
-
* @param userConfig - User-provided configuration object or function
|
|
205
|
-
* @returns Merged configuration
|
|
206
|
-
* @internal
|
|
207
|
-
*/ export async function extendViteConfigWithUserConfig(env, defaultConfig, userConfig) {
|
|
208
|
-
let config = defaultConfig;
|
|
209
|
-
if (typeof userConfig === 'function') {
|
|
210
|
-
debug('Extending vite config using user-specified function');
|
|
211
|
-
config = await userConfig(config, env);
|
|
212
|
-
} else if (typeof userConfig === 'object') {
|
|
213
|
-
debug('Merging vite config using user-specified object');
|
|
214
|
-
config = mergeConfig(config, userConfig);
|
|
215
|
-
}
|
|
216
|
-
return config;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
//# sourceMappingURL=getViteConfig.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/build/getViteConfig.ts"],"sourcesContent":["import path from 'node:path'\n\nimport {getDefaultFaviconsPath} from '@sanity/cli-build/_internal'\nimport {\n type CliConfig,\n findProjectRoot,\n getCliTelemetry,\n type UserViteConfig,\n} from '@sanity/cli-core'\nimport viteReact from '@vitejs/plugin-react'\nimport {type PluginOptions as ReactCompilerConfig} from 'babel-plugin-react-compiler'\nimport debug from 'debug'\nimport {type ConfigEnv, type InlineConfig, mergeConfig, type Rollup} from 'vite'\n\nimport {SANITY_CACHE_DIR} from '../../constants.js'\nimport {sanityBuildEntries} from '../../server/vite/plugin-sanity-build-entries.js'\nimport {sanityFaviconsPlugin} from '../../server/vite/plugin-sanity-favicons.js'\nimport {sanityRuntimeRewritePlugin} from '../../server/vite/plugin-sanity-runtime-rewrite.js'\nimport {sanitySchemaExtractionPlugin} from '../../server/vite/plugin-schema-extraction.js'\nimport {sanityTypegenPlugin} from '../../server/vite/plugin-typegen.js'\nimport {createExternalFromImportMap} from './createExternalFromImportMap.js'\nimport {\n getAppEnvironmentVariables,\n getStudioEnvironmentVariables,\n} from './getStudioEnvironmentVariables.js'\nimport {normalizeBasePath} from './normalizeBasePath.js'\n\ninterface ViteOptions {\n /**\n * Root path of the studio/sanity app\n */\n cwd: string\n\n /**\n * Mode to run vite in - eg development or production\n */\n mode: 'development' | 'production'\n\n reactCompiler: ReactCompilerConfig | undefined\n\n /**\n * CSS URLs for auto-updated packages (loaded via module server)\n */\n autoUpdatesCssUrls?: string[]\n\n /**\n * Base path (eg under where to serve the app - `/studio` or similar)\n * Will be normalized to ensure it starts and ends with a `/`\n */\n basePath?: string\n\n importMap?: {imports?: Record<string, string>}\n\n isApp?: boolean\n\n /**\n * Whether or not to minify the output (only used in `mode: 'production'`)\n */\n minify?: boolean\n\n /**\n * Output directory (eg where to place the built files, if any)\n */\n outputDir?: string\n /**\n * Schema extraction configuration\n */\n schemaExtraction?: CliConfig['schemaExtraction']\n /**\n * HTTP development server configuration\n */\n server?: {host?: string; port?: number}\n /**\n * Whether or not to enable source maps\n */\n sourceMap?: boolean\n /**\n * Typegen configuration\n */\n typegen?: CliConfig['typegen']\n}\n\n/**\n * Get a configuration object for Vite based on the passed options\n *\n * @internal Only meant for consumption inside of Sanity modules, do not depend on this externally\n */\nexport async function getViteConfig(options: ViteOptions): Promise<InlineConfig> {\n const {\n autoUpdatesCssUrls,\n basePath: rawBasePath = '/',\n cwd,\n importMap,\n isApp,\n minify,\n mode,\n outputDir,\n reactCompiler,\n schemaExtraction,\n server,\n // default to `true` when `mode=development`\n sourceMap = options.mode === 'development',\n typegen,\n } = options\n\n const basePath = normalizeBasePath(rawBasePath)\n\n const configPath = (await findProjectRoot(cwd)).path\n\n const customFaviconsPath = path.join(cwd, 'static')\n const defaultFaviconsPath = await getDefaultFaviconsPath()\n const staticPath = `${basePath}static`\n\n const envVars = isApp\n ? getAppEnvironmentVariables({jsonEncode: true, prefix: 'process.env.'})\n : getStudioEnvironmentVariables({jsonEncode: true, prefix: 'process.env.'})\n\n const viteConfig: InlineConfig = {\n base: basePath,\n build: {\n outDir: outputDir || path.resolve(cwd, 'dist'),\n sourcemap: sourceMap,\n },\n // Define a custom cache directory so that sanity's vite cache\n // does not conflict with any potential local vite projects\n cacheDir: `${SANITY_CACHE_DIR}/vite`,\n configFile: false,\n define: {\n __SANITY_BUILD_TIMESTAMP__: JSON.stringify(Date.now()),\n __SANITY_STAGING__: process.env.SANITY_INTERNAL_ENV === 'staging',\n 'process.env.MODE': JSON.stringify(mode),\n 'process.env.PKG_BUILD_VERSION': JSON.stringify(process.env.PKG_BUILD_VERSION),\n /**\n * Yes, double negatives are confusing.\n * The default value of `SC_DISABLE_SPEEDY` is `process.env.NODE_ENV === 'production'`: https://github.com/styled-components/styled-components/blob/99c02f52d69e8e509c0bf012cadee7f8e819a6dd/packages/styled-components/src/constants.ts#L34\n * Which means that in production, use the much faster way of inserting CSS rules, based on the CSSStyleSheet API (https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/insertRule)\n * while in dev mode, use the slower way of inserting CSS rules, which appends text nodes to the `<style>` tag: https://github.com/styled-components/styled-components/blob/99c02f52d69e8e509c0bf012cadee7f8e819a6dd/packages/styled-components/src/sheet/Tag.ts#L74-L76\n * There are historical reasons for this, primarily that browsers initially did not support editing CSS rules in the DevTools inspector if `CSSStyleSheet.insetRule` were used.\n * However, that's no longer the case (since Chrome 81 back in April 2020: https://developer.chrome.com/docs/css-ui/css-in-js), the latest version of FireFox also supports it,\n * and there is no longer any reason to use the much slower method in dev mode.\n */\n 'process.env.SC_DISABLE_SPEEDY': JSON.stringify('false'),\n ...envVars,\n },\n envPrefix: isApp ? 'SANITY_APP_' : 'SANITY_STUDIO_',\n logLevel: mode === 'production' ? 'silent' : 'info',\n mode,\n plugins: [\n viteReact(\n reactCompiler\n ? {\n babel: {\n generatorOpts: {compact: true},\n plugins: [['babel-plugin-react-compiler', reactCompiler]],\n },\n }\n : {},\n ),\n sanityFaviconsPlugin({customFaviconsPath, defaultFaviconsPath, staticUrlPath: staticPath}),\n sanityRuntimeRewritePlugin(),\n sanityBuildEntries({autoUpdatesCssUrls, basePath, cwd, importMap, isApp}),\n // Add schema extraction when enabled\n ...(schemaExtraction?.enabled\n ? [\n sanitySchemaExtractionPlugin({\n additionalPatterns: schemaExtraction.watchPatterns,\n configPath,\n enforceRequiredFields: schemaExtraction.enforceRequiredFields,\n outputPath: schemaExtraction.path,\n telemetryLogger: getCliTelemetry(),\n workDir: cwd,\n workspaceName: schemaExtraction.workspace,\n }),\n ]\n : []),\n // Add typegen when enabled\n ...(typegen?.enabled\n ? [\n sanityTypegenPlugin({\n config: typegen,\n telemetryLogger: getCliTelemetry(),\n workDir: cwd,\n }),\n ]\n : []),\n ],\n resolve: {\n dedupe: ['react', 'react-dom', 'sanity', 'styled-components'],\n },\n root: cwd,\n server: {\n host: server?.host,\n port: server?.port || 3333,\n // Only enable strict port for studio,\n // since apps can run on any port\n strictPort: isApp ? false : true,\n\n /**\n * Significantly speed up startup time,\n * and most importantly eliminates the `new dependencies optimized: foobar. optimized dependencies changed. reloading`\n * types of initial reload loops that otherwise happen as vite discovers deps that need to be optimized.\n * This option starts the traversal up front, and warms up the dep tree required to render the userland sanity.config.ts file,\n * and thus avoids frustrating reload loops.\n */\n warmup: {\n clientFiles: ['./.sanity/runtime/app.js'],\n },\n },\n }\n\n if (mode === 'production') {\n viteConfig.build = {\n ...viteConfig.build,\n\n assetsDir: 'static',\n emptyOutDir: false, // Rely on CLI to do this\n minify: minify ? 'esbuild' : false,\n\n rollupOptions: {\n external: createExternalFromImportMap(importMap),\n input: {\n sanity: path.join(cwd, '.sanity', 'runtime', 'app.js'),\n },\n onwarn: onRollupWarn,\n },\n }\n }\n\n return viteConfig\n}\n\nfunction onRollupWarn(warning: Rollup.RollupLog, warn: Rollup.LoggingFunction) {\n if (suppressUnusedImport(warning)) {\n return\n }\n\n warn(warning)\n}\n\nfunction suppressUnusedImport(warning: Rollup.RollupLog & {ids?: string[]}): boolean {\n if (warning.code !== 'UNUSED_EXTERNAL_IMPORT') return false\n\n // Suppress:\n // ```\n // \"useDebugValue\" is imported from external module \"react\"…\n // ```\n if (warning.names?.includes('useDebugValue')) {\n warning.names = warning.names.filter((n) => n !== 'useDebugValue')\n if (warning.names.length === 0) return true\n }\n\n // If some library does something unexpected, we suppress since it isn't actionable\n if (warning.ids?.every((id) => id.includes('/node_modules/') || id.includes('\\\\node_modules\\\\')))\n return true\n\n return false\n}\n\n/**\n * Ensure Sanity entry chunk is always loaded\n *\n * @param config - User-modified configuration\n * @returns Merged configuration\n * @internal\n */\nexport async function finalizeViteConfig(config: InlineConfig): Promise<InlineConfig> {\n if (typeof config.build?.rollupOptions?.input !== 'object') {\n throw new TypeError(\n 'Vite config must contain `build.rollupOptions.input`, and it must be an object',\n )\n }\n\n if (!config.root) {\n throw new Error(\n 'Vite config must contain `root` property, and must point to the Sanity root directory',\n )\n }\n\n return mergeConfig(config, {\n build: {\n rollupOptions: {\n input: {\n sanity: path.join(config.root, '.sanity', 'runtime', 'app.js'),\n },\n },\n },\n })\n}\n\n/**\n * Merge user-provided Vite configuration object or function\n *\n * @param defaultConfig - Default configuration object\n * @param userConfig - User-provided configuration object or function\n * @returns Merged configuration\n * @internal\n */\nexport async function extendViteConfigWithUserConfig(\n env: ConfigEnv,\n defaultConfig: InlineConfig,\n userConfig: UserViteConfig,\n): Promise<InlineConfig> {\n let config = defaultConfig\n\n if (typeof userConfig === 'function') {\n debug('Extending vite config using user-specified function')\n config = await userConfig(config, env)\n } else if (typeof userConfig === 'object') {\n debug('Merging vite config using user-specified object')\n config = mergeConfig(config, userConfig)\n }\n\n return config\n}\n"],"names":["path","getDefaultFaviconsPath","findProjectRoot","getCliTelemetry","viteReact","debug","mergeConfig","SANITY_CACHE_DIR","sanityBuildEntries","sanityFaviconsPlugin","sanityRuntimeRewritePlugin","sanitySchemaExtractionPlugin","sanityTypegenPlugin","createExternalFromImportMap","getAppEnvironmentVariables","getStudioEnvironmentVariables","normalizeBasePath","getViteConfig","options","autoUpdatesCssUrls","basePath","rawBasePath","cwd","importMap","isApp","minify","mode","outputDir","reactCompiler","schemaExtraction","server","sourceMap","typegen","configPath","customFaviconsPath","join","defaultFaviconsPath","staticPath","envVars","jsonEncode","prefix","viteConfig","base","build","outDir","resolve","sourcemap","cacheDir","configFile","define","__SANITY_BUILD_TIMESTAMP__","JSON","stringify","Date","now","__SANITY_STAGING__","process","env","SANITY_INTERNAL_ENV","PKG_BUILD_VERSION","envPrefix","logLevel","plugins","babel","generatorOpts","compact","staticUrlPath","enabled","additionalPatterns","watchPatterns","enforceRequiredFields","outputPath","telemetryLogger","workDir","workspaceName","workspace","config","dedupe","root","host","port","strictPort","warmup","clientFiles","assetsDir","emptyOutDir","rollupOptions","external","input","sanity","onwarn","onRollupWarn","warning","warn","suppressUnusedImport","code","names","includes","filter","n","length","ids","every","id","finalizeViteConfig","TypeError","Error","extendViteConfigWith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