Skip to content

Commit

Permalink
perf: constant variable provide check
Browse files Browse the repository at this point in the history
  • Loading branch information
pengzhanbo committed Jan 17, 2024
1 parent f1acafd commit 2af011c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import { ensureProxies, lookupFile, normalizePath } from './utils'
declare const __PACKAGE_NAME__: string
declare const __PACKAGE_VERSION__: string

const packageName = typeof __PACKAGE_NAME__ === 'string' ? __PACKAGE_NAME__ : 'vite-plugin-mock-dev-server'
const packageVersion = typeof __PACKAGE_VERSION__ === 'string' ? __PACKAGE_VERSION__ : 'latest'

type PluginContext<T = Plugin['buildEnd']> = T extends (
this: infer R,
...args: any[]
Expand Down Expand Up @@ -109,7 +112,7 @@ export async function generateMockServer(

function getMockDependencies(deps: Metafile['inputs'], alias: ResolvedConfig['resolve']['alias']): string[] {
const list = new Set<string>()
const excludeDeps = [__PACKAGE_NAME__, 'connect', 'cors']
const excludeDeps = [packageName, 'connect', 'cors']
const isAlias = (p: string) => alias.find(({ find }) => aliasMatches(find, p))
Object.keys(deps).forEach((mPath) => {
const imports = deps[mPath].imports
Expand All @@ -134,7 +137,7 @@ function generatePackageJson(pkg: any, mockDeps: string[]) {
},
dependencies: {
'connect': '^3.7.0',
'vite-plugin-mock-dev-server': `^${__PACKAGE_VERSION__}`,
'vite-plugin-mock-dev-server': `^${packageVersion}`,
'cors': '^2.8.5',
} as Record<string, string>,
pnpm: { peerDependencyRules: { ignoreMissing: ['vite'] } },
Expand Down

0 comments on commit 2af011c

Please sign in to comment.