Skip to content
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

Merged
merged 15 commits into from
Dec 7, 2018

Conversation

sebastianmalysa-wf
Copy link
Contributor

@sebastianmalysa-wf sebastianmalysa-wf commented Nov 15, 2018

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:

  • find and remove the ignore comment and the associated part directive required by the builder

Testing suggestions:

Code changes and tests make sense
CI passes

@corwinsheahan-wf @evanweible-wf @greglittlefield-wf

@sebastianmalysa-wf sebastianmalysa-wf added the dart2 PRs targeting our effort to get to Dart SDK 2.0 compatibility label Nov 15, 2018
@sebastianmalysa-wf sebastianmalysa-wf requested a review from a team as a code owner November 15, 2018 18:08
@aviary2-wf
Copy link

aviary2-wf commented Nov 15, 2018

Security Insights

No security relevant content was detected by automated scans.

Action Items

  • Review PR for security impact; comment "security review required" if needed or unsure
  • Verify aviary.yaml coverage of security relevant code

Questions or Comments? Reach out on Slack: #support-infosec.

@@ -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(.;)');
Copy link
Contributor

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.

Copy link
Contributor

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


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\';";
Copy link
Contributor

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

@@ -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(.;)');
Copy link
Contributor

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-io
Copy link

codecov-io commented Nov 20, 2018

Codecov Report

Merging #201 into master will increase coverage by 1.33%.
The diff coverage is 100%.

@@            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

@sebastianmalysa-wf
Copy link
Contributor Author

Working on adding tests.

@sebastianmalysa-wf sebastianmalysa-wf added the Hold Hold merges label Nov 20, 2018
@corwinsheahan-wf
Copy link
Contributor

@sebastianmalysa-wf to keep with dart naming conventions, we're gonna have the output extension be over_react.g.dart instead of overReact.g.dart. We'll have to update this PR to look for the former instead of the latter.

// 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';
Copy link
Contributor

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

// 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) {
Copy link
Contributor

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';
Copy link
Contributor

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 ""'));
Copy link
Contributor

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:

Suggested change
expect(fileAssets[0].toString(), equals('String ""'));
expect(fileAssets[0].readAsString(), isEmpty);

@corwinsheahan-wf corwinsheahan-wf changed the title AF-3083: Transformer should remove the .overReact.g.dart part directive AF-3083: Transformer should remove the .over_react.g.dart part directive Dec 3, 2018
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), '');
Copy link
Contributor

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 🤷‍♂️

Copy link
Contributor

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 {
Copy link
Contributor

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?

@corwinsheahan-wf corwinsheahan-wf changed the title AF-3083: Transformer should remove the .over_react.g.dart part directive AF-3083: Transformer should emit an empty part file for libraries containing the .over_react.g.dart part directive Dec 5, 2018
@sebastianmalysa-wf sebastianmalysa-wf removed the Hold Hold merges label Dec 6, 2018
Copy link
Contributor

@greglittlefield-wf greglittlefield-wf left a comment

Choose a reason for hiding this comment

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

+1

@@ -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)['"];''');
Copy link
Contributor

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

@evanweible-wf
Copy link
Contributor

QA +1

  • CI passes

  • All tests passed in WSD branch with part directives added to every file with over_react code

    +dependency_overrides:
    +  over_react:
    +    git:
    +      url: git@github.com:sebastianmalysa-wf/over_react.git
    +      ref: AF-3083
    23:44 +27294: All tests passed!
    

@Workiva/release-management-p

@rmconsole2-wf rmconsole2-wf merged commit b353c3e into Workiva:master Dec 7, 2018
@evanweible-wf evanweible-wf added this to the Dart 2 Compat milestone Dec 21, 2018
@evanweible-wf evanweible-wf modified the milestones: Dart 2 Compat, 2.0.0 (Dart 1 & 2 compatibility) Jan 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dart2 PRs targeting our effort to get to Dart SDK 2.0 compatibility Merge Requirements Met RM Ready
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants