@cedarjs/codemods 3.0.0-canary.13644 → 3.0.0-canary.13646
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.
|
@@ -33,11 +33,11 @@ async function getPrismaV7Context() {
|
|
|
33
33
|
} else if (fs.existsSync(dbPathJs)) {
|
|
34
34
|
dbFilePath = dbPathJs;
|
|
35
35
|
}
|
|
36
|
-
return { provider, isSqlite, isPostgres,
|
|
36
|
+
return { provider, isSqlite, isPostgres, dbFilePath };
|
|
37
37
|
}
|
|
38
38
|
async function prismaV7() {
|
|
39
|
+
const paths = getPaths();
|
|
39
40
|
const context = await getPrismaV7Context();
|
|
40
|
-
const { paths, isSqlite } = context;
|
|
41
41
|
await runUpdateSchemaFile();
|
|
42
42
|
await updatePrismaConfig(paths.api.prismaConfig);
|
|
43
43
|
if (context.dbFilePath) {
|
|
@@ -46,14 +46,14 @@ async function prismaV7() {
|
|
|
46
46
|
targetPaths: [context.dbFilePath],
|
|
47
47
|
parser: "ts",
|
|
48
48
|
options: {
|
|
49
|
-
isSqlite,
|
|
49
|
+
isSqlite: context.isSqlite,
|
|
50
50
|
isPostgres: context.isPostgres,
|
|
51
51
|
silent: true
|
|
52
52
|
}
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
55
|
await rewriteRemainingImports();
|
|
56
|
-
if (isSqlite || context.isPostgres) {
|
|
56
|
+
if (context.isSqlite || context.isPostgres) {
|
|
57
57
|
await updateApiPackageJson(path.join(paths.api.base, "package.json"), {
|
|
58
58
|
provider: context.provider
|
|
59
59
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { styleText } from "node:util";
|
|
3
|
+
import { getPaths } from "@cedarjs/project-config";
|
|
3
4
|
import runTransform from "../../../lib/runTransform.js";
|
|
4
5
|
import { getPrismaV7Context } from "./prismaV7.js";
|
|
5
6
|
import rewriteRemainingImports from "./rewriteRemainingImports.js";
|
|
@@ -16,8 +17,9 @@ function step(label, output) {
|
|
|
16
17
|
console.log(` \u2192 ${output}`);
|
|
17
18
|
}
|
|
18
19
|
const handler = async () => {
|
|
20
|
+
const paths = getPaths();
|
|
19
21
|
const context = await getPrismaV7Context();
|
|
20
|
-
const {
|
|
22
|
+
const { isSqlite, isPostgres, provider, dbFilePath } = context;
|
|
21
23
|
console.log(styleText("bold", "\u276F Prisma v7 Migration"));
|
|
22
24
|
const { results: schemaResults } = await runUpdateSchemaFile();
|
|
23
25
|
if (schemaResults.length === 0) {
|
|
@@ -144,7 +146,7 @@ const handler = async () => {
|
|
|
144
146
|
` ${offset + 1}. Run \`yarn install\` to install new dependencies`,
|
|
145
147
|
` ${offset + 2}. Run \`yarn cedar prisma generate\` to generate the new Prisma client`,
|
|
146
148
|
` ${offset + 3}. Run \`yarn cedar prisma migrate dev\` to verify migrations work`,
|
|
147
|
-
` ${offset + 4}. Run \`yarn cedar lint --fix\` to fix
|
|
149
|
+
` ${offset + 4}. Run \`yarn cedar lint --fix\` to fix code formatting issues`
|
|
148
150
|
);
|
|
149
151
|
console.log(styleText("bold", "\n Next steps:"));
|
|
150
152
|
console.log(nextSteps.join("\n"));
|
|
@@ -11,6 +11,55 @@ function transform(file, api, options = {}) {
|
|
|
11
11
|
if (alreadyMigrated) {
|
|
12
12
|
return file.source;
|
|
13
13
|
}
|
|
14
|
+
function insertAdapterImport(importDecl) {
|
|
15
|
+
const clientImport = root.find(j.ImportDeclaration, {
|
|
16
|
+
source: { value: NEW_CLIENT_PATH }
|
|
17
|
+
});
|
|
18
|
+
if (clientImport.length > 0) {
|
|
19
|
+
clientImport.insertBefore(importDecl);
|
|
20
|
+
} else {
|
|
21
|
+
root.find(j.ImportDeclaration).at(0).insertBefore(importDecl);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function addAdapterToPrismaClient() {
|
|
25
|
+
root.find(j.NewExpression, {
|
|
26
|
+
callee: { type: "Identifier", name: "PrismaClient" }
|
|
27
|
+
}).forEach((nodePath) => {
|
|
28
|
+
const args = nodePath.node.arguments;
|
|
29
|
+
if (args.length === 0) {
|
|
30
|
+
nodePath.node.arguments = [
|
|
31
|
+
j.objectExpression([
|
|
32
|
+
Object.assign(
|
|
33
|
+
j.objectProperty(
|
|
34
|
+
j.identifier("adapter"),
|
|
35
|
+
j.identifier("adapter")
|
|
36
|
+
),
|
|
37
|
+
{ shorthand: true }
|
|
38
|
+
)
|
|
39
|
+
])
|
|
40
|
+
];
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const firstArg = args[0];
|
|
44
|
+
if (firstArg.type !== "ObjectExpression") {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const hasAdapterProp = firstArg.properties.some(
|
|
48
|
+
(prop) => prop.type === "ObjectProperty" && prop.key.type === "Identifier" && "name" in prop.key && prop.key.name === "adapter"
|
|
49
|
+
);
|
|
50
|
+
if (!hasAdapterProp) {
|
|
51
|
+
firstArg.properties.push(
|
|
52
|
+
Object.assign(
|
|
53
|
+
j.objectProperty(
|
|
54
|
+
j.identifier("adapter"),
|
|
55
|
+
j.identifier("adapter")
|
|
56
|
+
),
|
|
57
|
+
{ shorthand: true }
|
|
58
|
+
)
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
14
63
|
let didTransform = false;
|
|
15
64
|
root.find(j.ImportDeclaration, { source: { value: OLD_PRISMA_CLIENT } }).forEach((nodePath) => {
|
|
16
65
|
nodePath.node.source = j.stringLiteral(NEW_CLIENT_PATH);
|
|
@@ -31,25 +80,25 @@ function transform(file, api, options = {}) {
|
|
|
31
80
|
source: { value: "@prisma/adapter-pg" }
|
|
32
81
|
}).length > 0;
|
|
33
82
|
if (!hasAdapterImport2) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
83
|
+
insertAdapterImport(
|
|
84
|
+
j.importDeclaration(
|
|
85
|
+
[
|
|
86
|
+
j.importSpecifier(
|
|
87
|
+
j.identifier("PrismaPg"),
|
|
88
|
+
j.identifier("PrismaPg")
|
|
89
|
+
)
|
|
90
|
+
],
|
|
91
|
+
j.stringLiteral("@prisma/adapter-pg")
|
|
92
|
+
)
|
|
40
93
|
);
|
|
41
|
-
clientImport2.insertBefore(adapterImport);
|
|
42
94
|
}
|
|
43
95
|
const hasAdapter2 = root.find(j.VariableDeclarator, {
|
|
44
96
|
id: { type: "Identifier", name: "adapter" }
|
|
45
97
|
}).length > 0;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const prismaClientDeclaration = prismaClientNewExpr2.closest(
|
|
51
|
-
j.VariableDeclaration
|
|
52
|
-
);
|
|
98
|
+
if (!hasAdapter2) {
|
|
99
|
+
const prismaClientDeclaration = root.find(j.NewExpression, {
|
|
100
|
+
callee: { type: "Identifier", name: "PrismaClient" }
|
|
101
|
+
}).closest(j.VariableDeclaration);
|
|
53
102
|
const adapterDecl = j.variableDeclaration("const", [
|
|
54
103
|
j.variableDeclarator(
|
|
55
104
|
j.identifier("adapter"),
|
|
@@ -71,43 +120,7 @@ function transform(file, api, options = {}) {
|
|
|
71
120
|
]);
|
|
72
121
|
prismaClientDeclaration.insertBefore(adapterDecl);
|
|
73
122
|
}
|
|
74
|
-
|
|
75
|
-
callee: { type: "Identifier", name: "PrismaClient" }
|
|
76
|
-
}).forEach((nodePath) => {
|
|
77
|
-
const args = nodePath.node.arguments;
|
|
78
|
-
if (args.length === 0) {
|
|
79
|
-
nodePath.node.arguments = [
|
|
80
|
-
j.objectExpression([
|
|
81
|
-
Object.assign(
|
|
82
|
-
j.objectProperty(
|
|
83
|
-
j.identifier("adapter"),
|
|
84
|
-
j.identifier("adapter")
|
|
85
|
-
),
|
|
86
|
-
{ shorthand: true }
|
|
87
|
-
)
|
|
88
|
-
])
|
|
89
|
-
];
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
const firstArg = args[0];
|
|
93
|
-
if (firstArg.type !== "ObjectExpression") {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
const hasAdapterProp = firstArg.properties.some(
|
|
97
|
-
(prop) => prop.type === "ObjectProperty" && prop.key.type === "Identifier" && prop.key.name === "adapter"
|
|
98
|
-
);
|
|
99
|
-
if (!hasAdapterProp) {
|
|
100
|
-
firstArg.properties.push(
|
|
101
|
-
Object.assign(
|
|
102
|
-
j.objectProperty(
|
|
103
|
-
j.identifier("adapter"),
|
|
104
|
-
j.identifier("adapter")
|
|
105
|
-
),
|
|
106
|
-
{ shorthand: true }
|
|
107
|
-
)
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
});
|
|
123
|
+
addAdapterToPrismaClient();
|
|
111
124
|
return root.toSource({ quote: "single" });
|
|
112
125
|
}
|
|
113
126
|
if (!isSqlite) {
|
|
@@ -120,29 +133,26 @@ function transform(file, api, options = {}) {
|
|
|
120
133
|
const hasGetPathsImport = root.find(j.ImportDeclaration, {
|
|
121
134
|
source: { value: "@cedarjs/project-config" }
|
|
122
135
|
}).length > 0;
|
|
123
|
-
const allImports = root.find(j.ImportDeclaration);
|
|
124
|
-
const firstImport = allImports.at(0);
|
|
125
136
|
if (!hasPathImport) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
137
|
+
root.find(j.ImportDeclaration).at(0).insertBefore(
|
|
138
|
+
j.importDeclaration(
|
|
139
|
+
[j.importDefaultSpecifier(j.identifier("path"))],
|
|
140
|
+
j.stringLiteral("node:path")
|
|
141
|
+
)
|
|
129
142
|
);
|
|
130
|
-
firstImport.insertBefore(pathImport);
|
|
131
143
|
}
|
|
132
|
-
const clientImport = root.find(j.ImportDeclaration, {
|
|
133
|
-
source: { value: NEW_CLIENT_PATH }
|
|
134
|
-
});
|
|
135
144
|
if (!hasAdapterImport) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
j.
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
145
|
+
insertAdapterImport(
|
|
146
|
+
j.importDeclaration(
|
|
147
|
+
[
|
|
148
|
+
j.importSpecifier(
|
|
149
|
+
j.identifier("PrismaBetterSqlite3"),
|
|
150
|
+
j.identifier("PrismaBetterSqlite3")
|
|
151
|
+
)
|
|
152
|
+
],
|
|
153
|
+
j.stringLiteral("@prisma/adapter-better-sqlite3")
|
|
154
|
+
)
|
|
144
155
|
);
|
|
145
|
-
clientImport.insertBefore(adapterImport);
|
|
146
156
|
}
|
|
147
157
|
if (!hasGetPathsImport) {
|
|
148
158
|
const cedarjsImports = root.find(
|
|
@@ -153,6 +163,9 @@ function transform(file, api, options = {}) {
|
|
|
153
163
|
[j.importSpecifier(j.identifier("getPaths"), j.identifier("getPaths"))],
|
|
154
164
|
j.stringLiteral("@cedarjs/project-config")
|
|
155
165
|
);
|
|
166
|
+
const clientImport = root.find(j.ImportDeclaration, {
|
|
167
|
+
source: { value: NEW_CLIENT_PATH }
|
|
168
|
+
});
|
|
156
169
|
if (cedarjsImports.length > 0) {
|
|
157
170
|
cedarjsImports.at(-1).insertAfter(getPathsImport);
|
|
158
171
|
} else {
|
|
@@ -210,40 +223,7 @@ const resolveSqliteUrl = (url = 'file:./db/dev.db') => {
|
|
|
210
223
|
prismaClientDeclaration.insertBefore(adapterDecl);
|
|
211
224
|
}
|
|
212
225
|
}
|
|
213
|
-
|
|
214
|
-
callee: { type: "Identifier", name: "PrismaClient" }
|
|
215
|
-
}).forEach((nodePath) => {
|
|
216
|
-
const args = nodePath.node.arguments;
|
|
217
|
-
if (args.length === 0) {
|
|
218
|
-
nodePath.node.arguments = [
|
|
219
|
-
j.objectExpression([
|
|
220
|
-
Object.assign(
|
|
221
|
-
j.objectProperty(
|
|
222
|
-
j.identifier("adapter"),
|
|
223
|
-
j.identifier("adapter")
|
|
224
|
-
),
|
|
225
|
-
{ shorthand: true }
|
|
226
|
-
)
|
|
227
|
-
])
|
|
228
|
-
];
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
const firstArg = args[0];
|
|
232
|
-
if (firstArg.type !== "ObjectExpression") {
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
const hasAdapterProp = firstArg.properties.some(
|
|
236
|
-
(prop) => prop.type === "ObjectProperty" && prop.key.type === "Identifier" && prop.key.name === "adapter"
|
|
237
|
-
);
|
|
238
|
-
if (!hasAdapterProp) {
|
|
239
|
-
firstArg.properties.push(
|
|
240
|
-
Object.assign(
|
|
241
|
-
j.objectProperty(j.identifier("adapter"), j.identifier("adapter")),
|
|
242
|
-
{ shorthand: true }
|
|
243
|
-
)
|
|
244
|
-
);
|
|
245
|
-
}
|
|
246
|
-
});
|
|
226
|
+
addAdapterToPrismaClient();
|
|
247
227
|
return root.toSource({ quote: "single" });
|
|
248
228
|
}
|
|
249
229
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/codemods",
|
|
3
|
-
"version": "3.0.0-canary.
|
|
3
|
+
"version": "3.0.0-canary.13646+d2a971cc8",
|
|
4
4
|
"description": "Codemods to ease upgrading a CedarJS Project",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"@babel/parser": "7.29.2",
|
|
30
30
|
"@babel/plugin-transform-typescript": "^7.26.8",
|
|
31
31
|
"@babel/traverse": "7.29.0",
|
|
32
|
-
"@cedarjs/cli-helpers": "3.0.0-canary.
|
|
33
|
-
"@cedarjs/project-config": "3.0.0-canary.
|
|
32
|
+
"@cedarjs/cli-helpers": "3.0.0-canary.13646",
|
|
33
|
+
"@cedarjs/project-config": "3.0.0-canary.13646",
|
|
34
34
|
"@svgr/core": "8.1.0",
|
|
35
35
|
"@svgr/plugin-jsx": "8.1.0",
|
|
36
36
|
"@vscode/ripgrep": "1.17.1",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"yargs": "17.7.2"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@cedarjs/framework-tools": "3.0.0-canary.
|
|
51
|
+
"@cedarjs/framework-tools": "3.0.0-canary.13646",
|
|
52
52
|
"@types/babel__core": "7.20.5",
|
|
53
53
|
"@types/jscodeshift": "17.3.0",
|
|
54
54
|
"@types/yargs": "17.0.35",
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"publishConfig": {
|
|
62
62
|
"access": "public"
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "d2a971cc88b3047f421cb2df6d6bfdee38fab561"
|
|
65
65
|
}
|