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

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
@@ -2,6 +2,9 @@ run locally with source files
2
2
 
3
3
  ```sh
4
4
  DEV=1 pnpx tsx path/to/cli.ts
5
+
6
+ # example
7
+ cd examples/minimal-react/client && DEV=1 pnpx tsx ../../../packages/upgrade/src/bin/cli.ts --force --skipTanstackQuery --verbose
5
8
  ```
6
9
 
7
10
  or compiled
package/dist/cli.cjs CHANGED
@@ -13,10 +13,16 @@ var path__default = /*#__PURE__*/_interopDefault(path);
13
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
+ const getPackageManager = ()=>effect.Match.value(process.env.npm_config_user_agent ?? 'npm').pipe(effect.Match.when(effect.String.startsWith('pnpm'), ()=>'pnpm'), effect.Match.when(effect.String.startsWith('yarn'), ()=>'yarn'), effect.Match.when(effect.String.startsWith('bun'), ()=>'bun'), effect.Match.orElse(()=>'npm'));
16
17
  const installPackage = (packageName)=>{
17
- const packageManager = effect.Match.value(process.env.npm_config_user_agent ?? 'npm').pipe(effect.Match.when(effect.String.startsWith('pnpm'), ()=>'pnpm'), effect.Match.when(effect.String.startsWith('yarn'), ()=>'yarn'), effect.Match.when(effect.String.startsWith('bun'), ()=>'bun'), effect.Match.orElse(()=>'npm'));
18
+ const packageManager = getPackageManager();
18
19
  return platform.Command.streamLines(platform.Command.make(packageManager, 'install', packageName)).pipe(effect.Stream.mapEffect(effect.Console.log), effect.Stream.runDrain);
19
20
  };
21
+ const uninstallPackage = (packageName)=>{
22
+ const packageManager = getPackageManager();
23
+ const uninstallCmd = packageManager === 'yarn' ? 'remove' : 'uninstall';
24
+ return platform.Command.streamLines(platform.Command.make(packageManager, uninstallCmd, packageName)).pipe(effect.Stream.mapEffect(effect.Console.log), effect.Stream.runDrain);
25
+ };
20
26
  const filterIgnored = (files)=>effect.Effect.gen(function*() {
21
27
  const ignores = yield* platform.Command.string(platform.Command.make('git', 'check-ignore', '**/*')).pipe(effect.Effect.map((_)=>_.split('\n')));
22
28
  yield* effect.Effect.logDebug('All files in program:', files.map((_)=>_.fileName));
@@ -40,15 +46,22 @@ const force = cli$1.Options.boolean('force').pipe(cli$1.Options.withAlias('f'),
40
46
  * TODO: Instead of default values these should be detected automatically from the TS program
41
47
  */ const trpcFile = cli$1.Options.text('trpcFile').pipe(cli$1.Options.withAlias('f'), cli$1.Options.withDefault('~/trpc'), cli$1.Options.withDescription('Path to the trpc import file'));
42
48
  const trpcImportName = cli$1.Options.text('trpcImportName').pipe(cli$1.Options.withAlias('i'), cli$1.Options.withDefault('trpc'), cli$1.Options.withDescription('Name of the trpc import'));
49
+ const skipTanstackQuery = cli$1.Options.boolean('skipTanstackQuery').pipe(cli$1.Options.withAlias('q'), cli$1.Options.withDefault(false), cli$1.Options.withDescription('Skip installing @trpc/tanstack-react-query package'));
50
+ const verbose = cli$1.Options.boolean('verbose').pipe(cli$1.Options.withAlias('v'), cli$1.Options.withDefault(false), cli$1.Options.withDescription('Enable verbose logging'));
43
51
  const rootComamnd = cli$1.Command.make('upgrade', {
44
52
  force,
45
53
  trpcFile,
46
- trpcImportName
54
+ trpcImportName,
55
+ skipTanstackQuery,
56
+ verbose
47
57
  }, (args)=>effect.Effect.gen(function*() {
58
+ if (args.verbose) {
59
+ yield* effect.Effect.log('Running upgrade with args:', args);
60
+ }
48
61
  if (!args.force) {
49
62
  yield* assertCleanGitTree;
50
63
  }
51
- const transforms = yield* effect.Effect.map(cli$1.Prompt.multiSelect({
64
+ const transforms = yield* effect.pipe(cli$1.Prompt.multiSelect({
52
65
  message: 'Select transforms to run',
53
66
  choices: [
54
67
  {
@@ -60,16 +73,25 @@ const rootComamnd = cli$1.Command.make('upgrade', {
60
73
  value: require.resolve(transformPath('../transforms/provider.ts'))
61
74
  }
62
75
  ]
63
- }), // Make sure provider transform runs first if it's selected
64
- effect.Array.sortWith((a)=>!a.includes('provider.ts'), effect.Order.boolean));
76
+ }), effect.Effect.flatMap((selected)=>{
77
+ if (selected.length === 0) {
78
+ return effect.Effect.fail(new Error('Please select at least one transform to run'));
79
+ }
80
+ return effect.Effect.succeed(selected);
81
+ }), effect.Effect.map(// Make sure provider transform runs first if it's selected
82
+ effect.Array.sortWith((a)=>!a.includes('provider.ts'), effect.Order.boolean)));
65
83
  const program = yield* TSProgram;
66
84
  const sourceFiles = program.getSourceFiles();
67
85
  const commitedFiles = yield* filterIgnored(sourceFiles);
68
86
  yield* effect.Effect.forEach(transforms, (transform)=>{
69
87
  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', _)));
70
88
  });
71
- yield* effect.Effect.log('Installing @trpc/tanstack-react-query');
72
- yield* installPackage('@trpc/tanstack-react-query');
89
+ if (!args.skipTanstackQuery) {
90
+ yield* effect.Effect.log('Installing @trpc/tanstack-react-query');
91
+ yield* installPackage('@trpc/tanstack-react-query');
92
+ yield* effect.Effect.log('Uninstalling @trpc/react-query');
93
+ yield* uninstallPackage('@trpc/react-query');
94
+ }
73
95
  }));
74
96
  const cli = cli$1.Command.run(rootComamnd, {
75
97
  name: 'tRPC Upgrade CLI',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/upgrade",
3
- "version": "0.0.0-alpha.4",
3
+ "version": "0.0.0-alpha.5",
4
4
  "description": "Upgrade scripts for tRPC",
5
5
  "author": "juliusmarminge",
6
6
  "license": "MIT",
package/src/bin/cli.ts CHANGED
@@ -31,21 +31,29 @@ const assertCleanGitTree = Command.string(Command.make('git', 'status')).pipe(
31
31
  'Git tree is not clean, please commit your changes and try again, or run with `--force`',
32
32
  ),
33
33
  );
34
-
35
- const installPackage = (packageName: string) => {
36
- const packageManager = Match.value(
37
- process.env.npm_config_user_agent ?? 'npm',
38
- ).pipe(
34
+ const getPackageManager = () =>
35
+ Match.value(process.env.npm_config_user_agent ?? 'npm').pipe(
39
36
  Match.when(String.startsWith('pnpm'), () => 'pnpm'),
40
37
  Match.when(String.startsWith('yarn'), () => 'yarn'),
41
38
  Match.when(String.startsWith('bun'), () => 'bun'),
42
39
  Match.orElse(() => 'npm'),
43
40
  );
41
+
42
+ const installPackage = (packageName: string) => {
43
+ const packageManager = getPackageManager();
44
44
  return Command.streamLines(
45
45
  Command.make(packageManager, 'install', packageName),
46
46
  ).pipe(Stream.mapEffect(Console.log), Stream.runDrain);
47
47
  };
48
48
 
49
+ const uninstallPackage = (packageName: string) => {
50
+ const packageManager = getPackageManager();
51
+ const uninstallCmd = packageManager === 'yarn' ? 'remove' : 'uninstall';
52
+ return Command.streamLines(
53
+ Command.make(packageManager, uninstallCmd, packageName),
54
+ ).pipe(Stream.mapEffect(Console.log), Stream.runDrain);
55
+ };
56
+
49
57
  const filterIgnored = (files: readonly SourceFile[]) =>
50
58
  Effect.gen(function* () {
51
59
  const ignores = yield* Command.string(
@@ -114,20 +122,36 @@ const trpcImportName = Options.text('trpcImportName').pipe(
114
122
  Options.withDescription('Name of the trpc import'),
115
123
  );
116
124
 
125
+ const skipTanstackQuery = Options.boolean('skipTanstackQuery').pipe(
126
+ Options.withAlias('q'),
127
+ Options.withDefault(false),
128
+ Options.withDescription('Skip installing @trpc/tanstack-react-query package'),
129
+ );
130
+
131
+ const verbose = Options.boolean('verbose').pipe(
132
+ Options.withAlias('v'),
133
+ Options.withDefault(false),
134
+ Options.withDescription('Enable verbose logging'),
135
+ );
136
+
117
137
  const rootComamnd = CLICommand.make(
118
138
  'upgrade',
119
139
  {
120
140
  force,
121
141
  trpcFile,
122
142
  trpcImportName,
143
+ skipTanstackQuery,
144
+ verbose,
123
145
  },
124
146
  (args) =>
125
147
  Effect.gen(function* () {
148
+ if (args.verbose) {
149
+ yield* Effect.log('Running upgrade with args:', args);
150
+ }
126
151
  if (!args.force) {
127
152
  yield* assertCleanGitTree;
128
153
  }
129
-
130
- const transforms = yield* Effect.map(
154
+ const transforms = yield* pipe(
131
155
  Prompt.multiSelect({
132
156
  message: 'Select transforms to run',
133
157
  choices: [
@@ -145,8 +169,18 @@ const rootComamnd = CLICommand.make(
145
169
  },
146
170
  ],
147
171
  }),
148
- // Make sure provider transform runs first if it's selected
149
- Array.sortWith((a) => !a.includes('provider.ts'), Order.boolean),
172
+ Effect.flatMap((selected) => {
173
+ if (selected.length === 0) {
174
+ return Effect.fail(
175
+ new Error('Please select at least one transform to run'),
176
+ );
177
+ }
178
+ return Effect.succeed(selected);
179
+ }),
180
+ Effect.map(
181
+ // Make sure provider transform runs first if it's selected
182
+ Array.sortWith((a) => !a.includes('provider.ts'), Order.boolean),
183
+ ),
150
184
  );
151
185
 
152
186
  const program = yield* TSProgram;
@@ -167,8 +201,13 @@ const rootComamnd = CLICommand.make(
167
201
  );
168
202
  });
169
203
 
170
- yield* Effect.log('Installing @trpc/tanstack-react-query');
171
- yield* installPackage('@trpc/tanstack-react-query');
204
+ if (!args.skipTanstackQuery) {
205
+ yield* Effect.log('Installing @trpc/tanstack-react-query');
206
+ yield* installPackage('@trpc/tanstack-react-query');
207
+
208
+ yield* Effect.log('Uninstalling @trpc/react-query');
209
+ yield* uninstallPackage('@trpc/react-query');
210
+ }
172
211
  }),
173
212
  );
174
213