Skip to content

Commit

Permalink
feat: remove karma binary in favor of karma-cli
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
The `karma` module does not export `karma` binary anymore. The recommended way is to have local modules (karma and all the plugins that your project needs) stored in your `package.json`. You can run that particular Karma by `./node_modules/karma/bin/karma`. Or you can have `karma-cli` installed globally on your system, which enables you to use the `karma` command.

The global `karma` command (installed by `karma-cli`) does look for local version of Karma (including parent directories) first and fall backs to a global one.

The `bin/karma` binary does not look for any other instances of Karma and just runs the one that it belongs to.
  • Loading branch information
vojtajina committed Nov 16, 2013
1 parent ee15a4e commit c7d4627
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 31 deletions.
29 changes: 1 addition & 28 deletions bin/karma
@@ -1,30 +1,3 @@
#!/usr/bin/env node

var path = require('path');
var fs = require('fs');

// Try to find a local install
var dir = path.resolve(process.cwd(), 'node_modules', 'karma', 'lib');

// Check if the local install exists else we use the install we are in
if (!fs.existsSync(dir)) {
dir = path.join('..', 'lib');
}

var cli = require(path.join(dir, 'cli'));
var config = cli.process();

switch (config.cmd) {
case 'start':
require(path.join(dir, 'server')).start(config);
break;
case 'run':
require(path.join(dir, 'runner')).run(config);
break;
case 'init':
require(path.join(dir, 'init')).init(config);
break;
case 'completion':
require(path.join(dir, 'completion')).completion(config);
break;
}
require('../lib/cli').run();
21 changes: 21 additions & 0 deletions lib/cli.js
Expand Up @@ -215,6 +215,27 @@ exports.process = function() {
return processArgs(argv, options, fs, path);
};


exports.run = function() {
var config = exports.process();

switch (config.cmd) {
case 'start':
require('./server').start(config);
break;
case 'run':
require('./runner').run(config);
break;
case 'init':
require('./init').init(config);
break;
case 'completion':
require('./completion').completion(config);
break;
}
};


// just for testing
exports.processArgs = processArgs;
exports.parseClientArgs = parseClientArgs;
Expand Down
4 changes: 1 addition & 3 deletions package.json
Expand Up @@ -164,9 +164,7 @@
"grunt-browserify": "~1.2.4"
},
"main": "./lib/index",
"bin": {
"karma": "./bin/karma"
},
"bin": {},
"engines": {
"node": "~0.8 || ~0.10"
},
Expand Down

8 comments on commit c7d4627

@caitp
Copy link

@caitp caitp commented on c7d4627 Feb 27, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vojtajina this seems to be causing some issues running tests on windows, https://github.com/angular/templating and https://github.com/caitp/watchtower.js both suffer from this. Exporting the binaries creates a .cmd wrapper file on windows, which is necessary as windows ignores the shebang line in binaries.

I'm not sure if this property of the configuration is deprecated or not (in which case this should be an NPM issue), but this seems to be causing problems, and it would be great to find out if there's a proper way around this.

@necolas
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this has broken npm-scripts aliasing, so you can't do this in a package anymore:

package.json:

{
  "scripts": {
    "test": "karma start"
  }
}

Normally that would run the local binary.

@sudodoki
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for this change?

@maksimr
Copy link
Contributor

@maksimr maksimr commented on c7d4627 Jun 5, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@necolas you can install karma-cli locally to the project

npm install --save-dev karma-cli

and use karma start in package.json

@sudodoki couple of reasons:

  1. Separation of concerns
  2. Common tool to run different version of karma (simple)
  3. No conflict and subtle errors related version karma when use global karma.

@sudodoki
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify: I'm mostly interested in why would binary not be put into node_modules/.bin/karma, but be kept in node_modules/karma/bin/karma.

@drkibitz
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npm installs files specified as bin in package.json files into a node_modules/.bin directory which is a stand-in for $NODE_PREFIX/bin e.g. /usr/local/bin, /usr/bin, etc.. When packages that specify anything as bin are installed outside of the global directory, this is what happens.

@megawac
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A user's informed me ./node_modules/karma/bin/karma doesn't work in powershell and we aren't going to force users to install karma globally...

@maksimr
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@megawac you can install krma-cli locale to the project and use npm test

Please sign in to comment.