@sanity/cli-core 0.0.2-alpha.1 → 0.0.2-alpha.2
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/SanityCommand.d.ts +1 -1
- package/dist/SanityCommand.js.map +1 -1
- package/dist/config/__tests__/findProjectRootSync.test.js +112 -0
- package/dist/config/__tests__/findProjectRootSync.test.js.map +1 -0
- package/dist/config/__tests__/getCliConfigSync.test.js +31 -0
- package/dist/config/__tests__/getCliConfigSync.test.js.map +1 -0
- package/dist/config/cli/getCliConfig.d.ts +1 -1
- package/dist/config/cli/getCliConfig.js +9 -8
- package/dist/config/cli/getCliConfig.js.map +1 -1
- package/dist/config/cli/getCliConfigSync.d.ts +12 -0
- package/dist/config/cli/getCliConfigSync.js +51 -0
- package/dist/config/cli/getCliConfigSync.js.map +1 -0
- package/dist/config/cli/schemas.d.ts +121 -70
- package/dist/config/cli/schemas.js +13 -41
- package/dist/config/cli/schemas.js.map +1 -1
- package/dist/config/cli/types/cliConfig.d.ts +74 -0
- package/dist/config/cli/types/cliConfig.js +5 -0
- package/dist/config/cli/types/cliConfig.js.map +1 -0
- package/dist/config/cli/types/userViteConfig.d.ts +5 -0
- package/dist/config/cli/types/userViteConfig.js +5 -0
- package/dist/config/cli/types/userViteConfig.js.map +1 -0
- package/dist/config/findProjectRootSync.d.ts +27 -0
- package/dist/config/findProjectRootSync.js +82 -0
- package/dist/config/findProjectRootSync.js.map +1 -0
- package/dist/config/studio/readStudioConfig.worker.js +2 -16
- package/dist/config/studio/readStudioConfig.worker.js.map +1 -1
- package/dist/config/util/configPathsSync.d.ts +17 -0
- package/dist/config/util/configPathsSync.js +85 -0
- package/dist/config/util/configPathsSync.js.map +1 -0
- package/dist/config/util/isSanityV2StudioRoot.js +3 -0
- package/dist/config/util/isSanityV2StudioRoot.js.map +1 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/loaders/studio/studioWorkerLoader.worker.js +9 -27
- package/dist/loaders/studio/studioWorkerLoader.worker.js.map +1 -1
- package/dist/services/apiClient.js +12 -6
- package/dist/services/apiClient.js.map +1 -1
- package/dist/util/__tests__/createExpiringConfig.test.js +91 -0
- package/dist/util/__tests__/createExpiringConfig.test.js.map +1 -1
- package/dist/util/createExpiringConfig.d.ts +6 -1
- package/dist/util/createExpiringConfig.js +28 -3
- package/dist/util/createExpiringConfig.js.map +1 -1
- package/dist/util/environment/getStudioEnvironmentVariables.d.ts +12 -0
- package/dist/util/environment/getStudioEnvironmentVariables.js +33 -0
- package/dist/util/environment/getStudioEnvironmentVariables.js.map +1 -0
- package/dist/util/environment/mockBrowserEnvironment.d.ts +17 -0
- package/dist/util/environment/mockBrowserEnvironment.js +46 -0
- package/dist/util/environment/mockBrowserEnvironment.js.map +1 -0
- package/dist/util/environment/setupBrowserStubs.d.ts +10 -0
- package/dist/util/environment/setupBrowserStubs.js +43 -0
- package/dist/util/environment/setupBrowserStubs.js.map +1 -0
- package/dist/{loaders/studio → util/environment}/stubs.d.ts +6 -6
- package/dist/util/environment/stubs.js.map +1 -0
- package/dist/util/getEmptyAuth.d.ts +5 -0
- package/dist/util/getEmptyAuth.js +16 -0
- package/dist/util/getEmptyAuth.js.map +1 -0
- package/dist/util/readJsonFile.d.ts +7 -1
- package/dist/util/readJsonFile.js.map +1 -1
- package/dist/util/safeStructuredClone.js +3 -0
- package/dist/util/safeStructuredClone.js.map +1 -1
- package/dist/util/tryGetDefaultExport.d.ts +5 -0
- package/dist/util/tryGetDefaultExport.js +18 -0
- package/dist/util/tryGetDefaultExport.js.map +1 -0
- package/package.json +10 -9
- package/dist/config/cli/types.d.ts +0 -13
- package/dist/config/cli/types.js +0 -3
- package/dist/config/cli/types.js.map +0 -1
- package/dist/loaders/studio/stubs.js.map +0 -1
- /package/dist/{loaders/studio → util/environment}/stubs.js +0 -0
package/dist/SanityCommand.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Command, Interfaces } from '@oclif/core';
|
|
2
|
-
import { type CliConfig } from './config/cli/types.js';
|
|
2
|
+
import { type CliConfig } from './config/cli/types/cliConfig.js';
|
|
3
3
|
import { type ProjectRootResult } from './config/util/recursivelyResolveProjectRoot.js';
|
|
4
4
|
import { type GlobalCliClientOptions, type ProjectCliClientOptions } from './services/apiClient.js';
|
|
5
5
|
import { type Output } from './types.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/SanityCommand.ts"],"sourcesContent":["import {Command, Interfaces} from '@oclif/core'\n\nimport {getCliConfig} from './config/cli/getCliConfig.js'\nimport {type CliConfig} from './config/cli/types.js'\nimport {findProjectRoot} from './config/findProjectRoot.js'\nimport {type ProjectRootResult} from './config/util/recursivelyResolveProjectRoot.js'\nimport {\n getGlobalCliClient,\n getProjectCliClient,\n type GlobalCliClientOptions,\n type ProjectCliClientOptions,\n} from './services/apiClient.js'\nimport {type Output} from './types.js'\n\ntype Flags<T extends typeof Command> = Interfaces.InferredFlags<\n (typeof SanityCommand)['baseFlags'] & T['flags']\n>\n\ntype Args<T extends typeof Command> = Interfaces.InferredArgs<T['args']>\n\nexport abstract class SanityCommand<T extends typeof Command> extends Command {\n protected args!: Args<T>\n protected flags!: Flags<T>\n\n /**\n * Get the global API client.\n *\n * @param args - The global API client options.\n * @returns The global API client.\n */\n protected getGlobalApiClient = (args: GlobalCliClientOptions) => getGlobalCliClient(args)\n\n /**\n * Get the project API client.\n *\n * @param args - The project API client options.\n * @returns The project API client.\n */\n protected getProjectApiClient = (args: ProjectCliClientOptions) => getProjectCliClient(args)\n\n /**\n * Helper for outputting to the console.\n *\n * @example\n * ```ts\n * this.output.log('Hello')\n * this.output.warn('Warning')\n * this.output.error('Error')\n * ```\n */\n protected output: Output = {\n error: this.error.bind(this),\n log: this.log.bind(this),\n warn: this.warn.bind(this),\n }\n\n /**\n * Get the CLI config.\n *\n * @returns The CLI config.\n */\n protected async getCliConfig(): Promise<CliConfig> {\n const root = await this.getProjectRoot()\n const config = await getCliConfig(root.directory)\n\n return config\n }\n\n /**\n * Get the project ID from the CLI config.\n *\n * @returns The project ID or `undefined` if it's not set.\n */\n protected async getProjectId(): Promise<string | undefined> {\n const config = await this.getCliConfig()\n\n return config.api?.projectId\n }\n\n /**\n * Get the project's root directory by resolving the config\n *\n * @returns The root project root.\n */\n protected getProjectRoot(): Promise<ProjectRootResult> {\n return findProjectRoot(process.cwd())\n }\n\n public async init(): Promise<void> {\n const {args, flags} = await this.parse({\n args: this.ctor.args,\n baseFlags: (super.ctor as typeof SanityCommand).baseFlags,\n enableJsonFlag: this.ctor.enableJsonFlag,\n flags: this.ctor.flags,\n strict: this.ctor.strict,\n })\n\n this.args = args as Args<T>\n this.flags = flags as Flags<T>\n\n await super.init()\n }\n}\n"],"names":["Command","getCliConfig","findProjectRoot","getGlobalCliClient","getProjectCliClient","SanityCommand","args","flags","getGlobalApiClient","getProjectApiClient","output","error","bind","log","warn","root","getProjectRoot","config","directory","getProjectId","api","projectId","process","cwd","init","parse","ctor","baseFlags","enableJsonFlag","strict"],"mappings":"AAAA,SAAQA,OAAO,QAAmB,cAAa;AAE/C,SAAQC,YAAY,QAAO,+BAA8B;AAEzD,SAAQC,eAAe,QAAO,8BAA6B;AAE3D,SACEC,kBAAkB,EAClBC,mBAAmB,QAGd,0BAAyB;AAShC,OAAO,MAAeC,sBAAgDL;IAC1DM,KAAc;IACdC,MAAgB;IAE1B;;;;;GAKC,GACD,AAAUC,qBAAqB,CAACF,OAAiCH,mBAAmBG,MAAK;IAEzF;;;;;GAKC,GACD,AAAUG,sBAAsB,CAACH,OAAkCF,oBAAoBE,MAAK;IAE5F;;;;;;;;;GASC,GACD,AAAUI,SAAiB;QACzBC,OAAO,IAAI,CAACA,KAAK,CAACC,IAAI,CAAC,IAAI;QAC3BC,KAAK,IAAI,CAACA,GAAG,CAACD,IAAI,CAAC,IAAI;QACvBE,MAAM,IAAI,CAACA,IAAI,CAACF,IAAI,CAAC,IAAI;IAC3B,EAAC;IAED;;;;GAIC,GACD,MAAgBX,eAAmC;QACjD,MAAMc,OAAO,MAAM,IAAI,CAACC,cAAc;QACtC,MAAMC,SAAS,MAAMhB,aAAac,KAAKG,SAAS;QAEhD,OAAOD;IACT;IAEA;;;;GAIC,GACD,MAAgBE,eAA4C;QAC1D,MAAMF,SAAS,MAAM,IAAI,CAAChB,YAAY;QAEtC,OAAOgB,OAAOG,GAAG,EAAEC;IACrB;IAEA;;;;GAIC,GACD,AAAUL,iBAA6C;QACrD,OAAOd,gBAAgBoB,QAAQC,GAAG;IACpC;IAEA,MAAaC,OAAsB;QACjC,MAAM,EAAClB,IAAI,EAAEC,KAAK,EAAC,GAAG,MAAM,IAAI,CAACkB,KAAK,CAAC;YACrCnB,MAAM,IAAI,CAACoB,IAAI,CAACpB,IAAI;YACpBqB,WAAW,AAAC,KAAK,CAACD,KAA8BC,SAAS;YACzDC,gBAAgB,IAAI,CAACF,IAAI,CAACE,cAAc;YACxCrB,OAAO,IAAI,CAACmB,IAAI,CAACnB,KAAK;YACtBsB,QAAQ,IAAI,CAACH,IAAI,CAACG,MAAM;QAC1B;QAEA,IAAI,CAACvB,IAAI,GAAGA;QACZ,IAAI,CAACC,KAAK,GAAGA;QAEb,MAAM,KAAK,CAACiB;IACd;AACF"}
|
|
1
|
+
{"version":3,"sources":["../src/SanityCommand.ts"],"sourcesContent":["import {Command, Interfaces} from '@oclif/core'\n\nimport {getCliConfig} from './config/cli/getCliConfig.js'\nimport {type CliConfig} from './config/cli/types/cliConfig.js'\nimport {findProjectRoot} from './config/findProjectRoot.js'\nimport {type ProjectRootResult} from './config/util/recursivelyResolveProjectRoot.js'\nimport {\n getGlobalCliClient,\n getProjectCliClient,\n type GlobalCliClientOptions,\n type ProjectCliClientOptions,\n} from './services/apiClient.js'\nimport {type Output} from './types.js'\n\ntype Flags<T extends typeof Command> = Interfaces.InferredFlags<\n (typeof SanityCommand)['baseFlags'] & T['flags']\n>\n\ntype Args<T extends typeof Command> = Interfaces.InferredArgs<T['args']>\n\nexport abstract class SanityCommand<T extends typeof Command> extends Command {\n protected args!: Args<T>\n protected flags!: Flags<T>\n\n /**\n * Get the global API client.\n *\n * @param args - The global API client options.\n * @returns The global API client.\n */\n protected getGlobalApiClient = (args: GlobalCliClientOptions) => getGlobalCliClient(args)\n\n /**\n * Get the project API client.\n *\n * @param args - The project API client options.\n * @returns The project API client.\n */\n protected getProjectApiClient = (args: ProjectCliClientOptions) => getProjectCliClient(args)\n\n /**\n * Helper for outputting to the console.\n *\n * @example\n * ```ts\n * this.output.log('Hello')\n * this.output.warn('Warning')\n * this.output.error('Error')\n * ```\n */\n protected output: Output = {\n error: this.error.bind(this),\n log: this.log.bind(this),\n warn: this.warn.bind(this),\n }\n\n /**\n * Get the CLI config.\n *\n * @returns The CLI config.\n */\n protected async getCliConfig(): Promise<CliConfig> {\n const root = await this.getProjectRoot()\n const config = await getCliConfig(root.directory)\n\n return config\n }\n\n /**\n * Get the project ID from the CLI config.\n *\n * @returns The project ID or `undefined` if it's not set.\n */\n protected async getProjectId(): Promise<string | undefined> {\n const config = await this.getCliConfig()\n\n return config.api?.projectId\n }\n\n /**\n * Get the project's root directory by resolving the config\n *\n * @returns The root project root.\n */\n protected getProjectRoot(): Promise<ProjectRootResult> {\n return findProjectRoot(process.cwd())\n }\n\n public async init(): Promise<void> {\n const {args, flags} = await this.parse({\n args: this.ctor.args,\n baseFlags: (super.ctor as typeof SanityCommand).baseFlags,\n enableJsonFlag: this.ctor.enableJsonFlag,\n flags: this.ctor.flags,\n strict: this.ctor.strict,\n })\n\n this.args = args as Args<T>\n this.flags = flags as Flags<T>\n\n await super.init()\n }\n}\n"],"names":["Command","getCliConfig","findProjectRoot","getGlobalCliClient","getProjectCliClient","SanityCommand","args","flags","getGlobalApiClient","getProjectApiClient","output","error","bind","log","warn","root","getProjectRoot","config","directory","getProjectId","api","projectId","process","cwd","init","parse","ctor","baseFlags","enableJsonFlag","strict"],"mappings":"AAAA,SA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AACG,MAAM;QAC1B;QAEA,IAAI,CAACvB,IAAI,GAAGA;QACZ,IAAI,CAACC,KAAK,GAAGA;QAEb,MAAM,KAAK,CAACiB;IACd;AACF"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
|
|
3
|
+
import { findProjectRootSync } from '../findProjectRootSync';
|
|
4
|
+
// Mock node:fs since configPathsSync uses it directly
|
|
5
|
+
vi.mock('node:fs', async ()=>{
|
|
6
|
+
const actual = await vi.importActual('node:fs');
|
|
7
|
+
return {
|
|
8
|
+
...actual,
|
|
9
|
+
existsSync: vi.fn(),
|
|
10
|
+
readFileSync: vi.fn()
|
|
11
|
+
};
|
|
12
|
+
});
|
|
13
|
+
describe('findProjectRootSync', ()=>{
|
|
14
|
+
const mockCwd = '/mock/project/path';
|
|
15
|
+
beforeEach(()=>{
|
|
16
|
+
vi.clearAllMocks();
|
|
17
|
+
});
|
|
18
|
+
afterEach(()=>{
|
|
19
|
+
vi.resetAllMocks();
|
|
20
|
+
});
|
|
21
|
+
test('finds a TypeScript studio config in the current directory', async ()=>{
|
|
22
|
+
const { existsSync } = await import('node:fs');
|
|
23
|
+
vi.mocked(existsSync).mockImplementation((path)=>{
|
|
24
|
+
return path === join(mockCwd, 'sanity.config.ts');
|
|
25
|
+
});
|
|
26
|
+
const result = findProjectRootSync(mockCwd);
|
|
27
|
+
expect(result).toEqual({
|
|
28
|
+
directory: mockCwd,
|
|
29
|
+
path: join(mockCwd, 'sanity.config.ts'),
|
|
30
|
+
type: 'studio'
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
test('finds a JavaScript studio config in the current directory', async ()=>{
|
|
34
|
+
const { existsSync } = await import('node:fs');
|
|
35
|
+
vi.mocked(existsSync).mockImplementation((path)=>{
|
|
36
|
+
return path === join(mockCwd, 'sanity.config.js');
|
|
37
|
+
});
|
|
38
|
+
const result = findProjectRootSync(mockCwd);
|
|
39
|
+
expect(result).toEqual({
|
|
40
|
+
directory: mockCwd,
|
|
41
|
+
path: join(mockCwd, 'sanity.config.js'),
|
|
42
|
+
type: 'studio'
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
test('finds a TypeScript app config in the current directory', async ()=>{
|
|
46
|
+
const { existsSync } = await import('node:fs');
|
|
47
|
+
vi.mocked(existsSync).mockImplementation((path)=>{
|
|
48
|
+
return path === join(mockCwd, 'sanity.cli.ts');
|
|
49
|
+
});
|
|
50
|
+
const result = findProjectRootSync(mockCwd);
|
|
51
|
+
expect(result).toEqual({
|
|
52
|
+
directory: mockCwd,
|
|
53
|
+
path: join(mockCwd, 'sanity.cli.ts'),
|
|
54
|
+
type: 'app'
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
test('finds a JavaScript app config in the current directory', async ()=>{
|
|
58
|
+
const { existsSync } = await import('node:fs');
|
|
59
|
+
vi.mocked(existsSync).mockImplementation((path)=>{
|
|
60
|
+
return path === join(mockCwd, 'sanity.cli.js');
|
|
61
|
+
});
|
|
62
|
+
const result = findProjectRootSync(mockCwd);
|
|
63
|
+
expect(result).toEqual({
|
|
64
|
+
directory: mockCwd,
|
|
65
|
+
path: join(mockCwd, 'sanity.cli.js'),
|
|
66
|
+
type: 'app'
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
test('prioritizes studio config over app config when both are present', async ()=>{
|
|
70
|
+
const { existsSync } = await import('node:fs');
|
|
71
|
+
vi.mocked(existsSync).mockImplementation((path)=>{
|
|
72
|
+
return path === join(mockCwd, 'sanity.config.ts') || path === join(mockCwd, 'sanity.cli.ts');
|
|
73
|
+
});
|
|
74
|
+
const result = findProjectRootSync(mockCwd);
|
|
75
|
+
expect(result).toEqual({
|
|
76
|
+
directory: mockCwd,
|
|
77
|
+
path: join(mockCwd, 'sanity.config.ts'),
|
|
78
|
+
type: 'studio'
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
test('recursively searches parent directories for config', async ()=>{
|
|
82
|
+
const { existsSync } = await import('node:fs');
|
|
83
|
+
const parentPath = '/mock/project';
|
|
84
|
+
vi.mocked(existsSync).mockImplementation((path)=>{
|
|
85
|
+
return path === join(parentPath, 'sanity.config.ts');
|
|
86
|
+
});
|
|
87
|
+
const result = findProjectRootSync(mockCwd);
|
|
88
|
+
expect(result).toEqual({
|
|
89
|
+
directory: parentPath,
|
|
90
|
+
path: join(parentPath, 'sanity.config.ts'),
|
|
91
|
+
type: 'studio'
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
test('throws error when no config is found', async ()=>{
|
|
95
|
+
const { existsSync, readFileSync } = await import('node:fs');
|
|
96
|
+
vi.mocked(existsSync).mockReturnValue(false);
|
|
97
|
+
vi.mocked(readFileSync).mockReturnValue(JSON.stringify({
|
|
98
|
+
root: false
|
|
99
|
+
}));
|
|
100
|
+
expect(()=>findProjectRootSync(mockCwd)).toThrow('No project root found');
|
|
101
|
+
});
|
|
102
|
+
test('throws error when v2 studio root is found', async ()=>{
|
|
103
|
+
const { existsSync, readFileSync } = await import('node:fs');
|
|
104
|
+
vi.mocked(existsSync).mockReturnValue(false);
|
|
105
|
+
vi.mocked(readFileSync).mockReturnValue(JSON.stringify({
|
|
106
|
+
root: true
|
|
107
|
+
}));
|
|
108
|
+
expect(()=>findProjectRootSync(mockCwd)).toThrow("Found 'sanity.json' at /mock/project/path - Sanity Studio < v3 is no longer supported");
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
//# sourceMappingURL=findProjectRootSync.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/config/__tests__/findProjectRootSync.test.ts"],"sourcesContent":["import {join} from 'node:path'\n\nimport {afterEach, beforeEach, describe, expect, test, vi} from 'vitest'\n\nimport {findProjectRootSync} from '../findProjectRootSync'\n\n// Mock node:fs since configPathsSync uses it directly\nvi.mock('node:fs', async () => {\n const actual = await vi.importActual('node:fs')\n return {\n ...actual,\n existsSync: vi.fn(),\n readFileSync: vi.fn(),\n }\n})\n\ndescribe('findProjectRootSync', () => {\n const mockCwd = '/mock/project/path'\n\n beforeEach(() => {\n vi.clearAllMocks()\n })\n\n afterEach(() => {\n vi.resetAllMocks()\n })\n\n test('finds a TypeScript studio config in the current directory', async () => {\n const {existsSync} = await import('node:fs')\n\n vi.mocked(existsSync).mockImplementation((path) => {\n return path === join(mockCwd, 'sanity.config.ts')\n })\n\n const result = findProjectRootSync(mockCwd)\n expect(result).toEqual({\n directory: mockCwd,\n path: join(mockCwd, 'sanity.config.ts'),\n type: 'studio',\n })\n })\n\n test('finds a JavaScript studio config in the current directory', async () => {\n const {existsSync} = await import('node:fs')\n\n vi.mocked(existsSync).mockImplementation((path) => {\n return path === join(mockCwd, 'sanity.config.js')\n })\n\n const result = findProjectRootSync(mockCwd)\n expect(result).toEqual({\n directory: mockCwd,\n path: join(mockCwd, 'sanity.config.js'),\n type: 'studio',\n })\n })\n\n test('finds a TypeScript app config in the current directory', async () => {\n const {existsSync} = await import('node:fs')\n\n vi.mocked(existsSync).mockImplementation((path) => {\n return path === join(mockCwd, 'sanity.cli.ts')\n })\n\n const result = findProjectRootSync(mockCwd)\n expect(result).toEqual({\n directory: mockCwd,\n path: join(mockCwd, 'sanity.cli.ts'),\n type: 'app',\n })\n })\n\n test('finds a JavaScript app config in the current directory', async () => {\n const {existsSync} = await import('node:fs')\n\n vi.mocked(existsSync).mockImplementation((path) => {\n return path === join(mockCwd, 'sanity.cli.js')\n })\n\n const result = findProjectRootSync(mockCwd)\n expect(result).toEqual({\n directory: mockCwd,\n path: join(mockCwd, 'sanity.cli.js'),\n type: 'app',\n })\n })\n\n test('prioritizes studio config over app config when both are present', async () => {\n const {existsSync} = await import('node:fs')\n\n vi.mocked(existsSync).mockImplementation((path) => {\n return path === join(mockCwd, 'sanity.config.ts') || path === join(mockCwd, 'sanity.cli.ts')\n })\n\n const result = findProjectRootSync(mockCwd)\n expect(result).toEqual({\n directory: mockCwd,\n path: join(mockCwd, 'sanity.config.ts'),\n type: 'studio',\n })\n })\n\n test('recursively searches parent directories for config', async () => {\n const {existsSync} = await import('node:fs')\n const parentPath = '/mock/project'\n\n vi.mocked(existsSync).mockImplementation((path) => {\n return path === join(parentPath, 'sanity.config.ts')\n })\n\n const result = findProjectRootSync(mockCwd)\n expect(result).toEqual({\n directory: parentPath,\n path: join(parentPath, 'sanity.config.ts'),\n type: 'studio',\n })\n })\n\n test('throws error when no config is found', async () => {\n const {existsSync, readFileSync} = await import('node:fs')\n\n vi.mocked(existsSync).mockReturnValue(false)\n vi.mocked(readFileSync).mockReturnValue(JSON.stringify({root: false}))\n\n expect(() => findProjectRootSync(mockCwd)).toThrow('No project root found')\n })\n\n test('throws error when v2 studio root is found', async () => {\n const {existsSync, readFileSync} = await import('node:fs')\n\n vi.mocked(existsSync).mockReturnValue(false)\n vi.mocked(readFileSync).mockReturnValue(JSON.stringify({root: true}))\n\n expect(() => findProjectRootSync(mockCwd)).toThrow(\n \"Found 'sanity.json' at /mock/project/path - Sanity Studio < v3 is no longer supported\",\n )\n })\n})\n"],"names":["join","afterEach","beforeEach","describe","expect","test","vi","findProjectRootSync","mock","actual","importActual","existsSync","fn","readFileSync","mockCwd","clearAllMocks","resetAllMocks","mocked","mockImplementation","path","result","toEqual","directory","type","parentPath","mockReturnValue","JSON","stringify","root","toThrow"],"mappings":"AAAA,SAAQA,IAAI,QAAO,YAAW;AAE9B,SAAQC,SAAS,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,IAAI,EAAEC,EAAE,QAAO,SAAQ;AAExE,SAAQC,mBAAmB,QAAO,yBAAwB;AAE1D,sDAAsD;AACtDD,GAAGE,IAAI,CAAC,WAAW;IACjB,MAAMC,SAAS,MAAMH,GAAGI,YAAY,CAAC;IACrC,OAAO;QACL,GAAGD,MAAM;QACTE,YAAYL,GAAGM,EAAE;QACjBC,cAAcP,GAAGM,EAAE;IACrB;AACF;AAEAT,SAAS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AI;QAElExB,OAAO,IAAMG,oBAAoBO,UAAUe,OAAO,CAChD;IAEJ;AACF"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
|
|
2
|
+
import { getCliConfigSync } from '../cli/getCliConfigSync';
|
|
3
|
+
// Mock node:fs
|
|
4
|
+
vi.mock('node:fs', async ()=>{
|
|
5
|
+
const actual = await vi.importActual('node:fs');
|
|
6
|
+
return {
|
|
7
|
+
...actual,
|
|
8
|
+
existsSync: vi.fn()
|
|
9
|
+
};
|
|
10
|
+
});
|
|
11
|
+
describe('getCliConfigSync', ()=>{
|
|
12
|
+
const mockRootPath = '/mock/project';
|
|
13
|
+
beforeEach(()=>{
|
|
14
|
+
vi.clearAllMocks();
|
|
15
|
+
});
|
|
16
|
+
afterEach(()=>{
|
|
17
|
+
vi.resetAllMocks();
|
|
18
|
+
});
|
|
19
|
+
test('throws error when no CLI config found', async ()=>{
|
|
20
|
+
const { existsSync } = await import('node:fs');
|
|
21
|
+
vi.mocked(existsSync).mockReturnValue(false);
|
|
22
|
+
expect(()=>getCliConfigSync(mockRootPath)).toThrow('No CLI config found at');
|
|
23
|
+
});
|
|
24
|
+
test('throws error when multiple config files found', async ()=>{
|
|
25
|
+
const { existsSync } = await import('node:fs');
|
|
26
|
+
vi.mocked(existsSync).mockReturnValue(true);
|
|
27
|
+
expect(()=>getCliConfigSync(mockRootPath)).toThrow('Multiple CLI config files found');
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=getCliConfigSync.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/config/__tests__/getCliConfigSync.test.ts"],"sourcesContent":["import {afterEach, beforeEach, describe, expect, test, vi} from 'vitest'\n\nimport {getCliConfigSync} from '../cli/getCliConfigSync'\n\n// Mock node:fs\nvi.mock('node:fs', async () => {\n const actual = await vi.importActual('node:fs')\n return {\n ...actual,\n existsSync: vi.fn(),\n }\n})\n\ndescribe('getCliConfigSync', () => {\n const mockRootPath = '/mock/project'\n\n beforeEach(() => {\n vi.clearAllMocks()\n })\n\n afterEach(() => {\n vi.resetAllMocks()\n })\n\n test('throws error when no CLI config found', async () => {\n const {existsSync} = await import('node:fs')\n\n vi.mocked(existsSync).mockReturnValue(false)\n\n expect(() => getCliConfigSync(mockRootPath)).toThrow('No CLI config found at')\n })\n\n test('throws error when multiple config files found', async () => {\n const {existsSync} = await import('node:fs')\n\n vi.mocked(existsSync).mockReturnValue(true)\n\n expect(() => getCliConfigSync(mockRootPath)).toThrow('Multiple CLI config files found')\n })\n})\n"],"names":["afterEach","beforeEach","describe","expect","test","vi","getCliConfigSync","mock","actual","importActual","existsSync","fn","mockRootPath","clearAllMocks","resetAllMocks","mocked","mockReturnValue","toThrow"],"mappings":"AAAA,SAAQA,SAAS,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,IAAI,EAAEC,EAAE,QAAO,SAAQ;AAExE,SAAQC,gBAAgB,QAAO,0BAAyB;AAExD,eAAe;AACfD,GAAGE,IAAI,CAAC,WAAW;IACjB,MAAMC,SAAS,MAAMH,GAAGI,YAAY,CAAC;IACrC,OAAO;QACL,GAAGD,MAAM;QACTE,YAAYL,GAAGM,EAAE;IACnB;AACF;AAEAT,SAAS,oBAAoB;IAC3B,MAAMU,eAAe;IAErBX,WAAW;QACTI,GAAGQ,aAAa;IAClB;IAEAb,UAAU;QACRK,GAAGS,aAAa;IAClB;IAEAV,KAAK,yCAAyC;QAC5C,MAAM,EAACM,UAAU,EAAC,GAAG,MAAM,MAAM,CAAC;QAElCL,GAAGU,MAAM,CAACL,YAAYM,eAAe,CAAC;QAEtCb,OAAO,IAAMG,iBAAiBM,eAAeK,OAAO,CAAC;IACvD;IAEAb,KAAK,iDAAiD;QACpD,MAAM,EAACM,UAAU,EAAC,GAAG,MAAM,MAAM,CAAC;QAElCL,GAAGU,MAAM,CAACL,YAAYM,eAAe,CAAC;QAEtCb,OAAO,IAAMG,iBAAiBM,eAAeK,OAAO,CAAC;IACvD;AACF"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { getTsconfig } from 'get-tsconfig';
|
|
2
|
-
import {
|
|
2
|
+
import { tsImport } from 'tsx/esm/api';
|
|
3
3
|
import { debug } from '../../debug.js';
|
|
4
4
|
import { tsxWorkerTask } from '../../loaders/tsx/tsxWorkerTask.js';
|
|
5
|
-
import { isRecord } from '../../util/isRecord.js';
|
|
6
5
|
import { NotFoundError } from '../../util/NotFoundError.js';
|
|
6
|
+
import { tryGetDefaultExport } from '../../util/tryGetDefaultExport.js';
|
|
7
7
|
import { findPathForFiles } from '../util/findConfigsPaths.js';
|
|
8
8
|
import { cliConfigSchema } from './schemas.js';
|
|
9
9
|
/**
|
|
@@ -46,14 +46,15 @@ import { cliConfigSchema } from './schemas.js';
|
|
|
46
46
|
// Assuming that didn't work because of unseriazable properties, so we'll try the
|
|
47
47
|
// main thread with tsx registered.
|
|
48
48
|
const tsconfig = getTsconfig(rootPath);
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
// Ensure we get the default export (sometimes we get a bit of a mixed bag)
|
|
50
|
+
cliConfig = await tsImport(configPath, {
|
|
51
|
+
parentURL: import.meta.url,
|
|
51
52
|
tsconfig: tsconfig?.path ?? undefined
|
|
52
53
|
});
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
cliConfig = tryGetDefaultExport(cliConfig);
|
|
55
|
+
if (!cliConfig) {
|
|
56
|
+
throw new Error('Invalid CLI config structure');
|
|
57
|
+
}
|
|
57
58
|
}
|
|
58
59
|
const { data, error, success } = cliConfigSchema.safeParse(cliConfig);
|
|
59
60
|
if (!success) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/config/cli/getCliConfig.ts"],"sourcesContent":["import {getTsconfig} from 'get-tsconfig'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/config/cli/getCliConfig.ts"],"sourcesContent":["import {getTsconfig} from 'get-tsconfig'\nimport {tsImport} from 'tsx/esm/api'\n\nimport {debug} from '../../debug.js'\nimport {tsxWorkerTask} from '../../loaders/tsx/tsxWorkerTask.js'\nimport {NotFoundError} from '../../util/NotFoundError.js'\nimport {tryGetDefaultExport} from '../../util/tryGetDefaultExport.js'\nimport {findPathForFiles} from '../util/findConfigsPaths.js'\nimport {cliConfigSchema} from './schemas.js'\nimport {type CliConfig} from './types/cliConfig.js'\n\n/**\n * Get the CLI config for a project, given the root path.\n *\n * We really want to avoid loading the CLI config in the main thread, as we'll need\n * TypeScript loading logic, potentially with ts path aliases, syntax extensions and all\n * sorts of nonsense. Thus, we _attempt_ to use a worker thread - but have to fall back\n * to using the main thread if not possible. This can be the case if the configuration\n * contains non-serializable properties, such as functions. This is unfortunately used\n * by the vite config, for example.\n *\n * @param rootPath - Root path for the project, eg where `sanity.cli.(ts|js)` is located.\n * @returns The CLI config\n * @internal\n */\nexport async function getCliConfig(rootPath: string): Promise<CliConfig> {\n const paths = await findPathForFiles(rootPath, ['sanity.cli.ts', 'sanity.cli.js'])\n const configPaths = paths.filter((path) => path.exists)\n\n if (configPaths.length === 0) {\n throw new NotFoundError(`No CLI config found at ${rootPath}/sanity.cli.(ts|js)`)\n }\n\n if (configPaths.length > 1) {\n throw new Error(\n `Multiple CLI config files found (${configPaths.map((path) => path.path).join(', ')})`,\n )\n }\n\n const configPath = configPaths[0].path\n\n let cliConfig: CliConfig | undefined\n try {\n cliConfig = await tsxWorkerTask<CliConfig | undefined>(\n new URL('getCliConfig.worker.js', import.meta.url),\n {\n name: 'cliConfig',\n rootPath,\n workerData: {configPath},\n },\n )\n } catch (err) {\n debug('Failed to load CLI config in worker thread: %s', err)\n\n // Assuming that didn't work because of unseriazable properties, so we'll try the\n // main thread with tsx registered.\n const tsconfig = getTsconfig(rootPath)\n\n // Ensure we get the default export (sometimes we get a bit of a mixed bag)\n cliConfig = await tsImport(configPath, {\n parentURL: import.meta.url,\n tsconfig: tsconfig?.path ?? undefined,\n })\n cliConfig = tryGetDefaultExport(cliConfig) as CliConfig | undefined\n\n if (!cliConfig) {\n throw new Error('Invalid CLI config structure')\n }\n }\n\n const {data, error, success} = cliConfigSchema.safeParse(cliConfig)\n if (!success) {\n throw new Error(`Invalid CLI config: ${error.message}`)\n }\n\n // There is a minor difference here because of the `vite` property and how the types\n // aren't as specific as our manually typed `CliConfig` type, thus the cast.\n return data as CliConfig\n}\n"],"names":["getTsconfig","tsImport","debug","tsxWorkerTask","NotFoundError","tryGetDefaultExport","findPathForFiles","cliConfigSchema","getCliConfig","rootPath","paths","configPaths","filter","path","exists","length","Error","map","join","configPath","cliConfig","URL","url","name","workerData","err","tsconfig","parentURL","undefined","data","error","success","safeParse","message"],"mappings":"AAAA,SAAQA,WAAW,QAAO,eAAc;AACxC,SAAQC,QAAQ,QAAO,cAAa;AAEpC,SAAQC,KAAK,QAAO,iBAAgB;AACpC,SAAQC,aAAa,QAAO,qCAAoC;AAChE,SAAQC,aAAa,QAAO,8BAA6B;AACzD,SAAQC,mBAAmB,QAAO,oCAAmC;AACrE,SAAQC,gBAAgB,QAAO,8BAA6B;AAC5D,SAAQC,eAAe,QAAO,eAAc;AAG5C;;;;;;;;;;;;;CAaC,GACD,OAAO,eAAeC,aAAaC,QAAgB;IACjD,MAAMC,QAAQ,MAAMJ,iBAAiBG,UAAU;QAAC;QAAiB;KAAgB;IACjF,MAAME,cAAcD,MAAME,MAAM,CAAC,CAACC,OAASA,KAAKC,MAAM;IAEtD,IAAIH,YAAYI,MAAM,KAAK,GAAG;QAC5B,MAAM,IAAIX,cAAc,CAAC,uBAAuB,EAAEK,SAAS,mBAAmB,CAAC;IACjF;IAEA,IAAIE,YAAYI,MAAM,GAAG,GAAG;QAC1B,MAAM,IAAIC,MACR,CAAC,iCAAiC,EAAEL,YAAYM,GAAG,CAAC,CAACJ,OAASA,KAAKA,IAAI,EAAEK,IAAI,CAAC,MAAM,CAAC,CAAC;IAE1F;IAEA,MAAMC,aAAaR,WAAW,CAAC,EAAE,CAACE,IAAI;IAEtC,IAAIO;IACJ,IAAI;QACFA,YAAY,MAAMjB,cAChB,IAAIkB,IAAI,0BAA0B,YAAYC,GAAG,GACjD;YACEC,MAAM;YACNd;YACAe,YAAY;gBAACL;YAAU;QACzB;IAEJ,EAAE,OAAOM,KAAK;QACZvB,MAAM,kDAAkDuB;QAExD,iFAAiF;QACjF,mCAAmC;QACnC,MAAMC,WAAW1B,YAAYS;QAE7B,2EAA2E;QAC3EW,YAAY,MAAMnB,SAASkB,YAAY;YACrCQ,WAAW,YAAYL,GAAG;YAC1BI,UAAUA,UAAUb,QAAQe;QAC9B;QACAR,YAAYf,oBAAoBe;QAEhC,IAAI,CAACA,WAAW;YACd,MAAM,IAAIJ,MAAM;QAClB;IACF;IAEA,MAAM,EAACa,IAAI,EAAEC,KAAK,EAAEC,OAAO,EAAC,GAAGxB,gBAAgByB,SAAS,CAACZ;IACzD,IAAI,CAACW,SAAS;QACZ,MAAM,IAAIf,MAAM,CAAC,oBAAoB,EAAEc,MAAMG,OAAO,EAAE;IACxD;IAEA,oFAAoF;IACpF,4EAA4E;IAC5E,OAAOJ;AACT"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type CliConfig } from './types/cliConfig.js';
|
|
2
|
+
/**
|
|
3
|
+
* Get the CLI config for a project synchronously, given the root path.
|
|
4
|
+
*
|
|
5
|
+
* This loads the CLI config in the main thread using tsx/register for TypeScript support.
|
|
6
|
+
* Note: This is a synchronous operation and does not use worker threads like the async version.
|
|
7
|
+
*
|
|
8
|
+
* @param rootPath - Root path for the project, eg where `sanity.cli.(ts|js)` is located.
|
|
9
|
+
* @returns The CLI config
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export declare function getCliConfigSync(rootPath: string): CliConfig;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { register } from 'tsx/esm/api';
|
|
5
|
+
import { NotFoundError } from '../../util/NotFoundError.js';
|
|
6
|
+
import { tryGetDefaultExport } from '../../util/tryGetDefaultExport.js';
|
|
7
|
+
import { cliConfigSchema } from './schemas.js';
|
|
8
|
+
/**
|
|
9
|
+
* Get the CLI config for a project synchronously, given the root path.
|
|
10
|
+
*
|
|
11
|
+
* This loads the CLI config in the main thread using tsx/register for TypeScript support.
|
|
12
|
+
* Note: This is a synchronous operation and does not use worker threads like the async version.
|
|
13
|
+
*
|
|
14
|
+
* @param rootPath - Root path for the project, eg where `sanity.cli.(ts|js)` is located.
|
|
15
|
+
* @returns The CLI config
|
|
16
|
+
* @internal
|
|
17
|
+
*/ export function getCliConfigSync(rootPath) {
|
|
18
|
+
const possiblePaths = [
|
|
19
|
+
'sanity.cli.ts',
|
|
20
|
+
'sanity.cli.js'
|
|
21
|
+
].map((file)=>join(rootPath, file));
|
|
22
|
+
const configPaths = possiblePaths.filter((path)=>existsSync(path));
|
|
23
|
+
if (configPaths.length === 0) {
|
|
24
|
+
throw new NotFoundError(`No CLI config found at ${rootPath}/sanity.cli.(ts|js)`);
|
|
25
|
+
}
|
|
26
|
+
if (configPaths.length > 1) {
|
|
27
|
+
throw new Error(`Multiple CLI config files found (${configPaths.join(', ')})`);
|
|
28
|
+
}
|
|
29
|
+
const configPath = configPaths[0];
|
|
30
|
+
// Register tsx for TypeScript support
|
|
31
|
+
const unregister = register();
|
|
32
|
+
let cliConfig;
|
|
33
|
+
try {
|
|
34
|
+
// Use createRequire for synchronous loading in ESM contexts
|
|
35
|
+
// This works when tsx loader is active
|
|
36
|
+
const require = createRequire(import.meta.url);
|
|
37
|
+
const loaded = require(configPath);
|
|
38
|
+
cliConfig = tryGetDefaultExport(loaded);
|
|
39
|
+
} finally{
|
|
40
|
+
unregister();
|
|
41
|
+
}
|
|
42
|
+
const { data, error, success } = cliConfigSchema.safeParse(cliConfig);
|
|
43
|
+
if (!success) {
|
|
44
|
+
throw new Error(`Invalid CLI config: ${error.message}`);
|
|
45
|
+
}
|
|
46
|
+
// There is a minor difference here because of the `vite` property and how the types
|
|
47
|
+
// aren't as specific as our manually typed `CliConfig` type, thus the cast.
|
|
48
|
+
return data;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=getCliConfigSync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/config/cli/getCliConfigSync.ts"],"sourcesContent":["import {existsSync} from 'node:fs'\nimport {createRequire} from 'node:module'\nimport {join} from 'node:path'\n\nimport {register} from 'tsx/esm/api'\n\nimport {NotFoundError} from '../../util/NotFoundError.js'\nimport {tryGetDefaultExport} from '../../util/tryGetDefaultExport.js'\nimport {cliConfigSchema} from './schemas.js'\nimport {type CliConfig} from './types/cliConfig.js'\n\n/**\n * Get the CLI config for a project synchronously, given the root path.\n *\n * This loads the CLI config in the main thread using tsx/register for TypeScript support.\n * Note: This is a synchronous operation and does not use worker threads like the async version.\n *\n * @param rootPath - Root path for the project, eg where `sanity.cli.(ts|js)` is located.\n * @returns The CLI config\n * @internal\n */\nexport function getCliConfigSync(rootPath: string): CliConfig {\n const possiblePaths = ['sanity.cli.ts', 'sanity.cli.js'].map((file) => join(rootPath, file))\n const configPaths = possiblePaths.filter((path) => existsSync(path))\n\n if (configPaths.length === 0) {\n throw new NotFoundError(`No CLI config found at ${rootPath}/sanity.cli.(ts|js)`)\n }\n\n if (configPaths.length > 1) {\n throw new Error(`Multiple CLI config files found (${configPaths.join(', ')})`)\n }\n\n const configPath = configPaths[0]\n\n // Register tsx for TypeScript support\n const unregister = register()\n\n let cliConfig: CliConfig | undefined\n try {\n // Use createRequire for synchronous loading in ESM contexts\n // This works when tsx loader is active\n const require = createRequire(import.meta.url)\n const loaded = require(configPath)\n cliConfig = tryGetDefaultExport(loaded) as CliConfig | undefined\n } finally {\n unregister()\n }\n\n const {data, error, success} = cliConfigSchema.safeParse(cliConfig)\n if (!success) {\n throw new Error(`Invalid CLI config: ${error.message}`)\n }\n\n // There is a minor difference here because of the `vite` property and how the types\n // aren't as specific as our manually typed `CliConfig` type, thus the cast.\n return data as CliConfig\n}\n"],"names":["existsSync","createRequire","join","register","NotFoundError","tryGetDefaultExport","cliConfigSchema","getCliConfigSync","rootPath","possiblePaths","map","file","configPaths","filter","path","length","Error","configPath","unregister","cliConfig","require","url","loaded","data","error","success","safeParse","message"],"mappings":"AAAA,SAAQA,UAAU,QAAO,UAAS;AAClC,SAAQC,aAAa,QAAO,cAAa;AACzC,SAAQC,IAAI,QAAO,YAAW;AAE9B,SAAQC,QAAQ,QAAO,cAAa;AAEpC,SAAQC,aAAa,QAAO,8BAA6B;AACzD,SAAQC,mBAAmB,QAAO,oCAAmC;AACrE,SAAQC,eAAe,QAAO,eAAc;AAG5C;;;;;;;;;CASC,GACD,OAAO,SAASC,iBAAiBC,QAAgB;IAC/C,MAAMC,gBAAgB;QAAC;QAAiB;KAAgB,CAACC,GAAG,CAAC,CAACC,OAAST,KAAKM,UAAUG;IACtF,MAAMC,cAAcH,cAAcI,MAAM,CAAC,CAACC,OAASd,WAAWc;IAE9D,IAAIF,YAAYG,MAAM,KAAK,GAAG;QAC5B,MAAM,IAAIX,cAAc,CAAC,uBAAuB,EAAEI,SAAS,mBAAmB,CAAC;IACjF;IAEA,IAAII,YAAYG,MAAM,GAAG,GAAG;QAC1B,MAAM,IAAIC,MAAM,CAAC,iCAAiC,EAAEJ,YAAYV,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/E;IAEA,MAAMe,aAAaL,WAAW,CAAC,EAAE;IAEjC,sCAAsC;IACtC,MAAMM,aAAaf;IAEnB,IAAIgB;IACJ,IAAI;QACF,4DAA4D;QAC5D,uCAAuC;QACvC,MAAMC,UAAUnB,cAAc,YAAYoB,GAAG;QAC7C,MAAMC,SAASF,QAAQH;QACvBE,YAAYd,oBAAoBiB;IAClC,SAAU;QACRJ;IACF;IAEA,MAAM,EAACK,IAAI,EAAEC,KAAK,EAAEC,OAAO,EAAC,GAAGnB,gBAAgBoB,SAAS,CAACP;IACzD,IAAI,CAACM,SAAS;QACZ,MAAM,IAAIT,MAAM,CAAC,oBAAoB,EAAEQ,MAAMG,OAAO,EAAE;IACxD;IAEA,oFAAoF;IACpF,4EAA4E;IAC5E,OAAOJ;AACT"}
|
|
@@ -1,34 +1,9 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* @see https://react.dev/learn/react-compiler#existing-projects
|
|
7
|
-
*/
|
|
8
|
-
sources: z.ZodOptional<z.ZodUnion<[z.ZodFunction<z.ZodTuple<[z.ZodString], z.ZodUnknown>, z.ZodBoolean>, z.ZodArray<z.ZodString, "many">, z.ZodNull]>>;
|
|
9
|
-
/**
|
|
10
|
-
* The minimum major version of React that the compiler should emit code for. If the target is 19
|
|
11
|
-
* or higher, the compiler emits direct imports of React runtime APIs needed by the compiler. On
|
|
12
|
-
* versions prior to 19, an extra runtime package react-compiler-runtime is necessary to provide
|
|
13
|
-
* a userspace approximation of runtime APIs.
|
|
14
|
-
* @see https://react.dev/learn/react-compiler#using-react-compiler-with-react-17-or-18
|
|
15
|
-
*/
|
|
16
|
-
target: z.ZodEnum<["18", "19"]>;
|
|
17
|
-
}, "strip", z.ZodTypeAny, {
|
|
18
|
-
target: "18" | "19";
|
|
19
|
-
compilationMode?: "all" | "annotation" | "infer" | "syntax" | undefined;
|
|
20
|
-
panicThreshold?: "ALL_ERRORS" | "CRITICAL_ERRORS" | "NONE" | undefined;
|
|
21
|
-
sources?: string[] | ((args_0: string, ...args: unknown[]) => boolean) | null | undefined;
|
|
22
|
-
}, {
|
|
23
|
-
target: "18" | "19";
|
|
24
|
-
compilationMode?: "all" | "annotation" | "infer" | "syntax" | undefined;
|
|
25
|
-
panicThreshold?: "ALL_ERRORS" | "CRITICAL_ERRORS" | "NONE" | undefined;
|
|
26
|
-
sources?: string[] | ((args_0: string, ...args: unknown[]) => boolean) | null | undefined;
|
|
27
|
-
}>>;
|
|
2
|
+
import { type UserViteConfig } from './types/userViteConfig';
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
28
6
|
export declare const cliConfigSchema: z.ZodObject<{
|
|
29
|
-
/**
|
|
30
|
-
* API configuration
|
|
31
|
-
*/
|
|
32
7
|
api: z.ZodOptional<z.ZodObject<{
|
|
33
8
|
dataset: z.ZodOptional<z.ZodString>;
|
|
34
9
|
projectId: z.ZodOptional<z.ZodString>;
|
|
@@ -53,6 +28,16 @@ export declare const cliConfigSchema: z.ZodObject<{
|
|
|
53
28
|
organizationId?: string | undefined;
|
|
54
29
|
}>>;
|
|
55
30
|
autoUpdates: z.ZodOptional<z.ZodBoolean>;
|
|
31
|
+
deployment: z.ZodOptional<z.ZodObject<{
|
|
32
|
+
appId: z.ZodOptional<z.ZodString>;
|
|
33
|
+
autoUpdates: z.ZodOptional<z.ZodBoolean>;
|
|
34
|
+
}, "strip", z.ZodTypeAny, {
|
|
35
|
+
autoUpdates?: boolean | undefined;
|
|
36
|
+
appId?: string | undefined;
|
|
37
|
+
}, {
|
|
38
|
+
autoUpdates?: boolean | undefined;
|
|
39
|
+
appId?: string | undefined;
|
|
40
|
+
}>>;
|
|
56
41
|
graphql: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
57
42
|
filterSuffix: z.ZodOptional<z.ZodString>;
|
|
58
43
|
generation: z.ZodOptional<z.ZodEnum<["gen1", "gen2", "gen3"]>>;
|
|
@@ -81,6 +66,13 @@ export declare const cliConfigSchema: z.ZodObject<{
|
|
|
81
66
|
tag?: string | undefined;
|
|
82
67
|
workspace?: string | undefined;
|
|
83
68
|
}>, "many">>;
|
|
69
|
+
mediaLibrary: z.ZodOptional<z.ZodObject<{
|
|
70
|
+
aspectsPath: z.ZodOptional<z.ZodString>;
|
|
71
|
+
}, "strip", z.ZodTypeAny, {
|
|
72
|
+
aspectsPath?: string | undefined;
|
|
73
|
+
}, {
|
|
74
|
+
aspectsPath?: string | undefined;
|
|
75
|
+
}>>;
|
|
84
76
|
project: z.ZodOptional<z.ZodObject<{
|
|
85
77
|
basePath: z.ZodOptional<z.ZodString>;
|
|
86
78
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -88,32 +80,47 @@ export declare const cliConfigSchema: z.ZodObject<{
|
|
|
88
80
|
}, {
|
|
89
81
|
basePath?: string | undefined;
|
|
90
82
|
}>>;
|
|
91
|
-
reactCompiler: z.ZodOptional<z.
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
target: "18" | "19"
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}, {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
83
|
+
reactCompiler: z.ZodOptional<z.ZodType<Partial<{
|
|
84
|
+
environment: Partial<import("babel-plugin-react-compiler").EnvironmentConfig>;
|
|
85
|
+
logger: import("babel-plugin-react-compiler").Logger | null;
|
|
86
|
+
gating: import("babel-plugin-react-compiler").ExternalFunction | null;
|
|
87
|
+
dynamicGating: {
|
|
88
|
+
source: string;
|
|
89
|
+
} | null;
|
|
90
|
+
panicThreshold: unknown;
|
|
91
|
+
noEmit: boolean;
|
|
92
|
+
compilationMode: unknown;
|
|
93
|
+
eslintSuppressionRules: Array<string> | null | undefined;
|
|
94
|
+
flowSuppressions: boolean;
|
|
95
|
+
ignoreUseNoForget: boolean;
|
|
96
|
+
customOptOutDirectives: string[] | null;
|
|
97
|
+
sources: Array<string> | ((filename: string) => boolean) | null;
|
|
98
|
+
enableReanimatedCheck: boolean;
|
|
99
|
+
target: "17" | "18" | "19" | {
|
|
100
|
+
kind: "donotuse_meta_internal";
|
|
101
|
+
runtimeModule: string;
|
|
102
|
+
};
|
|
103
|
+
}>, z.ZodTypeDef, Partial<{
|
|
104
|
+
environment: Partial<import("babel-plugin-react-compiler").EnvironmentConfig>;
|
|
105
|
+
logger: import("babel-plugin-react-compiler").Logger | null;
|
|
106
|
+
gating: import("babel-plugin-react-compiler").ExternalFunction | null;
|
|
107
|
+
dynamicGating: {
|
|
108
|
+
source: string;
|
|
109
|
+
} | null;
|
|
110
|
+
panicThreshold: unknown;
|
|
111
|
+
noEmit: boolean;
|
|
112
|
+
compilationMode: unknown;
|
|
113
|
+
eslintSuppressionRules: Array<string> | null | undefined;
|
|
114
|
+
flowSuppressions: boolean;
|
|
115
|
+
ignoreUseNoForget: boolean;
|
|
116
|
+
customOptOutDirectives: string[] | null;
|
|
117
|
+
sources: Array<string> | ((filename: string) => boolean) | null;
|
|
118
|
+
enableReanimatedCheck: boolean;
|
|
119
|
+
target: "17" | "18" | "19" | {
|
|
120
|
+
kind: "donotuse_meta_internal";
|
|
121
|
+
runtimeModule: string;
|
|
122
|
+
};
|
|
123
|
+
}>>>;
|
|
117
124
|
reactStrictMode: z.ZodOptional<z.ZodBoolean>;
|
|
118
125
|
server: z.ZodOptional<z.ZodObject<{
|
|
119
126
|
hostname: z.ZodOptional<z.ZodString>;
|
|
@@ -126,7 +133,7 @@ export declare const cliConfigSchema: z.ZodObject<{
|
|
|
126
133
|
port?: number | undefined;
|
|
127
134
|
}>>;
|
|
128
135
|
studioHost: z.ZodOptional<z.ZodString>;
|
|
129
|
-
vite: z.ZodOptional<z.
|
|
136
|
+
vite: z.ZodOptional<z.ZodType<UserViteConfig, z.ZodTypeDef, UserViteConfig>>;
|
|
130
137
|
}, "strip", z.ZodTypeAny, {
|
|
131
138
|
api?: {
|
|
132
139
|
dataset?: string | undefined;
|
|
@@ -138,6 +145,10 @@ export declare const cliConfigSchema: z.ZodObject<{
|
|
|
138
145
|
organizationId?: string | undefined;
|
|
139
146
|
} | undefined;
|
|
140
147
|
autoUpdates?: boolean | undefined;
|
|
148
|
+
deployment?: {
|
|
149
|
+
autoUpdates?: boolean | undefined;
|
|
150
|
+
appId?: string | undefined;
|
|
151
|
+
} | undefined;
|
|
141
152
|
graphql?: {
|
|
142
153
|
id?: string | undefined;
|
|
143
154
|
filterSuffix?: string | undefined;
|
|
@@ -148,22 +159,40 @@ export declare const cliConfigSchema: z.ZodObject<{
|
|
|
148
159
|
tag?: string | undefined;
|
|
149
160
|
workspace?: string | undefined;
|
|
150
161
|
}[] | undefined;
|
|
162
|
+
mediaLibrary?: {
|
|
163
|
+
aspectsPath?: string | undefined;
|
|
164
|
+
} | undefined;
|
|
151
165
|
project?: {
|
|
152
166
|
basePath?: string | undefined;
|
|
153
167
|
} | undefined;
|
|
154
|
-
reactCompiler?: {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
168
|
+
reactCompiler?: Partial<{
|
|
169
|
+
environment: Partial<import("babel-plugin-react-compiler").EnvironmentConfig>;
|
|
170
|
+
logger: import("babel-plugin-react-compiler").Logger | null;
|
|
171
|
+
gating: import("babel-plugin-react-compiler").ExternalFunction | null;
|
|
172
|
+
dynamicGating: {
|
|
173
|
+
source: string;
|
|
174
|
+
} | null;
|
|
175
|
+
panicThreshold: unknown;
|
|
176
|
+
noEmit: boolean;
|
|
177
|
+
compilationMode: unknown;
|
|
178
|
+
eslintSuppressionRules: Array<string> | null | undefined;
|
|
179
|
+
flowSuppressions: boolean;
|
|
180
|
+
ignoreUseNoForget: boolean;
|
|
181
|
+
customOptOutDirectives: string[] | null;
|
|
182
|
+
sources: Array<string> | ((filename: string) => boolean) | null;
|
|
183
|
+
enableReanimatedCheck: boolean;
|
|
184
|
+
target: "17" | "18" | "19" | {
|
|
185
|
+
kind: "donotuse_meta_internal";
|
|
186
|
+
runtimeModule: string;
|
|
187
|
+
};
|
|
188
|
+
}> | undefined;
|
|
160
189
|
reactStrictMode?: boolean | undefined;
|
|
161
190
|
server?: {
|
|
162
191
|
hostname?: string | undefined;
|
|
163
192
|
port?: number | undefined;
|
|
164
193
|
} | undefined;
|
|
165
194
|
studioHost?: string | undefined;
|
|
166
|
-
vite?:
|
|
195
|
+
vite?: UserViteConfig | undefined;
|
|
167
196
|
}, {
|
|
168
197
|
api?: {
|
|
169
198
|
dataset?: string | undefined;
|
|
@@ -175,6 +204,10 @@ export declare const cliConfigSchema: z.ZodObject<{
|
|
|
175
204
|
organizationId?: string | undefined;
|
|
176
205
|
} | undefined;
|
|
177
206
|
autoUpdates?: boolean | undefined;
|
|
207
|
+
deployment?: {
|
|
208
|
+
autoUpdates?: boolean | undefined;
|
|
209
|
+
appId?: string | undefined;
|
|
210
|
+
} | undefined;
|
|
178
211
|
graphql?: {
|
|
179
212
|
id?: string | undefined;
|
|
180
213
|
filterSuffix?: string | undefined;
|
|
@@ -185,20 +218,38 @@ export declare const cliConfigSchema: z.ZodObject<{
|
|
|
185
218
|
tag?: string | undefined;
|
|
186
219
|
workspace?: string | undefined;
|
|
187
220
|
}[] | undefined;
|
|
221
|
+
mediaLibrary?: {
|
|
222
|
+
aspectsPath?: string | undefined;
|
|
223
|
+
} | undefined;
|
|
188
224
|
project?: {
|
|
189
225
|
basePath?: string | undefined;
|
|
190
226
|
} | undefined;
|
|
191
|
-
reactCompiler?: {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
227
|
+
reactCompiler?: Partial<{
|
|
228
|
+
environment: Partial<import("babel-plugin-react-compiler").EnvironmentConfig>;
|
|
229
|
+
logger: import("babel-plugin-react-compiler").Logger | null;
|
|
230
|
+
gating: import("babel-plugin-react-compiler").ExternalFunction | null;
|
|
231
|
+
dynamicGating: {
|
|
232
|
+
source: string;
|
|
233
|
+
} | null;
|
|
234
|
+
panicThreshold: unknown;
|
|
235
|
+
noEmit: boolean;
|
|
236
|
+
compilationMode: unknown;
|
|
237
|
+
eslintSuppressionRules: Array<string> | null | undefined;
|
|
238
|
+
flowSuppressions: boolean;
|
|
239
|
+
ignoreUseNoForget: boolean;
|
|
240
|
+
customOptOutDirectives: string[] | null;
|
|
241
|
+
sources: Array<string> | ((filename: string) => boolean) | null;
|
|
242
|
+
enableReanimatedCheck: boolean;
|
|
243
|
+
target: "17" | "18" | "19" | {
|
|
244
|
+
kind: "donotuse_meta_internal";
|
|
245
|
+
runtimeModule: string;
|
|
246
|
+
};
|
|
247
|
+
}> | undefined;
|
|
197
248
|
reactStrictMode?: boolean | undefined;
|
|
198
249
|
server?: {
|
|
199
250
|
hostname?: string | undefined;
|
|
200
251
|
port?: number | undefined;
|
|
201
252
|
} | undefined;
|
|
202
253
|
studioHost?: string | undefined;
|
|
203
|
-
vite?:
|
|
254
|
+
vite?: UserViteConfig | undefined;
|
|
204
255
|
}>;
|