Skip to content

Commit

Permalink
Remove optional dep from prod in reify
Browse files Browse the repository at this point in the history
- If optional dep installs, remove from prod array in lockfile
- If optional dep fails install, keep in prod array in lockfile
  • Loading branch information
rahulio96 committed Sep 8, 2024
1 parent fefd509 commit 235d698
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion workspaces/arborist/lib/arborist/reify.js
Original file line number Diff line number Diff line change
Expand Up @@ -1295,7 +1295,8 @@ module.exports = cls => class Reifier extends cls {

const updatedTrees = new Set()
const updateNodes = nodes => {
for (const { name, tree: addTree } of nodes) {
for (const node of nodes) {
const { name, tree: addTree } = node
// addTree either the root, or a workspace
const edge = addTree.edgesOut.get(name)
const pkg = addTree.package
Expand Down Expand Up @@ -1371,15 +1372,25 @@ module.exports = cls => class Reifier extends cls {
newSpec = req.saveSpec
}

// delete optional dep from prod if installation doesn't fail
const shouldDeleteFromProd = pkg.optionalDependencies && pkg.optionalDependencies[name] && pkg.dependencies
&& !this[_trashList].has(addTree.children.get(name).path)

if (options.saveType) {
const depType = saveTypeMap.get(options.saveType)
pkg[depType][name] = newSpec
// rpj will have moved it here if it was in both
// if it is empty it will be deleted later
if (options.saveType === 'prod' && pkg.optionalDependencies) {
delete pkg.optionalDependencies[name]
} else if (options.saveType === 'optional' && shouldDeleteFromProd) {
delete pkg.dependencies[name]
}
} else {
if (shouldDeleteFromProd) {
delete pkg.dependencies[name]
}

if (hasSubKey(pkg, 'dependencies', name)) {
pkg.dependencies[name] = newSpec
}
Expand Down

0 comments on commit 235d698

Please sign in to comment.