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

chore: add ModuleOptions to generated types #42

Merged
merged 1 commit into from
Nov 16, 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
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,20 @@
"vant": ">=4"
},
"dependencies": {
"@nuxt/kit": "^3.12.2",
"@nuxt/kit": "^3.14.159",
"magic-string": "^0.29.0",
"unplugin": "^1.10.2"
"unplugin": "^1.16.0"
},
"devDependencies": {
"@nuxt/module-builder": "^0.5.5",
"@nuxt/schema": "^3.12.2",
"@nuxt/schema": "^3.14.159",
"@nuxtjs/eslint-config-typescript": "^12.1.0",
"@types/node": "^18.19.39",
"eslint": "^8.57.0",
"nuxt": "^3.12.2",
"typescript": "^5.5.2",
"vant": "^4.9.1",
"vue": "^3.4.31"
"@types/node": "^22.9.0",
"eslint": "^8.57.1",
"nuxt": "^3.14.159",
"typescript": "^5.6.3",
"vant": "^4.9.8",
"vue": "^3.5.12"
},
"publishConfig": {
"access": "public",
Expand Down
2 changes: 1 addition & 1 deletion playground/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineNuxtConfig } from 'nuxt/config'
import Vant from '..'
import Vant from '../src/module'

export default defineNuxtConfig({
modules: [Vant],
Expand Down
4,840 changes: 2,109 additions & 2,731 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import AllComponents from 'vant'
import type { Options, PresetImport } from './types'
import type { ModuleOptions, PresetImport } from './types'

export const libraryName = 'vant'

Expand Down Expand Up @@ -47,7 +47,7 @@ const defaultExclude: RegExp[] = [
/[\\/]\.nuxt[\\/]/
]

export const defaults: Options = {
export const defaults: ModuleOptions = {
lazyload: false,
importStyle: true,
components: allComponents,
Expand Down
4 changes: 2 additions & 2 deletions src/core/components.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { addComponent, createResolver } from '@nuxt/kit'
import { libraryName } from '../config'
import { hyphenate, toArray } from '../utils'
import type { Options } from '../types'
import type { ModuleOptions } from '../types'

export function resolveComponents (config: Options) {
export function resolveComponents (config: ModuleOptions) {
const { components, excludeExports } = config
const { resolvePath } = createResolver(import.meta.url)

Expand Down
4 changes: 2 additions & 2 deletions src/core/imports.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { addImportsSources } from '@nuxt/kit'
import { libraryName } from '../config'
import type { Options } from '../types'
import type { ModuleOptions } from '../types'

export function resolveImports (config: Options) {
export function resolveImports (config: ModuleOptions) {
const { imports } = config

addImportsSources({
Expand Down
4 changes: 2 additions & 2 deletions src/core/lazyload.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { libraryName } from '../config'
import { isObject } from '../utils'
import type { Options } from '../types'
import type { ModuleOptions } from '../types'

export function resolveLazyload (config: Options) {
export function resolveLazyload (config: ModuleOptions) {
const { lazyload } = config
const options = isObject(lazyload) ? `, ${JSON.stringify(lazyload)}` : ''

Expand Down
4 changes: 2 additions & 2 deletions src/core/styles.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { allImportsWithStyle, libraryName } from '../config'
import { hyphenate } from '../utils'
import type { Options } from '../types'
import type { ModuleOptions } from '../types'

export function getStyleDir (name: string) {
return `${libraryName}/es/${hyphenate(name)}/style/index.mjs`
}

export function resolveStyles (config: Options, name: string) {
export function resolveStyles (config: ModuleOptions, name: string) {
const { components, importStyle } = config

if (importStyle === false) { return undefined }
Expand Down
9 changes: 4 additions & 5 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@ import {
localePlugin,
transformPlugin
} from './core/index'
import type { Options } from './types'
import type { ModuleOptions } from './types'
export type { ModuleOptions } from './types'

export default defineNuxtModule<Partial<Options>>({
export default defineNuxtModule<ModuleOptions>({
meta: {
name: libraryName,
configKey: libraryName
},
defaults,
setup (_options, nuxt) {
const options = _options as Options

setup (options, nuxt) {
resolveOptions()
nuxt.options.imports.autoImport !== false && resolveImports(options)
nuxt.options.components !== false && resolveComponents(options)
Expand Down
11 changes: 1 addition & 10 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface TransformOptions {
exclude: RegExp[]
}

export interface Options extends TransformOptions {
export interface ModuleOptions extends TransformOptions {
/**
* Whether to automatically load lazyload directives and components.
*
Expand Down Expand Up @@ -49,12 +49,3 @@ export interface Options extends TransformOptions {
*/
imports: PresetImport[]
}

declare module '@nuxt/schema' {
interface NuxtConfig {
vant?: Partial<Options>
}
interface NuxtOptions {
vant?: Partial<Options>
}
}