-
Notifications
You must be signed in to change notification settings - Fork 58
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
AF-3083: Transformer should emit an empty part file for libraries containing the .over_react.g.dart part directive #201
Conversation
Security InsightsNo security relevant content was detected by automated scans. Action Items
Questions or Comments? Reach out on Slack: #support-infosec. |
lib/transformer.dart
Outdated
@@ -98,6 +98,26 @@ class WebSkinDartTransformer extends Transformer implements LazyTransformer { | |||
TransformedSourceFile transformedFile = new TransformedSourceFile(sourceFile); | |||
TransformLogger logger = new JetBrainsFriendlyLogger(transform.logger); | |||
|
|||
var ignoreCommentPattern = new RegExp(r'\/\/\s?ignore:\s?uri_does_not_exist,\s?uri_has_not_been_generated'); | |||
var partPattern = new RegExp(r'(\s*?)part\s(.*?).overReact.g.dart(.;)'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this was already considered, but another option would be to emit an empty .g.dart
file from the transformer, which is probably more robust than trying to do this transformation.
Just putting it out there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We did talk about that and we went this direction because we didn't want to have to deal with mapping part files to their parent libraries, but I just realized we wouldn't have to do that since these .overReact.g.dart
part files would only show up in the parent libraries.
So I think we should do that instead. Sorry I missed that before @sebastianmalysa-wf
…he ignore comment and remove it
|
||
test('ignore line and part directive is removed from component file', () { | ||
final ignoreLine = '\/\/ ignore: uri_does_not_exist, uri_has_not_been_generated'; | ||
final partLine = "part \'component\.overReact\.g\.dart\';"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs one more test to verify that the part directive is removed even if the ignore comment isn't found
lib/transformer.dart
Outdated
@@ -98,6 +98,25 @@ class WebSkinDartTransformer extends Transformer implements LazyTransformer { | |||
TransformedSourceFile transformedFile = new TransformedSourceFile(sourceFile); | |||
TransformLogger logger = new JetBrainsFriendlyLogger(transform.logger); | |||
|
|||
var ignoreCommentPattern = new RegExp(r'\/\/\s?ignore:\s?uri_does_not_exist,\s?uri_has_not_been_generated'); | |||
var partPattern = new RegExp(r'(\s*?)part\s(.*?).overReact.g.dart(.;)'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this regex should actually enforce that the part
directive starts at the very beginning of the line so that we avoid a commented out part directive. My suggestion would be:
var partPattern = new RegExp(r'''^part\s+['"].+.overReact.g.dart['"];''');
Codecov Report
@@ Coverage Diff @@
## master #201 +/- ##
==========================================
+ Coverage 94.54% 95.87% +1.33%
==========================================
Files 34 34
Lines 1648 1669 +21
==========================================
+ Hits 1558 1600 +42
+ Misses 90 69 -21 |
Working on adding tests. |
@sebastianmalysa-wf to keep with dart naming conventions, we're gonna have the output extension be |
// ignore: uri_does_not_exist, uri_has_not_been_generated | ||
part 'foo.over_react.g.dart'; | ||
// ignore: uri_does_not_exist, uri_has_not_been_generated | ||
part 'bar.over_react.g.dart'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll only ever have 1 over_react.g.dart
part directive in a file, so we should remove lines 5-6
… directive in a file
lib/transformer.dart
Outdated
// For Dart 1 compatibility an empty generated part file will be created when a file contains | ||
// the part directive pointing to the generated file the new builder requires. | ||
if (partFilename != null) { | ||
partPattern.allMatches(sourceFile.getText(0)).forEach((match) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only expect zero or one .over_react.g.dart
part directives in any file, so I think instead of iterating over all matches we can just look for the first match.
@@ -0,0 +1,15 @@ | |||
import 'package:over_react/over_react.dart'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this filename should be component_with_part_directive.dart
expect(fileAssets.length, equals(2)); | ||
expect(fileAssets[0].id.toString(), equals('testId|foo.over_react.g.dart')); | ||
expect(fileAssets[1].id.toString(), equals('testId|componentWithPartDirective.dart')); | ||
expect(fileAssets[0].toString(), equals('String ""')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of verifying the string representation of the asset, it'd be better to actually read the contents:
expect(fileAssets[0].toString(), equals('String ""')); | |
expect(fileAssets[0].readAsString(), isEmpty); |
lib/transformer.dart
Outdated
if (partFilename != null) { | ||
var sourceFileDirectory = p.dirname(sourceFile.url.toFilePath()); | ||
var partFilePath = p.join(sourceFileDirectory, partFilename.group(1)); | ||
var asset = new Asset.fromString(new AssetId(transform.primaryInput.id.package, partFilePath), ''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this contain a part of
directive?
Or, does it not matter since dart2js doesn't care? If so, fine by me 🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it should, good catch.
var contents = "part of '${p.basename(sourceFile.url.toFilePath())}';";
var asset = new Asset.fromString(new AssetId(transform.primaryInput.id.package, partFilePath), contents);
@sebastianmalysa-wf seb we'll want to do this ^
expect(initWithConfig({}).isPrimary(new AssetId(fakePackage, 'dart_test.yaml')), isFalse); | ||
}); | ||
|
||
test('outputs an empty file when dart 2 boiler plate compatible part directive is found', () async { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have a test for when an empty file should not be emitted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
lib/transformer.dart
Outdated
@@ -98,6 +98,21 @@ class WebSkinDartTransformer extends Transformer implements LazyTransformer { | |||
TransformedSourceFile transformedFile = new TransformedSourceFile(sourceFile); | |||
TransformLogger logger = new JetBrainsFriendlyLogger(transform.logger); | |||
|
|||
var partPattern = new RegExp(r'''part\s+['"](.+.over_react.g.dart)['"];'''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#supernit these periods aren't escaped in the regex
QA +1
@Workiva/release-management-p |
Proposed solution for https://jira.atl.workiva.net/browse/AF-3083
Ultimate problem:
The builder requires a part file, but the transformer does not. The updated boilerplate rollout will include a part directive that includes this new generated part, but that file will not exist when running in Dart 1.
To handle this, the transformer should output an empty file for each of these parts so that it does not fail at runtime.
How it was fixed:
Testing suggestions:
Code changes and tests make sense
CI passes
@corwinsheahan-wf @evanweible-wf @greglittlefield-wf