refactor: re-organize types

This commit is contained in:
三咲智子 Kevin Deng 2024-11-29 00:33:58 +08:00
parent d70264160f
commit 2ebf5f5a61
No known key found for this signature in database
4 changed files with 17 additions and 17 deletions

View File

@ -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'

View File

@ -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
}

View File

@ -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 }

View File

@ -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))