felangel / felangel/mason

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

Open
#1,238 0 comments 0 reactions 0 assignees View on GitHub
customer:🦄
Dominant language
Dart
Stars
1.1k
Forks
113
PR merge metrics
No merged PRs in 30d

Description

**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:

```txt
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 .):
```sh
mason new my_brick --hooks
```

2. Create a Dart package (from .):
```sh
dart create my_package -t package
```

3. Add `my_package` as a path dependency to `my_brick`'s hooks (from ./my_brick/hooks):
```sh
dart pub add 'my_package:{"path":"../../my_package"}'
```

4. Create another Dart package to consume the bundle (from .):
```sh
dart create my_generator -t package
```

5. Add mason as a dependency (from my_generator):
```sh
dart pub add mason
```

6. Bundle `my_brick` (from my_generator):
```sh
mason bundle ../my_brick/ -t dart -o lib/
```

7. Attempt to generate hook from bundle (from my_generator/lib/my_genreator.dart):
```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'});
}
```

8. Running `my_generator.dart` fails since Mason is unable to install dependencies for hook:
```sh
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**

- #382

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.