@croquiscom/pds 8.0.0 → 8.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@croquiscom/pds",
3
- "version": "8.0.0",
3
+ "version": "8.1.0",
4
4
  "description": "Design system for Zigzag's Partner Center",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.es.js",
@@ -14,8 +14,10 @@ import { API, FileInfo } from 'jscodeshift';
14
14
 
15
15
  const migrations = {
16
16
  Table: 'DataTable',
17
+ TableProps: 'DataTableProps',
17
18
  TableColumnBase: 'DataTableColumnBase',
18
19
  TableColumnType: 'DataTableColumnType',
20
+ TableColumnsType: 'DataTableColumnsType',
19
21
  TableColumnGroupType: 'DataTableColumnGroupType',
20
22
  TableRowType: 'DataTableRowType',
21
23
  TableRowsType: 'DataTableRowsType',
@@ -24,11 +26,15 @@ const migrations = {
24
26
  };
25
27
 
26
28
  const original_name_list = Object.keys(migrations);
29
+ const migration_entries = Object.entries(migrations);
27
30
 
28
31
  export default function transformer(file: FileInfo, api: API) {
29
32
  const j = api.jscodeshift;
30
33
  const source = j(file.source);
31
34
 
35
+ let is_used_comp = false;
36
+ let is_used_props = false;
37
+
32
38
  if (!hasImportDeclaration(j, source, '@croquiscom/pds')) {
33
39
  return;
34
40
  }
@@ -38,16 +44,64 @@ export default function transformer(file: FileInfo, api: API) {
38
44
  .filter((path) => original_name_list.includes(path.node.imported.name))
39
45
  .forEach((path) => {
40
46
  const new_name = migrations[path.node.imported.name];
41
- if (new_name) {
42
- j(path).replaceWith(j.importSpecifier(j.identifier(new_name)));
47
+ if (!new_name) return;
48
+
49
+ if (new_name === 'DataTable') {
50
+ if (source.find(j.Identifier, { name: 'DataTable' }).length) {
51
+ j(path).replaceWith(j.importSpecifier(j.identifier(new_name), j.identifier('PdsDataTable')));
52
+ is_used_comp = true;
53
+ return;
54
+ }
55
+ }
56
+ if (new_name === 'DataTableProps') {
57
+ if (source.find(j.Identifier, { name: 'DataTableProps' }).length) {
58
+ j(path).replaceWith(j.importSpecifier(j.identifier(new_name), j.identifier('PdsDataTableProps')));
59
+ is_used_props = true;
60
+ return;
61
+ }
43
62
  }
63
+
64
+ j(path).replaceWith(j.importSpecifier(j.identifier(new_name)));
44
65
  });
45
66
 
46
- if (hasImportSpecifier(j, source, 'DataTable', '@croquiscom/pds')) {
47
- source.find(j.JSXIdentifier, { name: 'Table' }).forEach((path) => {
48
- j(path).replaceWith(j.jsxIdentifier('DataTable'));
67
+ migration_entries
68
+ .filter(([_origin, new_name]) => hasImportSpecifier(j, source, new_name, '@croquiscom/pds'))
69
+ .forEach(([original_name, new_name]) => {
70
+ if (new_name === 'DataTable') {
71
+ source.find(j.JSXIdentifier, { name: original_name }).forEach((path) => {
72
+ j(path).replaceWith(j.jsxIdentifier(is_used_comp ? 'PdsDataTable' : new_name));
73
+ });
74
+ return;
75
+ }
76
+
77
+ source.find(j.Identifier, { name: original_name }).forEach((path) => {
78
+ if (new_name === 'DataTableProps' && is_used_props) {
79
+ j(path).replaceWith('PdsDataTableProps');
80
+ } else {
81
+ j(path).replaceWith(new_name);
82
+ }
83
+ });
84
+
85
+ source
86
+ .find(j.CallExpression, { typeParameters: { type: 'TSTypeParameterInstantiation' } } as any)
87
+ .forEach((path) => {
88
+ const index = (path.node as any).typeParameters.params.findIndex((param) => {
89
+ return j(param).find(j.Identifier, { name: original_name }).length;
90
+ });
91
+
92
+ if (index === -1) return;
93
+
94
+ j((path.node as any).typeParameters.params[index])
95
+ .find(j.Identifier, { name: original_name })
96
+ .forEach((path) => {
97
+ if (new_name === 'DataTableProps' && is_used_props) {
98
+ j(path).replaceWith('PdsDataTableProps');
99
+ } else {
100
+ j(path).replaceWith(j.identifier(new_name));
101
+ }
102
+ });
103
+ });
49
104
  });
50
- }
51
105
 
52
106
  return source.toSource({ quote: 'single' });
53
107
  }