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 for @nuxt/schema #135

Merged
merged 2 commits into from
Nov 2, 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
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
"url": "https://github.com/element-plus/element-plus-nuxt/issues"
},
"scripts": {
"build": "npm run dev:prepare && nuxt-module-build",
"build": "npm run dev:prepare && nuxt-module-build build",
"dev": "nuxi dev playground",
"dev:build": "nuxi build playground",
"dev:start": "node playground/.output/server/index.mjs",
"dev:prepare": "nuxt-module-build --stub && nuxi prepare playground",
"dev:prepare": "nuxt-module-build build --stub && nuxi prepare playground",
"lint": "eslint . --fix --ext .ts,.vue,.js",
"lint:test": "eslint . --ext .ts,.vue,.js --max-warnings 0"
},
Expand All @@ -41,21 +41,21 @@
"element-plus": ">=2"
},
"dependencies": {
"@nuxt/kit": "^3.12.3",
"@nuxt/kit": "^3.13.2",
"magic-string": "^0.27.0",
"unplugin": "^1.11.0"
"unplugin": "^1.15.0"
},
"devDependencies": {
"@element-plus/icons-vue": "^2.3.1",
"@nuxt/module-builder": "^0.5.5",
"@nuxt/schema": "^3.12.3",
"@nuxt/schema": "^3.13.2",
"@nuxtjs/eslint-config-typescript": "^12.1.0",
"@types/node": "^20.14.10",
"element-plus": "^2.7.7",
"eslint": "^8.57.0",
"nuxi": "^3.12.0",
"nuxt": "^3.12.3",
"typescript": "^5.5.3",
"vue": "^3.4.31"
"@types/node": "^22.8.6",
"element-plus": "^2.8.7",
"eslint": "^8.57.1",
"nuxi": "^3.15.0",
"nuxt": "^3.13.2",
"typescript": "^5.6.3",
"vue": "^3.5.12"
}
}
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 ElementPlus from '..'
import ElementPlus from '../src/module'

export default defineNuxtConfig({
devtools: { enabled: true },
Expand Down
4,122 changes: 2,178 additions & 1,944 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
Expand Up @@ -4,7 +4,7 @@ import type { ElIdInjectionContext, ElZIndexInjectionContext } from 'element-plu
import type { Component } from 'vue'
import { getComponentPath } from './core/components'
import { isVueComponent } from './utils'
import type { Options, PresetDirectives, PresetImport } from './types'
import type { ModuleOptions, PresetDirectives, PresetImport } from './types'

export const libraryName = 'element-plus'

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

export const defaults: Options = {
export const defaults: ModuleOptions = {
components: allComponents,
subComponents: allSubComponents,
directives: allDirectives,
Expand Down
4 changes: 2 additions & 2 deletions src/core/components.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { addComponent } from '@nuxt/kit'
import { iconLibraryName, libraryName } from '../config'
import { genIconPresets, toArray, resolvePath, hyphenate } from '../utils'
import type { Options } from '../types'
import type { ModuleOptions } from '../types'

export function getComponentPath (name: string): string {
const dir = hyphenate(name.slice(2))
return `es/components/${dir}/index.mjs`
}

export function resolveComponents (config: Options) {
export function resolveComponents (config: ModuleOptions) {
const { components, subComponents, icon } = config
const icons = icon !== false ? genIconPresets(icon, iconLibraryName) : []
const allComponents = new Set([...components, ...icons])
Expand Down
4 changes: 2 additions & 2 deletions src/core/directives.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { libraryName } from '../config'
import { toArray } from '../utils'
import type { Options } from '../types'
import type { ModuleOptions } from '../types'
import { getComponentPath, getStyleDir } from './index'

export function resolveDirectives (
config: Options,
config: ModuleOptions,
name: string
): undefined | [name: string, path: string, style?: string] {
const { directives } = config
Expand Down
4 changes: 2 additions & 2 deletions src/core/globalConfig.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { libraryName } from '../config'
import type { Options } from '../types'
import type { ModuleOptions } from '../types'

export function resolveGlobalConfig (config: Options) {
export function resolveGlobalConfig (config: ModuleOptions) {
const { globalConfig } = config

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

export async function resolveImports (config: Options) {
export async function resolveImports (config: ModuleOptions) {
const { imports, icon } = config
const icons = icon !== false ? genIconPresets(icon) : []
const allImports = new Set(imports)
Expand Down
4 changes: 2 additions & 2 deletions src/core/injection.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { libraryName } from '../config'
import type { Options } from '../types'
import type { ModuleOptions } from '../types'

/** Inject some additional configuration into Vue at runtime */
export function resolveInjection (config: Options) {
export function resolveInjection (config: ModuleOptions) {
const { injectionID, injectionZIndex } = config

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

export function getStyleDir (config: Options, name: string) {
export function getStyleDir (config: ModuleOptions, name: string) {
if (config.importStyle === false) {
return undefined
}
Expand All @@ -12,7 +12,7 @@ export function getStyleDir (config: Options, name: string) {
return `${libraryName}/es/components/${dir}/style/${type}.mjs`
}

export function resolveStyles (config: Options, name: string) {
export function resolveStyles (config: ModuleOptions, name: string) {
const { components, noStylesComponents } = config
const allComponents = [...components, ...allImportsWithStyle]

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

export function resolveTeleports (config: Options) {
export function resolveTeleports (config: ModuleOptions) {
const { namespace, appendTo } = config
const defaultId = `#${namespace}-popper-container-`

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

export function resolveThemes (config: Options) {
export function resolveThemes (config: ModuleOptions) {
const nuxt = useNuxt()
const { themes, importStyle } = config
const allThemes = new Set(themes)
Expand Down
7 changes: 4 additions & 3 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import {
transformPlugin,
localePlugin
} 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: 'elementPlus',
Expand All @@ -25,7 +26,7 @@ export default defineNuxtModule<Partial<Options>>({
},
defaults,
setup (_options, nuxt) {
const options = _options as Options
const options = _options as ModuleOptions

resolveOptions()
resolveThemes(options)
Expand Down
11 changes: 1 addition & 10 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface TransformOptions {
exclude: RegExp[]
}

export interface Options extends TransformOptions {
export interface ModuleOptions extends TransformOptions {
/**
* A list of components that need to be automatically imported externally.
*
Expand Down Expand Up @@ -160,12 +160,3 @@ export interface Options extends TransformOptions {
*/
globalConfig?: ConfigProviderContext
}

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