Coder Social home page Coder Social logo

Comments (18)

jhnns avatar jhnns commented on May 21, 2024

We had this discussion on CoffeeScript in issue #8 and were talking about whether rewire should support compiling to CoffeeScript or not. I don't think that rewire should support every language in the node.js community (e.g. what about IcedCoffeeScript?). I think that anyone who is using a compile-to-js-language needs to take care of compiling it to JavaScript.

Personally I don't use CoffeeScript, so I don't know much about tools and typical workflows. Is there a possibility to add the CoffeeScript(Redux)-Compiler to require.extensions?

from rewire.

gprasant avatar gprasant commented on May 21, 2024

The extension of CSR is still .coffee and so an addition to require.extensions is not needed.

I see that you are doing a require("coffee-script") in

var coffee = require("coffee-script"),

This "coffee-script" is a module name. In my case, Coffee-script-redux is a different (stricter) compiler for .coffee files. It would be good if there was a json file for settings where the compiler can be specified and the specified compiler can be required. I believe this is how mocha does it..

from rewire.

jhnns avatar jhnns commented on May 21, 2024

Could you give me a link to a readme or something where the behavior of mocha is described?

If rewire didn't modify require.extensions would you be able to use CoffeeScriptRedux by modifying require.extensions before starting your tests?

from rewire.

gprasant avatar gprasant commented on May 21, 2024

The readme is on http://visionmedia.github.io/mocha/. Please go to the link and Ctrl+F for --compilers

from rewire.

jhnns avatar jhnns commented on May 21, 2024

Are you calling mocha with --compilers coffee:coffee-script?

It seems to me that the CS "feature" of rewire #8 prevents you from using other CS compilers which means that the feature should be regressed.

from rewire.

gprasant avatar gprasant commented on May 21, 2024

Are you calling mocha with --compilers coffee:coffee-script?

No, I call it with --compilers coffee:coffee-script-redux. But you have the correct understanding of it.

It seems to me that the CS "feature" of rewire #8 prevents you from using other CS compilers

I think so too. Though, I did try to get rewire to work with CSR but failed. I haven't looked at it enough to see where the problem lies. In short, let me share the gist of what I did https://gist.github.com/gprasant/7399548

from rewire.

jhnns avatar jhnns commented on May 21, 2024

Mhmmm k. And if you remove the whole CS-compile thing of rewire and start mocha with --compilers coffee:coffee-script it still works? If this is the case, I'll remove CS-support so everybody can choose his favorite CS-compiler.

from rewire.

gprasant avatar gprasant commented on May 21, 2024

Let me check if that will work.
On Nov 11, 2013 2:29 PM, "Johannes Ewald" [email protected] wrote:

Mhmmm k. And if you remove the whole CS-compile thing of rewire and start
mocha with --compilers coffee:coffee-script it still works? If this is
the case, I'll remove CS-support so everybody can choose his favorite
CS-compiler.


Reply to this email directly or view it on GitHubhttps://github.com//issues/21#issuecomment-28182217
.

from rewire.

gprasant avatar gprasant commented on May 21, 2024

Hello, I tried this today. I have a commit up at https://github.com/gprasant/rewire/tree/anycompiler
commit : gprasant@9518cc4.
Here is what I found out - One test fails it("should also work with CoffeeScript") . But it looks like the coffeescript file is read. But rewire is not able to set a variable . I thought it could be because of an outer closure introduced when compiling the file, but that doesn't look like it. You probably know more about how this works. Can you try to see if the way I have removed the coffeescript functionality is right and see whats causing rewire to not work in this case?

UPDATE It looks like coffeeModule.readFileSync is resulting in calling the actual fs.readFileSync even though we have stubbed it out.

UPDATE-2 Looks like it is the outer closure that was the problem. So, I compiled module.coffee with --bare and then ran the test against the compiled js file . This time, the test ran successfully. I don't know of a way to include this --bare switch in the mocha command line. yet.

from rewire.

jhnns avatar jhnns commented on May 21, 2024

Yep, the bare-option is needed as pointed out in this issue #8.

rewire can't invalidate the way how JavaScript closures work. Variables hidden "behind" a closure can never be accessed.

Your commit looks good, I think I'll regress the feature and bump the major version. @00Davo @djthread @es128

from rewire.

es128 avatar es128 commented on May 21, 2024

Wait, so why the need for the regress? This issue boiled down to an oversight of the requirement to use bare, which is good practice in node apps anyway since the module system does its own encapsulation.

Please... leave it alone.

from rewire.

jhnns avatar jhnns commented on May 21, 2024

The problem is that rewire's CoffeeScript-feature prevents other users from using another CoffeeScript-dialect because rewire will always compile files ending on .coffee with the original CoffeeScript compiler. If you compiled all your CoffeeScript to JavaScript and then run your tests it should be no problem.

If you're using mocha you just need to use the --compilers coffee:coffee-script argument.

The main problem here is that rewire does not know anything about CoffeeScript or other compilers (and in fact it should not care about). It just enhances node's require so you have private access to your modules.

from rewire.

es128 avatar es128 commented on May 21, 2024

But the feature as it stands works fine - allowing testing without a compilation step for the specific use-case.

For anyone else, they can precompile, which they'll have to do either way.

from rewire.

jhnns avatar jhnns commented on May 21, 2024

Seems like everyone who's using CoffeeScript doesn't like to pre-compile... ^^

from rewire.

es128 avatar es128 commented on May 21, 2024

Actually, TBH, I usually do run the tests on precompiled code as it's noticeably faster. But I like the option of not having to, perhaps for smaller projects/experiments. And I'm just not understanding the benefit gained by removing the existing, working feature, by imposing the workaround on everyone instead of just outliers.

Btw, since I haven't expressed this before - thank you for rewire, it is absolutely awesome. I will continue using it whether you decide to remove the built-in coffee-script support or not.

from rewire.

jhnns avatar jhnns commented on May 21, 2024

@gprasant is pre-compiling an option for you?
@es128 thx! 😄

from rewire.

gprasant avatar gprasant commented on May 21, 2024

I can manage precompiling

from rewire.

jhnns avatar jhnns commented on May 21, 2024

Cool! 👍

from rewire.

Related Issues (20)

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.