@@ -86,19 +86,26 @@ const ignoreCheckCache = new Map<
8686 ( filePath : string ) => Promise < boolean >
8787> ( )
8888
89- const getRemarkConfig = async ( filePath : string , cwd : string ) => {
90- let configLoad = configLoadCache . get ( cwd )
89+ const getRemarkConfig = async (
90+ filePath : string ,
91+ cwd : string ,
92+ remarkConfigPath ?: string ,
93+ ) => {
94+ const cacheKey = remarkConfigPath ? `${ cwd } \0${ remarkConfigPath } ` : cwd
95+
96+ let configLoad = configLoadCache . get ( cacheKey )
9197
9298 if ( ! configLoad ) {
9399 const config = new Configuration ( {
94100 cwd,
95101 packageField : 'remarkConfig' ,
96102 pluginPrefix : 'remark' ,
97103 rcName : '.remarkrc' ,
104+ rcPath : remarkConfigPath ,
98105 detectConfig : true ,
99106 } )
100107 configLoad = promisify ( config . load . bind ( config ) )
101- configLoadCache . set ( cwd , configLoad )
108+ configLoadCache . set ( cacheKey , configLoad )
102109 }
103110
104111 if ( ! Ignore ) {
@@ -109,7 +116,7 @@ const getRemarkConfig = async (filePath: string, cwd: string) => {
109116 ) ) as { Ignore : IgnoreClass } )
110117 }
111118
112- let ignoreCheck = ignoreCheckCache . get ( cwd )
119+ let ignoreCheck = ignoreCheckCache . get ( cacheKey )
113120
114121 if ( ! ignoreCheck ) {
115122 const ignore = new Ignore ( {
@@ -118,7 +125,7 @@ const getRemarkConfig = async (filePath: string, cwd: string) => {
118125 detectIgnore : true ,
119126 } )
120127 ignoreCheck = promisify ( ignore . check . bind ( ignore ) )
121- ignoreCheckCache . set ( cwd , ignoreCheck )
128+ ignoreCheckCache . set ( cacheKey , ignoreCheck )
122129 }
123130
124131 return configLoad ( filePath )
@@ -142,6 +149,7 @@ export const getRemarkProcessor = async (
142149 isMdx : boolean ,
143150 ignoreRemarkConfig ?: boolean ,
144151 cwd = process . cwd ( ) ,
152+ remarkConfigPath ?: string ,
145153) => {
146154 const initCacheKey = `${ String ( isMdx ) } -${ cwd } \0${ filePath } `
147155
@@ -153,7 +161,7 @@ export const getRemarkProcessor = async (
153161
154162 const result = ignoreRemarkConfig
155163 ? null
156- : await getRemarkConfig ( filePath , cwd )
164+ : await getRemarkConfig ( filePath , cwd , remarkConfigPath )
157165
158166 const cacheKey = result ?. filePath
159167 ? `${ String ( isMdx ) } -${ result . filePath } `
@@ -227,6 +235,8 @@ runAsWorker(
227235 isMdx,
228236 process,
229237 ignoreRemarkConfig,
238+ remarkConfigPath,
239+ // eslint-disable-next-line sonarjs/cognitive-complexity
230240 } : WorkerOptions ) : Promise < WorkerResult > => {
231241 sharedTokens . length = 0
232242
@@ -245,6 +255,7 @@ runAsWorker(
245255 isMdx ,
246256 ignoreRemarkConfig ,
247257 cwd ,
258+ remarkConfigPath ,
248259 )
249260
250261 const fileOptions : VFileOptions = {
@@ -254,7 +265,9 @@ runAsWorker(
254265 }
255266
256267 if ( process ) {
257- if ( await ignoreCheckCache . get ( cwd ) ( filePath ) ) {
268+ const cacheKey = remarkConfigPath ? `${ cwd } \0${ remarkConfigPath } ` : cwd
269+
270+ if ( await ignoreCheckCache . get ( cacheKey ) ( filePath ) ) {
258271 return {
259272 messages : [ ] ,
260273 }
0 commit comments