@dry-software/cmake-js 7.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +402 -0
- package/bin/cmake-js +343 -0
- package/changelog.md +225 -0
- package/lib/appCMakeJSConfig.js +58 -0
- package/lib/buildSystem.js +123 -0
- package/lib/cMake.js +362 -0
- package/lib/cmLog.js +61 -0
- package/lib/cpp/win_delay_load_hook.cc +52 -0
- package/lib/dist.js +176 -0
- package/lib/downloader.js +92 -0
- package/lib/environment.js +97 -0
- package/lib/import/Find-VisualStudio.cs +250 -0
- package/lib/import/LICENSE +24 -0
- package/lib/import/README +6 -0
- package/lib/import/find-visualstudio.js +439 -0
- package/lib/import/util.js +70 -0
- package/lib/index.js +12 -0
- package/lib/locateNAN.js +63 -0
- package/lib/locateNodeApi.js +18 -0
- package/lib/npmConfig.js +31 -0
- package/lib/processHelpers.js +53 -0
- package/lib/runtimePaths.js +95 -0
- package/lib/targetOptions.js +33 -0
- package/lib/toolset.js +224 -0
- package/package.json +76 -0
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const log = require('npmlog')
|
|
4
|
+
const { existsSync } = require('fs')
|
|
5
|
+
const { win32: path } = require('path')
|
|
6
|
+
const { regSearchKeys, execFile, logWithPrefix } = require('./util')
|
|
7
|
+
const semver = require('semver')
|
|
8
|
+
|
|
9
|
+
class VisualStudioFinder {
|
|
10
|
+
static findVisualStudio = (...args) => new VisualStudioFinder(...args).findVisualStudio()
|
|
11
|
+
|
|
12
|
+
log = logWithPrefix(log, 'find VS')
|
|
13
|
+
|
|
14
|
+
regSearchKeys = regSearchKeys
|
|
15
|
+
|
|
16
|
+
constructor(nodeSemver, configMsvsVersion) {
|
|
17
|
+
this.nodeSemver = nodeSemver
|
|
18
|
+
this.configMsvsVersion = configMsvsVersion
|
|
19
|
+
this.errorLog = []
|
|
20
|
+
this.validVersions = []
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Logs a message at verbose level, but also saves it to be displayed later
|
|
24
|
+
// at error level if an error occurs. This should help diagnose the problem.
|
|
25
|
+
addLog(message) {
|
|
26
|
+
this.log.verbose(message)
|
|
27
|
+
this.errorLog.push(message)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async findVisualStudio() {
|
|
31
|
+
this.configVersionYear = null
|
|
32
|
+
this.configPath = null
|
|
33
|
+
if (this.configMsvsVersion) {
|
|
34
|
+
this.addLog('msvs_version was set from command line or npm config')
|
|
35
|
+
if (this.configMsvsVersion.match(/^\d{4}$/)) {
|
|
36
|
+
this.configVersionYear = parseInt(this.configMsvsVersion, 10)
|
|
37
|
+
this.addLog(`- looking for Visual Studio version ${this.configVersionYear}`)
|
|
38
|
+
} else {
|
|
39
|
+
this.configPath = path.resolve(this.configMsvsVersion)
|
|
40
|
+
this.addLog(`- looking for Visual Studio installed in "${this.configPath}"`)
|
|
41
|
+
}
|
|
42
|
+
} else {
|
|
43
|
+
this.addLog('msvs_version not set from command line or npm config')
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (process.env.VCINSTALLDIR) {
|
|
47
|
+
this.envVcInstallDir = path.resolve(process.env.VCINSTALLDIR, '..')
|
|
48
|
+
this.addLog(
|
|
49
|
+
'running in VS Command Prompt, installation path is:\n' +
|
|
50
|
+
`"${this.envVcInstallDir}"\n- will only use this version`,
|
|
51
|
+
)
|
|
52
|
+
} else {
|
|
53
|
+
this.addLog('VCINSTALLDIR not set, not running in VS Command Prompt')
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const checks = [
|
|
57
|
+
() => this.findVisualStudio2017OrNewer(),
|
|
58
|
+
() => this.findVisualStudio2015(),
|
|
59
|
+
() => this.findVisualStudio2013(),
|
|
60
|
+
]
|
|
61
|
+
|
|
62
|
+
for (const check of checks) {
|
|
63
|
+
const info = await check()
|
|
64
|
+
if (info) {
|
|
65
|
+
return this.succeed(info)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return this.fail()
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
succeed(info) {
|
|
73
|
+
this.log.info(
|
|
74
|
+
`using VS${info.versionYear} (${info.version}) found at:` +
|
|
75
|
+
`\n"${info.path}"` +
|
|
76
|
+
'\nrun with --verbose for detailed information',
|
|
77
|
+
)
|
|
78
|
+
return info
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
fail() {
|
|
82
|
+
if (this.configMsvsVersion && this.envVcInstallDir) {
|
|
83
|
+
this.errorLog.push('msvs_version does not match this VS Command Prompt or the', 'installation cannot be used.')
|
|
84
|
+
} else if (this.configMsvsVersion) {
|
|
85
|
+
// If msvs_version was specified but finding VS failed, print what would
|
|
86
|
+
// have been accepted
|
|
87
|
+
this.errorLog.push('')
|
|
88
|
+
if (this.validVersions) {
|
|
89
|
+
this.errorLog.push('valid versions for msvs_version:')
|
|
90
|
+
this.validVersions.forEach((version) => {
|
|
91
|
+
this.errorLog.push(`- "${version}"`)
|
|
92
|
+
})
|
|
93
|
+
} else {
|
|
94
|
+
this.errorLog.push('no valid versions for msvs_version were found')
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const errorLog = this.errorLog.join('\n')
|
|
99
|
+
|
|
100
|
+
// For Windows 80 col console, use up to the column before the one marked
|
|
101
|
+
// with X (total 79 chars including logger prefix, 62 chars usable here):
|
|
102
|
+
// X
|
|
103
|
+
const infoLog = [
|
|
104
|
+
'**************************************************************',
|
|
105
|
+
'You need to install the latest version of Visual Studio',
|
|
106
|
+
'including the "Desktop development with C++" workload.',
|
|
107
|
+
'For more information consult the documentation at:',
|
|
108
|
+
'https://github.com/nodejs/node-gyp#on-windows',
|
|
109
|
+
'**************************************************************',
|
|
110
|
+
].join('\n')
|
|
111
|
+
|
|
112
|
+
this.log.error(`\n${errorLog}\n\n${infoLog}\n`)
|
|
113
|
+
throw new Error('Could not find any Visual Studio installation to use')
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Invoke the PowerShell script to get information about Visual Studio 2017
|
|
117
|
+
// or newer installations
|
|
118
|
+
async findVisualStudio2017OrNewer() {
|
|
119
|
+
const ps = path.join(process.env.SystemRoot, 'System32', 'WindowsPowerShell', 'v1.0', 'powershell.exe')
|
|
120
|
+
const csFile = path.join(__dirname, 'Find-VisualStudio.cs')
|
|
121
|
+
const psArgs = [
|
|
122
|
+
'-ExecutionPolicy',
|
|
123
|
+
'Unrestricted',
|
|
124
|
+
'-NoProfile',
|
|
125
|
+
'-Command',
|
|
126
|
+
"&{Add-Type -Path '" + csFile + "';" + '[VisualStudioConfiguration.Main]::PrintJson()}',
|
|
127
|
+
]
|
|
128
|
+
|
|
129
|
+
this.log.silly('Running', ps, psArgs)
|
|
130
|
+
const [err, stdout, stderr] = await execFile(ps, psArgs, { encoding: 'utf8' })
|
|
131
|
+
return this.parseData(err, stdout, stderr)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Parse the output of the PowerShell script and look for an installation
|
|
135
|
+
// of Visual Studio 2017 or newer to use
|
|
136
|
+
parseData(err, stdout, stderr) {
|
|
137
|
+
this.log.silly('PS stderr = %j', stderr)
|
|
138
|
+
|
|
139
|
+
const failPowershell = () => {
|
|
140
|
+
this.addLog(
|
|
141
|
+
"could not use PowerShell to find Visual Studio 2017 or newer, try re-running with '--loglevel silly' for more details",
|
|
142
|
+
)
|
|
143
|
+
return null
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (err) {
|
|
147
|
+
this.log.silly('PS err = %j', err && (err.stack || err))
|
|
148
|
+
return failPowershell()
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
let vsInfo
|
|
152
|
+
try {
|
|
153
|
+
vsInfo = JSON.parse(stdout)
|
|
154
|
+
} catch (e) {
|
|
155
|
+
this.log.silly('PS stdout = %j', stdout)
|
|
156
|
+
this.log.silly(e)
|
|
157
|
+
return failPowershell()
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (!Array.isArray(vsInfo)) {
|
|
161
|
+
this.log.silly('PS stdout = %j', stdout)
|
|
162
|
+
return failPowershell()
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
vsInfo = vsInfo.map((info) => {
|
|
166
|
+
this.log.silly(`processing installation: "${info.path}"`)
|
|
167
|
+
info.path = path.resolve(info.path)
|
|
168
|
+
const ret = this.getVersionInfo(info)
|
|
169
|
+
ret.path = info.path
|
|
170
|
+
ret.msBuild = this.getMSBuild(info, ret.versionYear)
|
|
171
|
+
ret.toolset = this.getToolset(info, ret.versionYear)
|
|
172
|
+
ret.sdk = this.getSDK(info)
|
|
173
|
+
return ret
|
|
174
|
+
})
|
|
175
|
+
this.log.silly('vsInfo:', vsInfo)
|
|
176
|
+
|
|
177
|
+
// Remove future versions or errors parsing version number
|
|
178
|
+
vsInfo = vsInfo.filter((info) => {
|
|
179
|
+
if (info.versionYear) {
|
|
180
|
+
return true
|
|
181
|
+
}
|
|
182
|
+
this.addLog(`unknown version "${info.version}" found at "${info.path}"`)
|
|
183
|
+
return false
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
// Sort to place newer versions first
|
|
187
|
+
vsInfo.sort((a, b) => b.versionYear - a.versionYear)
|
|
188
|
+
|
|
189
|
+
for (let i = 0; i < vsInfo.length; ++i) {
|
|
190
|
+
const info = vsInfo[i]
|
|
191
|
+
this.addLog(`checking VS${info.versionYear} (${info.version}) found ` + `at:\n"${info.path}"`)
|
|
192
|
+
|
|
193
|
+
if (info.msBuild) {
|
|
194
|
+
this.addLog('- found "Visual Studio C++ core features"')
|
|
195
|
+
} else {
|
|
196
|
+
this.addLog('- "Visual Studio C++ core features" missing')
|
|
197
|
+
continue
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (info.toolset) {
|
|
201
|
+
this.addLog(`- found VC++ toolset: ${info.toolset}`)
|
|
202
|
+
} else {
|
|
203
|
+
this.addLog('- missing any VC++ toolset')
|
|
204
|
+
continue
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (info.sdk) {
|
|
208
|
+
this.addLog(`- found Windows SDK: ${info.sdk}`)
|
|
209
|
+
} else {
|
|
210
|
+
this.addLog('- missing any Windows SDK')
|
|
211
|
+
continue
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (!this.checkConfigVersion(info.versionYear, info.path)) {
|
|
215
|
+
continue
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return info
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
this.addLog('could not find a version of Visual Studio 2017 or newer to use')
|
|
222
|
+
return null
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// Helper - process version information
|
|
226
|
+
getVersionInfo(info) {
|
|
227
|
+
const match = /^(\d+)\.(\d+)\..*/.exec(info.version)
|
|
228
|
+
if (!match) {
|
|
229
|
+
this.log.silly('- failed to parse version:', info.version)
|
|
230
|
+
return {}
|
|
231
|
+
}
|
|
232
|
+
this.log.silly('- version match = %j', match)
|
|
233
|
+
const ret = {
|
|
234
|
+
version: info.version,
|
|
235
|
+
versionMajor: parseInt(match[1], 10),
|
|
236
|
+
versionMinor: parseInt(match[2], 10),
|
|
237
|
+
}
|
|
238
|
+
if (ret.versionMajor === 15) {
|
|
239
|
+
ret.versionYear = 2017
|
|
240
|
+
return ret
|
|
241
|
+
}
|
|
242
|
+
if (ret.versionMajor === 16) {
|
|
243
|
+
ret.versionYear = 2019
|
|
244
|
+
return ret
|
|
245
|
+
}
|
|
246
|
+
if (ret.versionMajor === 17) {
|
|
247
|
+
ret.versionYear = 2022
|
|
248
|
+
return ret
|
|
249
|
+
}
|
|
250
|
+
this.log.silly('- unsupported version:', ret.versionMajor)
|
|
251
|
+
return {}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
msBuildPathExists(path) {
|
|
255
|
+
return existsSync(path)
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// Helper - process MSBuild information
|
|
259
|
+
getMSBuild(info, versionYear) {
|
|
260
|
+
const pkg = 'Microsoft.VisualStudio.VC.MSBuild.Base'
|
|
261
|
+
const msbuildPath = path.join(info.path, 'MSBuild', 'Current', 'Bin', 'MSBuild.exe')
|
|
262
|
+
const msbuildPathArm64 = path.join(info.path, 'MSBuild', 'Current', 'Bin', 'arm64', 'MSBuild.exe')
|
|
263
|
+
if (info.packages.indexOf(pkg) !== -1) {
|
|
264
|
+
this.log.silly('- found VC.MSBuild.Base')
|
|
265
|
+
if (versionYear === 2017) {
|
|
266
|
+
return path.join(info.path, 'MSBuild', '15.0', 'Bin', 'MSBuild.exe')
|
|
267
|
+
}
|
|
268
|
+
if (versionYear === 2019) {
|
|
269
|
+
return msbuildPath
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Visual Studio 2022 doesn't have the MSBuild package.
|
|
274
|
+
* Support for compiling _on_ ARM64 was added in MSVC 14.32.31326,
|
|
275
|
+
* so let's leverage it if the user has an ARM64 device.
|
|
276
|
+
*/
|
|
277
|
+
if (process.arch === 'arm64' && this.msBuildPathExists(msbuildPathArm64)) {
|
|
278
|
+
return msbuildPathArm64
|
|
279
|
+
} else if (this.msBuildPathExists(msbuildPath)) {
|
|
280
|
+
return msbuildPath
|
|
281
|
+
}
|
|
282
|
+
return null
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// Helper - process toolset information
|
|
286
|
+
getToolset(info, versionYear) {
|
|
287
|
+
const pkg = 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64'
|
|
288
|
+
const express = 'Microsoft.VisualStudio.WDExpress'
|
|
289
|
+
|
|
290
|
+
if (info.packages.indexOf(pkg) !== -1) {
|
|
291
|
+
this.log.silly('- found VC.Tools.x86.x64')
|
|
292
|
+
} else if (info.packages.indexOf(express) !== -1) {
|
|
293
|
+
this.log.silly('- found Visual Studio Express (looking for toolset)')
|
|
294
|
+
} else {
|
|
295
|
+
return null
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (versionYear === 2017) {
|
|
299
|
+
return 'v141'
|
|
300
|
+
} else if (versionYear === 2019) {
|
|
301
|
+
return 'v142'
|
|
302
|
+
} else if (versionYear === 2022) {
|
|
303
|
+
return 'v143'
|
|
304
|
+
}
|
|
305
|
+
this.log.silly('- invalid versionYear:', versionYear)
|
|
306
|
+
return null
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// Helper - process Windows SDK information
|
|
310
|
+
getSDK(info) {
|
|
311
|
+
const win8SDK = 'Microsoft.VisualStudio.Component.Windows81SDK'
|
|
312
|
+
const win10SDKPrefix = 'Microsoft.VisualStudio.Component.Windows10SDK.'
|
|
313
|
+
const win11SDKPrefix = 'Microsoft.VisualStudio.Component.Windows11SDK.'
|
|
314
|
+
|
|
315
|
+
let Win10or11SDKVer = 0
|
|
316
|
+
info.packages.forEach((pkg) => {
|
|
317
|
+
if (!pkg.startsWith(win10SDKPrefix) && !pkg.startsWith(win11SDKPrefix)) {
|
|
318
|
+
return
|
|
319
|
+
}
|
|
320
|
+
const parts = pkg.split('.')
|
|
321
|
+
if (parts.length > 5 && parts[5] !== 'Desktop') {
|
|
322
|
+
this.log.silly('- ignoring non-Desktop Win10/11SDK:', pkg)
|
|
323
|
+
return
|
|
324
|
+
}
|
|
325
|
+
const foundSdkVer = parseInt(parts[4], 10)
|
|
326
|
+
if (isNaN(foundSdkVer)) {
|
|
327
|
+
// Microsoft.VisualStudio.Component.Windows10SDK.IpOverUsb
|
|
328
|
+
this.log.silly('- failed to parse Win10/11SDK number:', pkg)
|
|
329
|
+
return
|
|
330
|
+
}
|
|
331
|
+
this.log.silly('- found Win10/11SDK:', foundSdkVer)
|
|
332
|
+
Win10or11SDKVer = Math.max(Win10or11SDKVer, foundSdkVer)
|
|
333
|
+
})
|
|
334
|
+
|
|
335
|
+
if (Win10or11SDKVer !== 0) {
|
|
336
|
+
return `10.0.${Win10or11SDKVer}.0`
|
|
337
|
+
} else if (info.packages.indexOf(win8SDK) !== -1) {
|
|
338
|
+
this.log.silly('- found Win8SDK')
|
|
339
|
+
return '8.1'
|
|
340
|
+
}
|
|
341
|
+
return null
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// Find an installation of Visual Studio 2015 to use
|
|
345
|
+
async findVisualStudio2015() {
|
|
346
|
+
if (semver.gte(this.nodeSemver, '19.0.0')) {
|
|
347
|
+
this.addLog('not looking for VS2015 as it is only supported up to Node.js 18')
|
|
348
|
+
return null
|
|
349
|
+
}
|
|
350
|
+
return this.findOldVS({
|
|
351
|
+
version: '14.0',
|
|
352
|
+
versionMajor: 14,
|
|
353
|
+
versionMinor: 0,
|
|
354
|
+
versionYear: 2015,
|
|
355
|
+
toolset: 'v140',
|
|
356
|
+
})
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// Find an installation of Visual Studio 2013 to use
|
|
360
|
+
async findVisualStudio2013() {
|
|
361
|
+
if (semver.gte(this.nodeSemver, '9.0.0')) {
|
|
362
|
+
this.addLog('not looking for VS2013 as it is only supported up to Node.js 8')
|
|
363
|
+
return null
|
|
364
|
+
}
|
|
365
|
+
return this.findOldVS({
|
|
366
|
+
version: '12.0',
|
|
367
|
+
versionMajor: 12,
|
|
368
|
+
versionMinor: 0,
|
|
369
|
+
versionYear: 2013,
|
|
370
|
+
toolset: 'v120',
|
|
371
|
+
})
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// Helper - common code for VS2013 and VS2015
|
|
375
|
+
async findOldVS(info) {
|
|
376
|
+
const regVC7 = [
|
|
377
|
+
'HKLM\\Software\\Microsoft\\VisualStudio\\SxS\\VC7',
|
|
378
|
+
'HKLM\\Software\\Wow6432Node\\Microsoft\\VisualStudio\\SxS\\VC7',
|
|
379
|
+
]
|
|
380
|
+
const regMSBuild = 'HKLM\\Software\\Microsoft\\MSBuild\\ToolsVersions'
|
|
381
|
+
|
|
382
|
+
this.addLog(`looking for Visual Studio ${info.versionYear}`)
|
|
383
|
+
try {
|
|
384
|
+
let res = await this.regSearchKeys(regVC7, info.version, [])
|
|
385
|
+
const vsPath = path.resolve(res, '..')
|
|
386
|
+
this.addLog(`- found in "${vsPath}"`)
|
|
387
|
+
const msBuildRegOpts = process.arch === 'ia32' ? [] : ['/reg:32']
|
|
388
|
+
|
|
389
|
+
try {
|
|
390
|
+
res = await this.regSearchKeys([`${regMSBuild}\\${info.version}`], 'MSBuildToolsPath', msBuildRegOpts)
|
|
391
|
+
} catch (err) {
|
|
392
|
+
this.addLog('- could not find MSBuild in registry for this version')
|
|
393
|
+
return null
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
const msBuild = path.join(res, 'MSBuild.exe')
|
|
397
|
+
this.addLog(`- MSBuild in "${msBuild}"`)
|
|
398
|
+
|
|
399
|
+
if (!this.checkConfigVersion(info.versionYear, vsPath)) {
|
|
400
|
+
return null
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
info.path = vsPath
|
|
404
|
+
info.msBuild = msBuild
|
|
405
|
+
info.sdk = null
|
|
406
|
+
return info
|
|
407
|
+
} catch (err) {
|
|
408
|
+
this.addLog('- not found')
|
|
409
|
+
return null
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// After finding a usable version of Visual Studio:
|
|
414
|
+
// - add it to validVersions to be displayed at the end if a specific
|
|
415
|
+
// version was requested and not found;
|
|
416
|
+
// - check if this is the version that was requested.
|
|
417
|
+
// - check if this matches the Visual Studio Command Prompt
|
|
418
|
+
checkConfigVersion(versionYear, vsPath) {
|
|
419
|
+
this.validVersions.push(versionYear)
|
|
420
|
+
this.validVersions.push(vsPath)
|
|
421
|
+
|
|
422
|
+
if (this.configVersionYear && this.configVersionYear !== versionYear) {
|
|
423
|
+
this.addLog('- msvs_version does not match this version')
|
|
424
|
+
return false
|
|
425
|
+
}
|
|
426
|
+
if (this.configPath && path.relative(this.configPath, vsPath) !== '') {
|
|
427
|
+
this.addLog('- msvs_version does not point to this installation')
|
|
428
|
+
return false
|
|
429
|
+
}
|
|
430
|
+
if (this.envVcInstallDir && path.relative(this.envVcInstallDir, vsPath) !== '') {
|
|
431
|
+
this.addLog('- does not match this Visual Studio Command Prompt')
|
|
432
|
+
return false
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
return true
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
module.exports = VisualStudioFinder
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const log = require('npmlog')
|
|
4
|
+
const cp = require('child_process')
|
|
5
|
+
const path = require('path')
|
|
6
|
+
|
|
7
|
+
const execFile = async (...args) =>
|
|
8
|
+
new Promise((resolve) => {
|
|
9
|
+
const child = cp.execFile(...args, (...a) => resolve(a))
|
|
10
|
+
child.stdin.end()
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
function logWithPrefix(log, prefix) {
|
|
14
|
+
function setPrefix(logFunction) {
|
|
15
|
+
return (...args) => logFunction.apply(null, [prefix, ...args]) // eslint-disable-line
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
silly: setPrefix(log.silly),
|
|
19
|
+
verbose: setPrefix(log.verbose),
|
|
20
|
+
info: setPrefix(log.info),
|
|
21
|
+
warn: setPrefix(log.warn),
|
|
22
|
+
error: setPrefix(log.error),
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function regGetValue(key, value, addOpts) {
|
|
27
|
+
const outReValue = value.replace(/\W/g, '.')
|
|
28
|
+
const outRe = new RegExp(`^\\s+${outReValue}\\s+REG_\\w+\\s+(\\S.*)$`, 'im')
|
|
29
|
+
const reg = path.join(process.env.SystemRoot, 'System32', 'reg.exe')
|
|
30
|
+
const regArgs = ['query', key, '/v', value].concat(addOpts)
|
|
31
|
+
|
|
32
|
+
log.silly('reg', 'running', reg, regArgs)
|
|
33
|
+
const [err, stdout, stderr] = await execFile(reg, regArgs, { encoding: 'utf8' })
|
|
34
|
+
|
|
35
|
+
log.silly('reg', 'reg.exe stdout = %j', stdout)
|
|
36
|
+
if (err || stderr.trim() !== '') {
|
|
37
|
+
log.silly('reg', 'reg.exe err = %j', err && (err.stack || err))
|
|
38
|
+
log.silly('reg', 'reg.exe stderr = %j', stderr)
|
|
39
|
+
if (err) {
|
|
40
|
+
throw err
|
|
41
|
+
}
|
|
42
|
+
throw new Error(stderr)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const result = outRe.exec(stdout)
|
|
46
|
+
if (!result) {
|
|
47
|
+
log.silly('reg', 'error parsing stdout')
|
|
48
|
+
throw new Error('Could not parse output of reg.exe')
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
log.silly('reg', 'found: %j', result[1])
|
|
52
|
+
return result[1]
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async function regSearchKeys(keys, value, addOpts) {
|
|
56
|
+
for (const key of keys) {
|
|
57
|
+
try {
|
|
58
|
+
return await regGetValue(key, value, addOpts)
|
|
59
|
+
} catch {
|
|
60
|
+
continue
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
module.exports = {
|
|
66
|
+
logWithPrefix: logWithPrefix,
|
|
67
|
+
regGetValue: regGetValue,
|
|
68
|
+
regSearchKeys: regSearchKeys,
|
|
69
|
+
execFile: execFile,
|
|
70
|
+
}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
BuildSystem: require('./buildSystem'),
|
|
5
|
+
CMLog: require('./cmLog'),
|
|
6
|
+
environment: require('./environment'),
|
|
7
|
+
TargetOptions: require('./targetOptions'),
|
|
8
|
+
Dist: require('./dist'),
|
|
9
|
+
CMake: require('./cMake'),
|
|
10
|
+
downloader: require('./downloader'),
|
|
11
|
+
Toolset: require('./toolset'),
|
|
12
|
+
}
|
package/lib/locateNAN.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
const fs = require('fs-extra')
|
|
3
|
+
const path = require('path')
|
|
4
|
+
|
|
5
|
+
const isNANModule = async function (dir) {
|
|
6
|
+
const h = path.join(dir, 'nan.h')
|
|
7
|
+
try {
|
|
8
|
+
const stat = await fs.stat(h)
|
|
9
|
+
return stat.isFile()
|
|
10
|
+
} catch (e) {
|
|
11
|
+
return false
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async function isNodeJSProject(dir) {
|
|
16
|
+
const pjson = path.join(dir, 'package.json')
|
|
17
|
+
const node_modules = path.join(dir, 'node_modules')
|
|
18
|
+
try {
|
|
19
|
+
let stat = await fs.stat(pjson)
|
|
20
|
+
if (stat.isFile()) {
|
|
21
|
+
return true
|
|
22
|
+
}
|
|
23
|
+
stat = await fs.stat(node_modules)
|
|
24
|
+
if (stat.isDirectory()) {
|
|
25
|
+
return true
|
|
26
|
+
}
|
|
27
|
+
} catch (e) {
|
|
28
|
+
// Ignore
|
|
29
|
+
}
|
|
30
|
+
return false
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const locateNAN = (module.exports = async function (projectRoot) {
|
|
34
|
+
if (locateNAN.__projectRoot) {
|
|
35
|
+
// Override for unit tests
|
|
36
|
+
projectRoot = locateNAN.__projectRoot
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let result = await isNodeJSProject(projectRoot)
|
|
40
|
+
if (!result) {
|
|
41
|
+
return null
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const nanModulePath = path.join(projectRoot, 'node_modules', 'nan')
|
|
45
|
+
result = await isNANModule(nanModulePath)
|
|
46
|
+
if (result) {
|
|
47
|
+
return nanModulePath
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Goto upper level:
|
|
51
|
+
return await locateNAN(goUp(projectRoot))
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
function goUp(dir) {
|
|
55
|
+
const items = dir.split(path.sep)
|
|
56
|
+
const scopeItem = items[items.length - 2]
|
|
57
|
+
if (scopeItem && scopeItem[0] === '@') {
|
|
58
|
+
// skip scope
|
|
59
|
+
dir = path.join(dir, '..')
|
|
60
|
+
}
|
|
61
|
+
dir = path.join(dir, '..', '..')
|
|
62
|
+
return path.normalize(dir)
|
|
63
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
const path = require('path')
|
|
3
|
+
|
|
4
|
+
const locateNodeApi = (module.exports = async function (projectRoot) {
|
|
5
|
+
if (locateNodeApi.__projectRoot) {
|
|
6
|
+
// Override for unit tests
|
|
7
|
+
projectRoot = locateNodeApi.__projectRoot
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
try {
|
|
11
|
+
const tmpRequire = require('module').createRequire(path.join(projectRoot, 'package.json'))
|
|
12
|
+
const inc = tmpRequire('node-addon-api')
|
|
13
|
+
return inc.include.replace(/"/g, '')
|
|
14
|
+
} catch (e) {
|
|
15
|
+
// It most likely wasn't found
|
|
16
|
+
return null
|
|
17
|
+
}
|
|
18
|
+
})
|
package/lib/npmConfig.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
function getNpmConfig() {
|
|
4
|
+
const npmOptions = {}
|
|
5
|
+
const npmConfigPrefix = 'npm_config_'
|
|
6
|
+
Object.keys(process.env).forEach(function (name) {
|
|
7
|
+
if (name.indexOf(npmConfigPrefix) !== 0) {
|
|
8
|
+
return
|
|
9
|
+
}
|
|
10
|
+
const value = process.env[name]
|
|
11
|
+
name = name.substring(npmConfigPrefix.length)
|
|
12
|
+
if (name) {
|
|
13
|
+
npmOptions[name] = value
|
|
14
|
+
}
|
|
15
|
+
}, this)
|
|
16
|
+
|
|
17
|
+
return npmOptions
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
module.exports = function (log) {
|
|
21
|
+
log.verbose('CFG', 'Looking for NPM config.')
|
|
22
|
+
const options = getNpmConfig()
|
|
23
|
+
|
|
24
|
+
if (options) {
|
|
25
|
+
log.silly('CFG', 'NPM options:', options)
|
|
26
|
+
} else {
|
|
27
|
+
log.verbose('CFG', 'There are no NPM options available.')
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return options
|
|
31
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
const spawn = require('child_process').spawn
|
|
3
|
+
const execFile = require('child_process').execFile
|
|
4
|
+
|
|
5
|
+
const processHelpers = {
|
|
6
|
+
run: function (command, options) {
|
|
7
|
+
if (!options) options = {}
|
|
8
|
+
|
|
9
|
+
return new Promise(function (resolve, reject) {
|
|
10
|
+
const env = Object.assign({}, process.env)
|
|
11
|
+
if (env.Path && env.PATH) {
|
|
12
|
+
if (env.Path !== env.PATH) {
|
|
13
|
+
env.PATH = env.Path + ';' + env.PATH
|
|
14
|
+
}
|
|
15
|
+
delete env.Path
|
|
16
|
+
}
|
|
17
|
+
const child = spawn(command[0], command.slice(1), {
|
|
18
|
+
stdio: options.silent ? 'ignore' : 'inherit',
|
|
19
|
+
env,
|
|
20
|
+
})
|
|
21
|
+
let ended = false
|
|
22
|
+
child.on('error', function (e) {
|
|
23
|
+
if (!ended) {
|
|
24
|
+
reject(e)
|
|
25
|
+
ended = true
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
child.on('exit', function (code, signal) {
|
|
29
|
+
if (!ended) {
|
|
30
|
+
if (code === 0) {
|
|
31
|
+
resolve()
|
|
32
|
+
} else {
|
|
33
|
+
reject(new Error('Process terminated: ' + code || signal))
|
|
34
|
+
}
|
|
35
|
+
ended = true
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
})
|
|
39
|
+
},
|
|
40
|
+
execFile: function (command) {
|
|
41
|
+
return new Promise(function (resolve, reject) {
|
|
42
|
+
execFile(command[0], command.slice(1), function (err, stdout, stderr) {
|
|
43
|
+
if (err) {
|
|
44
|
+
reject(new Error(err.message + '\n' + (stdout || stderr)))
|
|
45
|
+
} else {
|
|
46
|
+
resolve(stdout)
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
})
|
|
50
|
+
},
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
module.exports = processHelpers
|