2019-10-27 19:28:03 -04:00
|
|
|
const node = require('rollup-plugin-node-resolve');
|
|
|
|
const commonjs = require('rollup-plugin-commonjs');
|
|
|
|
|
2019-11-09 05:40:04 -05:00
|
|
|
// Parse the stamp file produced by Bazel from the version control system
|
|
|
|
let version = '<unknown>';
|
2021-02-04 17:11:53 -05:00
|
|
|
if (bazel_version_file) {
|
2019-11-09 05:40:04 -05:00
|
|
|
const versionTag = require('fs')
|
2021-02-04 17:11:53 -05:00
|
|
|
.readFileSync(bazel_version_file, {encoding: 'utf-8'})
|
2019-11-09 05:40:04 -05:00
|
|
|
.split('\n')
|
|
|
|
.find(s => s.startsWith('BUILD_SCM_VERSION'));
|
|
|
|
// Don't assume BUILD_SCM_VERSION exists
|
|
|
|
if (versionTag) {
|
|
|
|
version = versionTag.split(' ')[1].trim();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
fix(zone.js): fesm2015 bundle should also be strict module. (#40456)
Close #40215
`fesm2015/zone.js` is built to `esm` bundle with rollup, so the 'use strict';
statement is not generated in the bundle, even we put the 'use strict' in the src code,
rollup removes the code in the final bundle.
So if we load the `fesm2015/zone.js` as a module, such as `ng serve`, in the index.html
```
<script src="polyfills.js" type="module"></script>
```
Everything works fine, since polyfills.js is loaded as `module`, so it is always `strict`.
But in `ng test`, webpack concat the `zone.js` and loaded into the karma html. For other app and
test code, they are still `strict` since they are `module` because they have `export/import`
statement, but `zone.js` is a bundle without `export`, it is a `side effect` bundle, so after
loaded by webpack, it becomes non-strict. Which causes some issues, such as #40215,
the root cause is the `this` context should be `undefined` but treated as `Window` in `non-strict` mode.
```
Object.prototype.toString.apply(undefined);
// should be [object undefined], but it is [object Window] in non-strict mode.
// zone.js patched version of toString
Object.prototype.toString = function() {
...
// in non-strict mode, this is Window
return originalObjectPrototypeToString.call(this);
}
```
So in this commit, `'use strict';` is always added to the `esm` bundles.
PR Close #40456
2021-01-15 20:14:08 -05:00
|
|
|
// Add 'use strict' to the bundle, https://github.com/angular/angular/pull/40456
|
|
|
|
// When rollup build esm bundle of zone.js, there will be no 'use strict'
|
|
|
|
// since all esm bundles are `strict`, but when webpack load the esm bundle,
|
|
|
|
// because zone.js is a module without export and import, webpack is unable
|
|
|
|
// to determine the bundle is `esm` module or not, so it doesn't add the 'use strict'
|
|
|
|
// which webpack does to all other `esm` modules which has export or import.
|
|
|
|
// And it causes issues such as https://github.com/angular/angular/issues/40215
|
|
|
|
// `this` should be `undefined` but is assigned with `Window` instead.
|
|
|
|
const banner = `'use strict';
|
|
|
|
/**
|
2021-01-19 04:52:21 -05:00
|
|
|
* @license Angular v${version}
|
2021-02-19 16:17:11 -05:00
|
|
|
* (c) 2010-2021 Google LLC. https://angular.io/
|
2021-01-19 04:52:21 -05:00
|
|
|
* License: MIT
|
refactor(zone.js): refactor zone rollup config (#40481)
When migrating zone.js from gulp to bazel, some legacy build config files are still there,
we have `rollup-es5.config.js` and `rollup-es5_global-es2015.config.js`, since in gulp build
system, build `es5` or `esm` files are set in the config file, but in the bazel world,
the output format is not config in the config.js file, but is required by the downstream
bazel target. So we don't really need the two rollup config files any longer.
Another difference is in `rollup-es5.config.js`, the `external` and `global` libraries names
are also config there, and these settings are also valid for `es2015` build, these settings
are not in the `es2015.config.js` for some legacy reasons. So we don't need to keep this
difference either.
PR Close #40481
2021-01-19 07:33:03 -05:00
|
|
|
*/`;
|
2019-10-27 19:28:03 -04:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
plugins: [
|
|
|
|
node({
|
|
|
|
mainFields: ['es2015', 'module', 'jsnext:main', 'main'],
|
|
|
|
}),
|
|
|
|
commonjs(),
|
|
|
|
],
|
2020-03-10 00:44:13 -04:00
|
|
|
external: id => {
|
|
|
|
if (/build-esm/.test(id)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return /rxjs/.test(id) || /electron/.test(id);
|
|
|
|
},
|
|
|
|
output: {
|
|
|
|
globals: {
|
|
|
|
electron: 'electron',
|
|
|
|
'rxjs/Observable': 'Rx',
|
|
|
|
'rxjs/Subscriber': 'Rx',
|
|
|
|
'rxjs/Subscription': 'Rx',
|
|
|
|
'rxjs/Scheduler': 'Rx.Scheduler',
|
|
|
|
'rxjs/scheduler/asap': 'Rx.Scheduler',
|
|
|
|
'rxjs/scheduler/async': 'Rx.Scheduler',
|
|
|
|
'rxjs/symbol/rxSubscriber': 'Rx.Symbol'
|
|
|
|
},
|
|
|
|
banner
|
|
|
|
},
|
2019-10-27 19:28:03 -04:00
|
|
|
}
|