@@ -5,6 +5,7 @@ import type { EnvironmentOptions, InlineConfig } from '../config'
55import { resolveSubpathImports } from '../plugins/resolve'
66import { createServer } from '../server'
77import { createServerModuleRunner } from '../ssr/runtime/serverModuleRunner'
8+ import { normalizePath } from '../utils'
89
910for ( const id of [ '#hash#blocked' , '#hash?blocked' ] ) {
1011 test ( `does not fall back from explicitly blocked imports key ${ id } ` , ( ) => {
@@ -330,3 +331,63 @@ describe('file url', () => {
330331 expect ( mod2 . default . default ) . toBe ( 'ok' )
331332 } )
332333} )
334+
335+ describe ( 'alias replacement with $ patterns' , ( ) => {
336+ const fixtureDir = join ( import . meta. dirname , 'fixtures/alias-special-pattern' )
337+
338+ async function resolveWithAlias (
339+ alias : NonNullable < InlineConfig [ 'resolve' ] > [ 'alias' ] ,
340+ id : string ,
341+ ) {
342+ const server = await createServer ( {
343+ configFile : false ,
344+ root : import . meta. dirname ,
345+ logLevel : 'error' ,
346+ resolve : { alias } ,
347+ // the scanner would otherwise crawl every HTML fixture under `__tests__`
348+ optimizeDeps : {
349+ noDiscovery : true ,
350+ include : [ ] ,
351+ } ,
352+ server : {
353+ middlewareMode : true ,
354+ ws : false ,
355+ } ,
356+ } )
357+ onTestFinished ( ( ) => server . close ( ) )
358+ // The SSR dev plugin container exercises @rollup/plugin-alias, which we want to test here.
359+ // Builds use Rolldown's native alias plugin for aliases.
360+ return server . environments . ssr . pluginContainer . resolveId ( id )
361+ }
362+
363+ test ( '$$ in string replacement is inserted literally' , async ( ) => {
364+ const resolved = await resolveWithAlias (
365+ { '@dollar-double' : join ( fixtureDir , '$$' ) } ,
366+ '@dollar-double' ,
367+ )
368+ expect ( resolved ?. id ) . toBe ( normalizePath ( join ( fixtureDir , '$$/index.js' ) ) )
369+ } )
370+
371+ test ( '$& in string replacement is inserted literally' , async ( ) => {
372+ const resolved = await resolveWithAlias (
373+ { '@dollar-ampersand' : join ( fixtureDir , '$&' ) } ,
374+ '@dollar-ampersand' ,
375+ )
376+ expect ( resolved ?. id ) . toBe ( normalizePath ( join ( fixtureDir , '$&/index.js' ) ) )
377+ } )
378+
379+ test ( 'capture groups in regex replacement still work' , async ( ) => {
380+ const resolved = await resolveWithAlias (
381+ [
382+ {
383+ find : / ^ @ r e g e x - c a p t u r e \/ ( .* ) $ / ,
384+ replacement : join ( fixtureDir , 'regex-target' ) + '/$1' ,
385+ } ,
386+ ] ,
387+ '@regex-capture/file' ,
388+ )
389+ expect ( resolved ?. id ) . toBe (
390+ normalizePath ( join ( fixtureDir , 'regex-target/file.js' ) ) ,
391+ )
392+ } )
393+ } )
0 commit comments