Skip to content

Async Transformers #29100

Open
Open

Description

@kaaninel

I was using Compiler API and basically changed program.emit at host.afterProgramCreate just like examples and hooked my transformers into emit function. But one thing i couldn't find anywhere is a async transformer. Im using PostCSS and some other stuff like that and implementing those to a single typescript compiler but some plugins are async in postcss and i cant use them at the moment. Is there any way to implement this that im missing or undocumented ? And in case somebody offers to use webpack my code is mostly javascript based and i need really good static analysis for it with type data included that's also reason i use typescript's api instead of using babel which have those cases mostly covered with plugins. I'm implementing all-in-one solution for my company/community project so ideally it needs to be inside typescript compiler.

Activity

  1. DanielRosenwasser commented on Dec 19, 2018

    @DanielRosenwasser
    Member

    Can you give a concrete example of why the transformations/emit themselves being synchronous is a problem?

  2. j-oliveras commented on Dec 20, 2018

    @j-oliveras
    Contributor

    Daniel Rosenwasser (@DanielRosenwasser) I think he want to integrate an async transform into the compiler, but the compiler expects all transforms to be synchronous.

  3. kaaninel commented on Dec 20, 2018

    @kaaninel
    Author

    Basically i need

    const Template = node.initializer.template as ts.NoSubstitutionTemplateLiteral;
    PostCSS.process({ [(Cls as any).Tag]: Template.text }).then(p => {
      node.initializer.template = ts.createNoSubstitutionTemplateLiteral(p.css);
    });

    instead of

    const Template = node.initializer.template as ts.NoSubstitutionTemplateLiteral;
    const p = PostCSS.process({ [(Cls as any).Tag]: Template.text });
    node.initializer.template = ts.createNoSubstitutionTemplateLiteral(p.css);

    Tbh I dont think this is really necessary if i was writing whole system sync is more than enough but for 3rd party solutions i need this.

  4. weswigham commented on Dec 20, 2018

    @weswigham
    Member

    You could walk the tree, process all the postCSS tags asynchronously and save the results, then start a compilation/transform pass and perform the transformations synchronously using the saved results, no?

  5. kaaninel commented on Dec 20, 2018

    @kaaninel
    Author

    It would feel like a dirty hack but its possible. I will try it out and comment results. I hope it wont mess with watcher.

  6. added
    QuestionAn issue which isn't directly actionable in code
    Domain: APIRelates to the public API for TypeScript
    SuggestionAn idea for TypeScript
    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this feature
    and removed
    QuestionAn issue which isn't directly actionable in code
    on Dec 20, 2018
  7. longlho commented on Mar 24, 2019

    @longlho
    Contributor

    Kaan İnel (@kaaninel) FWIW, we did what Wesley Wigham (@weswigham) suggested and pre-process all CSS into json and inline with https://github.com/longlho/ts-transform-json. The JSONs are then also feed into other toolchain like jest or webpack and prevents things like className gets generated differently. (We regenerate/filter certain class name bc of adblocker)

  8. kaaninel commented on Mar 25, 2019

    @kaaninel
    Author

    I implemented it ( in more basic way )
    I basically scanned all of the typescript files and generated one big css file and processed it with postcss. Downside is I cant implement string interpolation.
    Linker/CSSCompiler (Where i collect all css source)
    Linker/CustomElements (Where i detect css sources)
    Linker/Compiler (Where I process postcss and emit)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureDomain: APIRelates to the public API for TypeScriptSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions