@trpc/upgrade 0.0.0-alpha.2 → 0.0.0-alpha.3
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 +1 -4
- package/dist/transforms/provider.cjs +9 -1
- package/package.json +1 -1
- package/src/bin/cli.ts +1 -1
- package/src/transforms/provider.ts +13 -1
package/dist/cli.cjs
CHANGED
|
@@ -66,10 +66,7 @@ const rootComamnd = cli$1.Command.make('upgrade', {
|
|
|
66
66
|
const sourceFiles = program.getSourceFiles();
|
|
67
67
|
const commitedFiles = yield* filterIgnored(sourceFiles);
|
|
68
68
|
yield* effect.Effect.forEach(transforms, (transform)=>{
|
|
69
|
-
return effect.pipe(effect.Effect.log('Running transform', transform), effect.Effect.flatMap(()=>effect.Effect.tryPromise(async ()=>import('jscodeshift/src/Runner.js').then(({ run })=>run(transform, commitedFiles,
|
|
70
|
-
...args,
|
|
71
|
-
verbose: true
|
|
72
|
-
})))), effect.Effect.map((_)=>effect.Effect.log('Transform result', _)));
|
|
69
|
+
return effect.pipe(effect.Effect.log('Running transform', transform), effect.Effect.flatMap(()=>effect.Effect.tryPromise(async ()=>import('jscodeshift/src/Runner.js').then(({ run })=>run(transform, commitedFiles, args)))), effect.Effect.map((_)=>effect.Effect.log('Transform result', _)));
|
|
73
70
|
});
|
|
74
71
|
yield* effect.Effect.log('Installing @trpc/tanstack-react-query');
|
|
75
72
|
yield* installPackage('@trpc/tanstack-react-query');
|
|
@@ -2,6 +2,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
2
2
|
|
|
3
3
|
function transform(file, api, options) {
|
|
4
4
|
const { trpcImportName } = options;
|
|
5
|
+
let routerName = undefined;
|
|
5
6
|
const j = api.jscodeshift;
|
|
6
7
|
const root = j(file.source);
|
|
7
8
|
let dirtyFlag = false;
|
|
@@ -10,6 +11,8 @@ function transform(file, api, options) {
|
|
|
10
11
|
const declaration = path.node.declarations[0];
|
|
11
12
|
if (j.Identifier.check(declaration.id) && declaration.id.name === trpcImportName) {
|
|
12
13
|
if (j.CallExpression.check(declaration.init) && j.Identifier.check(declaration.init.callee) && declaration.init.callee.name === 'createTRPCReact') {
|
|
14
|
+
// Get router name ( TODO : should probably get this from the TS compiler along with the import path)
|
|
15
|
+
routerName = declaration.init.original?.typeParameters?.params?.[0]?.typeName?.name;
|
|
13
16
|
// Replace the `createTRPCReact` call with `createTRPCContext`
|
|
14
17
|
declaration.init.callee.name = 'createTRPCContext';
|
|
15
18
|
// Destructure the result into `TRPCProvider` and `useTRPC`
|
|
@@ -46,7 +49,7 @@ function transform(file, api, options) {
|
|
|
46
49
|
});
|
|
47
50
|
});
|
|
48
51
|
}
|
|
49
|
-
// Replace trpc.createClient with createTRPCClient
|
|
52
|
+
// Replace trpc.createClient with createTRPCClient<TRouter>
|
|
50
53
|
root.find(j.CallExpression, {
|
|
51
54
|
callee: {
|
|
52
55
|
object: {
|
|
@@ -59,6 +62,11 @@ function transform(file, api, options) {
|
|
|
59
62
|
}).forEach((path)=>{
|
|
60
63
|
path.node.callee = j.identifier('createTRPCClient');
|
|
61
64
|
dirtyFlag = true;
|
|
65
|
+
if (routerName) {
|
|
66
|
+
path.node.typeParameters = j.tsTypeParameterInstantiation([
|
|
67
|
+
j.tsTypeReference(j.identifier(routerName))
|
|
68
|
+
]);
|
|
69
|
+
}
|
|
62
70
|
});
|
|
63
71
|
// Replace <trpc.Provider client={...} with <TRPCProvider trpcClient={...}
|
|
64
72
|
root.find(j.JSXElement, {
|
package/package.json
CHANGED
package/src/bin/cli.ts
CHANGED
|
@@ -159,7 +159,7 @@ const rootComamnd = CLICommand.make(
|
|
|
159
159
|
Effect.flatMap(() =>
|
|
160
160
|
Effect.tryPromise(async () =>
|
|
161
161
|
import('jscodeshift/src/Runner.js').then(({ run }) =>
|
|
162
|
-
run(transform, commitedFiles,
|
|
162
|
+
run(transform, commitedFiles, args),
|
|
163
163
|
),
|
|
164
164
|
),
|
|
165
165
|
),
|
|
@@ -10,6 +10,7 @@ export default function transform(
|
|
|
10
10
|
options: TransformOptions,
|
|
11
11
|
) {
|
|
12
12
|
const { trpcImportName } = options;
|
|
13
|
+
let routerName: string | undefined = undefined;
|
|
13
14
|
|
|
14
15
|
const j = api.jscodeshift;
|
|
15
16
|
const root = j(file.source);
|
|
@@ -27,6 +28,11 @@ export default function transform(
|
|
|
27
28
|
j.Identifier.check(declaration.init.callee) &&
|
|
28
29
|
declaration.init.callee.name === 'createTRPCReact'
|
|
29
30
|
) {
|
|
31
|
+
// Get router name ( TODO : should probably get this from the TS compiler along with the import path)
|
|
32
|
+
routerName =
|
|
33
|
+
declaration.init.original?.typeParameters?.params?.[0]?.typeName
|
|
34
|
+
?.name;
|
|
35
|
+
|
|
30
36
|
// Replace the `createTRPCReact` call with `createTRPCContext`
|
|
31
37
|
declaration.init.callee.name = 'createTRPCContext';
|
|
32
38
|
|
|
@@ -68,7 +74,7 @@ export default function transform(
|
|
|
68
74
|
});
|
|
69
75
|
}
|
|
70
76
|
|
|
71
|
-
// Replace trpc.createClient with createTRPCClient
|
|
77
|
+
// Replace trpc.createClient with createTRPCClient<TRouter>
|
|
72
78
|
root
|
|
73
79
|
.find(j.CallExpression, {
|
|
74
80
|
callee: {
|
|
@@ -79,6 +85,12 @@ export default function transform(
|
|
|
79
85
|
.forEach((path) => {
|
|
80
86
|
path.node.callee = j.identifier('createTRPCClient');
|
|
81
87
|
dirtyFlag = true;
|
|
88
|
+
|
|
89
|
+
if (routerName) {
|
|
90
|
+
(path.node as any).typeParameters = j.tsTypeParameterInstantiation([
|
|
91
|
+
j.tsTypeReference(j.identifier(routerName)),
|
|
92
|
+
]);
|
|
93
|
+
}
|
|
82
94
|
});
|
|
83
95
|
|
|
84
96
|
// Replace <trpc.Provider client={...} with <TRPCProvider trpcClient={...}
|