Skip to content

Commit

Permalink
style: lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pengzhanbo committed Oct 15, 2024
1 parent 28d7408 commit dbeaa33
Show file tree
Hide file tree
Showing 23 changed files with 84 additions and 84 deletions.
28 changes: 14 additions & 14 deletions src/core/baseMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
import { Buffer } from 'node:buffer'
import type * as http from 'node:http'
import type {
ExtraRequest,
Method,
MockHttpItem,
MockOptions,
MockRequest,
MockResponse,
MockServerPluginOptions,
ResponseBody,
} from '../types'
import type { Logger } from './logger'
import type { MockCompiler } from './mockCompiler'
import type { Middleware } from './mockMiddleware'
import { Buffer } from 'node:buffer'
import {
isArray,
isEmptyObject,
Expand All @@ -13,19 +26,7 @@ import HTTP_STATUS from 'http-status'
import * as mime from 'mime-types'
import { pathToRegexp } from 'path-to-regexp'
import colors from 'picocolors'
import type {
ExtraRequest,
Method,
MockHttpItem,
MockOptions,
MockRequest,
MockResponse,
MockServerPluginOptions,
ResponseBody,
} from '../types'
import type { Logger } from './logger'
import { matchingWeight } from './matchingWeight'
import type { MockCompiler } from './mockCompiler'
import { parseReqBody } from './parseReqBody'
import { collectRequest } from './requestRecovery'
import {
Expand All @@ -35,7 +36,6 @@ import {
urlParse,
} from './utils'
import { validate } from './validator'
import type { Middleware } from './mockMiddleware'

export interface BaseMiddlewareOptions {
formidableOptions: MockServerPluginOptions['formidableOptions']
Expand Down
10 changes: 5 additions & 5 deletions src/core/build.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { ServerBuildOption } from '../types'
import type { ResolvePluginOptions } from './resolvePluginOptions'
import fs from 'node:fs'
import fsp from 'node:fs/promises'
import path from 'node:path'
import process from 'node:process'
import fg from 'fast-glob'
import { toArray } from '@pengzhanbo/utils'
import { createFilter } from '@rollup/pluginutils'
import fg from 'fast-glob'
import color from 'picocolors'
import { toArray } from '@pengzhanbo/utils'
import type { ServerBuildOption } from '../types'
import { lookupFile, normalizePath, packageDir } from './utils'
import type { ResolvePluginOptions } from './resolvePluginOptions'
import { transformWithRspack } from './createRspackCompiler'
import { lookupFile, normalizePath, packageDir } from './utils'

export async function buildMockServer(
options: ResolvePluginOptions,
Expand Down
6 changes: 3 additions & 3 deletions src/core/createRspackCompiler.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { createRequire } from 'node:module'
import type { Compiler, RspackOptions, RspackPluginInstance } from '@rspack/core'
import { createRequire } from 'node:module'
import * as rspackCore from '@rspack/core'
import color from 'picocolors'
import isCore from 'is-core-module'
import color from 'picocolors'
import { vfs } from './utils'

const require = createRequire(import.meta.url)
Expand Down Expand Up @@ -68,7 +68,7 @@ export function createCompiler(
const compiler = rspackCore.rspack(rspackOptions, isWatch ? handler : undefined)

if (compiler)
compiler.outputFileSystem = vfs
compiler.outputFileSystem = vfs as unknown as rspackCore.OutputFileSystem

if (!isWatch) {
compiler?.run(async (...args) => {
Expand Down
2 changes: 1 addition & 1 deletion src/core/defineMock.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isArray } from '@pengzhanbo/utils'
import type { MockHttpItem, MockOptions, MockWebsocketItem } from '../types'
import { isArray } from '@pengzhanbo/utils'

/**
* mock config Type helper
Expand Down
2 changes: 1 addition & 1 deletion src/core/loadFromCode.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'node:path'
import fs, { promises as fsp } from 'node:fs'
import path from 'node:path'
import { pathToFileURL } from 'node:url'

interface LoadFromCodeOptions {
Expand Down
2 changes: 1 addition & 1 deletion src/core/logger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { LogLevel, LogType } from '../types'
import { isBoolean } from '@pengzhanbo/utils'
import colors from 'picocolors'
import type { LogLevel, LogType } from '../types'

export interface Logger {
debug: (msg: string, level?: boolean | LogLevel) => void
Expand Down
4 changes: 2 additions & 2 deletions src/core/matchingWeight.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { Token } from 'path-to-regexp'
import type { MockMatchPriority } from '../types'
/**
* 规则匹配优先级
*
Expand All @@ -18,9 +20,7 @@ import {
sortBy,
uniq,
} from '@pengzhanbo/utils'
import type { Token } from 'path-to-regexp'
import { parse, pathToRegexp } from 'path-to-regexp'
import type { MockMatchPriority } from '../types'

const tokensCache: Record<string, Token[]> = {}

Expand Down
24 changes: 12 additions & 12 deletions src/core/mockCompiler.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import EventEmitter from 'node:events'
import type { FSWatcher } from 'node:fs'
import process from 'node:process'
import path from 'node:path'
import type { Compiler, RspackPluginInstance } from '@rspack/core'
import fastGlob from 'fast-glob'
import chokidar from 'chokidar'
import { createFilter } from '@rollup/pluginutils'
import { toArray } from '@pengzhanbo/utils'
import type { FSWatcher } from 'node:fs'
import type { MockOptions } from '../types'
import { lookupFile } from './utils'
import { loadFromCode } from './loadFromCode'
import { transformMockData, transformRawData } from './transform'
import type { CompilerOptions } from './createRspackCompiler'
import { createCompiler } from './createRspackCompiler'
import type { Logger } from './logger'
import EventEmitter from 'node:events'
import path from 'node:path'
import process from 'node:process'
import { toArray } from '@pengzhanbo/utils'
import { createFilter } from '@rollup/pluginutils'
import chokidar from 'chokidar'
import fastGlob from 'fast-glob'
import { writeMockEntryFile } from './build'
import { createCompiler } from './createRspackCompiler'
import { loadFromCode } from './loadFromCode'
import { transformMockData, transformRawData } from './transform'
import { lookupFile } from './utils'

export interface MockCompilerOptions {
alias?: Record<string, false | string | (string | false)[]>
Expand Down
8 changes: 4 additions & 4 deletions src/core/mockMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type http from 'node:http'
import type { RspackOptionsNormalized, RspackPluginInstance } from '@rspack/core'
import type http from 'node:http'
import type { MockCompiler } from './mockCompiler'
import type { ResolvePluginOptions } from './resolvePluginOptions'
import cors, { type CorsOptions } from 'cors'
import { pathToRegexp } from 'path-to-regexp'
import type { ResolvePluginOptions } from './resolvePluginOptions'
import type { MockCompiler } from './mockCompiler'
import { doesProxyContextMatchUrl, urlParse } from './utils'
import { baseMiddleware } from './baseMiddleware'
import { doesProxyContextMatchUrl, urlParse } from './utils'

export interface MiddlewareOptions {
alias: Record<string, false | string | (string | false)[]>
Expand Down
8 changes: 4 additions & 4 deletions src/core/mockWebsocket.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import type { Server } from 'node:http'
import type { Http2SecureServer } from 'node:http2'
import Cookies from 'cookies'
import { pathToRegexp } from 'path-to-regexp'
import colors from 'picocolors'
import type { WebSocket } from 'ws'
import { WebSocketServer } from 'ws'
import type {
MockRequest,
MockServerPluginOptions,
Expand All @@ -13,6 +9,10 @@ import type {
} from '../types'
import type { Logger } from './logger'
import type { MockCompiler } from './mockCompiler'
import Cookies from 'cookies'
import { pathToRegexp } from 'path-to-regexp'
import colors from 'picocolors'
import { WebSocketServer } from 'ws'
import { doesProxyContextMatchUrl, parseParams, urlParse } from './utils'

type PoolMap = Map<string, WSSMap>
Expand Down
2 changes: 1 addition & 1 deletion src/core/parseReqBody.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type * as http from 'node:http'
import type { BodyParserOptions } from '../types'
import bodyParser from 'co-body'
import formidable from 'formidable'
import type { BodyParserOptions } from '../types'

export async function parseReqBody(
req: http.IncomingMessage,
Expand Down
2 changes: 1 addition & 1 deletion src/core/requestRecovery.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type * as http from 'node:http'
/**
* 请求复原
*
Expand All @@ -6,7 +7,6 @@
* 为此,我们在请求流中记录请求数据,当当前请求无法继续时,可以从备份中恢复请求流
*/
import { Buffer } from 'node:buffer'
import type * as http from 'node:http'

export const requestCollectCache = new WeakMap<http.IncomingMessage, Buffer>()

Expand Down
6 changes: 3 additions & 3 deletions src/core/resolvePluginOptions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import process from 'node:process'
import type { RspackPluginInstance } from '@rspack/core'
import { isBoolean, toArray } from '@pengzhanbo/utils'
import type { MockServerPluginOptions, ServerBuildOption } from '../types'
import { type Logger, createLogger } from './logger'
import process from 'node:process'
import { isBoolean, toArray } from '@pengzhanbo/utils'
import { createLogger, type Logger } from './logger'

export interface ResolvedCompilerOptions {
alias: Record<string, false | string | (string | false)[]>
Expand Down
2 changes: 1 addition & 1 deletion src/core/transform.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { MockHttpItem, MockOptions, MockWebsocketItem } from '../types'
import {
isEmptyObject,
isFunction,
isObject,
sortBy,
toArray,
} from '@pengzhanbo/utils'
import type { MockHttpItem, MockOptions, MockWebsocketItem } from '../types'
import { urlParse } from './utils'
import { isObjectSubset } from './validator'

Expand Down
10 changes: 5 additions & 5 deletions src/core/utils.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import fs from 'node:fs'
import path from 'node:path'
import type http from 'node:http'
import { parse as queryParse } from 'node:querystring'
import type { Readable, Stream } from 'node:stream'
import { URL, fileURLToPath } from 'node:url'
import fs from 'node:fs'
import os from 'node:os'
import path from 'node:path'
import { parse as queryParse } from 'node:querystring'
import { fileURLToPath, URL } from 'node:url'
import Debug from 'debug'
import { createFsFromVolume, Volume } from 'memfs'
import { match } from 'path-to-regexp'
import { Volume, createFsFromVolume } from 'memfs'

export const packageDir = getDirname(import.meta.url)
export const vfs = createFsFromVolume(new Volume())
Expand Down
2 changes: 1 addition & 1 deletion src/core/validator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isArray, isObject } from '@pengzhanbo/utils'
import type { ExtraRequest } from '../types'
import { isArray, isObject } from '@pengzhanbo/utils'

export function validate(
request: ExtraRequest,
Expand Down
2 changes: 1 addition & 1 deletion src/helper.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export type * from './types'
export * from './core/defineMock'
export * from './core/defineMockData'
export type * from './types'
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './rspack'
export * from './core/mockCompiler'
export * from './core/mockMiddleware'
export * from './core/mockWebsocket'
export * from './core/mockCompiler'
export * from './rspack'
16 changes: 8 additions & 8 deletions src/rsbuild.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import type { RsbuildConfig, RsbuildPlugin } from '@rsbuild/core'
import type { ProxyOptions } from '@rsbuild/core/dist-types/types'
import type * as http from 'node:http'
import process from 'node:process'
import type { MockServerPluginOptions } from './types'
import { createServer } from 'node:http'
import path from 'node:path'
import type { RsbuildConfig, RsbuildPlugin } from '@rsbuild/core'
import process from 'node:process'
import { isArray, toArray } from '@pengzhanbo/utils'
import rspack from '@rspack/core'
import color from 'picocolors'
import { getPortPromise } from 'portfinder'
import type { ProxyOptions } from '@rsbuild/core/dist-types/types'
import type { MockServerPluginOptions } from './types'
import { rewriteRequest } from './core/requestRecovery'
import { createMockMiddleware } from './core/mockMiddleware'
import { resolvePluginOptions } from './core/resolvePluginOptions'
import { buildMockServer } from './core/build'
import { createMockCompiler } from './core/mockCompiler'
import { createMockMiddleware } from './core/mockMiddleware'
import { mockWebSocket } from './core/mockWebsocket'
import { buildMockServer } from './core/build'
import { rewriteRequest } from './core/requestRecovery'
import { resolvePluginOptions } from './core/resolvePluginOptions'

export function pluginMockServer(options: MockServerPluginOptions = {}): RsbuildPlugin {
return {
Expand Down
14 changes: 7 additions & 7 deletions src/rspack.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import process from 'node:process'
import type { Compiler, RspackPluginInstance } from '@rspack/core'
import type { Server } from 'node:http'
import type { MockServerPluginOptions } from './types'
import path from 'node:path'
import type { Compiler, RspackPluginInstance } from '@rspack/core'
import rspack from '@rspack/core'
import process from 'node:process'
import { isString, toArray } from '@pengzhanbo/utils'
import type { MockServerPluginOptions } from './types'
import rspack from '@rspack/core'
import { buildMockServer } from './core/build'
import { createMockCompiler } from './core/mockCompiler'
import { createMockMiddleware } from './core/mockMiddleware'
import { mockWebSocket } from './core/mockWebsocket'
import { rewriteRequest } from './core/requestRecovery'
import {
type ResolvePluginOptions,
resolvePluginOptions as resolvePluginOptionsRaw,
} from './core/resolvePluginOptions'
import { createMockCompiler } from './core/mockCompiler'
import { mockWebSocket } from './core/mockWebsocket'
import { waitingFor } from './core/utils'
import { buildMockServer } from './core/build'

const PLUGIN_NAME = 'rspack-plugin-mock'

Expand Down
2 changes: 1 addition & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './core/baseMiddleware'
export * from './core/logger'
export * from './core/mockWebsocket'
export * from './core/transform'
export * from './core/logger'
8 changes: 4 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { Buffer } from 'node:buffer'
import type http from 'node:http'
import type { Readable } from 'node:stream'
import type { Options as COBodyOptions } from 'co-body'
import type Cookies from 'cookies'
import type { CorsOptions } from 'cors'
import type formidable from 'formidable'
import type { Buffer } from 'node:buffer'
import type http from 'node:http'
import type { Readable } from 'node:stream'
import type { WebSocketServer } from 'ws'
import type { Options as COBodyOptions } from 'co-body'

/**
* Configure plugin
Expand Down
4 changes: 2 additions & 2 deletions tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import process from 'node:process'
import { promises as fsp } from 'node:fs'
import path from 'node:path'
import { type Options, defineConfig } from 'tsup'
import process from 'node:process'
import fg from 'fast-glob'
import { defineConfig, type Options } from 'tsup'

const shared: Options = {
dts: true,
Expand Down

0 comments on commit dbeaa33

Please sign in to comment.