135 lines
29 KiB
JavaScript
135 lines
29 KiB
JavaScript
|
(function (factory) {
|
||
|
if (typeof module === "object" && typeof module.exports === "object") {
|
||
|
var v = factory(require, exports);
|
||
|
if (v !== undefined) module.exports = v;
|
||
|
}
|
||
|
else if (typeof define === "function" && define.amd) {
|
||
|
define("@angular/compiler-cli/ngcc/src/ngcc_options", ["require", "exports", "os", "@angular/compiler-cli/src/ngtsc/file_system", "@angular/compiler-cli/src/ngtsc/logging", "@angular/compiler-cli/src/perform_compile", "@angular/compiler-cli/ngcc/src/packages/entry_point", "@angular/compiler-cli/ngcc/src/path_mappings", "@angular/compiler-cli/ngcc/src/writing/in_place_file_writer", "@angular/compiler-cli/ngcc/src/writing/new_entry_point_file_writer"], factory);
|
||
|
}
|
||
|
})(function (require, exports) {
|
||
|
"use strict";
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
exports.getMaxNumberOfWorkers = exports.clearTsConfigCache = exports.getSharedSetup = void 0;
|
||
|
/**
|
||
|
* @license
|
||
|
* Copyright Google LLC 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
|
||
|
*/
|
||
|
var os = require("os");
|
||
|
var file_system_1 = require("@angular/compiler-cli/src/ngtsc/file_system");
|
||
|
var logging_1 = require("@angular/compiler-cli/src/ngtsc/logging");
|
||
|
var perform_compile_1 = require("@angular/compiler-cli/src/perform_compile");
|
||
|
var entry_point_1 = require("@angular/compiler-cli/ngcc/src/packages/entry_point");
|
||
|
var path_mappings_1 = require("@angular/compiler-cli/ngcc/src/path_mappings");
|
||
|
var in_place_file_writer_1 = require("@angular/compiler-cli/ngcc/src/writing/in_place_file_writer");
|
||
|
var new_entry_point_file_writer_1 = require("@angular/compiler-cli/ngcc/src/writing/new_entry_point_file_writer");
|
||
|
/**
|
||
|
* Instantiate common utilities that are always used and fix up options with defaults, as necessary.
|
||
|
*
|
||
|
* NOTE: Avoid eagerly instantiating anything that might not be used when running sync/async.
|
||
|
*/
|
||
|
function getSharedSetup(options) {
|
||
|
var fileSystem = file_system_1.getFileSystem();
|
||
|
var absBasePath = file_system_1.absoluteFrom(options.basePath);
|
||
|
var projectPath = fileSystem.dirname(absBasePath);
|
||
|
var tsConfig = options.tsConfigPath !== null ? getTsConfig(options.tsConfigPath || projectPath) : null;
|
||
|
var basePath = options.basePath, targetEntryPointPath = options.targetEntryPointPath, _a = options.propertiesToConsider, propertiesToConsider = _a === void 0 ? entry_point_1.SUPPORTED_FORMAT_PROPERTIES : _a, _b = options.typingsOnly, typingsOnly = _b === void 0 ? false : _b, _c = options.compileAllFormats, compileAllFormats = _c === void 0 ? true : _c, _d = options.createNewEntryPointFormats, createNewEntryPointFormats = _d === void 0 ? false : _d, _e = options.logger, logger = _e === void 0 ? new logging_1.ConsoleLogger(logging_1.LogLevel.info) : _e, _f = options.pathMappings, pathMappings = _f === void 0 ? path_mappings_1.getPathMappingsFromTsConfig(fileSystem, tsConfig, projectPath) : _f, _g = options.async, async = _g === void 0 ? false : _g, _h = options.errorOnFailedEntryPoint, errorOnFailedEntryPoint = _h === void 0 ? false : _h, _j = options.enableI18nLegacyMessageIdFormat, enableI18nLegacyMessageIdFormat = _j === void 0 ? true : _j, _k = options.invalidateEntryPointManifest, invalidateEntryPointManifest = _k === void 0 ? false : _k, tsConfigPath = options.tsConfigPath;
|
||
|
if (!!targetEntryPointPath) {
|
||
|
// targetEntryPointPath forces us to error if an entry-point fails.
|
||
|
errorOnFailedEntryPoint = true;
|
||
|
}
|
||
|
if (typingsOnly) {
|
||
|
// If we only want to process the typings then we do not want to waste time trying to process
|
||
|
// multiple JS formats.
|
||
|
compileAllFormats = false;
|
||
|
}
|
||
|
checkForSolutionStyleTsConfig(fileSystem, logger, projectPath, options.tsConfigPath, tsConfig);
|
||
|
return {
|
||
|
basePath: basePath,
|
||
|
targetEntryPointPath: targetEntryPointPath,
|
||
|
propertiesToConsider: propertiesToConsider,
|
||
|
typingsOnly: typingsOnly,
|
||
|
compileAllFormats: compileAllFormats,
|
||
|
createNewEntryPointFormats: createNewEntryPointFormats,
|
||
|
logger: logger,
|
||
|
pathMappings: pathMappings,
|
||
|
async: async,
|
||
|
errorOnFailedEntryPoint: errorOnFailedEntryPoint,
|
||
|
enableI18nLegacyMessageIdFormat: enableI18nLegacyMessageIdFormat,
|
||
|
invalidateEntryPointManifest: invalidateEntryPointManifest,
|
||
|
tsConfigPath: tsConfigPath,
|
||
|
fileSystem: fileSystem,
|
||
|
absBasePath: absBasePath,
|
||
|
projectPath: projectPath,
|
||
|
tsConfig: tsConfig,
|
||
|
getFileWriter: function (pkgJsonUpdater) { return createNewEntryPointFormats ?
|
||
|
new new_entry_point_file_writer_1.NewEntryPointFileWriter(fileSystem, logger, errorOnFailedEntryPoint, pkgJsonUpdater) :
|
||
|
new in_place_file_writer_1.InPlaceFileWriter(fileSystem, logger, errorOnFailedEntryPoint); },
|
||
|
};
|
||
|
}
|
||
|
exports.getSharedSetup = getSharedSetup;
|
||
|
var tsConfigCache = null;
|
||
|
var tsConfigPathCache = null;
|
||
|
/**
|
||
|
* Get the parsed configuration object for the given `tsConfigPath`.
|
||
|
*
|
||
|
* This function will cache the previous parsed configuration object to avoid unnecessary processing
|
||
|
* of the tsconfig.json in the case that it is requested repeatedly.
|
||
|
*
|
||
|
* This makes the assumption, which is true as of writing, that the contents of tsconfig.json and
|
||
|
* its dependencies will not change during the life of the process running ngcc.
|
||
|
*/
|
||
|
function getTsConfig(tsConfigPath) {
|
||
|
if (tsConfigPath !== tsConfigPathCache) {
|
||
|
tsConfigPathCache = tsConfigPath;
|
||
|
tsConfigCache = perform_compile_1.readConfiguration(tsConfigPath);
|
||
|
}
|
||
|
return tsConfigCache;
|
||
|
}
|
||
|
function clearTsConfigCache() {
|
||
|
tsConfigPathCache = null;
|
||
|
tsConfigCache = null;
|
||
|
}
|
||
|
exports.clearTsConfigCache = clearTsConfigCache;
|
||
|
function checkForSolutionStyleTsConfig(fileSystem, logger, projectPath, tsConfigPath, tsConfig) {
|
||
|
if (tsConfigPath !== null && !tsConfigPath && tsConfig !== null &&
|
||
|
tsConfig.rootNames.length === 0 && tsConfig.projectReferences !== undefined &&
|
||
|
tsConfig.projectReferences.length > 0) {
|
||
|
logger.warn("The inferred tsconfig file \"" + tsConfig.project + "\" appears to be \"solution-style\" " +
|
||
|
"since it contains no root files but does contain project references.\n" +
|
||
|
"This is probably not wanted, since ngcc is unable to infer settings like \"paths\" mappings from such a file.\n" +
|
||
|
"Perhaps you should have explicitly specified one of the referenced projects using the --tsconfig option. For example:\n\n" +
|
||
|
tsConfig.projectReferences.map(function (ref) { return " ngcc ... --tsconfig \"" + ref.originalPath + "\"\n"; })
|
||
|
.join('') +
|
||
|
"\nFind out more about solution-style tsconfig at https://devblogs.microsoft.com/typescript/announcing-typescript-3-9/#solution-style-tsconfig.\n" +
|
||
|
"If you did intend to use this file, then you can hide this warning by providing it explicitly:\n\n" +
|
||
|
(" ngcc ... --tsconfig \"" + fileSystem.relative(projectPath, tsConfig.project) + "\""));
|
||
|
}
|
||
|
}
|
||
|
/**
|
||
|
* Determines the maximum number of workers to use for parallel execution. This can be set using the
|
||
|
* NGCC_MAX_WORKERS environment variable, or is computed based on the number of available CPUs. One
|
||
|
* CPU core is always reserved for the master process, so we take the number of CPUs minus one, with
|
||
|
* a maximum of 4 workers. We don't scale the number of workers beyond 4 by default, as it takes
|
||
|
* considerably more memory and CPU cycles while not offering a substantial improvement in time.
|
||
|
*/
|
||
|
function getMaxNumberOfWorkers() {
|
||
|
var maxWorkers = process.env.NGCC_MAX_WORKERS;
|
||
|
if (maxWorkers === undefined) {
|
||
|
// Use up to 4 CPU cores for workers, always reserving one for master.
|
||
|
return Math.max(1, Math.min(4, os.cpus().length - 1));
|
||
|
}
|
||
|
var numericMaxWorkers = +maxWorkers.trim();
|
||
|
if (!Number.isInteger(numericMaxWorkers)) {
|
||
|
throw new Error('NGCC_MAX_WORKERS should be an integer.');
|
||
|
}
|
||
|
else if (numericMaxWorkers < 1) {
|
||
|
throw new Error('NGCC_MAX_WORKERS should be at least 1.');
|
||
|
}
|
||
|
return numericMaxWorkers;
|
||
|
}
|
||
|
exports.getMaxNumberOfWorkers = getMaxNumberOfWorkers;
|
||
|
});
|
||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibmdjY19vcHRpb25zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vLi4vcGFja2FnZXMvY29tcGlsZXItY2xpL25nY2Mvc3JjL25nY2Nfb3B0aW9ucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7SUFBQTs7Ozs7O09BTUc7SUFDSCx1QkFBeUI7SUFFekIsMkVBQXNIO0lBQ3RILG1FQUF3RTtJQUN4RSw2RUFBaUY7SUFFakYsbUZBQW1FO0lBQ25FLDhFQUEwRTtJQUUxRSxvR0FBaUU7SUFDakUsa0hBQThFO0lBd0o5RTs7OztPQUlHO0lBQ0gsU0FBZ0IsY0FBYyxDQUFDLE9BQW9CO1FBRWpELElBQU0sVUFBVSxHQUFHLDJCQUFhLEVBQUUsQ0FBQztRQUNuQyxJQUFNLFdBQVcsR0FBRywwQkFBWSxDQUFDLE9BQU8sQ0FBQyxRQUFRLENBQUMsQ0FBQztRQUNuRCxJQUFNLFdBQVcsR0FBRyxVQUFVLENBQUMsT0FBTyxDQUFDLFdBQVcsQ0FBQyxDQUFDO1FBQ3BELElBQU0sUUFBUSxHQUNWLE9BQU8sQ0FBQyxZQUFZLEtBQUssSUFBSSxDQUFDLENBQUMsQ0FBQyxXQUFXLENBQUMsT0FBTyxDQUFDLFlBQVksSUFBSSxXQUFXLENBQUMsQ0FBQyxDQUFDLENBQUMsSUFBSSxDQUFDO1FBRzFGLElBQUEsUUFBUSxHQWFOLE9BQU8sU0FiRCxFQUNSLG9CQUFvQixHQVlsQixPQUFPLHFCQVp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