Skip to content

Commit

Permalink
fix(compiler): use transformed css to check changed imports of global…
Browse files Browse the repository at this point in the history
…Style (#2422)
  • Loading branch information
simonhaenisch authored May 12, 2020
1 parent ed23e02 commit 7742a87
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/compiler/style/global-styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,28 +65,21 @@ const canSkipGlobalStyles = async (config: d.Config, compilerCtx: d.CompilerCtx,
return false;
}

const hasChangedImports = await hasChangedImportFile(config, compilerCtx, buildCtx, config.globalStyle, []);
const hasChangedImports = await hasChangedImportFile(config, compilerCtx, buildCtx, config.globalStyle, compilerCtx.cachedGlobalStyle, []);
if (hasChangedImports) {
return false;
}

return true;
};

const hasChangedImportFile = async (config: d.Config, compilerCtx: d.CompilerCtx, buildCtx: d.BuildCtx, filePath: string, noLoop: string[]): Promise<boolean> => {
const hasChangedImportFile = async (config: d.Config, compilerCtx: d.CompilerCtx, buildCtx: d.BuildCtx, filePath: string, content: string, noLoop: string[]): Promise<boolean> => {
if (noLoop.includes(filePath)) {
return false;
}
noLoop.push(filePath);

let rtn = false;

try {
const content = await compilerCtx.fs.readFile(filePath);
rtn = await hasChangedImportContent(config, compilerCtx, buildCtx, filePath, content, noLoop);
} catch (e) {}

return rtn;
return hasChangedImportContent(config, compilerCtx, buildCtx, filePath, content, noLoop);
};

const hasChangedImportContent = async (config: d.Config, compilerCtx: d.CompilerCtx, buildCtx: d.BuildCtx, filePath: string, content: string, checkedFiles: string[]) => {
Expand All @@ -106,8 +99,13 @@ const hasChangedImportContent = async (config: d.Config, compilerCtx: d.Compiler
}

// keep diggin'
const promises = cssImports.map(cssImportData => {
return hasChangedImportFile(config, compilerCtx, buildCtx, cssImportData.filePath, checkedFiles);
const promises = cssImports.map(async cssImportData => {
try {
const content = await compilerCtx.fs.readFile(cssImportData.filePath);
return hasChangedImportFile(config, compilerCtx, buildCtx, cssImportData.filePath, content, checkedFiles);
} catch (e) {
return false;
}
});

const results = await Promise.all(promises);
Expand Down

0 comments on commit 7742a87

Please sign in to comment.