Skip to content

Commit a2c0532

Browse files
alan-agius4mgechev
authored andcommitted
fix(@angular-devkit/build-angular): provide supported browsers to babel
By default the browserslist `configPath` will default to `process.cwd()`. This might return incorrect data in a multi app workspace setup. https://babeljs.io/docs/en/babel-preset-env#configpath
1 parent 9c4da54 commit a2c0532

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

packages/angular_devkit/build_angular/src/browser/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ export function buildWebpackBrowser(
243243
const tsConfig = readTsconfig(options.tsConfig, context.workspaceRoot);
244244
const target = tsConfig.options.target || ScriptTarget.ES5;
245245
const buildBrowserFeatures = new BuildBrowserFeatures(projectRoot, target);
246-
247246
const isDifferentialLoadingNeeded = buildBrowserFeatures.isDifferentialLoadingNeeded();
248247

249248
if (target > ScriptTarget.ES2015 && isDifferentialLoadingNeeded) {
@@ -471,6 +470,7 @@ export function buildWebpackBrowser(
471470
const runtimeOptions = {
472471
...processRuntimeAction,
473472
runtimeData: processResults,
473+
supportedBrowsers: buildBrowserFeatures.supportedBrowsers,
474474
};
475475
processResults.push(
476476
await import('../utils/process-bundle').then(m => m.process(runtimeOptions)),

packages/angular_devkit/build_angular/src/utils/build-browser-features.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import { feature, features } from 'caniuse-lite';
1111
import * as ts from 'typescript';
1212

1313
export class BuildBrowserFeatures {
14-
private readonly _supportedBrowsers: string[];
1514
private readonly _es6TargetOrLater: boolean;
15+
readonly supportedBrowsers: string[];
1616

1717
constructor(
1818
private projectRoot: string,
1919
private scriptTarget: ts.ScriptTarget,
2020
) {
21-
this._supportedBrowsers = browserslist(undefined, { path: this.projectRoot });
21+
this.supportedBrowsers = browserslist(undefined, { path: this.projectRoot });
2222
this._es6TargetOrLater = this.scriptTarget > ts.ScriptTarget.ES5;
2323
}
2424

@@ -53,7 +53,7 @@ export class BuildBrowserFeatures {
5353
'ios_saf 10.3',
5454
];
5555

56-
return this._supportedBrowsers.some(browser => safariBrowsers.includes(browser));
56+
return this.supportedBrowsers.some(browser => safariBrowsers.includes(browser));
5757
}
5858

5959
/**
@@ -71,7 +71,7 @@ export class BuildBrowserFeatures {
7171

7272
const data = feature(features[featureId]);
7373

74-
return !this._supportedBrowsers
74+
return !this.supportedBrowsers
7575
.some(browser => {
7676
const [agentId, version] = browser.split(' ');
7777

packages/angular_devkit/build_angular/src/utils/process-bundle.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export interface ProcessBundleOptions {
4646
integrityAlgorithm?: 'sha256' | 'sha384' | 'sha512';
4747
runtimeData?: ProcessBundleResult[];
4848
replacements?: [string, string][];
49+
supportedBrowsers?: string [] | Record<string, string>;
4950
}
5051

5152
export interface ProcessBundleResult {
@@ -129,6 +130,8 @@ export async function process(options: ProcessBundleOptions): Promise<ProcessBun
129130
presets: [[
130131
require.resolve('@babel/preset-env'),
131132
{
133+
// browserslist-compatible query or object of minimum environment versions to support
134+
targets: options.supportedBrowsers,
132135
// modules aren't needed since the bundles use webpack's custom module loading
133136
modules: false,
134137
// 'transform-typeof-symbol' generates slower code

0 commit comments

Comments
 (0)