Skip to content

Commit

Permalink
Breaking: Rename opts.require to opts.preload
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Apr 28, 2019
1 parent 638c18b commit e7a969d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ const onPrepare = function (env) {
MyApp.prepare({
cwd: argv.cwd,
configPath: argv.myappfile,
require: argv.require,
preload: argv.preload,
completion: argv.completion
}, onPrepare);
```
Expand Down Expand Up @@ -376,7 +376,7 @@ myapp --myappfile /Users/name/Myappfile.js --cwd /var/www/project1
myapp --myappfile /Users/name/Myappfile.js --cwd /var/www/project2
```

#### opts.require
#### opts.preload

A string or array of modules to attempt requiring from the local working directory before invoking the launch callback.

Expand All @@ -387,21 +387,21 @@ Default: `null`
```js
var argv = require('minimist')(process.argv.slice(2));
MyApp.launch({
require: argv.require
preload: argv.preload
}, invoke);
```

**Matching CLI Invocation:**
```js
myapp --require coffee-script/register
myapp --preload coffee-script/register
```

#### callback(env)

A function called after your environment is prepared. A good place to modify the environment before calling `execute`. When invoked, `this` will be your instance of Liftoff. The `env` param will contain the following keys:

- `cwd`: the current working directory
- `require`: an array of modules that liftoff tried to pre-load
- `preload`: an array of modules that liftoff tried to pre-load
- `configNameSearch`: the config files searched for
- `configPath`: the full path to your configuration file (if found)
- `configBase`: the base directory of your configuration file (if found)
Expand Down Expand Up @@ -436,7 +436,7 @@ MyApp.prepare({}, onPrepare);
A function called after your application is executed. When invoked, `this` will be your instance of Liftoff, `argv` will be all command-line arguments (minus node & v8 flags), and `env` will contain the following keys:

- `cwd`: the current working directory
- `require`: an array of modules that liftoff tried to pre-load
- `preload`: an array of modules that liftoff tried to pre-load
- `configNameSearch`: the config files searched for
- `configPath`: the full path to your configuration file (if found)
- `configBase`: the base directory of your configuration file (if found)
Expand All @@ -448,10 +448,10 @@ A function called after your application is executed. When invoked, `this` will

#### `on('preload:before', function(name) {})`

Emitted before a module is pre-load. (But for only a module which is specified by `opts.require`.)
Emitted before a module is pre-load. (But for only a module which is specified by `opts.preload`.)

```js
var Hacker = new Liftoff({name:'hacker', require:'coffee-script'});
var Hacker = new Liftoff({name:'hacker', preload:'coffee-script'});
Hacker.on('preload:before', function (name) {
console.log('Requiring external module: '+name+'...');
});
Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Liftoff.prototype.buildEnvironment = function(opts) {
opts = opts || {};

// get modules we want to preload
var preload = opts.require || [];
var preload = opts.preload || [];

// ensure items to preload is an array
if (!Array.isArray(preload)) {
Expand Down Expand Up @@ -131,7 +131,7 @@ Liftoff.prototype.buildEnvironment = function(opts) {

return {
cwd: cwd,
require: preload,
preload: preload,
configNameSearch: configNameSearch,
configPath: configPath,
configBase: configBase,
Expand Down Expand Up @@ -207,7 +207,7 @@ Liftoff.prototype.execute = function(env, forcedFlags, fn) {

function preloadModules(inst, env) {
var basedir = env.cwd;
env.require.filter(toUnique).forEach(function(module) {
env.preload.filter(toUnique).forEach(function(module) {
inst.requireLocal(module, basedir);
});
}
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/respawn_and_require.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Test.on('preload:success', function(name) {
});

Test.prepare({
require: 'coffeescript/register',
preload: 'coffeescript/register',
}, function(env) {
var forcedFlags = ['--lazy'];
Test.execute(env, forcedFlags, function() {
Expand Down
12 changes: 6 additions & 6 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,9 @@ describe('Liftoff', function() {
app.on('preload:failure', function(moduleName, err) {
done(err);
});
app.prepare({ require: ['coffeescript/register'] }, function(env) {
app.prepare({ preload: ['coffeescript/register'] }, function(env) {
app.execute(env, function(env) {
expect(env.require).to.deep.equal(['coffeescript/register']);
expect(env.preload).to.deep.equal(['coffeescript/register']);
expect(logs).to.deep.equal(['preload:success']);
done();
});
Expand All @@ -302,9 +302,9 @@ describe('Liftoff', function() {
app.on('preload:failure', function(moduleName, err) {
done(err);
});
app.prepare({ require: 'coffeescript/register' }, function(env) {
app.prepare({ preload: 'coffeescript/register' }, function(env) {
app.execute(env, function(env) {
expect(env.require).to.deep.equal(['coffeescript/register']);
expect(env.preload).to.deep.equal(['coffeescript/register']);
expect(logs).to.deep.equal(['preload:success']);
done();
});
Expand All @@ -319,9 +319,9 @@ describe('Liftoff', function() {
expect(err).to.not.equal(null);
logs.push('preload:failure');
});
app.prepare({ require: 'badmodule' }, function(env) {
app.prepare({ preload: 'badmodule' }, function(env) {
app.execute(env, function(env) {
expect(env.require).to.deep.equal(['badmodule']);
expect(env.preload).to.deep.equal(['badmodule']);
expect(logs).to.deep.equal(['preload:failure']);
done();
});
Expand Down

0 comments on commit e7a969d

Please sign in to comment.