source: node_modules/vite/bin/vite.js

Last change on this file was 57e58a3, checked in by ste08 <sjovanoska@…>, 4 months ago

Initial commit

  • Property mode set to 100644
File size: 2.0 KB
Line 
1#!/usr/bin/env node
2import { performance } from 'node:perf_hooks'
3import module from 'node:module'
4
5if (!import.meta.url.includes('node_modules')) {
6 try {
7 // only available as dev dependency
8 await import('source-map-support').then((r) => r.default.install())
9 } catch {}
10
11 process.on('unhandledRejection', (err) => {
12 throw new Error('UNHANDLED PROMISE REJECTION', { cause: err })
13 })
14}
15
16global.__vite_start_time = performance.now()
17
18// check debug mode first before requiring the CLI.
19const debugIndex = process.argv.findIndex((arg) => /^(?:-d|--debug)$/.test(arg))
20const filterIndex = process.argv.findIndex((arg) =>
21 /^(?:-f|--filter)$/.test(arg),
22)
23const profileIndex = process.argv.indexOf('--profile')
24
25if (debugIndex > 0) {
26 let value = process.argv[debugIndex + 1]
27 if (!value || value.startsWith('-')) {
28 value = 'vite:*'
29 } else {
30 // support debugging multiple flags with comma-separated list
31 value = value
32 .split(',')
33 .map((v) => `vite:${v}`)
34 .join(',')
35 }
36 process.env.DEBUG = `${
37 process.env.DEBUG ? process.env.DEBUG + ',' : ''
38 }${value}`
39
40 if (filterIndex > 0) {
41 const filter = process.argv[filterIndex + 1]
42 if (filter && !filter.startsWith('-')) {
43 process.env.VITE_DEBUG_FILTER = filter
44 }
45 }
46}
47
48function start() {
49 try {
50 // eslint-disable-next-line n/no-unsupported-features/node-builtins -- it is supported in Node 22.8.0+ and only called if it exists
51 module.enableCompileCache?.()
52 } catch {}
53 return import('../dist/node/cli.js')
54}
55
56if (profileIndex > 0) {
57 process.argv.splice(profileIndex, 1)
58 const next = process.argv[profileIndex]
59 if (next && !next.startsWith('-')) {
60 process.argv.splice(profileIndex, 1)
61 }
62 const inspector = await import('node:inspector').then((r) => r.default)
63 const session = (global.__vite_profile_session = new inspector.Session())
64 session.connect()
65 session.post('Profiler.enable', () => {
66 session.post('Profiler.start', start)
67 })
68} else {
69 start()
70}
Note: See TracBrowser for help on using the repository browser.