Skip to content

Commit 7b01a00

Browse files
clydinalan-agius4
authored andcommitted
fix(@angular-devkit/build-angular): enable custom es2015 conditional exports
By adding the `es2015` condition name, the build process will now use ES2015 specific files if a package's exports entries contain files for this condition. This allows packages to provide multiple variants of the code that the bundler can then use based on the bundler's configuration. For Angular v12, ES2015 code is preferred. However, some packages may prefer to export other variants by default but provide an `es2015` condition to allow other variants if requested. The server configuration is intentional not altered since the server output executes on Node.js and should use the `node` condition which is automatically added by Webpack based on the output target.
1 parent 8925674 commit 7b01a00

File tree

6 files changed

+54
-0
lines changed

6 files changed

+54
-0
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@
206206
"regenerator-runtime": "0.13.9",
207207
"resolve-url-loader": "4.0.0",
208208
"rxjs": "6.6.7",
209+
"rxjs-7": "npm:rxjs@7.4.0",
209210
"sass": "1.36.0",
210211
"sass-loader": "12.1.0",
211212
"sauce-connect-proxy": "https://saucelabs.com/downloads/sc-4.6.4-linux.tar.gz",

packages/angular_devkit/build_angular/BUILD.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ LARGE_SPECS = {
354354
"@npm//font-awesome",
355355
"@npm//jquery",
356356
"@npm//popper.js",
357+
"@npm//rxjs-7",
357358
],
358359
},
359360
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import { buildWebpackBrowser } from '../../index';
10+
import { BASE_OPTIONS, BROWSER_BUILDER_INFO, describeBuilder } from '../setup';
11+
12+
describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
13+
describe('Behavior: "RxJS ES2015 exports condition"', () => {
14+
it('uses the rxjs ES2015 distribution files with rxjs 7.x', async () => {
15+
// The `es2015` export condition is enabled by the browser webpack configuration partial.
16+
// This should cause the application output to contain the ES2015 code and not the ES5 code.
17+
18+
// Add rxjs usage to ensure it is present in the application output
19+
// The `rxjs-7` module specifier (and accompanying root package.json entry) is required to
20+
// support testing rxjs 7 while the actual CLI dependencies are still using rxjs 6 since
21+
// bazel unit test setup uses the main package.json dependencies during test.
22+
await harness.modifyFile(
23+
'src/main.ts',
24+
(content) => `import { of } from 'rxjs-7';\n` + content + '\nof(1, 2, 3);',
25+
);
26+
27+
harness.useTarget('build', {
28+
...BASE_OPTIONS,
29+
vendorChunk: true,
30+
});
31+
32+
const { result } = await harness.executeOnce();
33+
34+
expect(result?.success).toBe(true);
35+
harness
36+
.expectFile('dist/vendor.js')
37+
.content.not.toContain('./node_modules/rxjs-7/dist/esm5/');
38+
harness.expectFile('dist/vendor.js').content.toContain('./node_modules/rxjs-7/dist/esm/');
39+
harness.expectFile('dist/vendor.js').content.not.toContain('var Observable');
40+
harness.expectFile('dist/vendor.js').content.toContain('class Observable');
41+
});
42+
});
43+
});

packages/angular_devkit/build_angular/src/webpack/configs/browser.ts

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export function getBrowserConfig(wco: WebpackConfigOptions): webpack.Configurati
6565
devtool: false,
6666
resolve: {
6767
mainFields: ['es2015', 'browser', 'module', 'main'],
68+
conditionNames: ['es2015', '...'],
6869
},
6970
output: {
7071
crossOriginLoading,

packages/angular_devkit/build_angular/src/webpack/configs/test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export function getTestConfig(
5555
target: wco.tsConfig.options.target === ScriptTarget.ES5 ? ['web', 'es5'] : 'web',
5656
resolve: {
5757
mainFields: ['es2015', 'browser', 'module', 'main'],
58+
conditionNames: ['es2015', '...'],
5859
},
5960
devtool: false,
6061
entry: {

yarn.lock

+7
Original file line numberDiff line numberDiff line change
@@ -10261,6 +10261,13 @@ run-parallel@^1.1.9:
1026110261
dependencies:
1026210262
queue-microtask "^1.2.2"
1026310263

10264+
"rxjs-7@npm:rxjs@7.4.0":
10265+
version "7.4.0"
10266+
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-7.4.0.tgz#a12a44d7eebf016f5ff2441b87f28c9a51cebc68"
10267+
integrity sha512-7SQDi7xeTMCJpqViXh8gL/lebcwlp3d831F05+9B44A4B0WfsEwUQHR64gsH1kvJ+Ep/J9K2+n1hVl1CsGN23w==
10268+
dependencies:
10269+
tslib "~2.1.0"
10270+
1026410271
rxjs@6.6.7, rxjs@^6.4.0, rxjs@^6.5.0, rxjs@^6.5.3:
1026510272
version "6.6.7"
1026610273
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.6.7.tgz#90ac018acabf491bf65044235d5863c4dab804c9"

0 commit comments

Comments
 (0)