@sanity/cli-core 0.1.0-alpha.5 → 0.1.0-alpha.7
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/config/cli/schemas.d.ts +15 -0
- package/dist/config/cli/schemas.js +5 -2
- package/dist/config/cli/schemas.js.map +1 -1
- package/dist/config/cli/types/cliConfig.d.ts +9 -0
- package/dist/config/cli/types/cliConfig.js.map +1 -1
- package/dist/loaders/studio/studioWorkerLoader.worker.js +9 -24
- package/dist/loaders/studio/studioWorkerLoader.worker.js.map +1 -1
- package/package.json +11 -8
- package/dist/config/__tests__/cliToken.test.js +0 -74
- package/dist/config/__tests__/cliToken.test.js.map +0 -1
- package/dist/config/__tests__/cliUserConfig.test.js +0 -131
- package/dist/config/__tests__/cliUserConfig.test.js.map +0 -1
- package/dist/config/__tests__/findProjectRoot.test.js +0 -159
- package/dist/config/__tests__/findProjectRoot.test.js.map +0 -1
- package/dist/config/__tests__/findProjectRootSync.test.js +0 -112
- package/dist/config/__tests__/findProjectRootSync.test.js.map +0 -1
- package/dist/config/__tests__/getCliConfigSync.test.js +0 -31
- package/dist/config/__tests__/getCliConfigSync.test.js.map +0 -1
- package/dist/util/__tests__/createExpiringConfig.test.js +0 -400
- package/dist/util/__tests__/createExpiringConfig.test.js.map +0 -1
- package/dist/util/__tests__/parseStringFlag.test.js +0 -43
- package/dist/util/__tests__/parseStringFlag.test.js.map +0 -1
|
@@ -10,8 +10,10 @@ export declare const cliConfigSchema: z.ZodObject<{
|
|
|
10
10
|
}, z.core.$strip>>;
|
|
11
11
|
app: z.ZodOptional<z.ZodObject<{
|
|
12
12
|
entry: z.ZodOptional<z.ZodString>;
|
|
13
|
+
icon: z.ZodOptional<z.ZodString>;
|
|
13
14
|
id: z.ZodOptional<z.ZodString>;
|
|
14
15
|
organizationId: z.ZodOptional<z.ZodString>;
|
|
16
|
+
title: z.ZodOptional<z.ZodString>;
|
|
15
17
|
}, z.core.$strip>>;
|
|
16
18
|
autoUpdates: z.ZodOptional<z.ZodBoolean>;
|
|
17
19
|
deployment: z.ZodOptional<z.ZodObject<{
|
|
@@ -86,4 +88,17 @@ export declare const cliConfigSchema: z.ZodObject<{
|
|
|
86
88
|
}, z.core.$strip>>;
|
|
87
89
|
studioHost: z.ZodOptional<z.ZodString>;
|
|
88
90
|
vite: z.ZodOptional<z.ZodCustom<UserViteConfig, UserViteConfig>>;
|
|
91
|
+
typegen: z.ZodOptional<z.ZodCustom<{
|
|
92
|
+
path: string | string[];
|
|
93
|
+
schema: string;
|
|
94
|
+
generates: string;
|
|
95
|
+
formatGeneratedCode: boolean;
|
|
96
|
+
overloadClientMethods: boolean;
|
|
97
|
+
}, {
|
|
98
|
+
path: string | string[];
|
|
99
|
+
schema: string;
|
|
100
|
+
generates: string;
|
|
101
|
+
formatGeneratedCode: boolean;
|
|
102
|
+
overloadClientMethods: boolean;
|
|
103
|
+
}>>;
|
|
89
104
|
}, z.core.$strip>;
|
|
@@ -8,8 +8,10 @@ import { z } from 'zod';
|
|
|
8
8
|
}).optional(),
|
|
9
9
|
app: z.object({
|
|
10
10
|
entry: z.string().optional(),
|
|
11
|
+
icon: z.string().optional(),
|
|
11
12
|
id: z.string().optional(),
|
|
12
|
-
organizationId: z.string().optional()
|
|
13
|
+
organizationId: z.string().optional(),
|
|
14
|
+
title: z.string().optional()
|
|
13
15
|
}).optional(),
|
|
14
16
|
autoUpdates: z.boolean().optional(),
|
|
15
17
|
deployment: z.object({
|
|
@@ -43,7 +45,8 @@ import { z } from 'zod';
|
|
|
43
45
|
port: z.number().optional()
|
|
44
46
|
}).optional(),
|
|
45
47
|
studioHost: z.string().optional(),
|
|
46
|
-
vite: z.custom().optional()
|
|
48
|
+
vite: z.custom().optional(),
|
|
49
|
+
typegen: z.custom().optional()
|
|
47
50
|
});
|
|
48
51
|
|
|
49
52
|
//# sourceMappingURL=schemas.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/config/cli/schemas.ts"],"sourcesContent":["import {type PluginOptions as ReactCompilerConfig} from 'babel-plugin-react-compiler'\nimport {z} from 'zod'\n\nimport {type CliConfig} from './types/cliConfig'\nimport {type UserViteConfig} from './types/userViteConfig'\n\n/**\n * @public\n */\nexport const cliConfigSchema = z.object({\n api: z\n .object({\n dataset: z.string().optional(),\n projectId: z.string().optional(),\n })\n .optional(),\n\n app: z\n .object({\n entry: z.string().optional(),\n id: z.string().optional(),\n organizationId: z.string().optional(),\n })\n .optional(),\n\n autoUpdates: z.boolean().optional(),\n\n deployment: z\n .object({\n appId: z.string().optional(),\n autoUpdates: z.boolean().optional(),\n })\n .optional(),\n\n graphql: z\n .array(\n z.object({\n filterSuffix: z.string().optional(),\n generation: z.enum(['gen1', 'gen2', 'gen3']).optional(),\n id: z.string().optional(),\n nonNullDocumentFields: z.boolean().optional(),\n playground: z.boolean().optional(),\n source: z.string().optional(),\n tag: z.string().optional(),\n workspace: z.string().optional(),\n }),\n )\n .optional(),\n\n mediaLibrary: z\n .object({\n aspectsPath: z.string().optional(),\n })\n .optional(),\n\n project: z\n .object({\n basePath: z.string().optional(),\n })\n .optional(),\n\n reactCompiler: z.custom<ReactCompilerConfig>().optional(),\n\n reactStrictMode: z.boolean().optional(),\n\n server: z\n .object({\n hostname: z.string().optional(),\n port: z.number().optional(),\n })\n .optional(),\n\n studioHost: z.string().optional(),\n\n vite: z.custom<UserViteConfig>().optional(),\n}) satisfies z.ZodType<CliConfig>\n"],"names":["z","cliConfigSchema","object","api","dataset","string","optional","projectId","app","entry","id","organizationId","autoUpdates","boolean","deployment","appId","graphql","array","filterSuffix","generation","enum","nonNullDocumentFields","playground","source","tag","workspace","mediaLibrary","aspectsPath","project","basePath","reactCompiler","custom","reactStrictMode","server","hostname","port","number","studioHost","vite"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/config/cli/schemas.ts"],"sourcesContent":["import {type TypeGenConfig} from '@sanity/codegen'\nimport {type PluginOptions as ReactCompilerConfig} from 'babel-plugin-react-compiler'\nimport {z} from 'zod'\n\nimport {type CliConfig} from './types/cliConfig'\nimport {type UserViteConfig} from './types/userViteConfig'\n\n/**\n * @public\n */\nexport const cliConfigSchema = z.object({\n api: z\n .object({\n dataset: z.string().optional(),\n projectId: z.string().optional(),\n })\n .optional(),\n\n app: z\n .object({\n entry: z.string().optional(),\n icon: z.string().optional(),\n id: z.string().optional(),\n organizationId: z.string().optional(),\n title: z.string().optional(),\n })\n .optional(),\n\n autoUpdates: z.boolean().optional(),\n\n deployment: z\n .object({\n appId: z.string().optional(),\n autoUpdates: z.boolean().optional(),\n })\n .optional(),\n\n graphql: z\n .array(\n z.object({\n filterSuffix: z.string().optional(),\n generation: z.enum(['gen1', 'gen2', 'gen3']).optional(),\n id: z.string().optional(),\n nonNullDocumentFields: z.boolean().optional(),\n playground: z.boolean().optional(),\n source: z.string().optional(),\n tag: z.string().optional(),\n workspace: z.string().optional(),\n }),\n )\n .optional(),\n\n mediaLibrary: z\n .object({\n aspectsPath: z.string().optional(),\n })\n .optional(),\n\n project: z\n .object({\n basePath: z.string().optional(),\n })\n .optional(),\n\n reactCompiler: z.custom<ReactCompilerConfig>().optional(),\n\n reactStrictMode: z.boolean().optional(),\n\n server: z\n .object({\n hostname: z.string().optional(),\n port: z.number().optional(),\n })\n .optional(),\n\n studioHost: z.string().optional(),\n\n vite: z.custom<UserViteConfig>().optional(),\n\n typegen: z.custom<TypeGenConfig>().optional(),\n}) satisfies z.ZodType<CliConfig>\n"],"names":["z","cliConfigSchema","object","api","dataset","string","optional","projectId","app","entry","icon","id","organizationId","title","autoUpdates","boolean","deployment","appId","graphql","array","filterSuffix","generation","enum","nonNullDocumentFields","playground","source","tag","workspace","mediaLibrary","aspectsPath","project","basePath","reactCompiler","custom","reactStrictMode","server","hostname","port","number","studioHost","vite","typegen"],"mappings":"AAEA,SAAQA,CAAC,QAAO,MAAK;AAKrB;;CAEC,GACD,OAAO,MAAMC,kBAAkBD,EAAEE,MAAM,CAA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/B,GACCA,QAAQ;IAEX0B,eAAehC,EAAEiC,MAAM,GAAwB3B,QAAQ;IAEvD4B,iBAAiBlC,EAAEe,OAAO,GAAGT,QAAQ;IAErC6B,QAAQnC,EACLE,MAAM,CAAC;QACNkC,UAAUpC,EAAEK,MAAM,GAAGC,QAAQ;QAC7B+B,MAAMrC,EAAEsC,MAAM,GAAGhC,QAAQ;IAC3B,GACCA,QAAQ;IAEXiC,YAAYvC,EAAEK,MAAM,GAAGC,QAAQ;IAE/BkC,MAAMxC,EAAEiC,MAAM,GAAmB3B,QAAQ;IAEzCmC,SAASzC,EAAEiC,MAAM,GAAkB3B,QAAQ;AAC7C,GAAiC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type TypeGenConfig } from '@sanity/codegen';
|
|
1
2
|
import { type PluginOptions as ReactCompilerConfig } from 'babel-plugin-react-compiler';
|
|
2
3
|
import { type UserViteConfig } from './userViteConfig';
|
|
3
4
|
/**
|
|
@@ -13,10 +14,14 @@ export interface CliConfig {
|
|
|
13
14
|
app?: {
|
|
14
15
|
/** The entrypoint for your custom app. By default, `src/App.tsx` */
|
|
15
16
|
entry?: string;
|
|
17
|
+
/** String encoding of an icon (typically an SVG) */
|
|
18
|
+
icon?: string;
|
|
16
19
|
/** @deprecated Use deployment.appId */
|
|
17
20
|
id?: string;
|
|
18
21
|
/** The ID for the Sanity organization that manages this application */
|
|
19
22
|
organizationId?: string;
|
|
23
|
+
/** The title of the custom app. Used in Dashboard and in the browser tab */
|
|
24
|
+
title?: string;
|
|
20
25
|
};
|
|
21
26
|
/** @deprecated Use deployment.autoUpdates */
|
|
22
27
|
autoUpdates?: boolean;
|
|
@@ -69,6 +74,10 @@ export interface CliConfig {
|
|
|
69
74
|
};
|
|
70
75
|
/** @deprecated Use deployment.appId */
|
|
71
76
|
studioHost?: string;
|
|
77
|
+
/**
|
|
78
|
+
* Configuration for Sanity typegen
|
|
79
|
+
*/
|
|
80
|
+
typegen?: Partial<TypeGenConfig>;
|
|
72
81
|
/** Exposes the default Vite configuration for custom apps and the Studio so it can be changed and extended. */
|
|
73
82
|
vite?: UserViteConfig;
|
|
74
83
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/config/cli/types/cliConfig.ts"],"sourcesContent":["import {type PluginOptions as ReactCompilerConfig} from 'babel-plugin-react-compiler'\n\nimport {type UserViteConfig} from './userViteConfig'\n\n/**\n * @public\n */\nexport interface CliConfig {\n /** The project ID and dataset the Sanity CLI should use to run its commands */\n api?: {\n dataset?: string\n projectId?: string\n }\n\n /** Configuration for custom Sanity apps built with the App SDK */\n app?: {\n /** The entrypoint for your custom app. By default, `src/App.tsx` */\n entry?: string\n /** @deprecated Use deployment.appId */\n id?: string\n /** The ID for the Sanity organization that manages this application */\n organizationId?: string\n }\n\n /** @deprecated Use deployment.autoUpdates */\n autoUpdates?: boolean\n\n /** Options for custom app and Studio deployments */\n deployment?: {\n /**\n * The ID for your custom app or Studio. Generated when deploying your app or Studio for the first time.\n * Get your app ID by either:\n * 1. Checking the output of `sanity deploy`, or\n * 2. Checking your project’s Studio tab at https://sanity.io/manage\n *\n * @remarks This is required for all custom app deployments, and for Studios opting in to fine grained version control.\n * {@link https://www.sanity.io/docs/studio/latest-version-of-sanity#k0896ed4574b7}\n */\n appId?: string\n /**\n * Enable automatic updates for your Studio or custom app’s Sanity dependencies.\n * {@link https://www.sanity.io/docs/studio/latest-version-of-sanity}\n */\n autoUpdates?: boolean\n }\n\n /** Define the GraphQL APIs that the CLI can deploy and interact with */\n graphql?: Array<{\n filterSuffix?: string\n generation?: 'gen1' | 'gen2' | 'gen3'\n id?: string\n nonNullDocumentFields?: boolean\n playground?: boolean\n source?: string\n tag?: string\n workspace?: string\n }>\n\n /** Configuration for the Media Library */\n mediaLibrary?: {\n /** The path to the Media Library aspects directory. When using the CLI to manage aspects, this is the directory they will be read from and written to. */\n aspectsPath?: string\n }\n\n /** Contains the property `basePath` which lets you change the top-level slug for the Studio. You typically need to set this if you embed the Studio in another application where it is one of many routes. Defaults to an empty string. */\n project?: {\n basePath?: string\n }\n\n /** Configuration options for React Compiler */\n reactCompiler?: ReactCompilerConfig\n\n /** Wraps the Studio in \\<React.StrictMode\\> root to aid in flagging potential problems related to concurrent features (startTransition, useTransition, useDeferredValue, Suspense). Can also be enabled by setting SANITY_STUDIO_REACT_STRICT_MODE=\"true\"|\"false\". It only applies to sanity dev in development mode and is ignored in sanity build and in production. Defaults to false. */\n reactStrictMode?: boolean\n\n /** Defines the hostname and port that the development server should run on. hostname defaults to localhost, and port to 3333. */\n server?: {\n hostname?: string\n port?: number\n }\n\n /** @deprecated Use deployment.appId */\n studioHost?: string\n\n /** Exposes the default Vite configuration for custom apps and the Studio so it can be changed and extended. */\n vite?: UserViteConfig\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/config/cli/types/cliConfig.ts"],"sourcesContent":["import {type TypeGenConfig} from '@sanity/codegen'\nimport {type PluginOptions as ReactCompilerConfig} from 'babel-plugin-react-compiler'\n\nimport {type UserViteConfig} from './userViteConfig'\n\n/**\n * @public\n */\nexport interface CliConfig {\n /** The project ID and dataset the Sanity CLI should use to run its commands */\n api?: {\n dataset?: string\n projectId?: string\n }\n\n /** Configuration for custom Sanity apps built with the App SDK */\n app?: {\n /** The entrypoint for your custom app. By default, `src/App.tsx` */\n entry?: string\n /** String encoding of an icon (typically an SVG) */\n icon?: string\n /** @deprecated Use deployment.appId */\n id?: string\n /** The ID for the Sanity organization that manages this application */\n organizationId?: string\n /** The title of the custom app. Used in Dashboard and in the browser tab */\n title?: string\n }\n\n /** @deprecated Use deployment.autoUpdates */\n autoUpdates?: boolean\n\n /** Options for custom app and Studio deployments */\n deployment?: {\n /**\n * The ID for your custom app or Studio. Generated when deploying your app or Studio for the first time.\n * Get your app ID by either:\n * 1. Checking the output of `sanity deploy`, or\n * 2. Checking your project’s Studio tab at https://sanity.io/manage\n *\n * @remarks This is required for all custom app deployments, and for Studios opting in to fine grained version control.\n * {@link https://www.sanity.io/docs/studio/latest-version-of-sanity#k0896ed4574b7}\n */\n appId?: string\n /**\n * Enable automatic updates for your Studio or custom app’s Sanity dependencies.\n * {@link https://www.sanity.io/docs/studio/latest-version-of-sanity}\n */\n autoUpdates?: boolean\n }\n\n /** Define the GraphQL APIs that the CLI can deploy and interact with */\n graphql?: Array<{\n filterSuffix?: string\n generation?: 'gen1' | 'gen2' | 'gen3'\n id?: string\n nonNullDocumentFields?: boolean\n playground?: boolean\n source?: string\n tag?: string\n workspace?: string\n }>\n\n /** Configuration for the Media Library */\n mediaLibrary?: {\n /** The path to the Media Library aspects directory. When using the CLI to manage aspects, this is the directory they will be read from and written to. */\n aspectsPath?: string\n }\n\n /** Contains the property `basePath` which lets you change the top-level slug for the Studio. You typically need to set this if you embed the Studio in another application where it is one of many routes. Defaults to an empty string. */\n project?: {\n basePath?: string\n }\n\n /** Configuration options for React Compiler */\n reactCompiler?: ReactCompilerConfig\n\n /** Wraps the Studio in \\<React.StrictMode\\> root to aid in flagging potential problems related to concurrent features (startTransition, useTransition, useDeferredValue, Suspense). Can also be enabled by setting SANITY_STUDIO_REACT_STRICT_MODE=\"true\"|\"false\". It only applies to sanity dev in development mode and is ignored in sanity build and in production. Defaults to false. */\n reactStrictMode?: boolean\n\n /** Defines the hostname and port that the development server should run on. hostname defaults to localhost, and port to 3333. */\n server?: {\n hostname?: string\n port?: number\n }\n\n /** @deprecated Use deployment.appId */\n studioHost?: string\n\n /**\n * Configuration for Sanity typegen\n */\n typegen?: Partial<TypeGenConfig>\n\n /** Exposes the default Vite configuration for custom apps and the Studio so it can be changed and extended. */\n vite?: UserViteConfig\n}\n"],"names":[],"mappings":"AAKA;;CAEC,GACD,WAwFC"}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { isMainThread } from 'node:worker_threads';
|
|
2
|
-
import { createServer, loadEnv, mergeConfig } from 'vite';
|
|
3
|
-
import { ViteNodeRunner } from 'vite-node/client';
|
|
4
|
-
import { ViteNodeServer } from 'vite-node/server';
|
|
5
|
-
import { installSourcemapsSupport } from 'vite-node/source-map';
|
|
2
|
+
import { createServer, createServerModuleRunner, loadEnv, mergeConfig } from 'vite';
|
|
6
3
|
import { getCliConfig } from '../../config/cli/getCliConfig.js';
|
|
7
4
|
import { getStudioEnvironmentVariables } from '../../util/environment/getStudioEnvironmentVariables.js';
|
|
8
5
|
import { setupBrowserStubs } from '../../util/environment/setupBrowserStubs.js';
|
|
@@ -74,26 +71,14 @@ const env = loadEnv(server.config.mode, server.config.envDir, '');
|
|
|
74
71
|
for(const key in env){
|
|
75
72
|
process.env[key] ??= env[key];
|
|
76
73
|
}
|
|
77
|
-
// Now we're
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
getSourceMap: (source)=>node.getSourceMap(source)
|
|
74
|
+
// Now we're using Vite's Module Runner (replaces vite-node in Vite 4+)
|
|
75
|
+
const runner = await createServerModuleRunner(server.environments.ssr, {
|
|
76
|
+
hmr: false,
|
|
77
|
+
sourcemapInterceptor: 'prepareStackTrace'
|
|
82
78
|
});
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
},
|
|
88
|
-
resolveId (id, importer) {
|
|
89
|
-
return node.resolveId(id, importer);
|
|
90
|
-
},
|
|
91
|
-
root: server.config.root
|
|
92
|
-
});
|
|
93
|
-
// Copied from `vite-node` - it appears that this applies the `define` config from
|
|
94
|
-
// vite, but it also takes a surprisingly long time to execute. Not clear at this
|
|
95
|
-
// point why this is, so we should investigate whether it's necessary or not.
|
|
96
|
-
await runner.executeId('/@vite/env');
|
|
97
|
-
await runner.executeId(workerScriptPath);
|
|
79
|
+
// Apply the `define` config from vite - imports environment variables
|
|
80
|
+
await runner.import('/@vite/env');
|
|
81
|
+
// Execute the worker script
|
|
82
|
+
await runner.import(workerScriptPath);
|
|
98
83
|
|
|
99
84
|
//# sourceMappingURL=studioWorkerLoader.worker.js.map
|
|
@@ -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'\
|
|
1
|
+
{"version":3,"sources":["../../../src/loaders/studio/studioWorkerLoader.worker.ts"],"sourcesContent":["import {isMainThread} from 'node:worker_threads'\n\nimport {createServer, createServerModuleRunner, type InlineConfig, loadEnv, mergeConfig} from 'vite'\n\nimport {getCliConfig} from '../../config/cli/getCliConfig.js'\nimport {type CliConfig} from '../../config/cli/types/cliConfig.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 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\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 logLevel: 'error',\n optimizeDeps: {disabled: true}, // @todo is this necessary? cant remember why was added\n root: rootPath,\n server: {\n hmr: false,\n watch: null,\n },\n}\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 if (!isNotFoundError(err)) {\n console.warn('[warn] Failed to load CLI config:', err)\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\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, '')\nfor (const key in env) {\n process.env[key] ??= env[key]\n}\n\n// Now we're using Vite's Module Runner (replaces vite-node in Vite 4+)\nconst runner = await createServerModuleRunner(server.environments.ssr, {\n hmr: false,\n sourcemapInterceptor: 'prepareStackTrace',\n})\n\n// Apply the `define` config from vite - imports environment variables\nawait runner.import('/@vite/env')\n\n// Execute the worker script\nawait runner.import(workerScriptPath)\n"],"names":["isMainThread","createServer","createServerModuleRunner","loadEnv","mergeConfig","getCliConfig","getStudioEnvironmentVariables","setupBrowserStubs","isRecord","isNotFoundError","Error","rootPath","process","env","STUDIO_WORKER_STUDIO_ROOT_PATH","workerScriptPath","STUDIO_WORKER_TASK_FILE","studioEnvVars","defaultViteConfig","build","target","configFile","define","Object","fromEntries","entries","map","key","value","JSON","stringify","logLevel","optimizeDeps","disabled","root","server","hmr","watch","cliConfig","err","console","warn","viteConfig","vite","command","isSsrBuild","mode","pluginContainer","buildStart","config","envDir","runner","environments","ssr","sourcemapInterceptor","import"],"mappings":"AAA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J,UAAUK,IAAI,CAACD,YAAY;QAC7CE,SAAS;QACTC,YAAY;QACZC,MAAM;IACR;AACF,OAAO,IAAItC,SAAS8B,WAAWK,OAAO;IACpCD,aAAatC,YAAYsC,YAAYJ,UAAUK,IAAI;AACrD;AAEA,oFAAoF;AACpF,4FAA4F;AAC5F,MAAMR,SAAS,MAAMlC,aAAayC;AAElC,oFAAoF;AACpF,MAAMP,OAAOY,eAAe,CAACC,UAAU,CAAC,CAAC;AAEzC,6EAA6E;AAC7E,mGAAmG;AACnG,sCAAsC;AACtC,qCAAqC;AACrC,MAAMnC,MAAMV,QAAQgC,OAAOc,MAAM,CAACH,IAAI,EAAEX,OAAOc,MAAM,CAACC,MAAM,EAAE;AAC9D,IAAK,MAAMvB,OAAOd,IAAK;IACrBD,QAAQC,GAAG,CAACc,IAAI,KAAKd,GAAG,CAACc,IAAI;AAC/B;AAEA,uEAAuE;AACvE,MAAMwB,SAAS,MAAMjD,yBAAyBiC,OAAOiB,YAAY,CAACC,GAAG,EAAE;IACrEjB,KAAK;IACLkB,sBAAsB;AACxB;AAEA,sEAAsE;AACtE,MAAMH,OAAOI,MAAM,CAAC;AAEpB,4BAA4B;AAC5B,MAAMJ,OAAOI,MAAM,CAACxC"}
|
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.7",
|
|
4
4
|
"description": "Sanity CLI core package",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"author": "Sanity.io <hello@sanity.io>",
|
|
23
|
+
"sideEffects": false,
|
|
23
24
|
"type": "module",
|
|
24
25
|
"exports": {
|
|
25
26
|
".": {
|
|
@@ -48,7 +49,7 @@
|
|
|
48
49
|
"@inquirer/prompts": "^8.1.0",
|
|
49
50
|
"@oclif/core": "^4.8.0",
|
|
50
51
|
"@sanity/client": "^7.14.0",
|
|
51
|
-
"@sanity/types": "^5.
|
|
52
|
+
"@sanity/types": "^5.5.0",
|
|
52
53
|
"babel-plugin-react-compiler": "^1.0.0",
|
|
53
54
|
"chalk": "^5.6.2",
|
|
54
55
|
"configstore": "^7.0.0",
|
|
@@ -60,20 +61,21 @@
|
|
|
60
61
|
"log-symbols": "^7.0.1",
|
|
61
62
|
"ora": "^9.0.0",
|
|
62
63
|
"tsx": "^4.21.0",
|
|
63
|
-
"vite": "^7.3.
|
|
64
|
-
"vite-node": "^3.0.8",
|
|
64
|
+
"vite": "^7.3.1",
|
|
65
65
|
"zod": "^4.3.5"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@eslint/compat": "^2.0.
|
|
68
|
+
"@eslint/compat": "^2.0.1",
|
|
69
|
+
"@sanity/codegen": "^5.5.0",
|
|
69
70
|
"@swc/cli": "^0.7.9",
|
|
70
71
|
"@swc/core": "^1.15.8",
|
|
71
72
|
"@types/debug": "^4.1.12",
|
|
72
73
|
"@types/jsdom": "^27.0.0",
|
|
73
|
-
"@types/node": "^20.19.
|
|
74
|
+
"@types/node": "^20.19.30",
|
|
74
75
|
"eslint": "^9.39.2",
|
|
76
|
+
"publint": "^0.3.16",
|
|
75
77
|
"typescript": "^5.9.3",
|
|
76
|
-
"vitest": "^
|
|
78
|
+
"vitest": "^4.0.17",
|
|
77
79
|
"@repo/tsconfig": "3.70.0",
|
|
78
80
|
"@sanity/eslint-config-cli": "0.0.0-alpha.1"
|
|
79
81
|
},
|
|
@@ -84,10 +86,11 @@
|
|
|
84
86
|
"access": "public"
|
|
85
87
|
},
|
|
86
88
|
"scripts": {
|
|
87
|
-
"build": "swc --delete-dir-on-start --strip-leading-paths --out-dir dist/ src",
|
|
89
|
+
"build": "swc --delete-dir-on-start --strip-leading-paths --out-dir dist/ src --ignore '**/*.test.ts'",
|
|
88
90
|
"build:types": "tsc --project tsconfig.lib.json",
|
|
89
91
|
"check:types": "tsc --noEmit",
|
|
90
92
|
"lint": "eslint .",
|
|
93
|
+
"publint": "publint",
|
|
91
94
|
"test": "vitest run",
|
|
92
95
|
"posttest": "pnpm run lint",
|
|
93
96
|
"test:coverage": "vitest run --coverage",
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import { getConfig } from '../../services/cliUserConfig';
|
|
3
|
-
import * as cliTokenModule from '../../services/getCliToken';
|
|
4
|
-
vi.mock('../../services/cliUserConfig', ()=>({
|
|
5
|
-
getConfig: vi.fn()
|
|
6
|
-
}));
|
|
7
|
-
describe('getCliToken', ()=>{
|
|
8
|
-
const originalEnv = process.env;
|
|
9
|
-
let cachedToken;
|
|
10
|
-
beforeEach(()=>{
|
|
11
|
-
process.env = {
|
|
12
|
-
...originalEnv
|
|
13
|
-
};
|
|
14
|
-
vi.clearAllMocks();
|
|
15
|
-
vi.resetModules();
|
|
16
|
-
cachedToken = undefined;
|
|
17
|
-
vi.spyOn(cliTokenModule, 'getCliToken').mockImplementation(async ()=>{
|
|
18
|
-
if (cachedToken !== undefined) {
|
|
19
|
-
return cachedToken;
|
|
20
|
-
}
|
|
21
|
-
const token = process.env.SANITY_AUTH_TOKEN;
|
|
22
|
-
if (token) {
|
|
23
|
-
cachedToken = token.trim();
|
|
24
|
-
return cachedToken;
|
|
25
|
-
}
|
|
26
|
-
cachedToken = await getConfig('authToken');
|
|
27
|
-
return cachedToken;
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
afterEach(()=>{
|
|
31
|
-
process.env = originalEnv;
|
|
32
|
-
vi.restoreAllMocks();
|
|
33
|
-
});
|
|
34
|
-
it('should return token from environment variable', async ()=>{
|
|
35
|
-
process.env.SANITY_AUTH_TOKEN = 'test-token';
|
|
36
|
-
const token = await cliTokenModule.getCliToken();
|
|
37
|
-
expect(token).toBe('test-token');
|
|
38
|
-
expect(getConfig).not.toHaveBeenCalled();
|
|
39
|
-
});
|
|
40
|
-
it('should return token from config if no environment variable is set', async ()=>{
|
|
41
|
-
delete process.env.SANITY_AUTH_TOKEN;
|
|
42
|
-
vi.mocked(getConfig).mockResolvedValueOnce('config-token');
|
|
43
|
-
const token = await cliTokenModule.getCliToken();
|
|
44
|
-
expect(token).toBe('config-token');
|
|
45
|
-
expect(getConfig).toHaveBeenCalledWith('authToken');
|
|
46
|
-
});
|
|
47
|
-
it('should return undefined if no token is available', async ()=>{
|
|
48
|
-
delete process.env.SANITY_AUTH_TOKEN;
|
|
49
|
-
vi.mocked(getConfig).mockResolvedValueOnce(undefined);
|
|
50
|
-
const token = await cliTokenModule.getCliToken();
|
|
51
|
-
expect(token).toBeUndefined();
|
|
52
|
-
expect(getConfig).toHaveBeenCalledWith('authToken');
|
|
53
|
-
});
|
|
54
|
-
it('should cache the token from environment variable', async ()=>{
|
|
55
|
-
process.env.SANITY_AUTH_TOKEN = 'cached-env-token';
|
|
56
|
-
const firstCall = await cliTokenModule.getCliToken();
|
|
57
|
-
process.env.SANITY_AUTH_TOKEN = 'new-token';
|
|
58
|
-
const secondCall = await cliTokenModule.getCliToken();
|
|
59
|
-
expect(firstCall).toBe('cached-env-token');
|
|
60
|
-
expect(secondCall).toBe('cached-env-token');
|
|
61
|
-
expect(getConfig).not.toHaveBeenCalled();
|
|
62
|
-
});
|
|
63
|
-
it('should cache the token from config', async ()=>{
|
|
64
|
-
delete process.env.SANITY_AUTH_TOKEN;
|
|
65
|
-
vi.mocked(getConfig).mockResolvedValueOnce('cached-config-token');
|
|
66
|
-
const firstCall = await cliTokenModule.getCliToken();
|
|
67
|
-
const secondCall = await cliTokenModule.getCliToken();
|
|
68
|
-
expect(firstCall).toBe('cached-config-token');
|
|
69
|
-
expect(secondCall).toBe('cached-config-token');
|
|
70
|
-
expect(getConfig).toHaveBeenCalledTimes(1);
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
//# sourceMappingURL=cliToken.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/config/__tests__/cliToken.test.ts"],"sourcesContent":["import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest'\n\nimport {getConfig} from '../../services/cliUserConfig'\nimport * as cliTokenModule from '../../services/getCliToken'\n\nvi.mock('../../services/cliUserConfig', () => ({\n getConfig: vi.fn(),\n}))\n\ndescribe('getCliToken', () => {\n const originalEnv = process.env\n let cachedToken: string | undefined\n\n beforeEach(() => {\n process.env = {...originalEnv}\n vi.clearAllMocks()\n vi.resetModules()\n cachedToken = undefined\n vi.spyOn(cliTokenModule, 'getCliToken').mockImplementation(async () => {\n if (cachedToken !== undefined) {\n return cachedToken\n }\n\n const token = process.env.SANITY_AUTH_TOKEN\n if (token) {\n cachedToken = token.trim()\n return cachedToken\n }\n\n cachedToken = await getConfig('authToken')\n return cachedToken\n })\n })\n\n afterEach(() => {\n process.env = originalEnv\n vi.restoreAllMocks()\n })\n\n it('should return token from environment variable', async () => {\n process.env.SANITY_AUTH_TOKEN = 'test-token'\n const token = await cliTokenModule.getCliToken()\n expect(token).toBe('test-token')\n expect(getConfig).not.toHaveBeenCalled()\n })\n\n it('should return token from config if no environment variable is set', async () => {\n delete process.env.SANITY_AUTH_TOKEN\n vi.mocked(getConfig).mockResolvedValueOnce('config-token')\n\n const token = await cliTokenModule.getCliToken()\n expect(token).toBe('config-token')\n expect(getConfig).toHaveBeenCalledWith('authToken')\n })\n\n it('should return undefined if no token is available', async () => {\n delete process.env.SANITY_AUTH_TOKEN\n vi.mocked(getConfig).mockResolvedValueOnce(undefined)\n\n const token = await cliTokenModule.getCliToken()\n expect(token).toBeUndefined()\n expect(getConfig).toHaveBeenCalledWith('authToken')\n })\n\n it('should cache the token from environment variable', async () => {\n process.env.SANITY_AUTH_TOKEN = 'cached-env-token'\n\n const firstCall = await cliTokenModule.getCliToken()\n process.env.SANITY_AUTH_TOKEN = 'new-token'\n const secondCall = await cliTokenModule.getCliToken()\n\n expect(firstCall).toBe('cached-env-token')\n expect(secondCall).toBe('cached-env-token')\n expect(getConfig).not.toHaveBeenCalled()\n })\n\n it('should cache the token from config', async () => {\n delete process.env.SANITY_AUTH_TOKEN\n vi.mocked(getConfig).mockResolvedValueOnce('cached-config-token')\n\n const firstCall = await cliTokenModule.getCliToken()\n const secondCall = await cliTokenModule.getCliToken()\n\n expect(firstCall).toBe('cached-config-token')\n expect(secondCall).toBe('cached-config-token')\n expect(getConfig).toHaveBeenCalledTimes(1)\n })\n})\n"],"names":["afterEach","beforeEach","describe","expect","it","vi","getConfig","cliTokenModule","mock","fn","originalEnv","process","env","cachedToken","clearAllMocks","resetModules","undefined","spyOn","mockImplementation","token","SANITY_AUTH_TOKEN","trim","restoreAllMocks","getCliToken","toBe","not","toHaveBeenCalled","mocked","mockResolvedValueOnce","toHaveBeenCalledWith","toBeUndefined","firstCall","secondCall","toHaveBeenCalledTimes"],"mappings":"AAAA,SAAQA,SAAS,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAO,SAAQ;AAEtE,SAAQC,SAAS,QAAO,+BAA8B;AACtD,YAAYC,oBAAoB,6BAA4B;AAE5DF,GAAGG,IAAI,CAAC,gCAAgC,IAAO,CAAA;QAC7CF,WAAWD,GAAGI,EAAE;IAClB,CAAA;AAEAP,SAAS,eAAe;IACtB,MAAMQ,cAAcC,QAAQC,GAAG;IAC/B,IAAIC;IAEJZ,WAAW;QACTU,QAAQC,GAAG,GAAG;YAAC,GAAGF,WAAW;QAAA;QAC7BL,GAAGS,aAAa;QAChBT,GAAGU,YAAY;QACfF,cAAcG;QACdX,GAAGY,KAAK,CAACV,gBAAgB,eAAeW,kBAAkB,CAAC;YACzD,IAAIL,gBAAgBG,WAAW;gBAC7B,OAAOH;YACT;YAEA,MAAMM,QAAQR,QAAQC,GAAG,CAACQ,iBAAiB;YAC3C,IAAID,OAAO;gBACTN,cA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ACrB,WAAWsB,qBAAqB,CAAC;QAE3C,MAAMG,YAAY,MAAMxB,eAAegB,WAAW;QAClD,MAAMS,aAAa,MAAMzB,eAAegB,WAAW;QAEnDpB,OAAO4B,WAAWP,IAAI,CAAC;QACvBrB,OAAO6B,YAAYR,IAAI,CAAC;QACxBrB,OAAOG,WAAW2B,qBAAqB,CAAC;IAC1C;AACF"}
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import { mkdir } from 'node:fs/promises';
|
|
2
|
-
import { homedir } from 'node:os';
|
|
3
|
-
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
|
|
4
|
-
import { getConfig, setConfig } from '../../services/cliUserConfig';
|
|
5
|
-
import { readJsonFile } from '../../util/readJsonFile';
|
|
6
|
-
import { writeJsonFile } from '../../util/writeJsonFile';
|
|
7
|
-
vi.mock('node:fs/promises');
|
|
8
|
-
vi.mock('node:os');
|
|
9
|
-
vi.mock('../../util/readJsonFile');
|
|
10
|
-
vi.mock('../../util/writeJsonFile');
|
|
11
|
-
const mockHomedir = '/mock/home/dir';
|
|
12
|
-
describe('cliUserConfig', ()=>{
|
|
13
|
-
beforeEach(()=>{
|
|
14
|
-
vi.resetAllMocks();
|
|
15
|
-
vi.mocked(homedir).mockReturnValue(mockHomedir);
|
|
16
|
-
vi.mocked(mkdir).mockResolvedValue(undefined);
|
|
17
|
-
vi.mocked(readJsonFile).mockResolvedValue({});
|
|
18
|
-
vi.mocked(writeJsonFile).mockResolvedValue();
|
|
19
|
-
});
|
|
20
|
-
afterEach(()=>{
|
|
21
|
-
vi.resetAllMocks();
|
|
22
|
-
});
|
|
23
|
-
describe('readConfig behavior', ()=>{
|
|
24
|
-
test('returns empty config when file read fails', async ()=>{
|
|
25
|
-
vi.mocked(readJsonFile).mockRejectedValueOnce(new Error('File not found'));
|
|
26
|
-
const result = await getConfig('authToken');
|
|
27
|
-
expect(result).toBeUndefined();
|
|
28
|
-
});
|
|
29
|
-
test('returns empty config when file content is null', async ()=>{
|
|
30
|
-
vi.mocked(readJsonFile).mockResolvedValueOnce(null);
|
|
31
|
-
const result = await getConfig('authToken');
|
|
32
|
-
expect(result).toBeUndefined();
|
|
33
|
-
});
|
|
34
|
-
test('returns empty config when file content is an array', async ()=>{
|
|
35
|
-
vi.mocked(readJsonFile).mockResolvedValueOnce([]);
|
|
36
|
-
const result = await getConfig('authToken');
|
|
37
|
-
expect(result).toBeUndefined();
|
|
38
|
-
});
|
|
39
|
-
test('returns empty config when file content is not an object', async ()=>{
|
|
40
|
-
vi.mocked(readJsonFile).mockResolvedValueOnce('not an object');
|
|
41
|
-
const result = await getConfig('authToken');
|
|
42
|
-
expect(result).toBeUndefined();
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
describe('getConfig', ()=>{
|
|
46
|
-
test('returns authToken when valid', async ()=>{
|
|
47
|
-
vi.mocked(readJsonFile).mockResolvedValueOnce({
|
|
48
|
-
authToken: 'test-token'
|
|
49
|
-
});
|
|
50
|
-
const result = await getConfig('authToken');
|
|
51
|
-
expect(result).toBe('test-token');
|
|
52
|
-
});
|
|
53
|
-
test('returns undefined when authToken is not set', async ()=>{
|
|
54
|
-
vi.mocked(readJsonFile).mockResolvedValueOnce({});
|
|
55
|
-
const result = await getConfig('authToken');
|
|
56
|
-
expect(result).toBeUndefined();
|
|
57
|
-
});
|
|
58
|
-
test('returns telemetryConsent when valid', async ()=>{
|
|
59
|
-
const mockConsent = {
|
|
60
|
-
updatedAt: Date.now(),
|
|
61
|
-
value: {
|
|
62
|
-
status: 'granted',
|
|
63
|
-
type: 'explicit'
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
vi.mocked(readJsonFile).mockResolvedValueOnce({
|
|
67
|
-
telemetryConsent: mockConsent
|
|
68
|
-
});
|
|
69
|
-
const result = await getConfig('telemetryConsent');
|
|
70
|
-
expect(result).toEqual(mockConsent);
|
|
71
|
-
});
|
|
72
|
-
test('throws error for invalid property', async ()=>{
|
|
73
|
-
await expect(getConfig('invalidProp')).rejects.toThrow('No schema defined');
|
|
74
|
-
});
|
|
75
|
-
test('throws error for invalid value type', async ()=>{
|
|
76
|
-
vi.mocked(readJsonFile).mockResolvedValueOnce({
|
|
77
|
-
authToken: 123
|
|
78
|
-
});
|
|
79
|
-
await expect(getConfig('authToken')).rejects.toThrow('Invalid value');
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
describe('setConfig', ()=>{
|
|
83
|
-
test('sets valid authToken', async ()=>{
|
|
84
|
-
await setConfig('authToken', 'new-token');
|
|
85
|
-
expect(mkdir).toHaveBeenCalledWith(expect.any(String), {
|
|
86
|
-
recursive: true
|
|
87
|
-
});
|
|
88
|
-
expect(writeJsonFile).toHaveBeenCalledWith(expect.any(String), expect.objectContaining({
|
|
89
|
-
authToken: 'new-token'
|
|
90
|
-
}), expect.any(Object));
|
|
91
|
-
});
|
|
92
|
-
test('sets valid telemetryConsent', async ()=>{
|
|
93
|
-
const mockConsent = {
|
|
94
|
-
updatedAt: Date.now(),
|
|
95
|
-
value: {
|
|
96
|
-
status: 'granted',
|
|
97
|
-
type: 'explicit'
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
await setConfig('telemetryConsent', mockConsent);
|
|
101
|
-
expect(writeJsonFile).toHaveBeenCalledWith(expect.any(String), expect.objectContaining({
|
|
102
|
-
telemetryConsent: mockConsent
|
|
103
|
-
}), expect.any(Object));
|
|
104
|
-
});
|
|
105
|
-
test('throws error for invalid property', async ()=>{
|
|
106
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
107
|
-
await expect(setConfig('invalidProp', 'value')).rejects.toThrow('No schema defined');
|
|
108
|
-
});
|
|
109
|
-
test('throws error for invalid value type', async ()=>{
|
|
110
|
-
await expect(setConfig('authToken', 123)).rejects.toThrow('Invalid value');
|
|
111
|
-
});
|
|
112
|
-
test('merges new config with existing config', async ()=>{
|
|
113
|
-
vi.mocked(readJsonFile).mockResolvedValueOnce({
|
|
114
|
-
authToken: 'existing-token'
|
|
115
|
-
});
|
|
116
|
-
await setConfig('telemetryConsent', {
|
|
117
|
-
updatedAt: 123,
|
|
118
|
-
value: {
|
|
119
|
-
status: 'granted',
|
|
120
|
-
type: 'explicit'
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
expect(writeJsonFile).toHaveBeenCalledWith(expect.any(String), expect.objectContaining({
|
|
124
|
-
authToken: 'existing-token',
|
|
125
|
-
telemetryConsent: expect.any(Object)
|
|
126
|
-
}), expect.any(Object));
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
//# sourceMappingURL=cliUserConfig.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/config/__tests__/cliUserConfig.test.ts"],"sourcesContent":["import {mkdir} from 'node:fs/promises'\nimport {homedir} from 'node:os'\n\nimport {afterEach, beforeEach, describe, expect, test, vi} from 'vitest'\n\nimport {getConfig, setConfig} from '../../services/cliUserConfig'\nimport {readJsonFile} from '../../util/readJsonFile'\nimport {writeJsonFile} from '../../util/writeJsonFile'\n\nvi.mock('node:fs/promises')\nvi.mock('node:os')\nvi.mock('../../util/readJsonFile')\nvi.mock('../../util/writeJsonFile')\n\nconst mockHomedir = '/mock/home/dir'\n\ndescribe('cliUserConfig', () => {\n beforeEach(() => {\n vi.resetAllMocks()\n vi.mocked(homedir).mockReturnValue(mockHomedir)\n vi.mocked(mkdir).mockResolvedValue(undefined)\n vi.mocked(readJsonFile).mockResolvedValue({})\n vi.mocked(writeJsonFile).mockResolvedValue()\n })\n\n afterEach(() => {\n vi.resetAllMocks()\n })\n\n describe('readConfig behavior', () => {\n test('returns empty config when file read fails', async () => {\n vi.mocked(readJsonFile).mockRejectedValueOnce(new Error('File not found'))\n const result = await getConfig('authToken')\n expect(result).toBeUndefined()\n })\n\n test('returns empty config when file content is null', async () => {\n vi.mocked(readJsonFile).mockResolvedValueOnce(null)\n const result = await getConfig('authToken')\n expect(result).toBeUndefined()\n })\n\n test('returns empty config when file content is an array', async () => {\n vi.mocked(readJsonFile).mockResolvedValueOnce([])\n const result = await getConfig('authToken')\n expect(result).toBeUndefined()\n })\n\n test('returns empty config when file content is not an object', async () => {\n vi.mocked(readJsonFile).mockResolvedValueOnce('not an object')\n const result = await getConfig('authToken')\n expect(result).toBeUndefined()\n })\n })\n\n describe('getConfig', () => {\n test('returns authToken when valid', async () => {\n vi.mocked(readJsonFile).mockResolvedValueOnce({\n authToken: 'test-token',\n })\n\n const result = await getConfig('authToken')\n expect(result).toBe('test-token')\n })\n\n test('returns undefined when authToken is not set', async () => {\n vi.mocked(readJsonFile).mockResolvedValueOnce({})\n\n const result = await getConfig('authToken')\n expect(result).toBeUndefined()\n })\n\n test('returns telemetryConsent when valid', async () => {\n const mockConsent = {\n updatedAt: Date.now(),\n value: {\n status: 'granted',\n type: 'explicit',\n },\n }\n vi.mocked(readJsonFile).mockResolvedValueOnce({\n telemetryConsent: mockConsent,\n })\n\n const result = await getConfig('telemetryConsent')\n expect(result).toEqual(mockConsent)\n })\n\n test('throws error for invalid property', async () => {\n await expect(getConfig('invalidProp' as never)).rejects.toThrow('No schema defined')\n })\n\n test('throws error for invalid value type', async () => {\n vi.mocked(readJsonFile).mockResolvedValueOnce({\n authToken: 123, // Invalid type, should be string\n })\n\n await expect(getConfig('authToken')).rejects.toThrow('Invalid value')\n })\n })\n\n describe('setConfig', () => {\n test('sets valid authToken', async () => {\n await setConfig('authToken', 'new-token')\n\n expect(mkdir).toHaveBeenCalledWith(expect.any(String), {recursive: true})\n expect(writeJsonFile).toHaveBeenCalledWith(\n expect.any(String),\n expect.objectContaining({\n authToken: 'new-token',\n }),\n expect.any(Object),\n )\n })\n\n test('sets valid telemetryConsent', async () => {\n const mockConsent = {\n updatedAt: Date.now(),\n value: {\n status: 'granted' as const,\n type: 'explicit',\n },\n }\n\n await setConfig('telemetryConsent', mockConsent)\n\n expect(writeJsonFile).toHaveBeenCalledWith(\n expect.any(String),\n expect.objectContaining({\n telemetryConsent: mockConsent,\n }),\n expect.any(Object),\n )\n })\n\n test('throws error for invalid property', async () => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n await expect(setConfig('invalidProp' as any, 'value')).rejects.toThrow('No schema defined')\n })\n\n test('throws error for invalid value type', async () => {\n await expect(setConfig('authToken', 123 as never)).rejects.toThrow('Invalid value')\n })\n\n test('merges new config with existing config', async () => {\n vi.mocked(readJsonFile).mockResolvedValueOnce({\n authToken: 'existing-token',\n })\n\n await setConfig('telemetryConsent', {\n updatedAt: 123,\n value: {\n status: 'granted' as const,\n type: 'explicit',\n },\n })\n\n expect(writeJsonFile).toHaveBeenCalledWith(\n expect.any(String),\n expect.objectContaining({\n authToken: 'existing-token',\n telemetryConsent: expect.any(Object),\n }),\n expect.any(Object),\n )\n })\n })\n})\n"],"names":["mkdir","homedir","afterEach","beforeEach","describe","expect","test","vi","getConfig","setConfig","readJsonFile","writeJsonFile","mock","mockHomedir","resetAllMocks","mocked","mockReturnValue","mockResolvedValue","undefined","mockRejectedValueOnce","Error","result","toBeUndefined","mockResolvedValueOnce","authToken","toBe","mockConsent","updatedAt","Date","now","value","status","type","telemetryConsent","toEqual","rejects","toThrow","toHaveBeenCalledWith","any","String","recursive","objectContaining","Object"],"mappings":"AAAA,SAAQA,KAAK,QAAO,mBAAkB;AACtC,SAAQC,OAAO,QAAO,UAAS;AAE/B,SAAQC,SAAS,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,IAAI,EAAEC,EAAE,QAAO,SAAQ;AAExE,SAAQC,SAAS,EAAEC,SAAS,QAAO,+BAA8B;AACjE,SAAQC,YAAY,QAAO,0BAAyB;AACpD,SAAQC,aAAa,QAAO,2BAA0B;AAEtDJ,GAAGK,IAAI,CAAC;AACRL,GAAGK,IAAI,CAAC;AACRL,GAAGK,IAAI,CAAC;AACRL,GAAGK,IAAI,CAAC;AAER,MAAMC,cAAc;AAEpBT,SAAS,iBAAiB;IACxBD,WAAW;QACTI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