Socket
Socket
Sign inDemoInstall

node-gyp

Package Overview
Dependencies
Maintainers
3
Versions
145
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-gyp - npm Package Compare versions

Comparing version 10.0.1 to 10.1.0

.release-please-manifest.json

28

lib/configure.js
'use strict'
const { promises: fs } = require('graceful-fs')
const { promises: fs, readFileSync } = require('graceful-fs')
const path = require('path')

@@ -16,2 +16,6 @@ const log = require('./log')

const majorRe = /^#define NODE_MAJOR_VERSION (\d+)/m
const minorRe = /^#define NODE_MINOR_VERSION (\d+)/m
const patchRe = /^#define NODE_PATCH_VERSION (\d+)/m
async function configure (gyp, argv) {

@@ -31,2 +35,24 @@ const buildDir = path.resolve('build')

if (!gyp.opts.nodedir &&
process.config.variables.use_prefix_to_find_headers) {
// check if the headers can be found using the prefix specified
// at build time. Use them if they match the version expected
const prefix = process.config.variables.node_prefix
let availVersion
try {
const nodeVersionH = readFileSync(path.join(prefix,
'include', 'node', 'node_version.h'), { encoding: 'utf8' })
const major = nodeVersionH.match(majorRe)[1]
const minor = nodeVersionH.match(minorRe)[1]
const patch = nodeVersionH.match(patchRe)[1]
availVersion = major + '.' + minor + '.' + patch
} catch {}
if (availVersion === release.version) {
// ok version matches, use the headers
gyp.opts.nodedir = prefix
log.verbose('using local node headers based on prefix',
'setting nodedir to ' + gyp.opts.nodedir)
}
}
if (gyp.opts.nodedir) {

@@ -33,0 +59,0 @@ // --nodedir was specified. use that for the dev files

2

lib/find-python.js

@@ -44,3 +44,3 @@ 'use strict'

log = log.withPrefix('find Python')
argsExecutable = ['-c', 'import sys; print(sys.executable);']
argsExecutable = ['-c', 'import sys; sys.stdout.buffer.write(sys.executable.encode(\'utf-8\'));']
argsVersion = ['-c', 'import sys; print("%s.%s.%s" % sys.version_info[:3]);']

@@ -47,0 +47,0 @@ semverRange = '>=3.6.0'

@@ -57,3 +57,6 @@ 'use strict'

const checks = [
() => this.findVisualStudio2017OrNewer(),
() => this.findVisualStudio2019OrNewerUsingSetupModule(),
() => this.findVisualStudio2019OrNewer(),
() => this.findVisualStudio2017UsingSetupModule(),
() => this.findVisualStudio2017(),
() => this.findVisualStudio2015(),

@@ -117,5 +120,80 @@ () => this.findVisualStudio2013()

async findVisualStudio2019OrNewerUsingSetupModule () {
return this.findNewVSUsingSetupModule([2019, 2022])
}
async findVisualStudio2017UsingSetupModule () {
if (this.nodeSemver.major >= 22) {
this.addLog(
'not looking for VS2017 as it is only supported up to Node.js 21')
return null
}
return this.findNewVSUsingSetupModule([2017])
}
async findNewVSUsingSetupModule (supportedYears) {
const ps = path.join(process.env.SystemRoot, 'System32',
'WindowsPowerShell', 'v1.0', 'powershell.exe')
const vcInstallDir = this.envVcInstallDir
const checkModuleArgs = [
'-NoProfile',
'-Command',
'&{@(Get-Module -ListAvailable -Name VSSetup).Version.ToString()}'
]
this.log.silly('Running', ps, checkModuleArgs)
const [cErr] = await this.execFile(ps, checkModuleArgs)
if (cErr) {
this.addLog('VSSetup module doesn\'t seem to exist. You can install it via: "Install-Module VSSetup -Scope CurrentUser"')
this.log.silly('VSSetup error = %j', cErr && (cErr.stack || cErr))
return null
}
const filterArg = vcInstallDir !== undefined ? `| where {$_.InstallationPath -eq '${vcInstallDir}' }` : ''
const psArgs = [
'-NoProfile',
'-Command',
`&{Get-VSSetupInstance ${filterArg} | ConvertTo-Json -Depth 3}`
]
this.log.silly('Running', ps, psArgs)
const [err, stdout, stderr] = await this.execFile(ps, psArgs)
let parsedData = this.parseData(err, stdout, stderr)
if (parsedData === null) {
return null
}
this.log.silly('Parsed data', parsedData)
if (!Array.isArray(parsedData)) {
// if there are only 1 result, then Powershell will output non-array
parsedData = [parsedData]
}
// normalize output
parsedData = parsedData.map((info) => {
info.path = info.InstallationPath
info.version = `${info.InstallationVersion.Major}.${info.InstallationVersion.Minor}.${info.InstallationVersion.Build}.${info.InstallationVersion.Revision}`
info.packages = info.Packages.map((p) => p.Id)
return info
})
// pass for further processing
return this.processData(parsedData, supportedYears)
}
// Invoke the PowerShell script to get information about Visual Studio 2019
// or newer installations
async findVisualStudio2019OrNewer () {
return this.findNewVS([2019, 2022])
}
// Invoke the PowerShell script to get information about Visual Studio 2017
async findVisualStudio2017 () {
if (this.nodeSemver.major >= 22) {
this.addLog(
'not looking for VS2017 as it is only supported up to Node.js 21')
return null
}
return this.findNewVS([2017])
}
// Invoke the PowerShell script to get information about Visual Studio 2017
// or newer installations
async findVisualStudio2017OrNewer () {
async findNewVS (supportedYears) {
const ps = path.join(process.env.SystemRoot, 'System32',

@@ -133,14 +211,25 @@ 'WindowsPowerShell', 'v1.0', 'powershell.exe')

this.log.silly('Running', ps, psArgs)
const [err, stdout, stderr] = await execFile(ps, psArgs, { encoding: 'utf8' })
return this.parseData(err, stdout, stderr)
const [err, stdout, stderr] = await this.execFile(ps, psArgs)
const parsedData = this.parseData(err, stdout, stderr, { checkIsArray: true })
if (parsedData === null) {
return null
}
return this.processData(parsedData, supportedYears)
}
// Parse the output of the PowerShell script and look for an installation
// of Visual Studio 2017 or newer to use
parseData (err, stdout, stderr) {
// Parse the output of the PowerShell script, make sanity checks
parseData (err, stdout, stderr, sanityCheckOptions) {
const defaultOptions = {
checkIsArray: false
}
// Merging provided options with the default options
const sanityOptions = { ...defaultOptions, ...sanityCheckOptions }
this.log.silly('PS stderr = %j', stderr)
const failPowershell = () => {
const failPowershell = (failureDetails) => {
this.addLog(
'could not use PowerShell to find Visual Studio 2017 or newer, try re-running with \'--loglevel silly\' for more details')
`could not use PowerShell to find Visual Studio 2017 or newer, try re-running with '--loglevel silly' for more details. \n
Failure details: ${failureDetails}`)
return null

@@ -151,3 +240,3 @@ }

this.log.silly('PS err = %j', err && (err.stack || err))
return failPowershell()
return failPowershell(`${err}`.substring(0, 40))
}

@@ -164,7 +253,12 @@

if (!Array.isArray(vsInfo)) {
if (sanityOptions.checkIsArray && !Array.isArray(vsInfo)) {
this.log.silly('PS stdout = %j', stdout)
return failPowershell()
return failPowershell('Expected array as output of the PS script')
}
return vsInfo
}
// Process parsed data containing information about VS installations
// Look for the required parts, extract and output them back
processData (vsInfo, supportedYears) {
vsInfo = vsInfo.map((info) => {

@@ -183,7 +277,8 @@ this.log.silly(`processing installation: "${info.path}"`)

// Remove future versions or errors parsing version number
// Also remove any unsupported versions
vsInfo = vsInfo.filter((info) => {
if (info.versionYear) {
if (info.versionYear && supportedYears.indexOf(info.versionYear) !== -1) {
return true
}
this.addLog(`unknown version "${info.version}" found at "${info.path}"`)
this.addLog(`${info.versionYear ? 'unsupported' : 'unknown'} version "${info.version}" found at "${info.path}"`)
return false

@@ -447,4 +542,8 @@ })

}
async execFile (exec, args) {
return await execFile(exec, args, { encoding: 'utf8' })
}
}
module.exports = VisualStudioFinder

@@ -14,3 +14,3 @@ {

],
"version": "10.0.1",
"version": "10.1.0",
"installVersion": 11,

@@ -17,0 +17,0 @@ "author": "Nathan Rajlich <nathan@tootallnate.net> (http://tootallnate.net)",

@@ -14,5 +14,4 @@ # `node-gyp` - Node.js native addon build tool

Multiple target versions of Node.js are supported (i.e. `0.8`, ..., `4`, `5`, `6`,
etc.), regardless of what version of Node.js is actually installed on your system
(`node-gyp` downloads the necessary development files or headers for the target version).
All current and LTS target versions of Node.js are supported. Depending on what version of Node.js is actually installed on your system
`node-gyp` downloads the necessary development files or headers for the target version. List of stable Node.js versions can be found on [Node.js website](https://nodejs.org/en/about/previous-releases).

@@ -54,5 +53,3 @@ ## Features

Install tools and configuration manually:
* Install Visual C++ Build Environment: [Visual Studio Build Tools](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=BuildTools)
(using "Visual C++ build tools" if using a version older than VS2019, otherwise use "Desktop development with C++" workload) or [Visual Studio Community](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=Community)
(using the "Desktop development with C++" workload)
* Install Visual C++ Build Environment: For Visual Studio 2019 or later, use the `Desktop development with C++` workload from [Visual Studio Community](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=Community). For a version older than Visual Studio 2019, install [Visual Studio Build Tools](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=BuildTools) with the `Visual C++ build tools` option.

@@ -65,2 +62,5 @@ If the above steps didn't work for you, please visit [Microsoft's Node.js Guidelines for Windows](https://github.com/Microsoft/nodejs-guidelines/blob/master/windows-environment.md#compiling-native-addon-modules) for additional tips.

It's advised to install following Powershell module: [VSSetup](https://github.com/microsoft/vssetup.powershell) using `Install-Module VSSetup -Scope CurrentUser`.
This will make Visual Studio detection logic to use more flexible and accessible method, avoiding Powershell's `ConstrainedLanguage` mode.
### Configuring Python Dependency

@@ -67,0 +67,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc