File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
Expand file tree Collapse file tree 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'
33import { describe , expect , test } from 'vitest'
44import {
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+
1636describe ( 'injectQuery' , ( ) => {
1737 if ( isWindows ) {
1838 // 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(
137137 )
138138}
139139
140- export const bareImportRE = / ^ [ \w @ ] (? ! .* : \/ \/ ) /
140+ export const bareImportRE = / ^ (? ! [ a - z A - Z ] : ) [ \w @ ] (? ! .* : \/ \/ ) /
141141export const deepImportRE = / ^ ( [ ^ @ ] [ ^ / ] * ) \/ | ^ ( @ [ ^ / ] + \/ [ ^ / ] + ) \/ /
142142
143143// TODO: use import()
You can’t perform that action at this time.
0 commit comments