Skip to content

Commit e640939

Browse files
authored
perf: skip windows absolute paths for node resolve (#13162)
1 parent adf61d9 commit e640939

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

packages/vite/src/node/__tests__/utils.spec.ts

+20
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import path from 'node:path'
33
import { describe, expect, test } from 'vitest'
44
import {
55
asyncFlatten,
6+
bareImportRE,
67
getHash,
78
getLocalhostAddressIfDiffersFromDNS,
89
injectQuery,
@@ -13,6 +14,25 @@ import {
1314
resolveHostname,
1415
} from '../utils'
1516

17+
describe('bareImportRE', () => {
18+
test('should work with normal package name', () => {
19+
expect(bareImportRE.test('vite')).toBe(true)
20+
})
21+
test('should work with scoped package name', () => {
22+
expect(bareImportRE.test('@vitejs/plugin-vue')).toBe(true)
23+
})
24+
25+
test('should work with absolute paths', () => {
26+
expect(bareImportRE.test('/foo')).toBe(false)
27+
expect(bareImportRE.test('C:/foo')).toBe(false)
28+
expect(bareImportRE.test('C:\\foo')).toBe(false)
29+
})
30+
test('should work with relative path', () => {
31+
expect(bareImportRE.test('./foo')).toBe(false)
32+
expect(bareImportRE.test('.\\foo')).toBe(false)
33+
})
34+
})
35+
1636
describe('injectQuery', () => {
1737
if (isWindows) {
1838
// this test will work incorrectly on unix systems

packages/vite/src/node/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export function isOptimizable(
137137
)
138138
}
139139

140-
export const bareImportRE = /^[\w@](?!.*:\/\/)/
140+
export const bareImportRE = /^(?![a-zA-Z]:)[\w@](?!.*:\/\/)/
141141
export const deepImportRE = /^([^@][^/]*)\/|^(@[^/]+\/[^/]+)\//
142142

143143
// TODO: use import()

0 commit comments

Comments
 (0)