Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

utils.ts

41 lines1.2 KB

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
11​
12export function resolveViteId(id: string) {
13 return `\0${id}`
15​
16export function createIdFilter(ids: Array<string>): RegExp {
17 return new RegExp(`^(?:${ids.map(escapeRegExp).join('|')})$`)
19​
20export function escapeRegExp(value: string): string {
21 return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
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 }
34​
35function slash(path: string): string {
36 return path.replace(windowsSlashRE, '/')
38​
39export function normalizePath(id: string): string {
40 return path.posix.normalize(isWindows ? slash(id) : id)