File tree Expand file tree Collapse file tree 4 files changed +67
-6
lines changed Expand file tree Collapse file tree 4 files changed +67
-6
lines changed Original file line number Diff line number Diff line change @@ -90,6 +90,10 @@ const ui5 = {
90
90
} ,
91
91
92
92
async invokeCLI ( pkg ) {
93
+ if ( process . env . UI5_CLI_PROFILE ) {
94
+ const profile = await import ( "../lib/utils/profile.js" ) ;
95
+ await profile . start ( ) ;
96
+ }
93
97
const { default : cli } = await import ( "../lib/cli/cli.js" ) ;
94
98
await cli ( pkg ) ;
95
99
} ,
@@ -101,7 +105,8 @@ const ui5 = {
101
105
} else {
102
106
const localInstallationInvoked = await ui5 . invokeLocalInstallation ( pkg ) ;
103
107
if ( ! localInstallationInvoked ) {
104
- await ui5 . invokeCLI ( pkg ) ;
108
+ const exitCode = await ui5 . invokeCLI ( pkg ) ;
109
+ process . exit ( exitCode ) ;
105
110
}
106
111
}
107
112
}
Original file line number Diff line number Diff line change @@ -135,7 +135,5 @@ export default function(cli) {
135
135
process . stderr . write ( chalk . dim ( `See 'ui5 --help'` ) ) ;
136
136
process . stderr . write ( "\n" ) ;
137
137
}
138
- process . exit ( 1 ) ;
139
138
} ) ;
140
139
}
141
-
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
+ await profile . stop ( ) ;
83
+ }
84
+ }
85
+
86
+ return exitCode ;
74
87
} ;
Original file line number Diff line number Diff line change
1
+ import { writeFile } from "node:fs/promises" ;
2
+ import { Session } from "node:inspector" ;
3
+
4
+ let session ;
5
+
6
+ export async function start ( ) {
7
+ if ( session ) {
8
+ return ;
9
+ }
10
+ session = new Session ( ) ;
11
+ session . connect ( ) ;
12
+ await new Promise ( ( resolve ) => {
13
+ session . post ( "Profiler.enable" , ( ) => {
14
+ session . post ( "Profiler.start" , ( ) => {
15
+ resolve ( ) ;
16
+ } ) ;
17
+ } ) ;
18
+ } ) ;
19
+ }
20
+
21
+ async function writeProfile ( profile ) {
22
+ const d = new Date ( ) ;
23
+ const timestamp =
24
+ `${ d . getFullYear ( ) } -${ d . getMonth ( ) + 1 } -${ d . getDate ( ) } _${ d . getHours ( ) } -${ d . getMinutes ( ) } -${ d . getSeconds ( ) } ` ;
25
+
26
+ await writeFile ( `./ui5_${ timestamp } .cpuprofile` , JSON . stringify ( profile ) ) ;
27
+ }
28
+
29
+ export async function stop ( ) {
30
+ if ( ! session ) {
31
+ return ;
32
+ }
33
+ const profile = await new Promise ( ( resolve ) => {
34
+ session . post ( "Profiler.stop" , ( err , { profile} ) => {
35
+ if ( err ) {
36
+ resolve ( null ) ;
37
+ } else {
38
+ resolve ( profile ) ;
39
+ }
40
+ } ) ;
41
+ } ) ;
42
+ if ( profile ) {
43
+ await writeProfile ( profile ) ;
44
+ }
45
+ }
You can’t perform that action at this time.
0 commit comments