@comet/upgrade 1.32.0 → 1.34.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.
@@ -37,5 +37,9 @@ class PackageJson {
37
37
  save() {
38
38
  (0, fs_1.writeFileSync)(this.path, JSON.stringify(this.json, null, 4));
39
39
  }
40
+ addScript(name, script) {
41
+ this.json.scripts ??= {};
42
+ this.json.scripts[name] = script;
43
+ }
40
44
  }
41
45
  exports.PackageJson = PackageJson;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const promises_1 = require("fs/promises");
4
+ const glob_1 = require("glob");
5
+ /**
6
+ * BaseEntity no longer has generic type arguments.
7
+ * See https://mikro-orm.io/docs/upgrading-v5-to-v6#baseentity-no-longer-has-generic-type-arguments.
8
+ */
9
+ async function removeGenericFromBaseEntity() {
10
+ const files = glob_1.glob.sync(["api/src/**/*.entity.ts"]);
11
+ for (const filePath of files) {
12
+ let fileContent = await (0, promises_1.readFile)(filePath, "utf-8");
13
+ fileContent = fileContent.replaceAll(/BaseEntity<.*>/g, "BaseEntity");
14
+ await (0, promises_1.writeFile)(filePath, fileContent);
15
+ }
16
+ }
17
+ exports.default = removeGenericFromBaseEntity;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const promises_1 = require("fs/promises");
4
+ const glob_1 = require("glob");
5
+ /**
6
+ * Custom type has been removed in favor of just type.
7
+ * See https://mikro-orm.io/docs/upgrading-v5-to-v6#removed-propertyoptionscustomtype-in-favour-of-just-type.
8
+ */
9
+ async function replaceCustomType() {
10
+ const files = glob_1.glob.sync(["api/src/**/*.entity.ts"]);
11
+ for (const filePath of files) {
12
+ let fileContent = await (0, promises_1.readFile)(filePath, "utf-8");
13
+ fileContent = fileContent.replaceAll("customType:", "type:");
14
+ await (0, promises_1.writeFile)(filePath, fileContent);
15
+ }
16
+ }
17
+ exports.default = replaceCustomType;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const promises_1 = require("fs/promises");
4
+ const glob_1 = require("glob");
5
+ /**
6
+ * onDelete has been renamed to deleteRule.
7
+ * See https://mikro-orm.io/docs/upgrading-v5-to-v6#renames.
8
+ */
9
+ async function renameOnDelete() {
10
+ const files = glob_1.glob.sync(["api/src/**/*.entity.ts"]);
11
+ for (const filePath of files) {
12
+ let fileContent = await (0, promises_1.readFile)(filePath, "utf-8");
13
+ fileContent = fileContent.replaceAll("onDelete:", "deleteRule:");
14
+ await (0, promises_1.writeFile)(filePath, fileContent);
15
+ }
16
+ }
17
+ exports.default = renameOnDelete;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const fs_1 = require("fs");
4
+ const package_json_util_1 = require("../util/package-json.util");
5
+ /**
6
+ * Adds a `mikro-orm` script to package.json that calls dotenv.
7
+ * See https://mikro-orm.io/docs/upgrading-v5-to-v6#env-files-are-no-longer-automatically-loaded.
8
+ */
9
+ async function addDotenvCallToConfig() {
10
+ if (!(0, fs_1.existsSync)("api/package.json")) {
11
+ return;
12
+ }
13
+ const packageJson = new package_json_util_1.PackageJson("api/package.json");
14
+ packageJson.addScript("mikro-orm", "dotenv -e .env.secrets -e .env.local -e .env -e .env.site-configs -- mikro-orm");
15
+ packageJson.save();
16
+ }
17
+ exports.default = addDotenvCallToConfig;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const promises_1 = require("fs/promises");
4
+ const glob_1 = require("glob");
5
+ /**
6
+ * Always import form `@mikro-orm/postgresql`.
7
+ * See https://mikro-orm.io/docs/upgrading-v5-to-v6#all-drivers-now-re-export-the-mikro-ormcore-package.
8
+ */
9
+ async function replaceImports() {
10
+ const files = glob_1.glob.sync(["api/src/**/*.entity.ts"]);
11
+ for (const filePath of files) {
12
+ let fileContent = await (0, promises_1.readFile)(filePath, "utf-8");
13
+ fileContent = fileContent.replaceAll("@mikro-orm/core", "@mikro-orm/postgresql");
14
+ await (0, promises_1.writeFile)(filePath, fileContent);
15
+ }
16
+ }
17
+ exports.default = replaceImports;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const ts_morph_1 = require("ts-morph");
4
+ /**
5
+ * Wrap the config in createOrmConfig with defineConfig
6
+ */
7
+ async function replaceCustomType() {
8
+ const project = new ts_morph_1.Project({ tsConfigFilePath: "./api/tsconfig.json" });
9
+ const sourceFile = project.getSourceFile("api/src/db/ormconfig.ts");
10
+ if (!sourceFile) {
11
+ return;
12
+ }
13
+ sourceFile.addImportDeclaration({
14
+ namedImports: ["defineConfig"],
15
+ moduleSpecifier: "@mikro-orm/postgresql",
16
+ });
17
+ const config = sourceFile
18
+ .getVariableStatementOrThrow("ormConfig")
19
+ .getDeclarations()[0]
20
+ .getInitializerIfKindOrThrow(ts_morph_1.SyntaxKind.CallExpression)
21
+ .getArguments()[0];
22
+ config.replaceWithText(`defineConfig(${config.getText()})`);
23
+ await sourceFile.save();
24
+ }
25
+ exports.default = replaceCustomType;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const ts_morph_1 = require("ts-morph");
4
+ /**
5
+ * From
6
+ *
7
+ * if (error instanceof ValidationError) {
8
+ * return new ValidationError("Invalid request.");
9
+ * }
10
+ *
11
+ * to
12
+ *
13
+ * if (error.extensions?.code === "GRAPHQL_VALIDATION_FAILED") {
14
+ * return new ValidationError("Invalid request.");
15
+ * }
16
+ */
17
+ async function updateGraphQLFormatError() {
18
+ const project = new ts_morph_1.Project({ tsConfigFilePath: "./api/tsconfig.json" });
19
+ const sourceFile = project.getSourceFile("api/src/app.module.ts");
20
+ if (!sourceFile) {
21
+ throw new Error("app.module.ts not found");
22
+ }
23
+ // Change the import
24
+ sourceFile.getImportDeclaration((importDeclaration) => importDeclaration.getModuleSpecifierValue() === "apollo-server-express")?.remove();
25
+ sourceFile.addImportDeclaration({ namedImports: ["ValidationError"], moduleSpecifier: "@nestjs/apollo" });
26
+ // Update the if statement
27
+ sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.BinaryExpression).forEach((node) => {
28
+ if (node.getText() === "error instanceof ValidationError") {
29
+ node.replaceWithText(`error.extensions?.code === "GRAPHQL_VALIDATION_FAILED"`);
30
+ }
31
+ });
32
+ await sourceFile.save();
33
+ }
34
+ exports.default = updateGraphQLFormatError;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comet/upgrade",
3
- "version": "1.32.0",
3
+ "version": "1.34.0",
4
4
  "description": "Upgrade scripts for Comet DXP",
5
5
  "homepage": "https://github.com/vivid-planet/comet-upgrade#readme",
6
6
  "bugs": {