Skip to content

Commit 78aa088

Browse files
committed
chore: improve internal type safety and enable strict mode
1 parent c308cc5 commit 78aa088

File tree

5 files changed

+23
-15
lines changed

5 files changed

+23
-15
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"jiti": "^1.21.0",
5656
"nuxi": "^3.11.1",
5757
"nuxt": "^3.11.2",
58+
"typescript": "^5.4.5",
5859
"vitest": "^1.5.2",
5960
"vue": "^3.4.25",
6061
"vue-tsc": "^2.0.14"

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const main = defineCommand({
1919
setup(context) {
2020
// TODO: support 'default command' in citty?
2121
const firstArg = context.rawArgs[0]
22-
if (context.cmd.subCommands && !(firstArg in context.cmd.subCommands)) {
22+
if (context.cmd.subCommands && !(firstArg && firstArg in context.cmd.subCommands)) {
2323
consola.warn('Please specify the `build` command explicitly. In a future version of `@nuxt/module-builder`, the implicit default build command will be removed.')
2424
context.rawArgs.unshift('build')
2525
}

src/commands/build.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { existsSync, promises as fsp } from 'node:fs'
22
import { pathToFileURL } from 'node:url'
33
import { dirname, resolve } from 'pathe'
44
import { readTSConfig } from 'pkg-types'
5+
import type { TSConfig } from 'pkg-types'
56
import { defu } from 'defu'
67
import { consola } from 'consola'
78
import type { ModuleMeta, NuxtModule } from '@nuxt/schema'
@@ -82,7 +83,7 @@ export default defineCommand({
8283

8384
// Load module meta
8485
const moduleEntryPath = resolve(ctx.options.outDir, 'module.mjs')
85-
const moduleFn: NuxtModule<unknown> = await import(
86+
const moduleFn: NuxtModule<Record<string, unknown>> = await import(
8687
pathToFileURL(moduleEntryPath).toString()
8788
).then(r => r.default || r).catch((err) => {
8889
consola.error(err)
@@ -201,13 +202,14 @@ module.exports.getMeta = () => Promise.resolve(_meta)
201202
await fsp.writeFile(cjsStubFile, cjsStub, 'utf8')
202203
}
203204

204-
async function loadTSCompilerOptions(path: string) {
205+
async function loadTSCompilerOptions(path: string): Promise<NonNullable<TSConfig['compilerOptions']>> {
205206
const config = await readTSConfig(path).catch(() => {})
206207

207208
if (!config) return []
208209

209-
for (const alias in config.compilerOptions?.paths || {}) {
210-
config.compilerOptions.paths[alias] = config.compilerOptions.paths[alias].map((p) => {
210+
config.compilerOptions ||= {}
211+
for (const alias in config.compilerOptions.paths || {}) {
212+
config.compilerOptions.paths[alias] = config.compilerOptions.paths[alias].map((p: string) => {
211213
if (!/^\.{1,2}(\/|$)/.test(p)) return p
212214

213215
return resolve(path, p)

tsconfig.json

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
{
22
"compilerOptions": {
3-
"baseUrl": ".",
3+
"esModuleInterop": true,
44
"skipLibCheck": true,
5-
"target": "ESNext",
6-
"module": "ESNext",
7-
"verbatimModuleSyntax": true,
5+
"target": "es2022",
6+
"allowJs": true,
87
"resolveJsonModule": true,
9-
"moduleResolution": "Node",
10-
"esModuleInterop": true,
11-
"declaration": true,
12-
"types": [
13-
"node"
14-
]
8+
"moduleDetection": "force",
9+
"isolatedModules": true,
10+
"verbatimModuleSyntax": true,
11+
"strict": true,
12+
"noUncheckedIndexedAccess": true,
13+
"noImplicitOverride": true,
14+
"module": "ESNext",
15+
"moduleResolution": "Bundler",
16+
"declaration": true
1517
},
1618
"include": [
1719
"src",

0 commit comments

Comments
 (0)