Skip to content

Commit

Permalink
perf: skip windows absolute paths for node resolve (#13162)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored May 13, 2023
1 parent adf61d9 commit e640939
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions packages/vite/src/node/__tests__/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import path from 'node:path'
import { describe, expect, test } from 'vitest'
import {
asyncFlatten,
bareImportRE,
getHash,
getLocalhostAddressIfDiffersFromDNS,
injectQuery,
Expand All @@ -13,6 +14,25 @@ import {
resolveHostname,
} from '../utils'

describe('bareImportRE', () => {
test('should work with normal package name', () => {
expect(bareImportRE.test('vite')).toBe(true)
})
test('should work with scoped package name', () => {
expect(bareImportRE.test('@vitejs/plugin-vue')).toBe(true)
})

test('should work with absolute paths', () => {
expect(bareImportRE.test('/foo')).toBe(false)
expect(bareImportRE.test('C:/foo')).toBe(false)
expect(bareImportRE.test('C:\\foo')).toBe(false)
})
test('should work with relative path', () => {
expect(bareImportRE.test('./foo')).toBe(false)
expect(bareImportRE.test('.\\foo')).toBe(false)
})
})

describe('injectQuery', () => {
if (isWindows) {
// this test will work incorrectly on unix systems
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export function isOptimizable(
)
}

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

// TODO: use import()
Expand Down

0 comments on commit e640939

Please sign in to comment.