Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): dispose Sass worker resources on …
Browse files Browse the repository at this point in the history
…Webpack shutdown

Sass Worker instances and resource requests are now cleaned up when the Webpack compiler is shutdown. This removes the need to unreference the workers upon creation.

Fixes #20985

(cherry picked from commit 1dd5c28)
  • Loading branch information
clydin authored and alan-agius4 committed Jun 4, 2021
1 parent 10a263a commit 8575056
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,12 @@ export class SassWorkerImplementation {
/**
* Shutdown the Sass render worker.
* Executing this method will stop any pending render requests.
*
* The worker is unreferenced upon creation and will not block application exit. This method
* is only needed if early cleanup is needed.
*/
close(): void {
for (const worker of this.workers) {
void worker.terminate();
try {
void worker.terminate();
} catch {}
}
this.requests.clear();
}
Expand Down Expand Up @@ -197,7 +196,6 @@ export class SassWorkerImplementation {
},
);

worker.unref();
mainImporterPort.unref();

return worker;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export function getStylesConfig(wco: WebpackConfigOptions): webpack.Configuratio
);
}

let sassImplementation: {} | undefined;
let sassImplementation: SassWorkerImplementation | undefined;
try {
sassImplementation = require('node-sass');
wco.logger.warn(
Expand All @@ -117,6 +117,13 @@ export function getStylesConfig(wco: WebpackConfigOptions): webpack.Configuratio
);
} catch {
sassImplementation = new SassWorkerImplementation();
extraPlugins.push({
apply(compiler) {
compiler.hooks.shutdown.tap('sass-worker', () => {
sassImplementation?.close();
});
},
});
}

const assetNameTemplate = assetNameTemplateFactory(hashFormat);
Expand Down

0 comments on commit 8575056

Please sign in to comment.