Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

Commit

Permalink
fixup! fixup! WIP feat: make lockfileVersion configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Oct 12, 2021
1 parent 1672d69 commit 3098028
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions lib/shrinkwrap.js
Expand Up @@ -895,31 +895,32 @@ class Shrinkwrap {
}
}

// if we haven't set it by now, use the default
if (!this.lockfileVersion) {
this.lockfileVersion = defaultLockfileVersion
}
this.data.lockfileVersion = this.lockfileVersion

// hidden lockfiles don't include legacy metadata or a root entry
if (this.hiddenLockfile) {
delete this.data.packages['']
delete this.data.dependencies
} else if (this.tree) {
} else if (this.tree && this.lockfileVersion <= 3) {
this[_buildLegacyLockfile](this.tree, this.data)
}

// if we haven't set it by now, use the default
if (!this.lockfileVersion) {
this.lockfileVersion = defaultLockfileVersion
}
this.data.lockfileVersion = this.lockfileVersion

const data = { ...this.data }
// lf version 1 = dependencies only
// lf version 2 = dependencies and packages
// lf version 3 = packages only
if (this.lockfileVersion >= 3) {
delete data.dependencies
const { dependencies, ...data } = this.data
return data
} else if (this.lockfileVersion < 2) {
delete data.packages
const { packages, ...data } = this.data
return data
} else {
return { ...this.data }
}

return data
}

[_buildLegacyLockfile] (node, lock, path = []) {
Expand Down

0 comments on commit 3098028

Please sign in to comment.