@sanity/cli 6.4.0 → 6.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +201 -103
- package/dist/actions/build/buildApp.js +46 -17
- package/dist/actions/build/buildApp.js.map +1 -1
- package/dist/actions/build/buildStaticFiles.js +3 -1
- package/dist/actions/build/buildStaticFiles.js.map +1 -1
- package/dist/actions/build/buildStudio.js +80 -30
- package/dist/actions/build/buildStudio.js.map +1 -1
- package/dist/actions/build/buildVendorDependencies.js +10 -9
- package/dist/actions/build/buildVendorDependencies.js.map +1 -1
- package/dist/actions/build/checkRequiredDependencies.js +6 -9
- package/dist/actions/build/checkRequiredDependencies.js.map +1 -1
- package/dist/actions/build/checkStudioDependencyVersions.js +10 -11
- package/dist/actions/build/checkStudioDependencyVersions.js.map +1 -1
- package/dist/actions/build/getAutoUpdatesImportMap.js +9 -0
- package/dist/actions/build/getAutoUpdatesImportMap.js.map +1 -1
- package/dist/actions/build/getViteConfig.js +4 -2
- package/dist/actions/build/getViteConfig.js.map +1 -1
- package/dist/actions/build/renderDocument.js.map +1 -1
- package/dist/actions/build/renderDocumentWorker/addTimestampImportMapScriptToHtml.js +34 -14
- package/dist/actions/build/renderDocumentWorker/addTimestampImportMapScriptToHtml.js.map +1 -1
- package/dist/actions/build/renderDocumentWorker/getDocumentHtml.js +2 -2
- package/dist/actions/build/renderDocumentWorker/getDocumentHtml.js.map +1 -1
- package/dist/actions/build/renderDocumentWorker/renderDocumentWorker.js +2 -2
- package/dist/actions/build/renderDocumentWorker/renderDocumentWorker.js.map +1 -1
- package/dist/actions/codemods/reactIconsV3.js +3 -3
- package/dist/actions/codemods/reactIconsV3.js.map +1 -1
- package/dist/actions/deploy/deployApp.js +1 -1
- package/dist/actions/deploy/deployApp.js.map +1 -1
- package/dist/actions/deploy/deployStudio.js +1 -2
- package/dist/actions/deploy/deployStudio.js.map +1 -1
- package/dist/actions/dev/startStudioDevServer.js +3 -4
- package/dist/actions/dev/startStudioDevServer.js.map +1 -1
- package/dist/actions/doctor/types.js.map +1 -1
- package/dist/actions/graphql/resolveGraphQLApisFromWorkspaces.js.map +1 -1
- package/dist/actions/init/bootstrapTemplate.js.map +1 -1
- package/dist/actions/init/checkNextJsReactCompatibility.js +3 -3
- package/dist/actions/init/checkNextJsReactCompatibility.js.map +1 -1
- package/dist/actions/init/initAction.js +287 -0
- package/dist/actions/init/initAction.js.map +1 -0
- package/dist/actions/init/initApp.js +7 -16
- package/dist/actions/init/initApp.js.map +1 -1
- package/dist/actions/init/initError.js +10 -0
- package/dist/actions/init/initError.js.map +1 -0
- package/dist/actions/init/initHelpers.js +3 -12
- package/dist/actions/init/initHelpers.js.map +1 -1
- package/dist/actions/init/initNextJs.js +17 -20
- package/dist/actions/init/initNextJs.js.map +1 -1
- package/dist/actions/init/initStudio.js +11 -20
- package/dist/actions/init/initStudio.js.map +1 -1
- package/dist/actions/init/plan/getPlan.js +15 -0
- package/dist/actions/init/plan/getPlan.js.map +1 -0
- package/dist/actions/init/plan/verifyCoupon.js +35 -0
- package/dist/actions/init/plan/verifyCoupon.js.map +1 -0
- package/dist/actions/init/plan/verifyPlan.js +34 -0
- package/dist/actions/init/plan/verifyPlan.js.map +1 -0
- package/dist/actions/init/project/createProjectFromName.js +44 -0
- package/dist/actions/init/project/createProjectFromName.js.map +1 -0
- package/dist/actions/init/project/getOrCreateDataset.js +126 -0
- package/dist/actions/init/project/getOrCreateDataset.js.map +1 -0
- package/dist/actions/init/project/getOrCreateProject.js +128 -0
- package/dist/actions/init/project/getOrCreateProject.js.map +1 -0
- package/dist/actions/init/project/getProjectDetails.js +87 -0
- package/dist/actions/init/project/getProjectDetails.js.map +1 -0
- package/dist/actions/init/project/getProjectOutputPath.js +17 -0
- package/dist/actions/init/project/getProjectOutputPath.js.map +1 -0
- package/dist/actions/init/project/promptForAppTemplateSetup.js +112 -0
- package/dist/actions/init/project/promptForAppTemplateSetup.js.map +1 -0
- package/dist/actions/init/project/promptForProjectCreation.js +40 -0
- package/dist/actions/init/project/promptForProjectCreation.js.map +1 -0
- package/dist/actions/init/project/promptUserForNewOrganization.js +12 -0
- package/dist/actions/init/project/promptUserForNewOrganization.js.map +1 -0
- package/dist/actions/init/project/promptUserForOrganization.js +38 -0
- package/dist/actions/init/project/promptUserForOrganization.js.map +1 -0
- package/dist/actions/init/scaffoldTemplate.js +23 -29
- package/dist/actions/init/scaffoldTemplate.js.map +1 -1
- package/dist/actions/init/types.js +47 -1
- package/dist/actions/init/types.js.map +1 -1
- package/dist/actions/manifest/extractAppManifest.js +3 -2
- package/dist/actions/manifest/extractAppManifest.js.map +1 -1
- package/dist/actions/manifest/types.js +9 -1
- package/dist/actions/manifest/types.js.map +1 -1
- package/dist/actions/manifest/writeManifestFile.js +1 -2
- package/dist/actions/manifest/writeManifestFile.js.map +1 -1
- package/dist/actions/schema/uploadSchemaToLexicon.js +1 -2
- package/dist/actions/schema/uploadSchemaToLexicon.js.map +1 -1
- package/dist/actions/versions/buildPackageArray.js +3 -3
- package/dist/actions/versions/buildPackageArray.js.map +1 -1
- package/dist/actions/versions/findSanityModulesVersions.js +3 -3
- package/dist/actions/versions/findSanityModulesVersions.js.map +1 -1
- package/dist/commands/datasets/copy.js.map +1 -1
- package/dist/commands/init.js +11 -911
- package/dist/commands/init.js.map +1 -1
- package/dist/constants.js +8 -0
- package/dist/constants.js.map +1 -0
- package/dist/server/previewServer.js +1 -1
- package/dist/server/previewServer.js.map +1 -1
- package/dist/server/vite/plugin-sanity-build-entries.js +2 -1
- package/dist/server/vite/plugin-sanity-build-entries.js.map +1 -1
- package/dist/services/datasets.js.map +1 -1
- package/dist/services/userApplications.js.map +1 -1
- package/dist/telemetry/init.telemetry.js.map +1 -1
- package/dist/util/compareDependencyVersions.js +5 -6
- package/dist/util/compareDependencyVersions.js.map +1 -1
- package/dist/util/createExpiringConfig.js +1 -1
- package/dist/util/createExpiringConfig.js.map +1 -1
- package/dist/util/packageManager/installationInfo/analyzeIssues.js +7 -7
- package/dist/util/packageManager/installationInfo/analyzeIssues.js.map +1 -1
- package/dist/util/packageManager/installationInfo/types.js.map +1 -1
- package/dist/util/packageManager/packageManagerChoice.js +2 -2
- package/dist/util/packageManager/packageManagerChoice.js.map +1 -1
- package/dist/util/packageManager/preferredPm.js +106 -0
- package/dist/util/packageManager/preferredPm.js.map +1 -0
- package/oclif.manifest.json +526 -526
- package/package.json +27 -26
- package/dist/util/getLocalPackageVersion.js +0 -55
- package/dist/util/getLocalPackageVersion.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/actions/build/renderDocumentWorker/addTimestampImportMapScriptToHtml.ts"],"sourcesContent":["import {parse as parseHtml} from 'node-html-parser'\n\n/**\n * This script takes the import map from the `#__imports` script tag,\n * modifies relevant URLs that match the sanity-cdn hostname by replacing\n * the existing timestamp in the sanity-cdn URLs with a new runtime timestamp,\n * and injects the modified import map back into the HTML.\n *\n * This will be injected into the HTML of the user's bundle.\n *\n * Note that this is in a separate constants file to prevent \"Cannot access\n * before initialization\" errors.\n */\nconst TIMESTAMPED_IMPORTMAP_INJECTOR_SCRIPT = `<script>\n // auto-generated script to add import map with timestamp\n const importsJson = document.getElementById('__imports')?.textContent;\n const { imports = {}, ...rest } = importsJson ? JSON.parse(importsJson) : {};\n const importMapEl = document.createElement('script');\n importMapEl.type = 'importmap';\n const newTimestamp = \\`/t\\${Math.floor(Date.now() / 1000)}\\`;\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/actions/build/renderDocumentWorker/addTimestampImportMapScriptToHtml.ts"],"sourcesContent":["import {parse as parseHtml} from 'node-html-parser'\n\n/**\n * This script takes the import map from the `#__imports` script tag,\n * modifies relevant URLs that match the sanity-cdn hostname by replacing\n * the existing timestamp in the sanity-cdn URLs with a new runtime timestamp,\n * and injects the modified import map back into the HTML.\n *\n * It also synchronously creates `<link rel=\"stylesheet\">` tags for each CDN\n * CSS URL with a fresh timestamp.\n *\n * This will be injected into the HTML of the user's bundle.\n *\n * Note that this is in a separate constants file to prevent \"Cannot access\n * before initialization\" errors.\n */\nconst TIMESTAMPED_IMPORTMAP_INJECTOR_SCRIPT = `<script>\n // auto-generated script to add import map with timestamp\n const importsJson = document.getElementById('__imports')?.textContent;\n const { imports = {}, css = [], ...rest } = importsJson ? JSON.parse(importsJson) : {};\n const importMapEl = document.createElement('script');\n importMapEl.type = 'importmap';\n const newTimestamp = \\`/t\\${Math.floor(Date.now() / 1000)}\\`;\n\n function replaceTimestamp(urlStr) {\n try {\n const url = new URL(urlStr);\n if (/^sanity-cdn\\\\.[a-zA-Z]+$/.test(url.hostname)) {\n url.pathname = url.pathname.replace(/\\\\/t\\\\d+/, newTimestamp);\n }\n return url.toString();\n } catch {\n return urlStr;\n }\n }\n\n importMapEl.textContent = JSON.stringify({\n imports: Object.fromEntries(\n Object.entries(imports).map(([specifier, path]) => [specifier, replaceTimestamp(path)])\n ),\n ...rest,\n });\n document.head.appendChild(importMapEl);\n\n // Creates <link rel=\"stylesheet\"> tags with fresh timestamps.\n for (const cssUrl of css) {\n const linkEl = document.createElement('link');\n linkEl.rel = 'stylesheet';\n linkEl.href = replaceTimestamp(cssUrl);\n document.head.appendChild(linkEl);\n }\n</script>`\n\n/**\n * @internal\n */\nexport function addTimestampedImportMapScriptToHtml(\n html: string,\n importMap?: {imports?: Record<string, string>},\n autoUpdatesCssUrls?: string[],\n): string {\n if (!importMap) return html\n\n let root = parseHtml(html)\n let htmlEl = root.querySelector('html')\n if (!htmlEl) {\n const oldRoot = root\n root = parseHtml('<html></html>')\n htmlEl = root.querySelector('html')!\n htmlEl.append(oldRoot)\n }\n\n let headEl = htmlEl.querySelector('head')\n\n if (!headEl) {\n htmlEl.insertAdjacentHTML('afterbegin', '<head></head>')\n headEl = root.querySelector('head')!\n }\n\n // Include CSS URLs in the __imports JSON so the runtime script can create\n // <link> tags with fresh timestamps synchronously during head parsing.\n const importMapWithCss =\n autoUpdatesCssUrls && autoUpdatesCssUrls.length > 0\n ? {...importMap, css: autoUpdatesCssUrls}\n : importMap\n\n headEl.insertAdjacentHTML(\n 'beforeend',\n `<script type=\"application/json\" id=\"__imports\">${JSON.stringify(importMapWithCss)}</script>`,\n )\n\n headEl.insertAdjacentHTML('beforeend', TIMESTAMPED_IMPORTMAP_INJECTOR_SCRIPT)\n return root.outerHTML\n}\n"],"names":["parse","parseHtml","TIMESTAMPED_IMPORTMAP_INJECTOR_SCRIPT","addTimestampedImportMapScriptToHtml","html","importMap","autoUpdatesCssUrls","root","htmlEl","querySelector","oldRoot","append","headEl","insertAdjacentHTML","importMapWithCss","length","css","JSON","stringify","outerHTML"],"mappings":"AAAA,SAAQA,SAASC,SAAS,QAAO,mBAAkB;AAEnD;;;;;;;;;;;;;CAaC,GACD,MAAMC,wCAAwC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAmCtC,CAAC;AAEV;;CAEC,GACD,OAAO,SAASC,oCACdC,IAAY,EACZC,SAA8C,EAC9CC,kBAA6B;IAE7B,IAAI,CAACD,WAAW,OAAOD;IAEvB,IAAIG,OAAON,UAAUG;IACrB,IAAII,SAASD,KAAKE,aAAa,CAAC;IAChC,IAAI,CAACD,QAAQ;QACX,MAAME,UAAUH;QAChBA,OAAON,UAAU;QACjBO,SAASD,KAAKE,aAAa,CAAC;QAC5BD,OAAOG,MAAM,CAACD;IAChB;IAEA,IAAIE,SAASJ,OAAOC,aAAa,CAAC;IAElC,IAAI,CAACG,QAAQ;QACXJ,OAAOK,kBAAkB,CAAC,cAAc;QACxCD,SAASL,KAAKE,aAAa,CAAC;IAC9B;IAEA,0EAA0E;IAC1E,uEAAuE;IACvE,MAAMK,mBACJR,sBAAsBA,mBAAmBS,MAAM,GAAG,IAC9C;QAAC,GAAGV,SAAS;QAAEW,KAAKV;IAAkB,IACtCD;IAENO,OAAOC,kBAAkB,CACvB,aACA,CAAC,+CAA+C,EAAEI,KAAKC,SAAS,CAACJ,kBAAkB,SAAS,CAAC;IAG/FF,OAAOC,kBAAkB,CAAC,aAAaX;IACvC,OAAOK,KAAKY,SAAS;AACvB"}
|
|
@@ -27,7 +27,7 @@ import { getDocumentComponent } from './getDocumentComponent.js';
|
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
29
|
* @internal
|
|
30
|
-
*/ export async function getDocumentHtml(parent, studioRootPath, props, importMap, isApp) {
|
|
30
|
+
*/ export async function getDocumentHtml(parent, studioRootPath, props, importMap, isApp, autoUpdatesCssUrls) {
|
|
31
31
|
const Document = await getDocumentComponent(parent, studioRootPath, isApp);
|
|
32
32
|
const defaultProps = {
|
|
33
33
|
entryPath: './.sanity/runtime/app.js'
|
|
@@ -48,7 +48,7 @@ import { getDocumentComponent } from './getDocumentComponent.js';
|
|
|
48
48
|
...defaultProps,
|
|
49
49
|
...props,
|
|
50
50
|
css: css
|
|
51
|
-
})), importMap);
|
|
51
|
+
})), importMap, autoUpdatesCssUrls);
|
|
52
52
|
return `<!DOCTYPE html>${result}`;
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/actions/build/renderDocumentWorker/getDocumentHtml.tsx"],"sourcesContent":["import {type MessagePort} from 'node:worker_threads'\n\nimport {renderToStaticMarkup} from 'react-dom/server'\n\nimport {buildDebug} from '../buildDebug.js'\nimport {addTimestampedImportMapScriptToHtml} from './addTimestampImportMapScriptToHtml.js'\nimport {getDocumentComponent} from './getDocumentComponent.js'\nimport {type DocumentProps} from './types.js'\n\n/**\n * Adds a base path to a URL if necessary, and returns the resulting URL.\n * @param url - The URL to prefix with a base path.\n * @param basePath - The base path to prefix the URL with. Default value is `/`.\n * @returns The resulting URL with the base path.\n * @internal\n */\nfunction _prefixUrlWithBasePath(url: string, basePath: string): string {\n // Normalize basePath by adding a leading slash if it's missing.\n const normalizedBasePath = basePath.startsWith('/') ? basePath : `/${basePath}`\n\n // If the URL starts with a slash, append it to the basePath, removing any trailing slash if present.\n if (url.startsWith('/')) {\n if (normalizedBasePath.endsWith('/')) {\n return `${normalizedBasePath.slice(0, -1)}${url}`\n }\n return `${normalizedBasePath}${url}`\n }\n\n // If the URL doesn't start with a slash, append it to the basePath with a slash in between.\n if (normalizedBasePath.endsWith('/')) {\n return `${normalizedBasePath}${url}`\n }\n return `${normalizedBasePath}/${url}`\n}\n\n/**\n * @internal\n */\nexport async function getDocumentHtml(\n parent: MessagePort,\n studioRootPath: string,\n props?: DocumentProps,\n importMap?: {imports?: Record<string, string>},\n isApp?: boolean,\n): Promise<string> {\n const Document = await getDocumentComponent(parent, studioRootPath, isApp)\n\n const defaultProps = {\n entryPath: './.sanity/runtime/app.js',\n }\n\n // NOTE: Validate the list of CSS paths so implementers of `_document.tsx` don't have to\n // - If the path is not a full URL, check if it starts with `/`\n // - If not, then prepend a `/` to the string\n const css = props?.css?.map((url) => {\n try {\n // If the URL is absolute, we don't need to prefix it\n return new URL(url).toString()\n } catch {\n return _prefixUrlWithBasePath(url, props.basePath)\n }\n })\n\n buildDebug('Rendering document component using React')\n const result = addTimestampedImportMapScriptToHtml(\n renderToStaticMarkup(<Document {...defaultProps} {...props} css={css} />),\n importMap,\n )\n\n return `<!DOCTYPE html>${result}`\n}\n"],"names":["renderToStaticMarkup","buildDebug","addTimestampedImportMapScriptToHtml","getDocumentComponent","_prefixUrlWithBasePath","url","basePath","normalizedBasePath","startsWith","endsWith","slice","getDocumentHtml","parent","studioRootPath","props","importMap","isApp","Document","defaultProps","entryPath","css","map","URL","toString","result"],"mappings":";AAEA,SAAQA,oBAAoB,QAAO,mBAAkB;AAErD,SAAQC,UAAU,QAAO,mBAAkB;AAC3C,SAAQC,mCAAmC,QAAO,yCAAwC;AAC1F,SAAQC,oBAAoB,QAAO,4BAA2B;AAG9D;;;;;;CAMC,GACD,SAASC,uBAAuBC,GAAW,EAAEC,QAAgB;IAC3D,gEAAgE;IAChE,MAAMC,qBAAqBD,SAASE,UAAU,CAAC,OAAOF,WAAW,CAAC,CAAC,EAAEA,UAAU;IAE/E,qGAAqG;IACrG,IAAID,IAAIG,UAAU,CAAC,MAAM;QACvB,IAAID,mBAAmBE,QAAQ,CAAC,MAAM;YACpC,OAAO,GAAGF,mBAAmBG,KAAK,CAAC,GAAG,CAAC,KAAKL,KAAK;QACnD;QACA,OAAO,GAAGE,qBAAqBF,KAAK;IACtC;IAEA,4FAA4F;IAC5F,IAAIE,mBAAmBE,QAAQ,CAAC,MAAM;QACpC,OAAO,GAAGF,qBAAqBF,KAAK;IACtC;IACA,OAAO,GAAGE,mBAAmB,CAAC,EAAEF,KAAK;AACvC;AAEA;;CAEC,GACD,OAAO,eAAeM,gBACpBC,MAAmB,EACnBC,cAAsB,EACtBC,KAAqB,EACrBC,SAA8C,EAC9CC,KAAe;
|
|
1
|
+
{"version":3,"sources":["../../../../src/actions/build/renderDocumentWorker/getDocumentHtml.tsx"],"sourcesContent":["import {type MessagePort} from 'node:worker_threads'\n\nimport {renderToStaticMarkup} from 'react-dom/server'\n\nimport {buildDebug} from '../buildDebug.js'\nimport {addTimestampedImportMapScriptToHtml} from './addTimestampImportMapScriptToHtml.js'\nimport {getDocumentComponent} from './getDocumentComponent.js'\nimport {type DocumentProps} from './types.js'\n\n/**\n * Adds a base path to a URL if necessary, and returns the resulting URL.\n * @param url - The URL to prefix with a base path.\n * @param basePath - The base path to prefix the URL with. Default value is `/`.\n * @returns The resulting URL with the base path.\n * @internal\n */\nfunction _prefixUrlWithBasePath(url: string, basePath: string): string {\n // Normalize basePath by adding a leading slash if it's missing.\n const normalizedBasePath = basePath.startsWith('/') ? basePath : `/${basePath}`\n\n // If the URL starts with a slash, append it to the basePath, removing any trailing slash if present.\n if (url.startsWith('/')) {\n if (normalizedBasePath.endsWith('/')) {\n return `${normalizedBasePath.slice(0, -1)}${url}`\n }\n return `${normalizedBasePath}${url}`\n }\n\n // If the URL doesn't start with a slash, append it to the basePath with a slash in between.\n if (normalizedBasePath.endsWith('/')) {\n return `${normalizedBasePath}${url}`\n }\n return `${normalizedBasePath}/${url}`\n}\n\n/**\n * @internal\n */\nexport async function getDocumentHtml(\n parent: MessagePort,\n studioRootPath: string,\n props?: DocumentProps,\n importMap?: {imports?: Record<string, string>},\n isApp?: boolean,\n autoUpdatesCssUrls?: string[],\n): Promise<string> {\n const Document = await getDocumentComponent(parent, studioRootPath, isApp)\n\n const defaultProps = {\n entryPath: './.sanity/runtime/app.js',\n }\n\n // NOTE: Validate the list of CSS paths so implementers of `_document.tsx` don't have to\n // - If the path is not a full URL, check if it starts with `/`\n // - If not, then prepend a `/` to the string\n const css = props?.css?.map((url) => {\n try {\n // If the URL is absolute, we don't need to prefix it\n return new URL(url).toString()\n } catch {\n return _prefixUrlWithBasePath(url, props.basePath)\n }\n })\n\n buildDebug('Rendering document component using React')\n const result = addTimestampedImportMapScriptToHtml(\n renderToStaticMarkup(<Document {...defaultProps} {...props} css={css} />),\n importMap,\n autoUpdatesCssUrls,\n )\n\n return `<!DOCTYPE html>${result}`\n}\n"],"names":["renderToStaticMarkup","buildDebug","addTimestampedImportMapScriptToHtml","getDocumentComponent","_prefixUrlWithBasePath","url","basePath","normalizedBasePath","startsWith","endsWith","slice","getDocumentHtml","parent","studioRootPath","props","importMap","isApp","autoUpdatesCssUrls","Document","defaultProps","entryPath","css","map","URL","toString","result"],"mappings":";AAEA,SAAQA,oBAAoB,QAAO,mBAAkB;AAErD,SAAQC,UAAU,QAAO,mBAAkB;AAC3C,SAAQC,mCAAmC,QAAO,yCAAwC;AAC1F,SAAQC,oBAAoB,QAAO,4BAA2B;AAG9D;;;;;;CAMC,GACD,SAASC,uBAAuBC,GAAW,EAAEC,QAAgB;IAC3D,gEAAgE;IAChE,MAAMC,qBAAqBD,SAASE,UAAU,CAAC,OAAOF,WAAW,CAAC,CAAC,EAAEA,UAAU;IAE/E,qGAAqG;IACrG,IAAID,IAAIG,UAAU,CAAC,MAAM;QACvB,IAAID,mBAAmBE,QAAQ,CAAC,MAAM;YACpC,OAAO,GAAGF,mBAAmBG,KAAK,CAAC,GAAG,CAAC,KAAKL,KAAK;QACnD;QACA,OAAO,GAAGE,qBAAqBF,KAAK;IACtC;IAEA,4FAA4F;IAC5F,IAAIE,mBAAmBE,QAAQ,CAAC,MAAM;QACpC,OAAO,GAAGF,qBAAqBF,KAAK;IACtC;IACA,OAAO,GAAGE,mBAAmB,CAAC,EAAEF,KAAK;AACvC;AAEA;;CAEC,GACD,OAAO,eAAeM,gBACpBC,MAAmB,EACnBC,cAAsB,EACtBC,KAAqB,EACrBC,SAA8C,EAC9CC,KAAe,EACfC,kBAA6B;IAE7B,MAAMC,WAAW,MAAMf,qBAAqBS,QAAQC,gBAAgBG;IAEpE,MAAMG,eAAe;QACnBC,WAAW;IACb;IAEA,wFAAwF;IACxF,+DAA+D;IAC/D,+CAA+C;IAC/C,MAAMC,MAAMP,OAAOO,KAAKC,IAAI,CAACjB;QAC3B,IAAI;YACF,qDAAqD;YACrD,OAAO,IAAIkB,IAAIlB,KAAKmB,QAAQ;QAC9B,EAAE,OAAM;YACN,OAAOpB,uBAAuBC,KAAKS,MAAMR,QAAQ;QACnD;IACF;IAEAL,WAAW;IACX,MAAMwB,SAASvB,oCACbF,mCAAqB,KAACkB;QAAU,GAAGC,YAAY;QAAG,GAAGL,KAAK;QAAEO,KAAKA;SACjEN,WACAE;IAGF,OAAO,CAAC,eAAe,EAAEQ,QAAQ;AACnC"}
|
|
@@ -6,7 +6,7 @@ import { getDocumentHtml } from './getDocumentHtml.js';
|
|
|
6
6
|
* @param options - The options for the document to render
|
|
7
7
|
* @returns - The rendered document
|
|
8
8
|
*/ export async function renderDocumentWorker(parent, options) {
|
|
9
|
-
const { importMap, isApp, props, studioRootPath } = options;
|
|
9
|
+
const { autoUpdatesCssUrls, importMap, isApp, props, studioRootPath } = options;
|
|
10
10
|
if (typeof studioRootPath !== 'string') {
|
|
11
11
|
parent.postMessage({
|
|
12
12
|
message: 'Missing/invalid `studioRootPath` option',
|
|
@@ -21,7 +21,7 @@ import { getDocumentHtml } from './getDocumentHtml.js';
|
|
|
21
21
|
});
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
|
-
const html = await getDocumentHtml(parent, studioRootPath, props, importMap, isApp);
|
|
24
|
+
const html = await getDocumentHtml(parent, studioRootPath, props, importMap, isApp, autoUpdatesCssUrls);
|
|
25
25
|
parent.postMessage({
|
|
26
26
|
html,
|
|
27
27
|
type: 'result'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/actions/build/renderDocumentWorker/renderDocumentWorker.ts"],"sourcesContent":["import {type MessagePort} from 'node:worker_threads'\n\nimport {getDocumentHtml} from './getDocumentHtml.js'\nimport {type DocumentProps} from './types.js'\n\n/**\n * @internal\n */\nexport interface RenderDocumentWorkerOptions {\n studioRootPath: string\n\n importMap?: {\n imports?: Record<string, string>\n }\n isApp?: boolean\n props?: DocumentProps\n}\n\n/**\n * Renders a document in a worker thread\n *\n * @param parent - The parent port to send messages to\n * @param options - The options for the document to render\n * @returns - The rendered document\n */\nexport async function renderDocumentWorker(\n parent: MessagePort,\n options: RenderDocumentWorkerOptions,\n) {\n const {importMap, isApp, props, studioRootPath} = options\n\n if (typeof studioRootPath !== 'string') {\n parent.postMessage({\n message: 'Missing/invalid `studioRootPath` option',\n type: 'error',\n })\n return\n }\n\n if (props && typeof props !== 'object') {\n parent.postMessage({\n message: '`props` must be an object if provided',\n type: 'error',\n })\n return\n }\n\n const html = await getDocumentHtml(parent
|
|
1
|
+
{"version":3,"sources":["../../../../src/actions/build/renderDocumentWorker/renderDocumentWorker.ts"],"sourcesContent":["import {type MessagePort} from 'node:worker_threads'\n\nimport {getDocumentHtml} from './getDocumentHtml.js'\nimport {type DocumentProps} from './types.js'\n\n/**\n * @internal\n */\nexport interface RenderDocumentWorkerOptions {\n studioRootPath: string\n\n autoUpdatesCssUrls?: string[]\n importMap?: {\n imports?: Record<string, string>\n }\n isApp?: boolean\n props?: DocumentProps\n}\n\n/**\n * Renders a document in a worker thread\n *\n * @param parent - The parent port to send messages to\n * @param options - The options for the document to render\n * @returns - The rendered document\n */\nexport async function renderDocumentWorker(\n parent: MessagePort,\n options: RenderDocumentWorkerOptions,\n) {\n const {autoUpdatesCssUrls, importMap, isApp, props, studioRootPath} = options\n\n if (typeof studioRootPath !== 'string') {\n parent.postMessage({\n message: 'Missing/invalid `studioRootPath` option',\n type: 'error',\n })\n return\n }\n\n if (props && typeof props !== 'object') {\n parent.postMessage({\n message: '`props` must be an object if provided',\n type: 'error',\n })\n return\n }\n\n const html = await getDocumentHtml(\n parent,\n studioRootPath,\n props,\n importMap,\n isApp,\n autoUpdatesCssUrls,\n )\n\n parent.postMessage({\n html,\n type: 'result',\n })\n}\n"],"names":["getDocumentHtml","renderDocumentWorker","parent","options","autoUpdatesCssUrls","importMap","isApp","props","studioRootPath","postMessage","message","type","html"],"mappings":"AAEA,SAAQA,eAAe,QAAO,uBAAsB;AAiBpD;;;;;;CAMC,GACD,OAAO,eAAeC,qBACpBC,MAAmB,EACnBC,OAAoC;IAEpC,MAAM,EAACC,kBAAkB,EAAEC,SAAS,EAAEC,KAAK,EAAEC,KAAK,EAAEC,cAAc,EAAC,GAAGL;IAEtE,IAAI,OAAOK,mBAAmB,UAAU;QACtCN,OAAOO,WAAW,CAAC;YACjBC,SAAS;YACTC,MAAM;QACR;QACA;IACF;IAEA,IAAIJ,SAAS,OAAOA,UAAU,UAAU;QACtCL,OAAOO,WAAW,CAAC;YACjBC,SAAS;YACTC,MAAM;QACR;QACA;IACF;IAEA,MAAMC,OAAO,MAAMZ,gBACjBE,QACAM,gBACAD,OACAF,WACAC,OACAF;IAGFF,OAAOO,WAAW,CAAC;QACjBG;QACAD,MAAM;IACR;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { getLocalPackageVersion } from '@sanity/cli-core';
|
|
2
|
+
import { compare } from 'semver';
|
|
3
3
|
const purpose = 'Transform react-icons v2 imports to v3 form';
|
|
4
4
|
const description = `
|
|
5
5
|
Modifies all found react-icons import and require statements from their v2 form
|
|
@@ -21,7 +21,7 @@ export const reactIconsV3 = {
|
|
|
21
21
|
if (!dependencyVersion) {
|
|
22
22
|
throw new Error('Could not find react-icons declared as dependency in package.json');
|
|
23
23
|
}
|
|
24
|
-
if (
|
|
24
|
+
if (compare(dependencyVersion, '3.0.0') < 0) {
|
|
25
25
|
throw new Error('react-icons declared in package.json dependencies is lower than 3.0.0');
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/codemods/reactIconsV3.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/codemods/reactIconsV3.ts"],"sourcesContent":["import {getLocalPackageVersion} from '@sanity/cli-core'\nimport {compare} from 'semver'\n\nimport {type CodeMod} from './types.js'\n\nconst purpose = 'Transform react-icons v2 imports to v3 form'\nconst description = `\nModifies all found react-icons import and require statements from their v2 form\nto the path structure used in react-icons v3. For instance:\n\nfrom: import {MdPerson} from 'react-icons/lib/md'\n to: import {MdPerson} from 'react-icons/md'\n\nfrom: import PersonIcon from 'react-icons/lib/md/person'\n to: import {MdPerson as PersonIcon} from 'react-icons/md'\n`.trim()\n\nexport const reactIconsV3: CodeMod = {\n description,\n filename: 'reactIconsV3.js',\n purpose,\n verify: async (context) => {\n const {workDir} = context\n\n const dependencyVersion = await getLocalPackageVersion('react-icons', workDir)\n if (!dependencyVersion) {\n throw new Error('Could not find react-icons declared as dependency in package.json')\n }\n\n if (compare(dependencyVersion, '3.0.0') < 0) {\n throw new Error('react-icons declared in package.json dependencies is lower than 3.0.0')\n }\n },\n}\n"],"names":["getLocalPackageVersion","compare","purpose","description","trim","reactIconsV3","filename","verify","context","workDir","dependencyVersion","Error"],"mappings":"AAAA,SAAQA,sBAAsB,QAAO,mBAAkB;AACvD,SAAQC,OAAO,QAAO,SAAQ;AAI9B,MAAMC,UAAU;AAChB,MAAMC,cAAc,CAAC;;;;;;;;;AASrB,CAAC,CAACC,IAAI;AAEN,OAAO,MAAMC,eAAwB;IACnCF;IACAG,UAAU;IACVJ;IACAK,QAAQ,OAAOC;QACb,MAAM,EAACC,OAAO,EAAC,GAAGD;QAElB,MAAME,oBAAoB,MAAMV,uBAAuB,eAAeS;QACtE,IAAI,CAACC,mBAAmB;YACtB,MAAM,IAAIC,MAAM;QAClB;QAEA,IAAIV,QAAQS,mBAAmB,WAAW,GAAG;YAC3C,MAAM,IAAIC,MAAM;QAClB;IACF;AACF,EAAC"}
|
|
@@ -2,13 +2,13 @@ import { basename, dirname } from 'node:path';
|
|
|
2
2
|
import { styleText } from 'node:util';
|
|
3
3
|
import { createGzip } from 'node:zlib';
|
|
4
4
|
import { CLIError } from '@oclif/core/errors';
|
|
5
|
+
import { getLocalPackageVersion } from '@sanity/cli-core';
|
|
5
6
|
import { spinner } from '@sanity/cli-core/ux';
|
|
6
7
|
import { pack } from 'tar-fs';
|
|
7
8
|
import { createDeployment, updateUserApplication } from '../../services/userApplications.js';
|
|
8
9
|
import { getAppId } from '../../util/appId.js';
|
|
9
10
|
import { NO_ORGANIZATION_ID } from '../../util/errorMessages.js';
|
|
10
11
|
import { getErrorMessage } from '../../util/getErrorMessage.js';
|
|
11
|
-
import { getLocalPackageVersion } from '../../util/getLocalPackageVersion.js';
|
|
12
12
|
import { buildApp } from '../build/buildApp.js';
|
|
13
13
|
import { shouldAutoUpdate } from '../build/shouldAutoUpdate.js';
|
|
14
14
|
import { extractAppManifest } from '../manifest/extractAppManifest.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/deploy/deployApp.ts"],"sourcesContent":["import {basename, dirname} from 'node:path'\nimport {styleText} from 'node:util'\nimport {createGzip} from 'node:zlib'\n\nimport {CLIError} from '@oclif/core/errors'\nimport {spinner} from '@sanity/cli-core/ux'\nimport {pack} from 'tar-fs'\n\nimport {createDeployment, updateUserApplication} from '../../services/userApplications.js'\nimport {getAppId} from '../../util/appId.js'\nimport {NO_ORGANIZATION_ID} from '../../util/errorMessages.js'\nimport {getErrorMessage} from '../../util/getErrorMessage.js'\nimport {getLocalPackageVersion} from '../../util/getLocalPackageVersion.js'\nimport {buildApp} from '../build/buildApp.js'\nimport {shouldAutoUpdate} from '../build/shouldAutoUpdate.js'\nimport {extractAppManifest} from '../manifest/extractAppManifest.js'\nimport {type AppManifest} from '../manifest/types.js'\nimport {checkDir} from './checkDir.js'\nimport {createUserApplicationForApp} from './createUserApplicationForApp.js'\nimport {deployDebug} from './deployDebug.js'\nimport {findUserApplicationForApp} from './findUserApplicationForApp.js'\nimport {type DeployAppOptions} from './types.js'\n\n/**\n * Deploy a Sanity application.\n *\n * @internal\n */\nexport async function deployApp(options: DeployAppOptions) {\n const {cliConfig, flags, output, projectRoot, sourceDir} = options\n\n const workDir = projectRoot.directory\n\n const organizationId = cliConfig.app?.organizationId\n const appId = getAppId(cliConfig)\n const isAutoUpdating = shouldAutoUpdate({cliConfig, flags, output})\n const installedSdkVersion = await getLocalPackageVersion('@sanity/sdk-react', workDir)\n\n if (!installedSdkVersion) {\n output.error(`Failed to find installed @sanity/sdk-react version`, {exit: 1})\n return\n }\n\n if (!organizationId) {\n output.error(NO_ORGANIZATION_ID, {exit: 1})\n return\n }\n\n if (flags.external) {\n output.error('Deploying an app to an external host is not supported.', {exit: 1})\n }\n\n let spin = spinner('Verifying local content...')\n\n try {\n let userApplication = await findUserApplicationForApp({\n cliConfig,\n organizationId,\n output,\n })\n\n deployDebug(`User application found`, userApplication)\n\n if (!userApplication) {\n deployDebug(`No user application found. Creating a new one`)\n\n userApplication = await createUserApplicationForApp(organizationId)\n deployDebug(`User application created`, userApplication)\n }\n\n // Always build the project, unless --no-build is passed\n const shouldBuild = flags.build\n if (shouldBuild) {\n deployDebug(`Building app`)\n await buildApp({\n autoUpdatesEnabled: isAutoUpdating,\n calledFromDeploy: true,\n cliConfig,\n flags,\n outDir: sourceDir,\n output,\n workDir,\n })\n }\n\n // Ensure that the directory exists, is a directory and seems to have valid content\n spin = spin.start()\n try {\n await checkDir(sourceDir)\n spin.succeed()\n } catch (err) {\n spin.fail()\n deployDebug('Error checking directory', err)\n output.error('Error checking directory', {exit: 1})\n return\n }\n\n // Create a tarball of the given directory\n const parentDir = dirname(sourceDir)\n const base = basename(sourceDir)\n const tarball = pack(parentDir, {entries: [base]}).pipe(createGzip())\n let manifest: AppManifest | undefined\n try {\n manifest = await extractAppManifest({workDir})\n } catch (err) {\n deployDebug('Error extracting app manifest', err)\n const message = getErrorMessage(err)\n // manifests aren't strictly essential, so continue deploy\n output.warn(`Error extracting app manifest: ${message}`)\n }\n\n // Sync app title from manifest when it has changed (Brett user-applications)\n if (manifest?.title !== undefined && manifest.title !== userApplication.title) {\n deployDebug('Updating application title from manifest', {\n from: userApplication.title,\n to: manifest.title,\n })\n const existing = userApplication.title\n output.log(\n existing\n ? `Updating title from \"${existing}\" to \"${manifest.title}\"`\n : `Setting application title to \"${manifest.title}\"`,\n )\n spin = spinner(`Updating application title`).start()\n try {\n userApplication = await updateUserApplication({\n applicationId: userApplication.id,\n appType: 'coreApp',\n body: {title: manifest.title},\n })\n spin.succeed()\n } catch (err) {\n spin.fail()\n const message = getErrorMessage(err)\n deployDebug('Error updating application title', {message})\n output.warn(`Error updating application title: ${message}`)\n }\n }\n\n spin = spinner('Deploying...').start()\n await createDeployment({\n applicationId: userApplication.id,\n isApp: true,\n isAutoUpdating,\n manifest,\n tarball,\n version: installedSdkVersion,\n })\n\n spin.succeed()\n\n // And let the user know we're done\n output.log(`\\n🚀 ${styleText('bold', 'Success!')} Application deployed`)\n\n if (!appId) {\n output.log(`\\n════ ${styleText('bold', 'Next step:')} ════`)\n output.log(\n styleText(\n 'bold',\n '\\nAdd the deployment.appId to your sanity.cli.js or sanity.cli.ts file:',\n ),\n )\n output.log(`\n${styleText(\n 'dim',\n `app: {\n // your application config here…\n}`,\n)},\n${styleText(\n ['bold', 'green'],\n `deployment: {\n appId: '${userApplication.id}',\n}\\n`,\n)}`)\n }\n } catch (error) {\n spin.clear()\n // Don't throw generic error if user cancels\n if (error.name === 'ExitPromptError') {\n output.error('Deployment cancelled by user', {exit: 1})\n return\n }\n // If the error is a CLIError, we can just output the message & error options (if any), while ensuring we exit\n if (error instanceof CLIError) {\n const {message, ...errorOptions} = error\n output.error(message, {...errorOptions, exit: 1})\n return\n }\n\n deployDebug('Error deploying application', error)\n output.error(`Error deploying application: ${error}`, {exit: 1})\n }\n}\n"],"names":["basename","dirname","styleText","createGzip","CLIError","spinner","pack","createDeployment","updateUserApplication","getAppId","NO_ORGANIZATION_ID","getErrorMessage","getLocalPackageVersion","buildApp","shouldAutoUpdate","extractAppManifest","checkDir","createUserApplicationForApp","deployDebug","findUserApplicationForApp","deployApp","options","cliConfig","flags","output","projectRoot","sourceDir","workDir","directory","organizationId","app","appId","isAutoUpdating","installedSdkVersion","error","exit","external","spin","userApplication","shouldBuild","build","autoUpdatesEnabled","calledFromDeploy","outDir","start","succeed","err","fail","parentDir","base","tarball","entries","pipe","manifest","message","warn","title","undefined","from","to","existing","log","applicationId","id","appType","body","isApp","version","clear","name","errorOptions"],"mappings":"AAAA,SAAQA,QAAQ,EAAEC,OAAO,QAAO,YAAW;AAC3C,SAAQC,SAAS,QAAO,YAAW;AACnC,SAAQC,UAAU,QAAO,YAAW;AAEpC,SAAQC,QAAQ,QAAO,qBAAoB;AAC3C,SAAQC,OAAO,QAAO,sBAAqB;AAC3C,SAAQC,IAAI,QAAO,SAAQ;AAE3B,SAAQC,gBAAgB,EAAEC,qBAAqB,QAAO,qCAAoC;AAC1F,SAAQC,QAAQ,QAAO,sBAAqB;AAC5C,SAAQC,kBAAkB,QAAO,8BAA6B;AAC9D,SAAQC,eAAe,QAAO,gCAA+B;AAC7D,SAAQC,sBAAsB,QAAO,uCAAsC;AAC3E,SAAQC,QAAQ,QAAO,uBAAsB;AAC7C,SAAQC,gBAAgB,QAAO,+BAA8B;AAC7D,SAAQC,kBAAkB,QAAO,oCAAmC;AAEpE,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,YAAY,+BAA+BgB;QAC3CV,OAAOU,KAAK,CAAC,CAAC,6BAA6B,EAAEA,OAAO,EAAE;YAACC,MAAM;QAAC;IAChE;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/deploy/deployApp.ts"],"sourcesContent":["import {basename, dirname} from 'node:path'\nimport {styleText} from 'node:util'\nimport {createGzip} from 'node:zlib'\n\nimport {CLIError} from '@oclif/core/errors'\nimport {getLocalPackageVersion} from '@sanity/cli-core'\nimport {spinner} from '@sanity/cli-core/ux'\nimport {pack} from 'tar-fs'\n\nimport {createDeployment, updateUserApplication} from '../../services/userApplications.js'\nimport {getAppId} from '../../util/appId.js'\nimport {NO_ORGANIZATION_ID} from '../../util/errorMessages.js'\nimport {getErrorMessage} from '../../util/getErrorMessage.js'\nimport {buildApp} from '../build/buildApp.js'\nimport {shouldAutoUpdate} from '../build/shouldAutoUpdate.js'\nimport {extractAppManifest} from '../manifest/extractAppManifest.js'\nimport {type CoreAppManifest} from '../manifest/types.js'\nimport {checkDir} from './checkDir.js'\nimport {createUserApplicationForApp} from './createUserApplicationForApp.js'\nimport {deployDebug} from './deployDebug.js'\nimport {findUserApplicationForApp} from './findUserApplicationForApp.js'\nimport {type DeployAppOptions} from './types.js'\n\n/**\n * Deploy a Sanity application.\n *\n * @internal\n */\nexport async function deployApp(options: DeployAppOptions) {\n const {cliConfig, flags, output, projectRoot, sourceDir} = options\n\n const workDir = projectRoot.directory\n\n const organizationId = cliConfig.app?.organizationId\n const appId = getAppId(cliConfig)\n const isAutoUpdating = shouldAutoUpdate({cliConfig, flags, output})\n const installedSdkVersion = await getLocalPackageVersion('@sanity/sdk-react', workDir)\n\n if (!installedSdkVersion) {\n output.error(`Failed to find installed @sanity/sdk-react version`, {exit: 1})\n return\n }\n\n if (!organizationId) {\n output.error(NO_ORGANIZATION_ID, {exit: 1})\n return\n }\n\n if (flags.external) {\n output.error('Deploying an app to an external host is not supported.', {exit: 1})\n }\n\n let spin = spinner('Verifying local content...')\n\n try {\n let userApplication = await findUserApplicationForApp({\n cliConfig,\n organizationId,\n output,\n })\n\n deployDebug(`User application found`, userApplication)\n\n if (!userApplication) {\n deployDebug(`No user application found. Creating a new one`)\n\n userApplication = await createUserApplicationForApp(organizationId)\n deployDebug(`User application created`, userApplication)\n }\n\n // Always build the project, unless --no-build is passed\n const shouldBuild = flags.build\n if (shouldBuild) {\n deployDebug(`Building app`)\n await buildApp({\n autoUpdatesEnabled: isAutoUpdating,\n calledFromDeploy: true,\n cliConfig,\n flags,\n outDir: sourceDir,\n output,\n workDir,\n })\n }\n\n // Ensure that the directory exists, is a directory and seems to have valid content\n spin = spin.start()\n try {\n await checkDir(sourceDir)\n spin.succeed()\n } catch (err) {\n spin.fail()\n deployDebug('Error checking directory', err)\n output.error('Error checking directory', {exit: 1})\n return\n }\n\n // Create a tarball of the given directory\n const parentDir = dirname(sourceDir)\n const base = basename(sourceDir)\n const tarball = pack(parentDir, {entries: [base]}).pipe(createGzip())\n let manifest: CoreAppManifest | undefined\n try {\n manifest = await extractAppManifest({workDir})\n } catch (err) {\n deployDebug('Error extracting app manifest', err)\n const message = getErrorMessage(err)\n // manifests aren't strictly essential, so continue deploy\n output.warn(`Error extracting app manifest: ${message}`)\n }\n\n // Sync app title from manifest when it has changed (Brett user-applications)\n if (manifest?.title !== undefined && manifest.title !== userApplication.title) {\n deployDebug('Updating application title from manifest', {\n from: userApplication.title,\n to: manifest.title,\n })\n const existing = userApplication.title\n output.log(\n existing\n ? `Updating title from \"${existing}\" to \"${manifest.title}\"`\n : `Setting application title to \"${manifest.title}\"`,\n )\n spin = spinner(`Updating application title`).start()\n try {\n userApplication = await updateUserApplication({\n applicationId: userApplication.id,\n appType: 'coreApp',\n body: {title: manifest.title},\n })\n spin.succeed()\n } catch (err) {\n spin.fail()\n const message = getErrorMessage(err)\n deployDebug('Error updating application title', {message})\n output.warn(`Error updating application title: ${message}`)\n }\n }\n\n spin = spinner('Deploying...').start()\n await createDeployment({\n applicationId: userApplication.id,\n isApp: true,\n isAutoUpdating,\n manifest,\n tarball,\n version: installedSdkVersion,\n })\n\n spin.succeed()\n\n // And let the user know we're done\n output.log(`\\n🚀 ${styleText('bold', 'Success!')} Application deployed`)\n\n if (!appId) {\n output.log(`\\n════ ${styleText('bold', 'Next step:')} ════`)\n output.log(\n styleText(\n 'bold',\n '\\nAdd the deployment.appId to your sanity.cli.js or sanity.cli.ts file:',\n ),\n )\n output.log(`\n${styleText(\n 'dim',\n `app: {\n // your application config here…\n}`,\n)},\n${styleText(\n ['bold', 'green'],\n `deployment: {\n appId: '${userApplication.id}',\n}\\n`,\n)}`)\n }\n } catch (error) {\n spin.clear()\n // Don't throw generic error if user cancels\n if (error.name === 'ExitPromptError') {\n output.error('Deployment cancelled by user', {exit: 1})\n return\n }\n // If the error is a CLIError, we can just output the message & error options (if any), while ensuring we exit\n if (error instanceof CLIError) {\n const {message, ...errorOptions} = error\n output.error(message, {...errorOptions, exit: 1})\n return\n }\n\n deployDebug('Error deploying application', error)\n output.error(`Error deploying application: ${error}`, {exit: 1})\n }\n}\n"],"names":["basename","dirname","styleText","createGzip","CLIError","getLocalPackageVersion","spinner","pack","createDeployment","updateUserApplication","getAppId","NO_ORGANIZATION_ID","getErrorMessage","buildApp","shouldAutoUpdate","extractAppManifest","checkDir","createUserApplicationForApp","deployDebug","findUserApplicationForApp","deployApp","options","cliConfig","flags","output","projectRoot","sourceDir","workDir","directory","organizationId","app","appId","isAutoUpdating","installedSdkVersion","error","exit","external","spin","userApplication","shouldBuild","build","autoUpdatesEnabled","calledFromDeploy","outDir","start","succeed","err","fail","parentDir","base","tarball","entries","pipe","manifest","message","warn","title","undefined","from","to","existing","log","applicationId","id","appType","body","isApp","version","clear","name","errorOptions"],"mappings":"AAAA,SAAQA,QAAQ,EAAEC,OAAO,QAAO,YAAW;AAC3C,SAAQC,SAAS,QAAO,YAAW;AACnC,SAAQC,UAAU,QAAO,YAAW;AAEpC,SAAQC,QAAQ,QAAO,qBAAoB;AAC3C,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AC,GACD;QACC;IACF,EAAE,OAAO7B,OAAO;QACdG,KAAK+B,KAAK;QACV,4CAA4C;QAC5C,IAAIlC,MAAMmC,IAAI,KAAK,mBAAmB;YACpC7C,OAAOU,KAAK,CAAC,gCAAgC;gBAACC,MAAM;YAAC;YACrD;QACF;QACA,8GAA8G;QAC9G,IAAID,iBAAiB9B,UAAU;YAC7B,MAAM,EAACkD,OAAO,EAAE,GAAGgB,cAAa,GAAGpC;YACnCV,OAAOU,KAAK,CAACoB,SAAS;gBAAC,GAAGgB,YAAY;gBAAEnC,MAAM;YAAC;YAC/C;QACF;QAEAjB,YAAY,+BAA+BgB;QAC3CV,OAAOU,KAAK,CAAC,CAAC,6BAA6B,EAAEA,OAAO,EAAE;YAACC,MAAM;QAAC;IAChE;AACF"}
|
|
@@ -2,13 +2,12 @@ import { basename, dirname } from 'node:path';
|
|
|
2
2
|
import { styleText } from 'node:util';
|
|
3
3
|
import { createGzip } from 'node:zlib';
|
|
4
4
|
import { CLIError } from '@oclif/core/errors';
|
|
5
|
-
import { exitCodes } from '@sanity/cli-core';
|
|
5
|
+
import { exitCodes, getLocalPackageVersion } from '@sanity/cli-core';
|
|
6
6
|
import { spinner } from '@sanity/cli-core/ux';
|
|
7
7
|
import { pack } from 'tar-fs';
|
|
8
8
|
import { createDeployment } from '../../services/userApplications.js';
|
|
9
9
|
import { getAppId } from '../../util/appId.js';
|
|
10
10
|
import { NO_PROJECT_ID } from '../../util/errorMessages.js';
|
|
11
|
-
import { getLocalPackageVersion } from '../../util/getLocalPackageVersion.js';
|
|
12
11
|
import { buildStudio } from '../build/buildStudio.js';
|
|
13
12
|
import { shouldAutoUpdate } from '../build/shouldAutoUpdate.js';
|
|
14
13
|
import { formatSchemaValidation } from '../schema/formatSchemaValidation.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/deploy/deployStudio.ts"],"sourcesContent":["import {basename, dirname} from 'node:path'\nimport {styleText} from 'node:util'\nimport {createGzip, type Gzip} from 'node:zlib'\n\nimport {CLIError} from '@oclif/core/errors'\nimport {exitCodes, type Output} from '@sanity/cli-core'\nimport {spinner} from '@sanity/cli-core/ux'\nimport {type StudioManifest} from 'sanity'\nimport {pack} from 'tar-fs'\n\nimport {createDeployment} from '../../services/userApplications.js'\nimport {getAppId} from '../../util/appId.js'\nimport {NO_PROJECT_ID} from '../../util/errorMessages.js'\nimport {getLocalPackageVersion} from '../../util/getLocalPackageVersion.js'\nimport {buildStudio} from '../build/buildStudio.js'\nimport {shouldAutoUpdate} from '../build/shouldAutoUpdate.js'\nimport {formatSchemaValidation} from '../schema/formatSchemaValidation.js'\nimport {SchemaExtractionError} from '../schema/utils/SchemaExtractionError.js'\nimport {checkDir} from './checkDir.js'\nimport {createStudioUserApplication} from './createStudioUserApplication.js'\nimport {deployDebug} from './deployDebug.js'\nimport {deployStudioSchemasAndManifests} from './deployStudioSchemasAndManifests.js'\nimport {findUserApplicationForStudio} from './findUserApplicationForStudio.js'\nimport {type DeployAppOptions} from './types.js'\nimport {normalizeUrl, validateUrl} from './urlUtils.js'\n\nexport async function deployStudio(options: DeployAppOptions) {\n const {cliConfig, flags, output, projectRoot, sourceDir} = options\n\n const workDir = projectRoot.directory\n const configPath = projectRoot.path\n\n const appId = getAppId(cliConfig)\n const projectId = cliConfig.api?.projectId\n const installedSanityVersion = await getLocalPackageVersion('sanity', workDir)\n const isAutoUpdating = shouldAutoUpdate({cliConfig, flags, output})\n\n const isExternal = !!flags.external\n const urlType: 'external' | 'internal' = isExternal ? 'external' : 'internal'\n\n // Resolve the app host from --url flag (takes precedence) or studioHost config\n const appHost = resolveAppHost({flags, isExternal, output, studioHost: cliConfig.studioHost})\n\n if (!installedSanityVersion) {\n output.error(`Failed to find installed sanity version`, {exit: 1})\n return\n }\n\n if (!projectId) {\n output.error(NO_PROJECT_ID, {exit: 1})\n return\n }\n\n let spin = spinner('Verifying local content')\n\n try {\n let userApplication = await findUserApplicationForStudio({\n appHost,\n appId,\n output,\n projectId,\n unattended: !!flags.yes,\n urlType,\n })\n\n if (!userApplication) {\n if (flags.yes) {\n const flagHint = isExternal\n ? 'Use --url to specify the external studio URL'\n : 'Use --url to specify the studio hostname'\n output.error(\n `Cannot prompt for ${isExternal ? 'external studio URL' : 'studio hostname'} in unattended mode. ${flagHint}.`,\n {exit: exitCodes.USAGE_ERROR},\n )\n return\n }\n\n if (isExternal) {\n output.log('Your project has not been registered with an external studio URL.')\n output.log('Please enter the full URL where your studio is hosted.')\n } else {\n output.log('Your project has not been assigned a studio hostname.')\n output.log('To deploy your Sanity Studio to our hosted sanity.studio service,')\n output.log('you will need one. Please enter the subdomain you want to use.')\n }\n\n userApplication = await createStudioUserApplication({projectId, urlType})\n\n deployDebug('Created user application', userApplication)\n }\n\n deployDebug('Found user application', userApplication)\n\n // Always build the project, unless --no-build is passed or --external is passed\n const shouldBuild = flags.build && !isExternal\n if (shouldBuild) {\n deployDebug(`Building studio`)\n await buildStudio({\n autoUpdatesEnabled: isAutoUpdating,\n calledFromDeploy: true,\n cliConfig,\n flags,\n outDir: sourceDir,\n output,\n workDir,\n })\n }\n\n let studioManifest: StudioManifest | null = null\n try {\n studioManifest = await deployStudioSchemasAndManifests({\n configPath,\n isExternal,\n outPath: `${sourceDir}/static`,\n projectId,\n schemaRequired: flags['schema-required'],\n verbose: flags.verbose,\n workDir,\n })\n } catch (error) {\n deployDebug('Error deploying studio schemas and manifests', error)\n if (error instanceof SchemaExtractionError) {\n output.error(formatSchemaValidation(error.validation || []), {exit: 1})\n }\n output.error(`Error deploying studio schemas and manifests: ${error}`, {exit: 1})\n }\n\n if (!studioManifest) {\n output.error('Failed to generate studio manifest. Please check your schemas and manifests.', {\n exit: 1,\n })\n }\n\n let tarball: Gzip | undefined\n\n if (!isExternal) {\n // Ensure that the directory exists, is a directory and seems to have valid content\n spin = spin.start()\n try {\n await checkDir(sourceDir)\n spin.succeed()\n } catch (err) {\n spin.fail()\n deployDebug('Error checking directory', err)\n output.error('Error checking directory', {exit: 1})\n }\n\n // Create a tarball of the given directory\n const parentDir = dirname(sourceDir)\n const base = basename(sourceDir)\n tarball = pack(parentDir, {entries: [base]}).pipe(createGzip())\n }\n\n spin = spinner(isExternal ? 'Registering studio' : 'Deploying to sanity.studio').start()\n\n const {location} = await createDeployment({\n applicationId: userApplication.id,\n isApp: false,\n isAutoUpdating,\n manifest: studioManifest,\n projectId,\n tarball,\n version: installedSanityVersion,\n })\n\n spin.succeed()\n\n if (isExternal) {\n output.log(`\\nSuccess! Studio registered`)\n } else {\n output.log(`\\nSuccess! Studio deployed to ${styleText('cyan', location)}`)\n }\n\n if (!appId) {\n const example = `Example:\nexport default defineCliConfig({\n //…\n deployment: {\n ${styleText('cyan', `appId: '${userApplication.id}'`)},\n },\n //…\n})`\n output.log(`\\nAdd ${styleText('cyan', `appId: '${userApplication.id}'`)}`)\n output.log(`to the \\`deployment\\` section in sanity.cli.js or sanity.cli.ts`)\n output.log(`to avoid prompting for application id on next deploy.`)\n output.log(`\\n${example}`)\n }\n } catch (error) {\n // if the error is a CLIError, we can just output the message and preserve its exit code\n if (error instanceof CLIError) {\n output.error(error.message, {exit: error.oclif?.exit ?? exitCodes.RUNTIME_ERROR})\n return\n }\n\n spin.fail()\n deployDebug('Error deploying studio', error)\n output.error(`Error deploying studio: ${error}`, {exit: 1})\n }\n}\n\nfunction resolveAppHost({\n flags,\n isExternal,\n output,\n studioHost,\n}: {\n flags: DeployAppOptions['flags']\n isExternal: boolean\n output: Output\n studioHost: string | undefined\n}): string | undefined {\n const url = flags.url\n if (!url) {\n return studioHost\n }\n\n if (isExternal) {\n const normalized = normalizeUrl(url)\n const validation = validateUrl(normalized)\n if (validation !== true) {\n output.error(validation, {exit: exitCodes.USAGE_ERROR})\n return undefined\n }\n return normalized\n }\n\n // For internal deploys, strip protocol prefix and .sanity.studio suffix if present\n const hostname = url.replace(/^https?:\\/\\//i, '').replace(/\\.sanity\\.studio\\/?$/i, '')\n\n // If the result still looks like a URL (contains dots), the user likely meant --external\n if (hostname.includes('.')) {\n output.error(\n `\"${hostname}\" does not look like a sanity.studio hostname. Did you mean to use --external?`,\n {exit: exitCodes.USAGE_ERROR},\n )\n return undefined\n }\n\n // Validate hostname characters (alphanumeric and hyphens only)\n if (!/^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/i.test(hostname)) {\n output.error(\n `Invalid studio hostname \"${hostname}\". Hostnames can only contain letters, numbers, and hyphens.`,\n {exit: exitCodes.USAGE_ERROR},\n )\n return undefined\n }\n\n return hostname\n}\n"],"names":["basename","dirname","styleText","createGzip","CLIError","exitCodes","spinner","pack","createDeployment","getAppId","NO_PROJECT_ID","getLocalPackageVersion","buildStudio","shouldAutoUpdate","formatSchemaValidation","SchemaExtractionError","checkDir","createStudioUserApplication","deployDebug","deployStudioSchemasAndManifests","findUserApplicationForStudio","normalizeUrl","validateUrl","deployStudio","options","cliConfig","flags","output","projectRoot","sourceDir","workDir","directory","configPath","path","appId","projectId","api","installedSanityVersion","isAutoUpdating","isExternal","external","urlType","appHost","resolveAppHost","studioHost","error","exit","spin","userApplication","unattended","yes","flagHint","USAGE_ERROR","log","shouldBuild","build","autoUpdatesEnabled","calledFromDeploy","outDir","studioManifest","outPath","schemaRequired","verbose","validation","tarball","start","succeed","err","fail","parentDir","base","entries","pipe","location","applicationId","id","isApp","manifest","version","example","message","oclif","RUNTIME_ERROR","url","normalized","undefined","hostname","replace","includes","test"],"mappings":"AAAA,SAAQA,QAAQ,EAAEC,OAAO,QAAO,YAAW;AAC3C,SAAQC,SAAS,QAAO,YAAW;AACnC,SAAQC,UAAU,QAAkB,YAAW;AAE/C,SAAQC,QAAQ,QAAO,qBAAoB;AAC3C,SAAQC,SAAS,QAAoB,mBAAkB;AACvD,SAAQC,OAAO,QAAO,sBAAqB;AAE3C,SAAQC,IAAI,QAAO,SAAQ;AAE3B,SAAQC,gBAAgB,QAAO,qCAAoC;AACnE,SAAQC,QAAQ,QAAO,sBAAqB;AAC5C,SAAQC,aAAa,QAAO,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C,UAAU+C,WAAW;QAAA;QAE9B,OAAOiC;IACT;IAEA,+DAA+D;IAC/D,IAAI,CAAC,mCAAmCI,IAAI,CAACH,WAAW;QACtD3D,OAAOkB,KAAK,CACV,CAAC,yBAAyB,EAAEyC,SAAS,4DAA4D,CAAC,EAClG;YAACxC,MAAMzC,UAAU+C,WAAW;QAAA;QAE9B,OAAOiC;IACT;IAEA,OAAOC;AACT"}
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/deploy/deployStudio.ts"],"sourcesContent":["import {basename, dirname} from 'node:path'\nimport {styleText} from 'node:util'\nimport {createGzip, type Gzip} from 'node:zlib'\n\nimport {CLIError} from '@oclif/core/errors'\nimport {exitCodes, getLocalPackageVersion, type Output} from '@sanity/cli-core'\nimport {spinner} from '@sanity/cli-core/ux'\nimport {type StudioManifest} from 'sanity'\nimport {pack} from 'tar-fs'\n\nimport {createDeployment} from '../../services/userApplications.js'\nimport {getAppId} from '../../util/appId.js'\nimport {NO_PROJECT_ID} from '../../util/errorMessages.js'\nimport {buildStudio} from '../build/buildStudio.js'\nimport {shouldAutoUpdate} from '../build/shouldAutoUpdate.js'\nimport {formatSchemaValidation} from '../schema/formatSchemaValidation.js'\nimport {SchemaExtractionError} from '../schema/utils/SchemaExtractionError.js'\nimport {checkDir} from './checkDir.js'\nimport {createStudioUserApplication} from './createStudioUserApplication.js'\nimport {deployDebug} from './deployDebug.js'\nimport {deployStudioSchemasAndManifests} from './deployStudioSchemasAndManifests.js'\nimport {findUserApplicationForStudio} from './findUserApplicationForStudio.js'\nimport {type DeployAppOptions} from './types.js'\nimport {normalizeUrl, validateUrl} from './urlUtils.js'\n\nexport async function deployStudio(options: DeployAppOptions) {\n const {cliConfig, flags, output, projectRoot, sourceDir} = options\n\n const workDir = projectRoot.directory\n const configPath = projectRoot.path\n\n const appId = getAppId(cliConfig)\n const projectId = cliConfig.api?.projectId\n const installedSanityVersion = await getLocalPackageVersion('sanity', workDir)\n const isAutoUpdating = shouldAutoUpdate({cliConfig, flags, output})\n\n const isExternal = !!flags.external\n const urlType: 'external' | 'internal' = isExternal ? 'external' : 'internal'\n\n // Resolve the app host from --url flag (takes precedence) or studioHost config\n const appHost = resolveAppHost({flags, isExternal, output, studioHost: cliConfig.studioHost})\n\n if (!installedSanityVersion) {\n output.error(`Failed to find installed sanity version`, {exit: 1})\n return\n }\n\n if (!projectId) {\n output.error(NO_PROJECT_ID, {exit: 1})\n return\n }\n\n let spin = spinner('Verifying local content')\n\n try {\n let userApplication = await findUserApplicationForStudio({\n appHost,\n appId,\n output,\n projectId,\n unattended: !!flags.yes,\n urlType,\n })\n\n if (!userApplication) {\n if (flags.yes) {\n const flagHint = isExternal\n ? 'Use --url to specify the external studio URL'\n : 'Use --url to specify the studio hostname'\n output.error(\n `Cannot prompt for ${isExternal ? 'external studio URL' : 'studio hostname'} in unattended mode. ${flagHint}.`,\n {exit: exitCodes.USAGE_ERROR},\n )\n return\n }\n\n if (isExternal) {\n output.log('Your project has not been registered with an external studio URL.')\n output.log('Please enter the full URL where your studio is hosted.')\n } else {\n output.log('Your project has not been assigned a studio hostname.')\n output.log('To deploy your Sanity Studio to our hosted sanity.studio service,')\n output.log('you will need one. Please enter the subdomain you want to use.')\n }\n\n userApplication = await createStudioUserApplication({projectId, urlType})\n\n deployDebug('Created user application', userApplication)\n }\n\n deployDebug('Found user application', userApplication)\n\n // Always build the project, unless --no-build is passed or --external is passed\n const shouldBuild = flags.build && !isExternal\n if (shouldBuild) {\n deployDebug(`Building studio`)\n await buildStudio({\n autoUpdatesEnabled: isAutoUpdating,\n calledFromDeploy: true,\n cliConfig,\n flags,\n outDir: sourceDir,\n output,\n workDir,\n })\n }\n\n let studioManifest: StudioManifest | null = null\n try {\n studioManifest = await deployStudioSchemasAndManifests({\n configPath,\n isExternal,\n outPath: `${sourceDir}/static`,\n projectId,\n schemaRequired: flags['schema-required'],\n verbose: flags.verbose,\n workDir,\n })\n } catch (error) {\n deployDebug('Error deploying studio schemas and manifests', error)\n if (error instanceof SchemaExtractionError) {\n output.error(formatSchemaValidation(error.validation || []), {exit: 1})\n }\n output.error(`Error deploying studio schemas and manifests: ${error}`, {exit: 1})\n }\n\n if (!studioManifest) {\n output.error('Failed to generate studio manifest. Please check your schemas and manifests.', {\n exit: 1,\n })\n }\n\n let tarball: Gzip | undefined\n\n if (!isExternal) {\n // Ensure that the directory exists, is a directory and seems to have valid content\n spin = spin.start()\n try {\n await checkDir(sourceDir)\n spin.succeed()\n } catch (err) {\n spin.fail()\n deployDebug('Error checking directory', err)\n output.error('Error checking directory', {exit: 1})\n }\n\n // Create a tarball of the given directory\n const parentDir = dirname(sourceDir)\n const base = basename(sourceDir)\n tarball = pack(parentDir, {entries: [base]}).pipe(createGzip())\n }\n\n spin = spinner(isExternal ? 'Registering studio' : 'Deploying to sanity.studio').start()\n\n const {location} = await createDeployment({\n applicationId: userApplication.id,\n isApp: false,\n isAutoUpdating,\n manifest: studioManifest,\n projectId,\n tarball,\n version: installedSanityVersion,\n })\n\n spin.succeed()\n\n if (isExternal) {\n output.log(`\\nSuccess! Studio registered`)\n } else {\n output.log(`\\nSuccess! Studio deployed to ${styleText('cyan', location)}`)\n }\n\n if (!appId) {\n const example = `Example:\nexport default defineCliConfig({\n //…\n deployment: {\n ${styleText('cyan', `appId: '${userApplication.id}'`)},\n },\n //…\n})`\n output.log(`\\nAdd ${styleText('cyan', `appId: '${userApplication.id}'`)}`)\n output.log(`to the \\`deployment\\` section in sanity.cli.js or sanity.cli.ts`)\n output.log(`to avoid prompting for application id on next deploy.`)\n output.log(`\\n${example}`)\n }\n } catch (error) {\n // if the error is a CLIError, we can just output the message and preserve its exit code\n if (error instanceof CLIError) {\n output.error(error.message, {exit: error.oclif?.exit ?? exitCodes.RUNTIME_ERROR})\n return\n }\n\n spin.fail()\n deployDebug('Error deploying studio', error)\n output.error(`Error deploying studio: ${error}`, {exit: 1})\n }\n}\n\nfunction resolveAppHost({\n flags,\n isExternal,\n output,\n studioHost,\n}: {\n flags: DeployAppOptions['flags']\n isExternal: boolean\n output: Output\n studioHost: string | undefined\n}): string | undefined {\n const url = flags.url\n if (!url) {\n return studioHost\n }\n\n if (isExternal) {\n const normalized = normalizeUrl(url)\n const validation = validateUrl(normalized)\n if (validation !== true) {\n output.error(validation, {exit: exitCodes.USAGE_ERROR})\n return undefined\n }\n return normalized\n }\n\n // For internal deploys, strip protocol prefix and .sanity.studio suffix if present\n const hostname = url.replace(/^https?:\\/\\//i, '').replace(/\\.sanity\\.studio\\/?$/i, '')\n\n // If the result still looks like a URL (contains dots), the user likely meant --external\n if (hostname.includes('.')) {\n output.error(\n `\"${hostname}\" does not look like a sanity.studio hostname. Did you mean to use --external?`,\n {exit: exitCodes.USAGE_ERROR},\n )\n return undefined\n }\n\n // Validate hostname characters (alphanumeric and hyphens only)\n if (!/^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/i.test(hostname)) {\n output.error(\n `Invalid studio hostname \"${hostname}\". Hostnames can only contain letters, numbers, and hyphens.`,\n {exit: exitCodes.USAGE_ERROR},\n )\n return undefined\n }\n\n return hostname\n}\n"],"names":["basename","dirname","styleText","createGzip","CLIError","exitCodes","getLocalPackageVersion","spinner","pack","createDeployment","getAppId","NO_PROJECT_ID","buildStudio","shouldAutoUpdate","formatSchemaValidation","SchemaExtractionError","checkDir","createStudioUserApplication","deployDebug","deployStudioSchemasAndManifests","findUserApplicationForStudio","normalizeUrl","validateUrl","deployStudio","options","cliConfig","flags","output","projectRoot","sourceDir","workDir","directory","configPath","path","appId","projectId","api","installedSanityVersion","isAutoUpdating","isExternal","external","urlType","appHost","resolveAppHost","studioHost","error","exit","spin","userApplication","unattended","yes","flagHint","USAGE_ERROR","log","shouldBuild","build","autoUpdatesEnabled","calledFromDeploy","outDir","studioManifest","outPath","schemaRequired","verbose","validation","tarball","start","succeed","err","fail","parentDir","base","entries","pipe","location","applicationId","id","isApp","manifest","version","example","message","oclif","RUNTIME_ERROR","url","normalized","undefined","hostname","replace","includes","test"],"mappings":"AAAA,SA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,CAACkB,YAAY;gBAACjB,MAAMzC,UAAU+C,WAAW;YAAA;YACrD,OAAOiC;QACT;QACA,OAAOD;IACT;IAEA,mFAAmF;IACnF,MAAME,WAAWH,IAAII,OAAO,CAAC,iBAAiB,IAAIA,OAAO,CAAC,yBAAyB;IAEnF,yFAAyF;IACzF,IAAID,SAASE,QAAQ,CAAC,MAAM;QAC1B7D,OAAOkB,KAAK,CACV,CAAC,CAAC,EAAEyC,SAAS,8EAA8E,CAAC,EAC5F;YAACxC,MAAMzC,UAAU+C,WAAW;QAAA;QAE9B,OAAOiC;IACT;IAEA,+DAA+D;IAC/D,IAAI,CAAC,mCAAmCI,IAAI,CAACH,WAAW;QACtD3D,OAAOkB,KAAK,CACV,CAAC,yBAAyB,EAAEyC,SAAS,4DAA4D,CAAC,EAClG;YAACxC,MAAMzC,UAAU+C,WAAW;QAAA;QAE9B,OAAOiC;IACT;IAEA,OAAOC;AACT"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { styleText } from 'node:util';
|
|
2
|
-
import { isInteractive } from '@sanity/cli-core';
|
|
2
|
+
import { getLocalPackageVersion, isInteractive } from '@sanity/cli-core';
|
|
3
3
|
import { confirm, logSymbols, spinner } from '@sanity/cli-core/ux';
|
|
4
|
-
import
|
|
4
|
+
import { parse as semverParse } from 'semver';
|
|
5
5
|
import { startDevServer } from '../../server/devServer.js';
|
|
6
6
|
import { gracefulServerDeath } from '../../server/gracefulServerDeath.js';
|
|
7
7
|
import { getProjectById } from '../../services/projects.js';
|
|
8
8
|
import { getAppId } from '../../util/appId.js';
|
|
9
9
|
import { compareDependencyVersions } from '../../util/compareDependencyVersions.js';
|
|
10
|
-
import { getLocalPackageVersion } from '../../util/getLocalPackageVersion.js';
|
|
11
10
|
import { getPackageManagerChoice } from '../../util/packageManager/packageManagerChoice.js';
|
|
12
11
|
import { upgradePackages } from '../../util/packageManager/upgradePackages.js';
|
|
13
12
|
import { checkRequiredDependencies } from '../build/checkRequiredDependencies.js';
|
|
@@ -32,7 +31,7 @@ export async function startStudioDevServer(options) {
|
|
|
32
31
|
});
|
|
33
32
|
if (autoUpdatesEnabled) {
|
|
34
33
|
// Get the clean version without build metadata: https://semver.org/#spec-item-10
|
|
35
|
-
const cleanSanityVersion =
|
|
34
|
+
const cleanSanityVersion = semverParse(installedSanityVersion)?.version;
|
|
36
35
|
if (!cleanSanityVersion) {
|
|
37
36
|
throw new Error(`Failed to parse installed Sanity version: ${installedSanityVersion}`);
|
|
38
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/dev/startStudioDevServer.ts"],"sourcesContent":["import {styleText} from 'node:util'\n\nimport {isInteractive} from '@sanity/cli-core'\nimport {confirm, logSymbols, spinner} from '@sanity/cli-core/ux'\nimport semver from 'semver'\n\nimport {startDevServer} from '../../server/devServer.js'\nimport {gracefulServerDeath} from '../../server/gracefulServerDeath.js'\nimport {getProjectById} from '../../services/projects.js'\nimport {getAppId} from '../../util/appId.js'\nimport {compareDependencyVersions} from '../../util/compareDependencyVersions.js'\nimport {getLocalPackageVersion} from '../../util/getLocalPackageVersion.js'\nimport {getPackageManagerChoice} from '../../util/packageManager/packageManagerChoice.js'\nimport {upgradePackages} from '../../util/packageManager/upgradePackages.js'\nimport {checkRequiredDependencies} from '../build/checkRequiredDependencies.js'\nimport {checkStudioDependencyVersions} from '../build/checkStudioDependencyVersions.js'\nimport {shouldAutoUpdate} from '../build/shouldAutoUpdate.js'\nimport {devDebug} from './devDebug.js'\nimport {getDashboardAppURL} from './getDashboardAppUrl.js'\nimport {getDevServerConfig} from './getDevServerConfig.js'\nimport {type DevActionOptions} from './types.js'\n\nexport async function startStudioDevServer(\n options: DevActionOptions,\n): Promise<{close?: () => Promise<void>}> {\n const {cliConfig, flags, output, workDir} = options\n const projectId = cliConfig?.api?.projectId\n let organizationId: string | undefined\n\n const loadInDashboard = flags['load-in-dashboard']\n\n // Check studio dependency versions\n await checkStudioDependencyVersions(workDir, output)\n\n const {installedSanityVersion} = await checkRequiredDependencies(options)\n\n // Check if auto-updates are enabled\n const autoUpdatesEnabled = shouldAutoUpdate({cliConfig, flags, output})\n\n if (autoUpdatesEnabled) {\n // Get the clean version without build metadata: https://semver.org/#spec-item-10\n const cleanSanityVersion = semver.parse(installedSanityVersion)?.version\n if (!cleanSanityVersion) {\n throw new Error(`Failed to parse installed Sanity version: ${installedSanityVersion}`)\n }\n\n const sanityDependencies = [\n {name: 'sanity', version: cleanSanityVersion},\n {name: '@sanity/vision', version: cleanSanityVersion},\n ]\n\n output.log(`${logSymbols.info} Running with auto-updates enabled`)\n\n // Check local versions against deployed versions\n let result: Awaited<ReturnType<typeof compareDependencyVersions>> | undefined\n\n const appId = getAppId(cliConfig)\n\n try {\n result = await compareDependencyVersions(sanityDependencies, workDir, {appId})\n } catch (err) {\n output.warn(`Failed to compare local versions against auto-updating versions: ${err}`)\n }\n\n if (result?.unresolvedPrerelease.length) {\n for (const mod of result.unresolvedPrerelease) {\n output.warn(\n `Your local version of ${mod.pkg} (${mod.version}) is a prerelease not available on the auto-updates CDN. The locally installed version will be used.`,\n )\n }\n }\n\n // mismatch between local and auto-updating dependencies\n if (result?.mismatched.length) {\n const message =\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 run with the same versions locally as will be used when deploying.\\n\\n` +\n `${result.mismatched.map((mod) => ` - ${mod.pkg} (local version: ${mod.installed}, runtime version: ${mod.remote})`).join('\\n')}\\n\\n`\n\n if (isInteractive()) {\n const shouldUpgrade = await confirm({\n default: true,\n message: styleText('yellow', `${message}Do you want to upgrade local versions?`),\n })\n if (shouldUpgrade) {\n await upgradePackages(\n {\n packageManager: (await getPackageManagerChoice(workDir, {interactive: false})).chosen,\n packages: result.mismatched.map((res) => [res.pkg, res.remote]),\n },\n {output, workDir},\n )\n }\n } else {\n // In this case we warn the user but we don't ask them if they want to upgrade because it's not interactive.\n output.log(styleText('yellow', message))\n }\n }\n }\n\n if (cliConfig?.schemaExtraction?.enabled) {\n output.log(`${logSymbols.info} Running dev server with schema extraction enabled`)\n }\n\n const config = getDevServerConfig({cliConfig, flags, output, workDir})\n\n if (loadInDashboard) {\n if (!projectId) {\n output.error('Project Id is required to load in dashboard', {exit: 1})\n }\n\n try {\n const project = await getProjectById(projectId!)\n organizationId = project.organizationId!\n } catch (error) {\n devDebug('Error getting organization id from project id', error)\n output.error('Failed to get organization id from project id', {exit: 1})\n }\n }\n\n try {\n const startTime = Date.now()\n const spin = spinner('Starting dev server').start()\n const {close, server} = await startDevServer(config)\n\n const {info: loggerInfo} = server.config.logger\n const {port} = server.config.server\n const httpHost = config.httpHost || 'localhost'\n\n if (loadInDashboard) {\n spin.succeed()\n\n output.log(`Dev server started on port ${port}`)\n output.log(`View your studio in the Sanity dashboard here:`)\n output.log(\n styleText(\n ['blue', 'underline'],\n await getDashboardAppURL({\n httpHost,\n httpPort: port,\n organizationId: organizationId!,\n }),\n ),\n )\n } else {\n const startupDuration = Date.now() - startTime\n const url = `http://${httpHost || 'localhost'}:${port}${config.basePath}`\n const appType = 'Sanity Studio'\n\n const viteVersion = await getLocalPackageVersion('vite', import.meta.url)\n spin.succeed()\n\n loggerInfo(\n `${appType} ` +\n `using ${styleText('cyan', `vite@${viteVersion}`)} ` +\n `ready in ${styleText('cyan', `${Math.ceil(startupDuration)}ms`)} ` +\n `and running at ${styleText('cyan', url)}`,\n )\n }\n\n return {close}\n } catch (err) {\n devDebug('Error starting studio dev server', err)\n throw gracefulServerDeath('dev', config.httpHost, config.httpPort, err)\n }\n}\n"],"names":["styleText","isInteractive","confirm","logSymbols","spinner","semver","startDevServer","gracefulServerDeath","getProjectById","getAppId","compareDependencyVersions","getLocalPackageVersion","getPackageManagerChoice","upgradePackages","checkRequiredDependencies","checkStudioDependencyVersions","shouldAutoUpdate","devDebug","getDashboardAppURL","getDevServerConfig","startStudioDevServer","options","cliConfig","flags","output","workDir","projectId","api","organizationId","loadInDashboard","installedSanityVersion","autoUpdatesEnabled","cleanSanityVersion","parse","version","Error","sanityDependencies","name","log","info","result","appId","err","warn","unresolvedPrerelease","length","mod","pkg","mismatched","message","map","installed","remote","join","shouldUpgrade","default","packageManager","interactive","chosen","packages","res","schemaExtraction","enabled","config","error","exit","project","startTime","Date","now","spin","start","close","server","loggerInfo","logger","port","httpHost","succeed","httpPort","startupDuration","url","basePath","appType","viteVersion","Math","ceil"],"mappings":"AAAA,SAAQA,SAAS,QAAO,YAAW;AAEnC,SAAQC,aAAa,QAAO,mBAAkB;AAC9C,SAAQC,OAAO,EAAEC,UAAU,EAAEC,OAAO,QAAO,sBAAqB;AAChE,OAAOC,YAAY,SAAQ;AAE3B,SAAQC,cAAc,QAAO,4BAA2B;AACxD,SAAQC,mBAAmB,QAAO,sCAAqC;AACvE,SAAQC,cAAc,QAAO,6BAA4B;AACzD,SAAQC,QAAQ,QAAO,sBAAqB;AAC5C,SAAQC,yBAAyB,QAAO,0CAAyC;AACjF,SAAQC,sBAAsB,QAAO,uCAAsC;AAC3E,SAAQC,uBAAuB,QAAO,oDAAmD;AACzF,SAAQC,eAAe,QAAO,+CAA8C;AAC5E,SAAQC,yBAAyB,QAAO,wCAAuC;AAC/E,SAAQC,6BAA6B,QAAO,4CAA2C;AACvF,SAAQC,gBAAgB,QAAO,+BAA8B;AAC7D,SAAQC,QAAQ,QAAO,gBAAe;AACtC,SAAQC,kBAAkB,QAAO,0BAAyB;AAC1D,SAAQC,kBAAkB,QAAO,0BAAyB;AAG1D,OAAO,eAAeC,qBACpBC,OAAyB;IAEzB,MAAM,EAACC,SAAS,EAAEC,KAAK,EAAEC,MAAM,EAAEC,OAAO,EAAC,GAAGJ;IAC5C,MAAMK,YAAYJ,WAAWK,KAAKD;IAClC,IAAIE;IAEJ,MAAMC,kBAAkBN,KAAK,CAAC,oBAAoB;IAElD,mCAAmC;IACnC,MAAMR,8BAA8BU,SAASD;IAE7C,MAAM,EAACM,sBAAsB,EAAC,GAAG,MAAMhB,0BAA0BO;IAEjE,oCAAoC;IAC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,MAAM,CAACU,MAAM;QACnC,MAAMI,WAAWd,OAAOc,QAAQ,IAAI;QAEpC,IAAIhD,iBAAiB;YACnByC,KAAKQ,OAAO;YAEZtD,OAAOc,GAAG,CAAC,CAAC,2BAA2B,EAAEsC,MAAM;YAC/CpD,OAAOc,GAAG,CAAC,CAAC,8CAA8C,CAAC;YAC3Dd,OAAOc,GAAG,CACRtC,UACE;gBAAC;gBAAQ;aAAY,EACrB,MAAMkB,mBAAmB;gBACvB2D;gBACAE,UAAUH;gBACVhD,gBAAgBA;YAClB;QAGN,OAAO;YACL,MAAMoD,kBAAkBZ,KAAKC,GAAG,KAAKF;YACrC,MAAMc,MAAM,CAAC,OAAO,EAAEJ,YAAY,YAAY,CAAC,EAAED,OAAOb,OAAOmB,QAAQ,EAAE;YACzE,MAAMC,UAAU;YAEhB,MAAMC,cAAc,MAAMzE,uBAAuB,QAAQ,YAAYsE,GAAG;YACxEX,KAAKQ,OAAO;YAEZJ,WACE,GAAGS,QAAQ,CAAC,CAAC,GACX,CAAC,MAAM,EAAEnF,UAAU,QAAQ,CAAC,KAAK,EAAEoF,aAAa,EAAE,CAAC,CAAC,GACpD,CAAC,SAAS,EAAEpF,UAAU,QAAQ,GAAGqF,KAAKC,IAAI,CAACN,iBAAiB,EAAE,CAAC,EAAE,CAAC,CAAC,GACnE,CAAC,eAAe,EAAEhF,UAAU,QAAQiF,MAAM;QAEhD;QAEA,OAAO;YAACT;QAAK;IACf,EAAE,OAAO9B,KAAK;QACZzB,SAAS,oCAAoCyB;QAC7C,MAAMnC,oBAAoB,OAAOwD,OAAOc,QAAQ,EAAEd,OAAOgB,QAAQ,EAAErC;IACrE;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/dev/startStudioDevServer.ts"],"sourcesContent":["import {styleText} from 'node:util'\n\nimport {getLocalPackageVersion, isInteractive} from '@sanity/cli-core'\nimport {confirm, logSymbols, spinner} from '@sanity/cli-core/ux'\nimport {parse as semverParse} from 'semver'\n\nimport {startDevServer} from '../../server/devServer.js'\nimport {gracefulServerDeath} from '../../server/gracefulServerDeath.js'\nimport {getProjectById} from '../../services/projects.js'\nimport {getAppId} from '../../util/appId.js'\nimport {compareDependencyVersions} from '../../util/compareDependencyVersions.js'\nimport {getPackageManagerChoice} from '../../util/packageManager/packageManagerChoice.js'\nimport {upgradePackages} from '../../util/packageManager/upgradePackages.js'\nimport {checkRequiredDependencies} from '../build/checkRequiredDependencies.js'\nimport {checkStudioDependencyVersions} from '../build/checkStudioDependencyVersions.js'\nimport {shouldAutoUpdate} from '../build/shouldAutoUpdate.js'\nimport {devDebug} from './devDebug.js'\nimport {getDashboardAppURL} from './getDashboardAppUrl.js'\nimport {getDevServerConfig} from './getDevServerConfig.js'\nimport {type DevActionOptions} from './types.js'\n\nexport async function startStudioDevServer(\n options: DevActionOptions,\n): Promise<{close?: () => Promise<void>}> {\n const {cliConfig, flags, output, workDir} = options\n const projectId = cliConfig?.api?.projectId\n let organizationId: string | undefined\n\n const loadInDashboard = flags['load-in-dashboard']\n\n // Check studio dependency versions\n await checkStudioDependencyVersions(workDir, output)\n\n const {installedSanityVersion} = await checkRequiredDependencies(options)\n\n // Check if auto-updates are enabled\n const autoUpdatesEnabled = shouldAutoUpdate({cliConfig, flags, output})\n\n if (autoUpdatesEnabled) {\n // Get the clean version without build metadata: https://semver.org/#spec-item-10\n const cleanSanityVersion = semverParse(installedSanityVersion)?.version\n if (!cleanSanityVersion) {\n throw new Error(`Failed to parse installed Sanity version: ${installedSanityVersion}`)\n }\n\n const sanityDependencies = [\n {name: 'sanity', version: cleanSanityVersion},\n {name: '@sanity/vision', version: cleanSanityVersion},\n ]\n\n output.log(`${logSymbols.info} Running with auto-updates enabled`)\n\n // Check local versions against deployed versions\n let result: Awaited<ReturnType<typeof compareDependencyVersions>> | undefined\n\n const appId = getAppId(cliConfig)\n\n try {\n result = await compareDependencyVersions(sanityDependencies, workDir, {appId})\n } catch (err) {\n output.warn(`Failed to compare local versions against auto-updating versions: ${err}`)\n }\n\n if (result?.unresolvedPrerelease.length) {\n for (const mod of result.unresolvedPrerelease) {\n output.warn(\n `Your local version of ${mod.pkg} (${mod.version}) is a prerelease not available on the auto-updates CDN. The locally installed version will be used.`,\n )\n }\n }\n\n // mismatch between local and auto-updating dependencies\n if (result?.mismatched.length) {\n const message =\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 run with the same versions locally as will be used when deploying.\\n\\n` +\n `${result.mismatched.map((mod) => ` - ${mod.pkg} (local version: ${mod.installed}, runtime version: ${mod.remote})`).join('\\n')}\\n\\n`\n\n if (isInteractive()) {\n const shouldUpgrade = await confirm({\n default: true,\n message: styleText('yellow', `${message}Do you want to upgrade local versions?`),\n })\n if (shouldUpgrade) {\n await upgradePackages(\n {\n packageManager: (await getPackageManagerChoice(workDir, {interactive: false})).chosen,\n packages: result.mismatched.map((res) => [res.pkg, res.remote]),\n },\n {output, workDir},\n )\n }\n } else {\n // In this case we warn the user but we don't ask them if they want to upgrade because it's not interactive.\n output.log(styleText('yellow', message))\n }\n }\n }\n\n if (cliConfig?.schemaExtraction?.enabled) {\n output.log(`${logSymbols.info} Running dev server with schema extraction enabled`)\n }\n\n const config = getDevServerConfig({cliConfig, flags, output, workDir})\n\n if (loadInDashboard) {\n if (!projectId) {\n output.error('Project Id is required to load in dashboard', {exit: 1})\n }\n\n try {\n const project = await getProjectById(projectId!)\n organizationId = project.organizationId!\n } catch (error) {\n devDebug('Error getting organization id from project id', error)\n output.error('Failed to get organization id from project id', {exit: 1})\n }\n }\n\n try {\n const startTime = Date.now()\n const spin = spinner('Starting dev server').start()\n const {close, server} = await startDevServer(config)\n\n const {info: loggerInfo} = server.config.logger\n const {port} = server.config.server\n const httpHost = config.httpHost || 'localhost'\n\n if (loadInDashboard) {\n spin.succeed()\n\n output.log(`Dev server started on port ${port}`)\n output.log(`View your studio in the Sanity dashboard here:`)\n output.log(\n styleText(\n ['blue', 'underline'],\n await getDashboardAppURL({\n httpHost,\n httpPort: port,\n organizationId: organizationId!,\n }),\n ),\n )\n } else {\n const startupDuration = Date.now() - startTime\n const url = `http://${httpHost || 'localhost'}:${port}${config.basePath}`\n const appType = 'Sanity Studio'\n\n const viteVersion = await getLocalPackageVersion('vite', import.meta.url)\n spin.succeed()\n\n loggerInfo(\n `${appType} ` +\n `using ${styleText('cyan', `vite@${viteVersion}`)} ` +\n `ready in ${styleText('cyan', `${Math.ceil(startupDuration)}ms`)} ` +\n `and running at ${styleText('cyan', url)}`,\n )\n }\n\n return {close}\n } catch (err) {\n devDebug('Error starting studio dev server', err)\n throw gracefulServerDeath('dev', config.httpHost, config.httpPort, err)\n }\n}\n"],"names":["styleText","getLocalPackageVersion","isInteractive","confirm","logSymbols","spinner","parse","semverParse","startDevServer","gracefulServerDeath","getProjectById","getAppId","compareDependencyVersions","getPackageManagerChoice","upgradePackages","checkRequiredDependencies","checkStudioDependencyVersions","shouldAutoUpdate","devDebug","getDashboardAppURL","getDevServerConfig","startStudioDevServer","options","cliConfig","flags","output","workDir","projectId","api","organizationId","loadInDashboard","installedSanityVersion","autoUpdatesEnabled","cleanSanityVersion","version","Error","sanityDependencies","name","log","info","result","appId","err","warn","unresolvedPrerelease","length","mod","pkg","mismatched","message","map","installed","remote","join","shouldUpgrade","default","packageManager","interactive","chosen","packages","res","schemaExtraction","enabled","config","error","exit","project","startTime","Date","now","spin","start","close","server","loggerInfo","logger","port","httpHost","succeed","httpPort","startupDuration","url","basePath","appType","viteVersion","Math","ceil"],"mappings":"AAAA,SAAQA,SAAS,QAAO,YAAW;AAEnC,SAAQC,sBAAsB,EAAEC,aAAa,QAAO,mBAAkB;AACtE,SAAQC,OAAO,EAAEC,UAAU,EAAEC,OAAO,QAAO,sBAAqB;AAChE,SAAQC,SAASC,WAAW,QAAO,SAAQ;AAE3C,SAAQC,cAAc,QAAO,4BAA2B;AACxD,SAAQC,mBAAmB,QAAO,sCAAqC;AACvE,SAAQC,cAAc,QAAO,6BAA4B;AACzD,SAAQC,QAA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ACxEX,KAAKQ,OAAO;YAEZJ,WACE,GAAGS,QAAQ,CAAC,CAAC,GACX,CAAC,MAAM,EAAEnF,UAAU,QAAQ,CAAC,KAAK,EAAEoF,aAAa,EAAE,CAAC,CAAC,GACpD,CAAC,SAAS,EAAEpF,UAAU,QAAQ,GAAGqF,KAAKC,IAAI,CAACN,iBAAiB,EAAE,CAAC,EAAE,CAAC,CAAC,GACnE,CAAC,eAAe,EAAEhF,UAAU,QAAQiF,MAAM;QAEhD;QAEA,OAAO;YAACT;QAAK;IACf,EAAE,OAAO9B,KAAK;QACZxB,SAAS,oCAAoCwB;QAC7C,MAAMjC,oBAAoB,OAAOsD,OAAOc,QAAQ,EAAEd,OAAOgB,QAAQ,EAAErC;IACrE;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/doctor/types.ts"],"sourcesContent":["export interface DoctorCheck {\n name: string\n run(context: DoctorContext): Promise<CheckResult>\n title: string\n}\n\nexport type CheckResultStatus = 'error' | 'passed' | 'warning'\n\nexport type MessageType = 'error' | 'info' | 'success' | 'warning'\n\
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/doctor/types.ts"],"sourcesContent":["export interface DoctorCheck {\n name: string\n run(context: DoctorContext): Promise<CheckResult>\n title: string\n}\n\nexport type CheckResultStatus = 'error' | 'passed' | 'warning'\n\nexport type MessageType = 'error' | 'info' | 'success' | 'warning'\n\ntype SummaryTypes = 'errors' | 'passed' | 'warnings'\n\nexport interface DoctorContext {\n cwd: string\n}\n\nexport interface CheckResult {\n messages: CheckMessage[]\n status: CheckResultStatus\n}\n\nexport interface CheckMessage {\n text: string\n type: MessageType\n\n suggestions?: string[]\n}\n\nexport interface DoctorResults {\n checks: CheckResultWithMeta[]\n summary: Record<SummaryTypes, number>\n}\n\nexport interface CheckResultWithMeta extends CheckResult {\n name: string\n title: string\n}\n"],"names":[],"mappings":"AAiCA,WAGC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/graphql/resolveGraphQLApisFromWorkspaces.ts"],"sourcesContent":["import {type Schema} from '@sanity/types'\nimport isPlainObject from 'lodash-es/isPlainObject.js'\nimport {oneline} from 'oneline'\n\nimport {\n type ExtractedGraphQLAPI,\n type GraphQLAPIConfig,\n type SchemaDefinitionish,\n type TypeResolvedGraphQLAPI,\n} from './types.js'\n\nexport interface Source {\n dataset: string\n name: string\n projectId: string\n schema: Schema\n}\n\nexport interface Workspace extends Source {\n unstable_sources: Source[]\n}\n\n/**\n * Minimal source metadata — dataset/projectId pair for a source within a workspace.\n */\nexport interface SourceMetadata {\n dataset: string\n name: string\n projectId: string\n}\n\n/**\n * Minimal workspace metadata — enough for resolving API identifiers without compiling schemas.\n * This matches the raw workspace shape from `defineConfig()` before `resolveConfig()` processes it.\n *\n * The `sources` array mirrors `Workspace.unstable_sources` from the full resolved config.\n * When the raw config includes `unstable_sources`, they are extracted here. Otherwise, the\n * workspace itself is used as a single default source (matching what `resolveConfig()` would do).\n */\nexport interface WorkspaceMetadata {\n dataset: string\n name: string\n projectId: string\n sources: SourceMetadata[]\n}\n\ninterface ResolveGraphQLApisOptions {\n workspaces: Workspace[]\n\n cliConfig?: {graphql?: GraphQLAPIConfig[]}\n}\n\nexport function resolveGraphQLApis({\n cliConfig,\n workspaces,\n}: ResolveGraphQLApisOptions): TypeResolvedGraphQLAPI[] {\n const numSources = workspaces.reduce(\n (count, workspace) => count + workspace.unstable_sources.length,\n 0,\n )\n const multiSource = numSources > 1\n const multiWorkspace = workspaces.length > 1\n const hasGraphQLConfig = Boolean(cliConfig?.graphql)\n\n if (workspaces.length === 0) {\n throw new Error('No studio configuration found')\n }\n\n if (numSources === 0) {\n throw new Error('No sources (project ID / dataset) configured')\n }\n\n // We can only automatically configure if there is a single workspace + source in play\n if ((multiWorkspace || multiSource) && !hasGraphQLConfig) {\n throw new Error(oneline`\n Multiple workspaces/sources configured.\n You must define an array of GraphQL APIs in \\`sanity.cli.ts\\` or \\`sanity.cli.js\\`\n and specify which workspace/source to use.\n `)\n }\n\n // No config is defined, but we have a single workspace + source, so use that\n if (!hasGraphQLConfig) {\n const {dataset, projectId, schema} = workspaces[0].unstable_sources[0]\n return [{dataset, projectId, schemaTypes: getStrippedSchemaTypes(schema)}]\n }\n\n // Explicitly defined config\n const apiDefs = validateCliConfig(cliConfig?.graphql || [])\n return resolveGraphQLAPIsFromConfig(apiDefs, workspaces)\n}\n\n/**\n * Resolve GraphQL API metadata (projectId, dataset, tag, etc.) from raw workspace configs\n * without compiling schemas. This is used when we only need API identifiers, not schema types —\n * e.g. for `graphql undeploy --api` or `graphql list`.\n */\nexport function resolveGraphQLApiMetadata({\n cliConfig,\n workspaces,\n}: {\n cliConfig?: {graphql?: GraphQLAPIConfig[]}\n workspaces: WorkspaceMetadata[]\n}): ExtractedGraphQLAPI[] {\n const numSources = workspaces.reduce((count, ws) => count + ws.sources.length, 0)\n const multiSource = numSources > 1\n const multiWorkspace = workspaces.length > 1\n const hasGraphQLConfig = Boolean(cliConfig?.graphql)\n\n if (workspaces.length === 0) {\n throw new Error('No studio configuration found')\n }\n\n if (numSources === 0) {\n throw new Error('No sources (project ID / dataset) configured')\n }\n\n // We can only automatically configure if there is a single workspace + source in play\n if ((multiWorkspace || multiSource) && !hasGraphQLConfig) {\n throw new Error(oneline`\n Multiple workspaces/sources configured.\n You must define an array of GraphQL APIs in \\`sanity.cli.ts\\` or \\`sanity.cli.js\\`\n and specify which workspace/source to use.\n `)\n }\n\n // Validate that workspaces and their sources have non-empty projectId/dataset.\n // The worker's toWorkspaceMetadata validates this before constructing metadata,\n // but assert here to make the invariant explicit.\n for (const ws of workspaces) {\n if (!ws.projectId || !ws.dataset) {\n throw new Error(\n `Workspace \"${ws.name}\" is missing a projectId or dataset. ` +\n 'Check your studio configuration.',\n )\n }\n for (const source of ws.sources) {\n if (!source.projectId || !source.dataset) {\n throw new Error(\n `Source \"${source.name}\" in workspace \"${ws.name}\" is missing a projectId or dataset. ` +\n 'Check your studio configuration.',\n )\n }\n }\n }\n\n // No config is defined, but we have a single workspace + source, so use that\n if (!hasGraphQLConfig) {\n const {dataset, projectId} = workspaces[0].sources[0]\n return [{dataset, projectId}]\n }\n\n // Explicitly defined config\n const apiDefs = validateCliConfig(cliConfig?.graphql || [])\n return resolveGraphQLApiMetadataFromConfig(apiDefs, workspaces)\n}\n\n/**\n * Shared workspace/source resolution logic for both the metadata and full-compile paths.\n *\n * Both `resolveGraphQLAPIsFromConfig` and `resolveGraphQLApiMetadataFromConfig` need to\n * resolve the workspace and source for each GraphQL API config entry. This helper\n * extracts that shared logic so bug fixes and edge-case handling apply to both paths.\n */\nfunction resolveWorkspaceAndSource<\n TWorkspace extends {name: string},\n TSource extends {name: string},\n>(\n apiDef: GraphQLAPIConfig,\n workspaces: TWorkspace[],\n getSources: (workspace: TWorkspace) => TSource[],\n): {source: TSource; workspace: TWorkspace} {\n const {source: sourceName, workspace: workspaceName} = apiDef\n\n if (!workspaceName && workspaces.length > 1) {\n throw new Error(\n 'Must define `workspace` name in GraphQL API config when multiple workspaces are defined',\n )\n }\n\n // If we only have a single workspace defined, we can assume that is the intended one,\n // even if no `workspace` is defined for the GraphQL API\n const workspace =\n !workspaceName && workspaces.length === 1\n ? workspaces[0]\n : workspaces.find((space) => space.name === (workspaceName || 'default'))\n\n if (!workspace) {\n throw new Error(`Workspace \"${workspaceName || 'default'}\" not found`)\n }\n\n const sources = getSources(workspace)\n\n // If we only have a single source defined, we can assume that is the intended one,\n // even if no `source` is defined for the GraphQL API\n const source =\n !sourceName && sources.length === 1\n ? sources[0]\n : sources.find((src) => src.name === (sourceName || 'default'))\n\n if (!source) {\n throw new Error(\n `Source \"${sourceName || 'default'}\" not found in workspace \"${workspaceName || 'default'}\"`,\n )\n }\n\n return {source, workspace}\n}\n\nfunction resolveGraphQLApiMetadataFromConfig(\n apiDefs: GraphQLAPIConfig[],\n workspaces: WorkspaceMetadata[],\n): ExtractedGraphQLAPI[] {\n return apiDefs.map((apiDef) => {\n const {source} = resolveWorkspaceAndSource(apiDef, workspaces, (ws) => ws.sources)\n\n return {\n dataset: source.dataset,\n filterSuffix: apiDef.filterSuffix,\n generation: apiDef.generation,\n id: apiDef.id,\n nonNullDocumentFields: apiDef.nonNullDocumentFields,\n playground: apiDef.playground,\n projectId: source.projectId,\n tag: apiDef.tag,\n }\n })\n}\n\nfunction resolveGraphQLAPIsFromConfig(\n apiDefs: GraphQLAPIConfig[],\n workspaces: Workspace[],\n): TypeResolvedGraphQLAPI[] {\n return apiDefs.map((apiDef) => {\n const {source} = resolveWorkspaceAndSource(apiDef, workspaces, (ws) => ws.unstable_sources)\n\n return {\n ...apiDef,\n dataset: source.dataset,\n projectId: source.projectId,\n schemaTypes: getStrippedSchemaTypes(source.schema),\n }\n })\n}\n\nfunction validateCliConfig(\n config: GraphQLAPIConfig[],\n configPath = 'sanity.cli.js',\n): GraphQLAPIConfig[] {\n if (!Array.isArray(config)) {\n throw new TypeError(`\"graphql\" key in \"${configPath}\" must be an array if defined`)\n }\n\n if (config.length === 0) {\n throw new Error(`No GraphQL APIs defined in \"${configPath}\"`)\n }\n\n return config\n}\n\nfunction getStrippedSchemaTypes(schema: Schema): SchemaDefinitionish[] {\n const schemaDef = schema._original || {types: []}\n return schemaDef.types.map((type) => stripType(type))\n}\n\nfunction stripType(input: unknown): SchemaDefinitionish {\n return strip(input) as SchemaDefinitionish\n}\n\nfunction strip(input: unknown): unknown {\n if (Array.isArray(input)) {\n return input.map((item) => strip(item)).filter((item) => item !== undefined)\n }\n\n if (isPlainishObject(input)) {\n const stripped: Record<string, unknown> = {}\n for (const key of Object.keys(input)) {\n stripped[key] = strip(input[key])\n }\n return stripped\n }\n\n return isBasicType(input) ? input : undefined\n}\n\nfunction isPlainishObject(input: unknown): input is Record<string, unknown> {\n return isPlainObject(input)\n}\n\nfunction isBasicType(input: unknown): boolean {\n const type = typeof input\n if (type === 'boolean' || type === 'number' || type === 'string') {\n return true\n }\n\n if (type !== 'object') {\n return false\n }\n\n return Array.isArray(input) || input === null || isPlainishObject(input)\n}\n"],"names":["isPlainObject","oneline","resolveGraphQLApis","cliConfig","workspaces","numSources","reduce","count","workspace","unstable_sources","length","multiSource","multiWorkspace","hasGraphQLConfig","Boolean","graphql","Error","dataset","projectId","schema","schemaTypes","getStrippedSchemaTypes","apiDefs","validateCliConfig","resolveGraphQLAPIsFromConfig","resolveGraphQLApiMetadata","ws","sources","name","source","resolveGraphQLApiMetadataFromConfig","resolveWorkspaceAndSource","apiDef","getSources","sourceName","workspaceName","find","space","src","map","filterSuffix","generation","id","nonNullDocumentFields","playground","tag","config","configPath","Array","isArray","TypeError","schemaDef","_original","types","type","stripType","input","strip","item","filter","undefined","isPlainishObject","stripped","key","Object","keys","isBasicType"],"mappings":"AACA,OAAOA,mBAAmB,6BAA4B;AACtD,SAAQC,OAAO,QAAO,UAAS;AAkD/B,OAAO,SAASC,mBAAmB,EACjCC,SAAS,EACTC,UAAU,EACgB;IAC1B,MAAMC,aAAaD,WAAWE,MAAM,CAClC,CAACC,OAAOC,YAAcD,QAAQC,UAAUC,gBAAgB,CAACC,MAAM,EAC/D;IAEF,MAAMC,cAAcN,aAAa;IACjC,MAAMO,iBAAiBR,WAAWM,MAAM,GAAG;IAC3C,MAAMG,mBAAmBC,QAAQX,WAAWY;IAE5C,IAAIX,WAAWM,MAAM,KAAK,GAAG;QAC3B,MAAM,IAAIM,MAAM;IAClB;IAEA,IAAIX,eAAe,GAAG;QACpB,MAAM,IAAIW,MAAM;IAClB;IAEA,sFAAsF;IACtF,IAAI,AAACJ,CAAAA,kBAAkBD,WAAU,KAAM,CAACE,kBAAkB;QACxD,MAAM,IAAIG,MAAMf,OAAO,CAAC;;;;IAIxB,CAAC;IACH;IAEA,6EAA6E;IAC7E,IAAI,CAACY,kBAAkB;QACrB,MAAM,EAACI,OAAO,EAAEC,SAAS,EAAEC,MAAM,EAAC,GAAGf,UAAU,CAAC,EAAE,CAACK,gBAAgB,CAAC,EAAE;QACtE,OAAO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f;AAEA,SAASC,MAAMD,KAAc;IAC3B,IAAIR,MAAMC,OAAO,CAACO,QAAQ;QACxB,OAAOA,MAAMjB,GAAG,CAAC,CAACmB,OAASD,MAAMC,OAAOC,MAAM,CAAC,CAACD,OAASA,SAASE;IACpE;IAEA,IAAIC,iBAAiBL,QAAQ;QAC3B,MAAMM,WAAoC,CAAC;QAC3C,KAAK,MAAMC,OAAOC,OAAOC,IAAI,CAACT,OAAQ;YACpCM,QAAQ,CAACC,IAAI,GAAGN,MAAMD,KAAK,CAACO,IAAI;QAClC;QACA,OAAOD;IACT;IAEA,OAAOI,YAAYV,SAASA,QAAQI;AACtC;AAEA,SAASC,iBAAiBL,KAAc;IACtC,OAAOxD,cAAcwD;AACvB;AAEA,SAASU,YAAYV,KAAc;IACjC,MAAMF,OAAO,OAAOE;IACpB,IAAIF,SAAS,aAAaA,SAAS,YAAYA,SAAS,UAAU;QAChE,OAAO;IACT;IAEA,IAAIA,SAAS,UAAU;QACrB,OAAO;IACT;IAEA,OAAON,MAAMC,OAAO,CAACO,UAAUA,UAAU,QAAQK,iBAAiBL;AACpE"}
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/graphql/resolveGraphQLApisFromWorkspaces.ts"],"sourcesContent":["import {type Schema} from '@sanity/types'\nimport isPlainObject from 'lodash-es/isPlainObject.js'\nimport {oneline} from 'oneline'\n\nimport {\n type ExtractedGraphQLAPI,\n type GraphQLAPIConfig,\n type SchemaDefinitionish,\n type TypeResolvedGraphQLAPI,\n} from './types.js'\n\ninterface Source {\n dataset: string\n name: string\n projectId: string\n schema: Schema\n}\n\nexport interface Workspace extends Source {\n unstable_sources: Source[]\n}\n\n/**\n * Minimal source metadata — dataset/projectId pair for a source within a workspace.\n */\nexport interface SourceMetadata {\n dataset: string\n name: string\n projectId: string\n}\n\n/**\n * Minimal workspace metadata — enough for resolving API identifiers without compiling schemas.\n * This matches the raw workspace shape from `defineConfig()` before `resolveConfig()` processes it.\n *\n * The `sources` array mirrors `Workspace.unstable_sources` from the full resolved config.\n * When the raw config includes `unstable_sources`, they are extracted here. Otherwise, the\n * workspace itself is used as a single default source (matching what `resolveConfig()` would do).\n */\nexport interface WorkspaceMetadata {\n dataset: string\n name: string\n projectId: string\n sources: SourceMetadata[]\n}\n\ninterface ResolveGraphQLApisOptions {\n workspaces: Workspace[]\n\n cliConfig?: {graphql?: GraphQLAPIConfig[]}\n}\n\nexport function resolveGraphQLApis({\n cliConfig,\n workspaces,\n}: ResolveGraphQLApisOptions): TypeResolvedGraphQLAPI[] {\n const numSources = workspaces.reduce(\n (count, workspace) => count + workspace.unstable_sources.length,\n 0,\n )\n const multiSource = numSources > 1\n const multiWorkspace = workspaces.length > 1\n const hasGraphQLConfig = Boolean(cliConfig?.graphql)\n\n if (workspaces.length === 0) {\n throw new Error('No studio configuration found')\n }\n\n if (numSources === 0) {\n throw new Error('No sources (project ID / dataset) configured')\n }\n\n // We can only automatically configure if there is a single workspace + source in play\n if ((multiWorkspace || multiSource) && !hasGraphQLConfig) {\n throw new Error(oneline`\n Multiple workspaces/sources configured.\n You must define an array of GraphQL APIs in \\`sanity.cli.ts\\` or \\`sanity.cli.js\\`\n and specify which workspace/source to use.\n `)\n }\n\n // No config is defined, but we have a single workspace + source, so use that\n if (!hasGraphQLConfig) {\n const {dataset, projectId, schema} = workspaces[0].unstable_sources[0]\n return [{dataset, projectId, schemaTypes: getStrippedSchemaTypes(schema)}]\n }\n\n // Explicitly defined config\n const apiDefs = validateCliConfig(cliConfig?.graphql || [])\n return resolveGraphQLAPIsFromConfig(apiDefs, workspaces)\n}\n\n/**\n * Resolve GraphQL API metadata (projectId, dataset, tag, etc.) from raw workspace configs\n * without compiling schemas. This is used when we only need API identifiers, not schema types —\n * e.g. for `graphql undeploy --api` or `graphql list`.\n */\nexport function resolveGraphQLApiMetadata({\n cliConfig,\n workspaces,\n}: {\n cliConfig?: {graphql?: GraphQLAPIConfig[]}\n workspaces: WorkspaceMetadata[]\n}): ExtractedGraphQLAPI[] {\n const numSources = workspaces.reduce((count, ws) => count + ws.sources.length, 0)\n const multiSource = numSources > 1\n const multiWorkspace = workspaces.length > 1\n const hasGraphQLConfig = Boolean(cliConfig?.graphql)\n\n if (workspaces.length === 0) {\n throw new Error('No studio configuration found')\n }\n\n if (numSources === 0) {\n throw new Error('No sources (project ID / dataset) configured')\n }\n\n // We can only automatically configure if there is a single workspace + source in play\n if ((multiWorkspace || multiSource) && !hasGraphQLConfig) {\n throw new Error(oneline`\n Multiple workspaces/sources configured.\n You must define an array of GraphQL APIs in \\`sanity.cli.ts\\` or \\`sanity.cli.js\\`\n and specify which workspace/source to use.\n `)\n }\n\n // Validate that workspaces and their sources have non-empty projectId/dataset.\n // The worker's toWorkspaceMetadata validates this before constructing metadata,\n // but assert here to make the invariant explicit.\n for (const ws of workspaces) {\n if (!ws.projectId || !ws.dataset) {\n throw new Error(\n `Workspace \"${ws.name}\" is missing a projectId or dataset. ` +\n 'Check your studio configuration.',\n )\n }\n for (const source of ws.sources) {\n if (!source.projectId || !source.dataset) {\n throw new Error(\n `Source \"${source.name}\" in workspace \"${ws.name}\" is missing a projectId or dataset. ` +\n 'Check your studio configuration.',\n )\n }\n }\n }\n\n // No config is defined, but we have a single workspace + source, so use that\n if (!hasGraphQLConfig) {\n const {dataset, projectId} = workspaces[0].sources[0]\n return [{dataset, projectId}]\n }\n\n // Explicitly defined config\n const apiDefs = validateCliConfig(cliConfig?.graphql || [])\n return resolveGraphQLApiMetadataFromConfig(apiDefs, workspaces)\n}\n\n/**\n * Shared workspace/source resolution logic for both the metadata and full-compile paths.\n *\n * Both `resolveGraphQLAPIsFromConfig` and `resolveGraphQLApiMetadataFromConfig` need to\n * resolve the workspace and source for each GraphQL API config entry. This helper\n * extracts that shared logic so bug fixes and edge-case handling apply to both paths.\n */\nfunction resolveWorkspaceAndSource<\n TWorkspace extends {name: string},\n TSource extends {name: string},\n>(\n apiDef: GraphQLAPIConfig,\n workspaces: TWorkspace[],\n getSources: (workspace: TWorkspace) => TSource[],\n): {source: TSource; workspace: TWorkspace} {\n const {source: sourceName, workspace: workspaceName} = apiDef\n\n if (!workspaceName && workspaces.length > 1) {\n throw new Error(\n 'Must define `workspace` name in GraphQL API config when multiple workspaces are defined',\n )\n }\n\n // If we only have a single workspace defined, we can assume that is the intended one,\n // even if no `workspace` is defined for the GraphQL API\n const workspace =\n !workspaceName && workspaces.length === 1\n ? workspaces[0]\n : workspaces.find((space) => space.name === (workspaceName || 'default'))\n\n if (!workspace) {\n throw new Error(`Workspace \"${workspaceName || 'default'}\" not found`)\n }\n\n const sources = getSources(workspace)\n\n // If we only have a single source defined, we can assume that is the intended one,\n // even if no `source` is defined for the GraphQL API\n const source =\n !sourceName && sources.length === 1\n ? sources[0]\n : sources.find((src) => src.name === (sourceName || 'default'))\n\n if (!source) {\n throw new Error(\n `Source \"${sourceName || 'default'}\" not found in workspace \"${workspaceName || 'default'}\"`,\n )\n }\n\n return {source, workspace}\n}\n\nfunction resolveGraphQLApiMetadataFromConfig(\n apiDefs: GraphQLAPIConfig[],\n workspaces: WorkspaceMetadata[],\n): ExtractedGraphQLAPI[] {\n return apiDefs.map((apiDef) => {\n const {source} = resolveWorkspaceAndSource(apiDef, workspaces, (ws) => ws.sources)\n\n return {\n dataset: source.dataset,\n filterSuffix: apiDef.filterSuffix,\n generation: apiDef.generation,\n id: apiDef.id,\n nonNullDocumentFields: apiDef.nonNullDocumentFields,\n playground: apiDef.playground,\n projectId: source.projectId,\n tag: apiDef.tag,\n }\n })\n}\n\nfunction resolveGraphQLAPIsFromConfig(\n apiDefs: GraphQLAPIConfig[],\n workspaces: Workspace[],\n): TypeResolvedGraphQLAPI[] {\n return apiDefs.map((apiDef) => {\n const {source} = resolveWorkspaceAndSource(apiDef, workspaces, (ws) => ws.unstable_sources)\n\n return {\n ...apiDef,\n dataset: source.dataset,\n projectId: source.projectId,\n schemaTypes: getStrippedSchemaTypes(source.schema),\n }\n })\n}\n\nfunction validateCliConfig(\n config: GraphQLAPIConfig[],\n configPath = 'sanity.cli.js',\n): GraphQLAPIConfig[] {\n if (!Array.isArray(config)) {\n throw new TypeError(`\"graphql\" key in \"${configPath}\" must be an array if defined`)\n }\n\n if (config.length === 0) {\n throw new Error(`No GraphQL APIs defined in \"${configPath}\"`)\n }\n\n return config\n}\n\nfunction getStrippedSchemaTypes(schema: Schema): SchemaDefinitionish[] {\n const schemaDef = schema._original || {types: []}\n return schemaDef.types.map((type) => stripType(type))\n}\n\nfunction stripType(input: unknown): SchemaDefinitionish {\n return strip(input) as SchemaDefinitionish\n}\n\nfunction strip(input: unknown): unknown {\n if (Array.isArray(input)) {\n return input.map((item) => strip(item)).filter((item) => item !== undefined)\n }\n\n if (isPlainishObject(input)) {\n const stripped: Record<string, unknown> = {}\n for (const key of Object.keys(input)) {\n stripped[key] = strip(input[key])\n }\n return stripped\n }\n\n return isBasicType(input) ? input : undefined\n}\n\nfunction isPlainishObject(input: unknown): input is Record<string, unknown> {\n return isPlainObject(input)\n}\n\nfunction isBasicType(input: unknown): boolean {\n const type = typeof input\n if (type === 'boolean' || type === 'number' || type === 'string') {\n return true\n }\n\n if (type !== 'object') {\n return false\n }\n\n return Array.isArray(input) || input === null || isPlainishObject(input)\n}\n"],"names":["isPlainObject","oneline","resolveGraphQLApis","cliConfig","workspaces","numSources","reduce","count","workspace","unstable_sources","length","multiSource","multiWorkspace","hasGraphQLConfig","Boolean","graphql","Error","dataset","projectId","schema","schemaTypes","getStrippedSchemaTypes","apiDefs","validateCliConfig","resolveGraphQLAPIsFromConfig","resolveGraphQLApiMetadata","ws","sources","name","source","resolveGraphQLApiMetadataFromConfig","resolveWorkspaceAndSource","apiDef","getSources","sourceName","workspaceName","find","space","src","map","filterSuffix","generation","id","nonNullDocumentFields","playground","tag","config","configPath","Array","isArray","TypeError","schemaDef","_original","types","type","stripType","input","strip","item","filter","undefined","isPlainishObject","stripped","key","Object","keys","isBasicType"],"mappings":"AACA,OAAOA,mBAAmB,6BAA4B;AACtD,SAAQC,OAAO,QAAO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aAAaA,SAAS,YAAYA,SAAS,UAAU;QAChE,OAAO;IACT;IAEA,IAAIA,SAAS,UAAU;QACrB,OAAO;IACT;IAEA,OAAON,MAAMC,OAAO,CAACO,UAAUA,UAAU,QAAQK,iBAAiBL;AACpE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/init/bootstrapTemplate.ts"],"sourcesContent":["import {Output} from '@sanity/cli-core'\n\nimport {bootstrapLocalTemplate} from './bootstrapLocalTemplate.js'\nimport {bootstrapRemoteTemplate} from './bootstrapRemoteTemplate.js'\nimport {type GenerateConfigOptions} from './createStudioConfig.js'\nimport {type RepoInfo} from './remoteTemplate.js'\n\ninterface BootstrapTemplateOptions {\n autoUpdates: boolean\n bearerToken: string | undefined\n dataset: string\n organizationId: string | undefined\n output: Output\n outputPath: string\n
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/init/bootstrapTemplate.ts"],"sourcesContent":["import {Output} from '@sanity/cli-core'\n\nimport {bootstrapLocalTemplate} from './bootstrapLocalTemplate.js'\nimport {bootstrapRemoteTemplate} from './bootstrapRemoteTemplate.js'\nimport {type GenerateConfigOptions} from './createStudioConfig.js'\nimport {type RepoInfo} from './remoteTemplate.js'\n\ninterface BootstrapTemplateOptions {\n autoUpdates: boolean\n bearerToken: string | undefined\n dataset: string\n organizationId: string | undefined\n output: Output\n outputPath: string\n packageName: string\n projectId: string\n projectName: string\n remoteTemplateInfo: RepoInfo | undefined\n templateName: string\n\n useTypeScript: boolean\n\n overwriteFiles?: boolean\n}\n\nexport async function bootstrapTemplate({\n autoUpdates,\n bearerToken,\n dataset,\n organizationId,\n output,\n outputPath,\n overwriteFiles,\n packageName,\n projectId,\n projectName,\n remoteTemplateInfo,\n templateName,\n useTypeScript,\n}: BootstrapTemplateOptions) {\n const bootstrapVariables: GenerateConfigOptions['variables'] = {\n autoUpdates,\n dataset,\n organizationId,\n projectId,\n projectName,\n }\n\n if (remoteTemplateInfo) {\n return bootstrapRemoteTemplate({\n bearerToken,\n output,\n outputPath,\n packageName,\n repoInfo: remoteTemplateInfo,\n variables: bootstrapVariables,\n })\n }\n\n return bootstrapLocalTemplate({\n output,\n outputPath,\n overwriteFiles,\n packageName,\n templateName,\n useTypeScript,\n variables: bootstrapVariables,\n })\n}\n"],"names":["bootstrapLocalTemplate","bootstrapRemoteTemplate","bootstrapTemplate","autoUpdates","bearerToken","dataset","organizationId","output","outputPath","overwriteFiles","packageName","projectId","projectName","remoteTemplateInfo","templateName","useTypeScript","bootstrapVariables","repoInfo","variables"],"mappings":"AAEA,SAAQA,sBAAsB,QAAO,8BAA6B;AAClE,SAAQC,uBAAuB,QAAO,+BAA8B;AAsBpE,OAAO,eAAeC,kBAAkB,EACtCC,WAAW,EACXC,WAAW,EACXC,OAAO,EACPC,cAAc,EACdC,MAAM,EACNC,UAAU,EACVC,cAAc,EACdC,WAAW,EACXC,SAAS,EACTC,WAAW,EACXC,kBAAkB,EAClBC,YAAY,EACZC,aAAa,EACY;IACzB,MAAMC,qBAAyD;QAC7Db;QACAE;QACAC;QACAK;QACAC;IACF;IAEA,IAAIC,oBAAoB;QACtB,OAAOZ,wBAAwB;YAC7BG;YACAG;YACAC;YACAE;YACAO,UAAUJ;YACVK,WAAWF;QACb;IACF;IAEA,OAAOhB,uBAAuB;QAC5BO;QACAC;QACAC;QACAC;QACAI;QACAC;QACAG,WAAWF;IACb;AACF"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { readPackageJson } from '@sanity/cli-core';
|
|
2
|
-
import
|
|
2
|
+
import { coerce } from 'semver';
|
|
3
3
|
export async function checkNextJsReactCompatibility({ detectedFramework, output, outputPath }) {
|
|
4
4
|
const packageJson = await readPackageJson(`${outputPath}/package.json`);
|
|
5
5
|
const reactVersion = packageJson?.dependencies?.react;
|
|
6
6
|
if (reactVersion) {
|
|
7
|
-
const isUsingReact19 =
|
|
8
|
-
const isUsingNextJs15 =
|
|
7
|
+
const isUsingReact19 = coerce(reactVersion)?.major === 19;
|
|
8
|
+
const isUsingNextJs15 = coerce(detectedFramework?.detectedVersion)?.major === 15;
|
|
9
9
|
if (isUsingNextJs15 && isUsingReact19) {
|
|
10
10
|
output.warn('╭────────────────────────────────────────────────────────────╮');
|
|
11
11
|
output.warn('│ │');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/init/checkNextJsReactCompatibility.ts"],"sourcesContent":["import {Output, readPackageJson} from '@sanity/cli-core'\nimport
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/init/checkNextJsReactCompatibility.ts"],"sourcesContent":["import {Output, readPackageJson} from '@sanity/cli-core'\nimport {coerce} from 'semver'\n\nimport {VersionedFramework} from './types.js'\n\ninterface CheckCompatibilityOptions {\n detectedFramework: VersionedFramework\n output: Output\n outputPath: string\n}\n\nexport async function checkNextJsReactCompatibility({\n detectedFramework,\n output,\n outputPath,\n}: CheckCompatibilityOptions) {\n const packageJson = await readPackageJson(`${outputPath}/package.json`)\n const reactVersion = packageJson?.dependencies?.react\n\n if (reactVersion) {\n const isUsingReact19 = coerce(reactVersion)?.major === 19\n const isUsingNextJs15 = coerce(detectedFramework?.detectedVersion)?.major === 15\n\n if (isUsingNextJs15 && isUsingReact19) {\n output.warn('╭────────────────────────────────────────────────────────────╮')\n output.warn('│ │')\n output.warn('│ It looks like you are using Next.js 15 and React 19 │')\n output.warn('│ Please read our compatibility guide. │')\n output.warn('│ https://www.sanity.io/help/react-19 │')\n output.warn('│ │')\n output.warn('╰────────────────────────────────────────────────────────────╯')\n }\n }\n}\n"],"names":["readPackageJson","coerce","checkNextJsReactCompatibility","detectedFramework","output","outputPath","packageJson","reactVersion","dependencies","react","isUsingReact19","major","isUsingNextJs15","detectedVersion","warn"],"mappings":"AAAA,SAAgBA,eAAe,QAAO,mBAAkB;AACxD,SAAQC,MAAM,QAAO,SAAQ;AAU7B,OAAO,eAAeC,8BAA8B,EAClDC,iBAAiB,EACjBC,MAAM,EACNC,UAAU,EACgB;IAC1B,MAAMC,cAAc,MAAMN,gBAAgB,GAAGK,WAAW,aAAa,CAAC;IACtE,MAAME,eAAeD,aAAaE,cAAcC;IAEhD,IAAIF,cAAc;QAChB,MAAMG,iBAAiBT,OAAOM,eAAeI,UAAU;QACvD,MAAMC,kBAAkBX,OAAOE,mBAAmBU,kBAAkBF,UAAU;QAE9E,IAAIC,mBAAmBF,gBAAgB;YACrCN,OAAOU,IAAI,CAAC;YACZV,OAAOU,IAAI,CAAC;YACZV,OAAOU,IAAI,CAAC;YACZV,OAAOU,IAAI,CAAC;YACZV,OAAOU,IAAI,CAAC;YACZV,OAAOU,IAAI,CAAC;YACZV,OAAOU,IAAI,CAAC;QACd;IACF;AACF"}
|