Skip to content

Commit c40a925

Browse files
committed
[sass] Update logging, serialize writes
1 parent c3e5c09 commit c40a925

2 files changed

Lines changed: 39 additions & 38 deletions

File tree

heft-plugins/heft-sass-plugin/src/SassPlugin.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ export default class SassPlugin implements IHeftPlugin {
5757
public apply(taskSession: IHeftTaskSession, heftConfiguration: HeftConfiguration): void {
5858
const { numberOfCores, slashNormalizedBuildFolderPath } = heftConfiguration;
5959
const { logger, tempFolderPath } = taskSession;
60-
6160
const { terminal } = logger;
62-
6361
const { accessor } = this;
6462

6563
let sassProcessorPromise: Promise<SassProcessor> | undefined;
@@ -115,18 +113,31 @@ export default class SassPlugin implements IHeftPlugin {
115113
};
116114

117115
const sassProcessor: SassProcessor = new SassProcessor(sassProcessorOptions);
118-
119116
await sassProcessor.loadCacheAsync(tempFolderPath);
120117

121118
return sassProcessor;
122119
})());
123120
}
124121

122+
const compileFilesAsync = async (
123+
sassProcessor: SassProcessor,
124+
files: Set<string>,
125+
changed: boolean
126+
): Promise<void> => {
127+
if (files.size === 0) {
128+
terminal.writeLine(`No SCSS files to process.`);
129+
return;
130+
}
131+
132+
await sassProcessor.compileFilesAsync(files);
133+
terminal.writeLine(`Finished compiling.`);
134+
};
135+
125136
taskSession.hooks.run.tapPromise(PLUGIN_NAME, async (runOptions: IHeftTaskRunHookOptions) => {
126-
terminal.writeLine(`Initializing SASS compiler...`);
137+
terminal.writeLine(`Starting...`);
127138
const sassProcessor: SassProcessor = await initializeSassProcessorAsync();
128139

129-
terminal.writeLine(`Scanning for SCSS files...`);
140+
terminal.writeVerboseLine(`Scanning for SCSS files...`);
130141
const files: string[] = await runOptions.globAsync(sassProcessor.inputFileGlob, {
131142
absolute: true,
132143
ignore: sassProcessor.ignoredFileGlobs,
@@ -139,17 +150,16 @@ export default class SassPlugin implements IHeftPlugin {
139150
fileSet.add(path.resolve(file));
140151
}
141152

142-
await sassProcessor.compileFilesAsync(fileSet);
143-
terminal.writeLine(`Finished compiling.`);
153+
await compileFilesAsync(sassProcessor, fileSet, false);
144154
});
145155

146156
taskSession.hooks.runIncremental.tapPromise(
147157
PLUGIN_NAME,
148158
async (runOptions: IHeftTaskRunIncrementalHookOptions) => {
149-
terminal.writeLine(`Initializing SASS compiler...`);
159+
terminal.writeLine(`Starting...`);
150160
const sassProcessor: SassProcessor = await initializeSassProcessorAsync();
151161

152-
terminal.writeLine(`Scanning for SCSS files...`);
162+
terminal.writeVerboseLine(`Scanning for changed SCSS files...`);
153163
const changedFiles: Map<string, IWatchedFileState> = await runOptions.watchGlobAsync(
154164
sassProcessor.inputFileGlob,
155165
{
@@ -165,10 +175,8 @@ export default class SassPlugin implements IHeftPlugin {
165175
modifiedFiles.add(file);
166176
}
167177
}
168-
terminal.writeLine(`Compiling ${modifiedFiles.size} changed SCSS files...`);
169178

170-
await sassProcessor.compileFilesAsync(modifiedFiles);
171-
terminal.writeLine(`Finished compiling.`);
179+
await compileFilesAsync(sassProcessor, modifiedFiles, true);
172180
}
173181
);
174182
}

heft-plugins/heft-sass-plugin/src/SassProcessor.ts

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -171,43 +171,26 @@ interface IFileContentAndVersion {
171171
* @public
172172
*/
173173
export class SassProcessor {
174+
public readonly ignoredFileGlobs: string[] | undefined;
174175
public readonly inputFileGlob: string;
175176
public readonly sourceFolderPath: string;
176-
public readonly ignoredFileGlobs: string[] | undefined;
177177

178178
// Map of input file path -> record
179179
private readonly _fileInfo: Map<string, IFileRecord>;
180180
private readonly _resolutions: Map<string, SyncOrAsyncResolution>;
181181

182182
private readonly _isFileModule: (filePath: string) => boolean;
183183
private readonly _options: ISassProcessorOptions;
184-
private readonly _scssOptions: Options<'async'>;
185184
private readonly _realpathSync: (path: string) => string;
185+
private readonly _scssOptions: Options<'async'>;
186186

187187
private _configFilePath: string | undefined;
188188

189189
public constructor(options: ISassProcessorOptions) {
190190
const { silenceDeprecations, excludeFiles } = options;
191191

192-
this._configFilePath = undefined;
193-
194-
this._fileInfo = new Map();
195-
this._resolutions = new Map();
196-
197-
this._options = options;
198-
199-
this._realpathSync = new RealNodeModulePathResolver().realNodeModulePath;
200-
201192
const { isFileModule, allFileExtensions } = buildExtensionClassifier(options);
202193

203-
this.inputFileGlob = `**/*+(${allFileExtensions.join('|')})`;
204-
this.sourceFolderPath = options.srcFolder;
205-
this.ignoredFileGlobs = excludeFiles?.map((excludedFile) =>
206-
excludedFile.startsWith('./') ? excludedFile.slice(2) : excludedFile
207-
);
208-
209-
this._isFileModule = isFileModule;
210-
211194
const deprecationsToSilence: DeprecationOrId[] | undefined = silenceDeprecations
212195
? Array.from(silenceDeprecations, (deprecation) => {
213196
if (!Object.prototype.hasOwnProperty.call(deprecations, deprecation)) {
@@ -239,6 +222,18 @@ export class SassProcessor {
239222
};
240223
};
241224

225+
this.ignoredFileGlobs = excludeFiles?.map((excludedFile) =>
226+
excludedFile.startsWith('./') ? excludedFile.slice(2) : excludedFile
227+
);
228+
this.inputFileGlob = `**/*+(${allFileExtensions.join('|')})`;
229+
this.sourceFolderPath = options.srcFolder;
230+
231+
this._configFilePath = undefined;
232+
this._fileInfo = new Map();
233+
this._isFileModule = isFileModule;
234+
this._resolutions = new Map();
235+
this._options = options;
236+
this._realpathSync = new RealNodeModulePathResolver().realNodeModulePath;
242237
this._scssOptions = {
243238
style: 'expanded', // leave minification to clean-css
244239
importers: [
@@ -776,13 +771,13 @@ export class SassProcessor {
776771
ensureFolderExists: true
777772
};
778773

779-
const promises: Promise<void>[] = dtsOutputFolders.map((dtsOutputFolder: string) => {
780-
return FileSystem.writeFileAsync(
774+
for (const dtsOutputFolder of dtsOutputFolders) {
775+
await FileSystem.writeFileAsync(
781776
path.resolve(dtsOutputFolder, `${relativeFilePath}.d.ts`),
782777
dtsContent,
783778
writeFileOptions
784779
);
785-
});
780+
}
786781

787782
const filename: string = path.basename(relativeFilePath);
788783
const extensionStart: number = filename.lastIndexOf('.');
@@ -798,17 +793,15 @@ export class SassProcessor {
798793
const { folder, shimModuleFormat } = cssOutputFolder;
799794

800795
const cssFilePath: string = path.resolve(folder, relativeCssPath);
801-
promises.push(FileSystem.writeFileAsync(cssFilePath, css, writeFileOptions));
796+
await FileSystem.writeFileAsync(cssFilePath, css, writeFileOptions);
802797

803798
if (shimModuleFormat && !filename.endsWith('.css')) {
804799
const jsFilePath: string = path.resolve(folder, `${relativeFilePath}.js`);
805800
const jsShimContent: string = generateJsShimContent(shimModuleFormat, cssPathFromJs);
806-
promises.push(FileSystem.writeFileAsync(jsFilePath, jsShimContent, writeFileOptions));
801+
await FileSystem.writeFileAsync(jsFilePath, jsShimContent, writeFileOptions);
807802
}
808803
}
809804
}
810-
811-
await Promise.all(promises);
812805
}
813806

814807
private _createDTS(moduleMap: JsonObject | undefined): string {

0 commit comments

Comments
 (0)