@comet/upgrade 1.35.0 → 1.37.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.
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ts_morph_1 = require("ts-morph");
|
|
4
|
+
async function removeMuiDataGridErrorProp() {
|
|
5
|
+
console.log("Remove error prop from DataGrid and DataGridPro components");
|
|
6
|
+
const project = new ts_morph_1.Project({ tsConfigFilePath: "./admin/tsconfig.json" });
|
|
7
|
+
const sourceFiles = project.getSourceFiles("admin/src/**/*.tsx");
|
|
8
|
+
sourceFiles.forEach((sourceFile) => {
|
|
9
|
+
const importDeclarations = sourceFile.getImportDeclarations();
|
|
10
|
+
const dataGridImports = importDeclarations.filter((importDeclaration) => {
|
|
11
|
+
const moduleSpecifier = importDeclaration.getModuleSpecifier().getLiteralValue();
|
|
12
|
+
return moduleSpecifier === "@mui/x-data-grid" || moduleSpecifier === "@mui/x-data-grid-pro";
|
|
13
|
+
});
|
|
14
|
+
if (dataGridImports.length > 0) {
|
|
15
|
+
const jsxElements = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.JsxSelfClosingElement);
|
|
16
|
+
jsxElements.forEach((jsxElement) => {
|
|
17
|
+
const tagName = jsxElement.getTagNameNode().getText();
|
|
18
|
+
if (tagName.includes("DataGrid") || tagName.includes("DataGridPro")) {
|
|
19
|
+
const errorProp = jsxElement.getAttributes().find((attribute) => {
|
|
20
|
+
if (attribute.getKind() === ts_morph_1.SyntaxKind.JsxAttribute) {
|
|
21
|
+
const jsxAttribute = attribute.asKind(ts_morph_1.SyntaxKind.JsxAttribute);
|
|
22
|
+
return jsxAttribute && jsxAttribute.getNameNode().getText() === "error";
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
if (errorProp) {
|
|
26
|
+
console.log(`✅ Removed error prop on ${tagName} at line: ${errorProp.getStartLineNumber()} in `, sourceFile.getFilePath());
|
|
27
|
+
errorProp.replaceWithText(`/*
|
|
28
|
+
@comet/upgrade
|
|
29
|
+
TODO: DataGrid's error prop got removed in @mui/x-data-grid(-pro) > v5.
|
|
30
|
+
|
|
31
|
+
Recommended usage of errors is using parents ErrorBoundary: https://mui.com/x/migration/migration-data-grid-v5/#removed-props.
|
|
32
|
+
|
|
33
|
+
\`\`\`
|
|
34
|
+
if (error) {
|
|
35
|
+
throw error
|
|
36
|
+
}
|
|
37
|
+
\`\`\`
|
|
38
|
+
*/`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
sourceFile.save();
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
exports.default = removeMuiDataGridErrorProp;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const glob_1 = require("glob");
|
|
4
|
+
const ts_morph_1 = require("ts-morph");
|
|
5
|
+
/**
|
|
6
|
+
* This codemod changes `muiGridSortToGql` method from @comet/admin package.
|
|
7
|
+
*
|
|
8
|
+
* The function muiGridSortToGql arguments changed from `apiRef?: ReturnType<typeof useGridApiRef> to columns?: GridColDef[] introduced in Pull Request: https://github.com/vivid-planet/comet/pull/2763
|
|
9
|
+
*
|
|
10
|
+
* Change from:
|
|
11
|
+
* - muiGridSortToGql(dataGridRemote.sortModel, persistentColumnState.apiRef);
|
|
12
|
+
* + muiGridSortToGql(dataGridRemote.sortModel, columns);
|
|
13
|
+
*
|
|
14
|
+
* assuming, with the drawback, that columns variable is already available in the current scope.
|
|
15
|
+
*/
|
|
16
|
+
async function updateMuiXVersion() {
|
|
17
|
+
const project = new ts_morph_1.Project({ tsConfigFilePath: "./tsconfig.json" });
|
|
18
|
+
const files = glob_1.glob.sync(["src/**/*.ts", "src/**/*.tsx"]);
|
|
19
|
+
for (const filePath of files) {
|
|
20
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
21
|
+
if (!sourceFile) {
|
|
22
|
+
throw new Error(`Can't get source file for ${filePath}`);
|
|
23
|
+
}
|
|
24
|
+
const callExpressions = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression);
|
|
25
|
+
callExpressions.forEach((callExpression) => {
|
|
26
|
+
const expressionText = callExpression.getExpression().getText();
|
|
27
|
+
if (expressionText === "muiGridSortToGql") {
|
|
28
|
+
const args = callExpression.getArguments();
|
|
29
|
+
if (args.length === 2) {
|
|
30
|
+
args[1].replaceWithText("columns"); // expect that there is a columns variable already available in the current scope
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
await sourceFile.save();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.default = updateMuiXVersion;
|