Skip to content

🪝 [breaking change] Reserve top-level hook/ directory 🪝  #54334

Closed
@dcharkes

Description

@dcharkes

Change intent

(edit: Updated 2024-01-24 to reflect use of the hook/ toplevel directory.)

A package toplevel hook/ directory will be reserved for scripts run by the Dart and Flutter SDK at specific lifecycle events with a specific commandline API.

Examples:

  • hook/build.dart will be run before kernel compilation of Dart packages.
  • hook/link.dart will be run after kernel compilation of Dart packages, before making an application bundle.

If these scripts exist, they will be invoked by the Dart and Flutter build systems.

If these scripts exist, they must implement the commandline API.

For more context:

For more

Justification

Other languages standardize on a top level build script that builds code in other languages.

Most notably Rust defines a top level build.rs in packages to build native non-Rust code.

Reasoning for using hook/build.dart and hook/link.dart in Dart.

  • A Dart package public surface is the lib/ and bin/ directory. But build scripts should not be part of the programmatic or CLI API of a package.
  • A package private scripts reside in tool/. But build scripts should be run from the context outside that package itself.
  • The build/ directory is already reserved in Flutter. So nesting the build script inside the build/ directory doesn't work.

Alternatives considered

Impact

Anyone using a top level hook/ directory will need to migrate to a different file name.

We are aware of one use:

Mitigation

Migrate existing uses of hook/ to tool/, which is probably what those scripts are.

Action items after accepting proposal:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Complete

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions