1
+ import { performance } from 'node:perf_hooks'
2
+
1
3
import bodyparser from 'body-parser'
2
4
import Hook from 'console-feed/lib/Hook'
3
5
import { Encode } from 'console-feed/lib/Transform'
4
- import Debug from 'debug'
5
6
import { parseURL , withoutLeadingSlash } from 'ufo'
6
7
8
+ import { debug } from '@/common/log'
7
9
import { RESOLVED_NODE_ID , VIRUTAL_NODE_ID } from '@/common/resolver/constants'
8
10
import { isEsmSh } from '@/common/resolver/is'
9
11
import {
@@ -16,8 +18,6 @@ import { createStore } from '@/common/store'
16
18
17
19
import type { Plugin } from 'vite'
18
20
19
- const debug = Debug ( 'vsit:plugin' )
20
-
21
21
export const PluginVit = ( ) : Plugin [ ] => {
22
22
let content = ''
23
23
const store = createStore ( )
@@ -35,12 +35,12 @@ export const PluginVit = (): Plugin[] => {
35
35
if ( url . pathname === '/update-fake-node-file' && req . method === 'POST' ) {
36
36
const body = ( req as any ) . body as { content : string }
37
37
content = injectConsoleHook ( body . content )
38
- debug ( 'update fake node file %s' , content )
38
+ debug . plugin ( 'update fake node file %s' , content )
39
39
res . end ( 'ok' )
40
40
return
41
41
}
42
42
if ( url . pathname === '/fake-node-file' && req . method === 'GET' ) {
43
- debug ( 'request latest fake node file' )
43
+ debug . plugin ( 'request latest fake node file' )
44
44
try {
45
45
// console.log('request', req.url)
46
46
// /fake-node-file?t=<timestamp>
@@ -89,9 +89,11 @@ export const PluginVit = (): Plugin[] => {
89
89
// vite will remove duplicate slash if id starts with 'https://'
90
90
if ( isEsmSh ( id ) ) {
91
91
// un wrap
92
+ const now = performance . now ( )
92
93
const url = unWrapId ( id )
93
94
const code = await store . fetch ( url )
94
95
const resolvedCode = wrapCode ( code )
96
+ debug . benchmark ( 'load url %s took' , url , `${ ( performance . now ( ) - now ) / 1000 } ms` )
95
97
return {
96
98
code : resolvedCode ,
97
99
moduleSideEffects : false ,
0 commit comments