Skip to content

Commit

Permalink
style: lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pengzhanbo committed Sep 16, 2024
1 parent fd596b7 commit 054f9f9
Show file tree
Hide file tree
Showing 20 changed files with 57 additions and 57 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ You can access related `mock` interfaces through `localhost:8080/`.
## Contributors

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-6-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-6-orange.svg?style=flat-square)](#contributors)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
Expand Down
2 changes: 1 addition & 1 deletion docs/en/examples/websocket.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export default defineMock({
::: code-group

```ts [ws-chat.mock.ts]
import type { MockRequest } from 'vite-plugin-mock-dev-server'
import { defineMock } from 'vite-plugin-mock-dev-server'
import type { MockRequest } from 'vite-plugin-mock-dev-server'

export default defineMock({
url: '/socket/chat',
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/websocket.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export default defineMock({
::: code-group

```ts [ws-chat.mock.ts]
import type { MockRequest } from 'vite-plugin-mock-dev-server'
import { defineMock } from 'vite-plugin-mock-dev-server'
import type { MockRequest } from 'vite-plugin-mock-dev-server'

export default defineMock({
url: '/socket/chat',
Expand Down
2 changes: 1 addition & 1 deletion example/mock/ws.mock.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { MockRequest } from 'vite-plugin-mock-dev-server'
import { defineMock } from 'vite-plugin-mock-dev-server'
import type { MockRequest } from 'vite-plugin-mock-dev-server'

export default defineMock({
url: '/socket.io',
Expand Down
2 changes: 1 addition & 1 deletion plugin/deprecate.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'node:path'
import fs from 'node:fs'
import path from 'node:path'
import process from 'node:process'

const deprecatedContent = `The CJS build of vite-plugin-mock-dev-server's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.`
Expand Down
20 changes: 10 additions & 10 deletions plugin/src/core/baseMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ import * as mime from 'mime-types'
import { pathToRegexp } from 'path-to-regexp'
import colors from 'picocolors'
import type { Connect } from 'vite'
import { matchingWeight } from './matchingWeight'
import { parseReqBody } from './parseReqBody'
import { collectRequest } from './requestRecovery'
import {
doesProxyContextMatchUrl,
isReadableStream,
parseParams,
urlParse,
} from './utils'
import { validate } from './validator'
import type {
ExtraRequest,
Method,
Expand All @@ -24,17 +34,7 @@ import type {
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 {
doesProxyContextMatchUrl,
isReadableStream,
parseParams,
urlParse,
} from './utils'
import { validate } from './validator'

export interface BaseMiddlewareOptions {
formidableOptions: MockServerPluginOptions['formidableOptions']
Expand Down
8 changes: 4 additions & 4 deletions plugin/src/core/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import fsp from 'node:fs/promises'
import path from 'node:path'
import process from 'node:process'
import { toArray } from '@pengzhanbo/utils'
import type { Metafile } from 'esbuild'
import { createFilter } from '@rollup/pluginutils'
import fg from 'fast-glob'
import isCore from 'is-core-module'
import type { Plugin } from 'vite'
import { createFilter } from '@rollup/pluginutils'
import c from 'picocolors'
import type { ServerBuildOption } from '../types'
import type { Metafile } from 'esbuild'
import type { Plugin } from 'vite'
import { aliasMatches, transformWithEsbuild } from './compiler'
import { lookupFile, normalizePath } from './utils'
import type { ServerBuildOption } from '../types'
import type { ResolvedMockServerPluginOptions } from './resolvePluginOptions'

declare const __PACKAGE_NAME__: string
Expand Down
4 changes: 2 additions & 2 deletions plugin/src/core/compiler.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import fs, { promises as fsp } from 'node:fs'
import path from 'node:path'
import { pathToFileURL } from 'node:url'
import process from 'node:process'
import type { Metafile, Plugin } from 'esbuild'
import { pathToFileURL } from 'node:url'
import { build } from 'esbuild'
import JSON5 from 'json5'
import type { Metafile, Plugin } from 'esbuild'
import type { Alias } from 'vite'

/* ===== esbuild begin ===== */
Expand Down
2 changes: 1 addition & 1 deletion plugin/src/core/matchingWeight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import {
sortBy,
uniq,
} from '@pengzhanbo/utils'
import type { Token } from 'path-to-regexp'
import { parse, pathToRegexp } from 'path-to-regexp'
import type { Token } from 'path-to-regexp'
import type { MockMatchPriority } from '../types'

const tokensCache: Record<string, Token[]> = {}
Expand Down
6 changes: 3 additions & 3 deletions plugin/src/core/mockCompiler.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import EventEmitter from 'node:events'
import process from 'node:process'
import { promiseParallel, toArray } from '@pengzhanbo/utils'
import { createFilter } from '@rollup/pluginutils'
import chokidar, { type FSWatcher } from 'chokidar'
import type { Metafile } from 'esbuild'
import fastGlob from 'fast-glob'
import { createFilter } from '@rollup/pluginutils'
import type { MockHttpItem, MockOptions, MockWebsocketItem } from '../types'
import type { Metafile } from 'esbuild'
import { loadFromCode, transformWithEsbuild } from './compiler'
import { transformMockData, transformRawData } from './transform'
import { debug, lookupFile, normalizePath } from './utils'
import type { MockHttpItem, MockOptions, MockWebsocketItem } from '../types'
import type { ResolvedMockServerPluginOptions } from './resolvePluginOptions'

export function createMockCompiler(options: ResolvedMockServerPluginOptions) {
Expand Down
6 changes: 3 additions & 3 deletions plugin/src/core/mockMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { Server } from 'node:http'
import type { Http2SecureServer } from 'node:http2'
import cors from 'cors'
import { pathToRegexp } from 'path-to-regexp'
import type { Server } from 'node:http'
import type { Http2SecureServer } from 'node:http2'
import type { Connect, WebSocketServer } from 'vite'
import { baseMiddleware } from './baseMiddleware'
import type { MockCompiler } from './mockCompiler'
import { createMockCompiler } from './mockCompiler'
import { doesProxyContextMatchUrl, urlParse } from './utils'
import { mockWebSocket } from './ws'
import type { MockCompiler } from './mockCompiler'
import type { ResolvedMockServerPluginOptions } from './resolvePluginOptions'

export function mockServerMiddleware(
Expand Down
6 changes: 3 additions & 3 deletions plugin/src/core/resolvePluginOptions.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import process from 'node:process'
import { isArray, isBoolean, toArray, uniq } from '@pengzhanbo/utils'
import type { Alias, AliasOptions, ResolvedConfig } from 'vite'
import color from 'picocolors'
import type { CorsOptions } from 'cors'
import type { MockServerPluginOptions, ServerBuildOption } from '../types'
import { type Logger, createLogger } from './logger'
import type { Alias, AliasOptions, ResolvedConfig } from 'vite'
import { viteDefine } from './define'
import { createLogger, type Logger } from './logger'
import { ensureProxies } from './utils'
import type { MockServerPluginOptions, ServerBuildOption } from '../types'

export type ResolvedMockServerPluginOptions = Required<
Omit<MockServerPluginOptions, 'build' | 'cors' | 'wsPrefix' | 'prefix'>
Expand Down
2 changes: 1 addition & 1 deletion plugin/src/core/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
sortBy,
toArray,
} from '@pengzhanbo/utils'
import type { MockHttpItem, MockOptions, MockWebsocketItem } from '../types'
import { urlParse } from './utils'
import { isObjectSubset } from './validator'
import type { MockHttpItem, MockOptions, MockWebsocketItem } from '../types'

type MockRawData = MockOptions | MockHttpItem | MockWebsocketItem | Record<string, MockOptions | MockHttpItem | MockWebsocketItem>

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

export function isStream(stream: unknown): stream is Stream {
Expand Down Expand Up @@ -65,8 +65,8 @@ export function ensureProxies(serverProxy: ResolvedConfig['server']['proxy'] = {
if (
typeof value === 'string'
|| (!value.ws
&& !value.target?.toString().startsWith('ws:')
&& !value.target?.toString().startsWith('wss:'))
&& !value.target?.toString().startsWith('ws:')
&& !value.target?.toString().startsWith('wss:'))
) {
httpProxies.push(key)
}
Expand Down
8 changes: 4 additions & 4 deletions plugin/src/core/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@
* 于 `server.proxy` 中,避免 vite 内的 http-proxy ws 与 插件的 ws 的冲突。
*/

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 { Server } from 'node:http'
import type { Http2SecureServer } from 'node:http2'
import type { WebSocket } from 'ws'
import { doesProxyContextMatchUrl, parseParams, urlParse } from './utils'
import type {
MockRequest,
MockWebsocketItem,
WebSocketSetupContext,
} from '../types'
import type { MockCompiler } from './mockCompiler'
import { doesProxyContextMatchUrl, parseParams, urlParse } from './utils'
import type { ResolvedMockServerPluginOptions } from './resolvePluginOptions'

type PoolMap = Map<string, WSSMap>
Expand Down
4 changes: 2 additions & 2 deletions plugin/src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ export * from './core/defineMock'
export * from './core/defineMockData'

export type {
MockOptions,
MockHttpItem,
MockWebsocketItem,
MockOptions,
MockRequest,
MockWebsocketItem,
} from './types'
12 changes: 6 additions & 6 deletions plugin/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { mockDevServerPlugin } from './plugin'

export * from './helper'

export * from './server'
export type {
FormidableFile,
MockOptions,
MockHttpItem,
MockWebsocketItem,
MockServerPluginOptions,
MockOptions,
MockRequest,
MockServerPluginOptions,
MockWebsocketItem,
} from './types'

export * from './helper'
export * from './server'

export { mockDevServerPlugin }

/** @deprecated use named export `mockDevServerPlugin` instead */
Expand Down
4 changes: 2 additions & 2 deletions plugin/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import type { Plugin, ResolvedConfig } from 'vite'
import { generateMockServer } from './core/build'
import { mockServerMiddleware } from './core/mockMiddleware'
import { recoverRequest } from './core/requestRecovery'
import type { MockServerPluginOptions } from './types'
import type { ResolvedMockServerPluginOptions } from './core/resolvePluginOptions'
import { resolvePluginOptions } from './core/resolvePluginOptions'
import type { ResolvedMockServerPluginOptions } from './core/resolvePluginOptions'
import type { MockServerPluginOptions } from './types'

export function mockDevServerPlugin(options: MockServerPluginOptions = {}): Plugin[] {
const plugins: Plugin[] = [serverPlugin(options)]
Expand Down
4 changes: 2 additions & 2 deletions plugin/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './core/baseMiddleware'
export * from './core/ws'
export * from './core/transform'
export * from './core/logger'
export * from './core/transform'
export * from './core/ws'
8 changes: 4 additions & 4 deletions plugin/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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 { Connect } from 'vite'
import type { WebSocketServer } from 'ws'
import type { Options as COBodyOptions } from 'co-body'

/**
* Configure plugin
Expand Down

0 comments on commit 054f9f9

Please sign in to comment.