mirror of
https://github.com/axios/axios.git
synced 2026-04-11 02:11:50 +08:00
Revert "Update Webpack + deps, remove now unnecessary polyfills" (#2479)
* Revert "Update Webpack + deps, remove now unnecessary polyfills (#2410)"
This reverts commit 189b34c45a.
* Fix build (#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
This commit is contained in:
parent
494d817314
commit
097948698a
@ -21,6 +21,7 @@
|
||||
"license": "MIT",
|
||||
"ignore": [
|
||||
"**/.*",
|
||||
"*.iml",
|
||||
"examples",
|
||||
"lib",
|
||||
"node_modules",
|
||||
|
||||
@ -20,7 +20,7 @@ module.exports = function enhanceError(error, config, code, request, response) {
|
||||
error.response = response;
|
||||
error.isAxiosError = true;
|
||||
|
||||
error.toJSON = function toJSON() {
|
||||
error.toJSON = function() {
|
||||
return {
|
||||
// Standard
|
||||
message: this.message,
|
||||
|
||||
@ -39,7 +39,7 @@ module.exports = function buildURL(url, params, paramsSerializer) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Array.isArray(val)) {
|
||||
if (utils.isArray(val)) {
|
||||
key = key + '[]';
|
||||
} else {
|
||||
val = [val];
|
||||
|
||||
@ -34,8 +34,8 @@ module.exports = function parseHeaders(headers) {
|
||||
|
||||
utils.forEach(headers.split('\n'), function parser(line) {
|
||||
i = line.indexOf(':');
|
||||
key = line.substr(0, i).trim().toLowerCase();
|
||||
val = line.substr(i + 1).trim();
|
||||
key = utils.trim(line.substr(0, i)).toLowerCase();
|
||||
val = utils.trim(line.substr(i + 1));
|
||||
|
||||
if (key) {
|
||||
if (parsed[key] && ignoreDuplicateOf.indexOf(key) >= 0) {
|
||||
|
||||
40
lib/utils.js
40
lib/utils.js
@ -3,9 +3,21 @@
|
||||
var bind = require('./helpers/bind');
|
||||
var isBuffer = require('is-buffer');
|
||||
|
||||
/*global toString:true*/
|
||||
|
||||
// utils is a library of generic helper functions non-specific to axios
|
||||
|
||||
var _toString = Object.prototype.toString;
|
||||
var toString = Object.prototype.toString;
|
||||
|
||||
/**
|
||||
* Determine if a value is an Array
|
||||
*
|
||||
* @param {Object} val The value to test
|
||||
* @returns {boolean} True if value is an Array, otherwise false
|
||||
*/
|
||||
function isArray(val) {
|
||||
return toString.call(val) === '[object Array]';
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a value is an ArrayBuffer
|
||||
@ -14,7 +26,7 @@ var _toString = Object.prototype.toString;
|
||||
* @returns {boolean} True if value is an ArrayBuffer, otherwise false
|
||||
*/
|
||||
function isArrayBuffer(val) {
|
||||
return _toString.call(val) === '[object ArrayBuffer]';
|
||||
return toString.call(val) === '[object ArrayBuffer]';
|
||||
}
|
||||
|
||||
/**
|
||||
@ -90,7 +102,7 @@ function isObject(val) {
|
||||
* @returns {boolean} True if value is a Date, otherwise false
|
||||
*/
|
||||
function isDate(val) {
|
||||
return _toString.call(val) === '[object Date]';
|
||||
return toString.call(val) === '[object Date]';
|
||||
}
|
||||
|
||||
/**
|
||||
@ -100,7 +112,7 @@ function isDate(val) {
|
||||
* @returns {boolean} True if value is a File, otherwise false
|
||||
*/
|
||||
function isFile(val) {
|
||||
return _toString.call(val) === '[object File]';
|
||||
return toString.call(val) === '[object File]';
|
||||
}
|
||||
|
||||
/**
|
||||
@ -110,7 +122,7 @@ function isFile(val) {
|
||||
* @returns {boolean} True if value is a Blob, otherwise false
|
||||
*/
|
||||
function isBlob(val) {
|
||||
return _toString.call(val) === '[object Blob]';
|
||||
return toString.call(val) === '[object Blob]';
|
||||
}
|
||||
|
||||
/**
|
||||
@ -120,7 +132,7 @@ function isBlob(val) {
|
||||
* @returns {boolean} True if value is a Function, otherwise false
|
||||
*/
|
||||
function isFunction(val) {
|
||||
return _toString.call(val) === '[object Function]';
|
||||
return toString.call(val) === '[object Function]';
|
||||
}
|
||||
|
||||
/**
|
||||
@ -143,6 +155,16 @@ function isURLSearchParams(val) {
|
||||
return typeof URLSearchParams !== 'undefined' && val instanceof URLSearchParams;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trim excess whitespace off the beginning and end of a string
|
||||
*
|
||||
* @param {String} str The String to trim
|
||||
* @returns {String} The String freed of excess whitespace
|
||||
*/
|
||||
function trim(str) {
|
||||
return str.replace(/^\s*/, '').replace(/\s*$/, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if we're running in a standard browser environment
|
||||
*
|
||||
@ -194,7 +216,7 @@ function forEach(obj, fn) {
|
||||
obj = [obj];
|
||||
}
|
||||
|
||||
if (Array.isArray(obj)) {
|
||||
if (isArray(obj)) {
|
||||
// Iterate over array values
|
||||
for (var i = 0, l = obj.length; i < l; i++) {
|
||||
fn.call(null, obj[i], i, obj);
|
||||
@ -288,6 +310,7 @@ function extend(a, b, thisArg) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
isArray: isArray,
|
||||
isArrayBuffer: isArrayBuffer,
|
||||
isBuffer: isBuffer,
|
||||
isFormData: isFormData,
|
||||
@ -306,5 +329,6 @@ module.exports = {
|
||||
forEach: forEach,
|
||||
merge: merge,
|
||||
deepMerge: deepMerge,
|
||||
extend: extend
|
||||
extend: extend,
|
||||
trim: trim
|
||||
};
|
||||
|
||||
32
package.json
32
package.json
@ -34,37 +34,39 @@
|
||||
"devDependencies": {
|
||||
"bundlesize": "^0.17.0",
|
||||
"coveralls": "^3.0.0",
|
||||
"es6-promise": "^4.2.4",
|
||||
"grunt": "^1.0.2",
|
||||
"grunt-banner": "^0.6.0",
|
||||
"grunt-cli": "^1.2.0",
|
||||
"grunt-contrib-clean": "^2.0.0",
|
||||
"grunt-contrib-clean": "^1.1.0",
|
||||
"grunt-contrib-watch": "^1.0.0",
|
||||
"grunt-eslint": "^22.0.0",
|
||||
"grunt-karma": "^3.0.2",
|
||||
"grunt-eslint": "^20.1.0",
|
||||
"grunt-karma": "^2.0.0",
|
||||
"grunt-mocha-test": "^0.13.3",
|
||||
"grunt-ts": "^6.0.0-beta.19",
|
||||
"grunt-webpack": "^3.1.3",
|
||||
"istanbul-instrumenter-loader": "^3.0.1",
|
||||
"grunt-webpack": "^1.0.18",
|
||||
"istanbul-instrumenter-loader": "^1.0.0",
|
||||
"jasmine-core": "^2.4.1",
|
||||
"karma": "^4.3.0",
|
||||
"karma-chrome-launcher": "^3.1.0",
|
||||
"karma-coverage": "^2.0.1",
|
||||
"karma": "^1.3.0",
|
||||
"karma-chrome-launcher": "^2.2.0",
|
||||
"karma-coverage": "^1.1.1",
|
||||
"karma-firefox-launcher": "^1.1.0",
|
||||
"karma-jasmine": "^2.0.1",
|
||||
"karma-jasmine": "^1.1.1",
|
||||
"karma-jasmine-ajax": "^0.1.13",
|
||||
"karma-opera-launcher": "^1.0.0",
|
||||
"karma-safari-launcher": "^1.0.0",
|
||||
"karma-sauce-launcher": "^2.0.2",
|
||||
"karma-sauce-launcher": "^1.2.0",
|
||||
"karma-sinon": "^1.0.5",
|
||||
"karma-sourcemap-loader": "^0.3.7",
|
||||
"karma-webpack": "^4.0.2",
|
||||
"load-grunt-tasks": "^5.1.0",
|
||||
"karma-webpack": "^1.7.0",
|
||||
"load-grunt-tasks": "^3.5.2",
|
||||
"minimist": "^1.2.0",
|
||||
"mocha": "^6.2.0",
|
||||
"sinon": "^7.4.2",
|
||||
"mocha": "^5.2.0",
|
||||
"sinon": "^4.5.0",
|
||||
"typescript": "^2.8.1",
|
||||
"url-search-params": "^0.10.0",
|
||||
"webpack": "^4.40.2"
|
||||
"webpack": "^1.13.1",
|
||||
"webpack-dev-server": "^1.14.1"
|
||||
},
|
||||
"browser": {
|
||||
"./lib/adapters/http.js": "./lib/adapters/xhr.js"
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
|
||||
An alert should be shown with the <code>{"name":"axios"}</code>
|
||||
|
||||
<script src="promise.js"></script>
|
||||
<script src="../../dist/axios.js"></script>
|
||||
<script>
|
||||
axios.get('./fixture.json').then(function(response) {
|
||||
@ -17,4 +18,4 @@ An alert should be shown with the <code>{"name":"axios"}</code>
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
@ -7,6 +7,7 @@
|
||||
|
||||
An alert should be shown with <code>{"status":"ok"}</code>
|
||||
|
||||
<script src="promise.js"></script>
|
||||
<script src="../../dist/axios.js"></script>
|
||||
<script>
|
||||
axios.get('http://cors-test.appspot.com/test').then(function(response) {
|
||||
@ -16,4 +17,4 @@ An alert should be shown with <code>{"status":"ok"}</code>
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
9
test/manual/promise.js
Normal file
9
test/manual/promise.js
Normal file
File diff suppressed because one or more lines are too long
@ -1,3 +1,6 @@
|
||||
// Polyfill ES6 Promise
|
||||
require('es6-promise').polyfill();
|
||||
|
||||
// Polyfill URLSearchParams
|
||||
URLSearchParams = require('url-search-params');
|
||||
|
||||
|
||||
@ -2,6 +2,11 @@ var utils = require('../../../lib/utils');
|
||||
var Stream = require('stream');
|
||||
|
||||
describe('utils::isX', function () {
|
||||
it('should validate Array', function () {
|
||||
expect(utils.isArray([])).toEqual(true);
|
||||
expect(utils.isArray({length: 5})).toEqual(false);
|
||||
});
|
||||
|
||||
it('should validate ArrayBuffer', function () {
|
||||
expect(utils.isArrayBuffer(new ArrayBuffer(2))).toEqual(true);
|
||||
expect(utils.isArrayBuffer({})).toEqual(false);
|
||||
|
||||
12
test/specs/utils/trim.spec.js
Normal file
12
test/specs/utils/trim.spec.js
Normal file
@ -0,0 +1,12 @@
|
||||
var trim = require('../../../lib/utils').trim;
|
||||
|
||||
describe('utils::trim', function () {
|
||||
it('should trim spaces', function () {
|
||||
expect(trim(' foo ')).toEqual('foo');
|
||||
});
|
||||
|
||||
it('should trim tabs', function () {
|
||||
expect(trim('\tfoo\t')).toEqual('foo');
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,13 +1,12 @@
|
||||
const webpack = require('webpack');
|
||||
const TerserPlugin = require('terser-webpack-plugin');
|
||||
const config = {};
|
||||
var webpack = require('webpack');
|
||||
var config = {};
|
||||
|
||||
function generateConfig(name) {
|
||||
return {
|
||||
mode: 'production',
|
||||
var uglify = name.indexOf('min') > -1;
|
||||
var config = {
|
||||
entry: './index.js',
|
||||
output: {
|
||||
path: `${__dirname}/dist`,
|
||||
path: 'dist/',
|
||||
filename: name + '.js',
|
||||
sourceMapFilename: name + '.map',
|
||||
library: 'axios',
|
||||
@ -16,21 +15,30 @@ function generateConfig(name) {
|
||||
node: {
|
||||
process: false
|
||||
},
|
||||
devtool: 'source-map',
|
||||
optimization: {
|
||||
minimize: name.includes('min'),
|
||||
minimizer: [
|
||||
// config options documented at https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
|
||||
new TerserPlugin({
|
||||
sourceMap: true,
|
||||
}),
|
||||
],
|
||||
},
|
||||
devtool: 'source-map'
|
||||
};
|
||||
|
||||
config.plugins = [
|
||||
new webpack.DefinePlugin({
|
||||
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
|
||||
})
|
||||
];
|
||||
|
||||
if (uglify) {
|
||||
config.plugins.push(
|
||||
new webpack.optimize.UglifyJsPlugin({
|
||||
compressor: {
|
||||
warnings: false
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
['axios', 'axios.min'].forEach(outputScript => {
|
||||
config[outputScript] = generateConfig(outputScript);
|
||||
['axios', 'axios.min'].forEach(function (key) {
|
||||
config[key] = generateConfig(key);
|
||||
});
|
||||
|
||||
module.exports = config;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user