Skip to content

Commit

Permalink
fix: remove dependency on lodash.isplainobject
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Jan 22, 2024
1 parent 7d24eab commit aa65731
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
3 changes: 1 addition & 2 deletions lib/appCMakeJSConfig.js
@@ -1,14 +1,13 @@
'use strict'
const path = require('path')
const isPlainObject = require('lodash.isplainobject')

function getConfig(lookPath, log) {
const pjsonPath = path.join(lookPath, 'package.json')
log.silly('CFG', "Looking for package.json in: '" + pjsonPath + "'.")
try {
const json = require(pjsonPath)
log.silly('CFG', 'Loaded:\n' + JSON.stringify(json))
if (isPlainObject(json) && isPlainObject(json['cmake-js'])) {
if (json && json['cmake-js'] && typeof json['cmake-js'] === 'object') {
log.silly('CFG', 'Config found.')
return json['cmake-js']
} else {
Expand Down
20 changes: 9 additions & 11 deletions lib/buildSystem.js
Expand Up @@ -5,7 +5,6 @@ const CMLog = require('./cmLog')
const appCMakeJSConfig = require('./appCMakeJSConfig')
const npmConfig = require('./npmConfig')
const path = require('path')
const isPlainObject = require('lodash.isplainobject')
const Toolset = require('./toolset')

function isNodeApi(log, projectRoot) {
Expand All @@ -29,20 +28,19 @@ class BuildSystem {
const appConfig = appCMakeJSConfig(this.options.directory, this.log)
const npmOptions = npmConfig(this.log)

if (isPlainObject(npmOptions) && Object.keys(npmOptions).length) {
if (npmOptions && typeof npmOptions === 'object' && Object.keys(npmOptions).length) {
this.options.runtimeDirectory = npmOptions['nodedir']
this.options.msvsVersion = npmOptions['msvs_version']
}
if (isPlainObject(appConfig)) {
if (Object.keys(appConfig).length) {
this.log.verbose('CFG', 'Applying CMake.js config from root package.json:')
this.log.verbose('CFG', JSON.stringify(appConfig))
// Applying applications's config, if there is no explicit runtime related options specified
this.options.runtime = this.options.runtime || appConfig.runtime
this.options.runtimeVersion = this.options.runtimeVersion || appConfig.runtimeVersion
this.options.arch = this.options.arch || appConfig.arch
}
if (appConfig && typeof appConfig === 'object' && Object.keys(appConfig).length) {
this.log.verbose('CFG', 'Applying CMake.js config from root package.json:')
this.log.verbose('CFG', JSON.stringify(appConfig))
// Applying applications's config, if there is no explicit runtime related options specified
this.options.runtime = this.options.runtime || appConfig.runtime
this.options.runtimeVersion = this.options.runtimeVersion || appConfig.runtimeVersion
this.options.arch = this.options.arch || appConfig.arch
}

this.log.verbose('CFG', 'Build system options:')
this.log.verbose('CFG', JSON.stringify(this.options))
this.cmake = new CMake(this.options)
Expand Down
8 changes: 5 additions & 3 deletions lib/runtimePaths.js
@@ -1,7 +1,6 @@
'use strict'
const assert = require('assert')
const semver = require('semver')
const isPlainObject = require('lodash.isplainobject')

const NODE_MIRROR = process.env.NVM_NODEJS_ORG_MIRROR || 'https://nodejs.org/dist'
const ELECTRON_MIRROR = process.env.ELECTRON_MIRROR || 'https://artifacts.electronjs.org/headers/dist'
Expand Down Expand Up @@ -83,8 +82,11 @@ const runtimePaths = {
const runtime = targetOptions.runtime
const func = runtimePaths[runtime]
let paths
if (typeof func === 'function' && isPlainObject((paths = func(targetOptions)))) {
return paths
if (typeof func === 'function') {
paths = func(targetOptions)
if (paths && typeof 'paths' === 'object') {
return paths
}
}
throw new Error('Unknown runtime: ' + runtime)
},
Expand Down
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -44,7 +44,6 @@
"axios": "^1.6.5",
"debug": "^4",
"fs-extra": "^11.2.0",
"lodash.isplainobject": "^4.0.6",
"memory-stream": "^1.0.0",
"node-api-headers": "^1.1.0",
"npmlog": "^6.0.2",
Expand Down

0 comments on commit aa65731

Please sign in to comment.