@trpc/upgrade 0.0.0-alpha.16 → 0.0.0-alpha.25
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/dist/cli.cjs
CHANGED
|
@@ -10,7 +10,7 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
10
10
|
|
|
11
11
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
12
12
|
|
|
13
|
-
var version = "
|
|
13
|
+
var version = "10.45.1";
|
|
14
14
|
|
|
15
15
|
const MakeCommand = (command, ...args)=>{
|
|
16
16
|
return platform.Command.make(command, ...args).pipe(platform.Command.workingDirectory(process.cwd()), platform.Command.runInShell(true));
|
|
@@ -1,6 +1,41 @@
|
|
|
1
1
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Replaces the identifier for the root path key
|
|
5
|
+
* of a member expression
|
|
6
|
+
*
|
|
7
|
+
* For dot notation like `rootKey.x.y.z` the AST
|
|
8
|
+
* is constructed with the `rootKey` being nested deep
|
|
9
|
+
* inside a wrapper MemberExpression holding `rootKey.x`
|
|
10
|
+
* and so on
|
|
11
|
+
*
|
|
12
|
+
* This function helps replace the `rootKey` identifier with
|
|
13
|
+
* the provided identifier node
|
|
14
|
+
*/ function replaceMemberExpressionRootIndentifier(j, expr, id) {
|
|
15
|
+
if (j.Identifier.check(expr.object)) {
|
|
16
|
+
expr.object = id;
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
if (j.MemberExpression.check(expr.object)) {
|
|
20
|
+
return replaceMemberExpressionRootIndentifier(j, expr.object, id);
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Walks the path upwards to look for the closest parent
|
|
27
|
+
* of the mentioned type
|
|
28
|
+
*/ function findParentOfType(path, type) {
|
|
29
|
+
if (!type.check(path.node)) {
|
|
30
|
+
return findParentOfType(path.parentPath, type);
|
|
31
|
+
}
|
|
32
|
+
if (!path.parent) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
return path;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const hookToOptions = {
|
|
4
39
|
useQuery: {
|
|
5
40
|
lib: '@tanstack/react-query',
|
|
6
41
|
fn: 'queryOptions'
|
|
@@ -155,23 +190,36 @@ function transform(file, api, options) {
|
|
|
155
190
|
name: oldIdentifier.name
|
|
156
191
|
}).forEach((path)=>{
|
|
157
192
|
if (j.MemberExpression.check(path.parent?.parent?.node)) {
|
|
158
|
-
const callExprPath = path.
|
|
193
|
+
const callExprPath = findParentOfType(path.parentPath, j.CallExpression);
|
|
194
|
+
if (!callExprPath) {
|
|
195
|
+
console.warn(`Failed to walk up the tree to find utilMethod call expression, on file: ${file.path}`, callExprPath, {
|
|
196
|
+
start: path.node.loc?.start,
|
|
197
|
+
end: path.node.loc?.end
|
|
198
|
+
});
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
159
201
|
const callExpr = callExprPath.node;
|
|
160
202
|
const memberExpr = callExpr.callee;
|
|
161
203
|
if (!j.CallExpression.check(callExpr) || !j.MemberExpression.check(memberExpr)) {
|
|
162
|
-
console.warn(
|
|
204
|
+
console.warn(`Failed to walk up the tree to find utilMethod with a \`trpc.PATH.<call>\`, on file: ${file.path}`, callExpr, {
|
|
205
|
+
start: path.node.loc?.start,
|
|
206
|
+
end: path.node.loc?.end
|
|
207
|
+
});
|
|
163
208
|
return;
|
|
164
209
|
}
|
|
165
|
-
if (!(j.MemberExpression.check(memberExpr.object) && j.Identifier.check(memberExpr.
|
|
210
|
+
if (!(j.MemberExpression.check(memberExpr.object) && j.Identifier.check(memberExpr.property) && memberExpr.property.name in utilMap)) {
|
|
166
211
|
console.warn('Failed to identify utilMethod from proxy call expression', memberExpr);
|
|
167
212
|
return;
|
|
168
213
|
}
|
|
169
214
|
// Replace util.PATH.proxyMethod() with trpc.PATH.queryFilter()
|
|
170
215
|
const proxyMethod = memberExpr.property.name;
|
|
171
|
-
|
|
216
|
+
const replacedPath = replaceMemberExpressionRootIndentifier(j, memberExpr, j.identifier(trpcImportName));
|
|
217
|
+
if (!replacedPath) {
|
|
218
|
+
console.warn('Failed to wrap proxy call expression', memberExpr);
|
|
219
|
+
}
|
|
172
220
|
memberExpr.property = j.identifier('queryFilter');
|
|
173
221
|
// Wrap it in queryClient.utilMethod()
|
|
174
|
-
|
|
222
|
+
callExprPath.replace(j.memberExpression(j.identifier('queryClient'), j.callExpression(j.identifier(utilMap[proxyMethod]), [
|
|
175
223
|
callExpr
|
|
176
224
|
])));
|
|
177
225
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trpc/upgrade",
|
|
3
|
-
"version": "0.0.0-alpha.
|
|
3
|
+
"version": "0.0.0-alpha.25",
|
|
4
4
|
"description": "Upgrade scripts for tRPC",
|
|
5
5
|
"author": "juliusmarminge",
|
|
6
6
|
"license": "MIT",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
"!**/__tests__"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@effect/cli": "0.
|
|
32
|
-
"@effect/platform": "0.
|
|
33
|
-
"@effect/platform-node": "0.
|
|
34
|
-
"effect": "3.12.
|
|
31
|
+
"@effect/cli": "0.55.0",
|
|
32
|
+
"@effect/platform": "0.76.0",
|
|
33
|
+
"@effect/platform-node": "0.72.0",
|
|
34
|
+
"effect": "3.12.11",
|
|
35
35
|
"jscodeshift": "17.1.1",
|
|
36
36
|
"typescript": "^5.6.2"
|
|
37
37
|
},
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Identifier, JSCodeshift, MemberExpression } from 'jscodeshift';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Replaces the identifier for the root path key
|
|
5
|
+
* of a member expression
|
|
6
|
+
*
|
|
7
|
+
* For dot notation like `rootKey.x.y.z` the AST
|
|
8
|
+
* is constructed with the `rootKey` being nested deep
|
|
9
|
+
* inside a wrapper MemberExpression holding `rootKey.x`
|
|
10
|
+
* and so on
|
|
11
|
+
*
|
|
12
|
+
* This function helps replace the `rootKey` identifier with
|
|
13
|
+
* the provided identifier node
|
|
14
|
+
*/
|
|
15
|
+
export function replaceMemberExpressionRootIndentifier(
|
|
16
|
+
j: JSCodeshift,
|
|
17
|
+
expr: MemberExpression,
|
|
18
|
+
id: Identifier,
|
|
19
|
+
) {
|
|
20
|
+
if (j.Identifier.check(expr.object)) {
|
|
21
|
+
expr.object = id;
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
if (j.MemberExpression.check(expr.object)) {
|
|
25
|
+
return replaceMemberExpressionRootIndentifier(j, expr.object, id);
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ASTPath, JSCodeshift } from 'jscodeshift';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Walks the path upwards to look for the closest parent
|
|
5
|
+
* of the mentioned type
|
|
6
|
+
*/
|
|
7
|
+
export function findParentOfType<TPath>(
|
|
8
|
+
path: ASTPath<unknown>,
|
|
9
|
+
type: JSCodeshift['AnyType'],
|
|
10
|
+
): ASTPath<unknown> | false {
|
|
11
|
+
if (!type.check(path.node)) {
|
|
12
|
+
return findParentOfType(path.parentPath, type);
|
|
13
|
+
}
|
|
14
|
+
if (!path.parent) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
return path as ASTPath<TPath>;
|
|
18
|
+
}
|
|
@@ -11,6 +11,8 @@ import type {
|
|
|
11
11
|
MemberExpression,
|
|
12
12
|
Options,
|
|
13
13
|
} from 'jscodeshift';
|
|
14
|
+
import { replaceMemberExpressionRootIndentifier } from '../lib/ast/modifiers';
|
|
15
|
+
import { findParentOfType } from '../lib/ast/walkers';
|
|
14
16
|
|
|
15
17
|
interface TransformOptions extends Options {
|
|
16
18
|
trpcImportName?: string;
|
|
@@ -205,7 +207,18 @@ export default function transform(
|
|
|
205
207
|
.find(j.Identifier, { name: oldIdentifier.name })
|
|
206
208
|
.forEach((path) => {
|
|
207
209
|
if (j.MemberExpression.check(path.parent?.parent?.node)) {
|
|
208
|
-
const callExprPath =
|
|
210
|
+
const callExprPath = findParentOfType<CallExpression>(
|
|
211
|
+
path.parentPath,
|
|
212
|
+
j.CallExpression,
|
|
213
|
+
);
|
|
214
|
+
if (!callExprPath) {
|
|
215
|
+
console.warn(
|
|
216
|
+
`Failed to walk up the tree to find utilMethod call expression, on file: ${file.path}`,
|
|
217
|
+
callExprPath,
|
|
218
|
+
{ start: path.node.loc?.start, end: path.node.loc?.end },
|
|
219
|
+
);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
209
222
|
const callExpr = callExprPath.node as CallExpression;
|
|
210
223
|
const memberExpr = callExpr.callee as MemberExpression;
|
|
211
224
|
if (
|
|
@@ -213,8 +226,9 @@ export default function transform(
|
|
|
213
226
|
!j.MemberExpression.check(memberExpr)
|
|
214
227
|
) {
|
|
215
228
|
console.warn(
|
|
216
|
-
|
|
229
|
+
`Failed to walk up the tree to find utilMethod with a \`trpc.PATH.<call>\`, on file: ${file.path}`,
|
|
217
230
|
callExpr,
|
|
231
|
+
{ start: path.node.loc?.start, end: path.node.loc?.end },
|
|
218
232
|
);
|
|
219
233
|
return;
|
|
220
234
|
}
|
|
@@ -222,7 +236,6 @@ export default function transform(
|
|
|
222
236
|
if (
|
|
223
237
|
!(
|
|
224
238
|
j.MemberExpression.check(memberExpr.object) &&
|
|
225
|
-
j.Identifier.check(memberExpr.object.object) &&
|
|
226
239
|
j.Identifier.check(memberExpr.property) &&
|
|
227
240
|
memberExpr.property.name in utilMap
|
|
228
241
|
)
|
|
@@ -236,11 +249,21 @@ export default function transform(
|
|
|
236
249
|
|
|
237
250
|
// Replace util.PATH.proxyMethod() with trpc.PATH.queryFilter()
|
|
238
251
|
const proxyMethod = memberExpr.property.name as ProxyMethod;
|
|
239
|
-
|
|
252
|
+
const replacedPath = replaceMemberExpressionRootIndentifier(
|
|
253
|
+
j,
|
|
254
|
+
memberExpr,
|
|
255
|
+
j.identifier(trpcImportName!),
|
|
256
|
+
);
|
|
257
|
+
if (!replacedPath) {
|
|
258
|
+
console.warn(
|
|
259
|
+
'Failed to wrap proxy call expression',
|
|
260
|
+
memberExpr,
|
|
261
|
+
);
|
|
262
|
+
}
|
|
240
263
|
memberExpr.property = j.identifier('queryFilter');
|
|
241
264
|
|
|
242
265
|
// Wrap it in queryClient.utilMethod()
|
|
243
|
-
|
|
266
|
+
callExprPath.replace(
|
|
244
267
|
j.memberExpression(
|
|
245
268
|
j.identifier('queryClient'),
|
|
246
269
|
j.callExpression(j.identifier(utilMap[proxyMethod]), [
|