|
1 | 1 | import * as path from 'path';
|
2 | 2 | import * as process from 'process';
|
3 |
| -import { performance } from 'perf_hooks'; |
4 | 3 | import * as childProcess from 'child_process';
|
5 | 4 | import * as semver from 'semver';
|
6 | 5 | import chalk, { Chalk } from 'chalk';
|
@@ -118,6 +117,7 @@ class ForkTsCheckerWebpackPlugin {
|
118 | 117 | private vue: boolean;
|
119 | 118 |
|
120 | 119 | private measureTime: boolean;
|
| 120 | + private performance: any; |
121 | 121 | private startAt: number = 0;
|
122 | 122 | constructor(options?: Partial<Options>) {
|
123 | 123 | options = options || ({} as Options);
|
@@ -186,6 +186,10 @@ class ForkTsCheckerWebpackPlugin {
|
186 | 186 |
|
187 | 187 | this.vue = options.vue === true; // default false
|
188 | 188 | this.measureTime = options.measureCompilationTime === true;
|
| 189 | + if (this.measureTime) { |
| 190 | + // Node 8+ only |
| 191 | + this.performance = require('perf_hooks').performance; |
| 192 | + } |
189 | 193 | }
|
190 | 194 |
|
191 | 195 | private validateVersions() {
|
@@ -362,7 +366,7 @@ class ForkTsCheckerWebpackPlugin {
|
362 | 366 |
|
363 | 367 | try {
|
364 | 368 | if (this.measureTime) {
|
365 |
| - this.startAt = performance.now(); |
| 369 | + this.startAt = this.performance.now(); |
366 | 370 | }
|
367 | 371 | this.service!.send(this.cancellationToken);
|
368 | 372 | } catch (error) {
|
@@ -625,7 +629,7 @@ class ForkTsCheckerWebpackPlugin {
|
625 | 629 |
|
626 | 630 | private handleServiceMessage(message: Message): void {
|
627 | 631 | if (this.measureTime) {
|
628 |
| - const delta = performance.now() - this.startAt; |
| 632 | + const delta = this.performance.now() - this.startAt; |
629 | 633 | this.logger.info(`compilation took: ${delta} ms.`);
|
630 | 634 | }
|
631 | 635 | if (this.cancellationToken) {
|
|
0 commit comments