@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.
Files changed (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +297 -0
  3. package/dist/codemods/list.yargs.js +67 -0
  4. package/dist/codemods/v2.3.x/tsconfigForRouteHooks/tsconfigForRouteHooks.js +74 -0
  5. package/dist/codemods/v2.3.x/tsconfigForRouteHooks/tsconfigForRouteHooks.yargs.js +51 -0
  6. package/dist/codemods/v2.x.x/configureFastify/configureFastify.js +43 -0
  7. package/dist/codemods/v2.x.x/configureFastify/configureFastify.yargs.js +83 -0
  8. package/dist/codemods/v2.x.x/updateResolverTypes/updateResolverTypes.js +77 -0
  9. package/dist/codemods/v2.x.x/updateResolverTypes/updateResolverTypes.yargs.js +62 -0
  10. package/dist/codemods/v4.2.x/updateClerkGetCurrentUser/updateClerkGetCurrentUser.js +71 -0
  11. package/dist/codemods/v4.2.x/updateClerkGetCurrentUser/updateClerkGetCurrentUser.yargs.js +58 -0
  12. package/dist/codemods/v4.x.x/useArmor/useArmor.js +63 -0
  13. package/dist/codemods/v4.x.x/useArmor/useArmor.yargs.js +62 -0
  14. package/dist/codemods/v5.x.x/cellQueryResult/cellQueryResult.js +110 -0
  15. package/dist/codemods/v5.x.x/cellQueryResult/cellQueryResult.yargs.js +58 -0
  16. package/dist/codemods/v5.x.x/detectEmptyCells/detectEmptyCells.js +88 -0
  17. package/dist/codemods/v5.x.x/detectEmptyCells/detectEmptyCells.yargs.js +59 -0
  18. package/dist/codemods/v5.x.x/renameValidateWith/renameValidateWith.js +32 -0
  19. package/dist/codemods/v5.x.x/renameValidateWith/renameValidateWith.yargs.js +65 -0
  20. package/dist/codemods/v5.x.x/updateAuth0ToV2/updateAuth0ToV2.js +48 -0
  21. package/dist/codemods/v5.x.x/updateAuth0ToV2/updateAuth0ToV2.yargs.js +68 -0
  22. package/dist/codemods/v5.x.x/updateNodeEngineTo18/updateNodeEngineTo18.js +46 -0
  23. package/dist/codemods/v5.x.x/updateNodeEngineTo18/updateNodeEngineTo18.yargs.js +57 -0
  24. package/dist/codemods/v5.x.x/upgradeToReact18/upgradeToReact18.js +135 -0
  25. package/dist/codemods/v5.x.x/upgradeToReact18/upgradeToReact18.yargs.js +56 -0
  26. package/dist/codemods/v6.x.x/changeGlobalToGlobalThis/changeGlobalToGlobalThis.js +29 -0
  27. package/dist/codemods/v6.x.x/changeGlobalToGlobalThis/changeGlobalToGlobalThis.yargs.js +60 -0
  28. package/dist/codemods/v6.x.x/convertJsToJsx/convertJsToJsx.js +45 -0
  29. package/dist/codemods/v6.x.x/convertJsToJsx/convertJsToJsx.yargs.js +59 -0
  30. package/dist/codemods/v6.x.x/entryClientNullCheck/entryClientNullCheck.js +51 -0
  31. package/dist/codemods/v6.x.x/entryClientNullCheck/entryClientNullCheck.yargs.js +60 -0
  32. package/dist/codemods/v6.x.x/processEnvDotNotation/processEnvDotNotation.js +44 -0
  33. package/dist/codemods/v6.x.x/processEnvDotNotation/processEnvDotNotation.yargs.js +60 -0
  34. package/dist/codemods/v6.x.x/replaceComponentSvgs/replaceComponentSvgs.js +154 -0
  35. package/dist/codemods/v6.x.x/replaceComponentSvgs/replaceComponentSvgs.yargs.js +61 -0
  36. package/dist/codemods/v6.x.x/updateDevFatalErrorPage/updateDevFatalErrorPage.js +58 -0
  37. package/dist/codemods/v6.x.x/updateDevFatalErrorPage/updateDevFatalErrorPage.yargs.js +50 -0
  38. package/dist/codemods/v6.x.x/updateThemeConfig/updateThemeConfig.js +51 -0
  39. package/dist/codemods/v6.x.x/updateThemeConfig/updateThemeConfig.yargs.js +61 -0
  40. package/dist/codemods/v7.x.x/updateGraphQLConfig/updateGraphqlConfig.js +51 -0
  41. package/dist/codemods/v7.x.x/updateGraphQLConfig/updateGraphqlConfig.yargs.js +50 -0
  42. package/dist/codemods.js +45 -0
  43. package/dist/lib/cells.js +230 -0
  44. package/dist/lib/fetchFileFromTemplate.js +29 -0
  45. package/dist/lib/getFilesWithPattern.js +51 -0
  46. package/dist/lib/getRootPackageJSON.js +44 -0
  47. package/dist/lib/isTSProject.js +39 -0
  48. package/dist/lib/prettify.js +55 -0
  49. package/dist/lib/runTransform.js +76 -0
  50. package/dist/lib/ts2js.js +57 -0
  51. package/package.json +67 -0
@@ -0,0 +1,59 @@
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 detectEmptyCells_yargs_exports = {};
30
+ __export(detectEmptyCells_yargs_exports, {
31
+ command: () => command,
32
+ description: () => description,
33
+ handler: () => handler
34
+ });
35
+ module.exports = __toCommonJS(detectEmptyCells_yargs_exports);
36
+ var import_tasuku = __toESM(require("tasuku"));
37
+ var import_detectEmptyCells = require("./detectEmptyCells");
38
+ const command = "detect-empty-cells";
39
+ const description = "(v4.x.x->v5.x.x) Detects Cells susceptible to the new Empty behavior";
40
+ const handler = () => {
41
+ (0, import_tasuku.default)(
42
+ "Detecting Cells susceptible to the new Empty behavior",
43
+ async (taskContext) => {
44
+ try {
45
+ await (0, import_detectEmptyCells.detectEmptyCells)(taskContext);
46
+ } catch (e) {
47
+ taskContext.setError(
48
+ "Failed to detect cells susceptible to the new Empty behavior in your project \n" + e?.message
49
+ );
50
+ }
51
+ }
52
+ );
53
+ };
54
+ // Annotate the CommonJS export names for ESM import in node:
55
+ 0 && (module.exports = {
56
+ command,
57
+ description,
58
+ handler
59
+ });
@@ -0,0 +1,32 @@
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 renameValidateWith_exports = {};
20
+ __export(renameValidateWith_exports, {
21
+ default: () => transform
22
+ });
23
+ module.exports = __toCommonJS(renameValidateWith_exports);
24
+ function transform(file, api) {
25
+ const j = api.jscodeshift;
26
+ const root = j(file.source);
27
+ root.find(j.Identifier, {
28
+ type: "Identifier",
29
+ name: "validateWith"
30
+ }).replaceWith({ type: "Identifier", name: "validateWithSync" });
31
+ return root.toSource();
32
+ }
@@ -0,0 +1,65 @@
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 renameValidateWith_yargs_exports = {};
30
+ __export(renameValidateWith_yargs_exports, {
31
+ command: () => command,
32
+ description: () => description,
33
+ handler: () => handler
34
+ });
35
+ module.exports = __toCommonJS(renameValidateWith_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_getFilesWithPattern = __toESM(require("../../../lib/getFilesWithPattern"));
40
+ var import_runTransform = __toESM(require("../../../lib/runTransform"));
41
+ const command = "rename-validate-with";
42
+ const description = "(v4.x.x->v5.x.x) Renames validateWith to validateWithSync";
43
+ const handler = () => {
44
+ (0, import_tasuku.default)(
45
+ "Renaming `validateWith` to `validateWithSync`",
46
+ async ({ setOutput }) => {
47
+ const redwoodProjectPaths = (0, import_project_config.getPaths)();
48
+ const files = (0, import_getFilesWithPattern.default)({
49
+ pattern: "validateWith",
50
+ filesToSearch: [redwoodProjectPaths.api.src]
51
+ });
52
+ await (0, import_runTransform.default)({
53
+ transformPath: import_path.default.join(__dirname, "renameValidateWith.js"),
54
+ targetPaths: files
55
+ });
56
+ setOutput("All done! Run `yarn rw lint --fix` to prettify your code");
57
+ }
58
+ );
59
+ };
60
+ // Annotate the CommonJS export names for ESM import in node:
61
+ 0 && (module.exports = {
62
+ command,
63
+ description,
64
+ handler
65
+ });
@@ -0,0 +1,48 @@
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 updateAuth0ToV2_exports = {};
20
+ __export(updateAuth0ToV2_exports, {
21
+ default: () => transform
22
+ });
23
+ module.exports = __toCommonJS(updateAuth0ToV2_exports);
24
+ function transform(file, api) {
25
+ const j = api.jscodeshift;
26
+ const ast = j(file.source);
27
+ const paths = ast.find(j.ObjectProperty, (node) => {
28
+ return "name" in node.key && (node.key.name === "redirect_uri" || node.key.name === "audience");
29
+ });
30
+ let nodes = paths.nodes();
31
+ nodes = nodes.map((node) => {
32
+ const { comments: _comments, ...rest } = node;
33
+ return rest;
34
+ });
35
+ paths.remove();
36
+ ast.find(j.ObjectProperty, { key: { name: "client_id" } }).insertAfter(
37
+ j.objectProperty(
38
+ j.identifier("authorizationParams"),
39
+ j.objectExpression(nodes)
40
+ )
41
+ );
42
+ ast.find(j.Identifier, { name: "client_id" }).replaceWith("clientId");
43
+ return ast.toSource({
44
+ trailingComma: true,
45
+ quote: "single",
46
+ lineTerminator: "\n"
47
+ });
48
+ }
@@ -0,0 +1,68 @@
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 updateAuth0ToV2_yargs_exports = {};
30
+ __export(updateAuth0ToV2_yargs_exports, {
31
+ command: () => command,
32
+ description: () => description,
33
+ handler: () => handler
34
+ });
35
+ module.exports = __toCommonJS(updateAuth0ToV2_yargs_exports);
36
+ var import_path = __toESM(require("path"));
37
+ var import_execa = __toESM(require("execa"));
38
+ var import_tasuku = __toESM(require("tasuku"));
39
+ var import_project_config = require("@cedarjs/project-config");
40
+ var import_isTSProject = __toESM(require("../../../lib/isTSProject"));
41
+ var import_runTransform = __toESM(require("../../../lib/runTransform"));
42
+ const command = "update-auth0-to-v2";
43
+ const description = "(v4.x.x->v5.x.x) Updates the web-side auth.{ts,js} file to the v2 SDK";
44
+ const handler = () => {
45
+ (0, import_tasuku.default)("Updating Auth0 to v2", async ({ setOutput }) => {
46
+ const authFile = import_isTSProject.default ? "auth.ts" : "auth.js";
47
+ try {
48
+ await import_execa.default.command("yarn up @auth0/auth0-spa-js@^2", {
49
+ cwd: (0, import_project_config.getPaths)().web.base
50
+ });
51
+ } catch {
52
+ console.error(
53
+ "Couldn't update @auth0/auth0-spa-js; you'll have to upgrade it manually to the latest v2.x.x version"
54
+ );
55
+ }
56
+ await (0, import_runTransform.default)({
57
+ transformPath: import_path.default.join(__dirname, "updateAuth0ToV2.js"),
58
+ targetPaths: [import_path.default.join((0, import_project_config.getPaths)().web.src, authFile)]
59
+ });
60
+ setOutput("All done! Run `yarn rw lint --fix` to prettify your code");
61
+ });
62
+ };
63
+ // Annotate the CommonJS export names for ESM import in node:
64
+ 0 && (module.exports = {
65
+ command,
66
+ description,
67
+ handler
68
+ });
@@ -0,0 +1,46 @@
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 updateNodeEngineTo18_exports = {};
30
+ __export(updateNodeEngineTo18_exports, {
31
+ updateNodeEngineTo18: () => updateNodeEngineTo18
32
+ });
33
+ module.exports = __toCommonJS(updateNodeEngineTo18_exports);
34
+ var import_fs = __toESM(require("fs"));
35
+ var import_path = __toESM(require("path"));
36
+ var import_project_config = require("@cedarjs/project-config");
37
+ async function updateNodeEngineTo18() {
38
+ const packageJSONPath = import_path.default.join((0, import_project_config.getPaths)().base, "package.json");
39
+ const packageJSON = JSON.parse(import_fs.default.readFileSync(packageJSONPath, "utf-8"));
40
+ packageJSON.engines.node = "=18.x";
41
+ import_fs.default.writeFileSync(packageJSONPath, JSON.stringify(packageJSON, null, 2));
42
+ }
43
+ // Annotate the CommonJS export names for ESM import in node:
44
+ 0 && (module.exports = {
45
+ updateNodeEngineTo18
46
+ });
@@ -0,0 +1,57 @@
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 updateNodeEngineTo18_yargs_exports = {};
30
+ __export(updateNodeEngineTo18_yargs_exports, {
31
+ command: () => command,
32
+ description: () => description,
33
+ handler: () => handler
34
+ });
35
+ module.exports = __toCommonJS(updateNodeEngineTo18_yargs_exports);
36
+ var import_tasuku = __toESM(require("tasuku"));
37
+ var import_updateNodeEngineTo18 = require("./updateNodeEngineTo18");
38
+ const command = "update-node-engine-to-18";
39
+ const description = '(v4.x.x->v5.x.x) Updates `engines.node` to `"=18.x"` in your project\'s root package.json';
40
+ const handler = () => {
41
+ (0, import_tasuku.default)(
42
+ 'Updating `engines.node` to `"=18.x"` in root package.json',
43
+ async ({ setError }) => {
44
+ try {
45
+ await (0, import_updateNodeEngineTo18.updateNodeEngineTo18)();
46
+ } catch (e) {
47
+ setError("Failed to codemod your project \n" + e?.message);
48
+ }
49
+ }
50
+ );
51
+ };
52
+ // Annotate the CommonJS export names for ESM import in node:
53
+ 0 && (module.exports = {
54
+ command,
55
+ description,
56
+ handler
57
+ });
@@ -0,0 +1,135 @@
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 upgradeToReact18_exports = {};
30
+ __export(upgradeToReact18_exports, {
31
+ checkAndTransformReactRoot: () => checkAndTransformReactRoot,
32
+ checkAndUpdateCustomWebIndex: () => checkAndUpdateCustomWebIndex,
33
+ upgradeReactDepsTo18: () => upgradeReactDepsTo18
34
+ });
35
+ module.exports = __toCommonJS(upgradeToReact18_exports);
36
+ var import_fs = __toESM(require("fs"));
37
+ var import_path = __toESM(require("path"));
38
+ var import_cheerio = require("cheerio");
39
+ var import_execa = __toESM(require("execa"));
40
+ var import_project_config = require("@cedarjs/project-config");
41
+ function checkAndTransformReactRoot(taskContext) {
42
+ const indexHTMLFilepath = import_path.default.join((0, import_project_config.getPaths)().web.src, "index.html");
43
+ const indexHTML = (0, import_cheerio.load)(import_fs.default.readFileSync(indexHTMLFilepath, "utf-8"));
44
+ const reactRoot = indexHTML("#redwood-app");
45
+ const reactRootChildren = reactRoot.children();
46
+ if (reactRootChildren.length) {
47
+ let reactRootHTML = reactRoot.html();
48
+ if (!reactRootHTML) {
49
+ throw new Error(
50
+ `Couldn't get HTML in react root (div with id="redwood-app")`
51
+ );
52
+ }
53
+ reactRootHTML = reactRootHTML.replace("<!-- Please keep the line below for prerender support. -->", "").replace("&lt;%= prerenderPlaceholder %&gt;", "").split("\n").filter((line) => line.match(/\S/)).join("\n");
54
+ taskContext.setWarning(
55
+ [
56
+ `The react root (<div id="redwood-app"></div>) in ${indexHTMLFilepath} has children:`,
57
+ "",
58
+ reactRootHTML,
59
+ "",
60
+ "React expects to control this DOM node completely. This codemod has moved the children outside the react root,",
61
+ "but consider moving them into a layout."
62
+ ].join("\n")
63
+ );
64
+ }
65
+ indexHTML("body").append(reactRootChildren);
66
+ reactRoot.text("");
67
+ import_fs.default.writeFileSync(indexHTMLFilepath, indexHTML.html());
68
+ }
69
+ async function upgradeReactDepsTo18() {
70
+ const redwoodProjectPaths = (0, import_project_config.getPaths)();
71
+ const webPackageJSONPath = import_path.default.join(
72
+ redwoodProjectPaths.web.base,
73
+ "package.json"
74
+ );
75
+ const webPackageJSON = JSON.parse(
76
+ import_fs.default.readFileSync(webPackageJSONPath, "utf-8")
77
+ );
78
+ const latestReactVersion = "18.2.0";
79
+ for (const requiredReactDep of ["react", "react-dom"]) {
80
+ if (!Object.hasOwn(webPackageJSON.dependencies, requiredReactDep)) {
81
+ throw new Error(
82
+ `Couldn't find ${requiredReactDep} in web/package.json dependencies`
83
+ );
84
+ }
85
+ webPackageJSON.dependencies[requiredReactDep] = latestReactVersion;
86
+ }
87
+ import_fs.default.writeFileSync(webPackageJSONPath, JSON.stringify(webPackageJSON, null, 2));
88
+ await import_execa.default.command("yarn install", {
89
+ cwd: redwoodProjectPaths.base
90
+ });
91
+ }
92
+ async function checkAndUpdateCustomWebIndex(taskContext) {
93
+ const redwoodProjectPaths = (0, import_project_config.getPaths)();
94
+ const bundlerToCustomWebIndex = {
95
+ vite: import_path.default.join(redwoodProjectPaths.web.src, "entry-client.jsx"),
96
+ webpack: import_path.default.join(redwoodProjectPaths.web.src, "index.js")
97
+ };
98
+ const customWebIndexFound = Object.entries(bundlerToCustomWebIndex).find(
99
+ ([, filepath]) => import_fs.default.existsSync(filepath)
100
+ );
101
+ if (!customWebIndexFound) {
102
+ return;
103
+ }
104
+ import_fs.default.writeFileSync(customWebIndexFound[1], customWebIndexTemplate);
105
+ taskContext.setWarning(
106
+ [
107
+ `We updated the custom web index for you at ${customWebIndexFound[1]}.`,
108
+ " If you made manual changes to this file, you'll have to copy them over manually from the diff."
109
+ ].join("\n")
110
+ );
111
+ }
112
+ const customWebIndexTemplate = `import { hydrateRoot, createRoot } from 'react-dom/client'
113
+
114
+ import App from './App'
115
+ /**
116
+ * When \`#redwood-app\` isn't empty then it's very likely that you're using
117
+ * prerendering. So React attaches event listeners to the existing markup
118
+ * rather than replacing it.
119
+ * https://reactjs.org/docs/react-dom-client.html#hydrateroot
120
+ */
121
+ const redwoodAppElement = document.getElementById('redwood-app')
122
+
123
+ if (redwoodAppElement.children?.length > 0) {
124
+ hydrateRoot(redwoodAppElement, <App />)
125
+ } else {
126
+ const root = createRoot(redwoodAppElement)
127
+ root.render(<App />)
128
+ }
129
+ `;
130
+ // Annotate the CommonJS export names for ESM import in node:
131
+ 0 && (module.exports = {
132
+ checkAndTransformReactRoot,
133
+ checkAndUpdateCustomWebIndex,
134
+ upgradeReactDepsTo18
135
+ });
@@ -0,0 +1,56 @@
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 upgradeToReact18_yargs_exports = {};
30
+ __export(upgradeToReact18_yargs_exports, {
31
+ command: () => command,
32
+ description: () => description,
33
+ handler: () => handler
34
+ });
35
+ module.exports = __toCommonJS(upgradeToReact18_yargs_exports);
36
+ var import_tasuku = __toESM(require("tasuku"));
37
+ var import_upgradeToReact18 = require("./upgradeToReact18");
38
+ const command = "upgrade-to-react-18";
39
+ const description = "(v4.x.x->v5.0.0) Upgrades a project to React 18 and checks the react root";
40
+ const handler = () => {
41
+ (0, import_tasuku.default)("Check and transform react root", async (taskContext) => {
42
+ (0, import_upgradeToReact18.checkAndTransformReactRoot)(taskContext);
43
+ });
44
+ (0, import_tasuku.default)("Check and update custom web index", async (taskContext) => {
45
+ await (0, import_upgradeToReact18.checkAndUpdateCustomWebIndex)(taskContext);
46
+ });
47
+ (0, import_tasuku.default)("Update react deps", async () => {
48
+ await (0, import_upgradeToReact18.upgradeReactDepsTo18)();
49
+ });
50
+ };
51
+ // Annotate the CommonJS export names for ESM import in node:
52
+ 0 && (module.exports = {
53
+ command,
54
+ description,
55
+ handler
56
+ });
@@ -0,0 +1,29 @@
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 changeGlobalToGlobalThis_exports = {};
20
+ __export(changeGlobalToGlobalThis_exports, {
21
+ default: () => transform
22
+ });
23
+ module.exports = __toCommonJS(changeGlobalToGlobalThis_exports);
24
+ function transform(file, api) {
25
+ const j = api.jscodeshift;
26
+ const ast = j(file.source);
27
+ ast.find(j.Identifier, { name: "global" }).replaceWith(j.identifier("globalThis"));
28
+ return ast.toSource();
29
+ }
@@ -0,0 +1,60 @@
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 changeGlobalToGlobalThis_yargs_exports = {};
30
+ __export(changeGlobalToGlobalThis_yargs_exports, {
31
+ command: () => command,
32
+ description: () => description,
33
+ handler: () => handler
34
+ });
35
+ module.exports = __toCommonJS(changeGlobalToGlobalThis_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 = "change-global-to-global-this";
42
+ const description = "(v6.x.x->v6.x.x) Converts world to bazinga";
43
+ const handler = () => {
44
+ (0, import_tasuku.default)("Change Global To Global This", async ({ setOutput }) => {
45
+ await (0, import_runTransform.default)({
46
+ transformPath: import_path.default.join(__dirname, "changeGlobalToGlobalThis.js"),
47
+ targetPaths: import_fast_glob.default.sync("**/*.{js,jsx,tsx}", {
48
+ cwd: (0, import_project_config.getPaths)().web.src,
49
+ absolute: true
50
+ })
51
+ });
52
+ setOutput("All done! Run `yarn rw lint --fix` to prettify your code");
53
+ });
54
+ };
55
+ // Annotate the CommonJS export names for ESM import in node:
56
+ 0 && (module.exports = {
57
+ command,
58
+ description,
59
+ handler
60
+ });