@cedarjs/codemods 0.0.4
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/LICENSE +21 -0
- package/README.md +297 -0
- package/dist/codemods/list.yargs.js +67 -0
- package/dist/codemods/v2.3.x/tsconfigForRouteHooks/tsconfigForRouteHooks.js +74 -0
- package/dist/codemods/v2.3.x/tsconfigForRouteHooks/tsconfigForRouteHooks.yargs.js +51 -0
- package/dist/codemods/v2.x.x/configureFastify/configureFastify.js +43 -0
- package/dist/codemods/v2.x.x/configureFastify/configureFastify.yargs.js +83 -0
- package/dist/codemods/v2.x.x/updateResolverTypes/updateResolverTypes.js +77 -0
- package/dist/codemods/v2.x.x/updateResolverTypes/updateResolverTypes.yargs.js +62 -0
- package/dist/codemods/v4.2.x/updateClerkGetCurrentUser/updateClerkGetCurrentUser.js +71 -0
- package/dist/codemods/v4.2.x/updateClerkGetCurrentUser/updateClerkGetCurrentUser.yargs.js +58 -0
- package/dist/codemods/v4.x.x/useArmor/useArmor.js +63 -0
- package/dist/codemods/v4.x.x/useArmor/useArmor.yargs.js +62 -0
- package/dist/codemods/v5.x.x/cellQueryResult/cellQueryResult.js +110 -0
- package/dist/codemods/v5.x.x/cellQueryResult/cellQueryResult.yargs.js +58 -0
- package/dist/codemods/v5.x.x/detectEmptyCells/detectEmptyCells.js +88 -0
- package/dist/codemods/v5.x.x/detectEmptyCells/detectEmptyCells.yargs.js +59 -0
- package/dist/codemods/v5.x.x/renameValidateWith/renameValidateWith.js +32 -0
- package/dist/codemods/v5.x.x/renameValidateWith/renameValidateWith.yargs.js +65 -0
- package/dist/codemods/v5.x.x/updateAuth0ToV2/updateAuth0ToV2.js +48 -0
- package/dist/codemods/v5.x.x/updateAuth0ToV2/updateAuth0ToV2.yargs.js +68 -0
- package/dist/codemods/v5.x.x/updateNodeEngineTo18/updateNodeEngineTo18.js +46 -0
- package/dist/codemods/v5.x.x/updateNodeEngineTo18/updateNodeEngineTo18.yargs.js +57 -0
- package/dist/codemods/v5.x.x/upgradeToReact18/upgradeToReact18.js +135 -0
- package/dist/codemods/v5.x.x/upgradeToReact18/upgradeToReact18.yargs.js +56 -0
- package/dist/codemods/v6.x.x/changeGlobalToGlobalThis/changeGlobalToGlobalThis.js +29 -0
- package/dist/codemods/v6.x.x/changeGlobalToGlobalThis/changeGlobalToGlobalThis.yargs.js +60 -0
- package/dist/codemods/v6.x.x/convertJsToJsx/convertJsToJsx.js +45 -0
- package/dist/codemods/v6.x.x/convertJsToJsx/convertJsToJsx.yargs.js +59 -0
- package/dist/codemods/v6.x.x/entryClientNullCheck/entryClientNullCheck.js +51 -0
- package/dist/codemods/v6.x.x/entryClientNullCheck/entryClientNullCheck.yargs.js +60 -0
- package/dist/codemods/v6.x.x/processEnvDotNotation/processEnvDotNotation.js +44 -0
- package/dist/codemods/v6.x.x/processEnvDotNotation/processEnvDotNotation.yargs.js +60 -0
- package/dist/codemods/v6.x.x/replaceComponentSvgs/replaceComponentSvgs.js +154 -0
- package/dist/codemods/v6.x.x/replaceComponentSvgs/replaceComponentSvgs.yargs.js +61 -0
- package/dist/codemods/v6.x.x/updateDevFatalErrorPage/updateDevFatalErrorPage.js +58 -0
- package/dist/codemods/v6.x.x/updateDevFatalErrorPage/updateDevFatalErrorPage.yargs.js +50 -0
- package/dist/codemods/v6.x.x/updateThemeConfig/updateThemeConfig.js +51 -0
- package/dist/codemods/v6.x.x/updateThemeConfig/updateThemeConfig.yargs.js +61 -0
- package/dist/codemods/v7.x.x/updateGraphQLConfig/updateGraphqlConfig.js +51 -0
- package/dist/codemods/v7.x.x/updateGraphQLConfig/updateGraphqlConfig.yargs.js +50 -0
- package/dist/codemods.js +45 -0
- package/dist/lib/cells.js +230 -0
- package/dist/lib/fetchFileFromTemplate.js +29 -0
- package/dist/lib/getFilesWithPattern.js +51 -0
- package/dist/lib/getRootPackageJSON.js +44 -0
- package/dist/lib/isTSProject.js +39 -0
- package/dist/lib/prettify.js +55 -0
- package/dist/lib/runTransform.js +76 -0
- package/dist/lib/ts2js.js +57 -0
- package/package.json +67 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var updateResolverTypes_exports = {};
|
|
20
|
+
__export(updateResolverTypes_exports, {
|
|
21
|
+
default: () => transform
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(updateResolverTypes_exports);
|
|
24
|
+
var import_jscodeshift = require("jscodeshift");
|
|
25
|
+
const isTypeReference = (typeAnnotation) => import_jscodeshift.TSTypeReference.check(typeAnnotation);
|
|
26
|
+
const getTypeName = (node) => {
|
|
27
|
+
return import_jscodeshift.Identifier.check(node.typeName) ? node.typeName.name : null;
|
|
28
|
+
};
|
|
29
|
+
const isWrappedInPartial = (node) => {
|
|
30
|
+
const typeAnnotation = node.typeAnnotation;
|
|
31
|
+
return isTypeReference(typeAnnotation) && getTypeName(typeAnnotation) === "Partial";
|
|
32
|
+
};
|
|
33
|
+
function transform(file, api) {
|
|
34
|
+
const j = api.jscodeshift;
|
|
35
|
+
const ast = j(file.source);
|
|
36
|
+
const findImportFromGqlTypes = (importName) => {
|
|
37
|
+
return ast.find(j.ImportDeclaration, {
|
|
38
|
+
source: { value: "types/graphql" }
|
|
39
|
+
}).find(j.ImportSpecifier, { imported: { name: importName } });
|
|
40
|
+
};
|
|
41
|
+
const addToGqlTypesImports = (importName) => {
|
|
42
|
+
ast.find(j.ImportDeclaration, {
|
|
43
|
+
source: { value: "types/graphql" }
|
|
44
|
+
}).forEach((importStatement) => {
|
|
45
|
+
importStatement.node.specifiers?.push(
|
|
46
|
+
j.importSpecifier(j.identifier(importName))
|
|
47
|
+
);
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
ast.find(j.TSTypeAnnotation).forEach((path) => {
|
|
51
|
+
const typeAnnotationNode = path.node;
|
|
52
|
+
if (
|
|
53
|
+
// If it's a MutationResolvers['x'] or QueryResolvers['x']
|
|
54
|
+
j.TSIndexedAccessType.check(typeAnnotationNode.typeAnnotation)
|
|
55
|
+
) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (!isWrappedInPartial(typeAnnotationNode) && isTypeReference(typeAnnotationNode.typeAnnotation)) {
|
|
59
|
+
const originalTypeName = getTypeName(typeAnnotationNode.typeAnnotation);
|
|
60
|
+
if (!originalTypeName || !originalTypeName.includes("Resolvers") || findImportFromGqlTypes(originalTypeName).length === 0 || // check if it was imported from types/graphql
|
|
61
|
+
originalTypeName.includes("RelationResolvers")) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const newTypeName = originalTypeName.replace(
|
|
65
|
+
"Resolvers",
|
|
66
|
+
"RelationResolvers"
|
|
67
|
+
);
|
|
68
|
+
console.log(`Converting ${originalTypeName} to ${newTypeName}....`);
|
|
69
|
+
path.replace(
|
|
70
|
+
j.tsTypeAnnotation(j.tsTypeReference(j.identifier(newTypeName)))
|
|
71
|
+
);
|
|
72
|
+
findImportFromGqlTypes(originalTypeName)?.remove();
|
|
73
|
+
addToGqlTypesImports(newTypeName);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
return ast.toSource();
|
|
77
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
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 updateResolverTypes_yargs_exports = {};
|
|
30
|
+
__export(updateResolverTypes_yargs_exports, {
|
|
31
|
+
command: () => command,
|
|
32
|
+
description: () => description,
|
|
33
|
+
handler: () => handler
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(updateResolverTypes_yargs_exports);
|
|
36
|
+
var import_path = __toESM(require("path"));
|
|
37
|
+
var import_fast_glob = __toESM(require("fast-glob"));
|
|
38
|
+
var import_tasuku = __toESM(require("tasuku"));
|
|
39
|
+
var import_project_config = require("@cedarjs/project-config");
|
|
40
|
+
var import_runTransform = __toESM(require("../../../lib/runTransform"));
|
|
41
|
+
const command = "update-resolver-types";
|
|
42
|
+
const description = '(v2.x.x->v3.x.x) Wraps types for "relation" resolvers in the bottom of service files';
|
|
43
|
+
const handler = () => {
|
|
44
|
+
(0, import_tasuku.default)("Update Resolver Types", async ({ setOutput }) => {
|
|
45
|
+
await (0, import_runTransform.default)({
|
|
46
|
+
transformPath: import_path.default.join(__dirname, "updateResolverTypes.js"),
|
|
47
|
+
// Target services written in TS only
|
|
48
|
+
targetPaths: import_fast_glob.default.sync("**/*.ts", {
|
|
49
|
+
cwd: (0, import_project_config.getPaths)().api.services,
|
|
50
|
+
ignore: ["**/node_modules/**", "**/*.test.ts", "**/*.scenarios.ts"],
|
|
51
|
+
absolute: true
|
|
52
|
+
})
|
|
53
|
+
});
|
|
54
|
+
setOutput("All done! Run `yarn rw lint --fix` to prettify your code");
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
58
|
+
0 && (module.exports = {
|
|
59
|
+
command,
|
|
60
|
+
description,
|
|
61
|
+
handler
|
|
62
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var updateClerkGetCurrentUser_exports = {};
|
|
20
|
+
__export(updateClerkGetCurrentUser_exports, {
|
|
21
|
+
default: () => transform
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(updateClerkGetCurrentUser_exports);
|
|
24
|
+
const newReturn = `userWithoutPrivateMetadata`;
|
|
25
|
+
const destructureStatement = `const { privateMetadata, ...${newReturn} } = decoded`;
|
|
26
|
+
function transform(file, api) {
|
|
27
|
+
const j = api.jscodeshift;
|
|
28
|
+
const ast = j(file.source);
|
|
29
|
+
const parseJWTStatement = ast.find(j.VariableDeclaration, {
|
|
30
|
+
declarations: [
|
|
31
|
+
{
|
|
32
|
+
type: "VariableDeclarator",
|
|
33
|
+
init: {
|
|
34
|
+
type: "CallExpression",
|
|
35
|
+
callee: {
|
|
36
|
+
name: "parseJWT"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
});
|
|
42
|
+
parseJWTStatement.insertAfter(destructureStatement);
|
|
43
|
+
ast.find(j.ReturnStatement, {
|
|
44
|
+
argument: {
|
|
45
|
+
type: "ObjectExpression",
|
|
46
|
+
properties: [
|
|
47
|
+
{
|
|
48
|
+
type: "SpreadElement",
|
|
49
|
+
argument: {
|
|
50
|
+
name: "decoded"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
}).replaceWith((path) => {
|
|
56
|
+
if (path.value.argument?.type !== "ObjectExpression") {
|
|
57
|
+
return path.value;
|
|
58
|
+
}
|
|
59
|
+
const properties = path.value.argument.properties.filter((property) => {
|
|
60
|
+
return !(property.type === "SpreadElement" && property.argument.type === "Identifier" && property.argument.name === "decoded");
|
|
61
|
+
});
|
|
62
|
+
const spreadElement = j.spreadProperty(j.identifier(newReturn));
|
|
63
|
+
properties.push(spreadElement);
|
|
64
|
+
return j.returnStatement(j.objectExpression(properties));
|
|
65
|
+
});
|
|
66
|
+
return ast.toSource({
|
|
67
|
+
trailingComma: true,
|
|
68
|
+
quote: "single",
|
|
69
|
+
lineTerminator: "\n"
|
|
70
|
+
});
|
|
71
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
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 updateClerkGetCurrentUser_yargs_exports = {};
|
|
30
|
+
__export(updateClerkGetCurrentUser_yargs_exports, {
|
|
31
|
+
command: () => command,
|
|
32
|
+
description: () => description,
|
|
33
|
+
handler: () => handler
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(updateClerkGetCurrentUser_yargs_exports);
|
|
36
|
+
var import_path = __toESM(require("path"));
|
|
37
|
+
var import_tasuku = __toESM(require("tasuku"));
|
|
38
|
+
var import_project_config = require("@cedarjs/project-config");
|
|
39
|
+
var import_isTSProject = __toESM(require("../../../lib/isTSProject"));
|
|
40
|
+
var import_runTransform = __toESM(require("../../../lib/runTransform"));
|
|
41
|
+
const command = "update-clerk-get-current-user";
|
|
42
|
+
const description = "(v4.1.x->v4.2.x) For Clerk users; updates the getCurrentUser function";
|
|
43
|
+
const handler = () => {
|
|
44
|
+
(0, import_tasuku.default)("Update getCurrentUser", async ({ setOutput }) => {
|
|
45
|
+
const authFile = import_isTSProject.default ? "auth.ts" : "auth.js";
|
|
46
|
+
await (0, import_runTransform.default)({
|
|
47
|
+
transformPath: import_path.default.join(__dirname, "updateClerkGetCurrentUser.js"),
|
|
48
|
+
targetPaths: [import_path.default.join((0, import_project_config.getPaths)().api.base, "src", "lib", authFile)]
|
|
49
|
+
});
|
|
50
|
+
setOutput("All done! Run `yarn rw lint --fix` to prettify your code");
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
54
|
+
0 && (module.exports = {
|
|
55
|
+
command,
|
|
56
|
+
description,
|
|
57
|
+
handler
|
|
58
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var useArmor_exports = {};
|
|
20
|
+
__export(useArmor_exports, {
|
|
21
|
+
default: () => transform
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(useArmor_exports);
|
|
24
|
+
function transform(file, api) {
|
|
25
|
+
const j = api.jscodeshift;
|
|
26
|
+
const ast = j(file.source);
|
|
27
|
+
ast.find(j.CallExpression, { callee: { name: "createGraphQLHandler" } }).forEach((path) => {
|
|
28
|
+
const depthLimitOptionsProp = j(path.node).find(j.ObjectProperty, {
|
|
29
|
+
key: {
|
|
30
|
+
name: "depthLimitOptions"
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
if (depthLimitOptionsProp.length > 0) {
|
|
34
|
+
console.info(`Updating createGraphQLHandler config in ${file.path} ...`);
|
|
35
|
+
const maxDepthProp = depthLimitOptionsProp.find(j.ObjectProperty, {
|
|
36
|
+
key: {
|
|
37
|
+
name: "maxDepth"
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
const depthLimitOption = maxDepthProp.find(j.Literal);
|
|
41
|
+
if (depthLimitOption.length > 0) {
|
|
42
|
+
const depthLimitOptionValue = depthLimitOption.at(0).get().value.value;
|
|
43
|
+
depthLimitOptionsProp.replaceWith([
|
|
44
|
+
j.identifier(
|
|
45
|
+
`armorConfig: { maxDepth: { n: ${depthLimitOptionValue || 11} } }`
|
|
46
|
+
)
|
|
47
|
+
]);
|
|
48
|
+
console.info(
|
|
49
|
+
`useArmor configured to use existing maxDepth of ${depthLimitOptionValue || 11}.`
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
console.info(
|
|
54
|
+
`No mods needed to createGraphQLHandler config in ${file.path}. Skipping...`
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
return ast.toSource({
|
|
59
|
+
trailingComma: true,
|
|
60
|
+
quote: "single",
|
|
61
|
+
lineTerminator: "\n"
|
|
62
|
+
});
|
|
63
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
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 useArmor_yargs_exports = {};
|
|
30
|
+
__export(useArmor_yargs_exports, {
|
|
31
|
+
command: () => command,
|
|
32
|
+
description: () => description,
|
|
33
|
+
handler: () => handler
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(useArmor_yargs_exports);
|
|
36
|
+
var import_path = __toESM(require("path"));
|
|
37
|
+
var import_tasuku = __toESM(require("tasuku"));
|
|
38
|
+
var import_project_config = require("@cedarjs/project-config");
|
|
39
|
+
var import_isTSProject = __toESM(require("../../../lib/isTSProject"));
|
|
40
|
+
var import_runTransform = __toESM(require("../../../lib/runTransform"));
|
|
41
|
+
const command = "use-armor";
|
|
42
|
+
const description = "(v4.x.x->v4.x.x) Updates createGraphQLHandler config to use GraphQL Armor config as needed";
|
|
43
|
+
const handler = () => {
|
|
44
|
+
(0, import_tasuku.default)("Use Armor", async ({ setOutput }) => {
|
|
45
|
+
const graphqlHandlerFile = import_isTSProject.default ? "graphql.ts" : "graphql.js";
|
|
46
|
+
await (0, import_runTransform.default)({
|
|
47
|
+
transformPath: import_path.default.join(__dirname, "useArmor.js"),
|
|
48
|
+
targetPaths: [
|
|
49
|
+
import_path.default.join((0, import_project_config.getPaths)().api.base, "src", "functions", graphqlHandlerFile)
|
|
50
|
+
]
|
|
51
|
+
});
|
|
52
|
+
setOutput(
|
|
53
|
+
"Updating createGraphQLHandler for useArmor config is done! Run `yarn rw lint --fix` to prettify your code"
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
58
|
+
0 && (module.exports = {
|
|
59
|
+
command,
|
|
60
|
+
description,
|
|
61
|
+
handler
|
|
62
|
+
});
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var cellQueryResult_exports = {};
|
|
20
|
+
__export(cellQueryResult_exports, {
|
|
21
|
+
default: () => transform
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(cellQueryResult_exports);
|
|
24
|
+
const cellFunctionsToCheck = ["Success", "Failure", "Loading", "Empty"];
|
|
25
|
+
const nonSpreadVariables = [
|
|
26
|
+
"previousData",
|
|
27
|
+
"variables",
|
|
28
|
+
"networkStatus",
|
|
29
|
+
"client",
|
|
30
|
+
"called",
|
|
31
|
+
"refetch",
|
|
32
|
+
"fetchMore",
|
|
33
|
+
"startPolling",
|
|
34
|
+
"stopPolling",
|
|
35
|
+
"subscribeToMore",
|
|
36
|
+
"updateQuery"
|
|
37
|
+
];
|
|
38
|
+
function transform(file, api) {
|
|
39
|
+
const j = api.jscodeshift;
|
|
40
|
+
const ast = j(file.source);
|
|
41
|
+
cellFunctionsToCheck.forEach((variableName) => {
|
|
42
|
+
const foundCellFunctions = ast.findVariableDeclarators(variableName);
|
|
43
|
+
if (foundCellFunctions.size() === 1) {
|
|
44
|
+
const foundFunction = foundCellFunctions.paths()[0];
|
|
45
|
+
if (foundFunction.value.init?.type === "ArrowFunctionExpression" || foundFunction.value.init?.type === "FunctionExpression") {
|
|
46
|
+
const firstParameter = foundFunction.value.init.params.at(0);
|
|
47
|
+
if (!firstParameter) {
|
|
48
|
+
} else {
|
|
49
|
+
if (firstParameter.type === "ObjectPattern") {
|
|
50
|
+
const previouslySpreadPropertiesInUse = firstParameter.properties.filter((property) => {
|
|
51
|
+
if (property.type === "SpreadProperty" || property.type === "SpreadPropertyPattern" || property.type === "RestProperty" || property.key.type !== "Identifier") {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
return nonSpreadVariables.includes(property.key.name);
|
|
55
|
+
});
|
|
56
|
+
if (previouslySpreadPropertiesInUse.length > 0) {
|
|
57
|
+
firstParameter.properties.push(
|
|
58
|
+
j.property(
|
|
59
|
+
"init",
|
|
60
|
+
j.identifier("queryResult"),
|
|
61
|
+
// Previously spead properties are now found within 'queryResult'
|
|
62
|
+
j.objectPattern(
|
|
63
|
+
// For every previously spead property in use add a destructuring
|
|
64
|
+
previouslySpreadPropertiesInUse.map((usedProperty) => {
|
|
65
|
+
if (!("key" in usedProperty) || !("value" in usedProperty) || usedProperty.key.type !== "Identifier" || usedProperty.value.type !== "Identifier") {
|
|
66
|
+
throw new Error(
|
|
67
|
+
"Unable to process a parameter within the cell function"
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
const prop = j.property(
|
|
71
|
+
"init",
|
|
72
|
+
j.identifier(usedProperty.key.name),
|
|
73
|
+
j.identifier(usedProperty.value.name)
|
|
74
|
+
);
|
|
75
|
+
prop.shorthand = usedProperty.shorthand;
|
|
76
|
+
return prop;
|
|
77
|
+
})
|
|
78
|
+
)
|
|
79
|
+
)
|
|
80
|
+
);
|
|
81
|
+
firstParameter.properties = firstParameter.properties.filter(
|
|
82
|
+
(property) => {
|
|
83
|
+
if (!("key" in property) || property.key.type !== "Identifier") {
|
|
84
|
+
throw new Error("Unable to process a parameter");
|
|
85
|
+
}
|
|
86
|
+
return !nonSpreadVariables.includes(property.key.name);
|
|
87
|
+
}
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
} else {
|
|
91
|
+
console.warn(
|
|
92
|
+
`The first parameter to '${variableName}' was not an object and we could not process this.`
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
console.warn(
|
|
98
|
+
`'${variableName}' is not a function and we could not process this.`
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
} else {
|
|
102
|
+
console.warn(`Could not find a unique '${variableName}' variable`);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
return ast.toSource({
|
|
106
|
+
trailingComma: true,
|
|
107
|
+
quote: "single",
|
|
108
|
+
lineTerminator: "\n"
|
|
109
|
+
});
|
|
110
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
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 cellQueryResult_yargs_exports = {};
|
|
30
|
+
__export(cellQueryResult_yargs_exports, {
|
|
31
|
+
command: () => command,
|
|
32
|
+
description: () => description,
|
|
33
|
+
handler: () => handler
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(cellQueryResult_yargs_exports);
|
|
36
|
+
var import_path = __toESM(require("path"));
|
|
37
|
+
var import_tasuku = __toESM(require("tasuku"));
|
|
38
|
+
var import_cells = require("../../../lib/cells");
|
|
39
|
+
var import_runTransform = __toESM(require("../../../lib/runTransform"));
|
|
40
|
+
const command = "cell-query-result";
|
|
41
|
+
const description = "(v4.x.x->v5.x.x) Updates cells to use the `queryResult` property";
|
|
42
|
+
const handler = () => {
|
|
43
|
+
(0, import_tasuku.default)("cellQueryResult", async ({ setOutput }) => {
|
|
44
|
+
await (0, import_runTransform.default)({
|
|
45
|
+
transformPath: import_path.default.join(__dirname, "cellQueryResult.js"),
|
|
46
|
+
targetPaths: (0, import_cells.findCells)()
|
|
47
|
+
});
|
|
48
|
+
setOutput(
|
|
49
|
+
"Updates to your cells are complete! Please run `yarn rw lint --fix` to prettify your code"
|
|
50
|
+
);
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
54
|
+
0 && (module.exports = {
|
|
55
|
+
command,
|
|
56
|
+
description,
|
|
57
|
+
handler
|
|
58
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var detectEmptyCells_exports = {};
|
|
20
|
+
__export(detectEmptyCells_exports, {
|
|
21
|
+
detectEmptyCells: () => detectEmptyCells
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(detectEmptyCells_exports);
|
|
24
|
+
var import_cells = require("../../../lib/cells");
|
|
25
|
+
async function detectEmptyCells(taskContext) {
|
|
26
|
+
const warnings = [];
|
|
27
|
+
const cellPaths = (0, import_cells.findCells)();
|
|
28
|
+
const susceptibleCells = cellPaths.filter((cellPath) => {
|
|
29
|
+
const fileContents = (0, import_cells.fileToAst)(cellPath);
|
|
30
|
+
const cellQuery = (0, import_cells.getCellGqlQuery)(fileContents);
|
|
31
|
+
if (!cellQuery) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
let fields;
|
|
35
|
+
try {
|
|
36
|
+
fields = (0, import_cells.parseGqlQueryToAst)(cellQuery)[0].fields;
|
|
37
|
+
} catch {
|
|
38
|
+
warnings.push(cellPath);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
return fields.length > 1;
|
|
42
|
+
});
|
|
43
|
+
if (susceptibleCells.length === 0 && warnings.length === 0) {
|
|
44
|
+
taskContext.setOutput(
|
|
45
|
+
"None of your project's Cells are susceptible to the new `isDataEmpty` behavior."
|
|
46
|
+
);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const message = [];
|
|
50
|
+
if (susceptibleCells.length > 0) {
|
|
51
|
+
message.push(
|
|
52
|
+
[
|
|
53
|
+
"You have Cells that are susceptible to the new `isDataEmpty` behavior:",
|
|
54
|
+
"",
|
|
55
|
+
susceptibleCells.map((c) => `\u2022 ${c}`).join("\n"),
|
|
56
|
+
""
|
|
57
|
+
].join("\n")
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
if (warnings.length > 0) {
|
|
61
|
+
message.push(
|
|
62
|
+
[
|
|
63
|
+
[
|
|
64
|
+
message.length > 0 && "\u2192",
|
|
65
|
+
`The following Cell(s) could not be parsed:`
|
|
66
|
+
].filter(Boolean).join(" "),
|
|
67
|
+
"",
|
|
68
|
+
warnings.map((c) => `\u2022 ${c}`).join("\n"),
|
|
69
|
+
"",
|
|
70
|
+
"You'll have to audit them manually.",
|
|
71
|
+
""
|
|
72
|
+
].join("\n")
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
message.push(
|
|
76
|
+
[
|
|
77
|
+
"The new behavior is documented in detail on the forums: https://community.redwoodjs.com/t/redwood-v5-0-0-rc-is-now-available/4715.",
|
|
78
|
+
"It's most likely what you want, but consider whether it affects you.",
|
|
79
|
+
"If you'd like to revert to the old behavior, you can override the `isDataEmpty` function."
|
|
80
|
+
].join("\n")
|
|
81
|
+
);
|
|
82
|
+
const taskContextMethod = warnings.length > 0 ? "setWarning" : "setOutput";
|
|
83
|
+
taskContext[taskContextMethod](message.join("\n"));
|
|
84
|
+
}
|
|
85
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
86
|
+
0 && (module.exports = {
|
|
87
|
+
detectEmptyCells
|
|
88
|
+
});
|