@octanejs/codemod 0.2.1 → 0.2.3
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/README.md +107 -8
- package/dist/bin.js +2 -2
- package/dist/effect-receivers.d.ts +2 -0
- package/dist/effect-receivers.js +10 -0
- package/dist/expression-wrappers.d.ts +2 -0
- package/dist/expression-wrappers.js +19 -0
- package/dist/forwarded-props.d.ts +5 -1
- package/dist/forwarded-props.js +18 -3
- package/dist/local-react-hook.d.ts +8 -3
- package/dist/local-react-hook.js +106 -50
- package/dist/local-uses.d.ts +2 -0
- package/dist/local-uses.js +22 -0
- package/dist/mappings.d.ts +5 -1
- package/dist/mappings.js +16 -3
- package/dist/path-svg.d.ts +5 -0
- package/dist/path-svg.js +19 -2
- package/dist/project.js +997 -129
- package/dist/react-intl.d.ts +1 -1
- package/dist/react-intl.js +23 -3
- package/dist/react-island-sources.d.ts +32 -7
- package/dist/react-island-sources.js +812 -74
- package/dist/react-renderer.d.ts +2 -0
- package/dist/react-renderer.js +94 -0
- package/dist/scoped-store-contract.d.ts +6 -1
- package/dist/scoped-store-contract.js +199 -31
- package/dist/store-hook-uses.js +1 -20
- package/dist/store-inputs.js +3 -1
- package/dist/transform.d.ts +6 -0
- package/dist/transform.js +2183 -270
- package/dist/types.d.ts +27 -9
- package/package.json +4 -3
- package/src/path-svg.ts +20 -2
- package/templates/octane-path-svg.ts +4 -0
- package/templates/react-intl.tsrx +64 -11
package/dist/types.d.ts
CHANGED
|
@@ -22,6 +22,8 @@ export interface TransformOptions {
|
|
|
22
22
|
strong?: boolean;
|
|
23
23
|
/** The project checks with `strictNullChecks`, so TypeScript types can prove text holes and boolean guards. */
|
|
24
24
|
strictNullChecks?: boolean;
|
|
25
|
+
/** Whether the project can expose the selected module through mutable exports. */
|
|
26
|
+
mutableExports?(): boolean;
|
|
25
27
|
/** This module in a program over the whole project, whose resolved imports type what the module's own program cannot. */
|
|
26
28
|
types?: {
|
|
27
29
|
sourceFile: ts.SourceFile;
|
|
@@ -33,18 +35,32 @@ export interface TransformOptions {
|
|
|
33
35
|
bindingExports?(from: string, to: string): ReadonlySet<string> | undefined;
|
|
34
36
|
/** Record a successful rewrite that was checked against a partial binding's catalog. */
|
|
35
37
|
recordBindingRewrite?(from: string, to: string): void;
|
|
38
|
+
/** Resolve a direct relative import of an unselected source in a single-file run. */
|
|
39
|
+
retainedRegistry?(specifier: string): ts.SourceFile | undefined;
|
|
36
40
|
/** The issuer resolves the original installed React runtime and types. */
|
|
37
41
|
originalReact?: boolean;
|
|
38
|
-
/**
|
|
39
|
-
|
|
42
|
+
/** The authored React bridge and its direct component import still resolve to React. */
|
|
43
|
+
retainedReactBridgeComponent?(bridge: string, module: string, name: string): boolean;
|
|
44
|
+
/** The issuer resolves the original React DOM server entry that this call will migrate. */
|
|
45
|
+
originalReactServerEntry?(module: string): boolean;
|
|
46
|
+
/** A React DOM resource hint called by an imported plain TypeScript function. */
|
|
47
|
+
initializerResourceHint?(module: string, name: string, retainedOnly?: boolean): string | undefined;
|
|
40
48
|
/** Renderer work called by an unchanged local TypeScript export. */
|
|
41
49
|
localReactHook?(module: string, name: string, nativeOnly: boolean): string | {
|
|
42
50
|
from: string;
|
|
43
51
|
} | {
|
|
44
52
|
privateContext: true;
|
|
53
|
+
} | {
|
|
54
|
+
retainedStore: true;
|
|
45
55
|
} | undefined;
|
|
46
56
|
/** A dispatcher hook directly called by an unchanged component at a migrated React DOM root. */
|
|
47
57
|
localReactRootComponent?(module: string, name: string): string | undefined;
|
|
58
|
+
/** Whether a retained local export returns JSX under the project's React JSX settings. */
|
|
59
|
+
localReactTemplateComponent?(module: string, name: string): boolean;
|
|
60
|
+
/** A directly imported context declaration that remains in React. */
|
|
61
|
+
localReactContext?(module: string, name: string, member: boolean): boolean;
|
|
62
|
+
/** Severity for a direct render of a local React class component. */
|
|
63
|
+
localReactClass?(module: string, name: string): 'error' | 'warning' | undefined;
|
|
48
64
|
/** Resolve a source-backed workspace hook after verifying its implementation and its call sites. */
|
|
49
65
|
resolveStoreHook?(module: string, name: string, safeUses: (sharedInput: StoreInputCheck, unchangedHelper?: (module: string, name: string) => boolean, retainedArgument?: (module: string, name: string) => boolean) => boolean): {
|
|
50
66
|
from: string;
|
|
@@ -54,19 +70,19 @@ export interface TransformOptions {
|
|
|
54
70
|
reactIntlAdapter?: string;
|
|
55
71
|
/** Whether a directly imported, selected component forwards this prop only to text attributes. */
|
|
56
72
|
forwardedText?(module: string, exported: string, prop: string, ordinaryCaller?: boolean, through?: boolean): boolean;
|
|
57
|
-
/** Whether
|
|
73
|
+
/** Whether this selected component accepts one explicit element, with separate review for path aliases. */
|
|
58
74
|
elementChild?(binding: number | {
|
|
59
75
|
module: string;
|
|
60
76
|
imported: string;
|
|
61
|
-
}): boolean;
|
|
77
|
+
}): boolean | 'review-alias';
|
|
62
78
|
/** Whether a selected, directly imported component inspects its child descriptors. */
|
|
63
79
|
descriptorChild?(binding: {
|
|
64
80
|
module: string;
|
|
65
81
|
imported: string;
|
|
66
82
|
}): boolean;
|
|
67
83
|
/** Whether an imported name is a context, with separate review for selected alias targets. */
|
|
68
|
-
isContext?(specifier: string, name: string, local: string): boolean | 'review-alias' | null;
|
|
69
|
-
/** The React package an import specifier names when
|
|
84
|
+
isContext?(specifier: string, name: string, local: string, attributed?: boolean): boolean | 'review-alias' | null;
|
|
85
|
+
/** The React package an import specifier names when the codemod keeps it on React, or null. */
|
|
70
86
|
unported?(specifier: string): string | null;
|
|
71
87
|
/** The project has React and React DOM 19.2 or newer in the React 19 series, so `ReactCompat` can host an unported package's components. */
|
|
72
88
|
reactCompat?: boolean;
|
|
@@ -80,6 +96,8 @@ export interface TransformOptions {
|
|
|
80
96
|
cssModuleFile?(specifier: string): string | undefined;
|
|
81
97
|
/** The generated native SVG helper, if the project verified this raw asset. */
|
|
82
98
|
pathSvgAdapter?(specifier: string): string | null;
|
|
99
|
+
/** Whether a native server SVG entry resolves to the adapter's installed Octane. */
|
|
100
|
+
originalSvgServer?: boolean;
|
|
83
101
|
/** With pathSvgAdapter, supplies a native SVG adapter with the requested fixed root color. */
|
|
84
102
|
fixedColorSvgAdapter?(specifier: string, color: string): string | null;
|
|
85
103
|
/** The project compiles this file with the original React automatic JSX runtime. */
|
|
@@ -87,12 +105,12 @@ export interface TransformOptions {
|
|
|
87
105
|
/** This file uses React's automatic JSX runtime and the component resolves to its original React package. */
|
|
88
106
|
reactStoreComponent?(specifier: string): boolean;
|
|
89
107
|
}
|
|
90
|
-
/** A React package
|
|
108
|
+
/** A retained React package import and how migrated code uses it. */
|
|
91
109
|
export interface Unported {
|
|
92
110
|
name: string;
|
|
93
111
|
/** Elements now rendered in a `ReactCompat` island. */
|
|
94
112
|
islands: number;
|
|
95
|
-
/** Uses that
|
|
113
|
+
/** Uses that need review before migrating to an Octane renderer. */
|
|
96
114
|
blocked: number;
|
|
97
115
|
}
|
|
98
116
|
export interface TransformResult {
|
|
@@ -181,7 +199,7 @@ export interface CodemodResult {
|
|
|
181
199
|
name: string;
|
|
182
200
|
patch: string;
|
|
183
201
|
}[];
|
|
184
|
-
/** React
|
|
202
|
+
/** React package imports the codemod keeps on React, and how the code uses them. */
|
|
185
203
|
missing: (Unported & {
|
|
186
204
|
modules: number;
|
|
187
205
|
})[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octanejs/codemod",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=22.22.2"
|
|
@@ -45,9 +45,10 @@
|
|
|
45
45
|
"./package.json": "./package.json"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@octanejs/cli": "0.3.
|
|
48
|
+
"@octanejs/cli": "0.3.6",
|
|
49
49
|
"@tsrx/oxc": "0.23.0",
|
|
50
|
-
"octane": "0.
|
|
50
|
+
"octane": "0.19.1",
|
|
51
|
+
"parse5": "8.0.1",
|
|
51
52
|
"picocolors": "^1.1.1",
|
|
52
53
|
"typescript": "^5.9.3"
|
|
53
54
|
},
|
package/src/path-svg.ts
CHANGED
|
@@ -220,6 +220,7 @@ function closedContainer(tag: SvgParent, children: readonly StaticSvgNode[]) {
|
|
|
220
220
|
export function parseStaticSvg(source: string) {
|
|
221
221
|
if (typeof source !== 'string') return null;
|
|
222
222
|
let root: Record<string, string> | null = null;
|
|
223
|
+
let title: string | undefined;
|
|
223
224
|
const children: StaticSvgNode[] = [];
|
|
224
225
|
const open: { tag: SvgParent; children: StaticSvgNode[] }[] = [];
|
|
225
226
|
const definitions = new Map<string, SvgTag>();
|
|
@@ -244,6 +245,21 @@ export function parseStaticSvg(source: string) {
|
|
|
244
245
|
root = attributes(fields!, rootAttributes, true);
|
|
245
246
|
if (!root) return null;
|
|
246
247
|
open.push({ tag, children });
|
|
248
|
+
} else if (tag === 'title') {
|
|
249
|
+
if (parent?.tag !== 'svg' || children.length || title !== undefined || fields || selfClosing)
|
|
250
|
+
return null;
|
|
251
|
+
// Keep one literal text child. XML entities, markup, and line endings require loader rules.
|
|
252
|
+
const titleToken = /([^<&]+)<\/title>/uy;
|
|
253
|
+
titleToken.lastIndex = token.lastIndex;
|
|
254
|
+
const text = titleToken.exec(source);
|
|
255
|
+
if (
|
|
256
|
+
!text ||
|
|
257
|
+
/\]\]>|[^\u0020-\uD7FF\uE000-\uFFFD\u{10000}-\u{10FFFF}]/u.test(text[1]) ||
|
|
258
|
+
!text[1].trim()
|
|
259
|
+
)
|
|
260
|
+
return null;
|
|
261
|
+
title = text[1];
|
|
262
|
+
token.lastIndex = titleToken.lastIndex;
|
|
247
263
|
} else {
|
|
248
264
|
if (!parent || !tag || !Object.prototype.hasOwnProperty.call(shapeAttributes, tag))
|
|
249
265
|
return null;
|
|
@@ -308,14 +324,16 @@ export function parseStaticSvg(source: string) {
|
|
|
308
324
|
definitions.get(id) === target || (rootRect && definitions.get(id) === 'pattern'),
|
|
309
325
|
) &&
|
|
310
326
|
space.test(source.slice(end))
|
|
311
|
-
?
|
|
327
|
+
? title === undefined
|
|
328
|
+
? { root, children }
|
|
329
|
+
: { root, children, title }
|
|
312
330
|
: null;
|
|
313
331
|
}
|
|
314
332
|
|
|
315
333
|
// Existing generated helpers expose this path-only result to their importers.
|
|
316
334
|
export function parsePathSvg(source: string) {
|
|
317
335
|
const svg = parseStaticSvg(source);
|
|
318
|
-
return svg && svg.children.every((node) => node.tag === 'path')
|
|
336
|
+
return svg && svg.title === undefined && svg.children.every((node) => node.tag === 'path')
|
|
319
337
|
? { root: svg.root, paths: svg.children.map((node) => node.attributes) }
|
|
320
338
|
: null;
|
|
321
339
|
}
|
|
@@ -24,6 +24,10 @@ export function pathSvg(source: string, fixedStyle?: string) {
|
|
|
24
24
|
if (!geometry) throw new Error('Expected a raw SVG containing only supported static geometry.');
|
|
25
25
|
const root = fixedStyle === undefined ? geometry.root : { ...geometry.root, style: fixedStyle };
|
|
26
26
|
const children = geometry.children.map(prepareShape);
|
|
27
|
+
if (geometry.title !== undefined) {
|
|
28
|
+
const props = { key: -1, children: geometry.title };
|
|
29
|
+
children.unshift(() => createElement('title', props));
|
|
30
|
+
}
|
|
27
31
|
return function PathSvg(props: {
|
|
28
32
|
className?: unknown;
|
|
29
33
|
'aria-hidden'?: string | boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strong';
|
|
2
2
|
|
|
3
|
-
import { createContext, useContext, useMemo, type OctaneNode } from 'octane';
|
|
3
|
+
import { createContext, memo, useContext, useMemo, type OctaneNode } from 'octane';
|
|
4
4
|
import { ReactCompat } from 'octane/react';
|
|
5
5
|
import type { ChildrenBlock } from 'octane/tsrx-boundary';
|
|
6
6
|
import {
|
|
@@ -87,19 +87,47 @@ export function IntlProvider({
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
type MessageProps = MessageDescriptor &
|
|
90
|
-
Pick<ComponentProps<typeof ReactMessage>, 'values' | 'ignoreTag'
|
|
90
|
+
Pick<ComponentProps<typeof ReactMessage>, 'values' | 'ignoreTag'> & {
|
|
91
|
+
inlineHost?: typeof ReactCompat;
|
|
92
|
+
};
|
|
91
93
|
|
|
92
94
|
function ReactContent({ content }: { content: ReactNode }) {
|
|
93
95
|
return content;
|
|
94
96
|
}
|
|
95
97
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
98
|
+
type MessagePart = string | number | bigint | boolean | null | undefined;
|
|
99
|
+
|
|
100
|
+
function isMessagePart(value: unknown): value is MessagePart {
|
|
101
|
+
return (
|
|
102
|
+
typeof value === 'string' ||
|
|
103
|
+
typeof value === 'number' ||
|
|
104
|
+
typeof value === 'bigint' ||
|
|
105
|
+
typeof value === 'boolean' ||
|
|
106
|
+
value === null ||
|
|
107
|
+
value === undefined
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function plainMessageParts(value: unknown): MessagePart[] | undefined {
|
|
112
|
+
if (
|
|
113
|
+
!Array.isArray(value) ||
|
|
114
|
+
Object.getPrototypeOf(value) !== Array.prototype ||
|
|
115
|
+
Object.hasOwn(value, '$$typeof') ||
|
|
116
|
+
Object.hasOwn(value, 'then')
|
|
117
|
+
)
|
|
118
|
+
return;
|
|
119
|
+
// Copy dense data parts without calling methods or getters on custom formatter output.
|
|
120
|
+
const parts: MessagePart[] = [];
|
|
121
|
+
for (let i = 0, length = value.length; i < length; i++) {
|
|
122
|
+
const part = Object.getOwnPropertyDescriptor(value, i);
|
|
123
|
+
if (!part || !Object.hasOwn(part, 'value') || !isMessagePart(part.value)) return;
|
|
124
|
+
parts.push(part.value);
|
|
125
|
+
}
|
|
126
|
+
return parts;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function NativeFormattedMessage(props: MessageProps) @{
|
|
130
|
+
const { id, defaultMessage, description, values, ignoreTag } = props;
|
|
103
131
|
const intl = useIntl();
|
|
104
132
|
const descriptor = { id, defaultMessage, description };
|
|
105
133
|
const { textComponent, formatMessage } = intl;
|
|
@@ -109,8 +137,33 @@ export function FormattedMessage({
|
|
|
109
137
|
const content = requiresReact
|
|
110
138
|
? reactElement(ReactMessage, { ...descriptor, values, ignoreTag })
|
|
111
139
|
: formatMessage(descriptor, values, { ignoreTag });
|
|
112
|
-
if (
|
|
140
|
+
if (isMessagePart(content)) return content;
|
|
141
|
+
const parts = plainMessageParts(content);
|
|
142
|
+
if (parts) return parts;
|
|
143
|
+
const Island = Object.hasOwn(props, 'inlineHost')
|
|
144
|
+
? (props.inlineHost ?? ReactCompat)
|
|
145
|
+
: ReactCompat;
|
|
113
146
|
<Locale value={intl}>
|
|
114
|
-
<
|
|
147
|
+
<Island component={ReactContent} props={{ content }} contexts={intlContexts} />
|
|
115
148
|
</Locale>
|
|
116
149
|
}
|
|
150
|
+
|
|
151
|
+
function equalOwnValues<T extends object>(before: T | undefined, after: T | undefined): boolean {
|
|
152
|
+
if (before === after) return true;
|
|
153
|
+
if (!before || !after) return false;
|
|
154
|
+
const keys = Object.keys(before) as (keyof T)[];
|
|
155
|
+
if (keys.length !== Object.keys(after).length) return false;
|
|
156
|
+
for (const key of keys) {
|
|
157
|
+
if (before[key] !== after[key] || !Object.hasOwn(after, key)) return false;
|
|
158
|
+
}
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function equalMessages(previous: Readonly<MessageProps>, next: Readonly<MessageProps>): boolean {
|
|
163
|
+
const { values, ...message } = previous;
|
|
164
|
+
const { values: nextValues, ...nextMessage } = next;
|
|
165
|
+
// React Intl compares its values separately with strict equality (including ±0 and NaN).
|
|
166
|
+
return equalOwnValues(nextValues, values) && equalOwnValues(message, nextMessage);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export const FormattedMessage = memo(NativeFormattedMessage, equalMessages);
|