From fac7c66ec63d91fbab845c136c1bd154b58dab0a Mon Sep 17 00:00:00 2001 From: Gus Caplan Date: Sun, 4 Mar 2018 18:25:02 -0600 Subject: [PATCH] tools,bootstrap: preprocess gypi files to json PR-URL: https://github.com/nodejs/node/pull/19140 Reviewed-By: Anna Henningsen Reviewed-By: Joyee Cheung --- lib/internal/process.js | 9 +-------- tools/js2c.py | 5 +++++ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/internal/process.js b/lib/internal/process.js index ba61928adcd6b5..d64fe9877198b8 100644 --- a/lib/internal/process.js +++ b/lib/internal/process.js @@ -128,16 +128,9 @@ function setupMemoryUsage() { function setupConfig(_source) { // NativeModule._source // used for `process.config`, but not a real module - var config = _source.config; + const config = _source.config; delete _source.config; - // strip the gyp comment line at the beginning - config = config.split('\n') - .slice(1) - .join('\n') - .replace(/"/g, '\\"') - .replace(/'/g, '"'); - process.config = JSON.parse(config, function(key, value) { if (value === 'true') return true; if (value === 'false') return false; diff --git a/tools/js2c.py b/tools/js2c.py index 213a9fefdcafca..bcfc4764a97df5 100755 --- a/tools/js2c.py +++ b/tools/js2c.py @@ -292,6 +292,11 @@ def JS2C(source, target): split = split[1:] name = '/'.join(split) + # if its a gypi file we're going to want it as json + # later on anyway, so get it out of the way now + if name.endswith(".gypi"): + lines = re.sub(r'#.*?\n', '', lines) + lines = re.sub(r'\'', '"', lines) name = name.split('.', 1)[0] var = name.replace('-', '_').replace('/', '_') key = '%s_key' % var