From b45796f9a3ef4d34cc21e792c94c3b7ea28629ac Mon Sep 17 00:00:00 2001 From: Mestery Date: Sun, 7 Mar 2021 18:33:59 +0100 Subject: [PATCH] support yarn pnp for nodeAddonIncludes This solves problems with Yarn PnP and node addon includes. --- .../src/LanguageServer/configurations.ts | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/Extension/src/LanguageServer/configurations.ts b/Extension/src/LanguageServer/configurations.ts index 213f739f57..3f4e481864 100644 --- a/Extension/src/LanguageServer/configurations.ts +++ b/Extension/src/LanguageServer/configurations.ts @@ -406,15 +406,23 @@ export class CppProperties { if (!error) { try { const pathToNode: string = which.sync("node"); - const nodeAddonMap: { [dependency: string]: string } = { - "nan": `"${pathToNode}" --no-warnings -e "require('nan')"`, - "node-addon-api": `"${pathToNode}" --no-warnings -p "require('node-addon-api').include"` - }; + const nodeAddonMap: [string, string][] = [ + ["node-addon-api", `"${pathToNode}" --no-warnings -p "require('node-addon-api').include"`], + ["nan", `"${pathToNode}" --no-warnings -e "require('nan')"`] + ]; + // Yarn (2) PnP support + const pathToYarn: string | null = which.sync("yarn", { nothrow: true }); + if (pathToYarn && await util.checkDirectoryExists(path.join(rootPath, ".yarn/cache"))) { + nodeAddonMap.push( + ["node-addon-api", `"${pathToYarn}" node --no-warnings -p "require('node-addon-api').include"`], + ["nan", `"${pathToYarn}" node --no-warnings -e "require('nan')"`] + ); + } - for (const dep in nodeAddonMap) { + for (const [dep, execCmd] of nodeAddonMap) { if (dep in package_json.dependencies) { - const execCmd: string = nodeAddonMap[dep]; - let stdout: string = await util.execChildProcess(execCmd, rootPath); + let stdout: string | void = await util.execChildProcess(execCmd, rootPath) + .catch((error) => console.log('readNodeAddonIncludeLocations', error.message)); if (!stdout) { continue; }