@oceanbase/codemod 0.2.4 → 0.2.6
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/package.json +5 -5
- package/transforms/__testfixtures__/obui-to-oceanbase-design-and-ui/locale.input.js +8 -0
- package/transforms/__testfixtures__/obui-to-oceanbase-design-and-ui/locale.output.js +8 -0
- package/transforms/__testfixtures__/obui-to-oceanbase-design-and-ui/obui.input.js +2 -1
- package/transforms/__testfixtures__/obui-to-oceanbase-design-and-ui/obui.output.js +3 -2
- package/transforms/__tests__/obui-to-oceanbase-design-and-ui.test.ts +1 -1
- package/transforms/obui-to-oceanbase-design-and-ui.js +30 -0
- package/transforms/utils/config.js +1 -0
- package/transforms/utils/import-component.js +15 -11
- package/transforms/utils/index.js +3 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oceanbase/codemod",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"description": "Codemod for OceanBase Design upgrade",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"oceanbase",
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
"command-exists": "^1.2.9",
|
|
28
28
|
"execa": "^5.1.1",
|
|
29
29
|
"find-up": "^4.1.0",
|
|
30
|
-
"glob": "^
|
|
30
|
+
"glob": "^10.3.10",
|
|
31
31
|
"is-directory": "^0.3.1",
|
|
32
32
|
"is-git-clean": "^1.1.0",
|
|
33
33
|
"jscodeshift": "^0.15.0",
|
|
34
|
-
"lodash": "^4.17.
|
|
34
|
+
"lodash": "^4.17.21",
|
|
35
35
|
"prettier": "^3.0.3",
|
|
36
36
|
"read-pkg-up": "^9.1.0",
|
|
37
37
|
"semver": "^7.5.4",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/jest": "^29.5.5",
|
|
43
43
|
"@types/jscodeshift": "^0.11.7",
|
|
44
|
-
"enzyme": "^3.
|
|
44
|
+
"enzyme": "^3.11.0",
|
|
45
45
|
"enzyme-to-json": "^3.6.2"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "1138341df7a35d3d4939ccea79225ddf220de2cc"
|
|
48
48
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { Alert, Button, BasicLayout, Login, PageContainer } from '@alipay/ob-ui';
|
|
2
|
+
import { Alert, Button, BackgroundTaskManager, BackgroundTaskManagerConstants, BasicLayout, Boundary, ConfigProvider, ContentWithQuestion, IconFont, Login, PageContainer, Ranger, theme, TreeSearch } from '@alipay/ob-ui';
|
|
3
|
+
import type { BackgroundTaskManagerRef, ITaskMgrPreset, ITaskMgrQueue, TaskMgrID } from '@alipay/ob-ui';
|
|
3
4
|
import type { BasicLayoutProps } from '@alipay/ob-ui/es/BasicLayout';
|
|
4
5
|
import type { LoginProps } from '@alipay/ob-ui/es/Login';
|
|
5
6
|
import type { PageContainerProps } from '@alipay/ob-ui/es/PageContainer';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { Alert, Button } from '@oceanbase/design';
|
|
3
|
-
import { BasicLayout, Login, PageContainer } from '@oceanbase/ui';
|
|
2
|
+
import { Alert, Button, ConfigProvider, theme } from '@oceanbase/design';
|
|
3
|
+
import { BackgroundTaskManager, BackgroundTaskManagerConstants, BasicLayout, Boundary, ContentWithQuestion, IconFont, Login, PageContainer, Ranger, TreeSearch } from '@oceanbase/ui';
|
|
4
|
+
import type { BackgroundTaskManagerRef, ITaskMgrPreset, ITaskMgrQueue, TaskMgrID } from '@oceanbase/ui';
|
|
4
5
|
import type { BasicLayoutProps } from '@oceanbase/ui/es/BasicLayout';
|
|
5
6
|
import type { LoginProps } from '@oceanbase/ui/es/Login';
|
|
6
7
|
import type { PageContainerProps } from '@oceanbase/ui/es/PageContainer';
|
|
@@ -12,32 +12,62 @@ module.exports = (file, api, options) => {
|
|
|
12
12
|
'PageContainer',
|
|
13
13
|
'Action',
|
|
14
14
|
'BackgroundTaskManager',
|
|
15
|
+
'BackgroundTaskManagerConstants',
|
|
15
16
|
'BasicLayout',
|
|
16
17
|
'BatchOperationBar',
|
|
17
18
|
'Boundary',
|
|
18
19
|
'ContentWithQuestion',
|
|
19
20
|
'Dialog',
|
|
20
21
|
'DocDialog',
|
|
22
|
+
'FullscreenBox',
|
|
23
|
+
'Highlight',
|
|
21
24
|
'GraphToolbar',
|
|
25
|
+
'IconFont',
|
|
22
26
|
'Login',
|
|
23
27
|
'Lottie',
|
|
24
28
|
'NavMenu',
|
|
29
|
+
'Password',
|
|
30
|
+
'Ranger',
|
|
31
|
+
'SideTip',
|
|
32
|
+
'TaskGraph',
|
|
33
|
+
'TreeSearch',
|
|
34
|
+
'Welcome',
|
|
25
35
|
],
|
|
26
36
|
types: [
|
|
27
37
|
'PageContainerProps',
|
|
28
38
|
'ActionProps',
|
|
39
|
+
// BackgroundTaskManager
|
|
29
40
|
'BackgroundTaskManagerProps',
|
|
41
|
+
'BackgroundTaskManagerRef',
|
|
42
|
+
'ITaskMgrPreset',
|
|
43
|
+
'ITaskMgrQueue',
|
|
44
|
+
'TaskMgrID',
|
|
30
45
|
'BasicLayoutProps',
|
|
31
46
|
'BatchOperationBarProps',
|
|
32
47
|
'BoundaryProps',
|
|
33
48
|
'ContentWithQuestionProps',
|
|
34
49
|
'DialogProps',
|
|
35
50
|
'DocDialogProps',
|
|
51
|
+
'FullscreenBoxProps',
|
|
36
52
|
'GraphToolbarProps',
|
|
53
|
+
'HighlightProps',
|
|
54
|
+
'IconFontProps',
|
|
37
55
|
'LoginProps',
|
|
38
56
|
'LottieProps',
|
|
39
57
|
'NavMenuProps',
|
|
58
|
+
'PasswordProps',
|
|
59
|
+
// Ranger
|
|
60
|
+
'RangerProps',
|
|
61
|
+
'QuickPickerProps',
|
|
62
|
+
'SideTipProps',
|
|
63
|
+
'TaskGraphProps',
|
|
64
|
+
// TreeSearch
|
|
65
|
+
'TreeSearchProps',
|
|
66
|
+
'TreeSearchRef',
|
|
67
|
+
'Node',
|
|
68
|
+
'WelcomeProps',
|
|
40
69
|
],
|
|
70
|
+
paths: ['/locale/', '/locale/'],
|
|
41
71
|
},
|
|
42
72
|
{
|
|
43
73
|
name: '@oceanbase/design',
|
|
@@ -3,6 +3,7 @@ const { markDependency } = require('./marker');
|
|
|
3
3
|
const { printOptions } = require('./config');
|
|
4
4
|
const { isPlainObject } = require('lodash');
|
|
5
5
|
const { flatten } = require('lodash');
|
|
6
|
+
const { some } = require('lodash');
|
|
6
7
|
|
|
7
8
|
function importComponent(j, root, options) {
|
|
8
9
|
const { fromPkgNames, toPkgList } = options;
|
|
@@ -19,15 +20,18 @@ function importComponent(j, root, options) {
|
|
|
19
20
|
path.value.specifiers.forEach(specifier => {
|
|
20
21
|
const toPkgByComponents = toPkgList.find(
|
|
21
22
|
toPkg =>
|
|
22
|
-
toPkg.components?.includes(specifier.imported
|
|
23
|
-
toPkg.components?.find(component => component[specifier.imported
|
|
23
|
+
toPkg.components?.includes(specifier.imported?.name) ||
|
|
24
|
+
toPkg.components?.find(component => component[specifier.imported?.name])
|
|
24
25
|
);
|
|
25
26
|
const toPkgByTypes = toPkgList.find(
|
|
26
27
|
toPkg =>
|
|
27
|
-
toPkg.types?.includes(specifier.imported
|
|
28
|
-
toPkg.types?.find(type => type[specifier.imported
|
|
28
|
+
toPkg.types?.includes(specifier.imported?.name) ||
|
|
29
|
+
toPkg.types?.find(type => type[specifier.imported?.name])
|
|
29
30
|
);
|
|
30
|
-
const
|
|
31
|
+
const toPkgByPaths = toPkgList.find(toPkg =>
|
|
32
|
+
some(toPkg.paths, pathString => path.value.source.value?.includes(pathString))
|
|
33
|
+
);
|
|
34
|
+
const toPkg = toPkgByComponents || toPkgByTypes || toPkgByPaths;
|
|
31
35
|
if (toPkg) {
|
|
32
36
|
// replace to toPkg for xxx/es/xxx、xxx/lib/xxx
|
|
33
37
|
if (new RegExp(`${fromPkgName}/(es|lib|locale)/`).test(path.value.source.value)) {
|
|
@@ -35,17 +39,17 @@ function importComponent(j, root, options) {
|
|
|
35
39
|
} else {
|
|
36
40
|
// remove old imports
|
|
37
41
|
path.value.specifiers = path.value.specifiers.filter(
|
|
38
|
-
item => !item.imported || item.imported
|
|
42
|
+
item => !item.imported || item.imported?.name !== specifier.imported?.name
|
|
39
43
|
);
|
|
40
44
|
const renameComponent = toPkg.components?.find(
|
|
41
|
-
component => component[specifier.imported
|
|
45
|
+
component => component[specifier.imported?.name]
|
|
42
46
|
);
|
|
43
|
-
const renameType = toPkg.types?.find(type => type[specifier.imported
|
|
47
|
+
const renameType = toPkg.types?.find(type => type[specifier.imported?.name]);
|
|
44
48
|
const rename = renameComponent || renameType;
|
|
45
49
|
// add and rename new imports
|
|
46
50
|
addSubmoduleImport(j, root, {
|
|
47
51
|
moduleName: toPkg.name,
|
|
48
|
-
importedName: rename ? rename[specifier.imported
|
|
52
|
+
importedName: rename ? rename[specifier.imported?.name] : specifier.imported?.name,
|
|
49
53
|
importKind: toPkgByTypes ? 'type' : 'value',
|
|
50
54
|
after: fromPkgName,
|
|
51
55
|
});
|
|
@@ -53,10 +57,10 @@ function importComponent(j, root, options) {
|
|
|
53
57
|
if (rename) {
|
|
54
58
|
root
|
|
55
59
|
.find(j.Identifier, {
|
|
56
|
-
name: specifier.imported
|
|
60
|
+
name: specifier.imported?.name,
|
|
57
61
|
})
|
|
58
62
|
.forEach(path => {
|
|
59
|
-
path.node.name = rename[specifier.imported
|
|
63
|
+
path.node.name = rename[specifier.imported?.name];
|
|
60
64
|
});
|
|
61
65
|
}
|
|
62
66
|
}
|
|
@@ -138,7 +138,9 @@ function addModuleImport(j, root, { pkgName, importSpecifier, importKind, before
|
|
|
138
138
|
|
|
139
139
|
return a.imported.name.localeCompare(b.imported.name);
|
|
140
140
|
});
|
|
141
|
-
|
|
141
|
+
const importStatement = j.importDeclaration(mergedImportSpecifiers, j.literal(pkgName));
|
|
142
|
+
importStatement.importKind = importKind;
|
|
143
|
+
return importStatement;
|
|
142
144
|
});
|
|
143
145
|
return true;
|
|
144
146
|
}
|