@sanity/cli-build 6.5.0 → 7.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_exports/_internal/extract.d.ts +12 -23
- package/dist/_exports/_internal/extract.js +1 -2
- package/dist/_exports/_internal/extract.js.map +1 -1
- package/dist/_exports/_internal/manifest.d.ts +2 -2
- package/dist/_exports/_internal/manifest.js.map +1 -1
- package/dist/_exports/_internal/{types-Dj4qu4gT.d.ts → types-BFK33dtE.d.ts} +14 -2
- package/dist/actions/build/buildApp.js +16 -2
- package/dist/actions/build/buildApp.js.map +1 -1
- package/dist/actions/build/vite/plugin-sanity-build-entries.js +116 -54
- package/dist/actions/build/vite/plugin-sanity-build-entries.js.map +1 -1
- package/dist/actions/manifest/types.js.map +1 -1
- package/dist/actions/schema/buildStudioSchemasAndManifests.js +2 -1
- package/dist/actions/schema/buildStudioSchemasAndManifests.js.map +1 -1
- package/dist/actions/schema/buildStudioSchemasAndManifests.worker.js +1 -1
- package/dist/actions/schema/buildStudioSchemasAndManifests.worker.js.map +1 -1
- package/dist/actions/schema/{workerBuildStudioSchemasAndManifests.js → buildStudioSchemasAndManifestsWorker.js} +47 -36
- package/dist/actions/schema/buildStudioSchemasAndManifestsWorker.js.map +1 -0
- package/dist/actions/schema/types.js +1 -0
- package/dist/actions/schema/types.js.map +1 -1
- package/package.json +4 -4
- package/dist/actions/schema/workerBuildStudioSchemasAndManifests.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { d as WorkspaceSchemaInput } from "./types-BFK33dtE.js";
|
|
2
2
|
import { ProjectRootResult } from "@sanity/cli-core/types";
|
|
3
3
|
import { SchemaValidationProblemGroup } from "@sanity/types";
|
|
4
|
-
import { StudioManifest
|
|
4
|
+
import { StudioManifest } from "sanity";
|
|
5
5
|
import { z } from "zod/mini";
|
|
6
6
|
import { extractSchema } from "@sanity/schema/_internal";
|
|
7
7
|
declare const buildStudioSchemasAndManifestsWorkerData: z.ZodMiniObject<{
|
|
@@ -9,14 +9,15 @@ declare const buildStudioSchemasAndManifestsWorkerData: z.ZodMiniObject<{
|
|
|
9
9
|
isExternal: z.ZodMiniBoolean<boolean>;
|
|
10
10
|
outPath: z.ZodMiniString<string>;
|
|
11
11
|
projectId: z.ZodMiniString<string>;
|
|
12
|
+
schemaRequired: z.ZodMiniBoolean<boolean>;
|
|
12
13
|
verbose: z.ZodMiniBoolean<boolean>;
|
|
13
14
|
workDir: z.ZodMiniString<string>;
|
|
14
15
|
}, z.core.$strip>;
|
|
15
16
|
type BuildStudioSchemasAndManifestsWorkerData = z.infer<typeof buildStudioSchemasAndManifestsWorkerData>;
|
|
16
17
|
type BuildStudioSchemasAndManifestsWorkerSuccess = {
|
|
18
|
+
schemaInputs: WorkspaceSchemaInput[] | null;
|
|
17
19
|
studioManifest: StudioManifest | null;
|
|
18
20
|
type: 'success';
|
|
19
|
-
workspaceManifests: CreateWorkspaceManifest[];
|
|
20
21
|
};
|
|
21
22
|
/**
|
|
22
23
|
* 1. Extracts the create manifest in dist/static (tar/gzipped with studio)
|
|
@@ -24,6 +25,13 @@ type BuildStudioSchemasAndManifestsWorkerSuccess = {
|
|
|
24
25
|
* 3. Creates a studio manifest (which can be sent to populus)
|
|
25
26
|
*/
|
|
26
27
|
declare function buildStudioSchemasAndManifests(applicationId: string, options: BuildStudioSchemasAndManifestsWorkerData): Promise<BuildStudioSchemasAndManifestsWorkerSuccess>;
|
|
28
|
+
/**
|
|
29
|
+
* This function must only be called from another worker process.
|
|
30
|
+
* @param options - The worker options
|
|
31
|
+
*/
|
|
32
|
+
declare function workerBuildStudioSchemasAndManifests(options: BuildStudioSchemasAndManifestsWorkerData & {
|
|
33
|
+
workspaceSchemaHandler?: (workspaces: WorkspaceSchemaInput[]) => Promise<void>;
|
|
34
|
+
}): Promise<BuildStudioSchemasAndManifestsWorkerSuccess>;
|
|
27
35
|
declare function getAggregatedSeverity(groupOrGroups: SchemaValidationProblemGroup | SchemaValidationProblemGroup[]): 'error' | 'warning';
|
|
28
36
|
declare function formatSchemaValidation(validation: SchemaValidationProblemGroup[]): string;
|
|
29
37
|
interface ExtractOptions {
|
|
@@ -60,18 +68,6 @@ declare function createSchemaPatternMatcher(patterns: string[]): {
|
|
|
60
68
|
* Throws SchemaExtractionError on failure.
|
|
61
69
|
*/
|
|
62
70
|
declare function runSchemaExtraction(extractOptions: Omit<ExtractOptions, 'watchPatterns'>): Promise<ReturnType<typeof extractSchema>>;
|
|
63
|
-
interface UploadSchemaToLexiconOptions {
|
|
64
|
-
projectId: string;
|
|
65
|
-
workDir: string;
|
|
66
|
-
workspaces: Workspace[];
|
|
67
|
-
verbose?: boolean;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Uploads the schemas to Lexicon and returns the studio manifest
|
|
71
|
-
* @param options - The options for the uploadSchemaToLexicon function
|
|
72
|
-
* @returns The studio manifest
|
|
73
|
-
*/
|
|
74
|
-
declare function uploadSchemaToLexicon(options: UploadSchemaToLexiconOptions): Promise<StudioManifest | null>;
|
|
75
71
|
/**
|
|
76
72
|
* Extracts validation problem groups from a SchemaError.
|
|
77
73
|
*/
|
|
@@ -80,13 +76,6 @@ declare class SchemaExtractionError extends Error {
|
|
|
80
76
|
validation?: SchemaValidationProblemGroup[];
|
|
81
77
|
constructor(message: string, validation?: SchemaValidationProblemGroup[]);
|
|
82
78
|
}
|
|
83
|
-
/**
|
|
84
|
-
* This function must only be called from another worker process.
|
|
85
|
-
* @param options - The worker options
|
|
86
|
-
*/
|
|
87
|
-
declare function workerBuildStudioSchemasAndManifests(options: BuildStudioSchemasAndManifestsWorkerData & {
|
|
88
|
-
workspaceManifestsHandler?: (workspaceManifests: CreateWorkspaceManifest[]) => Promise<void>;
|
|
89
|
-
}): Promise<BuildStudioSchemasAndManifestsWorkerSuccess>;
|
|
90
79
|
interface SchemaExtractedTraceAttributes {
|
|
91
80
|
enforceRequiredFields: boolean;
|
|
92
81
|
schemaAllTypesCount: number;
|
|
@@ -113,5 +102,5 @@ interface SchemaDeployTraceData {
|
|
|
113
102
|
declare const SchemaExtractedTrace: import("@sanity/telemetry").DefinedTelemetryTrace<SchemaExtractedTraceAttributes, void>;
|
|
114
103
|
declare const SchemaExtractionWatchModeTrace: import("@sanity/telemetry").DefinedTelemetryTrace<SchemaExtractionWatchModeAttributes, void>;
|
|
115
104
|
declare const SchemaDeploy: import("@sanity/telemetry").DefinedTelemetryTrace<SchemaDeployTraceData, void>;
|
|
116
|
-
export { type ExtractOptions, SchemaDeploy, SchemaExtractedTrace, SchemaExtractionError, SchemaExtractionWatchModeTrace, buildStudioSchemasAndManifests, createSchemaPatternMatcher, extractValidationFromSchemaError, formatSchemaValidation, getAggregatedSeverity, getExtractOptions, runSchemaExtraction,
|
|
105
|
+
export { type ExtractOptions, SchemaDeploy, SchemaExtractedTrace, SchemaExtractionError, SchemaExtractionWatchModeTrace, buildStudioSchemasAndManifests, createSchemaPatternMatcher, extractValidationFromSchemaError, formatSchemaValidation, getAggregatedSeverity, getExtractOptions, runSchemaExtraction, workerBuildStudioSchemasAndManifests };
|
|
117
106
|
//# sourceMappingURL=extract.d.ts.map
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
export { buildStudioSchemasAndManifests } from '../../actions/schema/buildStudioSchemasAndManifests.js';
|
|
2
|
+
export { workerBuildStudioSchemasAndManifests } from '../../actions/schema/buildStudioSchemasAndManifestsWorker.js';
|
|
2
3
|
export { formatSchemaValidation, getAggregatedSeverity } from '../../actions/schema/formatSchemaValidation.js';
|
|
3
4
|
export { getExtractOptions } from '../../actions/schema/getExtractOptions.js';
|
|
4
5
|
export { createSchemaPatternMatcher } from '../../actions/schema/matchSchemaPattern.js';
|
|
5
6
|
export { runSchemaExtraction } from '../../actions/schema/runSchemaExtraction.js';
|
|
6
|
-
export { uploadSchemaToLexicon } from '../../actions/schema/uploadSchemaToLexicon.js';
|
|
7
7
|
export { extractValidationFromSchemaError } from '../../actions/schema/utils/extractValidationFromSchemaError.js';
|
|
8
8
|
export { SchemaExtractionError } from '../../actions/schema/utils/SchemaExtractionError.js';
|
|
9
|
-
export { workerBuildStudioSchemasAndManifests } from '../../actions/schema/workerBuildStudioSchemasAndManifests.js';
|
|
10
9
|
export { SchemaDeploy, SchemaExtractedTrace, SchemaExtractionWatchModeTrace } from '../../telemetry/extractSchema.telemetry.js';
|
|
11
10
|
|
|
12
11
|
//# sourceMappingURL=extract.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/_exports/_internal/extract.ts"],"sourcesContent":["export {buildStudioSchemasAndManifests} from '../../actions/schema/buildStudioSchemasAndManifests.js'\nexport {\n formatSchemaValidation,\n getAggregatedSeverity,\n} from '../../actions/schema/formatSchemaValidation.js'\nexport {type ExtractOptions, getExtractOptions} from '../../actions/schema/getExtractOptions.js'\nexport {createSchemaPatternMatcher} from '../../actions/schema/matchSchemaPattern.js'\nexport {runSchemaExtraction} from '../../actions/schema/runSchemaExtraction.js'\nexport {
|
|
1
|
+
{"version":3,"sources":["../../../src/_exports/_internal/extract.ts"],"sourcesContent":["export {buildStudioSchemasAndManifests} from '../../actions/schema/buildStudioSchemasAndManifests.js'\nexport {workerBuildStudioSchemasAndManifests} from '../../actions/schema/buildStudioSchemasAndManifestsWorker.js'\nexport {\n formatSchemaValidation,\n getAggregatedSeverity,\n} from '../../actions/schema/formatSchemaValidation.js'\nexport {type ExtractOptions, getExtractOptions} from '../../actions/schema/getExtractOptions.js'\nexport {createSchemaPatternMatcher} from '../../actions/schema/matchSchemaPattern.js'\nexport {runSchemaExtraction} from '../../actions/schema/runSchemaExtraction.js'\nexport {extractValidationFromSchemaError} from '../../actions/schema/utils/extractValidationFromSchemaError.js'\nexport {SchemaExtractionError} from '../../actions/schema/utils/SchemaExtractionError.js'\nexport {\n SchemaDeploy,\n SchemaExtractedTrace,\n SchemaExtractionWatchModeTrace,\n} from '../../telemetry/extractSchema.telemetry.js'\n"],"names":["buildStudioSchemasAndManifests","workerBuildStudioSchemasAndManifests","formatSchemaValidation","getAggregatedSeverity","getExtractOptions","createSchemaPatternMatcher","runSchemaExtraction","extractValidationFromSchemaError","SchemaExtractionError","SchemaDeploy","SchemaExtractedTrace","SchemaExtractionWatchModeTrace"],"mappings":"AAAA,SAAQA,8BAA8B,QAAO,yDAAwD;AACrG,SAAQC,oCAAoC,QAAO,+DAA8D;AACjH,SACEC,sBAAsB,EACtBC,qBAAqB,QAChB,iDAAgD;AACvD,SAA6BC,iBAAiB,QAAO,4CAA2C;AAChG,SAAQC,0BAA0B,QAAO,6CAA4C;AACrF,SAAQC,mBAAmB,QAAO,8CAA6C;AAC/E,SAAQC,gCAAgC,QAAO,iEAAgE;AAC/G,SAAQC,qBAAqB,QAAO,sDAAqD;AACzF,SACEC,YAAY,EACZC,oBAAoB,EACpBC,8BAA8B,QACzB,6CAA4C"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as DefaultWorkspaceSchemaId, c as StoredWorkspaceSchema, i as CreateWorkspaceManifest, l as StudioManifest, n as CoreAppManifest, o as ManifestSchemaType, r as CreateManifest, s as SANITY_WORKSPACE_SCHEMA_ID_PREFIX, t as CURRENT_WORKSPACE_SCHEMA_VERSION, u as WorkspaceSchemaId } from "./types-
|
|
1
|
+
import { a as DefaultWorkspaceSchemaId, c as StoredWorkspaceSchema, d as WorkspaceSchemaInput, i as CreateWorkspaceManifest, l as StudioManifest, n as CoreAppManifest, o as ManifestSchemaType, r as CreateManifest, s as SANITY_WORKSPACE_SCHEMA_ID_PREFIX, t as CURRENT_WORKSPACE_SCHEMA_VERSION, u as WorkspaceSchemaId } from "./types-BFK33dtE.js";
|
|
2
2
|
import { Schema } from "@sanity/types";
|
|
3
3
|
import { Workspace } from "sanity";
|
|
4
4
|
interface ExtractCoreAppManifestOptions {
|
|
@@ -65,5 +65,5 @@ declare function extractWorkspaceManifest(workspaces: Workspace[], workDir: stri
|
|
|
65
65
|
* @internal
|
|
66
66
|
*/
|
|
67
67
|
declare function extractManifestSchemaTypes(schema: Schema, workDir: string): Promise<ManifestSchemaType[]>;
|
|
68
|
-
export { CURRENT_WORKSPACE_SCHEMA_VERSION, type CoreAppManifest, type CreateManifest, type CreateWorkspaceManifest, type DefaultWorkspaceSchemaId, MANIFEST_FILENAME, type ManifestSchemaType, SANITY_WORKSPACE_SCHEMA_ID_PREFIX, type StoredWorkspaceSchema, type StudioManifest, type WorkspaceSchemaId, extractCoreAppManifest, extractManifest, extractManifestSchemaTypes, extractWorkspaceManifest, readIconFromPath, resolveTitleUpdate, writeManifestFile };
|
|
68
|
+
export { CURRENT_WORKSPACE_SCHEMA_VERSION, type CoreAppManifest, type CreateManifest, type CreateWorkspaceManifest, type DefaultWorkspaceSchemaId, MANIFEST_FILENAME, type ManifestSchemaType, SANITY_WORKSPACE_SCHEMA_ID_PREFIX, type StoredWorkspaceSchema, type StudioManifest, type WorkspaceSchemaId, type WorkspaceSchemaInput, extractCoreAppManifest, extractManifest, extractManifestSchemaTypes, extractWorkspaceManifest, readIconFromPath, resolveTitleUpdate, writeManifestFile };
|
|
69
69
|
//# sourceMappingURL=manifest.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/_exports/_internal/manifest.ts"],"sourcesContent":["export {\n extractCoreAppManifest,\n readIconFromPath,\n resolveTitleUpdate,\n} from '../../actions/manifest/extractCoreAppManifest.js'\nexport {extractManifest} from '../../actions/manifest/extractManifest.js'\nexport {\n extractManifestSchemaTypes,\n extractWorkspaceManifest,\n} from '../../actions/manifest/extractWorkspaceManifest.js'\nexport {\n type CoreAppManifest,\n type CreateManifest,\n type CreateWorkspaceManifest,\n CURRENT_WORKSPACE_SCHEMA_VERSION,\n type DefaultWorkspaceSchemaId,\n type ManifestSchemaType,\n SANITY_WORKSPACE_SCHEMA_ID_PREFIX,\n type StoredWorkspaceSchema,\n type StudioManifest,\n type WorkspaceSchemaId,\n} from '../../actions/manifest/types.js'\nexport {MANIFEST_FILENAME, writeManifestFile} from '../../actions/manifest/writeManifestFile.js'\n"],"names":["extractCoreAppManifest","readIconFromPath","resolveTitleUpdate","extractManifest","extractManifestSchemaTypes","extractWorkspaceManifest","CURRENT_WORKSPACE_SCHEMA_VERSION","SANITY_WORKSPACE_SCHEMA_ID_PREFIX","MANIFEST_FILENAME","writeManifestFile"],"mappings":"AAAA,SACEA,sBAAsB,EACtBC,gBAAgB,EAChBC,kBAAkB,QACb,mDAAkD;AACzD,SAAQC,eAAe,QAAO,4CAA2C;AACzE,SACEC,0BAA0B,EAC1BC,wBAAwB,QACnB,qDAAoD;AAC3D,SAIEC,gCAAgC,EAGhCC,iCAAiC,
|
|
1
|
+
{"version":3,"sources":["../../../src/_exports/_internal/manifest.ts"],"sourcesContent":["export {\n extractCoreAppManifest,\n readIconFromPath,\n resolveTitleUpdate,\n} from '../../actions/manifest/extractCoreAppManifest.js'\nexport {extractManifest} from '../../actions/manifest/extractManifest.js'\nexport {\n extractManifestSchemaTypes,\n extractWorkspaceManifest,\n} from '../../actions/manifest/extractWorkspaceManifest.js'\nexport {\n type CoreAppManifest,\n type CreateManifest,\n type CreateWorkspaceManifest,\n CURRENT_WORKSPACE_SCHEMA_VERSION,\n type DefaultWorkspaceSchemaId,\n type ManifestSchemaType,\n SANITY_WORKSPACE_SCHEMA_ID_PREFIX,\n type StoredWorkspaceSchema,\n type StudioManifest,\n type WorkspaceSchemaId,\n type WorkspaceSchemaInput,\n} from '../../actions/manifest/types.js'\nexport {MANIFEST_FILENAME, writeManifestFile} from '../../actions/manifest/writeManifestFile.js'\n"],"names":["extractCoreAppManifest","readIconFromPath","resolveTitleUpdate","extractManifest","extractManifestSchemaTypes","extractWorkspaceManifest","CURRENT_WORKSPACE_SCHEMA_VERSION","SANITY_WORKSPACE_SCHEMA_ID_PREFIX","MANIFEST_FILENAME","writeManifestFile"],"mappings":"AAAA,SACEA,sBAAsB,EACtBC,gBAAgB,EAChBC,kBAAkB,QACb,mDAAkD;AACzD,SAAQC,eAAe,QAAO,4CAA2C;AACzE,SACEC,0BAA0B,EAC1BC,wBAAwB,QACnB,qDAAoD;AAC3D,SAIEC,gCAAgC,EAGhCC,iCAAiC,QAK5B,kCAAiC;AACxC,SAAQC,iBAAiB,EAAEC,iBAAiB,QAAO,8CAA6C"}
|
|
@@ -112,5 +112,17 @@ interface StoredWorkspaceSchema extends SanityDocumentLike {
|
|
|
112
112
|
};
|
|
113
113
|
tag?: string;
|
|
114
114
|
}
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
/**
|
|
116
|
+
* Workspace metadata + pre-extracted manifest schema for deployment.
|
|
117
|
+
* The schema must already be in ManifestSchemaType[] format (extracted from
|
|
118
|
+
* the live Schema object before any structured clone boundary).
|
|
119
|
+
*/
|
|
120
|
+
interface WorkspaceSchemaInput {
|
|
121
|
+
dataset: string;
|
|
122
|
+
manifestSchema: ManifestSchemaType[];
|
|
123
|
+
name: string;
|
|
124
|
+
projectId: string;
|
|
125
|
+
title?: string;
|
|
126
|
+
}
|
|
127
|
+
export { DefaultWorkspaceSchemaId as a, StoredWorkspaceSchema as c, WorkspaceSchemaInput as d, CreateWorkspaceManifest as i, StudioManifest$1 as l, CoreAppManifest as n, ManifestSchemaType as o, CreateManifest as r, SANITY_WORKSPACE_SCHEMA_ID_PREFIX as s, CURRENT_WORKSPACE_SCHEMA_VERSION as t, WorkspaceSchemaId as u };
|
|
128
|
+
//# sourceMappingURL=types-BFK33dtE.d.ts.map
|
|
@@ -29,7 +29,13 @@ import { resolveVendorBuildConfig } from './resolveVendorBuildConfig.js';
|
|
|
29
29
|
const outputDir = path.resolve(outDir || defaultOutputDir);
|
|
30
30
|
const installedSdkVersion = await getLocalPackageVersion('@sanity/sdk-react', workDir);
|
|
31
31
|
const installedSanityVersion = await getLocalPackageVersion('sanity', workDir);
|
|
32
|
-
|
|
32
|
+
// A Media Library config ships no SDK app — its inputs are island-rendered
|
|
33
|
+
// by `sanity`, so verify that instead and skip the SDK auto-update
|
|
34
|
+
// machinery. Checked via the `appType` discriminator, not the mere presence
|
|
35
|
+
// of a config: a future `ConfigSchema` member must not inherit these
|
|
36
|
+
// media-library build semantics by default.
|
|
37
|
+
const isMediaLibraryConfigBuild = options.exposes?.config?.appType === 'media-library';
|
|
38
|
+
if (!installedSdkVersion && !isMediaLibraryConfigBuild) {
|
|
33
39
|
output.error(`Failed to find installed @sanity/sdk-react version`, {
|
|
34
40
|
exit: exitCodes.RUNTIME_ERROR
|
|
35
41
|
});
|
|
@@ -37,9 +43,17 @@ import { resolveVendorBuildConfig } from './resolveVendorBuildConfig.js';
|
|
|
37
43
|
mfManifest: undefined
|
|
38
44
|
};
|
|
39
45
|
}
|
|
46
|
+
if (isMediaLibraryConfigBuild && !installedSanityVersion) {
|
|
47
|
+
output.error(`Failed to find installed sanity version`, {
|
|
48
|
+
exit: exitCodes.RUNTIME_ERROR
|
|
49
|
+
});
|
|
50
|
+
return {
|
|
51
|
+
mfManifest: undefined
|
|
52
|
+
};
|
|
53
|
+
}
|
|
40
54
|
let autoUpdatesImports = {};
|
|
41
55
|
let autoUpdatesCssUrls = [];
|
|
42
|
-
if (autoUpdatesEnabled) {
|
|
56
|
+
if (autoUpdatesEnabled && !isMediaLibraryConfigBuild) {
|
|
43
57
|
// Get the clean version without build metadata: https://semver.org/#spec-item-10
|
|
44
58
|
const cleanSDKVersion = semverParse(installedSdkVersion)?.version;
|
|
45
59
|
if (!cleanSDKVersion) {
|
|
@@ -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 {exitCodes} from '@sanity/cli-core/ExitCodes'\nimport {getLocalPackageVersion} from '@sanity/cli-core/package-manager'\nimport {getCliTelemetry} from '@sanity/cli-core/telemetry'\nimport {type CliConfig, type Output, type UserViteConfig} from '@sanity/cli-core/types'\nimport {isInteractive} from '@sanity/cli-core/util'\nimport {confirm, getTimer, logSymbols, spinner, type SpinnerInstance} from '@sanity/cli-core/ux'\nimport {readBuiltManifest, type WorkbenchExposes} from '@sanity/workbench-cli/build'\nimport {parse as semverParse} from 'semver'\n\nimport {AppBuildTrace} from '../../telemetry/build.telemetry.js'\nimport {CompareDependencyVersionsResult} from '../../util/compareDependencyVersions.js'\nimport {formatModuleSizes, sortModulesBySize} from '../../util/moduleFormatUtils.js'\nimport {buildDebug} from './buildDebug.js'\nimport {buildStaticFiles} from './buildStaticFiles.js'\nimport {BuildEventListener} from './eventListener.js'\nimport {getAutoUpdatesCssUrls, getAutoUpdatesImportMap} from './getAutoUpdatesImportMap.js'\nimport {getAppEnvironmentVariables} from './getEnvironmentVariables.js'\nimport {handlePrereleaseVersions} from './handlePrereleaseVersions.js'\nimport {resolveVendorBuildConfig} from './resolveVendorBuildConfig.js'\n\nexport type BuildAppEventListener = BuildEventListener\nexport interface BuildOptions {\n appId: string | undefined\n appTitle: string | undefined\n autoUpdatesEnabled: boolean\n checkAppId: () => void\n compareDependencyVersions: (\n packages: {name: string; version: string}[],\n ) => Promise<CompareDependencyVersionsResult>\n determineBasePath: () => string\n entry: string | undefined\n eventListener: Partial<BuildAppEventListener>\n isWorkbenchApp: boolean\n minify: boolean\n outDir: string | undefined\n output: Output\n reactCompiler: CliConfig['reactCompiler']\n schemaExtraction: CliConfig['schemaExtraction']\n sourceMap: boolean\n stats: boolean\n unattendedMode: boolean\n vite: UserViteConfig | undefined\n workDir: string\n\n exposes?: WorkbenchExposes\n /**\n * The build is running under Sanity Blueprints (invoked programmatically by\n * `@sanity/runtime-cli`), so emit the statically-imported resource-bindings\n * module Brett rewrites at deploy. Defaults to `false`, so a normal\n * `sanity build`/`dev`/`preview` never emits it.\n */\n isBlueprints?: boolean\n\n /** The workbench app's bus identity (`__SANITY_APP_ID__`). */\n workbenchAppId?: string\n}\n\n/**\n * Internal build app that avoids depending on flags for CLI config.\n * @param options - options for the build\n */\nexport async function buildApp(\n options: BuildOptions,\n): Promise<{mfManifest: Record<string, unknown> | undefined}> {\n buildDebug(`Building app`)\n\n const {appId, determineBasePath, eventListener, outDir, output, workDir} = options\n let {autoUpdatesEnabled} = options\n const unattendedMode = options.unattendedMode\n\n const timer = getTimer()\n\n const defaultOutputDir = path.resolve(path.join(workDir, 'dist'))\n const outputDir = path.resolve(outDir || defaultOutputDir)\n\n const installedSdkVersion = await getLocalPackageVersion('@sanity/sdk-react', workDir)\n const installedSanityVersion = await getLocalPackageVersion('sanity', workDir)\n\n if (!installedSdkVersion) {\n output.error(`Failed to find installed @sanity/sdk-react version`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n return {mfManifest: undefined}\n }\n\n let autoUpdatesImports = {}\n let autoUpdatesCssUrls: string[] = []\n\n if (autoUpdatesEnabled) {\n // Get the clean version without build metadata: https://semver.org/#spec-item-10\n const cleanSDKVersion = semverParse(installedSdkVersion)?.version\n if (!cleanSDKVersion) {\n output.error(`Failed to parse installed SDK version: ${installedSdkVersion}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n return {mfManifest: undefined}\n }\n\n // Sanity might not be installed, but if it is, we want to auto update it.\n const cleanSanityVersion = semverParse(installedSanityVersion)?.version\n\n const autoUpdatedPackages = [\n {name: '@sanity/sdk', version: cleanSDKVersion},\n {name: '@sanity/sdk-react', version: cleanSDKVersion},\n ...(cleanSanityVersion\n ? [{cssFile: 'index.css', name: 'sanity' as const, version: cleanSanityVersion}]\n : []),\n ]\n autoUpdatesImports = getAutoUpdatesImportMap(autoUpdatedPackages, {appId})\n autoUpdatesCssUrls = getAutoUpdatesCssUrls(autoUpdatedPackages, {appId})\n\n output.log(`${logSymbols.info} Building with auto-updates enabled`)\n\n // Warn if auto updates enabled but no appId configured.\n options.checkAppId()\n\n // Check the versions\n const {mismatched, unresolvedPrerelease} =\n await options.compareDependencyVersions(autoUpdatedPackages)\n\n if (unresolvedPrerelease.length > 0) {\n await handlePrereleaseVersions({\n onPreReleaseInInteractiveAutoUpdate: eventListener.onPreReleaseInInteractiveAutoUpdate,\n onPreReleaseInNonInteractiveAutoUpdate:\n eventListener.onPreReleaseInNonInteractiveAutoUpdate,\n unattendedMode,\n unresolvedPrerelease,\n })\n autoUpdatesImports = {}\n autoUpdatesCssUrls = []\n autoUpdatesEnabled = false\n }\n\n if (mismatched.length > 0 && autoUpdatesEnabled) {\n const versionMismatchWarning =\n `The following local package versions are different from the versions currently served at runtime.\\n` +\n `When using auto updates, we recommend that you test locally with the same versions before deploying. \\n\\n` +\n `${mismatched.map((mod) => ` - ${mod.pkg} (local version: ${mod.installed}, runtime version: ${mod.remote})`).join('\\n')}`\n\n // If it is non-interactive or in unattended mode, we don't want to prompt\n if (isInteractive() && !unattendedMode) {\n const shouldContinue = await confirm({\n default: false,\n message: styleText('yellow', `${versionMismatchWarning} \\n\\nContinue anyway?`),\n })\n\n if (!shouldContinue) {\n output.error('Declined to continue with build', {exit: exitCodes.RUNTIME_ERROR})\n return {mfManifest: undefined}\n }\n } else {\n // if non-interactive or unattended, just show the warning\n output.warn(versionMismatchWarning)\n }\n }\n }\n\n const envVarKeys = Object.keys(getAppEnvironmentVariables())\n if (envVarKeys.length > 0) {\n output.log('\\nIncluding the following environment variables as part of the JavaScript bundle:')\n for (const key of envVarKeys) output.log(`- ${key}`)\n output.log('')\n }\n\n let shouldClean = true\n if (outputDir !== defaultOutputDir && !unattendedMode && isInteractive()) {\n shouldClean = await confirm({\n default: true,\n message: `Do you want to delete the existing directory (${outputDir}) first?`,\n })\n }\n\n const basePath = determineBasePath()\n\n let spin: SpinnerInstance\n if (shouldClean) {\n timer.start('cleanOutputFolder')\n spin = spinner('Clean output folder').start()\n await rm(outputDir, {force: true, recursive: true})\n const cleanDuration = timer.end('cleanOutputFolder')\n spin.text = `Clean output folder (${cleanDuration.toFixed(0)}ms)`\n spin.succeed()\n }\n\n spin = spinner(`Building Sanity application`).start()\n\n const trace = getCliTelemetry().trace(AppBuildTrace)\n trace.start()\n\n let autoUpdates\n if (autoUpdatesEnabled && !options.isWorkbenchApp) {\n autoUpdates = {\n cssUrls: autoUpdatesCssUrls,\n imports: autoUpdatesImports,\n vendor: await resolveVendorBuildConfig({cwd: workDir, isApp: true}),\n }\n }\n\n try {\n timer.start('bundleStudio')\n\n const bundle = await buildStaticFiles({\n appTitle: options.appTitle,\n autoUpdates,\n basePath,\n cwd: workDir,\n entry: options.entry,\n exposes: options.exposes,\n isApp: true,\n isBlueprints: options.isBlueprints,\n isWorkbenchApp: options.isWorkbenchApp,\n minify: options.minify,\n outputDir,\n reactCompiler: options.reactCompiler,\n schemaExtraction: options.schemaExtraction,\n sourceMap: options.sourceMap,\n vite: options.vite,\n workbenchAppId: options.workbenchAppId,\n })\n const mfManifest = options.isWorkbenchApp ? await readBuiltManifest(outputDir) : undefined\n\n trace.log({\n outputSize: bundle.chunks\n .flatMap((chunk) => chunk.modules.flatMap((mod) => mod.renderedLength))\n .reduce((sum, n) => sum + n, 0),\n })\n const buildDuration = timer.end('bundleStudio')\n\n spin.text = `Build Sanity application (${buildDuration.toFixed(0)}ms)`\n spin.succeed()\n\n if (options.stats) {\n output.log('\\nLargest module files:')\n output.log(formatModuleSizes(sortModulesBySize(bundle.chunks).slice(0, 15)))\n }\n\n trace.complete()\n return {mfManifest}\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: exitCodes.RUNTIME_ERROR})\n return {mfManifest: undefined}\n }\n}\n"],"names":["rm","path","styleText","exitCodes","getLocalPackageVersion","getCliTelemetry","isInteractive","confirm","getTimer","logSymbols","spinner","readBuiltManifest","parse","semverParse","AppBuildTrace","formatModuleSizes","sortModulesBySize","buildDebug","buildStaticFiles","getAutoUpdatesCssUrls","getAutoUpdatesImportMap","getAppEnvironmentVariables","handlePrereleaseVersions","resolveVendorBuildConfig","buildApp","options","appId","determineBasePath","eventListener","outDir","output","workDir","autoUpdatesEnabled","unattendedMode","timer","defaultOutputDir","resolve","join","outputDir","installedSdkVersion","installedSanityVersion","error","exit","RUNTIME_ERROR","mfManifest","undefined","autoUpdatesImports","autoUpdatesCssUrls","cleanSDKVersion","version","cleanSanityVersion","autoUpdatedPackages","name","cssFile","log","info","checkAppId","mismatched","unresolvedPrerelease","compareDependencyVersions","length","onPreReleaseInInteractiveAutoUpdate","onPreReleaseInNonInteractiveAutoUpdate","versionMismatchWarning","map","mod","pkg","installed","remote","shouldContinue","default","message","warn","envVarKeys","Object","keys","key","shouldClean","basePath","spin","start","force","recursive","cleanDuration","end","text","toFixed","succeed","trace","autoUpdates","isWorkbenchApp","cssUrls","imports","vendor","cwd","isApp","bundle","appTitle","entry","exposes","isBlueprints","minify","reactCompiler","schemaExtraction","sourceMap","vite","workbenchAppId","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,SAAS,QAAO,6BAA4B;AACpD,SAAQC,sBAAsB,QAAO,mCAAkC;AACvE,SAAQC,eAAe,QAAO,6BAA4B;AAE1D,SAAQC,aAAa,QAAO,wBAAuB;AACnD,SAAQC,OAAO,EAAEC,QAAQ,EAAEC,UAAU,EAAEC,OAAO,QAA6B,sBAAqB;AAChG,SAAQC,iBAAiB,QAA8B,8BAA6B;AACpF,SAAQC,SAASC,WAAW,QAAO,SAAQ;AAE3C,SAAQC,aAAa,QAAO,qCAAoC;AAEhE,SAAQC,iBAAiB,EAAEC,iBAAiB,QAAO,kCAAiC;AACpF,SAAQC,UAAU,QAAO,kBAAiB;AAC1C,SAAQC,gBAAgB,QAAO,wBAAuB;AAEtD,SAAQC,qBAAqB,EAAEC,uBAAuB,QAAO,+BAA8B;AAC3F,SAAQC,0BAA0B,QAAO,+BAA8B;AACvE,SAAQC,wBAAwB,QAAO,gCA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OW,KAAK,CAAC,CAAC,oCAAoC,EAAE8B,SAAS,EAAE;YAAC7B,MAAMvC,UAAUwC,aAAa;QAAA;QAC7F,OAAO;YAACC,YAAYC;QAAS;IAC/B;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 {exitCodes} from '@sanity/cli-core/ExitCodes'\nimport {getLocalPackageVersion} from '@sanity/cli-core/package-manager'\nimport {getCliTelemetry} from '@sanity/cli-core/telemetry'\nimport {type CliConfig, type Output, type UserViteConfig} from '@sanity/cli-core/types'\nimport {isInteractive} from '@sanity/cli-core/util'\nimport {confirm, getTimer, logSymbols, spinner, type SpinnerInstance} from '@sanity/cli-core/ux'\nimport {readBuiltManifest, type WorkbenchExposes} from '@sanity/workbench-cli/build'\nimport {parse as semverParse} from 'semver'\n\nimport {AppBuildTrace} from '../../telemetry/build.telemetry.js'\nimport {CompareDependencyVersionsResult} from '../../util/compareDependencyVersions.js'\nimport {formatModuleSizes, sortModulesBySize} from '../../util/moduleFormatUtils.js'\nimport {buildDebug} from './buildDebug.js'\nimport {buildStaticFiles} from './buildStaticFiles.js'\nimport {BuildEventListener} from './eventListener.js'\nimport {getAutoUpdatesCssUrls, getAutoUpdatesImportMap} from './getAutoUpdatesImportMap.js'\nimport {getAppEnvironmentVariables} from './getEnvironmentVariables.js'\nimport {handlePrereleaseVersions} from './handlePrereleaseVersions.js'\nimport {resolveVendorBuildConfig} from './resolveVendorBuildConfig.js'\n\nexport type BuildAppEventListener = BuildEventListener\nexport interface BuildOptions {\n appId: string | undefined\n appTitle: string | undefined\n autoUpdatesEnabled: boolean\n checkAppId: () => void\n compareDependencyVersions: (\n packages: {name: string; version: string}[],\n ) => Promise<CompareDependencyVersionsResult>\n determineBasePath: () => string\n entry: string | undefined\n eventListener: Partial<BuildAppEventListener>\n isWorkbenchApp: boolean\n minify: boolean\n outDir: string | undefined\n output: Output\n reactCompiler: CliConfig['reactCompiler']\n schemaExtraction: CliConfig['schemaExtraction']\n sourceMap: boolean\n stats: boolean\n unattendedMode: boolean\n vite: UserViteConfig | undefined\n workDir: string\n\n exposes?: WorkbenchExposes\n /**\n * The build is running under Sanity Blueprints (invoked programmatically by\n * `@sanity/runtime-cli`), so emit the statically-imported resource-bindings\n * module Brett rewrites at deploy. Defaults to `false`, so a normal\n * `sanity build`/`dev`/`preview` never emits it.\n */\n isBlueprints?: boolean\n\n /** The workbench app's bus identity (`__SANITY_APP_ID__`). */\n workbenchAppId?: string\n}\n\n/**\n * Internal build app that avoids depending on flags for CLI config.\n * @param options - options for the build\n */\nexport async function buildApp(\n options: BuildOptions,\n): Promise<{mfManifest: Record<string, unknown> | undefined}> {\n buildDebug(`Building app`)\n\n const {appId, determineBasePath, eventListener, outDir, output, workDir} = options\n let {autoUpdatesEnabled} = options\n const unattendedMode = options.unattendedMode\n\n const timer = getTimer()\n\n const defaultOutputDir = path.resolve(path.join(workDir, 'dist'))\n const outputDir = path.resolve(outDir || defaultOutputDir)\n\n const installedSdkVersion = await getLocalPackageVersion('@sanity/sdk-react', workDir)\n const installedSanityVersion = await getLocalPackageVersion('sanity', workDir)\n\n // A Media Library config ships no SDK app — its inputs are island-rendered\n // by `sanity`, so verify that instead and skip the SDK auto-update\n // machinery. Checked via the `appType` discriminator, not the mere presence\n // of a config: a future `ConfigSchema` member must not inherit these\n // media-library build semantics by default.\n const isMediaLibraryConfigBuild = options.exposes?.config?.appType === 'media-library'\n\n if (!installedSdkVersion && !isMediaLibraryConfigBuild) {\n output.error(`Failed to find installed @sanity/sdk-react version`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n return {mfManifest: undefined}\n }\n\n if (isMediaLibraryConfigBuild && !installedSanityVersion) {\n output.error(`Failed to find installed sanity version`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n return {mfManifest: undefined}\n }\n\n let autoUpdatesImports = {}\n let autoUpdatesCssUrls: string[] = []\n\n if (autoUpdatesEnabled && !isMediaLibraryConfigBuild) {\n // Get the clean version without build metadata: https://semver.org/#spec-item-10\n const cleanSDKVersion = semverParse(installedSdkVersion)?.version\n if (!cleanSDKVersion) {\n output.error(`Failed to parse installed SDK version: ${installedSdkVersion}`, {\n exit: exitCodes.RUNTIME_ERROR,\n })\n return {mfManifest: undefined}\n }\n\n // Sanity might not be installed, but if it is, we want to auto update it.\n const cleanSanityVersion = semverParse(installedSanityVersion)?.version\n\n const autoUpdatedPackages = [\n {name: '@sanity/sdk', version: cleanSDKVersion},\n {name: '@sanity/sdk-react', version: cleanSDKVersion},\n ...(cleanSanityVersion\n ? [{cssFile: 'index.css', name: 'sanity' as const, version: cleanSanityVersion}]\n : []),\n ]\n autoUpdatesImports = getAutoUpdatesImportMap(autoUpdatedPackages, {appId})\n autoUpdatesCssUrls = getAutoUpdatesCssUrls(autoUpdatedPackages, {appId})\n\n output.log(`${logSymbols.info} Building with auto-updates enabled`)\n\n // Warn if auto updates enabled but no appId configured.\n options.checkAppId()\n\n // Check the versions\n const {mismatched, unresolvedPrerelease} =\n await options.compareDependencyVersions(autoUpdatedPackages)\n\n if (unresolvedPrerelease.length > 0) {\n await handlePrereleaseVersions({\n onPreReleaseInInteractiveAutoUpdate: eventListener.onPreReleaseInInteractiveAutoUpdate,\n onPreReleaseInNonInteractiveAutoUpdate:\n eventListener.onPreReleaseInNonInteractiveAutoUpdate,\n unattendedMode,\n unresolvedPrerelease,\n })\n autoUpdatesImports = {}\n autoUpdatesCssUrls = []\n autoUpdatesEnabled = false\n }\n\n if (mismatched.length > 0 && autoUpdatesEnabled) {\n const versionMismatchWarning =\n `The following local package versions are different from the versions currently served at runtime.\\n` +\n `When using auto updates, we recommend that you test locally with the same versions before deploying. \\n\\n` +\n `${mismatched.map((mod) => ` - ${mod.pkg} (local version: ${mod.installed}, runtime version: ${mod.remote})`).join('\\n')}`\n\n // If it is non-interactive or in unattended mode, we don't want to prompt\n if (isInteractive() && !unattendedMode) {\n const shouldContinue = await confirm({\n default: false,\n message: styleText('yellow', `${versionMismatchWarning} \\n\\nContinue anyway?`),\n })\n\n if (!shouldContinue) {\n output.error('Declined to continue with build', {exit: exitCodes.RUNTIME_ERROR})\n return {mfManifest: undefined}\n }\n } else {\n // if non-interactive or unattended, just show the warning\n output.warn(versionMismatchWarning)\n }\n }\n }\n\n const envVarKeys = Object.keys(getAppEnvironmentVariables())\n if (envVarKeys.length > 0) {\n output.log('\\nIncluding the following environment variables as part of the JavaScript bundle:')\n for (const key of envVarKeys) output.log(`- ${key}`)\n output.log('')\n }\n\n let shouldClean = true\n if (outputDir !== defaultOutputDir && !unattendedMode && isInteractive()) {\n shouldClean = await confirm({\n default: true,\n message: `Do you want to delete the existing directory (${outputDir}) first?`,\n })\n }\n\n const basePath = determineBasePath()\n\n let spin: SpinnerInstance\n if (shouldClean) {\n timer.start('cleanOutputFolder')\n spin = spinner('Clean output folder').start()\n await rm(outputDir, {force: true, recursive: true})\n const cleanDuration = timer.end('cleanOutputFolder')\n spin.text = `Clean output folder (${cleanDuration.toFixed(0)}ms)`\n spin.succeed()\n }\n\n spin = spinner(`Building Sanity application`).start()\n\n const trace = getCliTelemetry().trace(AppBuildTrace)\n trace.start()\n\n let autoUpdates\n if (autoUpdatesEnabled && !options.isWorkbenchApp) {\n autoUpdates = {\n cssUrls: autoUpdatesCssUrls,\n imports: autoUpdatesImports,\n vendor: await resolveVendorBuildConfig({cwd: workDir, isApp: true}),\n }\n }\n\n try {\n timer.start('bundleStudio')\n\n const bundle = await buildStaticFiles({\n appTitle: options.appTitle,\n autoUpdates,\n basePath,\n cwd: workDir,\n entry: options.entry,\n exposes: options.exposes,\n isApp: true,\n isBlueprints: options.isBlueprints,\n isWorkbenchApp: options.isWorkbenchApp,\n minify: options.minify,\n outputDir,\n reactCompiler: options.reactCompiler,\n schemaExtraction: options.schemaExtraction,\n sourceMap: options.sourceMap,\n vite: options.vite,\n workbenchAppId: options.workbenchAppId,\n })\n const mfManifest = options.isWorkbenchApp ? await readBuiltManifest(outputDir) : undefined\n\n trace.log({\n outputSize: bundle.chunks\n .flatMap((chunk) => chunk.modules.flatMap((mod) => mod.renderedLength))\n .reduce((sum, n) => sum + n, 0),\n })\n const buildDuration = timer.end('bundleStudio')\n\n spin.text = `Build Sanity application (${buildDuration.toFixed(0)}ms)`\n spin.succeed()\n\n if (options.stats) {\n output.log('\\nLargest module files:')\n output.log(formatModuleSizes(sortModulesBySize(bundle.chunks).slice(0, 15)))\n }\n\n trace.complete()\n return {mfManifest}\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: exitCodes.RUNTIME_ERROR})\n return {mfManifest: undefined}\n }\n}\n"],"names":["rm","path","styleText","exitCodes","getLocalPackageVersion","getCliTelemetry","isInteractive","confirm","getTimer","logSymbols","spinner","readBuiltManifest","parse","semverParse","AppBuildTrace","formatModuleSizes","sortModulesBySize","buildDebug","buildStaticFiles","getAutoUpdatesCssUrls","getAutoUpdatesImportMap","getAppEnvironmentVariables","handlePrereleaseVersions","resolveVendorBuildConfig","buildApp","options","appId","determineBasePath","eventListener","outDir","output","workDir","autoUpdatesEnabled","unattendedMode","timer","defaultOutputDir","resolve","join","outputDir","installedSdkVersion","installedSanityVersion","isMediaLibraryConfigBuild","exposes","config","appType","error","exit","RUNTIME_ERROR","mfManifest","undefined","autoUpdatesImports","autoUpdatesCssUrls","cleanSDKVersion","version","cleanSanityVersion","autoUpdatedPackages","name","cssFile","log","info","checkAppId","mismatched","unresolvedPrerelease","compareDependencyVersions","length","onPreReleaseInInteractiveAutoUpdate","onPreReleaseInNonInteractiveAutoUpdate","versionMismatchWarning","map","mod","pkg","installed","remote","shouldContinue","default","message","warn","envVarKeys","Object","keys","key","shouldClean","basePath","spin","start","force","recursive","cleanDuration","end","text","toFixed","succeed","trace","autoUpdates","isWorkbenchApp","cssUrls","imports","vendor","cwd","isApp","bundle","appTitle","entry","isBlueprints","minify","reactCompiler","schemaExtraction","sourceMap","vite","workbenchAppId","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,SAAS,QAAO,6BAA4B;AACpD,SAAQC,sBAAsB,QAAO,mCAAkC;AACvE,SAAQC,eAAe,QAAO,6BAA4B;AAE1D,SAAQC,aAAa,QAAO,wBAAuB;AACnD,SAAQC,OAAO,EAAEC,QAAQ,EAAEC,UAAU,EAAEC,OAAO,QAA6B,sBAAqB;AAChG,SAAQC,iBAAiB,QAA8B,8BAA6B;AACpF,SAAQC,SAASC,WAAW,QAAO,SAAQ;AAE3C,SAAQC,aAAa,QAAO,qCAAoC;AAEhE,SAAQC,iBAAiB,EAAEC,iBAAiB,QAAO,kCAAiC;AACpF,SAAQC,UAAU,QAAO,kBAAiB;AAC1C,SAAQC,gBAAgB,QAAO,wBAAuB;AAEtD,SAAQC,qBAAqB,EAAEC,uBAAuB,QAAO,+BAA8B;AAC3F,SAAQC,0BAA0B,QAAO,+BAA8B;AACvE,SAAQC,wBAAwB,QAAO,gCAA+B;AACtE,SAAQC,wBAAwB,QAAO,gCAA+B;AAuCtE;;;CAGC,GACD,OAAO,eAAeC,SACpBC,OAAqB;IAErBR,WAAW,CAAC,YAAY,CAAC;IAEzB,MAAM,EAACS,KAAK,EAAEC,iBAAiB,EAAEC,aAAa,EAAEC,MAAM,EAAEC,MAAM,EAAEC,OAAO,EAAC,GAAGN;IAC3E,IAAI,EAACO,kBAAkB,EAAC,GAAGP;IAC3B,MAAMQ,iBAAiBR,QAAQQ,cAAc;IAE7C,MAAMC,QAAQ1B;IAEd,MAAM2B,mBAAmBlC,KAAKmC,OAAO,CAACnC,KAAKoC,IAAI,CAACN,SAAS;IACzD,MAA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;QAAA;QAC7F,OAAO;YAACC,YAAYC;QAAS;IAC/B;AACF"}
|
|
@@ -3,11 +3,22 @@ import { decorateIndexWithBridgeScript } from '../decorateIndexWithBridgeScript.
|
|
|
3
3
|
import { decorateIndexWithStagingScript } from '../decorateIndexWithStagingScript.js';
|
|
4
4
|
import { renderDocument } from '../renderDocument.js';
|
|
5
5
|
const entryChunkId = '.sanity/runtime/app.js';
|
|
6
|
+
/**
|
|
7
|
+
* Logical name Vite gives the single CSS asset emitted when
|
|
8
|
+
* `build.cssCodeSplit` is false. `assetFileNames` can change the file written
|
|
9
|
+
* to disk; `names` / `originalFileNames` still carry this value.
|
|
10
|
+
*/ const CSS_BUNDLE_NAME = 'style.css';
|
|
6
11
|
export function sanityBuildEntries(options) {
|
|
7
12
|
const { autoUpdates, basePath, bridge = true, cwd, isApp } = options;
|
|
13
|
+
// Vite's default. `configResolved` replaces this with the resolved value,
|
|
14
|
+
// including a userland `vite` config that sets `build.cssCodeSplit: false`.
|
|
15
|
+
let cssCodeSplit = true;
|
|
8
16
|
return {
|
|
9
17
|
apply: 'build',
|
|
10
18
|
name: 'sanity/server/build-entries',
|
|
19
|
+
configResolved (resolved) {
|
|
20
|
+
cssCodeSplit = resolved.build.cssCodeSplit;
|
|
21
|
+
},
|
|
11
22
|
buildStart () {
|
|
12
23
|
this.emitFile({
|
|
13
24
|
id: entryChunkId,
|
|
@@ -15,64 +26,115 @@ export function sanityBuildEntries(options) {
|
|
|
15
26
|
type: 'chunk'
|
|
16
27
|
});
|
|
17
28
|
},
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const entryFileName = entryFile.fileName;
|
|
28
|
-
const entryPath = [
|
|
29
|
-
basePath.replace(/\/+$/, ''),
|
|
30
|
-
entryFileName
|
|
31
|
-
].join('/');
|
|
32
|
-
let css = [];
|
|
33
|
-
if (entryFile.viteMetadata?.importedCss) {
|
|
34
|
-
// Check all the top-level imports of the entryPoint to see if they have
|
|
35
|
-
// static CSS assets that need loading
|
|
36
|
-
css = [
|
|
37
|
-
...entryFile.viteMetadata.importedCss
|
|
38
|
-
];
|
|
39
|
-
for (const key of entryFile.imports){
|
|
40
|
-
// Traverse all CSS assets that isn't loaded by the runtime and
|
|
41
|
-
// need <link> tags in the HTML template
|
|
42
|
-
const entry = bundle[key];
|
|
43
|
-
const importedCss = entry && entry.type === 'chunk' ? entry.viteMetadata.importedCss : undefined;
|
|
44
|
-
if (importedCss) {
|
|
45
|
-
css.push(...importedCss);
|
|
46
|
-
}
|
|
29
|
+
// `vite:css-post` emits the combined stylesheet during its own
|
|
30
|
+
// `generateBundle`. That hook is unordered, so this one has to run after
|
|
31
|
+
// it (`order: 'post'`) or the asset is not in the bundle yet.
|
|
32
|
+
generateBundle: {
|
|
33
|
+
async handler (_options, outputBundle) {
|
|
34
|
+
const bundle = outputBundle;
|
|
35
|
+
const entryFile = Object.values(bundle).find((file)=>file.type === 'chunk' && file.name === 'sanity' && file.facadeModuleId?.endsWith(entryChunkId));
|
|
36
|
+
if (!entryFile) {
|
|
37
|
+
throw new Error(`Failed to find entry file in bundle (${entryChunkId})`);
|
|
47
38
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
// chunks emitted by this very build (hashed filenames, resolved from the
|
|
51
|
-
// bundle) with the module-CDN imports for auto-updated packages.
|
|
52
|
-
const importMap = autoUpdates ? {
|
|
53
|
-
imports: {
|
|
54
|
-
...createVendorImportMapFromBundle(bundle, autoUpdates.vendor.specifiersByChunkName, basePath),
|
|
55
|
-
...autoUpdates.imports
|
|
39
|
+
if (entryFile.type !== 'chunk') {
|
|
40
|
+
throw new Error('Entry file is not a chunk');
|
|
56
41
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
42
|
+
const entryFileName = entryFile.fileName;
|
|
43
|
+
const entryPath = [
|
|
44
|
+
basePath.replace(/\/+$/, ''),
|
|
45
|
+
entryFileName
|
|
46
|
+
].join('/');
|
|
47
|
+
const css = collectStylesheets(entryFile, bundle, cssCodeSplit);
|
|
48
|
+
// For auto-updating studios/apps the import map combines the vendor
|
|
49
|
+
// chunks emitted by this very build (hashed filenames, resolved from the
|
|
50
|
+
// bundle) with the module-CDN imports for auto-updated packages.
|
|
51
|
+
const importMap = autoUpdates ? {
|
|
52
|
+
imports: {
|
|
53
|
+
...createVendorImportMapFromBundle(bundle, autoUpdates.vendor.specifiersByChunkName, basePath),
|
|
54
|
+
...autoUpdates.imports
|
|
55
|
+
}
|
|
56
|
+
} : undefined;
|
|
57
|
+
const html = await renderDocument({
|
|
58
|
+
autoUpdatesCssUrls: autoUpdates?.cssUrls,
|
|
59
|
+
importMap,
|
|
60
|
+
isApp,
|
|
61
|
+
props: {
|
|
62
|
+
basePath,
|
|
63
|
+
css,
|
|
64
|
+
entryPath
|
|
65
|
+
},
|
|
66
|
+
studioRootPath: cwd
|
|
67
|
+
});
|
|
68
|
+
this.emitFile({
|
|
69
|
+
fileName: 'index.html',
|
|
70
|
+
source: decorateIndexWithStagingScript(bridge ? decorateIndexWithBridgeScript(html) : html),
|
|
71
|
+
type: 'asset'
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
order: 'post'
|
|
74
75
|
}
|
|
75
76
|
};
|
|
76
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Stylesheets the document should link.
|
|
80
|
+
*
|
|
81
|
+
* With CSS code splitting, Vite records each chunk's styles on
|
|
82
|
+
* `viteMetadata.importedCss` (including the chunks the entry statically
|
|
83
|
+
* imports). With `cssCodeSplit: false`, Vite emits one combined asset instead
|
|
84
|
+
* and never adds it to `importedCss`. `vite:build-html` finds that asset by
|
|
85
|
+
* its bundle name (`style.css`); mirror that, and if Rolldown omits `names` /
|
|
86
|
+
* `originalFileNames`, link every emitted `.css` asset so the document is not
|
|
87
|
+
* unstyled.
|
|
88
|
+
*/ function collectStylesheets(entryFile, bundle, cssCodeSplit) {
|
|
89
|
+
const css = collectImportedCss(entryFile, bundle);
|
|
90
|
+
if (cssCodeSplit) return css;
|
|
91
|
+
const seen = new Set(css);
|
|
92
|
+
for (const fileName of collectCombinedStylesheets(bundle)){
|
|
93
|
+
if (seen.has(fileName)) continue;
|
|
94
|
+
seen.add(fileName);
|
|
95
|
+
css.push(fileName);
|
|
96
|
+
}
|
|
97
|
+
return css;
|
|
98
|
+
}
|
|
99
|
+
function collectImportedCss(entryFile, bundle) {
|
|
100
|
+
const css = cssFilesFromChunk(entryFile);
|
|
101
|
+
for (const key of entryFile.imports){
|
|
102
|
+
const imported = bundle[key];
|
|
103
|
+
if (imported?.type === 'chunk') css.push(...cssFilesFromChunk(imported));
|
|
104
|
+
}
|
|
105
|
+
return css;
|
|
106
|
+
}
|
|
107
|
+
function cssFilesFromChunk(chunk) {
|
|
108
|
+
const imported = chunk.viteMetadata?.importedCss;
|
|
109
|
+
if (!imported) return [];
|
|
110
|
+
return [
|
|
111
|
+
...imported
|
|
112
|
+
];
|
|
113
|
+
}
|
|
114
|
+
function collectCombinedStylesheets(bundle) {
|
|
115
|
+
const cssAssets = Object.values(bundle).filter((file)=>isCssAsset(file));
|
|
116
|
+
const named = cssAssets.filter((asset)=>isCombinedCssBundle(asset));
|
|
117
|
+
const chosen = named.length > 0 ? named : cssAssets;
|
|
118
|
+
return chosen.flatMap((asset)=>asset.fileName ? [
|
|
119
|
+
asset.fileName
|
|
120
|
+
] : []);
|
|
121
|
+
}
|
|
122
|
+
function isCssAsset(file) {
|
|
123
|
+
return file.type === 'asset' && typeof file.fileName === 'string' && file.fileName.endsWith('.css');
|
|
124
|
+
}
|
|
125
|
+
function isCombinedCssBundle(asset) {
|
|
126
|
+
return assetIdentifiers(asset).some((name)=>baseName(name) === CSS_BUNDLE_NAME);
|
|
127
|
+
}
|
|
128
|
+
function assetIdentifiers(asset) {
|
|
129
|
+
return [
|
|
130
|
+
asset.name,
|
|
131
|
+
asset.originalFileName,
|
|
132
|
+
...asset.names ?? [],
|
|
133
|
+
...asset.originalFileNames ?? []
|
|
134
|
+
].filter((name)=>typeof name === 'string' && name.length > 0);
|
|
135
|
+
}
|
|
136
|
+
function baseName(fileName) {
|
|
137
|
+
return fileName.split(/[/\\]/).pop() ?? fileName;
|
|
138
|
+
}
|
|
77
139
|
|
|
78
140
|
//# sourceMappingURL=plugin-sanity-build-entries.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/actions/build/vite/plugin-sanity-build-entries.ts"],"sourcesContent":["import {type ChunkMetadata, type Plugin} from 'vite'\n\nimport {type AutoUpdatesBuildConfig} from '../autoUpdates.js'\nimport {createVendorImportMapFromBundle} from '../createVendorImportMapFromBundle.js'\nimport {decorateIndexWithBridgeScript} from '../decorateIndexWithBridgeScript.js'\nimport {decorateIndexWithStagingScript} from '../decorateIndexWithStagingScript.js'\nimport {renderDocument} from '../renderDocument.js'\n\ninterface ViteOutputBundle {\n [fileName: string]: ViteRenderedAsset | ViteRenderedChunk\n}\n\ninterface ViteRenderedAsset {\n type: 'asset'\n}\n\ninterface ViteRenderedChunk {\n code: string\n facadeModuleId: string | null\n fileName: string\n imports: string[]\n isEntry: boolean\n name: string\n type: 'chunk'\n viteMetadata: ChunkMetadata\n}\n\nconst entryChunkId = '.sanity/runtime/app.js'\n\nexport function sanityBuildEntries(options: {\n autoUpdates?: AutoUpdatesBuildConfig\n basePath: string\n /**\n * Injects the core-ui bridge script into the emitted `index.html`. Defaults to\n * `true`. Workbench remotes serve themselves standalone and pass `false`.\n */\n bridge?: boolean\n cwd: string\n isApp?: boolean\n}): Plugin {\n const {autoUpdates, basePath, bridge = true, cwd, isApp} = options\n\n return {\n apply: 'build',\n name: 'sanity/server/build-entries',\n\n buildStart() {\n this.emitFile({\n id: entryChunkId,\n name: 'sanity',\n type: 'chunk',\n })\n },\n\n async generateBundle(_options, outputBundle) {\n const bundle = outputBundle as unknown as ViteOutputBundle\n const entryFile = Object.values(bundle).find(\n (file) =>\n file.type === 'chunk' &&\n file.name === 'sanity' &&\n file.facadeModuleId?.endsWith(entryChunkId),\n )\n\n if (!entryFile) {\n throw new Error(`Failed to find entry file in bundle (${entryChunkId})`)\n }\n\n if (entryFile.type !== 'chunk') {\n throw new Error('Entry file is not a chunk')\n }\n\n const entryFileName = entryFile.fileName\n const entryPath = [basePath.replace(/\\/+$/, ''), entryFileName].join('/')\n\n let css: string[] = []\n if (entryFile.viteMetadata?.importedCss) {\n // Check all the top-level imports of the entryPoint to see if they have\n // static CSS assets that need loading\n css = [...entryFile.viteMetadata.importedCss]\n for (const key of entryFile.imports) {\n // Traverse all CSS assets that isn't loaded by the runtime and\n // need <link> tags in the HTML template\n const entry = bundle[key]\n const importedCss =\n entry && entry.type === 'chunk' ? entry.viteMetadata.importedCss : undefined\n\n if (importedCss) {\n css.push(...importedCss)\n }\n }\n }\n\n // For auto-updating studios/apps the import map combines the vendor\n // chunks emitted by this very build (hashed filenames, resolved from the\n // bundle) with the module-CDN imports for auto-updated packages.\n const importMap = autoUpdates\n ? {\n imports: {\n ...createVendorImportMapFromBundle(\n bundle,\n autoUpdates.vendor.specifiersByChunkName,\n basePath,\n ),\n ...autoUpdates.imports,\n },\n }\n : undefined\n\n const html = await renderDocument({\n autoUpdatesCssUrls: autoUpdates?.cssUrls,\n importMap,\n isApp,\n props: {\n basePath,\n css,\n entryPath,\n },\n studioRootPath: cwd,\n })\n\n this.emitFile({\n fileName: 'index.html',\n source: decorateIndexWithStagingScript(bridge ? decorateIndexWithBridgeScript(html) : html),\n type: 'asset',\n })\n },\n }\n}\n"],"names":["createVendorImportMapFromBundle","decorateIndexWithBridgeScript","decorateIndexWithStagingScript","renderDocument","entryChunkId","sanityBuildEntries","options","autoUpdates","basePath","bridge","cwd","isApp","apply","name","buildStart","emitFile","id","type","generateBundle","_options","outputBundle","bundle","entryFile","Object","values","find","file","facadeModuleId","endsWith","Error","entryFileName","fileName","entryPath","replace","join","css","viteMetadata","importedCss","key","imports","entry","undefined","push","importMap","vendor","specifiersByChunkName","html","autoUpdatesCssUrls","cssUrls","props","studioRootPath","source"],"mappings":"AAGA,SAAQA,+BAA+B,QAAO,wCAAuC;AACrF,SAAQC,6BAA6B,QAAO,sCAAqC;AACjF,SAAQC,8BAA8B,QAAO,uCAAsC;AACnF,SAAQC,cAAc,QAAO,uBAAsB;AAqBnD,MAAMC,eAAe;AAErB,OAAO,SAASC,mBAAmBC,OAUlC;IACC,MAAM,EAACC,WAAW,EAAEC,QAAQ,EAAEC,SAAS,IAAI,EAAEC,GAAG,EAAEC,KAAK,EAAC,GAAGL;IAE3D,OAAO;QACLM,OAAO;QACPC,MAAM;QAENC;YACE,IAAI,CAACC,QAAQ,CAAC;gBACZC,IAAIZ;gBACJS,MAAM;gBACNI,MAAM;YACR;QACF;QAEA,MAAMC,gBAAeC,QAAQ,EAAEC,YAAY;YACzC,MAAMC,SAASD;YACf,MAAME,YAAYC,OAAOC,MAAM,CAACH,QAAQI,IAAI,CAC1C,CAACC,OACCA,KAAKT,IAAI,KAAK,WACdS,KAAKb,IAAI,KAAK,YACda,KAAKC,cAAc,EAAEC,SAASxB;YAGlC,IAAI,CAACkB,WAAW;gBACd,MAAM,IAAIO,MAAM,CAAC,qCAAqC,EAAEzB,aAAa,CAAC,CAAC;YACzE;YAEA,IAAIkB,UAAUL,IAAI,KAAK,SAAS;gBAC9B,MAAM,IAAIY,MAAM;YAClB;YAEA,MAAMC,gBAAgBR,UAAUS,QAAQ;YACxC,MAAMC,YAAY;gBAACxB,SAASyB,OAAO,CAAC,QAAQ;gBAAKH;aAAc,CAACI,IAAI,CAAC;YAErE,IAAIC,MAAgB,EAAE;YACtB,IAAIb,UAAUc,YAAY,EAAEC,aAAa;gBACvC,wEAAwE;gBACxE,sCAAsC;gBACtCF,MAAM;uBAAIb,UAAUc,YAAY,CAACC,WAAW;iBAAC;gBAC7C,KAAK,MAAMC,OAAOhB,UAAUiB,OAAO,CAAE;oBACnC,+DAA+D;oBAC/D,wCAAwC;oBACxC,MAAMC,QAAQnB,MAAM,CAACiB,IAAI;oBACzB,MAAMD,cACJG,SAASA,MAAMvB,IAAI,KAAK,UAAUuB,MAAMJ,YAAY,CAACC,WAAW,GAAGI;oBAErE,IAAIJ,aAAa;wBACfF,IAAIO,IAAI,IAAIL;oBACd;gBACF;YACF;YAEA,oEAAoE;YACpE,yEAAyE;YACzE,iEAAiE;YACjE,MAAMM,YAAYpC,cACd;gBACEgC,SAAS;oBACP,GAAGvC,gCACDqB,QACAd,YAAYqC,MAAM,CAACC,qBAAqB,EACxCrC,SACD;oBACD,GAAGD,YAAYgC,OAAO;gBACxB;YACF,IACAE;YAEJ,MAAMK,OAAO,MAAM3C,eAAe;gBAChC4C,oBAAoBxC,aAAayC;gBACjCL;gBACAhC;gBACAsC,OAAO;oBACLzC;oBACA2B;oBACAH;gBACF;gBACAkB,gBAAgBxC;YAClB;YAEA,IAAI,CAACK,QAAQ,CAAC;gBACZgB,UAAU;gBACVoB,QAAQjD,+BAA+BO,SAASR,8BAA8B6C,QAAQA;gBACtF7B,MAAM;YACR;QACF;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/actions/build/vite/plugin-sanity-build-entries.ts"],"sourcesContent":["import {type ChunkMetadata, type Plugin} from 'vite'\n\nimport {type AutoUpdatesBuildConfig} from '../autoUpdates.js'\nimport {createVendorImportMapFromBundle} from '../createVendorImportMapFromBundle.js'\nimport {decorateIndexWithBridgeScript} from '../decorateIndexWithBridgeScript.js'\nimport {decorateIndexWithStagingScript} from '../decorateIndexWithStagingScript.js'\nimport {renderDocument} from '../renderDocument.js'\n\ninterface ViteOutputBundle {\n [fileName: string]: ViteRenderedAsset | ViteRenderedChunk\n}\n\ninterface ViteRenderedAsset {\n type: 'asset'\n\n fileName?: string\n name?: string | null\n names?: string[]\n originalFileName?: string | null\n originalFileNames?: string[]\n}\n\ninterface ViteRenderedChunk {\n code: string\n facadeModuleId: string | null\n fileName: string\n imports: string[]\n isEntry: boolean\n name: string\n type: 'chunk'\n\n /**\n * Populated by Vite when `build.cssCodeSplit` is true. Rolldown-based Vite\n * (Vite 7/8 and `rolldown-vite`) may omit it, or leave `importedCss` empty,\n * for the single stylesheet emitted when code splitting is disabled.\n */\n viteMetadata?: ChunkMetadata\n}\n\nconst entryChunkId = '.sanity/runtime/app.js'\n\n/**\n * Logical name Vite gives the single CSS asset emitted when\n * `build.cssCodeSplit` is false. `assetFileNames` can change the file written\n * to disk; `names` / `originalFileNames` still carry this value.\n */\nconst CSS_BUNDLE_NAME = 'style.css'\n\nexport function sanityBuildEntries(options: {\n autoUpdates?: AutoUpdatesBuildConfig\n basePath: string\n /**\n * Injects the core-ui bridge script into the emitted `index.html`. Defaults to\n * `true`. Workbench remotes serve themselves standalone and pass `false`.\n */\n bridge?: boolean\n cwd: string\n isApp?: boolean\n}): Plugin {\n const {autoUpdates, basePath, bridge = true, cwd, isApp} = options\n // Vite's default. `configResolved` replaces this with the resolved value,\n // including a userland `vite` config that sets `build.cssCodeSplit: false`.\n let cssCodeSplit = true\n\n return {\n apply: 'build',\n name: 'sanity/server/build-entries',\n\n configResolved(resolved) {\n cssCodeSplit = resolved.build.cssCodeSplit\n },\n\n buildStart() {\n this.emitFile({\n id: entryChunkId,\n name: 'sanity',\n type: 'chunk',\n })\n },\n\n // `vite:css-post` emits the combined stylesheet during its own\n // `generateBundle`. That hook is unordered, so this one has to run after\n // it (`order: 'post'`) or the asset is not in the bundle yet.\n generateBundle: {\n async handler(_options, outputBundle) {\n const bundle = outputBundle as unknown as ViteOutputBundle\n const entryFile = Object.values(bundle).find(\n (file) =>\n file.type === 'chunk' &&\n file.name === 'sanity' &&\n file.facadeModuleId?.endsWith(entryChunkId),\n )\n\n if (!entryFile) {\n throw new Error(`Failed to find entry file in bundle (${entryChunkId})`)\n }\n\n if (entryFile.type !== 'chunk') {\n throw new Error('Entry file is not a chunk')\n }\n\n const entryFileName = entryFile.fileName\n const entryPath = [basePath.replace(/\\/+$/, ''), entryFileName].join('/')\n const css = collectStylesheets(entryFile, bundle, cssCodeSplit)\n\n // For auto-updating studios/apps the import map combines the vendor\n // chunks emitted by this very build (hashed filenames, resolved from the\n // bundle) with the module-CDN imports for auto-updated packages.\n const importMap = autoUpdates\n ? {\n imports: {\n ...createVendorImportMapFromBundle(\n bundle,\n autoUpdates.vendor.specifiersByChunkName,\n basePath,\n ),\n ...autoUpdates.imports,\n },\n }\n : undefined\n\n const html = await renderDocument({\n autoUpdatesCssUrls: autoUpdates?.cssUrls,\n importMap,\n isApp,\n props: {\n basePath,\n css,\n entryPath,\n },\n studioRootPath: cwd,\n })\n\n this.emitFile({\n fileName: 'index.html',\n source: decorateIndexWithStagingScript(\n bridge ? decorateIndexWithBridgeScript(html) : html,\n ),\n type: 'asset',\n })\n },\n order: 'post',\n },\n }\n}\n\n/**\n * Stylesheets the document should link.\n *\n * With CSS code splitting, Vite records each chunk's styles on\n * `viteMetadata.importedCss` (including the chunks the entry statically\n * imports). With `cssCodeSplit: false`, Vite emits one combined asset instead\n * and never adds it to `importedCss`. `vite:build-html` finds that asset by\n * its bundle name (`style.css`); mirror that, and if Rolldown omits `names` /\n * `originalFileNames`, link every emitted `.css` asset so the document is not\n * unstyled.\n */\nfunction collectStylesheets(\n entryFile: ViteRenderedChunk,\n bundle: ViteOutputBundle,\n cssCodeSplit: boolean,\n): string[] {\n const css = collectImportedCss(entryFile, bundle)\n if (cssCodeSplit) return css\n\n const seen = new Set(css)\n for (const fileName of collectCombinedStylesheets(bundle)) {\n if (seen.has(fileName)) continue\n seen.add(fileName)\n css.push(fileName)\n }\n return css\n}\n\nfunction collectImportedCss(entryFile: ViteRenderedChunk, bundle: ViteOutputBundle): string[] {\n const css = cssFilesFromChunk(entryFile)\n for (const key of entryFile.imports) {\n const imported = bundle[key]\n if (imported?.type === 'chunk') css.push(...cssFilesFromChunk(imported))\n }\n return css\n}\n\nfunction cssFilesFromChunk(chunk: ViteRenderedChunk): string[] {\n const imported = chunk.viteMetadata?.importedCss\n if (!imported) return []\n return [...imported]\n}\n\nfunction collectCombinedStylesheets(bundle: ViteOutputBundle): string[] {\n const cssAssets = Object.values(bundle).filter((file) => isCssAsset(file))\n const named = cssAssets.filter((asset) => isCombinedCssBundle(asset))\n const chosen = named.length > 0 ? named : cssAssets\n return chosen.flatMap((asset) => (asset.fileName ? [asset.fileName] : []))\n}\n\nfunction isCssAsset(file: ViteRenderedAsset | ViteRenderedChunk): file is ViteRenderedAsset {\n return (\n file.type === 'asset' && typeof file.fileName === 'string' && file.fileName.endsWith('.css')\n )\n}\n\nfunction isCombinedCssBundle(asset: ViteRenderedAsset): boolean {\n return assetIdentifiers(asset).some((name) => baseName(name) === CSS_BUNDLE_NAME)\n}\n\nfunction assetIdentifiers(asset: ViteRenderedAsset): string[] {\n return [\n asset.name,\n asset.originalFileName,\n ...(asset.names ?? []),\n ...(asset.originalFileNames ?? []),\n ].filter((name): name is string => typeof name === 'string' && name.length > 0)\n}\n\nfunction baseName(fileName: string): string {\n return fileName.split(/[/\\\\]/).pop() ?? fileName\n}\n"],"names":["createVendorImportMapFromBundle","decorateIndexWithBridgeScript","decorateIndexWithStagingScript","renderDocument","entryChunkId","CSS_BUNDLE_NAME","sanityBuildEntries","options","autoUpdates","basePath","bridge","cwd","isApp","cssCodeSplit","apply","name","configResolved","resolved","build","buildStart","emitFile","id","type","generateBundle","handler","_options","outputBundle","bundle","entryFile","Object","values","find","file","facadeModuleId","endsWith","Error","entryFileName","fileName","entryPath","replace","join","css","collectStylesheets","importMap","imports","vendor","specifiersByChunkName","undefined","html","autoUpdatesCssUrls","cssUrls","props","studioRootPath","source","order","collectImportedCss","seen","Set","collectCombinedStylesheets","has","add","push","cssFilesFromChunk","key","imported","chunk","viteMetadata","importedCss","cssAssets","filter","isCssAsset","named","asset","isCombinedCssBundle","chosen","length","flatMap","assetIdentifiers","some","baseName","originalFileName","names","originalFileNames","split","pop"],"mappings":"AAGA,SAAQA,+BAA+B,QAAO,wCAAuC;AACrF,SAAQC,6BAA6B,QAAO,sCAAqC;AACjF,SAAQC,8BAA8B,QAAO,uCAAsC;AACnF,SAAQC,cAAc,QAAO,uBAAsB;AAiCnD,MAAMC,eAAe;AAErB;;;;CAIC,GACD,MAAMC,kBAAkB;AAExB,OAAO,SAASC,mBAAmBC,OAUlC;IACC,MAAM,EAACC,WAAW,EAAEC,QAAQ,EAAEC,SAAS,IAAI,EAAEC,GAAG,EAAEC,KAAK,EAAC,GAAGL;IAC3D,0EAA0E;IAC1E,4EAA4E;IAC5E,IAAIM,eAAe;IAEnB,OAAO;QACLC,OAAO;QACPC,MAAM;QAENC,gBAAeC,QAAQ;YACrBJ,eAAeI,SAASC,KAAK,CAACL,YAAY;QAC5C;QAEAM;YACE,IAAI,CAACC,QAAQ,CAAC;gBACZC,IAAIjB;gBACJW,MAAM;gBACNO,MAAM;YACR;QACF;QAEA,+DAA+D;QAC/D,yEAAyE;QACzE,8DAA8D;QAC9DC,gBAAgB;YACd,MAAMC,SAAQC,QAAQ,EAAEC,YAAY;gBAClC,MAAMC,SAASD;gBACf,MAAME,YAAYC,OAAOC,MAAM,CAACH,QAAQI,IAAI,CAC1C,CAACC,OACCA,KAAKV,IAAI,KAAK,WACdU,KAAKjB,IAAI,KAAK,YACdiB,KAAKC,cAAc,EAAEC,SAAS9B;gBAGlC,IAAI,CAACwB,WAAW;oBACd,MAAM,IAAIO,MAAM,CAAC,qCAAqC,EAAE/B,aAAa,CAAC,CAAC;gBACzE;gBAEA,IAAIwB,UAAUN,IAAI,KAAK,SAAS;oBAC9B,MAAM,IAAIa,MAAM;gBAClB;gBAEA,MAAMC,gBAAgBR,UAAUS,QAAQ;gBACxC,MAAMC,YAAY;oBAAC7B,SAAS8B,OAAO,CAAC,QAAQ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IACjD,MAAMD,WAAWC,MAAMC,YAAY,EAAEC;IACrC,IAAI,CAACH,UAAU,OAAO,EAAE;IACxB,OAAO;WAAIA;KAAS;AACtB;AAEA,SAASN,2BAA2B/B,MAAwB;IAC1D,MAAMyC,YAAYvC,OAAOC,MAAM,CAACH,QAAQ0C,MAAM,CAAC,CAACrC,OAASsC,WAAWtC;IACpE,MAAMuC,QAAQH,UAAUC,MAAM,CAAC,CAACG,QAAUC,oBAAoBD;IAC9D,MAAME,SAASH,MAAMI,MAAM,GAAG,IAAIJ,QAAQH;IAC1C,OAAOM,OAAOE,OAAO,CAAC,CAACJ,QAAWA,MAAMnC,QAAQ,GAAG;YAACmC,MAAMnC,QAAQ;SAAC,GAAG,EAAE;AAC1E;AAEA,SAASiC,WAAWtC,IAA2C;IAC7D,OACEA,KAAKV,IAAI,KAAK,WAAW,OAAOU,KAAKK,QAAQ,KAAK,YAAYL,KAAKK,QAAQ,CAACH,QAAQ,CAAC;AAEzF;AAEA,SAASuC,oBAAoBD,KAAwB;IACnD,OAAOK,iBAAiBL,OAAOM,IAAI,CAAC,CAAC/D,OAASgE,SAAShE,UAAUV;AACnE;AAEA,SAASwE,iBAAiBL,KAAwB;IAChD,OAAO;QACLA,MAAMzD,IAAI;QACVyD,MAAMQ,gBAAgB;WAClBR,MAAMS,KAAK,IAAI,EAAE;WACjBT,MAAMU,iBAAiB,IAAI,EAAE;KAClC,CAACb,MAAM,CAAC,CAACtD,OAAyB,OAAOA,SAAS,YAAYA,KAAK4D,MAAM,GAAG;AAC/E;AAEA,SAASI,SAAS1C,QAAgB;IAChC,OAAOA,SAAS8C,KAAK,CAAC,SAASC,GAAG,MAAM/C;AAC1C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/manifest/types.ts"],"sourcesContent":["import {type SanityDocumentLike} from '@sanity/types'\nimport {type MediaLibraryConfig} from 'sanity'\nimport {z} from 'zod/mini'\n\nexport const SANITY_WORKSPACE_SCHEMA_ID_PREFIX = '_.schemas'\nexport const CURRENT_WORKSPACE_SCHEMA_VERSION = '2025-05-01'\n\nexport type ManifestSerializable =\n | boolean\n | ManifestSerializable[]\n | number\n | string\n | {[k: string]: ManifestSerializable}\n\nexport interface CreateManifest {\n createdAt: string\n studioVersion: string | null\n version: number\n workspaces: ManifestWorkspaceFile[]\n}\n\n// The studio/app manifest contract lives in `@sanity/cli-core` so the CLI and\n// the workbench dev-server registry validate against the same schemas without\n// depending on each other.\nexport {type CoreAppManifest, coreAppManifestSchema, type StudioManifest} from '@sanity/cli-core'\n\nexport interface ManifestWorkspaceFile extends Omit<CreateWorkspaceManifest, 'schema' | 'tools'> {\n schema: string // filename\n tools: string // filename\n}\n\nexport interface CreateWorkspaceManifest {\n basePath: string\n dataset: string\n /**\n * returns null in the case of the icon not being able to be stringified\n */\n icon: string | null\n name: string\n projectId: string\n schema: ManifestSchemaType[]\n tools: ManifestTool[]\n\n mediaLibrary?: MediaLibraryConfig\n subtitle?: string\n title?: string\n}\n\nexport interface ManifestSchemaType {\n name: string\n type: string\n\n deprecated?: {\n reason: string\n }\n fields?: ManifestField[]\n fieldsets?: ManifestFieldset[]\n hidden?: 'conditional' | boolean\n lists?: ManifestTitledValue[]\n //portable text\n marks?: {\n annotations?: ManifestArrayMember[]\n decorators?: ManifestTitledValue[]\n }\n of?: ManifestArrayMember[]\n options?: Record<string, ManifestSerializable>\n preview?: {\n select: Record<string, string>\n }\n readOnly?: 'conditional' | boolean\n styles?: ManifestTitledValue[]\n title?: string\n to?: ManifestReferenceMember[]\n validation?: ManifestValidationGroup[]\n\n // userland (assignable to ManifestSerializable | undefined)\n // not included to add some typesafty to extractManifest\n // [index: string]: unknown\n}\n\nexport interface ManifestFieldset {\n [index: string]: ManifestSerializable | undefined\n name: string\n\n title?: string\n}\n\nexport interface ManifestTitledValue {\n value: string\n\n title?: string\n}\n\ntype ManifestArrayMember = Omit<ManifestSchemaType, 'name'> & {name?: string}\ntype ManifestReferenceMember = Omit<ManifestSchemaType, 'name'> & {name?: string}\nexport type ManifestField = ManifestSchemaType & {fieldset?: string}\n\nexport interface ManifestValidationGroup {\n rules: ManifestValidationRule[]\n\n level?: 'error' | 'info' | 'warning'\n message?: string\n}\n\nexport type ManifestValidationRule = {\n [index: string]: ManifestSerializable | undefined\n constraint?: ManifestSerializable\n flag: string\n}\n\nexport interface ManifestTool {\n /**\n * returns null in the case of the icon not being able to be stringified\n */\n icon: string | null\n name: string\n title: string\n type: string | null\n}\n\nexport type DefaultWorkspaceSchemaId = `${typeof SANITY_WORKSPACE_SCHEMA_ID_PREFIX}.${string}`\ntype PrefixedWorkspaceSchemaId = `${DefaultWorkspaceSchemaId}.${string}`\nexport type WorkspaceSchemaId = DefaultWorkspaceSchemaId | PrefixedWorkspaceSchemaId\n\nexport interface StoredWorkspaceSchema extends SanityDocumentLike {\n _id: WorkspaceSchemaId\n _type: 'system.schema'\n /**\n * The API expects JSON coming in, but will store a string to save on attribute paths.\n * Consumers must use JSON.parse on the value, but we deploy to the API using ManifestSchemaType[]\n */\n schema: ManifestSchemaType[] | string\n /* api-like version string: date at which the format had a meaningful change */\n version: typeof CURRENT_WORKSPACE_SCHEMA_VERSION | undefined\n workspace: {\n name: string\n title?: string\n }\n\n tag?: string\n}\n\nexport const extractManifestWorkerData = z.object({configPath: z.string(), workDir: z.string()})\n\nexport type ExtractManifestWorkerData = z.infer<typeof extractManifestWorkerData>\n"],"names":["z","SANITY_WORKSPACE_SCHEMA_ID_PREFIX","CURRENT_WORKSPACE_SCHEMA_VERSION","coreAppManifestSchema","extractManifestWorkerData","object","configPath","string","workDir"],"mappings":"AAEA,SAAQA,CAAC,QAAO,WAAU;AAE1B,OAAO,MAAMC,oCAAoC,YAAW;AAC5D,OAAO,MAAMC,mCAAmC,aAAY;AAgB5D,8EAA8E;AAC9E,8EAA8E;AAC9E,2BAA2B;AAC3B,SAA8BC,qBAAqB,QAA4B,mBAAkB;AAsHjG,OAAO,MAAMC,4BAA4BJ,EAAEK,MAAM,CAAC;IAACC,YAAYN,EAAEO,MAAM;IAAIC,SAASR,EAAEO,MAAM;AAAE,GAAE"}
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/manifest/types.ts"],"sourcesContent":["import {type SanityDocumentLike} from '@sanity/types'\nimport {type MediaLibraryConfig} from 'sanity'\nimport {z} from 'zod/mini'\n\nexport const SANITY_WORKSPACE_SCHEMA_ID_PREFIX = '_.schemas'\nexport const CURRENT_WORKSPACE_SCHEMA_VERSION = '2025-05-01'\n\nexport type ManifestSerializable =\n | boolean\n | ManifestSerializable[]\n | number\n | string\n | {[k: string]: ManifestSerializable}\n\nexport interface CreateManifest {\n createdAt: string\n studioVersion: string | null\n version: number\n workspaces: ManifestWorkspaceFile[]\n}\n\n// The studio/app manifest contract lives in `@sanity/cli-core` so the CLI and\n// the workbench dev-server registry validate against the same schemas without\n// depending on each other.\nexport {type CoreAppManifest, coreAppManifestSchema, type StudioManifest} from '@sanity/cli-core'\n\nexport interface ManifestWorkspaceFile extends Omit<CreateWorkspaceManifest, 'schema' | 'tools'> {\n schema: string // filename\n tools: string // filename\n}\n\nexport interface CreateWorkspaceManifest {\n basePath: string\n dataset: string\n /**\n * returns null in the case of the icon not being able to be stringified\n */\n icon: string | null\n name: string\n projectId: string\n schema: ManifestSchemaType[]\n tools: ManifestTool[]\n\n mediaLibrary?: MediaLibraryConfig\n subtitle?: string\n title?: string\n}\n\nexport interface ManifestSchemaType {\n name: string\n type: string\n\n deprecated?: {\n reason: string\n }\n fields?: ManifestField[]\n fieldsets?: ManifestFieldset[]\n hidden?: 'conditional' | boolean\n lists?: ManifestTitledValue[]\n //portable text\n marks?: {\n annotations?: ManifestArrayMember[]\n decorators?: ManifestTitledValue[]\n }\n of?: ManifestArrayMember[]\n options?: Record<string, ManifestSerializable>\n preview?: {\n select: Record<string, string>\n }\n readOnly?: 'conditional' | boolean\n styles?: ManifestTitledValue[]\n title?: string\n to?: ManifestReferenceMember[]\n validation?: ManifestValidationGroup[]\n\n // userland (assignable to ManifestSerializable | undefined)\n // not included to add some typesafty to extractManifest\n // [index: string]: unknown\n}\n\nexport interface ManifestFieldset {\n [index: string]: ManifestSerializable | undefined\n name: string\n\n title?: string\n}\n\nexport interface ManifestTitledValue {\n value: string\n\n title?: string\n}\n\ntype ManifestArrayMember = Omit<ManifestSchemaType, 'name'> & {name?: string}\ntype ManifestReferenceMember = Omit<ManifestSchemaType, 'name'> & {name?: string}\nexport type ManifestField = ManifestSchemaType & {fieldset?: string}\n\nexport interface ManifestValidationGroup {\n rules: ManifestValidationRule[]\n\n level?: 'error' | 'info' | 'warning'\n message?: string\n}\n\nexport type ManifestValidationRule = {\n [index: string]: ManifestSerializable | undefined\n constraint?: ManifestSerializable\n flag: string\n}\n\nexport interface ManifestTool {\n /**\n * returns null in the case of the icon not being able to be stringified\n */\n icon: string | null\n name: string\n title: string\n type: string | null\n}\n\nexport type DefaultWorkspaceSchemaId = `${typeof SANITY_WORKSPACE_SCHEMA_ID_PREFIX}.${string}`\ntype PrefixedWorkspaceSchemaId = `${DefaultWorkspaceSchemaId}.${string}`\nexport type WorkspaceSchemaId = DefaultWorkspaceSchemaId | PrefixedWorkspaceSchemaId\n\nexport interface StoredWorkspaceSchema extends SanityDocumentLike {\n _id: WorkspaceSchemaId\n _type: 'system.schema'\n /**\n * The API expects JSON coming in, but will store a string to save on attribute paths.\n * Consumers must use JSON.parse on the value, but we deploy to the API using ManifestSchemaType[]\n */\n schema: ManifestSchemaType[] | string\n /* api-like version string: date at which the format had a meaningful change */\n version: typeof CURRENT_WORKSPACE_SCHEMA_VERSION | undefined\n workspace: {\n name: string\n title?: string\n }\n\n tag?: string\n}\n\nexport const extractManifestWorkerData = z.object({configPath: z.string(), workDir: z.string()})\n\nexport type ExtractManifestWorkerData = z.infer<typeof extractManifestWorkerData>\n\n/**\n * Workspace metadata + pre-extracted manifest schema for deployment.\n * The schema must already be in ManifestSchemaType[] format (extracted from\n * the live Schema object before any structured clone boundary).\n */\nexport interface WorkspaceSchemaInput {\n dataset: string\n manifestSchema: ManifestSchemaType[]\n name: string\n projectId: string\n\n title?: string\n}\n"],"names":["z","SANITY_WORKSPACE_SCHEMA_ID_PREFIX","CURRENT_WORKSPACE_SCHEMA_VERSION","coreAppManifestSchema","extractManifestWorkerData","object","configPath","string","workDir"],"mappings":"AAEA,SAAQA,CAAC,QAAO,WAAU;AAE1B,OAAO,MAAMC,oCAAoC,YAAW;AAC5D,OAAO,MAAMC,mCAAmC,aAAY;AAgB5D,8EAA8E;AAC9E,8EAA8E;AAC9E,2BAA2B;AAC3B,SAA8BC,qBAAqB,QAA4B,mBAAkB;AAsHjG,OAAO,MAAMC,4BAA4BJ,EAAEK,MAAM,CAAC;IAACC,YAAYN,EAAEO,MAAM;IAAIC,SAASR,EAAEO,MAAM;AAAE,GAAE"}
|
|
@@ -7,7 +7,7 @@ const debug = subdebug('buildStudioSchemasAndManifests');
|
|
|
7
7
|
* 2. Uploads the schema to lexicon
|
|
8
8
|
* 3. Creates a studio manifest (which can be sent to populus)
|
|
9
9
|
*/ export async function buildStudioSchemasAndManifests(applicationId, options) {
|
|
10
|
-
const { configPath, isExternal, outPath, projectId, verbose, workDir } = options;
|
|
10
|
+
const { configPath, isExternal, outPath, projectId, schemaRequired, verbose, workDir } = options;
|
|
11
11
|
const trace = getCliTelemetry().trace(SchemaBuild, {
|
|
12
12
|
// If the studio is externally hosted, we don't need to extract the manifest
|
|
13
13
|
extractManifest: !isExternal,
|
|
@@ -31,6 +31,7 @@ const debug = subdebug('buildStudioSchemasAndManifests');
|
|
|
31
31
|
isExternal,
|
|
32
32
|
outPath,
|
|
33
33
|
projectId,
|
|
34
|
+
schemaRequired,
|
|
34
35
|
verbose,
|
|
35
36
|
workDir
|
|
36
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/schema/buildStudioSchemasAndManifests.ts"],"sourcesContent":["import {getCliTelemetry, studioWorkerTask, subdebug} from '@sanity/cli-core'\nimport {type SchemaValidationProblemGroup} from '@sanity/types'\nimport {type StudioManifest} from 'sanity'\n\nimport {SchemaBuild} from '../../telemetry/extractSchema.telemetry.js'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/schema/buildStudioSchemasAndManifests.ts"],"sourcesContent":["import {getCliTelemetry, studioWorkerTask, subdebug} from '@sanity/cli-core'\nimport {type SchemaValidationProblemGroup} from '@sanity/types'\nimport {type StudioManifest} from 'sanity'\n\nimport {SchemaBuild} from '../../telemetry/extractSchema.telemetry.js'\nimport {WorkspaceSchemaInput} from '../manifest/types.js'\nimport {type BuildStudioSchemasAndManifestsWorkerData} from './types.js'\nimport {SchemaExtractionError} from './utils/SchemaExtractionError.js'\n\nexport type BuildStudioSchemasAndManifestsWorkerSuccess = {\n schemaInputs: WorkspaceSchemaInput[] | null\n studioManifest: StudioManifest | null\n type: 'success'\n}\ntype BuildStudioSchemasAndManifestsWorkerError = {\n error: string\n type: 'error'\n validation?: SchemaValidationProblemGroup[]\n}\nexport type BuildStudioSchemasAndManifestsWorkerMessage =\n | BuildStudioSchemasAndManifestsWorkerError\n | BuildStudioSchemasAndManifestsWorkerSuccess\n\nconst debug = subdebug('buildStudioSchemasAndManifests')\n\n/**\n * 1. Extracts the create manifest in dist/static (tar/gzipped with studio)\n * 2. Uploads the schema to lexicon\n * 3. Creates a studio manifest (which can be sent to populus)\n */\nexport async function buildStudioSchemasAndManifests(\n applicationId: string,\n options: BuildStudioSchemasAndManifestsWorkerData,\n): Promise<BuildStudioSchemasAndManifestsWorkerSuccess> {\n const {configPath, isExternal, outPath, projectId, schemaRequired, verbose, workDir} = options\n\n const trace = getCliTelemetry().trace(SchemaBuild, {\n // If the studio is externally hosted, we don't need to extract the manifest\n extractManifest: !isExternal,\n manifestDir: outPath,\n })\n\n try {\n trace.start()\n const result = await studioWorkerTask<BuildStudioSchemasAndManifestsWorkerMessage>(\n new URL('buildStudioSchemasAndManifests.worker.js', import.meta.url),\n {\n applicationId,\n env: {\n ...process.env,\n // Workers don't inherit TTY state — propagate color support from parent\n ...(process.stdout.isTTY && !process.env.NO_COLOR ? {FORCE_COLOR: '1'} : {}),\n },\n name: 'buildStudioSchemasAndManifests',\n studioRootPath: workDir,\n workerData: {\n configPath,\n isExternal,\n outPath,\n projectId,\n schemaRequired,\n verbose,\n workDir,\n } satisfies BuildStudioSchemasAndManifestsWorkerData,\n },\n )\n\n debug('Result %o', result)\n\n // If the schema is required, we throw an error\n if (result.type === 'error') {\n throw new SchemaExtractionError(result.error, result.validation)\n }\n\n trace.complete()\n return result\n } catch (err) {\n trace.error(err)\n throw err\n }\n}\n"],"names":["getCliTelemetry","studioWorkerTask","subdebug","SchemaBuild","SchemaExtractionError","debug","buildStudioSchemasAndManifests","applicationId","options","configPath","isExternal","outPath","projectId","schemaRequired","verbose","workDir","trace","extractManifest","manifestDir","start","result","URL","url","env","process","stdout","isTTY","NO_COLOR","FORCE_COLOR","name","studioRootPath","workerData","type","error","validation","complete","err"],"mappings":"AAAA,SAAQA,eAAe,EAAEC,gBAAgB,EAAEC,QAAQ,QAAO,mBAAkB;AAI5E,SAAQC,WAAW,QAAO,6CAA4C;AAGtE,SAAQC,qBAAqB,QAAO,mCAAkC;AAgBtE,MAAMC,QAAQH,SAAS;AAEvB;;;;CAIC,GACD,OAAO,eAAeI,+BACpBC,aAAqB,EACrBC,OAAiD;IAEjD,MAAM,EAACC,UAAU,EAAEC,UAAU,EAAEC,OAAO,EAAEC,SAAS,EAAEC,cAAc,EAAEC,OAAO,EAAEC,OAAO,EAAC,GAAGP;IAEvF,MAAMQ,QAAQhB,kBAAkBgB,KAAK,CAACb,aAAa;QACjD,4EAA4E;QAC5Ec,iBAAiB,CAACP;QAClBQ,aAAaP;IACf;IAEA,IAAI;QACFK,MAAMG,KAAK;QACX,MAAMC,SAAS,MAAMnB,iBACnB,IAAIoB,IAAI,4CAA4C,YAAYC,GAAG,GACnE;YACEf;YACAgB,KAAK;gBACH,GAAGC,QAAQD,GAAG;gBACd,wEAAwE;gBACxE,GAAIC,QAAQC,MAAM,CAACC,KAAK,IAAI,CAACF,QAAQD,GAAG,CAACI,QAAQ,GAAG;oBAACC,aAAa;gBAAG,IAAI,CAAC,CAAC;YAC7E;YACAC,MAAM;YACNC,gBAAgBf;YAChBgB,YAAY;gBACVtB;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC;YACF;QACF;QAGFV,MAAM,aAAae;QAEnB,+CAA+C;QAC/C,IAAIA,OAAOY,IAAI,KAAK,SAAS;YAC3B,MAAM,IAAI5B,sBAAsBgB,OAAOa,KAAK,EAAEb,OAAOc,UAAU;QACjE;QAEAlB,MAAMmB,QAAQ;QACd,OAAOf;IACT,EAAE,OAAOgB,KAAK;QACZpB,MAAMiB,KAAK,CAACG;QACZ,MAAMA;IACR;AACF"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { isMainThread, parentPort, workerData } from 'node:worker_threads';
|
|
2
2
|
import { subdebug } from '@sanity/cli-core';
|
|
3
|
+
import { workerBuildStudioSchemasAndManifests } from './buildStudioSchemasAndManifestsWorker.js';
|
|
3
4
|
import { buildStudioSchemasAndManifestsWorkerData } from './types.js';
|
|
4
5
|
import { extractValidationFromSchemaError } from './utils/extractValidationFromSchemaError.js';
|
|
5
|
-
import { workerBuildStudioSchemasAndManifests } from './workerBuildStudioSchemasAndManifests.js';
|
|
6
6
|
const debug = subdebug('buildStudioSchemasAndManifests.worker');
|
|
7
7
|
async function main() {
|
|
8
8
|
if (isMainThread || !parentPort) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/schema/buildStudioSchemasAndManifests.worker.ts"],"sourcesContent":["import {isMainThread, parentPort, workerData} from 'node:worker_threads'\n\nimport {subdebug} from '@sanity/cli-core'\n\nimport {type BuildStudioSchemasAndManifestsWorkerMessage} from './buildStudioSchemasAndManifests.js'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/schema/buildStudioSchemasAndManifests.worker.ts"],"sourcesContent":["import {isMainThread, parentPort, workerData} from 'node:worker_threads'\n\nimport {subdebug} from '@sanity/cli-core'\n\nimport {type BuildStudioSchemasAndManifestsWorkerMessage} from './buildStudioSchemasAndManifests.js'\nimport {workerBuildStudioSchemasAndManifests} from './buildStudioSchemasAndManifestsWorker.js'\nimport {buildStudioSchemasAndManifestsWorkerData} from './types.js'\nimport {extractValidationFromSchemaError} from './utils/extractValidationFromSchemaError.js'\n\nconst debug = subdebug('buildStudioSchemasAndManifests.worker')\n\nasync function main() {\n if (isMainThread || !parentPort) {\n throw new Error('Should only be run in a worker!')\n }\n\n const options = buildStudioSchemasAndManifestsWorkerData.parse(workerData)\n\n try {\n const message = await workerBuildStudioSchemasAndManifests(options)\n\n parentPort.postMessage(message)\n } catch (error) {\n debug('Error deploying studio schemas and manifests', error)\n const validation = await extractValidationFromSchemaError(error, options.workDir)\n parentPort.postMessage({\n error: error instanceof Error ? error.message : String(error),\n type: 'error',\n validation,\n } satisfies BuildStudioSchemasAndManifestsWorkerMessage)\n }\n}\n\nawait main()\n"],"names":["isMainThread","parentPort","workerData","subdebug","workerBuildStudioSchemasAndManifests","buildStudioSchemasAndManifestsWorkerData","extractValidationFromSchemaError","debug","main","Error","options","parse","message","postMessage","error","validation","workDir","String","type"],"mappings":"AAAA,SAAQA,YAAY,EAAEC,UAAU,EAAEC,UAAU,QAAO,sBAAqB;AAExE,SAAQC,QAAQ,QAAO,mBAAkB;AAGzC,SAAQC,oCAAoC,QAAO,4CAA2C;AAC9F,SAAQC,wCAAwC,QAAO,aAAY;AACnE,SAAQC,gCAAgC,QAAO,8CAA6C;AAE5F,MAAMC,QAAQJ,SAAS;AAEvB,eAAeK;IACb,IAAIR,gBAAgB,CAACC,YAAY;QAC/B,MAAM,IAAIQ,MAAM;IAClB;IAEA,MAAMC,UAAUL,yCAAyCM,KAAK,CAACT;IAE/D,IAAI;QACF,MAAMU,UAAU,MAAMR,qCAAqCM;QAE3DT,WAAWY,WAAW,CAACD;IACzB,EAAE,OAAOE,OAAO;QACdP,MAAM,gDAAgDO;QACtD,MAAMC,aAAa,MAAMT,iCAAiCQ,OAAOJ,QAAQM,OAAO;QAChFf,WAAWY,WAAW,CAAC;YACrBC,OAAOA,iBAAiBL,QAAQK,MAAMF,OAAO,GAAGK,OAAOH;YACvDI,MAAM;YACNH;QACF;IACF;AACF;AAEA,MAAMP"}
|
|
@@ -11,7 +11,7 @@ const debug = subdebug('buildStudioSchemasAndManifests.worker');
|
|
|
11
11
|
if (isMainThread) {
|
|
12
12
|
throw new Error('workerBuildStudioSchemasAndManifests should only be called from a worker thread');
|
|
13
13
|
}
|
|
14
|
-
const { configPath, isExternal, outPath, projectId, verbose, workDir,
|
|
14
|
+
const { configPath, isExternal, outPath, projectId, schemaRequired, verbose, workDir, workspaceSchemaHandler } = options;
|
|
15
15
|
debug('Building studio schemas and manifests from config path %s', configPath);
|
|
16
16
|
const workspaces = await getStudioWorkspaces(configPath);
|
|
17
17
|
debug('Workspaces %o', workspaces);
|
|
@@ -22,33 +22,42 @@ const debug = subdebug('buildStudioSchemasAndManifests.worker');
|
|
|
22
22
|
// still live. Both writeWorkspaceToDist and updateWorkspacesSchemas consume the result.
|
|
23
23
|
const workspaceManifests = await extractWorkspaceManifest(workspaces, workDir);
|
|
24
24
|
debug('Handling build for %s', isExternal ? 'external' : 'internal');
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
projectId,
|
|
41
|
-
verbose,
|
|
42
|
-
workDir,
|
|
43
|
-
workspaceManifests,
|
|
44
|
-
workspaceManifestsHandler,
|
|
45
|
-
workspaces
|
|
46
|
-
});
|
|
25
|
+
async function workspaceManifestsHandler(workspaceManifests) {
|
|
26
|
+
if (!isExternal || schemaRequired) {
|
|
27
|
+
const schemaInputs = workspaceManifests.map((manifest)=>({
|
|
28
|
+
dataset: manifest.dataset,
|
|
29
|
+
manifestSchema: manifest.schema,
|
|
30
|
+
name: manifest.name,
|
|
31
|
+
projectId: manifest.projectId,
|
|
32
|
+
title: manifest.title
|
|
33
|
+
}));
|
|
34
|
+
if (workspaceSchemaHandler) {
|
|
35
|
+
await workspaceSchemaHandler(schemaInputs);
|
|
36
|
+
}
|
|
37
|
+
return schemaInputs;
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
47
40
|
}
|
|
41
|
+
const result = isExternal ? await handleExternalStudio({
|
|
42
|
+
projectId,
|
|
43
|
+
verbose,
|
|
44
|
+
workDir,
|
|
45
|
+
workspaceManifests,
|
|
46
|
+
workspaceManifestsHandler,
|
|
47
|
+
workspaces
|
|
48
|
+
}) : await handleInternalStudio({
|
|
49
|
+
outPath,
|
|
50
|
+
projectId,
|
|
51
|
+
verbose,
|
|
52
|
+
workDir,
|
|
53
|
+
workspaceManifests,
|
|
54
|
+
workspaceManifestsHandler,
|
|
55
|
+
workspaces
|
|
56
|
+
});
|
|
48
57
|
return {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
58
|
+
schemaInputs: result.schemaInputs,
|
|
59
|
+
studioManifest: result.studioManifest,
|
|
60
|
+
type: 'success'
|
|
52
61
|
};
|
|
53
62
|
}
|
|
54
63
|
/**
|
|
@@ -56,18 +65,19 @@ const debug = subdebug('buildStudioSchemasAndManifests.worker');
|
|
|
56
65
|
* 1. Update the workspace schemas to the /schemas endpoint IF --schema-required is passed
|
|
57
66
|
* 2. Call the workspace manifest handler if provided to update server-side schemas
|
|
58
67
|
*/ async function handleExternalStudio({ projectId, verbose, workDir, workspaceManifests, workspaceManifestsHandler, workspaces }) {
|
|
59
|
-
const [studioManifest] = await Promise.all([
|
|
68
|
+
const [studioManifest, schemaInputs] = await Promise.all([
|
|
60
69
|
uploadSchemaToLexicon({
|
|
61
70
|
projectId,
|
|
62
71
|
verbose,
|
|
63
72
|
workDir,
|
|
64
73
|
workspaces
|
|
65
74
|
}),
|
|
66
|
-
workspaceManifestsHandler
|
|
75
|
+
workspaceManifestsHandler(workspaceManifests)
|
|
67
76
|
]);
|
|
68
|
-
return
|
|
77
|
+
return {
|
|
78
|
+
schemaInputs,
|
|
69
79
|
studioManifest
|
|
70
|
-
|
|
80
|
+
};
|
|
71
81
|
}
|
|
72
82
|
/**
|
|
73
83
|
*
|
|
@@ -78,23 +88,24 @@ const debug = subdebug('buildStudioSchemasAndManifests.worker');
|
|
|
78
88
|
*
|
|
79
89
|
* @param workspaces - The workspaces to deploy
|
|
80
90
|
*/ async function handleInternalStudio({ outPath, projectId, verbose, workDir, workspaceManifests, workspaceManifestsHandler, workspaces }) {
|
|
81
|
-
const [studioManifest] = await Promise.all([
|
|
91
|
+
const [studioManifest, schemaInputs] = await Promise.all([
|
|
82
92
|
uploadSchemaToLexicon({
|
|
83
93
|
projectId,
|
|
84
94
|
verbose,
|
|
85
95
|
workDir,
|
|
86
96
|
workspaces
|
|
87
97
|
}),
|
|
98
|
+
workspaceManifestsHandler(workspaceManifests),
|
|
88
99
|
writeManifestFile({
|
|
89
100
|
outPath,
|
|
90
101
|
workDir,
|
|
91
102
|
workspaceManifests
|
|
92
|
-
})
|
|
93
|
-
workspaceManifestsHandler && workspaceManifestsHandler(workspaceManifests)
|
|
103
|
+
})
|
|
94
104
|
]);
|
|
95
|
-
return
|
|
105
|
+
return {
|
|
106
|
+
schemaInputs,
|
|
96
107
|
studioManifest
|
|
97
|
-
|
|
108
|
+
};
|
|
98
109
|
}
|
|
99
110
|
|
|
100
|
-
//# sourceMappingURL=
|
|
111
|
+
//# sourceMappingURL=buildStudioSchemasAndManifestsWorker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/schema/buildStudioSchemasAndManifestsWorker.ts"],"sourcesContent":["import {isMainThread} from 'node:worker_threads'\n\nimport {getStudioWorkspaces, subdebug} from '@sanity/cli-core'\nimport {type StudioManifest, type Workspace} from 'sanity'\n\nimport {extractWorkspaceManifest} from '../manifest/extractWorkspaceManifest.js'\nimport {type CreateWorkspaceManifest, WorkspaceSchemaInput} from '../manifest/types.js'\nimport {writeManifestFile} from '../manifest/writeManifestFile.js'\nimport {type BuildStudioSchemasAndManifestsWorkerSuccess} from './buildStudioSchemasAndManifests.js'\nimport {type BuildStudioSchemasAndManifestsWorkerData} from './types.js'\nimport {uploadSchemaToLexicon} from './uploadSchemaToLexicon.js'\n\nconst debug = subdebug('buildStudioSchemasAndManifests.worker')\n\n/**\n * This function must only be called from another worker process.\n * @param options - The worker options\n */\nexport async function workerBuildStudioSchemasAndManifests(\n options: BuildStudioSchemasAndManifestsWorkerData & {\n workspaceSchemaHandler?: (workspaces: WorkspaceSchemaInput[]) => Promise<void>\n },\n): Promise<BuildStudioSchemasAndManifestsWorkerSuccess> {\n if (isMainThread) {\n throw new Error(\n 'workerBuildStudioSchemasAndManifests should only be called from a worker thread',\n )\n }\n\n const {\n configPath,\n isExternal,\n outPath,\n projectId,\n schemaRequired,\n verbose,\n workDir,\n workspaceSchemaHandler,\n } = options\n\n debug('Building studio schemas and manifests from config path %s', configPath)\n const workspaces = await getStudioWorkspaces(configPath)\n debug('Workspaces %o', workspaces)\n\n if (workspaces.length === 0) {\n throw new Error('No workspaces found')\n }\n\n // Extract manifest data (including ManifestSchemaType[]) once, while Schema objects are\n // still live. Both writeWorkspaceToDist and updateWorkspacesSchemas consume the result.\n const workspaceManifests = await extractWorkspaceManifest(workspaces, workDir)\n\n debug('Handling build for %s', isExternal ? 'external' : 'internal')\n\n async function workspaceManifestsHandler(\n workspaceManifests: CreateWorkspaceManifest[],\n ): Promise<WorkspaceSchemaInput[] | null> {\n if (!isExternal || schemaRequired) {\n const schemaInputs: WorkspaceSchemaInput[] = workspaceManifests.map((manifest) => ({\n dataset: manifest.dataset,\n manifestSchema: manifest.schema,\n name: manifest.name,\n projectId: manifest.projectId,\n title: manifest.title,\n }))\n\n if (workspaceSchemaHandler) {\n await workspaceSchemaHandler(schemaInputs)\n }\n\n return schemaInputs\n }\n\n return null\n }\n\n const result = isExternal\n ? await handleExternalStudio({\n projectId,\n verbose,\n workDir,\n workspaceManifests,\n workspaceManifestsHandler,\n workspaces,\n })\n : await handleInternalStudio({\n outPath,\n projectId,\n verbose,\n workDir,\n workspaceManifests,\n workspaceManifestsHandler,\n workspaces,\n })\n\n return {\n schemaInputs: result.schemaInputs,\n studioManifest: result.studioManifest,\n type: 'success',\n }\n}\n\ntype HandleStudioResult = {\n schemaInputs: WorkspaceSchemaInput[] | null\n studioManifest: StudioManifest | null\n}\n\n/**\n * External deployments:\n * 1. Update the workspace schemas to the /schemas endpoint IF --schema-required is passed\n * 2. Call the workspace manifest handler if provided to update server-side schemas\n */\nasync function handleExternalStudio({\n projectId,\n verbose,\n workDir,\n workspaceManifests,\n workspaceManifestsHandler,\n workspaces,\n}: {\n projectId: string\n verbose: boolean\n workDir: string\n workspaceManifests: CreateWorkspaceManifest[]\n workspaceManifestsHandler: (\n workspaceManifests: CreateWorkspaceManifest[],\n ) => Promise<WorkspaceSchemaInput[] | null>\n workspaces: Workspace[]\n}): Promise<HandleStudioResult> {\n const [studioManifest, schemaInputs] = await Promise.all([\n uploadSchemaToLexicon({\n projectId,\n verbose,\n workDir,\n workspaces,\n }),\n workspaceManifestsHandler(workspaceManifests),\n ])\n\n return {schemaInputs, studioManifest}\n}\n\n/**\n *\n * Internal deployments:\n * 1. Write the workspace manifests to the dist directory\n * 2. Update the workspaces schemas to the /schemas endpoint\n * 3. Call the workspace manifest handler if provided to update server-side schemas\n *\n * @param workspaces - The workspaces to deploy\n */\nasync function handleInternalStudio({\n outPath,\n projectId,\n verbose,\n workDir,\n workspaceManifests,\n workspaceManifestsHandler,\n workspaces,\n}: {\n outPath: string\n projectId: string\n verbose: boolean\n workDir: string\n workspaceManifests: CreateWorkspaceManifest[]\n workspaceManifestsHandler: (\n workspaceManifests: CreateWorkspaceManifest[],\n ) => Promise<WorkspaceSchemaInput[] | null>\n workspaces: Workspace[]\n}): Promise<HandleStudioResult> {\n const [studioManifest, schemaInputs] = await Promise.all([\n uploadSchemaToLexicon({\n projectId,\n verbose,\n workDir,\n workspaces,\n }),\n workspaceManifestsHandler(workspaceManifests),\n writeManifestFile({outPath, workDir, workspaceManifests}),\n ])\n\n return {schemaInputs, studioManifest}\n}\n"],"names":["isMainThread","getStudioWorkspaces","subdebug","extractWorkspaceManifest","writeManifestFile","uploadSchemaToLexicon","debug","workerBuildStudioSchemasAndManifests","options","Error","configPath","isExternal","outPath","projectId","schemaRequired","verbose","workDir","workspaceSchemaHandler","workspaces","length","workspaceManifests","workspaceManifestsHandler","schemaInputs","map","manifest","dataset","manifestSchema","schema","name","title","result","handleExternalStudio","handleInternalStudio","studioManifest","type","Promise","all"],"mappings":"AAAA,SAAQA,YAAY,QAAO,sBAAqB;AAEhD,SAAQC,mBAAmB,EAAEC,QAAQ,QAAO,mBAAkB;AAG9D,SAAQC,wBAAwB,QAAO,0CAAyC;AAEhF,SAAQC,iBAAiB,QAAO,mCAAkC;AAGlE,SAAQC,qBAAqB,QAAO,6BAA4B;AAEhE,MAAMC,QAAQJ,SAAS;AAEvB;;;CAGC,GACD,OAAO,eAAeK,qCACpBC,OAEC;IAED,IAAIR,cAAc;QAChB,MAAM,IAAIS,MACR;IAEJ;IAEA,MAAM,EACJC,UAAU,EACVC,UAAU,EACVC,OAAO,EACPC,SAAS,EACTC,cAAc,EACdC,OAAO,EACPC,OAAO,EACPC,sBAAsB,EACvB,GAAGT;IAEJF,MAAM,6DAA6DI;IACnE,MAAMQ,aAAa,MAAMjB,oBAAoBS;IAC7CJ,MAAM,iBAAiBY;IAEvB,IAAIA,WAAWC,MAAM,KAAK,GAAG;QAC3B,MAAM,IAAIV,MAAM;IAClB;IAEA,wFAAwF;IACxF,wFAAwF;IACxF,MAAMW,qBAAqB,MAAMjB,yBAAyBe,YAAYF;IAEtEV,MAAM,yBAAyBK,aAAa,aAAa;IA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KACxD;IAED,OAAO;QAACE;QAAcW;IAAc;AACtC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/schema/types.ts"],"sourcesContent":["import {type SchemaValidationProblemGroup} from '@sanity/types'\nimport {z} from 'zod/mini'\n\nexport const extractSchemaWorkerData = z.object({\n configPath: z.string(),\n enforceRequiredFields: z.boolean(),\n workDir: z.string(),\n workspaceName: z.optional(z.string()),\n})\n\nexport type ExtractSchemaWorkerData = z.infer<typeof extractSchemaWorkerData>\n\n/** @internal */\nexport interface ExtractSchemaWorkerError {\n error: string\n type: 'error'\n\n validation?: SchemaValidationProblemGroup[]\n}\n\nexport const buildStudioSchemasAndManifestsWorkerData = z.object({\n configPath: z.string(),\n isExternal: z.boolean(),\n outPath: z.string(),\n projectId: z.string(),\n verbose: z.boolean(),\n workDir: z.string(),\n})\n\nexport type BuildStudioSchemasAndManifestsWorkerData = z.infer<\n typeof buildStudioSchemasAndManifestsWorkerData\n>\n"],"names":["z","extractSchemaWorkerData","object","configPath","string","enforceRequiredFields","boolean","workDir","workspaceName","optional","buildStudioSchemasAndManifestsWorkerData","isExternal","outPath","projectId","verbose"],"mappings":"AACA,SAAQA,CAAC,QAAO,WAAU;AAE1B,OAAO,MAAMC,0BAA0BD,EAAEE,MAAM,CAAC;IAC9CC,YAAYH,EAAEI,MAAM;IACpBC,uBAAuBL,EAAEM,OAAO;IAChCC,SAASP,EAAEI,MAAM;IACjBI,eAAeR,EAAES,QAAQ,CAACT,EAAEI,MAAM;AACpC,GAAE;AAYF,OAAO,MAAMM,2CAA2CV,EAAEE,MAAM,CAAC;IAC/DC,YAAYH,EAAEI,MAAM;IACpBO,YAAYX,EAAEM,OAAO;IACrBM,SAASZ,EAAEI,MAAM;IACjBS,WAAWb,EAAEI,MAAM;IACnBU,
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/schema/types.ts"],"sourcesContent":["import {type SchemaValidationProblemGroup} from '@sanity/types'\nimport {z} from 'zod/mini'\n\nexport const extractSchemaWorkerData = z.object({\n configPath: z.string(),\n enforceRequiredFields: z.boolean(),\n workDir: z.string(),\n workspaceName: z.optional(z.string()),\n})\n\nexport type ExtractSchemaWorkerData = z.infer<typeof extractSchemaWorkerData>\n\n/** @internal */\nexport interface ExtractSchemaWorkerError {\n error: string\n type: 'error'\n\n validation?: SchemaValidationProblemGroup[]\n}\n\nexport const buildStudioSchemasAndManifestsWorkerData = z.object({\n configPath: z.string(),\n isExternal: z.boolean(),\n outPath: z.string(),\n projectId: z.string(),\n schemaRequired: z.boolean(),\n verbose: z.boolean(),\n workDir: z.string(),\n})\n\nexport type BuildStudioSchemasAndManifestsWorkerData = z.infer<\n typeof buildStudioSchemasAndManifestsWorkerData\n>\n"],"names":["z","extractSchemaWorkerData","object","configPath","string","enforceRequiredFields","boolean","workDir","workspaceName","optional","buildStudioSchemasAndManifestsWorkerData","isExternal","outPath","projectId","schemaRequired","verbose"],"mappings":"AACA,SAAQA,CAAC,QAAO,WAAU;AAE1B,OAAO,MAAMC,0BAA0BD,EAAEE,MAAM,CAAC;IAC9CC,YAAYH,EAAEI,MAAM;IACpBC,uBAAuBL,EAAEM,OAAO;IAChCC,SAASP,EAAEI,MAAM;IACjBI,eAAeR,EAAES,QAAQ,CAACT,EAAEI,MAAM;AACpC,GAAE;AAYF,OAAO,MAAMM,2CAA2CV,EAAEE,MAAM,CAAC;IAC/DC,YAAYH,EAAEI,MAAM;IACpBO,YAAYX,EAAEM,OAAO;IACrBM,SAASZ,EAAEI,MAAM;IACjBS,WAAWb,EAAEI,MAAM;IACnBU,gBAAgBd,EAAEM,OAAO;IACzBS,SAASf,EAAEM,OAAO;IAClBC,SAASP,EAAEI,MAAM;AACnB,GAAE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/cli-build",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.1",
|
|
4
4
|
"description": "Internal Sanity package for building studios and apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -52,12 +52,12 @@
|
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@oclif/core": "^4.11.14",
|
|
54
54
|
"@rolldown/plugin-babel": "^0.2.4",
|
|
55
|
-
"@sanity/cli-core": "^3.11.
|
|
55
|
+
"@sanity/cli-core": "^3.11.1",
|
|
56
56
|
"@sanity/generate-help-url": "^4.0.0",
|
|
57
57
|
"@sanity/schema": "^6.17.0",
|
|
58
58
|
"@sanity/telemetry": "^1.1.0",
|
|
59
59
|
"@sanity/types": "^6.17.0",
|
|
60
|
-
"@sanity/workbench-cli": "^2.
|
|
60
|
+
"@sanity/workbench-cli": "^2.13.0",
|
|
61
61
|
"@vitejs/plugin-react": "^6.1.2",
|
|
62
62
|
"chokidar": "^5.0.0",
|
|
63
63
|
"cjs-module-lexer": "^2.2.1",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"@eslint/compat": "^2.1.0",
|
|
80
80
|
"@repo/package.config": "0.0.1",
|
|
81
81
|
"@repo/tsconfig": "3.70.0",
|
|
82
|
-
"@sanity/cli-test": "21.0.
|
|
82
|
+
"@sanity/cli-test": "21.0.1",
|
|
83
83
|
"@sanity/eslint-config-cli": "^1.1.3",
|
|
84
84
|
"@sanity/pkg-utils": "^12.3.4",
|
|
85
85
|
"@sanity/ui": "^4.3.1",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/schema/workerBuildStudioSchemasAndManifests.ts"],"sourcesContent":["import {isMainThread} from 'node:worker_threads'\n\nimport {getStudioWorkspaces, subdebug} from '@sanity/cli-core'\nimport {type StudioManifest, type Workspace} from 'sanity'\n\nimport {extractWorkspaceManifest} from '../manifest/extractWorkspaceManifest.js'\nimport {type CreateWorkspaceManifest} from '../manifest/types.js'\nimport {writeManifestFile} from '../manifest/writeManifestFile.js'\nimport {type BuildStudioSchemasAndManifestsWorkerSuccess} from './buildStudioSchemasAndManifests.js'\nimport {type BuildStudioSchemasAndManifestsWorkerData} from './types.js'\nimport {uploadSchemaToLexicon} from './uploadSchemaToLexicon.js'\n\nconst debug = subdebug('buildStudioSchemasAndManifests.worker')\n\n/**\n * This function must only be called from another worker process.\n * @param options - The worker options\n */\nexport async function workerBuildStudioSchemasAndManifests(\n options: BuildStudioSchemasAndManifestsWorkerData & {\n workspaceManifestsHandler?: (workspaceManifests: CreateWorkspaceManifest[]) => Promise<void>\n },\n): Promise<BuildStudioSchemasAndManifestsWorkerSuccess> {\n if (isMainThread) {\n throw new Error(\n 'workerBuildStudioSchemasAndManifests should only be called from a worker thread',\n )\n }\n\n const {configPath, isExternal, outPath, projectId, verbose, workDir, workspaceManifestsHandler} =\n options\n\n debug('Building studio schemas and manifests from config path %s', configPath)\n const workspaces = await getStudioWorkspaces(configPath)\n debug('Workspaces %o', workspaces)\n\n if (workspaces.length === 0) {\n throw new Error('No workspaces found')\n }\n\n // Extract manifest data (including ManifestSchemaType[]) once, while Schema objects are\n // still live. Both writeWorkspaceToDist and updateWorkspacesSchemas consume the result.\n const workspaceManifests = await extractWorkspaceManifest(workspaces, workDir)\n\n debug('Handling build for %s', isExternal ? 'external' : 'internal')\n\n let studioManifest: StudioManifest | null\n\n if (isExternal) {\n ;[studioManifest] = await handleExternalStudio({\n projectId,\n verbose,\n workDir,\n workspaceManifests,\n workspaceManifestsHandler,\n workspaces,\n })\n } else {\n ;[studioManifest] = await handleInternalStudio({\n outPath,\n projectId,\n verbose,\n workDir,\n workspaceManifests,\n workspaceManifestsHandler,\n workspaces,\n })\n }\n return {\n studioManifest,\n type: 'success',\n workspaceManifests,\n }\n}\n\n/**\n * External deployments:\n * 1. Update the workspace schemas to the /schemas endpoint IF --schema-required is passed\n * 2. Call the workspace manifest handler if provided to update server-side schemas\n */\nasync function handleExternalStudio({\n projectId,\n verbose,\n workDir,\n workspaceManifests,\n workspaceManifestsHandler,\n workspaces,\n}: {\n projectId: string\n verbose: boolean\n workDir: string\n workspaceManifests: CreateWorkspaceManifest[]\n workspaceManifestsHandler?: (workspaceManifests: CreateWorkspaceManifest[]) => Promise<void>\n workspaces: Workspace[]\n}): Promise<[StudioManifest | null]> {\n const [studioManifest] = await Promise.all([\n uploadSchemaToLexicon({\n projectId,\n verbose,\n workDir,\n workspaces,\n }),\n workspaceManifestsHandler && workspaceManifestsHandler(workspaceManifests),\n ])\n\n return [studioManifest]\n}\n\n/**\n *\n * Internal deployments:\n * 1. Write the workspace manifests to the dist directory\n * 2. Update the workspaces schemas to the /schemas endpoint\n * 3. Call the workspace manifest handler if provided to update server-side schemas\n *\n * @param workspaces - The workspaces to deploy\n */\nasync function handleInternalStudio({\n outPath,\n projectId,\n verbose,\n workDir,\n workspaceManifests,\n workspaceManifestsHandler,\n workspaces,\n}: {\n outPath: string\n projectId: string\n verbose: boolean\n workDir: string\n workspaceManifests: CreateWorkspaceManifest[]\n workspaceManifestsHandler?: (workspaceManifests: CreateWorkspaceManifest[]) => Promise<void>\n workspaces: Workspace[]\n}): Promise<[StudioManifest | null]> {\n const [studioManifest] = await Promise.all([\n uploadSchemaToLexicon({\n projectId,\n verbose,\n workDir,\n workspaces,\n }),\n writeManifestFile({outPath, workDir, workspaceManifests}),\n workspaceManifestsHandler && workspaceManifestsHandler(workspaceManifests),\n ])\n\n return [studioManifest]\n}\n"],"names":["isMainThread","getStudioWorkspaces","subdebug","extractWorkspaceManifest","writeManifestFile","uploadSchemaToLexicon","debug","workerBuildStudioSchemasAndManifests","options","Error","configPath","isExternal","outPath","projectId","verbose","workDir","workspaceManifestsHandler","workspaces","length","workspaceManifests","studioManifest","handleExternalStudio","handleInternalStudio","type","Promise","all"],"mappings":"AAAA,SAAQA,YAAY,QAAO,sBAAqB;AAEhD,SAAQC,mBAAmB,EAAEC,QAAQ,QAAO,mBAAkB;AAG9D,SAAQC,wBAAwB,QAAO,0CAAyC;AAEhF,SAAQC,iBAAiB,QAAO,mCAAkC;AAGlE,SAAQC,qBAAqB,QAAO,6BAA4B;AAE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