Skip to content

Commit 3e489b5

Browse files
Fix the compiling fail for earlier versions of antd 5.x series (GH-48)
2 parents 3849641 + 20623ef commit 3e489b5

File tree

7 files changed

+147
-5
lines changed

7 files changed

+147
-5
lines changed

.github/workflows/tests.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,38 @@ jobs:
3030

3131
- name: Run tests
3232
run: npm test
33+
34+
build:
35+
36+
runs-on: ubuntu-latest
37+
38+
strategy:
39+
matrix:
40+
env: [ antd_v424, antd_v510, antd_v520, antd_v530, antd_v540, antd_v550, antd_v560, antd_v570, antd_v580, antd_v590 ]
41+
42+
steps:
43+
- name: Checkout
44+
uses: actions/checkout@v3
45+
46+
- name: Set up Python
47+
uses: actions/setup-python@v2
48+
49+
- name: Install Tox
50+
run: |
51+
pip install --upgrade pip
52+
pip install tox tox-gh-actions
53+
54+
- name: Set up Node
55+
uses: actions/setup-node@v3
56+
with:
57+
node-version: 16.x
58+
registry-url: https://registry.npmjs.org/
59+
60+
- name: Build and Package
61+
run: |
62+
npm install
63+
npm run build
64+
npm pack
65+
66+
- name: Run Tox
67+
run: tox -e ${{ matrix.env }}

examples/antd4.x/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"typescript": "^4.9.5"
1717
},
1818
"scripts": {
19-
"start": "craco start"
19+
"start": "craco start",
20+
"build": "craco build"
2021
},
2122
"eslintConfig": {
2223
"extends": [

examples/antd5.x/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"typescript": "^4.9.5"
1414
},
1515
"scripts": {
16-
"start": "react-scripts start"
16+
"start": "react-scripts start",
17+
"build": "react-scripts build"
1718
},
1819
"eslintConfig": {
1920
"extends": [

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.2.2",
2+
"version": "0.2.3",
33
"name": "antd-phone-input",
44
"description": "Advanced, highly customizable phone input component for Ant Design.",
55
"keywords": [
@@ -64,6 +64,7 @@
6464
"compile": "tsc --module commonjs && npm run rename -- cjs && npm run rename -- cjs legacy/ && tsc --declaration",
6565
"build": "npm run compile && tsx scripts/prepare-styles.ts",
6666
"prebuild": "rm -r legacy index* style* types* || true",
67+
"postpack": "tsx scripts/prepare-package.ts",
6768
"test": "jest --config jestconfig.json"
6869
},
6970
"license": "MIT",

scripts/prepare-package.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import fs from "fs";
2+
3+
const packageJson = JSON.parse(fs.readFileSync("package.json", "utf8"));
4+
const version = packageJson.version;
5+
const name = packageJson.name;
6+
7+
for (const pkgFile of ["examples/antd4.x/package.json", "examples/antd5.x/package.json"]) {
8+
const packageJson = JSON.parse(fs.readFileSync(pkgFile, "utf8"));
9+
packageJson.dependencies[name] = `file:../../${name}-${version}.tgz`;
10+
fs.writeFileSync(pkgFile, JSON.stringify(packageJson, null, 2));
11+
}

src/style.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import {mergeToken} from "antd/lib/theme/internal";
22
import * as inputHelper from "antd/lib/input/style";
33

4+
const inputStyle = inputHelper as any;
5+
46
export default (token: any) => ({
57
".react-tel-input": {
68
".country-list": {
@@ -10,8 +12,8 @@ export default (token: any) => ({
1012
".search": {backgroundColor: token.colorBgElevated},
1113
".search-box": inputHelper.genBasicInputStyle(
1214
mergeToken(
13-
((inputHelper as any).initInputToken || (() => ({})))(token),
14-
((inputHelper as any).initComponentToken || (() => ({})))(token),
15+
("initInputToken" in inputStyle ? inputStyle.initInputToken : (() => ({})))(token),
16+
("initComponentToken" in inputStyle ? inputStyle.initComponentToken : (() => ({})))(token),
1517
)
1618
),
1719
".country": {

tox.ini

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
[tox]
2+
envlist =
3+
antd_v424
4+
antd_v510
5+
antd_v520
6+
antd_v530
7+
antd_v540
8+
antd_v550
9+
antd_v560
10+
antd_v570
11+
antd_v580
12+
antd_v590
13+
14+
[testenv:antd_v424]
15+
changedir = examples/antd4.x
16+
allowlist_externals = npm
17+
commands =
18+
npm install --legacy-peer-deps
19+
npm run build
20+
21+
[testenv:antd_v510]
22+
changedir = examples/antd5.x
23+
allowlist_externals = npm
24+
commands =
25+
npm install
26+
npm install [email protected]
27+
npm run build
28+
29+
[testenv:antd_v520]
30+
changedir = examples/antd5.x
31+
allowlist_externals = npm
32+
commands =
33+
npm install
34+
npm install [email protected]
35+
npm run build
36+
37+
[testenv:antd_v530]
38+
changedir = examples/antd5.x
39+
allowlist_externals = npm
40+
commands =
41+
npm install
42+
npm install [email protected]
43+
npm run build
44+
45+
[testenv:antd_v540]
46+
changedir = examples/antd5.x
47+
allowlist_externals = npm
48+
commands =
49+
npm install
50+
npm install [email protected]
51+
npm run build
52+
53+
[testenv:antd_v550]
54+
changedir = examples/antd5.x
55+
allowlist_externals = npm
56+
commands =
57+
npm install
58+
npm install [email protected]
59+
npm run build
60+
61+
[testenv:antd_v560]
62+
changedir = examples/antd5.x
63+
allowlist_externals = npm
64+
commands =
65+
npm install
66+
npm install [email protected]
67+
npm run build
68+
69+
[testenv:antd_v570]
70+
changedir = examples/antd5.x
71+
allowlist_externals = npm
72+
commands =
73+
npm install
74+
npm install [email protected]
75+
npm run build
76+
77+
[testenv:antd_v580]
78+
changedir = examples/antd5.x
79+
allowlist_externals = npm
80+
commands =
81+
npm install
82+
npm install [email protected]
83+
npm run build
84+
85+
[testenv:antd_v590]
86+
changedir = examples/antd5.x
87+
allowlist_externals = npm
88+
commands =
89+
npm install
90+
npm install [email protected]
91+
npm run build

0 commit comments

Comments
 (0)