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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ jobs:
- run: pnpm test -- --coverage
- run: pnpm build
- run: pnpm example:build
- run: pnpm test:types
- run: npx publint
working-directory: example
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ package-lock.json
.nuxt
.output
.idea/
example/playground/.nuxtrc
11 changes: 9 additions & 2 deletions example/playground/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
export default defineNuxtConfig({
modules: ['../src/module'],
myModule: {}
modules: ['my-module'],
myModule: {
apiKey: '',
// @ts-expect-error invalid configuration key
api: ''
},
hooks: {
'my-module:init' () {}
}
})
9 changes: 9 additions & 0 deletions example/playground/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
{
"private": true,
"name": "my-module-playground",
"scripts": {
"test:types": "pnpm test:types:bundler && pnpm test:types:node10",
"test:types:bundler": "echo typescript.tsConfig.compilerOptions.moduleResolution=bundler > .nuxtrc && nuxt prepare && vue-tsc --noEmit",
"test:types:node10": "echo typescript.tsConfig.compilerOptions.moduleResolution=node10 > .nuxtrc && nuxt prepare && vue-tsc --noEmit"
},
"dependencies": {
"my-module": "workspace:*",
"nuxt": "latest"
},
"devDependencies": {
"typescript": "^5.3.2",
"vue-tsc": "^1.8.22"
}
}
3 changes: 3 additions & 0 deletions example/playground/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "./.nuxt/tsconfig.json"
}
15 changes: 15 additions & 0 deletions example/playground/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { describe, expectTypeOf, it } from 'vitest'
import { useNuxtApp } from '#app'

describe('', () => {
it('should have typed injection', () => {
expectTypeOf(useNuxtApp().$injection).toEqualTypeOf<'injected'>()
})
it('should have typed runtime hooks', () => {
useNuxtApp().hook('my-module:runtime-hook', () => {})
})
it('should have typed runtime config', () => {
expectTypeOf(useRuntimeConfig().public.NAME).toEqualTypeOf<string>()
expectTypeOf(useRuntimeConfig().PRIVATE_NAME).toEqualTypeOf<string>()
})
})
4 changes: 2 additions & 2 deletions example/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ export interface ModuleOptions {
}

export interface ModuleHooks {
'my-module:init': any
'my-module:init': () => void
}

export interface RuntimeModuleHooks {
'my-module:runtime-hook': any
'my-module:runtime-hook': () => void
}

export interface ModulePublicRuntimeConfig {
Expand Down
11 changes: 9 additions & 2 deletions example/src/runtime/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
// TODO: fix module-builder failing to emit correct types
import type { Plugin } from 'nuxt/app'
import { defineNuxtPlugin } from '#imports'

export default defineNuxtPlugin((_nuxtApp) => {
export default defineNuxtPlugin(() => {
// eslint-disable-next-line no-console
console.log('Plugin injected by my-module!')
})
return {
provide: {
injection: 'injected' as const
}
}
}) as Plugin<{ injection: 'injected' }>
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"nuxt-module-build": "JITI_ESM_RESOLVE=1 jiti ./src/cli.ts",
"prepack": "pnpm build",
"release": "pnpm vitest run && pnpm build && changelogen --release && pnpm publish && git push --follow-tags",
"test": "pnpm vitest"
"test": "pnpm vitest",
"test:types": "tsc --noEmit && pnpm -r test:types"
},
"packageManager": "[email protected]",
"dependencies": {
Expand Down
104 changes: 94 additions & 10 deletions pnpm-lock.yaml

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

2 changes: 1 addition & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const main = defineCommand({
setup (context) {
// TODO: support 'default command' in citty?
const firstArg = context.rawArgs[0]
if (!(firstArg in context.cmd.subCommands)) {
if (context.cmd.subCommands && !(firstArg in context.cmd.subCommands)) {
consola.warn('Please specify the `build` command explicitly. In a future version of `@nuxt/module-builder`, the implicit default build command will be removed.')
context.rawArgs.unshift('build')
}
Expand Down
Loading