node_modules in subdirectory? #210

Closed
DenisGorbachev opened this Issue Jul 23, 2015 · 10 comments

Projects

None yet

4 participants

@DenisGorbachev

Reproduction steps:

Results:

  • mocha works
  • Wallaby doesn't work (Error: Cannot find module 'object-path')

That's because Wallaby only uses the top-level node_modules, while ignoring all node_modules (both top-level and inside core/).

In theory, I could install "core" as npm package itself. However, I'd like to keep it as git submodule, because I develop core along with the main package.

Is it possible to utilize all node_modules, not just top-level ones?

@ArtemGovorov
Member

It is possible, you may just give wallaby a hint where to look for node modules:

module.exports = function(wallaby) {
  process.env.NODE_PATH = 
    require('path').join(wallaby.localProjectDir, 'core', 'node_modules');
  ...
}

I understand it's not perfect and it'd be better if it would just work as in mocha (actually mocha with any code coverage solution should fail for the same reason, as it also has its own cache of instrumented files where it will not copy nested node modules, unless instructed to do so). So as opposed to mocha that is using a local folder, wallaby is using its own cache and doesn't copy node modules there, so needs a hint where to find node modules. Top level modules are automatically handled, but modules in subfolders may need scanning to find them, which will be a bit less performant than the proposed solution with NODE_PATH.

P.S You may consider adding !core/node_modules/** to your files list, right now all coffee script files from the node modules are copied to the wallaby cache.

@DenisGorbachev

Thanks for the tips, it works!

Here's my final wallaby.js: https://gist.github.com/DenisGorbachev/c370efdee4acec46b83e

@DenisGorbachev

By the way, maybe it would be better to update the docs with these instructions?

Plus, a micro-pull-request:

- process.env.NODE_PATH = require('path').join(wallaby.localProjectDir, 'core', 'node_modules');
+ process.env.NODE_PATH += ':' + require('path').join(wallaby.localProjectDir, 'core', 'node_modules');
@ArtemGovorov
Member
@DinisCruz

that worked really well, I'm still in early stages of integrating wallaby on my project so my wallaby.js is still quite simple:

module.exports = function (wallaby) {
  process.env.NODE_PATH = require('path').join(wallaby.localProjectDir, 'TM_Website', 'node_modules');

  //console.dir(wallaby)

  return {
    files: [
      "TM_Website/src/**/*.coffee",
      "TM_Jade/**/*.jade"
    ],

    tests: [
      "TM_Website/test/**/*.coffee"
    ],

    env: {
      type: 'node',
    }
  };
};
@ArtemGovorov
Member

@DenisGorbachev quick note on using ':' + require('path').join..., I have corrected the example in docs to make it cross-platform:

process.env.NODE_PATH += path.delimiter 
  + path.join(wallaby.localProjectDir, 'core', 'node_modules');
@DenisGorbachev

Ah, totally forgot about Windows :) Thanks!

On Fri, Jul 31, 2015 at 5:41 AM Artem Govorov notifications@github.com
wrote:

@DenisGorbachev https://github.com/DenisGorbachev quick note on using ':'

  • require('path').join..., I have corrected the example in docs to make
    it cross-platform:

process.env.NODE_PATH += path.delimiter

  • path.join(wallaby.localProjectDir, 'core', 'node_modules');


Reply to this email directly or view it on GitHub
#210 (comment).

@szarouski

Probably a silly question, but how wallaby should be defined?

@ArtemGovorov
Member

@szarouski wallaby in the context of this issue is a parameter passed to the main configuration function of your wallaby config:

module.exports = function(wallaby) { ...

Does it answer your question? If not, could you please clarify a bit what do you mean by defined?

@szarouski

Yes, this is it. Thanks Artem.

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