@trpc/upgrade 11.18.1-canary.9 → 11.19.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/dist/bin.d.mts +1 -0
- package/dist/{bin.js → bin.mjs} +16 -25
- package/dist/bin.mjs.map +1 -0
- package/dist/transforms/hooksToOptions.cjs +21 -22
- package/dist/transforms/hooksToOptions.d.cts +9 -0
- package/dist/transforms/hooksToOptions.d.cts.map +1 -0
- package/dist/transforms/provider.cjs +5 -4
- package/dist/transforms/provider.d.cts +9 -0
- package/dist/transforms/provider.d.cts.map +1 -0
- package/package.json +9 -9
- package/src/transforms/hooksToOptions.ts +4 -6
package/dist/bin.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
package/dist/{bin.js → bin.mjs}
RENAMED
|
@@ -8,14 +8,11 @@ import * as ts from "typescript";
|
|
|
8
8
|
import { resolve } from "path";
|
|
9
9
|
import { exec } from "node:child_process";
|
|
10
10
|
import { promisify } from "node:util";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
14
|
-
|
|
11
|
+
//#region \0rolldown/runtime.js
|
|
12
|
+
var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
|
|
15
13
|
//#endregion
|
|
16
14
|
//#region package.json
|
|
17
|
-
var version = "11.
|
|
18
|
-
|
|
15
|
+
var version = "11.19.0";
|
|
19
16
|
//#endregion
|
|
20
17
|
//#region src/lib/ast/scanners.ts
|
|
21
18
|
function getProgram() {
|
|
@@ -27,15 +24,14 @@ function getProgram() {
|
|
|
27
24
|
if (process.env["VERBOSE"]) p.log.info(`Using tsconfig: ${configFile}`);
|
|
28
25
|
const { config } = ts.readConfigFile(configFile, (filepath) => ts.sys.readFile(filepath));
|
|
29
26
|
const parsedConfig = ts.parseJsonConfigFileContent(config, ts.sys, process.cwd());
|
|
30
|
-
|
|
27
|
+
return ts.createProgram({
|
|
31
28
|
options: parsedConfig.options,
|
|
32
29
|
rootNames: parsedConfig.fileNames,
|
|
33
30
|
configFileParsingDiagnostics: parsedConfig.errors
|
|
34
31
|
});
|
|
35
|
-
return program$1;
|
|
36
32
|
}
|
|
37
|
-
function findSourceAndImportName(program
|
|
38
|
-
const files = program
|
|
33
|
+
function findSourceAndImportName(program) {
|
|
34
|
+
const files = program.getSourceFiles().filter((sourceFile) => {
|
|
39
35
|
if (sourceFile.isDeclarationFile) return false;
|
|
40
36
|
let found = false;
|
|
41
37
|
ts.forEachChild(sourceFile, (node) => {
|
|
@@ -59,14 +55,14 @@ function findSourceAndImportName(program$1) {
|
|
|
59
55
|
importName
|
|
60
56
|
};
|
|
61
57
|
}
|
|
62
|
-
function findTRPCImportReferences(program
|
|
63
|
-
const { files: filesImportingTRPC, importName } = findSourceAndImportName(program
|
|
58
|
+
function findTRPCImportReferences(program) {
|
|
59
|
+
const { files: filesImportingTRPC, importName } = findSourceAndImportName(program);
|
|
64
60
|
const trpcReferenceSpecifiers = /* @__PURE__ */ new Map();
|
|
65
|
-
program
|
|
61
|
+
program.getSourceFiles().forEach((sourceFile) => {
|
|
66
62
|
if (sourceFile.isDeclarationFile) return;
|
|
67
63
|
ts.forEachChild(sourceFile, (node) => {
|
|
68
64
|
if (ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier)) {
|
|
69
|
-
const resolved = ts.resolveModuleName(node.moduleSpecifier.text, sourceFile.fileName, program
|
|
65
|
+
const resolved = ts.resolveModuleName(node.moduleSpecifier.text, sourceFile.fileName, program.getCompilerOptions(), ts.sys);
|
|
70
66
|
if (resolved.resolvedModule && filesImportingTRPC.includes(resolved.resolvedModule.resolvedFileName)) trpcReferenceSpecifiers.set(resolved.resolvedModule.resolvedFileName, node.moduleSpecifier.text);
|
|
71
67
|
}
|
|
72
68
|
});
|
|
@@ -87,11 +83,9 @@ function findTRPCImportReferences(program$1) {
|
|
|
87
83
|
all: Object.fromEntries(trpcReferenceSpecifiers.entries())
|
|
88
84
|
};
|
|
89
85
|
}
|
|
90
|
-
|
|
91
86
|
//#endregion
|
|
92
87
|
//#region src/lib/execa.ts
|
|
93
88
|
const execa = promisify(exec);
|
|
94
|
-
|
|
95
89
|
//#endregion
|
|
96
90
|
//#region src/lib/git.ts
|
|
97
91
|
async function assertCleanGitTree() {
|
|
@@ -103,11 +97,10 @@ async function assertCleanGitTree() {
|
|
|
103
97
|
}
|
|
104
98
|
async function filterIgnored(files) {
|
|
105
99
|
let stdout = "";
|
|
106
|
-
let stderr = "";
|
|
107
100
|
try {
|
|
108
101
|
const result = await execa("git check-ignore **/*");
|
|
109
102
|
stdout = result.stdout;
|
|
110
|
-
|
|
103
|
+
result.stderr;
|
|
111
104
|
} catch (error) {
|
|
112
105
|
log.error("Error executing git check-ignore:", error);
|
|
113
106
|
stdout = "";
|
|
@@ -122,7 +115,6 @@ async function filterIgnored(files) {
|
|
|
122
115
|
if (process.env["VERBOSE"]) log.info(`Filtered files: ${filteredSourcePaths.join(", ")}`);
|
|
123
116
|
return filteredSourcePaths;
|
|
124
117
|
}
|
|
125
|
-
|
|
126
118
|
//#endregion
|
|
127
119
|
//#region src/lib/pkgmgr.ts
|
|
128
120
|
function getPackageManager() {
|
|
@@ -134,19 +126,16 @@ function getPackageManager() {
|
|
|
134
126
|
}
|
|
135
127
|
async function installPackage(packageName) {
|
|
136
128
|
const packageManager = getPackageManager();
|
|
137
|
-
const
|
|
138
|
-
const { stdout, stderr } = await execa(`${packageManager} ${installCmd} ${packageName}`);
|
|
129
|
+
const { stdout, stderr } = await execa(`${packageManager} ${packageManager === "yarn" ? "add" : "install"} ${packageName}`);
|
|
139
130
|
if (stderr) log.error(stderr);
|
|
140
131
|
if (process.env["VERBOSE"]) log.info(stdout);
|
|
141
132
|
}
|
|
142
133
|
async function uninstallPackage(packageName) {
|
|
143
134
|
const packageManager = getPackageManager();
|
|
144
|
-
const
|
|
145
|
-
const { stdout, stderr } = await execa(`${packageManager} ${uninstallCmd} ${packageName}`);
|
|
135
|
+
const { stdout, stderr } = await execa(`${packageManager} ${packageManager === "yarn" ? "remove" : "uninstall"} ${packageName}`);
|
|
146
136
|
if (stderr) log.error(stderr);
|
|
147
137
|
if (process.env["VERBOSE"]) log.info(stdout);
|
|
148
138
|
}
|
|
149
|
-
|
|
150
139
|
//#endregion
|
|
151
140
|
//#region src/bin/index.ts
|
|
152
141
|
const args = parse(process.argv.slice(2), {
|
|
@@ -216,5 +205,7 @@ if (!args.skipTanstackQuery) {
|
|
|
216
205
|
log.success("@trpc/react-query uninstalled");
|
|
217
206
|
}
|
|
218
207
|
outro("Upgrade complete! 🎉");
|
|
208
|
+
//#endregion
|
|
209
|
+
export {};
|
|
219
210
|
|
|
220
|
-
//#
|
|
211
|
+
//# sourceMappingURL=bin.mjs.map
|
package/dist/bin.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.mjs","names":[],"sources":["../package.json","../src/lib/ast/scanners.ts","../src/lib/execa.ts","../src/lib/git.ts","../src/lib/pkgmgr.ts","../src/bin/index.ts"],"sourcesContent":["","import * as p from '@clack/prompts';\nimport * as ts from 'typescript';\n\nexport function getProgram() {\n const configFile = ts.findConfigFile(process.cwd(), (filepath) =>\n ts.sys.fileExists(filepath),\n );\n if (!configFile) {\n p.log.error('No tsconfig found');\n process.exit(1);\n }\n\n if (process.env['VERBOSE']) {\n p.log.info(`Using tsconfig: ${configFile}`);\n }\n\n const { config } = ts.readConfigFile(configFile, (filepath) =>\n ts.sys.readFile(filepath),\n );\n const parsedConfig = ts.parseJsonConfigFileContent(\n config,\n ts.sys,\n process.cwd(),\n );\n const program = ts.createProgram({\n options: parsedConfig.options,\n rootNames: parsedConfig.fileNames,\n configFileParsingDiagnostics: parsedConfig.errors,\n });\n\n return program;\n}\n\nexport function findSourceAndImportName(program: ts.Program) {\n const files = program.getSourceFiles().filter((sourceFile) => {\n if (sourceFile.isDeclarationFile) return false;\n let found = false;\n ts.forEachChild(sourceFile, (node) => {\n if (!found && ts.isImportDeclaration(node)) {\n const { moduleSpecifier } = node;\n if (\n ts.isStringLiteral(moduleSpecifier) &&\n moduleSpecifier.text.includes('@trpc/react-query')\n ) {\n found = true;\n }\n }\n });\n return found;\n });\n\n let importName = 'trpc';\n files.forEach((sourceFile) => {\n ts.forEachChild(sourceFile, (node) => {\n if (\n ts.isVariableStatement(node) &&\n node.modifiers?.some((mod) => mod.getText(sourceFile) === 'export')\n ) {\n node.declarationList.declarations.forEach((declaration) => {\n if (\n ts.isVariableDeclaration(declaration) &&\n declaration.initializer &&\n ts.isCallExpression(declaration.initializer) &&\n ts.isIdentifier(declaration.initializer.expression) &&\n declaration.initializer.expression.getText(sourceFile) ===\n 'createTRPCReact'\n ) {\n importName = declaration.name.getText(sourceFile);\n }\n });\n }\n });\n });\n\n return {\n files: files.map((d) => d.fileName),\n importName,\n };\n}\n\nexport function findTRPCImportReferences(program: ts.Program) {\n const { files: filesImportingTRPC, importName } =\n findSourceAndImportName(program);\n const trpcReferenceSpecifiers = new Map<string, string>();\n\n program.getSourceFiles().forEach((sourceFile) => {\n if (sourceFile.isDeclarationFile) return;\n ts.forEachChild(sourceFile, (node) => {\n if (\n ts.isImportDeclaration(node) &&\n ts.isStringLiteral(node.moduleSpecifier)\n ) {\n const resolved = ts.resolveModuleName(\n node.moduleSpecifier.text,\n sourceFile.fileName,\n program.getCompilerOptions(),\n ts.sys,\n );\n if (\n resolved.resolvedModule &&\n filesImportingTRPC.includes(resolved.resolvedModule.resolvedFileName)\n ) {\n trpcReferenceSpecifiers.set(\n resolved.resolvedModule.resolvedFileName,\n node.moduleSpecifier.text,\n );\n }\n }\n });\n });\n\n const counts: Record<string, number> = {};\n let currentMax = 0;\n const mostUsed = { file: '' };\n\n [...trpcReferenceSpecifiers.values()].forEach((specifier) => {\n counts[specifier] = (counts[specifier] ?? 0) + 1;\n if (counts[specifier] > currentMax) {\n currentMax = counts[specifier];\n mostUsed.file = specifier;\n }\n });\n\n return {\n importName,\n mostUsed,\n all: Object.fromEntries(trpcReferenceSpecifiers.entries()),\n };\n}\n","import { exec } from 'node:child_process';\nimport { promisify } from 'node:util';\n\nexport const execa = promisify(exec);\n","import { resolve } from 'path';\nimport { cancel, log } from '@clack/prompts';\nimport type { SourceFile } from 'typescript';\nimport { execa } from './execa';\n\nexport async function assertCleanGitTree() {\n const { stdout } = await execa('git status');\n if (!stdout.includes('nothing to commit')) {\n cancel(\n 'Git tree is not clean, please commit your changes and try again, or run with `--force`',\n );\n process.exit(1);\n }\n}\n\nexport async function filterIgnored(files: readonly SourceFile[]) {\n let stdout = '';\n let stderr = '';\n try {\n const result = await execa('git check-ignore **/*');\n stdout = result.stdout;\n stderr = result.stderr;\n } catch (error) {\n log.error('Error executing git check-ignore:', error);\n stdout = '';\n }\n\n const ignores = stdout.split('\\n');\n\n if (process.env['VERBOSE']) {\n log.info(`cwd: ${process.cwd()}`);\n log.info(\n `All files in program: ${files.map((file) => file.fileName).join(', ')}`,\n );\n log.info(`Ignored files: ${ignores.join(', ')}`);\n }\n\n // Ignore \"common files\"\n const filteredSourcePaths = files\n .filter(\n (source) =>\n source.fileName.startsWith(resolve()) && // only look ahead of current directory\n !source.fileName.includes('/trpc/packages/') && // relative paths when running codemod locally\n !source.fileName.includes('/node_modules/') && // always ignore node_modules\n !ignores.includes(source.fileName), // ignored files\n )\n .map((source) => source.fileName);\n\n if (process.env['VERBOSE']) {\n log.info(`Filtered files: ${filteredSourcePaths.join(', ')}`);\n }\n\n return filteredSourcePaths;\n}\n","import { log } from '@clack/prompts';\nimport { execa } from './execa';\n\nfunction getPackageManager() {\n const userAgent = process.env['npm_config_user_agent'];\n if (userAgent?.startsWith('pnpm')) return 'pnpm';\n if (userAgent?.startsWith('yarn')) return 'yarn';\n if (userAgent?.startsWith('bun')) return 'bun';\n return 'npm';\n}\n\nexport async function installPackage(packageName: string) {\n const packageManager = getPackageManager();\n const installCmd = packageManager === 'yarn' ? 'add' : 'install';\n const { stdout, stderr } = await execa(\n `${packageManager} ${installCmd} ${packageName}`,\n );\n if (stderr) {\n log.error(stderr);\n }\n if (process.env['VERBOSE']) {\n log.info(stdout);\n }\n}\n\nexport async function uninstallPackage(packageName: string) {\n const packageManager = getPackageManager();\n const uninstallCmd = packageManager === 'yarn' ? 'remove' : 'uninstall';\n const { stdout, stderr } = await execa(\n `${packageManager} ${uninstallCmd} ${packageName}`,\n );\n if (stderr) {\n log.error(stderr);\n }\n if (process.env['VERBOSE']) {\n log.info(stdout);\n }\n}\n","#!/usr/bin/env node\nimport { basename, extname } from 'node:path';\nimport { parse } from '@bomb.sh/args';\nimport { intro, isCancel, log, multiselect, outro } from '@clack/prompts';\nimport { version } from '../../package.json';\nimport { findTRPCImportReferences, getProgram } from '../lib/ast/scanners';\nimport { assertCleanGitTree, filterIgnored } from '../lib/git';\nimport { installPackage, uninstallPackage } from '../lib/pkgmgr';\n\nconst args = parse(process.argv.slice(2), {\n default: {\n force: false,\n skipTanstackQuery: false,\n verbose: false,\n },\n alias: {\n f: 'force',\n h: 'help',\n v: 'verbose',\n q: 'skipTanstackQuery',\n },\n boolean: true,\n});\nif (args.verbose) process.env['VERBOSE'] = '1';\n\nintro(`tRPC Upgrade CLI v${version}`);\n\nif (args['help']) {\n log.info(\n `\nUsage: upgrade [options]\n\nOptions:\n -f, --force Skip git status check, use with caution\n -q, --skipTanstackQuery Skip installing @trpc/tanstack-react-query package\n -v, --verbose Enable verbose logging\n -h, --help Show help\n `.trim(),\n );\n process.exit(0);\n}\n\nif (args.verbose) {\n log.info(`Running upgrade with args: ${JSON.stringify(args, null, 2)}`);\n}\n\nif (!args.force) {\n await assertCleanGitTree();\n}\n\nconst transforms = await multiselect({\n message: 'Select transforms to run',\n options: [\n {\n value: require.resolve('@trpc/upgrade/transforms/hooksToOptions'),\n label: 'Migrate Hooks to xxxOptions API',\n },\n {\n value: require.resolve('@trpc/upgrade/transforms/provider'),\n label: 'Migrate context provider setup',\n },\n ],\n});\nif (isCancel(transforms)) process.exit(0);\n\n// Make sure provider transform runs first if it's selected\nconst sortedTransforms = transforms.sort((a) =>\n a.includes('provider') ? -1 : 1,\n);\n\nconst program = getProgram();\nconst sourceFiles = program.getSourceFiles();\nconst possibleReferences = findTRPCImportReferences(program);\nconst trpcFile = possibleReferences.mostUsed.file;\nconst trpcImportName = possibleReferences.importName;\n\nconst committedFiles = await filterIgnored(sourceFiles);\n\nfor (const transform of sortedTransforms) {\n log.step(`Running transform: ${basename(transform, extname(transform))}`);\n const { run } = await import('jscodeshift/src/Runner.js');\n await run(transform, committedFiles, {\n ...args,\n trpcFile,\n trpcImportName,\n });\n log.success(`Transform completed`);\n}\n\nif (!args.skipTanstackQuery) {\n log.info('Installing @trpc/tanstack-react-query');\n await installPackage('@trpc/tanstack-react-query');\n log.success('@trpc/tanstack-react-query installed');\n\n log.info('Uninstalling @trpc/react-query');\n await uninstallPackage('@trpc/react-query');\n log.success('@trpc/react-query uninstalled');\n}\n\noutro('Upgrade complete! 🎉');\n"],"mappings":";;;;;;;;;;;;;;;;;ACGA,SAAgB,aAAa;CAC3B,MAAM,aAAa,GAAG,eAAe,QAAQ,IAAI,IAAI,aACnD,GAAG,IAAI,WAAW,QAAQ,CAC5B;CACA,IAAI,CAAC,YAAY;EACf,EAAE,IAAI,MAAM,mBAAmB;EAC/B,QAAQ,KAAK,CAAC;CAChB;CAEA,IAAI,QAAQ,IAAI,YACd,EAAE,IAAI,KAAK,mBAAmB,YAAY;CAG5C,MAAM,EAAE,WAAW,GAAG,eAAe,aAAa,aAChD,GAAG,IAAI,SAAS,QAAQ,CAC1B;CACA,MAAM,eAAe,GAAG,2BACtB,QACA,GAAG,KACH,QAAQ,IAAI,CACd;CAOA,OANgB,GAAG,cAAc;EAC/B,SAAS,aAAa;EACtB,WAAW,aAAa;EACxB,8BAA8B,aAAa;CAC7C,CAEa;AACf;AAEA,SAAgB,wBAAwB,SAAqB;CAC3D,MAAM,QAAQ,QAAQ,eAAe,CAAC,CAAC,QAAQ,eAAe;EAC5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
|
+
});
|
|
3
5
|
//#region src/lib/ast/modifiers.ts
|
|
4
6
|
/**
|
|
5
7
|
* Replaces the identifier for the root path key
|
|
@@ -20,7 +22,6 @@ function replaceMemberExpressionRootIndentifier(j, expr, id) {
|
|
|
20
22
|
}
|
|
21
23
|
return !j.MemberExpression.check(expr.object) ? false : replaceMemberExpressionRootIndentifier(j, expr.object, id);
|
|
22
24
|
}
|
|
23
|
-
|
|
24
25
|
//#endregion
|
|
25
26
|
//#region src/lib/ast/walkers.ts
|
|
26
27
|
/**
|
|
@@ -31,7 +32,6 @@ function findParentOfType(path, type) {
|
|
|
31
32
|
if (!path.parent) return false;
|
|
32
33
|
return type.check(path.node) ? path : findParentOfType(path.parentPath, type);
|
|
33
34
|
}
|
|
34
|
-
|
|
35
35
|
//#endregion
|
|
36
36
|
//#region src/transforms/hooksToOptions.ts
|
|
37
37
|
const hookToOptions = {
|
|
@@ -145,16 +145,15 @@ function transform(file, api, options) {
|
|
|
145
145
|
}
|
|
146
146
|
function migrateUseUtils(fnPath) {
|
|
147
147
|
j(fnPath).find(j.CallExpression, { callee: { property: { name: (name) => ["useContext", "useUtils"].includes(name) } } }).forEach((path) => {
|
|
148
|
-
|
|
149
|
-
if (isTRPCContextUtil && j.VariableDeclarator.check(path.parentPath.node) && j.Identifier.check(path.parentPath.node.id)) {
|
|
148
|
+
if (j.MemberExpression.check(path.value.callee) && j.Identifier.check(path.value.callee.object) && path.value.callee.object.name == trpcImportName && j.VariableDeclarator.check(path.parentPath.node) && j.Identifier.check(path.parentPath.node.id)) {
|
|
150
149
|
const oldIdentifier = path.parentPath.node.id;
|
|
151
|
-
root.find(j.Identifier, { name: oldIdentifier.name }).forEach((path
|
|
152
|
-
if (j.MemberExpression.check(path
|
|
153
|
-
const callExprPath = findParentOfType(path
|
|
150
|
+
root.find(j.Identifier, { name: oldIdentifier.name }).forEach((path) => {
|
|
151
|
+
if (j.MemberExpression.check(path.parent?.parent?.node) || j.CallExpression.check(path.parent?.parent?.node)) {
|
|
152
|
+
const callExprPath = findParentOfType(path.parentPath, j.CallExpression);
|
|
154
153
|
if (!callExprPath) {
|
|
155
154
|
console.warn(`Failed to walk up the tree to find utilMethod call expression, on file: ${file.path}`, callExprPath, {
|
|
156
|
-
start: path
|
|
157
|
-
end: path
|
|
155
|
+
start: path.node.loc?.start,
|
|
156
|
+
end: path.node.loc?.end
|
|
158
157
|
});
|
|
159
158
|
return;
|
|
160
159
|
}
|
|
@@ -162,8 +161,8 @@ function transform(file, api, options) {
|
|
|
162
161
|
const memberExpr = callExpr.callee;
|
|
163
162
|
if (!j.CallExpression.check(callExpr) || !j.MemberExpression.check(memberExpr)) {
|
|
164
163
|
console.warn(`Failed to walk up the tree to find utilMethod with a \`trpc.PATH.<call>\`, on file: ${file.path}`, callExpr, {
|
|
165
|
-
start: path
|
|
166
|
-
end: path
|
|
164
|
+
start: path.node.loc?.start,
|
|
165
|
+
end: path.node.loc?.end
|
|
167
166
|
});
|
|
168
167
|
return;
|
|
169
168
|
}
|
|
@@ -172,8 +171,7 @@ function transform(file, api, options) {
|
|
|
172
171
|
return;
|
|
173
172
|
}
|
|
174
173
|
const proxyMethod = memberExpr.property.name;
|
|
175
|
-
|
|
176
|
-
if (!replacedPath) console.warn("Failed to wrap proxy call expression", memberExpr);
|
|
174
|
+
if (!replaceMemberExpressionRootIndentifier(j, memberExpr, j.identifier(trpcImportName))) console.warn("Failed to wrap proxy call expression", memberExpr);
|
|
177
175
|
/**
|
|
178
176
|
* If no input, use pathFilter
|
|
179
177
|
* If input is undefined, use pathFilter
|
|
@@ -194,8 +192,10 @@ function transform(file, api, options) {
|
|
|
194
192
|
} else if (isNoArgs || isUndefindInputArg) {
|
|
195
193
|
memberExpr.property = j.identifier("pathFilter");
|
|
196
194
|
if (isUndefindInputArg) callExpr.arguments.shift();
|
|
197
|
-
} else if (j.ObjectExpression.check(callExpr.arguments[0]))
|
|
198
|
-
|
|
195
|
+
} else if (j.ObjectExpression.check(callExpr.arguments[0])) {
|
|
196
|
+
if (callExpr.arguments[0].properties.find((p) => j.ObjectProperty.check(p) && j.Identifier.check(p.key) && p.key.name === "cursor")) memberExpr.property = j.identifier("infiniteQueryFilter");
|
|
197
|
+
else memberExpr.property = j.identifier("queryFilter");
|
|
198
|
+
}
|
|
199
199
|
callExprPath.replace(j.memberExpression(j.identifier("queryClient"), j.callExpression(j.identifier(utilMap[proxyMethod][0]), [callExpr, ...argToForward ? [argToForward] : []])));
|
|
200
200
|
ensureUseTRPCCall(fnPath);
|
|
201
201
|
}
|
|
@@ -213,8 +213,8 @@ function transform(file, api, options) {
|
|
|
213
213
|
});
|
|
214
214
|
}
|
|
215
215
|
function removeSuspenseDestructuring(path) {
|
|
216
|
-
j(path).find(j.VariableDeclaration).forEach((path
|
|
217
|
-
const declarator = j.VariableDeclarator.check(path
|
|
216
|
+
j(path).find(j.VariableDeclaration).forEach((path) => {
|
|
217
|
+
const declarator = j.VariableDeclarator.check(path.node.declarations[0]) ? path.node.declarations[0] : null;
|
|
218
218
|
if (!j.CallExpression.check(declarator?.init) || !j.Identifier.check(declarator.init.callee) || !["useSuspenseQuery", "useSuspenseInfiniteQuery"].includes(declarator.init.callee.name)) return;
|
|
219
219
|
const tuple = j.ArrayPattern.check(declarator?.id) ? declarator.id : null;
|
|
220
220
|
const dataName = j.Identifier.check(tuple?.elements?.[0]) ? tuple.elements[0].name : null;
|
|
@@ -223,7 +223,7 @@ function transform(file, api, options) {
|
|
|
223
223
|
if (queryName) {
|
|
224
224
|
declarator.id = j.identifier(queryName);
|
|
225
225
|
dirtyFlag = true;
|
|
226
|
-
if (dataName) j(path
|
|
226
|
+
if (dataName) j(path).insertAfter(j.variableDeclaration("const", [j.variableDeclarator(j.identifier(dataName), j.memberExpression(declarator.id, j.identifier("data")))]));
|
|
227
227
|
} else if (dataName) {
|
|
228
228
|
declarator.id = j.objectPattern([j.property("init", j.identifier("data"), j.identifier(dataName))]);
|
|
229
229
|
dirtyFlag = true;
|
|
@@ -236,7 +236,6 @@ function transform(file, api, options) {
|
|
|
236
236
|
return dirtyFlag ? root.toSource() : void 0;
|
|
237
237
|
}
|
|
238
238
|
const parser = "tsx";
|
|
239
|
-
|
|
240
239
|
//#endregion
|
|
241
240
|
exports.default = transform;
|
|
242
|
-
exports.parser = parser;
|
|
241
|
+
exports.parser = parser;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { API, FileInfo, Options } from "jscodeshift";
|
|
2
|
+
//#region src/transforms/hooksToOptions.d.ts
|
|
3
|
+
interface TransformOptions extends Options {
|
|
4
|
+
trpcImportName?: string;
|
|
5
|
+
}
|
|
6
|
+
export default function transform(file: FileInfo, api: API, options: TransformOptions): string | undefined;
|
|
7
|
+
export declare const parser = "tsx";
|
|
8
|
+
//#endregion
|
|
9
|
+
//# sourceMappingURL=hooksToOptions.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooksToOptions.d.cts","names":[],"sources":["../../src/transforms/hooksToOptions.ts"],"mappings":";;UAgBU,yBAAyB;EACjC;;wBA6CsB,UACtB,MAAM,UACN,KAAK,KACL,SAAS;qBA2XE"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
Object.
|
|
2
|
-
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
3
5
|
//#region src/transforms/provider.ts
|
|
4
6
|
function transform(file, api, options) {
|
|
5
7
|
const { trpcImportName } = options;
|
|
@@ -65,7 +67,6 @@ function transform(file, api, options) {
|
|
|
65
67
|
return dirtyFlag ? root.toSource() : void 0;
|
|
66
68
|
}
|
|
67
69
|
const parser = "tsx";
|
|
68
|
-
|
|
69
70
|
//#endregion
|
|
70
71
|
exports.default = transform;
|
|
71
|
-
exports.parser = parser;
|
|
72
|
+
exports.parser = parser;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { API, FileInfo, Options } from "jscodeshift";
|
|
2
|
+
//#region src/transforms/provider.d.ts
|
|
3
|
+
interface TransformOptions extends Options {
|
|
4
|
+
trpcImportName?: string;
|
|
5
|
+
}
|
|
6
|
+
export default function transform(file: FileInfo, api: API, options: TransformOptions): string | undefined;
|
|
7
|
+
export declare const parser = "tsx";
|
|
8
|
+
//#endregion
|
|
9
|
+
//# sourceMappingURL=provider.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.cts","names":[],"sources":["../../src/transforms/provider.ts"],"mappings":";;UAEU,yBAAyB;EACjC;;wBAGsB,UACtB,MAAM,UACN,KAAK,KACL,SAAS;qBAwIE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trpc/upgrade",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.19.0",
|
|
4
4
|
"description": "Upgrade scripts for tRPC",
|
|
5
5
|
"author": "juliusmarminge",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,19 +35,19 @@
|
|
|
35
35
|
"@bomb.sh/args": "0.3.1",
|
|
36
36
|
"@clack/prompts": "1.2.0",
|
|
37
37
|
"jscodeshift": "17.3.0",
|
|
38
|
-
"typescript": "
|
|
38
|
+
"typescript": "catalog:ts-api"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@tanstack/react-query": "^5.80.3",
|
|
42
|
-
"@trpc/client": "11.
|
|
43
|
-
"@trpc/react-query": "11.
|
|
44
|
-
"@trpc/server": "11.
|
|
45
|
-
"@trpc/tanstack-react-query": "11.
|
|
42
|
+
"@trpc/client": "11.19.0",
|
|
43
|
+
"@trpc/react-query": "11.19.0",
|
|
44
|
+
"@trpc/server": "11.19.0",
|
|
45
|
+
"@trpc/tanstack-react-query": "11.19.0",
|
|
46
46
|
"@types/jscodeshift": "17.3.0",
|
|
47
|
-
"@types/node": "
|
|
47
|
+
"@types/node": "catalog:",
|
|
48
48
|
"react": "^19.1.0",
|
|
49
49
|
"react-dom": "^19.1.0",
|
|
50
|
-
"tsdown": "
|
|
50
|
+
"tsdown": "catalog:",
|
|
51
51
|
"zod": "^4.2.1"
|
|
52
52
|
},
|
|
53
53
|
"publishConfig": {
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"funding": [
|
|
57
57
|
"https://trpc.io/sponsor"
|
|
58
58
|
],
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "fcc6bca0ece2762e393e6d8c8527bbaa17a878d2"
|
|
60
60
|
}
|
|
@@ -262,12 +262,10 @@ export default function transform(
|
|
|
262
262
|
return;
|
|
263
263
|
}
|
|
264
264
|
|
|
265
|
-
if (
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
)
|
|
270
|
-
) {
|
|
265
|
+
if (!(
|
|
266
|
+
j.Identifier.check(memberExpr.property) &&
|
|
267
|
+
memberExpr.property.name in utilMap
|
|
268
|
+
)) {
|
|
271
269
|
console.warn(
|
|
272
270
|
'Failed to identify utilMethod from proxy call expression',
|
|
273
271
|
memberExpr,
|