build: stop hardcoding rollup globals for CDK entry points (#6150)

* Now the rollup globals for the CDK secondary entry-points are no longer hard-coded. There is already a method called `getSecondaryEntryPointsForPackage` which can be used.
This commit is contained in:
Paul Gschwendtner
2017-08-02 23:31:31 +02:00
committed by tinayuangao
parent 8a23157dc3
commit 4168fb39db
5 changed files with 96 additions and 77 deletions
-71
View File
@@ -1,71 +0,0 @@
{
"tslib": "tslib",
"@angular/animations": "ng.animations",
"@angular/core": "ng.core",
"@angular/common": "ng.common",
"@angular/forms": "ng.forms",
"@angular/http": "ng.http",
"@angular/router": "ng.router",
"@angular/platform-browser": "ng.platformBrowser",
"@angular/platform-server": "ng.platformServer",
"@angular/platform-browser-dynamic": "ng.platformBrowserDynamic",
"@angular/platform-browser/animations": "ng.platformBrowser.animations",
"@angular/core/testing": "ng.core.testing",
"@angular/common/testing": "ng.common.testing",
"@angular/http/testing": "ng.http.testing",
"@angular/material": "ng.material",
"@angular/cdk/a11y": "ng.cdk.a11y",
"@angular/cdk/bidi": "ng.cdk.bidi",
"@angular/cdk/coercion": "ng.cdk.coercion",
"@angular/cdk/keyboard": "ng.cdk.keyboard",
"@angular/cdk/observe-content": "ng.cdk.observeContent",
"@angular/cdk/platform": "ng.cdk.platform",
"@angular/cdk/portal": "ng.cdk.portal",
"@angular/cdk/rxjs": "ng.cdk.rxjs",
"@angular/cdk/table": "ng.cdk.table",
"@angular/cdk": "ng.cdk",
"@angular/cdk/testing": "ng.cdk.testing",
"@angular/material-examples": "ng.materialExamples",
"rxjs/BehaviorSubject": "Rx",
"rxjs/Observable": "Rx",
"rxjs/Subject": "Rx",
"rxjs/Subscription": "Rx",
"rxjs/Observer": "Rx",
"rxjs/Scheduler": "Rx",
"rxjs/observable/combineLatest": "Rx.Observable",
"rxjs/observable/forkJoin": "Rx.Observable",
"rxjs/observable/fromEvent": "Rx.Observable",
"rxjs/observable/merge": "Rx.Observable",
"rxjs/observable/of": "Rx.Observable",
"rxjs/observable/throw": "Rx.Observable",
"rxjs/operator/auditTime": "Rx.Observable.prototype",
"rxjs/operator/catch": "Rx.Observable.prototype",
"rxjs/operator/debounceTime": "Rx.Observable.prototype",
"rxjs/operator/do": "Rx.Observable.prototype",
"rxjs/operator/filter": "Rx.Observable.prototype",
"rxjs/operator/finally": "Rx.Observable.prototype",
"rxjs/operator/first": "Rx.Observable.prototype",
"rxjs/operator/let": "Rx.Observable.prototype",
"rxjs/operator/map": "Rx.Observable.prototype",
"rxjs/operator/share": "Rx.Observable.prototype",
"rxjs/operator/startWith": "Rx.Observable.prototype",
"rxjs/operator/switchMap": "Rx.Observable.prototype",
"rxjs/operator/takeUntil": "Rx.Observable.prototype",
"rxjs/operator/toPromise": "Rx.Observable.prototype",
"rxjs/add/observable/merge": "Rx.Observable",
"rxjs/add/observable/fromEvent": "Rx.Observable",
"rxjs/add/observable/of": "Rx.Observable",
"rxjs/add/observable/interval": "Rx.Observable",
"rxjs/add/operator/startWith": "Rx.Observable.prototype",
"rxjs/add/operator/map": "Rx.Observable.prototype",
"rxjs/add/operator/debounceTime": "Rx.Observable.prototype",
"rxjs/add/operator/distinctUntilChanged": "Rx.Observable.prototype",
"rxjs/add/operator/first": "Rx.Observable.prototype",
"rxjs/add/operator/catch": "Rx.Observable.prototype",
"rxjs/add/operator/switchMap": "Rx.Observable.prototype"
}
+83
View File
@@ -0,0 +1,83 @@
import {getSecondaryEntryPointsForPackage} from './secondary-entry-points';
/** Method that converts dash-case strings to a camel-based string. */
const dashCaseToCamelCase = (str: string) => str.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
/** List of available secondary entry-points for the CDK package. */
const cdkSecondaryEntryPoints = getSecondaryEntryPointsForPackage('cdk');
/** Object with all CDK entry points in the format of Rollup globals. */
const rollupCdkEntryPoints = cdkSecondaryEntryPoints.reduce((globals: any, entryPoint: string) => {
globals[`@angular/cdk/${entryPoint}`] = `ng.cdk.${dashCaseToCamelCase(entryPoint)}`;
return globals;
}, {});
/** Map of globals that are used inside of the different packages. */
export const rollupGlobals = {
'tslib': 'tslib',
'@angular/animations': 'ng.animations',
'@angular/core': 'ng.core',
'@angular/common': 'ng.common',
'@angular/forms': 'ng.forms',
'@angular/http': 'ng.http',
'@angular/router': 'ng.router',
'@angular/platform-browser': 'ng.platformBrowser',
'@angular/platform-server': 'ng.platformServer',
'@angular/platform-browser-dynamic': 'ng.platformBrowserDynamic',
'@angular/platform-browser/animations': 'ng.platformBrowser.animations',
'@angular/core/testing': 'ng.core.testing',
'@angular/common/testing': 'ng.common.testing',
'@angular/http/testing': 'ng.http.testing',
'@angular/material': 'ng.material',
'@angular/cdk': 'ng.cdk',
// Include secondary entry-points of the CDK package
...rollupCdkEntryPoints,
// Some packages are not really needed for the UMD bundles, but for the missingRollupGlobals rule.
// TODO(devversion): remove by adding minimatch and better globbing to rules
'@angular/cdk/testing': 'ng.cdk.testing',
'@angular/material-examples': 'ng.materialExamples',
'rxjs/BehaviorSubject': 'Rx',
'rxjs/Observable': 'Rx',
'rxjs/Subject': 'Rx',
'rxjs/Subscription': 'Rx',
'rxjs/Observer': 'Rx',
'rxjs/Scheduler': 'Rx',
'rxjs/observable/combineLatest': 'Rx.Observable',
'rxjs/observable/forkJoin': 'Rx.Observable',
'rxjs/observable/fromEvent': 'Rx.Observable',
'rxjs/observable/merge': 'Rx.Observable',
'rxjs/observable/of': 'Rx.Observable',
'rxjs/observable/throw': 'Rx.Observable',
'rxjs/operator/auditTime': 'Rx.Observable.prototype',
'rxjs/operator/catch': 'Rx.Observable.prototype',
'rxjs/operator/debounceTime': 'Rx.Observable.prototype',
'rxjs/operator/do': 'Rx.Observable.prototype',
'rxjs/operator/filter': 'Rx.Observable.prototype',
'rxjs/operator/finally': 'Rx.Observable.prototype',
'rxjs/operator/first': 'Rx.Observable.prototype',
'rxjs/operator/let': 'Rx.Observable.prototype',
'rxjs/operator/map': 'Rx.Observable.prototype',
'rxjs/operator/share': 'Rx.Observable.prototype',
'rxjs/operator/startWith': 'Rx.Observable.prototype',
'rxjs/operator/switchMap': 'Rx.Observable.prototype',
'rxjs/operator/takeUntil': 'Rx.Observable.prototype',
'rxjs/operator/toPromise': 'Rx.Observable.prototype',
'rxjs/add/observable/merge': 'Rx.Observable',
'rxjs/add/observable/fromEvent': 'Rx.Observable',
'rxjs/add/observable/of': 'Rx.Observable',
'rxjs/add/observable/interval': 'Rx.Observable',
'rxjs/add/operator/startWith': 'Rx.Observable.prototype',
'rxjs/add/operator/map': 'Rx.Observable.prototype',
'rxjs/add/operator/debounceTime': 'Rx.Observable.prototype',
'rxjs/add/operator/distinctUntilChanged': 'Rx.Observable.prototype',
'rxjs/add/operator/first': 'Rx.Observable.prototype',
'rxjs/add/operator/catch': 'Rx.Observable.prototype',
'rxjs/add/operator/switchMap': 'Rx.Observable.prototype'
};
+4 -4
View File
@@ -1,10 +1,10 @@
import {buildConfig} from './build-config';
import {rollupRemoveLicensesPlugin} from './rollup-remove-licenses';
import {rollupGlobals} from './rollup-globals';
// There are no type definitions available for these imports.
const rollup = require('rollup');
const rollupNodeResolutionPlugin = require('rollup-plugin-node-resolve');
const ROLLUP_GLOBALS = require('./rollup-globals.json');
export type BundleConfig = {
entry: string;
@@ -17,7 +17,7 @@ export type BundleConfig = {
export function createRollupBundle(config: BundleConfig): Promise<any> {
const bundleOptions = {
context: 'this',
external: Object.keys(ROLLUP_GLOBALS),
external: Object.keys(rollupGlobals),
entry: config.entry,
plugins: [rollupRemoveLicensesPlugin]
};
@@ -29,7 +29,7 @@ export function createRollupBundle(config: BundleConfig): Promise<any> {
banner: buildConfig.licenseBanner,
format: config.format,
dest: config.dest,
globals: ROLLUP_GLOBALS,
globals: rollupGlobals,
sourceMap: true
};
@@ -38,7 +38,7 @@ export function createRollupBundle(config: BundleConfig): Promise<any> {
if (config.format === 'umd') {
bundleOptions.plugins.push(rollupNodeResolutionPlugin());
const external = Object.keys(ROLLUP_GLOBALS);
const external = Object.keys(rollupGlobals);
external.splice(external.indexOf('tslib'), 1);
bundleOptions.external = external;
}
@@ -1,6 +1,13 @@
const path = require('path');
const Lint = require('tslint');
// Since the packaging is based on TypeScript and is only compiled at run-time using ts-node, the
// custom TSLint rule is not able to read the map of rollup globals. Because the custom rules
// for TSLint are written in JavaScript we also need to use ts-node here to read the globals.
require('ts-node').register({
project: path.join(__dirname, '../gulp/tsconfig.json')
});
/**
* Rule that enforces that the specified external packages have been included in our Rollup config.
* Usage: [true, './path/to/rollup/config.json']
@@ -22,7 +29,7 @@ class Walker extends Lint.RuleWalker {
const [configPath, ...whitelist] = options.ruleArguments;
this._configPath = path.resolve(process.cwd(), configPath);
this._config = require(this._configPath);
this._config = require(this._configPath).rollupGlobals;
this._enabled = !whitelist.length || whitelist.some(p => new RegExp(p).test(file.fileName));
}
+1 -1
View File
@@ -37,7 +37,7 @@
],
"missing-rollup-globals": [
true,
"./tools/package-tools/rollup-globals.json",
"./tools/package-tools/rollup-globals.ts",
"^((?!tools).)*$"
],
"one-line": [