@cedarjs/codemods 2.6.1-next.0 → 2.6.1-next.115

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
@@ -235,8 +235,8 @@ yarn build
235
235
  The CLI is meant to be run on a Cedar project (i.e. it expects you to be cd'd into a Cedar project), but you can provide it as an environment variable too!
236
236
 
237
237
  ```shell
238
- CEDAR_CWD=/path/to/rw-project node "./packages/codemods/dist/codemods.js" {your-codemod-name}
239
- # ☝️ this is the path to your rw project (not the framework!)
238
+ CEDAR_CWD=/path/to/cedar-project node ./packages/codemods/dist/codemods.js {your-codemod-name}
239
+ # ☝️ this is the path to your Cedar project (not the framework!)
240
240
  ```
241
241
 
242
242
  > **💡 Tip**
@@ -0,0 +1,134 @@
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_project_config = require("@cedarjs/project-config");
40
+ const CODE_FILE_GLOB = "**/*.{ts,tsx,cts,mts,js,jsx,cjs,mjs}";
41
+ const PRISMA_CLIENT_REEXPORT = "export * from '@prisma/client'";
42
+ function insertDbReexport(source) {
43
+ if (source.includes(PRISMA_CLIENT_REEXPORT)) {
44
+ return source;
45
+ }
46
+ const lines = source.split("\n");
47
+ const prismaImportIndex = lines.findIndex(
48
+ (line) => /from\s+['"]@prisma\/client['"]/.test(line)
49
+ );
50
+ if (prismaImportIndex < 0) {
51
+ throw new Error("Unexpected src/lib/db content");
52
+ }
53
+ lines.splice(prismaImportIndex + 1, 0, "", PRISMA_CLIENT_REEXPORT);
54
+ return lines.join("\n");
55
+ }
56
+ async function collectCodeFiles(dir) {
57
+ try {
58
+ return await Array.fromAsync(import_node_fs.default.promises.glob(CODE_FILE_GLOB, { cwd: dir }));
59
+ } catch (error) {
60
+ if (typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT") {
61
+ return [];
62
+ }
63
+ throw error;
64
+ }
65
+ }
66
+ async function getPrismaV7PrepContext() {
67
+ const paths = (0, import_project_config.getPaths)();
68
+ const prismaConfigPath = paths.api.prismaConfig;
69
+ const dataMigrationsPath = await (0, import_project_config.getDataMigrationsPath)(prismaConfigPath);
70
+ const dbPathTs = import_node_path.default.join(paths.api.lib, "db.ts");
71
+ const dbPathJs = import_node_path.default.join(paths.api.lib, "db.js");
72
+ let dbFilePath = null;
73
+ if (import_node_fs.default.existsSync(dbPathTs)) {
74
+ dbFilePath = dbPathTs;
75
+ } else if (import_node_fs.default.existsSync(dbPathJs)) {
76
+ dbFilePath = dbPathJs;
77
+ }
78
+ return {
79
+ dataMigrationsPath,
80
+ dbFilePath,
81
+ paths
82
+ };
83
+ }
84
+ async function updateDbFile(dbFilePath) {
85
+ if (!dbFilePath) {
86
+ return "skipped";
87
+ }
88
+ const source = await import_node_fs.default.promises.readFile(dbFilePath, "utf-8");
89
+ const transformed = insertDbReexport(source);
90
+ if (transformed === source) {
91
+ return "unmodified";
92
+ }
93
+ await import_node_fs.default.promises.writeFile(dbFilePath, transformed);
94
+ return "updated";
95
+ }
96
+ async function rewritePrismaImportsInDirectory(dir, dbFilePath) {
97
+ const scriptsDir = (0, import_project_config.ensurePosixPath)((0, import_project_config.getPaths)().scripts);
98
+ const normalizedDbFilePath = dbFilePath ? (0, import_project_config.ensurePosixPath)(dbFilePath) : null;
99
+ const fileMatches = await collectCodeFiles(dir);
100
+ const files = fileMatches.map((relativePath) => import_node_path.default.join(dir, relativePath)).filter((filePath) => (0, import_project_config.ensurePosixPath)(filePath) !== normalizedDbFilePath);
101
+ if (files.length === 0) {
102
+ return "skipped";
103
+ }
104
+ for (const filePath of files) {
105
+ const source = await import_node_fs.default.promises.readFile(filePath, "utf-8");
106
+ const isScriptFile = (0, import_project_config.ensurePosixPath)(filePath).startsWith(scriptsDir);
107
+ const importPath = isScriptFile ? "api/src/lib/db" : "src/lib/db";
108
+ const importPattern = /(['"])@prisma\/client\1/g;
109
+ const transformed = source.replace(importPattern, `$1${importPath}$1`);
110
+ if (transformed !== source) {
111
+ await import_node_fs.default.promises.writeFile(filePath, transformed);
112
+ }
113
+ }
114
+ return "updated";
115
+ }
116
+ async function prismaV7Prep() {
117
+ const context = await getPrismaV7PrepContext();
118
+ await updateDbFile(context.dbFilePath);
119
+ const dirsToTransform = [
120
+ context.paths.api.src,
121
+ context.dataMigrationsPath,
122
+ context.paths.scripts
123
+ ];
124
+ for (const dir of dirsToTransform) {
125
+ await rewritePrismaImportsInDirectory(dir, context.dbFilePath);
126
+ }
127
+ }
128
+ var prismaV7Prep_default = prismaV7Prep;
129
+ // Annotate the CommonJS export names for ESM import in node:
130
+ 0 && (module.exports = {
131
+ getPrismaV7PrepContext,
132
+ rewritePrismaImportsInDirectory,
133
+ updateDbFile
134
+ });
@@ -0,0 +1,89 @@
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 = async () => {
41
+ const context = await (0, import_prismaV7Prep.getPrismaV7PrepContext)();
42
+ await import_tasuku.default.group((task2) => [
43
+ task2("Add api/src/lib/db re-export", async ({ setOutput }) => {
44
+ const result = await (0, import_prismaV7Prep.updateDbFile)(context.dbFilePath);
45
+ if (result === "skipped") {
46
+ setOutput("Skipped (no api/src/lib/db.ts or api/src/lib/db.js found)");
47
+ return;
48
+ } else if (result === "unmodified") {
49
+ setOutput("Skipped (no changes needed)");
50
+ return;
51
+ }
52
+ setOutput(`Updated ${context.dbFilePath}`);
53
+ }),
54
+ task2(
55
+ "Rewrite imports in api/src",
56
+ () => (0, import_prismaV7Prep.rewritePrismaImportsInDirectory)(
57
+ context.paths.api.src,
58
+ context.dbFilePath
59
+ )
60
+ ),
61
+ task2("Rewrite imports in api/db/dataMigrations", async ({ setOutput }) => {
62
+ const result = await (0, import_prismaV7Prep.rewritePrismaImportsInDirectory)(
63
+ context.dataMigrationsPath,
64
+ context.dbFilePath
65
+ );
66
+ if (result === "skipped") {
67
+ setOutput("Skipped (directory missing or empty)");
68
+ }
69
+ }),
70
+ task2("Rewrite imports in scripts", async ({ setOutput }) => {
71
+ const result = await (0, import_prismaV7Prep.rewritePrismaImportsInDirectory)(
72
+ context.paths.scripts,
73
+ context.dbFilePath
74
+ );
75
+ if (result === "skipped") {
76
+ setOutput("Skipped (directory missing or empty)");
77
+ }
78
+ })
79
+ ]);
80
+ console.log(
81
+ "Some imports might be in the wrong order. If that's the case, you can run `yarn cedar lint --fix` to reorder them."
82
+ );
83
+ };
84
+ // Annotate the CommonJS export names for ESM import in node:
85
+ 0 && (module.exports = {
86
+ command,
87
+ description,
88
+ handler
89
+ });
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
- import_yargs.default.scriptName("").command(v2MoveGeneratorTemplates).command("redwood", "List or run Redwood codemods", (yargs2) => {
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
  [
@@ -31,12 +31,17 @@ __export(prettify_exports, {
31
31
  default: () => prettify_default
32
32
  });
33
33
  module.exports = __toCommonJS(prettify_exports);
34
- var import_path = __toESM(require("path"));
34
+ var import_node_fs = __toESM(require("node:fs"));
35
+ var import_node_path = __toESM(require("node:path"));
35
36
  var import_prettier = require("prettier");
36
37
  var import_project_config = require("@cedarjs/project-config");
37
38
  const getPrettierConfig = async () => {
39
+ const basePath = (0, import_project_config.getPaths)().base;
40
+ const prettierConfigCjsPath = import_node_path.default.join(basePath, "prettier.config.cjs");
41
+ const prettierConfigMjsPath = import_node_path.default.join(basePath, "prettier.config.mjs");
42
+ const prettierConfigPath = import_node_fs.default.existsSync(prettierConfigCjsPath) ? prettierConfigCjsPath : prettierConfigMjsPath;
38
43
  try {
39
- const { default: prettierConfig } = await import(`file://${import_path.default.join((0, import_project_config.getPaths)().base, "prettier.config.cjs")}`);
44
+ const { default: prettierConfig } = await import(`file://${prettierConfigPath}`);
40
45
  return prettierConfig;
41
46
  } catch {
42
47
  return void 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/codemods",
3
- "version": "2.6.1-next.0+30211aa9a",
3
+ "version": "2.6.1-next.115+b00f80537",
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.0+30211aa9a",
33
+ "@cedarjs/project-config": "2.6.1-next.115+b00f80537",
34
34
  "@svgr/core": "8.1.0",
35
35
  "@svgr/plugin-jsx": "8.1.0",
36
36
  "@vscode/ripgrep": "1.17.0",
@@ -40,25 +40,27 @@
40
40
  "deepmerge": "4.3.1",
41
41
  "execa": "5.1.1",
42
42
  "fast-glob": "3.3.3",
43
- "graphql": "16.12.0",
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.8",
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.1",
52
+ "@cedarjs/framework-tools": "2.6.1-next.115",
53
53
  "@types/babel__core": "7.20.5",
54
54
  "@types/jscodeshift": "0.12.0",
55
55
  "@types/yargs": "17.0.35",
56
+ "memfs": "4.56.10",
56
57
  "publint": "0.3.17",
58
+ "ts-dedent": "2.2.0",
57
59
  "tsx": "4.21.0",
58
60
  "vitest": "3.2.4"
59
61
  },
60
62
  "publishConfig": {
61
63
  "access": "public"
62
64
  },
63
- "gitHead": "30211aa9a59a86cf7e631071f0f67df976f6acfb"
65
+ "gitHead": "b00f80537b951b64c7b627dc2efbbe1ed2f3ea40"
64
66
  }