Skip to content

Commit ead41ef

Browse files
Use IFileSystem.search() instead of glob().
1 parent 0b1554d commit ead41ef

File tree

3 files changed

+23
-27
lines changed

3 files changed

+23
-27
lines changed

src/client/common/platform/fileSystem.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ import * as glob from 'glob';
99
import { inject, injectable } from 'inversify';
1010
import * as path from 'path';
1111
import * as tmp from 'tmp';
12+
import { promisify } from 'util';
1213
import { FileStat } from 'vscode';
1314
import { createDeferred } from '../utils/async';
1415
import { noop } from '../utils/misc';
1516
import { IFileSystem, IPlatformService, TemporaryFile } from './types';
1617

18+
const globAsync = promisify(glob);
19+
1720
@injectable()
1821
export class FileSystem implements IFileSystem {
1922
constructor(@inject(IPlatformService) private platformService: IPlatformService) {}
@@ -173,15 +176,17 @@ export class FileSystem implements IFileSystem {
173176
});
174177
});
175178
}
176-
public search(globPattern: string): Promise<string[]> {
177-
return new Promise<string[]>((resolve, reject) => {
178-
glob(globPattern, (ex, files) => {
179-
if (ex) {
180-
return reject(ex);
181-
}
182-
resolve(Array.isArray(files) ? files : []);
183-
});
184-
});
179+
public async search(globPattern: string, cwd?: string): Promise<string[]> {
180+
let found: string[];
181+
if (cwd) {
182+
const options = {
183+
cwd: cwd
184+
};
185+
found = await globAsync(globPattern, options);
186+
} else {
187+
found = await globAsync(globPattern);
188+
}
189+
return Array.isArray(found) ? found : [];
185190
}
186191
public createTemporaryFile(extension: string): Promise<TemporaryFile> {
187192
return new Promise<TemporaryFile>((resolve, reject) => {

src/client/common/platform/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export interface IFileSystem {
6262
copyFile(src: string, dest: string): Promise<void>;
6363
deleteFile(filename: string): Promise<void>;
6464
getFileHash(filePath: string): Promise<string>;
65-
search(globPattern: string): Promise<string[]>;
65+
search(globPattern: string, cwd?: string): Promise<string[]>;
6666
createTemporaryFile(extension: string): Promise<TemporaryFile>;
6767
createReadStream(path: string): fs.ReadStream;
6868
createWriteStream(path: string): fs.WriteStream;

src/client/datascience/themeFinder.ts

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33
'use strict';
4-
import * as glob from 'glob';
54
import { inject, injectable } from 'inversify';
65
import * as path from 'path';
76

@@ -107,14 +106,10 @@ export class ThemeFinder implements IThemeFinder {
107106

108107
// Search through all package.json files in the directory and below, looking
109108
// for the themeName in them.
110-
const foundPackages = await new Promise<string[]>((resolve, reject) => {
111-
glob('**/package.json', { cwd: rootPath }, (err, matches) => {
112-
if (err) {
113-
reject(err);
114-
}
115-
resolve(matches);
116-
});
117-
});
109+
const fs = new FileSystem(
110+
new PlatformService()
111+
);
112+
const foundPackages = await fs.search('**/package.json', rootPath);
118113
if (foundPackages.length > 0) {
119114
// For each one, open it up and look for the theme name.
120115
for (const f of foundPackages) {
@@ -167,14 +162,10 @@ export class ThemeFinder implements IThemeFinder {
167162
private async findMatchingThemes(rootPath: string, themeName: string) : Promise<IThemeData | undefined> {
168163
// Search through all package.json files in the directory and below, looking
169164
// for the themeName in them.
170-
const foundPackages = await new Promise<string []>((resolve, reject) => {
171-
glob('**/package.json', { cwd: rootPath }, (err, matches) => {
172-
if (err) {
173-
reject(err);
174-
}
175-
resolve(matches);
176-
});
177-
});
165+
const fs = new FileSystem(
166+
new PlatformService()
167+
);
168+
const foundPackages = await fs.search('**/package.json', rootPath);
178169
if (foundPackages.length > 0) {
179170
// For each one, open it up and look for the theme name.
180171
for (const f of foundPackages) {

0 commit comments

Comments
 (0)