File tree 2 files changed +21
-1
lines changed
2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import path from 'node:path'
3
3
import { describe , expect , test } from 'vitest'
4
4
import {
5
5
asyncFlatten ,
6
+ bareImportRE ,
6
7
getHash ,
7
8
getLocalhostAddressIfDiffersFromDNS ,
8
9
injectQuery ,
@@ -13,6 +14,25 @@ import {
13
14
resolveHostname ,
14
15
} from '../utils'
15
16
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
+
16
36
describe ( 'injectQuery' , ( ) => {
17
37
if ( isWindows ) {
18
38
// this test will work incorrectly on unix systems
Original file line number Diff line number Diff line change @@ -137,7 +137,7 @@ export function isOptimizable(
137
137
)
138
138
}
139
139
140
- export const bareImportRE = / ^ [ \w @ ] (? ! .* : \/ \/ ) /
140
+ export const bareImportRE = / ^ (? ! [ a - z A - Z ] : ) [ \w @ ] (? ! .* : \/ \/ ) /
141
141
export const deepImportRE = / ^ ( [ ^ @ ] [ ^ / ] * ) \/ | ^ ( @ [ ^ / ] + \/ [ ^ / ] + ) \/ /
142
142
143
143
// TODO: use import()
You can’t perform that action at this time.
0 commit comments