@genesislcap/ts-builder 14.436.0-FUI-2489.2 → 14.437.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.map +1 -1
- package/dist/react-wrapper-generator.d.ts.map +1 -1
- package/dist/react-wrapper-generator.js +30 -160
- package/package.json +3 -3
- package/src/index.ts +1 -3
- package/src/react-wrapper-generator.ts +48 -216
- package/tsconfig.json +10 -3
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;yBAIrC,KAAK,YAAY;AAAvC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;yBAIrC,KAAK,YAAY;AAAvC,wBAoDE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-wrapper-generator.d.ts","sourceRoot":"","sources":["../src/react-wrapper-generator.ts"],"names":[],"mappings":"AAyCA,KAAK,cAAc,
|
|
1
|
+
{"version":3,"file":"react-wrapper-generator.d.ts","sourceRoot":"","sources":["../src/react-wrapper-generator.ts"],"names":[],"mappings":"AAyCA,KAAK,cAAc,GACf;IAAE,SAAS,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,SAAS,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAswBzC,wBAAsB,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAqChF"}
|
|
@@ -9,73 +9,24 @@ const node_path_1 = require("node:path");
|
|
|
9
9
|
const PRIMITIVE_UNION_REGEX = /^(?:\s*(?:string|number|boolean|bigint|null|undefined|unknown|any|void|'[^']*'|"[^"]*"|`[^`]*`|(?:\d+(?:\.\d+)?))\s*)(?:\|\s*(?:string|number|boolean|bigint|null|undefined|unknown|any|void|'[^']*'|"[^"]*"|`[^`]*`|(?:\d+(?:\.\d+)?))\s*)*$/;
|
|
10
10
|
const IDENTIFIER_TOKEN_REGEX = /[A-Za-z_$][A-Za-z0-9_$]*(?:\.[A-Za-z_$][A-Za-z0-9_$]*)*/g;
|
|
11
11
|
const PRIMITIVE_TOKENS = new Set([
|
|
12
|
-
'true',
|
|
13
|
-
'
|
|
14
|
-
'null',
|
|
15
|
-
'undefined',
|
|
16
|
-
'string',
|
|
17
|
-
'number',
|
|
18
|
-
'boolean',
|
|
19
|
-
'bigint',
|
|
20
|
-
'symbol',
|
|
21
|
-
'unknown',
|
|
22
|
-
'any',
|
|
23
|
-
'void',
|
|
24
|
-
'never',
|
|
12
|
+
'true', 'false', 'null', 'undefined', 'string', 'number', 'boolean',
|
|
13
|
+
'bigint', 'symbol', 'unknown', 'any', 'void', 'never',
|
|
25
14
|
]);
|
|
26
15
|
const KNOWN_TYPE_NAMES = new Set([
|
|
27
|
-
'Array',
|
|
28
|
-
'
|
|
29
|
-
'
|
|
30
|
-
'
|
|
31
|
-
'
|
|
32
|
-
'
|
|
33
|
-
'Pick',
|
|
34
|
-
'Omit',
|
|
35
|
-
'Map',
|
|
36
|
-
'Set',
|
|
37
|
-
'WeakMap',
|
|
38
|
-
'WeakSet',
|
|
39
|
-
'Date',
|
|
40
|
-
'RegExp',
|
|
41
|
-
'Error',
|
|
42
|
-
'Node',
|
|
43
|
-
'Element',
|
|
44
|
-
'HTMLElement',
|
|
45
|
-
'SVGElement',
|
|
46
|
-
'Event',
|
|
47
|
-
'CustomEvent',
|
|
48
|
-
'MouseEvent',
|
|
49
|
-
'KeyboardEvent',
|
|
50
|
-
'FocusEvent',
|
|
51
|
-
'InputEvent',
|
|
52
|
-
'PointerEvent',
|
|
53
|
-
'WheelEvent',
|
|
54
|
-
'DragEvent',
|
|
55
|
-
'SubmitEvent',
|
|
56
|
-
'AbortSignal',
|
|
57
|
-
'DOMRect',
|
|
58
|
-
'Document',
|
|
59
|
-
'Window',
|
|
60
|
-
'URL',
|
|
61
|
-
'URLSearchParams',
|
|
62
|
-
'CSSStyleDeclaration',
|
|
63
|
-
'Intl.Locale',
|
|
16
|
+
'Array', 'ReadonlyArray', 'Promise', 'Record', 'Partial', 'Required', 'Pick', 'Omit',
|
|
17
|
+
'Map', 'Set', 'WeakMap', 'WeakSet', 'Date', 'RegExp', 'Error', 'Node', 'Element',
|
|
18
|
+
'HTMLElement', 'SVGElement', 'Event', 'CustomEvent', 'MouseEvent', 'KeyboardEvent',
|
|
19
|
+
'FocusEvent', 'InputEvent', 'PointerEvent', 'WheelEvent', 'DragEvent', 'SubmitEvent',
|
|
20
|
+
'AbortSignal', 'DOMRect', 'Document', 'Window', 'URL', 'URLSearchParams',
|
|
21
|
+
'CSSStyleDeclaration', 'Intl.Locale',
|
|
64
22
|
]);
|
|
65
23
|
/**
|
|
66
24
|
* DOM event classes that map directly to `(event: T) => void`.
|
|
67
25
|
* Excludes bare `CustomEvent` which needs special handling for its detail type.
|
|
68
26
|
*/
|
|
69
27
|
const DOM_EVENT_CLASS_NAMES = new Set([
|
|
70
|
-
'Event',
|
|
71
|
-
'
|
|
72
|
-
'KeyboardEvent',
|
|
73
|
-
'FocusEvent',
|
|
74
|
-
'InputEvent',
|
|
75
|
-
'PointerEvent',
|
|
76
|
-
'WheelEvent',
|
|
77
|
-
'DragEvent',
|
|
78
|
-
'SubmitEvent',
|
|
28
|
+
'Event', 'MouseEvent', 'KeyboardEvent', 'FocusEvent', 'InputEvent',
|
|
29
|
+
'PointerEvent', 'WheelEvent', 'DragEvent', 'SubmitEvent',
|
|
79
30
|
]);
|
|
80
31
|
/**
|
|
81
32
|
* React DOM reserves these `on*` prop names for native/synthetic events. When a CEM event
|
|
@@ -94,96 +45,26 @@ function loadReactEventHandlerNames() {
|
|
|
94
45
|
for (const m of content.matchAll(/\b(on[A-Z][a-zA-Z]+)\??\s*:/g)) {
|
|
95
46
|
names.add(m[1]);
|
|
96
47
|
}
|
|
97
|
-
// oxlint-disable-next-line no-magic-numbers -- 20 is a sanity threshold for react event names
|
|
98
48
|
if (names.size > 20)
|
|
99
49
|
return names;
|
|
100
50
|
}
|
|
101
51
|
catch (_a) { }
|
|
102
52
|
// Static snapshot — kept as fallback only.
|
|
103
53
|
return new Set([
|
|
104
|
-
'onCopy',
|
|
105
|
-
'
|
|
106
|
-
'
|
|
107
|
-
'
|
|
108
|
-
'
|
|
109
|
-
'
|
|
110
|
-
'
|
|
111
|
-
'
|
|
112
|
-
'
|
|
113
|
-
'
|
|
114
|
-
'
|
|
115
|
-
'
|
|
116
|
-
'
|
|
117
|
-
'
|
|
118
|
-
'onLoad',
|
|
119
|
-
'onError',
|
|
120
|
-
'onKeyDown',
|
|
121
|
-
'onKeyPress',
|
|
122
|
-
'onKeyUp',
|
|
123
|
-
'onAbort',
|
|
124
|
-
'onCanPlay',
|
|
125
|
-
'onCanPlayThrough',
|
|
126
|
-
'onDurationChange',
|
|
127
|
-
'onEmptied',
|
|
128
|
-
'onEncrypted',
|
|
129
|
-
'onEnded',
|
|
130
|
-
'onLoadedData',
|
|
131
|
-
'onLoadedMetadata',
|
|
132
|
-
'onLoadStart',
|
|
133
|
-
'onPause',
|
|
134
|
-
'onPlay',
|
|
135
|
-
'onPlaying',
|
|
136
|
-
'onProgress',
|
|
137
|
-
'onRateChange',
|
|
138
|
-
'onResize',
|
|
139
|
-
'onSeeked',
|
|
140
|
-
'onSeeking',
|
|
141
|
-
'onStalled',
|
|
142
|
-
'onSuspend',
|
|
143
|
-
'onTimeUpdate',
|
|
144
|
-
'onVolumeChange',
|
|
145
|
-
'onWaiting',
|
|
146
|
-
'onAuxClick',
|
|
147
|
-
'onClick',
|
|
148
|
-
'onContextMenu',
|
|
149
|
-
'onDoubleClick',
|
|
150
|
-
'onDrag',
|
|
151
|
-
'onDragEnd',
|
|
152
|
-
'onDragEnter',
|
|
153
|
-
'onDragExit',
|
|
154
|
-
'onDragLeave',
|
|
155
|
-
'onDragOver',
|
|
156
|
-
'onDragStart',
|
|
157
|
-
'onDrop',
|
|
158
|
-
'onMouseDown',
|
|
159
|
-
'onMouseEnter',
|
|
160
|
-
'onMouseLeave',
|
|
161
|
-
'onMouseMove',
|
|
162
|
-
'onMouseOut',
|
|
163
|
-
'onMouseOver',
|
|
164
|
-
'onMouseUp',
|
|
165
|
-
'onSelect',
|
|
166
|
-
'onTouchCancel',
|
|
167
|
-
'onTouchEnd',
|
|
168
|
-
'onTouchMove',
|
|
169
|
-
'onTouchStart',
|
|
170
|
-
'onPointerOver',
|
|
171
|
-
'onPointerEnter',
|
|
172
|
-
'onPointerDown',
|
|
173
|
-
'onPointerMove',
|
|
174
|
-
'onPointerUp',
|
|
175
|
-
'onPointerCancel',
|
|
176
|
-
'onPointerOut',
|
|
177
|
-
'onPointerLeave',
|
|
178
|
-
'onGotPointerCapture',
|
|
179
|
-
'onLostPointerCapture',
|
|
180
|
-
'onScroll',
|
|
181
|
-
'onWheel',
|
|
182
|
-
'onAnimationStart',
|
|
183
|
-
'onAnimationEnd',
|
|
184
|
-
'onAnimationIteration',
|
|
185
|
-
'onTransitionEnd',
|
|
186
|
-
'onToggle',
|
|
54
|
+
'onCopy', 'onCut', 'onPaste', 'onCompositionEnd', 'onCompositionStart', 'onCompositionUpdate',
|
|
55
|
+
'onFocus', 'onBlur', 'onChange', 'onBeforeInput', 'onInput', 'onReset', 'onSubmit',
|
|
56
|
+
'onInvalid', 'onLoad', 'onError', 'onKeyDown', 'onKeyPress', 'onKeyUp', 'onAbort',
|
|
57
|
+
'onCanPlay', 'onCanPlayThrough', 'onDurationChange', 'onEmptied', 'onEncrypted', 'onEnded',
|
|
58
|
+
'onLoadedData', 'onLoadedMetadata', 'onLoadStart', 'onPause', 'onPlay', 'onPlaying',
|
|
59
|
+
'onProgress', 'onRateChange', 'onResize', 'onSeeked', 'onSeeking', 'onStalled', 'onSuspend',
|
|
60
|
+
'onTimeUpdate', 'onVolumeChange', 'onWaiting', 'onAuxClick', 'onClick', 'onContextMenu',
|
|
61
|
+
'onDoubleClick', 'onDrag', 'onDragEnd', 'onDragEnter', 'onDragExit', 'onDragLeave',
|
|
62
|
+
'onDragOver', 'onDragStart', 'onDrop', 'onMouseDown', 'onMouseEnter', 'onMouseLeave',
|
|
63
|
+
'onMouseMove', 'onMouseOut', 'onMouseOver', 'onMouseUp', 'onSelect', 'onTouchCancel',
|
|
64
|
+
'onTouchEnd', 'onTouchMove', 'onTouchStart', 'onPointerOver', 'onPointerEnter',
|
|
65
|
+
'onPointerDown', 'onPointerMove', 'onPointerUp', 'onPointerCancel', 'onPointerOut',
|
|
66
|
+
'onPointerLeave', 'onGotPointerCapture', 'onLostPointerCapture', 'onScroll', 'onWheel',
|
|
67
|
+
'onAnimationStart', 'onAnimationEnd', 'onAnimationIteration', 'onTransitionEnd', 'onToggle',
|
|
187
68
|
]);
|
|
188
69
|
}
|
|
189
70
|
const REACT_NATIVE_EVENT_HANDLER_NAMES = loadReactEventHandlerNames();
|
|
@@ -300,7 +181,7 @@ function canUseComplexType(typeText, typeImportState) {
|
|
|
300
181
|
return false;
|
|
301
182
|
if (/[{};=]/.test(typeText) || /=>/.test(typeText))
|
|
302
183
|
return false;
|
|
303
|
-
if (!/^[A-Za-z0-9_
|
|
184
|
+
if (!/^[A-Za-z0-9_$<>\[\]()|&,.?'"`\s:-]+$/.test(typeText))
|
|
304
185
|
return false;
|
|
305
186
|
for (const token of getIdentifierTokens(typeText)) {
|
|
306
187
|
if (isPrimitiveToken(token) || isKnownTypeIdentifier(token))
|
|
@@ -324,7 +205,6 @@ function toSafeType(typeText, typeImportState) {
|
|
|
324
205
|
return 'unknown';
|
|
325
206
|
if (PRIMITIVE_UNION_REGEX.test(normalized))
|
|
326
207
|
return normalized;
|
|
327
|
-
// oxlint-disable-next-line no-magic-numbers -- -2 strips trailing '[]'
|
|
328
208
|
if (normalized.endsWith('[]') && PRIMITIVE_UNION_REGEX.test(normalized.slice(0, -2).trim())) {
|
|
329
209
|
return normalized;
|
|
330
210
|
}
|
|
@@ -380,18 +260,15 @@ function getCEMManifestPath(cwd, packageJson) {
|
|
|
380
260
|
// CEM paths are relative to src/ (e.g. "src/entities/entities.ts").
|
|
381
261
|
// react.mjs/cjs live in dist/ while compiled JS lives in dist/esm/.
|
|
382
262
|
function cemModulePathToJsImport(modulePath) {
|
|
383
|
-
// oxlint-disable no-magic-numbers -- numeric offsets for known file extension lengths
|
|
384
263
|
let p = modulePath.startsWith('src/') ? modulePath.slice(4) : modulePath;
|
|
385
264
|
if (p.endsWith('.tsx'))
|
|
386
265
|
p = `${p.slice(0, -4)}.js`;
|
|
387
266
|
else if (p.endsWith('.ts'))
|
|
388
267
|
p = `${p.slice(0, -3)}.js`;
|
|
389
|
-
// oxlint-enable no-magic-numbers
|
|
390
268
|
return `./esm/${p}`;
|
|
391
269
|
}
|
|
392
270
|
function cemModulePathToDtsImport(modulePath) {
|
|
393
|
-
|
|
394
|
-
const p = modulePath.startsWith('src/') ? modulePath.slice(4) : modulePath;
|
|
271
|
+
let p = modulePath.startsWith('src/') ? modulePath.slice(4) : modulePath;
|
|
395
272
|
const lastDot = p.lastIndexOf('.');
|
|
396
273
|
return `./${lastDot !== -1 ? p.slice(0, lastDot) : p}`;
|
|
397
274
|
}
|
|
@@ -459,8 +336,7 @@ function mergeFastInheritanceFromManifest(cwd, entries) {
|
|
|
459
336
|
return entry;
|
|
460
337
|
}
|
|
461
338
|
const inherited = (_f = (_c = byTagAndName.get(`${declaration.tagName}::${(_b = declaration.name) !== null && _b !== void 0 ? _b : ''}`)) !== null && _c !== void 0 ? _c : byTagAndName.get(`${declaration.tagName}::${(_e = (_d = declaration.superclass) === null || _d === void 0 ? void 0 : _d.name) !== null && _e !== void 0 ? _e : ''}`)) !== null && _f !== void 0 ? _f : byTag.get(declaration.tagName);
|
|
462
|
-
return inherited
|
|
463
|
-
? Object.assign(Object.assign({}, entry), { declaration: mergeDeclarationMetadata(declaration, inherited) }) : entry;
|
|
339
|
+
return inherited ? Object.assign(Object.assign({}, entry), { declaration: mergeDeclarationMetadata(declaration, inherited) }) : entry;
|
|
464
340
|
});
|
|
465
341
|
});
|
|
466
342
|
}
|
|
@@ -602,7 +478,9 @@ function generateReactWrapperDts(entries, typeImportState) {
|
|
|
602
478
|
for (const { declaration } of valid) {
|
|
603
479
|
const name = declaration.name;
|
|
604
480
|
// Build event lookup scoped to this element to avoid cross-element type pollution.
|
|
605
|
-
const eventsByName = new Map(((_a = declaration.events) !== null && _a !== void 0 ? _a : [])
|
|
481
|
+
const eventsByName = new Map(((_a = declaration.events) !== null && _a !== void 0 ? _a : [])
|
|
482
|
+
.filter((e) => e.name)
|
|
483
|
+
.map((e) => [e.name, e]));
|
|
606
484
|
const eventLines = buildWrapperEventEntries(declaration).map(({ handlerName, eventName }) => {
|
|
607
485
|
var _a;
|
|
608
486
|
const event = eventsByName.get(eventName);
|
|
@@ -645,7 +523,6 @@ function collectFilesRecursively(rootDirectory, isTargetFile) {
|
|
|
645
523
|
const stack = [rootDirectory];
|
|
646
524
|
while (stack.length) {
|
|
647
525
|
const dir = stack.pop();
|
|
648
|
-
// oxlint-disable-next-line no-await-in-loop -- iterative directory traversal, sequential by design
|
|
649
526
|
const dirEntries = yield (0, promises_1.readdir)(dir, { withFileTypes: true });
|
|
650
527
|
for (const entry of dirEntries) {
|
|
651
528
|
const fullPath = (0, node_path_1.resolve)(dir, entry.name);
|
|
@@ -749,7 +626,6 @@ function findWorkspaceRoot(startDirectory) {
|
|
|
749
626
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
750
627
|
let dir = startDirectory;
|
|
751
628
|
while (true) {
|
|
752
|
-
// oxlint-disable-next-line no-await-in-loop -- upward directory search must be sequential
|
|
753
629
|
const [hasPackages, hasPackageJson] = yield Promise.all([
|
|
754
630
|
fileExists((0, node_path_1.resolve)(dir, 'packages')),
|
|
755
631
|
fileExists((0, node_path_1.resolve)(dir, 'package.json')),
|
|
@@ -770,7 +646,6 @@ function getWorkspacePackageDirectoryByName(workspaceRoot, packageName) {
|
|
|
770
646
|
return undefined;
|
|
771
647
|
const packageJsonFiles = yield collectFilesRecursively(packagesDir, (n) => n === 'package.json');
|
|
772
648
|
for (const jsonPath of packageJsonFiles) {
|
|
773
|
-
// oxlint-disable-next-line no-await-in-loop -- early-exit search, sequential is correct
|
|
774
649
|
const pkg = JSON.parse(yield (0, promises_1.readFile)(jsonPath, 'utf8'));
|
|
775
650
|
if (pkg.name === packageName)
|
|
776
651
|
return (0, node_path_1.dirname)(jsonPath);
|
|
@@ -784,20 +659,15 @@ function enrichFromWorkspaceWildcardExports(cwd, state) {
|
|
|
784
659
|
// for...of over a Set processes items added inside the loop (spec-guaranteed behaviour).
|
|
785
660
|
const pending = new Set([...state.wildcardExportModules].filter((m) => m.startsWith('@genesislcap/')));
|
|
786
661
|
for (const moduleSpecifier of pending) {
|
|
787
|
-
// oxlint-disable-next-line no-await-in-loop -- sequential per-package processing is intentional
|
|
788
662
|
const pkgDir = yield getWorkspacePackageDirectoryByName(workspaceRoot, moduleSpecifier);
|
|
789
663
|
if (!pkgDir)
|
|
790
664
|
continue;
|
|
791
665
|
const distDir = (0, node_path_1.resolve)(pkgDir, 'dist');
|
|
792
|
-
// oxlint-disable-next-line no-await-in-loop -- sequential per-package processing is intentional
|
|
793
666
|
if (!(yield fileExists(distDir)))
|
|
794
667
|
continue;
|
|
795
668
|
const refState = createTypeImportState();
|
|
796
|
-
// oxlint-disable-next-line no-await-in-loop -- sequential per-package processing is intentional
|
|
797
669
|
const { apiJsonFiles, dtsFiles } = yield collectTypeMetadataFiles(distDir);
|
|
798
|
-
// oxlint-disable-next-line no-await-in-loop -- sequential per-package processing is intentional
|
|
799
670
|
yield parseApiJsonFiles(apiJsonFiles, refState);
|
|
800
|
-
// oxlint-disable-next-line no-await-in-loop -- sequential per-package processing is intentional
|
|
801
671
|
yield parseDtsFiles(dtsFiles, refState);
|
|
802
672
|
mergeTypeImportStateInto(state, refState);
|
|
803
673
|
for (const mod of refState.wildcardExportModules) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@genesislcap/ts-builder",
|
|
3
3
|
"description": "Typescript builder",
|
|
4
|
-
"version": "14.
|
|
4
|
+
"version": "14.437.0",
|
|
5
5
|
"license": "SEE LICENSE IN license.txt",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@custom-elements-manifest/analyzer": "^0.8.2",
|
|
20
|
-
"@genesislcap/build-kit": "14.
|
|
20
|
+
"@genesislcap/build-kit": "14.437.0",
|
|
21
21
|
"consola": "^3.0.2",
|
|
22
22
|
"copyfiles": "^2.4.1",
|
|
23
23
|
"pkg-types": "^1.0.2"
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
"publishConfig": {
|
|
31
31
|
"access": "public"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "c30c777f0ab5e45f4e931a9cc1200ac85bcace35"
|
|
34
34
|
}
|
package/src/index.ts
CHANGED
|
@@ -50,9 +50,7 @@ export default async (ctx: BuildContext) => {
|
|
|
50
50
|
} else {
|
|
51
51
|
// strictNullChecks is off in this workspace, so boolean literal narrowing
|
|
52
52
|
// doesn't apply to the discriminated union — cast to access the skipped variant.
|
|
53
|
-
consola.debug(
|
|
54
|
-
`React wrappers skipped: ${(reactWrappersResult as { reason: string }).reason}`,
|
|
55
|
-
);
|
|
53
|
+
consola.debug(`React wrappers skipped: ${(reactWrappersResult as { reason: string }).reason}`);
|
|
56
54
|
}
|
|
57
55
|
} else {
|
|
58
56
|
throw new Error(`Unrecognized command: ${JSON.stringify(options)}`);
|
|
@@ -39,7 +39,9 @@ type TypeImportState = {
|
|
|
39
39
|
|
|
40
40
|
// ── Public API return type ───────────────────────────────────────────────────
|
|
41
41
|
|
|
42
|
-
type GenerateResult =
|
|
42
|
+
type GenerateResult =
|
|
43
|
+
| { generated: true; path: string }
|
|
44
|
+
| { generated: false; reason: string };
|
|
43
45
|
|
|
44
46
|
// ── Constants ────────────────────────────────────────────────────────────────
|
|
45
47
|
|
|
@@ -49,59 +51,17 @@ const PRIMITIVE_UNION_REGEX =
|
|
|
49
51
|
const IDENTIFIER_TOKEN_REGEX = /[A-Za-z_$][A-Za-z0-9_$]*(?:\.[A-Za-z_$][A-Za-z0-9_$]*)*/g;
|
|
50
52
|
|
|
51
53
|
const PRIMITIVE_TOKENS = new Set([
|
|
52
|
-
'true',
|
|
53
|
-
'
|
|
54
|
-
'null',
|
|
55
|
-
'undefined',
|
|
56
|
-
'string',
|
|
57
|
-
'number',
|
|
58
|
-
'boolean',
|
|
59
|
-
'bigint',
|
|
60
|
-
'symbol',
|
|
61
|
-
'unknown',
|
|
62
|
-
'any',
|
|
63
|
-
'void',
|
|
64
|
-
'never',
|
|
54
|
+
'true', 'false', 'null', 'undefined', 'string', 'number', 'boolean',
|
|
55
|
+
'bigint', 'symbol', 'unknown', 'any', 'void', 'never',
|
|
65
56
|
]);
|
|
66
57
|
|
|
67
58
|
const KNOWN_TYPE_NAMES = new Set([
|
|
68
|
-
'Array',
|
|
69
|
-
'
|
|
70
|
-
'
|
|
71
|
-
'
|
|
72
|
-
'
|
|
73
|
-
'
|
|
74
|
-
'Pick',
|
|
75
|
-
'Omit',
|
|
76
|
-
'Map',
|
|
77
|
-
'Set',
|
|
78
|
-
'WeakMap',
|
|
79
|
-
'WeakSet',
|
|
80
|
-
'Date',
|
|
81
|
-
'RegExp',
|
|
82
|
-
'Error',
|
|
83
|
-
'Node',
|
|
84
|
-
'Element',
|
|
85
|
-
'HTMLElement',
|
|
86
|
-
'SVGElement',
|
|
87
|
-
'Event',
|
|
88
|
-
'CustomEvent',
|
|
89
|
-
'MouseEvent',
|
|
90
|
-
'KeyboardEvent',
|
|
91
|
-
'FocusEvent',
|
|
92
|
-
'InputEvent',
|
|
93
|
-
'PointerEvent',
|
|
94
|
-
'WheelEvent',
|
|
95
|
-
'DragEvent',
|
|
96
|
-
'SubmitEvent',
|
|
97
|
-
'AbortSignal',
|
|
98
|
-
'DOMRect',
|
|
99
|
-
'Document',
|
|
100
|
-
'Window',
|
|
101
|
-
'URL',
|
|
102
|
-
'URLSearchParams',
|
|
103
|
-
'CSSStyleDeclaration',
|
|
104
|
-
'Intl.Locale',
|
|
59
|
+
'Array', 'ReadonlyArray', 'Promise', 'Record', 'Partial', 'Required', 'Pick', 'Omit',
|
|
60
|
+
'Map', 'Set', 'WeakMap', 'WeakSet', 'Date', 'RegExp', 'Error', 'Node', 'Element',
|
|
61
|
+
'HTMLElement', 'SVGElement', 'Event', 'CustomEvent', 'MouseEvent', 'KeyboardEvent',
|
|
62
|
+
'FocusEvent', 'InputEvent', 'PointerEvent', 'WheelEvent', 'DragEvent', 'SubmitEvent',
|
|
63
|
+
'AbortSignal', 'DOMRect', 'Document', 'Window', 'URL', 'URLSearchParams',
|
|
64
|
+
'CSSStyleDeclaration', 'Intl.Locale',
|
|
105
65
|
]);
|
|
106
66
|
|
|
107
67
|
/**
|
|
@@ -109,15 +69,8 @@ const KNOWN_TYPE_NAMES = new Set([
|
|
|
109
69
|
* Excludes bare `CustomEvent` which needs special handling for its detail type.
|
|
110
70
|
*/
|
|
111
71
|
const DOM_EVENT_CLASS_NAMES = new Set([
|
|
112
|
-
'Event',
|
|
113
|
-
'
|
|
114
|
-
'KeyboardEvent',
|
|
115
|
-
'FocusEvent',
|
|
116
|
-
'InputEvent',
|
|
117
|
-
'PointerEvent',
|
|
118
|
-
'WheelEvent',
|
|
119
|
-
'DragEvent',
|
|
120
|
-
'SubmitEvent',
|
|
72
|
+
'Event', 'MouseEvent', 'KeyboardEvent', 'FocusEvent', 'InputEvent',
|
|
73
|
+
'PointerEvent', 'WheelEvent', 'DragEvent', 'SubmitEvent',
|
|
121
74
|
]);
|
|
122
75
|
|
|
123
76
|
/**
|
|
@@ -137,94 +90,24 @@ function loadReactEventHandlerNames(): Set<string> {
|
|
|
137
90
|
for (const m of content.matchAll(/\b(on[A-Z][a-zA-Z]+)\??\s*:/g)) {
|
|
138
91
|
names.add(m[1]);
|
|
139
92
|
}
|
|
140
|
-
// oxlint-disable-next-line no-magic-numbers -- 20 is a sanity threshold for react event names
|
|
141
93
|
if (names.size > 20) return names;
|
|
142
94
|
} catch {}
|
|
143
95
|
// Static snapshot — kept as fallback only.
|
|
144
96
|
return new Set([
|
|
145
|
-
'onCopy',
|
|
146
|
-
'
|
|
147
|
-
'
|
|
148
|
-
'
|
|
149
|
-
'
|
|
150
|
-
'
|
|
151
|
-
'
|
|
152
|
-
'
|
|
153
|
-
'
|
|
154
|
-
'
|
|
155
|
-
'
|
|
156
|
-
'
|
|
157
|
-
'
|
|
158
|
-
'
|
|
159
|
-
'onLoad',
|
|
160
|
-
'onError',
|
|
161
|
-
'onKeyDown',
|
|
162
|
-
'onKeyPress',
|
|
163
|
-
'onKeyUp',
|
|
164
|
-
'onAbort',
|
|
165
|
-
'onCanPlay',
|
|
166
|
-
'onCanPlayThrough',
|
|
167
|
-
'onDurationChange',
|
|
168
|
-
'onEmptied',
|
|
169
|
-
'onEncrypted',
|
|
170
|
-
'onEnded',
|
|
171
|
-
'onLoadedData',
|
|
172
|
-
'onLoadedMetadata',
|
|
173
|
-
'onLoadStart',
|
|
174
|
-
'onPause',
|
|
175
|
-
'onPlay',
|
|
176
|
-
'onPlaying',
|
|
177
|
-
'onProgress',
|
|
178
|
-
'onRateChange',
|
|
179
|
-
'onResize',
|
|
180
|
-
'onSeeked',
|
|
181
|
-
'onSeeking',
|
|
182
|
-
'onStalled',
|
|
183
|
-
'onSuspend',
|
|
184
|
-
'onTimeUpdate',
|
|
185
|
-
'onVolumeChange',
|
|
186
|
-
'onWaiting',
|
|
187
|
-
'onAuxClick',
|
|
188
|
-
'onClick',
|
|
189
|
-
'onContextMenu',
|
|
190
|
-
'onDoubleClick',
|
|
191
|
-
'onDrag',
|
|
192
|
-
'onDragEnd',
|
|
193
|
-
'onDragEnter',
|
|
194
|
-
'onDragExit',
|
|
195
|
-
'onDragLeave',
|
|
196
|
-
'onDragOver',
|
|
197
|
-
'onDragStart',
|
|
198
|
-
'onDrop',
|
|
199
|
-
'onMouseDown',
|
|
200
|
-
'onMouseEnter',
|
|
201
|
-
'onMouseLeave',
|
|
202
|
-
'onMouseMove',
|
|
203
|
-
'onMouseOut',
|
|
204
|
-
'onMouseOver',
|
|
205
|
-
'onMouseUp',
|
|
206
|
-
'onSelect',
|
|
207
|
-
'onTouchCancel',
|
|
208
|
-
'onTouchEnd',
|
|
209
|
-
'onTouchMove',
|
|
210
|
-
'onTouchStart',
|
|
211
|
-
'onPointerOver',
|
|
212
|
-
'onPointerEnter',
|
|
213
|
-
'onPointerDown',
|
|
214
|
-
'onPointerMove',
|
|
215
|
-
'onPointerUp',
|
|
216
|
-
'onPointerCancel',
|
|
217
|
-
'onPointerOut',
|
|
218
|
-
'onPointerLeave',
|
|
219
|
-
'onGotPointerCapture',
|
|
220
|
-
'onLostPointerCapture',
|
|
221
|
-
'onScroll',
|
|
222
|
-
'onWheel',
|
|
223
|
-
'onAnimationStart',
|
|
224
|
-
'onAnimationEnd',
|
|
225
|
-
'onAnimationIteration',
|
|
226
|
-
'onTransitionEnd',
|
|
227
|
-
'onToggle',
|
|
97
|
+
'onCopy', 'onCut', 'onPaste', 'onCompositionEnd', 'onCompositionStart', 'onCompositionUpdate',
|
|
98
|
+
'onFocus', 'onBlur', 'onChange', 'onBeforeInput', 'onInput', 'onReset', 'onSubmit',
|
|
99
|
+
'onInvalid', 'onLoad', 'onError', 'onKeyDown', 'onKeyPress', 'onKeyUp', 'onAbort',
|
|
100
|
+
'onCanPlay', 'onCanPlayThrough', 'onDurationChange', 'onEmptied', 'onEncrypted', 'onEnded',
|
|
101
|
+
'onLoadedData', 'onLoadedMetadata', 'onLoadStart', 'onPause', 'onPlay', 'onPlaying',
|
|
102
|
+
'onProgress', 'onRateChange', 'onResize', 'onSeeked', 'onSeeking', 'onStalled', 'onSuspend',
|
|
103
|
+
'onTimeUpdate', 'onVolumeChange', 'onWaiting', 'onAuxClick', 'onClick', 'onContextMenu',
|
|
104
|
+
'onDoubleClick', 'onDrag', 'onDragEnd', 'onDragEnter', 'onDragExit', 'onDragLeave',
|
|
105
|
+
'onDragOver', 'onDragStart', 'onDrop', 'onMouseDown', 'onMouseEnter', 'onMouseLeave',
|
|
106
|
+
'onMouseMove', 'onMouseOut', 'onMouseOver', 'onMouseUp', 'onSelect', 'onTouchCancel',
|
|
107
|
+
'onTouchEnd', 'onTouchMove', 'onTouchStart', 'onPointerOver', 'onPointerEnter',
|
|
108
|
+
'onPointerDown', 'onPointerMove', 'onPointerUp', 'onPointerCancel', 'onPointerOut',
|
|
109
|
+
'onPointerLeave', 'onGotPointerCapture', 'onLostPointerCapture', 'onScroll', 'onWheel',
|
|
110
|
+
'onAnimationStart', 'onAnimationEnd', 'onAnimationIteration', 'onTransitionEnd', 'onToggle',
|
|
228
111
|
]);
|
|
229
112
|
}
|
|
230
113
|
|
|
@@ -322,11 +205,7 @@ function createTypeImportState(): TypeImportState {
|
|
|
322
205
|
};
|
|
323
206
|
}
|
|
324
207
|
|
|
325
|
-
function registerTypeImport(
|
|
326
|
-
state: TypeImportState,
|
|
327
|
-
identifier: string,
|
|
328
|
-
moduleSpecifier: string,
|
|
329
|
-
): void {
|
|
208
|
+
function registerTypeImport(state: TypeImportState, identifier: string, moduleSpecifier: string): void {
|
|
330
209
|
if (state.ambiguousIdentifiers.has(identifier)) return;
|
|
331
210
|
|
|
332
211
|
const existing = state.importsByIdentifier.get(identifier);
|
|
@@ -341,11 +220,7 @@ function registerTypeImport(
|
|
|
341
220
|
}
|
|
342
221
|
}
|
|
343
222
|
|
|
344
|
-
function trackImportedIdentifierUsage(
|
|
345
|
-
state: TypeImportState,
|
|
346
|
-
identifier: string,
|
|
347
|
-
moduleSpecifier: string,
|
|
348
|
-
): void {
|
|
223
|
+
function trackImportedIdentifierUsage(state: TypeImportState, identifier: string, moduleSpecifier: string): void {
|
|
349
224
|
if (!state.usedImports.has(moduleSpecifier)) {
|
|
350
225
|
state.usedImports.set(moduleSpecifier, new Set());
|
|
351
226
|
}
|
|
@@ -359,7 +234,7 @@ function isBareModuleSpecifier(moduleSpecifier: string): boolean {
|
|
|
359
234
|
function canUseComplexType(typeText: string, typeImportState?: TypeImportState): boolean {
|
|
360
235
|
if (!typeText) return false;
|
|
361
236
|
if (/[{};=]/.test(typeText) || /=>/.test(typeText)) return false;
|
|
362
|
-
if (!/^[A-Za-z0-9_
|
|
237
|
+
if (!/^[A-Za-z0-9_$<>\[\]()|&,.?'"`\s:-]+$/.test(typeText)) return false;
|
|
363
238
|
|
|
364
239
|
for (const token of getIdentifierTokens(typeText)) {
|
|
365
240
|
if (isPrimitiveToken(token) || isKnownTypeIdentifier(token)) continue;
|
|
@@ -370,11 +245,7 @@ function canUseComplexType(typeText: string, typeImportState?: TypeImportState):
|
|
|
370
245
|
!typeImportState.ambiguousIdentifiers.has(root) &&
|
|
371
246
|
typeImportState.importsByIdentifier.has(root)
|
|
372
247
|
) {
|
|
373
|
-
trackImportedIdentifierUsage(
|
|
374
|
-
typeImportState,
|
|
375
|
-
root,
|
|
376
|
-
typeImportState.importsByIdentifier.get(root)!,
|
|
377
|
-
);
|
|
248
|
+
trackImportedIdentifierUsage(typeImportState, root, typeImportState.importsByIdentifier.get(root)!);
|
|
378
249
|
continue;
|
|
379
250
|
}
|
|
380
251
|
|
|
@@ -391,7 +262,6 @@ function toSafeType(typeText?: string, typeImportState?: TypeImportState): strin
|
|
|
391
262
|
|
|
392
263
|
if (PRIMITIVE_UNION_REGEX.test(normalized)) return normalized;
|
|
393
264
|
|
|
394
|
-
// oxlint-disable-next-line no-magic-numbers -- -2 strips trailing '[]'
|
|
395
265
|
if (normalized.endsWith('[]') && PRIMITIVE_UNION_REGEX.test(normalized.slice(0, -2).trim())) {
|
|
396
266
|
return normalized;
|
|
397
267
|
}
|
|
@@ -460,17 +330,14 @@ function getCEMManifestPath(cwd: string, packageJson: Record<string, unknown>):
|
|
|
460
330
|
// CEM paths are relative to src/ (e.g. "src/entities/entities.ts").
|
|
461
331
|
// react.mjs/cjs live in dist/ while compiled JS lives in dist/esm/.
|
|
462
332
|
function cemModulePathToJsImport(modulePath: string): string {
|
|
463
|
-
// oxlint-disable no-magic-numbers -- numeric offsets for known file extension lengths
|
|
464
333
|
let p = modulePath.startsWith('src/') ? modulePath.slice(4) : modulePath;
|
|
465
334
|
if (p.endsWith('.tsx')) p = `${p.slice(0, -4)}.js`;
|
|
466
335
|
else if (p.endsWith('.ts')) p = `${p.slice(0, -3)}.js`;
|
|
467
|
-
// oxlint-enable no-magic-numbers
|
|
468
336
|
return `./esm/${p}`;
|
|
469
337
|
}
|
|
470
338
|
|
|
471
339
|
function cemModulePathToDtsImport(modulePath: string): string {
|
|
472
|
-
|
|
473
|
-
const p = modulePath.startsWith('src/') ? modulePath.slice(4) : modulePath;
|
|
340
|
+
let p = modulePath.startsWith('src/') ? modulePath.slice(4) : modulePath;
|
|
474
341
|
const lastDot = p.lastIndexOf('.');
|
|
475
342
|
return `./${lastDot !== -1 ? p.slice(0, lastDot) : p}`;
|
|
476
343
|
}
|
|
@@ -552,9 +419,7 @@ async function mergeFastInheritanceFromManifest(
|
|
|
552
419
|
byTagAndName.get(`${declaration.tagName}::${declaration.superclass?.name ?? ''}`) ??
|
|
553
420
|
byTag.get(declaration.tagName);
|
|
554
421
|
|
|
555
|
-
return inherited
|
|
556
|
-
? { ...entry, declaration: mergeDeclarationMetadata(declaration, inherited) }
|
|
557
|
-
: entry;
|
|
422
|
+
return inherited ? { ...entry, declaration: mergeDeclarationMetadata(declaration, inherited) } : entry;
|
|
558
423
|
});
|
|
559
424
|
}
|
|
560
425
|
|
|
@@ -570,8 +435,7 @@ function buildWrapperEventEntries(
|
|
|
570
435
|
const normalized = normalizePropertyName(event.name);
|
|
571
436
|
if (!normalized) continue;
|
|
572
437
|
const handlerName = `on${toPascalCase(normalized)}`;
|
|
573
|
-
if (!handlerName || REACT_NATIVE_EVENT_HANDLER_NAMES.has(handlerName) || seen.has(handlerName))
|
|
574
|
-
continue;
|
|
438
|
+
if (!handlerName || REACT_NATIVE_EVENT_HANDLER_NAMES.has(handlerName) || seen.has(handlerName)) continue;
|
|
575
439
|
seen.add(handlerName);
|
|
576
440
|
result.push({ handlerName, eventName: event.name });
|
|
577
441
|
}
|
|
@@ -626,18 +490,12 @@ function generateReactWrapperJs(entries: CEMElementEntry[], format: 'esm' | 'cjs
|
|
|
626
490
|
}
|
|
627
491
|
|
|
628
492
|
for (const [modulePath, pathEntries] of [...groupEntriesByPath(valid).entries()].sort()) {
|
|
629
|
-
const sorted = [...pathEntries].sort((a, b) =>
|
|
630
|
-
a.declaration.name!.localeCompare(b.declaration.name!),
|
|
631
|
-
);
|
|
493
|
+
const sorted = [...pathEntries].sort((a, b) => a.declaration.name!.localeCompare(b.declaration.name!));
|
|
632
494
|
const jsPath = cemModulePathToJsImport(modulePath);
|
|
633
495
|
if (esm) {
|
|
634
|
-
lines.push(
|
|
635
|
-
`import { ${sorted.map((e) => `${e.declaration.name} as ${e.declaration.name}WC`).join(', ')} } from '${jsPath}';`,
|
|
636
|
-
);
|
|
496
|
+
lines.push(`import { ${sorted.map((e) => `${e.declaration.name} as ${e.declaration.name}WC`).join(', ')} } from '${jsPath}';`);
|
|
637
497
|
} else {
|
|
638
|
-
lines.push(
|
|
639
|
-
`const { ${sorted.map((e) => `${e.declaration.name}: ${e.declaration.name}WC`).join(', ')} } = require('${jsPath}');`,
|
|
640
|
-
);
|
|
498
|
+
lines.push(`const { ${sorted.map((e) => `${e.declaration.name}: ${e.declaration.name}WC`).join(', ')} } = require('${jsPath}');`);
|
|
641
499
|
}
|
|
642
500
|
}
|
|
643
501
|
|
|
@@ -667,9 +525,7 @@ function generateReactWrapperJs(entries: CEMElementEntry[], format: 'esm' | 'cjs
|
|
|
667
525
|
lines.push(`${prefix} ${name} = React.forwardRef(function ${name}(props, ref) {`);
|
|
668
526
|
|
|
669
527
|
if (events.length) {
|
|
670
|
-
lines.push(
|
|
671
|
-
` const { ${events.map((e) => e.handlerName).join(', ')}, children, ...rest } = props;`,
|
|
672
|
-
);
|
|
528
|
+
lines.push(` const { ${events.map((e) => e.handlerName).join(', ')}, children, ...rest } = props;`);
|
|
673
529
|
lines.push(' const _innerRef = React.useRef(null);');
|
|
674
530
|
for (const { handlerName } of events) {
|
|
675
531
|
lines.push(` const _${handlerName}Ref = React.useRef(${handlerName});`);
|
|
@@ -688,14 +544,10 @@ function generateReactWrapperJs(entries: CEMElementEntry[], format: 'esm' | 'cjs
|
|
|
688
544
|
}
|
|
689
545
|
lines.push(' };');
|
|
690
546
|
lines.push(' }, []);');
|
|
691
|
-
lines.push(
|
|
692
|
-
` return React.createElement(customElements.getName(${name}WC) ?? '${tagName}', { ...rest, ref: _mergeRefs(_innerRef, ref) }, children);`,
|
|
693
|
-
);
|
|
547
|
+
lines.push(` return React.createElement(customElements.getName(${name}WC) ?? '${tagName}', { ...rest, ref: _mergeRefs(_innerRef, ref) }, children);`);
|
|
694
548
|
} else {
|
|
695
549
|
lines.push(' const { children, ...rest } = props;');
|
|
696
|
-
lines.push(
|
|
697
|
-
` return React.createElement(customElements.getName(${name}WC) ?? '${tagName}', { ...rest, ref }, children);`,
|
|
698
|
-
);
|
|
550
|
+
lines.push(` return React.createElement(customElements.getName(${name}WC) ?? '${tagName}', { ...rest, ref }, children);`);
|
|
699
551
|
}
|
|
700
552
|
|
|
701
553
|
lines.push('});');
|
|
@@ -711,10 +563,7 @@ function generateReactWrapperJs(entries: CEMElementEntry[], format: 'esm' | 'cjs
|
|
|
711
563
|
return lines.join('\n');
|
|
712
564
|
}
|
|
713
565
|
|
|
714
|
-
function generateReactWrapperDts(
|
|
715
|
-
entries: CEMElementEntry[],
|
|
716
|
-
typeImportState: TypeImportState,
|
|
717
|
-
): string {
|
|
566
|
+
function generateReactWrapperDts(entries: CEMElementEntry[], typeImportState: TypeImportState): string {
|
|
718
567
|
const valid = entries.filter((e) => e.declaration.name && e.declaration.tagName && e.modulePath);
|
|
719
568
|
if (!valid.length) return '';
|
|
720
569
|
|
|
@@ -735,16 +584,14 @@ function generateReactWrapperDts(
|
|
|
735
584
|
|
|
736
585
|
// Build event lookup scoped to this element to avoid cross-element type pollution.
|
|
737
586
|
const eventsByName = new Map(
|
|
738
|
-
(declaration.events ?? [])
|
|
587
|
+
(declaration.events ?? [])
|
|
588
|
+
.filter((e) => e.name)
|
|
589
|
+
.map((e) => [e.name!, e] as const),
|
|
739
590
|
);
|
|
740
591
|
|
|
741
592
|
const eventLines = buildWrapperEventEntries(declaration).map(({ handlerName, eventName }) => {
|
|
742
593
|
const event = eventsByName.get(eventName);
|
|
743
|
-
const handlerType = toEventHandlerType(
|
|
744
|
-
event?.type?.text,
|
|
745
|
-
wrapperTypeState,
|
|
746
|
-
event?.description,
|
|
747
|
-
);
|
|
594
|
+
const handlerType = toEventHandlerType(event?.type?.text, wrapperTypeState, event?.description);
|
|
748
595
|
return ` ${handlerName}?: ${handlerType};`;
|
|
749
596
|
});
|
|
750
597
|
|
|
@@ -798,7 +645,6 @@ async function collectFilesRecursively(
|
|
|
798
645
|
const stack: string[] = [rootDirectory];
|
|
799
646
|
while (stack.length) {
|
|
800
647
|
const dir = stack.pop()!;
|
|
801
|
-
// oxlint-disable-next-line no-await-in-loop -- iterative directory traversal, sequential by design
|
|
802
648
|
const dirEntries = await readdir(dir, { withFileTypes: true });
|
|
803
649
|
for (const entry of dirEntries) {
|
|
804
650
|
const fullPath = resolve(dir, entry.name);
|
|
@@ -858,8 +704,7 @@ function parseImportsFromDtsContent(content: string, state: TypeImportState): vo
|
|
|
858
704
|
registerTypeImport(state, alias[2], moduleSpecifier);
|
|
859
705
|
continue;
|
|
860
706
|
}
|
|
861
|
-
if (/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(entry))
|
|
862
|
-
registerTypeImport(state, entry, moduleSpecifier);
|
|
707
|
+
if (/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(entry)) registerTypeImport(state, entry, moduleSpecifier);
|
|
863
708
|
}
|
|
864
709
|
}
|
|
865
710
|
|
|
@@ -903,7 +748,6 @@ function mergeTypeImportStateInto(target: TypeImportState, source: TypeImportSta
|
|
|
903
748
|
async function findWorkspaceRoot(startDirectory: string): Promise<string> {
|
|
904
749
|
let dir = startDirectory;
|
|
905
750
|
while (true) {
|
|
906
|
-
// oxlint-disable-next-line no-await-in-loop -- upward directory search must be sequential
|
|
907
751
|
const [hasPackages, hasPackageJson] = await Promise.all([
|
|
908
752
|
fileExists(resolve(dir, 'packages')),
|
|
909
753
|
fileExists(resolve(dir, 'package.json')),
|
|
@@ -924,17 +768,13 @@ async function getWorkspacePackageDirectoryByName(
|
|
|
924
768
|
|
|
925
769
|
const packageJsonFiles = await collectFilesRecursively(packagesDir, (n) => n === 'package.json');
|
|
926
770
|
for (const jsonPath of packageJsonFiles) {
|
|
927
|
-
// oxlint-disable-next-line no-await-in-loop -- early-exit search, sequential is correct
|
|
928
771
|
const pkg = JSON.parse(await readFile(jsonPath, 'utf8')) as Record<string, unknown>;
|
|
929
772
|
if (pkg.name === packageName) return dirname(jsonPath);
|
|
930
773
|
}
|
|
931
774
|
return undefined;
|
|
932
775
|
}
|
|
933
776
|
|
|
934
|
-
async function enrichFromWorkspaceWildcardExports(
|
|
935
|
-
cwd: string,
|
|
936
|
-
state: TypeImportState,
|
|
937
|
-
): Promise<void> {
|
|
777
|
+
async function enrichFromWorkspaceWildcardExports(cwd: string, state: TypeImportState): Promise<void> {
|
|
938
778
|
const workspaceRoot = await findWorkspaceRoot(cwd);
|
|
939
779
|
// for...of over a Set processes items added inside the loop (spec-guaranteed behaviour).
|
|
940
780
|
const pending = new Set(
|
|
@@ -942,20 +782,15 @@ async function enrichFromWorkspaceWildcardExports(
|
|
|
942
782
|
);
|
|
943
783
|
|
|
944
784
|
for (const moduleSpecifier of pending) {
|
|
945
|
-
// oxlint-disable-next-line no-await-in-loop -- sequential per-package processing is intentional
|
|
946
785
|
const pkgDir = await getWorkspacePackageDirectoryByName(workspaceRoot, moduleSpecifier);
|
|
947
786
|
if (!pkgDir) continue;
|
|
948
787
|
|
|
949
788
|
const distDir = resolve(pkgDir, 'dist');
|
|
950
|
-
// oxlint-disable-next-line no-await-in-loop -- sequential per-package processing is intentional
|
|
951
789
|
if (!(await fileExists(distDir))) continue;
|
|
952
790
|
|
|
953
791
|
const refState = createTypeImportState();
|
|
954
|
-
// oxlint-disable-next-line no-await-in-loop -- sequential per-package processing is intentional
|
|
955
792
|
const { apiJsonFiles, dtsFiles } = await collectTypeMetadataFiles(distDir);
|
|
956
|
-
// oxlint-disable-next-line no-await-in-loop -- sequential per-package processing is intentional
|
|
957
793
|
await parseApiJsonFiles(apiJsonFiles, refState);
|
|
958
|
-
// oxlint-disable-next-line no-await-in-loop -- sequential per-package processing is intentional
|
|
959
794
|
await parseDtsFiles(dtsFiles, refState);
|
|
960
795
|
mergeTypeImportStateInto(state, refState);
|
|
961
796
|
|
|
@@ -986,10 +821,7 @@ export async function generateReactWrappers(cwd: string): Promise<GenerateResult
|
|
|
986
821
|
return { generated: false, reason: 'No package.json found.' };
|
|
987
822
|
}
|
|
988
823
|
|
|
989
|
-
const packageJson = JSON.parse(await readFile(packageJsonPath, 'utf8')) as Record<
|
|
990
|
-
string,
|
|
991
|
-
unknown
|
|
992
|
-
>;
|
|
824
|
+
const packageJson = JSON.parse(await readFile(packageJsonPath, 'utf8')) as Record<string, unknown>;
|
|
993
825
|
const manifestPath = getCEMManifestPath(cwd, packageJson);
|
|
994
826
|
if (!(await fileExists(manifestPath))) {
|
|
995
827
|
return { generated: false, reason: 'No custom elements manifest found.' };
|
package/tsconfig.json
CHANGED
|
@@ -2,10 +2,17 @@
|
|
|
2
2
|
"extends": "../../../../tsconfig.json",
|
|
3
3
|
"compilerOptions": {
|
|
4
4
|
"declarationDir": "./dist",
|
|
5
|
-
"lib": [
|
|
5
|
+
"lib": [
|
|
6
|
+
"ES2015",
|
|
7
|
+
"ES2016",
|
|
8
|
+
"ES2017",
|
|
9
|
+
"ES2019",
|
|
10
|
+
],
|
|
6
11
|
"module": "commonjs",
|
|
7
12
|
"outDir": "./dist",
|
|
8
|
-
"rootDir": "./src"
|
|
13
|
+
"rootDir": "./src",
|
|
9
14
|
},
|
|
10
|
-
"include": [
|
|
15
|
+
"include": [
|
|
16
|
+
"src/**/*"
|
|
17
|
+
]
|
|
11
18
|
}
|