File tree Expand file tree Collapse file tree 4 files changed +58
-6
lines changed Expand file tree Collapse file tree 4 files changed +58
-6
lines changed Original file line number Diff line number Diff line change @@ -77,6 +77,10 @@ const ui5 = {
77
77
} ,
78
78
79
79
async invokeCLI ( pkg ) {
80
+ if ( process . env . UI5_CLI_PROFILE ) {
81
+ const profile = await import ( "../lib/utils/profile.js" ) ;
82
+ await profile . start ( ) ;
83
+ }
80
84
const { default : cli } = await import ( "../lib/cli/cli.js" ) ;
81
85
await cli ( pkg ) ;
82
86
} ,
@@ -88,7 +92,8 @@ const ui5 = {
88
92
}
89
93
const localInstallationInvoked = await ui5 . invokeLocalInstallation ( pkg ) ;
90
94
if ( ! localInstallationInvoked ) {
91
- await ui5 . invokeCLI ( pkg ) ;
95
+ const exitCode = await ui5 . invokeCLI ( pkg ) ;
96
+ process . exit ( exitCode ) ;
92
97
}
93
98
}
94
99
} ;
Original file line number Diff line number Diff line change @@ -72,7 +72,5 @@ export default function(cli) {
72
72
console . log ( "" ) ;
73
73
console . log ( chalk . dim ( `See 'ui5 --help' or 'ui5 build --help' for help` ) ) ;
74
74
}
75
- process . exit ( 1 ) ;
76
75
} ) ;
77
76
}
78
-
Original file line number Diff line number Diff line change @@ -68,7 +68,20 @@ export default async (pkg) => {
68
68
// Format terminal output to full available width
69
69
cli . wrap ( cli . terminalWidth ( ) ) ;
70
70
71
- // yargs registers a get method on the argv property.
72
- // The property needs to be accessed to initialize everything.
73
- cli . argv ;
71
+ let exitCode = 0 ;
72
+ try {
73
+ // Call parse to run yargs
74
+ await cli . parse ( ) ;
75
+ } catch ( err ) {
76
+ // Error is already handled via .fail callback in ./base.js
77
+ exitCode = 1 ;
78
+ } finally {
79
+ // Stop profiling after CLI finished execution
80
+ if ( process . env . UI5_CLI_PROFILE ) {
81
+ const profile = await import ( "../utils/profile.js" ) ;
82
+ profile . stop ( ) ;
83
+ }
84
+ }
85
+
86
+ return exitCode ;
74
87
} ;
Original file line number Diff line number Diff line change
1
+ import fs from "node:fs" ;
2
+ import { Session } from "node:inspector" ;
3
+
4
+ let session ;
5
+
6
+ export function start ( ) {
7
+ return new Promise ( ( resolve ) => {
8
+ if ( session ) {
9
+ resolve ( ) ;
10
+ return ;
11
+ }
12
+ session = new Session ( ) ;
13
+ session . connect ( ) ;
14
+ session . post ( "Profiler.enable" , ( ) => {
15
+ session . post ( "Profiler.start" , ( ) => {
16
+ resolve ( ) ;
17
+ } ) ;
18
+ } ) ;
19
+ } ) ;
20
+ }
21
+
22
+ export function stop ( ) {
23
+ if ( ! session ) {
24
+ return ;
25
+ }
26
+ session . post ( "Profiler.stop" , ( err , { profile} ) => {
27
+ if ( err ) {
28
+ return ;
29
+ }
30
+ const d = new Date ( ) ;
31
+ const timestamp =
32
+ `${ d . getFullYear ( ) } -${ d . getMonth ( ) + 1 } -${ d . getDate ( ) } _${ d . getHours ( ) } -${ d . getMinutes ( ) } -${ d . getSeconds ( ) } ` ;
33
+
34
+ fs . writeFileSync ( `./ui5_${ timestamp } .cpuprofile` , JSON . stringify ( profile ) ) ;
35
+ } ) ;
36
+ }
You can’t perform that action at this time.
0 commit comments