@@ -198,6 +198,46 @@ function invalidateResolutionCacheForChangedFiles(changedFiles, projectRoot) {
198198 }
199199}
200200
201+ function normalizeChangedFileToAbsolutePath ( filePath , projectRoot ) {
202+ if ( typeof filePath !== 'string' || filePath === '' ) {
203+ return null ;
204+ }
205+
206+ if ( filePath . startsWith ( '~' ) ) {
207+ return path . resolve ( projectRoot , filePath . slice ( 1 ) ) ;
208+ }
209+
210+ if ( path . isAbsolute ( filePath ) ) {
211+ return path . resolve ( filePath ) ;
212+ }
213+
214+ return path . resolve ( projectRoot , filePath ) ;
215+ }
216+
217+ function invalidateFileContentCacheForChangedFiles ( changedFiles , projectRoot , fileContentCache ) {
218+ if ( ! changedFiles || changedFiles . length === 0 || ! fileContentCache || fileContentCache . size === 0 ) {
219+ return ;
220+ }
221+
222+ const absolutePaths = new Set ( ) ;
223+ for ( const file of changedFiles ) {
224+ const absolutePath = normalizeChangedFileToAbsolutePath ( file , projectRoot ) ;
225+ if ( absolutePath ) {
226+ absolutePaths . add ( absolutePath ) ;
227+ }
228+ }
229+
230+ if ( absolutePaths . size === 0 ) {
231+ return ;
232+ }
233+
234+ for ( const cachedPath of fileContentCache . keys ( ) ) {
235+ if ( absolutePaths . has ( cachedPath ) ) {
236+ fileContentCache . delete ( cachedPath ) ;
237+ }
238+ }
239+ }
240+
201241function toWatchedFilePath ( item ) {
202242 if ( typeof item === 'string' ) {
203243 return item ;
@@ -253,6 +293,7 @@ function createScssSidecar(projectRoot) {
253293 const cssOutputPath = path . resolve ( generatedEntryDirectoryPath , HOT_CSS_FILE_NAME ) ;
254294 const cssMapOutputPath = path . resolve ( generatedEntryDirectoryPath , HOT_CSS_MAP_FILE_NAME ) ;
255295 const scssSourceMapEnabled = asString ( process . env . SHOPWARE_STOREFRONT_SCSS_SOURCE_MAP , '1' ) === '1' ;
296+ const scssSourceMapIncludeSources = asString ( process . env . SHOPWARE_STOREFRONT_SCSS_SOURCE_MAP_INCLUDE_SOURCES , '0' ) === '1' ;
256297 const silenceDeprecations = asString ( process . env . SHOPWARE_STOREFRONT_SASS_SILENCE_DEPRECATIONS , '1' ) === '1' ;
257298
258299 const fileContentCache = new Map ( ) ;
@@ -447,6 +488,7 @@ function createScssSidecar(projectRoot) {
447488
448489 if ( currentContent !== content ) {
449490 fs . writeFileSync ( generatedThemeEntryPath , content , 'utf8' ) ;
491+ fileContentCache . delete ( generatedThemeEntryPath ) ;
450492 }
451493 }
452494
@@ -559,7 +601,7 @@ function createScssSidecar(projectRoot) {
559601 }
560602
561603 state . compileInFlight = true ;
562- fileContentCache . clear ( ) ;
604+ invalidateFileContentCacheForChangedFiles ( changedFiles , rootPath , fileContentCache ) ;
563605 invalidateResolutionCacheForChangedFiles ( changedFiles , rootPath ) ;
564606 const startedAt = Date . now ( ) ;
565607 log . status ( 'RUN' , `compiling (${ reasonLabel } )` ) ;
@@ -656,7 +698,7 @@ function createScssSidecar(projectRoot) {
656698
657699 const result = await compile ( entryPath , {
658700 sourceMap : scssSourceMapEnabled ,
659- sourceMapIncludeSources : scssSourceMapEnabled ,
701+ sourceMapIncludeSources : scssSourceMapEnabled && scssSourceMapIncludeSources ,
660702 style : 'expanded' ,
661703 quietDeps : true ,
662704 loadPaths : shared . loadPaths ,
@@ -719,7 +761,7 @@ function createScssSidecar(projectRoot) {
719761 file : entryPath ,
720762 outFile : cssOutputPath ,
721763 sourceMap : scssSourceMapEnabled ,
722- sourceMapContents : scssSourceMapEnabled ,
764+ sourceMapContents : scssSourceMapEnabled && scssSourceMapIncludeSources ,
723765 outputStyle : 'expanded' ,
724766 quietDeps : true ,
725767 includePaths : shared . loadPaths ,
0 commit comments