@@ -19,6 +19,8 @@ import { IWatcherRequest, IWatcherService, IWatcherOptions } from 'vs/platform/f
1919import { Emitter , Event } from 'vs/base/common/event' ;
2020import { equals } from 'vs/base/common/arrays' ;
2121
22+ process . noAsar = true ; // disable ASAR support in watcher process
23+
2224interface IWatcher {
2325 requests : ExtendedWatcherRequest [ ] ;
2426 stop ( ) : any ;
@@ -50,43 +52,46 @@ export class ChokidarWatcherService implements IWatcherService {
5052 private readonly _onLogMessage = new Emitter < ILogMessage > ( ) ;
5153 readonly onLogMessage : Event < ILogMessage > = this . _onLogMessage . event ;
5254
53- public watch ( options : IWatcherOptions ) : Event < IDiskFileChange [ ] > {
55+ watch ( options : IWatcherOptions ) : Event < IDiskFileChange [ ] > {
5456 this . _pollingInterval = options . pollingInterval ;
5557 this . _usePolling = options . usePolling ;
5658 this . _watchers = Object . create ( null ) ;
5759 this . _watcherCount = 0 ;
60+
5861 return this . onWatchEvent ;
5962 }
6063
61- public setVerboseLogging ( enabled : boolean ) : Promise < void > {
64+ setVerboseLogging ( enabled : boolean ) : Promise < void > {
6265 this . _verboseLogging = enabled ;
6366
6467 return Promise . resolve ( ) ;
6568 }
6669
67- public setRoots ( requests : IWatcherRequest [ ] ) : Promise < void > {
70+ setRoots ( requests : IWatcherRequest [ ] ) : Promise < void > {
6871 const watchers = Object . create ( null ) ;
6972 const newRequests : string [ ] = [ ] ;
7073
7174 const requestsByBasePath = normalizeRoots ( requests ) ;
7275
7376 // evaluate new & remaining watchers
74- for ( let basePath in requestsByBasePath ) {
75- let watcher = this . _watchers [ basePath ] ;
77+ for ( const basePath in requestsByBasePath ) {
78+ const watcher = this . _watchers [ basePath ] ;
7679 if ( watcher && isEqualRequests ( watcher . requests , requestsByBasePath [ basePath ] ) ) {
7780 watchers [ basePath ] = watcher ;
7881 delete this . _watchers [ basePath ] ;
7982 } else {
8083 newRequests . push ( basePath ) ;
8184 }
8285 }
86+
8387 // stop all old watchers
84- for ( let path in this . _watchers ) {
88+ for ( const path in this . _watchers ) {
8589 this . _watchers [ path ] . stop ( ) ;
8690 }
91+
8792 // start all new watchers
88- for ( let basePath of newRequests ) {
89- let requests = requestsByBasePath [ basePath ] ;
93+ for ( const basePath of newRequests ) {
94+ const requests = requestsByBasePath [ basePath ] ;
9095 watchers [ basePath ] = this . _watch ( basePath , requests ) ;
9196 }
9297
@@ -95,7 +100,7 @@ export class ChokidarWatcherService implements IWatcherService {
95100 }
96101
97102 // for test purposes
98- public get wacherCount ( ) {
103+ get wacherCount ( ) {
99104 return this . _watcherCount ;
100105 }
101106
@@ -121,9 +126,10 @@ export class ChokidarWatcherService implements IWatcherService {
121126 } ;
122127
123128 const excludes : string [ ] = [ ] ;
124- // if there's only one request, use the built-in ignore-filterering
129+
125130 const isSingleFolder = requests . length === 1 ;
126131 if ( isSingleFolder ) {
132+ // if there's only one request, use the built-in ignore-filterering
127133 excludes . push ( ...requests [ 0 ] . excludes ) ;
128134 }
129135
@@ -133,6 +139,9 @@ export class ChokidarWatcherService implements IWatcherService {
133139 excludes . push ( '/proc/**' , '/sys/**' ) ;
134140 }
135141 }
142+
143+ excludes . push ( '**/*.asar' ) ; // Ensure we never recurse into ASAR archives
144+
136145 watcherOpts . ignored = excludes ;
137146
138147 // Chokidar fails when the basePath does not match case-identical to the path on disk
@@ -220,7 +229,7 @@ export class ChokidarWatcherService implements IWatcherService {
220229 }
221230 }
222231
223- let event = { type : eventType , path } ;
232+ const event = { type : eventType , path } ;
224233
225234 // Logging
226235 if ( this . _verboseLogging ) {
@@ -284,12 +293,14 @@ export class ChokidarWatcherService implements IWatcherService {
284293 return watcher ;
285294 }
286295
287- public stop ( ) : Promise < void > {
288- for ( let path in this . _watchers ) {
289- let watcher = this . _watchers [ path ] ;
296+ stop ( ) : Promise < void > {
297+ for ( const path in this . _watchers ) {
298+ const watcher = this . _watchers [ path ] ;
290299 watcher . stop ( ) ;
291300 }
301+
292302 this . _watchers = Object . create ( null ) ;
303+
293304 return Promise . resolve ( ) ;
294305 }
295306
@@ -307,25 +318,28 @@ export class ChokidarWatcherService implements IWatcherService {
307318}
308319
309320function isIgnored ( path : string , requests : ExtendedWatcherRequest [ ] ) : boolean {
310- for ( let request of requests ) {
321+ for ( const request of requests ) {
311322 if ( request . path === path ) {
312323 return false ;
313324 }
325+
314326 if ( extpath . isEqualOrParent ( path , request . path ) ) {
315327 if ( ! request . parsedPattern ) {
316328 if ( request . excludes && request . excludes . length > 0 ) {
317- let pattern = `{${ request . excludes . join ( ',' ) } }` ;
329+ const pattern = `{${ request . excludes . join ( ',' ) } }` ;
318330 request . parsedPattern = glob . parse ( pattern ) ;
319331 } else {
320332 request . parsedPattern = ( ) => false ;
321333 }
322334 }
335+
323336 const relPath = path . substr ( request . path . length + 1 ) ;
324337 if ( ! request . parsedPattern ( relPath ) ) {
325338 return false ;
326339 }
327340 }
328341 }
342+
329343 return true ;
330344}
331345
@@ -335,11 +349,12 @@ function isIgnored(path: string, requests: ExtendedWatcherRequest[]): boolean {
335349 */
336350export function normalizeRoots ( requests : IWatcherRequest [ ] ) : { [ basePath : string ] : IWatcherRequest [ ] } {
337351 requests = requests . sort ( ( r1 , r2 ) => r1 . path . localeCompare ( r2 . path ) ) ;
352+
338353 let prevRequest : IWatcherRequest | null = null ;
339- let result : { [ basePath : string ] : IWatcherRequest [ ] } = Object . create ( null ) ;
340- for ( let request of requests ) {
341- let basePath = request . path ;
342- let ignored = ( request . excludes || [ ] ) . sort ( ) ;
354+ const result : { [ basePath : string ] : IWatcherRequest [ ] } = Object . create ( null ) ;
355+ for ( const request of requests ) {
356+ const basePath = request . path ;
357+ const ignored = ( request . excludes || [ ] ) . sort ( ) ;
343358 if ( prevRequest && ( extpath . isEqualOrParent ( basePath , prevRequest . path ) ) ) {
344359 if ( ! isEqualIgnore ( ignored , prevRequest . excludes ) ) {
345360 result [ prevRequest . path ] . push ( { path : basePath , excludes : ignored } ) ;
@@ -349,6 +364,7 @@ export function normalizeRoots(requests: IWatcherRequest[]): { [basePath: string
349364 result [ basePath ] = [ prevRequest ] ;
350365 }
351366 }
367+
352368 return result ;
353369}
354370
0 commit comments