-
Notifications
You must be signed in to change notification settings - Fork 0
/
typecheck.ts
63 lines (56 loc) · 1.66 KB
/
typecheck.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { execa } from 'execa'
import { resolve } from 'pathe'
// 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 { tryResolveModule } from '../utils/esm'
import { loadKit } from '../utils/kit'
import { defineCommand } from 'citty'
import { legacyRootDirArgs, sharedArgs } from './_shared'
export default defineCommand({
meta: {
name: 'typecheck',
description: 'Runs `vue-tsc` to check types throughout your app.',
},
args: {
...sharedArgs,
...legacyRootDirArgs,
},
async run(ctx) {
process.env.NODE_ENV = process.env.NODE_ENV || 'production'
const cwd = resolve(ctx.args.cwd || ctx.args.rootDir || '.')
const {
loadNuxt,
buildNuxt,
writeTypes = writeTypesLegacy,
} = await loadKit(cwd)
const nuxt = await loadNuxt({
cwd,
overrides: {
_prepare: true,
logLevel: ctx.args.logLevel as 'silent' | 'info' | 'verbose',
.../*ctx.options?.overrides || */ {},
},
})
// Generate types and build Nuxt instance
await writeTypes(nuxt)
await buildNuxt(nuxt)
await nuxt.close()
// Prefer local install if possible
const hasLocalInstall =
(await tryResolveModule('typescript', cwd)) &&
(await tryResolveModule('vue-tsc/package.json', cwd))
if (hasLocalInstall) {
await execa('vue-tsc', ['--noEmit'], {
preferLocal: true,
stdio: 'inherit',
cwd,
})
} else {
await execa(
'npx',
'-p vue-tsc -p typescript vue-tsc --noEmit'.split(' '),
{ stdio: 'inherit', cwd },
)
}
},
})