Skip to content

Commit

Permalink
feat: add fromContent method to set contents directly
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Apr 22, 2024
1 parent 9597b84 commit e1cf483
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ class PackageJson {
return this
}

fromContent (data) {
this.#manifest = data
this.#canSave = false
return this
}

// Load data from a comment
// /**package { "name": "foo", "version": "1.2.3", ... } **/
fromComment (data) {
Expand Down
5 changes: 5 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,8 @@ t.test('cannot update with no content', async t => {
message: /Can not update without content/,
})
})

t.test('can set data', async t => {
const p = new PackageJson().fromContent({ data: 1 })
t.strictSame(p.content, { data: 1 })
})

0 comments on commit e1cf483

Please sign in to comment.