Skip to content

Commit 0979486

Browse files
Revert "Update Webpack + deps, remove now unnecessary polyfills" (axios#2479)
* Revert "Update Webpack + deps, remove now unnecessary polyfills (axios#2410)" This reverts commit 189b34c. * Fix build (axios#2496) * Change syntax to see if build passes * Test commit * Test with node 10 * Test adding all browsers in travis * remove other browsers when running on travis
1 parent 494d817 commit 0979486

File tree

13 files changed

+113
-47
lines changed

13 files changed

+113
-47
lines changed

bower.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"license": "MIT",
2222
"ignore": [
2323
"**/.*",
24+
"*.iml",
2425
"examples",
2526
"lib",
2627
"node_modules",

lib/core/enhanceError.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = function enhanceError(error, config, code, request, response) {
2020
error.response = response;
2121
error.isAxiosError = true;
2222

23-
error.toJSON = function toJSON() {
23+
error.toJSON = function() {
2424
return {
2525
// Standard
2626
message: this.message,

lib/helpers/buildURL.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ module.exports = function buildURL(url, params, paramsSerializer) {
3939
return;
4040
}
4141

42-
if (Array.isArray(val)) {
42+
if (utils.isArray(val)) {
4343
key = key + '[]';
4444
} else {
4545
val = [val];

lib/helpers/parseHeaders.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ module.exports = function parseHeaders(headers) {
3434

3535
utils.forEach(headers.split('\n'), function parser(line) {
3636
i = line.indexOf(':');
37-
key = line.substr(0, i).trim().toLowerCase();
38-
val = line.substr(i + 1).trim();
37+
key = utils.trim(line.substr(0, i)).toLowerCase();
38+
val = utils.trim(line.substr(i + 1));
3939

4040
if (key) {
4141
if (parsed[key] && ignoreDuplicateOf.indexOf(key) >= 0) {

lib/utils.js

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,21 @@
33
var bind = require('./helpers/bind');
44
var isBuffer = require('is-buffer');
55

6+
/*global toString:true*/
7+
68
// utils is a library of generic helper functions non-specific to axios
79

8-
var _toString = Object.prototype.toString;
10+
var toString = Object.prototype.toString;
11+
12+
/**
13+
* Determine if a value is an Array
14+
*
15+
* @param {Object} val The value to test
16+
* @returns {boolean} True if value is an Array, otherwise false
17+
*/
18+
function isArray(val) {
19+
return toString.call(val) === '[object Array]';
20+
}
921

1022
/**
1123
* Determine if a value is an ArrayBuffer
@@ -14,7 +26,7 @@ var _toString = Object.prototype.toString;
1426
* @returns {boolean} True if value is an ArrayBuffer, otherwise false
1527
*/
1628
function isArrayBuffer(val) {
17-
return _toString.call(val) === '[object ArrayBuffer]';
29+
return toString.call(val) === '[object ArrayBuffer]';
1830
}
1931

2032
/**
@@ -90,7 +102,7 @@ function isObject(val) {
90102
* @returns {boolean} True if value is a Date, otherwise false
91103
*/
92104
function isDate(val) {
93-
return _toString.call(val) === '[object Date]';
105+
return toString.call(val) === '[object Date]';
94106
}
95107

96108
/**
@@ -100,7 +112,7 @@ function isDate(val) {
100112
* @returns {boolean} True if value is a File, otherwise false
101113
*/
102114
function isFile(val) {
103-
return _toString.call(val) === '[object File]';
115+
return toString.call(val) === '[object File]';
104116
}
105117

106118
/**
@@ -110,7 +122,7 @@ function isFile(val) {
110122
* @returns {boolean} True if value is a Blob, otherwise false
111123
*/
112124
function isBlob(val) {
113-
return _toString.call(val) === '[object Blob]';
125+
return toString.call(val) === '[object Blob]';
114126
}
115127

116128
/**
@@ -120,7 +132,7 @@ function isBlob(val) {
120132
* @returns {boolean} True if value is a Function, otherwise false
121133
*/
122134
function isFunction(val) {
123-
return _toString.call(val) === '[object Function]';
135+
return toString.call(val) === '[object Function]';
124136
}
125137

126138
/**
@@ -143,6 +155,16 @@ function isURLSearchParams(val) {
143155
return typeof URLSearchParams !== 'undefined' && val instanceof URLSearchParams;
144156
}
145157

158+
/**
159+
* Trim excess whitespace off the beginning and end of a string
160+
*
161+
* @param {String} str The String to trim
162+
* @returns {String} The String freed of excess whitespace
163+
*/
164+
function trim(str) {
165+
return str.replace(/^\s*/, '').replace(/\s*$/, '');
166+
}
167+
146168
/**
147169
* Determine if we're running in a standard browser environment
148170
*
@@ -194,7 +216,7 @@ function forEach(obj, fn) {
194216
obj = [obj];
195217
}
196218

197-
if (Array.isArray(obj)) {
219+
if (isArray(obj)) {
198220
// Iterate over array values
199221
for (var i = 0, l = obj.length; i < l; i++) {
200222
fn.call(null, obj[i], i, obj);
@@ -288,6 +310,7 @@ function extend(a, b, thisArg) {
288310
}
289311

290312
module.exports = {
313+
isArray: isArray,
291314
isArrayBuffer: isArrayBuffer,
292315
isBuffer: isBuffer,
293316
isFormData: isFormData,
@@ -306,5 +329,6 @@ module.exports = {
306329
forEach: forEach,
307330
merge: merge,
308331
deepMerge: deepMerge,
309-
extend: extend
332+
extend: extend,
333+
trim: trim
310334
};

package.json

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,37 +34,39 @@
3434
"devDependencies": {
3535
"bundlesize": "^0.17.0",
3636
"coveralls": "^3.0.0",
37+
"es6-promise": "^4.2.4",
3738
"grunt": "^1.0.2",
3839
"grunt-banner": "^0.6.0",
3940
"grunt-cli": "^1.2.0",
40-
"grunt-contrib-clean": "^2.0.0",
41+
"grunt-contrib-clean": "^1.1.0",
4142
"grunt-contrib-watch": "^1.0.0",
42-
"grunt-eslint": "^22.0.0",
43-
"grunt-karma": "^3.0.2",
43+
"grunt-eslint": "^20.1.0",
44+
"grunt-karma": "^2.0.0",
4445
"grunt-mocha-test": "^0.13.3",
4546
"grunt-ts": "^6.0.0-beta.19",
46-
"grunt-webpack": "^3.1.3",
47-
"istanbul-instrumenter-loader": "^3.0.1",
47+
"grunt-webpack": "^1.0.18",
48+
"istanbul-instrumenter-loader": "^1.0.0",
4849
"jasmine-core": "^2.4.1",
49-
"karma": "^4.3.0",
50-
"karma-chrome-launcher": "^3.1.0",
51-
"karma-coverage": "^2.0.1",
50+
"karma": "^1.3.0",
51+
"karma-chrome-launcher": "^2.2.0",
52+
"karma-coverage": "^1.1.1",
5253
"karma-firefox-launcher": "^1.1.0",
53-
"karma-jasmine": "^2.0.1",
54+
"karma-jasmine": "^1.1.1",
5455
"karma-jasmine-ajax": "^0.1.13",
5556
"karma-opera-launcher": "^1.0.0",
5657
"karma-safari-launcher": "^1.0.0",
57-
"karma-sauce-launcher": "^2.0.2",
58+
"karma-sauce-launcher": "^1.2.0",
5859
"karma-sinon": "^1.0.5",
5960
"karma-sourcemap-loader": "^0.3.7",
60-
"karma-webpack": "^4.0.2",
61-
"load-grunt-tasks": "^5.1.0",
61+
"karma-webpack": "^1.7.0",
62+
"load-grunt-tasks": "^3.5.2",
6263
"minimist": "^1.2.0",
63-
"mocha": "^6.2.0",
64-
"sinon": "^7.4.2",
64+
"mocha": "^5.2.0",
65+
"sinon": "^4.5.0",
6566
"typescript": "^2.8.1",
6667
"url-search-params": "^0.10.0",
67-
"webpack": "^4.40.2"
68+
"webpack": "^1.13.1",
69+
"webpack-dev-server": "^1.14.1"
6870
},
6971
"browser": {
7072
"./lib/adapters/http.js": "./lib/adapters/xhr.js"

test/manual/basic.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
An alert should be shown with the <code>{"name":"axios"}</code>
99

10+
<script src="promise.js"></script>
1011
<script src="../../dist/axios.js"></script>
1112
<script>
1213
axios.get('./fixture.json').then(function(response) {
@@ -17,4 +18,4 @@
1718
</script>
1819

1920
</body>
20-
</html>
21+
</html>

test/manual/cors.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
An alert should be shown with <code>{"status":"ok"}</code>
99

10+
<script src="promise.js"></script>
1011
<script src="../../dist/axios.js"></script>
1112
<script>
1213
axios.get('http://cors-test.appspot.com/test').then(function(response) {
@@ -16,4 +17,4 @@
1617
</script>
1718

1819
</body>
19-
</html>
20+
</html>

test/manual/promise.js

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/specs/__helpers.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Polyfill ES6 Promise
2+
require('es6-promise').polyfill();
3+
14
// Polyfill URLSearchParams
25
URLSearchParams = require('url-search-params');
36

test/specs/utils/isX.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ var utils = require('../../../lib/utils');
22
var Stream = require('stream');
33

44
describe('utils::isX', function () {
5+
it('should validate Array', function () {
6+
expect(utils.isArray([])).toEqual(true);
7+
expect(utils.isArray({length: 5})).toEqual(false);
8+
});
9+
510
it('should validate ArrayBuffer', function () {
611
expect(utils.isArrayBuffer(new ArrayBuffer(2))).toEqual(true);
712
expect(utils.isArrayBuffer({})).toEqual(false);

test/specs/utils/trim.spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var trim = require('../../../lib/utils').trim;
2+
3+
describe('utils::trim', function () {
4+
it('should trim spaces', function () {
5+
expect(trim(' foo ')).toEqual('foo');
6+
});
7+
8+
it('should trim tabs', function () {
9+
expect(trim('\tfoo\t')).toEqual('foo');
10+
});
11+
});
12+

webpack.config.js

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
const webpack = require('webpack');
2-
const TerserPlugin = require('terser-webpack-plugin');
3-
const config = {};
1+
var webpack = require('webpack');
2+
var config = {};
43

54
function generateConfig(name) {
6-
return {
7-
mode: 'production',
5+
var uglify = name.indexOf('min') > -1;
6+
var config = {
87
entry: './index.js',
98
output: {
10-
path: `${__dirname}/dist`,
9+
path: 'dist/',
1110
filename: name + '.js',
1211
sourceMapFilename: name + '.map',
1312
library: 'axios',
@@ -16,21 +15,30 @@ function generateConfig(name) {
1615
node: {
1716
process: false
1817
},
19-
devtool: 'source-map',
20-
optimization: {
21-
minimize: name.includes('min'),
22-
minimizer: [
23-
// config options documented at https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
24-
new TerserPlugin({
25-
sourceMap: true,
26-
}),
27-
],
28-
},
18+
devtool: 'source-map'
2919
};
20+
21+
config.plugins = [
22+
new webpack.DefinePlugin({
23+
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
24+
})
25+
];
26+
27+
if (uglify) {
28+
config.plugins.push(
29+
new webpack.optimize.UglifyJsPlugin({
30+
compressor: {
31+
warnings: false
32+
}
33+
})
34+
);
35+
}
36+
37+
return config;
3038
}
3139

32-
['axios', 'axios.min'].forEach(outputScript => {
33-
config[outputScript] = generateConfig(outputScript);
40+
['axios', 'axios.min'].forEach(function (key) {
41+
config[key] = generateConfig(key);
3442
});
3543

3644
module.exports = config;

0 commit comments

Comments
 (0)