增加 esm 版本
parent
862f7d3134
commit
bafa1658ab
|
@ -1,4 +1,5 @@
|
|||
import axios from '../src/axios';
|
||||
import CancelToken from '../src/cancel/CancelToken';
|
||||
|
||||
describe('测试 src/axios.ts', () => {
|
||||
it('default', () => {
|
||||
|
@ -87,4 +88,22 @@ describe('测试 src/axios.ts', () => {
|
|||
|
||||
expect(instance.defaults).toEqual(axios.defaults);
|
||||
});
|
||||
|
||||
it('取消请求', (done) => {
|
||||
const source = CancelToken.source();
|
||||
const instance = axios.create();
|
||||
instance.interceptors.response.use(
|
||||
(res) => {
|
||||
return res;
|
||||
},
|
||||
(err) => {
|
||||
expect(axios.isCancel(err)).toBe(true);
|
||||
done();
|
||||
}
|
||||
);
|
||||
instance('/test', {
|
||||
cancelToken: source.token,
|
||||
});
|
||||
source.cancel('取消');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,21 +1,6 @@
|
|||
module.exports = {
|
||||
presets: [
|
||||
[
|
||||
'@babel/preset-env',
|
||||
{
|
||||
useBuiltIns: 'usage',
|
||||
corejs: 3,
|
||||
},
|
||||
],
|
||||
'@babel/preset-typescript',
|
||||
],
|
||||
presets: ['@babel/preset-env', '@babel/preset-typescript'],
|
||||
plugins: [
|
||||
[
|
||||
'@babel/plugin-transform-runtime',
|
||||
{
|
||||
corejs: 3,
|
||||
},
|
||||
],
|
||||
'@babel/plugin-transform-typescript',
|
||||
'@babel/plugin-proposal-optional-chaining',
|
||||
'@babel/plugin-proposal-nullish-coalescing-operator',
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
17
package.json
17
package.json
|
@ -1,12 +1,14 @@
|
|||
{
|
||||
"name": "axios-miniprogram",
|
||||
"version": "1.1.6",
|
||||
"version": "1.2.2",
|
||||
"description": "基于 Promise 的 HTTP 请求库,适用于各大小程序平台。",
|
||||
"main": "package/index.js",
|
||||
"miniprogram": "package",
|
||||
"main": "lib/index.js",
|
||||
"module": "es/index.js",
|
||||
"miniprogram": "lib",
|
||||
"types": "types/index.d.ts",
|
||||
"files": [
|
||||
"package",
|
||||
"lib",
|
||||
"es",
|
||||
"types"
|
||||
],
|
||||
"scripts": {
|
||||
|
@ -40,14 +42,12 @@
|
|||
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.10.4",
|
||||
"@babel/plugin-proposal-optional-chaining": "^7.11.0",
|
||||
"@babel/plugin-transform-modules-commonjs": "^7.10.4",
|
||||
"@babel/plugin-transform-runtime": "^7.10.5",
|
||||
"@babel/plugin-transform-typescript": "^7.10.3",
|
||||
"@babel/preset-env": "^7.11.0",
|
||||
"@babel/preset-typescript": "^7.10.4",
|
||||
"@babel/runtime": "^7.10.5",
|
||||
"@babel/runtime-corejs3": "^7.11.2",
|
||||
"@rollup/plugin-babel": "^5.1.0",
|
||||
"@rollup/plugin-commonjs": "^14.0.0",
|
||||
"@rollup/plugin-node-resolve": "^9.0.0",
|
||||
"@types/jest": "^26.0.5",
|
||||
"@typescript-eslint/eslint-plugin": "^3.7.0",
|
||||
"@typescript-eslint/parser": "^3.7.0",
|
||||
|
@ -59,9 +59,8 @@
|
|||
"jest": "^26.1.0",
|
||||
"lint-staged": "^10.2.11",
|
||||
"prettier": "^2.0.5",
|
||||
"rollup-plugin-node-resolve": "^5.2.0",
|
||||
"rollup-plugin-typescript2": "^0.27.1",
|
||||
"ts-jest": "^26.1.3",
|
||||
"typescript": "^3.9.7"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import nodeResolve from 'rollup-plugin-node-resolve';
|
||||
import nodeResolve from '@rollup/plugin-node-resolve';
|
||||
import babel from '@rollup/plugin-babel';
|
||||
import commonjs from '@rollup/plugin-commonjs';
|
||||
import typescript2 from 'rollup-plugin-typescript2';
|
||||
|
@ -20,23 +20,44 @@ export default function () {
|
|||
removeDir('package');
|
||||
removeDir('types');
|
||||
const extensions = ['.ts'];
|
||||
return {
|
||||
input: 'src/index.ts',
|
||||
output: {
|
||||
file: 'package/index.js',
|
||||
format: 'cjs',
|
||||
indent: false,
|
||||
return [
|
||||
{
|
||||
input: 'src/index.ts',
|
||||
output: {
|
||||
file: 'es/index.js',
|
||||
format: 'esm',
|
||||
indent: false,
|
||||
},
|
||||
plugins: [
|
||||
nodeResolve({ extensions }),
|
||||
typescript2({ useTsconfigDeclarationDir: true }),
|
||||
commonjs({
|
||||
include: /node_modules/,
|
||||
}),
|
||||
babel({
|
||||
extensions,
|
||||
babelHelpers: 'bundled',
|
||||
}),
|
||||
],
|
||||
},
|
||||
plugins: [
|
||||
nodeResolve({ extensions }),
|
||||
typescript2({ useTsconfigDeclarationDir: true }),
|
||||
commonjs({
|
||||
include: /node_modules/,
|
||||
}),
|
||||
babel({
|
||||
extensions,
|
||||
babelHelpers:'runtime'
|
||||
}),
|
||||
],
|
||||
};
|
||||
{
|
||||
input: 'src/index.ts',
|
||||
output: {
|
||||
file: 'lib/index.js',
|
||||
format: 'cjs',
|
||||
indent: false,
|
||||
},
|
||||
plugins: [
|
||||
nodeResolve({ extensions }),
|
||||
typescript2({ useTsconfigDeclarationDir: true }),
|
||||
commonjs({
|
||||
include: /node_modules/,
|
||||
}),
|
||||
babel({
|
||||
extensions,
|
||||
babelHelpers: 'bundled',
|
||||
}),
|
||||
],
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
53
yarn.lock
53
yarn.lock
|
@ -143,7 +143,7 @@
|
|||
dependencies:
|
||||
"@babel/types" "^7.10.5"
|
||||
|
||||
"@babel/helper-module-imports@^7.0.0", "@babel/helper-module-imports@^7.10.4", "@babel/helper-module-imports@^7.7.4":
|
||||
"@babel/helper-module-imports@^7.10.4", "@babel/helper-module-imports@^7.7.4":
|
||||
version "7.10.4"
|
||||
resolved "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.10.4.tgz#4c5c54be04bd31670a7382797d75b9fa2e5b5620"
|
||||
integrity sha512-nEQJHqYavI217oD9+s5MUBzk6x1IlvoS9WTPfgG43CbMEeStE0v+r+TucWdx8KFGowPGvyOkDT9+7DHedIDnVw==
|
||||
|
@ -1128,7 +1128,19 @@
|
|||
magic-string "^0.25.2"
|
||||
resolve "^1.11.0"
|
||||
|
||||
"@rollup/pluginutils@^3.0.8":
|
||||
"@rollup/plugin-node-resolve@^9.0.0":
|
||||
version "9.0.0"
|
||||
resolved "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-9.0.0.tgz#39bd0034ce9126b39c1699695f440b4b7d2b62e6"
|
||||
integrity sha512-gPz+utFHLRrd41WMP13Jq5mqqzHL3OXrfj3/MkSyB6UBIcuNt9j60GCbarzMzdf1VHFpOxfQh/ez7wyadLMqkg==
|
||||
dependencies:
|
||||
"@rollup/pluginutils" "^3.1.0"
|
||||
"@types/resolve" "1.17.1"
|
||||
builtin-modules "^3.1.0"
|
||||
deepmerge "^4.2.2"
|
||||
is-module "^1.0.0"
|
||||
resolve "^1.17.0"
|
||||
|
||||
"@rollup/pluginutils@^3.0.8", "@rollup/pluginutils@^3.1.0":
|
||||
version "3.1.0"
|
||||
resolved "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-3.1.0.tgz#706b4524ee6dc8b103b3c995533e5ad680c02b9b"
|
||||
integrity sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg==
|
||||
|
@ -1264,10 +1276,10 @@
|
|||
resolved "https://registry.npmjs.org/@types/prettier/-/prettier-2.0.2.tgz#5bb52ee68d0f8efa9cc0099920e56be6cc4e37f3"
|
||||
integrity sha512-IkVfat549ggtkZUthUzEX49562eGikhSYeVGX97SkMFn+sTZrgRewXjQ4tPKFPCykZHkX1Zfd9OoELGqKU2jJA==
|
||||
|
||||
"@types/resolve@0.0.8":
|
||||
version "0.0.8"
|
||||
resolved "https://registry.npmjs.org/@types/resolve/-/resolve-0.0.8.tgz#f26074d238e02659e323ce1a13d041eee280e194"
|
||||
integrity sha512-auApPaJf3NPfe18hSoJkp8EbZzer2ISk7o8mCC3M9he/a04+gbMF97NkpD2S8riMGvm4BMRI59/SZQSaLTKpsQ==
|
||||
"@types/resolve@1.17.1":
|
||||
version "1.17.1"
|
||||
resolved "https://registry.npmjs.org/@types/resolve/-/resolve-1.17.1.tgz#3afd6ad8967c77e4376c598a82ddd58f46ec45d6"
|
||||
integrity sha512-yy7HuzQhj0dhGpD8RLXSZWEkLsV9ibvxvi6EiJ3bkqLAO1RGo0WbkWQiwpRlSFymTJRz0d3k5LM3kkx8ArDbLw==
|
||||
dependencies:
|
||||
"@types/node" "*"
|
||||
|
||||
|
@ -3694,7 +3706,7 @@ loose-envify@^1.0.0:
|
|||
dependencies:
|
||||
js-tokens "^3.0.0 || ^4.0.0"
|
||||
|
||||
magic-string@^0.25.2:
|
||||
magic-string@^0.25.2, magic-string@^0.25.3:
|
||||
version "0.25.7"
|
||||
resolved "https://registry.npmjs.org/magic-string/-/magic-string-0.25.7.tgz#3f497d6fd34c669c6798dcb821f2ef31f5445051"
|
||||
integrity sha512-4CrMT5DOHTDk4HYDlzmwu4FVCcIYI8gauveasrdCu2IKIFOJ3f0v/8MDGJCDL9oD2ppz/Av1b0Nj345H9M+XIA==
|
||||
|
@ -4392,7 +4404,7 @@ resolve@1.15.1:
|
|||
dependencies:
|
||||
path-parse "^1.0.6"
|
||||
|
||||
resolve@^1.10.0, resolve@^1.11.0, resolve@^1.11.1, resolve@^1.17.0, resolve@^1.3.2, resolve@^1.8.1:
|
||||
resolve@^1.10.0, resolve@^1.11.0, resolve@^1.17.0, resolve@^1.3.2, resolve@^1.8.1:
|
||||
version "1.17.0"
|
||||
resolved "https://registry.npmjs.org/resolve/-/resolve-1.17.0.tgz#b25941b54968231cc2d1bb76a79cb7f2c0bf8444"
|
||||
integrity sha512-ic+7JYiV8Vi2yzQGFWOkiZD5Z9z7O2Zhm9XMaTxdJExKasieFCr+yXZ/WmXsckHiKl12ar0y6XiXDx3m4RHn1w==
|
||||
|
@ -4426,24 +4438,21 @@ rimraf@^3.0.0:
|
|||
dependencies:
|
||||
glob "^7.1.3"
|
||||
|
||||
rollup-plugin-babel@^4.4.0:
|
||||
version "4.4.0"
|
||||
resolved "https://registry.npmjs.org/rollup-plugin-babel/-/rollup-plugin-babel-4.4.0.tgz#d15bd259466a9d1accbdb2fe2fff17c52d030acb"
|
||||
integrity sha512-Lek/TYp1+7g7I+uMfJnnSJ7YWoD58ajo6Oarhlex7lvUce+RCKRuGRSgztDO3/MF/PuGKmUL5iTHKf208UNszw==
|
||||
rollup-plugin-inject@^3.0.0:
|
||||
version "3.0.2"
|
||||
resolved "https://registry.npmjs.org/rollup-plugin-inject/-/rollup-plugin-inject-3.0.2.tgz#e4233855bfba6c0c12a312fd6649dff9a13ee9f4"
|
||||
integrity sha512-ptg9PQwzs3orn4jkgXJ74bfs5vYz1NCZlSQMBUA0wKcGp5i5pA1AO3fOUEte8enhGUC+iapTCzEWw2jEFFUO/w==
|
||||
dependencies:
|
||||
"@babel/helper-module-imports" "^7.0.0"
|
||||
estree-walker "^0.6.1"
|
||||
magic-string "^0.25.3"
|
||||
rollup-pluginutils "^2.8.1"
|
||||
|
||||
rollup-plugin-node-resolve@^5.2.0:
|
||||
version "5.2.0"
|
||||
resolved "https://registry.npmjs.org/rollup-plugin-node-resolve/-/rollup-plugin-node-resolve-5.2.0.tgz#730f93d10ed202473b1fb54a5997a7db8c6d8523"
|
||||
integrity sha512-jUlyaDXts7TW2CqQ4GaO5VJ4PwwaV8VUGA7+km3n6k6xtOEacf61u0VXwN80phY/evMcaS+9eIeJ9MOyDxt5Zw==
|
||||
rollup-plugin-node-polyfills@^0.2.1:
|
||||
version "0.2.1"
|
||||
resolved "https://registry.npmjs.org/rollup-plugin-node-polyfills/-/rollup-plugin-node-polyfills-0.2.1.tgz#53092a2744837164d5b8a28812ba5f3ff61109fd"
|
||||
integrity sha512-4kCrKPTJ6sK4/gLL/U5QzVT8cxJcofO0OU74tnB19F40cmuAKSzH5/siithxlofFEjwvw1YAhPmbvGNA6jEroA==
|
||||
dependencies:
|
||||
"@types/resolve" "0.0.8"
|
||||
builtin-modules "^3.1.0"
|
||||
is-module "^1.0.0"
|
||||
resolve "^1.11.1"
|
||||
rollup-pluginutils "^2.8.1"
|
||||
rollup-plugin-inject "^3.0.0"
|
||||
|
||||
rollup-plugin-typescript2@^0.27.1:
|
||||
version "0.27.1"
|
||||
|
|
Loading…
Reference in New Issue