Skip to content
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
4 changes: 1 addition & 3 deletions src/commands/prepare.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { relative, resolve } from 'pathe'
import { consola } from 'consola'
// we are deliberately inlining this code as a backup in case user has `@nuxt/schema<3.7`
import { writeTypes as writeTypesLegacy } from '@nuxt/kit'

import { defineCommand } from 'citty'
import { clearBuildDir } from '../utils/fs'
Expand All @@ -26,7 +24,7 @@ export default defineCommand({

const cwd = resolve(ctx.args.cwd || ctx.args.rootDir)

const { loadNuxt, buildNuxt, writeTypes = writeTypesLegacy } = await loadKit(cwd)
const { loadNuxt, buildNuxt, writeTypes } = await loadKit(cwd)
const nuxt = await loadNuxt({
cwd,
dotenv: {
Expand Down
5 changes: 1 addition & 4 deletions src/commands/typecheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import { defineCommand } from 'citty'
import { isBun } from 'std-env'
import { createJiti } from 'jiti'

// we are deliberately inlining this code as a backup in case user has `@nuxt/schema<3.7`
import { writeTypes as writeTypesLegacy } from '@nuxt/kit'

import { loadKit } from '../utils/kit'

import { cwdArgs, legacyRootDirArgs, logLevelArgs } from './_shared'
Expand All @@ -27,7 +24,7 @@ export default defineCommand({

const cwd = resolve(ctx.args.cwd || ctx.args.rootDir)

const { loadNuxt, buildNuxt, writeTypes = writeTypesLegacy } = await loadKit(cwd)
const { loadNuxt, buildNuxt, writeTypes } = await loadKit(cwd)
const nuxt = await loadNuxt({
cwd,
overrides: {
Expand Down
10 changes: 6 additions & 4 deletions src/utils/kit.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// we are deliberately inlining this code as a backup in case user has `@nuxt/schema<3.7`
import { writeTypes as writeTypesLegacy } from '@nuxt/kit'
import { createJiti } from 'jiti'

export const loadKit = async (rootDir: string): Promise<typeof import('@nuxt/kit')> => {
Expand All @@ -11,8 +9,12 @@ export const loadKit = async (rootDir: string): Promise<typeof import('@nuxt/kit
const rootURL = localKit ? rootDir : (await tryResolveNuxt(rootDir)) || rootDir
let kit: typeof import('@nuxt/kit') = await jiti.import('@nuxt/kit', { parentURL: rootURL })
if (!kit.writeTypes) {
// Polyfills for schema < 3.7
kit = { ...kit, writeTypes: writeTypesLegacy }
kit = {
...kit,
writeTypes: () => {
throw new Error('`writeTypes` is not available in this version of `@nuxt/kit`. Please upgrade to v3.7 or newer.')
},
}
}
return kit
}
Expand Down
Loading