Skip to content

Commit

Permalink
support yarn pnp for nodeAddonIncludes
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 committed Mar 7, 2021
1 parent d2cb685 commit ea8e9a6
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 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 Expand Up @@ -700,6 +708,7 @@ export class CppProperties {
const origIncludePath: string[] | undefined = configuration.includePath;
if (settings.addNodeAddonIncludePaths) {
const includePath: string[] = origIncludePath || [];
console.log(this.nodeAddonIncludes);
configuration.includePath = includePath.concat(this.nodeAddonIncludes.filter(i => includePath.indexOf(i) < 0));
}
configuration.defines = this.updateConfigurationStringArray(configuration.defines, settings.defaultDefines, env);
Expand Down

0 comments on commit ea8e9a6

Please sign in to comment.