Skip to content

Commit

Permalink
refactor: re-organize types
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Nov 28, 2024
1 parent d702641 commit 2ebf5f5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
3 changes: 1 addition & 2 deletions src/farm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
5 changes: 5 additions & 0 deletions src/farm/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { JsPlugin } from '@farmfe/core'
import type { TransformResult } from '../types'
import path from 'path'
import * as querystring from 'querystring'
Expand Down Expand Up @@ -86,3 +87,7 @@ export function customParseQueryString(url: string | null) {

return paramsArray
}

export interface JsPluginExtended extends JsPlugin {
[key: string]: any
}
14 changes: 10 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }
Expand Down
12 changes: 1 addition & 11 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ResolvedUnpluginOptions } from './types'
import type { Arrayable, Nullable, ResolvedUnpluginOptions } from './types'
import { isAbsolute, normalize } from 'path'

/**
Expand All @@ -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))
Expand Down

0 comments on commit 2ebf5f5

Please sign in to comment.