@cedarjs/codemods 3.0.0-canary.13482 → 3.0.0-canary.13485

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.
@@ -28,7 +28,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var prismaV7Prep_exports = {};
30
30
  __export(prismaV7Prep_exports, {
31
- default: () => prismaV7Prep_default
31
+ default: () => prismaV7Prep_default,
32
+ getPrismaV7PrepContext: () => getPrismaV7PrepContext,
33
+ rewritePrismaImportsInDirectory: () => rewritePrismaImportsInDirectory,
34
+ updateDbFile: () => updateDbFile
32
35
  });
33
36
  module.exports = __toCommonJS(prismaV7Prep_exports);
34
37
  var import_node_fs = __toESM(require("node:fs"));
@@ -83,44 +86,79 @@ function transformOtherFile(file) {
83
86
  });
84
87
  return root.toSource();
85
88
  }
86
- async function prismaV7Prep() {
89
+ async function getPrismaV7PrepContext() {
87
90
  const paths = (0, import_project_config.getPaths)();
88
91
  const prismaConfigPath = paths.api.prismaConfig;
89
92
  const dataMigrationsPath = await (0, import_project_config.getDataMigrationsPath)(prismaConfigPath);
90
- const dbPath = import_node_path.default.join(paths.api.src, "lib", "db.ts");
91
- const dbPathJs = import_node_path.default.join(paths.api.src, "lib", "db.js");
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");
92
95
  let dbFilePath = dbPath;
93
96
  if (!import_node_fs.default.existsSync(dbPath)) {
94
97
  dbFilePath = dbPathJs;
95
98
  }
96
- if (import_node_fs.default.existsSync(dbFilePath)) {
97
- const source = import_node_fs.default.readFileSync(dbFilePath, "utf-8");
98
- const transformed = transformDbFile({ source, path: dbFilePath });
99
- import_node_fs.default.writeFileSync(
100
- dbFilePath,
101
- await (0, import_prettify.default)(transformed, {
102
- parser: getPrettierParserForFile(dbFilePath)
103
- })
104
- );
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";
105
108
  }
106
- const dirsToTransform = [paths.api.src, dataMigrationsPath, paths.scripts];
107
- for (const dir of dirsToTransform) {
108
- if (!import_node_fs.default.existsSync(dir)) {
109
- continue;
110
- }
111
- const files = import_node_fs.default.readdirSync(dir, { recursive: true, encoding: "utf8" }).filter(
112
- (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")
113
- ).map((file) => import_node_path.default.join(dir, file)).filter((file) => import_node_fs.default.statSync(file).isFile()).filter((file) => file !== dbFilePath);
114
- for (const file of files) {
115
- const source = import_node_fs.default.readFileSync(file, "utf-8");
116
- const transformed = transformOtherFile({ source, path: file });
117
- import_node_fs.default.writeFileSync(
118
- file,
119
- await (0, import_prettify.default)(transformed, {
120
- parser: getPrettierParserForFile(file)
121
- })
122
- );
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);
123
139
  }
124
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
+ }
125
157
  }
126
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
+ });
@@ -34,13 +34,61 @@ __export(prismaV7Prep_yargs_exports, {
34
34
  });
35
35
  module.exports = __toCommonJS(prismaV7Prep_yargs_exports);
36
36
  var import_tasuku = __toESM(require("tasuku"));
37
- var import_prismaV7Prep = __toESM(require("./prismaV7Prep"));
37
+ var import_prismaV7Prep = require("./prismaV7Prep");
38
38
  const command = "prisma-v7-prep";
39
39
  const description = "(v2.7.x) Prepares for Prisma v7 by funneling imports through src/lib/db";
40
40
  const handler = () => {
41
41
  (0, import_tasuku.default)("Prisma v7 Prep", async ({ setError }) => {
42
42
  try {
43
- await (0, import_prismaV7Prep.default)();
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
+ });
44
92
  } catch (e) {
45
93
  setError("Failed to codemod your project \n" + e?.message);
46
94
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/codemods",
3
- "version": "3.0.0-canary.13482+ea250e347",
3
+ "version": "3.0.0-canary.13485+c6bb42be6",
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": "3.0.0-canary.13482",
33
+ "@cedarjs/project-config": "3.0.0-canary.13485",
34
34
  "@svgr/core": "8.1.0",
35
35
  "@svgr/plugin-jsx": "8.1.0",
36
36
  "@vscode/ripgrep": "1.17.0",
@@ -49,7 +49,7 @@
49
49
  "yargs": "17.7.2"
50
50
  },
51
51
  "devDependencies": {
52
- "@cedarjs/framework-tools": "3.0.0-canary.13482",
52
+ "@cedarjs/framework-tools": "3.0.0-canary.13485",
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": "ea250e347f4f786189a73ecd93c44ba4bf6bcbc1"
63
+ "gitHead": "c6bb42be6ae3fc25b8a2fd6c0e9dc94056498e5a"
64
64
  }