Skip to content

Commit a141ab5

Browse files
committed
Include umd build in npm package
Fixes #1087
1 parent 051fd03 commit a141ab5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+460
-381
lines changed

bower.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "react-router",
33
"version": "0.13.2",
44
"description": "A complete routing library for React.js",
5-
"main": "build/global/ReactRouter.js",
5+
"main": "build/umd/ReactRouter.js",
66
"homepage": "https://github.com/rackt/react-router",
77
"authors": [
88
"Ryan Florence",
@@ -17,10 +17,10 @@
1717
"**/.*",
1818
"node_modules",
1919
"bower_components",
20-
"specs",
20+
"docs",
2121
"modules",
2222
"examples",
23-
"script",
23+
"scripts",
2424
"CONTRIBUTING.md",
2525
"karma.conf.js",
2626
"package.json",

build/npm/README.md renamed to build/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[![npm package](https://img.shields.io/npm/v/react-router.svg?style=flat-square)](https://www.npmjs.org/package/react-router)
22
[![build status](https://img.shields.io/travis/rackt/react-router/master.svg?style=flat-square)](https://travis-ci.org/rackt/react-router)
33
[![dependency status](https://img.shields.io/david/rackt/react-router.svg?style=flat-square)](https://david-dm.org/rackt/react-router)
4+
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/rackt/react-router?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
45

56
React Router
67
============

build/global/ReactRouter.min.js

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
"use strict";
2-
31
/**
42
* Represents a cancellation caused by navigating away
53
* before the previous transition has fully resolved.
64
*/
5+
"use strict";
6+
77
function Cancellation() {}
88

99
module.exports = Cancellation;
File renamed without changes.
File renamed without changes.

build/npm/lib/Navigation.js renamed to build/lib/Navigation.js

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11
"use strict";
22

3-
var warning = require("react/lib/warning");
43
var PropTypes = require("./PropTypes");
54

6-
function deprecatedMethod(routerMethodName, fn) {
7-
return function () {
8-
warning(false, "Router.Navigation is deprecated. Please use this.context.router." + routerMethodName + "() instead");
9-
10-
return fn.apply(this, arguments);
11-
};
12-
}
13-
145
/**
156
* A mixin for components that modify the URL.
167
*
@@ -39,40 +30,40 @@ var Navigation = {
3930
* Returns an absolute URL path created from the given route
4031
* name, URL parameters, and query values.
4132
*/
42-
makePath: deprecatedMethod("makePath", function (to, params, query) {
33+
makePath: function makePath(to, params, query) {
4334
return this.context.router.makePath(to, params, query);
44-
}),
35+
},
4536

4637
/**
4738
* Returns a string that may safely be used as the href of a
4839
* link to the route with the given name.
4940
*/
50-
makeHref: deprecatedMethod("makeHref", function (to, params, query) {
41+
makeHref: function makeHref(to, params, query) {
5142
return this.context.router.makeHref(to, params, query);
52-
}),
43+
},
5344

5445
/**
5546
* Transitions to the URL specified in the arguments by pushing
5647
* a new URL onto the history stack.
5748
*/
58-
transitionTo: deprecatedMethod("transitionTo", function (to, params, query) {
49+
transitionTo: function transitionTo(to, params, query) {
5950
this.context.router.transitionTo(to, params, query);
60-
}),
51+
},
6152

6253
/**
6354
* Transitions to the URL specified in the arguments by replacing
6455
* the current URL in the history stack.
6556
*/
66-
replaceWith: deprecatedMethod("replaceWith", function (to, params, query) {
57+
replaceWith: function replaceWith(to, params, query) {
6758
this.context.router.replaceWith(to, params, query);
68-
}),
59+
},
6960

7061
/**
7162
* Transitions to the previous URL.
7263
*/
73-
goBack: deprecatedMethod("goBack", function () {
64+
goBack: function goBack() {
7465
return this.context.router.goBack();
75-
})
66+
}
7667

7768
};
7869

build/lib/PathUtils.js

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
/* jshint -W084 */
2+
"use strict";
3+
4+
var invariant = require("react/lib/invariant");
5+
var assign = require("object-assign");
6+
var qs = require("qs");
7+
8+
var queryMatcher = /\?(.*)$/;
9+
10+
function escapeRegExp(string) {
11+
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
12+
}
13+
14+
function _compilePattern(pattern) {
15+
var escapedSource = "";
16+
var paramNames = [];
17+
var tokens = [];
18+
19+
var match,
20+
lastIndex = 0,
21+
matcher = /:([a-zA-Z_$][a-zA-Z0-9_$]*)|\*|\(|\)/g;
22+
while (match = matcher.exec(pattern)) {
23+
if (match.index !== lastIndex) {
24+
tokens.push(pattern.slice(lastIndex, match.index));
25+
escapedSource += escapeRegExp(pattern.slice(lastIndex, match.index));
26+
}
27+
28+
if (match[1]) {
29+
escapedSource += "([^/?#]+)";
30+
paramNames.push(match[1]);
31+
} else if (match[0] === "*") {
32+
escapedSource += "(.*?)";
33+
paramNames.push("splat");
34+
} else if (match[0] === "(") {
35+
escapedSource += "(?:";
36+
} else if (match[0] === ")") {
37+
escapedSource += ")?";
38+
}
39+
40+
tokens.push(match[0]);
41+
42+
lastIndex = matcher.lastIndex;
43+
}
44+
45+
if (lastIndex !== pattern.length) {
46+
tokens.push(pattern.slice(lastIndex, pattern.length));
47+
escapedSource += escapeRegExp(pattern.slice(lastIndex, pattern.length));
48+
}
49+
50+
return {
51+
pattern: pattern,
52+
escapedSource: escapedSource,
53+
paramNames: paramNames,
54+
tokens: tokens
55+
};
56+
}
57+
58+
var _compiledPatterns = {};
59+
60+
function compilePattern(pattern) {
61+
if (!(pattern in _compiledPatterns)) _compiledPatterns[pattern] = _compilePattern(pattern);
62+
63+
return _compiledPatterns[pattern];
64+
}
65+
66+
var PathUtils = {
67+
68+
/**
69+
* Returns true if the given path is absolute.
70+
*/
71+
isAbsolute: function isAbsolute(path) {
72+
return path.charAt(0) === "/";
73+
},
74+
75+
/**
76+
* Joins two URL paths together.
77+
*/
78+
join: function join(a, b) {
79+
return a.replace(/\/*$/, "/") + b;
80+
},
81+
82+
/**
83+
* Returns an array of the names of all parameters in the given pattern.
84+
*/
85+
extractParamNames: function extractParamNames(pattern) {
86+
return compilePattern(pattern).paramNames;
87+
},
88+
89+
/**
90+
* Extracts the portions of the given URL path that match the given pattern
91+
* and returns an object of param name => value pairs. Returns null if the
92+
* pattern does not match the given path.
93+
*/
94+
extractParams: function extractParams(pattern, path) {
95+
var _compilePattern2 = compilePattern(pattern);
96+
97+
var escapedSource = _compilePattern2.escapedSource;
98+
var paramNames = _compilePattern2.paramNames;
99+
100+
var matcher = new RegExp("^" + escapedSource + "$", "i");
101+
var match = path.match(matcher);
102+
103+
if (!match) {
104+
return null;
105+
}var params = {};
106+
107+
paramNames.forEach(function (paramName, index) {
108+
params[paramName] = match[index + 1];
109+
});
110+
111+
return params;
112+
},
113+
114+
/**
115+
* Returns a version of the given route path with params interpolated. Throws
116+
* if there is a dynamic segment of the route path for which there is no param.
117+
*/
118+
injectParams: function injectParams(pattern, params) {
119+
params = params || {};
120+
121+
var _compilePattern2 = compilePattern(pattern);
122+
123+
var tokens = _compilePattern2.tokens;
124+
125+
var parenCount = 0,
126+
pathname = "",
127+
splatIndex = 0;
128+
129+
var token, paramName, paramValue;
130+
for (var i = 0, len = tokens.length; i < len; ++i) {
131+
token = tokens[i];
132+
133+
if (token === "*") {
134+
paramValue = Array.isArray(params.splat) ? params.splat[splatIndex++] : params.splat;
135+
136+
invariant(paramValue != null || parenCount > 0, "Missing splat #%s for path \"%s\"", splatIndex, pattern);
137+
138+
if (paramValue != null) pathname += paramValue;
139+
} else if (token === "(") {
140+
parenCount += 1;
141+
} else if (token === ")") {
142+
parenCount -= 1;
143+
} else if (token.charAt(0) === ":") {
144+
paramName = token.substring(1);
145+
paramValue = params[paramName];
146+
147+
invariant(paramValue != null || parenCount > 0, "Missing \"%s\" parameter for path \"%s\"", paramName, pattern);
148+
149+
if (paramValue != null) pathname += paramValue;
150+
} else {
151+
pathname += token;
152+
}
153+
}
154+
155+
return pathname.replace(/\/+/g, "/");
156+
},
157+
158+
/**
159+
* Returns an object that is the result of parsing any query string contained
160+
* in the given path, null if the path contains no query string.
161+
*/
162+
extractQuery: function extractQuery(path) {
163+
var match = path.match(queryMatcher);
164+
return match && qs.parse(match[1]);
165+
},
166+
167+
/**
168+
* Returns a version of the given path without the query string.
169+
*/
170+
withoutQuery: function withoutQuery(path) {
171+
return path.replace(queryMatcher, "");
172+
},
173+
174+
/**
175+
* Returns a version of the given path with the parameters in the given
176+
* query merged into the query string.
177+
*/
178+
withQuery: function withQuery(path, query) {
179+
var existingQuery = PathUtils.extractQuery(path);
180+
181+
if (existingQuery) query = query ? assign(existingQuery, query) : existingQuery;
182+
183+
var queryString = qs.stringify(query, { arrayFormat: "brackets" });
184+
185+
if (queryString) {
186+
return PathUtils.withoutQuery(path) + "?" + queryString;
187+
}return PathUtils.withoutQuery(path);
188+
}
189+
190+
};
191+
192+
module.exports = PathUtils;

build/npm/lib/PropTypes.js renamed to build/lib/PropTypes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var PropTypes = assign({}, ReactPropTypes, {
1111
*/
1212
falsy: function falsy(props, propName, componentName) {
1313
if (props[propName]) {
14-
return new Error("<" + componentName + "> may not have a \"" + propName + "\" prop");
14+
return new Error("<" + componentName + "> should not have a \"" + propName + "\" prop");
1515
}
1616
},
1717

build/npm/lib/Redirect.js renamed to build/lib/Redirect.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
"use strict";
2-
31
/**
42
* Encapsulates a redirect to the given route.
53
*/
4+
"use strict";
5+
66
function Redirect(to, params, query) {
77
this.to = to;
88
this.params = params;

0 commit comments

Comments
 (0)