From 4c21ce6859afcdec0f2d6081fab17e17791fd4f6 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Fri, 3 Dec 2021 11:13:18 +0100 Subject: [PATCH] refactor(@angular-devkit/build-angular): remove `NG_BUILD_PROFILING` and `DEVKIT_PROFILING` logic Generating a CPU profile using Node.JS `--cpu-prof` or Chrome insector is preferred. Closes #20336 --- lib/bootstrap-local.js | 36 ------------------- .../src/utils/environment-options.ts | 4 --- .../src/webpack/configs/common.ts | 11 +----- tests/legacy-cli/e2e/tests/build/profile.ts | 12 ------- 4 files changed, 1 insertion(+), 62 deletions(-) delete mode 100644 tests/legacy-cli/e2e/tests/build/profile.ts diff --git a/lib/bootstrap-local.js b/lib/bootstrap-local.js index c6441e56f47d..1c9bf9f36b99 100644 --- a/lib/bootstrap-local.js +++ b/lib/bootstrap-local.js @@ -31,42 +31,6 @@ const compilerOptions = ts.getParsedCommandLineOfConfigFile( ts.sys, ).options; -// Check if we need to profile this CLI run. -let profiler = null; -if (process.env['DEVKIT_PROFILING']) { - debugLocal('setup profiling'); - try { - profiler = require('v8-profiler-node8'); - } catch (err) { - throw new Error( - `Could not require 'v8-profiler-node8'. You must install it separetely with` + - `'npm install v8-profiler-node8 --no-save.\n\nOriginal error:\n\n${err}`, - ); - } - - profiler.startProfiling(); - - function exitHandler(options, _err) { - if (options.cleanup) { - const cpuProfile = profiler.stopProfiling(); - const profileData = JSON.stringify(cpuProfile); - const filePath = path.resolve(process.cwd(), process.env.DEVKIT_PROFILING) + '.cpuprofile'; - - debugLocal('saving profiling data'); - console.log(`Profiling data saved in "${filePath}": ${profileData.length} bytes`); - fs.writeFileSync(filePath, profileData); - } - - if (options.exit) { - process.exit(); - } - } - - process.on('exit', exitHandler.bind(null, { cleanup: true })); - process.on('SIGINT', exitHandler.bind(null, { exit: true })); - process.on('uncaughtException', exitHandler.bind(null, { exit: true })); -} - if (process.env['DEVKIT_LONG_STACK_TRACE']) { debugLocal('setup long stack trace'); Error.stackTraceLimit = Infinity; diff --git a/packages/angular_devkit/build_angular/src/utils/environment-options.ts b/packages/angular_devkit/build_angular/src/utils/environment-options.ts index dcd1bb84723b..17be9238fa6e 100644 --- a/packages/angular_devkit/build_angular/src/utils/environment-options.ts +++ b/packages/angular_devkit/build_angular/src/utils/environment-options.ts @@ -66,10 +66,6 @@ export const allowMangle = isPresent(mangleVariable) export const shouldBeautify = debugOptimize.beautify; export const allowMinify = debugOptimize.minify; -// Build profiling -const profilingVariable = process.env['NG_BUILD_PROFILING']; -export const profilingEnabled = isPresent(profilingVariable) && isEnabled(profilingVariable); - /** * 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. diff --git a/packages/angular_devkit/build_angular/src/webpack/configs/common.ts b/packages/angular_devkit/build_angular/src/webpack/configs/common.ts index fdc3ac4b5a01..43b96902427e 100644 --- a/packages/angular_devkit/build_angular/src/webpack/configs/common.ts +++ b/packages/angular_devkit/build_angular/src/webpack/configs/common.ts @@ -16,12 +16,11 @@ import { ContextReplacementPlugin, RuleSetRule, SourceMapDevToolPlugin, - debug, } from 'webpack'; import { SubresourceIntegrityPlugin } from 'webpack-subresource-integrity'; import { AngularBabelLoaderOptions } from '../../babel/webpack-loader'; import { WebpackConfigOptions } from '../../utils/build-options'; -import { allowMangle, profilingEnabled } from '../../utils/environment-options'; +import { allowMangle } from '../../utils/environment-options'; import { loadEsmModule } from '../../utils/load-esm'; import { CommonJsUsageWarnPlugin, @@ -133,14 +132,6 @@ export async function getCommonConfig(wco: WebpackConfigOptions): Promise