@comet/upgrade 1.41.0 → 1.42.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.
|
@@ -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
|
}
|