Description
The recently added SassWorkerImplementation in 12.0.1, when it creates a worker, immediately calls unref()
on it as seen here. This can cause the process to exit too early (before the worker gets to receive any message) in certain scenarios where there are no other handles (CI environments, Docker builds, etc). The reason this is currently working in those environments is because there's an interval running to flush the analytics while the build is running (command-runner.ts#L252), which keeps the event loop busy and prevents the process from exiting.
Relying on that interval to keep the process alive is not ideal. I'm not sure if that was intentional or not, but this could lead to the SASS implementation unexpectedly being broken if that interval is removed in the future, with hard to debug issues and no apparent reason for it to break since the change might seem unrelated.
This issue did appear on Nx workspaces since Nx runs the builders directly (by mimicking what Angular CLI does except the analytics part) and it doesn't go through the command runner, therefore no interval was running and the process was exiting without producing any build artifact (repro: nrwl/nx#5729 (comment) and workaround: nrwl/nx#5807).
I did confirm in the Angular CLI code that by removing the analytics interval, the issue would arise. By removing the calls to unref()
everything works fine and the process exits normally when the compilation is finished or errored.