@oceanbase/codemod 0.2.2 → 0.2.4

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 CHANGED
@@ -17,7 +17,7 @@ npx -p @oceanbase/codemod codemod src
17
17
 
18
18
  ### `antd-to-oceanbase-design`
19
19
 
20
- import components and typs from `antd` and `@alipay/bigfish/antd` to `@oceanbase/design`.
20
+ import components and types from `antd` and `@alipay/bigfish/antd` to `@oceanbase/design`.
21
21
 
22
22
  ```diff
23
23
  import React from 'react';
@@ -43,7 +43,7 @@ import components and typs from `antd` and `@alipay/bigfish/antd` to `@oceanbase
43
43
 
44
44
  ### `obui-to-oceanbase-design-and-ui`
45
45
 
46
- import components and typs from `antd` to `@oceanbase/design` and `@oceanbase/ui`.
46
+ import components and types from `antd` to `@oceanbase/design` and `@oceanbase/ui`.
47
47
 
48
48
  ```diff
49
49
  import React from 'react';
@@ -86,7 +86,7 @@ import `PageContainer` from `@alipay/tech-ui` to `@ant-design/pro-components` an
86
86
 
87
87
  ### `antd-and-ob-charts-to-oceanbase-charts`
88
88
 
89
- import components and typs from `@ant-design/charts` and `@alipay/ob-charts` to `@oceanbase/charts`.
89
+ import components and types from `@ant-design/charts` and `@alipay/ob-charts` to `@oceanbase/charts`.
90
90
 
91
91
  ```diff
92
92
  import React from 'react';
@@ -118,15 +118,17 @@ import components and typs from `@ant-design/charts` and `@alipay/ob-charts` to
118
118
 
119
119
  ### `obutil-to-oceanbase-util`
120
120
 
121
- import components and typs from `@alipay/ob-util` to `@oceanbase/util`.
121
+ import utils and hooks from `@alipay/ob-util` to `@oceanbase/util`. Additionally, it will rename `getTableData` to `useTableData` to follow hooks naming conventions.
122
122
 
123
123
  ```diff
124
124
  import React from 'react';
125
- - import { isNullValue, sortByNumber } from '@alipay/ob-util';
126
- + import { isNullValue, sortByNumber } from '@oceanbase/util';
125
+ - import { isNullValue, sortByNumber, getTableData } from '@alipay/ob-util';
126
+ + import { isNullValue, sortByNumber, useTableData } from '@oceanbase/util';
127
127
 
128
128
  const Demo = () => {
129
- return <div />;
129
+ - const { tableProps } = getTableData(fn, {});
130
+ + const { tableProps } = useTableData(fn, {});
131
+ return <div />;
130
132
  };
131
133
 
132
134
  export default Demo;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oceanbase/codemod",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "Codemod for OceanBase Design upgrade",
5
5
  "keywords": [
6
6
  "oceanbase",
@@ -23,7 +23,7 @@
23
23
  "build": "father build"
24
24
  },
25
25
  "dependencies": {
26
- "chalk": "^5.3.0",
26
+ "chalk": "^3.0.0",
27
27
  "command-exists": "^1.2.9",
28
28
  "execa": "^5.1.1",
29
29
  "find-up": "^4.1.0",
@@ -34,15 +34,15 @@
34
34
  "lodash": "^4.17.15",
35
35
  "prettier": "^3.0.3",
36
36
  "read-pkg-up": "^9.1.0",
37
- "semver": "^7.1.3",
37
+ "semver": "^7.5.4",
38
38
  "update-check": "^1.5.4",
39
39
  "yargs-parser": "^21.1.1"
40
40
  },
41
41
  "devDependencies": {
42
- "@types/jest": "^29.2.3",
42
+ "@types/jest": "^29.5.5",
43
43
  "@types/jscodeshift": "^0.11.7",
44
44
  "enzyme": "^3.0.0",
45
45
  "enzyme-to-json": "^3.6.2"
46
46
  },
47
- "gitHead": "3d55f9a8967c0b20491eb7d154f53db8943c1522"
47
+ "gitHead": "38becd333620011d0d084df62b1131135a396abb"
48
48
  }
@@ -0,0 +1,28 @@
1
+ import React from 'react';
2
+ import { getTableData } from '@alipay/ob-util';
3
+
4
+ const Demo = () => {
5
+ const { tableProps, refresh } = getTableData({
6
+ fn: getClusters,
7
+ params: {
8
+ configName,
9
+ },
10
+ refreshDeps: [],
11
+ options: {
12
+ pagePropName: 'pageNo',
13
+ sizePropName: 'pageSize',
14
+ formatResult: (res: any) => {
15
+ const { data, pageNo, pageSize, total } = res || {};
16
+ return {
17
+ list: data || [],
18
+ current: pageNo,
19
+ pageSize,
20
+ total,
21
+ };
22
+ },
23
+ },
24
+ });
25
+ return <div />;
26
+ };
27
+
28
+ export default Demo;
@@ -0,0 +1,28 @@
1
+ import React from 'react';
2
+ import { useTableData } from '@oceanbase/util';
3
+
4
+ const Demo = () => {
5
+ const { tableProps, refresh } = useTableData({
6
+ fn: getClusters,
7
+ params: {
8
+ configName,
9
+ },
10
+ refreshDeps: [],
11
+ options: {
12
+ pagePropName: 'pageNo',
13
+ sizePropName: 'pageSize',
14
+ formatResult: (res: any) => {
15
+ const { data, pageNo, pageSize, total } = res || {};
16
+ return {
17
+ list: data || [],
18
+ current: pageNo,
19
+ pageSize,
20
+ total,
21
+ };
22
+ },
23
+ },
24
+ });
25
+ return <div />;
26
+ };
27
+
28
+ export default Demo;
@@ -1,7 +1,7 @@
1
1
  import { defineTest } from 'jscodeshift/src/testUtils';
2
2
 
3
3
  const testUnit = 'obutil-to-oceanbase-util';
4
- const tests = ['obutil'];
4
+ const tests = ['obutil', 'getTableData'];
5
5
 
6
6
  describe(testUnit, () => {
7
7
  tests.forEach(test =>
@@ -5,6 +5,15 @@ module.exports = (file, api, options) => {
5
5
  ...options,
6
6
  fromPkgNames: '@alipay/ob-util',
7
7
  toPkgList: [
8
+ {
9
+ name: '@oceanbase/util',
10
+ components: [
11
+ {
12
+ // rename
13
+ getTableData: 'useTableData',
14
+ },
15
+ ],
16
+ },
8
17
  {
9
18
  name: '@oceanbase/util',
10
19
  },
@@ -1,6 +1,8 @@
1
1
  const { addSubmoduleImport, removeEmptyModuleImport, parseStrToArray } = require('./index');
2
2
  const { markDependency } = require('./marker');
3
3
  const { printOptions } = require('./config');
4
+ const { isPlainObject } = require('lodash');
5
+ const { flatten } = require('lodash');
4
6
 
5
7
  function importComponent(j, root, options) {
6
8
  const { fromPkgNames, toPkgList } = options;
@@ -15,11 +17,15 @@ function importComponent(j, root, options) {
15
17
  );
16
18
  if (fromPkgName) {
17
19
  path.value.specifiers.forEach(specifier => {
18
- const toPkgByComponents = toPkgList.find(toPkg =>
19
- toPkg.components?.includes(specifier.imported.name)
20
+ const toPkgByComponents = toPkgList.find(
21
+ toPkg =>
22
+ toPkg.components?.includes(specifier.imported.name) ||
23
+ toPkg.components?.find(component => component[specifier.imported.name])
20
24
  );
21
- const toPkgByTypes = toPkgList.find(toPkg =>
22
- toPkg.types?.includes(specifier.imported.name)
25
+ const toPkgByTypes = toPkgList.find(
26
+ toPkg =>
27
+ toPkg.types?.includes(specifier.imported.name) ||
28
+ toPkg.types?.find(type => type[specifier.imported.name])
23
29
  );
24
30
  const toPkg = toPkgByComponents || toPkgByTypes;
25
31
  if (toPkg) {
@@ -31,13 +37,28 @@ function importComponent(j, root, options) {
31
37
  path.value.specifiers = path.value.specifiers.filter(
32
38
  item => !item.imported || item.imported.name !== specifier.imported.name
33
39
  );
34
- // add new imports
40
+ const renameComponent = toPkg.components?.find(
41
+ component => component[specifier.imported.name]
42
+ );
43
+ const renameType = toPkg.types?.find(type => type[specifier.imported.name]);
44
+ const rename = renameComponent || renameType;
45
+ // add and rename new imports
35
46
  addSubmoduleImport(j, root, {
36
47
  moduleName: toPkg.name,
37
- importedName: specifier.imported.name,
48
+ importedName: rename ? rename[specifier.imported.name] : specifier.imported.name,
38
49
  importKind: toPkgByTypes ? 'type' : 'value',
39
50
  after: fromPkgName,
40
51
  });
52
+ // rename used part
53
+ if (rename) {
54
+ root
55
+ .find(j.Identifier, {
56
+ name: specifier.imported.name,
57
+ })
58
+ .forEach(path => {
59
+ path.node.name = rename[specifier.imported.name];
60
+ });
61
+ }
41
62
  }
42
63
  markDependency(toPkg.name);
43
64
  }