@sanity/cli-core 0.1.0-alpha.16 → 0.1.0-alpha.17
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/ux.d.ts +34 -2
- package/dist/_exports/ux.js +1 -0
- package/dist/_exports/ux.js.map +1 -1
- package/dist/index.d.ts +21 -6
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/loaders/studio/studioWorkerLoader.worker.js +1 -2
- package/dist/loaders/studio/studioWorkerLoader.worker.js.map +1 -1
- package/dist/loaders/studio/studioWorkerTask.js +13 -2
- package/dist/loaders/studio/studioWorkerTask.js.map +1 -1
- package/dist/loaders/tsx/tsxWorkerTask.js +1 -3
- package/dist/loaders/tsx/tsxWorkerTask.js.map +1 -1
- package/dist/util/NonInteractiveError.js +12 -0
- package/dist/util/NonInteractiveError.js.map +1 -0
- package/dist/util/isInteractive.js +1 -1
- package/dist/util/isInteractive.js.map +1 -1
- package/dist/util/promisifyWorker.js +15 -11
- package/dist/util/promisifyWorker.js.map +1 -1
- package/dist/ux/prompts.js +49 -1
- package/dist/ux/prompts.js.map +1 -1
- package/package.json +9 -9
package/dist/_exports/ux.d.ts
CHANGED
|
@@ -2,7 +2,9 @@ import {default as boxen} from 'boxen'
|
|
|
2
2
|
import {Options as BoxenOptions} from 'boxen'
|
|
3
3
|
import {Boxes} from 'boxen'
|
|
4
4
|
import {CustomBorderStyle} from 'boxen'
|
|
5
|
+
import * as inquirer from '@inquirer/prompts'
|
|
5
6
|
import {default as logSymbols} from 'log-symbols'
|
|
7
|
+
import {Separator} from '@inquirer/prompts'
|
|
6
8
|
import {Spacing} from 'boxen'
|
|
7
9
|
import {Spinner} from 'ora'
|
|
8
10
|
import {default as spinner} from 'ora'
|
|
@@ -17,10 +19,42 @@ export {BoxenOptions}
|
|
|
17
19
|
|
|
18
20
|
export {Boxes}
|
|
19
21
|
|
|
22
|
+
export declare const checkbox: typeof inquirer.checkbox
|
|
23
|
+
|
|
24
|
+
declare const confirm_2: typeof inquirer.confirm
|
|
25
|
+
export {confirm_2 as confirm}
|
|
26
|
+
|
|
20
27
|
export {CustomBorderStyle}
|
|
21
28
|
|
|
29
|
+
export declare const editor: typeof inquirer.editor
|
|
30
|
+
|
|
31
|
+
export declare const expand: typeof inquirer.expand
|
|
32
|
+
|
|
33
|
+
export declare const input: typeof inquirer.input
|
|
34
|
+
|
|
22
35
|
export {logSymbols}
|
|
23
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Error thrown when a prompt is attempted in a non-interactive environment
|
|
39
|
+
* (e.g., CI, non-TTY, piped stdin). Callers can catch this specific error
|
|
40
|
+
* to provide appropriate fallback behavior.
|
|
41
|
+
*/
|
|
42
|
+
export declare class NonInteractiveError extends Error {
|
|
43
|
+
constructor(promptName: string)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export declare const number: typeof inquirer.number
|
|
47
|
+
|
|
48
|
+
export declare const password: typeof inquirer.password
|
|
49
|
+
|
|
50
|
+
export declare const rawlist: typeof inquirer.rawlist
|
|
51
|
+
|
|
52
|
+
export declare const search: typeof inquirer.search
|
|
53
|
+
|
|
54
|
+
export declare const select: typeof inquirer.select
|
|
55
|
+
|
|
56
|
+
export {Separator}
|
|
57
|
+
|
|
24
58
|
export {Spacing}
|
|
25
59
|
|
|
26
60
|
export {Spinner}
|
|
@@ -35,6 +69,4 @@ export {spinnerPromise}
|
|
|
35
69
|
|
|
36
70
|
export {SpinnerPromiseOptions}
|
|
37
71
|
|
|
38
|
-
export * from '@inquirer/prompts'
|
|
39
|
-
|
|
40
72
|
export {}
|
package/dist/_exports/ux.js
CHANGED
package/dist/_exports/ux.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/_exports/ux.ts"],"sourcesContent":["export * from '../ux/boxen.js'\nexport * from '../ux/logSymbols.js'\nexport * from '../ux/prompts.js'\nexport * from '../ux/spinner.js'\n"],"names":[],"mappings":"AAAA,cAAc,iBAAgB;AAC9B,cAAc,sBAAqB;AACnC,cAAc,mBAAkB;AAChC,cAAc,mBAAkB"}
|
|
1
|
+
{"version":3,"sources":["../../src/_exports/ux.ts"],"sourcesContent":["export {NonInteractiveError} from '../util/NonInteractiveError.js'\nexport * from '../ux/boxen.js'\nexport * from '../ux/logSymbols.js'\nexport * from '../ux/prompts.js'\nexport * from '../ux/spinner.js'\n"],"names":["NonInteractiveError"],"mappings":"AAAA,SAAQA,mBAAmB,QAAO,iCAAgC;AAClE,cAAc,iBAAgB;AAC9B,cAAc,sBAAqB;AACnC,cAAc,mBAAkB;AAChC,cAAc,mBAAkB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -683,6 +683,15 @@ export declare function isTrueish(value: string | undefined): boolean
|
|
|
683
683
|
*/
|
|
684
684
|
export declare function mockBrowserEnvironment(basePath: string): Promise<() => void>
|
|
685
685
|
|
|
686
|
+
/**
|
|
687
|
+
* Error thrown when a prompt is attempted in a non-interactive environment
|
|
688
|
+
* (e.g., CI, non-TTY, piped stdin). Callers can catch this specific error
|
|
689
|
+
* to provide appropriate fallback behavior.
|
|
690
|
+
*/
|
|
691
|
+
export declare class NonInteractiveError extends Error {
|
|
692
|
+
constructor(promptName: string)
|
|
693
|
+
}
|
|
694
|
+
|
|
686
695
|
/**
|
|
687
696
|
* Normalizes a path for cross-platform comparison by converting backslashes to forward slashes.
|
|
688
697
|
* Useful for converting windows paths to unix paths.
|
|
@@ -809,17 +818,21 @@ export declare interface ProjectRootResult {
|
|
|
809
818
|
}
|
|
810
819
|
|
|
811
820
|
/**
|
|
812
|
-
*
|
|
813
|
-
*
|
|
814
|
-
* or non-zero exit code.
|
|
815
|
-
* is received.
|
|
821
|
+
* Creates a Node.js Worker from the given file path and options, and wraps it
|
|
822
|
+
* in a Promise that resolves with the first message the worker sends, and
|
|
823
|
+
* rejects on error, message deserialization failure, or non-zero exit code.
|
|
824
|
+
* The worker is terminated after a message or error is received.
|
|
816
825
|
*
|
|
817
|
-
* @param
|
|
826
|
+
* @param filePath - URL to the worker file
|
|
827
|
+
* @param options - Options to pass to the Worker constructor
|
|
818
828
|
* @returns A promise that resolves with the first message from the worker
|
|
819
829
|
* @throws If the worker emits an error, a message deserialization error, or exits with a non-zero code
|
|
820
830
|
* @internal
|
|
821
831
|
*/
|
|
822
|
-
export declare function promisifyWorker<T = unknown>(
|
|
832
|
+
export declare function promisifyWorker<T = unknown>(
|
|
833
|
+
filePath: URL,
|
|
834
|
+
options?: WorkerOptions_2,
|
|
835
|
+
): Promise<T>
|
|
823
836
|
|
|
824
837
|
declare const rawConfigSchema: z_2.ZodUnion<
|
|
825
838
|
readonly [
|
|
@@ -1306,4 +1319,6 @@ export declare type UserViteConfig =
|
|
|
1306
1319
|
| ((config: InlineConfig, env: ConfigEnv) => InlineConfig | Promise<InlineConfig>)
|
|
1307
1320
|
| InlineConfig
|
|
1308
1321
|
|
|
1322
|
+
export declare const waitForAsync: (ms?: number) => Promise<void>
|
|
1323
|
+
|
|
1309
1324
|
export {}
|
package/dist/index.js
CHANGED
|
@@ -32,6 +32,7 @@ export * from './util/isInteractive.js';
|
|
|
32
32
|
export * from './util/isRecord.js';
|
|
33
33
|
export * from './util/isStaging.js';
|
|
34
34
|
export * from './util/isTrueish.js';
|
|
35
|
+
export * from './util/NonInteractiveError.js';
|
|
35
36
|
export * from './util/normalizePath.js';
|
|
36
37
|
export * from './util/parseStringFlag.js';
|
|
37
38
|
export * from './util/promisifyWorker.js';
|
|
@@ -40,6 +41,7 @@ export * from './util/readPackageJson.js';
|
|
|
40
41
|
export * from './util/resolveLocalPackage.js';
|
|
41
42
|
export * from './util/safeStructuredClone.js';
|
|
42
43
|
export * from './util/tryGetDefaultExport.js';
|
|
44
|
+
export * from './util/waitForAsync.js';
|
|
43
45
|
export * from './ux/colorizeJson.js';
|
|
44
46
|
export * from './ux/formatObject.js';
|
|
45
47
|
export * from './ux/printKeyValue.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './config/cli/getCliConfig.js'\nexport * from './config/cli/getCliConfigSync.js'\nexport {type CliConfig} from './config/cli/types/cliConfig.js'\nexport {type UserViteConfig} from './config/cli/types/userViteConfig.js'\nexport * from './config/findProjectRoot.js'\nexport * from './config/findProjectRootSync.js'\nexport * from './config/studio/getStudioConfig.js'\nexport * from './config/studio/getStudioWorkspaces.js'\nexport * from './config/util/findConfigsPaths.js'\nexport * from './config/util/findStudioConfigPath.js'\nexport {type ProjectRootResult} from './config/util/recursivelyResolveProjectRoot.js'\nexport * from './debug.js'\nexport * from './loaders/studio/studioWorkerTask.js'\nexport * from './loaders/tsx/tsxWorkerTask.js'\nexport * from './SanityCommand.js'\nexport * from './services/apiClient.js'\nexport * from './services/cliUserConfig.js'\nexport * from './services/getCliToken.js'\nexport * from './telemetry/createTelemetryStore.js'\nexport * from './telemetry/flushTelemetryFiles.js'\nexport * from './telemetry/getTelemetryBaseInfo.js'\nexport * from './telemetry/telemetryStoreDebug.js'\nexport {\n type CLITelemetryStore,\n type ConsentInformation,\n type TelemetryUserProperties,\n} from './telemetry/types.js'\nexport {type Output, type SanityOrgUser} from './types.js'\nexport * from './util/createExpiringConfig.js'\nexport {doImport} from './util/doImport.js'\nexport * from './util/environment/mockBrowserEnvironment.js'\nexport * from './util/fileExists.js'\nexport {\n clearCliTelemetry,\n CLI_TELEMETRY_SYMBOL,\n getCliTelemetry,\n setCliTelemetry,\n} from './util/getCliTelemetry.js'\nexport * from './util/getEmptyAuth.js'\nexport * from './util/getSanityEnvVar.js'\nexport * from './util/getSanityUrl.js'\nexport * from './util/getUserConfig.js'\nexport * from './util/importModule.js'\nexport * from './util/isCi.js'\nexport * from './util/isInteractive.js'\nexport * from './util/isRecord.js'\nexport * from './util/isStaging.js'\nexport * from './util/isTrueish.js'\nexport * from './util/normalizePath.js'\nexport * from './util/parseStringFlag.js'\nexport * from './util/promisifyWorker.js'\nexport * from './util/readNDJSON.js'\nexport * from './util/readPackageJson.js'\nexport * from './util/resolveLocalPackage.js'\nexport * from './util/safeStructuredClone.js'\nexport * from './util/tryGetDefaultExport.js'\nexport * from './ux/colorizeJson.js'\nexport * from './ux/formatObject.js'\nexport * from './ux/printKeyValue.js'\nexport * from './ux/timer.js'\n"],"names":["doImport","clearCliTelemetry","CLI_TELEMETRY_SYMBOL","getCliTelemetry","setCliTelemetry"],"mappings":"AAAA,cAAc,+BAA8B;AAC5C,cAAc,mCAAkC;AAGhD,cAAc,8BAA6B;AAC3C,cAAc,kCAAiC;AAC/C,cAAc,qCAAoC;AAClD,cAAc,yCAAwC;AACtD,cAAc,oCAAmC;AACjD,cAAc,wCAAuC;AAErD,cAAc,aAAY;AAC1B,cAAc,uCAAsC;AACpD,cAAc,iCAAgC;AAC9C,cAAc,qBAAoB;AAClC,cAAc,0BAAyB;AACvC,cAAc,8BAA6B;AAC3C,cAAc,4BAA2B;AACzC,cAAc,sCAAqC;AACnD,cAAc,qCAAoC;AAClD,cAAc,sCAAqC;AACnD,cAAc,qCAAoC;AAOlD,cAAc,iCAAgC;AAC9C,SAAQA,QAAQ,QAAO,qBAAoB;AAC3C,cAAc,+CAA8C;AAC5D,cAAc,uBAAsB;AACpC,SACEC,iBAAiB,EACjBC,oBAAoB,EACpBC,eAAe,EACfC,eAAe,QACV,4BAA2B;AAClC,cAAc,yBAAwB;AACtC,cAAc,4BAA2B;AACzC,cAAc,yBAAwB;AACtC,cAAc,0BAAyB;AACvC,cAAc,yBAAwB;AACtC,cAAc,iBAAgB;AAC9B,cAAc,0BAAyB;AACvC,cAAc,qBAAoB;AAClC,cAAc,sBAAqB;AACnC,cAAc,sBAAqB;AACnC,cAAc,0BAAyB;AACvC,cAAc,4BAA2B;AACzC,cAAc,4BAA2B;AACzC,cAAc,uBAAsB;AACpC,cAAc,4BAA2B;AACzC,cAAc,gCAA+B;AAC7C,cAAc,gCAA+B;AAC7C,cAAc,gCAA+B;AAC7C,cAAc,uBAAsB;AACpC,cAAc,uBAAsB;AACpC,cAAc,wBAAuB;AACrC,cAAc,gBAAe"}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './config/cli/getCliConfig.js'\nexport * from './config/cli/getCliConfigSync.js'\nexport {type CliConfig} from './config/cli/types/cliConfig.js'\nexport {type UserViteConfig} from './config/cli/types/userViteConfig.js'\nexport * from './config/findProjectRoot.js'\nexport * from './config/findProjectRootSync.js'\nexport * from './config/studio/getStudioConfig.js'\nexport * from './config/studio/getStudioWorkspaces.js'\nexport * from './config/util/findConfigsPaths.js'\nexport * from './config/util/findStudioConfigPath.js'\nexport {type ProjectRootResult} from './config/util/recursivelyResolveProjectRoot.js'\nexport * from './debug.js'\nexport * from './loaders/studio/studioWorkerTask.js'\nexport * from './loaders/tsx/tsxWorkerTask.js'\nexport * from './SanityCommand.js'\nexport * from './services/apiClient.js'\nexport * from './services/cliUserConfig.js'\nexport * from './services/getCliToken.js'\nexport * from './telemetry/createTelemetryStore.js'\nexport * from './telemetry/flushTelemetryFiles.js'\nexport * from './telemetry/getTelemetryBaseInfo.js'\nexport * from './telemetry/telemetryStoreDebug.js'\nexport {\n type CLITelemetryStore,\n type ConsentInformation,\n type TelemetryUserProperties,\n} from './telemetry/types.js'\nexport {type Output, type SanityOrgUser} from './types.js'\nexport * from './util/createExpiringConfig.js'\nexport {doImport} from './util/doImport.js'\nexport * from './util/environment/mockBrowserEnvironment.js'\nexport * from './util/fileExists.js'\nexport {\n clearCliTelemetry,\n CLI_TELEMETRY_SYMBOL,\n getCliTelemetry,\n setCliTelemetry,\n} from './util/getCliTelemetry.js'\nexport * from './util/getEmptyAuth.js'\nexport * from './util/getSanityEnvVar.js'\nexport * from './util/getSanityUrl.js'\nexport * from './util/getUserConfig.js'\nexport * from './util/importModule.js'\nexport * from './util/isCi.js'\nexport * from './util/isInteractive.js'\nexport * from './util/isRecord.js'\nexport * from './util/isStaging.js'\nexport * from './util/isTrueish.js'\nexport * from './util/NonInteractiveError.js'\nexport * from './util/normalizePath.js'\nexport * from './util/parseStringFlag.js'\nexport * from './util/promisifyWorker.js'\nexport * from './util/readNDJSON.js'\nexport * from './util/readPackageJson.js'\nexport * from './util/resolveLocalPackage.js'\nexport * from './util/safeStructuredClone.js'\nexport * from './util/tryGetDefaultExport.js'\nexport * from './util/waitForAsync.js'\nexport * from './ux/colorizeJson.js'\nexport * from './ux/formatObject.js'\nexport * from './ux/printKeyValue.js'\nexport * from './ux/timer.js'\n"],"names":["doImport","clearCliTelemetry","CLI_TELEMETRY_SYMBOL","getCliTelemetry","setCliTelemetry"],"mappings":"AAAA,cAAc,+BAA8B;AAC5C,cAAc,mCAAkC;AAGhD,cAAc,8BAA6B;AAC3C,cAAc,kCAAiC;AAC/C,cAAc,qCAAoC;AAClD,cAAc,yCAAwC;AACtD,cAAc,oCAAmC;AACjD,cAAc,wCAAuC;AAErD,cAAc,aAAY;AAC1B,cAAc,uCAAsC;AACpD,cAAc,iCAAgC;AAC9C,cAAc,qBAAoB;AAClC,cAAc,0BAAyB;AACvC,cAAc,8BAA6B;AAC3C,cAAc,4BAA2B;AACzC,cAAc,sCAAqC;AACnD,cAAc,qCAAoC;AAClD,cAAc,sCAAqC;AACnD,cAAc,qCAAoC;AAOlD,cAAc,iCAAgC;AAC9C,SAAQA,QAAQ,QAAO,qBAAoB;AAC3C,cAAc,+CAA8C;AAC5D,cAAc,uBAAsB;AACpC,SACEC,iBAAiB,EACjBC,oBAAoB,EACpBC,eAAe,EACfC,eAAe,QACV,4BAA2B;AAClC,cAAc,yBAAwB;AACtC,cAAc,4BAA2B;AACzC,cAAc,yBAAwB;AACtC,cAAc,0BAAyB;AACvC,cAAc,yBAAwB;AACtC,cAAc,iBAAgB;AAC9B,cAAc,0BAAyB;AACvC,cAAc,qBAAoB;AAClC,cAAc,sBAAqB;AACnC,cAAc,sBAAqB;AACnC,cAAc,gCAA+B;AAC7C,cAAc,0BAAyB;AACvC,cAAc,4BAA2B;AACzC,cAAc,4BAA2B;AACzC,cAAc,uBAAsB;AACpC,cAAc,4BAA2B;AACzC,cAAc,gCAA+B;AAC7C,cAAc,gCAA+B;AAC7C,cAAc,gCAA+B;AAC7C,cAAc,yBAAwB;AACtC,cAAc,uBAAsB;AACpC,cAAc,uBAAsB;AACpC,cAAc,wBAAuB;AACrC,cAAc,gBAAe"}
|
|
@@ -71,7 +71,6 @@ const defaultViteConfig = {
|
|
|
71
71
|
`process.env.${key}`,
|
|
72
72
|
JSON.stringify(value)
|
|
73
73
|
])),
|
|
74
|
-
// TODO: Combine with `determineIsApp` from `@sanity/cli`
|
|
75
74
|
envPrefix: cliConfig && 'app' in cliConfig ? 'SANITY_APP_' : 'SANITY_STUDIO_',
|
|
76
75
|
esbuild: {
|
|
77
76
|
jsx: 'automatic'
|
|
@@ -93,6 +92,7 @@ const defaultViteConfig = {
|
|
|
93
92
|
*/ noExternal: true
|
|
94
93
|
}
|
|
95
94
|
};
|
|
95
|
+
// Merge the CLI config's Vite config with the default Vite config
|
|
96
96
|
let viteConfig = defaultViteConfig;
|
|
97
97
|
if (typeof cliConfig?.vite === 'function') {
|
|
98
98
|
viteConfig = await cliConfig.vite(viteConfig, {
|
|
@@ -112,7 +112,6 @@ await server.pluginContainer.buildStart({});
|
|
|
112
112
|
// Load environment variables from `.env` files in the same way as Vite does.
|
|
113
113
|
// Note that Sanity also provides environment variables through `process.env.*` for compat reasons,
|
|
114
114
|
// and so we need to do the same here.
|
|
115
|
-
// @todo is this in line with sanity?
|
|
116
115
|
const env = loadEnv(server.config.mode, server.config.envDir, viteConfig.envPrefix ?? '');
|
|
117
116
|
for(const key in env){
|
|
118
117
|
process.env[key] ??= env[key];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/loaders/studio/studioWorkerLoader.worker.ts"],"sourcesContent":["import {isMainThread} from 'node:worker_threads'\n\nimport {createServer, type InlineConfig, loadEnv, mergeConfig} from 'vite'\nimport {ViteNodeRunner} from 'vite-node/client'\nimport {ViteNodeServer} from 'vite-node/server'\nimport {installSourcemapsSupport} from 'vite-node/source-map'\n\nimport {getCliConfig} from '../../config/cli/getCliConfig.js'\nimport {type CliConfig} from '../../config/cli/types/cliConfig.js'\nimport {subdebug} from '../../debug.js'\nimport {getStudioEnvironmentVariables} from '../../util/environment/getStudioEnvironmentVariables.js'\nimport {setupBrowserStubs} from '../../util/environment/setupBrowserStubs.js'\nimport {isRecord} from '../../util/isRecord.js'\nimport {isNotFoundError} from '../../util/NotFoundError.js'\n\nif (isMainThread) {\n throw new Error('Should be child of thread, not the main thread')\n}\n\nconst rootPath = process.env.STUDIO_WORKER_STUDIO_ROOT_PATH\nif (!rootPath) {\n throw new Error('Missing `STUDIO_WORKER_STUDIO_ROOT_PATH` environment variable')\n}\n\nconst debug = subdebug('studio:worker')\n\nconst workerScriptPath = process.env.STUDIO_WORKER_TASK_FILE\nif (!workerScriptPath) {\n throw new Error('Missing `STUDIO_WORKER_TASK_FILE` environment variable')\n}\n\nawait setupBrowserStubs()\n\nconst studioEnvVars = await getStudioEnvironmentVariables(rootPath)\n\n// Allow the CLI config (`sanity.cli.(js|ts)`) to define a `vite` property which can\n// extend/modify the default vite configuration for the studio.\nlet cliConfig: CliConfig | undefined\ntry {\n cliConfig = await getCliConfig(rootPath)\n} catch (err) {\n debug('Failed to load CLI config: %o', err)\n if (!isNotFoundError(err)) {\n // eslint-disable-next-line no-console\n console.warn('[warn] Failed to load CLI config:', err)\n }\n}\n\n/**\n * Fetches and caches modules from HTTP/HTTPS URLs.\n * Vite's SSR transform treats `https://` imports as external and bypasses the plugin\n * resolve pipeline entirely, so we intercept them at the ViteNodeRunner level instead.\n */\nconst httpModuleCache = new Map<string, string>()\nasync function fetchHttpModule(url: string): Promise<{code: string}> {\n const cached = httpModuleCache.get(url)\n if (cached) return {code: cached}\n\n debug('Fetching HTTP import: %s', url)\n const response = await fetch(url, {signal: AbortSignal.timeout(30_000)})\n if (!response.ok) {\n throw new Error(`Failed to fetch module from ${url}: ${response.status} ${response.statusText}`)\n }\n\n const code = await response.text()\n httpModuleCache.set(url, code)\n return {code}\n}\n\nfunction isHttpsUrl(id: string): boolean {\n return id.startsWith('https://')\n}\n\nconst defaultViteConfig: InlineConfig = {\n build: {target: 'node'},\n configFile: false, // @todo Should use `vite` prop from `sanity.cli.ts` (if any)\n // Inject environment variables as compile-time constants for Vite\n define: Object.fromEntries(\n Object.entries(studioEnvVars).map(([key, value]) => [\n `process.env.${key}`,\n JSON.stringify(value),\n ]),\n ),\n // TODO: Combine with `determineIsApp` from `@sanity/cli`\n envPrefix: cliConfig && 'app' in cliConfig ? 'SANITY_APP_' : 'SANITY_STUDIO_',\n esbuild: {\n jsx: 'automatic',\n },\n logLevel: 'error',\n optimizeDeps: {\n include: undefined,\n noDiscovery: true,\n },\n root: rootPath,\n server: {\n hmr: false,\n watch: null,\n },\n ssr: {\n /**\n * We don't want to externalize any dependencies, we want everything to run thru vite.\n * Especially for CJS compatibility, etc.\n */\n noExternal: true,\n },\n}\n\nlet viteConfig = defaultViteConfig\nif (typeof cliConfig?.vite === 'function') {\n viteConfig = (await cliConfig.vite(viteConfig, {\n command: 'build',\n isSsrBuild: true,\n mode: 'production',\n })) as InlineConfig\n} else if (isRecord(cliConfig?.vite)) {\n viteConfig = mergeConfig(viteConfig, cliConfig.vite)\n}\n\ndebug('Creating Vite server with config: %o', viteConfig)\n// Vite will build the files we give it - targetting Node.js instead of the browser.\n// We include the inject plugin in order to provide the stubs for the undefined global APIs.\nconst server = await createServer(viteConfig)\n\n// Bit of a hack, but seems necessary based on the `node-vite` binary implementation\nawait server.pluginContainer.buildStart({})\n\n// Load environment variables from `.env` files in the same way as Vite does.\n// Note that Sanity also provides environment variables through `process.env.*` for compat reasons,\n// and so we need to do the same here.\n// @todo is this in line with sanity?\nconst env = loadEnv(server.config.mode, server.config.envDir, viteConfig.envPrefix ?? '')\nfor (const key in env) {\n process.env[key] ??= env[key]\n}\n\n// Now we're providing the glue that ensures node-specific loading and execution works.\nconst node = new ViteNodeServer(server)\n\n// Should make it easier to debug any crashes in the imported code…\ninstallSourcemapsSupport({\n getSourceMap: (source) => node.getSourceMap(source),\n})\n\nconst runner = new ViteNodeRunner({\n base: server.config.base,\n async fetchModule(id) {\n // Vite's SSR transform externalizes https:// imports, so Node's ESM loader\n // would reject them. We fetch the module over HTTP and run it through Vite's\n // SSR transform to rewrite ESM export/import syntax to the __vite_ssr_*\n // format that ViteNodeRunner expects.\n if (isHttpsUrl(id)) {\n const {code: rawCode} = await fetchHttpModule(id)\n const result = await server.ssrTransform(rawCode, null, id)\n return {code: result?.code || rawCode}\n }\n return node.fetchModule(id)\n },\n resolveId(id, importer) {\n // Prevent vite-node from trying to resolve HTTP URLs through Node's resolver\n if (isHttpsUrl(id)) return {id}\n // Resolve any import from an HTTP-fetched module against the remote origin\n // (e.g. esm.sh returns `export * from '/pkg@1.0/es2022/pkg.mjs'`)\n if (importer && isHttpsUrl(importer)) {\n return {id: new URL(id, importer).href}\n }\n return node.resolveId(id, importer)\n },\n root: server.config.root,\n})\n\n// Copied from `vite-node` - it appears that this applies the `define` config from\n// vite, but it also takes a surprisingly long time to execute. Not clear at this\n// point why this is, so we should investigate whether it's necessary or not.\nawait runner.executeId('/@vite/env')\n\nawait runner.executeId(workerScriptPath)\n"],"names":["isMainThread","createServer","loadEnv","mergeConfig","ViteNodeRunner","ViteNodeServer","installSourcemapsSupport","getCliConfig","subdebug","getStudioEnvironmentVariables","setupBrowserStubs","isRecord","isNotFoundError","Error","rootPath","process","env","STUDIO_WORKER_STUDIO_ROOT_PATH","debug","workerScriptPath","STUDIO_WORKER_TASK_FILE","studioEnvVars","cliConfig","err","console","warn","httpModuleCache","Map","fetchHttpModule","url","cached","get","code","response","fetch","signal","AbortSignal","timeout","ok","status","statusText","text","set","isHttpsUrl","id","startsWith","defaultViteConfig","build","target","configFile","define","Object","fromEntries","entries","map","key","value","JSON","stringify","envPrefix","esbuild","jsx","logLevel","optimizeDeps","include","undefined","noDiscovery","root","server","hmr","watch","ssr","noExternal","viteConfig","vite","command","isSsrBuild","mode","pluginContainer","buildStart","config","envDir","node","getSourceMap","source","runner","base","fetchModule","rawCode","result","ssrTransform","resolveId","importer","URL","href","executeId"],"mappings":"AAAA,SAAQA,YAAY,QAAO,sBAAqB;AAEhD,SAAQC,YAAY,EAAqBC,OAAO,EAAEC,WAAW,QAAO,OAAM;AAC1E,SAAQC,cAAc,QAAO,mBAAkB;AAC/C,SAAQC,cAAc,QAAO,mBAAkB;AAC/C,SAAQC,wBAAwB,QAAO,uBAAsB;AAE7D,SAAQC,YAAY,QAAO,mCAAkC;AAE7D,SAAQC,QAAQ,QAAO,iBAAgB;AACvC,SAAQC,6BAA6B,QAAO,0DAAyD;AACrG,SAAQC,iBAAiB,QAAO,8CAA6C;AAC7E,SAAQC,QAAQ,QAAO,yBAAwB;AAC/C,SAAQC,eAAe,QAAO,8BAA6B;AAE3D,IAAIZ,cAAc;IAChB,MAAM,IAAIa,MAAM;AAClB;AAEA,MAAMC,WAAWC,QAAQC,GAAG,CAACC,8BAA8B;AAC3D,IAAI,CAACH,UAAU;IACb,MAAM,IAAID,MAAM;AAClB;AAEA,MAAMK,QAAQV,SAAS;AAEvB,MAAMW,mBAAmBJ,QAAQC,GAAG,CAACI,uBAAuB;AAC5D,IAAI,CAACD,kBAAkB;IACrB,MAAM,IAAIN,MAAM;AAClB;AAEA,MAAMH;AAEN,MAAMW,gBAAgB,MAAMZ,8BAA8BK;AAE1D,oFAAoF;AACpF,+DAA+D;AAC/D,IAAIQ;AACJ,IAAI;IACFA,YAAY,MAAMf,aAAaO;AACjC,EAAE,OAAOS,KAAK;IACZL,MAAM,iCAAiCK;IACvC,IAAI,CAACX,gBAAgBW,MAAM;QACzB,sCAAsC;QACtCC,QAAQC,IAAI,CAAC,qCAAqCF;IACpD;AACF;AAEA;;;;CAIC,GACD,MAAMG,kBAAkB,IAAIC;AAC5B,eAAeC,gBAAgBC,GAAW;IACxC,MAAMC,SAASJ,gBAAgBK,GAA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,OAAOZ,KAAKS,SAAS,CAAC/C,IAAIgD;IAC5B;IACAzB,MAAMC,OAAOY,MAAM,CAACb,IAAI;AAC1B;AAEA,kFAAkF;AAClF,iFAAiF;AACjF,6EAA6E;AAC7E,MAAMkB,OAAOU,SAAS,CAAC;AAEvB,MAAMV,OAAOU,SAAS,CAAC5E"}
|
|
1
|
+
{"version":3,"sources":["../../../src/loaders/studio/studioWorkerLoader.worker.ts"],"sourcesContent":["import {isMainThread} from 'node:worker_threads'\n\nimport {createServer, type InlineConfig, loadEnv, mergeConfig} from 'vite'\nimport {ViteNodeRunner} from 'vite-node/client'\nimport {ViteNodeServer} from 'vite-node/server'\nimport {installSourcemapsSupport} from 'vite-node/source-map'\n\nimport {getCliConfig} from '../../config/cli/getCliConfig.js'\nimport {type CliConfig} from '../../config/cli/types/cliConfig.js'\nimport {subdebug} from '../../debug.js'\nimport {getStudioEnvironmentVariables} from '../../util/environment/getStudioEnvironmentVariables.js'\nimport {setupBrowserStubs} from '../../util/environment/setupBrowserStubs.js'\nimport {isRecord} from '../../util/isRecord.js'\nimport {isNotFoundError} from '../../util/NotFoundError.js'\n\nif (isMainThread) {\n throw new Error('Should be child of thread, not the main thread')\n}\n\nconst rootPath = process.env.STUDIO_WORKER_STUDIO_ROOT_PATH\nif (!rootPath) {\n throw new Error('Missing `STUDIO_WORKER_STUDIO_ROOT_PATH` environment variable')\n}\n\nconst debug = subdebug('studio:worker')\n\nconst workerScriptPath = process.env.STUDIO_WORKER_TASK_FILE\nif (!workerScriptPath) {\n throw new Error('Missing `STUDIO_WORKER_TASK_FILE` environment variable')\n}\n\nawait setupBrowserStubs()\n\nconst studioEnvVars = await getStudioEnvironmentVariables(rootPath)\n\n// Allow the CLI config (`sanity.cli.(js|ts)`) to define a `vite` property which can\n// extend/modify the default vite configuration for the studio.\nlet cliConfig: CliConfig | undefined\ntry {\n cliConfig = await getCliConfig(rootPath)\n} catch (err) {\n debug('Failed to load CLI config: %o', err)\n if (!isNotFoundError(err)) {\n // eslint-disable-next-line no-console\n console.warn('[warn] Failed to load CLI config:', err)\n }\n}\n\n/**\n * Fetches and caches modules from HTTP/HTTPS URLs.\n * Vite's SSR transform treats `https://` imports as external and bypasses the plugin\n * resolve pipeline entirely, so we intercept them at the ViteNodeRunner level instead.\n */\nconst httpModuleCache = new Map<string, string>()\nasync function fetchHttpModule(url: string): Promise<{code: string}> {\n const cached = httpModuleCache.get(url)\n if (cached) return {code: cached}\n\n debug('Fetching HTTP import: %s', url)\n const response = await fetch(url, {signal: AbortSignal.timeout(30_000)})\n if (!response.ok) {\n throw new Error(`Failed to fetch module from ${url}: ${response.status} ${response.statusText}`)\n }\n\n const code = await response.text()\n httpModuleCache.set(url, code)\n return {code}\n}\n\nfunction isHttpsUrl(id: string): boolean {\n return id.startsWith('https://')\n}\n\nconst defaultViteConfig: InlineConfig = {\n build: {target: 'node'},\n configFile: false,\n // Inject environment variables as compile-time constants for Vite\n define: Object.fromEntries(\n Object.entries(studioEnvVars).map(([key, value]) => [\n `process.env.${key}`,\n JSON.stringify(value),\n ]),\n ),\n envPrefix: cliConfig && 'app' in cliConfig ? 'SANITY_APP_' : 'SANITY_STUDIO_',\n esbuild: {\n jsx: 'automatic',\n },\n logLevel: 'error',\n optimizeDeps: {\n include: undefined,\n noDiscovery: true,\n },\n root: rootPath,\n server: {\n hmr: false,\n watch: null,\n },\n ssr: {\n /**\n * We don't want to externalize any dependencies, we want everything to run thru vite.\n * Especially for CJS compatibility, etc.\n */\n noExternal: true,\n },\n}\n\n// Merge the CLI config's Vite config with the default Vite config\nlet viteConfig = defaultViteConfig\nif (typeof cliConfig?.vite === 'function') {\n viteConfig = (await cliConfig.vite(viteConfig, {\n command: 'build',\n isSsrBuild: true,\n mode: 'production',\n })) as InlineConfig\n} else if (isRecord(cliConfig?.vite)) {\n viteConfig = mergeConfig(viteConfig, cliConfig.vite)\n}\n\ndebug('Creating Vite server with config: %o', viteConfig)\n// Vite will build the files we give it - targetting Node.js instead of the browser.\n// We include the inject plugin in order to provide the stubs for the undefined global APIs.\nconst server = await createServer(viteConfig)\n\n// Bit of a hack, but seems necessary based on the `node-vite` binary implementation\nawait server.pluginContainer.buildStart({})\n\n// Load environment variables from `.env` files in the same way as Vite does.\n// Note that Sanity also provides environment variables through `process.env.*` for compat reasons,\n// and so we need to do the same here.\nconst env = loadEnv(server.config.mode, server.config.envDir, viteConfig.envPrefix ?? '')\nfor (const key in env) {\n process.env[key] ??= env[key]\n}\n\n// Now we're providing the glue that ensures node-specific loading and execution works.\nconst node = new ViteNodeServer(server)\n\n// Should make it easier to debug any crashes in the imported code…\ninstallSourcemapsSupport({\n getSourceMap: (source) => node.getSourceMap(source),\n})\n\nconst runner = new ViteNodeRunner({\n base: server.config.base,\n async fetchModule(id) {\n // Vite's SSR transform externalizes https:// imports, so Node's ESM loader\n // would reject them. We fetch the module over HTTP and run it through Vite's\n // SSR transform to rewrite ESM export/import syntax to the __vite_ssr_*\n // format that ViteNodeRunner expects.\n if (isHttpsUrl(id)) {\n const {code: rawCode} = await fetchHttpModule(id)\n const result = await server.ssrTransform(rawCode, null, id)\n return {code: result?.code || rawCode}\n }\n return node.fetchModule(id)\n },\n resolveId(id, importer) {\n // Prevent vite-node from trying to resolve HTTP URLs through Node's resolver\n if (isHttpsUrl(id)) return {id}\n // Resolve any import from an HTTP-fetched module against the remote origin\n // (e.g. esm.sh returns `export * from '/pkg@1.0/es2022/pkg.mjs'`)\n if (importer && isHttpsUrl(importer)) {\n return {id: new URL(id, importer).href}\n }\n return node.resolveId(id, importer)\n },\n root: server.config.root,\n})\n\n// Copied from `vite-node` - it appears that this applies the `define` config from\n// vite, but it also takes a surprisingly long time to execute. Not clear at this\n// point why this is, so we should investigate whether it's necessary or not.\nawait runner.executeId('/@vite/env')\n\nawait runner.executeId(workerScriptPath)\n"],"names":["isMainThread","createServer","loadEnv","mergeConfig","ViteNodeRunner","ViteNodeServer","installSourcemapsSupport","getCliConfig","subdebug","getStudioEnvironmentVariables","setupBrowserStubs","isRecord","isNotFoundError","Error","rootPath","process","env","STUDIO_WORKER_STUDIO_ROOT_PATH","debug","workerScriptPath","STUDIO_WORKER_TASK_FILE","studioEnvVars","cliConfig","err","console","warn","httpModuleCache","Map","fetchHttpModule","url","cached","get","code","response","fetch","signal","AbortSignal","timeout","ok","status","statusText","text","set","isHttpsUrl","id","startsWith","defaultViteConfig","build","target","configFile","define","Object","fromEntries","entries","map","key","value","JSON","stringify","envPrefix","esbuild","jsx","logLevel","optimizeDeps","include","undefined","noDiscovery","root","server","hmr","watch","ssr","noExternal","viteConfig","vite","command","isSsrBuild","mode","pluginContainer","buildStart","config","envDir","node","getSourceMap","source","runner","base","fetchModule","rawCode","result","ssrTransform","resolveId","importer","URL","href","executeId"],"mappings":"AAAA,SAAQA,YAAY,QAAO,sBAAqB;AAEhD,SAAQC,YAAY,EAAqBC,OAAO,EAAEC,WAAW,QAAO,OAAM;AAC1E,SAAQC,cAAc,QAAO,mBAAkB;AAC/C,SAAQC,cAAc,QAAO,mBAAkB;AAC/C,SAAQC,wBAAwB,QAAO,uBAAsB;AAE7D,SAAQC,YAAY,QAAO,mCAAkC;AAE7D,SAAQC,QAAQ,QAAO,iBAAgB;AACvC,SAAQC,6BAA6B,QAAO,0DAAyD;AACrG,SAAQC,iBAAiB,QAAO,8CAA6C;AAC7E,SAAQC,QAAQ,QAAO,yBAAwB;AAC/C,SAAQC,eAAe,QAAO,8BAA6B;AAE3D,IAAIZ,cAAc;IAChB,MAAM,IAAIa,MAAM;AAClB;AAEA,MAAMC,WAAWC,QAAQC,GAAG,CAACC,8BAA8B;AAC3D,IAAI,CAACH,UAAU;IACb,MAAM,IAAID,MAAM;AAClB;AAEA,MAAMK,QAAQV,SAAS;AAEvB,MAAMW,mBAAmBJ,QAAQC,GAAG,CAACI,uBAAuB;AAC5D,IAAI,CAACD,kBAAkB;IACrB,MAAM,IAAIN,MAAM;AAClB;AAEA,MAAMH;AAEN,MAAMW,gBAAgB,MAAMZ,8BAA8BK;AAE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AAQzD,QAAQwD;YAAO;QACvC;QACA,OAAON,KAAKK,WAAW,CAAC3C;IAC1B;IACA+C,WAAU/C,EAAE,EAAEgD,QAAQ;QACpB,6EAA6E;QAC7E,IAAIjD,WAAWC,KAAK,OAAO;YAACA;QAAE;QAC9B,2EAA2E;QAC3E,kEAAkE;QAClE,IAAIgD,YAAYjD,WAAWiD,WAAW;YACpC,OAAO;gBAAChD,IAAI,IAAIiD,IAAIjD,IAAIgD,UAAUE,IAAI;YAAA;QACxC;QACA,OAAOZ,KAAKS,SAAS,CAAC/C,IAAIgD;IAC5B;IACAzB,MAAMC,OAAOY,MAAM,CAACb,IAAI;AAC1B;AAEA,kFAAkF;AAClF,iFAAiF;AACjF,6EAA6E;AAC7E,MAAMkB,OAAOU,SAAS,CAAC;AAEvB,MAAMV,OAAOU,SAAS,CAAC5E"}
|
|
@@ -30,8 +30,19 @@ import { promisifyWorker } from '../../util/promisifyWorker.js';
|
|
|
30
30
|
* @throws If the worker exits with a non-zero code
|
|
31
31
|
* @internal
|
|
32
32
|
*/ export function studioWorkerTask(filePath, options) {
|
|
33
|
-
const
|
|
34
|
-
|
|
33
|
+
const normalizedFilePath = fileURLToPath(filePath);
|
|
34
|
+
if (!/\.worker\.(js|ts)$/.test(normalizedFilePath)) {
|
|
35
|
+
throw new Error('Studio worker tasks must include `.worker.(js|ts)` in path');
|
|
36
|
+
}
|
|
37
|
+
const { studioRootPath, ...workerOptions } = options;
|
|
38
|
+
return promisifyWorker(new URL('studioWorkerLoader.worker.js', import.meta.url), {
|
|
39
|
+
...workerOptions,
|
|
40
|
+
env: {
|
|
41
|
+
...isRecord(workerOptions.env) ? workerOptions.env : process.env,
|
|
42
|
+
STUDIO_WORKER_STUDIO_ROOT_PATH: studioRootPath,
|
|
43
|
+
STUDIO_WORKER_TASK_FILE: normalizedFilePath
|
|
44
|
+
}
|
|
45
|
+
});
|
|
35
46
|
}
|
|
36
47
|
/**
|
|
37
48
|
* Creates a new worker for a studio worker task.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/loaders/studio/studioWorkerTask.ts"],"sourcesContent":["import {fileURLToPath} from 'node:url'\nimport {Worker, type WorkerOptions} from 'node:worker_threads'\n\nimport {type RequireProps} from '../../types.js'\nimport {isRecord} from '../../util/isRecord.js'\nimport {promisifyWorker} from '../../util/promisifyWorker.js'\n\n/**\n * Options for the studio worker task\n *\n * @internal\n */\ninterface StudioWorkerTaskOptions extends RequireProps<WorkerOptions, 'name'> {\n studioRootPath: string\n}\n\n/**\n * Executes a worker file in a Sanity Studio browser context.\n *\n * This uses a combination of vite for \"bundling\" + jsdom for emulating a browser\n * environment under the hood, which means that the same thing that will work in vite\n * _should_ work in the worker - to a degree. If the user has defined any typescript\n * path aliases, these will have to be added as aliases to the vite config - the same\n * behavior as you would see with regular vite. Other things that are accounted for:\n *\n * - TypeScript support (+JSX, enums and other \"compilation needed\" features)\n * - CSS, font and other file imports will resolve to a file path\n * - CSS module imports will resolve to a javascript object of class names\n * - Environment variables are available both as `import.meta.env` and `process.env`,\n * and `.env` files are loaded in the same way that they would in a Sanity studio.\n * - Browser globals not available in a Node.js environment but _are_ provided by JSDOM\n * are defined directly to the Node environment as globals. While this polutes the\n * global namespace, it is done only in the worker thread.\n * - Certain browser globals that are _not_ available in JSDOM are also provided to the\n * global namespace - things like `requestIdleCallback`, `IntersectionObserver` etc.\n * These are provided with a minimal stub implementation to make them not crash.\n *\n * @param filePath - Path to the worker file (`.ts` works and is encouraged)\n * @param options - Options to pass to the worker\n * @returns A promise that resolves with the message from the worker\n * @throws If the file does not exist\n * @throws If the worker exits with a non-zero code\n * @internal\n */\nexport function studioWorkerTask<T = unknown>(\n filePath: URL,\n options: StudioWorkerTaskOptions,\n): Promise<T> {\n const
|
|
1
|
+
{"version":3,"sources":["../../../src/loaders/studio/studioWorkerTask.ts"],"sourcesContent":["import {fileURLToPath} from 'node:url'\nimport {Worker, type WorkerOptions} from 'node:worker_threads'\n\nimport {type RequireProps} from '../../types.js'\nimport {isRecord} from '../../util/isRecord.js'\nimport {promisifyWorker} from '../../util/promisifyWorker.js'\n\n/**\n * Options for the studio worker task\n *\n * @internal\n */\ninterface StudioWorkerTaskOptions extends RequireProps<WorkerOptions, 'name'> {\n studioRootPath: string\n}\n\n/**\n * Executes a worker file in a Sanity Studio browser context.\n *\n * This uses a combination of vite for \"bundling\" + jsdom for emulating a browser\n * environment under the hood, which means that the same thing that will work in vite\n * _should_ work in the worker - to a degree. If the user has defined any typescript\n * path aliases, these will have to be added as aliases to the vite config - the same\n * behavior as you would see with regular vite. Other things that are accounted for:\n *\n * - TypeScript support (+JSX, enums and other \"compilation needed\" features)\n * - CSS, font and other file imports will resolve to a file path\n * - CSS module imports will resolve to a javascript object of class names\n * - Environment variables are available both as `import.meta.env` and `process.env`,\n * and `.env` files are loaded in the same way that they would in a Sanity studio.\n * - Browser globals not available in a Node.js environment but _are_ provided by JSDOM\n * are defined directly to the Node environment as globals. While this polutes the\n * global namespace, it is done only in the worker thread.\n * - Certain browser globals that are _not_ available in JSDOM are also provided to the\n * global namespace - things like `requestIdleCallback`, `IntersectionObserver` etc.\n * These are provided with a minimal stub implementation to make them not crash.\n *\n * @param filePath - Path to the worker file (`.ts` works and is encouraged)\n * @param options - Options to pass to the worker\n * @returns A promise that resolves with the message from the worker\n * @throws If the file does not exist\n * @throws If the worker exits with a non-zero code\n * @internal\n */\nexport function studioWorkerTask<T = unknown>(\n filePath: URL,\n options: StudioWorkerTaskOptions,\n): Promise<T> {\n const normalizedFilePath = fileURLToPath(filePath)\n\n if (!/\\.worker\\.(js|ts)$/.test(normalizedFilePath)) {\n throw new Error('Studio worker tasks must include `.worker.(js|ts)` in path')\n }\n\n const {studioRootPath, ...workerOptions} = options\n return promisifyWorker<T>(new URL('studioWorkerLoader.worker.js', import.meta.url), {\n ...workerOptions,\n env: {\n ...(isRecord(workerOptions.env) ? workerOptions.env : process.env),\n STUDIO_WORKER_STUDIO_ROOT_PATH: studioRootPath,\n STUDIO_WORKER_TASK_FILE: normalizedFilePath,\n },\n })\n}\n\n/**\n * Creates a new worker for a studio worker task.\n *\n * This uses a combination of vite for \"bundling\" + jsdom for emulating a browser\n * environment under the hood, which means that the same thing that will work in vite\n * _should_ work in the worker - to a degree. If the user has defined any typescript\n * path aliases, these will have to be added as aliases to the vite config - the same\n * behavior as you would see with regular vite. Other things that are accounted for:\n *\n * - TypeScript support (+JSX, enums and other \"compilation needed\" features)\n * - CSS, font and other file imports will resolve to a file path\n * - CSS module imports will resolve to a javascript object of class names\n * - Environment variables are available both as `import.meta.env` and `process.env`,\n * and `.env` files are loaded in the same way that they would in a Sanity studio.\n * - Browser globals not available in a Node.js environment but _are_ provided by JSDOM\n * are defined directly to the Node environment as globals. While this polutes the\n * global namespace, it is done only in the worker thread.\n * - Certain browser globals that are _not_ available in JSDOM are also provided to the\n * global namespace - things like `requestIdleCallback`, `IntersectionObserver` etc.\n * These are provided with a minimal stub implementation to make them not crash.\n *\n * @param filePath - Path to the worker file (`.ts` works and is encouraged)\n * @param options - Options to pass to the worker\n * @returns A promise that resolves with the message from the worker\n * @throws If the file does not exist\n * @throws If the worker exits with a non-zero code\n * @internal\n */\nexport function createStudioWorker(filePath: URL, options: StudioWorkerTaskOptions) {\n const normalizedFilePath = fileURLToPath(filePath)\n\n if (!/\\.worker\\.(js|ts)$/.test(normalizedFilePath)) {\n throw new Error('Studio worker tasks must include `.worker.(js|ts)` in path')\n }\n\n return new Worker(new URL('studioWorkerLoader.worker.js', import.meta.url), {\n ...options,\n env: {\n ...(isRecord(options.env) ? options.env : process.env),\n STUDIO_WORKER_STUDIO_ROOT_PATH: options.studioRootPath,\n STUDIO_WORKER_TASK_FILE: normalizedFilePath,\n },\n })\n}\n"],"names":["fileURLToPath","Worker","isRecord","promisifyWorker","studioWorkerTask","filePath","options","normalizedFilePath","test","Error","studioRootPath","workerOptions","URL","url","env","process","STUDIO_WORKER_STUDIO_ROOT_PATH","STUDIO_WORKER_TASK_FILE","createStudioWorker"],"mappings":"AAAA,SAAQA,aAAa,QAAO,WAAU;AACtC,SAAQC,MAAM,QAA2B,sBAAqB;AAG9D,SAAQC,QAAQ,QAAO,yBAAwB;AAC/C,SAAQC,eAAe,QAAO,gCAA+B;AAW7D;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2BC,GACD,OAAO,SAASC,iBACdC,QAAa,EACbC,OAAgC;IAEhC,MAAMC,qBAAqBP,cAAcK;IAEzC,IAAI,CAAC,qBAAqBG,IAAI,CAACD,qBAAqB;QAClD,MAAM,IAAIE,MAAM;IAClB;IAEA,MAAM,EAACC,cAAc,EAAE,GAAGC,eAAc,GAAGL;IAC3C,OAAOH,gBAAmB,IAAIS,IAAI,gCAAgC,YAAYC,GAAG,GAAG;QAClF,GAAGF,aAAa;QAChBG,KAAK;YACH,GAAIZ,SAASS,cAAcG,GAAG,IAAIH,cAAcG,GAAG,GAAGC,QAAQD,GAAG;YACjEE,gCAAgCN;YAChCO,yBAAyBV;QAC3B;IACF;AACF;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2BC,GACD,OAAO,SAASW,mBAAmBb,QAAa,EAAEC,OAAgC;IAChF,MAAMC,qBAAqBP,cAAcK;IAEzC,IAAI,CAAC,qBAAqBG,IAAI,CAACD,qBAAqB;QAClD,MAAM,IAAIE,MAAM;IAClB;IAEA,OAAO,IAAIR,OAAO,IAAIW,IAAI,gCAAgC,YAAYC,GAAG,GAAG;QAC1E,GAAGP,OAAO;QACVQ,KAAK;YACH,GAAIZ,SAASI,QAAQQ,GAAG,IAAIR,QAAQQ,GAAG,GAAGC,QAAQD,GAAG;YACrDE,gCAAgCV,QAAQI,cAAc;YACtDO,yBAAyBV;QAC3B;IACF;AACF"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { fileURLToPath, URL } from 'node:url';
|
|
2
|
-
import { Worker } from 'node:worker_threads';
|
|
3
2
|
import { getTsconfig } from 'get-tsconfig';
|
|
4
3
|
import { isRecord } from '../../util/isRecord.js';
|
|
5
4
|
import { promisifyWorker } from '../../util/promisifyWorker.js';
|
|
@@ -26,11 +25,10 @@ import { promisifyWorker } from '../../util/promisifyWorker.js';
|
|
|
26
25
|
} : {},
|
|
27
26
|
TSX_WORKER_TASK_SCRIPT: fileURLToPath(filePath)
|
|
28
27
|
};
|
|
29
|
-
|
|
28
|
+
return promisifyWorker(new URL('tsxWorkerLoader.worker.js', import.meta.url), {
|
|
30
29
|
...options,
|
|
31
30
|
env
|
|
32
31
|
});
|
|
33
|
-
return promisifyWorker(worker);
|
|
34
32
|
}
|
|
35
33
|
|
|
36
34
|
//# sourceMappingURL=tsxWorkerTask.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/loaders/tsx/tsxWorkerTask.ts"],"sourcesContent":["import {fileURLToPath, URL} from 'node:url'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/loaders/tsx/tsxWorkerTask.ts"],"sourcesContent":["import {fileURLToPath, URL} from 'node:url'\nimport {type WorkerOptions} from 'node:worker_threads'\n\nimport {getTsconfig} from 'get-tsconfig'\n\nimport {type RequireProps} from '../../types.js'\nimport {isRecord} from '../../util/isRecord.js'\nimport {promisifyWorker} from '../../util/promisifyWorker.js'\n\n/**\n * Options for the tsx worker task\n *\n * @internal\n */\ninterface TsxWorkerTaskOptions extends RequireProps<WorkerOptions, 'name'> {\n rootPath: string\n}\n\n/**\n * Executes a worker file with tsx registered. This means you can import other\n * typescript with fairly rich syntax, and still have that only apply to the worker\n * thread instead of the full parent process. The worker should emit a message when\n * complete using `parentPort`. Once it has received a single message will resolve the\n * returned promise with that message. If you are expecting multiple messages, you will\n * have to implement another method ;)\n *\n * @param filePath - Path to the worker file\n * @param options - Options to pass to the worker\n * @returns A promise that resolves with the message from the worker\n * @throws If the file does not exist\n * @throws If the worker exits with a non-zero code\n * @internal\n */\nexport function tsxWorkerTask<T = unknown>(\n filePath: URL,\n options: TsxWorkerTaskOptions,\n): Promise<T> {\n const tsconfig = getTsconfig(options.rootPath)\n\n const env = {\n ...(isRecord(options.env) ? options.env : process.env),\n ...(tsconfig?.path ? {TSX_TSCONFIG_PATH: tsconfig.path} : {}),\n TSX_WORKER_TASK_SCRIPT: fileURLToPath(filePath),\n }\n\n return promisifyWorker<T>(new URL('tsxWorkerLoader.worker.js', import.meta.url), {\n ...options,\n env,\n })\n}\n"],"names":["fileURLToPath","URL","getTsconfig","isRecord","promisifyWorker","tsxWorkerTask","filePath","options","tsconfig","rootPath","env","process","path","TSX_TSCONFIG_PATH","TSX_WORKER_TASK_SCRIPT","url"],"mappings":"AAAA,SAAQA,aAAa,EAAEC,GAAG,QAAO,WAAU;AAG3C,SAAQC,WAAW,QAAO,eAAc;AAGxC,SAAQC,QAAQ,QAAO,yBAAwB;AAC/C,SAAQC,eAAe,QAAO,gCAA+B;AAW7D;;;;;;;;;;;;;;CAcC,GACD,OAAO,SAASC,cACdC,QAAa,EACbC,OAA6B;IAE7B,MAAMC,WAAWN,YAAYK,QAAQE,QAAQ;IAE7C,MAAMC,MAAM;QACV,GAAIP,SAASI,QAAQG,GAAG,IAAIH,QAAQG,GAAG,GAAGC,QAAQD,GAAG;QACrD,GAAIF,UAAUI,OAAO;YAACC,mBAAmBL,SAASI,IAAI;QAAA,IAAI,CAAC,CAAC;QAC5DE,wBAAwBd,cAAcM;IACxC;IAEA,OAAOF,gBAAmB,IAAIH,IAAI,6BAA6B,YAAYc,GAAG,GAAG;QAC/E,GAAGR,OAAO;QACVG;IACF;AACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error thrown when a prompt is attempted in a non-interactive environment
|
|
3
|
+
* (e.g., CI, non-TTY, piped stdin). Callers can catch this specific error
|
|
4
|
+
* to provide appropriate fallback behavior.
|
|
5
|
+
*/ export class NonInteractiveError extends Error {
|
|
6
|
+
constructor(promptName){
|
|
7
|
+
super(`Cannot run "${promptName}" prompt in a non-interactive environment. ` + 'Provide the required value via flags or environment variables, or run in an interactive terminal.');
|
|
8
|
+
this.name = 'NonInteractiveError';
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=NonInteractiveError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/util/NonInteractiveError.ts"],"sourcesContent":["/**\n * Error thrown when a prompt is attempted in a non-interactive environment\n * (e.g., CI, non-TTY, piped stdin). Callers can catch this specific error\n * to provide appropriate fallback behavior.\n */\nexport class NonInteractiveError extends Error {\n constructor(promptName: string) {\n super(\n `Cannot run \"${promptName}\" prompt in a non-interactive environment. ` +\n 'Provide the required value via flags or environment variables, or run in an interactive terminal.',\n )\n this.name = 'NonInteractiveError'\n }\n}\n"],"names":["NonInteractiveError","Error","promptName","name"],"mappings":"AAAA;;;;CAIC,GACD,OAAO,MAAMA,4BAA4BC;IACvC,YAAYC,UAAkB,CAAE;QAC9B,KAAK,CACH,CAAC,YAAY,EAAEA,WAAW,2CAA2C,CAAC,GACpE;QAEJ,IAAI,CAACC,IAAI,GAAG;IACd;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/util/isInteractive.ts"],"sourcesContent":["export function isInteractive(): boolean {\n return process.
|
|
1
|
+
{"version":3,"sources":["../../src/util/isInteractive.ts"],"sourcesContent":["export function isInteractive(): boolean {\n return Boolean(process.stdin.isTTY) && process.env.TERM !== 'dumb' && !('CI' in process.env)\n}\n"],"names":["isInteractive","Boolean","process","stdin","isTTY","env","TERM"],"mappings":"AAAA,OAAO,SAASA;IACd,OAAOC,QAAQC,QAAQC,KAAK,CAACC,KAAK,KAAKF,QAAQG,GAAG,CAACC,IAAI,KAAK,UAAU,CAAE,CAAA,QAAQJ,QAAQG,GAAG,AAAD;AAC5F"}
|
|
@@ -1,16 +1,20 @@
|
|
|
1
|
+
import { Worker } from 'node:worker_threads';
|
|
1
2
|
import { subdebug } from '../debug.js';
|
|
2
|
-
const debug = subdebug('
|
|
3
|
+
const debug = subdebug('promisifyWorker');
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* or non-zero exit code.
|
|
7
|
-
* is received.
|
|
5
|
+
* Creates a Node.js Worker from the given file path and options, and wraps it
|
|
6
|
+
* in a Promise that resolves with the first message the worker sends, and
|
|
7
|
+
* rejects on error, message deserialization failure, or non-zero exit code.
|
|
8
|
+
* The worker is terminated after a message or error is received.
|
|
8
9
|
*
|
|
9
|
-
* @param
|
|
10
|
+
* @param filePath - URL to the worker file
|
|
11
|
+
* @param options - Options to pass to the Worker constructor
|
|
10
12
|
* @returns A promise that resolves with the first message from the worker
|
|
11
13
|
* @throws If the worker emits an error, a message deserialization error, or exits with a non-zero code
|
|
12
14
|
* @internal
|
|
13
|
-
*/ export function promisifyWorker(
|
|
15
|
+
*/ export function promisifyWorker(filePath, options) {
|
|
16
|
+
const worker = new Worker(filePath, options);
|
|
17
|
+
const fileName = `[${filePath.pathname}]`;
|
|
14
18
|
return new Promise((resolve, reject)=>{
|
|
15
19
|
let settled = false;
|
|
16
20
|
worker.addListener('error', function onWorkerError(err) {
|
|
@@ -25,22 +29,22 @@ const debug = subdebug('worker');
|
|
|
25
29
|
// so there is nothing to terminate or remove listeners from.
|
|
26
30
|
worker.addListener('exit', function onWorkerExit(code) {
|
|
27
31
|
if (code > 0) {
|
|
28
|
-
debug(
|
|
32
|
+
debug(`${fileName} exited with code ${code}`);
|
|
29
33
|
reject(new Error(`Worker exited with code ${code}`));
|
|
30
34
|
} else if (!settled) {
|
|
31
|
-
debug(
|
|
35
|
+
debug(`${fileName} exited with code 0 without sending a message`);
|
|
32
36
|
reject(new Error('Worker exited without sending a message'));
|
|
33
37
|
}
|
|
34
38
|
});
|
|
35
39
|
worker.addListener('messageerror', function onWorkerMessageError(err) {
|
|
36
40
|
settled = true;
|
|
37
|
-
debug(
|
|
41
|
+
debug(`${fileName} message error: ${err.message}`, err);
|
|
38
42
|
reject(new Error(`Failed to deserialize worker message: ${err}`));
|
|
39
43
|
cleanup();
|
|
40
44
|
});
|
|
41
45
|
worker.addListener('message', function onWorkerMessage(message) {
|
|
42
46
|
settled = true;
|
|
43
|
-
debug(
|
|
47
|
+
debug(`${fileName} message %o`, message);
|
|
44
48
|
resolve(message);
|
|
45
49
|
cleanup();
|
|
46
50
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/util/promisifyWorker.ts"],"sourcesContent":["import {type
|
|
1
|
+
{"version":3,"sources":["../../src/util/promisifyWorker.ts"],"sourcesContent":["import {Worker, type WorkerOptions} from 'node:worker_threads'\n\nimport {subdebug} from '../debug.js'\n\nconst debug = subdebug('promisifyWorker')\n\n/**\n * Creates a Node.js Worker from the given file path and options, and wraps it\n * in a Promise that resolves with the first message the worker sends, and\n * rejects on error, message deserialization failure, or non-zero exit code.\n * The worker is terminated after a message or error is received.\n *\n * @param filePath - URL to the worker file\n * @param options - Options to pass to the Worker constructor\n * @returns A promise that resolves with the first message from the worker\n * @throws If the worker emits an error, a message deserialization error, or exits with a non-zero code\n * @internal\n */\nexport function promisifyWorker<T = unknown>(filePath: URL, options?: WorkerOptions): Promise<T> {\n const worker = new Worker(filePath, options)\n\n const fileName = `[${filePath.pathname}]`\n\n return new Promise<T>((resolve, reject) => {\n let settled = false\n\n worker.addListener('error', function onWorkerError(err) {\n settled = true\n debug(`Worker error: ${err.message}`, err)\n reject(new Error(`Worker error: ${err.message}`, {cause: err}))\n cleanup()\n })\n // No cleanup() here — the worker is already dead after exiting,\n // so there is nothing to terminate or remove listeners from.\n worker.addListener('exit', function onWorkerExit(code) {\n if (code > 0) {\n debug(`${fileName} exited with code ${code}`)\n reject(new Error(`Worker exited with code ${code}`))\n } else if (!settled) {\n debug(`${fileName} exited with code 0 without sending a message`)\n reject(new Error('Worker exited without sending a message'))\n }\n })\n worker.addListener('messageerror', function onWorkerMessageError(err) {\n settled = true\n debug(`${fileName} message error: ${err.message}`, err)\n reject(new Error(`Failed to deserialize worker message: ${err}`))\n cleanup()\n })\n worker.addListener('message', function onWorkerMessage(message) {\n settled = true\n debug(`${fileName} message %o`, message)\n resolve(message)\n cleanup()\n })\n\n function cleanup() {\n setImmediate(() => worker.terminate())\n worker.removeAllListeners()\n }\n })\n}\n"],"names":["Worker","subdebug","debug","promisifyWorker","filePath","options","worker","fileName","pathname","Promise","resolve","reject","settled","addListener","onWorkerError","err","message","Error","cause","cleanup","onWorkerExit","code","onWorkerMessageError","onWorkerMessage","setImmediate","terminate","removeAllListeners"],"mappings":"AAAA,SAAQA,MAAM,QAA2B,sBAAqB;AAE9D,SAAQC,QAAQ,QAAO,cAAa;AAEpC,MAAMC,QAAQD,SAAS;AAEvB;;;;;;;;;;;CAWC,GACD,OAAO,SAASE,gBAA6BC,QAAa,EAAEC,OAAuB;IACjF,MAAMC,SAAS,IAAIN,OAAOI,UAAUC;IAEpC,MAAME,WAAW,CAAC,CAAC,EAAEH,SAASI,QAAQ,CAAC,CAAC,CAAC;IAEzC,OAAO,IAAIC,QAAW,CAACC,SAASC;QAC9B,IAAIC,UAAU;QAEdN,OAAOO,WAAW,CAAC,SAAS,SAASC,cAAcC,GAAG;YACpDH,UAAU;YACVV,MAAM,CAAC,cAAc,EAAEa,IAAIC,OAAO,EAAE,EAAED;YACtCJ,OAAO,IAAIM,MAAM,CAAC,cAAc,EAAEF,IAAIC,OAAO,EAAE,EAAE;gBAACE,OAAOH;YAAG;YAC5DI;QACF;QACA,gEAAgE;QAChE,6DAA6D;QAC7Db,OAAOO,WAAW,CAAC,QAAQ,SAASO,aAAaC,IAAI;YACnD,IAAIA,OAAO,GAAG;gBACZnB,MAAM,GAAGK,SAAS,kBAAkB,EAAEc,MAAM;gBAC5CV,OAAO,IAAIM,MAAM,CAAC,wBAAwB,EAAEI,MAAM;YACpD,OAAO,IAAI,CAACT,SAAS;gBACnBV,MAAM,GAAGK,SAAS,6CAA6C,CAAC;gBAChEI,OAAO,IAAIM,MAAM;YACnB;QACF;QACAX,OAAOO,WAAW,CAAC,gBAAgB,SAASS,qBAAqBP,GAAG;YAClEH,UAAU;YACVV,MAAM,GAAGK,SAAS,gBAAgB,EAAEQ,IAAIC,OAAO,EAAE,EAAED;YACnDJ,OAAO,IAAIM,MAAM,CAAC,sCAAsC,EAAEF,KAAK;YAC/DI;QACF;QACAb,OAAOO,WAAW,CAAC,WAAW,SAASU,gBAAgBP,OAAO;YAC5DJ,UAAU;YACVV,MAAM,GAAGK,SAAS,WAAW,CAAC,EAAES;YAChCN,QAAQM;YACRG;QACF;QAEA,SAASA;YACPK,aAAa,IAAMlB,OAAOmB,SAAS;YACnCnB,OAAOoB,kBAAkB;QAC3B;IACF;AACF"}
|
package/dist/ux/prompts.js
CHANGED
|
@@ -1,3 +1,51 @@
|
|
|
1
|
-
|
|
1
|
+
import * as inquirer from '@inquirer/prompts';
|
|
2
|
+
import { isInteractive } from '../util/isInteractive.js';
|
|
3
|
+
import { NonInteractiveError } from '../util/NonInteractiveError.js';
|
|
4
|
+
export { Separator } from '@inquirer/prompts';
|
|
5
|
+
function assertInteractive(promptName) {
|
|
6
|
+
if (!isInteractive()) {
|
|
7
|
+
throw new NonInteractiveError(promptName);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export const checkbox = (...args)=>{
|
|
11
|
+
assertInteractive('checkbox');
|
|
12
|
+
return inquirer.checkbox(...args);
|
|
13
|
+
};
|
|
14
|
+
export const confirm = (...args)=>{
|
|
15
|
+
assertInteractive('confirm');
|
|
16
|
+
return inquirer.confirm(...args);
|
|
17
|
+
};
|
|
18
|
+
export const editor = (...args)=>{
|
|
19
|
+
assertInteractive('editor');
|
|
20
|
+
return inquirer.editor(...args);
|
|
21
|
+
};
|
|
22
|
+
export const expand = (...args)=>{
|
|
23
|
+
assertInteractive('expand');
|
|
24
|
+
return inquirer.expand(...args);
|
|
25
|
+
};
|
|
26
|
+
export const input = (...args)=>{
|
|
27
|
+
assertInteractive('input');
|
|
28
|
+
return inquirer.input(...args);
|
|
29
|
+
};
|
|
30
|
+
export const number = (...args)=>{
|
|
31
|
+
assertInteractive('number');
|
|
32
|
+
return inquirer.number(...args);
|
|
33
|
+
};
|
|
34
|
+
export const password = (...args)=>{
|
|
35
|
+
assertInteractive('password');
|
|
36
|
+
return inquirer.password(...args);
|
|
37
|
+
};
|
|
38
|
+
export const rawlist = (...args)=>{
|
|
39
|
+
assertInteractive('rawlist');
|
|
40
|
+
return inquirer.rawlist(...args);
|
|
41
|
+
};
|
|
42
|
+
export const search = (...args)=>{
|
|
43
|
+
assertInteractive('search');
|
|
44
|
+
return inquirer.search(...args);
|
|
45
|
+
};
|
|
46
|
+
export const select = (...args)=>{
|
|
47
|
+
assertInteractive('select');
|
|
48
|
+
return inquirer.select(...args);
|
|
49
|
+
};
|
|
2
50
|
|
|
3
51
|
//# sourceMappingURL=prompts.js.map
|
package/dist/ux/prompts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ux/prompts.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../src/ux/prompts.ts"],"sourcesContent":["import * as inquirer from '@inquirer/prompts'\n\nimport {isInteractive} from '../util/isInteractive.js'\nimport {NonInteractiveError} from '../util/NonInteractiveError.js'\n\nexport {Separator} from '@inquirer/prompts'\n\nfunction assertInteractive(promptName: string): void {\n if (!isInteractive()) {\n throw new NonInteractiveError(promptName)\n }\n}\n\nexport const checkbox: typeof inquirer.checkbox = (...args) => {\n assertInteractive('checkbox')\n return inquirer.checkbox(...args)\n}\n\nexport const confirm: typeof inquirer.confirm = (...args) => {\n assertInteractive('confirm')\n return inquirer.confirm(...args)\n}\n\nexport const editor: typeof inquirer.editor = (...args) => {\n assertInteractive('editor')\n return inquirer.editor(...args)\n}\n\nexport const expand: typeof inquirer.expand = (...args) => {\n assertInteractive('expand')\n return inquirer.expand(...args)\n}\n\nexport const input: typeof inquirer.input = (...args) => {\n assertInteractive('input')\n return inquirer.input(...args)\n}\n\nexport const number: typeof inquirer.number = (...args) => {\n assertInteractive('number')\n return inquirer.number(...args)\n}\n\nexport const password: typeof inquirer.password = (...args) => {\n assertInteractive('password')\n return inquirer.password(...args)\n}\n\nexport const rawlist: typeof inquirer.rawlist = (...args) => {\n assertInteractive('rawlist')\n return inquirer.rawlist(...args)\n}\n\nexport const search: typeof inquirer.search = (...args) => {\n assertInteractive('search')\n return inquirer.search(...args)\n}\n\nexport const select: typeof inquirer.select = (...args) => {\n assertInteractive('select')\n return inquirer.select(...args)\n}\n"],"names":["inquirer","isInteractive","NonInteractiveError","Separator","assertInteractive","promptName","checkbox","args","confirm","editor","expand","input","number","password","rawlist","search","select"],"mappings":"AAAA,YAAYA,cAAc,oBAAmB;AAE7C,SAAQC,aAAa,QAAO,2BAA0B;AACtD,SAAQC,mBAAmB,QAAO,iCAAgC;AAElE,SAAQC,SAAS,QAAO,oBAAmB;AAE3C,SAASC,kBAAkBC,UAAkB;IAC3C,IAAI,CAACJ,iBAAiB;QACpB,MAAM,IAAIC,oBAAoBG;IAChC;AACF;AAEA,OAAO,MAAMC,WAAqC,CAAC,GAAGC;IACpDH,kBAAkB;IAClB,OAAOJ,SAASM,QAAQ,IAAIC;AAC9B,EAAC;AAED,OAAO,MAAMC,UAAmC,CAAC,GAAGD;IAClDH,kBAAkB;IAClB,OAAOJ,SAASQ,OAAO,IAAID;AAC7B,EAAC;AAED,OAAO,MAAME,SAAiC,CAAC,GAAGF;IAChDH,kBAAkB;IAClB,OAAOJ,SAASS,MAAM,IAAIF;AAC5B,EAAC;AAED,OAAO,MAAMG,SAAiC,CAAC,GAAGH;IAChDH,kBAAkB;IAClB,OAAOJ,SAASU,MAAM,IAAIH;AAC5B,EAAC;AAED,OAAO,MAAMI,QAA+B,CAAC,GAAGJ;IAC9CH,kBAAkB;IAClB,OAAOJ,SAASW,KAAK,IAAIJ;AAC3B,EAAC;AAED,OAAO,MAAMK,SAAiC,CAAC,GAAGL;IAChDH,kBAAkB;IAClB,OAAOJ,SAASY,MAAM,IAAIL;AAC5B,EAAC;AAED,OAAO,MAAMM,WAAqC,CAAC,GAAGN;IACpDH,kBAAkB;IAClB,OAAOJ,SAASa,QAAQ,IAAIN;AAC9B,EAAC;AAED,OAAO,MAAMO,UAAmC,CAAC,GAAGP;IAClDH,kBAAkB;IAClB,OAAOJ,SAASc,OAAO,IAAIP;AAC7B,EAAC;AAED,OAAO,MAAMQ,SAAiC,CAAC,GAAGR;IAChDH,kBAAkB;IAClB,OAAOJ,SAASe,MAAM,IAAIR;AAC5B,EAAC;AAED,OAAO,MAAMS,SAAiC,CAAC,GAAGT;IAChDH,kBAAkB;IAClB,OAAOJ,SAASgB,MAAM,IAAIT;AAC5B,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/cli-core",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.17",
|
|
4
4
|
"description": "Sanity CLI core package",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
],
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@inquirer/prompts": "^8.2.0",
|
|
51
|
-
"@oclif/core": "^4.8.
|
|
51
|
+
"@oclif/core": "^4.8.1",
|
|
52
52
|
"@rexxars/jiti": "^2.6.2",
|
|
53
53
|
"@sanity/client": "^7.16.0",
|
|
54
54
|
"@sanity/types": "^5.12.0",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"get-it": "^8.7.0",
|
|
60
60
|
"get-tsconfig": "^4.13.6",
|
|
61
61
|
"import-meta-resolve": "^4.2.0",
|
|
62
|
-
"jsdom": "^
|
|
62
|
+
"jsdom": "^28.1.0",
|
|
63
63
|
"json-lexer": "^1.2.0",
|
|
64
64
|
"log-symbols": "^7.0.1",
|
|
65
65
|
"ora": "^9.0.0",
|
|
@@ -78,18 +78,18 @@
|
|
|
78
78
|
"@sanity/pkg-utils": "^10.4.4",
|
|
79
79
|
"@sanity/telemetry": "^0.8.1",
|
|
80
80
|
"@swc/cli": "^0.8.0",
|
|
81
|
-
"@swc/core": "^1.15.
|
|
81
|
+
"@swc/core": "^1.15.13",
|
|
82
82
|
"@types/debug": "^4.1.12",
|
|
83
|
-
"@types/jsdom": "^
|
|
84
|
-
"@types/node": "^20.19.
|
|
85
|
-
"eslint": "^9.39.
|
|
83
|
+
"@types/jsdom": "^28.0.0",
|
|
84
|
+
"@types/node": "^20.19.35",
|
|
85
|
+
"eslint": "^9.39.3",
|
|
86
86
|
"publint": "^0.3.17",
|
|
87
87
|
"sanity": "^5.12.0",
|
|
88
88
|
"typescript": "^5.9.3",
|
|
89
89
|
"vitest": "^4.0.18",
|
|
90
|
-
"@repo/package.config": "0.0.1",
|
|
91
90
|
"@repo/tsconfig": "3.70.0",
|
|
92
|
-
"@sanity/eslint-config-cli": "0.0.0-alpha.
|
|
91
|
+
"@sanity/eslint-config-cli": "0.0.0-alpha.3",
|
|
92
|
+
"@repo/package.config": "0.0.1"
|
|
93
93
|
},
|
|
94
94
|
"peerDependencies": {
|
|
95
95
|
"@sanity/telemetry": ">=0.8.1 <0.9.0"
|