mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
build: remove duplicate licenses in bundles (#5195)
* No longer includes the license comments from every source file in the different FESM and UMD bundles. * Build packages are now emitted with explicit `LF` line endings instead of platform dependent line endings.
This commit is contained in:
committed by
Jeremy Elbourn
parent
b456eed0b7
commit
39f22c2aa2
@@ -1,5 +1,5 @@
|
||||
import {join} from 'path';
|
||||
import {ScriptTarget, ModuleKind} from 'typescript';
|
||||
import {ScriptTarget, ModuleKind, NewLineKind} from 'typescript';
|
||||
import {uglifyJsFile} from './minify-sources';
|
||||
import {createRollupBundle} from './rollup-helpers';
|
||||
import {remapSourcemap} from './sourcemap-remap';
|
||||
@@ -38,7 +38,8 @@ export async function buildPackageBundles(entryFile: string, packageName: string
|
||||
importHelpers: true,
|
||||
target: ScriptTarget.ES5,
|
||||
module: ModuleKind.ES2015,
|
||||
allowJs: true
|
||||
allowJs: true,
|
||||
newLine: NewLineKind.LineFeed
|
||||
});
|
||||
|
||||
await remapSourcemap(fesm2014File);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import {buildConfig} from './build-config';
|
||||
import {rollupRemoveLicensesPlugin} from './rollup-remove-licenses';
|
||||
|
||||
// There are no type definitions available for these imports.
|
||||
const rollup = require('rollup');
|
||||
@@ -59,10 +60,11 @@ export type BundleConfig = {
|
||||
|
||||
/** Creates a rollup bundle of a specified JavaScript file.*/
|
||||
export function createRollupBundle(config: BundleConfig): Promise<any> {
|
||||
const bundleOptions: any = {
|
||||
const bundleOptions = {
|
||||
context: 'this',
|
||||
external: Object.keys(ROLLUP_GLOBALS),
|
||||
entry: config.entry,
|
||||
plugins: [rollupRemoveLicensesPlugin]
|
||||
};
|
||||
|
||||
const writeOptions = {
|
||||
@@ -79,7 +81,7 @@ export function createRollupBundle(config: BundleConfig): Promise<any> {
|
||||
// When creating a UMD, we want to exclude tslib from the `external` bundle option so that it
|
||||
// is inlined into the bundle.
|
||||
if (config.format === 'umd') {
|
||||
bundleOptions.plugins = [rollupNodeResolutionPlugin()];
|
||||
bundleOptions.plugins.push(rollupNodeResolutionPlugin());
|
||||
|
||||
const external = Object.keys(ROLLUP_GLOBALS);
|
||||
external.splice(external.indexOf('tslib'), 1);
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import {buildConfig} from './build-config';
|
||||
import MagicString from 'magic-string';
|
||||
|
||||
/** License banner from the build config that will be removed in all source files. */
|
||||
const licenseBanner = buildConfig.licenseBanner;
|
||||
|
||||
/**
|
||||
* Rollup plugin that removes all license banners of source files.
|
||||
* This is necessary to avoid having the license comment repeated in the output.
|
||||
*/
|
||||
export const rollupRemoveLicensesPlugin = {
|
||||
name: 'rollup-clean-duplicate-licenses',
|
||||
transform: (code: string) => {
|
||||
const newContent = new MagicString(code);
|
||||
|
||||
// Walks through every occurrence of a license comment and overwrites it with an empty string.
|
||||
for (let pos = -1; (pos = code.indexOf(licenseBanner, pos + 1)) !== -1; null) {
|
||||
newContent.overwrite(pos, pos + licenseBanner.length, '');
|
||||
}
|
||||
|
||||
return {
|
||||
code: newContent.toString(),
|
||||
map: newContent.generateMap({ hires: true })
|
||||
};
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user