Skip to content

Commit

Permalink
perf(@angular-devkit/build-angular): only load browserslist in babel …
Browse files Browse the repository at this point in the history
…preset if needed

The `browserslist` package is only needed in the custom Babel application preset if
the `supportedBrowsers` option is specified. This option is not used within the esbuild-
based browser application builder. The `browserslist` is now lazily imported only when
needed and avoids the overhead of loading browser support data when not needed by the build.
  • Loading branch information
clydin committed Jul 10, 2023
1 parent 974748c commit a0a2c7a
Showing 1 changed file with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ import type {
makeEs2015TranslatePlugin,
makeLocalePlugin,
} from '@angular/localize/tools';
import { strict as assert } from 'assert';
import browserslist from 'browserslist';
import * as fs from 'fs';
import * as path from 'path';
import assert from 'node:assert';
import fs from 'node:fs';
import path from 'node:path';
import { loadEsmModule } from '../../../utils/load-esm';

/**
Expand All @@ -31,14 +30,7 @@ let needsLinking: typeof import('@angular/compiler-cli/linker').needsLinking | u
* See: https://github.com/angular/angular-cli/issues/24355#issuecomment-1333477033
* See: https://github.com/WebKit/WebKit/commit/e8788a34b3d5f5b4edd7ff6450b80936bff396f2
*/
const safariClassFieldScopeBugBrowsers = new Set(
browserslist([
// Safari <15 is technically not supported via https://angular.io/guide/browser-support,
// but we apply the workaround if forcibly selected.
'Safari <=15',
'iOS <=15',
]),
);
let safariClassFieldScopeBugBrowsers: ReadonlySet<string>;

export type DiagnosticReporter = (type: 'error' | 'warning' | 'info', message: string) => void;

Expand Down Expand Up @@ -198,6 +190,18 @@ export default function (api: unknown, options: ApplicationPresetOptions) {
if (options.supportedBrowsers) {
const includePlugins: string[] = [];

if (safariClassFieldScopeBugBrowsers === undefined) {
const browserslist = require('browserslist');
safariClassFieldScopeBugBrowsers = new Set(
browserslist([
// Safari <15 is technically not supported via https://angular.io/guide/browser-support,
// but we apply the workaround if forcibly selected.
'Safari <=15',
'iOS <=15',
]),
);
}

// If a Safari browser affected by the class field scope bug is selected, we
// downlevel class properties by ensuring the class properties Babel plugin
// is always included- regardless of the preset-env targets.
Expand Down

0 comments on commit a0a2c7a

Please sign in to comment.