@cedarjs/codemods 2.7.1-next.0 → 2.8.0-rc.37
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/codemods/list.yargs.js +13 -47
- package/dist/codemods/redwood/v2.3.x/tsconfigForRouteHooks/tsconfigForRouteHooks.js +7 -37
- package/dist/codemods/redwood/v2.3.x/tsconfigForRouteHooks/tsconfigForRouteHooks.yargs.js +6 -42
- package/dist/codemods/redwood/v2.x.x/configureFastify/configureFastify.js +3 -23
- package/dist/codemods/redwood/v2.x.x/configureFastify/configureFastify.yargs.js +22 -58
- package/dist/codemods/redwood/v2.x.x/updateResolverTypes/updateResolverTypes.js +6 -26
- package/dist/codemods/redwood/v2.x.x/updateResolverTypes/updateResolverTypes.yargs.js +12 -48
- package/dist/codemods/redwood/v4.2.x/updateClerkGetCurrentUser/updateClerkGetCurrentUser.js +3 -23
- package/dist/codemods/redwood/v4.2.x/updateClerkGetCurrentUser/updateClerkGetCurrentUser.yargs.js +15 -48
- package/dist/codemods/redwood/v4.x.x/useArmor/useArmor.js +3 -23
- package/dist/codemods/redwood/v4.x.x/useArmor/useArmor.yargs.js +12 -48
- package/dist/codemods/redwood/v5.x.x/cellQueryResult/cellQueryResult.js +3 -23
- package/dist/codemods/redwood/v5.x.x/cellQueryResult/cellQueryResult.yargs.js +10 -46
- package/dist/codemods/redwood/v5.x.x/detectEmptyCells/detectEmptyCells.js +12 -31
- package/dist/codemods/redwood/v5.x.x/detectEmptyCells/detectEmptyCells.yargs.js +6 -42
- package/dist/codemods/redwood/v5.x.x/renameValidateWith/renameValidateWith.js +3 -23
- package/dist/codemods/redwood/v5.x.x/renameValidateWith/renameValidateWith.yargs.js +12 -48
- package/dist/codemods/redwood/v5.x.x/updateAuth0ToV2/updateAuth0ToV2.js +3 -23
- package/dist/codemods/redwood/v5.x.x/updateAuth0ToV2/updateAuth0ToV2.yargs.js +15 -51
- package/dist/codemods/redwood/v5.x.x/updateNodeEngineTo18/updateNodeEngineTo18.js +8 -42
- package/dist/codemods/redwood/v5.x.x/updateNodeEngineTo18/updateNodeEngineTo18.yargs.js +6 -42
- package/dist/codemods/redwood/v5.x.x/upgradeToReact18/upgradeToReact18.js +20 -56
- package/dist/codemods/redwood/v5.x.x/upgradeToReact18/upgradeToReact18.yargs.js +14 -46
- package/dist/codemods/redwood/v6.x.x/changeGlobalToGlobalThis/changeGlobalToGlobalThis.js +3 -23
- package/dist/codemods/redwood/v6.x.x/changeGlobalToGlobalThis/changeGlobalToGlobalThis.yargs.js +15 -48
- package/dist/codemods/redwood/v6.x.x/convertJsToJsx/convertJsToJsx.js +5 -35
- package/dist/codemods/redwood/v6.x.x/convertJsToJsx/convertJsToJsx.yargs.js +10 -46
- package/dist/codemods/redwood/v6.x.x/entryClientNullCheck/entryClientNullCheck.js +3 -23
- package/dist/codemods/redwood/v6.x.x/entryClientNullCheck/entryClientNullCheck.yargs.js +12 -48
- package/dist/codemods/redwood/v6.x.x/processEnvDotNotation/processEnvDotNotation.js +3 -23
- package/dist/codemods/redwood/v6.x.x/processEnvDotNotation/processEnvDotNotation.yargs.js +12 -48
- package/dist/codemods/redwood/v6.x.x/replaceComponentSvgs/replaceComponentSvgs.js +20 -50
- package/dist/codemods/redwood/v6.x.x/replaceComponentSvgs/replaceComponentSvgs.yargs.js +12 -48
- package/dist/codemods/redwood/v6.x.x/updateDevFatalErrorPage/updateDevFatalErrorPage.js +15 -49
- package/dist/codemods/redwood/v6.x.x/updateDevFatalErrorPage/updateDevFatalErrorPage.yargs.js +6 -42
- package/dist/codemods/redwood/v6.x.x/updateThemeConfig/updateThemeConfig.js +3 -23
- package/dist/codemods/redwood/v6.x.x/updateThemeConfig/updateThemeConfig.yargs.js +12 -48
- package/dist/codemods/redwood/v7.x.x/updateGraphQLConfig/updateGraphqlConfig.js +8 -42
- package/dist/codemods/redwood/v7.x.x/updateGraphQLConfig/updateGraphqlConfig.yargs.js +6 -42
- package/dist/codemods/v2.3.x/moveGeneratorTemplates/moveGeneratorTemplates.js +15 -45
- package/dist/codemods/v2.3.x/moveGeneratorTemplates/moveGeneratorTemplates.yargs.js +6 -42
- package/dist/codemods/v2.7.x/prismaV7Prep/prismaV7Prep.js +25 -57
- package/dist/codemods/v2.7.x/prismaV7Prep/prismaV7Prep.yargs.js +62 -80
- package/dist/codemods.js +24 -46
- package/dist/lib/cells.js +33 -75
- package/dist/lib/fetchFileFromTemplate.js +5 -25
- package/dist/lib/getFilesWithPattern.js +6 -36
- package/dist/lib/getRootPackageJSON.js +8 -38
- package/dist/lib/isTSProject.js +6 -36
- package/dist/lib/prettify.js +12 -42
- package/dist/lib/runTransform.js +4 -38
- package/dist/lib/ts2js.js +9 -39
- package/package.json +9 -9
|
@@ -1,54 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 moveGeneratorTemplates_yargs_exports = {};
|
|
30
|
-
__export(moveGeneratorTemplates_yargs_exports, {
|
|
31
|
-
command: () => command,
|
|
32
|
-
description: () => description,
|
|
33
|
-
handler: () => handler
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(moveGeneratorTemplates_yargs_exports);
|
|
36
|
-
var import_tasuku = __toESM(require("tasuku"));
|
|
37
|
-
var import_moveGeneratorTemplates = __toESM(require("./moveGeneratorTemplates"));
|
|
1
|
+
import task from "tasuku";
|
|
2
|
+
import moveGeneratorTemplates from "./moveGeneratorTemplates.js";
|
|
38
3
|
const command = "move-generator-templates";
|
|
39
4
|
const description = "(v2.3.x) Moves generator templates to `/generatorTemplates`";
|
|
40
5
|
const handler = () => {
|
|
41
|
-
(
|
|
6
|
+
task("Move Generator Templates", async ({ setError }) => {
|
|
42
7
|
try {
|
|
43
|
-
await (
|
|
8
|
+
await moveGeneratorTemplates();
|
|
44
9
|
} catch (e) {
|
|
45
10
|
setError("Failed to codemod your project \n" + e?.message);
|
|
46
11
|
}
|
|
47
12
|
});
|
|
48
13
|
};
|
|
49
|
-
|
|
50
|
-
0 && (module.exports = {
|
|
14
|
+
export {
|
|
51
15
|
command,
|
|
52
16
|
description,
|
|
53
17
|
handler
|
|
54
|
-
}
|
|
18
|
+
};
|
|
@@ -1,42 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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");
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import {
|
|
4
|
+
ensurePosixPath,
|
|
5
|
+
getDataMigrationsPath,
|
|
6
|
+
getPaths
|
|
7
|
+
} from "@cedarjs/project-config";
|
|
40
8
|
const CODE_FILE_GLOB = "**/*.{ts,tsx,cts,mts,js,jsx,cjs,mjs}";
|
|
41
9
|
const PRISMA_CLIENT_REEXPORT = "export * from '@prisma/client'";
|
|
42
10
|
function insertDbReexport(source) {
|
|
@@ -55,7 +23,7 @@ function insertDbReexport(source) {
|
|
|
55
23
|
}
|
|
56
24
|
async function collectCodeFiles(dir) {
|
|
57
25
|
try {
|
|
58
|
-
return await Array.fromAsync(
|
|
26
|
+
return await Array.fromAsync(fs.promises.glob(CODE_FILE_GLOB, { cwd: dir }));
|
|
59
27
|
} catch (error) {
|
|
60
28
|
if (typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT") {
|
|
61
29
|
return [];
|
|
@@ -64,15 +32,15 @@ async function collectCodeFiles(dir) {
|
|
|
64
32
|
}
|
|
65
33
|
}
|
|
66
34
|
async function getPrismaV7PrepContext() {
|
|
67
|
-
const paths =
|
|
35
|
+
const paths = getPaths();
|
|
68
36
|
const prismaConfigPath = paths.api.prismaConfig;
|
|
69
|
-
const dataMigrationsPath = await
|
|
70
|
-
const dbPathTs =
|
|
71
|
-
const dbPathJs =
|
|
37
|
+
const dataMigrationsPath = await getDataMigrationsPath(prismaConfigPath);
|
|
38
|
+
const dbPathTs = path.join(paths.api.lib, "db.ts");
|
|
39
|
+
const dbPathJs = path.join(paths.api.lib, "db.js");
|
|
72
40
|
let dbFilePath = null;
|
|
73
|
-
if (
|
|
41
|
+
if (fs.existsSync(dbPathTs)) {
|
|
74
42
|
dbFilePath = dbPathTs;
|
|
75
|
-
} else if (
|
|
43
|
+
} else if (fs.existsSync(dbPathJs)) {
|
|
76
44
|
dbFilePath = dbPathJs;
|
|
77
45
|
}
|
|
78
46
|
return {
|
|
@@ -85,30 +53,30 @@ async function updateDbFile(dbFilePath) {
|
|
|
85
53
|
if (!dbFilePath) {
|
|
86
54
|
return "skipped";
|
|
87
55
|
}
|
|
88
|
-
const source = await
|
|
56
|
+
const source = await fs.promises.readFile(dbFilePath, "utf-8");
|
|
89
57
|
const transformed = insertDbReexport(source);
|
|
90
58
|
if (transformed === source) {
|
|
91
59
|
return "unmodified";
|
|
92
60
|
}
|
|
93
|
-
await
|
|
61
|
+
await fs.promises.writeFile(dbFilePath, transformed);
|
|
94
62
|
return "updated";
|
|
95
63
|
}
|
|
96
64
|
async function rewritePrismaImportsInDirectory(dir, dbFilePath) {
|
|
97
|
-
const scriptsDir =
|
|
98
|
-
const normalizedDbFilePath = dbFilePath ?
|
|
65
|
+
const scriptsDir = ensurePosixPath(getPaths().scripts);
|
|
66
|
+
const normalizedDbFilePath = dbFilePath ? ensurePosixPath(dbFilePath) : null;
|
|
99
67
|
const fileMatches = await collectCodeFiles(dir);
|
|
100
|
-
const files = fileMatches.map((relativePath) =>
|
|
68
|
+
const files = fileMatches.map((relativePath) => path.join(dir, relativePath)).filter((filePath) => ensurePosixPath(filePath) !== normalizedDbFilePath);
|
|
101
69
|
if (files.length === 0) {
|
|
102
70
|
return "skipped";
|
|
103
71
|
}
|
|
104
72
|
for (const filePath of files) {
|
|
105
|
-
const source = await
|
|
106
|
-
const isScriptFile =
|
|
73
|
+
const source = await fs.promises.readFile(filePath, "utf-8");
|
|
74
|
+
const isScriptFile = ensurePosixPath(filePath).startsWith(scriptsDir);
|
|
107
75
|
const importPath = isScriptFile ? "api/src/lib/db" : "src/lib/db";
|
|
108
76
|
const importPattern = /(['"])@prisma\/client\1/g;
|
|
109
77
|
const transformed = source.replace(importPattern, `$1${importPath}$1`);
|
|
110
78
|
if (transformed !== source) {
|
|
111
|
-
await
|
|
79
|
+
await fs.promises.writeFile(filePath, transformed);
|
|
112
80
|
}
|
|
113
81
|
}
|
|
114
82
|
return "updated";
|
|
@@ -126,9 +94,9 @@ async function prismaV7Prep() {
|
|
|
126
94
|
}
|
|
127
95
|
}
|
|
128
96
|
var prismaV7Prep_default = prismaV7Prep;
|
|
129
|
-
|
|
130
|
-
|
|
97
|
+
export {
|
|
98
|
+
prismaV7Prep_default as default,
|
|
131
99
|
getPrismaV7PrepContext,
|
|
132
100
|
rewritePrismaImportsInDirectory,
|
|
133
101
|
updateDbFile
|
|
134
|
-
}
|
|
102
|
+
};
|
|
@@ -1,89 +1,71 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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");
|
|
1
|
+
import task from "tasuku";
|
|
2
|
+
import {
|
|
3
|
+
getPrismaV7PrepContext,
|
|
4
|
+
rewritePrismaImportsInDirectory,
|
|
5
|
+
updateDbFile
|
|
6
|
+
} from "./prismaV7Prep.js";
|
|
38
7
|
const command = "prisma-v7-prep";
|
|
39
8
|
const description = "(v2.7.x) Prepares for Prisma v7 by funneling imports through src/lib/db";
|
|
40
9
|
const handler = async () => {
|
|
41
|
-
const context = await
|
|
42
|
-
await
|
|
43
|
-
task2(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
10
|
+
const context = await getPrismaV7PrepContext();
|
|
11
|
+
await task("Prisma v7 Prep", async ({ task: task2 }) => {
|
|
12
|
+
await task2.group(
|
|
13
|
+
(task3) => [
|
|
14
|
+
task3("Add api/src/lib/db re-export", async ({ setOutput }) => {
|
|
15
|
+
const result = await updateDbFile(context.dbFilePath);
|
|
16
|
+
if (result === "skipped") {
|
|
17
|
+
setOutput(
|
|
18
|
+
"Skipped (no api/src/lib/db.ts or api/src/lib/db.js found)"
|
|
19
|
+
);
|
|
20
|
+
return;
|
|
21
|
+
} else if (result === "unmodified") {
|
|
22
|
+
setOutput("Skipped (no changes needed)");
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
setOutput(`Updated ${context.dbFilePath}`);
|
|
26
|
+
}),
|
|
27
|
+
task3(
|
|
28
|
+
"Rewrite imports in api/src",
|
|
29
|
+
() => rewritePrismaImportsInDirectory(
|
|
30
|
+
context.paths.api.src,
|
|
31
|
+
context.dbFilePath
|
|
32
|
+
)
|
|
33
|
+
),
|
|
34
|
+
task3(
|
|
35
|
+
"Rewrite imports in api/db/dataMigrations",
|
|
36
|
+
async ({ setOutput }) => {
|
|
37
|
+
const result = await rewritePrismaImportsInDirectory(
|
|
38
|
+
context.dataMigrationsPath,
|
|
39
|
+
context.dbFilePath
|
|
40
|
+
);
|
|
41
|
+
if (result === "skipped") {
|
|
42
|
+
setOutput("No data migrations found");
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
),
|
|
46
|
+
task3("Rewrite imports in scripts", async ({ setOutput }) => {
|
|
47
|
+
const result = await rewritePrismaImportsInDirectory(
|
|
48
|
+
context.paths.scripts,
|
|
49
|
+
context.dbFilePath
|
|
50
|
+
);
|
|
51
|
+
if (result === "skipped") {
|
|
52
|
+
setOutput("Skipped (directory missing or empty)");
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
],
|
|
56
|
+
{
|
|
57
|
+
concurrency: Infinity
|
|
68
58
|
}
|
|
69
|
-
|
|
70
|
-
task2("
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
context.dbFilePath
|
|
59
|
+
);
|
|
60
|
+
await task2("One more thing...", async ({ setOutput }) => {
|
|
61
|
+
setOutput(
|
|
62
|
+
"\n\nSome imports (most likely in your scenario files) might now be\nin the wrong order. If that's the case, you can run\n`yarn cedar lint --fix` to reorder them."
|
|
74
63
|
);
|
|
75
|
-
|
|
76
|
-
|
|
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
|
-
);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
83
66
|
};
|
|
84
|
-
|
|
85
|
-
0 && (module.exports = {
|
|
67
|
+
export {
|
|
86
68
|
command,
|
|
87
69
|
description,
|
|
88
70
|
handler
|
|
89
|
-
}
|
|
71
|
+
};
|
package/dist/codemods.js
CHANGED
|
@@ -1,50 +1,28 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
var v2TsconfigForRouteHooks = __toESM(require("./codemods/redwood/v2.3.x/tsconfigForRouteHooks/tsconfigForRouteHooks.yargs.js"));
|
|
27
|
-
var v2ConfigureFastify = __toESM(require("./codemods/redwood/v2.x.x/configureFastify/configureFastify.yargs.js"));
|
|
28
|
-
var v2UpdateResolverTypes = __toESM(require("./codemods/redwood/v2.x.x/updateResolverTypes/updateResolverTypes.yargs.js"));
|
|
29
|
-
var v4UpdateClerkGetCurrentUser = __toESM(require("./codemods/redwood/v4.2.x/updateClerkGetCurrentUser/updateClerkGetCurrentUser.yargs.js"));
|
|
30
|
-
var v4UseArmor = __toESM(require("./codemods/redwood/v4.x.x/useArmor/useArmor.yargs.js"));
|
|
31
|
-
var v5CellQueryResult = __toESM(require("./codemods/redwood/v5.x.x/cellQueryResult/cellQueryResult.yargs.js"));
|
|
32
|
-
var v5DetectEmptyCells = __toESM(require("./codemods/redwood/v5.x.x/detectEmptyCells/detectEmptyCells.yargs.js"));
|
|
33
|
-
var v5RenameValidateWith = __toESM(require("./codemods/redwood/v5.x.x/renameValidateWith/renameValidateWith.yargs.js"));
|
|
34
|
-
var v5UpdateAuth0ToV2 = __toESM(require("./codemods/redwood/v5.x.x/updateAuth0ToV2/updateAuth0ToV2.yargs.js"));
|
|
35
|
-
var v5UpdateNodeEngineTo18 = __toESM(require("./codemods/redwood/v5.x.x/updateNodeEngineTo18/updateNodeEngineTo18.yargs.js"));
|
|
36
|
-
var v5UpgradeToReact18 = __toESM(require("./codemods/redwood/v5.x.x/upgradeToReact18/upgradeToReact18.yargs.js"));
|
|
37
|
-
var v6GlobalThis = __toESM(require("./codemods/redwood/v6.x.x/changeGlobalToGlobalThis/changeGlobalToGlobalThis.yargs.js"));
|
|
38
|
-
var v6Jsx = __toESM(require("./codemods/redwood/v6.x.x/convertJsToJsx/convertJsToJsx.yargs.js"));
|
|
39
|
-
var v6EntryClient = __toESM(require("./codemods/redwood/v6.x.x/entryClientNullCheck/entryClientNullCheck.yargs.js"));
|
|
40
|
-
var v6EnvDot = __toESM(require("./codemods/redwood/v6.x.x/processEnvDotNotation/processEnvDotNotation.yargs.js"));
|
|
41
|
-
var v6Svgs = __toESM(require("./codemods/redwood/v6.x.x/replaceComponentSvgs/replaceComponentSvgs.yargs.js"));
|
|
42
|
-
var v6DevFatalErrorPage = __toESM(require("./codemods/redwood/v6.x.x/updateDevFatalErrorPage/updateDevFatalErrorPage.yargs.js"));
|
|
43
|
-
var v6ThemeConfig = __toESM(require("./codemods/redwood/v6.x.x/updateThemeConfig/updateThemeConfig.yargs.js"));
|
|
44
|
-
var v7Gql = __toESM(require("./codemods/redwood/v7.x.x/updateGraphQLConfig/updateGraphqlConfig.yargs.js"));
|
|
45
|
-
var v2MoveGeneratorTemplates = __toESM(require("./codemods/v2.3.x/moveGeneratorTemplates/moveGeneratorTemplates.yargs.js"));
|
|
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) => {
|
|
2
|
+
import { hideBin } from "yargs/helpers";
|
|
3
|
+
import yargs from "yargs/yargs";
|
|
4
|
+
import * as v2TsconfigForRouteHooks from "./codemods/redwood/v2.3.x/tsconfigForRouteHooks/tsconfigForRouteHooks.yargs.js";
|
|
5
|
+
import * as v2ConfigureFastify from "./codemods/redwood/v2.x.x/configureFastify/configureFastify.yargs.js";
|
|
6
|
+
import * as v2UpdateResolverTypes from "./codemods/redwood/v2.x.x/updateResolverTypes/updateResolverTypes.yargs.js";
|
|
7
|
+
import * as v4UpdateClerkGetCurrentUser from "./codemods/redwood/v4.2.x/updateClerkGetCurrentUser/updateClerkGetCurrentUser.yargs.js";
|
|
8
|
+
import * as v4UseArmor from "./codemods/redwood/v4.x.x/useArmor/useArmor.yargs.js";
|
|
9
|
+
import * as v5CellQueryResult from "./codemods/redwood/v5.x.x/cellQueryResult/cellQueryResult.yargs.js";
|
|
10
|
+
import * as v5DetectEmptyCells from "./codemods/redwood/v5.x.x/detectEmptyCells/detectEmptyCells.yargs.js";
|
|
11
|
+
import * as v5RenameValidateWith from "./codemods/redwood/v5.x.x/renameValidateWith/renameValidateWith.yargs.js";
|
|
12
|
+
import * as v5UpdateAuth0ToV2 from "./codemods/redwood/v5.x.x/updateAuth0ToV2/updateAuth0ToV2.yargs.js";
|
|
13
|
+
import * as v5UpdateNodeEngineTo18 from "./codemods/redwood/v5.x.x/updateNodeEngineTo18/updateNodeEngineTo18.yargs.js";
|
|
14
|
+
import * as v5UpgradeToReact18 from "./codemods/redwood/v5.x.x/upgradeToReact18/upgradeToReact18.yargs.js";
|
|
15
|
+
import * as v6GlobalThis from "./codemods/redwood/v6.x.x/changeGlobalToGlobalThis/changeGlobalToGlobalThis.yargs.js";
|
|
16
|
+
import * as v6Jsx from "./codemods/redwood/v6.x.x/convertJsToJsx/convertJsToJsx.yargs.js";
|
|
17
|
+
import * as v6EntryClient from "./codemods/redwood/v6.x.x/entryClientNullCheck/entryClientNullCheck.yargs.js";
|
|
18
|
+
import * as v6EnvDot from "./codemods/redwood/v6.x.x/processEnvDotNotation/processEnvDotNotation.yargs.js";
|
|
19
|
+
import * as v6Svgs from "./codemods/redwood/v6.x.x/replaceComponentSvgs/replaceComponentSvgs.yargs.js";
|
|
20
|
+
import * as v6DevFatalErrorPage from "./codemods/redwood/v6.x.x/updateDevFatalErrorPage/updateDevFatalErrorPage.yargs.js";
|
|
21
|
+
import * as v6ThemeConfig from "./codemods/redwood/v6.x.x/updateThemeConfig/updateThemeConfig.yargs.js";
|
|
22
|
+
import * as v7Gql from "./codemods/redwood/v7.x.x/updateGraphQLConfig/updateGraphqlConfig.yargs.js";
|
|
23
|
+
import * as v2MoveGeneratorTemplates from "./codemods/v2.3.x/moveGeneratorTemplates/moveGeneratorTemplates.yargs.js";
|
|
24
|
+
import * as v2PrismaV7Prep from "./codemods/v2.7.x/prismaV7Prep/prismaV7Prep.yargs.js";
|
|
25
|
+
yargs(hideBin(process.argv)).scriptName("").command(v2MoveGeneratorTemplates).command(v2PrismaV7Prep).command("redwood", "List or run Redwood codemods", (yargs2) => {
|
|
48
26
|
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();
|
|
49
27
|
}).demandCommand().epilog(
|
|
50
28
|
[
|
package/dist/lib/cells.js
CHANGED
|
@@ -1,54 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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 cells_exports = {};
|
|
30
|
-
__export(cells_exports, {
|
|
31
|
-
fileToAst: () => fileToAst,
|
|
32
|
-
findCells: () => findCells,
|
|
33
|
-
getCellGqlQuery: () => getCellGqlQuery,
|
|
34
|
-
getNamedExports: () => getNamedExports,
|
|
35
|
-
hasDefaultExport: () => hasDefaultExport,
|
|
36
|
-
isCellFile: () => isCellFile,
|
|
37
|
-
isFileInsideFolder: () => isFileInsideFolder,
|
|
38
|
-
parseDocumentAST: () => parseDocumentAST,
|
|
39
|
-
parseGqlQueryToAst: () => parseGqlQueryToAst
|
|
40
|
-
});
|
|
41
|
-
module.exports = __toCommonJS(cells_exports);
|
|
42
|
-
var import_node_fs = __toESM(require("node:fs"));
|
|
43
|
-
var import_path = __toESM(require("path"));
|
|
44
|
-
var import_core = require("@babel/core");
|
|
45
|
-
var import_parser = require("@babel/parser");
|
|
46
|
-
var import_traverse = __toESM(require("@babel/traverse"));
|
|
47
|
-
var import_fast_glob = __toESM(require("fast-glob"));
|
|
48
|
-
var import_graphql = require("graphql");
|
|
49
|
-
var import_project_config = require("@cedarjs/project-config");
|
|
50
|
-
const findCells = (cwd = (0, import_project_config.getPaths)().web.src) => {
|
|
51
|
-
const modules = import_fast_glob.default.sync("**/*Cell.{js,jsx,ts,tsx}", {
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { types } from "@babel/core";
|
|
4
|
+
import { parse as babelParse } from "@babel/parser";
|
|
5
|
+
import traverse from "@babel/traverse";
|
|
6
|
+
import fg from "fast-glob";
|
|
7
|
+
import { Kind, parse, visit } from "graphql";
|
|
8
|
+
import { getPaths } from "@cedarjs/project-config";
|
|
9
|
+
const findCells = (cwd = getPaths().web.src) => {
|
|
10
|
+
const modules = fg.sync("**/*Cell.{js,jsx,ts,tsx}", {
|
|
52
11
|
cwd,
|
|
53
12
|
absolute: true,
|
|
54
13
|
ignore: ["node_modules"]
|
|
@@ -56,8 +15,8 @@ const findCells = (cwd = (0, import_project_config.getPaths)().web.src) => {
|
|
|
56
15
|
return modules.filter(isCellFile);
|
|
57
16
|
};
|
|
58
17
|
const isCellFile = (p) => {
|
|
59
|
-
const { dir, name } =
|
|
60
|
-
if (!isFileInsideFolder(p,
|
|
18
|
+
const { dir, name } = path.parse(p);
|
|
19
|
+
if (!isFileInsideFolder(p, getPaths().web.src)) {
|
|
61
20
|
return false;
|
|
62
21
|
}
|
|
63
22
|
if (!dir.endsWith(name)) {
|
|
@@ -67,18 +26,18 @@ const isCellFile = (p) => {
|
|
|
67
26
|
if (hasDefaultExport(ast)) {
|
|
68
27
|
return false;
|
|
69
28
|
}
|
|
70
|
-
const
|
|
71
|
-
const exportedQUERY =
|
|
72
|
-
const exportedSuccess =
|
|
29
|
+
const exports = getNamedExports(ast);
|
|
30
|
+
const exportedQUERY = exports.findIndex((v) => v.name === "QUERY") !== -1;
|
|
31
|
+
const exportedSuccess = exports.findIndex((v) => v.name === "Success") !== -1;
|
|
73
32
|
if (!exportedQUERY && !exportedSuccess) {
|
|
74
33
|
return false;
|
|
75
34
|
}
|
|
76
35
|
return true;
|
|
77
36
|
};
|
|
78
37
|
const isFileInsideFolder = (filePath, folderPath) => {
|
|
79
|
-
const { dir } =
|
|
80
|
-
const relativePathFromFolder =
|
|
81
|
-
if (!relativePathFromFolder || relativePathFromFolder.startsWith("..") ||
|
|
38
|
+
const { dir } = path.parse(filePath);
|
|
39
|
+
const relativePathFromFolder = path.relative(folderPath, dir);
|
|
40
|
+
if (!relativePathFromFolder || relativePathFromFolder.startsWith("..") || path.isAbsolute(relativePathFromFolder)) {
|
|
82
41
|
return false;
|
|
83
42
|
} else {
|
|
84
43
|
return true;
|
|
@@ -86,7 +45,7 @@ const isFileInsideFolder = (filePath, folderPath) => {
|
|
|
86
45
|
};
|
|
87
46
|
const hasDefaultExport = (ast) => {
|
|
88
47
|
let exported = false;
|
|
89
|
-
(
|
|
48
|
+
traverse(ast, {
|
|
90
49
|
ExportDefaultDeclaration() {
|
|
91
50
|
exported = true;
|
|
92
51
|
return;
|
|
@@ -96,7 +55,7 @@ const hasDefaultExport = (ast) => {
|
|
|
96
55
|
};
|
|
97
56
|
const getNamedExports = (ast) => {
|
|
98
57
|
const namedExports = [];
|
|
99
|
-
(
|
|
58
|
+
traverse(ast, {
|
|
100
59
|
ExportNamedDeclaration(path2) {
|
|
101
60
|
const specifiers = path2.node?.specifiers;
|
|
102
61
|
if (specifiers.length) {
|
|
@@ -135,8 +94,8 @@ const getNamedExports = (ast) => {
|
|
|
135
94
|
return namedExports;
|
|
136
95
|
};
|
|
137
96
|
const fileToAst = (filePath) => {
|
|
138
|
-
const code =
|
|
139
|
-
const isJsxFile =
|
|
97
|
+
const code = fs.readFileSync(filePath, "utf-8");
|
|
98
|
+
const isJsxFile = path.extname(filePath).match(/[jt]sx$/) || isFileInsideFolder(filePath, getPaths().web.base);
|
|
140
99
|
const plugins = [
|
|
141
100
|
"typescript",
|
|
142
101
|
"nullishCoalescingOperator",
|
|
@@ -144,7 +103,7 @@ const fileToAst = (filePath) => {
|
|
|
144
103
|
isJsxFile && "jsx"
|
|
145
104
|
].filter(Boolean);
|
|
146
105
|
try {
|
|
147
|
-
return (
|
|
106
|
+
return babelParse(code, {
|
|
148
107
|
sourceType: "module",
|
|
149
108
|
plugins
|
|
150
109
|
});
|
|
@@ -155,11 +114,11 @@ const fileToAst = (filePath) => {
|
|
|
155
114
|
};
|
|
156
115
|
const getCellGqlQuery = (ast) => {
|
|
157
116
|
let cellQuery = void 0;
|
|
158
|
-
(
|
|
117
|
+
traverse(ast, {
|
|
159
118
|
ExportNamedDeclaration({ node }) {
|
|
160
|
-
if (node.exportKind === "value" &&
|
|
119
|
+
if (node.exportKind === "value" && types.isVariableDeclaration(node.declaration)) {
|
|
161
120
|
const exportedQueryNode = node.declaration.declarations.find((d) => {
|
|
162
|
-
return
|
|
121
|
+
return types.isIdentifier(d.id) && d.id.name === "QUERY" && types.isTaggedTemplateExpression(d.init);
|
|
163
122
|
});
|
|
164
123
|
if (exportedQueryNode) {
|
|
165
124
|
const templateExpression = exportedQueryNode.init;
|
|
@@ -172,12 +131,12 @@ const getCellGqlQuery = (ast) => {
|
|
|
172
131
|
return cellQuery;
|
|
173
132
|
};
|
|
174
133
|
const parseGqlQueryToAst = (gqlQuery) => {
|
|
175
|
-
const ast =
|
|
134
|
+
const ast = parse(gqlQuery);
|
|
176
135
|
return parseDocumentAST(ast);
|
|
177
136
|
};
|
|
178
137
|
const parseDocumentAST = (document) => {
|
|
179
138
|
const operations = [];
|
|
180
|
-
|
|
139
|
+
visit(document, {
|
|
181
140
|
OperationDefinition(node) {
|
|
182
141
|
const fields = [];
|
|
183
142
|
node.selectionSet.selections.forEach((field) => {
|
|
@@ -202,12 +161,12 @@ const getFields = (field) => {
|
|
|
202
161
|
const lookAtFieldNode = (node) => {
|
|
203
162
|
node.selectionSet?.selections.forEach((subField) => {
|
|
204
163
|
switch (subField.kind) {
|
|
205
|
-
case
|
|
164
|
+
case Kind.FIELD:
|
|
206
165
|
obj[field.name.value].push(getFields(subField));
|
|
207
166
|
break;
|
|
208
|
-
case
|
|
167
|
+
case Kind.FRAGMENT_SPREAD:
|
|
209
168
|
break;
|
|
210
|
-
case
|
|
169
|
+
case Kind.INLINE_FRAGMENT:
|
|
211
170
|
lookAtFieldNode(subField);
|
|
212
171
|
}
|
|
213
172
|
});
|
|
@@ -216,8 +175,7 @@ const getFields = (field) => {
|
|
|
216
175
|
return obj;
|
|
217
176
|
}
|
|
218
177
|
};
|
|
219
|
-
|
|
220
|
-
0 && (module.exports = {
|
|
178
|
+
export {
|
|
221
179
|
fileToAst,
|
|
222
180
|
findCells,
|
|
223
181
|
getCellGqlQuery,
|
|
@@ -227,4 +185,4 @@ const getFields = (field) => {
|
|
|
227
185
|
isFileInsideFolder,
|
|
228
186
|
parseDocumentAST,
|
|
229
187
|
parseGqlQueryToAst
|
|
230
|
-
}
|
|
188
|
+
};
|