jaredhanson / electrolyte

Elegant dependency injection for Node.js.
MIT License
564 stars 59 forks source link

Allow @literal to be false for node modules #43

Closed cabloo closed 7 years ago

cabloo commented 8 years ago

My application uses require('app/...') so the node_modules source works for injection of my files. However, when the files get injected they are (surprisingly) the original function with no dependencies injected. Some digging revealed that @literal was the cause of this, and I was surprised when I could not turn it off using exports['@literal'] = false; inside my file. This allows that functionality.

For others having this issue, it also turned out that changing

IoC.use(IoC.dir('./'));
IoC.use(IoC.node_modules());

to

IoC.use(IoC.node_modules());
IoC.use(IoC.dir('./'));

fixed the issue for me. I would expect the priority to be on the first items, but I guess it makes more sense the other way around.

coveralls commented 8 years ago

Coverage Status

Coverage increased (+0.007%) to 98.565% when pulling 030fcf3fb90c9c7ecea22526ecd54958a2453cc0 on cabloo:patch-1 into 47562ca26e1ddeaf0ecc8dcbc294cba8748db304 on jaredhanson:master.

jaredhanson commented 8 years ago

To clarify: If the order is

IoC.use(IoC.node_modules());
IoC.use(IoC.dir('./'));

Then this PR isn't needed, correct?

cabloo commented 8 years ago

Well, that's more of a workaround. I personally would not use this feature, but it could be used if components of your application were distributed and included via npm. IoC.create('my-custom-npm-package') would then do dependency injection as expected if my-custom-npm-package's index.js had

exports['@literal'] = false;

whereas currently, this value is overridden.

cabloo commented 8 years ago

Will this feature be any use? If so I could fix up the broken tests and write another test showing that it works.