Skip to content

Commit 3f37c21

Browse files
authoredMar 21, 2024
fix: move typegen cli into @sanity/cli (#6111)
1 parent 69a5d6d commit 3f37c21

File tree

14 files changed

+30
-36
lines changed

14 files changed

+30
-36
lines changed
 

‎packages/@sanity/cli/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
},
6464
"dependencies": {
6565
"@babel/traverse": "^7.23.5",
66+
"@sanity/codegen": "3.35.2",
6667
"@sanity/telemetry": "^0.7.6",
6768
"@sanity/util": "3.35.2",
6869
"chalk": "^4.1.2",
@@ -71,6 +72,7 @@
7172
"esbuild-register": "^3.4.1",
7273
"get-it": "^8.4.16",
7374
"golden-fleece": "^1.0.9",
75+
"groq-js": "^1.5.0",
7476
"node-machine-id": "^1.1.12",
7577
"pkg-dir": "^5.0.0",
7678
"semver": "^7.3.5",

‎packages/sanity/src/_internal/cli/actions/typegen/generateAction.ts renamed to ‎packages/@sanity/cli/src/actions/typegen/generateAction.ts

+5-17
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import {constants, open} from 'node:fs/promises'
2-
import {dirname, join} from 'node:path'
2+
import {join} from 'node:path'
33

4-
import {type CliCommandArguments, type CliCommandContext} from '@sanity/cli'
54
import {readConfig} from '@sanity/codegen'
6-
import readPkgUp from 'read-pkg-up'
75
import {Worker} from 'worker_threads'
86

7+
import {type CliCommandArguments, type CliCommandContext} from '../../types'
8+
import {getCliWorkerPath} from '../../util/cliWorker'
99
import {
1010
type TypegenGenerateTypesWorkerData,
1111
type TypegenGenerateTypesWorkerMessage,
12-
} from '../../threads/typegenGenerate'
12+
} from '../../workers/typegenGenerate'
1313
import {TypesGeneratedTrace} from './generate.telemetry'
1414

1515
export interface TypegenGenerateTypesCommandFlags {
@@ -42,19 +42,7 @@ export default async function typegenGenerateAction(
4242

4343
const codegenConfig = await readConfig(flags.configPath || 'sanity-typegen.json')
4444

45-
const rootPkgPath = readPkgUp.sync({cwd: __dirname})?.path
46-
if (!rootPkgPath) {
47-
throw new Error('Could not find the root directory for the `sanity` package')
48-
}
49-
50-
const workerPath = join(
51-
dirname(rootPkgPath),
52-
'lib',
53-
'_internal',
54-
'cli',
55-
'threads',
56-
'typegenGenerate.js',
57-
)
45+
const workerPath = await getCliWorkerPath('typegenGenerate')
5846

5947
const spinner = output.spinner({}).start('Generating types')
6048

‎packages/@sanity/cli/src/commands/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import disableTelemetryCommand from './telemetry/disableTelemetryCommand'
1414
import enableTelemetryCommand from './telemetry/enableTelemetryCommand'
1515
import telemetryGroup from './telemetry/telemetryGroup'
1616
import telemetryStatusCommand from './telemetry/telemetryStatusCommand'
17+
import generateTypegenCommand from './typegen/generateTypesCommand'
1718
import upgradeCommand from './upgrade/upgradeCommand'
1819
import versionsCommand from './versions/versionsCommand'
1920

@@ -35,4 +36,5 @@ export const baseCommands: (CliCommandDefinition | CliCommandGroupDefinition)[]
3536
disableTelemetryCommand,
3637
enableTelemetryCommand,
3738
telemetryStatusCommand,
39+
generateTypegenCommand,
3840
]

‎packages/sanity/src/_internal/cli/commands/typegen/generateTypesCommand.ts renamed to ‎packages/@sanity/cli/src/commands/typegen/generateTypesCommand.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {type CliCommandDefinition} from '@sanity/cli'
1+
import {type CliCommandDefinition} from '../../types'
22

33
const description = 'Generates TypeScript types from schema types and GROQ queries'
44

‎packages/sanity/src/_internal/cli/threads/typegenGenerate.ts renamed to ‎packages/@sanity/cli/src/workers/typegenGenerate.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import {isMainThread, parentPort, workerData as _workerData} from 'node:worker_threads'
2+
13
import {
24
findQueriesInPath,
35
getResolver,
@@ -7,7 +9,6 @@ import {
79
} from '@sanity/codegen'
810
import createDebug from 'debug'
911
import {parse, typeEvaluate, type TypeNode} from 'groq-js'
10-
import {isMainThread, parentPort, workerData as _workerData} from 'worker_threads'
1112

1213
const $info = createDebug('sanity:codegen:generate:info')
1314

‎packages/@sanity/cli/tsconfig.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,9 @@
1212
"jsx": "react-jsx",
1313
"resolveJsonModule": true
1414
},
15-
"references": [{"path": "../types/tsconfig.lib.json"}, {"path": "../util/tsconfig.lib.json"}]
15+
"references": [
16+
{"path": "../codegen/tsconfig.lib.json"},
17+
{"path": "../types/tsconfig.lib.json"},
18+
{"path": "../util/tsconfig.lib.json"}
19+
]
1620
}

‎packages/@sanity/cli/tsconfig.lib.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,9 @@
1818
"jsx": "react-jsx",
1919
"resolveJsonModule": true
2020
},
21-
"references": [{"path": "../types/tsconfig.lib.json"}, {"path": "../util/tsconfig.lib.json"}]
21+
"references": [
22+
{"path": "../codegen/tsconfig.lib.json"},
23+
{"path": "../types/tsconfig.lib.json"},
24+
{"path": "../util/tsconfig.lib.json"}
25+
]
2226
}

‎packages/sanity/package.config.ts

-5
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@ export default defineConfig({
4444
require: './lib/_internal/cli/threads/extractSchema.js',
4545
default: './lib/_internal/cli/threads/extractSchema.js',
4646
},
47-
'./_internal/cli/threads/typegenGenerate': {
48-
source: './src/_internal/cli/threads/typegenGenerate.ts',
49-
require: './lib/_internal/cli/threads/typegenGenerate.js',
50-
default: './lib/_internal/cli/threads/typegenGenerate.js',
51-
},
5247
}),
5348

5449
extract: {

‎packages/sanity/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@
199199
"@sanity/block-tools": "3.35.2",
200200
"@sanity/cli": "3.35.2",
201201
"@sanity/client": "^6.15.7",
202-
"@sanity/codegen": "workspace:*",
203202
"@sanity/color": "^3.0.0",
204203
"@sanity/diff": "3.35.2",
205204
"@sanity/diff-match-patch": "^3.1.1",

‎packages/sanity/src/_internal/cli/commands/index.ts

-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ import extractSchemaCommand from './schema/extractSchemaCommand'
5050
import schemaGroup from './schema/schemaGroup'
5151
import validateSchemaCommand from './schema/validateSchemaCommand'
5252
import startCommand from './start/startCommand'
53-
import generateTypegenCommand from './typegen/generateTypesCommand'
5453
import uninstallCommand from './uninstall/uninstallCommand'
5554
import inviteUserCommand from './users/inviteUserCommand'
5655
import listUsersCommand from './users/listUsersCommand'
@@ -98,7 +97,6 @@ const commands: (CliCommandDefinition | CliCommandGroupDefinition)[] = [
9897
queryDocumentsCommand,
9998
deleteDocumentsCommand,
10099
createDocumentsCommand,
101-
generateTypegenCommand,
102100
validateDocumentsCommand,
103101
graphqlGroup,
104102
listGraphQLAPIsCommand,

‎packages/sanity/tsconfig.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
{"path": "../@sanity/types/tsconfig.lib.json"},
4343
{"path": "../@sanity/cli/tsconfig.lib.json"},
4444
{"path": "../@sanity/util/tsconfig.lib.json"},
45-
{"path": "../@sanity/migrate/tsconfig.lib.json"},
46-
{"path": "../@sanity/codegen/tsconfig.lib.json"}
45+
{"path": "../@sanity/migrate/tsconfig.lib.json"}
4746
]
4847
}

‎packages/sanity/tsconfig.lib.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
{"path": "../@sanity/types/tsconfig.lib.json"},
4242
{"path": "../@sanity/cli/tsconfig.lib.json"},
4343
{"path": "../@sanity/util/tsconfig.lib.json"},
44-
{"path": "../@sanity/migrate/tsconfig.lib.json"},
45-
{"path": "../@sanity/codegen/tsconfig.lib.json"}
44+
{"path": "../@sanity/migrate/tsconfig.lib.json"}
4645
]
4746
}

‎pnpm-lock.yaml

+6-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.