这是indexloc提供的服务,不要输入任何密码
Skip to content

fix: hook stuck when installed via git #1573

@Joschiller

Description

@Joschiller

Description

We have the following scenario:

  • Our brick contains a pre-hook that prints out some metadata (e.g. project directory) and injects it into the template files of the brick.
  • When installing the brick locally via a file-path, running the brick works fine (console output is visible and files are generated).
  • When installing the brick from a git repository, running the brick leads to a stuck console. Not even the log output of the hook is visible.

If we install any other brick without any hook via git, these bricks work just fine.

Steps To Reproduce

  1. Create a brick with a pre hook and push it to a git repository
  2. Install the brick via the git-url in another project
  3. Run the brick

Expected Behavior

The pre hook should be executed, even if the corresponding brick was installed via git.

Screenshots

none

Additional Context

Contents of our pre-hook. Purpose: retrieving the package name from the pubspec.yaml.

import 'dart:io';

import 'package:mason/mason.dart';
import 'package:yaml/yaml.dart';

const pubspecYamlName = 'pubspec.yaml';
Future<File?> _getPackageYaml(HookContext context) async {
  var directory = Directory.current;

  var depth = 5;
  do {
    try {
      context.logger.info(directory.path);
      final yaml = (await directory
          .list()
          .firstWhere((file) => file.path.endsWith(pubspecYamlName)));
      return File(yaml.absolute.path);
    } catch (_) {
      directory = directory.parent;
      depth--;
    }
  } while (depth > 0);
  return null;
}

void run(HookContext context) async {
  final yamlFile = await _getPackageYaml(context);
  if (yamlFile != null) {
    context.logger.info('Füge $pubspecYamlName-Inhalt unter "package" ein.');
    final data = loadYaml(await yamlFile.readAsString());
    context.vars.putIfAbsent('package', () => data);
  }
}

I am quite sure, that the combination of hook + git integration is the reason for the problem as all our bricks work just fine if just one of those are used.

Environment: Windows 10, Flutter 3.32.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingquestionFurther information is requestedwaiting for responseWaiting for additional information

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions