Skip to content

Commit

Permalink
feat: add more official plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
ntnyq committed Sep 15, 2024
1 parent 53d01a0 commit 9807e3f
Show file tree
Hide file tree
Showing 18 changed files with 187 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
"iife",
"jridgewell",
"jsxdev",
"kwai",
"nerv",
"nextjs",
"nocheck",
"nosources",
"pnpm",
Expand Down
2 changes: 1 addition & 1 deletion src/config/packages/postcss-html-transform.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* `postcss-html-transform` 配置
*
* @see https://github.com/NervJS/taro/tree/next/packages/postcss-html-transform
* @see https://github.com/NervJS/taro/tree/main/packages/postcss-html-transform
*/

import type { LiteralUnion } from '../../utility-types'
Expand Down
2 changes: 1 addition & 1 deletion src/config/packages/postcss-pxtransform.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* `postcss-pxtransform` 配置
*
* @see https://github.com/NervJS/taro/tree/next/packages/postcss-pxtransform#配置-options
* @see https://github.com/NervJS/taro/tree/main/packages/postcss-pxtransform#配置-options
*/

import type { DesignWidth } from '../design-width'
Expand Down
49 changes: 36 additions & 13 deletions src/config/plugin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,50 @@
* @see https://nervjs.github.io/taro-docs/docs/config-detail#plugins
*/

import type { Awaitable } from '../utility-types'
import type { PluginHtmlOptions, PluginHttpOptions, PluginInjectOptions } from './plugins'
import type { Awaitable, ExcludeEmptyObjects } from '../utility-types'
import type {
PluginHtmlOptions,
PluginHttpOptions,
PluginIndieOptions,
PluginInjectOptions,
PluginMiniCIOptions,
PluginMockOptions,
PluginPlatformAlipayDdOptions,
PluginPlatformKwaiOptions,
PluginPlatformLarkOptions,
PluginPlatformNextJsOptions,
PluginPlatformXhsOptions,
} from './plugins'

export interface OfficialPluginOptionsMap {
'@tarojs/plugin-html': PluginHtmlOptions
'@tarojs/plugin-inject': PluginInjectOptions
'@tarojs/plugin-http': PluginHttpOptions
'@tarojs/plugin-mock': PluginMockOptions
'@tarojs/plugin-indie': PluginIndieOptions
'@tarojs/plugin-mini-ci': PluginMiniCIOptions

/**
* Platform plugins
*/
'@tarojs/plugin-platform-xhs': PluginPlatformXhsOptions
'@tarojs/plugin-platform-lark': PluginPlatformLarkOptions
'@tarojs/plugin-platform-kwai': PluginPlatformKwaiOptions
'@tarojs/plugin-platform-alipay-dd': PluginPlatformAlipayDdOptions

// // Official
'tarojs-plugin-platform-nextjs': PluginPlatformNextJsOptions
}

export type OfficialPluginName = keyof OfficialPluginOptionsMap

export type OfficialPluginTuple<K extends OfficialPluginName = OfficialPluginName> =
| [K, OfficialPluginOptionsMap[K]?]
| [K, () => Awaitable<OfficialPluginOptionsMap[K]>]

export interface CustomPluginOptionsMap {}
export type PluginsOptionsMap = OfficialPluginOptionsMap & CustomPluginOptionsMap

export type OfficialPluginName = keyof OfficialPluginOptionsMap
export type CustomPluginName = keyof CustomPluginOptionsMap
export type PluginName = keyof PluginsOptionsMap

export type CustomPluginTuple<K extends CustomPluginName = CustomPluginName> =
| [K, CustomPluginOptionsMap[K]?]
| [K, () => Awaitable<CustomPluginOptionsMap[K]>]
export type PluginTuple<T extends PluginName = PluginName> =
| [T]
| [T, ExcludeEmptyObjects<PluginsOptionsMap>[T]]
| [T, () => Awaitable<ExcludeEmptyObjects<PluginsOptionsMap>[T]>]

export type Plugin = OfficialPluginName | OfficialPluginTuple | CustomPluginName | CustomPluginTuple
export type Plugin = PluginName | PluginTuple
2 changes: 1 addition & 1 deletion src/config/plugins/html.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Options for `@tarojs/plugin-html`
*
* @see https://github.com/NervJS/taro/tree/next/packages/taro-plugin-html
* @see https://github.com/NervJS/taro/tree/main/packages/taro-plugin-html
*/

export interface PluginHtmlOptions {
Expand Down
2 changes: 1 addition & 1 deletion src/config/plugins/http.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Options for `@tarojs/plugin-http`
*
* @see https://github.com/NervJS/taro/tree/next/packages/taro-plugin-http
* @see https://github.com/NervJS/taro/tree/main/packages/taro-plugin-http
*/

export interface PluginHttpOptions {
Expand Down
10 changes: 10 additions & 0 deletions src/config/plugins/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
export * from './html'
export * from './http'
export * from './inject'
export * from './miniCI'

export * from './mock'
export * from './indie'

export * from './platformKwai'
export * from './platformLark'
export * from './platformXhs'
export * from './platformNextJs'
export * from './platformAlipayDd'
13 changes: 13 additions & 0 deletions src/config/plugins/indie.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Options for `@tarojs/plugin-indie`
*
* @see https://github.com/NervJS/taro-plugin-indie
*/

export interface PluginIndieOptions {
/**
* 插件支持自定义小程序样式处理规则
* @see https://github.com/NervJS/taro-plugin-indie?tab=readme-ov-file#1-pathstyleimportwithcustomrule
*/
pathStyleImportWithCustomRule?: (filename: string) => boolean
}
2 changes: 1 addition & 1 deletion src/config/plugins/inject.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Options for `@tarojs/plugin-inject`
*
* @see https://github.com/NervJS/taro/tree/next/packages/taro-plugin-inject
* @see https://github.com/NervJS/taro/tree/main/packages/taro-plugin-inject
*/

type VoidComponents = Set<string>
Expand Down
7 changes: 7 additions & 0 deletions src/config/plugins/miniCI.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Options for `@tarojs/plugin-mini-ci`
*
* @see https://github.com/NervJS/taro/tree/main/packages/taro-plugin-mini-ci
*/

export interface PluginMiniCIOptions {}
31 changes: 31 additions & 0 deletions src/config/plugins/mock.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Options for `@tarojs/plugin-mock`
*
* @see https://github.com/NervJS/taro-plugin-mock
*/

import type { LiteralUnion } from '../../utility-types'

type HTTPMethod = LiteralUnion<
'GET' | 'POST' | 'HEAD' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'PATCH'
>

export interface PluginMockOptions {
/**
* 数据 Mock 服务地址
* @default `127.0.0.1`
*/
host?: string

/**
* 数据 Mock 服务端口
* @default 9527
*/
port?: number

/**
* 数据 Mock 接口,可以使用 `mock` 目录下文件
* @see https://github.com/NervJS/taro-plugin-mock?tab=readme-ov-file#%E5%8F%82%E6%95%B0
*/
mocks?: Record<`${HTTPMethod} ${string}`, Record<string, any>>
}
7 changes: 7 additions & 0 deletions src/config/plugins/platformAlipayDd.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Options for `@tarojs/plugin-platform-alipay-dd`
*
* @see https://github.com/NervJS/taro-plugin-platform-alipay-dd
*/

export interface PluginPlatformAlipayDdOptions {}
7 changes: 7 additions & 0 deletions src/config/plugins/platformKwai.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Options for `@tarojs/plugin-platform-kwai`
*
* @see https://github.com/NervJS/taro-plugin-platform-kwai
*/

export interface PluginPlatformKwaiOptions {}
20 changes: 20 additions & 0 deletions src/config/plugins/platformLark.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Options for `@tarojs/plugin-platform-lark`
*
* @see https://github.com/NervJS/taro-plugin-platform-lark
*/

export interface PluginPlatformLarkOptions {
/**
* Lark 小程序是否支持 PC 端的组件属性
* @default false
*/
pc?: boolean

/**
* Lark 小程序编译时的入口文件
* @see https://github.com/NervJS/taro-plugin-platform-lark?tab=readme-ov-file#%E6%8F%92%E4%BB%B6%E9%80%89%E9%A1%B9
* @default undefined
*/
entry?: string
}
24 changes: 24 additions & 0 deletions src/config/plugins/platformNextJs.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Options for `@tarojs/plugin-platform-nextjs`
*
* @see https://github.com/NervJS/tarojs-plugin-ssr
*/

export interface PluginPlatformNextJsOptions {
/**
* 执行 taro build --type nextjs --watch 命令后,是否需要自动执行 next dev 命令
* @default true
*/
runNextjs?: boolean

/**
* 是否启动后自动打开浏览器
* @default true
*/
browser?: boolean

/**
* 插件编译阶段需要复制到 Next.js 中的附加文件
*/
extraFiles?: string[]
}
7 changes: 7 additions & 0 deletions src/config/plugins/platformXhs.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Options for `@tarojs/plugin-platform-xhs`
*
* @see https://github.com/NervJS/taro-plugin-platform-xhs
*/

export interface PluginPlatformXhsOptions {}
12 changes: 12 additions & 0 deletions src/utility-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,15 @@ export type AnyFn<T = unknown> = (...args: T[]) => T
export type LiteralUnion<Union extends Base, Base = string> =
| Union
| (Base & { zz_IGNORE_ME?: never })

/**
* Non empty object `{}`
*/
export type NonEmptyObject<T> = T extends Record<string, never> ? never : T

/**
* Exclude empty object properties from a type
*/
export type ExcludeEmptyObjects<T> = {
[K in keyof T]: NonEmptyObject<T[K]>
}
6 changes: 6 additions & 0 deletions test/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ it('define base config', () => {
enable: true,
},
],
[
'@tarojs/plugin-indie',
() => ({
pathStyleImportWithCustomRule: () => true,
}),
],
],
presets: [],
terser: {
Expand Down

0 comments on commit 9807e3f

Please sign in to comment.