Skip to content

Commit 76b54c5

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 d5f76d0 commit 76b54c5

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ export function buildWebpackBrowser(
428428
const runtimeOptions = {
429429
...processRuntimeAction,
430430
runtimeData: processResults,
431+
supportedBrowsers: buildBrowserFeatures.supportedBrowsers,
431432
};
432433
processResults.push(
433434
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
@@ -17,14 +17,14 @@ export const fullDifferential =
1717
fullDifferentialEnv.toLowerCase() !== 'false';
1818

1919
export class BuildBrowserFeatures {
20-
private readonly _supportedBrowsers: string[];
2120
private readonly _es6TargetOrLater: boolean;
21+
readonly supportedBrowsers: string[];
2222

2323
constructor(
2424
private projectRoot: string,
2525
private scriptTarget: ts.ScriptTarget,
2626
) {
27-
this._supportedBrowsers = browserslist(undefined, { path: this.projectRoot });
27+
this.supportedBrowsers = browserslist(undefined, { path: this.projectRoot });
2828
this._es6TargetOrLater = this.scriptTarget > ts.ScriptTarget.ES5;
2929
}
3030

@@ -59,7 +59,7 @@ export class BuildBrowserFeatures {
5959
'ios_saf 10.3',
6060
];
6161

62-
return this._supportedBrowsers.some(browser => safariBrowsers.includes(browser));
62+
return this.supportedBrowsers.some(browser => safariBrowsers.includes(browser));
6363
}
6464

6565
/**
@@ -77,7 +77,7 @@ export class BuildBrowserFeatures {
7777

7878
const data = feature(features[featureId]);
7979

80-
return !this._supportedBrowsers
80+
return !this.supportedBrowsers
8181
.some(browser => {
8282
const [agentId, version] = browser.split(' ');
8383

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export interface ProcessBundleOptions {
3030
cacheKeys?: (string | undefined)[];
3131
integrityAlgorithm?: 'sha256' | 'sha384' | 'sha512';
3232
runtimeData?: ProcessBundleResult[];
33+
supportedBrowsers?: string [] | Record<string, string>;
3334
}
3435

3536
export interface ProcessBundleResult {
@@ -111,6 +112,8 @@ export async function process(options: ProcessBundleOptions): Promise<ProcessBun
111112
[
112113
require.resolve('@babel/preset-env'),
113114
{
115+
// browserslist-compatible query or object of minimum environment versions to support
116+
targets: options.supportedBrowsers,
114117
// modules aren't needed since the bundles use webpack's custom module loading
115118
modules: false,
116119
// 'transform-typeof-symbol' generates slower code

0 commit comments

Comments
 (0)