Skip to content

perf: skip windows absolute paths for node resolve #13162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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