Skip to content

Commit

Permalink
Improve package.json file check
Browse files Browse the repository at this point in the history
  • Loading branch information
alexr00 committed Apr 22, 2021
1 parent 690c76c commit f38f90d
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion extensions/npm/src/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down

0 comments on commit f38f90d

Please sign in to comment.