Skip to content

Commit ea34d3b

Browse files
committed
build: update preinstall and deps
1 parent 8ef9206 commit ea34d3b

2 files changed

Lines changed: 44 additions & 2 deletions

File tree

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"lint:css": "stylelint \"{src,test}/**/*.{css,less}\"",
1919
"lint:es": "eslint \"{src,test}/**/*.{js,jsx,ts,tsx}\"",
2020
"prepublishOnly": "father doctor && npm run build",
21+
"preinstall": "node scripts/preinstall.js",
2122
"deploy": "gh-pages -d docs-dist"
2223
},
2324
"authors": [
@@ -54,7 +55,8 @@
5455
},
5556
"peerDependencies": {
5657
"react": ">=16.9.0",
57-
"react-dom": ">=16.9.0"
58+
"react-dom": ">=16.9.0",
59+
"react-router": "3.0.4"
5860
},
5961
"devDependencies": {
6062
"@commitlint/cli": "^17.1.2",
@@ -79,6 +81,7 @@
7981
"jest": "^29.3.1",
8082
"jest-environment-jsdom": "^29.3.1",
8183
"lint-staged": "^13.0.3",
84+
"ko-lint-config": "^2.2.15",
8285
"prettier": "^2.7.1",
8386
"prettier-plugin-organize-imports": "^3.0.0",
8487
"prettier-plugin-packagejson": "^2.2.18",
@@ -96,7 +99,6 @@
9699
"classnames": "^2.2.6",
97100
"handsontable": "7.0.1",
98101
"highlight.js": "^10.5.0",
99-
"ko-lint-config": "^2.2.15",
100102
"lodash": "^4.17.21",
101103
"mxgraph": "^4.2.2",
102104
"showdown": "^1.9.0"

scripts/preinstall.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// 由于 react-router 的版本不兼容的问题,导致 react-router@3 需要 alias 到 react-router-3 上
2+
// 在某些仓库中,会直接引用 src 下的源码,需要将源码中的 react-router-3 改写为 react-router
3+
4+
const fs = require('fs');
5+
const path = require('path');
6+
7+
function redirectReactRouterPath() {
8+
try {
9+
const files = [
10+
'src/breadcrumb/index.tsx',
11+
'src/goBack/goBack.tsx',
12+
'src/goBack/goBackButton.tsx',
13+
];
14+
const baseUrl = path.join(__dirname, '../');
15+
16+
if (fs.existsSync(path.join(__dirname, '../src'))) {
17+
files.forEach((filePath) => {
18+
let content = fs.readFileSync(path.join(baseUrl, filePath), 'utf-8');
19+
content = content.replace(/react-router-3/gm, 'react-router');
20+
fs.writeFileSync(path.join(baseUrl, filePath), content);
21+
});
22+
} else {
23+
console.log(path.join(__dirname, '../src'), '不存在');
24+
}
25+
} catch (error) {
26+
console.log(error);
27+
}
28+
}
29+
30+
try {
31+
const config = fs.readFileSync(path.join(__dirname, '../.git/config'), 'utf-8');
32+
// 如果非本仓库的情况下也去修改
33+
if (!config.includes('dt-react-component.git')) {
34+
console.log(config);
35+
redirectReactRouterPath();
36+
}
37+
} catch (error) {
38+
// 如果没有 .git 则修改
39+
redirectReactRouterPath();
40+
}

0 commit comments

Comments
 (0)