@comet/upgrade 1.26.0 → 1.28.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/README.md
CHANGED
|
@@ -39,17 +39,10 @@ npx @comet/upgrade v7/hide-graphql-field-suggestions.ts
|
|
|
39
39
|
cd project-you-want-to-upgrade/
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
Run the upgrade script. Replace `<path-to-comet-upgrade-repository>` with the location of the cloned comet-upgrade repository (e.g., `../comet-upgrade/`):
|
|
43
43
|
|
|
44
44
|
```sh
|
|
45
|
-
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
Execute the local @comet/upgrade binary:
|
|
49
|
-
|
|
50
|
-
```sh
|
|
51
|
-
../comet-upgrade/bin/index.js 4 # comet-upgrade directory
|
|
52
|
-
|
|
45
|
+
<path-to-comet-upgrade-repository>/bin/index.js v4/change-something.ts
|
|
53
46
|
```
|
|
54
47
|
|
|
55
48
|
Verify the changes in your project. If something is not as expected, adapt the upgrade script accordingly and then run it again on a clean state:
|
|
@@ -57,5 +50,5 @@ npx @comet/upgrade v7/hide-graphql-field-suggestions.ts
|
|
|
57
50
|
```sh
|
|
58
51
|
git reset --hard HEAD
|
|
59
52
|
|
|
60
|
-
|
|
53
|
+
<path-to-comet-upgrade-repository>/bin/index.js v4/change-something.ts
|
|
61
54
|
```
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const fs_1 = require("fs");
|
|
4
|
+
const ts_morph_1 = require("ts-morph");
|
|
5
|
+
/**
|
|
6
|
+
* Removes the GraphQL client/fetch from the site preview handlers
|
|
7
|
+
*
|
|
8
|
+
* App Router: `sitePreviewRoute(request, createGraphQLFetch())` -> `sitePreviewRoute(request)`
|
|
9
|
+
* Pages Router: `legacyPagesRouterSitePreviewApiHandler(req, res, createGraphQLClient())` -> `legacyPagesRouterSitePreviewApiHandler(req, res)`
|
|
10
|
+
*/
|
|
11
|
+
async function removeGraphQLClientFromSitePreviewHandlers() {
|
|
12
|
+
const project = new ts_morph_1.Project({ tsConfigFilePath: "./site/tsconfig.json" });
|
|
13
|
+
// App Router
|
|
14
|
+
if ((0, fs_1.existsSync)("site/src/app/api/site-preview/route.ts")) {
|
|
15
|
+
const sourceFile = project.getSourceFile("site/src/app/api/site-preview/route.ts");
|
|
16
|
+
if (!sourceFile) {
|
|
17
|
+
throw new Error("Can't get source file for site/src/app/api/site-preview/route.ts");
|
|
18
|
+
}
|
|
19
|
+
const getFunction = sourceFile.getFunction("GET");
|
|
20
|
+
if (getFunction) {
|
|
21
|
+
const callExpression = getFunction.getFirstDescendantByKind(ts_morph_1.SyntaxKind.CallExpression);
|
|
22
|
+
if (callExpression) {
|
|
23
|
+
callExpression.removeArgument(1);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
await sourceFile.save();
|
|
27
|
+
}
|
|
28
|
+
// Pages Router
|
|
29
|
+
let pagesRouterApiRouteFile;
|
|
30
|
+
if ((0, fs_1.existsSync)("site/src/pages/api/site-preview.page.ts")) {
|
|
31
|
+
pagesRouterApiRouteFile = "site/src/pages/api/site-preview.page.ts";
|
|
32
|
+
}
|
|
33
|
+
else if ((0, fs_1.existsSync)("site/src/pages/api/site-preview.ts")) {
|
|
34
|
+
// Projects without .page.ts extension
|
|
35
|
+
pagesRouterApiRouteFile = "site/src/pages/api/site-preview.ts";
|
|
36
|
+
}
|
|
37
|
+
if (pagesRouterApiRouteFile) {
|
|
38
|
+
const sourceFile = project.getSourceFile(pagesRouterApiRouteFile);
|
|
39
|
+
if (!sourceFile) {
|
|
40
|
+
throw new Error(`Can't get source file for ${pagesRouterApiRouteFile}`);
|
|
41
|
+
}
|
|
42
|
+
const callExpression = sourceFile.getFirstDescendantByKind(ts_morph_1.SyntaxKind.CallExpression);
|
|
43
|
+
if (callExpression) {
|
|
44
|
+
callExpression.removeArgument(2);
|
|
45
|
+
}
|
|
46
|
+
await sourceFile.save();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.default = removeGraphQLClientFromSitePreviewHandlers;
|