Skip to content

Commit

Permalink
refactor: extract regex
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Jun 28, 2022
1 parent afb69df commit 56a77de
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/vite/src/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1064,11 +1064,13 @@ export function stripBomTag(content: string): string {

export const isTS = (filename: string): boolean => /\.[cm]?ts$/.test(filename)

const windowsDrivePathPrefixRE = /^[A-Za-z]:[/\\]/

/**
* path.isAbsolute also returns true for drive relative paths on windows (e.g. /something)
* this function returns false for them but true for absolute paths (e.g. C:/something)
*/
export const isNonDriveRelativeAbsolutePath = (p: string): boolean => {
if (!isWindows) return p.startsWith('/')
return /^[A-Za-z]:[/\\]/.test(p)
return windowsDrivePathPrefixRE.test(p)
}

0 comments on commit 56a77de

Please sign in to comment.