Improve package.json file check

Fixes #120279
This commit is contained in:
Alex Ross 2021-04-22 17:34:39 +02:00
parent 690c76c105
commit f38f90dfe1
No known key found for this signature in database
GPG key ID: 89DDDBA66CBA7840

View file

@ -370,7 +370,23 @@ export async function hasPackageJson(): Promise<boolean> {
const timeout = setTimeout(() => token.cancel(), 1000);
const files = await workspace.findFiles('**/package.json', undefined, 1, token.token);
clearTimeout(timeout);
return files.length > 0;
return files.length > 0 || await hasRootPackageJson();
}
async function hasRootPackageJson(): Promise<boolean> {
let folders = workspace.workspaceFolders;
if (!folders) {
return false;
}
for (const folder of folders) {
if (folder.uri.scheme === 'file') {
let packageJson = path.join(folder.uri.fsPath, 'package.json');
if (await exists(packageJson)) {
return true;
}
}
}
return false;
}
async function exists(file: string): Promise<boolean> {