Skip to content

Commit

Permalink
Support package.json devdependencies on publish (#45)
Browse files Browse the repository at this point in the history
When I published the JavaScript packages I noticed the
`@appsignal/types` package had to versions in `yarn.lock`.
This was because the package was specified in the `devdependencies` of
the `@appsignal/plugin-breadcrumbs-console` package. Mono only checked
the `dependencies` and `optionalDependencies`, so the package version
was not updated.

This was not really a problem because it's only used during development
and testing, but it's not good to not update the package version and
possibly keep testing against an older version.

This change will update any package in the workspace listed in
`devdependencies` upon `mono publish`.
  • Loading branch information
tombruijn authored Feb 14, 2022
1 parent 43c92f7 commit bdbbcf5
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changesets/support-node-js-devdependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
bump: "patch"
type: "add"
---

Support Node.js package.json `devDependencies`. Any package in the workspace that's specified as a dev dependency by other packages are also updated upon publish.
3 changes: 2 additions & 1 deletion lib/mono/languages/nodejs/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def dependencies
begin
deps = @package_json.fetch("dependencies", {})
optional_deps = @package_json.fetch("optionalDependencies", {})
deps.merge(optional_deps)
dev_deps = @package_json.fetch("devDependencies", {})
deps.merge(optional_deps).merge(dev_deps)
end
end

Expand Down
47 changes: 44 additions & 3 deletions spec/lib/mono/languages/nodejs/package_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,54 @@
)
end
end

context "with optionalDependencies" do
it "returns dependencies hash" do
package_name = "test_package"
create_package_with_dependencies package_name,
:dependencies => {
"lodash" => "4.17.21"
},
:optionalDependencies => {
"tslib" => "2.2.1"
}

package = package_for_path(package_name)
expect(package.dependencies).to eql(
"lodash" => "4.17.21",
"tslib" => "2.2.1"
)
end
end

context "with devDependencies" do
it "returns dependencies hash" do
package_name = "test_package"
create_package_with_dependencies package_name,
:dependencies => {
"lodash" => "4.17.21"
},
:devDependencies => {
"tslib" => "2.2.2"
}

package = package_for_path(package_name)
expect(package.dependencies).to eql(
"lodash" => "4.17.21",
"tslib" => "2.2.2"
)
end
end
end

def create_package_with_dependencies(path, version: "1.2.3", dependencies: {})
def create_package_with_dependencies(
path,
version: "1.2.3",
**options
)
prepare_new_project do
create_package path do
create_package_json :version => version,
:dependencies => dependencies
create_package_json({ :version => version }.merge(options))
end
end
end
Expand Down

0 comments on commit bdbbcf5

Please sign in to comment.