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/** Read `build.rollupOptions` or `build.rolldownOptions` from a build config. */
8export function getBundlerOptions(build: any): any {
9 return build?.rolldownOptions ?? build?.rollupOptions
10}
11β
12export function resolveViteId(id: string) {
13 return `\0${id}`
14}
15β
16export function createIdFilter(ids: Array<string>): RegExp {
17 return new RegExp(`^(?:${ids.map(escapeRegExp).join('|')})$`)
18}
19β
20export function escapeRegExp(value: string): string {
21 return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
22}
23β
24export function createLogger(prefix: string) {
25 const label = `[${prefix}]`
26 return {
27 log: (...args: any) => console.log(label, ...args),
28 debug: (...args: any) => console.debug(label, ...args),
29 info: (...args: any) => console.info(label, ...args),
30 warn: (...args: any) => console.warn(label, ...args),
31 error: (...args: any) => console.error(label, ...args),
32 }
33}
34β
35function slash(path: string): string {
36 return path.replace(windowsSlashRE, '/')
37}
38β
39export function normalizePath(id: string): string {
40 return path.posix.normalize(isWindows ? slash(id) : id)
41}