Skip to content

Commit

Permalink
Include umd build in npm package
Browse files Browse the repository at this point in the history
  • Loading branch information
mjackson committed Apr 21, 2015
1 parent 051fd03 commit a141ab5
Show file tree
Hide file tree
Showing 44 changed files with 460 additions and 381 deletions.
6 changes: 3 additions & 3 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "react-router",
"version": "0.13.2",
"description": "A complete routing library for React.js",
"main": "build/global/ReactRouter.js",
"main": "build/umd/ReactRouter.js",
"homepage": "https://github.com/rackt/react-router",
"authors": [
"Ryan Florence",
Expand All @@ -17,10 +17,10 @@
"**/.*",
"node_modules",
"bower_components",
"specs",
"docs",
"modules",
"examples",
"script",
"scripts",
"CONTRIBUTING.md",
"karma.conf.js",
"package.json",
Expand Down
1 change: 1 addition & 0 deletions build/npm/README.md → build/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[![npm package](https://img.shields.io/npm/v/react-router.svg?style=flat-square)](https://www.npmjs.org/package/react-router)
[![build status](https://img.shields.io/travis/rackt/react-router/master.svg?style=flat-square)](https://travis-ci.org/rackt/react-router)
[![dependency status](https://img.shields.io/david/rackt/react-router.svg?style=flat-square)](https://david-dm.org/rackt/react-router)
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/rackt/react-router?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)

React Router
============
Expand Down
6 changes: 0 additions & 6 deletions build/global/ReactRouter.min.js

This file was deleted.

4 changes: 2 additions & 2 deletions build/npm/lib/Cancellation.js → build/lib/Cancellation.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use strict";

/**
* Represents a cancellation caused by navigating away
* before the previous transition has fully resolved.
*/
"use strict";

function Cancellation() {}

module.exports = Cancellation;
File renamed without changes.
File renamed without changes.
29 changes: 10 additions & 19 deletions build/npm/lib/Navigation.js → build/lib/Navigation.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
"use strict";

var warning = require("react/lib/warning");
var PropTypes = require("./PropTypes");

function deprecatedMethod(routerMethodName, fn) {
return function () {
warning(false, "Router.Navigation is deprecated. Please use this.context.router." + routerMethodName + "() instead");

return fn.apply(this, arguments);
};
}

/**
* A mixin for components that modify the URL.
*
Expand Down Expand Up @@ -39,40 +30,40 @@ var Navigation = {
* Returns an absolute URL path created from the given route
* name, URL parameters, and query values.
*/
makePath: deprecatedMethod("makePath", function (to, params, query) {
makePath: function makePath(to, params, query) {
return this.context.router.makePath(to, params, query);
}),
},

/**
* Returns a string that may safely be used as the href of a
* link to the route with the given name.
*/
makeHref: deprecatedMethod("makeHref", function (to, params, query) {
makeHref: function makeHref(to, params, query) {
return this.context.router.makeHref(to, params, query);
}),
},

/**
* Transitions to the URL specified in the arguments by pushing
* a new URL onto the history stack.
*/
transitionTo: deprecatedMethod("transitionTo", function (to, params, query) {
transitionTo: function transitionTo(to, params, query) {
this.context.router.transitionTo(to, params, query);
}),
},

/**
* Transitions to the URL specified in the arguments by replacing
* the current URL in the history stack.
*/
replaceWith: deprecatedMethod("replaceWith", function (to, params, query) {
replaceWith: function replaceWith(to, params, query) {
this.context.router.replaceWith(to, params, query);
}),
},

/**
* Transitions to the previous URL.
*/
goBack: deprecatedMethod("goBack", function () {
goBack: function goBack() {
return this.context.router.goBack();
})
}

};

Expand Down
192 changes: 192 additions & 0 deletions build/lib/PathUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
/* jshint -W084 */
"use strict";

var invariant = require("react/lib/invariant");
var assign = require("object-assign");
var qs = require("qs");

var queryMatcher = /\?(.*)$/;

function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}

function _compilePattern(pattern) {
var escapedSource = "";
var paramNames = [];
var tokens = [];

var match,
lastIndex = 0,
matcher = /:([a-zA-Z_$][a-zA-Z0-9_$]*)|\*|\(|\)/g;
while (match = matcher.exec(pattern)) {
if (match.index !== lastIndex) {
tokens.push(pattern.slice(lastIndex, match.index));
escapedSource += escapeRegExp(pattern.slice(lastIndex, match.index));
}

if (match[1]) {
escapedSource += "([^/?#]+)";
paramNames.push(match[1]);
} else if (match[0] === "*") {
escapedSource += "(.*?)";
paramNames.push("splat");
} else if (match[0] === "(") {
escapedSource += "(?:";
} else if (match[0] === ")") {
escapedSource += ")?";
}

tokens.push(match[0]);

lastIndex = matcher.lastIndex;
}

if (lastIndex !== pattern.length) {
tokens.push(pattern.slice(lastIndex, pattern.length));
escapedSource += escapeRegExp(pattern.slice(lastIndex, pattern.length));
}

return {
pattern: pattern,
escapedSource: escapedSource,
paramNames: paramNames,
tokens: tokens
};
}

var _compiledPatterns = {};

function compilePattern(pattern) {
if (!(pattern in _compiledPatterns)) _compiledPatterns[pattern] = _compilePattern(pattern);

return _compiledPatterns[pattern];
}

var PathUtils = {

/**
* Returns true if the given path is absolute.
*/
isAbsolute: function isAbsolute(path) {
return path.charAt(0) === "/";
},

/**
* Joins two URL paths together.
*/
join: function join(a, b) {
return a.replace(/\/*$/, "/") + b;
},

/**
* Returns an array of the names of all parameters in the given pattern.
*/
extractParamNames: function extractParamNames(pattern) {
return compilePattern(pattern).paramNames;
},

/**
* Extracts the portions of the given URL path that match the given pattern
* and returns an object of param name => value pairs. Returns null if the
* pattern does not match the given path.
*/
extractParams: function extractParams(pattern, path) {
var _compilePattern2 = compilePattern(pattern);

var escapedSource = _compilePattern2.escapedSource;
var paramNames = _compilePattern2.paramNames;

var matcher = new RegExp("^" + escapedSource + "$", "i");
var match = path.match(matcher);

if (!match) {
return null;
}var params = {};

paramNames.forEach(function (paramName, index) {
params[paramName] = match[index + 1];
});

return params;
},

/**
* Returns a version of the given route path with params interpolated. Throws
* if there is a dynamic segment of the route path for which there is no param.
*/
injectParams: function injectParams(pattern, params) {
params = params || {};

var _compilePattern2 = compilePattern(pattern);

var tokens = _compilePattern2.tokens;

var parenCount = 0,
pathname = "",
splatIndex = 0;

var token, paramName, paramValue;
for (var i = 0, len = tokens.length; i < len; ++i) {
token = tokens[i];

if (token === "*") {
paramValue = Array.isArray(params.splat) ? params.splat[splatIndex++] : params.splat;

invariant(paramValue != null || parenCount > 0, "Missing splat #%s for path \"%s\"", splatIndex, pattern);

if (paramValue != null) pathname += paramValue;
} else if (token === "(") {
parenCount += 1;
} else if (token === ")") {
parenCount -= 1;
} else if (token.charAt(0) === ":") {
paramName = token.substring(1);
paramValue = params[paramName];

invariant(paramValue != null || parenCount > 0, "Missing \"%s\" parameter for path \"%s\"", paramName, pattern);

if (paramValue != null) pathname += paramValue;
} else {
pathname += token;
}
}

return pathname.replace(/\/+/g, "/");
},

/**
* Returns an object that is the result of parsing any query string contained
* in the given path, null if the path contains no query string.
*/
extractQuery: function extractQuery(path) {
var match = path.match(queryMatcher);
return match && qs.parse(match[1]);
},

/**
* Returns a version of the given path without the query string.
*/
withoutQuery: function withoutQuery(path) {
return path.replace(queryMatcher, "");
},

/**
* Returns a version of the given path with the parameters in the given
* query merged into the query string.
*/
withQuery: function withQuery(path, query) {
var existingQuery = PathUtils.extractQuery(path);

if (existingQuery) query = query ? assign(existingQuery, query) : existingQuery;

var queryString = qs.stringify(query, { arrayFormat: "brackets" });

if (queryString) {
return PathUtils.withoutQuery(path) + "?" + queryString;
}return PathUtils.withoutQuery(path);
}

};

module.exports = PathUtils;
2 changes: 1 addition & 1 deletion build/npm/lib/PropTypes.js → build/lib/PropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var PropTypes = assign({}, ReactPropTypes, {
*/
falsy: function falsy(props, propName, componentName) {
if (props[propName]) {
return new Error("<" + componentName + "> may not have a \"" + propName + "\" prop");
return new Error("<" + componentName + "> should not have a \"" + propName + "\" prop");
}
},

Expand Down
4 changes: 2 additions & 2 deletions build/npm/lib/Redirect.js → build/lib/Redirect.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"use strict";

/**
* Encapsulates a redirect to the given route.
*/
"use strict";

function Redirect(to, params, query) {
this.to = to;
this.params = params;
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit a141ab5

Please sign in to comment.