From f099c5faa48f15339308017432e92876f3fc50e9 Mon Sep 17 00:00:00 2001 From: Ralf Pannemans Date: Tue, 20 Aug 2024 23:18:35 +0200 Subject: [PATCH] Marshal dependencies from package.toml (#33) --- package_json.go | 2 ++ package_json_test.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/package_json.go b/package_json.go index b33f00e..2a1ff1e 100644 --- a/package_json.go +++ b/package_json.go @@ -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"` } diff --git a/package_json_test.go b/package_json_test.go index e6f3af5..815d4da 100644 --- a/package_json_test.go +++ b/package_json_test.go @@ -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")) + }) + + }) + }