GithubHelp home page GithubHelp logo

Comments (3)

lgirma avatar lgirma commented on August 29, 2024

Up on further investigation, I got it to work using (in rollup config):

import typescript from '@rollup/plugin-typescript'

...

plugins: [typescript({
  transformers: {
    before: [ { type: 'program', factory: (program) => di({program}).before[0] } ],
    after: [ { type: 'program', factory: (program) => di({program}).after[0] } ]
  }
})]

This generates the correct bundle like:

container.registerSingleton(undefined, { identifier: 'HackerNewsService', implementation: HackerNewsService });

But the javascript code for all of my classes (like HackerNewsService above) are omitted. And thus running into HackerNewsService is not defined errors.

from di-compiler.

wessberg avatar wessberg commented on August 29, 2024

Hi there,

The DI-Compiler must be passed a TypeScript Program since it depends on a type checker. That's why you need to pass the program on to it.

Your example doesn't work, though, as you pass the DI Custom Transformer twice, one for the before hook and one for the after hook. That's not correct usage of it. The DI custom transformer must be passed a program, and it itself returns a structure of the form {before, after}.

If you experience issues with interoperability between @rollup/plugin-typescript and Custom Transformers such as DI-Compiler, I suggest that you open an issue with a minimal repro over at the Rollup plugins monorepo. Specifically, it should be able to handle Custom Transformers that implement multiple hooks, such as DI-compiler, that does things in both the before and after hooks.

In the meantime, you can use DI-Compiler with rollup-plugin-ts which is tested and verified to be working correctly.

from di-compiler.

SitamMatt avatar SitamMatt commented on August 29, 2024

Hi,

I've wrote a workaround helper for @rollup/plugin-typescript to easly apply this transformer. Here is the npm link

Usage:

import typescript from "@rollup/plugin-typescript";
import { di } from "@wessberg/di-compiler";
import { applyTransformer } from "rollup-typescript-custom-transformer-helper";

(...)

typescript({
  sourceMap: true,
  inlineSources: true,
  transformers: {
    ...applyTransformer((program) => di({ program })),
  },
}),

from di-compiler.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.