Conversation
|
|
||
| const errors = Object.entries(options).reduce( | ||
| (errors, [option, value]) => | ||
| !isNil(value) && !VALIDATORS[option](value) |
There was a problem hiding this comment.
isNil: https://github.com/lodash/lodash/blob/4.17.23/lodash.js#L12080
Note: We cannot use value != null since linter xo complains: Use === to compare with null. no-eq-null
|
|
||
| let verified; | ||
|
|
||
| const defaultTo = (value, defaultValue) => (Number.isNaN(value) ? null : value) ?? defaultValue; |
There was a problem hiding this comment.
defaultTo: https://github.com/lodash/lodash/blob/4.17.23/lodash.js#L15529
value !== value was replaced with more readable Number.isNaN(value)
| // If the Changelog prepare plugin is used and has `changelogFile` configured, validate them now in order to prevent any release if the configuration is wrong | ||
| if (options.prepare) { | ||
| const preparePlugin = | ||
| castArray(options.prepare).find((config) => config.path && config.path === '@semantic-release/changelog') || {}; |
There was a problem hiding this comment.
| const resolveConfig = require('./resolve-config.js'); | ||
| const {isStringObject} = require('util/types'); | ||
|
|
||
| const isString = (value) => typeof value === 'string' || isStringObject(value); |
There was a problem hiding this comment.
isString: https://github.com/lodash/lodash/blob/4.17.23/lodash.js#L12242
I've used typeof for primitives and util.types.isStringObject for boxed strings. Lodash’s manual tag-checking is somewhat outdated because it can be spoofed. Using util.types is the modern way to guarantee the value actually possesses the internal [[StringData]] slot, providing a more accurate type check without the Lodash dependency.
There was a problem hiding this comment.
I dug deeper into the Lodash source code and realized my previous point about spoofing was slightly off. Lodash actually uses a clever getRawTag mechanism to handle Symbol.toStringTag. While Lodash's isString is robust, its internal implementation (getRawTag) is quite heavy. It temporarily mutates Symbol.toStringTag on the object to retrieve the raw tag.
Using util.types.isStringObject is a much cleaner and more performant alternative in Node.js. It directly checks the internal [[StringData]] slot at the engine level without any side effects or the overhead of manual property manipulation.
This PR drops dependency to
lodashand replaces existing code to their equivalent counterparts.