@sanity/cli-core 3.15.1 → 3.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_exports/images.d.ts +13 -0
- package/dist/_exports/images.js +3 -0
- package/dist/_exports/images.js.map +1 -0
- package/dist/config/studio/getStudioWorkspaces.js +2 -2
- package/dist/config/studio/getStudioWorkspaces.js.map +1 -1
- package/dist/util/doImport.js +2 -2
- package/dist/util/doImport.js.map +1 -1
- package/dist/util/environment/setupBrowserStubs.js +1 -1
- package/dist/util/environment/setupBrowserStubs.js.map +1 -1
- package/dist/util/readImageFile.js +50 -0
- package/dist/util/readImageFile.js.map +1 -0
- package/package.json +13 -10
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** @public */
|
|
2
|
+
interface ImageFile {
|
|
3
|
+
contentType: string;
|
|
4
|
+
image: Buffer;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Read an image file to upload, such as an organization's logo. Throws an error a user can act on
|
|
8
|
+
* when the file is missing, isn't a supported image type, or is over 5 MB.
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
declare function readImageFile(filePath: string): Promise<ImageFile>;
|
|
12
|
+
export { type ImageFile, readImageFile };
|
|
13
|
+
//# sourceMappingURL=images.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/_exports/images.ts"],"sourcesContent":["export {type ImageFile, readImageFile} from '../util/readImageFile.js'\n"],"names":["readImageFile"],"mappings":"AAAA,SAAwBA,aAAa,QAAO,2BAA0B"}
|
|
@@ -50,9 +50,9 @@ const debug = subdebug('worker:getStudioWorkspaces');
|
|
|
50
50
|
// Imported lazily: rxjs and `@sanity/client` are only needed here, but this
|
|
51
51
|
// module is reachable from the `@sanity/cli-core` barrel that every command loads.
|
|
52
52
|
const [{ firstValueFrom, of }, { getEmptyAuth }] = await Promise.all([
|
|
53
|
-
// eslint-disable-next-line no-restricted-syntax -- package import, not a file path
|
|
53
|
+
// eslint-disable-next-line eslint-js/no-restricted-syntax -- package import, not a file path
|
|
54
54
|
import('rxjs'),
|
|
55
|
-
// eslint-disable-next-line no-restricted-syntax -- static relative import, not a user file path
|
|
55
|
+
// eslint-disable-next-line eslint-js/no-restricted-syntax -- static relative import, not a user file path
|
|
56
56
|
import('../../util/getEmptyAuth.js')
|
|
57
57
|
]);
|
|
58
58
|
const emptyAuth = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/config/studio/getStudioWorkspaces.ts"],"sourcesContent":["import {stat} from 'node:fs/promises'\nimport {dirname} from 'node:path'\nimport {isMainThread} from 'node:worker_threads'\n\nimport {type Workspace} from 'sanity'\n\nimport {subdebug} from '../../_exports/debug.js'\nimport {doImport} from '../../util/doImport.js'\nimport {resolveLocalPackage} from '../../util/resolveLocalPackage.js'\nimport {findStudioConfigPath} from '../util/findStudioConfigPath.js'\nimport {isStudioConfig} from './isStudioConfig.js'\n\nconst debug = subdebug('worker:getStudioWorkspaces')\n\n/**\n * Resolves the workspaces from the studio config.\n *\n * NOTE: This function should only be called from a worker thread.\n *\n * @param configPath - The path to the studio config\n * @returns The workspaces\n * @internal\n */\nexport async function getStudioWorkspaces(configPath: string): Promise<Workspace[]> {\n if (isMainThread) {\n throw new Error('getStudioWorkspaces should only be called from a worker thread')\n }\n const isDirectory = (await stat(configPath)).isDirectory()\n if (isDirectory) {\n configPath = await findStudioConfigPath(configPath)\n }\n debug('Finding studio config path %s', configPath)\n const mod = await doImport(configPath)\n // Named exports like `projectId` can make the module itself look like a config\n const config = 'default' in mod && isStudioConfig(mod.default) ? mod.default : mod\n\n debug('Imported config %o', config)\n if (!isStudioConfig(config)) {\n debug('Invalid studio config format in \"%s\"', configPath)\n throw new TypeError(`Invalid studio config format in \"${configPath}\"`)\n }\n\n const workDir = dirname(configPath)\n debug('Work dir %s', workDir)\n const {resolveConfig} = await resolveLocalPackage<typeof import('sanity')>('sanity', workDir)\n if (typeof resolveConfig !== 'function') {\n throw new TypeError('Expected `resolveConfig` from `sanity` to be a function')\n }\n\n // We will also want to stub out some configuration - we don't need to resolve the\n // users' logged in state, for instance - so let's disable the auth implementation.\n const rawWorkspaces = Array.isArray(config)\n ? config\n : [{...config, basePath: config.basePath || '/', name: config.name || 'default'}]\n\n // Imported lazily: rxjs and `@sanity/client` are only needed here, but this\n // module is reachable from the `@sanity/cli-core` barrel that every command loads.\n const [{firstValueFrom, of}, {getEmptyAuth}] = await Promise.all([\n // eslint-disable-next-line no-restricted-syntax -- package import, not a file path\n import('rxjs'),\n // eslint-disable-next-line no-restricted-syntax -- static relative import, not a user file path\n import('../../util/getEmptyAuth.js'),\n ])\n const emptyAuth = {state: of(getEmptyAuth())}\n\n const unauthedWorkspaces = rawWorkspaces.map((workspace) => ({\n ...workspace,\n auth: emptyAuth,\n }))\n\n debug('Unauthed workspaces %o', unauthedWorkspaces)\n\n return firstValueFrom(resolveConfig(unauthedWorkspaces))\n}\n"],"names":["stat","dirname","isMainThread","subdebug","doImport","resolveLocalPackage","findStudioConfigPath","isStudioConfig","debug","getStudioWorkspaces","configPath","Error","isDirectory","mod","config","default","TypeError","workDir","resolveConfig","rawWorkspaces","Array","isArray","basePath","name","firstValueFrom","of","getEmptyAuth","Promise","all","emptyAuth","state","unauthedWorkspaces","map","workspace","auth"],"mappings":"AAAA,SAAQA,IAAI,QAAO,mBAAkB;AACrC,SAAQC,OAAO,QAAO,YAAW;AACjC,SAAQC,YAAY,QAAO,sBAAqB;AAIhD,SAAQC,QAAQ,QAAO,0BAAyB;AAChD,SAAQC,QAAQ,QAAO,yBAAwB;AAC/C,SAAQC,mBAAmB,QAAO,oCAAmC;AACrE,SAAQC,oBAAoB,QAAO,kCAAiC;AACpE,SAAQC,cAAc,QAAO,sBAAqB;AAElD,MAAMC,QAAQL,SAAS;AAEvB;;;;;;;;CAQC,GACD,OAAO,eAAeM,oBAAoBC,UAAkB;IAC1D,IAAIR,cAAc;QAChB,MAAM,IAAIS,MAAM;IAClB;IACA,MAAMC,cAAc,AAAC,CAAA,MAAMZ,KAAKU,WAAU,EAAGE,WAAW;IACxD,IAAIA,aAAa;QACfF,aAAa,MAAMJ,qBAAqBI;IAC1C;IACAF,MAAM,iCAAiCE;IACvC,MAAMG,MAAM,MAAMT,SAASM;IAC3B,+EAA+E;IAC/E,MAAMI,SAAS,aAAaD,OAAON,eAAeM,IAAIE,OAAO,IAAIF,IAAIE,OAAO,GAAGF;IAE/EL,MAAM,sBAAsBM;IAC5B,IAAI,CAACP,eAAeO,SAAS;QAC3BN,MAAM,wCAAwCE;QAC9C,MAAM,IAAIM,UAAU,CAAC,iCAAiC,EAAEN,WAAW,CAAC,CAAC;IACvE;IAEA,MAAMO,UAAUhB,QAAQS;IACxBF,MAAM,eAAeS;IACrB,MAAM,EAACC,aAAa,EAAC,GAAG,MAAMb,oBAA6C,UAAUY;IACrF,IAAI,OAAOC,kBAAkB,YAAY;QACvC,MAAM,IAAIF,UAAU;IACtB;IAEA,kFAAkF;IAClF,mFAAmF;IACnF,MAAMG,gBAAgBC,MAAMC,OAAO,CAACP,UAChCA,SACA;QAAC;YAAC,GAAGA,MAAM;YAAEQ,UAAUR,OAAOQ,QAAQ,IAAI;YAAKC,MAAMT,OAAOS,IAAI,IAAI;QAAS;KAAE;IAEnF,4EAA4E;IAC5E,mFAAmF;IACnF,MAAM,CAAC,EAACC,cAAc,EAAEC,EAAE,EAAC,EAAE,EAACC,YAAY,EAAC,CAAC,GAAG,MAAMC,QAAQC,GAAG,CAAC;QAC/D,
|
|
1
|
+
{"version":3,"sources":["../../../src/config/studio/getStudioWorkspaces.ts"],"sourcesContent":["import {stat} from 'node:fs/promises'\nimport {dirname} from 'node:path'\nimport {isMainThread} from 'node:worker_threads'\n\nimport {type Workspace} from 'sanity'\n\nimport {subdebug} from '../../_exports/debug.js'\nimport {doImport} from '../../util/doImport.js'\nimport {resolveLocalPackage} from '../../util/resolveLocalPackage.js'\nimport {findStudioConfigPath} from '../util/findStudioConfigPath.js'\nimport {isStudioConfig} from './isStudioConfig.js'\n\nconst debug = subdebug('worker:getStudioWorkspaces')\n\n/**\n * Resolves the workspaces from the studio config.\n *\n * NOTE: This function should only be called from a worker thread.\n *\n * @param configPath - The path to the studio config\n * @returns The workspaces\n * @internal\n */\nexport async function getStudioWorkspaces(configPath: string): Promise<Workspace[]> {\n if (isMainThread) {\n throw new Error('getStudioWorkspaces should only be called from a worker thread')\n }\n const isDirectory = (await stat(configPath)).isDirectory()\n if (isDirectory) {\n configPath = await findStudioConfigPath(configPath)\n }\n debug('Finding studio config path %s', configPath)\n const mod = await doImport(configPath)\n // Named exports like `projectId` can make the module itself look like a config\n const config = 'default' in mod && isStudioConfig(mod.default) ? mod.default : mod\n\n debug('Imported config %o', config)\n if (!isStudioConfig(config)) {\n debug('Invalid studio config format in \"%s\"', configPath)\n throw new TypeError(`Invalid studio config format in \"${configPath}\"`)\n }\n\n const workDir = dirname(configPath)\n debug('Work dir %s', workDir)\n const {resolveConfig} = await resolveLocalPackage<typeof import('sanity')>('sanity', workDir)\n if (typeof resolveConfig !== 'function') {\n throw new TypeError('Expected `resolveConfig` from `sanity` to be a function')\n }\n\n // We will also want to stub out some configuration - we don't need to resolve the\n // users' logged in state, for instance - so let's disable the auth implementation.\n const rawWorkspaces = Array.isArray(config)\n ? config\n : [{...config, basePath: config.basePath || '/', name: config.name || 'default'}]\n\n // Imported lazily: rxjs and `@sanity/client` are only needed here, but this\n // module is reachable from the `@sanity/cli-core` barrel that every command loads.\n const [{firstValueFrom, of}, {getEmptyAuth}] = await Promise.all([\n // eslint-disable-next-line eslint-js/no-restricted-syntax -- package import, not a file path\n import('rxjs'),\n // eslint-disable-next-line eslint-js/no-restricted-syntax -- static relative import, not a user file path\n import('../../util/getEmptyAuth.js'),\n ])\n const emptyAuth = {state: of(getEmptyAuth())}\n\n const unauthedWorkspaces = rawWorkspaces.map((workspace) => ({\n ...workspace,\n auth: emptyAuth,\n }))\n\n debug('Unauthed workspaces %o', unauthedWorkspaces)\n\n return firstValueFrom(resolveConfig(unauthedWorkspaces))\n}\n"],"names":["stat","dirname","isMainThread","subdebug","doImport","resolveLocalPackage","findStudioConfigPath","isStudioConfig","debug","getStudioWorkspaces","configPath","Error","isDirectory","mod","config","default","TypeError","workDir","resolveConfig","rawWorkspaces","Array","isArray","basePath","name","firstValueFrom","of","getEmptyAuth","Promise","all","emptyAuth","state","unauthedWorkspaces","map","workspace","auth"],"mappings":"AAAA,SAAQA,IAAI,QAAO,mBAAkB;AACrC,SAAQC,OAAO,QAAO,YAAW;AACjC,SAAQC,YAAY,QAAO,sBAAqB;AAIhD,SAAQC,QAAQ,QAAO,0BAAyB;AAChD,SAAQC,QAAQ,QAAO,yBAAwB;AAC/C,SAAQC,mBAAmB,QAAO,oCAAmC;AACrE,SAAQC,oBAAoB,QAAO,kCAAiC;AACpE,SAAQC,cAAc,QAAO,sBAAqB;AAElD,MAAMC,QAAQL,SAAS;AAEvB;;;;;;;;CAQC,GACD,OAAO,eAAeM,oBAAoBC,UAAkB;IAC1D,IAAIR,cAAc;QAChB,MAAM,IAAIS,MAAM;IAClB;IACA,MAAMC,cAAc,AAAC,CAAA,MAAMZ,KAAKU,WAAU,EAAGE,WAAW;IACxD,IAAIA,aAAa;QACfF,aAAa,MAAMJ,qBAAqBI;IAC1C;IACAF,MAAM,iCAAiCE;IACvC,MAAMG,MAAM,MAAMT,SAASM;IAC3B,+EAA+E;IAC/E,MAAMI,SAAS,aAAaD,OAAON,eAAeM,IAAIE,OAAO,IAAIF,IAAIE,OAAO,GAAGF;IAE/EL,MAAM,sBAAsBM;IAC5B,IAAI,CAACP,eAAeO,SAAS;QAC3BN,MAAM,wCAAwCE;QAC9C,MAAM,IAAIM,UAAU,CAAC,iCAAiC,EAAEN,WAAW,CAAC,CAAC;IACvE;IAEA,MAAMO,UAAUhB,QAAQS;IACxBF,MAAM,eAAeS;IACrB,MAAM,EAACC,aAAa,EAAC,GAAG,MAAMb,oBAA6C,UAAUY;IACrF,IAAI,OAAOC,kBAAkB,YAAY;QACvC,MAAM,IAAIF,UAAU;IACtB;IAEA,kFAAkF;IAClF,mFAAmF;IACnF,MAAMG,gBAAgBC,MAAMC,OAAO,CAACP,UAChCA,SACA;QAAC;YAAC,GAAGA,MAAM;YAAEQ,UAAUR,OAAOQ,QAAQ,IAAI;YAAKC,MAAMT,OAAOS,IAAI,IAAI;QAAS;KAAE;IAEnF,4EAA4E;IAC5E,mFAAmF;IACnF,MAAM,CAAC,EAACC,cAAc,EAAEC,EAAE,EAAC,EAAE,EAACC,YAAY,EAAC,CAAC,GAAG,MAAMC,QAAQC,GAAG,CAAC;QAC/D,6FAA6F;QAC7F,MAAM,CAAC;QACP,0GAA0G;QAC1G,MAAM,CAAC;KACR;IACD,MAAMC,YAAY;QAACC,OAAOL,GAAGC;IAAe;IAE5C,MAAMK,qBAAqBZ,cAAca,GAAG,CAAC,CAACC,YAAe,CAAA;YAC3D,GAAGA,SAAS;YACZC,MAAML;QACR,CAAA;IAEArB,MAAM,0BAA0BuB;IAEhC,OAAOP,eAAeN,cAAca;AACtC"}
|
package/dist/util/doImport.js
CHANGED
|
@@ -9,8 +9,8 @@ import { pathToFileURL } from 'node:url';
|
|
|
9
9
|
// Absolute paths in windows are not valid URLs and are not supported by import().
|
|
10
10
|
// We need to convert the path to a file URL.
|
|
11
11
|
// See: https://github.com/nodejs/node/issues/31710
|
|
12
|
-
const url =
|
|
13
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
12
|
+
const url = source.startsWith('file://') ? source : pathToFileURL(source).href;
|
|
13
|
+
// eslint-disable-next-line eslint-js/no-restricted-syntax
|
|
14
14
|
return import(/* @vite-ignore */ url);
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/util/doImport.ts"],"sourcesContent":["// Only file that should be using dynamic import\nimport {pathToFileURL} from 'node:url'\n\n/**\n * This function is a replacement for built in dynamic import\n * This handles the case for windows file paths especially for absolute paths.\n *\n * @param source - File path\n */\nexport function doImport(source: string) {\n // Absolute paths in windows are not valid URLs and are not supported by import().\n // We need to convert the path to a file URL.\n // See: https://github.com/nodejs/node/issues/31710\n const url =
|
|
1
|
+
{"version":3,"sources":["../../src/util/doImport.ts"],"sourcesContent":["// Only file that should be using dynamic import\nimport {pathToFileURL} from 'node:url'\n\n/**\n * This function is a replacement for built in dynamic import\n * This handles the case for windows file paths especially for absolute paths.\n *\n * @param source - File path\n */\nexport function doImport(source: string) {\n // Absolute paths in windows are not valid URLs and are not supported by import().\n // We need to convert the path to a file URL.\n // See: https://github.com/nodejs/node/issues/31710\n const url = source.startsWith('file://') ? source : pathToFileURL(source).href\n // eslint-disable-next-line eslint-js/no-restricted-syntax\n return import(\n /* @vite-ignore */\n url\n )\n}\n"],"names":["pathToFileURL","doImport","source","url","startsWith","href"],"mappings":"AAAA,gDAAgD;AAChD,SAAQA,aAAa,QAAO,WAAU;AAEtC;;;;;CAKC,GACD,OAAO,SAASC,SAASC,MAAc;IACrC,kFAAkF;IAClF,6CAA6C;IAC7C,mDAAmD;IACnD,MAAMC,MAAMD,OAAOE,UAAU,CAAC,aAAaF,SAASF,cAAcE,QAAQG,IAAI;IAC9E,0DAA0D;IAC1D,OAAO,MAAM,CACX,gBAAgB,GAChBF;AAEJ"}
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
// even if Node provides them, so realm identity stays consistent.
|
|
19
19
|
// Imported lazily: `stubs.js` pulls in JSDOM (~600 modules), and this module
|
|
20
20
|
// is reachable from the `@sanity/cli-core` barrel that every command loads.
|
|
21
|
-
// eslint-disable-next-line no-restricted-syntax -- static relative import, not a user file path
|
|
21
|
+
// eslint-disable-next-line eslint-js/no-restricted-syntax -- static relative import, not a user file path
|
|
22
22
|
const { getBrowserStubs } = await import('./stubs.js');
|
|
23
23
|
const stubs = getBrowserStubs();
|
|
24
24
|
const mockedGlobalThis = globalThis;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/util/environment/setupBrowserStubs.ts"],"sourcesContent":["/**\n * Sets up browser globals (window, document, etc.) in the global scope.\n *\n * This is used by both mockBrowserEnvironment (for child processes) and\n * studioWorkerLoader (for worker threads) to provide a browser-like environment.\n *\n * @returns A cleanup function that removes the injected globals\n * @internal\n */\nexport async function setupBrowserStubs(): Promise<() => void> {\n // Guard against double-registering\n if (globalThis.window && '__mockedBySanity' in globalThis.window) {\n return () => {\n /* intentional noop - already mocked */\n }\n }\n\n // Inject browser stubs into global scope. `getBrowserStubs()` has already\n // decided what to inject — including a small set of keys (e.g.\n // `localStorage`/`sessionStorage`/`Storage`) that we want to take from JSDOM\n // even if Node provides them, so realm identity stays consistent.\n // Imported lazily: `stubs.js` pulls in JSDOM (~600 modules), and this module\n // is reachable from the `@sanity/cli-core` barrel that every command loads.\n // eslint-disable-next-line no-restricted-syntax -- static relative import, not a user file path\n const {getBrowserStubs} = await import('./stubs.js')\n const stubs = getBrowserStubs()\n const mockedGlobalThis: Record<string, unknown> = globalThis\n const stubbedKeys: string[] = []\n const originalDescriptors = new Map<string, PropertyDescriptor>()\n\n for (const key of Object.keys(stubs)) {\n // Snapshot via descriptor to avoid triggering getters (e.g. Node 26's\n // `localStorage` getter logs an ExperimentalWarning on read).\n const descriptor = Object.getOwnPropertyDescriptor(globalThis, key)\n if (descriptor) {\n originalDescriptors.set(key, descriptor)\n // Assignment would throw for getter-only accessors (e.g. Node 26's\n // `localStorage`/`sessionStorage`), so replace the property outright.\n Object.defineProperty(globalThis, key, {\n configurable: true,\n enumerable: descriptor.enumerable,\n value: stubs[key],\n writable: true,\n })\n } else {\n mockedGlobalThis[key] = stubs[key]\n }\n stubbedKeys.push(key)\n }\n\n // Add marker to window to detect double-mocking\n if (globalThis.window) {\n ;(globalThis.window as unknown as Record<string, unknown>).__mockedBySanity = true\n }\n\n // Return cleanup function\n return () => {\n // Remove marker before deleting window\n if (globalThis.window) {\n delete (globalThis.window as unknown as Record<string, unknown>).__mockedBySanity\n }\n\n for (const key of stubbedKeys) {\n const descriptor = originalDescriptors.get(key)\n if (descriptor) {\n Object.defineProperty(globalThis, key, descriptor)\n } else {\n delete mockedGlobalThis[key]\n }\n }\n }\n}\n"],"names":["setupBrowserStubs","globalThis","window","getBrowserStubs","stubs","mockedGlobalThis","stubbedKeys","originalDescriptors","Map","key","Object","keys","descriptor","getOwnPropertyDescriptor","set","defineProperty","configurable","enumerable","value","writable","push","__mockedBySanity","get"],"mappings":"AAAA;;;;;;;;CAQC,GACD,OAAO,eAAeA;IACpB,mCAAmC;IACnC,IAAIC,WAAWC,MAAM,IAAI,sBAAsBD,WAAWC,MAAM,EAAE;QAChE,OAAO;QACL,qCAAqC,GACvC;IACF;IAEA,0EAA0E;IAC1E,+DAA+D;IAC/D,6EAA6E;IAC7E,kEAAkE;IAClE,6EAA6E;IAC7E,4EAA4E;IAC5E,
|
|
1
|
+
{"version":3,"sources":["../../../src/util/environment/setupBrowserStubs.ts"],"sourcesContent":["/**\n * Sets up browser globals (window, document, etc.) in the global scope.\n *\n * This is used by both mockBrowserEnvironment (for child processes) and\n * studioWorkerLoader (for worker threads) to provide a browser-like environment.\n *\n * @returns A cleanup function that removes the injected globals\n * @internal\n */\nexport async function setupBrowserStubs(): Promise<() => void> {\n // Guard against double-registering\n if (globalThis.window && '__mockedBySanity' in globalThis.window) {\n return () => {\n /* intentional noop - already mocked */\n }\n }\n\n // Inject browser stubs into global scope. `getBrowserStubs()` has already\n // decided what to inject — including a small set of keys (e.g.\n // `localStorage`/`sessionStorage`/`Storage`) that we want to take from JSDOM\n // even if Node provides them, so realm identity stays consistent.\n // Imported lazily: `stubs.js` pulls in JSDOM (~600 modules), and this module\n // is reachable from the `@sanity/cli-core` barrel that every command loads.\n // eslint-disable-next-line eslint-js/no-restricted-syntax -- static relative import, not a user file path\n const {getBrowserStubs} = await import('./stubs.js')\n const stubs = getBrowserStubs()\n const mockedGlobalThis: Record<string, unknown> = globalThis\n const stubbedKeys: string[] = []\n const originalDescriptors = new Map<string, PropertyDescriptor>()\n\n for (const key of Object.keys(stubs)) {\n // Snapshot via descriptor to avoid triggering getters (e.g. Node 26's\n // `localStorage` getter logs an ExperimentalWarning on read).\n const descriptor = Object.getOwnPropertyDescriptor(globalThis, key)\n if (descriptor) {\n originalDescriptors.set(key, descriptor)\n // Assignment would throw for getter-only accessors (e.g. Node 26's\n // `localStorage`/`sessionStorage`), so replace the property outright.\n Object.defineProperty(globalThis, key, {\n configurable: true,\n enumerable: descriptor.enumerable,\n value: stubs[key],\n writable: true,\n })\n } else {\n mockedGlobalThis[key] = stubs[key]\n }\n stubbedKeys.push(key)\n }\n\n // Add marker to window to detect double-mocking\n if (globalThis.window) {\n ;(globalThis.window as unknown as Record<string, unknown>).__mockedBySanity = true\n }\n\n // Return cleanup function\n return () => {\n // Remove marker before deleting window\n if (globalThis.window) {\n delete (globalThis.window as unknown as Record<string, unknown>).__mockedBySanity\n }\n\n for (const key of stubbedKeys) {\n const descriptor = originalDescriptors.get(key)\n if (descriptor) {\n Object.defineProperty(globalThis, key, descriptor)\n } else {\n delete mockedGlobalThis[key]\n }\n }\n }\n}\n"],"names":["setupBrowserStubs","globalThis","window","getBrowserStubs","stubs","mockedGlobalThis","stubbedKeys","originalDescriptors","Map","key","Object","keys","descriptor","getOwnPropertyDescriptor","set","defineProperty","configurable","enumerable","value","writable","push","__mockedBySanity","get"],"mappings":"AAAA;;;;;;;;CAQC,GACD,OAAO,eAAeA;IACpB,mCAAmC;IACnC,IAAIC,WAAWC,MAAM,IAAI,sBAAsBD,WAAWC,MAAM,EAAE;QAChE,OAAO;QACL,qCAAqC,GACvC;IACF;IAEA,0EAA0E;IAC1E,+DAA+D;IAC/D,6EAA6E;IAC7E,kEAAkE;IAClE,6EAA6E;IAC7E,4EAA4E;IAC5E,0GAA0G;IAC1G,MAAM,EAACC,eAAe,EAAC,GAAG,MAAM,MAAM,CAAC;IACvC,MAAMC,QAAQD;IACd,MAAME,mBAA4CJ;IAClD,MAAMK,cAAwB,EAAE;IAChC,MAAMC,sBAAsB,IAAIC;IAEhC,KAAK,MAAMC,OAAOC,OAAOC,IAAI,CAACP,OAAQ;QACpC,sEAAsE;QACtE,8DAA8D;QAC9D,MAAMQ,aAAaF,OAAOG,wBAAwB,CAACZ,YAAYQ;QAC/D,IAAIG,YAAY;YACdL,oBAAoBO,GAAG,CAACL,KAAKG;YAC7B,mEAAmE;YACnE,sEAAsE;YACtEF,OAAOK,cAAc,CAACd,YAAYQ,KAAK;gBACrCO,cAAc;gBACdC,YAAYL,WAAWK,UAAU;gBACjCC,OAAOd,KAAK,CAACK,IAAI;gBACjBU,UAAU;YACZ;QACF,OAAO;YACLd,gBAAgB,CAACI,IAAI,GAAGL,KAAK,CAACK,IAAI;QACpC;QACAH,YAAYc,IAAI,CAACX;IACnB;IAEA,gDAAgD;IAChD,IAAIR,WAAWC,MAAM,EAAE;;QACnBD,WAAWC,MAAM,CAAwCmB,gBAAgB,GAAG;IAChF;IAEA,0BAA0B;IAC1B,OAAO;QACL,uCAAuC;QACvC,IAAIpB,WAAWC,MAAM,EAAE;YACrB,OAAO,AAACD,WAAWC,MAAM,CAAwCmB,gBAAgB;QACnF;QAEA,KAAK,MAAMZ,OAAOH,YAAa;YAC7B,MAAMM,aAAaL,oBAAoBe,GAAG,CAACb;YAC3C,IAAIG,YAAY;gBACdF,OAAOK,cAAc,CAACd,YAAYQ,KAAKG;YACzC,OAAO;gBACL,OAAOP,gBAAgB,CAACI,IAAI;YAC9B;QACF;IACF;AACF"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { readFile, stat } from 'node:fs/promises';
|
|
2
|
+
import { extname } from 'node:path';
|
|
3
|
+
// The image formats Sanity accepts for uploaded images, such as organization logos. Uploads need
|
|
4
|
+
// an image Content-Type, and the CLI has no other source for one.
|
|
5
|
+
const IMAGE_CONTENT_TYPES = {
|
|
6
|
+
'.avif': 'image/avif',
|
|
7
|
+
'.bmp': 'image/bmp',
|
|
8
|
+
'.gif': 'image/gif',
|
|
9
|
+
'.heic': 'image/heic',
|
|
10
|
+
'.heif': 'image/heif',
|
|
11
|
+
'.jpeg': 'image/jpeg',
|
|
12
|
+
'.jpg': 'image/jpeg',
|
|
13
|
+
'.png': 'image/png',
|
|
14
|
+
'.svg': 'image/svg+xml',
|
|
15
|
+
'.tif': 'image/tiff',
|
|
16
|
+
'.tiff': 'image/tiff',
|
|
17
|
+
'.webp': 'image/webp'
|
|
18
|
+
};
|
|
19
|
+
// Matches the upload limit, so a large file fails here instead of after uploading it.
|
|
20
|
+
const MAX_IMAGE_BYTES = 5 * 1024 * 1024;
|
|
21
|
+
/**
|
|
22
|
+
* Read an image file to upload, such as an organization's logo. Throws an error a user can act on
|
|
23
|
+
* when the file is missing, isn't a supported image type, or is over 5 MB.
|
|
24
|
+
* @public
|
|
25
|
+
*/ export async function readImageFile(filePath) {
|
|
26
|
+
const contentType = IMAGE_CONTENT_TYPES[extname(filePath).toLowerCase()];
|
|
27
|
+
if (!contentType) {
|
|
28
|
+
throw new Error(`"${filePath}" isn't a supported image type. Use a PNG, JPEG, GIF, WebP, SVG, BMP, TIFF, HEIF or AVIF file.`);
|
|
29
|
+
}
|
|
30
|
+
let stats;
|
|
31
|
+
try {
|
|
32
|
+
stats = await stat(filePath);
|
|
33
|
+
} catch (error) {
|
|
34
|
+
if (error instanceof Error && 'code' in error && error.code === 'ENOENT') {
|
|
35
|
+
throw new Error(`Couldn't find "${filePath}". Check the path and try again.`, {
|
|
36
|
+
cause: error
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
if (stats.size > MAX_IMAGE_BYTES) {
|
|
42
|
+
throw new Error(`"${filePath}" is larger than 5 MB, the upload limit. Use a smaller image.`);
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
contentType,
|
|
46
|
+
image: await readFile(filePath)
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
//# sourceMappingURL=readImageFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/util/readImageFile.ts"],"sourcesContent":["import {type Stats} from 'node:fs'\nimport {readFile, stat} from 'node:fs/promises'\nimport {extname} from 'node:path'\n\n// The image formats Sanity accepts for uploaded images, such as organization logos. Uploads need\n// an image Content-Type, and the CLI has no other source for one.\nconst IMAGE_CONTENT_TYPES: Record<string, string> = {\n '.avif': 'image/avif',\n '.bmp': 'image/bmp',\n '.gif': 'image/gif',\n '.heic': 'image/heic',\n '.heif': 'image/heif',\n '.jpeg': 'image/jpeg',\n '.jpg': 'image/jpeg',\n '.png': 'image/png',\n '.svg': 'image/svg+xml',\n '.tif': 'image/tiff',\n '.tiff': 'image/tiff',\n '.webp': 'image/webp',\n}\n\n// Matches the upload limit, so a large file fails here instead of after uploading it.\nconst MAX_IMAGE_BYTES = 5 * 1024 * 1024\n\n/** @public */\nexport interface ImageFile {\n contentType: string\n image: Buffer\n}\n\n/**\n * Read an image file to upload, such as an organization's logo. Throws an error a user can act on\n * when the file is missing, isn't a supported image type, or is over 5 MB.\n * @public\n */\nexport async function readImageFile(filePath: string): Promise<ImageFile> {\n const contentType = IMAGE_CONTENT_TYPES[extname(filePath).toLowerCase()]\n if (!contentType) {\n throw new Error(\n `\"${filePath}\" isn't a supported image type. Use a PNG, JPEG, GIF, WebP, SVG, BMP, TIFF, HEIF or AVIF file.`,\n )\n }\n\n let stats: Stats\n try {\n stats = await stat(filePath)\n } catch (error) {\n if (error instanceof Error && 'code' in error && error.code === 'ENOENT') {\n throw new Error(`Couldn't find \"${filePath}\". Check the path and try again.`, {cause: error})\n }\n throw error\n }\n\n if (stats.size > MAX_IMAGE_BYTES) {\n throw new Error(`\"${filePath}\" is larger than 5 MB, the upload limit. Use a smaller image.`)\n }\n\n return {contentType, image: await readFile(filePath)}\n}\n"],"names":["readFile","stat","extname","IMAGE_CONTENT_TYPES","MAX_IMAGE_BYTES","readImageFile","filePath","contentType","toLowerCase","Error","stats","error","code","cause","size","image"],"mappings":"AACA,SAAQA,QAAQ,EAAEC,IAAI,QAAO,mBAAkB;AAC/C,SAAQC,OAAO,QAAO,YAAW;AAEjC,iGAAiG;AACjG,kEAAkE;AAClE,MAAMC,sBAA8C;IAClD,SAAS;IACT,QAAQ;IACR,QAAQ;IACR,SAAS;IACT,SAAS;IACT,SAAS;IACT,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,SAAS;IACT,SAAS;AACX;AAEA,sFAAsF;AACtF,MAAMC,kBAAkB,IAAI,OAAO;AAQnC;;;;CAIC,GACD,OAAO,eAAeC,cAAcC,QAAgB;IAClD,MAAMC,cAAcJ,mBAAmB,CAACD,QAAQI,UAAUE,WAAW,GAAG;IACxE,IAAI,CAACD,aAAa;QAChB,MAAM,IAAIE,MACR,CAAC,CAAC,EAAEH,SAAS,8FAA8F,CAAC;IAEhH;IAEA,IAAII;IACJ,IAAI;QACFA,QAAQ,MAAMT,KAAKK;IACrB,EAAE,OAAOK,OAAO;QACd,IAAIA,iBAAiBF,SAAS,UAAUE,SAASA,MAAMC,IAAI,KAAK,UAAU;YACxE,MAAM,IAAIH,MAAM,CAAC,eAAe,EAAEH,SAAS,gCAAgC,CAAC,EAAE;gBAACO,OAAOF;YAAK;QAC7F;QACA,MAAMA;IACR;IAEA,IAAID,MAAMI,IAAI,GAAGV,iBAAiB;QAChC,MAAM,IAAIK,MAAM,CAAC,CAAC,EAAEH,SAAS,6DAA6D,CAAC;IAC7F;IAEA,OAAO;QAACC;QAAaQ,OAAO,MAAMf,SAASM;IAAS;AACtD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/cli-core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.16.0",
|
|
4
4
|
"description": "Sanity CLI core package",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -61,6 +61,10 @@
|
|
|
61
61
|
"source": "./src/_exports/errors.ts",
|
|
62
62
|
"default": "./dist/_exports/errors.js"
|
|
63
63
|
},
|
|
64
|
+
"./images": {
|
|
65
|
+
"source": "./src/_exports/images.ts",
|
|
66
|
+
"default": "./dist/_exports/images.js"
|
|
67
|
+
},
|
|
64
68
|
"./executionContext": {
|
|
65
69
|
"source": "./src/executionContext.ts",
|
|
66
70
|
"default": "./dist/executionContext.js"
|
|
@@ -122,7 +126,7 @@
|
|
|
122
126
|
"@inquirer/core": "^12.0.6",
|
|
123
127
|
"@inquirer/prompts": "^8.7.5",
|
|
124
128
|
"@oclif/core": "^4.14.0",
|
|
125
|
-
"@sanity/client": "^8.
|
|
129
|
+
"@sanity/client": "^8.17.0",
|
|
126
130
|
"boxen": "^8.0.1",
|
|
127
131
|
"empathic": "^2.1.0",
|
|
128
132
|
"get-it": "^9.7.0",
|
|
@@ -140,10 +144,9 @@
|
|
|
140
144
|
"zod": "^4.6.7"
|
|
141
145
|
},
|
|
142
146
|
"devDependencies": {
|
|
143
|
-
"@
|
|
147
|
+
"@repo/oxc-config": "0.0.0",
|
|
144
148
|
"@repo/package.config": "0.0.1",
|
|
145
149
|
"@repo/tsconfig": "3.70.0",
|
|
146
|
-
"@sanity/eslint-config-cli": "1.1.3",
|
|
147
150
|
"@sanity/pkg-utils": "^12.3.4",
|
|
148
151
|
"@sanity/telemetry": "^1.1.0",
|
|
149
152
|
"@swc/cli": "^0.8.2",
|
|
@@ -151,12 +154,12 @@
|
|
|
151
154
|
"@types/jsdom": "^28.0.3",
|
|
152
155
|
"@types/node": "^22.20.5",
|
|
153
156
|
"babel-plugin-react-compiler": "^1.0.0",
|
|
154
|
-
"eslint": "^10.7.0",
|
|
155
157
|
"oxc-transform-react": "^0.158.0",
|
|
156
|
-
"
|
|
157
|
-
"
|
|
158
|
+
"oxlint": "^1.94.0",
|
|
159
|
+
"publint": "^0.3.25",
|
|
160
|
+
"sanity": "^6.24.0",
|
|
158
161
|
"typescript": "^6.0.3",
|
|
159
|
-
"vitest": "^5.1.
|
|
162
|
+
"vitest": "^5.1.1"
|
|
160
163
|
},
|
|
161
164
|
"peerDependencies": {
|
|
162
165
|
"babel-plugin-react-compiler": "*",
|
|
@@ -177,12 +180,12 @@
|
|
|
177
180
|
"build": "swc --delete-dir-on-start --strip-leading-paths --out-dir dist/ src",
|
|
178
181
|
"build:types": "pkg-utils build --emitDeclarationOnly",
|
|
179
182
|
"check:types": "tsc --noEmit",
|
|
180
|
-
"lint": "eslint .",
|
|
181
183
|
"publint": "publint",
|
|
182
184
|
"test": "vitest run",
|
|
183
185
|
"posttest": "pnpm run lint",
|
|
184
186
|
"test:coverage": "vitest run --coverage",
|
|
185
187
|
"test:watch": "vitest",
|
|
186
|
-
"watch": "swc --delete-dir-on-start --strip-leading-paths --out-dir dist/ --watch src"
|
|
188
|
+
"watch": "swc --delete-dir-on-start --strip-leading-paths --out-dir dist/ --watch src",
|
|
189
|
+
"lint": "oxlint -c oxlint.config.ts"
|
|
187
190
|
}
|
|
188
191
|
}
|