Skip to content
This repository has been archived by the owner on Jul 20, 2018. It is now read-only.

Allow transformers to generate/modify code in packages as a result of whole-code evaluation #39

Open
DartBot opened this issue Jun 5, 2015 · 12 comments
Labels

Comments

@DartBot
Copy link

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/2152569?v=3" align="left" width="96" height="96"hspace="10"> Issue by blois
Originally opened as dart-lang/sdk#17306


Right now transformers can only modify code in packages when that package is being transformed, but there are a number of scenarios where the transformation on the package needs to be done with the results of some whole-program analysis.

The specific scenario I'm running into is generating code for Angular in a lazy-loading environment. In a non-lazy environment the generated caches are all injected into the application entry point, but in the lazy-loaded scenario the code needs to be injected into the root of the lazy library.

The issue is that the calculation of what needs to be cached needs to take the entire app into account.

One approach discussed is the 'global transformers' which execute after all package transformers and can modify every package contents.

Marking as critical as it is required for Angular's transformers once lazy-loading is supported.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/46275?v=3" align="left" width="48" height="48"hspace="10"> Comment by munificent


Issue dart-lang/pub#670 has been merged into this issue.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/188?v=3" align="left" width="48" height="48"hspace="10"> Comment by nex3


Removed Area-Pub, Pub-Build labels.
Added Area-Pkg, Pkg-Barback labels.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/188?v=3" align="left" width="48" height="48"hspace="10"> Comment by nex3


Removed Priority-Critical label.
Added Priority-Medium label.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/2049220?v=3" align="left" width="48" height="48"hspace="10"> Comment by sigmundch


FYI - the latest update is that we'll try to do this as a special transformer that creates a copy-on-write of assets. More details here: https://code.google.com/p/dart/issues/detail?id=18489

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/188?v=3" align="left" width="48" height="48"hspace="10"> Comment by nex3


We're going to experimentally try an API that allows an application to declare transformers for its dependencies. The syntax will be something like this:

    experimental.global_transformers:
    - some_transformer
    - another_transformer:
        config: value

Each transformer is loaded and applied to each package's asset cascade in order after the normal transformer loading has finished.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/522948?v=3" align="left" width="48" height="48"hspace="10"> Comment by justinfagnani


Interesting!

Not to look a gift horse in the mouth, but I think that we often need the other direction - that it when a library declares a transformer it needs to transform the entrypoints as well. This is true for libraries that need to register or initialize like custom elements, js-interop, polymer expressions, etc.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/188?v=3" align="left" width="48" height="48"hspace="10"> Comment by nex3


I think the way to handle those might be requiring the entrypoint to add a transformer to its global transformer list.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/522948?v=3" align="left" width="48" height="48"hspace="10"> Comment by justinfagnani


Which is what we currently do. What's unfortunate about that is that it's hard to document. Some transitive dependency uses Polymer and then the app needs to declare the transformer.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/188?v=3" align="left" width="48" height="48"hspace="10"> Comment by nex3


If a transitive dependency needs to change code in an application, I think it's reasonable for that application to explicitly opt into that dependency's modifications. Letting them happen silently is a recipe for confusing non-local effects, even if we could deal with the ordering concerns.

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/405837?v=3" align="left" width="48" height="48"hspace="10"> Comment by zoechi


My package needs a transformer (DI) for examples only and causes troubles (a bug in DI though) in an app that has my package as a dependency because the transformer is executed during pre-compilation and no way to opt out.

#­10 see http://dartbug.com/21777

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/188?v=3" align="left" width="48" height="48"hspace="10"> Comment by nex3


If you only include the example directory, it shouldn't ever get instantiated for a dependency:

    transformers:
    - di:
      $include: example/**

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/405837?v=3" align="left" width="48" height="48"hspace="10"> Comment by zoechi


Thanks, that's actually a good idea. Didn't think of it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

2 participants