Skip to content

Commit 6691958

Browse files
committed
feat(cli): add experimental patch-compat-table command
1 parent b4d7288 commit 6691958

File tree

9 files changed

+497
-21
lines changed

9 files changed

+497
-21
lines changed

docs/ReadMeCompat.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ import ReadMe from '../packages/compat/README.md?raw';
88

99
<Markdown>{ReadMe.split('## Documentation')[0].trim()}</Markdown>
1010

11+
<br />
12+
<br />
13+
1114
<Footer />

packages/cli/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ You can find an interactive documentation in our [Storybook](https://sap.github.
1616

1717
- [Wrapper generation](https://sap.github.io/ui5-webcomponents-react/v2/?path=/docs/knowledge-base-bring-your-own-web-components--docs)
1818
- [Code-mod](https://sap.github.io/ui5-webcomponents-react/v2/?path=/docs/migration-guide--docs#codemod)
19+
- [Patch compatibility table](https://sap.github.io/ui5-webcomponents-react/v2/?path=/docs/legacy-components-docs--docs#experimental-patch-script)
1920

2021
## Contribute
2122

packages/cli/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@
2929
"access": "public"
3030
},
3131
"files": [
32-
"dist"
32+
"dist",
33+
"patches"
3334
],
3435
"dependencies": {
35-
"dedent": "1.6.0"
36+
"dedent": "1.6.0",
37+
"execa": "^9.5.3",
38+
"patch-package": "^8.0.0"
3639
}
3740
}

packages/cli/patches/@ui5+webcomponents-compat+2.10.0.patch

Lines changed: 130 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
diff --git a/node_modules/@ui5/webcomponents-react-compat/dist/components/Table/index.js b/node_modules/@ui5/webcomponents-react-compat/dist/components/Table/index.js
2+
index 250a159..3e6d6c2 100644
3+
--- a/node_modules/@ui5/webcomponents-react-compat/dist/components/Table/index.js
4+
+++ b/node_modules/@ui5/webcomponents-react-compat/dist/components/Table/index.js
5+
@@ -56,7 +56,7 @@ import { withWebComponent } from '@ui5/webcomponents-react-base/dist/wrapper/wit
6+
*
7+
* __Note__: This is a UI5 Web Component! [Repository](https://github.com/SAP/ui5-webcomponents) | [Documentation](https://sap.github.io/ui5-webcomponents/)
8+
*/
9+
-const Table = withWebComponent('ui5-table', [
10+
+const Table = withWebComponent('ui5-table-v1', [
11+
'accessibleName',
12+
'accessibleNameRef',
13+
'busyDelay',
14+
diff --git a/node_modules/@ui5/webcomponents-react-compat/dist/components/TableCell/index.js b/node_modules/@ui5/webcomponents-react-compat/dist/components/TableCell/index.js
15+
index 2e5338f..cce3387 100644
16+
--- a/node_modules/@ui5/webcomponents-react-compat/dist/components/TableCell/index.js
17+
+++ b/node_modules/@ui5/webcomponents-react-compat/dist/components/TableCell/index.js
18+
@@ -6,6 +6,6 @@ import { withWebComponent } from '@ui5/webcomponents-react-base/dist/wrapper/wit
19+
*
20+
* __Note__: This is a UI5 Web Component! [Repository](https://github.com/SAP/ui5-webcomponents) | [Documentation](https://sap.github.io/ui5-webcomponents/)
21+
*/
22+
-const TableCell = withWebComponent('ui5-table-cell', [], [], [], []);
23+
+const TableCell = withWebComponent('ui5-table-cell-v1', [], [], [], []);
24+
TableCell.displayName = 'TableCell';
25+
export { TableCell };
26+
diff --git a/node_modules/@ui5/webcomponents-react-compat/dist/components/TableRow/index.js b/node_modules/@ui5/webcomponents-react-compat/dist/components/TableRow/index.js
27+
index 6d568f3..e5ace7d 100644
28+
--- a/node_modules/@ui5/webcomponents-react-compat/dist/components/TableRow/index.js
29+
+++ b/node_modules/@ui5/webcomponents-react-compat/dist/components/TableRow/index.js
30+
@@ -6,6 +6,7 @@ import { withWebComponent } from '@ui5/webcomponents-react-base/dist/wrapper/wit
31+
*
32+
* __Note__: This is a UI5 Web Component! [Repository](https://github.com/SAP/ui5-webcomponents) | [Documentation](https://sap.github.io/ui5-webcomponents/)
33+
*/
34+
-const TableRow = withWebComponent('ui5-table-row', ['type'], ['navigated', 'selected'], [], []);
35+
+const TableRow = withWebComponent('ui5-table-row-v1', ['type'], ['navigated', 'selected'], [], []);
36+
TableRow.displayName = 'TableRow';
37+
export { TableRow };
38+
+console.log("hello")
39+
\ No newline at end of file

packages/cli/src/bin/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#!/usr/bin/env node
22
import { resolve } from 'node:path';
3+
import { fileURLToPath } from 'node:url';
34
import { parseArgs } from 'node:util';
5+
import path from 'path';
46
import * as process from 'process';
7+
import { $ } from 'execa';
58

69
const { positionals } = parseArgs({ allowPositionals: true, strict: false });
710

@@ -120,6 +123,20 @@ switch (command) {
120123
await codemod.default(values.transform!, values.src!, values.typescript);
121124
break;
122125
}
126+
127+
case 'patch-compat-table': {
128+
const patchesPath = path.relative(process.cwd(), fileURLToPath(new URL('../../patches', import.meta.url)));
129+
130+
try {
131+
await $`patch-package --patch-dir ${patchesPath}`;
132+
console.log('Patches applied successfully!');
133+
} catch (error) {
134+
console.error('Failed to apply patches:', error);
135+
process.exit(1);
136+
}
137+
138+
break;
139+
}
123140
default:
124141
console.warn('Unknown command', command);
125142
process.exit(1);

packages/cli/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
"types": ["node"],
99
"skipLibCheck": true
1010
},
11-
"include": ["src", "**/*.json"]
11+
"include": ["src", "**/*.json", "patches"]
1212
}

packages/compat/README.md

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,23 @@ Components in this package will not receive any new features. Only critical bugs
1414
npm install @ui5/webcomponents-react-compat
1515
```
1616

17-
## Importing Components
18-
19-
As the v1 `ui5-table` (`Table`) component is part of this package and some custom element names are equal to the new v2 `ui5-table`, importing components from the root (`import { Table } from "@ui5/webcomponents-react-compat"`) is discouraged.
20-
The primary reason is that tree-shaking capabilities are limited in the default configurations of most bundlers in dev mode. As a result, custom elements for the v1 table will still be defined, even if only the `Toolbar` is imported. This can cause unexpected behavior if the v2 table is also used in the same app.
21-
2217
> ⚠️ **Warning:** It is not supported using the v1 `Table` and the v2 `Table` in the same application!
2318
2419
> ⚠️ **Warning:** Please only import components from this package via the file path!
2520
21+
## Compatibility
22+
23+
The legacy v1 (compat) `Table` and the modern v2 `Table` component and some subcomponents both register the same custom element names for `ui5-table`, `ui5-table-row` and `ui5-table-cell`, which will lead to conflicts when they coexist in the same application.
24+
25+
### Recommendation
26+
27+
We strongly recommend migrating fully to the v2 `Table`, especially if the `FilterBar` or `VariantManagement` component is used!
28+
29+
### Importing Components
30+
31+
Importing components from the root (`import { Toolbar } from "@ui5/webcomponents-react-compat"`) is discouraged.
32+
The primary reason is that tree-shaking capabilities are limited in the default configurations of most bundlers in dev mode. As a result, custom elements for the v1 table will still be defined, even if only the `Toolbar` is imported. This can cause unexpected behavior if the v2 table is also used in the same app.
33+
2634
E.g.:
2735

2836
- `import { Table } from '@ui5/webcomponents-react-compat/dist/components/Table/index.js';`
@@ -36,6 +44,60 @@ Following are the imports of duplicate custom element names:
3644
- `TableCell` (`ui5-table-cell`): `import "@ui5/webcomponents-compat/dist/TableCell.js";`
3745
- `TableRow` (`ui5-table-row`): `import "@ui5/webcomponents-compat/dist/TableRow.js";`
3846

47+
### Experimental Patch Script
48+
49+
The `patch-compat-table` script (included in the `@ui5/webcomponents-react-cli` package) is developed to address specific compatibility issues that arise when using the legacy v1 Table component in conjunction with the `FilterBar` or `VariantManagement` components. These components internally rely on the v2 `Table`, and therefore conflicts will occur when using the v1 `Table`.
50+
The script will change the custom element name by adding a `-v1` suffix (via `patch-package`) to all duplicate v1 table components.
51+
52+
> ⚠️ **Experimental**: This script is in experimental state and not subject to semantic versioning.
53+
54+
> ⚠️ **Temporary Solution:** This script is intended as a temporary workaround. It is strongly recommended to plan for a migration to the v2 Table component to ensure long-term compatibility and support.
55+
56+
<details style="cursor:auto;">
57+
58+
<summary><h4 style="display: inline; margin: 0; font-size:18px; cursor:pointer;">Using the script</h4></summary>
59+
60+
<br />
61+
62+
**What it does**
63+
64+
<p>The script patches the `@ui5/webcomponents-compat` and `@ui5/webcomponents-react-compat` table component and subcomponents components and subcomponents to render with a different custom element name (tag name) compared to the v2 implementation.
65+
This is done internally using [patch-package](https://github.com/ds300/patch-package) to adjust the implementation in the **node_modules**.</p>
66+
67+
**How to use**
68+
69+
<p>**Install** the `@ui5/webcomponents-react-cli` and `@ui5/webcomponents-compat` packages:</p>
70+
71+
```
72+
// install `@ui5/webcomponents-compat` explicitly
73+
npm i @ui5/webcomponents-react-cli @ui5/webcomponents-compat
74+
```
75+
76+
<p>**Run** the script:</p>
77+
78+
```
79+
// ui5-wcr is an executable added by the `@ui5/webcomponents-react-cli` package
80+
ui5-wcr patch-compat-table
81+
```
82+
83+
<p>The `ui5-wcr` executable is provided by the `@ui5/webcomponents-react-cli` package. The `patch-compat-table` command applies the necessary patches.</p>
84+
85+
<p>**Recommendation:**</p>
86+
87+
<p>Add the script as `postinstall` script in the `package.json`, so it runs after every module update.</p>
88+
89+
```
90+
{
91+
"//": "rest of your applications package.json",
92+
"scripts": {
93+
"//": "your other scripts",
94+
"postinstall": "ui5-wcr patch-compat-table"
95+
}
96+
}
97+
```
98+
99+
</details>
100+
39101
## Documentation
40102

41103
You can find an interactive documentation in our [Storybook](https://sap.github.io/ui5-webcomponents-react/) (Legacy Components).

0 commit comments

Comments
 (0)