@socketsecurity/cli-with-sentry 1.0.3 → 1.0.5

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.
Files changed (114) hide show
  1. package/dist/cli.js +2 -2
  2. package/dist/cli.js.map +1 -1
  3. package/dist/constants.js +3 -3
  4. package/dist/constants.js.map +1 -1
  5. package/dist/vendor.js +3 -3
  6. package/external/node-gyp/.release-please-manifest.json +3 -0
  7. package/external/node-gyp/CHANGELOG.md +1053 -0
  8. package/external/node-gyp/CODE_OF_CONDUCT.md +4 -0
  9. package/external/node-gyp/CONTRIBUTING.md +34 -0
  10. package/external/node-gyp/LICENSE +24 -0
  11. package/external/node-gyp/README.md +273 -0
  12. package/external/node-gyp/SECURITY.md +2 -0
  13. package/external/node-gyp/addon.gypi +204 -0
  14. package/external/node-gyp/bin/node-gyp.js +137 -0
  15. package/external/node-gyp/eslint.config.js +3 -0
  16. package/external/node-gyp/gyp/.release-please-manifest.json +3 -0
  17. package/external/node-gyp/gyp/LICENSE +28 -0
  18. package/external/node-gyp/gyp/data/ninja/build.ninja +4 -0
  19. package/external/node-gyp/gyp/data/win/large-pdb-shim.cc +12 -0
  20. package/external/node-gyp/gyp/docs/GypVsCMake.md +116 -0
  21. package/external/node-gyp/gyp/docs/Hacking.md +46 -0
  22. package/external/node-gyp/gyp/docs/InputFormatReference.md +1083 -0
  23. package/external/node-gyp/gyp/docs/LanguageSpecification.md +430 -0
  24. package/external/node-gyp/gyp/docs/README.md +27 -0
  25. package/external/node-gyp/gyp/docs/Testing.md +450 -0
  26. package/external/node-gyp/gyp/docs/UserDocumentation.md +965 -0
  27. package/external/node-gyp/gyp/gyp +8 -0
  28. package/external/node-gyp/gyp/gyp.bat +5 -0
  29. package/external/node-gyp/gyp/gyp_main.py +45 -0
  30. package/external/node-gyp/gyp/pylib/gyp/MSVSNew.py +365 -0
  31. package/external/node-gyp/gyp/pylib/gyp/MSVSProject.py +206 -0
  32. package/external/node-gyp/gyp/pylib/gyp/MSVSSettings.py +1272 -0
  33. package/external/node-gyp/gyp/pylib/gyp/MSVSSettings_test.py +1547 -0
  34. package/external/node-gyp/gyp/pylib/gyp/MSVSToolFile.py +59 -0
  35. package/external/node-gyp/gyp/pylib/gyp/MSVSUserFile.py +152 -0
  36. package/external/node-gyp/gyp/pylib/gyp/MSVSUtil.py +270 -0
  37. package/external/node-gyp/gyp/pylib/gyp/MSVSVersion.py +574 -0
  38. package/external/node-gyp/gyp/pylib/gyp/__init__.py +704 -0
  39. package/external/node-gyp/gyp/pylib/gyp/common.py +709 -0
  40. package/external/node-gyp/gyp/pylib/gyp/common_test.py +173 -0
  41. package/external/node-gyp/gyp/pylib/gyp/easy_xml.py +169 -0
  42. package/external/node-gyp/gyp/pylib/gyp/easy_xml_test.py +113 -0
  43. package/external/node-gyp/gyp/pylib/gyp/flock_tool.py +55 -0
  44. package/external/node-gyp/gyp/pylib/gyp/generator/__init__.py +0 -0
  45. package/external/node-gyp/gyp/pylib/gyp/generator/analyzer.py +805 -0
  46. package/external/node-gyp/gyp/pylib/gyp/generator/android.py +1172 -0
  47. package/external/node-gyp/gyp/pylib/gyp/generator/cmake.py +1319 -0
  48. package/external/node-gyp/gyp/pylib/gyp/generator/compile_commands_json.py +128 -0
  49. package/external/node-gyp/gyp/pylib/gyp/generator/dump_dependency_json.py +104 -0
  50. package/external/node-gyp/gyp/pylib/gyp/generator/eclipse.py +462 -0
  51. package/external/node-gyp/gyp/pylib/gyp/generator/gypd.py +89 -0
  52. package/external/node-gyp/gyp/pylib/gyp/generator/gypsh.py +56 -0
  53. package/external/node-gyp/gyp/pylib/gyp/generator/make.py +2745 -0
  54. package/external/node-gyp/gyp/pylib/gyp/generator/msvs.py +3976 -0
  55. package/external/node-gyp/gyp/pylib/gyp/generator/msvs_test.py +44 -0
  56. package/external/node-gyp/gyp/pylib/gyp/generator/ninja.py +2965 -0
  57. package/external/node-gyp/gyp/pylib/gyp/generator/ninja_test.py +67 -0
  58. package/external/node-gyp/gyp/pylib/gyp/generator/xcode.py +1391 -0
  59. package/external/node-gyp/gyp/pylib/gyp/generator/xcode_test.py +26 -0
  60. package/external/node-gyp/gyp/pylib/gyp/input.py +3112 -0
  61. package/external/node-gyp/gyp/pylib/gyp/input_test.py +99 -0
  62. package/external/node-gyp/gyp/pylib/gyp/mac_tool.py +767 -0
  63. package/external/node-gyp/gyp/pylib/gyp/msvs_emulation.py +1260 -0
  64. package/external/node-gyp/gyp/pylib/gyp/ninja_syntax.py +174 -0
  65. package/external/node-gyp/gyp/pylib/gyp/simple_copy.py +61 -0
  66. package/external/node-gyp/gyp/pylib/gyp/win_tool.py +373 -0
  67. package/external/node-gyp/gyp/pylib/gyp/xcode_emulation.py +1939 -0
  68. package/external/node-gyp/gyp/pylib/gyp/xcode_emulation_test.py +54 -0
  69. package/external/node-gyp/gyp/pylib/gyp/xcode_ninja.py +303 -0
  70. package/external/node-gyp/gyp/pylib/gyp/xcodeproj_file.py +3196 -0
  71. package/external/node-gyp/gyp/pylib/gyp/xml_fix.py +65 -0
  72. package/external/node-gyp/gyp/pylib/packaging/LICENSE +3 -0
  73. package/external/node-gyp/gyp/pylib/packaging/LICENSE.APACHE +177 -0
  74. package/external/node-gyp/gyp/pylib/packaging/LICENSE.BSD +23 -0
  75. package/external/node-gyp/gyp/pylib/packaging/__init__.py +15 -0
  76. package/external/node-gyp/gyp/pylib/packaging/_elffile.py +108 -0
  77. package/external/node-gyp/gyp/pylib/packaging/_manylinux.py +252 -0
  78. package/external/node-gyp/gyp/pylib/packaging/_musllinux.py +83 -0
  79. package/external/node-gyp/gyp/pylib/packaging/_parser.py +359 -0
  80. package/external/node-gyp/gyp/pylib/packaging/_structures.py +61 -0
  81. package/external/node-gyp/gyp/pylib/packaging/_tokenizer.py +192 -0
  82. package/external/node-gyp/gyp/pylib/packaging/markers.py +252 -0
  83. package/external/node-gyp/gyp/pylib/packaging/metadata.py +825 -0
  84. package/external/node-gyp/gyp/pylib/packaging/py.typed +0 -0
  85. package/external/node-gyp/gyp/pylib/packaging/requirements.py +90 -0
  86. package/external/node-gyp/gyp/pylib/packaging/specifiers.py +1030 -0
  87. package/external/node-gyp/gyp/pylib/packaging/tags.py +553 -0
  88. package/external/node-gyp/gyp/pylib/packaging/utils.py +172 -0
  89. package/external/node-gyp/gyp/pylib/packaging/version.py +563 -0
  90. package/external/node-gyp/gyp/pyproject.toml +115 -0
  91. package/external/node-gyp/gyp/release-please-config.json +11 -0
  92. package/external/node-gyp/gyp/test_gyp.py +261 -0
  93. package/external/node-gyp/lib/Find-VisualStudio.cs +250 -0
  94. package/external/node-gyp/lib/build.js +230 -0
  95. package/external/node-gyp/lib/clean.js +15 -0
  96. package/external/node-gyp/lib/configure.js +328 -0
  97. package/external/node-gyp/lib/create-config-gypi.js +153 -0
  98. package/external/node-gyp/lib/download.js +41 -0
  99. package/external/node-gyp/lib/find-node-directory.js +63 -0
  100. package/external/node-gyp/lib/find-python.js +310 -0
  101. package/external/node-gyp/lib/find-visualstudio.js +600 -0
  102. package/external/node-gyp/lib/install.js +415 -0
  103. package/external/node-gyp/lib/list.js +26 -0
  104. package/external/node-gyp/lib/log.js +168 -0
  105. package/external/node-gyp/lib/node-gyp.js +188 -0
  106. package/external/node-gyp/lib/process-release.js +148 -0
  107. package/external/node-gyp/lib/rebuild.js +12 -0
  108. package/external/node-gyp/lib/remove.js +43 -0
  109. package/external/node-gyp/lib/util.js +81 -0
  110. package/external/node-gyp/macOS_Catalina_acid_test.sh +21 -0
  111. package/external/node-gyp/package.json +52 -0
  112. package/external/node-gyp/release-please-config.json +40 -0
  113. package/external/node-gyp/src/win_delay_load_hook.cc +41 -0
  114. package/package.json +2 -1
@@ -0,0 +1,600 @@
1
+ 'use strict'
2
+
3
+ const log = require('./log')
4
+ const { existsSync } = require('fs')
5
+ const { win32: path } = require('path')
6
+ const { regSearchKeys, execFile } = require('./util')
7
+
8
+ class VisualStudioFinder {
9
+ static findVisualStudio = (...args) => new VisualStudioFinder(...args).findVisualStudio()
10
+
11
+ log = log.withPrefix('find VS')
12
+
13
+ regSearchKeys = regSearchKeys
14
+
15
+ constructor (nodeSemver, configMsvsVersion) {
16
+ this.nodeSemver = nodeSemver
17
+ this.configMsvsVersion = configMsvsVersion
18
+ this.errorLog = []
19
+ this.validVersions = []
20
+ }
21
+
22
+ // Logs a message at verbose level, but also saves it to be displayed later
23
+ // at error level if an error occurs. This should help diagnose the problem.
24
+ addLog (message) {
25
+ this.log.verbose(message)
26
+ this.errorLog.push(message)
27
+ }
28
+
29
+ async findVisualStudio () {
30
+ this.configVersionYear = null
31
+ this.configPath = null
32
+ if (this.configMsvsVersion) {
33
+ this.addLog('msvs_version was set from command line or npm config')
34
+ if (this.configMsvsVersion.match(/^\d{4}$/)) {
35
+ this.configVersionYear = parseInt(this.configMsvsVersion, 10)
36
+ this.addLog(
37
+ `- looking for Visual Studio version ${this.configVersionYear}`)
38
+ } else {
39
+ this.configPath = path.resolve(this.configMsvsVersion)
40
+ this.addLog(
41
+ `- looking for Visual Studio installed in "${this.configPath}"`)
42
+ }
43
+ } else {
44
+ this.addLog('msvs_version not set from command line or npm config')
45
+ }
46
+
47
+ if (process.env.VCINSTALLDIR) {
48
+ this.envVcInstallDir =
49
+ path.resolve(process.env.VCINSTALLDIR, '..')
50
+ this.addLog('running in VS Command Prompt, installation path is:\n' +
51
+ `"${this.envVcInstallDir}"\n- will only use this version`)
52
+ } else {
53
+ this.addLog('VCINSTALLDIR not set, not running in VS Command Prompt')
54
+ }
55
+
56
+ const checks = [
57
+ () => this.findVisualStudio2019OrNewerFromSpecifiedLocation(),
58
+ () => this.findVisualStudio2019OrNewerUsingSetupModule(),
59
+ () => this.findVisualStudio2019OrNewer(),
60
+ () => this.findVisualStudio2017FromSpecifiedLocation(),
61
+ () => this.findVisualStudio2017UsingSetupModule(),
62
+ () => this.findVisualStudio2017(),
63
+ () => this.findVisualStudio2015(),
64
+ () => this.findVisualStudio2013()
65
+ ]
66
+
67
+ for (const check of checks) {
68
+ const info = await check()
69
+ if (info) {
70
+ return this.succeed(info)
71
+ }
72
+ }
73
+
74
+ return this.fail()
75
+ }
76
+
77
+ succeed (info) {
78
+ this.log.info(`using VS${info.versionYear} (${info.version}) found at:` +
79
+ `\n"${info.path}"` +
80
+ '\nrun with --verbose for detailed information')
81
+ return info
82
+ }
83
+
84
+ fail () {
85
+ if (this.configMsvsVersion && this.envVcInstallDir) {
86
+ this.errorLog.push(
87
+ 'msvs_version does not match this VS Command Prompt or the',
88
+ 'installation cannot be used.')
89
+ } else if (this.configMsvsVersion) {
90
+ // If msvs_version was specified but finding VS failed, print what would
91
+ // have been accepted
92
+ this.errorLog.push('')
93
+ if (this.validVersions) {
94
+ this.errorLog.push('valid versions for msvs_version:')
95
+ this.validVersions.forEach((version) => {
96
+ this.errorLog.push(`- "${version}"`)
97
+ })
98
+ } else {
99
+ this.errorLog.push('no valid versions for msvs_version were found')
100
+ }
101
+ }
102
+
103
+ const errorLog = this.errorLog.join('\n')
104
+
105
+ // For Windows 80 col console, use up to the column before the one marked
106
+ // with X (total 79 chars including logger prefix, 62 chars usable here):
107
+ // X
108
+ const infoLog = [
109
+ '**************************************************************',
110
+ 'You need to install the latest version of Visual Studio',
111
+ 'including the "Desktop development with C++" workload.',
112
+ 'For more information consult the documentation at:',
113
+ 'https://github.com/nodejs/node-gyp#on-windows',
114
+ '**************************************************************'
115
+ ].join('\n')
116
+
117
+ this.log.error(`\n${errorLog}\n\n${infoLog}\n`)
118
+ throw new Error('Could not find any Visual Studio installation to use')
119
+ }
120
+
121
+ async findVisualStudio2019OrNewerFromSpecifiedLocation () {
122
+ return this.findVSFromSpecifiedLocation([2019, 2022])
123
+ }
124
+
125
+ async findVisualStudio2017FromSpecifiedLocation () {
126
+ if (this.nodeSemver.major >= 22) {
127
+ this.addLog(
128
+ 'not looking for VS2017 as it is only supported up to Node.js 21')
129
+ return null
130
+ }
131
+ return this.findVSFromSpecifiedLocation([2017])
132
+ }
133
+
134
+ async findVSFromSpecifiedLocation (supportedYears) {
135
+ if (!this.envVcInstallDir) {
136
+ return null
137
+ }
138
+ const info = {
139
+ path: path.resolve(this.envVcInstallDir),
140
+ // Assume the version specified by the user is correct.
141
+ // Since Visual Studio 2015, the Developer Command Prompt sets the
142
+ // VSCMD_VER environment variable which contains the version information
143
+ // for Visual Studio.
144
+ // https://learn.microsoft.com/en-us/visualstudio/ide/reference/command-prompt-powershell?view=vs-2022
145
+ version: process.env.VSCMD_VER,
146
+ packages: [
147
+ 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64',
148
+ 'Microsoft.VisualStudio.Component.VC.Tools.ARM64',
149
+ // Assume MSBuild exists. It will be checked in processing.
150
+ 'Microsoft.VisualStudio.VC.MSBuild.Base'
151
+ ]
152
+ }
153
+
154
+ // Is there a better way to get SDK information?
155
+ const envWindowsSDKVersion = process.env.WindowsSDKVersion
156
+ const sdkVersionMatched = envWindowsSDKVersion?.match(/^(\d+)\.(\d+)\.(\d+)\..*/)
157
+ if (sdkVersionMatched) {
158
+ info.packages.push(`Microsoft.VisualStudio.Component.Windows10SDK.${sdkVersionMatched[3]}.Desktop`)
159
+ }
160
+ // pass for further processing
161
+ return this.processData([info], supportedYears)
162
+ }
163
+
164
+ async findVisualStudio2019OrNewerUsingSetupModule () {
165
+ return this.findNewVSUsingSetupModule([2019, 2022])
166
+ }
167
+
168
+ async findVisualStudio2017UsingSetupModule () {
169
+ if (this.nodeSemver.major >= 22) {
170
+ this.addLog(
171
+ 'not looking for VS2017 as it is only supported up to Node.js 21')
172
+ return null
173
+ }
174
+ return this.findNewVSUsingSetupModule([2017])
175
+ }
176
+
177
+ async findNewVSUsingSetupModule (supportedYears) {
178
+ const ps = path.join(process.env.SystemRoot, 'System32',
179
+ 'WindowsPowerShell', 'v1.0', 'powershell.exe')
180
+ const vcInstallDir = this.envVcInstallDir
181
+
182
+ const checkModuleArgs = [
183
+ '-NoProfile',
184
+ '-Command',
185
+ '&{@(Get-Module -ListAvailable -Name VSSetup).Version.ToString()}'
186
+ ]
187
+ this.log.silly('Running', ps, checkModuleArgs)
188
+ const [cErr] = await this.execFile(ps, checkModuleArgs)
189
+ if (cErr) {
190
+ this.addLog('VSSetup module doesn\'t seem to exist. You can install it via: "Install-Module VSSetup -Scope CurrentUser"')
191
+ this.log.silly('VSSetup error = %j', cErr && (cErr.stack || cErr))
192
+ return null
193
+ }
194
+ const filterArg = vcInstallDir !== undefined ? `| where {$_.InstallationPath -eq '${vcInstallDir}' }` : ''
195
+ const psArgs = [
196
+ '-NoProfile',
197
+ '-Command',
198
+ `&{Get-VSSetupInstance ${filterArg} | ConvertTo-Json -Depth 3}`
199
+ ]
200
+
201
+ this.log.silly('Running', ps, psArgs)
202
+ const [err, stdout, stderr] = await this.execFile(ps, psArgs)
203
+ let parsedData = this.parseData(err, stdout, stderr)
204
+ if (parsedData === null) {
205
+ return null
206
+ }
207
+ this.log.silly('Parsed data', parsedData)
208
+ if (!Array.isArray(parsedData)) {
209
+ // if there are only 1 result, then Powershell will output non-array
210
+ parsedData = [parsedData]
211
+ }
212
+ // normalize output
213
+ parsedData = parsedData.map((info) => {
214
+ info.path = info.InstallationPath
215
+ info.version = `${info.InstallationVersion.Major}.${info.InstallationVersion.Minor}.${info.InstallationVersion.Build}.${info.InstallationVersion.Revision}`
216
+ info.packages = info.Packages.map((p) => p.Id)
217
+ return info
218
+ })
219
+ // pass for further processing
220
+ return this.processData(parsedData, supportedYears)
221
+ }
222
+
223
+ // Invoke the PowerShell script to get information about Visual Studio 2019
224
+ // or newer installations
225
+ async findVisualStudio2019OrNewer () {
226
+ return this.findNewVS([2019, 2022])
227
+ }
228
+
229
+ // Invoke the PowerShell script to get information about Visual Studio 2017
230
+ async findVisualStudio2017 () {
231
+ if (this.nodeSemver.major >= 22) {
232
+ this.addLog(
233
+ 'not looking for VS2017 as it is only supported up to Node.js 21')
234
+ return null
235
+ }
236
+ return this.findNewVS([2017])
237
+ }
238
+
239
+ // Invoke the PowerShell script to get information about Visual Studio 2017
240
+ // or newer installations
241
+ async findNewVS (supportedYears) {
242
+ const ps = path.join(process.env.SystemRoot, 'System32',
243
+ 'WindowsPowerShell', 'v1.0', 'powershell.exe')
244
+ const csFile = path.join(__dirname, 'Find-VisualStudio.cs')
245
+ const psArgs = [
246
+ '-ExecutionPolicy',
247
+ 'Unrestricted',
248
+ '-NoProfile',
249
+ '-Command',
250
+ '&{Add-Type -Path \'' + csFile + '\';' + '[VisualStudioConfiguration.Main]::PrintJson()}'
251
+ ]
252
+
253
+ this.log.silly('Running', ps, psArgs)
254
+ const [err, stdout, stderr] = await this.execFile(ps, psArgs)
255
+ const parsedData = this.parseData(err, stdout, stderr, { checkIsArray: true })
256
+ if (parsedData === null) {
257
+ return null
258
+ }
259
+ return this.processData(parsedData, supportedYears)
260
+ }
261
+
262
+ // Parse the output of the PowerShell script, make sanity checks
263
+ parseData (err, stdout, stderr, sanityCheckOptions) {
264
+ const defaultOptions = {
265
+ checkIsArray: false
266
+ }
267
+
268
+ // Merging provided options with the default options
269
+ const sanityOptions = { ...defaultOptions, ...sanityCheckOptions }
270
+
271
+ this.log.silly('PS stderr = %j', stderr)
272
+
273
+ const failPowershell = (failureDetails) => {
274
+ this.addLog(
275
+ `could not use PowerShell to find Visual Studio 2017 or newer, try re-running with '--loglevel silly' for more details. \n
276
+ Failure details: ${failureDetails}`)
277
+ return null
278
+ }
279
+
280
+ if (err) {
281
+ this.log.silly('PS err = %j', err && (err.stack || err))
282
+ return failPowershell(`${err}`.substring(0, 40))
283
+ }
284
+
285
+ let vsInfo
286
+ try {
287
+ vsInfo = JSON.parse(stdout)
288
+ } catch (e) {
289
+ this.log.silly('PS stdout = %j', stdout)
290
+ this.log.silly(e)
291
+ return failPowershell()
292
+ }
293
+
294
+ if (sanityOptions.checkIsArray && !Array.isArray(vsInfo)) {
295
+ this.log.silly('PS stdout = %j', stdout)
296
+ return failPowershell('Expected array as output of the PS script')
297
+ }
298
+ return vsInfo
299
+ }
300
+
301
+ // Process parsed data containing information about VS installations
302
+ // Look for the required parts, extract and output them back
303
+ processData (vsInfo, supportedYears) {
304
+ vsInfo = vsInfo.map((info) => {
305
+ this.log.silly(`processing installation: "${info.path}"`)
306
+ info.path = path.resolve(info.path)
307
+ const ret = this.getVersionInfo(info)
308
+ ret.path = info.path
309
+ ret.msBuild = this.getMSBuild(info, ret.versionYear)
310
+ ret.toolset = this.getToolset(info, ret.versionYear)
311
+ ret.sdk = this.getSDK(info)
312
+ return ret
313
+ })
314
+ this.log.silly('vsInfo:', vsInfo)
315
+
316
+ // Remove future versions or errors parsing version number
317
+ // Also remove any unsupported versions
318
+ vsInfo = vsInfo.filter((info) => {
319
+ if (info.versionYear && supportedYears.indexOf(info.versionYear) !== -1) {
320
+ return true
321
+ }
322
+ this.addLog(`${info.versionYear ? 'unsupported' : 'unknown'} version "${info.version}" found at "${info.path}"`)
323
+ return false
324
+ })
325
+
326
+ // Sort to place newer versions first
327
+ vsInfo.sort((a, b) => b.versionYear - a.versionYear)
328
+
329
+ for (let i = 0; i < vsInfo.length; ++i) {
330
+ const info = vsInfo[i]
331
+ this.addLog(`checking VS${info.versionYear} (${info.version}) found ` +
332
+ `at:\n"${info.path}"`)
333
+
334
+ if (info.msBuild) {
335
+ this.addLog('- found "Visual Studio C++ core features"')
336
+ } else {
337
+ this.addLog('- "Visual Studio C++ core features" missing')
338
+ continue
339
+ }
340
+
341
+ if (info.toolset) {
342
+ this.addLog(`- found VC++ toolset: ${info.toolset}`)
343
+ } else {
344
+ this.addLog('- missing any VC++ toolset')
345
+ continue
346
+ }
347
+
348
+ if (info.sdk) {
349
+ this.addLog(`- found Windows SDK: ${info.sdk}`)
350
+ } else {
351
+ this.addLog('- missing any Windows SDK')
352
+ continue
353
+ }
354
+
355
+ if (!this.checkConfigVersion(info.versionYear, info.path)) {
356
+ continue
357
+ }
358
+
359
+ return info
360
+ }
361
+
362
+ this.addLog(
363
+ 'could not find a version of Visual Studio 2017 or newer to use')
364
+ return null
365
+ }
366
+
367
+ // Helper - process version information
368
+ getVersionInfo (info) {
369
+ const match = /^(\d+)\.(\d+)(?:\..*)?/.exec(info.version)
370
+ if (!match) {
371
+ this.log.silly('- failed to parse version:', info.version)
372
+ return {}
373
+ }
374
+ this.log.silly('- version match = %j', match)
375
+ const ret = {
376
+ version: info.version,
377
+ versionMajor: parseInt(match[1], 10),
378
+ versionMinor: parseInt(match[2], 10)
379
+ }
380
+ if (ret.versionMajor === 15) {
381
+ ret.versionYear = 2017
382
+ return ret
383
+ }
384
+ if (ret.versionMajor === 16) {
385
+ ret.versionYear = 2019
386
+ return ret
387
+ }
388
+ if (ret.versionMajor === 17) {
389
+ ret.versionYear = 2022
390
+ return ret
391
+ }
392
+ this.log.silly('- unsupported version:', ret.versionMajor)
393
+ return {}
394
+ }
395
+
396
+ msBuildPathExists (path) {
397
+ return existsSync(path)
398
+ }
399
+
400
+ // Helper - process MSBuild information
401
+ getMSBuild (info, versionYear) {
402
+ const pkg = 'Microsoft.VisualStudio.VC.MSBuild.Base'
403
+ const msbuildPath = path.join(info.path, 'MSBuild', 'Current', 'Bin', 'MSBuild.exe')
404
+ const msbuildPathArm64 = path.join(info.path, 'MSBuild', 'Current', 'Bin', 'arm64', 'MSBuild.exe')
405
+ if (info.packages.indexOf(pkg) !== -1) {
406
+ this.log.silly('- found VC.MSBuild.Base')
407
+ if (versionYear === 2017) {
408
+ return path.join(info.path, 'MSBuild', '15.0', 'Bin', 'MSBuild.exe')
409
+ }
410
+ if (versionYear === 2019) {
411
+ if (process.arch === 'arm64' && this.msBuildPathExists(msbuildPathArm64)) {
412
+ return msbuildPathArm64
413
+ } else {
414
+ return msbuildPath
415
+ }
416
+ }
417
+ }
418
+ /**
419
+ * Visual Studio 2022 doesn't have the MSBuild package.
420
+ * Support for compiling _on_ ARM64 was added in MSVC 14.32.31326,
421
+ * so let's leverage it if the user has an ARM64 device.
422
+ */
423
+ if (process.arch === 'arm64' && this.msBuildPathExists(msbuildPathArm64)) {
424
+ return msbuildPathArm64
425
+ } else if (this.msBuildPathExists(msbuildPath)) {
426
+ return msbuildPath
427
+ }
428
+ return null
429
+ }
430
+
431
+ // Helper - process toolset information
432
+ getToolset (info, versionYear) {
433
+ const vcToolsArm64 = 'VC.Tools.ARM64'
434
+ const pkgArm64 = `Microsoft.VisualStudio.Component.${vcToolsArm64}`
435
+ const vcToolsX64 = 'VC.Tools.x86.x64'
436
+ const pkgX64 = `Microsoft.VisualStudio.Component.${vcToolsX64}`
437
+ const express = 'Microsoft.VisualStudio.WDExpress'
438
+
439
+ if (process.arch === 'arm64' && info.packages.includes(pkgArm64)) {
440
+ this.log.silly(`- found ${vcToolsArm64}`)
441
+ } else if (info.packages.includes(pkgX64)) {
442
+ if (process.arch === 'arm64') {
443
+ this.addLog(`- found ${vcToolsX64} on ARM64 platform. Expect less performance and/or link failure with ARM64 binary.`)
444
+ } else {
445
+ this.log.silly(`- found ${vcToolsX64}`)
446
+ }
447
+ } else if (info.packages.includes(express)) {
448
+ this.log.silly('- found Visual Studio Express (looking for toolset)')
449
+ } else {
450
+ return null
451
+ }
452
+
453
+ if (versionYear === 2017) {
454
+ return 'v141'
455
+ } else if (versionYear === 2019) {
456
+ return 'v142'
457
+ } else if (versionYear === 2022) {
458
+ return 'v143'
459
+ }
460
+ this.log.silly('- invalid versionYear:', versionYear)
461
+ return null
462
+ }
463
+
464
+ // Helper - process Windows SDK information
465
+ getSDK (info) {
466
+ const win8SDK = 'Microsoft.VisualStudio.Component.Windows81SDK'
467
+ const win10SDKPrefix = 'Microsoft.VisualStudio.Component.Windows10SDK.'
468
+ const win11SDKPrefix = 'Microsoft.VisualStudio.Component.Windows11SDK.'
469
+
470
+ let Win10or11SDKVer = 0
471
+ info.packages.forEach((pkg) => {
472
+ if (!pkg.startsWith(win10SDKPrefix) && !pkg.startsWith(win11SDKPrefix)) {
473
+ return
474
+ }
475
+ const parts = pkg.split('.')
476
+ if (parts.length > 5 && parts[5] !== 'Desktop') {
477
+ this.log.silly('- ignoring non-Desktop Win10/11SDK:', pkg)
478
+ return
479
+ }
480
+ const foundSdkVer = parseInt(parts[4], 10)
481
+ if (isNaN(foundSdkVer)) {
482
+ // Microsoft.VisualStudio.Component.Windows10SDK.IpOverUsb
483
+ this.log.silly('- failed to parse Win10/11SDK number:', pkg)
484
+ return
485
+ }
486
+ this.log.silly('- found Win10/11SDK:', foundSdkVer)
487
+ Win10or11SDKVer = Math.max(Win10or11SDKVer, foundSdkVer)
488
+ })
489
+
490
+ if (Win10or11SDKVer !== 0) {
491
+ return `10.0.${Win10or11SDKVer}.0`
492
+ } else if (info.packages.indexOf(win8SDK) !== -1) {
493
+ this.log.silly('- found Win8SDK')
494
+ return '8.1'
495
+ }
496
+ return null
497
+ }
498
+
499
+ // Find an installation of Visual Studio 2015 to use
500
+ async findVisualStudio2015 () {
501
+ if (this.nodeSemver.major >= 19) {
502
+ this.addLog(
503
+ 'not looking for VS2015 as it is only supported up to Node.js 18')
504
+ return null
505
+ }
506
+ return this.findOldVS({
507
+ version: '14.0',
508
+ versionMajor: 14,
509
+ versionMinor: 0,
510
+ versionYear: 2015,
511
+ toolset: 'v140'
512
+ })
513
+ }
514
+
515
+ // Find an installation of Visual Studio 2013 to use
516
+ async findVisualStudio2013 () {
517
+ if (this.nodeSemver.major >= 9) {
518
+ this.addLog(
519
+ 'not looking for VS2013 as it is only supported up to Node.js 8')
520
+ return null
521
+ }
522
+ return this.findOldVS({
523
+ version: '12.0',
524
+ versionMajor: 12,
525
+ versionMinor: 0,
526
+ versionYear: 2013,
527
+ toolset: 'v120'
528
+ })
529
+ }
530
+
531
+ // Helper - common code for VS2013 and VS2015
532
+ async findOldVS (info) {
533
+ const regVC7 = ['HKLM\\Software\\Microsoft\\VisualStudio\\SxS\\VC7',
534
+ 'HKLM\\Software\\Wow6432Node\\Microsoft\\VisualStudio\\SxS\\VC7']
535
+ const regMSBuild = 'HKLM\\Software\\Microsoft\\MSBuild\\ToolsVersions'
536
+
537
+ this.addLog(`looking for Visual Studio ${info.versionYear}`)
538
+ try {
539
+ let res = await this.regSearchKeys(regVC7, info.version, [])
540
+ const vsPath = path.resolve(res, '..')
541
+ this.addLog(`- found in "${vsPath}"`)
542
+ const msBuildRegOpts = process.arch === 'ia32' ? [] : ['/reg:32']
543
+
544
+ try {
545
+ res = await this.regSearchKeys([`${regMSBuild}\\${info.version}`], 'MSBuildToolsPath', msBuildRegOpts)
546
+ } catch (err) {
547
+ this.addLog('- could not find MSBuild in registry for this version')
548
+ return null
549
+ }
550
+
551
+ const msBuild = path.join(res, 'MSBuild.exe')
552
+ this.addLog(`- MSBuild in "${msBuild}"`)
553
+
554
+ if (!this.checkConfigVersion(info.versionYear, vsPath)) {
555
+ return null
556
+ }
557
+
558
+ info.path = vsPath
559
+ info.msBuild = msBuild
560
+ info.sdk = null
561
+ return info
562
+ } catch (err) {
563
+ this.addLog('- not found')
564
+ return null
565
+ }
566
+ }
567
+
568
+ // After finding a usable version of Visual Studio:
569
+ // - add it to validVersions to be displayed at the end if a specific
570
+ // version was requested and not found;
571
+ // - check if this is the version that was requested.
572
+ // - check if this matches the Visual Studio Command Prompt
573
+ checkConfigVersion (versionYear, vsPath) {
574
+ this.validVersions.push(versionYear)
575
+ this.validVersions.push(vsPath)
576
+
577
+ if (this.configVersionYear && this.configVersionYear !== versionYear) {
578
+ this.addLog('- msvs_version does not match this version')
579
+ return false
580
+ }
581
+ if (this.configPath &&
582
+ path.relative(this.configPath, vsPath) !== '') {
583
+ this.addLog('- msvs_version does not point to this installation')
584
+ return false
585
+ }
586
+ if (this.envVcInstallDir &&
587
+ path.relative(this.envVcInstallDir, vsPath) !== '') {
588
+ this.addLog('- does not match this Visual Studio Command Prompt')
589
+ return false
590
+ }
591
+
592
+ return true
593
+ }
594
+
595
+ async execFile (exec, args) {
596
+ return await execFile(exec, args, { encoding: 'utf8' })
597
+ }
598
+ }
599
+
600
+ module.exports = VisualStudioFinder