@sanity/cli 7.2.3 → 7.3.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/bin/run.js +3 -12
- package/dist/actions/auth/authServer.js +37 -20
- package/dist/actions/auth/authServer.js.map +1 -1
- package/dist/actions/backup/assertDatasetExist.js +3 -3
- package/dist/actions/backup/assertDatasetExist.js.map +1 -1
- package/dist/actions/build/buildApp.js +15 -5
- package/dist/actions/build/buildApp.js.map +1 -1
- package/dist/actions/build/buildStaticFiles.js +57 -5
- package/dist/actions/build/buildStaticFiles.js.map +1 -1
- package/dist/actions/build/buildStudio.js +13 -5
- package/dist/actions/build/buildStudio.js.map +1 -1
- package/dist/actions/build/handlePrereleaseVersions.js +2 -2
- package/dist/actions/build/handlePrereleaseVersions.js.map +1 -1
- package/dist/actions/dataset/resolveDataset.js +2 -2
- package/dist/actions/dataset/resolveDataset.js.map +1 -1
- package/dist/actions/deploy/deployApp.js +43 -5
- package/dist/actions/deploy/deployApp.js.map +1 -1
- package/dist/actions/deploy/deployStudio.js +14 -2
- package/dist/actions/deploy/deployStudio.js.map +1 -1
- package/dist/actions/deploy/viewDeployment.js +32 -0
- package/dist/actions/deploy/viewDeployment.js.map +1 -0
- package/dist/actions/dev/devAction.js +219 -4
- package/dist/actions/dev/devAction.js.map +1 -1
- package/dist/actions/dev/registration/deriveInterfaces.js +46 -0
- package/dist/actions/dev/registration/deriveInterfaces.js.map +1 -0
- package/dist/actions/dev/registration/extractDevServerManifest.js +30 -0
- package/dist/actions/dev/registration/extractDevServerManifest.js.map +1 -0
- package/dist/actions/dev/registration/interfaceSetId.js +41 -0
- package/dist/actions/dev/registration/interfaceSetId.js.map +1 -0
- package/dist/actions/dev/registration/startDevManifestWatcher.js +104 -0
- package/dist/actions/dev/registration/startDevManifestWatcher.js.map +1 -0
- package/dist/actions/dev/registration/startDevServerRegistration.js +121 -0
- package/dist/actions/dev/registration/startDevServerRegistration.js.map +1 -0
- package/dist/actions/dev/servers/getDashboardAppUrl.js.map +1 -0
- package/dist/actions/dev/servers/getDevServerConfig.js +45 -0
- package/dist/actions/dev/servers/getDevServerConfig.js.map +1 -0
- package/dist/actions/dev/servers/startAppDevServer.js +78 -0
- package/dist/actions/dev/servers/startAppDevServer.js.map +1 -0
- package/dist/actions/dev/{startStudioDevServer.js → servers/startStudioDevServer.js} +20 -16
- package/dist/actions/dev/servers/startStudioDevServer.js.map +1 -0
- package/dist/actions/dev/types.js +7 -1
- package/dist/actions/dev/types.js.map +1 -1
- package/dist/actions/dev/workbench/startWorkbenchDevServer.js +276 -0
- package/dist/actions/dev/workbench/startWorkbenchDevServer.js.map +1 -0
- package/dist/actions/dev/workbench/writeWorkbenchRuntime.js +66 -0
- package/dist/actions/dev/workbench/writeWorkbenchRuntime.js.map +1 -0
- package/dist/actions/init/bootstrapLocalTemplate.js +15 -3
- package/dist/actions/init/bootstrapLocalTemplate.js.map +1 -1
- package/dist/actions/init/bootstrapTemplate.js +3 -2
- package/dist/actions/init/bootstrapTemplate.js.map +1 -1
- package/dist/actions/init/createAppCliConfig.js +5 -2
- package/dist/actions/init/createAppCliConfig.js.map +1 -1
- package/dist/actions/init/createCliConfig.js +5 -3
- package/dist/actions/init/createCliConfig.js.map +1 -1
- package/dist/actions/init/createStudioConfig.js.map +1 -1
- package/dist/actions/init/initAction.js +11 -4
- package/dist/actions/init/initAction.js.map +1 -1
- package/dist/actions/init/initApp.js +2 -1
- package/dist/actions/init/initApp.js.map +1 -1
- package/dist/actions/init/initStudio.js +2 -1
- package/dist/actions/init/initStudio.js.map +1 -1
- package/dist/actions/init/scaffoldTemplate.js +3 -2
- package/dist/actions/init/scaffoldTemplate.js.map +1 -1
- package/dist/actions/init/templates/pageBuilder.js +1 -1
- package/dist/actions/init/templates/pageBuilder.js.map +1 -1
- package/dist/actions/init/types.js +1 -0
- package/dist/actions/init/types.js.map +1 -1
- package/dist/actions/manifest/{extractAppManifest.js → extractCoreAppManifest.js} +30 -11
- package/dist/actions/manifest/extractCoreAppManifest.js.map +1 -0
- package/dist/actions/manifest/extractManifest.js +7 -7
- package/dist/actions/manifest/extractManifest.js.map +1 -1
- package/dist/actions/manifest/iconResolver.js +2 -3
- package/dist/actions/manifest/iconResolver.js.map +1 -1
- package/dist/actions/manifest/sanitizeIcon.js +13 -0
- package/dist/actions/manifest/sanitizeIcon.js.map +1 -0
- package/dist/actions/manifest/types.js +4 -9
- package/dist/actions/manifest/types.js.map +1 -1
- package/dist/actions/manifest/writeManifestFile.js +1 -1
- package/dist/actions/manifest/writeManifestFile.js.map +1 -1
- package/dist/actions/mcp/editorConfigs.js +26 -2
- package/dist/actions/mcp/editorConfigs.js.map +1 -1
- package/dist/actions/mcp/setupMCP.js +24 -25
- package/dist/actions/mcp/setupMCP.js.map +1 -1
- package/dist/actions/mcp/types.js.map +1 -1
- package/dist/actions/skills/configureSkills.js +49 -0
- package/dist/actions/skills/configureSkills.js.map +1 -0
- package/dist/actions/skills/readSkillState.js +40 -5
- package/dist/actions/skills/readSkillState.js.map +1 -1
- package/dist/actions/skills/setupSkills.js +47 -6
- package/dist/actions/skills/setupSkills.js.map +1 -1
- package/dist/actions/skills/skillCandidates.js +40 -0
- package/dist/actions/skills/skillCandidates.js.map +1 -0
- package/dist/actions/telemetry/telemetryDisclosure.js +2 -3
- package/dist/actions/telemetry/telemetryDisclosure.js.map +1 -1
- package/dist/actions/tokens/validateRole.js +3 -3
- package/dist/actions/tokens/validateRole.js.map +1 -1
- package/dist/commands/backups/disable.js +1 -1
- package/dist/commands/backups/disable.js.map +1 -1
- package/dist/commands/backups/download.js +1 -1
- package/dist/commands/backups/download.js.map +1 -1
- package/dist/commands/backups/enable.js +1 -1
- package/dist/commands/backups/enable.js.map +1 -1
- package/dist/commands/backups/list.js +1 -1
- package/dist/commands/backups/list.js.map +1 -1
- package/dist/commands/datasets/embeddings/disable.js +1 -0
- package/dist/commands/datasets/embeddings/disable.js.map +1 -1
- package/dist/commands/datasets/embeddings/enable.js +1 -0
- package/dist/commands/datasets/embeddings/enable.js.map +1 -1
- package/dist/commands/datasets/embeddings/status.js +1 -0
- package/dist/commands/datasets/embeddings/status.js.map +1 -1
- package/dist/commands/dev.js +11 -1
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/init.js +7 -0
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/manifest/extract.js +7 -2
- package/dist/commands/manifest/extract.js.map +1 -1
- package/dist/commands/mcp/configure.js +1 -0
- package/dist/commands/mcp/configure.js.map +1 -1
- package/dist/commands/skills/install.js +40 -0
- package/dist/commands/skills/install.js.map +1 -0
- package/dist/commands/tokens/add.js +1 -1
- package/dist/commands/tokens/add.js.map +1 -1
- package/dist/exports/index.d.ts +6 -0
- package/dist/exports/index.js +8 -0
- package/dist/exports/index.js.map +1 -1
- package/dist/exports/runtime.d.ts +41 -0
- package/dist/exports/runtime.js +13 -0
- package/dist/exports/runtime.js.map +1 -0
- package/dist/hooks/prerun/setupTelemetry.js +3 -1
- package/dist/hooks/prerun/setupTelemetry.js.map +1 -1
- package/dist/server/devServer.js +8 -3
- package/dist/server/devServer.js.map +1 -1
- package/dist/services/documents.js +0 -1
- package/dist/services/documents.js.map +1 -1
- package/dist/telemetry/skills.telemetry.js +8 -0
- package/dist/telemetry/skills.telemetry.js.map +1 -0
- package/dist/util/compareDependencyVersions.js +1 -1
- package/dist/util/compareDependencyVersions.js.map +1 -1
- package/dist/util/determineIsApp.js +12 -1
- package/dist/util/determineIsApp.js.map +1 -1
- package/dist/util/getSharedServerConfig.js +2 -1
- package/dist/util/getSharedServerConfig.js.map +1 -1
- package/dist/util/resolveReactStrictMode.js +11 -0
- package/dist/util/resolveReactStrictMode.js.map +1 -0
- package/oclif.config.js +2 -1
- package/oclif.manifest.json +146 -113
- package/package.json +26 -17
- package/templates/page-builder/schemaTypes/index.js +1 -1
- package/dist/actions/build/checkRequiredDependencies.js +0 -124
- package/dist/actions/build/checkRequiredDependencies.js.map +0 -1
- package/dist/actions/build/getAutoUpdatesImportMap.js +0 -66
- package/dist/actions/build/getAutoUpdatesImportMap.js.map +0 -1
- package/dist/actions/dev/getDashboardAppUrl.js.map +0 -1
- package/dist/actions/dev/getDevServerConfig.js +0 -32
- package/dist/actions/dev/getDevServerConfig.js.map +0 -1
- package/dist/actions/dev/startAppDevServer.js +0 -59
- package/dist/actions/dev/startAppDevServer.js.map +0 -1
- package/dist/actions/dev/startStudioDevServer.js.map +0 -1
- package/dist/actions/manifest/extractAppManifest.js.map +0 -1
- /package/dist/actions/dev/{getDashboardAppUrl.js → servers/getDashboardAppUrl.js} +0 -0
package/bin/run.js
CHANGED
|
@@ -6,25 +6,16 @@ var nodeVersionParts = process.version.replace(/^v/i, '').split('.').map(Number)
|
|
|
6
6
|
|
|
7
7
|
var majorVersion = nodeVersionParts[0]
|
|
8
8
|
var minorVersion = nodeVersionParts[1]
|
|
9
|
-
var patchVersion = nodeVersionParts[2]
|
|
10
9
|
|
|
11
|
-
function isSupportedNodeVersion(major, minor
|
|
12
|
-
if (major === 20) {
|
|
13
|
-
if (minor > 19) return true
|
|
14
|
-
if (minor === 19 && patch >= 1) return true
|
|
15
|
-
return false
|
|
16
|
-
}
|
|
17
|
-
if (major === 21) return true
|
|
10
|
+
function isSupportedNodeVersion(major, minor) {
|
|
18
11
|
if (major === 22 && minor >= 12) return true
|
|
19
12
|
if (major > 22) return true
|
|
20
13
|
return false
|
|
21
14
|
}
|
|
22
15
|
|
|
23
|
-
if (!isSupportedNodeVersion(majorVersion, minorVersion
|
|
16
|
+
if (!isSupportedNodeVersion(majorVersion, minorVersion)) {
|
|
24
17
|
// eslint-disable-next-line no-console
|
|
25
|
-
console.error(
|
|
26
|
-
`${err}Node.js version >=20.19.1 <22 or >=22.12 required. You are running ${process.version}`,
|
|
27
|
-
)
|
|
18
|
+
console.error(`${err}Node.js version >=22.12 required. You are running ${process.version}`)
|
|
28
19
|
// eslint-disable-next-line no-console
|
|
29
20
|
console.error('')
|
|
30
21
|
process.exit(1)
|
|
@@ -3,15 +3,35 @@ import os from 'node:os';
|
|
|
3
3
|
import { getSanityUrl, subdebug } from '@sanity/cli-core';
|
|
4
4
|
import { getTokenDetails } from '../../services/auth.js';
|
|
5
5
|
const debug = subdebug('auth');
|
|
6
|
-
const
|
|
7
|
-
4321,
|
|
8
|
-
4000,
|
|
9
|
-
3003,
|
|
10
|
-
1234,
|
|
11
|
-
8080,
|
|
12
|
-
13_333
|
|
13
|
-
];
|
|
6
|
+
const defaultCallbackPort = 4321;
|
|
14
7
|
const callbackEndpoint = '/callback';
|
|
8
|
+
/**
|
|
9
|
+
* Get the port to first attempt binding the auth callback server to.
|
|
10
|
+
*
|
|
11
|
+
* The auth backend accepts any `http://localhost:<port>` origin for token
|
|
12
|
+
* callbacks, but we prefer a predictable port: it is friendlier for users who
|
|
13
|
+
* need to allow or forward the port (e.g. logging in from a remote machine over
|
|
14
|
+
* an SSH tunnel). If the preferred port is taken, we fall back to an
|
|
15
|
+
* OS-assigned ephemeral port.
|
|
16
|
+
*
|
|
17
|
+
* The `SANITY_CLI_CALLBACK_PORT` environment variable overrides the preferred
|
|
18
|
+
* port (`0` for an OS-assigned port). The override exists primarily for tests,
|
|
19
|
+
* where OS-assigned ports prevent collisions between tests running in parallel.
|
|
20
|
+
*
|
|
21
|
+
* @returns Port number to attempt first
|
|
22
|
+
* @internal
|
|
23
|
+
*/ function getPreferredCallbackPort() {
|
|
24
|
+
const override = process.env.SANITY_CLI_CALLBACK_PORT;
|
|
25
|
+
if (!override) {
|
|
26
|
+
return defaultCallbackPort;
|
|
27
|
+
}
|
|
28
|
+
debug('Using callback port from SANITY_CLI_CALLBACK_PORT: %s', override);
|
|
29
|
+
const port = Number.parseInt(override.trim(), 10);
|
|
30
|
+
if (Number.isNaN(port) || port < 0 || port > 65_535) {
|
|
31
|
+
throw new Error(`Invalid SANITY_CLI_CALLBACK_PORT value: "${override}"`);
|
|
32
|
+
}
|
|
33
|
+
return port;
|
|
34
|
+
}
|
|
15
35
|
const platformNames = {
|
|
16
36
|
aix: 'AIX',
|
|
17
37
|
android: 'Android',
|
|
@@ -29,17 +49,13 @@ const platformNames = {
|
|
|
29
49
|
* do a request to the `/auth/fetch` endpoint with to get the actual auth token,
|
|
30
50
|
* invalidating the SID in the process.
|
|
31
51
|
*
|
|
32
|
-
* If we fail to bind to the
|
|
52
|
+
* If we fail to bind to the preferred port, we retry with an OS-assigned port.
|
|
33
53
|
*
|
|
34
54
|
* @param providerUrl - The URL of the login provider
|
|
35
55
|
* @returns Resolves with HTTP server instance, a login URL to send user to, and a `token` promise
|
|
36
56
|
* @internal
|
|
37
57
|
*/ export function startServerForTokenCallback(providerUrl) {
|
|
38
58
|
const sanityUrl = getSanityUrl();
|
|
39
|
-
const attemptPorts = [
|
|
40
|
-
...callbackPorts
|
|
41
|
-
];
|
|
42
|
-
let callbackPort = attemptPorts.shift();
|
|
43
59
|
// note: replace with `Promise.withResolvers()` when minimum Node.js is 22+
|
|
44
60
|
let resolveToken;
|
|
45
61
|
let rejectToken;
|
|
@@ -48,6 +64,7 @@ const platformNames = {
|
|
|
48
64
|
rejectToken = reject;
|
|
49
65
|
});
|
|
50
66
|
return new Promise((resolve, reject)=>{
|
|
67
|
+
let callbackPort = getPreferredCallbackPort();
|
|
51
68
|
const server = createServer(async function onCallbackServerRequest(req, res) {
|
|
52
69
|
function failLoginRequest(code = '') {
|
|
53
70
|
res.writeHead(303, 'See Other', {
|
|
@@ -107,13 +124,13 @@ const platformNames = {
|
|
|
107
124
|
});
|
|
108
125
|
});
|
|
109
126
|
server.on('error', function onCallbackServerError(err) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
127
|
+
// The auth backend accepts any localhost port in the callback origin, so if
|
|
128
|
+
// the preferred port is busy we fall back to an OS-assigned ephemeral port.
|
|
129
|
+
// Port 0 cannot itself be "in use" - an EADDRINUSE there means something is
|
|
130
|
+
// genuinely wrong, so only fall back once.
|
|
131
|
+
if ('code' in err && err.code === 'EADDRINUSE' && callbackPort !== 0) {
|
|
132
|
+
debug('Port %d busy, falling back to OS-assigned port', callbackPort);
|
|
133
|
+
callbackPort = 0;
|
|
117
134
|
server.listen(callbackPort);
|
|
118
135
|
} else {
|
|
119
136
|
reject(err);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/auth/authServer.ts"],"sourcesContent":["import {createServer, type Server} from 'node:http'\nimport os from 'node:os'\n\nimport {getSanityUrl, subdebug} from '@sanity/cli-core'\n\nimport {getTokenDetails} from '../../services/auth.js'\nimport {type TokenDetails} from './types.js'\n\nconst debug = subdebug('auth')\nconst callbackPorts = [4321, 4000, 3003, 1234, 8080, 13_333]\nconst callbackEndpoint = '/callback'\n\nconst platformNames: Record<string, string | undefined> = {\n aix: 'AIX',\n android: 'Android',\n darwin: 'MacOS',\n freebsd: 'FreeBSD',\n linux: 'Linux',\n openbsd: 'OpenBSD',\n sunos: 'SunOS',\n win32: 'Windows',\n}\n\n/**\n * Start a local HTTP server and wait for a request to the auth callback endpoint.\n * This happens by the user being sent to a login page with a callback URL that points to\n * this local server. This request includes a short-lived \"SID\" (session ID) that we then\n * do a request to the `/auth/fetch` endpoint with to get the actual auth token,\n * invalidating the SID in the process.\n *\n * If we fail to bind to the first port, we retry with the next port in the list.\n *\n * @param providerUrl - The URL of the login provider\n * @returns Resolves with HTTP server instance, a login URL to send user to, and a `token` promise\n * @internal\n */\nexport function startServerForTokenCallback(\n providerUrl: string,\n): Promise<{loginUrl: URL; server: Server; token: Promise<TokenDetails>}> {\n const sanityUrl = getSanityUrl()\n\n const attemptPorts = [...callbackPorts]\n let callbackPort = attemptPorts.shift()\n\n // note: replace with `Promise.withResolvers()` when minimum Node.js is 22+\n let resolveToken: (resolvedToken: PromiseLike<TokenDetails> | TokenDetails) => void\n let rejectToken: (reason: Error) => void\n const tokenPromise = new Promise<TokenDetails>((resolve, reject) => {\n resolveToken = resolve\n rejectToken = reject\n })\n\n return new Promise((resolve, reject) => {\n const server = createServer(async function onCallbackServerRequest(req, res) {\n function failLoginRequest(code = '') {\n res.writeHead(303, 'See Other', {\n Connection: 'close',\n Location: `${sanityUrl}/login/error${code ? `?error=${code}` : ''}`,\n })\n res.end()\n server.close()\n }\n\n const url = new URL(req.url || '/', `http://localhost:${callbackPort}`)\n if (url.pathname !== callbackEndpoint) {\n res.writeHead(404, 'Not Found', {Connection: 'close', 'Content-Type': 'text/plain'})\n res.write('404 Not Found')\n res.end()\n return\n }\n\n const absoluteTokenUrl = url.searchParams.get('url')\n if (!absoluteTokenUrl) {\n failLoginRequest()\n rejectToken(new Error('Missing callback URL'))\n return\n }\n\n const tokenUrl = new URL(absoluteTokenUrl)\n if (!tokenUrl.searchParams.has('sid')) {\n failLoginRequest('NO_SESSION_ID')\n rejectToken(new Error('Missing session ID in callback'))\n return\n }\n\n let token: TokenDetails\n try {\n token = await getTokenDetails(tokenUrl.search)\n } catch (err) {\n failLoginRequest('UNRESOLVED_SESSION')\n rejectToken(err instanceof Error ? err : new Error(`Unknown error: ${err}`))\n return\n }\n\n res.writeHead(303, 'See Other', {\n Connection: 'close',\n Location: `${sanityUrl}/login/success`,\n })\n res.end()\n server.close()\n resolveToken(token)\n })\n\n server.on('listening', function onCallbackListen() {\n // Once the server is successfully listening on a port, we can return the promise.\n // We'll then await the _token promise_, while the server is running in the background.\n const callbackUrl = getCallbackUrl(server)\n const loginUrl = getLoginUrl(providerUrl, callbackUrl)\n resolve({loginUrl, server, token: tokenPromise})\n })\n\n server.on('error', function onCallbackServerError(err) {\n if ('code' in err && err.code === 'EADDRINUSE') {\n callbackPort = attemptPorts.shift()\n if (!callbackPort) {\n reject(new Error('Failed to find port number to bind auth callback server to'))\n return\n }\n\n debug('Port busy, trying %d', callbackPort)\n server.listen(callbackPort)\n } else {\n reject(err)\n }\n })\n\n debug('Starting callback server on port %d', callbackPort)\n server.listen(callbackPort)\n })\n}\n\n/**\n * Get the login URL to send the user to for the given auth provider.\n *\n * The generated URL will include a label for the session that includes the\n * hostname and platform of the current computer, to help identify the session.\n *\n * @param providerUrl - The URL of the login provider\n * @param callbackUrl - The callback URL for the local auth token server\n * @returns The login URL\n * @internal\n */\nfunction getLoginUrl(providerUrl: string, callbackUrl: URL): URL {\n // Build a login URL that redirects back back to OAuth flow on success\n const loginUrl = new URL(providerUrl)\n\n // Prefer `MacOS` over `darwin` etc\n const platformName = os.platform()\n const platform = platformName in platformNames ? platformNames[platformName] : platformName\n\n // Prefer `espens-macbook` over `espens-macbook.local`\n const hostname = os.hostname().replaceAll(/\\.(local|lan)$/g, '')\n\n loginUrl.searchParams.set('type', 'token')\n loginUrl.searchParams.set('label', `${hostname} / ${platform}`)\n loginUrl.searchParams.set('origin', callbackUrl.href)\n\n return loginUrl\n}\n\nfunction getCallbackUrl(server: Server): URL {\n const serverUrl = server.address()\n if (!serverUrl || typeof serverUrl === 'string') {\n // Note: `serverUrl` is string only when binding to unix sockets,\n // thus we can safely assume Something Is Wrong™ if it's a string\n throw new Error('Failed to start auth callback server')\n }\n\n return new URL(callbackEndpoint, `http://localhost:${serverUrl.port}`)\n}\n"],"names":["createServer","os","getSanityUrl","subdebug","getTokenDetails","debug","callbackPorts","callbackEndpoint","platformNames","aix","android","darwin","freebsd","linux","openbsd","sunos","win32","startServerForTokenCallback","providerUrl","sanityUrl","attemptPorts","callbackPort","shift","resolveToken","rejectToken","tokenPromise","Promise","resolve","reject","server","onCallbackServerRequest","req","res","failLoginRequest","code","writeHead","Connection","Location","end","close","url","URL","pathname","write","absoluteTokenUrl","searchParams","get","Error","tokenUrl","has","token","search","err","on","onCallbackListen","callbackUrl","getCallbackUrl","loginUrl","getLoginUrl","onCallbackServerError","listen","platformName","platform","hostname","replaceAll","set","href","serverUrl","address","port"],"mappings":"AAAA,SAAQA,YAAY,QAAoB,YAAW;AACnD,OAAOC,QAAQ,UAAS;AAExB,SAAQC,YAAY,EAAEC,QAAQ,QAAO,mBAAkB;AAEvD,SAAQC,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mCAAmC;IACnC,MAAM2C,eAAe5D,GAAG6D,QAAQ;IAChC,MAAMA,WAAWD,gBAAgBrD,gBAAgBA,aAAa,CAACqD,aAAa,GAAGA;IAE/E,sDAAsD;IACtD,MAAME,WAAW9D,GAAG8D,QAAQ,GAAGC,UAAU,CAAC,mBAAmB;IAE7DP,SAASZ,YAAY,CAACoB,GAAG,CAAC,QAAQ;IAClCR,SAASZ,YAAY,CAACoB,GAAG,CAAC,SAAS,GAAGF,SAAS,GAAG,EAAED,UAAU;IAC9DL,SAASZ,YAAY,CAACoB,GAAG,CAAC,UAAUV,YAAYW,IAAI;IAEpD,OAAOT;AACT;AAEA,SAASD,eAAe3B,MAAc;IACpC,MAAMsC,YAAYtC,OAAOuC,OAAO;IAChC,IAAI,CAACD,aAAa,OAAOA,cAAc,UAAU;QAC/C,iEAAiE;QACjE,iEAAiE;QACjE,MAAM,IAAIpB,MAAM;IAClB;IAEA,OAAO,IAAIN,IAAIlC,kBAAkB,CAAC,iBAAiB,EAAE4D,UAAUE,IAAI,EAAE;AACvE"}
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/auth/authServer.ts"],"sourcesContent":["import {createServer, type Server} from 'node:http'\nimport os from 'node:os'\n\nimport {getSanityUrl, subdebug} from '@sanity/cli-core'\n\nimport {getTokenDetails} from '../../services/auth.js'\nimport {type TokenDetails} from './types.js'\n\nconst debug = subdebug('auth')\nconst defaultCallbackPort = 4321\nconst callbackEndpoint = '/callback'\n\n/**\n * Get the port to first attempt binding the auth callback server to.\n *\n * The auth backend accepts any `http://localhost:<port>` origin for token\n * callbacks, but we prefer a predictable port: it is friendlier for users who\n * need to allow or forward the port (e.g. logging in from a remote machine over\n * an SSH tunnel). If the preferred port is taken, we fall back to an\n * OS-assigned ephemeral port.\n *\n * The `SANITY_CLI_CALLBACK_PORT` environment variable overrides the preferred\n * port (`0` for an OS-assigned port). The override exists primarily for tests,\n * where OS-assigned ports prevent collisions between tests running in parallel.\n *\n * @returns Port number to attempt first\n * @internal\n */\nfunction getPreferredCallbackPort(): number {\n const override = process.env.SANITY_CLI_CALLBACK_PORT\n if (!override) {\n return defaultCallbackPort\n }\n\n debug('Using callback port from SANITY_CLI_CALLBACK_PORT: %s', override)\n\n const port = Number.parseInt(override.trim(), 10)\n if (Number.isNaN(port) || port < 0 || port > 65_535) {\n throw new Error(`Invalid SANITY_CLI_CALLBACK_PORT value: \"${override}\"`)\n }\n\n return port\n}\n\nconst platformNames: Record<string, string | undefined> = {\n aix: 'AIX',\n android: 'Android',\n darwin: 'MacOS',\n freebsd: 'FreeBSD',\n linux: 'Linux',\n openbsd: 'OpenBSD',\n sunos: 'SunOS',\n win32: 'Windows',\n}\n\n/**\n * Start a local HTTP server and wait for a request to the auth callback endpoint.\n * This happens by the user being sent to a login page with a callback URL that points to\n * this local server. This request includes a short-lived \"SID\" (session ID) that we then\n * do a request to the `/auth/fetch` endpoint with to get the actual auth token,\n * invalidating the SID in the process.\n *\n * If we fail to bind to the preferred port, we retry with an OS-assigned port.\n *\n * @param providerUrl - The URL of the login provider\n * @returns Resolves with HTTP server instance, a login URL to send user to, and a `token` promise\n * @internal\n */\nexport function startServerForTokenCallback(\n providerUrl: string,\n): Promise<{loginUrl: URL; server: Server; token: Promise<TokenDetails>}> {\n const sanityUrl = getSanityUrl()\n\n // note: replace with `Promise.withResolvers()` when minimum Node.js is 22+\n let resolveToken: (resolvedToken: PromiseLike<TokenDetails> | TokenDetails) => void\n let rejectToken: (reason: Error) => void\n const tokenPromise = new Promise<TokenDetails>((resolve, reject) => {\n resolveToken = resolve\n rejectToken = reject\n })\n\n return new Promise((resolve, reject) => {\n let callbackPort = getPreferredCallbackPort()\n\n const server = createServer(async function onCallbackServerRequest(req, res) {\n function failLoginRequest(code = '') {\n res.writeHead(303, 'See Other', {\n Connection: 'close',\n Location: `${sanityUrl}/login/error${code ? `?error=${code}` : ''}`,\n })\n res.end()\n server.close()\n }\n\n const url = new URL(req.url || '/', `http://localhost:${callbackPort}`)\n if (url.pathname !== callbackEndpoint) {\n res.writeHead(404, 'Not Found', {Connection: 'close', 'Content-Type': 'text/plain'})\n res.write('404 Not Found')\n res.end()\n return\n }\n\n const absoluteTokenUrl = url.searchParams.get('url')\n if (!absoluteTokenUrl) {\n failLoginRequest()\n rejectToken(new Error('Missing callback URL'))\n return\n }\n\n const tokenUrl = new URL(absoluteTokenUrl)\n if (!tokenUrl.searchParams.has('sid')) {\n failLoginRequest('NO_SESSION_ID')\n rejectToken(new Error('Missing session ID in callback'))\n return\n }\n\n let token: TokenDetails\n try {\n token = await getTokenDetails(tokenUrl.search)\n } catch (err) {\n failLoginRequest('UNRESOLVED_SESSION')\n rejectToken(err instanceof Error ? err : new Error(`Unknown error: ${err}`))\n return\n }\n\n res.writeHead(303, 'See Other', {\n Connection: 'close',\n Location: `${sanityUrl}/login/success`,\n })\n res.end()\n server.close()\n resolveToken(token)\n })\n\n server.on('listening', function onCallbackListen() {\n // Once the server is successfully listening on a port, we can return the promise.\n // We'll then await the _token promise_, while the server is running in the background.\n const callbackUrl = getCallbackUrl(server)\n const loginUrl = getLoginUrl(providerUrl, callbackUrl)\n resolve({loginUrl, server, token: tokenPromise})\n })\n\n server.on('error', function onCallbackServerError(err) {\n // The auth backend accepts any localhost port in the callback origin, so if\n // the preferred port is busy we fall back to an OS-assigned ephemeral port.\n // Port 0 cannot itself be \"in use\" - an EADDRINUSE there means something is\n // genuinely wrong, so only fall back once.\n if ('code' in err && err.code === 'EADDRINUSE' && callbackPort !== 0) {\n debug('Port %d busy, falling back to OS-assigned port', callbackPort)\n callbackPort = 0\n server.listen(callbackPort)\n } else {\n reject(err)\n }\n })\n\n debug('Starting callback server on port %d', callbackPort)\n server.listen(callbackPort)\n })\n}\n\n/**\n * Get the login URL to send the user to for the given auth provider.\n *\n * The generated URL will include a label for the session that includes the\n * hostname and platform of the current computer, to help identify the session.\n *\n * @param providerUrl - The URL of the login provider\n * @param callbackUrl - The callback URL for the local auth token server\n * @returns The login URL\n * @internal\n */\nfunction getLoginUrl(providerUrl: string, callbackUrl: URL): URL {\n // Build a login URL that redirects back back to OAuth flow on success\n const loginUrl = new URL(providerUrl)\n\n // Prefer `MacOS` over `darwin` etc\n const platformName = os.platform()\n const platform = platformName in platformNames ? platformNames[platformName] : platformName\n\n // Prefer `espens-macbook` over `espens-macbook.local`\n const hostname = os.hostname().replaceAll(/\\.(local|lan)$/g, '')\n\n loginUrl.searchParams.set('type', 'token')\n loginUrl.searchParams.set('label', `${hostname} / ${platform}`)\n loginUrl.searchParams.set('origin', callbackUrl.href)\n\n return loginUrl\n}\n\nfunction getCallbackUrl(server: Server): URL {\n const serverUrl = server.address()\n if (!serverUrl || typeof serverUrl === 'string') {\n // Note: `serverUrl` is string only when binding to unix sockets,\n // thus we can safely assume Something Is Wrong™ if it's a string\n throw new Error('Failed to start auth callback server')\n }\n\n return new URL(callbackEndpoint, `http://localhost:${serverUrl.port}`)\n}\n"],"names":["createServer","os","getSanityUrl","subdebug","getTokenDetails","debug","defaultCallbackPort","callbackEndpoint","getPreferredCallbackPort","override","process","env","SANITY_CLI_CALLBACK_PORT","port","Number","parseInt","trim","isNaN","Error","platformNames","aix","android","darwin","freebsd","linux","openbsd","sunos","win32","startServerForTokenCallback","providerUrl","sanityUrl","resolveToken","rejectToken","tokenPromise","Promise","resolve","reject","callbackPort","server","onCallbackServerRequest","req","res","failLoginRequest","code","writeHead","Connection","Location","end","close","url","URL","pathname","write","absoluteTokenUrl","searchParams","get","tokenUrl","has","token","search","err","on","onCallbackListen","callbackUrl","getCallbackUrl","loginUrl","getLoginUrl","onCallbackServerError","listen","platformName","platform","hostname","replaceAll","set","href","serverUrl","address"],"mappings":"AAAA,SAAQA,YAAY,QAAoB,YAAW;AACnD,OAAOC,QAAQ,UAAS;AAExB,SAAQC,YAAY,EAAEC,QAAQ,QAAO,mBAAkB;AAEvD,SAAQC,eAAe,QAAO,yBAAwB;AAGtD,MAAMC,QAAQF,SAAS;AACvB,MAAMG,sBAAsB;AAC5B,MAAMC,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;QACF;QAEAvD,MAAM,uCAAuCgC;QAC7CC,OAAO8B,MAAM,CAAC/B;IAChB;AACF;AAEA;;;;;;;;;;CAUC,GACD,SAAS6B,YAAYrC,WAAmB,EAAEkC,WAAgB;IACxD,sEAAsE;IACtE,MAAME,WAAW,IAAIf,IAAIrB;IAEzB,mCAAmC;IACnC,MAAMwC,eAAepE,GAAGqE,QAAQ;IAChC,MAAMA,WAAWD,gBAAgBlD,gBAAgBA,aAAa,CAACkD,aAAa,GAAGA;IAE/E,sDAAsD;IACtD,MAAME,WAAWtE,GAAGsE,QAAQ,GAAGC,UAAU,CAAC,mBAAmB;IAE7DP,SAASX,YAAY,CAACmB,GAAG,CAAC,QAAQ;IAClCR,SAASX,YAAY,CAACmB,GAAG,CAAC,SAAS,GAAGF,SAAS,GAAG,EAAED,UAAU;IAC9DL,SAASX,YAAY,CAACmB,GAAG,CAAC,UAAUV,YAAYW,IAAI;IAEpD,OAAOT;AACT;AAEA,SAASD,eAAe1B,MAAc;IACpC,MAAMqC,YAAYrC,OAAOsC,OAAO;IAChC,IAAI,CAACD,aAAa,OAAOA,cAAc,UAAU;QAC/C,iEAAiE;QACjE,iEAAiE;QACjE,MAAM,IAAIzD,MAAM;IAClB;IAEA,OAAO,IAAIgC,IAAI3C,kBAAkB,CAAC,iBAAiB,EAAEoE,UAAU9D,IAAI,EAAE;AACvE"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { ux } from '@oclif/core';
|
|
2
1
|
/**
|
|
3
2
|
* Asserts that a dataset exists in a list of datasets, exits if not found
|
|
4
3
|
*
|
|
5
4
|
* @param datasets - The list of datasets to check
|
|
6
5
|
* @param datasetName - The name of the dataset to check for
|
|
7
|
-
|
|
6
|
+
* @param output - Output to raise the error through the calling command
|
|
7
|
+
*/ export function assertDatasetExists(datasets, datasetName, output) {
|
|
8
8
|
const exists = datasets.some((d)=>d.name === datasetName);
|
|
9
9
|
if (!exists) {
|
|
10
|
-
|
|
10
|
+
output.error(`Dataset '${datasetName}' not found in this project. Available datasets: ${datasets.map((d)=>d.name).join(', ')}`, {
|
|
11
11
|
exit: 1
|
|
12
12
|
});
|
|
13
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/backup/assertDatasetExist.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/backup/assertDatasetExist.ts"],"sourcesContent":["import {type Output} from '@sanity/cli-core'\nimport {type DatasetsResponse} from '@sanity/client'\n\n/**\n * Asserts that a dataset exists in a list of datasets, exits if not found\n *\n * @param datasets - The list of datasets to check\n * @param datasetName - The name of the dataset to check for\n * @param output - Output to raise the error through the calling command\n */\nexport function assertDatasetExists(\n datasets: DatasetsResponse,\n datasetName: string,\n output: Output,\n): void {\n const exists = datasets.some((d) => d.name === datasetName)\n if (!exists) {\n output.error(\n `Dataset '${datasetName}' not found in this project. Available datasets: ${datasets.map((d) => d.name).join(', ')}`,\n {exit: 1},\n )\n }\n}\n"],"names":["assertDatasetExists","datasets","datasetName","output","exists","some","d","name","error","map","join","exit"],"mappings":"AAGA;;;;;;CAMC,GACD,OAAO,SAASA,oBACdC,QAA0B,EAC1BC,WAAmB,EACnBC,MAAc;IAEd,MAAMC,SAASH,SAASI,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKL;IAC/C,IAAI,CAACE,QAAQ;QACXD,OAAOK,KAAK,CACV,CAAC,SAAS,EAAEN,YAAY,iDAAiD,EAAED,SAASQ,GAAG,CAAC,CAACH,IAAMA,EAAEC,IAAI,EAAEG,IAAI,CAAC,OAAO,EACnH;YAACC,MAAM;QAAC;IAEZ;AACF"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { rm } from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { styleText } from 'node:util';
|
|
4
|
-
import { AppBuildTrace, buildDebug, resolveVendorBuildConfig } from '@sanity/cli-build/_internal/build';
|
|
4
|
+
import { AppBuildTrace, buildDebug, getAutoUpdatesCssUrls, getAutoUpdatesImportMap, resolveVendorBuildConfig } from '@sanity/cli-build/_internal/build';
|
|
5
5
|
import { getCliTelemetry, getLocalPackageVersion, getTimer, isInteractive } from '@sanity/cli-core';
|
|
6
6
|
import { confirm, logSymbols, spinner } from '@sanity/cli-core/ux';
|
|
7
|
+
import { resolveWorkbenchApp } from '@sanity/workbench-cli/build';
|
|
7
8
|
import { parse as semverParse } from 'semver';
|
|
8
9
|
import { getAppId } from '../../util/appId.js';
|
|
9
10
|
import { compareDependencyVersions } from '../../util/compareDependencyVersions.js';
|
|
@@ -11,7 +12,6 @@ import { formatModuleSizes, sortModulesBySize } from '../../util/moduleFormatUti
|
|
|
11
12
|
import { warnAboutMissingAppId } from '../../util/warnAboutMissingAppId.js';
|
|
12
13
|
import { buildStaticFiles } from './buildStaticFiles.js';
|
|
13
14
|
import { determineBasePath } from './determineBasePath.js';
|
|
14
|
-
import { getAutoUpdatesCssUrls, getAutoUpdatesImportMap } from './getAutoUpdatesImportMap.js';
|
|
15
15
|
import { getAppEnvironmentVariables } from './getEnvironmentVariables.js';
|
|
16
16
|
import { handlePrereleaseVersions } from './handlePrereleaseVersions.js';
|
|
17
17
|
/**
|
|
@@ -20,21 +20,28 @@ import { handlePrereleaseVersions } from './handlePrereleaseVersions.js';
|
|
|
20
20
|
* @internal
|
|
21
21
|
*/ export async function buildApp(options) {
|
|
22
22
|
const { cliConfig, flags, outDir, output, workDir } = options;
|
|
23
|
+
const app = cliConfig && 'app' in cliConfig ? cliConfig.app : undefined;
|
|
24
|
+
// `views`/`services` live on the branded `unstable_defineApp` result, not the
|
|
25
|
+
// legacy `app` config object — resolve the workbench capability to read them.
|
|
26
|
+
const workbench = resolveWorkbenchApp(cliConfig);
|
|
23
27
|
await internalBuildApp({
|
|
24
28
|
appId: getAppId(cliConfig),
|
|
25
|
-
appTitle:
|
|
29
|
+
appTitle: app?.title,
|
|
26
30
|
autoUpdatesEnabled: options.autoUpdatesEnabled,
|
|
27
31
|
calledFromDeploy: options.calledFromDeploy,
|
|
28
32
|
determineBasePath: ()=>determineBasePath(cliConfig, 'app', output),
|
|
29
|
-
entry:
|
|
33
|
+
entry: app?.entry,
|
|
34
|
+
isWorkbenchApp: !!workbench,
|
|
30
35
|
minify: flags.minify,
|
|
31
36
|
outDir,
|
|
32
37
|
output,
|
|
33
38
|
reactCompiler: cliConfig && 'reactCompiler' in cliConfig ? cliConfig.reactCompiler : undefined,
|
|
34
39
|
schemaExtraction: cliConfig?.schemaExtraction,
|
|
40
|
+
services: workbench?.services,
|
|
35
41
|
sourceMap: Boolean(flags['source-maps']),
|
|
36
42
|
stats: flags.stats,
|
|
37
43
|
unattendedMode: flags.yes,
|
|
44
|
+
views: workbench?.views,
|
|
38
45
|
vite: cliConfig.vite,
|
|
39
46
|
workDir
|
|
40
47
|
});
|
|
@@ -168,7 +175,7 @@ import { handlePrereleaseVersions } from './handlePrereleaseVersions.js';
|
|
|
168
175
|
const trace = getCliTelemetry().trace(AppBuildTrace);
|
|
169
176
|
trace.start();
|
|
170
177
|
let autoUpdates;
|
|
171
|
-
if (autoUpdatesEnabled) {
|
|
178
|
+
if (autoUpdatesEnabled && !options.isWorkbenchApp) {
|
|
172
179
|
autoUpdates = {
|
|
173
180
|
cssUrls: autoUpdatesCssUrls,
|
|
174
181
|
imports: autoUpdatesImports,
|
|
@@ -187,11 +194,14 @@ import { handlePrereleaseVersions } from './handlePrereleaseVersions.js';
|
|
|
187
194
|
cwd: workDir,
|
|
188
195
|
entry: options.entry,
|
|
189
196
|
isApp: true,
|
|
197
|
+
isWorkbenchApp: options.isWorkbenchApp,
|
|
190
198
|
minify: options.minify,
|
|
191
199
|
outputDir,
|
|
192
200
|
reactCompiler: options.reactCompiler,
|
|
193
201
|
schemaExtraction: options.schemaExtraction,
|
|
202
|
+
services: options.services,
|
|
194
203
|
sourceMap: options.sourceMap,
|
|
204
|
+
views: options.views,
|
|
195
205
|
vite: options.vite
|
|
196
206
|
});
|
|
197
207
|
trace.log({
|
|
@@ -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 {\n AppBuildTrace,\n buildDebug,\n resolveVendorBuildConfig,\n} from '@sanity/cli-build/_internal/build'\nimport {\n type CliConfig,\n getCliTelemetry,\n getLocalPackageVersion,\n getTimer,\n isInteractive,\n type Output,\n UserViteConfig,\n} from '@sanity/cli-core'\nimport {confirm, logSymbols, spinner, type SpinnerInstance} from '@sanity/cli-core/ux'\nimport {parse as semverParse} from 'semver'\n\nimport {getAppId} from '../../util/appId.js'\nimport {compareDependencyVersions} from '../../util/compareDependencyVersions.js'\nimport {formatModuleSizes, sortModulesBySize} from '../../util/moduleFormatUtils.js'\nimport {warnAboutMissingAppId} from '../../util/warnAboutMissingAppId.js'\nimport {buildStaticFiles} from './buildStaticFiles.js'\nimport {determineBasePath} from './determineBasePath.js'\nimport {getAutoUpdatesCssUrls, getAutoUpdatesImportMap} from './getAutoUpdatesImportMap.js'\nimport {getAppEnvironmentVariables} from './getEnvironmentVariables.js'\nimport {handlePrereleaseVersions} from './handlePrereleaseVersions.js'\nimport {type BuildOptions} from './types.js'\n\ninterface InternalBuildOptions {\n appId: string | undefined\n appTitle: string | undefined\n autoUpdatesEnabled: boolean\n calledFromDeploy: boolean | undefined\n determineBasePath: () => string\n entry: string | undefined\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\n/**\n * Build the Sanity app.\n *\n * @internal\n */\nexport async function buildApp(options: BuildOptions): Promise<void> {\n const {cliConfig, flags, outDir, output, workDir} = options\n\n await internalBuildApp({\n appId: getAppId(cliConfig),\n appTitle: cliConfig && 'app' in cliConfig ? cliConfig.app?.title : undefined,\n autoUpdatesEnabled: options.autoUpdatesEnabled,\n calledFromDeploy: options.calledFromDeploy,\n determineBasePath: () => determineBasePath(cliConfig, 'app', output),\n entry: cliConfig && 'app' in cliConfig ? cliConfig.app?.entry : undefined,\n minify: flags.minify,\n outDir,\n output,\n reactCompiler: cliConfig && 'reactCompiler' in cliConfig ? cliConfig.reactCompiler : undefined,\n schemaExtraction: cliConfig?.schemaExtraction,\n sourceMap: Boolean(flags['source-maps']),\n stats: flags.stats,\n unattendedMode: flags.yes,\n vite: cliConfig.vite,\n workDir,\n })\n}\n\n/**\n * Internal build app that avoids depending on flags for CLI config.\n * @param options - options for the build\n */\nasync function internalBuildApp(options: InternalBuildOptions): Promise<void> {\n buildDebug(`Building app`)\n\n const {appId, determineBasePath, 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`, {exit: 1})\n return\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}`, {exit: 1})\n return\n }\n\n // Sanity might not be installed, but if it is, we want to auto update it.\n const cleanSanityVersion = 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 // Skip when called from deploy, since deploy handles appId itself\n // (prompts the user and tells them to add it to config).\n if (!appId && !options.calledFromDeploy) {\n warnAboutMissingAppId({appType: 'app', output})\n }\n\n // Check the versions\n const {mismatched, unresolvedPrerelease} = await compareDependencyVersions(\n autoUpdatedPackages,\n workDir,\n {appId},\n )\n\n if (unresolvedPrerelease.length > 0) {\n await handlePrereleaseVersions({output, unattendedMode, unresolvedPrerelease})\n autoUpdatesImports = {}\n 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: 1})\n return\n }\n } else {\n // if non-interactive or unattended, just show the warning\n output.warn(versionMismatchWarning)\n }\n }\n }\n\n const envVarKeys = 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) {\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 isApp: true,\n minify: options.minify,\n outputDir,\n reactCompiler: options.reactCompiler,\n schemaExtraction: options.schemaExtraction,\n sourceMap: options.sourceMap,\n vite: options.vite,\n })\n\n trace.log({\n outputSize: bundle.chunks\n .flatMap((chunk) => chunk.modules.flatMap((mod) => mod.renderedLength))\n .reduce((sum, n) => sum + n, 0),\n })\n const buildDuration = timer.end('bundleStudio')\n\n spin.text = `Build Sanity application (${buildDuration.toFixed(0)}ms)`\n spin.succeed()\n\n if (options.stats) {\n output.log('\\nLargest module files:')\n output.log(formatModuleSizes(sortModulesBySize(bundle.chunks).slice(0, 15)))\n }\n\n trace.complete()\n } catch (error) {\n spin.fail()\n trace.error(error)\n const message = error instanceof Error ? error.message : String(error)\n buildDebug(`Failed to build Sanity application`, {error})\n output.error(`Failed to build Sanity application: ${message}`, {exit: 1})\n }\n}\n"],"names":["rm","path","styleText","AppBuildTrace","buildDebug","resolveVendorBuildConfig","getCliTelemetry","getLocalPackageVersion","getTimer","isInteractive","confirm","logSymbols","spinner","parse","semverParse","getAppId","compareDependencyVersions","formatModuleSizes","sortModulesBySize","warnAboutMissingAppId","buildStaticFiles","determineBasePath","getAutoUpdatesCssUrls","getAutoUpdatesImportMap","getAppEnvironmentVariables","handlePrereleaseVersions","buildApp","options","cliConfig","flags","outDir","output","workDir","internalBuildApp","appId","appTitle","app","title","undefined","autoUpdatesEnabled","calledFromDeploy","entry","minify","reactCompiler","schemaExtraction","sourceMap","Boolean","stats","unattendedMode","yes","vite","timer","defaultOutputDir","resolve","join","outputDir","installedSdkVersion","installedSanityVersion","error","exit","autoUpdatesImports","autoUpdatesCssUrls","cleanSDKVersion","version","cleanSanityVersion","autoUpdatedPackages","name","cssFile","log","info","appType","mismatched","unresolvedPrerelease","length","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","cssUrls","imports","vendor","cwd","isApp","bundle","outputSize","chunks","flatMap","chunk","modules","renderedLength","reduce","sum","n","buildDuration","slice","complete","fail","Error","String"],"mappings":"AAAA,SAAQA,EAAE,QAAO,mBAAkB;AACnC,OAAOC,UAAU,YAAW;AAC5B,SAAQC,SAAS,QAAO,YAAW;AAEnC,SACEC,aAAa,EACbC,UAAU,EACVC,wBAAwB,QACnB,oCAAmC;AAC1C,SAEEC,eAAe,EACfC,sBAAsB,EACtBC,QAAQ,EACRC,aAAa,QAGR,mBAAkB;AACzB,SAAQC,OAAO,EAAEC,UAAU,EAAEC,OAAO,QAA6B,sBAAqB;AACtF,SAAQC,SAASC,WAAW,QAAO,SAAQ;AAE3C,SAAQC,QAAQ,QAAO,sBAAqB;AAC5C,SAAQC,yBAAyB,QAAO,0CAAyC;AACjF,SAAQC,iBAAiB,EAAEC,iBAAiB,QAAO,kCAAiC;AACpF,SAAQC,qBAAqB,QAAO,sCAAqC;AACzE,SAAQC,gBAAgB,QAAO,wBAAuB;AACtD,SAAQC,iBAAiB,QAAO,yBAAwB;AACxD,SAAQC,qBAAqB,EAAEC,uBAAuB,QAAO,+BAA8B;AAC3F,SAAQC,0BAA0B,QAAO,+BAA8B;AACvE,S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YACjBhB,OAAOqC,GAAG,CAAC;YACXrC,OAAOqC,GAAG,CAACnD,kBAAkBC,kBAAkBwF,OAAOE,MAAM,EAAES,KAAK,CAAC,GAAG;QACzE;QAEAlB,MAAMmB,QAAQ;IAChB,EAAE,OAAO5D,OAAO;QACdgC,KAAK6B,IAAI;QACTpB,MAAMzC,KAAK,CAACA;QACZ,MAAMwB,UAAUxB,iBAAiB8D,QAAQ9D,MAAMwB,OAAO,GAAGuC,OAAO/D;QAChEtD,WAAW,CAAC,kCAAkC,CAAC,EAAE;YAACsD;QAAK;QACvD3B,OAAO2B,KAAK,CAAC,CAAC,oCAAoC,EAAEwB,SAAS,EAAE;YAACvB,MAAM;QAAC;IACzE;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/build/buildApp.ts"],"sourcesContent":["import {rm} from 'node:fs/promises'\nimport path from 'node:path'\nimport {styleText} from 'node:util'\n\nimport {\n AppBuildTrace,\n buildDebug,\n getAutoUpdatesCssUrls,\n getAutoUpdatesImportMap,\n resolveVendorBuildConfig,\n} from '@sanity/cli-build/_internal/build'\nimport {\n type CliConfig,\n getCliTelemetry,\n getLocalPackageVersion,\n getTimer,\n isInteractive,\n type Output,\n UserViteConfig,\n} from '@sanity/cli-core'\nimport {confirm, logSymbols, spinner, type SpinnerInstance} from '@sanity/cli-core/ux'\nimport {type DefineAppInput} from '@sanity/workbench-cli'\nimport {resolveWorkbenchApp} from '@sanity/workbench-cli/build'\nimport {parse as semverParse} from 'semver'\n\nimport {getAppId} from '../../util/appId.js'\nimport {compareDependencyVersions} from '../../util/compareDependencyVersions.js'\nimport {formatModuleSizes, sortModulesBySize} from '../../util/moduleFormatUtils.js'\nimport {warnAboutMissingAppId} from '../../util/warnAboutMissingAppId.js'\nimport {buildStaticFiles} from './buildStaticFiles.js'\nimport {determineBasePath} from './determineBasePath.js'\nimport {getAppEnvironmentVariables} from './getEnvironmentVariables.js'\nimport {handlePrereleaseVersions} from './handlePrereleaseVersions.js'\nimport {type BuildOptions} from './types.js'\n\ninterface InternalBuildOptions {\n appId: string | undefined\n appTitle: string | undefined\n autoUpdatesEnabled: boolean\n calledFromDeploy: boolean | undefined\n determineBasePath: () => string\n entry: string | undefined\n isWorkbenchApp: boolean\n minify: boolean\n outDir: string | undefined\n output: Output\n reactCompiler: CliConfig['reactCompiler']\n schemaExtraction: CliConfig['schemaExtraction']\n services: DefineAppInput['services']\n sourceMap: boolean\n stats: boolean\n unattendedMode: boolean\n views: DefineAppInput['views']\n vite: UserViteConfig | undefined\n workDir: string\n}\n\n/**\n * Build the Sanity app.\n *\n * @internal\n */\nexport async function buildApp(options: BuildOptions): Promise<void> {\n const {cliConfig, flags, outDir, output, workDir} = options\n\n const app = cliConfig && 'app' in cliConfig ? cliConfig.app : undefined\n // `views`/`services` live on the branded `unstable_defineApp` result, not the\n // legacy `app` config object — resolve the workbench capability to read them.\n const workbench = resolveWorkbenchApp(cliConfig)\n\n await internalBuildApp({\n appId: getAppId(cliConfig),\n appTitle: app?.title,\n autoUpdatesEnabled: options.autoUpdatesEnabled,\n calledFromDeploy: options.calledFromDeploy,\n determineBasePath: () => determineBasePath(cliConfig, 'app', output),\n entry: app?.entry,\n isWorkbenchApp: !!workbench,\n minify: flags.minify,\n outDir,\n output,\n reactCompiler: cliConfig && 'reactCompiler' in cliConfig ? cliConfig.reactCompiler : undefined,\n schemaExtraction: cliConfig?.schemaExtraction,\n services: workbench?.services,\n sourceMap: Boolean(flags['source-maps']),\n stats: flags.stats,\n unattendedMode: flags.yes,\n views: workbench?.views,\n vite: cliConfig.vite,\n workDir,\n })\n}\n\n/**\n * Internal build app that avoids depending on flags for CLI config.\n * @param options - options for the build\n */\nasync function internalBuildApp(options: InternalBuildOptions): Promise<void> {\n buildDebug(`Building app`)\n\n const {appId, determineBasePath, 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`, {exit: 1})\n return\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}`, {exit: 1})\n return\n }\n\n // Sanity might not be installed, but if it is, we want to auto update it.\n const cleanSanityVersion = 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 // Skip when called from deploy, since deploy handles appId itself\n // (prompts the user and tells them to add it to config).\n if (!appId && !options.calledFromDeploy) {\n warnAboutMissingAppId({appType: 'app', output})\n }\n\n // Check the versions\n const {mismatched, unresolvedPrerelease} = await compareDependencyVersions(\n autoUpdatedPackages,\n workDir,\n {appId},\n )\n\n if (unresolvedPrerelease.length > 0) {\n await handlePrereleaseVersions({output, unattendedMode, unresolvedPrerelease})\n autoUpdatesImports = {}\n 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: 1})\n return\n }\n } else {\n // if non-interactive or unattended, just show the warning\n output.warn(versionMismatchWarning)\n }\n }\n }\n\n const envVarKeys = 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 isApp: true,\n isWorkbenchApp: options.isWorkbenchApp,\n minify: options.minify,\n outputDir,\n reactCompiler: options.reactCompiler,\n schemaExtraction: options.schemaExtraction,\n services: options.services,\n sourceMap: options.sourceMap,\n views: options.views,\n vite: options.vite,\n })\n\n trace.log({\n outputSize: bundle.chunks\n .flatMap((chunk) => chunk.modules.flatMap((mod) => mod.renderedLength))\n .reduce((sum, n) => sum + n, 0),\n })\n const buildDuration = timer.end('bundleStudio')\n\n spin.text = `Build Sanity application (${buildDuration.toFixed(0)}ms)`\n spin.succeed()\n\n if (options.stats) {\n output.log('\\nLargest module files:')\n output.log(formatModuleSizes(sortModulesBySize(bundle.chunks).slice(0, 15)))\n }\n\n trace.complete()\n } catch (error) {\n spin.fail()\n trace.error(error)\n const message = error instanceof Error ? error.message : String(error)\n buildDebug(`Failed to build Sanity application`, {error})\n output.error(`Failed to build Sanity application: ${message}`, {exit: 1})\n }\n}\n"],"names":["rm","path","styleText","AppBuildTrace","buildDebug","getAutoUpdatesCssUrls","getAutoUpdatesImportMap","resolveVendorBuildConfig","getCliTelemetry","getLocalPackageVersion","getTimer","isInteractive","confirm","logSymbols","spinner","resolveWorkbenchApp","parse","semverParse","getAppId","compareDependencyVersions","formatModuleSizes","sortModulesBySize","warnAboutMissingAppId","buildStaticFiles","determineBasePath","getAppEnvironmentVariables","handlePrereleaseVersions","buildApp","options","cliConfig","flags","outDir","output","workDir","app","undefined","workbench","internalBuildApp","appId","appTitle","title","autoUpdatesEnabled","calledFromDeploy","entry","isWorkbenchApp","minify","reactCompiler","schemaExtraction","services","sourceMap","Boolean","stats","unattendedMode","yes","views","vite","timer","defaultOutputDir","resolve","join","outputDir","installedSdkVersion","installedSanityVersion","error","exit","autoUpdatesImports","autoUpdatesCssUrls","cleanSDKVersion","version","cleanSanityVersion","autoUpdatedPackages","name","cssFile","log","info","appType","mismatched","unresolvedPrerelease","length","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","cssUrls","imports","vendor","cwd","isApp","bundle","outputSize","chunks","flatMap","chunk","modules","renderedLength","reduce","sum","n","buildDuration","slice","complete","fail","Error","String"],"mappings":"AAAA,SAAQA,EAAE,QAAO,mBAAkB;AACnC,OAAOC,UAAU,YAAW;AAC5B,SAAQC,SAAS,QAAO,YAAW;AAEnC,SACEC,aAAa,EACbC,UAAU,EACVC,qBAAqB,EACrBC,uBAAuB,EACvBC,wBAAwB,QACnB,oCAAmC;AAC1C,SAEEC,eAAe,EACfC,sBAAsB,EACtBC,QAAQ,EACRC,aAAa,QAGR,mBAAkB;AACzB,SAAQC,OAAO,EAAEC,UAAU,EAAEC,OAAO,QAA6B,sBAAqB;AAEtF,SAAQC,mBAAmB,QAAO,8BAA6B;AAC/D,SAAQC,SAASC,WAAW,QAAO,SAAQ;AAE3C,SAAQC,QAAQ,QAAO,sBAAqB;AAC5C,SAAQC,yBAAyB,QAAO,0CAAyC;AACjF,SAAQC,iBAAiB,EAAEC,iBAAiB,QAAO,kCAAiC;AACpF,SAAQC,qBAAqB,QAAO,sCAAqC;AACzE,SAAQC,gBAAgB,QAAO,wBAAuB;AACtD,SAAQC,iBAAiB,QAAO,yBAAwB;AACxD,SAAQC,0BAA0B,QAAO,+BAA8B;AACvE,SAAQC,wBAAwB,QAAO,gCAA+B;AAyBtE;;;;CAIC,GACD,OAAO,eAAeC,SAASC,OAAqB;IAClD,MAAM,EAACC,SAAS,EAAEC,KAAK,EAAEC,MAAM,EAAEC,MAAM,EAAEC,OAAO,EAAC,GAAGL;IAEpD,MAAMM,MAAML,aAAa,SAASA,YAAYA,UAAUK,GAAG,GAAGC;IAC9D,8EAA8E;IAC9E,8EAA8E;IAC9E,MAAMC,YAAYrB,oBAAoBc;IAEtC,MAAMQ,iBAAiB;QACrBC,OAAOpB,SAASW;QAChBU,UAAUL,KAAKM;QACfC,oBAAoBb,QAAQa,kBAAkB;QAC9CC,kBAAkBd,QAAQc,gBAAgB;QAC1ClB,mBAAmB,IAAMA,kBAAkBK,WAAW,OAAOG;QAC7DW,OAA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AAiB8D,QAAQ9D,MAAMwB,OAAO,GAAGuC,OAAO/D;QAChE3D,WAAW,CAAC,kCAAkC,CAAC,EAAE;YAAC2D;QAAK;QACvD/B,OAAO+B,KAAK,CAAC,CAAC,oCAAoC,EAAEwB,SAAS,EAAE;YAACvB,MAAM;QAAC;IACzE;AACF"}
|
|
@@ -1,20 +1,71 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import { buildDebug, copyDir, extendViteConfigWithUserConfig, finalizeViteConfig, getViteConfig, writeFavicons, writeSanityRuntime } from '@sanity/cli-build/_internal/build';
|
|
3
|
-
import { build } from 'vite';
|
|
2
|
+
import { buildDebug, copyDir, extendViteConfigWithUserConfig, finalizeViteConfig, getViteConfig, resolveEntries, writeFavicons, writeSanityRuntime } from '@sanity/cli-build/_internal/build';
|
|
3
|
+
import { build, createBuilder } from 'vite';
|
|
4
4
|
import { getAppEnvironmentVariables, getStudioEnvironmentVariables } from './getEnvironmentVariables.js';
|
|
5
5
|
/**
|
|
6
6
|
* Builds static files
|
|
7
7
|
*
|
|
8
8
|
* @internal
|
|
9
9
|
*/ export async function buildStaticFiles(options) {
|
|
10
|
-
const { appTitle, autoUpdates, basePath, cwd, entry, isApp, minify = true, outputDir, reactCompiler, schemaExtraction, sourceMap = false, vite: extendViteConfig } = options;
|
|
10
|
+
const { appTitle, autoUpdates, basePath, cwd, entry, isApp, isWorkbenchApp, minify = true, outputDir, reactCompiler, schemaExtraction, services, sourceMap = false, views, vite: extendViteConfig } = options;
|
|
11
|
+
const mode = 'production';
|
|
12
|
+
/* Federation builds only produce the federation environment
|
|
13
|
+
* (remote-entry, mf-manifest) — skip client-specific steps like
|
|
14
|
+
* runtime generation, static file copies, and favicons.
|
|
15
|
+
*/ if (isWorkbenchApp) {
|
|
16
|
+
buildDebug('Resolving entries for federation build');
|
|
17
|
+
const entries = await resolveEntries({
|
|
18
|
+
cwd,
|
|
19
|
+
entry,
|
|
20
|
+
isApp,
|
|
21
|
+
isWorkbenchApp
|
|
22
|
+
});
|
|
23
|
+
buildDebug('Resolving vite config (federation)');
|
|
24
|
+
let viteConfig = await getViteConfig({
|
|
25
|
+
basePath,
|
|
26
|
+
cwd,
|
|
27
|
+
entries,
|
|
28
|
+
getEnvironmentVariables,
|
|
29
|
+
isApp,
|
|
30
|
+
isWorkbenchApp,
|
|
31
|
+
minify,
|
|
32
|
+
mode,
|
|
33
|
+
outputDir,
|
|
34
|
+
reactCompiler,
|
|
35
|
+
// Schema extraction is a build-time artifact, not a client-specific step,
|
|
36
|
+
// so a federated studio extracts its schema like the legacy studio build.
|
|
37
|
+
schemaExtraction,
|
|
38
|
+
services,
|
|
39
|
+
sourceMap,
|
|
40
|
+
views
|
|
41
|
+
});
|
|
42
|
+
// Apply the user's Vite config so plugins like `@vanilla-extract/vite-plugin`
|
|
43
|
+
// transform source files before the federation environment is bundled.
|
|
44
|
+
// `finalizeViteConfig` is intentionally skipped: the federation environment
|
|
45
|
+
// has its own entry and does not use `.sanity/runtime/app.js`.
|
|
46
|
+
if (extendViteConfig) {
|
|
47
|
+
viteConfig = await extendViteConfigWithUserConfig({
|
|
48
|
+
command: 'build',
|
|
49
|
+
mode
|
|
50
|
+
}, viteConfig, extendViteConfig);
|
|
51
|
+
}
|
|
52
|
+
buildDebug('Bundling federation environment');
|
|
53
|
+
const builder = await createBuilder(viteConfig);
|
|
54
|
+
await builder.buildApp();
|
|
55
|
+
buildDebug('Bundling complete');
|
|
56
|
+
// TODO: add stats here
|
|
57
|
+
return {
|
|
58
|
+
chunks: []
|
|
59
|
+
};
|
|
60
|
+
}
|
|
11
61
|
buildDebug('Writing Sanity runtime files');
|
|
12
|
-
await writeSanityRuntime({
|
|
62
|
+
const { entries } = await writeSanityRuntime({
|
|
13
63
|
appTitle,
|
|
14
64
|
basePath,
|
|
15
65
|
cwd,
|
|
16
66
|
entry,
|
|
17
67
|
isApp,
|
|
68
|
+
isWorkbenchApp,
|
|
18
69
|
reactStrictMode: false,
|
|
19
70
|
watch: false
|
|
20
71
|
});
|
|
@@ -28,13 +79,14 @@ import { getAppEnvironmentVariables, getStudioEnvironmentVariables } from './get
|
|
|
28
79
|
});
|
|
29
80
|
}
|
|
30
81
|
buildDebug('Resolving vite config');
|
|
31
|
-
const mode = 'production';
|
|
32
82
|
let viteConfig = await getViteConfig({
|
|
33
83
|
autoUpdates,
|
|
34
84
|
basePath,
|
|
35
85
|
cwd,
|
|
86
|
+
entries,
|
|
36
87
|
getEnvironmentVariables,
|
|
37
88
|
isApp,
|
|
89
|
+
isWorkbenchApp,
|
|
38
90
|
minify,
|
|
39
91
|
mode,
|
|
40
92
|
outputDir,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/build/buildStaticFiles.ts"],"sourcesContent":["import path from 'node:path'\n\nimport {\n type AutoUpdatesBuildConfig,\n buildDebug,\n copyDir,\n extendViteConfigWithUserConfig,\n finalizeViteConfig,\n getViteConfig,\n writeFavicons,\n writeSanityRuntime,\n} from '@sanity/cli-build/_internal/build'\nimport {type CliConfig, type UserViteConfig} from '@sanity/cli-core'\nimport {type PluginOptions as ReactCompilerConfig} from 'babel-plugin-react-compiler'\nimport {build} from 'vite'\n\nimport {\n getAppEnvironmentVariables,\n getStudioEnvironmentVariables,\n} from './getEnvironmentVariables.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 minify?: boolean\n profile?: boolean\n reactCompiler?: ReactCompilerConfig\n schemaExtraction?: CliConfig['schemaExtraction']\n sourceMap?: boolean\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 minify = true,\n outputDir,\n reactCompiler,\n schemaExtraction,\n sourceMap = false,\n vite: extendViteConfig,\n } = options\n\n buildDebug('Writing Sanity runtime files')\n await writeSanityRuntime({\n appTitle,\n basePath,\n cwd,\n entry,\n isApp,\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
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/build/buildStaticFiles.ts"],"sourcesContent":["import path from 'node:path'\n\nimport {\n type AutoUpdatesBuildConfig,\n buildDebug,\n copyDir,\n extendViteConfigWithUserConfig,\n finalizeViteConfig,\n getViteConfig,\n resolveEntries,\n writeFavicons,\n writeSanityRuntime,\n} from '@sanity/cli-build/_internal/build'\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 {\n getAppEnvironmentVariables,\n getStudioEnvironmentVariables,\n} from './getEnvironmentVariables.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","buildDebug","copyDir","extendViteConfigWithUserConfig","finalizeViteConfig","getViteConfig","resolveEntries","writeFavicons","writeSanityRuntime","build","createBuilder","getAppEnvironmentVariables","getStudioEnvironmentVariables","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;AAE5B,SAEEC,UAAU,EACVC,OAAO,EACPC,8BAA8B,EAC9BC,kBAAkB,EAClBC,aAAa,EACbC,cAAc,EACdC,aAAa,EACbC,kBAAkB,QACb,oCAAmC;AAI1C,SAAQC,KAAK,EAAEC,aAAa,QAAO,OAAM;AAEzC,SACEC,0BAA0B,EAC1BC,6BAA6B,QACxB,+BAA8B;AAiCrC;;;;CAIC,GACD,OAAO,eAAeC,iBACpBC,OAA2B;IAE3B,MAAM,EACJC,QAAQ,EACRC,WAAW,EACXC,QAAQ,EACRC,GAAG,EACHC,KAAK,EACLC,KAAK,EACLC,cAAc,EACdC,SAAS,IAAI,EACbC,SAAS,EACTC,aAAa,EACbC,gBAAgB,EAChBC,QAAQ,EACRC,YAAY,KAAK,EACjBC,KAAK,EACLC,MAAMC,gBAAgB,EACvB,GAAGhB;IAEJ,MAAMiB,OAAO;IAEb;;;GAGC,GACD,IAAIV,gBAAgB;QAClBpB,WAAW;QACX,MAAM+B,UAAU,MAAM1B,eAAe;YAACY;YAAKC;YAAOC;YAAOC;QAAc;QAEvEpB,WAAW;QACX,IAAIgC,aAAa,MAAM5B,cAAc;YACnCY;YACAC;YACAc;YACAE;YACAd;YACAC;YACAC;YACAS;YACAR;YACAC;YACA,0EAA0E;YAC1E,0EAA0E;YAC1EC;YACAC;YACAC;YACAC;QACF;QAEA,8EAA8E;QAC9E,uEAAuE;QACvE,4EAA4E;QAC5E,+DAA+D;QAC/D,IAAIE,kBAAkB;YACpBG,aAAa,MAAM9B,+BACjB;gBAACgC,SAAS;gBAASJ;YAAI,GACvBE,YACAH;QAEJ;QAEA7B,WAAW;QACX,M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MAAMc,QAAsB,EAAE;IAC9B,KAAK,MAAMC,SAASJ,OAAOK,MAAM,CAAE;QACjC,IAAID,MAAME,IAAI,KAAK,SAAS;YAC1B;QACF;QAEAH,MAAMI,IAAI,CAAC;YACTC,SAASC,OAAO1B,OAAO,CAACqB,MAAMI,OAAO,EAAEE,GAAG,CAAC,CAAC,CAACC,aAAaC,YAAY;gBACpE,MAAMC,WAAWF,YAAYG,UAAU,CAAC,YACpCH,YAAYI,KAAK,CAAC,SAASC,MAAM,IACjCL;gBAEJ,OAAO;oBACLM,MAAMlE,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"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { rm } from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { styleText } from 'node:util';
|
|
4
|
-
import { buildDebug, checkStudioDependencyVersions, resolveVendorBuildConfig, StudioBuildTrace } from '@sanity/cli-build/_internal/build';
|
|
4
|
+
import { buildDebug, checkRequiredDependencies, checkStudioDependencyVersions, getAutoUpdatesCssUrls, getAutoUpdatesImportMap, resolveVendorBuildConfig, StudioBuildTrace } from '@sanity/cli-build/_internal/build';
|
|
5
5
|
import { getCliTelemetry, getLocalPackageVersion, getTimer, isInteractive } from '@sanity/cli-core';
|
|
6
6
|
import { confirm, logSymbols, select, spinner } from '@sanity/cli-core/ux';
|
|
7
|
+
import { resolveWorkbenchApp } from '@sanity/workbench-cli/build';
|
|
7
8
|
import { parse as semverParse } from 'semver';
|
|
8
9
|
import { getAppId } from '../../util/appId.js';
|
|
9
10
|
import { compareDependencyVersions } from '../../util/compareDependencyVersions.js';
|
|
@@ -13,9 +14,7 @@ import { getPackageManagerChoice } from '../../util/packageManager/packageManage
|
|
|
13
14
|
import { upgradePackages } from '../../util/packageManager/upgradePackages.js';
|
|
14
15
|
import { warnAboutMissingAppId } from '../../util/warnAboutMissingAppId.js';
|
|
15
16
|
import { buildStaticFiles } from './buildStaticFiles.js';
|
|
16
|
-
import { checkRequiredDependencies } from './checkRequiredDependencies.js';
|
|
17
17
|
import { determineBasePath } from './determineBasePath.js';
|
|
18
|
-
import { getAutoUpdatesCssUrls, getAutoUpdatesImportMap } from './getAutoUpdatesImportMap.js';
|
|
19
18
|
import { getStudioEnvironmentVariables } from './getEnvironmentVariables.js';
|
|
20
19
|
import { handlePrereleaseVersions } from './handlePrereleaseVersions.js';
|
|
21
20
|
/**
|
|
@@ -24,6 +23,9 @@ import { handlePrereleaseVersions } from './handlePrereleaseVersions.js';
|
|
|
24
23
|
* @internal
|
|
25
24
|
*/ export async function buildStudio(options) {
|
|
26
25
|
const { calledFromDeploy, cliConfig, flags, outDir, output, workDir } = options;
|
|
26
|
+
// `views`/`services` live on the branded `unstable_defineApp` result — resolve
|
|
27
|
+
// the workbench capability so it's gated on the brand, like the app build.
|
|
28
|
+
const workbench = resolveWorkbenchApp(cliConfig);
|
|
27
29
|
const upgradePkgs = async (options)=>{
|
|
28
30
|
await upgradePackages({
|
|
29
31
|
packageManager: (await getPackageManagerChoice(workDir, {
|
|
@@ -41,16 +43,19 @@ import { handlePrereleaseVersions } from './handlePrereleaseVersions.js';
|
|
|
41
43
|
calledFromDeploy,
|
|
42
44
|
determineBasePath: ()=>determineBasePath(cliConfig, 'studio', output),
|
|
43
45
|
isApp: determineIsApp(cliConfig),
|
|
46
|
+
isWorkbenchApp: !!workbench,
|
|
44
47
|
minify: Boolean(flags.minify),
|
|
45
48
|
outDir,
|
|
46
49
|
output,
|
|
47
50
|
projectId: cliConfig?.api?.projectId,
|
|
48
51
|
reactCompiler: cliConfig.reactCompiler,
|
|
49
52
|
schemaExtraction: cliConfig.schemaExtraction,
|
|
53
|
+
services: workbench?.services,
|
|
50
54
|
sourceMap: Boolean(flags['source-maps']),
|
|
51
55
|
stats: flags.stats,
|
|
52
56
|
unattendedMode: Boolean(flags.yes),
|
|
53
57
|
upgradePackages: upgradePkgs,
|
|
58
|
+
views: workbench?.views,
|
|
54
59
|
vite: cliConfig.vite,
|
|
55
60
|
workDir
|
|
56
61
|
});
|
|
@@ -61,7 +66,7 @@ import { handlePrereleaseVersions } from './handlePrereleaseVersions.js';
|
|
|
61
66
|
*/ async function internalBuildStudio(options) {
|
|
62
67
|
buildDebug(`Building studio`);
|
|
63
68
|
const timer = getTimer();
|
|
64
|
-
const { appId, determineBasePath, isApp, minify, outDir, output, projectId, reactCompiler, schemaExtraction, sourceMap, stats, unattendedMode, upgradePackages, vite, workDir } = options;
|
|
69
|
+
const { appId, determineBasePath, isApp, minify, outDir, output, projectId, reactCompiler, schemaExtraction, services, sourceMap, stats, unattendedMode, upgradePackages, views, vite, workDir } = options;
|
|
65
70
|
const defaultOutputDir = path.resolve(path.join(workDir, 'dist'));
|
|
66
71
|
const outputDir = path.resolve(outDir || defaultOutputDir);
|
|
67
72
|
await checkStudioDependencyVersions(workDir, output);
|
|
@@ -218,7 +223,7 @@ import { handlePrereleaseVersions } from './handlePrereleaseVersions.js';
|
|
|
218
223
|
const trace = getCliTelemetry().trace(StudioBuildTrace);
|
|
219
224
|
trace.start();
|
|
220
225
|
let autoUpdates;
|
|
221
|
-
if (autoUpdatesEnabled) {
|
|
226
|
+
if (autoUpdatesEnabled && !options.isWorkbenchApp) {
|
|
222
227
|
autoUpdates = {
|
|
223
228
|
cssUrls: autoUpdatesCssUrls,
|
|
224
229
|
imports: autoUpdatesImports,
|
|
@@ -234,11 +239,14 @@ import { handlePrereleaseVersions } from './handlePrereleaseVersions.js';
|
|
|
234
239
|
autoUpdates,
|
|
235
240
|
basePath,
|
|
236
241
|
cwd: workDir,
|
|
242
|
+
isWorkbenchApp: options.isWorkbenchApp,
|
|
237
243
|
minify,
|
|
238
244
|
outputDir,
|
|
239
245
|
reactCompiler,
|
|
240
246
|
schemaExtraction,
|
|
247
|
+
services,
|
|
241
248
|
sourceMap,
|
|
249
|
+
views,
|
|
242
250
|
vite
|
|
243
251
|
});
|
|
244
252
|
trace.log({
|