Skip to content

Commit

Permalink
Marshal dependencies from package.toml (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
c0d1ngm0nk3y authored Aug 20, 2024
1 parent 5099ee8 commit f099c5f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions package_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ type PackageJSON struct {
PreStart string
Start string
}
Dependencies map[string]string `json:"dependencies"`
DevDependencies map[string]string `json:"devDependencies"`

AllScripts map[string]string `json:"scripts"`
}
Expand Down
30 changes: 30 additions & 0 deletions package_json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,34 @@ func testPackageJSON(t *testing.T, context spec.G, it spec.S) {
})
})
})

context("ParseDependencies", func() {
it.Before(func() {
Expect(os.WriteFile(filePath, []byte(`{
"dependencies": {
"cpu-features": "0.0.4",
"express": "^4.18.2"
},
"devDependencies": {
"node-gyp": "^9.3.1"
}
}`), 0600)).To(Succeed())
})

it("parses the dependencies from a package.json file", func() {
pkg, err := libnodejs.ParsePackageJSON(workingDir)
Expect(err).NotTo(HaveOccurred())
Expect(pkg.Dependencies).To(HaveLen(2))
Expect(pkg.Dependencies).To(HaveKeyWithValue("express", "^4.18.2"))
})

it("parses the devDependencies from a package.json file", func() {
pkg, err := libnodejs.ParsePackageJSON(workingDir)
Expect(err).NotTo(HaveOccurred())
Expect(pkg.DevDependencies).To(HaveLen(1))
Expect(pkg.DevDependencies).To(HaveKeyWithValue("node-gyp", "^9.3.1"))
})

})

}

0 comments on commit f099c5f

Please sign in to comment.