mirror of
https://github.com/unjs/unplugin.git
synced 2025-12-08 20:26:33 +00:00
refactor: re-organize types
This commit is contained in:
parent
d70264160f
commit
2ebf5f5a61
@ -8,14 +8,13 @@ import type {
|
||||
PluginTransformHookResult,
|
||||
} from '@farmfe/core'
|
||||
import type {
|
||||
JsPluginExtended,
|
||||
TransformResult,
|
||||
UnpluginContextMeta,
|
||||
UnpluginFactory,
|
||||
UnpluginInstance,
|
||||
UnpluginOptions,
|
||||
} from '../types'
|
||||
import type { WatchChangeEvents } from './utils'
|
||||
import type { JsPluginExtended, WatchChangeEvents } from './utils'
|
||||
import path from 'path'
|
||||
import { toArray } from '../utils'
|
||||
import { createFarmContext, unpluginContext } from './context'
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import type { JsPlugin } from '@farmfe/core'
|
||||
import type { TransformResult } from '../types'
|
||||
import path from 'path'
|
||||
import * as querystring from 'querystring'
|
||||
@ -86,3 +87,7 @@ export function customParseQueryString(url: string | null) {
|
||||
|
||||
return paramsArray
|
||||
}
|
||||
|
||||
export interface JsPluginExtended extends JsPlugin {
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
14
src/types.ts
14
src/types.ts
@ -21,6 +21,16 @@ export type {
|
||||
|
||||
export type Thenable<T> = T | Promise<T>
|
||||
|
||||
/**
|
||||
* Null or whatever
|
||||
*/
|
||||
export type Nullable<T> = T | null | undefined
|
||||
|
||||
/**
|
||||
* Array, or not yet
|
||||
*/
|
||||
export type Arrayable<T> = T | Array<T>
|
||||
|
||||
export interface SourceMapCompact {
|
||||
file?: string
|
||||
mappings: string
|
||||
@ -32,10 +42,6 @@ export interface SourceMapCompact {
|
||||
version: number
|
||||
}
|
||||
|
||||
export interface JsPluginExtended extends FarmPlugin {
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
export type TransformResult = string | { code: string, map?: SourceMapInput | SourceMapCompact | null } | null | undefined | void
|
||||
|
||||
export interface ExternalIdResult { id: string, external?: boolean }
|
||||
|
||||
12
src/utils.ts
12
src/utils.ts
@ -1,4 +1,4 @@
|
||||
import type { ResolvedUnpluginOptions } from './types'
|
||||
import type { Arrayable, Nullable, ResolvedUnpluginOptions } from './types'
|
||||
import { isAbsolute, normalize } from 'path'
|
||||
|
||||
/**
|
||||
@ -18,16 +18,6 @@ export function normalizeAbsolutePath(path: string) {
|
||||
return path
|
||||
}
|
||||
|
||||
/**
|
||||
* Null or whatever
|
||||
*/
|
||||
export type Nullable<T> = T | null | undefined
|
||||
|
||||
/**
|
||||
* Array, or not yet
|
||||
*/
|
||||
export type Arrayable<T> = T | Array<T>
|
||||
|
||||
export function toArray<T>(array?: Nullable<Arrayable<T>>): Array<T> {
|
||||
array = array || []
|
||||
if (Array.isArray(array))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user