Skip to content

Commit

Permalink
support yarn pnp for nodeAddonIncludes (#7123)
Browse files Browse the repository at this point in the history
This solves problems with Yarn PnP and node addon includes.
  • Loading branch information
Mesteery authored Mar 15, 2021
1 parent fb0b4d1 commit 8285897
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions Extension/src/LanguageServer/configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 8285897

Please sign in to comment.