-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Enable to config to specify forced flags in app launch
- Loading branch information
Showing
9 changed files
with
197 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
function arrayOrFunction(arrayOrFunc, env) { | ||
if (typeof arrayOrFunc === 'function') { | ||
return arrayOrFunc.call(this, env); | ||
} | ||
if (Array.isArray(arrayOrFunc)) { | ||
return arrayOrFunc; | ||
} | ||
if (typeof arrayOrFunc === 'string') { | ||
return [arrayOrFunc]; | ||
} | ||
return []; | ||
} | ||
|
||
function fromReorderedArgv(reorderedArgv) { | ||
var nodeFlags = []; | ||
for (var i = 1, n = reorderedArgv.length; i < n; i++) { | ||
var arg = reorderedArgv[i]; | ||
if (!/^-/.test(arg) || arg === '--') { | ||
break; | ||
} | ||
nodeFlags.push(arg); | ||
} | ||
return nodeFlags; | ||
} | ||
|
||
module.exports = { | ||
arrayOrFunction: arrayOrFunction, | ||
fromReorderedArgv: fromReorderedArgv, | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const Liftoff = require('../..'); | ||
|
||
const Test = new Liftoff({ | ||
name: 'test', | ||
nodeFlags: function(opts, env) { | ||
return ['--lazy']; | ||
}, | ||
}); | ||
|
||
Test.on('respawn', function(execArgv) { | ||
console.log('saw respawn', execArgv); | ||
}); | ||
|
||
Test.launch({}, function(env, argv) { | ||
console.error(argv.slice(1).join(' ')); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const Liftoff = require('../..'); | ||
|
||
const Test = new Liftoff({ | ||
name: 'test', | ||
v8flags: ['--harmony'], | ||
nodeFlags: ['--lazy'], | ||
}); | ||
|
||
Test.on('respawn', function(flags, proc) { | ||
console.log('saw respawn', flags); | ||
}); | ||
|
||
Test.launch({}, function(env, argv) { | ||
console.error(argv.slice(1).join(' ')); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
const expect = require('chai').expect; | ||
const getNodeFlags = require('../../lib/get_node_flags'); | ||
|
||
describe('getNodeFlags', function() { | ||
|
||
describe('arrayOrFunction', function() { | ||
it('should return the first argument when it is an array', function() { | ||
var env = { cwd: 'aaa' }; | ||
expect(getNodeFlags.arrayOrFunction([], env)).to.has.members([]); | ||
expect(getNodeFlags.arrayOrFunction([ | ||
'--lazy', '--use_strict', '--harmony' | ||
], env)).to.has.members([ | ||
'--lazy', '--harmony', '--use_strict' | ||
]); | ||
}); | ||
|
||
it('should return the exection result of the first argument when it is a function', function() { | ||
var env = { cwd: 'aaa' }; | ||
expect(getNodeFlags.arrayOrFunction(function(env) { | ||
return []; | ||
}, env)).to.has.members([]); | ||
expect(getNodeFlags.arrayOrFunction(function(arg) { | ||
expect(arg).to.equal(env); | ||
return ['--lazy', '--harmony']; | ||
}, env)).to.has.members(['--lazy', '--harmony']); | ||
}); | ||
|
||
it('should return an array which has an element of the first argument when the first argument is a string', function() { | ||
var env = { cwd: 'aaa' }; | ||
expect(getNodeFlags.arrayOrFunction('--lazy', env)).to.has.members(['--lazy']); | ||
}); | ||
|
||
it('should return an empty array when the first argument is neither an array, a function nor a string', function() { | ||
var env = { cwd: 'aaa' }; | ||
expect(getNodeFlags.arrayOrFunction(undefined, env)).to.has.members([]); | ||
expect(getNodeFlags.arrayOrFunction(null, env)).to.has.members([]); | ||
expect(getNodeFlags.arrayOrFunction(true, env)).to.has.members([]); | ||
expect(getNodeFlags.arrayOrFunction(false, env)).to.has.members([]); | ||
expect(getNodeFlags.arrayOrFunction(0, env)).to.has.members([]); | ||
expect(getNodeFlags.arrayOrFunction(123, env)).to.has.members([]); | ||
expect(getNodeFlags.arrayOrFunction({}, env)).to.has.members([]); | ||
expect(getNodeFlags.arrayOrFunction({ length: 1 }, env)).to.has.members([]); | ||
}); | ||
}); | ||
|
||
describe('fromReorderedArgv', function() { | ||
it('should return only node flags from respawning arguments', function() { | ||
var env = { cwd: 'aaa' }; | ||
var cmd = ['node', '--lazy', '--harmony', '--use_strict', './aaa/bbb/app.js', '--ccc', 'ddd', '-e', 'fff']; | ||
expect(getNodeFlags.fromReorderedArgv(cmd, env)).to.deep.equal(['--lazy', '--harmony', '--use_strict']); | ||
}); | ||
|
||
it('should end node flags before "--"', function() { | ||
var env = { cwd: 'aaa' }; | ||
var cmd = ['node', '--lazy', '--', '--harmony', '--use_strict', './aaa/bbb/app.js', '--ccc', 'ddd', '-e', 'fff']; | ||
expect(getNodeFlags.fromReorderedArgv(cmd, env)).to.deep.equal(['--lazy']); | ||
|
||
}); | ||
|
||
it('should return node flags when arguments are only node flags', function() { | ||
var env = { cwd: 'aaa' }; | ||
var cmd = ['node', '--lazy', '--harmony', '--use_strict']; | ||
expect(getNodeFlags.fromReorderedArgv(cmd, env)).to.deep.equal(['--lazy', '--harmony', '--use_strict']); | ||
}); | ||
|
||
it('should return an empty array when no node flags', function() { | ||
var env = { cwd: 'aaa' }; | ||
var cmd = ['node', './aaa/bbb/app.js', '--aaa', 'bbb', '-c', 'd']; | ||
expect(getNodeFlags.fromReorderedArgv(cmd, env)).to.deep.equal([]); | ||
}); | ||
}); | ||
}); |