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

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

Open
alestiago opened this issue Feb 1, 2024 · 0 comments
Open

Comments

@alestiago
Copy link
Collaborator

alestiago commented Feb 1, 2024

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

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

No branches or pull requests

1 participant