@oceanbase/codemod 0.2.0 → 0.2.1

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.
Files changed (40) hide show
  1. package/README.md +17 -3
  2. package/bin/babylon.config.json +45 -0
  3. package/{src/bin → bin}/cli.js +62 -13
  4. package/package.json +6 -2
  5. package/{src/transforms/__testfixtures__/antd-charts-to-oceanbase-charts/antd-charts.input.tsx → transforms/__testfixtures__/antd-and-ob-charts-to-oceanbase-charts/antd-charts.input.js} +1 -0
  6. package/{src/transforms/__testfixtures__/antd-charts-to-oceanbase-charts/antd-charts.output.tsx → transforms/__testfixtures__/antd-and-ob-charts-to-oceanbase-charts/antd-charts.output.js} +1 -0
  7. package/transforms/__testfixtures__/antd-and-ob-charts-to-oceanbase-charts/ob-charts.input.js +10 -0
  8. package/transforms/__testfixtures__/antd-and-ob-charts-to-oceanbase-charts/ob-charts.output.js +10 -0
  9. package/{src/transforms/__testfixtures__/obui-to-oceanbase-design-and-ui/obui.input.tsx → transforms/__testfixtures__/obui-to-oceanbase-design-and-ui/obui.input.js} +2 -0
  10. package/{src/transforms/__testfixtures__/obui-to-oceanbase-design-and-ui/obui.output.tsx → transforms/__testfixtures__/obui-to-oceanbase-design-and-ui/obui.output.js} +2 -0
  11. package/{src/transforms/__testfixtures__/techui-to-oceanbase-ui/pro-components.output.tsx → transforms/__testfixtures__/page-container-to-oceanbase-ui/pro-components.output.js} +1 -0
  12. package/{src/transforms/__testfixtures__/techui-to-oceanbase-ui/techui.output.tsx → transforms/__testfixtures__/page-container-to-oceanbase-ui/techui.output.js} +1 -0
  13. package/{src/transforms/__tests__/antd-charts-to-oceanbase-charts.test.ts → transforms/__tests__/antd-and-ob-charts-to-oceanbase-charts.test.ts} +3 -3
  14. package/{src/transforms → transforms}/__tests__/antd-to-oceanbase-design.test.ts +1 -1
  15. package/{src/transforms → transforms}/__tests__/obui-to-oceanbase-design-and-ui.test.ts +1 -1
  16. package/{src/transforms → transforms}/__tests__/obutil-to-oceanbase-util.test.ts +1 -1
  17. package/{src/transforms/__tests__/techui-to-oceanbase-ui.test.ts → transforms/__tests__/page-container-to-oceanbase-ui.test.ts} +2 -2
  18. package/transforms/antd-and-ob-charts-to-oceanbase-charts.js +13 -0
  19. package/{src/transforms → transforms}/antd-to-oceanbase-design.js +0 -3
  20. package/{src/transforms → transforms}/obui-to-oceanbase-design-and-ui.js +0 -3
  21. package/{src/transforms → transforms}/obutil-to-oceanbase-util.js +0 -2
  22. package/{src/transforms/techui-to-oceanbase-ui.js → transforms/page-container-to-oceanbase-ui.js} +0 -3
  23. package/transforms/utils/config.js +8 -0
  24. package/{src/transforms → transforms}/utils/import-component.js +14 -12
  25. package/{src/transforms → transforms}/utils/marker.js +3 -1
  26. package/src/transforms/antd-charts-to-oceanbase-charts.js +0 -17
  27. package/src/transforms/utils/config.js +0 -11
  28. /package/{src/bin → bin}/codemod.ignore +0 -0
  29. /package/{src/bin → bin}/codemod.js +0 -0
  30. /package/{src/bin → bin}/upgrade-list.json +0 -0
  31. /package/{src/transforms → transforms}/__testfixtures__/.eslintrc.js +0 -0
  32. /package/{src/transforms/__testfixtures__/antd-to-oceanbase-design/antd.input.tsx → transforms/__testfixtures__/antd-to-oceanbase-design/antd.input.js} +0 -0
  33. /package/{src/transforms/__testfixtures__/antd-to-oceanbase-design/antd.output.tsx → transforms/__testfixtures__/antd-to-oceanbase-design/antd.output.js} +0 -0
  34. /package/{src/transforms/__testfixtures__/antd-to-oceanbase-design/bigfish-antd.input.tsx → transforms/__testfixtures__/antd-to-oceanbase-design/bigfish-antd.input.js} +0 -0
  35. /package/{src/transforms/__testfixtures__/antd-to-oceanbase-design/bigfish-antd.output.tsx → transforms/__testfixtures__/antd-to-oceanbase-design/bigfish-antd.output.js} +0 -0
  36. /package/{src/transforms/__testfixtures__/obutil-to-oceanbase-util/obutil.input.tsx → transforms/__testfixtures__/obutil-to-oceanbase-util/obutil.input.js} +0 -0
  37. /package/{src/transforms/__testfixtures__/obutil-to-oceanbase-util/obutil.output.tsx → transforms/__testfixtures__/obutil-to-oceanbase-util/obutil.output.js} +0 -0
  38. /package/{src/transforms/__testfixtures__/techui-to-oceanbase-ui/pro-components.input.tsx → transforms/__testfixtures__/page-container-to-oceanbase-ui/pro-components.input.js} +0 -0
  39. /package/{src/transforms/__testfixtures__/techui-to-oceanbase-ui/techui.input.tsx → transforms/__testfixtures__/page-container-to-oceanbase-ui/techui.input.js} +0 -0
  40. /package/{src/transforms → transforms}/utils/index.js +0 -0
package/README.md CHANGED
@@ -64,7 +64,7 @@ import components and typs from `antd` to `@oceanbase/design` and `@oceanbase/ui
64
64
  export default Demo;
65
65
  ```
66
66
 
67
- ### `techui-to-oceanbase-ui`
67
+ ### `page-container-to-oceanbase-ui`
68
68
 
69
69
  import `PageContainer` from `@alipay/tech-ui` to `@ant-design/pro-components` and `@oceanbase/ui`.
70
70
 
@@ -84,9 +84,9 @@ import `PageContainer` from `@alipay/tech-ui` to `@ant-design/pro-components` an
84
84
  export default Demo;
85
85
  ```
86
86
 
87
- ### `antd-charts-to-oceanbase-charts`
87
+ ### `antd-and-ob-charts-to-oceanbase-charts`
88
88
 
89
- import components and typs from `@ant-design/charts` to `@oceanbase/charts`.
89
+ import components and typs from `@ant-design/charts` and `@alipay/ob-charts` to `@oceanbase/charts`.
90
90
 
91
91
  ```diff
92
92
  import React from 'react';
@@ -102,6 +102,20 @@ import components and typs from `@ant-design/charts` to `@oceanbase/charts`.
102
102
  export default Demo;
103
103
  ```
104
104
 
105
+ ```diff
106
+ import React from 'react';
107
+ - import { Bar, Line } from '@alipay/ob-charts';
108
+ - import type { BarConfig, LineConfig } from '@ant-design/ob-charts';
109
+ + import { Bar, Line } from '@oceanbase/charts';
110
+ + import type { BarConfig, LineConfig } from '@oceanbase/charts';
111
+
112
+ const Demo = () => {
113
+ return <div />;
114
+ };
115
+
116
+ export default Demo;
117
+ ```
118
+
105
119
  ### `obutil-to-oceanbase-util`
106
120
 
107
121
  import components and typs from `@alipay/ob-util` to `@oceanbase/util`.
@@ -0,0 +1,45 @@
1
+ {
2
+ "sourceType": "module",
3
+ "allowImportExportEverywhere": true,
4
+ "allowReturnOutsideFunction": true,
5
+ "startLine": 1,
6
+ "tokens": true,
7
+ "plugins": [
8
+ "jsx",
9
+ "typescript",
10
+ "asyncGenerators",
11
+ "bigInt",
12
+ "classProperties",
13
+ "classPrivateProperties",
14
+ "classPrivateMethods",
15
+ [
16
+ "decorators",
17
+ {
18
+ "decoratorsBeforeExport": true
19
+ }
20
+ ],
21
+ "doExpressions",
22
+ "dynamicImport",
23
+ "exportDefaultFrom",
24
+ "exportExtensions",
25
+ "exportNamespaceFrom",
26
+ "functionBind",
27
+ "functionSent",
28
+ "importMeta",
29
+ "logicalAssignment",
30
+ "nullishCoalescingOperator",
31
+ "numericSeparator",
32
+ "objectRestSpread",
33
+ "optionalCatchBinding",
34
+ "optionalChaining",
35
+ [
36
+ "pipelineOperator",
37
+ {
38
+ "proposal": "minimal"
39
+ }
40
+ ],
41
+ "throwExpressions",
42
+ "asyncDoExpressions",
43
+ "topLevelAwait"
44
+ ]
45
+ }
@@ -11,6 +11,9 @@ const updateCheck = require('update-check');
11
11
  const findUp = require('find-up');
12
12
  const semver = require('semver');
13
13
  const { run: jscodeshift } = require('jscodeshift/src/Runner');
14
+ const execa = require('execa');
15
+ const isDirectory = require('is-directory');
16
+ const commandExistsSync = require('command-exists').sync;
14
17
 
15
18
  const pkg = require('../package.json');
16
19
  const pkgUpgradeList = require('./upgrade-list');
@@ -23,9 +26,11 @@ const transformersDir = path.join(__dirname, '../transforms');
23
26
  const ignoreConfig = path.join(__dirname, './codemod.ignore');
24
27
 
25
28
  const transformers = [
29
+ 'antd-and-ob-charts-to-oceanbase-charts',
26
30
  'antd-to-oceanbase-design',
27
- 'obui-to-oceanbase-design',
28
- 'techui-to-oceanbase-ui',
31
+ 'obui-to-oceanbase-design-and-ui',
32
+ 'obutil-to-oceanbase-util',
33
+ 'page-container-to-oceanbase-ui',
29
34
  ];
30
35
 
31
36
  const dependencyProperties = [
@@ -72,13 +77,19 @@ function getMaxWorkers(options = {}) {
72
77
  return options.cpus || Math.max(2, Math.ceil(os.cpus().length / 3));
73
78
  }
74
79
 
75
- function getRunnerArgs(transformerPath, parser = 'tsx', options = {}) {
80
+ function getRunnerArgs(transformerPath, parser = 'babylon', options = {}) {
76
81
  const args = {
77
82
  verbose: 2,
78
83
  // limit usage for cpus
79
84
  cpus: getMaxWorkers(options),
80
85
  parser,
81
- extensions: ['tsx', 'ts', 'jsx', 'js'].join(','),
86
+ // https://github.com/facebook/jscodeshift/blob/master/src/Runner.js#L255
87
+ // https://github.com/facebook/jscodeshift/blob/master/src/Worker.js#L50
88
+ babel: false,
89
+ // override default babylon parser config to enable `decorator-legacy`
90
+ // https://github.com/facebook/jscodeshift/blob/master/parser/babylon.js
91
+ parserConfig: require('./babylon.config.json'),
92
+ extensions: ['js', 'jsx', 'ts', 'tsx', 'd.ts'].join(','),
82
93
  transform: transformerPath,
83
94
  ignorePattern: '**/node_modules',
84
95
  ignoreConfig,
@@ -89,7 +100,7 @@ function getRunnerArgs(transformerPath, parser = 'tsx', options = {}) {
89
100
 
90
101
  async function run(filePath, args = {}) {
91
102
  for (const transformer of transformers) {
92
- await transform(transformer, 'tsx', filePath, args);
103
+ await transform(transformer, 'babylon', filePath, args);
93
104
  }
94
105
  }
95
106
 
@@ -108,6 +119,7 @@ async function transform(transformer, parser, filePath, options) {
108
119
 
109
120
  // js part
110
121
  await jscodeshift(transformerPath, [filePath], args);
122
+ console.log();
111
123
  } catch (err) {
112
124
  console.error(err);
113
125
  if (process.env.NODE_ENV === 'local') {
@@ -195,10 +207,14 @@ async function upgradeDetect(targetDir, needOBCharts, needObUtil) {
195
207
 
196
208
  console.log(
197
209
  chalk.yellow(
198
- "It's recommended to install or upgrade these dependencies to ensure working well with oceanbase design system\n"
210
+ 'It will install or upgrade these dependencies to ensure working well with oceanbase design system\n'
199
211
  )
200
212
  );
201
- console.log(`> package.json file: ${pkgJsonPath} \n`);
213
+ console.log(`> Update package.json file: ${pkgJsonPath} \n`);
214
+ const npmCommand = commandExistsSync('tnpm') ? 'tnpm' : 'npm';
215
+
216
+ // install dependencies
217
+ console.log(`New package installing...\n`);
202
218
  const dependencies = result.map(([operateType, depName, expectVersion, dependencyProperty]) =>
203
219
  [
204
220
  _.capitalize(operateType),
@@ -206,18 +222,37 @@ async function upgradeDetect(targetDir, needOBCharts, needObUtil) {
206
222
  dependencyProperty ? `in ${dependencyProperty}` : '',
207
223
  ].join(' ')
208
224
  );
209
-
210
225
  console.log(dependencies.map(n => `* ${n}`).join('\n'));
226
+ console.log('\n');
227
+ const installDependencies = result.map(([_, depName, expectVersion]) =>
228
+ expectVersion ? `${depName}@${expectVersion}` : depName
229
+ );
230
+ await execa(npmCommand, ['install', ...installDependencies, '--save'], {
231
+ stdio: 'inherit',
232
+ });
233
+ console.log(`\nNew package installed!\n`);
234
+
235
+ // uninstall dependencies
236
+ console.log(`Deprecated package uninstalling...\n`);
237
+ const uninstallDependencies = ['@alipay/ob-ui', '@alipay/ob-util', '@alipay/ob-charts'];
238
+ console.log(uninstallDependencies.map(n => `* ${n}`).join('\n'));
239
+ console.log('\n');
240
+ await execa(npmCommand, ['uninstall', ...uninstallDependencies, '--save'], {
241
+ stdio: 'inherit',
242
+ });
243
+ console.log(`\nDeprecated package uninstalled!\n`);
211
244
  }
212
245
 
213
246
  /**
214
247
  * options
215
- * --force // force skip git checking (dangerously)
216
- * --cpus=1 // specify cpus cores to use
248
+ * --force // force skip git checking (dangerously)
249
+ * --cpus=1 // specify cpus cores to use
250
+ * --disablePrettier // disable prettier
217
251
  */
218
252
 
219
253
  async function bootstrap() {
220
254
  const dir = process.argv[2];
255
+
221
256
  // eslint-disable-next-line global-require
222
257
  const args = require('yargs-parser')(process.argv.slice(3));
223
258
  if (process.env.NODE_ENV !== 'local') {
@@ -246,13 +281,27 @@ async function bootstrap() {
246
281
 
247
282
  await run(dir, args);
248
283
 
284
+ if (!args.disablePrettier) {
285
+ console.log('----------- Prettier Format -----------\n');
286
+ console.log('[Prettier] format files running...');
287
+ try {
288
+ const isDir = isDirectory.sync(dir);
289
+ const path = isDir ? '**/*.{js,jsx,tsx,ts,d.ts}' : dir;
290
+ const npxCommand = commandExistsSync('tnpx') ? 'tnpx' : 'npx';
291
+ await execa(npxCommand, ['prettier', '--write', path], { stdio: 'inherit' });
292
+ console.log('\n[Prettier] format files completed!\n');
293
+ } catch (err) {
294
+ console.log('\n[Prettier] format files failed, please format it by yourself.\n', err);
295
+ }
296
+ }
297
+
249
298
  try {
250
- console.log('----------- dependencies alert -----------\n');
299
+ console.log('----------- Dependencies Alert -----------\n');
251
300
  const depsList = await getDependencies();
252
301
  await upgradeDetect(
253
302
  dir,
254
- depsList.includes('@ant-design/charts'),
255
- depsList.includes('@alipay/ob-util')
303
+ depsList.includes('@oceanbase/charts'),
304
+ depsList.includes('@oceanbase/util')
256
305
  );
257
306
  } catch (err) {
258
307
  console.log('skip summary due to', err);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oceanbase/codemod",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Codemod for OceanBase Design upgrade",
5
5
  "keywords": [
6
6
  "oceanbase",
@@ -24,11 +24,15 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "chalk": "^3.0.0",
27
+ "command-exists": "^1.2.9",
28
+ "execa": "^5.1.1",
27
29
  "find-up": "^4.1.0",
28
30
  "glob": "^8.0.3",
31
+ "is-directory": "^0.3.1",
29
32
  "is-git-clean": "^1.1.0",
30
33
  "jscodeshift": "^0.14.0",
31
34
  "lodash": "^4.17.15",
35
+ "prettier": "^3.0.3",
32
36
  "read-pkg-up": "^9.1.0",
33
37
  "semver": "^7.1.3",
34
38
  "update-check": "^1.5.3",
@@ -40,5 +44,5 @@
40
44
  "enzyme": "^3.0.0",
41
45
  "enzyme-to-json": "^3.4.0"
42
46
  },
43
- "gitHead": "6f801e95ba5ddc345f6d2c462bcf2af1abc74c84"
47
+ "gitHead": "489ec76ca21b3a0448dae92fc001f2b03a4bf053"
44
48
  }
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import * as Charts from '@ant-design/charts';
2
3
  import { Bar, Line } from '@ant-design/charts';
3
4
  import type { BarConfig, LineConfig } from '@ant-design/charts';
4
5
 
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import * as Charts from '@oceanbase/charts';
2
3
  import { Bar, Line } from '@oceanbase/charts';
3
4
  import type { BarConfig, LineConfig } from '@oceanbase/charts';
4
5
 
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import * as Charts from '@alipay/ob-charts';
3
+ import { Bar, Line } from '@alipay/ob-charts';
4
+ import type { BarConfig, LineConfig } from '@alipay/ob-charts';
5
+
6
+ const Demo = () => {
7
+ return <div />;
8
+ };
9
+
10
+ export default Demo;
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import * as Charts from '@oceanbase/charts';
3
+ import { Bar, Line } from '@oceanbase/charts';
4
+ import type { BarConfig, LineConfig } from '@oceanbase/charts';
5
+
6
+ const Demo = () => {
7
+ return <div />;
8
+ };
9
+
10
+ export default Demo;
@@ -3,6 +3,8 @@ import { Alert, Button, BasicLayout, Login, PageContainer } from '@alipay/ob-ui'
3
3
  import type { BasicLayoutProps } from '@alipay/ob-ui/es/BasicLayout';
4
4
  import type { LoginProps } from '@alipay/ob-ui/es/Login';
5
5
  import type { PageContainerProps } from '@alipay/ob-ui/es/PageContainer';
6
+ import { Action } from '@alipay/ob-ui-v1';
7
+ import type { ActionProps } from '@alipay/ob-ui-v1/es/Action';
6
8
 
7
9
  const Demo = () => {
8
10
  return <div />;
@@ -4,6 +4,8 @@ import { BasicLayout, Login, PageContainer } from '@oceanbase/ui';
4
4
  import type { BasicLayoutProps } from '@oceanbase/ui/es/BasicLayout';
5
5
  import type { LoginProps } from '@oceanbase/ui/es/Login';
6
6
  import type { PageContainerProps } from '@oceanbase/ui/es/PageContainer';
7
+ import { Action } from '@alipay/ob-ui-v1';
8
+ import type { ActionProps } from '@alipay/ob-ui-v1/es/Action';
7
9
 
8
10
  const Demo = () => {
9
11
  return <div />;
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import { ProTable } from '@ant-design/pro-components';
3
3
  import { PageContainer } from '@oceanbase/ui';
4
4
  import type { ProTableProps } from '@ant-design/pro-components';
5
+
5
6
  import type { PageContainerProps } from '@oceanbase/ui';
6
7
 
7
8
  const Demo = () => {
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import { ProTable, WelcomeCard } from '@alipay/tech-ui';
3
3
  import { PageContainer } from '@oceanbase/ui';
4
4
  import type { ProTableProps, WelcomeCardProps } from '@alipay/tech-ui';
5
+
5
6
  import type { PageContainerProps } from '@oceanbase/ui';
6
7
 
7
8
  const Demo = () => {
@@ -1,10 +1,10 @@
1
1
  import { defineTest } from 'jscodeshift/src/testUtils';
2
2
 
3
- const testUnit = 'antd-charts-to-oceanbase-charts';
4
- const tests = ['antd-charts'];
3
+ const testUnit = 'antd-and-ob-charts-to-oceanbase-charts';
4
+ const tests = ['antd-charts', 'ob-charts'];
5
5
 
6
6
  describe(testUnit, () => {
7
7
  tests.forEach(test =>
8
- defineTest(__dirname, testUnit, {}, `${testUnit}/${test}`, { parser: 'tsx' })
8
+ defineTest(__dirname, testUnit, {}, `${testUnit}/${test}`, { parser: 'babylon' })
9
9
  );
10
10
  });
@@ -5,6 +5,6 @@ const tests = ['antd', 'bigfish-antd'];
5
5
 
6
6
  describe(testUnit, () => {
7
7
  tests.forEach(test =>
8
- defineTest(__dirname, testUnit, {}, `${testUnit}/${test}`, { parser: 'tsx' })
8
+ defineTest(__dirname, testUnit, {}, `${testUnit}/${test}`, { parser: 'babylon' })
9
9
  );
10
10
  });
@@ -5,6 +5,6 @@ const tests = ['obui'];
5
5
 
6
6
  describe(testUnit, () => {
7
7
  tests.forEach(test =>
8
- defineTest(__dirname, testUnit, {}, `${testUnit}/${test}`, { parser: 'tsx' })
8
+ defineTest(__dirname, testUnit, {}, `${testUnit}/${test}`, { parser: 'babylon' })
9
9
  );
10
10
  });
@@ -5,6 +5,6 @@ const tests = ['obutil'];
5
5
 
6
6
  describe(testUnit, () => {
7
7
  tests.forEach(test =>
8
- defineTest(__dirname, testUnit, {}, `${testUnit}/${test}`, { parser: 'tsx' })
8
+ defineTest(__dirname, testUnit, {}, `${testUnit}/${test}`, { parser: 'babylon' })
9
9
  );
10
10
  });
@@ -1,10 +1,10 @@
1
1
  import { defineTest } from 'jscodeshift/src/testUtils';
2
2
 
3
- const testUnit = 'techui-to-oceanbase-ui';
3
+ const testUnit = 'page-container-to-oceanbase-ui';
4
4
  const tests = ['techui', 'pro-components'];
5
5
 
6
6
  describe(testUnit, () => {
7
7
  tests.forEach(test =>
8
- defineTest(__dirname, testUnit, {}, `${testUnit}/${test}`, { parser: 'tsx' })
8
+ defineTest(__dirname, testUnit, {}, `${testUnit}/${test}`, { parser: 'babylon' })
9
9
  );
10
10
  });
@@ -0,0 +1,13 @@
1
+ const importComponent = require('./utils/import-component');
2
+
3
+ module.exports = (file, api, options) => {
4
+ return importComponent(file, api, {
5
+ ...options,
6
+ fromPkgNames: '@ant-design/charts,@alipay/ob-charts',
7
+ toPkgList: [
8
+ {
9
+ name: '@oceanbase/charts',
10
+ },
11
+ ],
12
+ });
13
+ };
@@ -1,8 +1,5 @@
1
1
  const importComponent = require('./utils/import-component');
2
2
 
3
- // from1: import { Button } from 'antd';
4
- // from2: import { Button } from '@alipay/bigfish/antd';
5
- // to: import { Button } from '@oceanbase/design';
6
3
  module.exports = (file, api, options) => {
7
4
  return importComponent(file, api, {
8
5
  ...options,
@@ -1,8 +1,5 @@
1
1
  const importComponent = require('./utils/import-component');
2
2
 
3
- // from: import { Button, BasicLayout } from '@alipay/ob-ui';
4
- // to1: import { Button } from '@oceanbase/design';
5
- // to2: import { BasicLayout } from '@oceanbase/ui';
6
3
  module.exports = (file, api, options) => {
7
4
  return importComponent(file, api, {
8
5
  ...options,
@@ -1,7 +1,5 @@
1
1
  const importComponent = require('./utils/import-component');
2
2
 
3
- // from: import { isNullValue, sortByNumber } from '@alipay/ob-util';
4
- // to: import { isNullValue, sortByNumber } from '@oceanbase/util';
5
3
  module.exports = (file, api, options) => {
6
4
  return importComponent(file, api, {
7
5
  ...options,
@@ -1,8 +1,5 @@
1
1
  const importComponent = require('./utils/import-component');
2
2
 
3
- // from1: import { PageContainer } from '@alipay/tech-ui';
4
- // from2: import { PageContainer } from '@ant-design/pro-components';
5
- // to: import { PageContainer } from '@oceanbase/ui';
6
3
  module.exports = (file, api, options) => {
7
4
  return importComponent(file, api, {
8
5
  ...options,
@@ -0,0 +1,8 @@
1
+ // https://github.com/benjamn/recast/blob/master/lib/options.ts
2
+ const printOptions = {
3
+ quote: 'single',
4
+ };
5
+
6
+ module.exports = {
7
+ printOptions,
8
+ };
@@ -1,20 +1,19 @@
1
1
  const { addSubmoduleImport, removeEmptyModuleImport, parseStrToArray } = require('./index');
2
+ const { markDependency } = require('./marker');
2
3
  const { printOptions } = require('./config');
3
4
 
4
5
  function importComponent(j, root, options) {
5
6
  const { fromPkgNames, toPkgList } = options;
6
7
  let hasChanged = false;
7
8
 
8
- root
9
- .find(j.ImportDeclaration)
10
- .filter(path =>
11
- fromPkgNames.some(fromPkgName => new RegExp(fromPkgName).test(path.value.source.value))
12
- )
13
- .forEach(path => {
14
- hasChanged = true;
15
- const fromPkgName = fromPkgNames.find(fromPkgName =>
16
- new RegExp(fromPkgName).test(path.value.source.value)
17
- );
9
+ root.find(j.ImportDeclaration).forEach(path => {
10
+ hasChanged = true;
11
+ const fromPkgName = fromPkgNames.find(
12
+ fromPkgName =>
13
+ fromPkgName === path.value.source.value ||
14
+ new RegExp(`${fromPkgName}/(es|lib|locale)/`).test(path.value.source.value)
15
+ );
16
+ if (fromPkgName) {
18
17
  path.value.specifiers.forEach(specifier => {
19
18
  const toPkgByComponents = toPkgList.find(toPkg =>
20
19
  toPkg.components?.includes(specifier.imported.name)
@@ -25,7 +24,7 @@ function importComponent(j, root, options) {
25
24
  const toPkg = toPkgByComponents || toPkgByTypes;
26
25
  if (toPkg) {
27
26
  // replace to toPkg for xxx/es/xxx、xxx/lib/xxx
28
- if (new RegExp(`${fromPkgName}/(es|lib)/`).test(path.value.source.value)) {
27
+ if (new RegExp(`${fromPkgName}/(es|lib|locale)/`).test(path.value.source.value)) {
29
28
  path.value.source.value = path.value.source.value?.replace(fromPkgName, toPkg.name);
30
29
  } else {
31
30
  // remove old imports
@@ -40,6 +39,7 @@ function importComponent(j, root, options) {
40
39
  after: fromPkgName,
41
40
  });
42
41
  }
42
+ markDependency(toPkg.name);
43
43
  }
44
44
  });
45
45
  if (path.value.specifiers.length > 0) {
@@ -47,9 +47,11 @@ function importComponent(j, root, options) {
47
47
  const toPkg = toPkgList.find(toPkg => !toPkg.components);
48
48
  if (toPkg) {
49
49
  path.value.source.value = path.value.source.value?.replace(fromPkgName, toPkg.name);
50
+ markDependency(toPkg.name);
50
51
  }
51
52
  }
52
- });
53
+ }
54
+ });
53
55
 
54
56
  return hasChanged;
55
57
  }
@@ -10,7 +10,9 @@ const markerPath = path.join(
10
10
  const newline = '\n';
11
11
 
12
12
  function ensureFile() {
13
- return fs.openSync(markerPath, 'w');
13
+ if (!fs.existsSync(markerPath)) {
14
+ fs.openSync(markerPath, 'w');
15
+ }
14
16
  }
15
17
 
16
18
  async function cleanup() {
@@ -1,17 +0,0 @@
1
- const importComponent = require('./utils/import-component');
2
-
3
- // from1: import { Line } from '@ant-design/charts';
4
- // from2: import type { LineConfig } from '@ant-design/charts';
5
- // to1: import { Line } from '@ant-design/charts';
6
- // from2: import type { LineConfig } from '@ant-design/charts';
7
- module.exports = (file, api, options) => {
8
- return importComponent(file, api, {
9
- ...options,
10
- fromPkgNames: '@ant-design/charts',
11
- toPkgList: [
12
- {
13
- name: '@oceanbase/charts',
14
- },
15
- ],
16
- });
17
- };
@@ -1,11 +0,0 @@
1
- // https://github.com/benjamn/recast/blob/master/lib/options.ts
2
- const printOptions = {
3
- quote: 'single',
4
- // remove extra empty line for insertAfter
5
- // ref: https://github.com/benjamn/recast/issues/371#issuecomment-565786863
6
- reuseWhitespace: false,
7
- };
8
-
9
- module.exports = {
10
- printOptions,
11
- };
File without changes
File without changes
File without changes
File without changes