fix(angular): target correct versions of ng-packagr to create stylesheet worker synchronously (#22485)
This commit is contained in:
parent
54d47805de
commit
9bfdf897be
@ -1,6 +1,5 @@
|
|||||||
import type { FactoryProvider } from 'injection-js';
|
import type { FactoryProvider } from 'injection-js';
|
||||||
import { STYLESHEET_PROCESSOR_TOKEN } from 'ng-packagr/lib/styles/stylesheet-processor.di';
|
import { STYLESHEET_PROCESSOR_TOKEN } from 'ng-packagr/lib/styles/stylesheet-processor.di';
|
||||||
import { gte, lt } from 'semver';
|
|
||||||
import { getInstalledPackageVersionInfo } from '../angular-version-utils';
|
import { getInstalledPackageVersionInfo } from '../angular-version-utils';
|
||||||
import {
|
import {
|
||||||
AsyncStylesheetProcessor,
|
AsyncStylesheetProcessor,
|
||||||
@ -13,7 +12,7 @@ export const STYLESHEET_PROCESSOR: FactoryProvider = {
|
|||||||
const { version: ngPackagrVersion } =
|
const { version: ngPackagrVersion } =
|
||||||
getInstalledPackageVersionInfo('ng-packagr');
|
getInstalledPackageVersionInfo('ng-packagr');
|
||||||
|
|
||||||
return lt(ngPackagrVersion, '17.2.0') || gte(ngPackagrVersion, '17.3.0')
|
return ngPackagrVersion !== '17.2.0'
|
||||||
? StylesheetProcessor
|
? StylesheetProcessor
|
||||||
: AsyncStylesheetProcessor;
|
: AsyncStylesheetProcessor;
|
||||||
},
|
},
|
||||||
|
|||||||
@ -129,10 +129,10 @@ export class StylesheetProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is used when ng-packagr version is greater than or equal to 17.2.0 and less than 17.3.0.
|
* This class is used when ng-packagr version is 17.2.0. The async `loadPostcssConfiguration` function
|
||||||
* The async `loadPostcssConfiguration` function introduced in ng-packagr 17.2.x causes a memory leak
|
* introduced in ng-packagr 17.2.0 causes a memory leak due to multiple workers being created. We must
|
||||||
* due to multiple workers being created. We must keep this class to support any workspace that might
|
* keep this class to support any workspace that might be using ng-packagr 17.2.0 where that function
|
||||||
* be using ng-packagr 17.2.x where that function need to be awaited.
|
* need to be awaited.
|
||||||
*/
|
*/
|
||||||
export class AsyncStylesheetProcessor {
|
export class AsyncStylesheetProcessor {
|
||||||
private renderWorker: typeof Piscina | undefined;
|
private renderWorker: typeof Piscina | undefined;
|
||||||
@ -199,7 +199,7 @@ export class AsyncStylesheetProcessor {
|
|||||||
const { version: ngPackagrVersion } =
|
const { version: ngPackagrVersion } =
|
||||||
getInstalledPackageVersionInfo('ng-packagr');
|
getInstalledPackageVersionInfo('ng-packagr');
|
||||||
let postcssConfiguration: PostcssConfiguration | undefined;
|
let postcssConfiguration: PostcssConfiguration | undefined;
|
||||||
if (gte(ngPackagrVersion, '17.2.0')) {
|
if (ngPackagrVersion === '17.2.0') {
|
||||||
const { loadPostcssConfiguration } = await import(
|
const { loadPostcssConfiguration } = await import(
|
||||||
'ng-packagr/lib/styles/postcss-configuration'
|
'ng-packagr/lib/styles/postcss-configuration'
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user