From 783db1b2955bbc010478909b50718bcbd02c9241 Mon Sep 17 00:00:00 2001 From: juliawegmayr <109900447+juliawegmayr@users.noreply.github.com> Date: Wed, 18 Dec 2024 16:20:37 +0100 Subject: [PATCH 1/6] Add script to update `Tooltip` imports from `@mui/material` to `@comet/admin` (#41) Co-authored-by: Julia Wegmayr --- src/v8/update-import-of-tooltip.ts | 50 ++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/v8/update-import-of-tooltip.ts diff --git a/src/v8/update-import-of-tooltip.ts b/src/v8/update-import-of-tooltip.ts new file mode 100644 index 0000000..50e49e7 --- /dev/null +++ b/src/v8/update-import-of-tooltip.ts @@ -0,0 +1,50 @@ +import { glob } from "glob"; +import { Project } from "ts-morph"; + +export default async function updateImportOfTooltip() { + const project = new Project({ tsConfigFilePath: "./admin/tsconfig.json" }); + const files: string[] = glob.sync(["admin/src/**/*.tsx"]); + + for (const filePath of files) { + const sourceFile = project.getSourceFile(filePath); + + if (!sourceFile) { + throw new Error(`Can't get source file for ${filePath}`); + } + + const adminImport = sourceFile.getImportDeclaration((declaration) => declaration.getModuleSpecifierValue().includes("@comet/admin")); + const adminImports = adminImport?.getNamedImports().map((namedImport) => namedImport.getText()); + + if (adminImports) { + if (adminImports.includes("Tooltip")) { + continue; + } + } + + const muiImport = sourceFile.getImportDeclaration((declaration) => declaration.getModuleSpecifierValue() === "@mui/material"); + + if (!muiImport) continue; + + const namedImports = muiImport.getNamedImports(); + const tooltipImport = namedImports.find((namedImport) => namedImport.getText() === "Tooltip"); + + if (tooltipImport) { + tooltipImport.remove(); + } + + if (muiImport.getNamedImports().length === 0) { + muiImport.remove(); + } + + if (adminImport) { + adminImport.addNamedImports(["Tooltip"]); + } else { + sourceFile.addImportDeclaration({ + namedImports: ["Tooltip"], + moduleSpecifier: "@comet/admin", + }); + } + + await sourceFile.save(); + } +} From bf405f3017004b6121b6515c3760e0e4525e1a86 Mon Sep 17 00:00:00 2001 From: johnnyomair Date: Wed, 18 Dec 2024 15:21:02 +0000 Subject: [PATCH 2/6] Publish v1.31.0 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 911c198..7e55722 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@comet/upgrade", - "version": "1.30.0", + "version": "1.31.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@comet/upgrade", - "version": "1.30.0", + "version": "1.31.0", "license": "BSD-2-Clause", "dependencies": { "eslint": "^8.56.0", diff --git a/package.json b/package.json index a2ab16a..815db39 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@comet/upgrade", - "version": "1.30.0", + "version": "1.31.0", "description": "Upgrade scripts for Comet DXP", "homepage": "https://github.com/vivid-planet/comet-upgrade#readme", "bugs": { From ea8d9d6b2e397f2dca90cc02545be04a9e1df610 Mon Sep 17 00:00:00 2001 From: Johannes Obermair <48853629+johnnyomair@users.noreply.github.com> Date: Thu, 19 Dec 2024 16:51:47 +0100 Subject: [PATCH 3/6] Add script to update MikroORM dependencies (#40) --- src/util/package-json.util.ts | 49 +++++++++++++++++++++++++ src/v8/update-mikro-orm-dependencies.ts | 21 +++++++++++ src/v8/update-nest-dependencies.ts | 49 ++++++++++--------------- 3 files changed, 90 insertions(+), 29 deletions(-) create mode 100644 src/util/package-json.util.ts create mode 100644 src/v8/update-mikro-orm-dependencies.ts diff --git a/src/util/package-json.util.ts b/src/util/package-json.util.ts new file mode 100644 index 0000000..c84fd20 --- /dev/null +++ b/src/util/package-json.util.ts @@ -0,0 +1,49 @@ +import { existsSync, readFileSync, writeFileSync } from "fs"; + +type Json = { + dependencies?: Record; + devDependencies?: Record; +}; + +export class PackageJson { + private path: string; + private json: Json; + + constructor(path: string) { + if (!existsSync(path)) { + throw new Error("File does not exist"); + } + + this.path = path; + this.json = JSON.parse(readFileSync(path, "utf-8")); + } + + addDependency(name: string, version: string, dev = false) { + if (dev) { + this.json.devDependencies ??= {}; + this.json.devDependencies[name] = version; + } else { + this.json.dependencies ??= {}; + this.json.dependencies[name] = version; + } + } + + updateDependency(name: string, version: string) { + if (this.json.dependencies?.[name]) { + this.json.dependencies[name] = version; + } + + if (this.json.devDependencies?.[name]) { + this.json.devDependencies[name] = version; + } + } + + removeDependency(name: string) { + delete this.json.dependencies?.[name]; + delete this.json.devDependencies?.[name]; + } + + save() { + writeFileSync(this.path, JSON.stringify(this.json, null, 4)); + } +} diff --git a/src/v8/update-mikro-orm-dependencies.ts b/src/v8/update-mikro-orm-dependencies.ts new file mode 100644 index 0000000..f488ed2 --- /dev/null +++ b/src/v8/update-mikro-orm-dependencies.ts @@ -0,0 +1,21 @@ +import { existsSync } from "fs"; + +import { PackageJson } from "../util/package-json.util"; + +export const stage = "before-install"; + +export default async function updateNestDependencies() { + if (!existsSync("api/package.json")) { + return; + } + + const packageJson = new PackageJson("api/package.json"); + + packageJson.updateDependency("@mikro-orm/cli", "^6.0.0"); + packageJson.updateDependency("@mikro-orm/core", "^6.0.0"); + packageJson.updateDependency("@mikro-orm/migrations", "^6.0.0"); + packageJson.updateDependency("@mikro-orm/nestjs", "^6.0.2"); + packageJson.updateDependency("@mikro-orm/postgresql", "^6.0.0"); + + packageJson.save(); +} diff --git a/src/v8/update-nest-dependencies.ts b/src/v8/update-nest-dependencies.ts index ce29539..6511c3e 100644 --- a/src/v8/update-nest-dependencies.ts +++ b/src/v8/update-nest-dependencies.ts @@ -1,45 +1,36 @@ import { existsSync } from "fs"; -import { readFile, writeFile } from "fs/promises"; -export const stage = "before-install"; +import { PackageJson } from "../util/package-json.util"; -function updateDependencyIfExists(dependencies: Record, name: string, version: string) { - if (dependencies[name]) { - dependencies[name] = version; - } -} +export const stage = "before-install"; export default async function updateNestDependencies() { if (!existsSync("api/package.json")) { return; } - const packageJson = JSON.parse(await readFile("api/package.json", "utf-8")); + const packageJson = new PackageJson("api/package.json"); - if (packageJson.dependencies) { - packageJson.dependencies["@apollo/server"] = "^4.0.0"; - delete packageJson.dependencies["apollo-server-core"]; - delete packageJson.dependencies["apollo-server-express"]; + packageJson.addDependency("@apollo/server", "^4.0.0"); + packageJson.removeDependency("apollo-server-core"); + packageJson.removeDependency("apollo-server-express"); - updateDependencyIfExists(packageJson.dependencies, "@nestjs/apollo", "^12.0.0"); - updateDependencyIfExists(packageJson.dependencies, "@nestjs/common", "^10.0.0"); - updateDependencyIfExists(packageJson.dependencies, "@nestjs/core", "^10.0.0"); - updateDependencyIfExists(packageJson.dependencies, "@nestjs/graphql", "^12.0.0"); - // TODO remove when https://github.com/vivid-planet/comet/pull/2809 has been merged - updateDependencyIfExists(packageJson.dependencies, "@nestjs/passport", "^10.0.0"); - updateDependencyIfExists(packageJson.dependencies, "@nestjs/platform-express", "^10.0.0"); + packageJson.updateDependency("@nestjs/apollo", "^12.0.0"); + packageJson.updateDependency("@nestjs/common", "^10.0.0"); + packageJson.updateDependency("@nestjs/core", "^10.0.0"); + packageJson.updateDependency("@nestjs/graphql", "^12.0.0"); + // TODO remove when https://github.com/vivid-planet/comet/pull/2809 has been merged + packageJson.updateDependency("@nestjs/passport", "^10.0.0"); + packageJson.updateDependency("@nestjs/platform-express", "^10.0.0"); - updateDependencyIfExists(packageJson.dependencies, "graphql", "^16.6.0"); + packageJson.updateDependency("graphql", "^16.6.0"); - updateDependencyIfExists(packageJson.dependencies, "nestjs-console", "^9.0.0"); - updateDependencyIfExists(packageJson.dependencies, "@golevelup/nestjs-discovery", "^4.0.0"); - } + packageJson.updateDependency("nestjs-console", "^9.0.0"); + packageJson.updateDependency("@golevelup/nestjs-discovery", "^4.0.0"); - if (packageJson.devDependencies) { - updateDependencyIfExists(packageJson.devDependencies, "@nestjs/cli", "^10.0.0"); - updateDependencyIfExists(packageJson.devDependencies, "@nestjs/schematics", "^10.0.0"); - updateDependencyIfExists(packageJson.devDependencies, "@nestjs/testing", "^10.0.0"); - } + packageJson.updateDependency("@nestjs/cli", "^10.0.0"); + packageJson.updateDependency("@nestjs/schematics", "^10.0.0"); + packageJson.updateDependency("@nestjs/testing", "^10.0.0"); - await writeFile("api/package.json", JSON.stringify(packageJson, null, 4)); + packageJson.save(); } From 71a7f323a778fa9a033d0ed11a6dce74a10b7642 Mon Sep 17 00:00:00 2001 From: johnnyomair Date: Thu, 19 Dec 2024 15:52:13 +0000 Subject: [PATCH 4/6] Publish v1.32.0 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7e55722..6d2c64b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@comet/upgrade", - "version": "1.31.0", + "version": "1.32.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@comet/upgrade", - "version": "1.31.0", + "version": "1.32.0", "license": "BSD-2-Clause", "dependencies": { "eslint": "^8.56.0", diff --git a/package.json b/package.json index 815db39..193804e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@comet/upgrade", - "version": "1.31.0", + "version": "1.32.0", "description": "Upgrade scripts for Comet DXP", "homepage": "https://github.com/vivid-planet/comet-upgrade#readme", "bugs": { From 2d54a11b36fa9a6309a4f5e7efb2b2112ea2b902 Mon Sep 17 00:00:00 2001 From: Johannes Obermair <48853629+johnnyomair@users.noreply.github.com> Date: Tue, 7 Jan 2025 15:48:54 +0100 Subject: [PATCH 5/6] Add script to update the formatError implementation (#38) --- src/v8/update-graphql-format-error.ts | 37 +++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/v8/update-graphql-format-error.ts diff --git a/src/v8/update-graphql-format-error.ts b/src/v8/update-graphql-format-error.ts new file mode 100644 index 0000000..12b15e7 --- /dev/null +++ b/src/v8/update-graphql-format-error.ts @@ -0,0 +1,37 @@ +import { Project, SyntaxKind } from "ts-morph"; + +/** + * From + * + * if (error instanceof ValidationError) { + * return new ValidationError("Invalid request."); + * } + * + * to + * + * if (error.extensions?.code === "GRAPHQL_VALIDATION_FAILED") { + * return new ValidationError("Invalid request."); + * } + */ +export default async function updateGraphQLFormatError() { + const project = new Project({ tsConfigFilePath: "./api/tsconfig.json" }); + + const sourceFile = project.getSourceFile("api/src/app.module.ts"); + + if (!sourceFile) { + throw new Error("app.module.ts not found"); + } + + // Change the import + sourceFile.getImportDeclaration((importDeclaration) => importDeclaration.getModuleSpecifierValue() === "apollo-server-express")?.remove(); + sourceFile.addImportDeclaration({ namedImports: ["ValidationError"], moduleSpecifier: "@nestjs/apollo" }); + + // Update the if statement + sourceFile.getDescendantsOfKind(SyntaxKind.BinaryExpression).forEach((node) => { + if (node.getText() === "error instanceof ValidationError") { + node.replaceWithText(`error.extensions?.code === "GRAPHQL_VALIDATION_FAILED"`); + } + }); + + await sourceFile.save(); +} From 92f0a756783977cc47ee941376effbaf99bbf88a Mon Sep 17 00:00:00 2001 From: johnnyomair Date: Tue, 7 Jan 2025 14:49:17 +0000 Subject: [PATCH 6/6] Publish v1.33.0 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6d2c64b..e47147c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@comet/upgrade", - "version": "1.32.0", + "version": "1.33.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@comet/upgrade", - "version": "1.32.0", + "version": "1.33.0", "license": "BSD-2-Clause", "dependencies": { "eslint": "^8.56.0", diff --git a/package.json b/package.json index 193804e..c6fc9ad 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@comet/upgrade", - "version": "1.32.0", + "version": "1.33.0", "description": "Upgrade scripts for Comet DXP", "homepage": "https://github.com/vivid-planet/comet-upgrade#readme", "bugs": {