Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.5.10

* Bug fixes:
* Do not fail when "library" is omitted but nothing would be output.
* Do not fail on extensions that don't end in ".dart" (valid use case).

## 0.5.9

* Update the minimum Dart SDK to `1.22.1`.
Expand Down
17 changes: 9 additions & 8 deletions lib/src/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,9 @@ class GeneratorBuilder extends Builder {
if (generatedExtension == null) {
throw new ArgumentError.notNull('generatedExtension');
}
if (generatedExtension.isEmpty ||
!generatedExtension.startsWith('.') ||
!generatedExtension.endsWith('.dart')) {
if (generatedExtension.isEmpty || !generatedExtension.startsWith('.')) {
throw new ArgumentError.value(generatedExtension, 'generatedExtension',
'Extension must be in the format of .dart or .*.dart');
'Extension must be in the format of .*');
}
if (this.isStandalone && this.generators.length > 1) {
throw new ArgumentError(
Expand Down Expand Up @@ -94,8 +92,14 @@ class GeneratorBuilder extends Builder {
var generatedOutputs =
await _generate(library, generators, buildStep).toList();

var contentBuffer = new StringBuffer();
// Don't output useless files.
//
// NOTE: It is important to do this check _before_ checking for valid
Copy link
Member

Choose a reason for hiding this comment

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

Would prefer if this was protected by a test rather than a comment. Can you file an issue so we can followup later?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

// library/part definitions because users expect some files to be skipped
// therefore they do not have "library".
if (generatedOutputs.isEmpty) return;

var contentBuffer = new StringBuffer();
if (!isStandalone) {
var asset = buildStep.inputId;
var name = nameOfPartial(
Expand All @@ -115,9 +119,6 @@ class GeneratorBuilder extends Builder {
contentBuffer.writeln();
}

// Don't output useless files.
if (generatedOutputs.isEmpty) return;

for (GeneratedOutput output in generatedOutputs) {
contentBuffer.writeln('');
contentBuffer.writeln(_headerLine);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: source_gen
version: 0.5.10-dev
version: 0.5.10
author: Dart Team <misc@dartlang.org>
description: Automated source code generation for Dart.
homepage: https://github.com/dart-lang/source_gen
Expand Down