@cedarjs/codemods 2.6.1-next.0 → 2.6.1-next.104
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.
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var prismaV7Prep_exports = {};
|
|
30
|
+
__export(prismaV7Prep_exports, {
|
|
31
|
+
default: () => prismaV7Prep_default,
|
|
32
|
+
getPrismaV7PrepContext: () => getPrismaV7PrepContext,
|
|
33
|
+
rewritePrismaImportsInDirectory: () => rewritePrismaImportsInDirectory,
|
|
34
|
+
updateDbFile: () => updateDbFile
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(prismaV7Prep_exports);
|
|
37
|
+
var import_node_fs = __toESM(require("node:fs"));
|
|
38
|
+
var import_node_path = __toESM(require("node:path"));
|
|
39
|
+
var import_jscodeshift = __toESM(require("jscodeshift"));
|
|
40
|
+
var import_project_config = require("@cedarjs/project-config");
|
|
41
|
+
var import_prettify = __toESM(require("../../../lib/prettify"));
|
|
42
|
+
function getParserForFile(filePath) {
|
|
43
|
+
if (filePath.endsWith(".tsx") || filePath.endsWith(".jsx")) {
|
|
44
|
+
return import_jscodeshift.default.withParser("tsx");
|
|
45
|
+
}
|
|
46
|
+
return import_jscodeshift.default.withParser("ts");
|
|
47
|
+
}
|
|
48
|
+
function getPrettierParserForFile(filePath) {
|
|
49
|
+
if (filePath.endsWith(".ts") || filePath.endsWith(".tsx") || filePath.endsWith(".cts") || filePath.endsWith(".mts")) {
|
|
50
|
+
return "typescript";
|
|
51
|
+
}
|
|
52
|
+
return "babel";
|
|
53
|
+
}
|
|
54
|
+
function transformDbFile(file) {
|
|
55
|
+
const parser = getParserForFile(file.path);
|
|
56
|
+
const root = parser(file.source);
|
|
57
|
+
const existingExport = root.find(parser.ExportAllDeclaration, {
|
|
58
|
+
source: { value: "@prisma/client" }
|
|
59
|
+
});
|
|
60
|
+
if (existingExport.length > 0) {
|
|
61
|
+
return file.source;
|
|
62
|
+
}
|
|
63
|
+
const prismaClientImport = root.find(parser.ImportDeclaration, {
|
|
64
|
+
source: { value: "@prisma/client" }
|
|
65
|
+
});
|
|
66
|
+
if (prismaClientImport.length === 0) {
|
|
67
|
+
return file.source;
|
|
68
|
+
}
|
|
69
|
+
const importNode = prismaClientImport.get();
|
|
70
|
+
const exportStatement = parser.exportAllDeclaration(
|
|
71
|
+
parser.literal("@prisma/client"),
|
|
72
|
+
null
|
|
73
|
+
);
|
|
74
|
+
importNode.insertAfter(exportStatement);
|
|
75
|
+
return root.toSource();
|
|
76
|
+
}
|
|
77
|
+
function transformOtherFile(file) {
|
|
78
|
+
const parser = getParserForFile(file.path);
|
|
79
|
+
const root = parser(file.source);
|
|
80
|
+
const isInRootScripts = file.path.startsWith((0, import_project_config.getPaths)().scripts + import_node_path.default.sep);
|
|
81
|
+
const importPath = isInRootScripts ? "api/src/lib/db" : "src/lib/db";
|
|
82
|
+
root.find(parser.ImportDeclaration, {
|
|
83
|
+
source: { value: "@prisma/client" }
|
|
84
|
+
}).forEach((importDecl) => {
|
|
85
|
+
importDecl.get("source").replace(parser.literal(importPath));
|
|
86
|
+
});
|
|
87
|
+
return root.toSource();
|
|
88
|
+
}
|
|
89
|
+
async function getPrismaV7PrepContext() {
|
|
90
|
+
const paths = (0, import_project_config.getPaths)();
|
|
91
|
+
const prismaConfigPath = paths.api.prismaConfig;
|
|
92
|
+
const dataMigrationsPath = await (0, import_project_config.getDataMigrationsPath)(prismaConfigPath);
|
|
93
|
+
const dbPath = import_node_path.default.join(paths.api.lib, "db.ts");
|
|
94
|
+
const dbPathJs = import_node_path.default.join(paths.api.lib, "db.js");
|
|
95
|
+
let dbFilePath = dbPath;
|
|
96
|
+
if (!import_node_fs.default.existsSync(dbPath)) {
|
|
97
|
+
dbFilePath = dbPathJs;
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
dataMigrationsPath,
|
|
101
|
+
dbFilePath: import_node_fs.default.existsSync(dbFilePath) ? dbFilePath : null,
|
|
102
|
+
paths
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
async function updateDbFile(dbFilePath) {
|
|
106
|
+
if (!dbFilePath) {
|
|
107
|
+
return "skipped";
|
|
108
|
+
}
|
|
109
|
+
const source = import_node_fs.default.readFileSync(dbFilePath, "utf-8");
|
|
110
|
+
const transformed = transformDbFile({ source, path: dbFilePath });
|
|
111
|
+
import_node_fs.default.writeFileSync(
|
|
112
|
+
dbFilePath,
|
|
113
|
+
await (0, import_prettify.default)(transformed, {
|
|
114
|
+
parser: getPrettierParserForFile(dbFilePath)
|
|
115
|
+
})
|
|
116
|
+
);
|
|
117
|
+
return "updated";
|
|
118
|
+
}
|
|
119
|
+
async function rewritePrismaImportsInDirectory(dir, dbFilePath) {
|
|
120
|
+
if (!import_node_fs.default.existsSync(dir)) {
|
|
121
|
+
return {
|
|
122
|
+
filesSeen: 0,
|
|
123
|
+
filesUpdated: 0
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
const files = import_node_fs.default.readdirSync(dir, { recursive: true, encoding: "utf8" }).filter(
|
|
127
|
+
(file) => file.endsWith(".ts") || file.endsWith(".cts") || file.endsWith(".mts") || file.endsWith(".tsx") || file.endsWith(".js") || file.endsWith(".cjs") || file.endsWith(".mjs") || file.endsWith(".jsx")
|
|
128
|
+
).map((file) => import_node_path.default.join(dir, file)).filter((file) => import_node_fs.default.statSync(file).isFile()).filter((file) => file !== dbFilePath);
|
|
129
|
+
let filesUpdated = 0;
|
|
130
|
+
for (const file of files) {
|
|
131
|
+
const source = import_node_fs.default.readFileSync(file, "utf-8");
|
|
132
|
+
const transformed = transformOtherFile({ source, path: file });
|
|
133
|
+
const prettified = await (0, import_prettify.default)(transformed, {
|
|
134
|
+
parser: getPrettierParserForFile(file)
|
|
135
|
+
});
|
|
136
|
+
if (prettified !== source) {
|
|
137
|
+
filesUpdated += 1;
|
|
138
|
+
import_node_fs.default.writeFileSync(file, prettified);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
filesSeen: files.length,
|
|
143
|
+
filesUpdated
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
async function prismaV7Prep() {
|
|
147
|
+
const context = await getPrismaV7PrepContext();
|
|
148
|
+
await updateDbFile(context.dbFilePath);
|
|
149
|
+
const dirsToTransform = [
|
|
150
|
+
context.paths.api.src,
|
|
151
|
+
context.dataMigrationsPath,
|
|
152
|
+
context.paths.scripts
|
|
153
|
+
];
|
|
154
|
+
for (const dir of dirsToTransform) {
|
|
155
|
+
await rewritePrismaImportsInDirectory(dir, context.dbFilePath);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
var prismaV7Prep_default = prismaV7Prep;
|
|
159
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
160
|
+
0 && (module.exports = {
|
|
161
|
+
getPrismaV7PrepContext,
|
|
162
|
+
rewritePrismaImportsInDirectory,
|
|
163
|
+
updateDbFile
|
|
164
|
+
});
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var prismaV7Prep_yargs_exports = {};
|
|
30
|
+
__export(prismaV7Prep_yargs_exports, {
|
|
31
|
+
command: () => command,
|
|
32
|
+
description: () => description,
|
|
33
|
+
handler: () => handler
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(prismaV7Prep_yargs_exports);
|
|
36
|
+
var import_tasuku = __toESM(require("tasuku"));
|
|
37
|
+
var import_prismaV7Prep = require("./prismaV7Prep");
|
|
38
|
+
const command = "prisma-v7-prep";
|
|
39
|
+
const description = "(v2.7.x) Prepares for Prisma v7 by funneling imports through src/lib/db";
|
|
40
|
+
const handler = () => {
|
|
41
|
+
(0, import_tasuku.default)("Prisma v7 Prep", async ({ setError }) => {
|
|
42
|
+
try {
|
|
43
|
+
const context = await (0, import_prismaV7Prep.getPrismaV7PrepContext)();
|
|
44
|
+
await (0, import_tasuku.default)(
|
|
45
|
+
"Resolve project paths",
|
|
46
|
+
async ({ setOutput }) => {
|
|
47
|
+
setOutput(
|
|
48
|
+
`api/src: ${context.paths.api.src} | dataMigrations: ${context.dataMigrationsPath} | scripts: ` + context.paths.scripts
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
await (0, import_tasuku.default)("Update api/src/lib/db re-export", async ({ setOutput }) => {
|
|
53
|
+
const result = await (0, import_prismaV7Prep.updateDbFile)(context.dbFilePath);
|
|
54
|
+
if (result === "skipped") {
|
|
55
|
+
setOutput("Skipped (no api/src/lib/db.ts or api/src/lib/db.js found)");
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
setOutput(`Updated ${context.dbFilePath}`);
|
|
59
|
+
});
|
|
60
|
+
await (0, import_tasuku.default)("Rewrite imports in api/src", async ({ setOutput }) => {
|
|
61
|
+
const result = await (0, import_prismaV7Prep.rewritePrismaImportsInDirectory)(
|
|
62
|
+
context.paths.api.src,
|
|
63
|
+
context.dbFilePath
|
|
64
|
+
);
|
|
65
|
+
setOutput(`Updated ${result.filesUpdated}/${result.filesSeen} files`);
|
|
66
|
+
});
|
|
67
|
+
await (0, import_tasuku.default)(
|
|
68
|
+
"Rewrite imports in api/db/dataMigrations",
|
|
69
|
+
async ({ setOutput }) => {
|
|
70
|
+
const result = await (0, import_prismaV7Prep.rewritePrismaImportsInDirectory)(
|
|
71
|
+
context.dataMigrationsPath,
|
|
72
|
+
context.dbFilePath
|
|
73
|
+
);
|
|
74
|
+
if (result.filesSeen === 0) {
|
|
75
|
+
setOutput("Skipped (directory missing or empty)");
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
setOutput(`Updated ${result.filesUpdated}/${result.filesSeen} files`);
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
await (0, import_tasuku.default)("Rewrite imports in scripts", async ({ setOutput }) => {
|
|
82
|
+
const result = await (0, import_prismaV7Prep.rewritePrismaImportsInDirectory)(
|
|
83
|
+
context.paths.scripts,
|
|
84
|
+
context.dbFilePath
|
|
85
|
+
);
|
|
86
|
+
if (result.filesSeen === 0) {
|
|
87
|
+
setOutput("Skipped (directory missing or empty)");
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
setOutput(`Updated ${result.filesUpdated}/${result.filesSeen} files`);
|
|
91
|
+
});
|
|
92
|
+
} catch (e) {
|
|
93
|
+
setError("Failed to codemod your project \n" + e?.message);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
98
|
+
0 && (module.exports = {
|
|
99
|
+
command,
|
|
100
|
+
description,
|
|
101
|
+
handler
|
|
102
|
+
});
|
package/dist/codemods.js
CHANGED
|
@@ -43,7 +43,8 @@ var v6DevFatalErrorPage = __toESM(require("./codemods/redwood/v6.x.x/updateDevFa
|
|
|
43
43
|
var v6ThemeConfig = __toESM(require("./codemods/redwood/v6.x.x/updateThemeConfig/updateThemeConfig.yargs.js"));
|
|
44
44
|
var v7Gql = __toESM(require("./codemods/redwood/v7.x.x/updateGraphQLConfig/updateGraphqlConfig.yargs.js"));
|
|
45
45
|
var v2MoveGeneratorTemplates = __toESM(require("./codemods/v2.3.x/moveGeneratorTemplates/moveGeneratorTemplates.yargs.js"));
|
|
46
|
-
|
|
46
|
+
var v2PrismaV7Prep = __toESM(require("./codemods/v2.7.x/prismaV7Prep/prismaV7Prep.yargs.js"));
|
|
47
|
+
import_yargs.default.scriptName("").command(v2MoveGeneratorTemplates).command(v2PrismaV7Prep).command("redwood", "List or run Redwood codemods", (yargs2) => {
|
|
47
48
|
return yargs2.command(v2TsconfigForRouteHooks).command(v2ConfigureFastify).command(v2UpdateResolverTypes).command(v4UpdateClerkGetCurrentUser).command(v4UseArmor).command(v5CellQueryResult).command(v5DetectEmptyCells).command(v5RenameValidateWith).command(v5UpdateAuth0ToV2).command(v5UpdateNodeEngineTo18).command(v5UpgradeToReact18).command(v6GlobalThis).command(v6Jsx).command(v6EntryClient).command(v6EnvDot).command(v6Svgs).command(v6DevFatalErrorPage).command(v6ThemeConfig).command(v7Gql).demandCommand().strict();
|
|
48
49
|
}).demandCommand().epilog(
|
|
49
50
|
[
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/codemods",
|
|
3
|
-
"version": "2.6.1-next.
|
|
3
|
+
"version": "2.6.1-next.104+6be0fa58d",
|
|
4
4
|
"description": "Codemods to ease upgrading a CedarJS Project",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"@babel/plugin-transform-typescript": "^7.26.8",
|
|
31
31
|
"@babel/runtime-corejs3": "7.29.0",
|
|
32
32
|
"@babel/traverse": "7.29.0",
|
|
33
|
-
"@cedarjs/project-config": "2.6.1-next.
|
|
33
|
+
"@cedarjs/project-config": "2.6.1-next.104+6be0fa58d",
|
|
34
34
|
"@svgr/core": "8.1.0",
|
|
35
35
|
"@svgr/plugin-jsx": "8.1.0",
|
|
36
36
|
"@vscode/ripgrep": "1.17.0",
|
|
@@ -40,16 +40,16 @@
|
|
|
40
40
|
"deepmerge": "4.3.1",
|
|
41
41
|
"execa": "5.1.1",
|
|
42
42
|
"fast-glob": "3.3.3",
|
|
43
|
-
"graphql": "16.
|
|
43
|
+
"graphql": "16.13.0",
|
|
44
44
|
"jscodeshift": "17.0.0",
|
|
45
45
|
"pascalcase": "1.0.0",
|
|
46
46
|
"prettier": "3.8.1",
|
|
47
|
-
"tasuku": "2.0
|
|
47
|
+
"tasuku": "2.3.0",
|
|
48
48
|
"typescript": "5.9.3",
|
|
49
49
|
"yargs": "17.7.2"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@cedarjs/framework-tools": "2.6.1-next.
|
|
52
|
+
"@cedarjs/framework-tools": "2.6.1-next.104",
|
|
53
53
|
"@types/babel__core": "7.20.5",
|
|
54
54
|
"@types/jscodeshift": "0.12.0",
|
|
55
55
|
"@types/yargs": "17.0.35",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"publishConfig": {
|
|
61
61
|
"access": "public"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "6be0fa58d21ad717026065445aab7117e39ee3eb"
|
|
64
64
|
}
|