1515process . env . TAILWIND_MODE = 'build' ;
1616
1717const CHECK_REFRESH_RATE = 1_000 ;
18- let previousConfig = null ;
1918let lastCheck = null ;
20- let mergedConfig = null ;
21- let lastModifiedDate = null ;
19+ let mergedConfig = new Map ( ) ;
20+ let lastModifiedDate = new Map ( ) ;
2221
2322/**
2423 * @see https://stackoverflow.com/questions/9210542/node-js-require-cache-possible-to-invalidate
@@ -51,9 +50,9 @@ function loadConfig(config) {
5150 if ( stats === null ) {
5251 // Default to no config
5352 loadedConfig = { } ;
54- } else if ( lastModifiedDate !== mtime ) {
53+ } else if ( lastModifiedDate . get ( resolvedPath ) !== mtime ) {
5554 // Load the config based on path
56- lastModifiedDate = mtime ;
55+ lastModifiedDate . set ( resolvedPath , mtime ) ;
5756 loadedConfig = requireUncached ( resolvedPath ) ;
5857 } else {
5958 // Unchanged config
@@ -73,31 +72,19 @@ function loadConfig(config) {
7372 }
7473}
7574
76- function convertConfigToString ( config ) {
77- switch ( typeof config ) {
78- case 'string' :
79- return config ;
80- case 'object' :
81- return JSON . stringify ( config ) ;
82- default :
83- return config . toString ( ) ;
84- }
85- }
86-
8775function resolve ( twConfig ) {
88- const newConfig = convertConfigToString ( twConfig ) !== convertConfigToString ( previousConfig ) ;
76+ const newConfig = mergedConfig . get ( twConfig ) === undefined ;
8977 const now = Date . now ( ) ;
9078 const expired = now - lastCheck > CHECK_REFRESH_RATE ;
9179 if ( newConfig || expired ) {
92- previousConfig = twConfig ;
9380 lastCheck = now ;
9481 const userConfig = loadConfig ( twConfig ) ;
9582 // userConfig is null when config file was not modified
9683 if ( userConfig !== null ) {
97- mergedConfig = resolveConfig ( userConfig ) ;
84+ mergedConfig . set ( twConfig , resolveConfig ( userConfig ) ) ;
9885 }
9986 }
100- return mergedConfig ;
87+ return mergedConfig . get ( twConfig ) ;
10188}
10289
10390module . exports = {
0 commit comments