Skip to content
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

[Proposal] Local hooks for pub publish validations #4058

Open
jonasfj opened this issue Nov 28, 2023 · 5 comments
Open

[Proposal] Local hooks for pub publish validations #4058

jonasfj opened this issue Nov 28, 2023 · 5 comments
Labels
type-enhancement A request for a change that isn't a bug

Comments

@jonasfj
Copy link
Member

jonasfj commented Nov 28, 2023

When running a Dart command like:

  • dart pub get
  • dart pub publish
  • dart test
  • dart analyze

It'd be really nice if it's possible to do hook into these commands from the root package.

Example:
Some packages may have a build or code-generation script that must run before the package is published.
It'd be nice if it was possible to make a hook/publish.dart script that is invoked by dart pub publish whenever the command is called.

Proposal: Invoke hook/<command>.dart from dart <command>

The proposal is fairly simple, we invoke hook/<command>.dart from dart <command>.
Perhaps we limit this to select commands, so that not all commands can be hooked, for example:

  • dart test would invoke hook/test.dart which could be used to:
    • Setup test environment
    • Build the program that should be tested
    • Download resources required for testing
    • Run tests that are not written using package:test
  • dart pub publish would invoke hook/publish.dart which could be used to:
    • Build native assets that you want to ship as binary artifacts in the package.
    • Build devtools extensions where you want to ship a prebuilt flutter web application.

Alternatives: dart run :<command> or tool/

Today the tool/ folder is codified as something to be used for scripts used during development.
Of course, that means you have to remember to use those tools. Having hooks that are automatically called, might be easier to remember and it might make it easier for other team members to remember to invoke these tools.

Creating a tool/publish.dart which does a build process and then calls dart pub publish is not a bad idea, but there is some risk that you or a teammate will forget about it and call dart pub publish directly instead.

Another alternative option today is to write commands in bin/<command>.dart and call these using dart run :<command> this have the same downside as tool/ (namely you have to remember to use it). But dart run will take care to fetch dependencies and such.
However, if you are publishing a package then the bin/ commands will also be available to people consuming your package, and this might not be desirable (especially for pre-publish build script).


Please upvote this issue, if you think this is a useful feature.

I think it's reasonable to be concerned that this quickly gets too complicated, and that it becomes hard to reason about what a command does when developing locally.

@jonasfj
Copy link
Member Author

jonasfj commented Nov 28, 2023

Note: This would have implications that makes it harder SLSA attestations with automated publishing as we'd probably want to run such publish-hook in a non-networked environment.

@sigurdm
Copy link
Contributor

sigurdm commented Nov 28, 2023

Just to be clear - you are not suggesting here that dependencies can define hooks that automatically get get executed?

@sigurdm
Copy link
Contributor

sigurdm commented Nov 28, 2023

I think this makes a lot of sense for pub publish such that you can set up your own validations.

It makes some sense for dart test. Though I think this should really be a feature in package:test....

For pub get I cannot see any good use-cases. Do you have any?

I don't think it makes sense to have hooks for pub add, pub upgrade, pub deps, pub cache ..., pub downgrade, pub token, global ... login, logout ....

@sigurdm
Copy link
Contributor

sigurdm commented Nov 28, 2023

Btw. the hook for dart test is probably an sdk feature - not a pub client feature.

@sigurdm
Copy link
Contributor

sigurdm commented Apr 9, 2024

I think we can narrow the scope of this issue to be just hooks for pub publish.

@sigurdm sigurdm changed the title [Proposal] Local hooks in pub get / publish / dart test / etc [Proposal] Local hooks for pub publish validations Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

2 participants