| #!/usr/bin/env node |
| import { performance } from 'node:perf_hooks' |
| import module from 'node:module' |
|
|
| if (!import.meta.url.includes('node_modules')) { |
| if (!process.env.DEBUG_DISABLE_SOURCE_MAP) { |
| |
| process.setSourceMapsEnabled(true) |
| } |
|
|
| process.on('unhandledRejection', (err) => { |
| throw new Error('UNHANDLED PROMISE REJECTION', { cause: err }) |
| }) |
| } |
|
|
| global.__vite_start_time = performance.now() |
|
|
| |
| const debugIndex = process.argv.findIndex((arg) => /^(?:-d|--debug)$/.test(arg)) |
| const filterIndex = process.argv.findIndex((arg) => |
| /^(?:-f|--filter)$/.test(arg), |
| ) |
| const profileIndex = process.argv.indexOf('--profile') |
|
|
| if (debugIndex > 0) { |
| let value = process.argv[debugIndex + 1] |
| if (!value || value[0] === '-') { |
| value = 'vite:*' |
| } else { |
| |
| value = value |
| .split(',') |
| .map((v) => `vite:${v}`) |
| .join(',') |
| } |
| process.env.DEBUG = `${ |
| process.env.DEBUG ? process.env.DEBUG + ',' : '' |
| }${value}` |
|
|
| if (filterIndex > 0) { |
| const filter = process.argv[filterIndex + 1] |
| if (filter && filter[0] !== '-') { |
| process.env.VITE_DEBUG_FILTER = filter |
| } |
| } |
| } |
|
|
| function start() { |
| try { |
| |
| module.enableCompileCache?.() |
| |
| |
| |
| setTimeout(() => { |
| try { |
| |
| module.flushCompileCache?.() |
| } catch {} |
| }, 10 * 1000).unref() |
| } catch {} |
| return import('../dist/node/cli.js') |
| } |
|
|
| if (profileIndex > 0) { |
| process.argv.splice(profileIndex, 1) |
| const next = process.argv[profileIndex] |
| if (next && next[0] !== '-') { |
| process.argv.splice(profileIndex, 1) |
| } |
| const inspector = await import('node:inspector').then((r) => r.default) |
| const session = (global.__vite_profile_session = new inspector.Session()) |
| session.connect() |
| session.post('Profiler.enable', () => { |
| session.post('Profiler.start', start) |
| }) |
| } else { |
| start() |
| } |
|
|