Skip to content

fix(@angular-devkit/build-angular): dispose Sass worker resources on Webpack shutdown #21045

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -207,7 +206,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