Skip to content

Instantly share code, notes, and snippets.

@alan-agius4
Created November 23, 2023 11:53
Show Gist options
  • Save alan-agius4/200fe02b59519a1bb0f5338fb8bcc225 to your computer and use it in GitHub Desktop.
Save alan-agius4/200fe02b59519a1bb0f5338fb8bcc225 to your computer and use it in GitHub Desktop.
"use strict";
/**
* @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
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.shouldWatchRoot = exports.debugPerformance = exports.useLegacySass = exports.useParallelTs = exports.maxWorkers = exports.allowMinify = exports.shouldBeautify = exports.allowMangle = void 0;
const color_1 = require("./color");
function isDisabled(variable) {
return variable === '0' || variable.toLowerCase() === 'false';
}
function isEnabled(variable) {
return variable === '1' || variable.toLowerCase() === 'true';
}
function isPresent(variable) {
return typeof variable === 'string' && variable !== '';
}
// Optimization and mangling
const debugOptimizeVariable = process.env['NG_BUILD_DEBUG_OPTIMIZE'];
const debugOptimize = (() => {
if (!isPresent(debugOptimizeVariable) || isDisabled(debugOptimizeVariable)) {
return {
mangle: true,
minify: true,
beautify: false,
};
}
const debugValue = {
mangle: false,
minify: false,
beautify: true,
};
if (isEnabled(debugOptimizeVariable)) {
return debugValue;
}
for (const part of debugOptimizeVariable.split(',')) {
switch (part.trim().toLowerCase()) {
case 'mangle':
debugValue.mangle = true;
break;
case 'minify':
debugValue.minify = true;
break;
case 'beautify':
debugValue.beautify = true;
break;
}
}
return debugValue;
})();
const mangleVariable = process.env['NG_BUILD_MANGLE'];
exports.allowMangle = isPresent(mangleVariable)
? !isDisabled(mangleVariable)
: debugOptimize.mangle;
exports.shouldBeautify = debugOptimize.beautify;
exports.allowMinify = debugOptimize.minify;
/**
* Some environments, like CircleCI which use Docker report a number of CPUs by the host and not the count of available.
* This cause `Error: Call retries were exceeded` errors when trying to use them.
*
* @see https://github.com/nodejs/node/issues/28762
* @see https://github.com/webpack-contrib/terser-webpack-plugin/issues/143
* @see https://ithub.com/angular/angular-cli/issues/16860#issuecomment-588828079
*
*/
const maxWorkersVariable = process.env['NG_BUILD_MAX_WORKERS'];
exports.maxWorkers = isPresent(maxWorkersVariable) ? +maxWorkersVariable : 4;
const parallelTsVariable = process.env['NG_BUILD_PARALLEL_TS'];
exports.useParallelTs = !isPresent(parallelTsVariable) || !isDisabled(parallelTsVariable);
const legacySassVariable = process.env['NG_BUILD_LEGACY_SASS'];
exports.useLegacySass = (() => {
if (!isPresent(legacySassVariable)) {
return false;
}
// eslint-disable-next-line no-console
console.warn(color_1.colors.yellow(`Warning: 'NG_BUILD_LEGACY_SASS' environment variable support will be removed in version 16.`));
return isEnabled(legacySassVariable);
})();
const debugPerfVariable = process.env['NG_BUILD_DEBUG_PERF'];
exports.debugPerformance = isPresent(debugPerfVariable) && isEnabled(debugPerfVariable);
// Default to true on Windows to workaround Visual Studio atomic file saving watch issues
const watchRootVariable = process.env['NG_BUILD_WATCH_ROOT'];
exports.shouldWatchRoot = isPresent(watchRootVariable) && isEnabled(watchRootVariable);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment