@openrewrite/recipes-react 0.19.0 → 0.21.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/i18n/translate-hard-coded-strings.d.ts +67 -0
- package/dist/i18n/translate-hard-coded-strings.d.ts.map +1 -0
- package/dist/i18n/translate-hard-coded-strings.js +439 -0
- package/dist/i18n/translate-hard-coded-strings.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/dist/search/find-enzyme-usage.d.ts +4 -0
- package/dist/search/find-enzyme-usage.d.ts.map +1 -1
- package/dist/search/find-enzyme-usage.js +64 -4
- package/dist/search/find-enzyme-usage.js.map +1 -1
- package/dist/search/find-hard-coded-strings.d.ts +110 -0
- package/dist/search/find-hard-coded-strings.d.ts.map +1 -0
- package/dist/search/find-hard-coded-strings.js +987 -0
- package/dist/search/find-hard-coded-strings.js.map +1 -0
- package/dist/search/find-missing-use-client-directive.d.ts +2 -0
- package/dist/search/find-missing-use-client-directive.d.ts.map +1 -1
- package/dist/search/find-missing-use-client-directive.js +1 -0
- package/dist/search/find-missing-use-client-directive.js.map +1 -1
- package/dist/testing/enzyme-portals.d.ts +3 -5
- package/dist/testing/enzyme-portals.d.ts.map +1 -1
- package/dist/testing/enzyme-portals.js +8 -39
- package/dist/testing/enzyme-portals.js.map +1 -1
- package/dist/testing/enzyme-render-blockers.d.ts +10 -0
- package/dist/testing/enzyme-render-blockers.d.ts.map +1 -0
- package/dist/testing/enzyme-render-blockers.js +119 -0
- package/dist/testing/enzyme-render-blockers.js.map +1 -0
- package/dist/testing/enzyme-shared-wrapper.d.ts +26 -0
- package/dist/testing/enzyme-shared-wrapper.d.ts.map +1 -0
- package/dist/testing/enzyme-shared-wrapper.js +213 -0
- package/dist/testing/enzyme-shared-wrapper.js.map +1 -0
- package/dist/testing/enzyme-to-react-testing-library.d.ts +9 -2
- package/dist/testing/enzyme-to-react-testing-library.d.ts.map +1 -1
- package/dist/testing/enzyme-to-react-testing-library.js +355 -16
- package/dist/testing/enzyme-to-react-testing-library.js.map +1 -1
- package/dist/testing/enzyme-usage.d.ts +5 -1
- package/dist/testing/enzyme-usage.d.ts.map +1 -1
- package/dist/testing/enzyme-usage.js +48 -6
- package/dist/testing/enzyme-usage.js.map +1 -1
- package/dist/testing/enzyme-wrapper-scope.d.ts +7 -1
- package/dist/testing/enzyme-wrapper-scope.d.ts.map +1 -1
- package/dist/testing/enzyme-wrapper-scope.js +24 -9
- package/dist/testing/enzyme-wrapper-scope.js.map +1 -1
- package/dist/util/json-and-javascript.d.ts +4 -0
- package/dist/util/json-and-javascript.d.ts.map +1 -0
- package/dist/util/json-and-javascript.js +37 -0
- package/dist/util/json-and-javascript.js.map +1 -0
- package/dist/util/module-imports.d.ts +36 -0
- package/dist/util/module-imports.d.ts.map +1 -1
- package/dist/util/module-imports.js +216 -0
- package/dist/util/module-imports.js.map +1 -1
- package/dist/util/test-source.d.ts +2 -0
- package/dist/util/test-source.d.ts.map +1 -0
- package/dist/util/test-source.js +5 -0
- package/dist/util/test-source.js.map +1 -0
- package/dist/zustand/entry-store.d.ts +9 -0
- package/dist/zustand/entry-store.d.ts.map +1 -0
- package/dist/zustand/entry-store.js +136 -0
- package/dist/zustand/entry-store.js.map +1 -0
- package/dist/zustand/redux-stores.d.ts +15 -4
- package/dist/zustand/redux-stores.d.ts.map +1 -1
- package/dist/zustand/redux-stores.js +155 -10
- package/dist/zustand/redux-stores.js.map +1 -1
- package/dist/zustand/redux-to-zustand.d.ts +29 -5
- package/dist/zustand/redux-to-zustand.d.ts.map +1 -1
- package/dist/zustand/redux-to-zustand.js +629 -42
- package/dist/zustand/redux-to-zustand.js.map +1 -1
- package/dist/zustand/zustand-plan.d.ts +31 -6
- package/dist/zustand/zustand-plan.d.ts.map +1 -1
- package/dist/zustand/zustand-plan.js +320 -31
- package/dist/zustand/zustand-plan.js.map +1 -1
- package/package.json +1 -1
- package/src/i18n/translate-hard-coded-strings.ts +442 -0
- package/src/index.ts +7 -0
- package/src/search/find-enzyme-usage.ts +59 -6
- package/src/search/find-hard-coded-strings.ts +1006 -0
- package/src/search/find-missing-use-client-directive.ts +1 -1
- package/src/testing/enzyme-portals.ts +4 -44
- package/src/testing/enzyme-render-blockers.ts +113 -0
- package/src/testing/enzyme-shared-wrapper.ts +224 -0
- package/src/testing/enzyme-to-react-testing-library.ts +354 -19
- package/src/testing/enzyme-usage.ts +62 -5
- package/src/testing/enzyme-wrapper-scope.ts +24 -6
- package/src/util/json-and-javascript.ts +26 -0
- package/src/util/module-imports.ts +223 -0
- package/src/util/test-source.ts +2 -0
- package/src/zustand/entry-store.ts +131 -0
- package/src/zustand/redux-stores.ts +171 -11
- package/src/zustand/redux-to-zustand.ts +689 -48
- package/src/zustand/zustand-plan.ts +350 -29
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ExecutionContext, ScanningRecipe, SourceFile, TreeVisitor } from "@openrewrite/rewrite";
|
|
2
2
|
import { AddDependencyOptions } from "@openrewrite/rewrite/javascript";
|
|
3
3
|
import { JavaDependencyRecipe } from "../util/java-recipe-proxy";
|
|
4
|
+
import { PathsConfigs } from "../util/module-imports";
|
|
4
5
|
import { SliceModule } from "./redux-stores";
|
|
5
6
|
import { SliceSource, SourceFacts } from "./zustand-plan";
|
|
6
7
|
export interface ZustandForecast {
|
|
@@ -10,55 +11,72 @@ export interface ZustandForecast {
|
|
|
10
11
|
lock: string;
|
|
11
12
|
}>;
|
|
12
13
|
react?: (root: string) => string | undefined;
|
|
14
|
+
withoutImmer?: Set<string>;
|
|
13
15
|
}
|
|
14
16
|
interface PackageFacts {
|
|
15
17
|
react?: string;
|
|
18
|
+
reactDom?: string;
|
|
19
|
+
reactNative?: string;
|
|
16
20
|
zustand?: string;
|
|
17
21
|
immer?: string;
|
|
22
|
+
redux?: string;
|
|
23
|
+
toolkit?: string;
|
|
24
|
+
reactRedux?: string;
|
|
18
25
|
}
|
|
19
26
|
interface Scanned {
|
|
20
27
|
sources: Map<string, SourceFacts>;
|
|
21
28
|
modules: Map<string, SliceModule>;
|
|
22
29
|
sliceSources: Map<string, SliceSource>;
|
|
23
30
|
packages: Map<string, PackageFacts>;
|
|
31
|
+
configs: PathsConfigs;
|
|
24
32
|
}
|
|
25
33
|
declare abstract class ZustandDependency extends JavaDependencyRecipe {
|
|
26
34
|
private readonly addition;
|
|
27
|
-
|
|
35
|
+
protected readonly forecast: ZustandForecast;
|
|
28
36
|
readonly landed: Set<string>;
|
|
29
37
|
private readonly held;
|
|
30
38
|
private readonly locks;
|
|
39
|
+
private readonly owned;
|
|
40
|
+
private readonly workspaces;
|
|
41
|
+
private readonly pending;
|
|
31
42
|
private readonly unfit;
|
|
32
43
|
protected constructor(addition: AddDependencyOptions, forecast: ZustandForecast);
|
|
33
44
|
initialValue(): number;
|
|
34
45
|
protected scanned(manifest: SourceFile): boolean;
|
|
35
46
|
protected edits(manifest: SourceFile): boolean;
|
|
47
|
+
protected skipped(): Iterable<string>;
|
|
36
48
|
private fits;
|
|
37
49
|
private lockOf;
|
|
50
|
+
private readWorkspaces;
|
|
38
51
|
generate(acc: number, ctx: ExecutionContext): Promise<SourceFile[]>;
|
|
39
52
|
}
|
|
40
53
|
export declare class AddZustand extends ZustandDependency {
|
|
41
54
|
readonly name = "org.openrewrite.react.migrate.add-zustand";
|
|
42
55
|
readonly displayName = "Add `zustand` where a Redux store is migrated";
|
|
43
|
-
readonly description = "Adds `zustand` 5 to packages that
|
|
56
|
+
readonly description = "Adds `zustand` 5 to packages that resolve React 18 or later, where a Redux store moves to zustand.";
|
|
44
57
|
constructor(forecast?: ZustandForecast);
|
|
45
58
|
}
|
|
46
59
|
export declare class AddZustand4 extends ZustandDependency {
|
|
47
60
|
readonly name = "org.openrewrite.react.migrate.add-zustand-4";
|
|
48
61
|
readonly displayName = "Add `zustand` 4 where a Redux store is migrated on React 16.8 to 17";
|
|
49
|
-
readonly description = "Adds `zustand` 4 to packages that
|
|
62
|
+
readonly description = "Adds `zustand` 4 to packages that resolve React 16.8 to 17, where a Redux store moves to zustand.";
|
|
50
63
|
constructor(forecast?: ZustandForecast);
|
|
51
64
|
}
|
|
52
65
|
export declare class AddImmer extends ZustandDependency {
|
|
53
66
|
readonly name = "org.openrewrite.react.migrate.add-immer";
|
|
54
67
|
readonly displayName = "Add `immer` where a Redux store is migrated";
|
|
55
|
-
readonly description = "Adds `immer` 10 to packages that
|
|
68
|
+
readonly description = "Adds `immer` 10 to packages that resolve React 16.8 or later, where a Redux store moves to zustand and its slices' reducers run through `produce`.";
|
|
56
69
|
constructor(forecast?: ZustandForecast);
|
|
70
|
+
protected skipped(): Iterable<string>;
|
|
57
71
|
}
|
|
58
72
|
export declare class ReduxToZustand extends ScanningRecipe<Scanned> {
|
|
59
73
|
readonly name = "org.openrewrite.react.migrate.redux-to-zustand";
|
|
60
74
|
readonly displayName = "Migrate Redux Toolkit slices to zustand";
|
|
61
|
-
readonly description = "Moves a repository's one Redux Toolkit store to zustand when it is a `configureStore` of `createSlice` reducers with no other option, its sources are JavaScript, and every use of it converts: each slice becomes a zustand store whose action creators keep their names and run the slice's reducers through immer's `produce`, `useSelector` reads of one slice become the slice's zustand hook, `dispatch` and `store.dispatch` of the slices' action creators become calls of them, `store.getState()` reads become the slice store's `getState()`, and the react-redux `Provider
|
|
75
|
+
readonly description = "Moves a repository's one Redux Toolkit store to zustand when it is a `configureStore` of `createSlice` reducers with no other option, its sources are JavaScript, and every use of it converts: each slice becomes a zustand store whose action creators keep their names and run the slice's reducers through immer's `produce`, `useSelector` reads of one slice become the slice's zustand hook, `dispatch` and `store.dispatch` of the slices' action creators become calls of them, `store.getState()` reads become the slice store's `getState()`, and the react-redux `Provider`, replaced with its children, and the store's source are removed. A slice's own `createAsyncThunk`s, whose stages its `extraReducers` handles, keep running on Redux Toolkit and send their actions to the slice's zustand store. A store of its `reducer` alone whose slices can't move one by one, such as one with a reducer that is no slice's, thunks that reach the rest of the store or dispatches whose result is used, moves whole: its reducer runs on one zustand store whose `dispatch` runs thunks as Redux Toolkit's default middleware does, its selectors run on that store, through a hook of the store's source that keeps each selection per state where zustand 5 would run the selector on each read, and the store keeps its `getState` and `dispatch`, and its `subscribe`, whose listeners its `dispatch` calls after every action as Redux does, where a source subscribes to it. A legacy `createStore` of a reducer, and perhaps a preloaded state, moves whole too, its `dispatch` taking plain actions only, as Redux's does without middleware, or thunks as well where its enhancer is `applyMiddleware(thunk)`, perhaps inside `compose` or Redux DevTools, which is dropped. Components connected with `connect`, with no `mergeProps` and no option but `forwardRef`, move with a store that moves whole: its source declares a `connect` for the zustand store that passes the same props, copies the same statics and skips the same re-renders as react-redux's, and the store batches its updates as react-redux does. A store that moves whole but is created, and not exported, at the top level of an application's entry source, such as the one that renders the `Provider`, moves to an `appStore` module beside that source, with the imports and top-level `const`s and `let`s only it uses, and the source imports back what it still uses. A store's source may export it in its declaration, as its default export or in an export list such as `export {store}`, and other sources may import it, and its slices, by relative paths or by aliases such as `@/store` that the `paths` of the nearest `tsconfig.json` or `jsconfig.json` declare. Adds `zustand`, and `immer` where slices move one by one, where they are missing. Stores with any other use, such as `connect` with `mergeProps`, other middleware or enhancers, other uses of the store object such as `persistStore(store)`, selectors with their own equality function or several stores, stay in Redux and are recorded for review.";
|
|
76
|
+
wholeStores?: boolean;
|
|
77
|
+
constructor(options?: {
|
|
78
|
+
wholeStores?: boolean;
|
|
79
|
+
});
|
|
62
80
|
private readonly forecast;
|
|
63
81
|
private readonly storeSources;
|
|
64
82
|
private asked?;
|
|
@@ -66,11 +84,17 @@ export declare class ReduxToZustand extends ScanningRecipe<Scanned> {
|
|
|
66
84
|
private readonly stores;
|
|
67
85
|
initialValue(): Scanned;
|
|
68
86
|
scanner(scanned: Scanned): Promise<TreeVisitor<any, ExecutionContext>>;
|
|
87
|
+
private reported;
|
|
88
|
+
private splits;
|
|
69
89
|
private plans;
|
|
70
90
|
private planned;
|
|
91
|
+
private split;
|
|
92
|
+
generate(scanned: Scanned, ctx: ExecutionContext): Promise<SourceFile[]>;
|
|
71
93
|
private dependencies;
|
|
72
94
|
editorWithData(scanned: Scanned): Promise<TreeVisitor<any, ExecutionContext>>;
|
|
73
95
|
recipeList(): Promise<(AddZustand | AddZustand4 | AddImmer)[]>;
|
|
74
96
|
}
|
|
97
|
+
export declare const SELECTOR = "export function SELECTOR_HOOK(selector) {\n const last = useRef(undefined);\n const select = () => {\n const state = HOOK.getState();\n const kept = last.current;\n if (kept && kept.state === state && kept.selector === selector) return kept.selection;\n const selection = selector(state);\n last.current = {state, selector, selection};\n return selection;\n };\n return useSyncExternalStore(HOOK.subscribe, select, select);\n}";
|
|
98
|
+
export declare function connectSource(hook: string, reactRedux: string | undefined): string;
|
|
75
99
|
export {};
|
|
76
100
|
//# sourceMappingURL=redux-to-zustand.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redux-to-zustand.d.ts","sourceRoot":"","sources":["../../src/zustand/redux-to-zustand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkC,gBAAgB,
|
|
1
|
+
{"version":3,"file":"redux-to-zustand.d.ts","sourceRoot":"","sources":["../../src/zustand/redux-to-zustand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkC,gBAAgB,EAA6C,cAAc,EAAE,UAAU,EAAsB,WAAW,EAAC,MAAM,sBAAsB,CAAC;AAC/L,OAAO,EACH,oBAAoB,EACvB,MAAM,iCAAiC,CAAC;AAMzC,OAAO,EAAC,oBAAoB,EAAc,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAmD,YAAY,EAAyB,MAAM,wBAAwB,CAAC;AAG9H,OAAO,EAAkJ,WAAW,EAAiD,MAAM,gBAAgB,CAAC;AAC5O,OAAO,EAEsE,WAAW,EAAE,WAAW,EACpG,MAAM,gBAAgB,CAAC;AAgBxB,MAAM,WAAW,eAAe;IAC5B,UAAU,CAAC,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC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