Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 0 additions & 71 deletions tools/package-tools/rollup-globals.json

This file was deleted.

83 changes: 83 additions & 0 deletions tools/package-tools/rollup-globals.ts
Original file line number Diff line number Diff line change
@@ -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'
};
8 changes: 4 additions & 4 deletions tools/package-tools/rollup-helpers.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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]
};
Expand All @@ -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
};

Expand All @@ -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;
}
Expand Down
9 changes: 8 additions & 1 deletion tools/tslint-rules/missingRollupGlobalsRule.js
Original file line number Diff line number Diff line change
@@ -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']
Expand All @@ -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));
}

Expand Down
2 changes: 1 addition & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
],
"missing-rollup-globals": [
true,
"./tools/package-tools/rollup-globals.json",
"./tools/package-tools/rollup-globals.ts",
"^((?!tools).)*$"
],
"one-line": [
Expand Down