Skip to content

Commit

Permalink
refactor(@angular/cli): remove outdated performance profiling code
Browse files Browse the repository at this point in the history
  • Loading branch information
clydin authored and filipesilva committed Jun 22, 2021
1 parent c1623c4 commit a2cecf0
Showing 1 changed file with 2 additions and 38 deletions.
40 changes: 2 additions & 38 deletions packages/angular/cli/lib/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,13 @@

import 'symbol-observable';
// symbol polyfill must go first
import * as fs from 'fs';
import { promises as fs } from 'fs';
import * as path from 'path';
import { SemVer } from 'semver';
import { VERSION } from '../models/version';
import { colors } from '../utilities/color';
import { isWarningEnabled } from '../utilities/config';

// Check if we need to profile this CLI run.
if (process.env['NG_CLI_PROFILING']) {
let profiler: {
startProfiling: (name?: string, recsamples?: boolean) => void;
stopProfiling: (name?: string) => unknown;
};
try {
profiler = require('v8-profiler-node8'); // eslint-disable-line import/no-extraneous-dependencies
} 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();

const exitHandler = (options: { cleanup?: boolean; exit?: boolean }) => {
if (options.cleanup) {
const cpuProfile = profiler.stopProfiling();
fs.writeFileSync(
path.resolve(process.cwd(), process.env.NG_CLI_PROFILING || '') + '.cpuprofile',
JSON.stringify(cpuProfile),
);
}

if (options.exit) {
process.exit();
}
};

process.on('exit', () => exitHandler({ cleanup: true }));
process.on('SIGINT', () => exitHandler({ exit: true }));
process.on('uncaughtException', () => exitHandler({ exit: true }));
}

(async () => {
/**
* Disable Browserslist old data warning as otherwise with every release we'd need to update this dependency
Expand Down Expand Up @@ -87,7 +51,7 @@ if (process.env['NG_CLI_PROFILING']) {
let localVersion = cli.VERSION?.full;
if (!localVersion) {
try {
const localPackageJson = await fs.promises.readFile(
const localPackageJson = await fs.readFile(
path.join(path.dirname(projectLocalCli), '../../package.json'),
'utf-8',
);
Expand Down

0 comments on commit a2cecf0

Please sign in to comment.