@comet/upgrade 1.60.0 → 1.61.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,34 @@
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
+ * Replace UseRequestContext with CreateRequestContext
7
+ */
8
+ async function mikroOrmCreateRequestContext() {
9
+ const project = new ts_morph_1.Project({ tsConfigFilePath: "./api/tsconfig.json" });
10
+ const files = glob_1.glob.sync("api/src/**/*.ts");
11
+ for (const filePath of files) {
12
+ const sourceFile = project.getSourceFile(filePath);
13
+ if (!sourceFile) {
14
+ continue;
15
+ }
16
+ const mikroOrmCoreImport = sourceFile.getImportDeclaration((importDeclaration) => importDeclaration.getModuleSpecifierValue() === "@mikro-orm/core");
17
+ if (!mikroOrmCoreImport) {
18
+ continue;
19
+ }
20
+ const useRequestContextImport = mikroOrmCoreImport.getNamedImports().find((namedImport) => namedImport.getText() === "UseRequestContext");
21
+ useRequestContextImport?.remove();
22
+ if (!mikroOrmCoreImport.getNamedImports().find((namedImport) => namedImport.getText() === "CreateRequestContext")) {
23
+ mikroOrmCoreImport.addNamedImport("CreateRequestContext");
24
+ }
25
+ sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.Decorator).forEach((decorator) => {
26
+ const identifier = decorator.getFirstDescendantByKind(ts_morph_1.SyntaxKind.Identifier);
27
+ if (identifier && identifier.getText() === "UseRequestContext") {
28
+ identifier.replaceWithText("CreateRequestContext");
29
+ }
30
+ });
31
+ await sourceFile.save();
32
+ }
33
+ }
34
+ exports.default = mikroOrmCreateRequestContext;
@@ -10,6 +10,9 @@ async function replaceCustomType() {
10
10
  if (!sourceFile) {
11
11
  return;
12
12
  }
13
+ if (sourceFile.getText().includes("defineConfig")) {
14
+ return;
15
+ }
13
16
  sourceFile.addImportDeclaration({
14
17
  namedImports: ["defineConfig"],
15
18
  moduleSpecifier: "@mikro-orm/postgresql",
@@ -19,6 +22,11 @@ async function replaceCustomType() {
19
22
  .getDeclarations()[0]
20
23
  .getInitializerIfKindOrThrow(ts_morph_1.SyntaxKind.CallExpression)
21
24
  .getArguments()[0];
25
+ for (const propertyAssignment of config.getDescendantsOfKind(ts_morph_1.SyntaxKind.PropertyAssignment)) {
26
+ if (propertyAssignment.getName() === "type") {
27
+ propertyAssignment.remove();
28
+ }
29
+ }
22
30
  config.replaceWithText(`defineConfig(${config.getText()})`);
23
31
  await sourceFile.save();
24
32
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comet/upgrade",
3
- "version": "1.60.0",
3
+ "version": "1.61.0",
4
4
  "description": "Upgrade scripts for Comet DXP",
5
5
  "homepage": "https://github.com/vivid-planet/comet-upgrade#readme",
6
6
  "bugs": {