Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
Fix running tasks on Windows (elastic#37)
Browse files Browse the repository at this point in the history
* create windows cmd wrapper

* use windows cmd wrapper on browser tests

* be explicit about the mocha command location

* use windows cmd wrapper on server tests

* use windows cmd wrapper on build

default to using npm as well
  • Loading branch information
w33ble authored and spalger committed Feb 8, 2018
1 parent e5f6593 commit 4cb5514
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
5 changes: 5 additions & 0 deletions packages/kbn-plugin-helpers/lib/win_cmd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var platform = require('os').platform();

module.exports = function winCmd(cmd) {
return /^win/.test(platform) ? cmd + '.cmd' : cmd;
};
7 changes: 5 additions & 2 deletions packages/kbn-plugin-helpers/tasks/build/create_build.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var rename = require('gulp-rename');

var rewritePackageJson = require('./rewrite_package_json');
var gitInfo = require('./git_info');
var winCmd = require('../../lib/win_cmd');

module.exports = function createBuild(plugin, buildTarget, buildVersion, kibanaVersion, files) {
var buildSource = plugin.root;
Expand All @@ -34,18 +35,20 @@ module.exports = function createBuild(plugin, buildTarget, buildVersion, kibanaV
})
.then(function () {
// install packages in build
var cmd = winCmd('npm');
var options = {
cwd: buildRoot,
stdio: ['ignore', 'ignore', 'pipe'],
};

try {
// use yarn if yarn lockfile is found in the build
cmd = winCmd('yarn');
statSync(join(buildRoot, 'yarn.lock'));
execFileSync('yarn', ['install', '--production'], options);
execFileSync(cmd, ['install', '--production'], options);
} catch (e) {
// use npm if there is no yarn lockfile in the build
execFileSync('npm', ['install', '--production', '--no-bin-links'], options);
execFileSync(cmd, ['install', '--production', '--no-bin-links'], options);
}
});
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var execFileSync = require('child_process').execFileSync;
var winCmd = require('../../../lib/win_cmd');

module.exports = function testBrowserAction(plugin, run, options) {
options = options || {};
Expand All @@ -13,7 +14,7 @@ module.exports = function testBrowserAction(plugin, run, options) {
kbnServerArgs.push('--kbnServer.tests_bundle.pluginId=' + plugin.id);
}

var cmd = 'npm';
var cmd = winCmd('npm');
var task = (options.dev) ? 'test:dev' : 'test:browser';
var args = ['run', task, '--'].concat(kbnServerArgs);
execFileSync(cmd, args, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var resolve = require('path').resolve;
var delimiter = require('path').delimiter;
var execFileSync = require('child_process').execFileSync;
var winCmd = require('../../../lib/win_cmd');

module.exports = function (plugin, run, options) {
options = options || {};
Expand All @@ -13,7 +14,8 @@ module.exports = function (plugin, run, options) {
testPaths = options.files;
}

var cmd = 'mocha';
var fullCmd = resolve(plugin.kibanaRoot, 'node_modules', '.bin', 'mocha');
var cmd = winCmd(fullCmd);
var args = ['--require', mochaSetupJs].concat(testPaths);
var path = `${kibanaBins}${delimiter}${process.env.PATH}`;

Expand Down

0 comments on commit 4cb5514

Please sign in to comment.