Skip to content

feat: add after build command option#77

Open
francescoberardi wants to merge 1 commit into
kevmoo:masterfrom
francescoberardi:after-build-command
Open

feat: add after build command option#77
francescoberardi wants to merge 1 commit into
kevmoo:masterfrom
francescoberardi:after-build-command

Conversation

@francescoberardi
Copy link
Copy Markdown

Introduced an optional command that will be executed after the build_runner execution

@kevmoo
Copy link
Copy Markdown
Owner

kevmoo commented Jul 17, 2025

Delete the workspace file. Add a test?

@francescoberardi
Copy link
Copy Markdown
Author

Thanks for the review, I updated the PR with your inputs

@kevmoo
Copy link
Copy Markdown
Owner

kevmoo commented Nov 11, 2025

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces an afterBuildCommand option, allowing a command to be run after the build process. The implementation is sound and is accompanied by a comprehensive set of integration tests that cover various success and failure scenarios. I've provided a couple of suggestions to address code duplication in both the implementation and the tests to enhance maintainability. Overall, this is a valuable addition.

Comment thread lib/src/impl.dart
Comment on lines +59 to +68
if (afterBuildCommand != null && afterBuildCommand.isNotEmpty) {
var executable = afterBuildCommand.first;
if (executable == 'DART') {
executable = dartPath;
}

final arguments = afterBuildCommand.skip(1).toList();

await _runProc(executable, arguments, workingDir);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logic to parse the command, resolve the DART placeholder, and prepare arguments is duplicated from lines 46-52 where the main command is processed. To improve maintainability and avoid redundancy, consider extracting this logic into a private helper function. This function could take a List<String> command and either run the process directly or return the prepared executable and arguments.

Comment on lines +93 to +131
group('afterBuildCommand when a file changes', () {
const pubspecLockFileName = 'pubspec.lock';

setUp(() async {
await gitDir.runCommand(['add', pubspecLockFileName]);
await gitDir.runCommand(['commit', '-am', 'commit pubspec']);
});

test('should fail if afterBuildCommand produces git changes', () async {
final afterBuildCommand = [
'sh',
'-c',
'echo "new content just for this test" > $pubspecLockFileName',
];

await expectLater(
expectBuildCleanImpl(d.sandbox, afterBuildCommand: afterBuildCommand),
throwsATestFailure,
);
});

test(
'should succeed if afterBuildCommand produces git changes which are then '
'ignored by gitDiffPathArguments',
() async {
final afterBuildCommand = [
'sh',
'-c',
'echo "new content just for this test" > $pubspecLockFileName',
];

await expectBuildCleanImpl(
d.sandbox,
afterBuildCommand: afterBuildCommand,
gitDiffPathArguments: [':!$pubspecLockFileName'],
);
},
);
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The afterBuildCommand variable is defined in both tests within this group, leading to code duplication. To improve readability and maintainability, you can define it once at the group level and reuse it in both tests.

  group('afterBuildCommand when a file changes', () {
    const pubspecLockFileName = 'pubspec.lock';
    final afterBuildCommand = [
      'sh',
      '-c',
      'echo "new content just for this test" > $pubspecLockFileName',
    ];

    setUp(() async {
      await gitDir.runCommand(['add', pubspecLockFileName]);
      await gitDir.runCommand(['commit', '-am', 'commit pubspec']);
    });

    test('should fail if afterBuildCommand produces git changes', () async {
      await expectLater(
        expectBuildCleanImpl(d.sandbox, afterBuildCommand: afterBuildCommand),
        throwsATestFailure,
      );
    });

    test(
      'should succeed if afterBuildCommand produces git changes which are then '
      'ignored by gitDiffPathArguments',
      () async {
        await expectBuildCleanImpl(
          d.sandbox,
          afterBuildCommand: afterBuildCommand,
          gitDiffPathArguments: [':!$pubspecLockFileName'],
        );
      },
    );
  });

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants