Merge pull request #124803 from nrayburn-tech/npm-activation

npm extension - check for root package.json before findFiles
This commit is contained in:
Megan Rogge 2024-01-22 15:04:27 -08:00 committed by GitHub
commit ba5f685b65
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -363,12 +363,16 @@ export function getPackageJsonUriFromTask(task: Task): Uri | null {
}
export async function hasPackageJson(): Promise<boolean> {
// Faster than `findFiles` for workspaces with a root package.json.
if (await hasRootPackageJson()) {
return true;
}
const token = new CancellationTokenSource();
// Search for files for max 1 second.
const timeout = setTimeout(() => token.cancel(), 1000);
const files = await workspace.findFiles('**/package.json', undefined, 1, token.token);
clearTimeout(timeout);
return files.length > 0 || await hasRootPackageJson();
return files.length > 0;
}
async function hasRootPackageJson(): Promise<boolean> {