Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): ensure output path for types exist before writing #6300

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/@sanity/cli/src/actions/typegen/generateAction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {constants, open, stat} from 'node:fs/promises'
import {join} from 'node:path'
import {constants, mkdir, open, stat} from 'node:fs/promises'
import {dirname, join} from 'node:path'

import {readConfig} from '@sanity/codegen'
import {Worker} from 'worker_threads'
Expand Down Expand Up @@ -70,8 +70,12 @@ export default async function typegenGenerateAction(
env: process.env,
})

const outputPath = join(process.cwd(), codegenConfig.generates)
const outputDir = dirname(outputPath)
await mkdir(outputDir, {recursive: true})

const typeFile = await open(
join(process.cwd(), codegenConfig.generates),
outputPath,
// eslint-disable-next-line no-bitwise
constants.O_TRUNC | constants.O_CREAT | constants.O_WRONLY,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"schema": "./working-schema.json"
"schema": "./working-schema.json",
"generates": "./out/types.ts"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we probably should have a test with a directory and one without a directory, but otherwise, 👍

}
Loading