@trpc/upgrade 0.0.0-alpha.2 → 0.0.0-alpha.4

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 = "0.0.0-alpha.2";
13
+ var version = "0.0.0-alpha.4";
14
14
 
15
15
  const assertCleanGitTree = platform.Command.string(platform.Command.make('git', 'status')).pipe(effect.Effect.filterOrFail(effect.String.includes('nothing to commit'), ()=>'Git tree is not clean, please commit your changes and try again, or run with `--force`'));
16
16
  const installPackage = (packageName)=>{
@@ -19,13 +19,13 @@ const installPackage = (packageName)=>{
19
19
  };
20
20
  const filterIgnored = (files)=>effect.Effect.gen(function*() {
21
21
  const ignores = yield* platform.Command.string(platform.Command.make('git', 'check-ignore', '**/*')).pipe(effect.Effect.map((_)=>_.split('\n')));
22
- yield* effect.Effect.log('All files in program:', files.map((_)=>_.fileName));
23
- yield* effect.Effect.log('Ignored files:', ignores);
22
+ yield* effect.Effect.logDebug('All files in program:', files.map((_)=>_.fileName));
23
+ yield* effect.Effect.logDebug('Ignored files:', ignores);
24
24
  // Ignore "common files"
25
25
  const filteredSourcePaths = files.filter((source)=>source.fileName.startsWith(path__default.default.resolve()) && // only look ahead of current directory
26
26
  !source.fileName.includes('/trpc/packages/') && // relative paths when running codemod locally
27
27
  !ignores.includes(source.fileName)).map((source)=>source.fileName);
28
- yield* effect.Effect.log('Filtered files:', filteredSourcePaths);
28
+ yield* effect.Effect.logDebug('Filtered files:', filteredSourcePaths);
29
29
  return filteredSourcePaths;
30
30
  });
31
31
  const TSProgram = effect.Effect.succeed(typescript.findConfigFile(process.cwd(), typescript.sys.fileExists)).pipe(effect.Effect.filterOrFail(effect.Predicate.isNotNullable, ()=>'No tsconfig found'), effect.Effect.tap((_)=>effect.Effect.logDebug('Using tsconfig', _)), effect.Effect.map((_)=>typescript.readConfigFile(_, typescript.sys.readFile)), effect.Effect.map((_)=>typescript.parseJsonConfigFileContent(_.config, typescript.sys, process.cwd())), effect.Effect.map((_)=>typescript.createProgram({
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/upgrade",
3
- "version": "0.0.0-alpha.2",
3
+ "version": "0.0.0-alpha.4",
4
4
  "description": "Upgrade scripts for tRPC",
5
5
  "author": "juliusmarminge",
6
6
  "license": "MIT",
package/src/bin/cli.ts CHANGED
@@ -52,11 +52,11 @@ const filterIgnored = (files: readonly SourceFile[]) =>
52
52
  Command.make('git', 'check-ignore', '**/*'),
53
53
  ).pipe(Effect.map((_) => _.split('\n')));
54
54
 
55
- yield* Effect.log(
55
+ yield* Effect.logDebug(
56
56
  'All files in program:',
57
57
  files.map((_) => _.fileName),
58
58
  );
59
- yield* Effect.log('Ignored files:', ignores);
59
+ yield* Effect.logDebug('Ignored files:', ignores);
60
60
 
61
61
  // Ignore "common files"
62
62
  const filteredSourcePaths = files
@@ -68,7 +68,7 @@ const filterIgnored = (files: readonly SourceFile[]) =>
68
68
  )
69
69
  .map((source) => source.fileName);
70
70
 
71
- yield* Effect.log('Filtered files:', filteredSourcePaths);
71
+ yield* Effect.logDebug('Filtered files:', filteredSourcePaths);
72
72
 
73
73
  return filteredSourcePaths;
74
74
  });
@@ -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, { ...args, verbose: true }),
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={...}