Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dep updates, update polyfill handling #2536

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion bower.json
Expand Up @@ -21,7 +21,6 @@
"license": "MIT",
"ignore": [
"**/.*",
"*.iml",
"examples",
"lib",
"node_modules",
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/buildURL.js
Expand Up @@ -39,7 +39,7 @@ module.exports = function buildURL(url, params, paramsSerializer) {
return;
}

if (utils.isArray(val)) {
if (Array.isArray(val)) {
key = key + '[]';
} else {
val = [val];
Expand Down
4 changes: 2 additions & 2 deletions lib/helpers/parseHeaders.js
Expand Up @@ -34,8 +34,8 @@ module.exports = function parseHeaders(headers) {

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

if (key) {
if (parsed[key] && ignoreDuplicateOf.indexOf(key) >= 0) {
Expand Down
28 changes: 2 additions & 26 deletions lib/utils.js
Expand Up @@ -2,22 +2,10 @@

var bind = require('./helpers/bind');

/*global toString:true*/

// utils is a library of generic helper functions non-specific to axios

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 undefined
*
Expand Down Expand Up @@ -165,16 +153,6 @@ 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
*
Expand Down Expand Up @@ -226,7 +204,7 @@ function forEach(obj, fn) {
obj = [obj];
}

if (isArray(obj)) {
if (Array.isArray(obj)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proof that Array.isArray is well supported and possibly more reliable since it doesn't depend on a string representation check:

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

// Iterate over array values
for (var i = 0, l = obj.length; i < l; i++) {
fn.call(null, obj[i], i, obj);
Expand Down Expand Up @@ -320,7 +298,6 @@ function extend(a, b, thisArg) {
}

module.exports = {
isArray: isArray,
isArrayBuffer: isArrayBuffer,
isBuffer: isBuffer,
isFormData: isFormData,
Expand All @@ -339,6 +316,5 @@ module.exports = {
forEach: forEach,
merge: merge,
deepMerge: deepMerge,
extend: extend,
trim: trim
extend: extend
};
40 changes: 19 additions & 21 deletions package.json
Expand Up @@ -32,41 +32,39 @@
},
"homepage": "https://github.com/axios/axios",
"devDependencies": {
"bundlesize": "^0.17.0",
"coveralls": "^3.0.0",
"es6-promise": "^4.2.4",
"bundlesize": "^0.18.0",
"coveralls": "^3.0.9",
"grunt": "^1.0.2",
"grunt-banner": "^0.6.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-eslint": "^20.1.0",
"grunt-karma": "^2.0.0",
"grunt-eslint": "^22.0.0",
"grunt-karma": "^3.0.2",
"grunt-mocha-test": "^0.13.3",
"grunt-ts": "^6.0.0-beta.19",
"grunt-webpack": "^1.0.18",
"istanbul-instrumenter-loader": "^1.0.0",
"jasmine-core": "^2.4.1",
"karma": "^1.3.0",
"karma-chrome-launcher": "^2.2.0",
"karma-coverage": "^1.1.1",
"karma-firefox-launcher": "^1.1.0",
"karma-jasmine": "^1.1.1",
"grunt-webpack": "^3.1.3",
"istanbul-instrumenter-loader": "^3.0.1",
"jasmine-core": "^3.5.0",
"karma": "^4.3.0",
"karma-chrome-launcher": "^3.1.0",
"karma-coverage": "^2.0.1",
"karma-firefox-launcher": "^1.3.0",
"karma-jasmine": "^3.1.0",
"karma-jasmine-ajax": "^0.1.13",
"karma-opera-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-sourcemap-loader": "^0.3.7",
"karma-webpack": "^1.7.0",
"load-grunt-tasks": "^3.5.2",
"karma-webpack": "^4.0.2",
"load-grunt-tasks": "^5.1.0",
"minimist": "^1.2.0",
"mocha": "^5.2.0",
"sinon": "^4.5.0",
"mocha": "^7.0.1",
"sinon": "^8.1.1",
"typescript": "^2.8.1",
"url-search-params": "^0.10.0",
"webpack": "^1.13.1",
"webpack-dev-server": "^1.14.1"
"webpack": "^4.40.2"
},
"browser": {
"./lib/adapters/http.js": "./lib/adapters/xhr.js"
Expand Down
7 changes: 5 additions & 2 deletions test/manual/basic.html
Expand Up @@ -7,7 +7,10 @@

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

<script src="promise.js"></script>
<script>
if (typeof Promise !== "function")
document.write('<script src="//cdnjs.cloudflare.com/ajax/libs/es6-promise/4.1.1/es6-promise.min.js"><\/script>');
</script>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a Cloudflare CDN polyfill for promise, which should fix the IE build breaking in continuous integration in master builds.

I recalled a question here. What's the difference between those two promises? And did you really test by IE?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chinesedfan sorry for the late reply. The Promise here is only really needed for running the unit tests in IE.

In my opinion, the unit tests can/should be moved to a brower-less testing approach, which would allow for the removal of any Promise polyfill and faster testing, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chinesedfan I had some trouble getting the IE VM from Microsoft up and running. Maybe Github actions can help with the problem here. They explicitly support the Windows containers:

https://github.com/features/actions

<script src="../../dist/axios.js"></script>
<script>
axios.get('./fixture.json').then(function(response) {
Expand All @@ -18,4 +21,4 @@
</script>

</body>
</html>
</html>
7 changes: 5 additions & 2 deletions test/manual/cors.html
Expand Up @@ -7,7 +7,10 @@

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

<script src="promise.js"></script>
<script>
if (typeof Promise !== "function")
document.write('<script src="//cdnjs.cloudflare.com/ajax/libs/es6-promise/4.1.1/es6-promise.min.js"><\/script>');
</script>
<script src="../../dist/axios.js"></script>
<script>
axios.get('http://cors-test.appspot.com/test').then(function(response) {
Expand All @@ -17,4 +20,4 @@
</script>

</body>
</html>
</html>
9 changes: 0 additions & 9 deletions test/manual/promise.js

This file was deleted.

3 changes: 0 additions & 3 deletions test/specs/__helpers.js
@@ -1,6 +1,3 @@
// Polyfill ES6 Promise
require('es6-promise').polyfill();

// Polyfill URLSearchParams
URLSearchParams = require('url-search-params');

Expand Down
5 changes: 0 additions & 5 deletions test/specs/utils/isX.spec.js
Expand Up @@ -2,11 +2,6 @@ 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 Buffer', function () {
expect(utils.isBuffer(Buffer.from('a'))).toEqual(true);
expect(utils.isBuffer(null)).toEqual(false);
Expand Down
12 changes: 0 additions & 12 deletions test/specs/utils/trim.spec.js

This file was deleted.

44 changes: 18 additions & 26 deletions webpack.config.js
@@ -1,12 +1,13 @@
var webpack = require('webpack');
var config = {};
const webpack = require('webpack');
const TerserPlugin = require('terser-webpack-plugin');
const config = {};

function generateConfig(name) {
var uglify = name.indexOf('min') > -1;
var config = {
return {
mode: 'production',
entry: './index.js',
output: {
path: 'dist/',
path: `${__dirname}/dist`,
filename: name + '.js',
sourceMapFilename: name + '.map',
library: 'axios',
Expand All @@ -15,30 +16,21 @@ function generateConfig(name) {
node: {
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) {
config[key] = generateConfig(key);
['axios', 'axios.min'].forEach(outputScript => {
config[outputScript] = generateConfig(outputScript);
});

module.exports = config;