react-native-chart-kit 6.12.1 → 7.0.0-next.0
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/README.md +33 -35
- package/dist/{BarChart.d.ts → charts/bar/BarChart.d.ts} +8 -7
- package/dist/charts/bar/BarChart.d.ts.map +1 -0
- package/dist/charts/bar/BarChart.js +161 -0
- package/dist/charts/bar/index.d.ts +3 -0
- package/dist/charts/bar/index.d.ts.map +1 -0
- package/dist/charts/bar/index.js +3 -0
- package/dist/{contribution-graph → charts/contribution-graph}/ContributionGraph.d.ts +7 -6
- package/dist/charts/contribution-graph/ContributionGraph.d.ts.map +1 -0
- package/dist/charts/contribution-graph/ContributionGraph.js +310 -0
- package/dist/charts/contribution-graph/constants.d.ts.map +1 -0
- package/dist/charts/contribution-graph/constants.js +17 -0
- package/dist/{contribution-graph/DateHelpers.d.ts → charts/contribution-graph/date.d.ts} +1 -1
- package/dist/charts/contribution-graph/date.d.ts.map +1 -0
- package/dist/charts/contribution-graph/date.js +14 -0
- package/dist/{contribution-graph → charts/contribution-graph}/index.d.ts +1 -1
- package/dist/charts/contribution-graph/index.d.ts.map +1 -0
- package/dist/charts/contribution-graph/index.js +3 -0
- package/dist/charts/line/LegendItem.d.ts +12 -0
- package/dist/charts/line/LegendItem.d.ts.map +1 -0
- package/dist/charts/line/LegendItem.js +23 -0
- package/dist/{line-chart → charts/line}/LineChart.d.ts +10 -8
- package/dist/charts/line/LineChart.d.ts.map +1 -0
- package/dist/charts/line/LineChart.js +481 -0
- package/dist/charts/line/index.d.ts.map +1 -0
- package/dist/charts/line/index.js +3 -0
- package/dist/{PieChart.d.ts → charts/pie/PieChart.d.ts} +3 -2
- package/dist/charts/pie/PieChart.d.ts.map +1 -0
- package/dist/charts/pie/PieChart.js +103 -0
- package/dist/charts/pie/index.d.ts +3 -0
- package/dist/charts/pie/index.d.ts.map +1 -0
- package/dist/charts/pie/index.js +3 -0
- package/dist/{ProgressChart.d.ts → charts/progress/ProgressChart.d.ts} +3 -2
- package/dist/charts/progress/ProgressChart.d.ts.map +1 -0
- package/dist/charts/progress/ProgressChart.js +136 -0
- package/dist/charts/progress/index.d.ts +3 -0
- package/dist/charts/progress/index.d.ts.map +1 -0
- package/dist/charts/progress/index.js +3 -0
- package/dist/{StackedBarChart.d.ts → charts/stacked-bar/StackedBarChart.d.ts} +4 -3
- package/dist/charts/stacked-bar/StackedBarChart.d.ts.map +1 -0
- package/dist/charts/stacked-bar/StackedBarChart.js +147 -0
- package/dist/charts/stacked-bar/index.d.ts +3 -0
- package/dist/charts/stacked-bar/index.d.ts.map +1 -0
- package/dist/charts/stacked-bar/index.js +3 -0
- package/dist/index.d.ts +7 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -8
- package/dist/{AbstractChart.d.ts → shared/AbstractChart.d.ts} +81 -58
- package/dist/shared/AbstractChart.d.ts.map +1 -0
- package/dist/shared/AbstractChart.js +283 -0
- package/dist/{HelperTypes.d.ts → shared/types.d.ts} +3 -2
- package/dist/shared/types.d.ts.map +1 -0
- package/dist/shared/types.js +2 -0
- package/dist/shared/utils.d.ts +5 -0
- package/dist/shared/utils.d.ts.map +1 -0
- package/dist/shared/utils.js +10 -0
- package/package.json +101 -54
- package/scripts/chartkit-codemod.mjs +256 -0
- package/dist/AbstractChart.d.ts.map +0 -1
- package/dist/AbstractChart.js +0 -240
- package/dist/BarChart.d.ts.map +0 -1
- package/dist/BarChart.js +0 -159
- package/dist/HelperTypes.d.ts.map +0 -1
- package/dist/HelperTypes.js +0 -2
- package/dist/PieChart.d.ts.map +0 -1
- package/dist/PieChart.js +0 -101
- package/dist/ProgressChart.d.ts.map +0 -1
- package/dist/ProgressChart.js +0 -134
- package/dist/StackedBarChart.d.ts.map +0 -1
- package/dist/StackedBarChart.js +0 -144
- package/dist/Utils.d.ts +0 -2
- package/dist/Utils.d.ts.map +0 -1
- package/dist/Utils.js +0 -4
- package/dist/contribution-graph/ContributionGraph.d.ts.map +0 -1
- package/dist/contribution-graph/ContributionGraph.js +0 -309
- package/dist/contribution-graph/DateHelpers.d.ts.map +0 -1
- package/dist/contribution-graph/DateHelpers.js +0 -14
- package/dist/contribution-graph/constants.d.ts.map +0 -1
- package/dist/contribution-graph/constants.js +0 -17
- package/dist/contribution-graph/index.d.ts.map +0 -1
- package/dist/contribution-graph/index.js +0 -3
- package/dist/line-chart/LegendItem.d.ts +0 -11
- package/dist/line-chart/LegendItem.d.ts.map +0 -1
- package/dist/line-chart/LegendItem.js +0 -23
- package/dist/line-chart/LineChart.d.ts.map +0 -1
- package/dist/line-chart/LineChart.js +0 -447
- package/dist/line-chart/index.d.ts.map +0 -1
- package/dist/line-chart/index.js +0 -3
- /package/dist/{contribution-graph → charts/contribution-graph}/constants.d.ts +0 -0
- /package/dist/{line-chart → charts/line}/index.d.ts +0 -0
package/package.json
CHANGED
|
@@ -1,77 +1,124 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-chart-kit",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0-next.0",
|
|
4
|
+
"workspaces": [
|
|
5
|
+
"packages/*",
|
|
6
|
+
"apps/expo-showcase"
|
|
7
|
+
],
|
|
4
8
|
"devDependencies": {
|
|
5
|
-
"@
|
|
6
|
-
"@
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"eslint": "
|
|
11
|
-
"eslint-
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"react-native": "https://github.com/expo/react-native/archive/sdk-37.0.1.tar.gz",
|
|
24
|
-
"react-native-flash-message": "^0.1.10",
|
|
25
|
-
"react-native-scrollable-tab-view": "^1.0.0",
|
|
26
|
-
"react-native-svg": "11.0.1",
|
|
27
|
-
"react-test-renderer": "16.7.0",
|
|
28
|
-
"typescript": "^5.4.5"
|
|
9
|
+
"@eslint/js": "^9.39.4",
|
|
10
|
+
"@playwright/test": "^1.59.1",
|
|
11
|
+
"@types/node": "^25.6.0",
|
|
12
|
+
"@types/react": "^19.2.14",
|
|
13
|
+
"eslint": "^9.39.4",
|
|
14
|
+
"eslint-plugin-react": "^7.37.5",
|
|
15
|
+
"eslint-plugin-react-hooks": "^7.1.1",
|
|
16
|
+
"globals": "^17.5.0",
|
|
17
|
+
"husky": "^9.1.7",
|
|
18
|
+
"lint-staged": "^16.4.0",
|
|
19
|
+
"prettier": "^3.8.3",
|
|
20
|
+
"react": "^19.2.5",
|
|
21
|
+
"react-native": "^0.83.9",
|
|
22
|
+
"react-native-gesture-handler": "~2.28.0",
|
|
23
|
+
"react-native-svg": "^15.15.4",
|
|
24
|
+
"typescript": "^5.9.3",
|
|
25
|
+
"typescript-eslint": "^8.59.1",
|
|
26
|
+
"vitest": "^4.1.5"
|
|
29
27
|
},
|
|
30
|
-
"_main": "./node_modules/expo/AppEntry.js",
|
|
31
28
|
"main": "./dist/index.js",
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
32
30
|
"typings": "./dist/index.d.ts",
|
|
33
31
|
"files": [
|
|
34
|
-
"dist"
|
|
32
|
+
"dist",
|
|
33
|
+
"scripts/chartkit-codemod.mjs"
|
|
35
34
|
],
|
|
35
|
+
"bin": {
|
|
36
|
+
"chartkit-codemod": "./scripts/chartkit-codemod.mjs"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public",
|
|
40
|
+
"registry": "https://registry.npmjs.org/"
|
|
41
|
+
},
|
|
36
42
|
"scripts": {
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
43
|
+
"lint": "eslint .",
|
|
44
|
+
"format": "prettier --write .",
|
|
45
|
+
"format:check": "prettier --check .",
|
|
46
|
+
"surface:check": "node scripts/verify-public-surface.mjs && node scripts/verify-package-boundaries.mjs && node scripts/verify-pro-preview-imports.mjs",
|
|
47
|
+
"boundaries:check": "node scripts/verify-package-boundaries.mjs",
|
|
48
|
+
"pack:check": "node scripts/check-package-packs.mjs",
|
|
49
|
+
"test": "npm run typecheck && npm run test:unit && npm run test:compat",
|
|
50
|
+
"test:unit": "vitest run --exclude \"packages/**/test/compat/**/*.test.ts\"",
|
|
51
|
+
"test:visual": "npm run visual:test",
|
|
52
|
+
"test:compat": "vitest run packages/core/test/compat",
|
|
53
|
+
"test:e2e": "npm run e2e:test",
|
|
54
|
+
"typecheck": "tsc --noEmit && npm run core:typecheck && npm run svg:typecheck && npm run skia:typecheck && npm run pro:typecheck && npm run rn:typecheck && npm run showcase:typecheck",
|
|
55
|
+
"core:typecheck": "tsc -p packages/core/tsconfig.json --noEmit && tsc -p packages/core/tsconfig.test.json --noEmit",
|
|
56
|
+
"core:build": "tsc -p packages/core/tsconfig.json",
|
|
57
|
+
"svg:typecheck": "tsc -p packages/svg-renderer/tsconfig.json --noEmit && tsc -p packages/svg-renderer/tsconfig.test.json --noEmit",
|
|
58
|
+
"svg:build": "tsc -p packages/svg-renderer/tsconfig.json",
|
|
59
|
+
"skia:typecheck": "tsc -p packages/skia-renderer/tsconfig.json --noEmit && tsc -p packages/skia-renderer/tsconfig.test.json --noEmit",
|
|
60
|
+
"skia:build": "tsc -p packages/skia-renderer/tsconfig.json",
|
|
61
|
+
"skia:parity": "vitest run packages/skia-renderer/test/skia-renderer.test.ts packages/react-native/test/line-renderer.test.ts packages/react-native/test/bar-renderer.test.ts packages/react-native/test/pie-renderer.test.ts packages/react-native/test/progress-renderer.test.ts packages/react-native/test/contribution-renderer.test.ts packages/react-native/test/combined-renderer.test.ts packages/react-native/test/candlestick-renderer.test.ts",
|
|
62
|
+
"pro:typecheck": "tsc -p packages/pro/tsconfig.json --noEmit && tsc -p packages/pro/tsconfig.test.json --noEmit",
|
|
63
|
+
"pro:build": "tsc -p packages/pro/tsconfig.json",
|
|
64
|
+
"rn:typecheck": "tsc -p packages/react-native/tsconfig.json --noEmit && tsc -p packages/react-native/tsconfig.test.json --noEmit",
|
|
65
|
+
"rn:build": "tsc -p packages/react-native/tsconfig.build.json",
|
|
66
|
+
"benchmark": "npm run benchmark:core-geometry && npm run benchmark:showcase-interaction",
|
|
67
|
+
"benchmark:core-geometry": "node scripts/benchmark-core-line.mjs",
|
|
68
|
+
"benchmark:core-line": "node scripts/benchmark-core-line.mjs",
|
|
69
|
+
"benchmark:showcase-interaction": "npm run showcase:build && playwright test -c apps/expo-showcase/benchmark.config.ts",
|
|
70
|
+
"showcase": "npm --workspace @chart-kit/expo-showcase run web --",
|
|
71
|
+
"showcase:build": "npm --workspace @chart-kit/expo-showcase run web:build",
|
|
72
|
+
"showcase:typecheck": "npm --workspace @chart-kit/expo-showcase run typecheck",
|
|
73
|
+
"expo:typecheck": "npm --workspace @chart-kit/expo-showcase run typecheck",
|
|
74
|
+
"visual:test": "npm run showcase:build && playwright test -c apps/expo-showcase/playwright.config.ts",
|
|
75
|
+
"visual:update": "npm run showcase:build && playwright test -c apps/expo-showcase/playwright.config.ts --update-snapshots",
|
|
76
|
+
"e2e:test": "npm run showcase:build && playwright test -c apps/expo-showcase/playwright.config.ts apps/expo-showcase/visual/chart-interaction.spec.ts",
|
|
77
|
+
"example:ios": "npm --workspace @chart-kit/expo-showcase run ios --",
|
|
78
|
+
"example:android": "npm --workspace @chart-kit/expo-showcase run android --",
|
|
79
|
+
"example:expo": "npm --workspace @chart-kit/expo-showcase run start --",
|
|
80
|
+
"example:rn-cli:typecheck": "tsc -p examples/rn-cli-basic/tsconfig.json --noEmit",
|
|
81
|
+
"native:release": "node scripts/run-expo-native-release-check.mjs --platform all",
|
|
82
|
+
"native:release:android": "node scripts/run-expo-native-release-check.mjs --platform android",
|
|
83
|
+
"native:release:ios": "node scripts/run-expo-native-release-check.mjs --platform ios",
|
|
84
|
+
"native:release:dry-run": "node scripts/run-expo-native-release-check.mjs --platform all --dry-run",
|
|
85
|
+
"release:native-workflow:record": "node scripts/record-native-workflow-evidence.mjs",
|
|
86
|
+
"release:qa:checklists": "node scripts/generate-native-qa-checklists.mjs",
|
|
87
|
+
"release:qa:checklists:check": "node scripts/generate-native-qa-checklists.mjs --check",
|
|
88
|
+
"release:qa:record": "node scripts/record-native-qa-evidence.mjs",
|
|
89
|
+
"release:owner:record": "node scripts/record-owner-gate-decision.mjs",
|
|
90
|
+
"release:gate": "node scripts/check-release-gates.mjs --strict",
|
|
91
|
+
"release:gate:report": "node scripts/check-release-gates.mjs",
|
|
92
|
+
"docs:build": "node scripts/docs-build.mjs && node scripts/typecheck-doc-examples.mjs",
|
|
93
|
+
"codemod:v1-to-v2": "node scripts/chartkit-codemod.mjs v1-to-v2",
|
|
94
|
+
"clean": "node scripts/clean-dist.mjs",
|
|
95
|
+
"build": "npm run clean && npm run core:build && npm run svg:build && npm run skia:build && npm run pro:build && npm run rn:build && tsc",
|
|
44
96
|
"dev": "tsc --watch",
|
|
45
|
-
"prepare": "npm run build"
|
|
46
|
-
},
|
|
47
|
-
"jest": {
|
|
48
|
-
"preset": "jest-expo"
|
|
97
|
+
"prepare": "npm run build && husky"
|
|
49
98
|
},
|
|
50
99
|
"peerDependencies": {
|
|
51
|
-
"react": "
|
|
52
|
-
"react-native": ">=
|
|
53
|
-
"react-native-
|
|
100
|
+
"react": ">=19.2.0 <20",
|
|
101
|
+
"react-native": ">=0.83 <1",
|
|
102
|
+
"react-native-gesture-handler": ">=2.28.0 <3",
|
|
103
|
+
"react-native-svg": ">=15.13.0 <16"
|
|
54
104
|
},
|
|
55
105
|
"dependencies": {
|
|
56
|
-
"
|
|
57
|
-
"paths-js": "^0.4.10",
|
|
58
|
-
"point-in-polygon": "^1.0.1"
|
|
106
|
+
"paths-js": "^0.4.11"
|
|
59
107
|
},
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
|
|
108
|
+
"lint-staged": {
|
|
109
|
+
"*.{js,jsx,ts,tsx}": [
|
|
110
|
+
"eslint --fix",
|
|
111
|
+
"prettier --write"
|
|
112
|
+
],
|
|
113
|
+
"*.{json,md,yml,yaml}": "prettier --write"
|
|
114
|
+
},
|
|
115
|
+
"engines": {
|
|
116
|
+
"node": ">=20.19.4"
|
|
64
117
|
},
|
|
65
118
|
"license": "MIT",
|
|
66
119
|
"homepage": "https://github.com/indiespirit/react-native-chart-kit",
|
|
67
120
|
"repository": {
|
|
68
121
|
"type": "git",
|
|
69
122
|
"url": "git+https://github.com/indiespirit/react-native-chart-kit.git"
|
|
70
|
-
},
|
|
71
|
-
"overrides": {
|
|
72
|
-
"@types/react": "16.14.8"
|
|
73
|
-
},
|
|
74
|
-
"resolutions": {
|
|
75
|
-
"@types/react": "16.14.8"
|
|
76
123
|
}
|
|
77
124
|
}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readdir, readFile, stat, writeFile } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import process from "node:process";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
6
|
+
|
|
7
|
+
export const legacyChartComponents = [
|
|
8
|
+
"LineChart",
|
|
9
|
+
"BarChart",
|
|
10
|
+
"StackedBarChart",
|
|
11
|
+
"PieChart",
|
|
12
|
+
"ProgressChart",
|
|
13
|
+
"ContributionGraph"
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
const sourceExtensions = new Set([".js", ".jsx", ".ts", ".tsx"]);
|
|
17
|
+
const ignoredDirectoryNames = new Set([
|
|
18
|
+
".git",
|
|
19
|
+
".tmp",
|
|
20
|
+
"build",
|
|
21
|
+
"dist",
|
|
22
|
+
"node_modules"
|
|
23
|
+
]);
|
|
24
|
+
const unsupportedLegacyProps = [
|
|
25
|
+
"decorator",
|
|
26
|
+
"getDotProps",
|
|
27
|
+
"renderDotContent",
|
|
28
|
+
"tooltipDataAttrs"
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
export const importsReactNativeChartKit = (source) =>
|
|
32
|
+
/from\s+["']react-native-chart-kit["']/.test(source) ||
|
|
33
|
+
/require\(\s*["']react-native-chart-kit["']\s*\)/.test(source);
|
|
34
|
+
|
|
35
|
+
const getImportedLegacyComponents = (source) => {
|
|
36
|
+
const imported = new Set();
|
|
37
|
+
const namedImportPattern =
|
|
38
|
+
/import\s+\{(?<names>[^}]+)\}\s+from\s+["']react-native-chart-kit["']/g;
|
|
39
|
+
let match;
|
|
40
|
+
|
|
41
|
+
while ((match = namedImportPattern.exec(source)) !== null) {
|
|
42
|
+
const names = match.groups?.names ?? "";
|
|
43
|
+
|
|
44
|
+
for (const name of names.split(",")) {
|
|
45
|
+
const localName = name
|
|
46
|
+
.trim()
|
|
47
|
+
.split(/\s+as\s+/i)
|
|
48
|
+
.at(-1)
|
|
49
|
+
?.trim();
|
|
50
|
+
|
|
51
|
+
if (localName && legacyChartComponents.includes(localName)) {
|
|
52
|
+
imported.add(localName);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const requirePattern =
|
|
58
|
+
/(?:const|let|var)\s+\{(?<names>[^}]+)\}\s*=\s*require\(\s*["']react-native-chart-kit["']\s*\)/g;
|
|
59
|
+
|
|
60
|
+
while ((match = requirePattern.exec(source)) !== null) {
|
|
61
|
+
const names = match.groups?.names ?? "";
|
|
62
|
+
|
|
63
|
+
for (const name of names.split(",")) {
|
|
64
|
+
const localName = name
|
|
65
|
+
.trim()
|
|
66
|
+
.split(/\s*:\s*/)
|
|
67
|
+
.at(-1)
|
|
68
|
+
?.trim();
|
|
69
|
+
|
|
70
|
+
if (localName && legacyChartComponents.includes(localName)) {
|
|
71
|
+
imported.add(localName);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return imported;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const getLineNumber = (source, index) =>
|
|
80
|
+
source.slice(0, index).split("\n").length;
|
|
81
|
+
|
|
82
|
+
const collectWarnings = ({ filePath, source }) => {
|
|
83
|
+
const warnings = [];
|
|
84
|
+
|
|
85
|
+
for (const prop of unsupportedLegacyProps) {
|
|
86
|
+
const pattern = new RegExp(`\\b${prop}\\s*=`, "g");
|
|
87
|
+
let match;
|
|
88
|
+
|
|
89
|
+
while ((match = pattern.exec(source)) !== null) {
|
|
90
|
+
warnings.push({
|
|
91
|
+
filePath,
|
|
92
|
+
line: getLineNumber(source, match.index),
|
|
93
|
+
message: `${prop} is preserved, but should be manually reviewed for the modern composable API.`
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (
|
|
99
|
+
/import\s+\*\s+as\s+\w+\s+from\s+["']react-native-chart-kit["']/.test(
|
|
100
|
+
source
|
|
101
|
+
)
|
|
102
|
+
) {
|
|
103
|
+
warnings.push({
|
|
104
|
+
filePath,
|
|
105
|
+
line: 1,
|
|
106
|
+
message:
|
|
107
|
+
"Namespace imports are detected but not rewritten; review ChartKit.LineChart-style usages manually."
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return warnings;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export const transformV1ToV2Source = (source) => {
|
|
115
|
+
if (!importsReactNativeChartKit(source)) {
|
|
116
|
+
return {
|
|
117
|
+
changed: false,
|
|
118
|
+
source
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const importedComponents = getImportedLegacyComponents(source);
|
|
123
|
+
|
|
124
|
+
if (importedComponents.size === 0) {
|
|
125
|
+
return {
|
|
126
|
+
changed: false,
|
|
127
|
+
source
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const componentAlternation = [...importedComponents].join("|");
|
|
132
|
+
const openingTagPattern = new RegExp(
|
|
133
|
+
`<(?<name>${componentAlternation})(?<attrs>\\s[^<>]*?)?(?<closing>\\/?)>`,
|
|
134
|
+
"g"
|
|
135
|
+
);
|
|
136
|
+
const nextSource = source.replace(
|
|
137
|
+
openingTagPattern,
|
|
138
|
+
(fullMatch, name, attrs = "", closing) => {
|
|
139
|
+
if (/\bcompatibility\s*=/.test(attrs)) {
|
|
140
|
+
return fullMatch;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return `<${name} compatibility="v1"${attrs}${closing}>`;
|
|
144
|
+
}
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
changed: nextSource !== source,
|
|
149
|
+
source: nextSource
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const collectSourceFiles = async (entry) => {
|
|
154
|
+
const absolutePath = path.resolve(entry);
|
|
155
|
+
const entryStat = await stat(absolutePath);
|
|
156
|
+
|
|
157
|
+
if (entryStat.isFile()) {
|
|
158
|
+
return sourceExtensions.has(path.extname(absolutePath))
|
|
159
|
+
? [absolutePath]
|
|
160
|
+
: [];
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (!entryStat.isDirectory()) {
|
|
164
|
+
return [];
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const children = await readdir(absolutePath, { withFileTypes: true });
|
|
168
|
+
const nested = await Promise.all(
|
|
169
|
+
children.map((child) => {
|
|
170
|
+
if (child.isDirectory() && ignoredDirectoryNames.has(child.name)) {
|
|
171
|
+
return [];
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return collectSourceFiles(path.join(absolutePath, child.name));
|
|
175
|
+
})
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
return nested.flat();
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
const runV1ToV2 = async ({ check, entries }) => {
|
|
182
|
+
const files = (await Promise.all(entries.map(collectSourceFiles))).flat();
|
|
183
|
+
const changedFiles = [];
|
|
184
|
+
const warnings = [];
|
|
185
|
+
|
|
186
|
+
for (const filePath of files) {
|
|
187
|
+
const source = await readFile(filePath, "utf8");
|
|
188
|
+
const result = transformV1ToV2Source(source);
|
|
189
|
+
|
|
190
|
+
warnings.push(...collectWarnings({ filePath, source }));
|
|
191
|
+
|
|
192
|
+
if (!result.changed) {
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
changedFiles.push(filePath);
|
|
197
|
+
|
|
198
|
+
if (!check) {
|
|
199
|
+
await writeFile(filePath, result.source, "utf8");
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return {
|
|
204
|
+
changedFiles,
|
|
205
|
+
checkedFiles: files.length,
|
|
206
|
+
warnings
|
|
207
|
+
};
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
const printUsage = () => {
|
|
211
|
+
console.log(`Usage:
|
|
212
|
+
chartkit-codemod v1-to-v2 <path...> [--check]
|
|
213
|
+
|
|
214
|
+
Examples:
|
|
215
|
+
npx chartkit-codemod v1-to-v2 ./src
|
|
216
|
+
npx chartkit-codemod v1-to-v2 ./src --check`);
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
export const runCli = async (argv) => {
|
|
220
|
+
const [, , command, ...rest] = argv;
|
|
221
|
+
const check = rest.includes("--check");
|
|
222
|
+
const entries = rest.filter((item) => item !== "--check");
|
|
223
|
+
|
|
224
|
+
if (command !== "v1-to-v2" || entries.length === 0) {
|
|
225
|
+
printUsage();
|
|
226
|
+
return 1;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const result = await runV1ToV2({ check, entries });
|
|
230
|
+
|
|
231
|
+
for (const warning of result.warnings) {
|
|
232
|
+
console.warn(
|
|
233
|
+
`${path.relative(process.cwd(), warning.filePath)}:${warning.line}: ${warning.message}`
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const action = check ? "would update" : "updated";
|
|
238
|
+
console.log(
|
|
239
|
+
`chartkit-codemod v1-to-v2 checked ${result.checkedFiles} files; ${action} ${result.changedFiles.length}.`
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
for (const filePath of result.changedFiles) {
|
|
243
|
+
console.log(`- ${path.relative(process.cwd(), filePath)}`);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return check && result.changedFiles.length > 0 ? 1 : 0;
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
const invokedUrl = process.argv[1]
|
|
250
|
+
? pathToFileURL(path.resolve(process.argv[1])).href
|
|
251
|
+
: "";
|
|
252
|
+
|
|
253
|
+
if (import.meta.url === invokedUrl) {
|
|
254
|
+
const exitCode = await runCli(process.argv);
|
|
255
|
+
process.exit(exitCode);
|
|
256
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AbstractChart.d.ts","sourceRoot":"","sources":["../src/AbstractChart.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGzC,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAEhE,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,mBAAmB,CAAC;IAClC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC9B;AAED,MAAM,WAAW,mBAAoB,SAAQ,WAAW;IACtD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,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