9
9
import * as path from 'path' ;
10
10
import * as os from 'os' ;
11
11
import * as fs from 'fs' ;
12
- import { PerformanceObserver , performance } from 'perf_hooks' ;
13
12
import { NamedPackageDir , Logger } from '@salesforce/core' ;
14
13
import * as git from 'isomorphic-git' ;
15
14
import { pathIsInFolder } from './functions' ;
16
- const obs = new PerformanceObserver ( ( items ) => {
17
- const item = items . getEntries ( ) [ 0 ] ;
18
- console . log ( `${ item . name } : ${ item . duration } ` ) ;
19
- performance . clearMarks ( item . name ) ;
20
- } ) ;
21
-
22
- obs . observe ( { type : 'measure' } ) ;
23
15
24
16
const cache = { } ;
25
17
const gitIgnoreFileName = '.gitignore' ;
@@ -74,14 +66,11 @@ export class ShadowRepo {
74
66
75
67
// think of singleton behavior but unique to the projectPath
76
68
public static async getInstance ( options : ShadowRepoOptions ) : Promise < ShadowRepo > {
77
- performance . mark ( 'start-instance' ) ;
78
69
if ( ! ShadowRepo . instanceMap . has ( options . projectPath ) ) {
79
70
const newInstance = new ShadowRepo ( options ) ;
80
71
await newInstance . init ( ) ;
81
72
ShadowRepo . instanceMap . set ( options . projectPath , newInstance ) ;
82
73
}
83
- performance . mark ( 'end-instance' ) ;
84
- performance . measure ( 'getInstance' , 'start-instance' , 'end-instance' ) ;
85
74
return ShadowRepo . instanceMap . get ( options . projectPath ) as ShadowRepo ;
86
75
}
87
76
@@ -128,7 +117,6 @@ export class ShadowRepo {
128
117
* @returns StatusRow[]
129
118
*/
130
119
public async getStatus ( noCache = false ) : Promise < StatusRow [ ] > {
131
- performance . mark ( 'start-status' ) ;
132
120
if ( ! this . status || noCache ) {
133
121
try {
134
122
// only ask about OS once but use twice
@@ -163,8 +151,6 @@ export class ShadowRepo {
163
151
await this . unStashIgnoreFile ( ) ;
164
152
}
165
153
}
166
- performance . mark ( 'end-status' ) ;
167
- performance . measure ( 'getStatus' , 'start-status' , 'end-status' ) ;
168
154
return this . status ;
169
155
}
170
156
@@ -251,20 +237,13 @@ export class ShadowRepo {
251
237
deletedFiles = deletedFiles . map ( ( filepath ) => path . normalize ( filepath ) . split ( path . sep ) . join ( path . posix . sep ) ) ;
252
238
}
253
239
try {
254
- performance . mark ( 'start-add' ) ;
255
- // for (const filepath of [...new Set(deployedFiles)]) {
256
- // performance.mark(`item-add-${filepath}`);
257
- await git . add ( { fs, dir : this . projectPath , gitdir : this . gitDir , filepath : [ ...new Set ( deployedFiles ) ] , cache } ) ;
258
- // performance.mark(`item-end-${filepath}`);
259
- // performance.measure(`add-${filepath}`, `item-add-${filepath}`, `item-end-${filepath}`);
260
- // }
261
- performance . mark ( 'end-add' ) ;
262
- performance . measure ( 'git add' , 'start-add' , 'end-add' ) ;
240
+ if ( deployedFiles . length ) {
241
+ await git . add ( { fs, dir : this . projectPath , gitdir : this . gitDir , filepath : [ ...new Set ( deployedFiles ) ] , cache } ) ;
242
+ }
263
243
264
244
for ( const filepath of [ ...new Set ( deletedFiles ) ] ) {
265
245
await git . remove ( { fs, dir : this . projectPath , gitdir : this . gitDir , filepath, cache } ) ;
266
246
}
267
- performance . mark ( 'start-commit' ) ;
268
247
269
248
const sha = await git . commit ( {
270
249
fs,
@@ -274,8 +253,6 @@ export class ShadowRepo {
274
253
author : { name : 'sfdx source tracking' } ,
275
254
cache,
276
255
} ) ;
277
- performance . mark ( 'end-commit' ) ;
278
- performance . measure ( 'git commit' , 'start-commit' , 'end-commit' ) ;
279
256
// status changed as a result of the commit. This prevents users from having to run getStatus(true) to avoid cache
280
257
if ( needsUpdatedStatus ) {
281
258
await this . getStatus ( true ) ;
@@ -320,6 +297,4 @@ export class ShadowRepo {
320
297
)
321
298
) ;
322
299
}
323
-
324
- // private async addMultipleFiles(files: string[]): Promise<void> {}
325
300
}
0 commit comments