@sanity/cli-build 1.1.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_exports/_internal/build.d.ts +43 -63
- package/dist/_exports/_internal/build.js +4 -4
- package/dist/_exports/_internal/build.js.map +1 -1
- package/dist/actions/build/buildStaticFiles.js +148 -0
- package/dist/actions/build/buildStaticFiles.js.map +1 -0
- package/dist/util/formatSize.js +10 -0
- package/dist/util/formatSize.js.map +1 -0
- package/dist/util/moduleFormatUtils.js +18 -0
- package/dist/util/moduleFormatUtils.js.map +1 -0
- package/package.json +5 -5
|
@@ -28,7 +28,7 @@ export declare const AppBuildTrace: DefinedTelemetryTrace<
|
|
|
28
28
|
*
|
|
29
29
|
* @internal
|
|
30
30
|
*/
|
|
31
|
-
|
|
31
|
+
declare interface AutoUpdatesBuildConfig {
|
|
32
32
|
/** Import map entries for the packages served from Sanity's module CDN. */
|
|
33
33
|
imports: Record<string, string>;
|
|
34
34
|
/** Vendor packages to emit as hashed browser-loadable ESM chunks. */
|
|
@@ -39,6 +39,15 @@ export declare interface AutoUpdatesBuildConfig {
|
|
|
39
39
|
|
|
40
40
|
export declare const buildDebug: Debugger;
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Builds static files
|
|
44
|
+
*
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
47
|
+
export declare function buildStaticFiles(options: StaticBuildOptions): Promise<{
|
|
48
|
+
chunks: ChunkStats[];
|
|
49
|
+
}>;
|
|
50
|
+
|
|
42
51
|
/**
|
|
43
52
|
* Checks that the studio has declared and installed the required dependencies
|
|
44
53
|
* needed by the Sanity modules. While we generally use regular, explicit
|
|
@@ -74,20 +83,15 @@ export declare function checkStudioDependencyVersions(
|
|
|
74
83
|
},
|
|
75
84
|
): Promise<void>;
|
|
76
85
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
export declare function copyDir(
|
|
87
|
-
srcDir: string,
|
|
88
|
-
destDir: string,
|
|
89
|
-
skipExisting?: boolean,
|
|
90
|
-
): Promise<void>;
|
|
86
|
+
declare interface ChunkModule {
|
|
87
|
+
name: string;
|
|
88
|
+
renderedLength: number;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
declare interface ChunkStats {
|
|
92
|
+
modules: ChunkModule[];
|
|
93
|
+
name: string;
|
|
94
|
+
}
|
|
91
95
|
|
|
92
96
|
/**
|
|
93
97
|
* Merge user-provided Vite configuration object or function
|
|
@@ -103,29 +107,7 @@ export declare function extendViteConfigWithUserConfig(
|
|
|
103
107
|
userConfig: UserViteConfig,
|
|
104
108
|
): Promise<InlineConfig>;
|
|
105
109
|
|
|
106
|
-
|
|
107
|
-
* Re-asserts the critical parts of the default config after a userland vite
|
|
108
|
-
* config (`vite` in `sanity.cli.ts`) has been applied.
|
|
109
|
-
*
|
|
110
|
-
* Everything `getViteConfig` sets under `build.rolldownOptions` is load-bearing:
|
|
111
|
-
* the `input` entries (the studio entry plus, for auto-updating studios/apps,
|
|
112
|
-
* the vendor entries), `preserveEntrySignatures`, the `experimental` flags the
|
|
113
|
-
* vendor plugins rely on, and the `output` chunk naming. A userland config that
|
|
114
|
-
* returns a brand-new object for any of these would silently break the build
|
|
115
|
-
* (e.g. vendor chunks never emitted while the bundle still treats them as
|
|
116
|
-
* external), so the default `rolldownOptions` are deep-merged back over the
|
|
117
|
-
* userland config: userland additions survive, replacements of critical
|
|
118
|
-
* options are healed.
|
|
119
|
-
*
|
|
120
|
-
* @param config - User-modified configuration
|
|
121
|
-
* @param defaultConfig - The configuration produced by `getViteConfig`, before the userland config was applied
|
|
122
|
-
* @returns Merged configuration
|
|
123
|
-
* @internal
|
|
124
|
-
*/
|
|
125
|
-
export declare function finalizeViteConfig(
|
|
126
|
-
config: InlineConfig,
|
|
127
|
-
defaultConfig: InlineConfig,
|
|
128
|
-
): Promise<InlineConfig>;
|
|
110
|
+
export declare function formatModuleSizes(modules: ChunkModule[]): string;
|
|
129
111
|
|
|
130
112
|
/**
|
|
131
113
|
* Generate CDN CSS URLs for auto-updated packages.
|
|
@@ -185,22 +167,6 @@ declare type PackageWithCss = Package & {
|
|
|
185
167
|
cssFile?: string;
|
|
186
168
|
};
|
|
187
169
|
|
|
188
|
-
/**
|
|
189
|
-
* Resolves the relative entry paths for a Sanity project without writing any
|
|
190
|
-
* runtime files to disk. Used by federation builds that skip the full runtime
|
|
191
|
-
* generation but still need entry metadata for the vite plugin.
|
|
192
|
-
*/
|
|
193
|
-
export declare function resolveEntries(options: {
|
|
194
|
-
cwd: string;
|
|
195
|
-
entry?: string;
|
|
196
|
-
isApp?: boolean;
|
|
197
|
-
isWorkbenchApp?: boolean;
|
|
198
|
-
runtimeDir?: string;
|
|
199
|
-
}): Promise<{
|
|
200
|
-
relativeConfigLocation: string | null;
|
|
201
|
-
relativeEntry: string | null;
|
|
202
|
-
}>;
|
|
203
|
-
|
|
204
170
|
/**
|
|
205
171
|
* Resolves vendor package entry points and metadata for a combined studio/app build.
|
|
206
172
|
* Does not run a build — callers add `entries` to the main Vite/Rolldown input and
|
|
@@ -237,6 +203,28 @@ declare interface RuntimeOptions {
|
|
|
237
203
|
*/
|
|
238
204
|
export declare const SANITY_CACHE_DIR = "node_modules/.sanity";
|
|
239
205
|
|
|
206
|
+
export declare function sortModulesBySize(chunks: ChunkStats[]): ChunkModule[];
|
|
207
|
+
|
|
208
|
+
declare interface StaticBuildOptions {
|
|
209
|
+
basePath: string;
|
|
210
|
+
cwd: string;
|
|
211
|
+
outputDir: string;
|
|
212
|
+
appTitle?: string;
|
|
213
|
+
autoUpdates?: AutoUpdatesBuildConfig;
|
|
214
|
+
entry?: string;
|
|
215
|
+
isApp?: boolean;
|
|
216
|
+
/** Workbench app (opted in via `unstable_defineApp`) — drives the federation build. */
|
|
217
|
+
isWorkbenchApp?: boolean;
|
|
218
|
+
minify?: boolean;
|
|
219
|
+
profile?: boolean;
|
|
220
|
+
reactCompiler?: PluginOptions;
|
|
221
|
+
schemaExtraction?: CliConfig["schemaExtraction"];
|
|
222
|
+
services?: DefineAppInput["services"];
|
|
223
|
+
sourceMap?: boolean;
|
|
224
|
+
views?: DefineAppInput["views"];
|
|
225
|
+
vite?: UserViteConfig;
|
|
226
|
+
}
|
|
227
|
+
|
|
240
228
|
export declare const StudioBuildTrace: DefinedTelemetryTrace<
|
|
241
229
|
{
|
|
242
230
|
outputSize: number;
|
|
@@ -250,7 +238,7 @@ declare interface TrackedPackage {
|
|
|
250
238
|
supported: string[];
|
|
251
239
|
}
|
|
252
240
|
|
|
253
|
-
|
|
241
|
+
declare interface VendorBuildConfig {
|
|
254
242
|
/** Rolldown entry name -\> absolute path to the package entry file. */
|
|
255
243
|
entries: Record<string, string>;
|
|
256
244
|
/** Named exports each CommonJS entry must re-expose as ESM, keyed by chunk name. */
|
|
@@ -333,14 +321,6 @@ declare interface ViteOptions {
|
|
|
333
321
|
views?: DefineAppInput["views"];
|
|
334
322
|
}
|
|
335
323
|
|
|
336
|
-
/**
|
|
337
|
-
* @internal
|
|
338
|
-
*/
|
|
339
|
-
export declare function writeFavicons(
|
|
340
|
-
basePath: string,
|
|
341
|
-
destDir: string,
|
|
342
|
-
): Promise<void>;
|
|
343
|
-
|
|
344
324
|
/**
|
|
345
325
|
* Generates the `.sanity/runtime` directory, and optionally watches for custom
|
|
346
326
|
* document files, rebuilding when they change
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
export { buildDebug } from '../../actions/build/buildDebug.js';
|
|
2
|
+
export { buildStaticFiles } from '../../actions/build/buildStaticFiles.js';
|
|
2
3
|
export { checkRequiredDependencies } from '../../actions/build/checkRequiredDependencies.js';
|
|
3
4
|
export { checkStudioDependencyVersions } from '../../actions/build/checkStudioDependencyVersions.js';
|
|
4
5
|
export { getAutoUpdatesCssUrls, getAutoUpdatesImportMap, getModuleUrl } from '../../actions/build/getAutoUpdatesImportMap.js';
|
|
5
|
-
export { extendViteConfigWithUserConfig,
|
|
6
|
+
export { extendViteConfigWithUserConfig, getViteConfig } from '../../actions/build/getViteConfig.js';
|
|
6
7
|
export { resolveVendorBuildConfig } from '../../actions/build/resolveVendorBuildConfig.js';
|
|
7
|
-
export {
|
|
8
|
-
export { resolveEntries, writeSanityRuntime } from '../../actions/build/writeSanityRuntime.js';
|
|
8
|
+
export { writeSanityRuntime } from '../../actions/build/writeSanityRuntime.js';
|
|
9
9
|
export { SANITY_CACHE_DIR } from '../../constants.js';
|
|
10
10
|
export { AppBuildTrace, StudioBuildTrace } from '../../telemetry/build.telemetry.js';
|
|
11
|
-
export {
|
|
11
|
+
export { formatModuleSizes, sortModulesBySize } from '../../util/moduleFormatUtils.js';
|
|
12
12
|
|
|
13
13
|
//# sourceMappingURL=build.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/_exports/_internal/build.ts"],"sourcesContent":["export {
|
|
1
|
+
{"version":3,"sources":["../../../src/_exports/_internal/build.ts"],"sourcesContent":["export {buildDebug} from '../../actions/build/buildDebug.js'\nexport {buildStaticFiles} from '../../actions/build/buildStaticFiles.js'\nexport {checkRequiredDependencies} from '../../actions/build/checkRequiredDependencies.js'\nexport {checkStudioDependencyVersions} from '../../actions/build/checkStudioDependencyVersions.js'\nexport {\n getAutoUpdatesCssUrls,\n getAutoUpdatesImportMap,\n getModuleUrl,\n} from '../../actions/build/getAutoUpdatesImportMap.js'\nexport {extendViteConfigWithUserConfig, getViteConfig} from '../../actions/build/getViteConfig.js'\nexport {resolveVendorBuildConfig} from '../../actions/build/resolveVendorBuildConfig.js'\nexport {writeSanityRuntime} from '../../actions/build/writeSanityRuntime.js'\nexport {SANITY_CACHE_DIR} from '../../constants.js'\nexport {AppBuildTrace, StudioBuildTrace} from '../../telemetry/build.telemetry.js'\nexport {formatModuleSizes, sortModulesBySize} from '../../util/moduleFormatUtils.js'\n"],"names":["buildDebug","buildStaticFiles","checkRequiredDependencies","checkStudioDependencyVersions","getAutoUpdatesCssUrls","getAutoUpdatesImportMap","getModuleUrl","extendViteConfigWithUserConfig","getViteConfig","resolveVendorBuildConfig","writeSanityRuntime","SANITY_CACHE_DIR","AppBuildTrace","StudioBuildTrace","formatModuleSizes","sortModulesBySize"],"mappings":"AAAA,SAAQA,UAAU,QAAO,oCAAmC;AAC5D,SAAQC,gBAAgB,QAAO,0CAAyC;AACxE,SAAQC,yBAAyB,QAAO,mDAAkD;AAC1F,SAAQC,6BAA6B,QAAO,uDAAsD;AAClG,SACEC,qBAAqB,EACrBC,uBAAuB,EACvBC,YAAY,QACP,iDAAgD;AACvD,SAAQC,8BAA8B,EAAEC,aAAa,QAAO,uCAAsC;AAClG,SAAQC,wBAAwB,QAAO,kDAAiD;AACxF,SAAQC,kBAAkB,QAAO,4CAA2C;AAC5E,SAAQC,gBAAgB,QAAO,qBAAoB;AACnD,SAAQC,aAAa,EAAEC,gBAAgB,QAAO,qCAAoC;AAClF,SAAQC,iBAAiB,EAAEC,iBAAiB,QAAO,kCAAiC"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { build, createBuilder } from 'vite';
|
|
3
|
+
import { copyDir } from '../../util/copyDir.js';
|
|
4
|
+
import { buildDebug } from './buildDebug.js';
|
|
5
|
+
import { getAppEnvironmentVariables, getStudioEnvironmentVariables } from './getEnvironmentVariables.js';
|
|
6
|
+
import { extendViteConfigWithUserConfig, finalizeViteConfig, getViteConfig } from './getViteConfig.js';
|
|
7
|
+
import { writeFavicons } from './writeFavicons.js';
|
|
8
|
+
import { resolveEntries, writeSanityRuntime } from './writeSanityRuntime.js';
|
|
9
|
+
/**
|
|
10
|
+
* Builds static files
|
|
11
|
+
*
|
|
12
|
+
* @internal
|
|
13
|
+
*/ export async function buildStaticFiles(options) {
|
|
14
|
+
const { appTitle, autoUpdates, basePath, cwd, entry, isApp, isWorkbenchApp, minify = true, outputDir, reactCompiler, schemaExtraction, services, sourceMap = false, views, vite: extendViteConfig } = options;
|
|
15
|
+
const mode = 'production';
|
|
16
|
+
/* Federation builds only produce the federation environment
|
|
17
|
+
* (remote-entry, mf-manifest) — skip client-specific steps like
|
|
18
|
+
* runtime generation, static file copies, and favicons.
|
|
19
|
+
*/ if (isWorkbenchApp) {
|
|
20
|
+
buildDebug('Resolving entries for federation build');
|
|
21
|
+
const entries = await resolveEntries({
|
|
22
|
+
cwd,
|
|
23
|
+
entry,
|
|
24
|
+
isApp,
|
|
25
|
+
isWorkbenchApp
|
|
26
|
+
});
|
|
27
|
+
buildDebug('Resolving vite config (federation)');
|
|
28
|
+
let viteConfig = await getViteConfig({
|
|
29
|
+
basePath,
|
|
30
|
+
cwd,
|
|
31
|
+
entries,
|
|
32
|
+
getEnvironmentVariables,
|
|
33
|
+
isApp,
|
|
34
|
+
isWorkbenchApp,
|
|
35
|
+
minify,
|
|
36
|
+
mode,
|
|
37
|
+
outputDir,
|
|
38
|
+
reactCompiler,
|
|
39
|
+
// Schema extraction is a build-time artifact, not a client-specific step,
|
|
40
|
+
// so a federated studio extracts its schema like the legacy studio build.
|
|
41
|
+
schemaExtraction,
|
|
42
|
+
services,
|
|
43
|
+
sourceMap,
|
|
44
|
+
views
|
|
45
|
+
});
|
|
46
|
+
// Apply the user's Vite config so plugins like `@vanilla-extract/vite-plugin`
|
|
47
|
+
// transform source files before the federation environment is bundled.
|
|
48
|
+
// `finalizeViteConfig` is intentionally skipped: the federation environment
|
|
49
|
+
// has its own entry and does not use `.sanity/runtime/app.js`.
|
|
50
|
+
if (extendViteConfig) {
|
|
51
|
+
viteConfig = await extendViteConfigWithUserConfig({
|
|
52
|
+
command: 'build',
|
|
53
|
+
mode
|
|
54
|
+
}, viteConfig, extendViteConfig);
|
|
55
|
+
}
|
|
56
|
+
buildDebug('Bundling federation environment');
|
|
57
|
+
const builder = await createBuilder(viteConfig);
|
|
58
|
+
await builder.buildApp();
|
|
59
|
+
buildDebug('Bundling complete');
|
|
60
|
+
// TODO: add stats here
|
|
61
|
+
return {
|
|
62
|
+
chunks: []
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
buildDebug('Writing Sanity runtime files');
|
|
66
|
+
const { entries } = await writeSanityRuntime({
|
|
67
|
+
appTitle,
|
|
68
|
+
basePath,
|
|
69
|
+
cwd,
|
|
70
|
+
entry,
|
|
71
|
+
isApp,
|
|
72
|
+
isWorkbenchApp,
|
|
73
|
+
reactStrictMode: false,
|
|
74
|
+
watch: false
|
|
75
|
+
});
|
|
76
|
+
function getEnvironmentVariables() {
|
|
77
|
+
return isApp ? getAppEnvironmentVariables({
|
|
78
|
+
jsonEncode: true,
|
|
79
|
+
prefix: 'process.env.'
|
|
80
|
+
}) : getStudioEnvironmentVariables({
|
|
81
|
+
jsonEncode: true,
|
|
82
|
+
prefix: 'process.env.'
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
buildDebug('Resolving vite config');
|
|
86
|
+
let viteConfig = await getViteConfig({
|
|
87
|
+
autoUpdates,
|
|
88
|
+
basePath,
|
|
89
|
+
cwd,
|
|
90
|
+
entries,
|
|
91
|
+
getEnvironmentVariables,
|
|
92
|
+
isApp,
|
|
93
|
+
isWorkbenchApp,
|
|
94
|
+
minify,
|
|
95
|
+
mode,
|
|
96
|
+
outputDir,
|
|
97
|
+
reactCompiler,
|
|
98
|
+
schemaExtraction,
|
|
99
|
+
sourceMap
|
|
100
|
+
});
|
|
101
|
+
if (extendViteConfig) {
|
|
102
|
+
const defaultViteConfig = viteConfig;
|
|
103
|
+
viteConfig = await extendViteConfigWithUserConfig({
|
|
104
|
+
command: 'build',
|
|
105
|
+
mode
|
|
106
|
+
}, viteConfig, extendViteConfig);
|
|
107
|
+
viteConfig = await finalizeViteConfig(viteConfig, defaultViteConfig);
|
|
108
|
+
}
|
|
109
|
+
const fromPath = path.join(cwd, 'static');
|
|
110
|
+
// Copy files placed in /static to the built /static
|
|
111
|
+
buildDebug(`Copying static files from ${fromPath} to output dir`);
|
|
112
|
+
const staticPath = path.join(outputDir, 'static');
|
|
113
|
+
await copyDir(fromPath, staticPath);
|
|
114
|
+
// Write favicons, not overwriting ones that already exist, to static folder
|
|
115
|
+
buildDebug('Writing favicons to output dir');
|
|
116
|
+
const faviconBasePath = `${basePath.replace(/\/+$/, '')}/static`;
|
|
117
|
+
await writeFavicons(faviconBasePath, staticPath);
|
|
118
|
+
buildDebug('Bundling using vite');
|
|
119
|
+
const bundle = await build(viteConfig);
|
|
120
|
+
buildDebug('Bundling complete');
|
|
121
|
+
// For typescript only - this shouldn't ever be the case given we're not watching
|
|
122
|
+
if (Array.isArray(bundle) || !('output' in bundle)) {
|
|
123
|
+
return {
|
|
124
|
+
chunks: []
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
const stats = [];
|
|
128
|
+
for (const chunk of bundle.output){
|
|
129
|
+
if (chunk.type !== 'chunk') {
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
stats.push({
|
|
133
|
+
modules: Object.entries(chunk.modules).map(([rawFilePath, chunkModule])=>{
|
|
134
|
+
const filePath = rawFilePath.startsWith('\u0000') ? rawFilePath.slice('\u0000'.length) : rawFilePath;
|
|
135
|
+
return {
|
|
136
|
+
name: path.isAbsolute(filePath) ? path.relative(cwd, filePath) : filePath,
|
|
137
|
+
renderedLength: chunkModule.renderedLength
|
|
138
|
+
};
|
|
139
|
+
}),
|
|
140
|
+
name: chunk.name
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
chunks: stats
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
//# sourceMappingURL=buildStaticFiles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/build/buildStaticFiles.ts"],"sourcesContent":["import path from 'node:path'\n\nimport {type CliConfig, type UserViteConfig} from '@sanity/cli-core'\nimport {type DefineAppInput} from '@sanity/workbench-cli'\nimport {type PluginOptions as ReactCompilerConfig} from 'babel-plugin-react-compiler'\nimport {build, createBuilder} from 'vite'\n\nimport {copyDir} from '../../util/copyDir.js'\nimport {type AutoUpdatesBuildConfig} from './autoUpdates.js'\nimport {buildDebug} from './buildDebug.js'\nimport {\n getAppEnvironmentVariables,\n getStudioEnvironmentVariables,\n} from './getEnvironmentVariables.js'\nimport {extendViteConfigWithUserConfig, finalizeViteConfig, getViteConfig} from './getViteConfig.js'\nimport {writeFavicons} from './writeFavicons.js'\nimport {resolveEntries, writeSanityRuntime} from './writeSanityRuntime.js'\n\nexport interface ChunkModule {\n name: string\n renderedLength: number\n}\n\nexport interface ChunkStats {\n modules: ChunkModule[]\n name: string\n}\n\ninterface StaticBuildOptions {\n basePath: string\n cwd: string\n outputDir: string\n\n appTitle?: string\n autoUpdates?: AutoUpdatesBuildConfig\n entry?: string\n isApp?: boolean\n /** Workbench app (opted in via `unstable_defineApp`) — drives the federation build. */\n isWorkbenchApp?: boolean\n minify?: boolean\n profile?: boolean\n reactCompiler?: ReactCompilerConfig\n schemaExtraction?: CliConfig['schemaExtraction']\n services?: DefineAppInput['services']\n sourceMap?: boolean\n views?: DefineAppInput['views']\n vite?: UserViteConfig\n}\n\n/**\n * Builds static files\n *\n * @internal\n */\nexport async function buildStaticFiles(\n options: StaticBuildOptions,\n): Promise<{chunks: ChunkStats[]}> {\n const {\n appTitle,\n autoUpdates,\n basePath,\n cwd,\n entry,\n isApp,\n isWorkbenchApp,\n minify = true,\n outputDir,\n reactCompiler,\n schemaExtraction,\n services,\n sourceMap = false,\n views,\n vite: extendViteConfig,\n } = options\n\n const mode = 'production'\n\n /* Federation builds only produce the federation environment\n * (remote-entry, mf-manifest) — skip client-specific steps like\n * runtime generation, static file copies, and favicons.\n */\n if (isWorkbenchApp) {\n buildDebug('Resolving entries for federation build')\n const entries = await resolveEntries({cwd, entry, isApp, isWorkbenchApp})\n\n buildDebug('Resolving vite config (federation)')\n let viteConfig = await getViteConfig({\n basePath,\n cwd,\n entries,\n getEnvironmentVariables,\n isApp,\n isWorkbenchApp,\n minify,\n mode,\n outputDir,\n reactCompiler,\n // Schema extraction is a build-time artifact, not a client-specific step,\n // so a federated studio extracts its schema like the legacy studio build.\n schemaExtraction,\n services,\n sourceMap,\n views,\n })\n\n // Apply the user's Vite config so plugins like `@vanilla-extract/vite-plugin`\n // transform source files before the federation environment is bundled.\n // `finalizeViteConfig` is intentionally skipped: the federation environment\n // has its own entry and does not use `.sanity/runtime/app.js`.\n if (extendViteConfig) {\n viteConfig = await extendViteConfigWithUserConfig(\n {command: 'build', mode},\n viteConfig,\n extendViteConfig,\n )\n }\n\n buildDebug('Bundling federation environment')\n const builder = await createBuilder(viteConfig)\n await builder.buildApp()\n buildDebug('Bundling complete')\n // TODO: add stats here\n return {chunks: []}\n }\n\n buildDebug('Writing Sanity runtime files')\n const {entries} = await writeSanityRuntime({\n appTitle,\n basePath,\n cwd,\n entry,\n isApp,\n isWorkbenchApp,\n reactStrictMode: false,\n watch: false,\n })\n\n function getEnvironmentVariables() {\n return isApp\n ? getAppEnvironmentVariables({jsonEncode: true, prefix: 'process.env.'})\n : getStudioEnvironmentVariables({jsonEncode: true, prefix: 'process.env.'})\n }\n\n buildDebug('Resolving vite config')\n let viteConfig = await getViteConfig({\n autoUpdates,\n basePath,\n cwd,\n entries,\n getEnvironmentVariables,\n isApp,\n isWorkbenchApp,\n minify,\n mode,\n outputDir,\n reactCompiler,\n schemaExtraction,\n sourceMap,\n })\n\n if (extendViteConfig) {\n const defaultViteConfig = viteConfig\n viteConfig = await extendViteConfigWithUserConfig(\n {command: 'build', mode},\n viteConfig,\n extendViteConfig,\n )\n viteConfig = await finalizeViteConfig(viteConfig, defaultViteConfig)\n }\n\n const fromPath = path.join(cwd, 'static')\n // Copy files placed in /static to the built /static\n buildDebug(`Copying static files from ${fromPath} to output dir`)\n const staticPath = path.join(outputDir, 'static')\n await copyDir(fromPath, staticPath)\n\n // Write favicons, not overwriting ones that already exist, to static folder\n buildDebug('Writing favicons to output dir')\n const faviconBasePath = `${basePath.replace(/\\/+$/, '')}/static`\n await writeFavicons(faviconBasePath, staticPath)\n\n buildDebug('Bundling using vite')\n const bundle = await build(viteConfig)\n buildDebug('Bundling complete')\n\n // For typescript only - this shouldn't ever be the case given we're not watching\n if (Array.isArray(bundle) || !('output' in bundle)) {\n return {chunks: []}\n }\n\n const stats: ChunkStats[] = []\n for (const chunk of bundle.output) {\n if (chunk.type !== 'chunk') {\n continue\n }\n\n stats.push({\n modules: Object.entries(chunk.modules).map(([rawFilePath, chunkModule]) => {\n const filePath = rawFilePath.startsWith('\\u0000')\n ? rawFilePath.slice('\\u0000'.length)\n : rawFilePath\n\n return {\n name: path.isAbsolute(filePath) ? path.relative(cwd, filePath) : filePath,\n renderedLength: chunkModule.renderedLength,\n }\n }),\n name: chunk.name,\n })\n }\n\n return {chunks: stats}\n}\n"],"names":["path","build","createBuilder","copyDir","buildDebug","getAppEnvironmentVariables","getStudioEnvironmentVariables","extendViteConfigWithUserConfig","finalizeViteConfig","getViteConfig","writeFavicons","resolveEntries","writeSanityRuntime","buildStaticFiles","options","appTitle","autoUpdates","basePath","cwd","entry","isApp","isWorkbenchApp","minify","outputDir","reactCompiler","schemaExtraction","services","sourceMap","views","vite","extendViteConfig","mode","entries","viteConfig","getEnvironmentVariables","command","builder","buildApp","chunks","reactStrictMode","watch","jsonEncode","prefix","defaultViteConfig","fromPath","join","staticPath","faviconBasePath","replace","bundle","Array","isArray","stats","chunk","output","type","push","modules","Object","map","rawFilePath","chunkModule","filePath","startsWith","slice","length","name","isAbsolute","relative","renderedLength"],"mappings":"AAAA,OAAOA,UAAU,YAAW;AAK5B,SAAQC,KAAK,EAAEC,aAAa,QAAO,OAAM;AAEzC,SAAQC,OAAO,QAAO,wBAAuB;AAE7C,SAAQC,UAAU,QAAO,kBAAiB;AAC1C,SACEC,0BAA0B,EAC1BC,6BAA6B,QACxB,+BAA8B;AACrC,SAAQC,8BAA8B,EAAEC,kBAAkB,EAAEC,a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KAAKmE,UAAU,CAACL,YAAY9D,KAAKoE,QAAQ,CAAClD,KAAK4C,YAAYA;oBACjEO,gBAAgBR,YAAYQ,cAAc;gBAC5C;YACF;YACAH,MAAMb,MAAMa,IAAI;QAClB;IACF;IAEA,OAAO;QAAC5B,QAAQc;IAAK;AACvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/util/formatSize.ts"],"sourcesContent":["import {styleText} from 'node:util'\n\n/**\n * Formats bytes to kB\n *\n * @internal\n */\nexport function formatSize(bytes: number): string {\n return styleText('cyan', `${(bytes / 1024).toFixed(0)} kB`)\n}\n"],"names":["styleText","formatSize","bytes","toFixed"],"mappings":"AAAA,SAAQA,SAAS,QAAO,YAAW;AAEnC;;;;CAIC,GACD,OAAO,SAASC,WAAWC,KAAa;IACtC,OAAOF,UAAU,QAAQ,GAAG,AAACE,CAAAA,QAAQ,IAAG,EAAGC,OAAO,CAAC,GAAG,GAAG,CAAC;AAC5D"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { formatSize } from './formatSize.js';
|
|
2
|
+
export function formatModuleSizes(modules) {
|
|
3
|
+
const lines = [];
|
|
4
|
+
for (const mod of modules){
|
|
5
|
+
lines.push(` - ${formatModuleName(mod.name)} (${formatSize(mod.renderedLength)})`);
|
|
6
|
+
}
|
|
7
|
+
return lines.join('\n');
|
|
8
|
+
}
|
|
9
|
+
function formatModuleName(modName) {
|
|
10
|
+
const delimiter = '/node_modules/';
|
|
11
|
+
const nodeIndex = modName.lastIndexOf(delimiter);
|
|
12
|
+
return nodeIndex === -1 ? modName : modName.slice(nodeIndex + delimiter.length);
|
|
13
|
+
}
|
|
14
|
+
export function sortModulesBySize(chunks) {
|
|
15
|
+
return chunks.flatMap((chunk)=>chunk.modules).toSorted((modA, modB)=>modB.renderedLength - modA.renderedLength);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=moduleFormatUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/util/moduleFormatUtils.ts"],"sourcesContent":["import {type ChunkModule, type ChunkStats} from '../actions/build/buildStaticFiles.js'\nimport {formatSize} from './formatSize.js'\n\nexport function formatModuleSizes(modules: ChunkModule[]): string {\n const lines: string[] = []\n for (const mod of modules) {\n lines.push(` - ${formatModuleName(mod.name)} (${formatSize(mod.renderedLength)})`)\n }\n\n return lines.join('\\n')\n}\n\nfunction formatModuleName(modName: string): string {\n const delimiter = '/node_modules/'\n const nodeIndex = modName.lastIndexOf(delimiter)\n return nodeIndex === -1 ? modName : modName.slice(nodeIndex + delimiter.length)\n}\n\nexport function sortModulesBySize(chunks: ChunkStats[]): ChunkModule[] {\n return chunks\n .flatMap((chunk) => chunk.modules)\n .toSorted((modA, modB) => modB.renderedLength - modA.renderedLength)\n}\n"],"names":["formatSize","formatModuleSizes","modules","lines","mod","push","formatModuleName","name","renderedLength","join","modName","delimiter","nodeIndex","lastIndexOf","slice","length","sortModulesBySize","chunks","flatMap","chunk","toSorted","modA","modB"],"mappings":"AACA,SAAQA,UAAU,QAAO,kBAAiB;AAE1C,OAAO,SAASC,kBAAkBC,OAAsB;IACtD,MAAMC,QAAkB,EAAE;IAC1B,KAAK,MAAMC,OAAOF,QAAS;QACzBC,MAAME,IAAI,CAAC,CAAC,GAAG,EAAEC,iBAAiBF,IAAIG,IAAI,EAAE,EAAE,EAAEP,WAAWI,IAAII,cAAc,EAAE,CAAC,CAAC;IACnF;IAEA,OAAOL,MAAMM,IAAI,CAAC;AACpB;AAEA,SAASH,iBAAiBI,OAAe;IACvC,MAAMC,YAAY;IAClB,MAAMC,YAAYF,QAAQG,WAAW,CAACF;IACtC,OAAOC,cAAc,CAAC,IAAIF,UAAUA,QAAQI,KAAK,CAACF,YAAYD,UAAUI,MAAM;AAChF;AAEA,OAAO,SAASC,kBAAkBC,MAAoB;IACpD,OAAOA,OACJC,OAAO,CAAC,CAACC,QAAUA,MAAMjB,OAAO,EAChCkB,QAAQ,CAAC,CAACC,MAAMC,OAASA,KAAKd,cAAc,GAAGa,KAAKb,cAAc;AACvE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/cli-build",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Internal Sanity package for building studios and apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -64,10 +64,10 @@
|
|
|
64
64
|
"react-dom": "^19.2.7",
|
|
65
65
|
"read-package-up": "^12.0.0",
|
|
66
66
|
"semver": "^7.8.1",
|
|
67
|
-
"vite": "
|
|
67
|
+
"vite": "8.1.0",
|
|
68
68
|
"zod": "^4.4.3",
|
|
69
|
-
"@sanity/cli-core": "^2.1.
|
|
70
|
-
"@sanity/workbench-cli": "^1.1.
|
|
69
|
+
"@sanity/cli-core": "^2.1.2",
|
|
70
|
+
"@sanity/workbench-cli": "^1.1.2"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@eslint/compat": "^2.1.0",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"vitest": "^4.1.9",
|
|
95
95
|
"@repo/package.config": "0.0.1",
|
|
96
96
|
"@repo/tsconfig": "3.70.0",
|
|
97
|
-
"@sanity/cli-test": "2.0.
|
|
97
|
+
"@sanity/cli-test": "2.0.2",
|
|
98
98
|
"@sanity/eslint-config-cli": "^1.1.2"
|
|
99
99
|
},
|
|
100
100
|
"peerDependencies": {
|