Skip to content

Commit

Permalink
New: Support flags.nodeFlags config option
Browse files Browse the repository at this point in the history
  • Loading branch information
sttk authored and phated committed Mar 26, 2019
1 parent 1b80d67 commit ad18c27
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ Supported configurations properties:
| flags.silent | Silence logging by default |
| flags.series | Run tasks given on the CLI in series (the default is parallel) |
| flags.require | An array of modules to require before running the gulpfile. Any relative paths will be resolved against the `--cwd` directory (if you don't want that behavior, use absolute paths) |
| flags.nodeFlags | An array of flags used to forcibly respawn the process upon startup. For example, if you always want your gulpfiles to run in node's harmony mode, you can set `--harmony` here |

## Flags

Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function run() {
// Set up event listeners for logging again after configuring.
toConsole(log, opts);

cli.execute(env, handleArguments);
cli.execute(env, env.nodeFlags, handleArguments);
});
}

Expand Down
5 changes: 5 additions & 0 deletions lib/shared/config/env-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var toFrom = {
configPath: 'flags.gulpfile',
configBase: 'flags.gulpfile',
require: 'flags.require',
nodeFlags: 'flags.nodeFlags',
};

function mergeConfigToEnvFlags(env, config, cliOpts) {
Expand All @@ -33,6 +34,10 @@ function mergeConfigToEnvFlags(env, config, cliOpts) {
return [].concat(envInfo.value, configInfo.value);
}

if (envInfo.keyChain === 'nodeFlags') {
return [].concat(configInfo.value || []);
}

return configInfo.value;
}
}
Expand Down
70 changes: 70 additions & 0 deletions test/config-flags-node-flags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
'use strict';

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

var fixturesDir = path.join(__dirname, 'fixtures/config');

var runner = require('gulp-test-tools').gulpRunner().basedir(fixturesDir);
var headLines = require('gulp-test-tools').headLines;
var eraseTime = require('gulp-test-tools').eraseTime;

describe('config: nodeFlags', function() {

it('Should respawn by a node flag: --lazy', function(done) {
runner
.chdir('flags/nodeFlags/string')
.gulp()
.run(cb);

function cb(err, stdout, stderr) {
expect(err).toEqual(null);
expect(stderr).toEqual('');

var line = eraseTime(headLines(stdout, 1));
expect(line).toEqual('Node flags detected: --lazy');

line = eraseTime(headLines(stdout, 2, 1));
expect(line).toMatch('Respawned to PID: ');
done(err);
}
});

it('Should respawn by a node flag: --lazy --trace-deprecation', function(done) {
runner
.chdir('flags/nodeFlags/array')
.gulp()
.run(cb);

function cb(err, stdout, stderr) {
expect(err).toEqual(null);
expect(stderr).toEqual('');

var line = eraseTime(headLines(stdout, 1));
expect(line).toEqual('Node flags detected: --lazy, --trace-deprecation');

line = eraseTime(headLines(stdout, 2, 1));
expect(line).toMatch('Respawned to PID: ');
done(err);
}
});

it('Should respawn with flags in config file and command line', function(done) {
runner
.chdir('flags/nodeFlags/string')
.gulp('--harmony')
.run(cb);

function cb(err, stdout, stderr) {
expect(err).toEqual(null);
expect(stderr).toEqual('');

var line = eraseTime(headLines(stdout, 1));
expect(line).toEqual('Node flags detected: --lazy, --harmony');

line = eraseTime(headLines(stdout, 2, 1));
expect(line).toMatch('Respawned to PID: ');
done(err);
}
});
});
5 changes: 5 additions & 0 deletions test/fixtures/config/flags/nodeFlags/array/.gulp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"flags": {
"nodeFlags": ["--lazy", "--trace-deprecation"]
}
}
6 changes: 6 additions & 0 deletions test/fixtures/config/flags/nodeFlags/array/gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

exports.default = function(done) {
console.log('Default');
done();
};
7 changes: 7 additions & 0 deletions test/fixtures/config/flags/nodeFlags/string/.gulp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

module.exports = {
flags: {
nodeFlags: '--lazy',
},
};
6 changes: 6 additions & 0 deletions test/fixtures/config/flags/nodeFlags/string/gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

exports.default = function(done) {
console.log('Default');
done();
};

0 comments on commit ad18c27

Please sign in to comment.