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
- Create a Mason brick with hooks (from .):
mason new my_brick --hooks
- Create a Dart package (from .):
dart create my_package -t package
- Add
my_package
as a path dependency tomy_brick
's hooks (from ./my_brick/hooks):
dart pub add 'my_package:{"path":"../../my_package"}'
- Create another Dart package to consume the bundle (from .):
dart create my_generator -t package
- Add mason as a dependency (from my_generator):
dart pub add mason
- Bundle
my_brick
(from my_generator):
mason bundle ../my_brick/ -t dart -o lib/
- 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'});
}
- 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