-
Notifications
You must be signed in to change notification settings - Fork 353
Expand file tree
/
Copy pathnodeSearchStrategy.ts
More file actions
96 lines (87 loc) · 2.94 KB
/
nodeSearchStrategy.ts
File metadata and controls
96 lines (87 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/
import globStream from 'glob-stream';
import { inject, injectable } from 'inversify';
import { PathMapping } from '../../configuration';
import { FileGlobList } from '../fileGlobList';
import { ILogger, LogTag } from '../logging';
import { fixDriveLetterAndSlashes, forceForwardSlashes } from '../pathUtils';
import { ISourceMapMetadata } from './sourceMap';
import { createMetadataForFile, ISearchStrategy } from './sourceMapRepository';
/**
* A source map repository that uses globbing to find candidate files.
*/
@injectable()
export class NodeSearchStrategy implements ISearchStrategy {
constructor(@inject(ILogger) private readonly logger: ILogger) {}
/**
* @inheritdoc
*/
public async streamAllChildren<T>(
files: FileGlobList,
onChild: (child: string) => T | Promise<T>,
): Promise<T[]> {
const todo: (T | Promise<T>)[] = [];
await new Promise((resolve, reject) =>
this.globForFiles(files)
.on('data', (value: globStream.Entry) =>
todo.push(onChild(fixDriveLetterAndSlashes(value.path))),
)
.on('finish', resolve)
.on('error', reject),
);
return (await Promise.all(todo)).filter((t): t is T => t !== undefined);
}
/**
* @inheritdoc
*/
public async streamChildrenWithPathMaps<T>(
_pathMapping: PathMapping,
_onChild: (child: Required<ISourceMapMetadata>) => T | Promise<T>,
): Promise<T[]> {
return Promise.resolve([]);
}
/**
* @inheritdoc
*/
public async streamChildrenWithSourcemaps<T>(
files: FileGlobList,
onChild: (child: Required<ISourceMapMetadata>) => T | Promise<T>,
): Promise<T[]> {
const todo: (T | Promise<T | void>)[] = [];
await new Promise((resolve, reject) =>
this.globForFiles(files)
.on('data', (value: globStream.Entry) =>
todo.push(
createMetadataForFile(fixDriveLetterAndSlashes(value.path))
.then(parsed => parsed && onChild(parsed))
.catch(error =>
this.logger.warn(LogTag.SourceMapParsing, 'Error parsing source map', {
error,
file: value.path,
}),
),
),
)
.on('finish', resolve)
.on('error', reject),
);
return (await Promise.all(todo)).filter((t): t is T => t !== undefined);
}
private globForFiles(files: FileGlobList) {
return globStream(
[
...files.patterns.map(forceForwardSlashes),
// Avoid reading asar files: electron patches in support for them, but
// if we see an invalid one then it throws a synchronous error that
// breaks glob. We don't care about asar's here, so just skip that:
'!**/*.asar/**',
],
{
matchBase: true,
cwd: files.rootPath,
},
);
}
}