@openrewrite/recipes-react 0.14.0 → 0.15.0
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/index.d.ts +12 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +70 -17
- package/dist/index.js.map +1 -1
- package/dist/migration/cra-to-vite/add-vite-config.d.ts +9 -0
- package/dist/migration/cra-to-vite/add-vite-config.d.ts.map +1 -0
- package/dist/migration/cra-to-vite/add-vite-config.js +49 -0
- package/dist/migration/cra-to-vite/add-vite-config.js.map +1 -0
- package/dist/migration/cra-to-vite/cra-blockers-table.d.ts +10 -0
- package/dist/migration/cra-to-vite/cra-blockers-table.d.ts.map +1 -0
- package/dist/migration/cra-to-vite/cra-blockers-table.js +31 -0
- package/dist/migration/cra-to-vite/cra-blockers-table.js.map +1 -0
- package/dist/migration/cra-to-vite/cra-to-vite.d.ts +14 -0
- package/dist/migration/cra-to-vite/cra-to-vite.d.ts.map +1 -0
- package/dist/migration/cra-to-vite/cra-to-vite.js +73 -0
- package/dist/migration/cra-to-vite/cra-to-vite.js.map +1 -0
- package/dist/migration/cra-to-vite/find-cra-config-blockers.d.ts +14 -0
- package/dist/migration/cra-to-vite/find-cra-config-blockers.d.ts.map +1 -0
- package/dist/migration/cra-to-vite/find-cra-config-blockers.js +185 -0
- package/dist/migration/cra-to-vite/find-cra-config-blockers.js.map +1 -0
- package/dist/migration/cra-to-vite/find-cra-env-file-blockers.d.ts +10 -0
- package/dist/migration/cra-to-vite/find-cra-env-file-blockers.d.ts.map +1 -0
- package/dist/migration/cra-to-vite/find-cra-env-file-blockers.js +67 -0
- package/dist/migration/cra-to-vite/find-cra-env-file-blockers.js.map +1 -0
- package/dist/migration/cra-to-vite/find-cra-source-blockers.d.ts +10 -0
- package/dist/migration/cra-to-vite/find-cra-source-blockers.d.ts.map +1 -0
- package/dist/migration/cra-to-vite/find-cra-source-blockers.js +168 -0
- package/dist/migration/cra-to-vite/find-cra-source-blockers.js.map +1 -0
- package/dist/migration/cra-to-vite/find-cra-to-vite-blockers.d.ts +8 -0
- package/dist/migration/cra-to-vite/find-cra-to-vite-blockers.d.ts.map +1 -0
- package/dist/migration/cra-to-vite/find-cra-to-vite-blockers.js +31 -0
- package/dist/migration/cra-to-vite/find-cra-to-vite-blockers.js.map +1 -0
- package/dist/migration/cra-to-vite/index.d.ts +16 -0
- package/dist/migration/cra-to-vite/index.d.ts.map +1 -0
- package/dist/migration/cra-to-vite/index.js +35 -0
- package/dist/migration/cra-to-vite/index.js.map +1 -0
- package/dist/migration/cra-to-vite/move-public-index-html.d.ts +11 -0
- package/dist/migration/cra-to-vite/move-public-index-html.d.ts.map +1 -0
- package/dist/migration/cra-to-vite/move-public-index-html.js +124 -0
- package/dist/migration/cra-to-vite/move-public-index-html.js.map +1 -0
- package/dist/migration/cra-to-vite/rename-process-env-react-app.d.ts +9 -0
- package/dist/migration/cra-to-vite/rename-process-env-react-app.d.ts.map +1 -0
- package/dist/migration/cra-to-vite/rename-process-env-react-app.js +92 -0
- package/dist/migration/cra-to-vite/rename-process-env-react-app.js.map +1 -0
- package/dist/migration/cra-to-vite/rename-react-app-env-vars-in-env-files.d.ts +9 -0
- package/dist/migration/cra-to-vite/rename-react-app-env-vars-in-env-files.d.ts.map +1 -0
- package/dist/migration/cra-to-vite/rename-react-app-env-vars-in-env-files.js +65 -0
- package/dist/migration/cra-to-vite/rename-react-app-env-vars-in-env-files.js.map +1 -0
- package/dist/migration/cra-to-vite/replace-react-scripts-dependency.d.ts +14 -0
- package/dist/migration/cra-to-vite/replace-react-scripts-dependency.d.ts.map +1 -0
- package/dist/migration/cra-to-vite/replace-react-scripts-dependency.js +98 -0
- package/dist/migration/cra-to-vite/replace-react-scripts-dependency.js.map +1 -0
- package/dist/migration/cra-to-vite/scan-cra-projects.d.ts +21 -0
- package/dist/migration/cra-to-vite/scan-cra-projects.d.ts.map +1 -0
- package/dist/migration/cra-to-vite/scan-cra-projects.js +87 -0
- package/dist/migration/cra-to-vite/scan-cra-projects.js.map +1 -0
- package/dist/migration/cra-to-vite/shared.d.ts +37 -0
- package/dist/migration/cra-to-vite/shared.d.ts.map +1 -0
- package/dist/migration/cra-to-vite/shared.js +218 -0
- package/dist/migration/cra-to-vite/shared.js.map +1 -0
- package/dist/migration/cra-to-vite/update-react-app-env-types.d.ts +9 -0
- package/dist/migration/cra-to-vite/update-react-app-env-types.d.ts.map +1 -0
- package/dist/migration/cra-to-vite/update-react-app-env-types.js +47 -0
- package/dist/migration/cra-to-vite/update-react-app-env-types.js.map +1 -0
- package/dist/migration/cra-to-vite/update-react-scripts-scripts.d.ts +9 -0
- package/dist/migration/cra-to-vite/update-react-scripts-scripts.d.ts.map +1 -0
- package/dist/migration/cra-to-vite/update-react-scripts-scripts.js +67 -0
- package/dist/migration/cra-to-vite/update-react-scripts-scripts.js.map +1 -0
- package/dist/migration/cra-to-vite/update-tsconfig-for-vite.d.ts +10 -0
- package/dist/migration/cra-to-vite/update-tsconfig-for-vite.d.ts.map +1 -0
- package/dist/migration/cra-to-vite/update-tsconfig-for-vite.js +53 -0
- package/dist/migration/cra-to-vite/update-tsconfig-for-vite.js.map +1 -0
- package/dist/react17/migrate-deprecated-lifecycles.d.ts +8 -0
- package/dist/react17/migrate-deprecated-lifecycles.d.ts.map +1 -0
- package/dist/react17/migrate-deprecated-lifecycles.js +258 -0
- package/dist/react17/migrate-deprecated-lifecycles.js.map +1 -0
- package/dist/react17/use-new-jsx-transform.d.ts +8 -0
- package/dist/react17/use-new-jsx-transform.d.ts.map +1 -0
- package/dist/react17/use-new-jsx-transform.js +169 -0
- package/dist/react17/use-new-jsx-transform.js.map +1 -0
- package/dist/react18/add-children-to-props.d.ts +8 -0
- package/dist/react18/add-children-to-props.d.ts.map +1 -0
- package/dist/react18/add-children-to-props.js +277 -0
- package/dist/react18/add-children-to-props.js.map +1 -0
- package/dist/react18/replace-reactdom-render.d.ts.map +1 -1
- package/dist/react18/replace-reactdom-render.js +109 -12
- package/dist/react18/replace-reactdom-render.js.map +1 -1
- package/dist/refactoring/class-to-functional.d.ts.map +1 -1
- package/dist/refactoring/class-to-functional.js +81 -7
- package/dist/refactoring/class-to-functional.js.map +1 -1
- package/dist/refactoring/fix-async-effect.d.ts +8 -0
- package/dist/refactoring/fix-async-effect.d.ts.map +1 -0
- package/dist/refactoring/fix-async-effect.js +71 -0
- package/dist/refactoring/fix-async-effect.js.map +1 -0
- package/dist/refactoring/prop-types-to-typescript.d.ts +8 -0
- package/dist/refactoring/prop-types-to-typescript.d.ts.map +1 -0
- package/dist/refactoring/prop-types-to-typescript.js +342 -0
- package/dist/refactoring/prop-types-to-typescript.js.map +1 -0
- package/dist/search/find-deprecated-lifecycles.d.ts +12 -0
- package/dist/search/find-deprecated-lifecycles.d.ts.map +1 -0
- package/dist/search/find-deprecated-lifecycles.js +86 -0
- package/dist/search/find-deprecated-lifecycles.js.map +1 -0
- package/dist/search/find-effects-without-cleanup.d.ts +9 -0
- package/dist/search/find-effects-without-cleanup.d.ts.map +1 -0
- package/dist/search/find-effects-without-cleanup.js +133 -0
- package/dist/search/find-effects-without-cleanup.js.map +1 -0
- package/dist/search/find-enzyme-usage.d.ts +9 -0
- package/dist/search/find-enzyme-usage.d.ts.map +1 -0
- package/dist/search/find-enzyme-usage.js +155 -0
- package/dist/search/find-enzyme-usage.js.map +1 -0
- package/dist/search/find-function-component-default-props.d.ts +11 -0
- package/dist/search/find-function-component-default-props.d.ts.map +1 -0
- package/dist/search/find-function-component-default-props.js +96 -0
- package/dist/search/find-function-component-default-props.js.map +1 -0
- package/dist/search/find-legacy-react-apis.d.ts +8 -0
- package/dist/search/find-legacy-react-apis.d.ts.map +1 -0
- package/dist/search/find-legacy-react-apis.js +41 -0
- package/dist/search/find-legacy-react-apis.js.map +1 -0
- package/dist/search/find-missing-use-client-directive.d.ts +9 -0
- package/dist/search/find-missing-use-client-directive.d.ts.map +1 -0
- package/dist/search/find-missing-use-client-directive.js +127 -0
- package/dist/search/find-missing-use-client-directive.js.map +1 -0
- package/dist/search/find-reactdom-root-apis.d.ts +14 -0
- package/dist/search/find-reactdom-root-apis.d.ts.map +1 -0
- package/dist/search/find-reactdom-root-apis.js +122 -0
- package/dist/search/find-reactdom-root-apis.js.map +1 -0
- package/dist/testing/enzyme-to-react-testing-library.d.ts +36 -0
- package/dist/testing/enzyme-to-react-testing-library.d.ts.map +1 -0
- package/dist/testing/enzyme-to-react-testing-library.js +547 -0
- package/dist/testing/enzyme-to-react-testing-library.js.map +1 -0
- package/dist/testing/enzyme-usage.d.ts +22 -0
- package/dist/testing/enzyme-usage.d.ts.map +1 -0
- package/dist/testing/enzyme-usage.js +107 -0
- package/dist/testing/enzyme-usage.js.map +1 -0
- package/dist/testing/enzyme-wrapper-scope.d.ts +42 -0
- package/dist/testing/enzyme-wrapper-scope.d.ts.map +1 -0
- package/dist/testing/enzyme-wrapper-scope.js +422 -0
- package/dist/testing/enzyme-wrapper-scope.js.map +1 -0
- package/dist/util/react-class.d.ts +6 -0
- package/dist/util/react-class.d.ts.map +1 -0
- package/dist/util/react-class.js +41 -0
- package/dist/util/react-class.js.map +1 -0
- package/dist/util/tree-search.d.ts +6 -0
- package/dist/util/tree-search.d.ts.map +1 -0
- package/dist/util/tree-search.js +51 -0
- package/dist/util/tree-search.js.map +1 -0
- package/package.json +7 -4
- package/src/index.ts +53 -12
- package/src/migration/cra-to-vite/add-vite-config.ts +47 -0
- package/src/migration/cra-to-vite/cra-blockers-table.ts +27 -0
- package/src/migration/cra-to-vite/cra-to-vite.ts +76 -0
- package/src/migration/cra-to-vite/find-cra-config-blockers.ts +179 -0
- package/src/migration/cra-to-vite/find-cra-env-file-blockers.ts +60 -0
- package/src/migration/cra-to-vite/find-cra-source-blockers.ts +138 -0
- package/src/migration/cra-to-vite/find-cra-to-vite-blockers.ts +21 -0
- package/src/migration/cra-to-vite/index.ts +26 -0
- package/src/migration/cra-to-vite/move-public-index-html.ts +132 -0
- package/src/migration/cra-to-vite/rename-process-env-react-app.ts +93 -0
- package/src/migration/cra-to-vite/rename-react-app-env-vars-in-env-files.ts +61 -0
- package/src/migration/cra-to-vite/replace-react-scripts-dependency.ts +96 -0
- package/src/migration/cra-to-vite/scan-cra-projects.ts +86 -0
- package/src/migration/cra-to-vite/shared.ts +244 -0
- package/src/migration/cra-to-vite/update-react-app-env-types.ts +40 -0
- package/src/migration/cra-to-vite/update-react-scripts-scripts.ts +69 -0
- package/src/migration/cra-to-vite/update-tsconfig-for-vite.ts +47 -0
- package/src/react17/migrate-deprecated-lifecycles.ts +265 -0
- package/src/react17/use-new-jsx-transform.ts +150 -0
- package/src/react18/add-children-to-props.ts +235 -0
- package/src/react18/replace-reactdom-render.ts +109 -20
- package/src/refactoring/class-to-functional.ts +101 -13
- package/src/refactoring/fix-async-effect.ts +88 -0
- package/src/refactoring/prop-types-to-typescript.ts +341 -0
- package/src/search/find-deprecated-lifecycles.ts +64 -0
- package/src/search/find-effects-without-cleanup.ts +109 -0
- package/src/search/find-enzyme-usage.ts +117 -0
- package/src/search/find-function-component-default-props.ts +68 -0
- package/src/search/find-legacy-react-apis.ts +41 -0
- package/src/search/find-missing-use-client-directive.ts +99 -0
- package/src/search/find-reactdom-root-apis.ts +99 -0
- package/src/testing/enzyme-to-react-testing-library.ts +553 -0
- package/src/testing/enzyme-usage.ts +94 -0
- package/src/testing/enzyme-wrapper-scope.ts +449 -0
- package/src/util/react-class.ts +34 -0
- package/src/util/tree-search.ts +32 -0
- package/dist/react16/upgrade-to-react-16.d.ts +0 -12
- package/dist/react16/upgrade-to-react-16.d.ts.map +0 -1
- package/dist/react16/upgrade-to-react-16.js +0 -66
- package/dist/react16/upgrade-to-react-16.js.map +0 -1
- package/dist/react17/upgrade-to-react-17.d.ts +0 -12
- package/dist/react17/upgrade-to-react-17.d.ts.map +0 -1
- package/dist/react17/upgrade-to-react-17.js +0 -62
- package/dist/react17/upgrade-to-react-17.js.map +0 -1
- package/dist/react18/upgrade-to-react-18.d.ts +0 -12
- package/dist/react18/upgrade-to-react-18.d.ts.map +0 -1
- package/dist/react18/upgrade-to-react-18.js +0 -64
- package/dist/react18/upgrade-to-react-18.js.map +0 -1
- package/dist/react19/upgrade-to-react-19.d.ts +0 -8
- package/dist/react19/upgrade-to-react-19.d.ts.map +0 -1
- package/dist/react19/upgrade-to-react-19.js +0 -68
- package/dist/react19/upgrade-to-react-19.js.map +0 -1
- package/src/react16/upgrade-to-react-16.ts +0 -59
- package/src/react17/upgrade-to-react-17.ts +0 -52
- package/src/react18/upgrade-to-react-18.ts +0 -55
- package/src/react19/upgrade-to-react-19.ts +0 -75
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { J } from "@openrewrite/rewrite/java";
|
|
2
|
+
export declare function unwrapBaseType(type: J | undefined): J | undefined;
|
|
3
|
+
export declare function baseTypeArguments(type: J | undefined): J.Container<J> | undefined;
|
|
4
|
+
export declare function extendedClassName(cd: J.ClassDeclaration): string | undefined;
|
|
5
|
+
export declare function extendsReactComponentByName(cd: J.ClassDeclaration): boolean;
|
|
6
|
+
//# sourceMappingURL=react-class.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-class.d.ts","sourceRoot":"","sources":["../../src/util/react-class.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,CAAC,EAAC,MAAM,2BAA2B,CAAC;AAM5C,wBAAgB,cAAc,CAAC,IAAI,EAAE,CAAC,GAAG,SAAS,GAAG,CAAC,GAAG,SAAS,CAKjE;AAGD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,CAAC,GAAG,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,CAKjF;AAGD,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,CAAC,CAAC,gBAAgB,GAAG,MAAM,GAAG,SAAS,CAK5E;AAGD,wBAAgB,2BAA2B,CAAC,EAAE,EAAE,CAAC,CAAC,gBAAgB,GAAG,OAAO,CAG3E"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unwrapBaseType = unwrapBaseType;
|
|
4
|
+
exports.baseTypeArguments = baseTypeArguments;
|
|
5
|
+
exports.extendedClassName = extendedClassName;
|
|
6
|
+
exports.extendsReactComponentByName = extendsReactComponentByName;
|
|
7
|
+
const java_1 = require("@openrewrite/rewrite/java");
|
|
8
|
+
const javascript_1 = require("@openrewrite/rewrite/javascript");
|
|
9
|
+
const COMPONENT_BASES = new Set(['Component', 'PureComponent']);
|
|
10
|
+
function unwrapBaseType(type) {
|
|
11
|
+
if ((type === null || type === void 0 ? void 0 : type.kind) === javascript_1.JS.Kind.TypeTreeExpression)
|
|
12
|
+
return unwrapBaseType(type.expression);
|
|
13
|
+
if ((type === null || type === void 0 ? void 0 : type.kind) === java_1.J.Kind.ParameterizedType)
|
|
14
|
+
return type.class;
|
|
15
|
+
if ((type === null || type === void 0 ? void 0 : type.kind) === javascript_1.JS.Kind.ExpressionWithTypeArguments)
|
|
16
|
+
return type.clazz;
|
|
17
|
+
return type;
|
|
18
|
+
}
|
|
19
|
+
function baseTypeArguments(type) {
|
|
20
|
+
if ((type === null || type === void 0 ? void 0 : type.kind) === javascript_1.JS.Kind.TypeTreeExpression)
|
|
21
|
+
return baseTypeArguments(type.expression);
|
|
22
|
+
if ((type === null || type === void 0 ? void 0 : type.kind) === java_1.J.Kind.ParameterizedType)
|
|
23
|
+
return type.typeParameters;
|
|
24
|
+
if ((type === null || type === void 0 ? void 0 : type.kind) === javascript_1.JS.Kind.ExpressionWithTypeArguments)
|
|
25
|
+
return type.typeArguments;
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
function extendedClassName(cd) {
|
|
29
|
+
var _a;
|
|
30
|
+
const base = unwrapBaseType((_a = cd.extends) === null || _a === void 0 ? void 0 : _a.element);
|
|
31
|
+
if ((base === null || base === void 0 ? void 0 : base.kind) === java_1.J.Kind.Identifier)
|
|
32
|
+
return base.simpleName;
|
|
33
|
+
if ((base === null || base === void 0 ? void 0 : base.kind) === java_1.J.Kind.FieldAccess)
|
|
34
|
+
return base.name.element.simpleName;
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
function extendsReactComponentByName(cd) {
|
|
38
|
+
const name = extendedClassName(cd);
|
|
39
|
+
return !!name && COMPONENT_BASES.has(name);
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=react-class.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-class.js","sourceRoot":"","sources":["../../src/util/react-class.ts"],"names":[],"mappings":";;AAMA,wCAKC;AAGD,8CAKC;AAGD,8CAKC;AAGD,kEAGC;AAjCD,oDAA4C;AAC5C,gEAAmD;AAEnD,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC,CAAC;AAGhE,SAAgB,cAAc,CAAC,IAAmB;IAC9C,IAAI,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,MAAK,eAAE,CAAC,IAAI,CAAC,kBAAkB;QAAE,OAAO,cAAc,CAAE,IAA8B,CAAC,UAAU,CAAC,CAAC;IACjH,IAAI,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,MAAK,QAAC,CAAC,IAAI,CAAC,iBAAiB;QAAE,OAAQ,IAA4B,CAAC,KAAK,CAAC;IACxF,IAAI,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,MAAK,eAAE,CAAC,IAAI,CAAC,2BAA2B;QAAE,OAAQ,IAAuC,CAAC,KAAK,CAAC;IAC9G,OAAO,IAAI,CAAC;AAChB,CAAC;AAGD,SAAgB,iBAAiB,CAAC,IAAmB;IACjD,IAAI,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,MAAK,eAAE,CAAC,IAAI,CAAC,kBAAkB;QAAE,OAAO,iBAAiB,CAAE,IAA8B,CAAC,UAAU,CAAC,CAAC;IACpH,IAAI,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,MAAK,QAAC,CAAC,IAAI,CAAC,iBAAiB;QAAE,OAAQ,IAA4B,CAAC,cAAc,CAAC;IACjG,IAAI,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,MAAK,eAAE,CAAC,IAAI,CAAC,2BAA2B;QAAE,OAAQ,IAAuC,CAAC,aAAa,CAAC;IACtH,OAAO,SAAS,CAAC;AACrB,CAAC;AAGD,SAAgB,iBAAiB,CAAC,EAAsB;;IACpD,MAAM,IAAI,GAAG,cAAc,CAAC,MAAA,EAAE,CAAC,OAAO,0CAAE,OAAO,CAAC,CAAC;IACjD,IAAI,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,MAAK,QAAC,CAAC,IAAI,CAAC,UAAU;QAAE,OAAQ,IAAqB,CAAC,UAAU,CAAC;IAC/E,IAAI,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,MAAK,QAAC,CAAC,IAAI,CAAC,WAAW;QAAE,OAAQ,IAAsB,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC;IAC9F,OAAO,SAAS,CAAC;AACrB,CAAC;AAGD,SAAgB,2BAA2B,CAAC,EAAsB;IAC9D,MAAM,IAAI,GAAG,iBAAiB,CAAC,EAAE,CAAC,CAAC;IACnC,OAAO,CAAC,CAAC,IAAI,IAAI,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { J } from "@openrewrite/rewrite/java";
|
|
2
|
+
export declare function firstResult<T>(tree: J | undefined, pick: (node: J) => T | undefined): Promise<T | undefined>;
|
|
3
|
+
export declare function anyNode(tree: J | undefined, test: (node: J) => boolean): Promise<boolean>;
|
|
4
|
+
export declare const isIdentifierNamed: (node: J, name: string) => boolean;
|
|
5
|
+
export declare const isThis: (expr: J | undefined) => boolean;
|
|
6
|
+
//# sourceMappingURL=tree-search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree-search.d.ts","sourceRoot":"","sources":["../../src/util/tree-search.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,CAAC,EAAC,MAAM,2BAA2B,CAAC;AAG5C,wBAAsB,WAAW,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,SAAS,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,SAAS,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAclH;AAGD,wBAAsB,OAAO,CAAC,IAAI,EAAE,CAAC,GAAG,SAAS,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAE/F;AAGD,eAAO,MAAM,iBAAiB,GAAI,MAAM,CAAC,EAAE,MAAM,MAAM,KAAG,OACuB,CAAC;AAGlF,eAAO,MAAM,MAAM,GAAI,MAAM,CAAC,GAAG,SAAS,KAAG,OAAoD,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.isThis = exports.isIdentifierNamed = void 0;
|
|
13
|
+
exports.firstResult = firstResult;
|
|
14
|
+
exports.anyNode = anyNode;
|
|
15
|
+
const javascript_1 = require("@openrewrite/rewrite/javascript");
|
|
16
|
+
const java_1 = require("@openrewrite/rewrite/java");
|
|
17
|
+
function firstResult(tree, pick) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
if (!tree)
|
|
20
|
+
return undefined;
|
|
21
|
+
let result;
|
|
22
|
+
yield new class extends javascript_1.JavaScriptVisitor {
|
|
23
|
+
visit(t, ctx, parent) {
|
|
24
|
+
const _super = Object.create(null, {
|
|
25
|
+
visit: { get: () => super.visit }
|
|
26
|
+
});
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
if (result !== undefined)
|
|
29
|
+
return t;
|
|
30
|
+
if (t && typeof t === 'object' && t.kind) {
|
|
31
|
+
result = pick(t);
|
|
32
|
+
if (result !== undefined)
|
|
33
|
+
return t;
|
|
34
|
+
}
|
|
35
|
+
return _super.visit.call(this, t, ctx, parent);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}().visit(tree, {});
|
|
39
|
+
return result;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
function anyNode(tree, test) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
return (yield firstResult(tree, n => test(n) ? true : undefined)) === true;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
const isIdentifierNamed = (node, name) => node.kind === java_1.J.Kind.Identifier && node.simpleName === name;
|
|
48
|
+
exports.isIdentifierNamed = isIdentifierNamed;
|
|
49
|
+
const isThis = (expr) => !!expr && (0, exports.isIdentifierNamed)(expr, 'this');
|
|
50
|
+
exports.isThis = isThis;
|
|
51
|
+
//# sourceMappingURL=tree-search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree-search.js","sourceRoot":"","sources":["../../src/util/tree-search.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,kCAcC;AAGD,0BAEC;AAvBD,gEAAkE;AAClE,oDAA4C;AAG5C,SAAsB,WAAW,CAAI,IAAmB,EAAE,IAAgC;;QACtF,IAAI,CAAC,IAAI;YAAE,OAAO,SAAS,CAAC;QAC5B,IAAI,MAAqB,CAAC;QAC1B,MAAM,IAAI,KAAM,SAAQ,8BAAmC;YACxC,KAAK,CAAc,CAAM,EAAE,GAAqB,EAAE,MAAY;;;;;oBACzE,IAAI,MAAM,KAAK,SAAS;wBAAE,OAAO,CAAC,CAAC;oBACnC,IAAI,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;wBACvC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;wBACjB,IAAI,MAAM,KAAK,SAAS;4BAAE,OAAO,CAAC,CAAC;oBACvC,CAAC;oBACD,OAAO,OAAM,KAAK,YAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE;gBACvC,CAAC;aAAA;SACJ,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,EAAsB,CAAC,CAAC;QACxC,OAAO,MAAM,CAAC;IAClB,CAAC;CAAA;AAGD,SAAsB,OAAO,CAAC,IAAmB,EAAE,IAA0B;;QACzE,OAAO,CAAA,MAAM,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,MAAK,IAAI,CAAC;IAC7E,CAAC;CAAA;AAGM,MAAM,iBAAiB,GAAG,CAAC,IAAO,EAAE,IAAY,EAAW,EAAE,CAChE,IAAI,CAAC,IAAI,KAAK,QAAC,CAAC,IAAI,CAAC,UAAU,IAAK,IAAqB,CAAC,UAAU,KAAK,IAAI,CAAC;AADrE,QAAA,iBAAiB,qBACoD;AAG3E,MAAM,MAAM,GAAG,CAAC,IAAmB,EAAW,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,IAAA,yBAAiB,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AAArF,QAAA,MAAM,UAA+E"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openrewrite/recipes-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"license": "Moderne Source Available License",
|
|
5
5
|
"description": "OpenRewrite recipes for React.",
|
|
6
6
|
"homepage": "https://github.com/openrewrite/rewrite",
|
|
@@ -24,14 +24,17 @@
|
|
|
24
24
|
"ci:test": "NODE_OPTIONS=--max-old-space-size=6144 vitest run"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@openrewrite/rewrite": "^8.97.
|
|
28
|
-
"mutative": "^1.1.0"
|
|
27
|
+
"@openrewrite/rewrite": "^8.97.2",
|
|
28
|
+
"mutative": "^1.1.0",
|
|
29
|
+
"semver": "^7.8.6"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
32
|
+
"@types/semver": "^7.8.0",
|
|
31
33
|
"bun": "^1.3.5",
|
|
32
34
|
"tmp-promise": "^3.0.3",
|
|
33
35
|
"ts-node": "^10.9.2",
|
|
34
36
|
"typescript": "^5.6.2",
|
|
35
|
-
"vitest": "^4.1.11"
|
|
37
|
+
"vitest": "^4.1.11",
|
|
38
|
+
"yaml": "^2.9.0"
|
|
36
39
|
}
|
|
37
40
|
}
|
package/src/index.ts
CHANGED
|
@@ -18,7 +18,6 @@ import {DeprecatedReactTypes} from './react19/deprecated-react-types';
|
|
|
18
18
|
import {FindLegacyContextAPI} from './react19/find-legacy-context-api';
|
|
19
19
|
import {FindDeprecatedReactDomAPIs} from './react19/find-deprecated-reactdom-apis';
|
|
20
20
|
import {FindContextConsumer} from './react19/find-context-consumer';
|
|
21
|
-
import {UpgradeToReact19} from './react19/upgrade-to-react-19';
|
|
22
21
|
|
|
23
22
|
import {FindElementRef} from './react19/find-element-ref';
|
|
24
23
|
import {ReplaceReactShallowRenderer} from './react19/replace-react-shallow-renderer';
|
|
@@ -28,13 +27,14 @@ import {ReplaceReactDomRender} from './react18/replace-reactdom-render';
|
|
|
28
27
|
import {RemoveUnstableBatchedUpdates} from './react18/remove-unstable-batched-updates';
|
|
29
28
|
import {ReplaceUnmountComponentAtNode} from './react18/replace-unmount-component-at-node';
|
|
30
29
|
import {ReplaceRenderCallback} from './react18/replace-render-callback';
|
|
31
|
-
import {
|
|
30
|
+
import {AddChildrenToProps} from './react18/add-children-to-props';
|
|
32
31
|
|
|
33
32
|
// React 17
|
|
33
|
+
import {MigrateDeprecatedLifecycles} from './react17/migrate-deprecated-lifecycles';
|
|
34
34
|
import {RenameUnsafeLifecycles} from './react17/rename-unsafe-lifecycles';
|
|
35
35
|
import {UpdateReactImports} from './react17/update-react-imports';
|
|
36
36
|
import {RemoveEventPersist} from './react17/remove-event-persist';
|
|
37
|
-
import {
|
|
37
|
+
import {UseNewJsxTransform} from './react17/use-new-jsx-transform';
|
|
38
38
|
|
|
39
39
|
// React 16
|
|
40
40
|
import {ErrorBoundaries} from './react16/error-boundaries';
|
|
@@ -43,7 +43,6 @@ import {ReactPropTypes} from './react16/react-prop-types';
|
|
|
43
43
|
import {ReactDomFactories} from './react16/react-dom-factories';
|
|
44
44
|
import {ReactToReactDom} from './react16/react-to-react-dom';
|
|
45
45
|
import {ReplaceCreateFactory} from './react16/replace-create-factory';
|
|
46
|
-
import {UpgradeToReact16} from './react16/upgrade-to-react-16';
|
|
47
46
|
|
|
48
47
|
// Refactoring
|
|
49
48
|
import {CreateClassToES6} from './refactoring/create-class-to-es6';
|
|
@@ -51,22 +50,38 @@ import {ClassToFunctional} from './refactoring/class-to-functional';
|
|
|
51
50
|
import {ManualBindToArrow} from './refactoring/manual-bind-to-arrow';
|
|
52
51
|
import {CreateElementToJsx} from './refactoring/create-element-to-jsx';
|
|
53
52
|
import {SortComp} from './refactoring/sort-comp';
|
|
53
|
+
import {PropTypesToTypeScript} from './refactoring/prop-types-to-typescript';
|
|
54
|
+
import {FixAsyncEffect} from './refactoring/fix-async-effect';
|
|
54
55
|
import {PureRenderMixin} from './refactoring/pure-render-mixin';
|
|
55
56
|
|
|
56
57
|
// React Native
|
|
57
58
|
import {ViewPropTypes} from './react-native/view-prop-types';
|
|
58
59
|
|
|
60
|
+
// Testing
|
|
61
|
+
import {EnzymeToReactTestingLibrary} from './testing/enzyme-to-react-testing-library';
|
|
62
|
+
|
|
59
63
|
// Search & Analysis
|
|
64
|
+
import {FindEnzymeUsage} from './search/find-enzyme-usage';
|
|
60
65
|
import {FindReactComponent} from './search/find-react-component';
|
|
61
66
|
import {FindHookUsage} from './search/find-hook-usage';
|
|
62
67
|
import {FindPropUsage} from './search/find-prop-usage';
|
|
63
68
|
import {FindServerRenderingUsage} from './search/find-server-rendering-usage';
|
|
64
69
|
|
|
70
|
+
import {FindLegacyReactApis} from './search/find-legacy-react-apis';
|
|
71
|
+
import {FindReactDomRootApis} from './search/find-reactdom-root-apis';
|
|
72
|
+
import {FindDeprecatedLifecycles} from './search/find-deprecated-lifecycles';
|
|
73
|
+
import {FindFunctionComponentDefaultProps} from './search/find-function-component-default-props';
|
|
74
|
+
import {FindEffectsWithoutCleanup} from './search/find-effects-without-cleanup';
|
|
75
|
+
import {FindMissingUseClientDirective} from './search/find-missing-use-client-directive';
|
|
76
|
+
|
|
65
77
|
// General
|
|
66
78
|
import {SimplifyReactImports} from './simplify-react-imports';
|
|
67
79
|
import {SimplifyObjectPatternProperty} from './simplify-object-pattern-property';
|
|
68
80
|
import {ChangeComponentPropValue} from './migration/change-component-prop-value';
|
|
69
81
|
|
|
82
|
+
// CRA to Vite
|
|
83
|
+
import {CraToVite, craToViteRecipes} from './migration/cra-to-vite';
|
|
84
|
+
|
|
70
85
|
// Categories
|
|
71
86
|
const React: CategoryDescriptor[] = [...JavaScript, {displayName: "React"}];
|
|
72
87
|
const ReactMigrate: CategoryDescriptor[] = [...React, {displayName: "Migrate"}];
|
|
@@ -76,6 +91,7 @@ const React18: CategoryDescriptor[] = [...ReactMigrate, {displayName: "React 18"
|
|
|
76
91
|
const React19: CategoryDescriptor[] = [...ReactMigrate, {displayName: "React 19"}];
|
|
77
92
|
const ReactMigration: CategoryDescriptor[] = [...React, {displayName: "Migration"}];
|
|
78
93
|
const ReactRefactoring: CategoryDescriptor[] = [...React, {displayName: "Refactoring"}];
|
|
94
|
+
const CraToViteMigrate: CategoryDescriptor[] = [...ReactMigrate, {displayName: "Create React App to Vite"}];
|
|
79
95
|
const ReactNative: CategoryDescriptor[] = [...React, {displayName: "React Native"}];
|
|
80
96
|
const ReactSearch: CategoryDescriptor[] = [...React, {displayName: "Search"}];
|
|
81
97
|
const JavaScriptCleanup: CategoryDescriptor[] = [...JavaScript, {displayName: "Cleanup"}];
|
|
@@ -101,20 +117,20 @@ export async function activate(marketplace: RecipeMarketplace) {
|
|
|
101
117
|
await marketplace.install(FindContextConsumer, React19);
|
|
102
118
|
await marketplace.install(FindElementRef, React19);
|
|
103
119
|
await marketplace.install(ReplaceReactShallowRenderer, React19);
|
|
104
|
-
await marketplace.install(UpgradeToReact19, ReactMigrate);
|
|
105
120
|
|
|
106
121
|
// React 18
|
|
107
122
|
await marketplace.install(ReplaceReactDomRender, React18);
|
|
108
123
|
await marketplace.install(RemoveUnstableBatchedUpdates, React18);
|
|
109
124
|
await marketplace.install(ReplaceUnmountComponentAtNode, React18);
|
|
110
125
|
await marketplace.install(ReplaceRenderCallback, React18);
|
|
111
|
-
await marketplace.install(
|
|
126
|
+
await marketplace.install(AddChildrenToProps, React18);
|
|
112
127
|
|
|
113
128
|
// React 17
|
|
129
|
+
await marketplace.install(MigrateDeprecatedLifecycles, React17);
|
|
114
130
|
await marketplace.install(RenameUnsafeLifecycles, React17);
|
|
115
131
|
await marketplace.install(UpdateReactImports, React17);
|
|
116
132
|
await marketplace.install(RemoveEventPersist, React17);
|
|
117
|
-
await marketplace.install(
|
|
133
|
+
await marketplace.install(UseNewJsxTransform, React17);
|
|
118
134
|
|
|
119
135
|
// React 16
|
|
120
136
|
await marketplace.install(ErrorBoundaries, React16);
|
|
@@ -123,7 +139,6 @@ export async function activate(marketplace: RecipeMarketplace) {
|
|
|
123
139
|
await marketplace.install(ReactDomFactories, React16);
|
|
124
140
|
await marketplace.install(ReactToReactDom, React16);
|
|
125
141
|
await marketplace.install(ReplaceCreateFactory, React16);
|
|
126
|
-
await marketplace.install(UpgradeToReact16, ReactMigrate);
|
|
127
142
|
|
|
128
143
|
// Refactoring
|
|
129
144
|
await marketplace.install(CreateClassToES6, ReactRefactoring);
|
|
@@ -132,15 +147,31 @@ export async function activate(marketplace: RecipeMarketplace) {
|
|
|
132
147
|
await marketplace.install(CreateElementToJsx, ReactRefactoring);
|
|
133
148
|
await marketplace.install(SortComp, ReactRefactoring);
|
|
134
149
|
await marketplace.install(PureRenderMixin, ReactRefactoring);
|
|
150
|
+
await marketplace.install(FixAsyncEffect, ReactRefactoring);
|
|
151
|
+
await marketplace.install(PropTypesToTypeScript, ReactRefactoring);
|
|
135
152
|
|
|
136
153
|
// React Native
|
|
137
154
|
await marketplace.install(ViewPropTypes, ReactNative);
|
|
138
155
|
|
|
156
|
+
// Testing
|
|
157
|
+
await marketplace.install(EnzymeToReactTestingLibrary, ReactMigration);
|
|
158
|
+
|
|
139
159
|
// Search & Analysis
|
|
140
160
|
await marketplace.install(FindReactComponent, ReactSearch);
|
|
141
161
|
await marketplace.install(FindHookUsage, ReactSearch);
|
|
162
|
+
await marketplace.install(FindEnzymeUsage, ReactSearch);
|
|
142
163
|
await marketplace.install(FindPropUsage, ReactSearch);
|
|
143
164
|
await marketplace.install(FindServerRenderingUsage, ReactSearch);
|
|
165
|
+
await marketplace.install(FindLegacyReactApis, ReactSearch);
|
|
166
|
+
await marketplace.install(FindReactDomRootApis, ReactSearch);
|
|
167
|
+
await marketplace.install(FindDeprecatedLifecycles, ReactSearch);
|
|
168
|
+
await marketplace.install(FindFunctionComponentDefaultProps, ReactSearch);
|
|
169
|
+
await marketplace.install(FindEffectsWithoutCleanup, ReactSearch);
|
|
170
|
+
await marketplace.install(FindMissingUseClientDirective, ReactSearch);
|
|
171
|
+
|
|
172
|
+
// CRA to Vite
|
|
173
|
+
await marketplace.install(CraToVite, ReactMigrate);
|
|
174
|
+
for (const recipe of craToViteRecipes) await marketplace.install(recipe, CraToViteMigrate);
|
|
144
175
|
|
|
145
176
|
// General
|
|
146
177
|
await marketplace.install(SimplifyReactImports, React);
|
|
@@ -167,20 +198,20 @@ export {FindDeprecatedReactDomAPIs} from './react19/find-deprecated-reactdom-api
|
|
|
167
198
|
export {FindContextConsumer} from './react19/find-context-consumer';
|
|
168
199
|
export {FindElementRef} from './react19/find-element-ref';
|
|
169
200
|
export {ReplaceReactShallowRenderer} from './react19/replace-react-shallow-renderer';
|
|
170
|
-
export {UpgradeToReact19} from './react19/upgrade-to-react-19';
|
|
171
201
|
|
|
172
202
|
// React 18
|
|
173
203
|
export {ReplaceReactDomRender} from './react18/replace-reactdom-render';
|
|
174
204
|
export {RemoveUnstableBatchedUpdates} from './react18/remove-unstable-batched-updates';
|
|
175
205
|
export {ReplaceUnmountComponentAtNode} from './react18/replace-unmount-component-at-node';
|
|
176
206
|
export {ReplaceRenderCallback} from './react18/replace-render-callback';
|
|
177
|
-
export {
|
|
207
|
+
export {AddChildrenToProps} from './react18/add-children-to-props';
|
|
178
208
|
|
|
179
209
|
// React 17
|
|
210
|
+
export {MigrateDeprecatedLifecycles} from './react17/migrate-deprecated-lifecycles';
|
|
180
211
|
export {RenameUnsafeLifecycles} from './react17/rename-unsafe-lifecycles';
|
|
181
212
|
export {UpdateReactImports} from './react17/update-react-imports';
|
|
182
213
|
export {RemoveEventPersist} from './react17/remove-event-persist';
|
|
183
|
-
export {
|
|
214
|
+
export {UseNewJsxTransform} from './react17/use-new-jsx-transform';
|
|
184
215
|
|
|
185
216
|
// React 16
|
|
186
217
|
export {ErrorBoundaries} from './react16/error-boundaries';
|
|
@@ -189,7 +220,6 @@ export {ReactPropTypes} from './react16/react-prop-types';
|
|
|
189
220
|
export {ReactDomFactories} from './react16/react-dom-factories';
|
|
190
221
|
export {ReactToReactDom} from './react16/react-to-react-dom';
|
|
191
222
|
export {ReplaceCreateFactory} from './react16/replace-create-factory';
|
|
192
|
-
export {UpgradeToReact16} from './react16/upgrade-to-react-16';
|
|
193
223
|
|
|
194
224
|
// Refactoring
|
|
195
225
|
export {CreateClassToES6} from './refactoring/create-class-to-es6';
|
|
@@ -197,6 +227,8 @@ export {ClassToFunctional} from './refactoring/class-to-functional';
|
|
|
197
227
|
export {ManualBindToArrow} from './refactoring/manual-bind-to-arrow';
|
|
198
228
|
export {CreateElementToJsx} from './refactoring/create-element-to-jsx';
|
|
199
229
|
export {SortComp} from './refactoring/sort-comp';
|
|
230
|
+
export {PropTypesToTypeScript} from './refactoring/prop-types-to-typescript';
|
|
231
|
+
export {FixAsyncEffect} from './refactoring/fix-async-effect';
|
|
200
232
|
export {PureRenderMixin} from './refactoring/pure-render-mixin';
|
|
201
233
|
|
|
202
234
|
// React Native
|
|
@@ -207,6 +239,15 @@ export {FindReactComponent} from './search/find-react-component';
|
|
|
207
239
|
export {FindHookUsage} from './search/find-hook-usage';
|
|
208
240
|
export {FindPropUsage} from './search/find-prop-usage';
|
|
209
241
|
export {FindServerRenderingUsage} from './search/find-server-rendering-usage';
|
|
242
|
+
export {FindLegacyReactApis} from './search/find-legacy-react-apis';
|
|
243
|
+
export {FindReactDomRootApis} from './search/find-reactdom-root-apis';
|
|
244
|
+
export {FindDeprecatedLifecycles} from './search/find-deprecated-lifecycles';
|
|
245
|
+
export {FindFunctionComponentDefaultProps} from './search/find-function-component-default-props';
|
|
246
|
+
export {FindEffectsWithoutCleanup} from './search/find-effects-without-cleanup';
|
|
247
|
+
export {FindMissingUseClientDirective} from './search/find-missing-use-client-directive';
|
|
248
|
+
|
|
249
|
+
// CRA to Vite
|
|
250
|
+
export * from './migration/cra-to-vite';
|
|
210
251
|
|
|
211
252
|
// General
|
|
212
253
|
export {SimplifyReactImports} from './simplify-react-imports';
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {ExecutionContext, SourceFile} from "@openrewrite/rewrite";
|
|
2
|
+
import {JavaScriptParser} from "@openrewrite/rewrite/javascript";
|
|
3
|
+
import {CraProjects, CraScanningRecipe, VITE_CONFIG_NAMES} from "./scan-cra-projects";
|
|
4
|
+
import {joinPath} from "./shared";
|
|
5
|
+
|
|
6
|
+
const CONFIG_BODY = `import {defineConfig} from 'vite';
|
|
7
|
+
import react from '@vitejs/plugin-react';
|
|
8
|
+
|
|
9
|
+
export default defineConfig({
|
|
10
|
+
plugins: [react()],
|
|
11
|
+
// Create React App served on 3000 and wrote to build/, which scripts and deployments often rely on.
|
|
12
|
+
server: {port: 3000},
|
|
13
|
+
build: {outDir: 'build'},
|
|
14
|
+
});
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Adds a `vite.config.ts` (or `vite.config.js` for projects without a `tsconfig.json`) next to the
|
|
19
|
+
* `package.json` of each Create React App project, which keeps the CRA port and `build` output folder.
|
|
20
|
+
*
|
|
21
|
+
* ```ts
|
|
22
|
+
* export default defineConfig({plugins: [react()], server: {port: 3000}, build: {outDir: 'build'}});
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* A project that already has a Vite config is left alone. JSX in `.js` files is not handled by
|
|
26
|
+
* `@vitejs/plugin-react`; `FindCraToViteBlockers` reports those files.
|
|
27
|
+
*
|
|
28
|
+
* @see https://react.dev/blog/2025/02/14/sunsetting-create-react-app#how-to-migrate-to-a-build-tool
|
|
29
|
+
*/
|
|
30
|
+
export class AddViteConfig extends CraScanningRecipe {
|
|
31
|
+
readonly name = "org.openrewrite.react.cra-to-vite.add-vite-config";
|
|
32
|
+
readonly displayName = "Add a Vite config to Create React App projects";
|
|
33
|
+
readonly description = "Adds a `vite.config.ts` or `vite.config.js` with the React plugin to each project that uses `react-scripts`, keeping the Create React App port `3000` and `build` output folder. Projects that already have a Vite config are left unchanged.";
|
|
34
|
+
|
|
35
|
+
async generate(acc: CraProjects, ctx: ExecutionContext): Promise<SourceFile[]> {
|
|
36
|
+
const generated: SourceFile[] = [];
|
|
37
|
+
const parser = new JavaScriptParser({ctx});
|
|
38
|
+
for (const root of acc.viteRoots) {
|
|
39
|
+
if (VITE_CONFIG_NAMES.some(name => acc.has(root, name))) continue;
|
|
40
|
+
const file = acc.has(root, "tsconfig.json") ? "vite.config.ts" : "vite.config.js";
|
|
41
|
+
const sourcePath = joinPath(root, file);
|
|
42
|
+
generated.push(await parser.parseOne({text: CONFIG_BODY, sourcePath}));
|
|
43
|
+
}
|
|
44
|
+
return generated;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {Column, DataTable} from "@openrewrite/rewrite";
|
|
2
|
+
|
|
3
|
+
export class CraToViteBlockerRow {
|
|
4
|
+
@Column({displayName: "File path", description: "The file that holds the construct."})
|
|
5
|
+
filePath!: string;
|
|
6
|
+
|
|
7
|
+
@Column({displayName: "Category", description: "The kind of Create React App feature that has no direct Vite equivalent, such as `craco`, `jest`, `svg-react-component`."})
|
|
8
|
+
category!: string;
|
|
9
|
+
|
|
10
|
+
@Column({displayName: "Detail", description: "The construct that was found, for example the script, dependency or import."})
|
|
11
|
+
detail!: string;
|
|
12
|
+
|
|
13
|
+
@Column({displayName: "Next step", description: "What to do by hand to finish the migration."})
|
|
14
|
+
nextStep!: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const CRA_TO_VITE_BLOCKERS_TABLE = "org.openrewrite.react.cra-to-vite.CraToViteBlockers";
|
|
18
|
+
|
|
19
|
+
/** Every finder writes to a table of this name, which the host merges into one. */
|
|
20
|
+
export function craToViteBlockersTable(): DataTable<CraToViteBlockerRow> {
|
|
21
|
+
return new DataTable<CraToViteBlockerRow>(
|
|
22
|
+
CRA_TO_VITE_BLOCKERS_TABLE,
|
|
23
|
+
"Create React App to Vite blockers",
|
|
24
|
+
"Constructs in a Create React App project that the Vite migration does not rewrite and that need a manual step.",
|
|
25
|
+
CraToViteBlockerRow
|
|
26
|
+
);
|
|
27
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import {Option, Recipe} from "@openrewrite/rewrite";
|
|
2
|
+
import {AddViteConfig} from "./add-vite-config";
|
|
3
|
+
import {FindCraConfigBlockers} from "./find-cra-config-blockers";
|
|
4
|
+
import {FindCraEnvFileBlockers} from "./find-cra-env-file-blockers";
|
|
5
|
+
import {FindCraSourceBlockers} from "./find-cra-source-blockers";
|
|
6
|
+
import {MovePublicIndexHtml} from "./move-public-index-html";
|
|
7
|
+
import {RenameProcessEnvReactApp} from "./rename-process-env-react-app";
|
|
8
|
+
import {RenameReactAppEnvVarsInEnvFiles} from "./rename-react-app-env-vars-in-env-files";
|
|
9
|
+
import {ReplaceReactScriptsDependency} from "./replace-react-scripts-dependency";
|
|
10
|
+
import {UpdateReactAppEnvTypes} from "./update-react-app-env-types";
|
|
11
|
+
import {UpdateReactScriptsScripts} from "./update-react-scripts-scripts";
|
|
12
|
+
import {UpdateTsconfigForVite} from "./update-tsconfig-for-vite";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Migrates a Create React App project to Vite.
|
|
16
|
+
*
|
|
17
|
+
* Changes include:
|
|
18
|
+
* - Add `vite` and `@vitejs/plugin-react`, rewrite the `start` and `build` scripts, remove `eject`, and remove
|
|
19
|
+
* `react-scripts` unless a script such as `react-scripts test` still runs it
|
|
20
|
+
* - Add a `vite.config.ts` or `vite.config.js`
|
|
21
|
+
* - Move `public/index.html` to the project root with a module script
|
|
22
|
+
* - Rename `REACT_APP_*` to `VITE_*` in `.env` files and `process.env.REACT_APP_*` to `import.meta.env.VITE_*`
|
|
23
|
+
* - Point `src/react-app-env.d.ts` and `tsconfig.json` at `vite/client`
|
|
24
|
+
* - Record in the `CraToViteBlockers` data table what needs a manual step: `craco`, Jest, SVG `ReactComponent`
|
|
25
|
+
* imports, `REACT_APP_*` values set outside `.env` files and the like
|
|
26
|
+
*
|
|
27
|
+
* A package that uses `craco` or `react-app-rewired`, or whose `start` or `build` script wraps `react-scripts`, is
|
|
28
|
+
* only reported in the data table and otherwise left unchanged.
|
|
29
|
+
*
|
|
30
|
+
* Run your package manager afterwards to update the lock file.
|
|
31
|
+
*
|
|
32
|
+
* @see https://react.dev/blog/2025/02/14/sunsetting-create-react-app#how-to-migrate-to-a-build-tool
|
|
33
|
+
*/
|
|
34
|
+
export class CraToVite extends Recipe {
|
|
35
|
+
readonly name = "org.openrewrite.react.migrate.cra-to-vite";
|
|
36
|
+
readonly displayName = "Migrate Create React App to Vite";
|
|
37
|
+
readonly description = "Moves a Create React App project to Vite: adds the Vite dependencies, rewrites the `start` and `build` scripts (keeping a type check in `build` when there is a `tsconfig.json`), adds a Vite config, moves `public/index.html` to the project root, renames `REACT_APP_*` variables to `VITE_*` and points TypeScript at `vite/client`. `react-scripts` is removed only when no script such as `react-scripts test` still runs it. Packages that use `craco` or `react-app-rewired`, or whose `start` or `build` script wraps `react-scripts`, are not edited; they and other constructs that need a manual step, such as Jest configuration or SVG `ReactComponent` imports, are recorded in a data table.";
|
|
38
|
+
|
|
39
|
+
@Option({
|
|
40
|
+
displayName: "Vite version",
|
|
41
|
+
description: "The version range of `vite` to add. Vite 7 needs Node 20.19 or later.",
|
|
42
|
+
example: "^7.0.0",
|
|
43
|
+
required: false
|
|
44
|
+
})
|
|
45
|
+
viteVersion?: string;
|
|
46
|
+
|
|
47
|
+
@Option({
|
|
48
|
+
displayName: "Vite React plugin version",
|
|
49
|
+
description: "The version range of `@vitejs/plugin-react` to add. It must accept the `vite` range above.",
|
|
50
|
+
example: "^5.2.0",
|
|
51
|
+
required: false
|
|
52
|
+
})
|
|
53
|
+
pluginReactVersion?: string;
|
|
54
|
+
|
|
55
|
+
constructor(options?: { viteVersion?: string; pluginReactVersion?: string }) {
|
|
56
|
+
super(options);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async recipeList(): Promise<Recipe[]> {
|
|
60
|
+
return [
|
|
61
|
+
// The finders and the file recipes look at the project as Create React App left it, so they run before
|
|
62
|
+
// the dependency swap removes react-scripts, which is how they recognize the project.
|
|
63
|
+
new FindCraConfigBlockers({markResults: false}),
|
|
64
|
+
new FindCraSourceBlockers(),
|
|
65
|
+
new FindCraEnvFileBlockers(),
|
|
66
|
+
new AddViteConfig(),
|
|
67
|
+
new MovePublicIndexHtml(),
|
|
68
|
+
new UpdateReactScriptsScripts(),
|
|
69
|
+
new RenameReactAppEnvVarsInEnvFiles(),
|
|
70
|
+
new RenameProcessEnvReactApp(),
|
|
71
|
+
new UpdateReactAppEnvTypes(),
|
|
72
|
+
new UpdateTsconfigForVite(),
|
|
73
|
+
new ReplaceReactScriptsDependency({viteVersion: this.viteVersion, pluginReactVersion: this.pluginReactVersion}),
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
}
|