@oceanbase/codemod 0.2.5 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oceanbase/codemod",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "description": "Codemod for OceanBase Design upgrade",
5
5
  "keywords": [
6
6
  "oceanbase",
@@ -44,5 +44,5 @@
44
44
  "enzyme": "^3.11.0",
45
45
  "enzyme-to-json": "^3.6.2"
46
46
  },
47
- "gitHead": "265c33e6cc878f7b00c14518850c93c91749353b"
47
+ "gitHead": "1138341df7a35d3d4939ccea79225ddf220de2cc"
48
48
  }
@@ -0,0 +1,8 @@
1
+ import enUS from '@alipay/ob-ui/es/locale/en-US';
2
+ import zhCN from '@alipay/ob-ui/es/locale/zh-CN';
3
+
4
+ const Demo = () => {
5
+ return <div />;
6
+ };
7
+
8
+ export default Demo;
@@ -0,0 +1,8 @@
1
+ import enUS from '@oceanbase/ui/es/locale/en-US';
2
+ import zhCN from '@oceanbase/ui/es/locale/zh-CN';
3
+
4
+ const Demo = () => {
5
+ return <div />;
6
+ };
7
+
8
+ export default Demo;
@@ -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';
@@ -1,7 +1,7 @@
1
1
  import { defineTest } from 'jscodeshift/src/testUtils';
2
2
 
3
3
  const testUnit = 'obui-to-oceanbase-design-and-ui';
4
- const tests = ['obui'];
4
+ const tests = ['obui', 'locale'];
5
5
 
6
6
  describe(testUnit, () => {
7
7
  tests.forEach(test =>
@@ -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',
@@ -1,6 +1,7 @@
1
1
  // https://github.com/benjamn/recast/blob/master/lib/options.ts
2
2
  const printOptions = {
3
3
  quote: 'single',
4
+ wrapColumn: 500,
4
5
  };
5
6
 
6
7
  module.exports = {
@@ -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.name) ||
23
- toPkg.components?.find(component => component[specifier.imported.name])
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.name) ||
28
- toPkg.types?.find(type => type[specifier.imported.name])
28
+ toPkg.types?.includes(specifier.imported?.name) ||
29
+ toPkg.types?.find(type => type[specifier.imported?.name])
29
30
  );
30
- const toPkg = toPkgByComponents || toPkgByTypes;
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.name !== specifier.imported.name
42
+ item => !item.imported || item.imported?.name !== specifier.imported?.name
39
43
  );
40
44
  const renameComponent = toPkg.components?.find(
41
- component => component[specifier.imported.name]
45
+ component => component[specifier.imported?.name]
42
46
  );
43
- const renameType = toPkg.types?.find(type => type[specifier.imported.name]);
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.name] : specifier.imported.name,
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.name,
60
+ name: specifier.imported?.name,
57
61
  })
58
62
  .forEach(path => {
59
- path.node.name = rename[specifier.imported.name];
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
- return j.importDeclaration(mergedImportSpecifiers, j.literal(pkgName));
141
+ const importStatement = j.importDeclaration(mergedImportSpecifiers, j.literal(pkgName));
142
+ importStatement.importKind = importKind;
143
+ return importStatement;
142
144
  });
143
145
  return true;
144
146
  }