2018-07-16 03:49:56 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
2018-08-09 08:54:20 -04:00
|
|
|
|
2018-12-04 16:18:00 -05:00
|
|
|
import {checkMarkerFile, writeMarkerFile} from './packages/build_marker';
|
2018-08-09 10:59:10 -04:00
|
|
|
import {DependencyHost} from './packages/dependency_host';
|
|
|
|
import {DependencyResolver} from './packages/dependency_resolver';
|
|
|
|
import {EntryPointFormat} from './packages/entry_point';
|
2018-11-25 16:40:25 -05:00
|
|
|
import {makeEntryPointBundle} from './packages/entry_point_bundle';
|
2018-08-09 10:59:10 -04:00
|
|
|
import {EntryPointFinder} from './packages/entry_point_finder';
|
|
|
|
import {Transformer} from './packages/transformer';
|
2018-07-16 03:49:56 -04:00
|
|
|
|
2019-03-20 09:47:58 -04:00
|
|
|
/**
|
|
|
|
* The options to configure the ngcc compiler.
|
|
|
|
*/
|
|
|
|
export interface NgccOptions {
|
|
|
|
/** The path to the node_modules folder that contains the packages to compile. */
|
|
|
|
baseSourcePath: string;
|
|
|
|
/** A list of JavaScript bundle formats that should be compiled. */
|
|
|
|
formats: EntryPointFormat[];
|
|
|
|
/** The path to the node_modules folder where modified files should be written. */
|
|
|
|
baseTargetPath?: string;
|
2019-03-20 09:47:58 -04:00
|
|
|
/**
|
|
|
|
* The path, relative to `baseSourcePath` of the primary package to be compiled.
|
|
|
|
* All its dependencies will need to be compiled too.
|
|
|
|
*/
|
|
|
|
targetEntryPointPath?: string;
|
2019-03-20 09:47:58 -04:00
|
|
|
}
|
2018-08-09 10:59:10 -04:00
|
|
|
|
2019-03-20 09:47:58 -04:00
|
|
|
/**
|
|
|
|
* This is the main entry-point into ngcc (aNGular Compatibility Compiler).
|
|
|
|
*
|
|
|
|
* You can call this function to process one or more npm packages, to ensure
|
|
|
|
* that they are compatible with the ivy compiler (ngtsc).
|
|
|
|
*
|
|
|
|
* @param options The options telling ngcc what to compile and how.
|
|
|
|
*/
|
2019-03-20 09:47:58 -04:00
|
|
|
export function mainNgcc({baseSourcePath, formats, baseTargetPath = baseSourcePath,
|
|
|
|
targetEntryPointPath}: NgccOptions): void {
|
2019-03-20 09:47:58 -04:00
|
|
|
const transformer = new Transformer(baseSourcePath, baseTargetPath);
|
2018-08-09 10:59:10 -04:00
|
|
|
const host = new DependencyHost();
|
|
|
|
const resolver = new DependencyResolver(host);
|
|
|
|
const finder = new EntryPointFinder(resolver);
|
|
|
|
|
2019-03-20 09:47:58 -04:00
|
|
|
const {entryPoints} = finder.findEntryPoints(baseSourcePath, targetEntryPointPath);
|
2019-03-20 09:47:58 -04:00
|
|
|
entryPoints.forEach(entryPoint => {
|
2018-11-25 16:40:25 -05:00
|
|
|
|
2019-03-20 09:47:58 -04:00
|
|
|
// Are we compiling the Angular core?
|
|
|
|
const isCore = entryPoint.name === '@angular/core';
|
2018-11-25 16:40:25 -05:00
|
|
|
|
2019-03-20 09:47:58 -04:00
|
|
|
// We transform the d.ts typings files while transforming one of the formats.
|
|
|
|
// This variable decides with which of the available formats to do this transform.
|
|
|
|
// It is marginally faster to process via the flat file if available.
|
|
|
|
const dtsTransformFormat: EntryPointFormat = entryPoint.fesm2015 ? 'fesm2015' : 'esm2015';
|
2018-11-25 16:40:25 -05:00
|
|
|
|
2019-03-20 09:47:58 -04:00
|
|
|
formats.forEach(format => {
|
|
|
|
if (checkMarkerFile(entryPoint, format)) {
|
|
|
|
console.warn(`Skipping ${entryPoint.name} : ${format} (already built).`);
|
|
|
|
return;
|
|
|
|
}
|
2018-12-04 16:18:00 -05:00
|
|
|
|
2019-03-20 09:47:58 -04:00
|
|
|
const bundle =
|
|
|
|
makeEntryPointBundle(entryPoint, isCore, format, format === dtsTransformFormat);
|
|
|
|
if (bundle === null) {
|
|
|
|
console.warn(
|
|
|
|
`Skipping ${entryPoint.name} : ${format} (no entry point file for this format).`);
|
|
|
|
} else {
|
|
|
|
transformer.transform(entryPoint, isCore, bundle);
|
|
|
|
}
|
2018-12-04 16:18:00 -05:00
|
|
|
|
2019-03-20 09:47:58 -04:00
|
|
|
// Write the built-with-ngcc marker
|
|
|
|
writeMarkerFile(entryPoint, format);
|
2018-10-16 03:56:54 -04:00
|
|
|
});
|
2019-03-20 09:47:58 -04:00
|
|
|
});
|
2018-08-09 08:54:20 -04:00
|
|
|
}
|