From 2ebf5f5a61a56dd5eee1dcbf08a6d87d065dbbc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90=20Kevin=20Deng?= Date: Fri, 29 Nov 2024 00:33:58 +0800 Subject: [PATCH] refactor: re-organize types --- src/farm/index.ts | 3 +-- src/farm/utils.ts | 5 +++++ src/types.ts | 14 ++++++++++---- src/utils.ts | 12 +----------- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/farm/index.ts b/src/farm/index.ts index d0ed9c4..1212747 100644 --- a/src/farm/index.ts +++ b/src/farm/index.ts @@ -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' diff --git a/src/farm/utils.ts b/src/farm/utils.ts index dd3eb85..35f9691 100644 --- a/src/farm/utils.ts +++ b/src/farm/utils.ts @@ -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 +} diff --git a/src/types.ts b/src/types.ts index 6648f1d..02cbe9f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -21,6 +21,16 @@ export type { export type Thenable = T | Promise +/** + * Null or whatever + */ +export type Nullable = T | null | undefined + +/** + * Array, or not yet + */ +export type Arrayable = T | Array + 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 } diff --git a/src/utils.ts b/src/utils.ts index 767ffc5..9287653 100644 --- a/src/utils.ts +++ b/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 | null | undefined - -/** - * Array, or not yet - */ -export type Arrayable = T | Array - export function toArray(array?: Nullable>): Array { array = array || [] if (Array.isArray(array))