/
inspect.ts
32 lines (24 loc) · 916 Bytes
/
inspect.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import debugFn from 'debug'
import type { PluginOption } from 'vite'
import type { ViteDevServerConfig } from '../devServer'
const debug = debugFn('cypress:vite-dev-server:plugins:inspect')
export const CypressInspect = (config: ViteDevServerConfig): PluginOption | null => {
if (!process.env.CYPRESS_INTERNAL_VITE_INSPECT) {
debug('skipping vite inspect because CYPRESS_INTERNAL_VITE_INSPECT is not set')
return null
}
let Inspect
try {
const inspectPluginPath = require.resolve('vite-plugin-inspect', { paths: [config.cypressConfig.projectRoot] })
Inspect = require(inspectPluginPath).default
debug('inspect was found', Inspect)
} catch (err) {
debug(`Tried to import the inspect plugin 'vite-plugin-inspect'. It's an optional peerDependency so install it if you'd like.`)
debug(err)
return null
}
return {
...Inspect(),
name: 'cypress:inspect',
}
}