2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-23 20:40:40 +03:00

Update Webpack + deps, remove now unnecessary polyfills (#2410)

* Update deps

 * handles webpack 1 -> 4 migration

* remove promise helpers from dev files

assume `Promise` is available, or polyfilled by
the consumer

* Remove isArray util. `isArray` has good coverage, even
   in IE9. So lets remove the custom polyfill.

 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray

also resolves a few lint issues

* Remove trim util

String.protoype.trim has good coverage (including IE9)

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim

Also, the http adapter already uses the native method.
This commit is contained in:
Avindra Goolcharan
2019-10-21 14:56:29 -04:00
committed by Felipe Martins
parent 29da6b24db
commit 189b34c45a
13 changed files with 47 additions and 113 deletions
-1
View File
@@ -21,7 +21,6 @@
"license": "MIT", "license": "MIT",
"ignore": [ "ignore": [
"**/.*", "**/.*",
"*.iml",
"examples", "examples",
"lib", "lib",
"node_modules", "node_modules",
+1 -1
View File
@@ -20,7 +20,7 @@ module.exports = function enhanceError(error, config, code, request, response) {
error.response = response; error.response = response;
error.isAxiosError = true; error.isAxiosError = true;
error.toJSON = function() { error.toJSON = function toJSON() {
return { return {
// Standard // Standard
message: this.message, message: this.message,
+1 -1
View File
@@ -39,7 +39,7 @@ module.exports = function buildURL(url, params, paramsSerializer) {
return; return;
} }
if (utils.isArray(val)) { if (Array.isArray(val)) {
key = key + '[]'; key = key + '[]';
} else { } else {
val = [val]; val = [val];
+2 -2
View File
@@ -34,8 +34,8 @@ module.exports = function parseHeaders(headers) {
utils.forEach(headers.split('\n'), function parser(line) { utils.forEach(headers.split('\n'), function parser(line) {
i = line.indexOf(':'); i = line.indexOf(':');
key = utils.trim(line.substr(0, i)).toLowerCase(); key = line.substr(0, i).trim().toLowerCase();
val = utils.trim(line.substr(i + 1)); val = line.substr(i + 1).trim();
if (key) { if (key) {
if (parsed[key] && ignoreDuplicateOf.indexOf(key) >= 0) { if (parsed[key] && ignoreDuplicateOf.indexOf(key) >= 0) {
+8 -32
View File
@@ -3,21 +3,9 @@
var bind = require('./helpers/bind'); var bind = require('./helpers/bind');
var isBuffer = require('is-buffer'); var isBuffer = require('is-buffer');
/*global toString:true*/
// utils is a library of generic helper functions non-specific to axios // 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 * Determine if a value is an ArrayBuffer
@@ -26,7 +14,7 @@ function isArray(val) {
* @returns {boolean} True if value is an ArrayBuffer, otherwise false * @returns {boolean} True if value is an ArrayBuffer, otherwise false
*/ */
function isArrayBuffer(val) { function isArrayBuffer(val) {
return toString.call(val) === '[object ArrayBuffer]'; return _toString.call(val) === '[object ArrayBuffer]';
} }
/** /**
@@ -102,7 +90,7 @@ function isObject(val) {
* @returns {boolean} True if value is a Date, otherwise false * @returns {boolean} True if value is a Date, otherwise false
*/ */
function isDate(val) { function isDate(val) {
return toString.call(val) === '[object Date]'; return _toString.call(val) === '[object Date]';
} }
/** /**
@@ -112,7 +100,7 @@ function isDate(val) {
* @returns {boolean} True if value is a File, otherwise false * @returns {boolean} True if value is a File, otherwise false
*/ */
function isFile(val) { function isFile(val) {
return toString.call(val) === '[object File]'; return _toString.call(val) === '[object File]';
} }
/** /**
@@ -122,7 +110,7 @@ function isFile(val) {
* @returns {boolean} True if value is a Blob, otherwise false * @returns {boolean} True if value is a Blob, otherwise false
*/ */
function isBlob(val) { function isBlob(val) {
return toString.call(val) === '[object Blob]'; return _toString.call(val) === '[object Blob]';
} }
/** /**
@@ -132,7 +120,7 @@ function isBlob(val) {
* @returns {boolean} True if value is a Function, otherwise false * @returns {boolean} True if value is a Function, otherwise false
*/ */
function isFunction(val) { function isFunction(val) {
return toString.call(val) === '[object Function]'; return _toString.call(val) === '[object Function]';
} }
/** /**
@@ -155,16 +143,6 @@ function isURLSearchParams(val) {
return typeof URLSearchParams !== 'undefined' && val instanceof URLSearchParams; 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 * Determine if we're running in a standard browser environment
* *
@@ -216,7 +194,7 @@ function forEach(obj, fn) {
obj = [obj]; obj = [obj];
} }
if (isArray(obj)) { if (Array.isArray(obj)) {
// Iterate over array values // Iterate over array values
for (var i = 0, l = obj.length; i < l; i++) { for (var i = 0, l = obj.length; i < l; i++) {
fn.call(null, obj[i], i, obj); fn.call(null, obj[i], i, obj);
@@ -310,7 +288,6 @@ function extend(a, b, thisArg) {
} }
module.exports = { module.exports = {
isArray: isArray,
isArrayBuffer: isArrayBuffer, isArrayBuffer: isArrayBuffer,
isBuffer: isBuffer, isBuffer: isBuffer,
isFormData: isFormData, isFormData: isFormData,
@@ -329,6 +306,5 @@ module.exports = {
forEach: forEach, forEach: forEach,
merge: merge, merge: merge,
deepMerge: deepMerge, deepMerge: deepMerge,
extend: extend, extend: extend
trim: trim
}; };
+15 -17
View File
@@ -34,39 +34,37 @@
"devDependencies": { "devDependencies": {
"bundlesize": "^0.17.0", "bundlesize": "^0.17.0",
"coveralls": "^3.0.0", "coveralls": "^3.0.0",
"es6-promise": "^4.2.4",
"grunt": "^1.0.2", "grunt": "^1.0.2",
"grunt-banner": "^0.6.0", "grunt-banner": "^0.6.0",
"grunt-cli": "^1.2.0", "grunt-cli": "^1.2.0",
"grunt-contrib-clean": "^1.1.0", "grunt-contrib-clean": "^2.0.0",
"grunt-contrib-watch": "^1.0.0", "grunt-contrib-watch": "^1.0.0",
"grunt-eslint": "^20.1.0", "grunt-eslint": "^22.0.0",
"grunt-karma": "^2.0.0", "grunt-karma": "^3.0.2",
"grunt-mocha-test": "^0.13.3", "grunt-mocha-test": "^0.13.3",
"grunt-ts": "^6.0.0-beta.19", "grunt-ts": "^6.0.0-beta.19",
"grunt-webpack": "^1.0.18", "grunt-webpack": "^3.1.3",
"istanbul-instrumenter-loader": "^1.0.0", "istanbul-instrumenter-loader": "^3.0.1",
"jasmine-core": "^2.4.1", "jasmine-core": "^2.4.1",
"karma": "^1.3.0", "karma": "^4.3.0",
"karma-chrome-launcher": "^2.2.0", "karma-chrome-launcher": "^3.1.0",
"karma-coverage": "^1.1.1", "karma-coverage": "^2.0.1",
"karma-firefox-launcher": "^1.1.0", "karma-firefox-launcher": "^1.1.0",
"karma-jasmine": "^1.1.1", "karma-jasmine": "^2.0.1",
"karma-jasmine-ajax": "^0.1.13", "karma-jasmine-ajax": "^0.1.13",
"karma-opera-launcher": "^1.0.0", "karma-opera-launcher": "^1.0.0",
"karma-safari-launcher": "^1.0.0", "karma-safari-launcher": "^1.0.0",
"karma-sauce-launcher": "^1.2.0", "karma-sauce-launcher": "^2.0.2",
"karma-sinon": "^1.0.5", "karma-sinon": "^1.0.5",
"karma-sourcemap-loader": "^0.3.7", "karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^1.7.0", "karma-webpack": "^4.0.2",
"load-grunt-tasks": "^3.5.2", "load-grunt-tasks": "^5.1.0",
"minimist": "^1.2.0", "minimist": "^1.2.0",
"mocha": "^5.2.0", "mocha": "^6.2.0",
"sinon": "^4.5.0", "sinon": "^7.4.2",
"typescript": "^2.8.1", "typescript": "^2.8.1",
"url-search-params": "^0.10.0", "url-search-params": "^0.10.0",
"webpack": "^1.13.1", "webpack": "^4.40.2"
"webpack-dev-server": "^1.14.1"
}, },
"browser": { "browser": {
"./lib/adapters/http.js": "./lib/adapters/xhr.js" "./lib/adapters/http.js": "./lib/adapters/xhr.js"
-1
View File
@@ -7,7 +7,6 @@
An alert should be shown with the <code>{"name":"axios"}</code> An alert should be shown with the <code>{"name":"axios"}</code>
<script src="promise.js"></script>
<script src="../../dist/axios.js"></script> <script src="../../dist/axios.js"></script>
<script> <script>
axios.get('./fixture.json').then(function(response) { axios.get('./fixture.json').then(function(response) {
-1
View File
@@ -7,7 +7,6 @@
An alert should be shown with <code>{"status":"ok"}</code> An alert should be shown with <code>{"status":"ok"}</code>
<script src="promise.js"></script>
<script src="../../dist/axios.js"></script> <script src="../../dist/axios.js"></script>
<script> <script>
axios.get('http://cors-test.appspot.com/test').then(function(response) { axios.get('http://cors-test.appspot.com/test').then(function(response) {
File diff suppressed because one or more lines are too long
-3
View File
@@ -1,6 +1,3 @@
// Polyfill ES6 Promise
require('es6-promise').polyfill();
// Polyfill URLSearchParams // Polyfill URLSearchParams
URLSearchParams = require('url-search-params'); URLSearchParams = require('url-search-params');
-5
View File
@@ -2,11 +2,6 @@ var utils = require('../../../lib/utils');
var Stream = require('stream'); var Stream = require('stream');
describe('utils::isX', function () { 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 () { it('should validate ArrayBuffer', function () {
expect(utils.isArrayBuffer(new ArrayBuffer(2))).toEqual(true); expect(utils.isArrayBuffer(new ArrayBuffer(2))).toEqual(true);
expect(utils.isArrayBuffer({})).toEqual(false); expect(utils.isArrayBuffer({})).toEqual(false);
-12
View File
@@ -1,12 +0,0 @@
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');
});
});
+18 -26
View File
@@ -1,12 +1,13 @@
var webpack = require('webpack'); const webpack = require('webpack');
var config = {}; const TerserPlugin = require('terser-webpack-plugin');
const config = {};
function generateConfig(name) { function generateConfig(name) {
var uglify = name.indexOf('min') > -1; return {
var config = { mode: 'production',
entry: './index.js', entry: './index.js',
output: { output: {
path: 'dist/', path: `${__dirname}/dist`,
filename: name + '.js', filename: name + '.js',
sourceMapFilename: name + '.map', sourceMapFilename: name + '.map',
library: 'axios', library: 'axios',
@@ -15,30 +16,21 @@ function generateConfig(name) {
node: { node: {
process: false process: false
}, },
devtool: 'source-map' 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,
}),
],
},
}; };
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(function (key) { ['axios', 'axios.min'].forEach(outputScript => {
config[key] = generateConfig(key); config[outputScript] = generateConfig(outputScript);
}); });
module.exports = config; module.exports = config;