@comet/upgrade 1.73.0 → 1.75.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.
package/lib/index.js CHANGED
@@ -37,8 +37,7 @@ const microservices = ["api", "admin", "site"];
37
37
  function microserviceExists(microservice) {
38
38
  return fs_1.default.existsSync(`${microservice}/package.json`);
39
39
  }
40
- const isRunningViaNpx = Boolean(process.env.npm_execpath?.includes("npx"));
41
- const isLocalDevelopment = !isRunningViaNpx;
40
+ const isLocalDevelopment = process.argv[0].endsWith("node");
42
41
  async function main() {
43
42
  let targetVersionArg = process.argv[2];
44
43
  if (targetVersionArg === undefined) {
@@ -46,7 +45,7 @@ async function main() {
46
45
  process.exit(-1);
47
46
  }
48
47
  if (isLocalDevelopment) {
49
- console.warn("Not running via npx -> assuming local development. Scripts will run twice to ensure idempotency.");
48
+ console.warn("Executed via node -> assuming local development. Scripts will run twice to ensure idempotency.");
50
49
  }
51
50
  const isUpgradeScript = targetVersionArg.endsWith(".ts");
52
51
  if (isUpgradeScript) {
@@ -0,0 +1,45 @@
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
+ async function removeReactBarrelImportsAdmin() {
6
+ const project = new ts_morph_1.Project({ tsConfigFilePath: "./admin/tsconfig.json" });
7
+ const files = glob_1.glob.sync(["admin/src/**/*.ts", "admin/src/**/*.tsx"]);
8
+ for (const filePath of files) {
9
+ const sourceFile = project.getSourceFile(filePath);
10
+ if (!sourceFile)
11
+ continue;
12
+ // Find and remove all imports of React from "react"
13
+ const reactImports = sourceFile.getImportDeclarations().filter((imp) => imp.getModuleSpecifierValue() === "react");
14
+ const namedUsages = new Set();
15
+ for (const imp of reactImports) {
16
+ // Collect named imports (if any)
17
+ const named = imp.getNamedImports().map((ni) => ni.getName());
18
+ named.forEach((n) => namedUsages.add(n));
19
+ // Remove the import
20
+ imp.remove();
21
+ }
22
+ // Find usages of React.something and replace with something
23
+ sourceFile.forEachDescendant((node) => {
24
+ if (node.getKindName() === "PropertyAccessExpression") {
25
+ const text = node.getText();
26
+ if (text.startsWith("React.")) {
27
+ // Only add the first property after React. as named import
28
+ const member = text.split(".")[1];
29
+ if (member)
30
+ namedUsages.add(member);
31
+ node.replaceWithText(text.replace("React.", ""));
32
+ }
33
+ }
34
+ });
35
+ // Add import { ... } from "react" for all used members
36
+ if (namedUsages.size > 0) {
37
+ sourceFile.addImportDeclaration({
38
+ namedImports: Array.from(namedUsages),
39
+ moduleSpecifier: "react",
40
+ });
41
+ }
42
+ }
43
+ await project.save();
44
+ }
45
+ exports.default = removeReactBarrelImportsAdmin;
@@ -0,0 +1,45 @@
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
+ async function removeReactBarrelImportsSite() {
6
+ const project = new ts_morph_1.Project({ tsConfigFilePath: "./site/tsconfig.json" });
7
+ const files = glob_1.glob.sync(["site/src/**/*.ts", "site/src/**/*.tsx"]);
8
+ for (const filePath of files) {
9
+ const sourceFile = project.getSourceFile(filePath);
10
+ if (!sourceFile)
11
+ continue;
12
+ // Find and remove all imports of React from "react"
13
+ const reactImports = sourceFile.getImportDeclarations().filter((imp) => imp.getModuleSpecifierValue() === "react");
14
+ const namedUsages = new Set();
15
+ for (const imp of reactImports) {
16
+ // Collect named imports (if any)
17
+ const named = imp.getNamedImports().map((ni) => ni.getName());
18
+ named.forEach((n) => namedUsages.add(n));
19
+ // Remove the import
20
+ imp.remove();
21
+ }
22
+ // Find usages of React.something and replace with something
23
+ sourceFile.forEachDescendant((node) => {
24
+ if (node.getKindName() === "PropertyAccessExpression") {
25
+ const text = node.getText();
26
+ if (text.startsWith("React.")) {
27
+ // Only add the first property after React. as named import
28
+ const member = text.split(".")[1];
29
+ if (member)
30
+ namedUsages.add(member);
31
+ node.replaceWithText(text.replace("React.", ""));
32
+ }
33
+ }
34
+ });
35
+ // Add import { ... } from "react" for all used members
36
+ if (namedUsages.size > 0) {
37
+ sourceFile.addImportDeclaration({
38
+ namedImports: Array.from(namedUsages),
39
+ moduleSpecifier: "react",
40
+ });
41
+ }
42
+ }
43
+ await project.save();
44
+ }
45
+ exports.default = removeReactBarrelImportsSite;
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const ts_morph_1 = require("ts-morph");
4
+ /**
5
+ * From
6
+ *
7
+ * GraphQLModule.forRootAsync<ApolloDriverConfig>({
8
+ * useFactory: (moduleRef: ModuleRef) => ({
9
+ * playground: config.debug,
10
+ * }),
11
+ * }),
12
+ *
13
+ * to
14
+ *
15
+ * GraphQLModule.forRootAsync<ApolloDriverConfig>({
16
+ * useFactory: (moduleRef: ModuleRef) => ({
17
+ * graphiql: config.debug ? { url: "/api/graphql" } : undefined,
18
+ * playground: false,
19
+ * }),
20
+ * }),
21
+ */
22
+ function default_1() {
23
+ const project = new ts_morph_1.Project();
24
+ const filePath = "api/src/app.module.ts";
25
+ const sourceFile = project.addSourceFileAtPath(filePath);
26
+ for (const node of sourceFile.getDescendants()) {
27
+ if (node.getKind() === ts_morph_1.SyntaxKind.CallExpression && node.getText().startsWith("GraphQLModule.forRootAsync")) {
28
+ const callExpr = node.asKindOrThrow(ts_morph_1.SyntaxKind.CallExpression);
29
+ const arg = callExpr.getArguments()[0];
30
+ if (arg && arg.getKind() === ts_morph_1.SyntaxKind.ObjectLiteralExpression) {
31
+ const obj = arg.asKindOrThrow(ts_morph_1.SyntaxKind.ObjectLiteralExpression);
32
+ const useFactoryProp = obj.getProperty("useFactory");
33
+ if (useFactoryProp && useFactoryProp.getKind() === ts_morph_1.SyntaxKind.PropertyAssignment) {
34
+ const useFactory = useFactoryProp.asKindOrThrow(ts_morph_1.SyntaxKind.PropertyAssignment);
35
+ const arrowFunc = useFactory.getInitializerIfKind(ts_morph_1.SyntaxKind.ArrowFunction);
36
+ if (arrowFunc) {
37
+ const body = arrowFunc.getBody();
38
+ if (body.getKind() === ts_morph_1.SyntaxKind.ParenthesizedExpression) {
39
+ const retObj = body.getFirstChildByKind(ts_morph_1.SyntaxKind.ObjectLiteralExpression);
40
+ if (retObj) {
41
+ if (retObj.getProperty("graphiql")) {
42
+ return; // Already has graphiql property
43
+ }
44
+ // Replace playground: config.debug with playground: false
45
+ const playgroundProp = retObj.getProperty("playground");
46
+ if (playgroundProp) {
47
+ playgroundProp.replaceWithText("playground: false");
48
+ }
49
+ const graphiqlProperty = retObj.insertPropertyAssignment(playgroundProp ? playgroundProp.getChildIndex() - 1 : 0, {
50
+ name: "graphiql",
51
+ initializer: 'config.debug ? { url: "/api/graphql" } : undefined',
52
+ });
53
+ graphiqlProperty.replaceWithText(`// eslint-disable-next-line @cspell/spellchecker\n${graphiqlProperty.getText()}`);
54
+ break;
55
+ }
56
+ }
57
+ }
58
+ }
59
+ }
60
+ }
61
+ }
62
+ sourceFile.saveSync();
63
+ }
64
+ exports.default = default_1;
@@ -12,15 +12,15 @@ async function updateNestDependencies() {
12
12
  packageJson.addDependency("@apollo/server", "^4.0.0");
13
13
  packageJson.removeDependency("apollo-server-core");
14
14
  packageJson.removeDependency("apollo-server-express");
15
- packageJson.updateDependency("@nestjs/apollo", "^13.0.3");
16
- packageJson.updateDependency("@nestjs/common", "^11.0.10");
17
- packageJson.updateDependency("@nestjs/core", "^11.0.10");
18
- packageJson.updateDependency("@nestjs/graphql", "^13.0.3");
15
+ packageJson.updateDependency("@nestjs/apollo", "^13.1.0");
16
+ packageJson.updateDependency("@nestjs/common", "^11.1.3");
17
+ packageJson.updateDependency("@nestjs/core", "^11.1.3");
18
+ packageJson.updateDependency("@nestjs/graphql", "^13.1.0");
19
19
  packageJson.updateDependency("@nestjs/mapped-types", "^2.1.0");
20
- packageJson.updateDependency("@nestjs/platform-express", "^11.0.10");
21
- packageJson.updateDependency("@nestjs/cli", "^11.0.3");
22
- packageJson.updateDependency("@nestjs/schematics", "^11.0.1");
23
- packageJson.updateDependency("@nestjs/testing", "^11.0.0");
20
+ packageJson.updateDependency("@nestjs/platform-express", "^11.1.3");
21
+ packageJson.updateDependency("@nestjs/cli", "^11.0.7");
22
+ packageJson.updateDependency("@nestjs/schematics", "^11.0.5");
23
+ packageJson.updateDependency("@nestjs/testing", "^11.1.3");
24
24
  packageJson.updateDependency("graphql", "^16.10.0");
25
25
  packageJson.updateDependency("express", "^5.0.1");
26
26
  packageJson.updateDependency("@types/express", "^5.0.0");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comet/upgrade",
3
- "version": "1.73.0",
3
+ "version": "1.75.0",
4
4
  "description": "Upgrade scripts for Comet DXP",
5
5
  "homepage": "https://github.com/vivid-planet/comet-upgrade#readme",
6
6
  "bugs": {