@sanity/cli-core 0.0.2-alpha.2 → 0.1.0-alpha.10

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.
Files changed (160) hide show
  1. package/dist/SanityCommand.js +34 -3
  2. package/dist/SanityCommand.js.map +1 -1
  3. package/dist/_exports/tree.d.ts +47 -0
  4. package/dist/_exports/tree.js +3 -0
  5. package/dist/_exports/tree.js.map +1 -0
  6. package/dist/_exports/ux.d.ts +40 -0
  7. package/dist/_exports/ux.js +6 -0
  8. package/dist/_exports/ux.js.map +1 -0
  9. package/dist/config/cli/getCliConfig.worker.js +2 -1
  10. package/dist/config/cli/getCliConfig.worker.js.map +1 -1
  11. package/dist/config/cli/schemas.js +5 -2
  12. package/dist/config/cli/schemas.js.map +1 -1
  13. package/dist/config/cli/types/cliConfig.js.map +1 -1
  14. package/dist/config/findProjectRoot.js +2 -2
  15. package/dist/config/findProjectRoot.js.map +1 -1
  16. package/dist/config/studio/getStudioConfig.js +0 -3
  17. package/dist/config/studio/getStudioConfig.js.map +1 -1
  18. package/dist/config/studio/getStudioWorkspaces.js +50 -0
  19. package/dist/config/studio/getStudioWorkspaces.js.map +1 -0
  20. package/dist/config/studio/isStudioConfig.js +19 -0
  21. package/dist/config/studio/isStudioConfig.js.map +1 -0
  22. package/dist/config/studio/readStudioConfig.js +13 -9
  23. package/dist/config/studio/readStudioConfig.js.map +1 -1
  24. package/dist/config/studio/readStudioConfig.worker.js +4 -30
  25. package/dist/config/studio/readStudioConfig.worker.js.map +1 -1
  26. package/dist/config/util/findStudioConfigPath.js +24 -3
  27. package/dist/config/util/findStudioConfigPath.js.map +1 -1
  28. package/dist/config/util/recursivelyResolveProjectRoot.js.map +1 -1
  29. package/dist/index.d.ts +6027 -36
  30. package/dist/index.js +14 -3
  31. package/dist/index.js.map +1 -1
  32. package/dist/loaders/studio/studioWorkerLoader.worker.js +10 -24
  33. package/dist/loaders/studio/studioWorkerLoader.worker.js.map +1 -1
  34. package/dist/loaders/studio/studioWorkerTask.js +41 -11
  35. package/dist/loaders/studio/studioWorkerTask.js.map +1 -1
  36. package/dist/loaders/tsx/tsxWorkerTask.js +3 -0
  37. package/dist/loaders/tsx/tsxWorkerTask.js.map +1 -1
  38. package/dist/services/apiClient.js +18 -17
  39. package/dist/services/apiClient.js.map +1 -1
  40. package/dist/telemetry/cleanupOldTelemetryFiles.js +30 -0
  41. package/dist/telemetry/cleanupOldTelemetryFiles.js.map +1 -0
  42. package/dist/telemetry/createTelemetryStore.js +95 -0
  43. package/dist/telemetry/createTelemetryStore.js.map +1 -0
  44. package/dist/telemetry/createTraceId.js +10 -0
  45. package/dist/telemetry/createTraceId.js.map +1 -0
  46. package/dist/telemetry/findTelemetryFiles.js +36 -0
  47. package/dist/telemetry/findTelemetryFiles.js.map +1 -0
  48. package/dist/telemetry/flushTelemetryFiles.js +107 -0
  49. package/dist/telemetry/flushTelemetryFiles.js.map +1 -0
  50. package/dist/telemetry/generateTelemetryFilePath.js +30 -0
  51. package/dist/telemetry/generateTelemetryFilePath.js.map +1 -0
  52. package/dist/telemetry/getTelemetryBaseInfo.js +33 -0
  53. package/dist/telemetry/getTelemetryBaseInfo.js.map +1 -0
  54. package/dist/telemetry/logger.js +54 -0
  55. package/dist/telemetry/logger.js.map +1 -0
  56. package/dist/telemetry/telemetryStoreDebug.js +7 -0
  57. package/dist/telemetry/telemetryStoreDebug.js.map +1 -0
  58. package/dist/telemetry/trace.js +150 -0
  59. package/dist/telemetry/trace.js.map +1 -0
  60. package/dist/telemetry/types.js +5 -0
  61. package/dist/telemetry/types.js.map +1 -0
  62. package/dist/types.js +2 -0
  63. package/dist/types.js.map +1 -1
  64. package/dist/util/doImport.js +16 -0
  65. package/dist/util/doImport.js.map +1 -0
  66. package/dist/util/environment/getStudioEnvironmentVariables.js +2 -1
  67. package/dist/util/environment/getStudioEnvironmentVariables.js.map +1 -1
  68. package/dist/util/getCliTelemetry.js +36 -0
  69. package/dist/util/getCliTelemetry.js.map +1 -0
  70. package/dist/util/isStaging.js +10 -0
  71. package/dist/util/isStaging.js.map +1 -0
  72. package/dist/util/normalizePath.js +12 -0
  73. package/dist/util/normalizePath.js.map +1 -0
  74. package/dist/util/parseStringFlag.js +19 -0
  75. package/dist/util/parseStringFlag.js.map +1 -0
  76. package/dist/util/readNDJSON.js +18 -0
  77. package/dist/util/readNDJSON.js.map +1 -0
  78. package/dist/util/resolveLocalPackage.js +34 -0
  79. package/dist/util/resolveLocalPackage.js.map +1 -0
  80. package/dist/util/tree.js +108 -0
  81. package/dist/util/tree.js.map +1 -0
  82. package/dist/util/waitForAsync.js +5 -0
  83. package/dist/util/waitForAsync.js.map +1 -0
  84. package/dist/ux/boxen.js +3 -0
  85. package/dist/ux/boxen.js.map +1 -0
  86. package/dist/ux/colorizeJson.js +6 -6
  87. package/dist/ux/colorizeJson.js.map +1 -1
  88. package/dist/ux/prompts.js +3 -0
  89. package/dist/ux/prompts.js.map +1 -0
  90. package/dist/ux/spinner.js +1 -1
  91. package/dist/ux/spinner.js.map +1 -1
  92. package/package.json +53 -28
  93. package/dist/SanityCommand.d.ts +0 -56
  94. package/dist/config/__tests__/cliToken.test.js +0 -74
  95. package/dist/config/__tests__/cliToken.test.js.map +0 -1
  96. package/dist/config/__tests__/cliUserConfig.test.js +0 -131
  97. package/dist/config/__tests__/cliUserConfig.test.js.map +0 -1
  98. package/dist/config/__tests__/findProjectRoot.test.js +0 -159
  99. package/dist/config/__tests__/findProjectRoot.test.js.map +0 -1
  100. package/dist/config/__tests__/findProjectRootSync.test.js +0 -112
  101. package/dist/config/__tests__/findProjectRootSync.test.js.map +0 -1
  102. package/dist/config/__tests__/getCliConfigSync.test.js +0 -31
  103. package/dist/config/__tests__/getCliConfigSync.test.js.map +0 -1
  104. package/dist/config/cli/getCliConfig.d.ts +0 -16
  105. package/dist/config/cli/getCliConfig.worker.d.ts +0 -1
  106. package/dist/config/cli/getCliConfigSync.d.ts +0 -12
  107. package/dist/config/cli/schemas.d.ts +0 -255
  108. package/dist/config/cli/types/cliConfig.d.ts +0 -74
  109. package/dist/config/cli/types/userViteConfig.d.ts +0 -5
  110. package/dist/config/findProjectRoot.d.ts +0 -14
  111. package/dist/config/findProjectRootSync.d.ts +0 -27
  112. package/dist/config/studio/getStudioConfig.d.ts +0 -14
  113. package/dist/config/studio/readStudioConfig.d.ts +0 -190
  114. package/dist/config/studio/readStudioConfig.worker.d.ts +0 -1
  115. package/dist/config/util/configPathsSync.d.ts +0 -17
  116. package/dist/config/util/findAppConfigPath.d.ts +0 -8
  117. package/dist/config/util/findConfigsPaths.d.ts +0 -16
  118. package/dist/config/util/findStudioConfigPath.d.ts +0 -9
  119. package/dist/config/util/isSanityV2StudioRoot.d.ts +0 -8
  120. package/dist/config/util/recursivelyResolveProjectRoot.d.ts +0 -27
  121. package/dist/debug.d.ts +0 -15
  122. package/dist/loaders/studio/studioWorkerLoader.worker.d.ts +0 -1
  123. package/dist/loaders/studio/studioWorkerTask.d.ts +0 -40
  124. package/dist/loaders/tsx/tsxWorkerLoader.worker.d.ts +0 -1
  125. package/dist/loaders/tsx/tsxWorkerTask.d.ts +0 -28
  126. package/dist/services/apiClient.d.ts +0 -53
  127. package/dist/services/cliUserConfig.d.ts +0 -57
  128. package/dist/services/getCliToken.d.ts +0 -7
  129. package/dist/types.d.ts +0 -7
  130. package/dist/util/NotFoundError.d.ts +0 -20
  131. package/dist/util/__tests__/createExpiringConfig.test.js +0 -400
  132. package/dist/util/__tests__/createExpiringConfig.test.js.map +0 -1
  133. package/dist/util/createExpiringConfig.d.ts +0 -37
  134. package/dist/util/environment/getStudioEnvironmentVariables.d.ts +0 -12
  135. package/dist/util/environment/mockBrowserEnvironment.d.ts +0 -17
  136. package/dist/util/environment/setupBrowserStubs.d.ts +0 -10
  137. package/dist/util/environment/stubs.d.ts +0 -254
  138. package/dist/util/fileExists.d.ts +0 -9
  139. package/dist/util/generateHelpUrl.d.ts +0 -8
  140. package/dist/util/getEmptyAuth.d.ts +0 -5
  141. package/dist/util/getSanityEnvVar.d.ts +0 -19
  142. package/dist/util/getSanityUrl.d.ts +0 -5
  143. package/dist/util/getUserConfig.d.ts +0 -2
  144. package/dist/util/isCi.d.ts +0 -1
  145. package/dist/util/isHttpError.d.ts +0 -29
  146. package/dist/util/isHttpError.js +0 -18
  147. package/dist/util/isHttpError.js.map +0 -1
  148. package/dist/util/isInteractive.d.ts +0 -1
  149. package/dist/util/isRecord.d.ts +0 -8
  150. package/dist/util/isTrueish.d.ts +0 -1
  151. package/dist/util/readJsonFile.d.ts +0 -14
  152. package/dist/util/safeStructuredClone.d.ts +0 -8
  153. package/dist/util/tryGetDefaultExport.d.ts +0 -5
  154. package/dist/util/writeJsonFile.d.ts +0 -9
  155. package/dist/ux/colorizeJson.d.ts +0 -1
  156. package/dist/ux/formatObject.d.ts +0 -1
  157. package/dist/ux/logSymbols.d.ts +0 -1
  158. package/dist/ux/printKeyValue.d.ts +0 -1
  159. package/dist/ux/spinner.d.ts +0 -1
  160. package/dist/ux/timer.d.ts +0 -12
@@ -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,GAAGO,aAAa;QAChBP,GAAGQ,MAAM,CAACd,SAASe,eAAe,CAACH;QACnCN,GAAGQ,MAAM,CAACf,OAAOiB,iBAAiB,CAACC;QACnCX,GAAGQ,MAAM,CAACL,cAAcO,iBAAiB,CAAC,CAAC;QAC3CV,GAAGQ,MAAM,CAACJ,eAAeM,iBAAiB;IAC5C;IAEAf,UAAU;QACRK,GAAGO,aAAa;IAClB;IAEAV,SAAS,uBAAuB;QAC9BE,KAAK,6CAA6C;YAChDC,GAAGQ,MAAM,CAACL,cAAcS,qBAAqB,CAAC,IAAIC,MAAM;YACxD,MAAMC,SAAS,MAAMb,UAAU;YAC/BH,OAAOgB,QAAQC,aAAa;QAC9B;QAEAhB,KAAK,kDAAkD;YACrDC,GAAGQ,MAAM,CAACL,cAAca,qBAAqB,CAAC;YAC9C,MAAMF,SAAS,MAAMb,UAAU;YAC/BH,OAAOgB,QAAQC,aAAa;QAC9B;QAEAhB,KAAK,sDAAsD;YACzDC,GAAGQ,MAAM,CAACL,cAAca,qBAAqB,CAAC,EAAE;YAChD,MAAMF,SAAS,MAAMb,UAAU;YAC/BH,OAAOgB,QAAQC,aAAa;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XlC,OAAOoC,gBAAgB,CAAC;gBACtBjB,WAAW;YACb,IACAnB,OAAOiC,GAAG,CAACI;QAEf;QAEApC,KAAK,+BAA+B;YAClC,MAAMoB,cAAc;gBAClBC,WAAWC,KAAKC,GAAG;gBACnBC,OAAO;oBACLC,QAAQ;oBACRC,MAAM;gBACR;YACF;YAEA,MAAMvB,UAAU,oBAAoBiB;YAEpCrB,OAAOM,eAAe0B,oBAAoB,CACxChC,OAAOiC,GAAG,CAACC,SACXlC,OAAOoC,gBAAgB,CAAC;gBACtBR,kBAAkBP;YACpB,IACArB,OAAOiC,GAAG,CAACI;QAEf;QAEApC,KAAK,qCAAqC;YACxC,8DAA8D;YAC9D,MAAMD,OAAOI,UAAU,eAAsB,UAAU0B,OAAO,CAACC,OAAO,CAAC;QACzE;QAEA9B,KAAK,uCAAuC;YAC1C,MAAMD,OAAOI,UAAU,aAAa,MAAe0B,OAAO,CAACC,OAAO,CAAC;QACrE;QAEA9B,KAAK,0CAA0C;YAC7CC,GAAGQ,MAAM,CAACL,cAAca,qBAAqB,CAAC;gBAC5CC,WAAW;YACb;YAEA,MAAMf,UAAU,oBAAoB;gBAClCkB,WAAW;gBACXG,OAAO;oBACLC,QAAQ;oBACRC,MAAM;gBACR;YACF;YAEA3B,OAAOM,eAAe0B,oBAAoB,CACxChC,OAAOiC,GAAG,CAACC,SACXlC,OAAOoC,gBAAgB,CAAC;gBACtBjB,WAAW;gBACXS,kBAAkB5B,OAAOiC,GAAG,CAACI;YAC/B,IACArC,OAAOiC,GAAG,CAACI;QAEf;IACF;AACF"}
@@ -1,159 +0,0 @@
1
- import { access } from 'node:fs/promises';
2
- import { join } from 'node:path';
3
- import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
4
- import { readJsonFile } from '../../util/readJsonFile';
5
- import { findProjectRoot } from '../findProjectRoot';
6
- // Mock the fs/promises module
7
- vi.mock('node:fs/promises', ()=>({
8
- access: vi.fn()
9
- }));
10
- // Mock the readJsonFile utility
11
- vi.mock('../../util/readJsonFile', ()=>({
12
- readJsonFile: vi.fn()
13
- }));
14
- describe('#findProjectRoot', ()=>{
15
- const mockCwd = '/mock/project/path';
16
- beforeEach(()=>{
17
- vi.clearAllMocks();
18
- });
19
- afterEach(()=>{
20
- vi.resetAllMocks();
21
- });
22
- test('finds a TypeScript studio config in the current directory', async ()=>{
23
- // Mock access to return true for sanity.config.ts
24
- vi.mocked(access).mockImplementation((path)=>{
25
- if (path === join(mockCwd, 'sanity.config.ts')) {
26
- return Promise.resolve();
27
- }
28
- return Promise.reject(new Error('File not found'));
29
- });
30
- const result = await findProjectRoot(mockCwd);
31
- expect(result).toEqual({
32
- directory: mockCwd,
33
- path: join(mockCwd, 'sanity.config.ts'),
34
- type: 'studio'
35
- });
36
- });
37
- test('finds a JavaScript studio config in the current directory', async ()=>{
38
- // Mock access to return true for sanity.config.js
39
- vi.mocked(access).mockImplementation((path)=>{
40
- if (path === join(mockCwd, 'sanity.config.js')) {
41
- return Promise.resolve();
42
- }
43
- return Promise.reject(new Error('File not found'));
44
- });
45
- const result = await findProjectRoot(mockCwd);
46
- expect(result).toEqual({
47
- directory: mockCwd,
48
- path: join(mockCwd, 'sanity.config.js'),
49
- type: 'studio'
50
- });
51
- });
52
- test('throws error when multiple config files are found', async ()=>{
53
- // Mock access to return true for multiple config files
54
- vi.mocked(access).mockImplementation((path)=>{
55
- if (path === join(mockCwd, 'sanity.config.ts') || path === join(mockCwd, 'sanity.config.js')) {
56
- return Promise.resolve();
57
- }
58
- return Promise.reject(new Error('File not found'));
59
- });
60
- await expect(findProjectRoot(mockCwd)).rejects.toThrow('Multiple studio config files found (sanity.config.ts, sanity.config.js)');
61
- });
62
- test('throws error when v2 studio root is found', async ()=>{
63
- // Mock access to reject all config files
64
- vi.mocked(access).mockRejectedValue(new Error('File not found'));
65
- // Mock readJsonFile to return a v2 config
66
- vi.mocked(readJsonFile).mockResolvedValue({
67
- root: true
68
- });
69
- await expect(findProjectRoot(mockCwd)).rejects.toThrow("Found 'sanity.json' at /mock/project/path - Sanity Studio < v3 is no longer supported");
70
- });
71
- test('recursively searches parent directories for config', async ()=>{
72
- const parentPath = '/mock/project';
73
- // Mock access to return true only for config in parent directory
74
- vi.mocked(access).mockImplementation((path)=>{
75
- if (path === join(parentPath, 'sanity.config.ts')) {
76
- return Promise.resolve();
77
- }
78
- return Promise.reject(new Error('File not found'));
79
- });
80
- const result = await findProjectRoot(mockCwd);
81
- expect(result).toEqual({
82
- directory: parentPath,
83
- path: join(parentPath, 'sanity.config.ts'),
84
- type: 'studio'
85
- });
86
- });
87
- test('throws error when no config is found', async ()=>{
88
- // Mock access to reject all files
89
- vi.mocked(access).mockRejectedValue(new Error('File not found'));
90
- // Mock readJsonFile to return non-root config
91
- vi.mocked(readJsonFile).mockResolvedValue({
92
- root: false
93
- });
94
- await expect(findProjectRoot(mockCwd)).rejects.toThrow('No project root found');
95
- });
96
- test('throws an error if v2 studio root is found', async ()=>{
97
- vi.mocked(readJsonFile).mockResolvedValue({
98
- root: true
99
- });
100
- await expect(findProjectRoot(mockCwd)).rejects.toThrow("Found 'sanity.json' at /mock/project/path - Sanity Studio < v3 is no longer supported");
101
- });
102
- test('finds a TypeScript app config in the current directory', async ()=>{
103
- // Mock access to return true for sanity.cli.ts
104
- vi.mocked(access).mockImplementation((path)=>{
105
- if (path === join(mockCwd, 'sanity.cli.ts')) {
106
- return Promise.resolve();
107
- }
108
- return Promise.reject(new Error('File not found'));
109
- });
110
- const result = await findProjectRoot(mockCwd);
111
- expect(result).toEqual({
112
- directory: mockCwd,
113
- path: join(mockCwd, 'sanity.cli.ts'),
114
- type: 'app'
115
- });
116
- });
117
- test('finds a JavaScript app config in the current directory', async ()=>{
118
- // Mock access to return true for sanity.cli.js
119
- vi.mocked(access).mockImplementation((path)=>{
120
- if (path === join(mockCwd, 'sanity.cli.js')) {
121
- return Promise.resolve();
122
- }
123
- return Promise.reject(new Error('File not found'));
124
- });
125
- const result = await findProjectRoot(mockCwd);
126
- expect(result).toEqual({
127
- directory: mockCwd,
128
- path: join(mockCwd, 'sanity.cli.js'),
129
- type: 'app'
130
- });
131
- });
132
- test('throws error when multiple app config files are found', async ()=>{
133
- // Mock access to return true for multiple app config files
134
- vi.mocked(access).mockImplementation((path)=>{
135
- if (path === join(mockCwd, 'sanity.cli.ts') || path === join(mockCwd, 'sanity.cli.js')) {
136
- return Promise.resolve();
137
- }
138
- return Promise.reject(new Error('File not found'));
139
- });
140
- await expect(findProjectRoot(mockCwd)).rejects.toThrow('Multiple app config files found');
141
- });
142
- test('prioritizes studio config over app config when both are present', async ()=>{
143
- // Mock access to return true for both studio and app config files
144
- vi.mocked(access).mockImplementation((path)=>{
145
- if (path === join(mockCwd, 'sanity.config.ts') || path === join(mockCwd, 'sanity.cli.ts')) {
146
- return Promise.resolve();
147
- }
148
- return Promise.reject(new Error('File not found'));
149
- });
150
- const result = await findProjectRoot(mockCwd);
151
- expect(result).toEqual({
152
- directory: mockCwd,
153
- path: join(mockCwd, 'sanity.config.ts'),
154
- type: 'studio'
155
- });
156
- });
157
- });
158
-
159
- //# sourceMappingURL=findProjectRoot.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/config/__tests__/findProjectRoot.test.ts"],"sourcesContent":["import {access} from 'node:fs/promises'\nimport {join} from 'node:path'\n\nimport {afterEach, beforeEach, describe, expect, test, vi} from 'vitest'\n\nimport {readJsonFile} from '../../util/readJsonFile'\nimport {findProjectRoot} from '../findProjectRoot'\n\n// Mock the fs/promises module\nvi.mock('node:fs/promises', () => ({\n access: vi.fn(),\n}))\n\n// Mock the readJsonFile utility\nvi.mock('../../util/readJsonFile', () => ({\n readJsonFile: vi.fn(),\n}))\n\ndescribe('#findProjectRoot', () => {\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 // Mock access to return true for sanity.config.ts\n vi.mocked(access).mockImplementation((path) => {\n if (path === join(mockCwd, 'sanity.config.ts')) {\n return Promise.resolve()\n }\n return Promise.reject(new Error('File not found'))\n })\n\n const result = await findProjectRoot(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 // Mock access to return true for sanity.config.js\n vi.mocked(access).mockImplementation((path) => {\n if (path === join(mockCwd, 'sanity.config.js')) {\n return Promise.resolve()\n }\n return Promise.reject(new Error('File not found'))\n })\n\n const result = await findProjectRoot(mockCwd)\n expect(result).toEqual({\n directory: mockCwd,\n path: join(mockCwd, 'sanity.config.js'),\n type: 'studio',\n })\n })\n\n test('throws error when multiple config files are found', async () => {\n // Mock access to return true for multiple config files\n vi.mocked(access).mockImplementation((path) => {\n if (\n path === join(mockCwd, 'sanity.config.ts') ||\n path === join(mockCwd, 'sanity.config.js')\n ) {\n return Promise.resolve()\n }\n return Promise.reject(new Error('File not found'))\n })\n\n await expect(findProjectRoot(mockCwd)).rejects.toThrow(\n 'Multiple studio config files found (sanity.config.ts, sanity.config.js)',\n )\n })\n\n test('throws error when v2 studio root is found', async () => {\n // Mock access to reject all config files\n vi.mocked(access).mockRejectedValue(new Error('File not found'))\n\n // Mock readJsonFile to return a v2 config\n vi.mocked(readJsonFile).mockResolvedValue({root: true})\n\n await expect(findProjectRoot(mockCwd)).rejects.toThrow(\n \"Found 'sanity.json' at /mock/project/path - Sanity Studio < v3 is no longer supported\",\n )\n })\n\n test('recursively searches parent directories for config', async () => {\n const parentPath = '/mock/project'\n\n // Mock access to return true only for config in parent directory\n vi.mocked(access).mockImplementation((path) => {\n if (path === join(parentPath, 'sanity.config.ts')) {\n return Promise.resolve()\n }\n return Promise.reject(new Error('File not found'))\n })\n\n const result = await findProjectRoot(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 // Mock access to reject all files\n vi.mocked(access).mockRejectedValue(new Error('File not found'))\n\n // Mock readJsonFile to return non-root config\n vi.mocked(readJsonFile).mockResolvedValue({root: false})\n\n await expect(findProjectRoot(mockCwd)).rejects.toThrow('No project root found')\n })\n\n test('throws an error if v2 studio root is found', async () => {\n vi.mocked(readJsonFile).mockResolvedValue({root: true})\n\n await expect(findProjectRoot(mockCwd)).rejects.toThrow(\n \"Found 'sanity.json' at /mock/project/path - Sanity Studio < v3 is no longer supported\",\n )\n })\n\n test('finds a TypeScript app config in the current directory', async () => {\n // Mock access to return true for sanity.cli.ts\n vi.mocked(access).mockImplementation((path) => {\n if (path === join(mockCwd, 'sanity.cli.ts')) {\n return Promise.resolve()\n }\n return Promise.reject(new Error('File not found'))\n })\n\n const result = await findProjectRoot(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 // Mock access to return true for sanity.cli.js\n vi.mocked(access).mockImplementation((path) => {\n if (path === join(mockCwd, 'sanity.cli.js')) {\n return Promise.resolve()\n }\n return Promise.reject(new Error('File not found'))\n })\n\n const result = await findProjectRoot(mockCwd)\n expect(result).toEqual({\n directory: mockCwd,\n path: join(mockCwd, 'sanity.cli.js'),\n type: 'app',\n })\n })\n\n test('throws error when multiple app config files are found', async () => {\n // Mock access to return true for multiple app config files\n vi.mocked(access).mockImplementation((path) => {\n if (path === join(mockCwd, 'sanity.cli.ts') || path === join(mockCwd, 'sanity.cli.js')) {\n return Promise.resolve()\n }\n return Promise.reject(new Error('File not found'))\n })\n\n await expect(findProjectRoot(mockCwd)).rejects.toThrow('Multiple app config files found')\n })\n\n test('prioritizes studio config over app config when both are present', async () => {\n // Mock access to return true for both studio and app config files\n vi.mocked(access).mockImplementation((path) => {\n if (path === join(mockCwd, 'sanity.config.ts') || path === join(mockCwd, 'sanity.cli.ts')) {\n return Promise.resolve()\n }\n return Promise.reject(new Error('File not found'))\n })\n\n const result = await findProjectRoot(mockCwd)\n expect(result).toEqual({\n directory: mockCwd,\n path: join(mockCwd, 'sanity.config.ts'),\n type: 'studio',\n })\n })\n})\n"],"names":["access","join","afterEach","beforeEach","describe","expect","test","vi","readJsonFile","findProjectRoot","mock","fn","mockCwd","clearAllMocks","resetAllMocks","mocked","mockImplementation","path","Promise","resolve","reject","Error","result","toEqual","directory","type","rejects","toThrow","mockRejectedValue","mockResolvedValue","root","parentPath"],"mappings":"AAAA,SAAQA,MAAM,QAAO,mBAAkB;AACvC,SAAQC,IAAI,QAAO,YAAW;AAE9B,SAAQC,SAAS,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,IAAI,EAAEC,EAAE,QAAO,SAAQ;AAExE,SAAQC,YAAY,QAAO,0BAAyB;AACpD,SAAQC,eAAe,QAAO,qBAAoB;AAElD,8BAA8B;AAC9BF,GAAGG,IAAI,CAAC,oBAAoB,IAAO,CAAA;QACjCV,QAAQO,GAAGI,EAAE;IACf,CAAA;AAEA,gCAAgC;AAChCJ,GAAGG,IAAI,CAAC,2BAA2B,IAAO,CAAA;QACxCF,cAAcD,GAAGI,EAAE;IACrB,CAAA;AAEAP,SAAS,oBAAoB;IAC3B,MAAMQ,UAAU;IAEhBT,WAAW;QACTI,GAAGM,aAAa;IAClB;IAEAX,UAAU;QACRK,GAAGO,aAAa;IAClB;IAEAR,KAAK,6DAA6D;QAChE,kDAAkD;QAClDC,GAAGQ,MAAM,CAACf,QAAQgB,kBAAkB,CAAC,CAACC;YACpC,IAAIA,SAAShB,KAAKW,SAAS,qBAAqB;gBAC9C,OAAOM,QAAQC,OAAO;YACxB;YACA,OAAOD,QAAQE,MAAM,CAAC,IAAIC,MAAM;QAClC;QAEA,MAAMC,SAAS,MAAMb,gBAAgBG;QACrCP,OAAOiB,QAAQC,OAAO,CAAC;YACrBC,WAAWZ;YACXK,MAAMhB,KAAKW,SAAS;YACpBa,MAAM;QACR;IACF;IAEAnB,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;QAC5D,2DAA2D;QAC3DC,GAAGQ,MAAM,CAACf,QAAQgB,kBAAkB,CAAC,CAACC;YACpC,IAAIA,SAAShB,KAAKW,SAAS,oBAAoBK,SAAShB,KAAKW,SAAS,kBAAkB;gBACtF,OAAOM,QAAQC,OAAO;YACxB;YACA,OAAOD,QAAQE,MAAM,CAAC,IAAIC,MAAM;QAClC;QAEA,MAAMhB,OAAOI,gBAAgBG,UAAUc,OAAO,CAACC,OAAO,CAAC;IACzD;IAEArB,KAAK,mEAAmE;QACtE,kEAAkE;QAClEC,GAAGQ,MAAM,CAACf,QAAQgB,kBAAkB,CAAC,CAACC;YACpC,IAAIA,SAAShB,KAAKW,SAAS,uBAAuBK,SAAShB,KAAKW,SAAS,kBAAkB;gBACzF,OAAOM,QAAQC,OAAO;YACxB;YACA,OAAOD,QAAQE,MAAM,CAAC,IAAIC,MAAM;QAClC;QAEA,MAAMC,SAAS,MAAMb,gBAAgBG;QACrCP,OAAOiB,QAAQC,OAAO,CAAC;YACrBC,WAAWZ;YACXK,MAAMhB,KAAKW,SAAS;YACpBa,MAAM;QACR;IACF;AACF"}
@@ -1,112 +0,0 @@
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
@@ -1 +0,0 @@
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,uBAAuB;IAC9B,MAAMW,UAAU;IAEhBZ,WAAW;QACTI,GAAGS,aAAa;IAClB;IAEAd,UAAU;QACRK,GAAGU,aAAa;IAClB;IAEAX,KAAK,6DAA6D;QAChE,MAAM,EAACM,UAAU,EAAC,GAAG,MAAM,MAAM,CAAC;QAElCL,GAAGW,MAAM,CAACN,YAAYO,kBAAkB,CAAC,CAACC;YACxC,OAAOA,SAASnB,KAAKc,SAAS;QAChC;QAEA,MAAMM,SAASb,oBAAoBO;QACnCV,OAAOgB,QAAQC,OAAO,CAAC;YACrBC,WAAWR;YACXK,MAAMnB,KAAKc,SAAS;YACpB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S,MAAM;QACR;IACF;IAEAlB,KAAK,sDAAsD;QACzD,MAAM,EAACM,UAAU,EAAC,GAAG,MAAM,MAAM,CAAC;QAClC,MAAMa,aAAa;QAEnBlB,GAAGW,MAAM,CAACN,YAAYO,kBAAkB,CAAC,CAACC;YACxC,OAAOA,SAASnB,KAAKwB,YAAY;QACnC;QAEA,MAAMJ,SAASb,oBAAoBO;QACnCV,OAAOgB,QAAQC,OAAO,CAAC;YACrBC,WAAWE;YACXL,MAAMnB,KAAKwB,YAAY;YACvBD,MAAM;QACR;IACF;IAEAlB,KAAK,wCAAwC;QAC3C,MAAM,EAACM,UAAU,EAAEE,YAAY,EAAC,GAAG,MAAM,MAAM,CAAC;QAEhDP,GAAGW,MAAM,CAACN,YAAYc,eAAe,CAAC;QACtCnB,GAAGW,MAAM,CAACJ,cAAcY,eAAe,CAACC,KAAKC,SAAS,CAAC;YAACC,MAAM;QAAK;QAEnExB,OAAO,IAAMG,oBAAoBO,UAAUe,OAAO,CAAC;IACrD;IAEAxB,KAAK,6CAA6C;QAChD,MAAM,EAACM,UAAU,EAAEE,YAAY,EAAC,GAAG,MAAM,MAAM,CAAC;QAEhDP,GAAGW,MAAM,CAACN,YAAYc,eAAe,CAAC;QACtCnB,GAAGW,MAAM,CAACJ,cAAcY,eAAe,CAACC,KAAKC,SAAS,CAAC;YAACC,MAAM;QAAI;QAElExB,OAAO,IAAMG,oBAAoBO,UAAUe,OAAO,CAChD;IAEJ;AACF"}
@@ -1,31 +0,0 @@
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
@@ -1 +0,0 @@
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,16 +0,0 @@
1
- import { type CliConfig } from './types/cliConfig.js';
2
- /**
3
- * Get the CLI config for a project, given the root path.
4
- *
5
- * We really want to avoid loading the CLI config in the main thread, as we'll need
6
- * TypeScript loading logic, potentially with ts path aliases, syntax extensions and all
7
- * sorts of nonsense. Thus, we _attempt_ to use a worker thread - but have to fall back
8
- * to using the main thread if not possible. This can be the case if the configuration
9
- * contains non-serializable properties, such as functions. This is unfortunately used
10
- * by the vite config, for example.
11
- *
12
- * @param rootPath - Root path for the project, eg where `sanity.cli.(ts|js)` is located.
13
- * @returns The CLI config
14
- * @internal
15
- */
16
- export declare function getCliConfig(rootPath: string): Promise<CliConfig>;
@@ -1 +0,0 @@
1
- export {};
@@ -1,12 +0,0 @@
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;