Comparing version 8.3.0 to 8.4.0
@@ -100,13 +100,11 @@ 'use strict' | ||
} | ||
createConfigGypi({ gyp, buildDir, nodeDir, vsInfo }, (err, configPath) => { | ||
createConfigGypi({ gyp, buildDir, nodeDir, vsInfo }).then(configPath => { | ||
configs.push(configPath) | ||
findConfigs(err) | ||
findConfigs() | ||
}).catch(err => { | ||
callback(err) | ||
}) | ||
} | ||
function findConfigs (err) { | ||
if (err) { | ||
return callback(err) | ||
} | ||
function findConfigs () { | ||
var name = configNames.shift() | ||
@@ -113,0 +111,0 @@ if (!name) { |
@@ -7,4 +7,34 @@ 'use strict' | ||
function getBaseConfigGypi () { | ||
const config = JSON.parse(JSON.stringify(process.config)) | ||
function parseConfigGypi (config) { | ||
// translated from tools/js2c.py of Node.js | ||
// 1. string comments | ||
config = config.replace(/#.*/g, '') | ||
// 2. join multiline strings | ||
config = config.replace(/'$\s+'/mg, '') | ||
// 3. normalize string literals from ' into " | ||
config = config.replace(/'/g, '"') | ||
return JSON.parse(config) | ||
} | ||
async function getBaseConfigGypi ({ gyp, nodeDir }) { | ||
// try reading $nodeDir/include/node/config.gypi first when: | ||
// 1. --dist-url or --nodedir is specified | ||
// 2. and --force-process-config is not specified | ||
const shouldReadConfigGypi = (gyp.opts.nodedir || gyp.opts['dist-url']) && !gyp.opts['force-process-config'] | ||
if (shouldReadConfigGypi && nodeDir) { | ||
try { | ||
const baseConfigGypiPath = path.resolve(nodeDir, 'include/node/config.gypi') | ||
const baseConfigGypi = await fs.promises.readFile(baseConfigGypiPath) | ||
return parseConfigGypi(baseConfigGypi.toString()) | ||
} catch (err) { | ||
log.warn('read config.gypi', err.message) | ||
} | ||
} | ||
// fallback to process.config if it is invalid | ||
return JSON.parse(JSON.stringify(process.config)) | ||
} | ||
async function getCurrentConfigGypi ({ gyp, nodeDir, vsInfo }) { | ||
const config = await getBaseConfigGypi({ gyp, nodeDir }) | ||
if (!config.target_defaults) { | ||
@@ -16,7 +46,3 @@ config.target_defaults = {} | ||
} | ||
return config | ||
} | ||
function getCurrentConfigGypi ({ gyp, nodeDir, vsInfo }) { | ||
const config = getBaseConfigGypi() | ||
const defaults = config.target_defaults | ||
@@ -90,3 +116,3 @@ const variables = config.variables | ||
function createConfigGypi ({ gyp, buildDir, nodeDir, vsInfo }, callback) { | ||
async function createConfigGypi ({ gyp, buildDir, nodeDir, vsInfo }) { | ||
const configFilename = 'config.gypi' | ||
@@ -97,3 +123,3 @@ const configPath = path.resolve(buildDir, configFilename) | ||
const config = getCurrentConfigGypi({ gyp, nodeDir, vsInfo }) | ||
const config = await getCurrentConfigGypi({ gyp, nodeDir, vsInfo }) | ||
@@ -115,5 +141,5 @@ // ensures that any boolean values in config.gypi get stringified | ||
log.verbose('build/' + configFilename, 'writing out config file: %s', configPath) | ||
fs.writeFile(configPath, [prefix, json, ''].join('\n'), (err) => { | ||
callback(err, configPath) | ||
}) | ||
await fs.promises.writeFile(configPath, [prefix, json, ''].join('\n')) | ||
return configPath | ||
} | ||
@@ -123,3 +149,4 @@ | ||
module.exports.test = { | ||
parseConfigGypi: parseConfigGypi, | ||
getCurrentConfigGypi: getCurrentConfigGypi | ||
} |
@@ -5,2 +5,3 @@ 'use strict' | ||
const execFile = require('child_process').execFile | ||
const fs = require('fs') | ||
const path = require('path').win32 | ||
@@ -261,2 +262,6 @@ const logWithPrefix = require('./util').logWithPrefix | ||
} | ||
if (ret.versionMajor === 17) { | ||
ret.versionYear = 2022 | ||
return ret | ||
} | ||
this.log.silly('- unsupported version:', ret.versionMajor) | ||
@@ -269,2 +274,3 @@ return {} | ||
const pkg = 'Microsoft.VisualStudio.VC.MSBuild.Base' | ||
const msbuildPath = path.join(info.path, 'MSBuild', 'Current', 'Bin', 'MSBuild.exe') | ||
if (info.packages.indexOf(pkg) !== -1) { | ||
@@ -276,5 +282,9 @@ this.log.silly('- found VC.MSBuild.Base') | ||
if (versionYear === 2019) { | ||
return path.join(info.path, 'MSBuild', 'Current', 'Bin', 'MSBuild.exe') | ||
return msbuildPath | ||
} | ||
} | ||
// visual studio 2022 don't has msbuild pkg | ||
if (fs.existsSync(msbuildPath)) { | ||
return msbuildPath | ||
} | ||
return null | ||
@@ -300,2 +310,4 @@ }, | ||
return 'v142' | ||
} else if (versionYear === 2022) { | ||
return 'v143' | ||
} | ||
@@ -302,0 +314,0 @@ this.log.silly('- invalid versionYear:', versionYear) |
@@ -78,3 +78,4 @@ 'use strict' | ||
jobs: String, // 'build' | ||
thin: String // 'configure' | ||
thin: String, // 'configure' | ||
'force-process-config': Boolean // 'configure' | ||
} | ||
@@ -81,0 +82,0 @@ |
@@ -14,3 +14,3 @@ { | ||
], | ||
"version": "8.3.0", | ||
"version": "8.4.0", | ||
"installVersion": 9, | ||
@@ -17,0 +17,0 @@ "author": "Nathan Rajlich <nathan@tootallnate.net> (http://tootallnate.net)", |
@@ -88,2 +88,18 @@ # `node-gyp` - Node.js native addon build tool | ||
### Build for Third Party Node.js Runtimes | ||
When building modules for thid party Node.js runtimes like Electron, which have | ||
different build configurations from the official Node.js distribution, you | ||
should use `--dist-url` or `--nodedir` flags to specify the headers of the | ||
runtime to build for. | ||
Also when `--dist-url` or `--nodedir` flags are passed, node-gyp will use the | ||
`config.gypi` shipped in the headers distribution to generate build | ||
configurations, which is different from the default mode that would use the | ||
`process.config` object of the running Node.js instance. | ||
Some old versions of Electron shipped malformed `config.gypi` in their headers | ||
distributions, and you might need to pass `--force-process-config` to node-gyp | ||
to work around configuration errors. | ||
## How to Use | ||
@@ -202,2 +218,3 @@ | ||
| `--solution=$solution` | Set Visual Studio Solution version (Windows only) | ||
| `--force-process-config` | Force using runtime's `process.config` object to generate `config.gypi` file | ||
@@ -204,0 +221,0 @@ ## Configuration |
@@ -14,3 +14,6 @@ 'use strict' | ||
stat: function (file, cb) { cb(null, {}) }, | ||
mkdir: function (dir, options, cb) { cb() } | ||
mkdir: function (dir, options, cb) { cb() }, | ||
promises: { | ||
writeFile: function (file, data) { return Promise.resolve(null) } | ||
} | ||
} | ||
@@ -17,0 +20,0 @@ }) |
'use strict' | ||
const path = require('path') | ||
const { test } = require('tap') | ||
const gyp = require('../lib/node-gyp') | ||
const createConfigGypi = require('../lib/create-config-gypi') | ||
const { getCurrentConfigGypi } = createConfigGypi.test | ||
const { parseConfigGypi, getCurrentConfigGypi } = createConfigGypi.test | ||
test('config.gypi with no options', function (t) { | ||
test('config.gypi with no options', async function (t) { | ||
t.plan(2) | ||
@@ -14,3 +15,3 @@ | ||
const config = getCurrentConfigGypi({ gyp: prog, vsInfo: {} }) | ||
const config = await getCurrentConfigGypi({ gyp: prog, vsInfo: {} }) | ||
t.equal(config.target_defaults.default_configuration, 'Release') | ||
@@ -20,3 +21,3 @@ t.equal(config.variables.target_arch, process.arch) | ||
test('config.gypi with --debug', function (t) { | ||
test('config.gypi with --debug', async function (t) { | ||
t.plan(1) | ||
@@ -27,7 +28,7 @@ | ||
const config = getCurrentConfigGypi({ gyp: prog, vsInfo: {} }) | ||
const config = await getCurrentConfigGypi({ gyp: prog, vsInfo: {} }) | ||
t.equal(config.target_defaults.default_configuration, 'Debug') | ||
}) | ||
test('config.gypi with custom options', function (t) { | ||
test('config.gypi with custom options', async function (t) { | ||
t.plan(1) | ||
@@ -38,4 +39,36 @@ | ||
const config = getCurrentConfigGypi({ gyp: prog, vsInfo: {} }) | ||
const config = await getCurrentConfigGypi({ gyp: prog, vsInfo: {} }) | ||
t.equal(config.variables.shared_libxml2, true) | ||
}) | ||
test('config.gypi with nodedir', async function (t) { | ||
t.plan(1) | ||
const nodeDir = path.join(__dirname, 'fixtures', 'nodedir') | ||
const prog = gyp() | ||
prog.parseArgv(['_', '_', `--nodedir=${nodeDir}`]) | ||
const config = await getCurrentConfigGypi({ gyp: prog, nodeDir, vsInfo: {} }) | ||
t.equal(config.variables.build_with_electron, true) | ||
}) | ||
test('config.gypi with --force-process-config', async function (t) { | ||
t.plan(1) | ||
const nodeDir = path.join(__dirname, 'fixtures', 'nodedir') | ||
const prog = gyp() | ||
prog.parseArgv(['_', '_', '--force-process-config', `--nodedir=${nodeDir}`]) | ||
const config = await getCurrentConfigGypi({ gyp: prog, nodeDir, vsInfo: {} }) | ||
t.equal(config.variables.build_with_electron, undefined) | ||
}) | ||
test('config.gypi parsing', function (t) { | ||
t.plan(1) | ||
const str = "# Some comments\n{'variables': {'multiline': 'A'\n'B'}}" | ||
const config = parseConfigGypi(str) | ||
t.deepEqual(config, { variables: { multiline: 'AB' } }) | ||
}) |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1977378
137
4148
257
63