1 | #!/usr/bin/env node
|
2 | import { performance } from 'node:perf_hooks'
|
3 |
|
4 | if (!import.meta.url.includes('node_modules')) {
|
5 | try {
|
6 |
|
7 | await import('source-map-support').then((r) => r.default.install())
|
8 | } catch (e) {}
|
9 | }
|
10 |
|
11 | global.__vite_start_time = performance.now()
|
12 |
|
13 |
|
14 | const debugIndex = process.argv.findIndex((arg) => /^(?:-d|--debug)$/.test(arg))
|
15 | const filterIndex = process.argv.findIndex((arg) =>
|
16 | /^(?:-f|--filter)$/.test(arg),
|
17 | )
|
18 | const profileIndex = process.argv.indexOf('--profile')
|
19 |
|
20 | if (debugIndex > 0) {
|
21 | let value = process.argv[debugIndex + 1]
|
22 | if (!value || value.startsWith('-')) {
|
23 | value = 'vite:*'
|
24 | } else {
|
25 |
|
26 | value = value
|
27 | .split(',')
|
28 | .map((v) => `vite:${v}`)
|
29 | .join(',')
|
30 | }
|
31 | process.env.DEBUG = `${
|
32 | process.env.DEBUG ? process.env.DEBUG + ',' : ''
|
33 | }${value}`
|
34 |
|
35 | if (filterIndex > 0) {
|
36 | const filter = process.argv[filterIndex + 1]
|
37 | if (filter && !filter.startsWith('-')) {
|
38 | process.env.VITE_DEBUG_FILTER = filter
|
39 | }
|
40 | }
|
41 | }
|
42 |
|
43 | function start() {
|
44 | return import('../dist/node/cli.js')
|
45 | }
|
46 |
|
47 | if (profileIndex > 0) {
|
48 | process.argv.splice(profileIndex, 1)
|
49 | const next = process.argv[profileIndex]
|
50 | if (next && !next.startsWith('-')) {
|
51 | process.argv.splice(profileIndex, 1)
|
52 | }
|
53 | const inspector = await import('node:inspector').then((r) => r.default)
|
54 | const session = (global.__vite_profile_session = new inspector.Session())
|
55 | session.connect()
|
56 | session.post('Profiler.enable', () => {
|
57 | session.post('Profiler.start', start)
|
58 | })
|
59 | } else {
|
60 | start()
|
61 | }
|