Skip to content

Refuse to publish packages that import dev dependencies #4567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

gideongrinberg
Copy link

This PR fixes #3143 by throwing an error when gleam publish is invoked and a dev dependency is imported in the code.

The check is implemented in do_build_hex_tarball. Another approach would be to implement the check in the analysis phase, but, as far as I can tell, there's no way to detect if the compilation has been invoked by gleam publish or something else.

I manually tested this and it works as expected, but I can add tests as well.

@gideongrinberg
Copy link
Author

@gideongrinberg
Copy link
Author

@inoas are there additional changes you think I should make?

@gideongrinberg
Copy link
Author

Sorry, I didn't mean to close that – are there any changes you are still looking for?

@lpil
Copy link
Member

lpil commented May 28, 2025

Hello! Sorry for taking so long to review this. I've got a bit caught up in this current release. I'll get to this once v1.11 is out!

@gideongrinberg
Copy link
Author

Thanks, not a problem. I see that the merge commit (I accidentially synced my branch with main) is causing the CI failure. Should I revert the merge?

@GearsDatapacks
Copy link
Member

You'll need to rebase instead, and remove the merge commit before this is merged.

Copy link
Member

@lpil lpil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thank you! I've left some notes inline

for (imported_module, _) in &module.dependencies {
if let Some(import_info) = built.module_interfaces.get(imported_module) {
let package = &import_info.package;
if dev_dependencies.contains(&package) && module.origin == Origin::Src {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dev_dependencies.contains(&package) isn't enough to determine if it's a dev dep or not because it could be a transient dev dependency, which would not be in this list.

If we are going to use this approach we'll need to before this reject the package if it using transient deps.


for module in built.root_package.modules.iter() {
for (imported_module, _) in &module.dependencies {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is cool but I think we could improve it!

src/ code shouldn't ever really use dev dependencies, so we should make it emit a warning when this happens (as an error would be a breaking change).

In the checking for this during we code analysis can record on modules if they use dev deps or transient deps or not, and then in gleam publish and gleam export erlang-shipment we can return an error by checking this flag on the module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compiler should refuse to publish a package that uses a dev-dependency in its source
4 participants