@lx-frontend/multi-ajax 0.2.4 → 0.2.6-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/scripts/axios/dist/axios.js +2966 -0
- package/build/scripts/axios/dist/browser/axios.cjs +3193 -0
- package/build/scripts/axios/dist/esm/axios.js +3215 -0
- package/build/scripts/axios/dist/esm/axios.min.js +1160 -0
- package/build/scripts/patch-axios-post-install.js +15 -35
- package/build/utils.js +25 -2
- package/dist/index.js +816 -0
- package/dist/index.js.map +1 -0
- package/output/src/adapters/index.js +2 -0
- package/output/src/adapters/wx-adapter.js +142 -0
- package/output/src/cancelLastSameRequest.js +81 -0
- package/output/src/canceller.js +94 -0
- package/output/src/compatibleMethods.js +303 -0
- package/output/src/duplicateRequestPrevent.js +17 -0
- package/output/src/helpers.js +130 -0
- package/output/src/index.js +36 -0
- package/output/src/methods.js +318 -0
- package/output/src/types.js +1 -0
- package/output/src/utils.js +108 -0
- package/package.json +1 -1
- /package/build/scripts/{patch-content.txt → axios/lib/platform/browser/index.js} +0 -0
|
@@ -1,40 +1,20 @@
|
|
|
1
|
-
const fs = require('fs')
|
|
2
1
|
const path = require('path')
|
|
3
|
-
const { resolveAxiosPath } = require('../utils')
|
|
4
|
-
|
|
5
|
-
function patchBrowserIndex(axiosPath) {
|
|
6
|
-
const patchPath = path.resolve(axiosPath, 'lib/platform/browser/index.js')
|
|
7
|
-
|
|
8
|
-
// TODO: 验证axios版本
|
|
9
|
-
// TODO:确定在pnpm下,如果存在多个axios版本会怎样?
|
|
10
|
-
|
|
11
|
-
const contentPath = path.resolve(__dirname, './patch-content.txt')
|
|
12
|
-
const patchContent = fs.readFileSync(contentPath)
|
|
13
|
-
|
|
14
|
-
console.log('patched axios file:', patchPath)
|
|
15
|
-
fs.writeFileSync(patchPath, patchContent)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function patchAxiosPackageJson(axiosPath) {
|
|
19
|
-
const packagePath = path.resolve(axiosPath, 'package.json')
|
|
20
|
-
|
|
21
|
-
const contentObj = require(packagePath)
|
|
22
|
-
|
|
23
|
-
const exportDot = contentObj.exports['.']
|
|
24
|
-
|
|
25
|
-
exportDot.browser.require = './index.js'
|
|
26
|
-
exportDot.default.require = './index.js'
|
|
27
|
-
|
|
28
|
-
fs.writeFileSync(packagePath, JSON.stringify(contentObj), {encoding: 'utf8'})
|
|
29
|
-
}
|
|
2
|
+
const { resolveAxiosPath, copyFiles } = require('../utils')
|
|
30
3
|
|
|
4
|
+
/**
|
|
5
|
+
* 从 packages/multi-ajax/build/scripts/axios 复制文件覆盖 node_modules/axios 中文件
|
|
6
|
+
*/
|
|
31
7
|
function patchAxios() {
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
8
|
+
const patchSourceAxiosPath = path.resolve(__dirname, './axios')
|
|
9
|
+
const targetAxiosPath = resolveAxiosPath()
|
|
10
|
+
console.log('打补丁: source', patchSourceAxiosPath)
|
|
11
|
+
console.log('打补丁: target', targetAxiosPath)
|
|
12
|
+
try {
|
|
13
|
+
copyFiles(patchSourceAxiosPath, targetAxiosPath);
|
|
14
|
+
console.log('打补丁完成')
|
|
15
|
+
} catch (e) {
|
|
16
|
+
console.log('打补丁异常', e)
|
|
17
|
+
}
|
|
38
18
|
}
|
|
39
19
|
|
|
40
|
-
patchAxios()
|
|
20
|
+
patchAxios()
|
package/build/utils.js
CHANGED
|
@@ -1,12 +1,35 @@
|
|
|
1
1
|
|
|
2
2
|
const path = require('path')
|
|
3
3
|
const resolve = require('resolve/sync');
|
|
4
|
+
const fs = require("fs");
|
|
4
5
|
|
|
5
6
|
function resolveAxiosPath() {
|
|
6
7
|
var res = resolve('axios', { basedir: __dirname, preserveSymlinks: false });
|
|
7
8
|
return path.dirname(res)
|
|
8
9
|
}
|
|
9
10
|
|
|
11
|
+
function copyFiles(sourceDir, targetDir) {
|
|
12
|
+
if (!fs.existsSync(targetDir)) {
|
|
13
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const files = fs.readdirSync(sourceDir);
|
|
17
|
+
files.forEach(file => {
|
|
18
|
+
const sourceFilePath = path.resolve(sourceDir, file);
|
|
19
|
+
const targetFilePath = path.resolve(targetDir, file);
|
|
20
|
+
|
|
21
|
+
console.log('file', file)
|
|
22
|
+
console.info(`覆盖: ${targetFilePath},来源:${sourceFilePath}`)
|
|
23
|
+
|
|
24
|
+
if (fs.statSync(sourceFilePath).isDirectory()) {
|
|
25
|
+
copyFiles(sourceFilePath, targetFilePath); // 递归处理子目录
|
|
26
|
+
} else {
|
|
27
|
+
fs.copyFileSync(sourceFilePath, targetFilePath); // 复制文件
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
10
32
|
module.exports = {
|
|
11
|
-
resolveAxiosPath
|
|
12
|
-
|
|
33
|
+
resolveAxiosPath,
|
|
34
|
+
copyFiles
|
|
35
|
+
}
|