Using _node to run JS code that requires coffeescript modules

25 views
Skip to first unread message

Phil Sung

unread,
Mar 19, 2015, 5:44:28 PM3/19/15
to stream...@googlegroups.com
Hi,

I've been trying to make our code compatible with the latest streamline and have run into the following. With streamline 0.10.13 and later, I get an error running

    _node test._js

where test._js contains:

    require('coffee-script');
    require('streamline').register();
    require('./mod');

and mod._coffee is a streamlined coffee file found in the same directory.

The error is:

    $ node_modules/.bin/_node test._js

    module.js:340
        throw err;
          ^
    Error: Cannot find module './mod'
        at Function.Module._resolveFilename (module.js:338:15)
        at Function.Module._load (module.js:280:25)
        at Module.require (module.js:364:17)
        at require (module.js:380:17)
        at Object.<anonymous> (/home/psung/test._js:3:1)
        [...]

The failure to find the ._coffee file seems to be something specific to the registration order that results from using _node, because if I use regular node and rename test._js to test.js, it works fine.

[Just as background info, we're hoping to use the former pattern with _node since our invocation is actually of this form:

    _node path/to/mocha path/to/ourtests._js

where mocha is third-party (non-streamlined) JS code that we were hoping could just transparently execute our streamline modules.]

This appears to have been a regression introduced between 0.10.12 and 0.10.13. Can anyone suggest a workaround, or is this a bug, or is there an alternative way we should think about doing this entirely?

Thanks for streamline, and thanks in advance for your help.
Phil

Bruno Jouhier

unread,
Mar 19, 2015, 6:08:24 PM3/19/15
to stream...@googlegroups.com
Hi Phil,

The regression was introduced a while ago (0.10.13 is August last year) and it looks like it is a side effect of an intentional change.

The change was that _node should be used to run *._js code (and not load the coffeescript compiler) while _coffee should be used for *._coffee. The module compilation hooks are a bit tricky and coffeescript hooks are not installed it we load coffeescript after streamline  (_node loads the streamline hooks before running your test._js so the streamline.register() call in your test._js is actually a no-op).

I see two workarounds:

1) rename your file test.js instead of test._js. The idea behind a loader is to have the .js extension so that you can run it with node, not _node. But I don't know if this would solve your mocha scenario.

2) run the script with _coffee instead of _node. This should solve your mocha scenario.

Let me know how it goes
Bruno

---
The contents of this e-mail and any attachments are confidential and only for use by the intended recipient. Any unauthorized use, distribution or copying of this message is strictly prohibited. If you are not the intended recipient please inform the sender immediately by reply e-mail and delete this message from your system. Thank you for your co-operation.

--
You received this message because you are subscribed to the Google Groups "streamline.js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to streamlinejs...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Phil Sung

unread,
Mar 26, 2015, 2:22:20 AM3/26/15
to stream...@googlegroups.com
On Thu, Mar 19, 2015 at 3:08 PM, Bruno Jouhier <bjou...@gmail.com> wrote:
> Hi Phil,
>
> The regression was introduced a while ago (0.10.13 is August last year) and
> it looks like it is a side effect of an intentional change.
>
> The change was that _node should be used to run *._js code (and not load the
> coffeescript compiler) while _coffee should be used for *._coffee. The
> module compilation hooks are a bit tricky and coffeescript hooks are not
> installed it we load coffeescript after streamline (_node loads the
> streamline hooks before running your test._js so the streamline.register()
> call in your test._js is actually a no-op).
>
> I see two workarounds:
>
> 1) rename your file test.js instead of test._js. The idea behind a loader is
> to have the .js extension so that you can run it with node, not _node. But I
> don't know if this would solve your mocha scenario.
>
> 2) run the script with _coffee instead of _node. This should solve your
> mocha scenario.

Sorry about the delay in responding, I've just gotten back to
investigating this further.

Thanks for the clarification. I ended up forking the mocha executable
that we'd use and adding "require('coffee-script');
require('streamline').register()" at the top of it, and it works now
(and can load our ._js test files). I'm also running it with node
instead of _node. I think this is the least disruptive way to get to
what we want, so thanks again for your help!

Regards,
Phil

--
Reply all
Reply to author
Forward
0 new messages