Skip to content
This repository has been archived by the owner on Jan 22, 2020. It is now read-only.

Commit

Permalink
Throw an error if peer dependency is not installed
Browse files Browse the repository at this point in the history
  • Loading branch information
stevemao committed Oct 21, 2015
1 parent efa7fa7 commit 7289e54
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### What is react-engine?
* a react render engine for [Universal](https://medium.com/@mjackson/universal-javascript-4761051b7ae9) (previously [Isomorphic](http://nerds.airbnb.com/isomorphic-javascript-future-web-apps/)) JavaScript apps written with express
* renders both plain react views and react-router views
* renders both plain react views and **optionally** react-router views
* enables server rendered views to be client mountable


Expand Down
12 changes: 10 additions & 2 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@

'use strict';

var React = require('react');
var Config = require('./config');
var Router = require('react-router');

// declaring like this helps in unit test
// dependency injection using `rewire` module
Expand All @@ -37,6 +35,16 @@ exports.data = function data() {
// the client side boot function
exports.boot = function boot(options, callback) {

var React = require('react');

try {
var Router = require('react-router');
} catch (err) {
if (!Router && createOptions.routes) {
throw err;
}
}

var router;

var viewResolver = options.viewResolver;
Expand Down
15 changes: 11 additions & 4 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ var omit = require('lodash-node/compat/object/omit');
var merge = require('lodash-node/compat/object/merge');
var isString = require('lodash-node/compat/lang/isString');

// safely require the peer-dependencies
var React = util.safeRequire('react');
var Router = util.safeRequire('react-router');

// a template of the `script` tag that gets
// injected into the server rendered pages.
var TEMPLATE = ['<script id="%s" type="application/javascript">var ',
Expand All @@ -38,6 +34,17 @@ var TEMPLATE = ['<script id="%s" type="application/javascript">var ',

exports.create = function create(createOptions) {

// safely require the peer-dependencies
var React = util.safeRequire('react');

try {
var Router = require('react-router');
} catch (err) {
if (!Router && createOptions.routes) {
throw err;
}
}

createOptions = createOptions || {};
createOptions.docType = isString(createOptions.docType) ? createOptions.docType : Config.docType;
createOptions.renderOptionsKeysToFilter = createOptions.renderOptionsKeysToFilter || [];
Expand Down

0 comments on commit 7289e54

Please sign in to comment.