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

Throw an error if peer dependency is not installed #98

Merged
merged 1 commit into from
Oct 28, 2015

Conversation

stevemao
Copy link
Contributor

No description provided.

}

if (!Router) {
throw new Error('React Router is required as a peer dependency. Run `npm instal react-router`.')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stevemao why are we throwing error if Router is not present, I thought the point was to make it optional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not? #97

@stevemao right now no. I guess we can move this https://github.com/paypal/react-engine/blob/master/lib/server.js#L29

Sorry if I misunderstood you.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

absolutely, but you might want to check if the user is intending to use react-router or not before throwing here.

once simple way is to examine if routes property exists in creatOptions createOptions.routes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Are you saying you want to make react-router optional if no router relevant options are passed?
My concern is if we make react-router optional, is there any other places we need to change?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to do a similar check in client.js as well.

@stevemao stevemao force-pushed the peer-deps branch 2 times, most recently from 0c49dbc to 5bf5bf1 Compare October 18, 2015 21:49
@stevemao
Copy link
Contributor Author

How does it look now? @samsel

@@ -38,6 +34,18 @@ var TEMPLATE = ['<script id="%s" type="application/javascript">var ',

exports.create = function create(createOptions) {

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stevemao if react-router is not installed, an error will be thrown on line 39 by default.

The correct way to do this would be to enclose this in a try/catch and conditionally throw.
condition === if (!Router && createOptions.routes)

@stevemao stevemao force-pushed the peer-deps branch 2 times, most recently from 375278a to 975d9ba Compare October 20, 2015 22:16
@stevemao
Copy link
Contributor Author

Updated. @samsel

}

if (!React) {
throw new Error('React is required as a peer dependency. Run `npm instal react` to install react.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, but this is not needed right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I don't think we need to throw a new Error then. Just throw the caught error.

@stevemao
Copy link
Contributor Author

@samsel any news?

samsel added a commit that referenced this pull request Oct 28, 2015
Throw an error if peer dependency is not installed
@samsel samsel merged commit 01d16e4 into paypal:master Oct 28, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants