@comet/upgrade 1.41.0 → 1.43.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
@@ -7,12 +7,13 @@ const fs_1 = __importDefault(require("fs"));
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const semver_1 = __importDefault(require("semver"));
9
9
  const execute_command_util_1 = require("./util/execute-command.util");
10
+ const get_latest_package_version_1 = require("./util/get-latest-package-version");
10
11
  const microservices = ["api", "admin", "site"];
11
12
  function microserviceExists(microservice) {
12
13
  return fs_1.default.existsSync(`${microservice}/package.json`);
13
14
  }
14
15
  async function main() {
15
- const targetVersionArg = process.argv[2];
16
+ let targetVersionArg = process.argv[2];
16
17
  if (targetVersionArg === undefined) {
17
18
  console.error("Missing target version! Usage: npx @comet/upgrade <version>");
18
19
  process.exit(-1);
@@ -36,6 +37,9 @@ async function main() {
36
37
  }
37
38
  return;
38
39
  }
40
+ if (!targetVersionArg.includes(".")) {
41
+ targetVersionArg = await (0, get_latest_package_version_1.getLatestPackageVersion)("@comet/admin", semver_1.default.coerce(targetVersionArg)?.major);
42
+ }
39
43
  const targetVersion = semver_1.default.coerce(targetVersionArg, { includePrerelease: true });
40
44
  if (!targetVersion) {
41
45
  console.error("Can't parse version number. Example usage: npx @comet/upgrade v4");
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getLatestPackageVersion = void 0;
7
+ const semver_1 = __importDefault(require("semver"));
8
+ async function getLatestPackageVersion(packageName, majorVersion) {
9
+ const url = `https://registry.npmjs.org/${packageName}`;
10
+ try {
11
+ const response = await fetch(url);
12
+ if (!response.ok) {
13
+ throw new Error(`Failed to fetch package info: ${response.status} ${response.statusText}`);
14
+ }
15
+ const packageInfo = (await response.json());
16
+ if (!majorVersion) {
17
+ return packageInfo.version;
18
+ }
19
+ const versions = Object.keys(packageInfo.versions);
20
+ const latestForMajor = versions.filter((version) => semver_1.default.satisfies(version, `^${majorVersion}.0.0`)).sort(semver_1.default.rcompare)[0];
21
+ return latestForMajor;
22
+ }
23
+ catch (error) {
24
+ throw new Error(`Failed to fetch package info for ${packageName}: ${error}`);
25
+ }
26
+ }
27
+ exports.getLatestPackageVersion = getLatestPackageVersion;
@@ -15,14 +15,23 @@ async function useGraphqlScalars() {
15
15
  await (0, execute_command_util_1.executeCommand)("npm", ["uninstall", "--prefix", "api", "--no-audit", "--loglevel", "error", "graphql-type-json"]);
16
16
  await (0, execute_command_util_1.executeCommand)("npm", ["install", "--prefix", "api", "--no-audit", "--loglevel", "error", "graphql-scalars"]);
17
17
  // replace graphql-type-json with graphql-scalars in all api files
18
- // before: import { GraphQLJSONObject } from "graphql-type-json";
19
- // after: import { GraphQLJSONObject } from "graphql-scalars";
18
+ // before: import { <GraphQLJSON|GraphQLJSONObject> } from "graphql-type-json"; or import <ImportedName> from "graphql-type-json";
19
+ // after: import { <GraphQLJSON|GraphQLJSONObject> } from "graphql-scalars";
20
20
  const files = glob_1.glob.sync(["api/src/**/*.ts"]);
21
21
  for (const filePath of files) {
22
22
  let fileContent = (await (0, promises_1.readFile)(filePath)).toString();
23
23
  if (!fileContent.includes("graphql-type-json")) {
24
24
  continue;
25
25
  }
26
+ // replace default imports (which is GraphQLJSON) from graphql-type-json. Because of the default import, the name can be anything.
27
+ const defaultImportMatches = fileContent.match(/import ([a-zA-Z]+) from "graphql-type-json";/);
28
+ if (defaultImportMatches) {
29
+ // replace default import
30
+ fileContent = fileContent.replace(new RegExp(`import ${defaultImportMatches[1]} from "graphql-type-json";`, "g"), `import { GraphQLJSON } from "graphql-scalars";`);
31
+ // replace all usages of the default import
32
+ fileContent = fileContent.replace(new RegExp(`${defaultImportMatches[1]}`, "g"), "GraphQLJSON");
33
+ }
34
+ // replace the rest
26
35
  fileContent = fileContent.replace(/graphql-type-json/g, "graphql-scalars");
27
36
  await (0, promises_1.writeFile)(filePath, await (0, format_code_util_1.formatCode)(fileContent, filePath));
28
37
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comet/upgrade",
3
- "version": "1.41.0",
3
+ "version": "1.43.0",
4
4
  "description": "Upgrade scripts for Comet DXP",
5
5
  "homepage": "https://github.com/vivid-planet/comet-upgrade#readme",
6
6
  "bugs": {