Skip to content

Commit

Permalink
fix: move up prod check in tsPath (#858)
Browse files Browse the repository at this point in the history
* fix: move up prod check in tsPath

* test: fix parser perf test

* fix: clarify performance debug logs

* chore: update log message

* fix: add bullet point for time spent loading root plugin
  • Loading branch information
mdonnalley authored Nov 8, 2023
1 parent 672abf0 commit 204de58
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/config/ts-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ export async function tsPath(root: string, orig: string | undefined, plugin?: Pl

const isProduction = isProd()

// Do not skip ts-node registration if the plugin is linked
if (settings.tsnodeEnabled === undefined && isProduction && plugin?.type !== 'link') {
debug(`Skipping ts-node registration for ${root} because NODE_ENV is NOT "test" or "development"`)
return orig
}

if (cannotTranspileEsm(rootPlugin, plugin, isProduction)) {
debug(
`Skipping ts-node registration for ${root} because it's an ESM module (NODE_ENV: ${process.env.NODE_ENV}, root plugin module type: ${rootPlugin?.moduleType})`,
Expand All @@ -214,12 +220,6 @@ export async function tsPath(root: string, orig: string | undefined, plugin?: Pl
return orig
}

// Do not skip ts-node registration if the plugin is linked
if (settings.tsnodeEnabled === undefined && isProduction && plugin?.type !== 'link') {
debug(`Skipping ts-node registration for ${root} because NODE_ENV is NOT "test" or "development"`)
return orig
}

if (cannotUseTsNode(root, plugin, isProduction)) {
debug(`Skipping ts-node registration for ${root} because ts-node is run in node version ${process.version}"`)
memoizedWarn(
Expand Down
13 changes: 12 additions & 1 deletion src/performance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,15 @@ export class Performance {
if (!Performance.enabled) return

const oclifDebug = require('debug')('oclif-perf')
oclifDebug('Total Time: %sms', Performance.oclifPerf['oclif.runMs'].toFixed(4))
const processUpTime = (process.uptime() * 1000).toFixed(4)
oclifDebug('Process Uptime: %sms', processUpTime)
oclifDebug('Oclif Time: %sms', Performance.oclifPerf['oclif.runMs'].toFixed(4))
oclifDebug('Init Time: %sms', Performance.oclifPerf['oclif.initMs'].toFixed(4))
oclifDebug('Config Load Time: %sms', Performance.oclifPerf['oclif.configLoadMs'].toFixed(4))
oclifDebug(
' • Root Plugin Load Time: %sms',
Performance.getResult(OCLIF_MARKER_OWNER, 'plugin.load#root')?.duration.toFixed(4) ?? 0,
)
oclifDebug(
' • Plugins Load Time: %sms',
Performance.getResult(OCLIF_MARKER_OWNER, 'config.loadAllPlugins')?.duration.toFixed(4) ?? 0,
Expand Down Expand Up @@ -227,6 +233,11 @@ export class Performance {

oclifDebug('Command Load Time: %sms', Performance.oclifPerf['oclif.commandLoadMs'].toFixed(4))
oclifDebug('Command Run Time: %sms', Performance.oclifPerf['oclif.commandRunMs'].toFixed(4))
if (Performance.oclifPerf['oclif.configLoadMs'] > Performance.oclifPerf['oclif.runMs']) {
oclifDebug(
'! Config load time is greater than total oclif time. This might mean that Config was instantiated before oclif was run.',
)
}

const nonCoreDebug = require('debug')('non-oclif-perf')

Expand Down
2 changes: 1 addition & 1 deletion test/perf/parser.perf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ suite
.add('multiple async flags that take time', {
defer: true,
fn(deferred: {resolve: () => any}) {
parse(['--flagA', 'foo', '--flagA', 'bar'], {
parse(['--flagA', 'foo', '--flagB', 'bar'], {
flags: {
flagA: Flags.string({
async parse(input) {
Expand Down

0 comments on commit 204de58

Please sign in to comment.