Skip to content

Commit

Permalink
fix: move typegen cli into @sanity/cli (#6111)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgulseth committed Mar 21, 2024
1 parent 69a5d6d commit 3f37c21
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 36 deletions.
2 changes: 2 additions & 0 deletions packages/@sanity/cli/package.json
Expand Up @@ -63,6 +63,7 @@
},
"dependencies": {
"@babel/traverse": "^7.23.5",
"@sanity/codegen": "3.35.2",
"@sanity/telemetry": "^0.7.6",
"@sanity/util": "3.35.2",
"chalk": "^4.1.2",
Expand All @@ -71,6 +72,7 @@
"esbuild-register": "^3.4.1",
"get-it": "^8.4.16",
"golden-fleece": "^1.0.9",
"groq-js": "^1.5.0",
"node-machine-id": "^1.1.12",
"pkg-dir": "^5.0.0",
"semver": "^7.3.5",
Expand Down
@@ -1,15 +1,15 @@
import {constants, open} from 'node:fs/promises'
import {dirname, join} from 'node:path'
import {join} from 'node:path'

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

import {type CliCommandArguments, type CliCommandContext} from '../../types'
import {getCliWorkerPath} from '../../util/cliWorker'
import {
type TypegenGenerateTypesWorkerData,
type TypegenGenerateTypesWorkerMessage,
} from '../../threads/typegenGenerate'
} from '../../workers/typegenGenerate'
import {TypesGeneratedTrace} from './generate.telemetry'

export interface TypegenGenerateTypesCommandFlags {
Expand Down Expand Up @@ -42,19 +42,7 @@ export default async function typegenGenerateAction(

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

const rootPkgPath = readPkgUp.sync({cwd: __dirname})?.path
if (!rootPkgPath) {
throw new Error('Could not find the root directory for the `sanity` package')
}

const workerPath = join(
dirname(rootPkgPath),
'lib',
'_internal',
'cli',
'threads',
'typegenGenerate.js',
)
const workerPath = await getCliWorkerPath('typegenGenerate')

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

Expand Down
2 changes: 2 additions & 0 deletions packages/@sanity/cli/src/commands/index.ts
Expand Up @@ -14,6 +14,7 @@ import disableTelemetryCommand from './telemetry/disableTelemetryCommand'
import enableTelemetryCommand from './telemetry/enableTelemetryCommand'
import telemetryGroup from './telemetry/telemetryGroup'
import telemetryStatusCommand from './telemetry/telemetryStatusCommand'
import generateTypegenCommand from './typegen/generateTypesCommand'
import upgradeCommand from './upgrade/upgradeCommand'
import versionsCommand from './versions/versionsCommand'

Expand All @@ -35,4 +36,5 @@ export const baseCommands: (CliCommandDefinition | CliCommandGroupDefinition)[]
disableTelemetryCommand,
enableTelemetryCommand,
telemetryStatusCommand,
generateTypegenCommand,
]
@@ -1,4 +1,4 @@
import {type CliCommandDefinition} from '@sanity/cli'
import {type CliCommandDefinition} from '../../types'

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

Expand Down
@@ -1,3 +1,5 @@
import {isMainThread, parentPort, workerData as _workerData} from 'node:worker_threads'

import {
findQueriesInPath,
getResolver,
Expand All @@ -7,7 +9,6 @@ import {
} from '@sanity/codegen'
import createDebug from 'debug'
import {parse, typeEvaluate, type TypeNode} from 'groq-js'
import {isMainThread, parentPort, workerData as _workerData} from 'worker_threads'

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

Expand Down
6 changes: 5 additions & 1 deletion packages/@sanity/cli/tsconfig.json
Expand Up @@ -12,5 +12,9 @@
"jsx": "react-jsx",
"resolveJsonModule": true
},
"references": [{"path": "../types/tsconfig.lib.json"}, {"path": "../util/tsconfig.lib.json"}]
"references": [
{"path": "../codegen/tsconfig.lib.json"},
{"path": "../types/tsconfig.lib.json"},
{"path": "../util/tsconfig.lib.json"}
]
}
6 changes: 5 additions & 1 deletion packages/@sanity/cli/tsconfig.lib.json
Expand Up @@ -18,5 +18,9 @@
"jsx": "react-jsx",
"resolveJsonModule": true
},
"references": [{"path": "../types/tsconfig.lib.json"}, {"path": "../util/tsconfig.lib.json"}]
"references": [
{"path": "../codegen/tsconfig.lib.json"},
{"path": "../types/tsconfig.lib.json"},
{"path": "../util/tsconfig.lib.json"}
]
}
5 changes: 0 additions & 5 deletions packages/sanity/package.config.ts
Expand Up @@ -44,11 +44,6 @@ export default defineConfig({
require: './lib/_internal/cli/threads/extractSchema.js',
default: './lib/_internal/cli/threads/extractSchema.js',
},
'./_internal/cli/threads/typegenGenerate': {
source: './src/_internal/cli/threads/typegenGenerate.ts',
require: './lib/_internal/cli/threads/typegenGenerate.js',
default: './lib/_internal/cli/threads/typegenGenerate.js',
},
}),

extract: {
Expand Down
1 change: 0 additions & 1 deletion packages/sanity/package.json
Expand Up @@ -199,7 +199,6 @@
"@sanity/block-tools": "3.35.2",
"@sanity/cli": "3.35.2",
"@sanity/client": "^6.15.7",
"@sanity/codegen": "workspace:*",
"@sanity/color": "^3.0.0",
"@sanity/diff": "3.35.2",
"@sanity/diff-match-patch": "^3.1.1",
Expand Down
2 changes: 0 additions & 2 deletions packages/sanity/src/_internal/cli/commands/index.ts
Expand Up @@ -50,7 +50,6 @@ import extractSchemaCommand from './schema/extractSchemaCommand'
import schemaGroup from './schema/schemaGroup'
import validateSchemaCommand from './schema/validateSchemaCommand'
import startCommand from './start/startCommand'
import generateTypegenCommand from './typegen/generateTypesCommand'
import uninstallCommand from './uninstall/uninstallCommand'
import inviteUserCommand from './users/inviteUserCommand'
import listUsersCommand from './users/listUsersCommand'
Expand Down Expand Up @@ -98,7 +97,6 @@ const commands: (CliCommandDefinition | CliCommandGroupDefinition)[] = [
queryDocumentsCommand,
deleteDocumentsCommand,
createDocumentsCommand,
generateTypegenCommand,
validateDocumentsCommand,
graphqlGroup,
listGraphQLAPIsCommand,
Expand Down
3 changes: 1 addition & 2 deletions packages/sanity/tsconfig.json
Expand Up @@ -42,7 +42,6 @@
{"path": "../@sanity/types/tsconfig.lib.json"},
{"path": "../@sanity/cli/tsconfig.lib.json"},
{"path": "../@sanity/util/tsconfig.lib.json"},
{"path": "../@sanity/migrate/tsconfig.lib.json"},
{"path": "../@sanity/codegen/tsconfig.lib.json"}
{"path": "../@sanity/migrate/tsconfig.lib.json"}
]
}
3 changes: 1 addition & 2 deletions packages/sanity/tsconfig.lib.json
Expand Up @@ -41,7 +41,6 @@
{"path": "../@sanity/types/tsconfig.lib.json"},
{"path": "../@sanity/cli/tsconfig.lib.json"},
{"path": "../@sanity/util/tsconfig.lib.json"},
{"path": "../@sanity/migrate/tsconfig.lib.json"},
{"path": "../@sanity/codegen/tsconfig.lib.json"}
{"path": "../@sanity/migrate/tsconfig.lib.json"}
]
}
9 changes: 6 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3f37c21

Please sign in to comment.