@npmcli/arborist 4.1.2 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/shrinkwrap.js +15 -4
  2. package/package.json +1 -1
package/lib/shrinkwrap.js CHANGED
@@ -1085,18 +1085,29 @@ class Shrinkwrap {
1085
1085
  return lock
1086
1086
  }
1087
1087
 
1088
- save (options = {}) {
1088
+ toJSON () {
1089
1089
  if (!this.data) {
1090
- throw new Error('run load() before saving data')
1090
+ throw new Error('run load() before getting or setting data')
1091
1091
  }
1092
1092
 
1093
+ return this.commit()
1094
+ }
1095
+
1096
+ toString (options = {}) {
1097
+ const data = this.toJSON()
1093
1098
  const { format = true } = options
1094
1099
  const defaultIndent = this.indent || 2
1095
1100
  const indent = format === true ? defaultIndent
1096
1101
  : format || 0
1097
1102
  const eol = format ? this.newline || '\n' : ''
1098
- const data = this.commit()
1099
- const json = stringify(data, swKeyOrder, indent).replace(/\n/g, eol)
1103
+ return stringify(data, swKeyOrder, indent).replace(/\n/g, eol)
1104
+ }
1105
+
1106
+ save (options = {}) {
1107
+ if (!this.data) {
1108
+ throw new Error('run load() before saving data')
1109
+ }
1110
+ const json = this.toString(options)
1100
1111
  return Promise.all([
1101
1112
  writeFile(this.filename, json).catch(er => {
1102
1113
  if (this.hiddenLockfile) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@npmcli/arborist",
3
- "version": "4.1.2",
3
+ "version": "4.2.0",
4
4
  "description": "Manage node_modules trees",
5
5
  "dependencies": {
6
6
  "@isaacs/string-locale-compare": "^1.1.0",