sanity
Version:
Sanity is a real-time content infrastructure with a scalable, hosted backend featuring a Graph Oriented Query Language (GROQ), asset pipelines and fast edge caches
1 lines • 4.33 kB
Source Map (JSON)
{"version":3,"file":"getStudioWorkspaces.cjs","sources":["../../src/_internal/cli/util/getStudioWorkspaces.ts"],"sourcesContent":["import fs from 'node:fs'\nimport {createRequire} from 'node:module'\nimport path from 'node:path'\n\nimport {firstValueFrom} from 'rxjs'\nimport {type Config, resolveConfig, type Workspace, type WorkspaceOptions} from 'sanity'\n\nimport {mockBrowserEnvironment} from './mockBrowserEnvironment'\n\nconst require = createRequire(import.meta.url)\n\nconst candidates = [\n 'sanity.config.js',\n 'sanity.config.jsx',\n 'sanity.config.ts',\n 'sanity.config.tsx',\n]\n\ninterface GetStudioWorkspacesOptions {\n configPath?: string\n basePath: string\n}\n\n/**\n * Note: Don't run this on the main thread, use it a forked process\n */\nexport function getStudioConfig({\n basePath,\n configPath: cfgPath,\n}: GetStudioWorkspacesOptions): WorkspaceOptions[] {\n let cleanup\n try {\n cleanup = mockBrowserEnvironment(basePath)\n\n let configPath = cfgPath\n if (configPath && !fs.existsSync(configPath)) {\n throw new Error(`Failed to find config at \"${cfgPath}\"`)\n } else if (!configPath) {\n configPath = candidates\n .map((candidate) => path.join(basePath, candidate))\n .find((candidate) => fs.existsSync(candidate))\n }\n\n if (!configPath) {\n throw new Error(`Failed to resolve sanity.config.(js|ts) for base path \"${basePath}\"`)\n }\n\n let config: Config | undefined\n try {\n // eslint-disable-next-line import/no-dynamic-require\n const mod = require(configPath)\n config = mod.__esModule && mod.default ? mod.default : mod\n } catch (err) {\n throw new Error(`Failed to load configuration file \"${configPath}\"`, {\n cause: err,\n })\n }\n\n if (!config) throw new Error('Configuration did not export expected config shape')\n const normalized = Array.isArray(config)\n ? config\n : [{...config, name: config.name || 'default', basePath: config.basePath || '/'}]\n\n return normalized\n } finally {\n cleanup?.()\n }\n}\n\n/**\n * Note: Don't run this on the main thread, use it a forked process\n */\nexport async function getStudioWorkspaces(\n options: GetStudioWorkspacesOptions,\n): Promise<Workspace[]> {\n let cleanup\n\n try {\n cleanup = mockBrowserEnvironment(options.basePath)\n const config = getStudioConfig(options)\n const workspaces = await firstValueFrom(resolveConfig(config))\n if (!workspaces) throw new Error('Failed to resolve configuration')\n return workspaces\n } finally {\n cleanup?.()\n }\n}\n"],"names":["require","createRequire","import","candidates","getStudioConfig","basePath","configPath","cfgPath","cleanup","mockBrowserEnvironment","fs","existsSync","Error","map","candidate","path","join","find","config","mod","__esModule","default","err","cause","Array","isArray","name","getStudioWorkspaces","options","workspaces","firstValueFrom","resolveConfig"],"mappings":";;;;;;AASA,MAAMA,YAAUC,OAAAA,cAAcC,OAAAA,WAAAA,MAAAA,QAAAA,KAAAA,EAAAA,cAAAA,UAAAA,EAAAA,OAAAA,0BAAAA,uBAAAA,QAAAA,YAAAA,MAAAA,YAAAA,uBAAAA,OAAAA,IAAAA,IAAAA,uCAAAA,SAAAA,OAAAA,EAAAA,IAAe,GAEvCC,aAAa,CACjB,oBACA,qBACA,oBACA,mBAAmB;AAWd,SAASC,gBAAgB;AAAA,EAC9BC;AAAAA,EACAC,YAAYC;AACc,GAAuB;AACjD,MAAIC;AACJ,MAAI;AACFA,cAAUC,uBAAAA,uBAAuBJ,QAAQ;AAEzC,QAAIC,aAAaC;AACjB,QAAID,cAAc,CAACI,oBAAGC,WAAWL,UAAU;AACzC,YAAM,IAAIM,MAAM,6BAA6BL,OAAO,GAAG;AAOzD,QANYD,eACVA,aAAaH,WACVU,IAAKC,CAAAA,cAAcC,cAAAA,QAAKC,KAAKX,UAAUS,SAAS,CAAC,EACjDG,KAAMH,CAAAA,cAAcJ,YAAAA,QAAGC,WAAWG,SAAS,CAAC,IAG7C,CAACR;AACH,YAAM,IAAIM,MAAM,0DAA0DP,QAAQ,GAAG;AAGvF,QAAIa;AACJ,QAAI;AAEF,YAAMC,MAAMnB,UAAQM,UAAU;AAC9BY,eAASC,IAAIC,cAAcD,IAAIE,UAAUF,IAA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