Open History to see the last commit
1import path from 'node:path'
2β
3const isWindows: boolean =
4 typeof process !== 'undefined' && process.platform === 'win32'
5const windowsSlashRE = /\\/g
6β
7/**
8 * Read `build.rolldownOptions` from a build config. Vite 8 still accepts
9 * `build.rollupOptions` as a deprecated alias, and a user config can reach a
10 * plugin before Vite maps it.
11 */
12export function getBundlerOptions(build: any): any {
13 return build?.rolldownOptions ?? build?.rollupOptions
14}
15β
16export function resolveViteId(id: string) {
17 return `\0${id}`
18}
19β
20export function createIdFilter(ids: Array<string>): RegExp {
21 return new RegExp(`^(?:${ids.map(escapeRegExp).join('|')})$`)
22}
23β
24export function escapeRegExp(value: string): string {
25 return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
26}
27β
28export function createLogger(prefix: string) {
29 const label = `[${prefix}]`
30 return {
31 log: (...args: any) => console.log(label, ...args),
32 debug: (...args: any) => console.debug(label, ...args),
33 info: (...args: any) => console.info(label, ...args),
34 warn: (...args: any) => console.warn(label, ...args),
35 error: (...args: any) => console.error(label, ...args),
36 }
37}
38β
39function slash(path: string): string {
40 return path.replace(windowsSlashRE, '/')
41}
42β
43export function normalizePath(id: string): string {
44 return path.posix.normalize(isWindows ? slash(id) : id)
45}