From f8cdcf615f1d1b98bf4043c196c695f845cab23c Mon Sep 17 00:00:00 2001 From: Tyler Wanek Date: Thu, 7 Feb 2019 12:24:44 -0700 Subject: [PATCH] Handle new gyp information for electron builds --- generate/templates/templates/binding.gyp | 18 ++++--------- package-lock.json | 25 +++++++++++++++--- package.json | 1 + utils/isBuildingForElectron.js | 32 ++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 17 deletions(-) create mode 100644 utils/isBuildingForElectron.js diff --git a/generate/templates/templates/binding.gyp b/generate/templates/templates/binding.gyp index e6f1141cb..c15a7ec55 100644 --- a/generate/templates/templates/binding.gyp +++ b/generate/templates/templates/binding.gyp @@ -1,21 +1,13 @@ { - "conditions": [ - ["(OS=='win' and node_root_dir.split('\\\\')[-1].startswith('iojs')) or (OS=='mac' and node_root_dir.split('/')[-1].startswith('iojs'))", { - "variables": { - "is_electron%": "1", - } - }, { - "variables": { - "is_electron%": "0", - } - }] - ], + "variables": { + "is_electron%": " arr[arr.length - 1]; +const sep = process.platform === "win32" ? "\\\\" : "/"; +const [, , nodeRootDir] = process.argv; + +let isElectron = last(nodeRootDir.split(sep)).startsWith("iojs"); + +if (!isElectron) { + try { + // Not ideal, would love it if there were a full featured gyp package to do this operation instead. + const { variables: { built_with_electron } } = JSON5.parse( + fs.readFileSync( + path.resolve(nodeRootDir, "include", "node", "config.gypi"), + "utf8" + ) + ); + + if (built_with_electron) { + isElectron = true; + } + } catch (e) {} +} + +fs.writeFileSync("was_electron", isElectron ? "1" : "0"); +process.stdout.write(isElectron ? "1" : "0");