Skip to content

Commit

Permalink
feat: add node timing
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Jun 8, 2020
1 parent 8e87a00 commit 57ab8e5
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/cli/commands/build.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { PerformanceObserver, performance } from 'perf_hooks'

import chalk from 'chalk'
import consola from 'consola'

import { Package } from '../../package'
Expand All @@ -7,13 +10,21 @@ export interface BuildOptions {
watch?: boolean
}

const obs = new PerformanceObserver(items => {
const { duration, name } = items.getEntries()[0]
const seconds = (duration / 1000).toFixed(1)
consola.success(`${name} in ${chalk.bold(seconds + 's')}`)
})
obs.observe({ entryTypes: ['measure'] })

export async function build(options: BuildOptions = {}) {
// Read package at current directory
const rootPackage = new Package()
const workspacePackages = await rootPackage.getWorkspacePackages()

const { watch } = options
consola.info(`Beginning build${watch ? ' (watching)' : ''}`)
performance.mark('Start build')

// Universal linkedDependencies based on workspace
const linkedDependencies = workspacePackages.map(p =>
Expand Down Expand Up @@ -46,4 +57,7 @@ export async function build(options: BuildOptions = {}) {
pkg.autoFix()
pkg.writePackage()
})
performance.mark('Stop build')

performance.measure('Finished build', 'Start build', 'Stop build')
}

0 comments on commit 57ab8e5

Please sign in to comment.