felangel / mason

Tools which allow developers to create and consume reusable templates called bricks.

Home Page:https://docs.brickhub.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

fix: allow bundling path dependencies that are not within hook path

alestiago opened this issue · comments

Description

When bundling, a hook can't depend on a dependency which is sourced from a path that is not within the hook's path.

Example

If you have the following directory structure, you will be unable to completly bundle the brick:

my_brick/
├─ hooks/
│  ├─ pubspec.yaml # Depends on ../../my_models
my_models/
├─ pubspec.yaml
my_package/
├─ pubspec.yaml # Depends on ../my_models

Reproductive steps

  1. Create a Mason brick with hooks (from .):
mason new my_brick --hooks
  1. Create a Dart package (from .):
dart create my_package -t package 
  1. Add my_package as a path dependency to my_brick's hooks (from ./my_brick/hooks):
dart pub add 'my_package:{"path":"../../my_package"}'
  1. Create another Dart package to consume the bundle (from .):
dart create my_generator -t package
  1. Add mason as a dependency (from my_generator):
dart pub add mason
  1. Bundle my_brick (from my_generator):
mason bundle ../my_brick/ -t dart -o lib/
  1. Attempt to generate hook from bundle (from my_generator/lib/my_genreator.dart):
// lib/my_generator.dart

import 'package:mason/mason.dart';
import 'package:my_generator/my_brick_bundle.dart';

void main() async {
  final generator = await MasonGenerator.fromBundle(myBrickBundle);
  await generator.hooks.preGen(vars: {'name': 'Dash'});
}
  1. Running my_generator.dart fails since Mason is unable to install dependencies for hook:
dart lib/my_generator.dart
# Unable to install dependencies for hook [...]

Note: Optionally, you can simply bundle my_brick and unbundle to see that the path dependencies not within the hook are not bundled. Performing a dart pub get on the unbundled hooks will also fail.

Expected behaviour

As a developer, I expect to be able to use a bundle in MasonBundle even if the hook has a path dependency of a package that is not within the hook.

Additional Context