@@ -53,6 +53,7 @@ import {
5353import { restoreTokens } from './tokens.ts'
5454import type {
5555 Arrayable ,
56+ IgnoreClass ,
5657 MDXCode ,
5758 MDXHeading ,
5859 NormalPosition ,
@@ -73,18 +74,51 @@ export const processorCache = new Map<
7374 Processor < Root , undefined , undefined , Root , string >
7475> ( )
7576
76- let configLoad : ( filePath : string ) => Promise < ConfigResult >
77+ const configLoadCache = new Map <
78+ string ,
79+ ( filePath : string ) => Promise < ConfigResult >
80+ > ( )
81+
82+ let Ignore : IgnoreClass
83+
84+ const ignoreCheckCache = new Map <
85+ string ,
86+ ( filePath : string ) => Promise < boolean >
87+ > ( )
88+
89+ const getRemarkConfig = async ( filePath : string , cwd = process . cwd ( ) ) => {
90+ let configLoad = configLoadCache . get ( cwd )
7791
78- const getRemarkConfig = async ( filePath : string ) => {
7992 if ( ! configLoad ) {
8093 const config = new Configuration ( {
81- cwd : process . cwd ( ) ,
94+ cwd,
8295 packageField : 'remarkConfig' ,
8396 pluginPrefix : 'remark' ,
8497 rcName : '.remarkrc' ,
8598 detectConfig : true ,
8699 } )
87100 configLoad = promisify ( config . load . bind ( config ) )
101+ configLoadCache . set ( cwd , configLoad )
102+ }
103+
104+ if ( ! Ignore ) {
105+ ; ( { Ignore } = ( await import (
106+ pathToFileURL (
107+ path . resolve ( cjsRequire . resolve ( 'unified-engine' ) , '../lib/ignore.js' ) ,
108+ ) . href
109+ ) ) as { Ignore : IgnoreClass } )
110+ }
111+
112+ let ignoreCheck = ignoreCheckCache . get ( cwd )
113+
114+ if ( ! ignoreCheck ) {
115+ const ignore = new Ignore ( {
116+ cwd,
117+ ignoreName : '.remarkignore' ,
118+ detectIgnore : true ,
119+ } )
120+ ignoreCheck = promisify ( ignore . check . bind ( ignore ) )
121+ ignoreCheckCache . set ( cwd , ignoreCheck )
88122 }
89123
90124 return configLoad ( filePath )
@@ -216,6 +250,12 @@ runAsWorker(
216250 }
217251
218252 if ( process ) {
253+ if ( await ignoreCheckCache . get ( cwd ) ( filePath ) ) {
254+ return {
255+ messages : [ ] ,
256+ }
257+ }
258+
219259 const file = new VFile ( fileOptions )
220260 try {
221261 await processor . process ( file )
0 commit comments