Skip to content

Commit

Permalink
refactor(@angular-devkit/build-angular): update browserslist conversi…
Browse files Browse the repository at this point in the history
…on to latest esbuild browsers

The conversion of browserslist targets to esbuild targets has been updated to reflect additions
to esbuild. Additional browsers are now supported and the major/minor versions have been normalized.
The later of which ensures that `.0` major versions are not misinterpreted as ranges rather than
specific versions.

(cherry picked from commit a0f9db8)
  • Loading branch information
clydin authored and alan-agius4 committed Dec 2, 2022
1 parent 18f3100 commit 20e0742
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions packages/angular_devkit/build_angular/src/utils/esbuild-targets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,19 @@ export function transformSupportedBrowsersToTargets(supportedBrowsers: string[])
const transformed: string[] = [];

// https://esbuild.github.io/api/#target
const esBuildSupportedBrowsers = new Set(['safari', 'firefox', 'edge', 'chrome', 'ios', 'node']);
const esBuildSupportedBrowsers = new Set([
'chrome',
'edge',
'firefox',
'ie',
'ios',
'node',
'opera',
'safari',
]);

for (const browser of supportedBrowsers) {
let [browserName, version] = browser.split(' ');
let [browserName, version] = browser.toLowerCase().split(' ');

// browserslist uses the name `ios_saf` for iOS Safari whereas esbuild uses `ios`
if (browserName === 'ios_saf') {
Expand All @@ -33,6 +42,11 @@ export function transformSupportedBrowsersToTargets(supportedBrowsers: string[])
// esbuild only supports numeric versions so `TP` is converted to a high number (999) since
// a Technology Preview (TP) of Safari is assumed to support all currently known features.
version = '999';
} else if (!version.includes('.')) {
// A lone major version is considered by esbuild to include all minor versions. However,
// browserslist does not and is also inconsistent in its `.0` version naming. For example,
// Safari 15.0 is named `safari 15` but Safari 16.0 is named `safari 16.0`.
version += '.0';
}

transformed.push(browserName + version);
Expand Down

0 comments on commit 20e0742

Please sign in to comment.