@sanity/cli 6.0.0-alpha.16 → 6.0.0-alpha.18
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 +592 -470
- package/dist/SanityHelp.js +74 -21
- package/dist/SanityHelp.js.map +1 -1
- package/dist/actions/build/buildApp.js +42 -15
- package/dist/actions/build/buildApp.js.map +1 -1
- package/dist/actions/build/buildStudio.js +64 -45
- package/dist/actions/build/buildStudio.js.map +1 -1
- package/dist/actions/build/buildVendorDependencies.js +3 -16
- package/dist/actions/build/buildVendorDependencies.js.map +1 -1
- package/dist/actions/build/checkStudioDependencyVersions.js +7 -7
- package/dist/actions/build/checkStudioDependencyVersions.js.map +1 -1
- package/dist/actions/build/createExternalFromImportMap.js +1 -1
- package/dist/actions/build/createExternalFromImportMap.js.map +1 -1
- package/dist/actions/build/determineBasePath.js +5 -2
- package/dist/actions/build/determineBasePath.js.map +1 -1
- package/dist/actions/build/handlePrereleaseVersions.js +44 -0
- package/dist/actions/build/handlePrereleaseVersions.js.map +1 -0
- package/dist/actions/build/types.js.map +1 -1
- package/dist/actions/dataset/create.js +7 -1
- package/dist/actions/dataset/create.js.map +1 -1
- package/dist/actions/dataset/resolveDataset.js +26 -0
- package/dist/actions/dataset/resolveDataset.js.map +1 -0
- package/dist/actions/deploy/deployApp.js +1 -8
- package/dist/actions/deploy/deployApp.js.map +1 -1
- package/dist/actions/deploy/deployStudio.js +1 -0
- package/dist/actions/deploy/deployStudio.js.map +1 -1
- package/dist/actions/dev/getDevServerConfig.js +5 -2
- package/dist/actions/dev/getDevServerConfig.js.map +1 -1
- package/dist/actions/dev/startStudioDevServer.js +8 -3
- package/dist/actions/dev/startStudioDevServer.js.map +1 -1
- package/dist/actions/documents/types.js.map +1 -1
- package/dist/actions/documents/validate.js +11 -2
- package/dist/actions/documents/validate.js.map +1 -1
- package/dist/actions/documents/validateDocuments.worker.js +2 -2
- package/dist/actions/documents/validateDocuments.worker.js.map +1 -1
- package/dist/actions/documents/validation/reporters/jsonReporter.js +1 -1
- package/dist/actions/documents/validation/reporters/jsonReporter.js.map +1 -1
- package/dist/actions/documents/validation/reporters/ndjsonReporter.js +1 -1
- package/dist/actions/documents/validation/reporters/ndjsonReporter.js.map +1 -1
- package/dist/actions/graphql/SchemaError.js +1 -1
- package/dist/actions/graphql/SchemaError.js.map +1 -1
- package/dist/actions/graphql/__tests__/fixtures/many-self-refs.js +540 -0
- package/dist/actions/graphql/__tests__/fixtures/many-self-refs.js.map +1 -0
- package/dist/actions/graphql/__tests__/fixtures/test-studio.js +1143 -0
- package/dist/actions/graphql/__tests__/fixtures/test-studio.js.map +1 -0
- package/dist/actions/graphql/__tests__/fixtures/union-refs.js +591 -0
- package/dist/actions/graphql/__tests__/fixtures/union-refs.js.map +1 -0
- package/dist/actions/graphql/__tests__/helpers.js +23 -0
- package/dist/actions/graphql/__tests__/helpers.js.map +1 -0
- package/dist/actions/graphql/extractFromSanitySchema.js +2 -1
- package/dist/actions/graphql/extractFromSanitySchema.js.map +1 -1
- package/dist/actions/graphql/gen1/generateTypeFilters.js +1 -1
- package/dist/actions/graphql/gen1/generateTypeFilters.js.map +1 -1
- package/dist/actions/graphql/gen1/generateTypeQueries.js +2 -1
- package/dist/actions/graphql/gen1/generateTypeQueries.js.map +1 -1
- package/dist/actions/graphql/gen2/generateTypeQueries.js +1 -1
- package/dist/actions/graphql/gen2/generateTypeQueries.js.map +1 -1
- package/dist/actions/graphql/gen3/generateTypeQueries.js +1 -1
- package/dist/actions/graphql/gen3/generateTypeQueries.js.map +1 -1
- package/dist/actions/graphql/getGraphQLAPIs.js +2 -10
- package/dist/actions/graphql/getGraphQLAPIs.js.map +1 -1
- package/dist/actions/graphql/getGraphQLAPIs.worker.js +1 -1
- package/dist/actions/graphql/getGraphQLAPIs.worker.js.map +1 -1
- package/dist/actions/graphql/types.js.map +1 -1
- package/dist/actions/init/bootstrapLocalTemplate.js +1 -1
- package/dist/actions/init/bootstrapLocalTemplate.js.map +1 -1
- package/dist/actions/manifest/extractAppManifest.js.map +1 -1
- package/dist/actions/manifest/extractManifest.js +3 -22
- package/dist/actions/manifest/extractManifest.js.map +1 -1
- package/dist/actions/manifest/extractManifest.worker.js +5 -1
- package/dist/actions/manifest/extractManifest.worker.js.map +1 -1
- package/dist/actions/manifest/types.js.map +1 -1
- package/dist/actions/schema/deploySchemas.js +57 -80
- package/dist/actions/schema/deploySchemas.js.map +1 -1
- package/dist/actions/schema/extractSanityWorkspace.worker.js +24 -0
- package/dist/actions/schema/extractSanityWorkspace.worker.js.map +1 -0
- package/dist/actions/schema/extractSchemaWatcher.js +1 -1
- package/dist/actions/schema/extractSchemaWatcher.js.map +1 -1
- package/dist/actions/schema/types.js +4 -0
- package/dist/actions/schema/types.js.map +1 -1
- package/dist/actions/schema/uniqueWorkspaces.worker.js +3 -1
- package/dist/actions/schema/uniqueWorkspaces.worker.js.map +1 -1
- package/dist/actions/schema/utils/schemaStoreValidation.js +1 -7
- package/dist/actions/schema/utils/schemaStoreValidation.js.map +1 -1
- package/dist/actions/schema/utils/uniqByProjectIdDataset.js +1 -1
- package/dist/actions/schema/utils/uniqByProjectIdDataset.js.map +1 -1
- package/dist/actions/schema/watchExtractSchema.js +2 -1
- package/dist/actions/schema/watchExtractSchema.js.map +1 -1
- package/dist/actions/versions/getFormatters.js +1 -1
- package/dist/actions/versions/getFormatters.js.map +1 -1
- package/dist/commands/backup/list.js +4 -1
- package/dist/commands/backup/list.js.map +1 -1
- package/dist/commands/dataset/copy.js +3 -1
- package/dist/commands/dataset/copy.js.map +1 -1
- package/dist/commands/dataset/create.js +12 -0
- package/dist/commands/dataset/create.js.map +1 -1
- package/dist/commands/dataset/embeddings/disable.js +62 -0
- package/dist/commands/dataset/embeddings/disable.js.map +1 -0
- package/dist/commands/dataset/embeddings/enable.js +128 -0
- package/dist/commands/dataset/embeddings/enable.js.map +1 -0
- package/dist/commands/dataset/embeddings/status.js +61 -0
- package/dist/commands/dataset/embeddings/status.js.map +1 -0
- package/dist/commands/debug.js +2 -1
- package/dist/commands/debug.js.map +1 -1
- package/dist/commands/documents/create.js +2 -1
- package/dist/commands/documents/create.js.map +1 -1
- package/dist/commands/graphql/deploy.js +1 -1
- package/dist/commands/graphql/deploy.js.map +1 -1
- package/dist/commands/hook/logs.js +1 -1
- package/dist/commands/hook/logs.js.map +1 -1
- package/dist/commands/init.js +13 -7
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/manage.js +0 -1
- package/dist/commands/manage.js.map +1 -1
- package/dist/commands/media/create-aspect.js +1 -1
- package/dist/commands/media/create-aspect.js.map +1 -1
- package/dist/commands/projects/list.js +2 -1
- package/dist/commands/projects/list.js.map +1 -1
- package/dist/commands/schema/deploy.js +11 -27
- package/dist/commands/schema/deploy.js.map +1 -1
- package/dist/commands/users/list.js +1 -1
- package/dist/commands/users/list.js.map +1 -1
- package/dist/commands/versions.js +1 -1
- package/dist/commands/versions.js.map +1 -1
- package/dist/exports/index.d.ts +62 -2
- package/dist/exports/index.js.map +1 -1
- package/dist/prompts/selectMediaLibrary.js +1 -1
- package/dist/prompts/selectMediaLibrary.js.map +1 -1
- package/dist/services/datasets.js +7 -5
- package/dist/services/datasets.js.map +1 -1
- package/dist/services/embeddings.js +25 -0
- package/dist/services/embeddings.js.map +1 -0
- package/dist/services/graphql.js.map +1 -1
- package/dist/services/schemas.js +1 -1
- package/dist/services/schemas.js.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/util/compareDependencyVersions.js +28 -7
- package/dist/util/compareDependencyVersions.js.map +1 -1
- package/dist/util/errorMessages.js +0 -1
- package/dist/util/errorMessages.js.map +1 -1
- package/dist/util/packageManager/getPeerDependencies.js +44 -0
- package/dist/util/packageManager/getPeerDependencies.js.map +1 -0
- package/oclif.manifest.json +325 -191
- package/package.json +19 -20
- package/dist/actions/schema/schemaStoreTypes.js +0 -19
- package/dist/actions/schema/schemaStoreTypes.js.map +0 -1
- package/dist/actions/schema/utils/manifestExtractor.js +0 -29
- package/dist/actions/schema/utils/manifestExtractor.js.map +0 -1
- package/dist/actions/schema/utils/manifestReader.js +0 -71
- package/dist/actions/schema/utils/manifestReader.js.map +0 -1
- package/dist/util/workerChannels.js +0 -172
- package/dist/util/workerChannels.js.map +0 -1
package/dist/SanityHelp.js
CHANGED
|
@@ -1,32 +1,73 @@
|
|
|
1
1
|
import { Help } from '@oclif/core';
|
|
2
|
-
|
|
2
|
+
// Running `oclif readme`, we don't want to apply the `prefixBinName` transformation,
|
|
3
|
+
// as it will include whatever pm was used to spawn the script in the generated readme.
|
|
4
|
+
// argv will contain something like [nodeBinPath, oclifBinPath, 'readme', …] so check
|
|
5
|
+
// for 'readme' with a preceeding argument that includes 'oclif' to be sure.
|
|
6
|
+
const IS_README_GENERATION = (process.argv[process.argv.indexOf('readme') - 1] ?? '').includes('oclif');
|
|
7
|
+
/**
|
|
8
|
+
* Custom Help class for Sanity CLI that overrides the default help formatting to
|
|
9
|
+
* prefix the bin name (e.g., `npx sanity`, `yarn sanity`, etc.) in the help text,
|
|
10
|
+
* and to replace `sanity init` references with the appropriate `create` command
|
|
11
|
+
* for the detected package manager when needed.
|
|
12
|
+
*
|
|
13
|
+
* @internal
|
|
14
|
+
*/ export default class SanityHelp extends Help {
|
|
3
15
|
formatCommand(command) {
|
|
4
|
-
|
|
16
|
+
let help = super.formatCommand(command);
|
|
5
17
|
// When `sanity init` is called, but originates from the `create-sanity`
|
|
6
18
|
// package/binary (eg the one used by `npm create sanity@latest` etc), we want to
|
|
7
|
-
// customize the help text to show that command instead of `sanity init`.
|
|
8
|
-
// future we may also want to consider prefixing with `npx` etc for non-init
|
|
9
|
-
// commands - but leaving that for another day.
|
|
19
|
+
// customize the help text to show that command instead of `sanity init`.
|
|
10
20
|
const isFromCreate = process.argv.includes('--from-create') && command.id === 'init';
|
|
11
|
-
if (
|
|
12
|
-
|
|
21
|
+
if (isFromCreate) {
|
|
22
|
+
help = replaceInitWithCreateCommand(help);
|
|
13
23
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return help.replaceAll(/(\s+)sanity(\s+)init(\s*)\n/g, `$1${createCmd}$2\n`).replaceAll(/(\s+)sanity(\s+)init/g, `$1${createCmd}${flagSeparator}`);
|
|
24
|
+
return prefixBinName(help);
|
|
25
|
+
}
|
|
26
|
+
formatRoot() {
|
|
27
|
+
return prefixBinName(super.formatRoot());
|
|
28
|
+
}
|
|
29
|
+
formatTopic(topic) {
|
|
30
|
+
return prefixBinName(super.formatTopic(topic));
|
|
22
31
|
}
|
|
23
32
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (
|
|
29
|
-
if (
|
|
33
|
+
/**
|
|
34
|
+
* @internal
|
|
35
|
+
*/ export function guessBinCommand() {
|
|
36
|
+
const pm = guessPackageManager();
|
|
37
|
+
if (pm === 'npm') return 'npx sanity';
|
|
38
|
+
if (pm === 'pnpm') return 'pnpm exec sanity';
|
|
39
|
+
if (pm === 'bun') return 'bunx sanity';
|
|
40
|
+
if (pm === 'yarn') {
|
|
41
|
+
const major = guessYarnMajorVersion();
|
|
42
|
+
if (major !== undefined && major >= 2) return 'yarn run sanity';
|
|
43
|
+
return 'yarn sanity';
|
|
44
|
+
}
|
|
45
|
+
return 'sanity';
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* @internal
|
|
49
|
+
*/ export function prefixBinName(help) {
|
|
50
|
+
if (IS_README_GENERATION) return help;
|
|
51
|
+
const binCommand = guessBinCommand();
|
|
52
|
+
if (binCommand === 'sanity') return help;
|
|
53
|
+
return help.replaceAll('$ sanity', `$ ${binCommand}`);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Replace `sanity init` references in help text with the equivalent `create` command
|
|
57
|
+
* for the detected package manager. Lines ending in just `sanity init\n` (no flags)
|
|
58
|
+
* are replaced without a flag separator, while lines with flags get the separator
|
|
59
|
+
* (eg `--` for npm) so the flags are forwarded correctly.
|
|
60
|
+
*
|
|
61
|
+
* @internal
|
|
62
|
+
*/ export function replaceInitWithCreateCommand(help) {
|
|
63
|
+
const createCmd = guessCreateCommand();
|
|
64
|
+
const flagSeparator = needsFlagSeparator() ? ' --' : '';
|
|
65
|
+
// First replace all `sanity init` references that ends with a newline with the
|
|
66
|
+
// create variant that does not include any flag separator (eg `--`). Then replace
|
|
67
|
+
// the other references that do. Most package managers do not require the `--`
|
|
68
|
+
// separator, but npm does. Only include it if we need to, as the commands look
|
|
69
|
+
// cleaner without it.
|
|
70
|
+
return help.replaceAll(/(\s+)sanity\s+init\s*\n/g, `$1${createCmd}\n`).replaceAll(/(\s+)sanity(\s+)init/g, `$1${createCmd}${flagSeparator}`);
|
|
30
71
|
}
|
|
31
72
|
function guessCreateCommand() {
|
|
32
73
|
const pm = guessPackageManager();
|
|
@@ -39,5 +80,17 @@ function needsFlagSeparator() {
|
|
|
39
80
|
const pm = guessPackageManager();
|
|
40
81
|
return pm === 'npm' || !pm;
|
|
41
82
|
}
|
|
83
|
+
function guessPackageManager() {
|
|
84
|
+
const ua = process.env.npm_config_user_agent || '';
|
|
85
|
+
if (ua.includes('pnpm')) return 'pnpm';
|
|
86
|
+
if (ua.includes('yarn')) return 'yarn';
|
|
87
|
+
if (ua.includes('bun')) return 'bun';
|
|
88
|
+
if (ua.includes('npm')) return 'npm';
|
|
89
|
+
}
|
|
90
|
+
function guessYarnMajorVersion() {
|
|
91
|
+
const ua = process.env.npm_config_user_agent || '';
|
|
92
|
+
const match = ua.match(/yarn\/(\d+)/);
|
|
93
|
+
return match ? Number.parseInt(match[1], 10) : undefined;
|
|
94
|
+
}
|
|
42
95
|
|
|
43
96
|
//# sourceMappingURL=SanityHelp.js.map
|
package/dist/SanityHelp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/SanityHelp.ts"],"sourcesContent":["import {Command, Help} from '@oclif/core'\n\nexport default class SanityHelp extends Help {\n protected formatCommand(command: Command.Loadable): string {\n
|
|
1
|
+
{"version":3,"sources":["../src/SanityHelp.ts"],"sourcesContent":["import {Command, Help, Interfaces} from '@oclif/core'\n\n// Running `oclif readme`, we don't want to apply the `prefixBinName` transformation,\n// as it will include whatever pm was used to spawn the script in the generated readme.\n// argv will contain something like [nodeBinPath, oclifBinPath, 'readme', …] so check\n// for 'readme' with a preceeding argument that includes 'oclif' to be sure.\nconst IS_README_GENERATION = (process.argv[process.argv.indexOf('readme') - 1] ?? '').includes(\n 'oclif',\n)\n\n/**\n * Custom Help class for Sanity CLI that overrides the default help formatting to\n * prefix the bin name (e.g., `npx sanity`, `yarn sanity`, etc.) in the help text,\n * and to replace `sanity init` references with the appropriate `create` command\n * for the detected package manager when needed.\n *\n * @internal\n */\nexport default class SanityHelp extends Help {\n protected formatCommand(command: Command.Loadable): string {\n let help = super.formatCommand(command)\n\n // When `sanity init` is called, but originates from the `create-sanity`\n // package/binary (eg the one used by `npm create sanity@latest` etc), we want to\n // customize the help text to show that command instead of `sanity init`.\n const isFromCreate = process.argv.includes('--from-create') && command.id === 'init'\n if (isFromCreate) {\n help = replaceInitWithCreateCommand(help)\n }\n\n return prefixBinName(help)\n }\n\n protected formatRoot(): string {\n return prefixBinName(super.formatRoot())\n }\n\n protected formatTopic(topic: Interfaces.Topic): string {\n return prefixBinName(super.formatTopic(topic))\n }\n}\n\n/**\n * @internal\n */\nexport function guessBinCommand(): string {\n const pm = guessPackageManager()\n if (pm === 'npm') return 'npx sanity'\n if (pm === 'pnpm') return 'pnpm exec sanity'\n if (pm === 'bun') return 'bunx sanity'\n if (pm === 'yarn') {\n const major = guessYarnMajorVersion()\n if (major !== undefined && major >= 2) return 'yarn run sanity'\n return 'yarn sanity'\n }\n return 'sanity'\n}\n\n/**\n * @internal\n */\nexport function prefixBinName(help: string): string {\n if (IS_README_GENERATION) return help\n const binCommand = guessBinCommand()\n if (binCommand === 'sanity') return help\n return help.replaceAll('$ sanity', `$ ${binCommand}`)\n}\n\n/**\n * Replace `sanity init` references in help text with the equivalent `create` command\n * for the detected package manager. Lines ending in just `sanity init\\n` (no flags)\n * are replaced without a flag separator, while lines with flags get the separator\n * (eg `--` for npm) so the flags are forwarded correctly.\n *\n * @internal\n */\nexport function replaceInitWithCreateCommand(help: string): string {\n const createCmd = guessCreateCommand()\n const flagSeparator = needsFlagSeparator() ? ' --' : ''\n\n // First replace all `sanity init` references that ends with a newline with the\n // create variant that does not include any flag separator (eg `--`). Then replace\n // the other references that do. Most package managers do not require the `--`\n // separator, but npm does. Only include it if we need to, as the commands look\n // cleaner without it.\n return help\n .replaceAll(/(\\s+)sanity\\s+init\\s*\\n/g, `$1${createCmd}\\n`)\n .replaceAll(/(\\s+)sanity(\\s+)init/g, `$1${createCmd}${flagSeparator}`)\n}\n\nfunction guessCreateCommand() {\n const pm = guessPackageManager()\n if (pm === 'yarn') return `yarn create sanity`\n if (pm === 'bun') return `bun create sanity@latest`\n if (pm === 'pnpm') return `pnpm create sanity@latest`\n return `npm create sanity@latest`\n}\n\nfunction needsFlagSeparator() {\n const pm = guessPackageManager()\n return pm === 'npm' || !pm\n}\n\nfunction guessPackageManager() {\n const ua = process.env.npm_config_user_agent || ''\n if (ua.includes('pnpm')) return 'pnpm'\n if (ua.includes('yarn')) return 'yarn'\n if (ua.includes('bun')) return 'bun'\n if (ua.includes('npm')) return 'npm'\n}\n\nfunction guessYarnMajorVersion(): number | undefined {\n const ua = process.env.npm_config_user_agent || ''\n const match = ua.match(/yarn\\/(\\d+)/)\n return match ? Number.parseInt(match[1], 10) : undefined\n}\n"],"names":["Help","IS_README_GENERATION","process","argv","indexOf","includes","SanityHelp","formatCommand","command","help","isFromCreate","id","replaceInitWithCreateCommand","prefixBinName","formatRoot","formatTopic","topic","guessBinCommand","pm","guessPackageManager","major","guessYarnMajorVersion","undefined","binCommand","replaceAll","createCmd","guessCreateCommand","flagSeparator","needsFlagSeparator","ua","env","npm_config_user_agent","match","Number","parse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gBAAgBC,uBAAuB,QAAQ;IAErD,+EAA+E;IAC/E,kFAAkF;IAClF,8EAA8E;IAC9E,+EAA+E;IAC/E,sBAAsB;IACtB,OAAOnB,KACJe,UAAU,CAAC,4BAA4B,CAAC,EAAE,EAAEC,UAAU,EAAE,CAAC,EACzDD,UAAU,CAAC,yBAAyB,CAAC,EAAE,EAAEC,YAAYE,eAAe;AACzE;AAEA,SAASD;IACP,MAAMR,KAAKC;IACX,IAAID,OAAO,QAAQ,OAAO,CAAC,kBAAkB,CAAC;IAC9C,IAAIA,OAAO,OAAO,OAAO,CAAC,wBAAwB,CAAC;IACnD,IAAIA,OAAO,QAAQ,OAAO,CAAC,yBAAyB,CAAC;IACrD,OAAO,CAAC,wBAAwB,CAAC;AACnC;AAEA,SAASU;IACP,MAAMV,KAAKC;IACX,OAAOD,OAAO,SAAS,CAACA;AAC1B;AAEA,SAASC;IACP,MAAMU,KAAK3B,QAAQ4B,GAAG,CAACC,qBAAqB,IAAI;IAChD,IAAIF,GAAGxB,QAAQ,CAAC,SAAS,OAAO;IAChC,IAAIwB,GAAGxB,QAAQ,CAAC,SAAS,OAAO;IAChC,IAAIwB,GAAGxB,QAAQ,CAAC,QAAQ,OAAO;IAC/B,IAAIwB,GAAGxB,QAAQ,CAAC,QAAQ,OAAO;AACjC;AAEA,SAASgB;IACP,MAAMQ,KAAK3B,QAAQ4B,GAAG,CAACC,qBAAqB,IAAI;IAChD,MAAMC,QAAQH,GAAGG,KAAK,CAAC;IACvB,OAAOA,QAAQC,OAAOC,QAAQ,CAACF,KAAK,CAAC,EAAE,EAAE,MAAMV;AACjD"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { rm } from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { styleText } from 'node:util';
|
|
4
|
-
import { getCliTelemetry, getTimer } from '@sanity/cli-core';
|
|
4
|
+
import { getCliTelemetry, getTimer, isInteractive } from '@sanity/cli-core';
|
|
5
5
|
import { confirm, logSymbols, spinner } from '@sanity/cli-core/ux';
|
|
6
6
|
import semver from 'semver';
|
|
7
7
|
import { AppBuildTrace } from '../../telemetry/build.telemetry.js';
|
|
@@ -9,18 +9,21 @@ import { getAppId } from '../../util/appId.js';
|
|
|
9
9
|
import { compareDependencyVersions } from '../../util/compareDependencyVersions.js';
|
|
10
10
|
import { getLocalPackageVersion } from '../../util/getLocalPackageVersion.js';
|
|
11
11
|
import { formatModuleSizes, sortModulesBySize } from '../../util/moduleFormatUtils.js';
|
|
12
|
+
import { warnAboutMissingAppId } from '../../util/warnAboutMissingAppId.js';
|
|
12
13
|
import { buildDebug } from './buildDebug.js';
|
|
13
14
|
import { buildStaticFiles } from './buildStaticFiles.js';
|
|
14
15
|
import { buildVendorDependencies } from './buildVendorDependencies.js';
|
|
15
16
|
import { determineBasePath } from './determineBasePath.js';
|
|
16
17
|
import { getAppEnvVars } from './getAppEnvVars.js';
|
|
17
18
|
import { getAutoUpdatesImportMap } from './getAutoUpdatesImportMap.js';
|
|
19
|
+
import { handlePrereleaseVersions } from './handlePrereleaseVersions.js';
|
|
18
20
|
/**
|
|
19
21
|
* Build the Sanity app.
|
|
20
22
|
*
|
|
21
23
|
* @internal
|
|
22
24
|
*/ export async function buildApp(options) {
|
|
23
|
-
const {
|
|
25
|
+
const { cliConfig, flags, outDir, output, workDir } = options;
|
|
26
|
+
let { autoUpdatesEnabled } = options;
|
|
24
27
|
const unattendedMode = flags.yes;
|
|
25
28
|
const timer = getTimer();
|
|
26
29
|
const defaultOutputDir = path.resolve(path.join(workDir, 'dist'));
|
|
@@ -66,21 +69,45 @@ import { getAutoUpdatesImportMap } from './getAutoUpdatesImportMap.js';
|
|
|
66
69
|
appId
|
|
67
70
|
});
|
|
68
71
|
output.log(`${logSymbols.info} Building with auto-updates enabled`);
|
|
72
|
+
// Warn if auto updates enabled but no appId configured.
|
|
73
|
+
// Skip when called from deploy, since deploy handles appId itself
|
|
74
|
+
// (prompts the user and tells them to add it to config).
|
|
75
|
+
if (!appId && !options.calledFromDeploy) {
|
|
76
|
+
warnAboutMissingAppId({
|
|
77
|
+
appType: 'app',
|
|
78
|
+
output
|
|
79
|
+
});
|
|
80
|
+
}
|
|
69
81
|
// Check the versions
|
|
70
|
-
const
|
|
82
|
+
const { mismatched, unresolvedPrerelease } = await compareDependencyVersions(autoUpdatedPackages, workDir, {
|
|
71
83
|
appId
|
|
72
84
|
});
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
85
|
+
if (unresolvedPrerelease.length > 0) {
|
|
86
|
+
await handlePrereleaseVersions({
|
|
87
|
+
output,
|
|
88
|
+
unattendedMode,
|
|
89
|
+
unresolvedPrerelease
|
|
78
90
|
});
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
91
|
+
autoUpdatesImports = {};
|
|
92
|
+
autoUpdatesEnabled = false;
|
|
93
|
+
}
|
|
94
|
+
if (mismatched.length > 0 && autoUpdatesEnabled) {
|
|
95
|
+
const versionMismatchWarning = `The following local package versions are different from the versions currently served at runtime.\n` + `When using auto updates, we recommend that you test locally with the same versions before deploying. \n\n` + `${mismatched.map((mod)=>` - ${mod.pkg} (local version: ${mod.installed}, runtime version: ${mod.remote})`).join('\n')}`;
|
|
96
|
+
// If it is non-interactive or in unattended mode, we don't want to prompt
|
|
97
|
+
if (isInteractive() && !unattendedMode) {
|
|
98
|
+
const shouldContinue = await confirm({
|
|
99
|
+
default: false,
|
|
100
|
+
message: styleText('yellow', `${versionMismatchWarning} \n\nContinue anyway?`)
|
|
82
101
|
});
|
|
83
|
-
|
|
102
|
+
if (!shouldContinue) {
|
|
103
|
+
output.error('Declined to continue with build', {
|
|
104
|
+
exit: 1
|
|
105
|
+
});
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
} else {
|
|
109
|
+
// if non-interactive or unattended, just show the warning
|
|
110
|
+
output.warn(versionMismatchWarning);
|
|
84
111
|
}
|
|
85
112
|
}
|
|
86
113
|
}
|
|
@@ -91,14 +118,14 @@ import { getAutoUpdatesImportMap } from './getAutoUpdatesImportMap.js';
|
|
|
91
118
|
output.log('');
|
|
92
119
|
}
|
|
93
120
|
let shouldClean = true;
|
|
94
|
-
if (outputDir !== defaultOutputDir && !unattendedMode) {
|
|
121
|
+
if (outputDir !== defaultOutputDir && !unattendedMode && isInteractive()) {
|
|
95
122
|
shouldClean = await confirm({
|
|
96
123
|
default: true,
|
|
97
124
|
message: `Do you want to delete the existing directory (${outputDir}) first?`
|
|
98
125
|
});
|
|
99
126
|
}
|
|
100
|
-
// Determine base path for built
|
|
101
|
-
const basePath = determineBasePath(cliConfig, 'app');
|
|
127
|
+
// Determine base path for built app
|
|
128
|
+
const basePath = determineBasePath(cliConfig, 'app', output);
|
|
102
129
|
let spin;
|
|
103
130
|
if (shouldClean) {
|
|
104
131
|
timer.start('cleanOutputFolder');
|
|
@@ -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 {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,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gBAAgBjE,MAAMsC,GAAG,CAAC;QAEhCL,KAAKM,IAAI,GAAG,CAAC,0BAA0B,EAAE0B,cAAczB,OAAO,CAAC,GAAG,GAAG,CAAC;QACtEP,KAAKQ,OAAO;QAEZ,IAAI/C,MAAMwE,KAAK,EAAE;YACftE,OAAOqB,GAAG,CAAC;YACXrB,OAAOqB,GAAG,CAACnC,kBAAkBC,kBAAkBgE,OAAOU,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
|
+
{"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, isInteractive} 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 {warnAboutMissingAppId} from '../../util/warnAboutMissingAppId.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 {handlePrereleaseVersions} from './handlePrereleaseVersions.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 {cliConfig, flags, outDir, output, workDir} = options\n let {autoUpdatesEnabled} = 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 // Warn if auto updates enabled but no appId configured.\n // Skip when called from deploy, since deploy handles appId itself\n // (prompts the user and tells them to add it to config).\n if (!appId && !options.calledFromDeploy) {\n warnAboutMissingAppId({appType: 'app', output})\n }\n\n // Check the versions\n const {mismatched, unresolvedPrerelease} = await compareDependencyVersions(\n autoUpdatedPackages,\n workDir,\n {appId},\n )\n\n if (unresolvedPrerelease.length > 0) {\n await handlePrereleaseVersions({output, unattendedMode, unresolvedPrerelease})\n autoUpdatesImports = {}\n autoUpdatesEnabled = false\n }\n\n if (mismatched.length > 0 && autoUpdatesEnabled) {\n const versionMismatchWarning =\n `The following local package versions are different from the versions currently served at runtime.\\n` +\n `When using auto updates, we recommend that you test locally with the same versions before deploying. \\n\\n` +\n `${mismatched.map((mod) => ` - ${mod.pkg} (local version: ${mod.installed}, runtime version: ${mod.remote})`).join('\\n')}`\n\n // If it is non-interactive or in unattended mode, we don't want to prompt\n if (isInteractive() && !unattendedMode) {\n const shouldContinue = await confirm({\n default: false,\n message: styleText('yellow', `${versionMismatchWarning} \\n\\nContinue anyway?`),\n })\n\n if (!shouldContinue) {\n output.error('Declined to continue with build', {exit: 1})\n return\n }\n } else {\n // if non-interactive or unattended, just show the warning\n output.warn(versionMismatchWarning)\n }\n }\n }\n\n const envVarKeys = 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 && isInteractive()) {\n shouldClean = await confirm({\n default: true,\n message: `Do you want to delete the existing directory (${outputDir}) first?`,\n })\n }\n\n // Determine base path for built app\n const basePath = determineBasePath(cliConfig, 'app', output)\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","isInteractive","confirm","logSymbols","spinner","semver","AppBuildTrace","getAppId","compareDependencyVersions","getLocalPackageVersion","formatModuleSizes","sortModulesBySize","warnAboutMissingAppId","buildDebug","buildStaticFiles","buildVendorDependencies","determineBasePath","getAppEnvVars","getAutoUpdatesImportMap","handlePrereleaseVersions","buildApp","options","cliConfig","flags","outDir","output","workDir","autoUpdatesEnabled","unattendedMode","yes","timer","defaultOutputDir","resolve","join","outputDir","appId","installedSdkVersion","installedSanityVersion","error","exit","autoUpdatesImports","cleanSDKVersion","parse","version","cleanSanityVersion","autoUpdatedPackages","name","log","info","calledFromDeploy","appType","mismatched","unresolvedPrerelease","length","versionMismatchWarning","map","mod","pkg","installed","remote","shouldContinue","default","message","warn","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,EAAEC,aAAa,QAAO,mBAAkB;AACzE,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,qBAAqB,QAAO,sCAAqC;AACzE,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;AACpE,SAAQC,wBAAwB,QAAO,gCAA+B;AAGtE;;;;CAIC,GACD,OAAO,eAAeC,SAASC,OAAqB;IAClD,MAAM,EAACC,SAAS,EAAEC,KAAK,EAAEC,MAAM,EAAEC,MAAM,EAAEC,OAAO,EAAC,GAAGL;IACpD,IAAI,EAACM,kBAAkB,EAAC,GAAGN;IAC3B,MAAMO,iBAAiBL,MAAMM,GAAG;IAChC,MAAMC,QAAQ9B;IAEd,MAAM+B,mBAAmBlC,KAAKmC,OAAO,CAACnC,KAAKoC,IAAI,CAACP,SAAS;IACzD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GAAG,CAAC;QAEhCL,KAAKM,IAAI,GAAG,CAAC,0BAA0B,EAAE0B,cAAczB,OAAO,CAAC,GAAG,GAAG,CAAC;QACtEP,KAAKQ,OAAO;QAEZ,IAAIrD,MAAM8E,KAAK,EAAE;YACf5E,OAAOsB,GAAG,CAAC;YACXtB,OAAOsB,GAAG,CAACrC,kBAAkBC,kBAAkBuE,OAAOU,MAAM,EAAEU,KAAK,CAAC,GAAG;QACzE;QAEAzB,MAAM0B,QAAQ;IAChB,EAAE,OAAOjE,OAAO;QACd8B,KAAKoC,IAAI;QACT3B,MAAMvC,KAAK,CAACA;QACZ,MAAMwB,UAAUxB,iBAAiBmE,QAAQnE,MAAMwB,OAAO,GAAG4C,OAAOpE;QAChEzB,WAAW,CAAC,kCAAkC,CAAC,EAAE;YAACyB;QAAK;QACvDb,OAAOa,KAAK,CAAC,CAAC,oCAAoC,EAAEwB,SAAS,EAAE;YAACvB,MAAM;QAAC;IACzE;AACF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { rm } from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { styleText } from 'node:util';
|
|
4
|
-
import { getCliTelemetry, getTimer } from '@sanity/cli-core';
|
|
4
|
+
import { getCliTelemetry, getTimer, isInteractive } from '@sanity/cli-core';
|
|
5
5
|
import { confirm, logSymbols, select, spinner } from '@sanity/cli-core/ux';
|
|
6
6
|
import semver from 'semver';
|
|
7
7
|
import { StudioBuildTrace } from '../../telemetry/build.telemetry.js';
|
|
@@ -19,6 +19,7 @@ import { checkStudioDependencyVersions } from './checkStudioDependencyVersions.j
|
|
|
19
19
|
import { determineBasePath } from './determineBasePath.js';
|
|
20
20
|
import { getAutoUpdatesImportMap } from './getAutoUpdatesImportMap.js';
|
|
21
21
|
import { getStudioEnvVars } from './getStudioEnvVars.js';
|
|
22
|
+
import { handlePrereleaseVersions } from './handlePrereleaseVersions.js';
|
|
22
23
|
import { shouldAutoUpdate } from './shouldAutoUpdate.js';
|
|
23
24
|
/**
|
|
24
25
|
* Build the Sanity Studio.
|
|
@@ -38,7 +39,7 @@ import { shouldAutoUpdate } from './shouldAutoUpdate.js';
|
|
|
38
39
|
output,
|
|
39
40
|
workDir
|
|
40
41
|
});
|
|
41
|
-
|
|
42
|
+
let autoUpdatesEnabled = shouldAutoUpdate({
|
|
42
43
|
cliConfig,
|
|
43
44
|
flags,
|
|
44
45
|
output
|
|
@@ -53,8 +54,10 @@ import { shouldAutoUpdate } from './shouldAutoUpdate.js';
|
|
|
53
54
|
output.log(`${logSymbols.info} Building with auto-updates enabled`);
|
|
54
55
|
const projectId = cliConfig?.api?.projectId;
|
|
55
56
|
const appId = getAppId(cliConfig);
|
|
56
|
-
// Warn if auto updates enabled but no appId configured
|
|
57
|
-
|
|
57
|
+
// Warn if auto updates enabled but no appId configured.
|
|
58
|
+
// Skip when called from deploy, since deploy handles appId itself
|
|
59
|
+
// (prompts the user and tells them to add it to config).
|
|
60
|
+
if (!appId && !options.calledFromDeploy) {
|
|
58
61
|
warnAboutMissingAppId({
|
|
59
62
|
appType: 'studio',
|
|
60
63
|
output,
|
|
@@ -75,54 +78,70 @@ import { shouldAutoUpdate } from './shouldAutoUpdate.js';
|
|
|
75
78
|
appId
|
|
76
79
|
});
|
|
77
80
|
// Check the versions
|
|
78
|
-
const
|
|
81
|
+
const { mismatched, unresolvedPrerelease } = await compareDependencyVersions(sanityDependencies, workDir, {
|
|
79
82
|
appId
|
|
80
83
|
});
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
name: `Upgrade and proceed with build`,
|
|
87
|
-
value: 'upgrade-and-proceed'
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
name: `Upgrade only. You will need to run the build command again`,
|
|
91
|
-
value: 'upgrade'
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
name: 'Cancel',
|
|
95
|
-
value: 'cancel'
|
|
96
|
-
}
|
|
97
|
-
],
|
|
98
|
-
default: 'upgrade-and-proceed',
|
|
99
|
-
message: styleText('yellow', `The following local package versions are different from the versions currently served at runtime.\n` + `When using auto updates, we recommend that you test locally with the same versions before deploying. \n\n` + `${result.map((mod)=>` - ${mod.pkg} (local version: ${mod.installed}, runtime version: ${mod.remote})`).join('\n')} \n\n` + `Do you want to upgrade local versions before deploying?`)
|
|
84
|
+
if (unresolvedPrerelease.length > 0) {
|
|
85
|
+
await handlePrereleaseVersions({
|
|
86
|
+
output,
|
|
87
|
+
unattendedMode,
|
|
88
|
+
unresolvedPrerelease
|
|
100
89
|
});
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (
|
|
108
|
-
await
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
90
|
+
autoUpdatesImports = {};
|
|
91
|
+
autoUpdatesEnabled = false;
|
|
92
|
+
}
|
|
93
|
+
if (mismatched.length > 0 && autoUpdatesEnabled) {
|
|
94
|
+
const versionMismatchWarning = `The following local package versions are different from the versions currently served at runtime.\n` + `When using auto updates, we recommend that you test locally with the same versions before deploying. \n\n` + `${mismatched.map((mod)=>` - ${mod.pkg} (local version: ${mod.installed}, runtime version: ${mod.remote})`).join('\n')}`;
|
|
95
|
+
// If it is non-interactive or in unattended mode, we don't want to prompt
|
|
96
|
+
if (isInteractive() && !unattendedMode) {
|
|
97
|
+
const choice = await select({
|
|
98
|
+
choices: [
|
|
99
|
+
{
|
|
100
|
+
name: `Upgrade local versions (recommended). You will need to run the build command again`,
|
|
101
|
+
value: 'upgrade'
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
name: `Upgrade and proceed with build`,
|
|
105
|
+
value: 'upgrade-and-proceed'
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
name: `Continue anyway`,
|
|
109
|
+
value: 'continue'
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
name: 'Cancel',
|
|
113
|
+
value: 'cancel'
|
|
114
|
+
}
|
|
115
|
+
],
|
|
116
|
+
default: 'upgrade',
|
|
117
|
+
message: styleText('yellow', `${logSymbols.warning} ${versionMismatchWarning}\n\nDo you want to upgrade local versions before deploying?`)
|
|
119
118
|
});
|
|
120
|
-
if (choice
|
|
119
|
+
if (choice === 'cancel') {
|
|
121
120
|
output.error('Declined to continue with build', {
|
|
122
121
|
exit: 1
|
|
123
122
|
});
|
|
124
123
|
return;
|
|
125
124
|
}
|
|
125
|
+
if (choice === 'upgrade' || choice === 'upgrade-and-proceed') {
|
|
126
|
+
await upgradePackages({
|
|
127
|
+
packageManager: (await getPackageManagerChoice(workDir, {
|
|
128
|
+
interactive: false
|
|
129
|
+
})).chosen,
|
|
130
|
+
packages: mismatched.map((res)=>[
|
|
131
|
+
res.pkg,
|
|
132
|
+
res.remote
|
|
133
|
+
])
|
|
134
|
+
}, {
|
|
135
|
+
output,
|
|
136
|
+
workDir
|
|
137
|
+
});
|
|
138
|
+
if (choice === 'upgrade') {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
} else {
|
|
143
|
+
// if non-interactive or unattended, just show the warning
|
|
144
|
+
output.warn(versionMismatchWarning);
|
|
126
145
|
}
|
|
127
146
|
}
|
|
128
147
|
}
|
|
@@ -135,14 +154,14 @@ import { shouldAutoUpdate } from './shouldAutoUpdate.js';
|
|
|
135
154
|
output.log('');
|
|
136
155
|
}
|
|
137
156
|
let shouldClean = true;
|
|
138
|
-
if (outputDir !== defaultOutputDir && !unattendedMode) {
|
|
157
|
+
if (outputDir !== defaultOutputDir && !unattendedMode && isInteractive()) {
|
|
139
158
|
shouldClean = await confirm({
|
|
140
159
|
default: true,
|
|
141
160
|
message: `Do you want to delete the existing directory (${outputDir}) first?`
|
|
142
161
|
});
|
|
143
162
|
}
|
|
144
163
|
// Determine base path for built studio
|
|
145
|
-
const basePath = determineBasePath(cliConfig, 'studio');
|
|
164
|
+
const basePath = determineBasePath(cliConfig, 'studio', output);
|
|
146
165
|
let spin;
|
|
147
166
|
if (shouldClean) {
|
|
148
167
|
timer.start('cleanOutputFolder');
|
|
@@ -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, {appId})\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;AAEnC,SAAQC,eAAe,EAAEC,QAAQ,QAAO,mBAAkB;AAC1D,SAAQC,OAAO,EAAEC,UAAU,EAAEC,MAAM,EAAEC,OAAO,QAA6B,sBAAqB;AAC9F,OAAOC,YAAY,SAAQ;AAE3B,SAAQC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;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
|
+
{"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, isInteractive} 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 {handlePrereleaseVersions} from './handlePrereleaseVersions.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 let 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 // Skip when called from deploy, since deploy handles appId itself\n // (prompts the user and tells them to add it to config).\n if (!appId && !options.calledFromDeploy) {\n warnAboutMissingAppId({appType: '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 {mismatched, unresolvedPrerelease} = await compareDependencyVersions(\n sanityDependencies,\n workDir,\n {appId},\n )\n\n if (unresolvedPrerelease.length > 0) {\n await handlePrereleaseVersions({output, unattendedMode, unresolvedPrerelease})\n autoUpdatesImports = {}\n autoUpdatesEnabled = false\n }\n\n if (mismatched.length > 0 && autoUpdatesEnabled) {\n const versionMismatchWarning =\n `The following local package versions are different from the versions currently served at runtime.\\n` +\n `When using auto updates, we recommend that you test locally with the same versions before deploying. \\n\\n` +\n `${mismatched.map((mod) => ` - ${mod.pkg} (local version: ${mod.installed}, runtime version: ${mod.remote})`).join('\\n')}`\n\n // If it is non-interactive or in unattended mode, we don't want to prompt\n if (isInteractive() && !unattendedMode) {\n const choice = await select({\n choices: [\n {\n name: `Upgrade local versions (recommended). You will need to run the build command again`,\n value: 'upgrade',\n },\n {\n name: `Upgrade and proceed with build`,\n value: 'upgrade-and-proceed',\n },\n {\n name: `Continue anyway`,\n value: 'continue',\n },\n {name: 'Cancel', value: 'cancel'},\n ],\n default: 'upgrade',\n message: styleText(\n 'yellow',\n `${logSymbols.warning} ${versionMismatchWarning}\\n\\nDo you want to upgrade local versions before deploying?`,\n ),\n })\n\n if (choice === 'cancel') {\n output.error('Declined to continue with build', {exit: 1})\n return\n }\n\n if (choice === 'upgrade' || choice === 'upgrade-and-proceed') {\n await upgradePackages(\n {\n packageManager: (await getPackageManagerChoice(workDir, {interactive: false})).chosen,\n packages: mismatched.map((res) => [res.pkg, res.remote]),\n },\n {output, workDir},\n )\n\n if (choice === 'upgrade') {\n return\n }\n }\n } else {\n // if non-interactive or unattended, just show the warning\n output.warn(versionMismatchWarning)\n }\n }\n }\n\n const envVarKeys = 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 && isInteractive()) {\n shouldClean = await confirm({\n default: true,\n message: `Do you want to delete the existing directory (${outputDir}) first?`,\n })\n }\n\n // Determine base path for built studio\n const basePath = determineBasePath(cliConfig, 'studio', output)\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","isInteractive","confirm","logSymbols","select","spinner","semver","StudioBuildTrace","getAppId","compareDependencyVersions","formatModuleSizes","sortModulesBySize","getPackageManagerChoice","upgradePackages","warnAboutMissingAppId","buildDebug","buildStaticFiles","buildVendorDependencies","checkRequiredDependencies","checkStudioDependencyVersions","determineBasePath","getAutoUpdatesImportMap","getStudioEnvVars","handlePrereleaseVersions","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","calledFromDeploy","appType","sanityDependencies","name","mismatched","unresolvedPrerelease","length","versionMismatchWarning","map","mod","pkg","installed","remote","choice","choices","value","default","message","warning","error","exit","packageManager","interactive","chosen","packages","res","warn","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;AAEnC,SAAQC,eAAe,EAAEC,QAAQ,EAAEC,aAAa,QAAO,mBAAkB;AACzE,SAAQC,OAAO,EAAEC,UAAU,EAAEC,MAAM,EAAEC,OAAO,QAA6B,sBAAqB;AAC9F,OAAOC,YAAY,SAAQ;AAE3B,SAAQC,gBAAgB,QAAO,qCAAoC;AACnE,SAAQC,QAAQ,QAAO,sBAAqB;AAC5C,SAAQC,yBAAyB,QAAO,0CAAyC;AACjF,SAAQC,iBAAiB,EAAEC,iBAAiB,QAAO,kCAAiC;AACpF,SAAQC,uBAAuB,QAAO,oDAAmD;AACzF,SAAQC,eAAe,QAAO,+CAA8C;AAC5E,SAAQC,qBAAqB,QAAO,sCAAqC;AACzE,SAAQC,UAAU,QAAO,kBAAiB;AAC1C,SAAQC,gBAAgB,QAAO,wBAAuB;AACtD,SAAQC,uBAAuB,QAAO,+BAA8B;AACpE,SAAQC,yBAAyB,QAAO,iCAAgC;AACxE,SAAQC,6BAA6B,QAAO,qCAAoC;AAChF,SAAQC,iBAAiB,QAAO,yBAAwB;AACxD,SAAQC,uBAAuB,QAAO,+BAA8B;AACpE,SAAQC,gBAAgB,QAAO,wBAAuB;AACtD,SAAQC,wBAAwB,QAAO,gCAA+B;AACtE,SAAQC,gBAAgB,QAAO,wBAAuB;AAGtD;;;;CAIC,GACD,OAAO,eAAeC,YAAYC,OAAqB;IACrD,MAAMC,QAAQ3B;IACd,MAAM,EAAC4B,SAAS,E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IR = 'vendor';
|
|
|
8
8
|
// Define the vendor packages and their corresponding versions and entry points
|
|
9
9
|
const VENDOR_IMPORTS = {
|
|
10
10
|
react: {
|
|
11
|
-
'^
|
|
12
|
-
'.': './cjs/react.production.min.js',
|
|
13
|
-
'./jsx-dev-runtime': './cjs/react-jsx-dev-runtime.production.min.js',
|
|
14
|
-
'./jsx-runtime': './cjs/react-jsx-runtime.production.min.js',
|
|
15
|
-
'./package.json': './package.json'
|
|
16
|
-
},
|
|
17
|
-
'^19.0.0': {
|
|
11
|
+
'^19.2.0': {
|
|
18
12
|
'.': './cjs/react.production.js',
|
|
19
13
|
'./compiler-runtime': './cjs/react-compiler-runtime.production.js',
|
|
20
14
|
'./jsx-dev-runtime': './cjs/react-jsx-dev-runtime.production.js',
|
|
@@ -23,14 +17,7 @@ const VENDOR_IMPORTS = {
|
|
|
23
17
|
}
|
|
24
18
|
},
|
|
25
19
|
'react-dom': {
|
|
26
|
-
'^
|
|
27
|
-
'.': './cjs/react-dom.production.min.js',
|
|
28
|
-
'./client': './cjs/react-dom.production.min.js',
|
|
29
|
-
'./package.json': './package.json',
|
|
30
|
-
'./server': './cjs/react-dom-server-legacy.browser.production.min.js',
|
|
31
|
-
'./server.browser': './cjs/react-dom-server-legacy.browser.production.min.js'
|
|
32
|
-
},
|
|
33
|
-
'^19.0.0': {
|
|
20
|
+
'^19.2.0': {
|
|
34
21
|
'.': './cjs/react-dom.production.js',
|
|
35
22
|
'./client': './cjs/react-dom-client.production.js',
|
|
36
23
|
'./package.json': './package.json',
|
|
@@ -44,7 +31,7 @@ const VENDOR_IMPORTS = {
|
|
|
44
31
|
const STYLED_COMPONENTS_IMPORTS = {
|
|
45
32
|
'styled-components': {
|
|
46
33
|
'^6.1.0': {
|
|
47
|
-
'.': './dist/styled-components.esm.js',
|
|
34
|
+
'.': './dist/styled-components.browser.esm.js',
|
|
48
35
|
'./package.json': './package.json'
|
|
49
36
|
}
|
|
50
37
|
}
|