@genesislcap/ts-builder 14.417.1-alpha-83eabbf.0 → 14.418.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/index.js +0 -8
- package/package.json +3 -3
- package/src/index.ts +0 -8
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/react-jsx-generator.d.ts +0 -6
- package/dist/react-jsx-generator.d.ts.map +0 -1
- package/dist/react-jsx-generator.js +0 -806
- package/src/react-jsx-generator.ts +0 -994
|
@@ -1,806 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateReactJsxTypes = generateReactJsxTypes;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const promises_1 = require("node:fs/promises");
|
|
6
|
-
const node_path_1 = require("node:path");
|
|
7
|
-
function createTypeImportState() {
|
|
8
|
-
return {
|
|
9
|
-
importsByIdentifier: new Map(),
|
|
10
|
-
ambiguousIdentifiers: new Set(),
|
|
11
|
-
usedImports: new Map(),
|
|
12
|
-
wildcardExportModules: new Set(),
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
const GENERATED_FILE_NAME = 'react-jsx-runtime.d.ts';
|
|
16
|
-
const primitiveUnionRegex = /^(?:\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*)*$/;
|
|
17
|
-
const allowedTypeIdentifierRegex = /^[A-Za-z_$][A-Za-z0-9_$]*(?:\.[A-Za-z_$][A-Za-z0-9_$]*)*$/;
|
|
18
|
-
const allowedTypeNameSet = new Set([
|
|
19
|
-
'Array',
|
|
20
|
-
'ReadonlyArray',
|
|
21
|
-
'Promise',
|
|
22
|
-
'Record',
|
|
23
|
-
'Partial',
|
|
24
|
-
'Required',
|
|
25
|
-
'Pick',
|
|
26
|
-
'Omit',
|
|
27
|
-
'Map',
|
|
28
|
-
'Set',
|
|
29
|
-
'WeakMap',
|
|
30
|
-
'WeakSet',
|
|
31
|
-
'Date',
|
|
32
|
-
'RegExp',
|
|
33
|
-
'Error',
|
|
34
|
-
'Node',
|
|
35
|
-
'Element',
|
|
36
|
-
'HTMLElement',
|
|
37
|
-
'SVGElement',
|
|
38
|
-
'Event',
|
|
39
|
-
'CustomEvent',
|
|
40
|
-
'MouseEvent',
|
|
41
|
-
'KeyboardEvent',
|
|
42
|
-
'FocusEvent',
|
|
43
|
-
'InputEvent',
|
|
44
|
-
'PointerEvent',
|
|
45
|
-
'WheelEvent',
|
|
46
|
-
'DragEvent',
|
|
47
|
-
'SubmitEvent',
|
|
48
|
-
'AbortSignal',
|
|
49
|
-
'DOMRect',
|
|
50
|
-
'Document',
|
|
51
|
-
'Window',
|
|
52
|
-
'URL',
|
|
53
|
-
'URLSearchParams',
|
|
54
|
-
'CSSStyleDeclaration',
|
|
55
|
-
'Intl.Locale',
|
|
56
|
-
]);
|
|
57
|
-
const reactNativeEventHandlerNames = new Set([
|
|
58
|
-
'onCopy',
|
|
59
|
-
'onCut',
|
|
60
|
-
'onPaste',
|
|
61
|
-
'onCompositionEnd',
|
|
62
|
-
'onCompositionStart',
|
|
63
|
-
'onCompositionUpdate',
|
|
64
|
-
'onFocus',
|
|
65
|
-
'onBlur',
|
|
66
|
-
'onChange',
|
|
67
|
-
'onBeforeInput',
|
|
68
|
-
'onInput',
|
|
69
|
-
'onReset',
|
|
70
|
-
'onSubmit',
|
|
71
|
-
'onInvalid',
|
|
72
|
-
'onLoad',
|
|
73
|
-
'onError',
|
|
74
|
-
'onKeyDown',
|
|
75
|
-
'onKeyPress',
|
|
76
|
-
'onKeyUp',
|
|
77
|
-
'onAbort',
|
|
78
|
-
'onCanPlay',
|
|
79
|
-
'onCanPlayThrough',
|
|
80
|
-
'onDurationChange',
|
|
81
|
-
'onEmptied',
|
|
82
|
-
'onEncrypted',
|
|
83
|
-
'onEnded',
|
|
84
|
-
'onLoadedData',
|
|
85
|
-
'onLoadedMetadata',
|
|
86
|
-
'onLoadStart',
|
|
87
|
-
'onPause',
|
|
88
|
-
'onPlay',
|
|
89
|
-
'onPlaying',
|
|
90
|
-
'onProgress',
|
|
91
|
-
'onRateChange',
|
|
92
|
-
'onResize',
|
|
93
|
-
'onSeeked',
|
|
94
|
-
'onSeeking',
|
|
95
|
-
'onStalled',
|
|
96
|
-
'onSuspend',
|
|
97
|
-
'onTimeUpdate',
|
|
98
|
-
'onVolumeChange',
|
|
99
|
-
'onWaiting',
|
|
100
|
-
'onAuxClick',
|
|
101
|
-
'onClick',
|
|
102
|
-
'onContextMenu',
|
|
103
|
-
'onDoubleClick',
|
|
104
|
-
'onDrag',
|
|
105
|
-
'onDragEnd',
|
|
106
|
-
'onDragEnter',
|
|
107
|
-
'onDragExit',
|
|
108
|
-
'onDragLeave',
|
|
109
|
-
'onDragOver',
|
|
110
|
-
'onDragStart',
|
|
111
|
-
'onDrop',
|
|
112
|
-
'onMouseDown',
|
|
113
|
-
'onMouseEnter',
|
|
114
|
-
'onMouseLeave',
|
|
115
|
-
'onMouseMove',
|
|
116
|
-
'onMouseOut',
|
|
117
|
-
'onMouseOver',
|
|
118
|
-
'onMouseUp',
|
|
119
|
-
'onSelect',
|
|
120
|
-
'onTouchCancel',
|
|
121
|
-
'onTouchEnd',
|
|
122
|
-
'onTouchMove',
|
|
123
|
-
'onTouchStart',
|
|
124
|
-
'onPointerOver',
|
|
125
|
-
'onPointerEnter',
|
|
126
|
-
'onPointerDown',
|
|
127
|
-
'onPointerMove',
|
|
128
|
-
'onPointerUp',
|
|
129
|
-
'onPointerCancel',
|
|
130
|
-
'onPointerOut',
|
|
131
|
-
'onPointerLeave',
|
|
132
|
-
'onGotPointerCapture',
|
|
133
|
-
'onLostPointerCapture',
|
|
134
|
-
'onScroll',
|
|
135
|
-
'onWheel',
|
|
136
|
-
'onAnimationStart',
|
|
137
|
-
'onAnimationEnd',
|
|
138
|
-
'onAnimationIteration',
|
|
139
|
-
'onTransitionEnd',
|
|
140
|
-
'onToggle',
|
|
141
|
-
]);
|
|
142
|
-
function normalizeWhitespace(value) {
|
|
143
|
-
return value.replace(/\s+/g, ' ').trim();
|
|
144
|
-
}
|
|
145
|
-
function toTypeNameSegment(value) {
|
|
146
|
-
const pascal = toPascalCase(value);
|
|
147
|
-
if (!pascal) {
|
|
148
|
-
return 'Pkg';
|
|
149
|
-
}
|
|
150
|
-
if (/^[0-9]/.test(pascal)) {
|
|
151
|
-
return `Pkg${pascal}`;
|
|
152
|
-
}
|
|
153
|
-
return pascal;
|
|
154
|
-
}
|
|
155
|
-
function getPackageTypePrefix(packageName) {
|
|
156
|
-
const withoutScope = packageName.replace(/^@/, '').replace(/\//g, '-');
|
|
157
|
-
const segment = toTypeNameSegment(withoutScope);
|
|
158
|
-
return `${segment}React`;
|
|
159
|
-
}
|
|
160
|
-
function normalizePropertyName(name) {
|
|
161
|
-
let normalized = name.trim();
|
|
162
|
-
if (!normalized)
|
|
163
|
-
return null;
|
|
164
|
-
const bracketQuotedMatch = normalized.match(/^\[\s*['"](.+?)['"]\s*\]$/);
|
|
165
|
-
if (bracketQuotedMatch) {
|
|
166
|
-
normalized = bracketQuotedMatch[1];
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
const bracketMatch = normalized.match(/^\[\s*(.+?)\s*\]$/);
|
|
170
|
-
if (bracketMatch) {
|
|
171
|
-
normalized = bracketMatch[1];
|
|
172
|
-
}
|
|
173
|
-
const quotedMatch = normalized.match(/^['"](.+?)['"]$/);
|
|
174
|
-
if (quotedMatch) {
|
|
175
|
-
normalized = quotedMatch[1];
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
normalized = normalized.trim();
|
|
179
|
-
if (!normalized)
|
|
180
|
-
return null;
|
|
181
|
-
if (normalized.includes('\n') || normalized.includes('\r'))
|
|
182
|
-
return null;
|
|
183
|
-
return normalized;
|
|
184
|
-
}
|
|
185
|
-
function escapeSingleQuotes(value) {
|
|
186
|
-
return value.replace(/\\/g, '\\\\').replace(/'/g, "\\'");
|
|
187
|
-
}
|
|
188
|
-
function isKnownTypeIdentifier(identifier) {
|
|
189
|
-
if (allowedTypeNameSet.has(identifier))
|
|
190
|
-
return true;
|
|
191
|
-
if (allowedTypeIdentifierRegex.test(identifier) && identifier.startsWith('globalThis.'))
|
|
192
|
-
return true;
|
|
193
|
-
return false;
|
|
194
|
-
}
|
|
195
|
-
function getIdentifierTokens(typeText) {
|
|
196
|
-
var _a;
|
|
197
|
-
return (_a = typeText.match(/[A-Za-z_$][A-Za-z0-9_$]*(?:\.[A-Za-z_$][A-Za-z0-9_$]*)*/g)) !== null && _a !== void 0 ? _a : [];
|
|
198
|
-
}
|
|
199
|
-
function isPrimitiveToken(match) {
|
|
200
|
-
return (match === 'true' ||
|
|
201
|
-
match === 'false' ||
|
|
202
|
-
match === 'null' ||
|
|
203
|
-
match === 'undefined' ||
|
|
204
|
-
match === 'string' ||
|
|
205
|
-
match === 'number' ||
|
|
206
|
-
match === 'boolean' ||
|
|
207
|
-
match === 'bigint' ||
|
|
208
|
-
match === 'symbol' ||
|
|
209
|
-
match === 'unknown' ||
|
|
210
|
-
match === 'any' ||
|
|
211
|
-
match === 'void' ||
|
|
212
|
-
match === 'never');
|
|
213
|
-
}
|
|
214
|
-
function registerTypeImport(state, identifier, moduleSpecifier) {
|
|
215
|
-
if (state.ambiguousIdentifiers.has(identifier)) {
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
const existing = state.importsByIdentifier.get(identifier);
|
|
219
|
-
if (existing && existing !== moduleSpecifier) {
|
|
220
|
-
state.importsByIdentifier.delete(identifier);
|
|
221
|
-
state.ambiguousIdentifiers.add(identifier);
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
if (!existing) {
|
|
225
|
-
state.importsByIdentifier.set(identifier, moduleSpecifier);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
function trackImportedIdentifierUsage(state, identifier, moduleSpecifier) {
|
|
229
|
-
if (!state.usedImports.has(moduleSpecifier)) {
|
|
230
|
-
state.usedImports.set(moduleSpecifier, new Set());
|
|
231
|
-
}
|
|
232
|
-
state.usedImports.get(moduleSpecifier).add(identifier);
|
|
233
|
-
}
|
|
234
|
-
function isBareModuleSpecifier(moduleSpecifier) {
|
|
235
|
-
return !!moduleSpecifier && !moduleSpecifier.startsWith('.') && !moduleSpecifier.startsWith('/');
|
|
236
|
-
}
|
|
237
|
-
function canUseComplexType(typeText, typeImportState) {
|
|
238
|
-
if (!typeText)
|
|
239
|
-
return false;
|
|
240
|
-
if (/[{};=]/.test(typeText))
|
|
241
|
-
return false;
|
|
242
|
-
if (/=>/.test(typeText))
|
|
243
|
-
return false;
|
|
244
|
-
if (!/^[A-Za-z0-9_$<>\[\]\(\)\|&,.?'"`\s:-]+$/.test(typeText))
|
|
245
|
-
return false;
|
|
246
|
-
const identifierMatches = getIdentifierTokens(typeText);
|
|
247
|
-
for (const match of identifierMatches) {
|
|
248
|
-
if (isPrimitiveToken(match)) {
|
|
249
|
-
continue;
|
|
250
|
-
}
|
|
251
|
-
if (isKnownTypeIdentifier(match)) {
|
|
252
|
-
continue;
|
|
253
|
-
}
|
|
254
|
-
const rootIdentifier = match.split('.')[0];
|
|
255
|
-
if (typeImportState &&
|
|
256
|
-
!typeImportState.ambiguousIdentifiers.has(rootIdentifier) &&
|
|
257
|
-
typeImportState.importsByIdentifier.has(rootIdentifier)) {
|
|
258
|
-
trackImportedIdentifierUsage(typeImportState, rootIdentifier, typeImportState.importsByIdentifier.get(rootIdentifier));
|
|
259
|
-
continue;
|
|
260
|
-
}
|
|
261
|
-
if (!isKnownTypeIdentifier(rootIdentifier)) {
|
|
262
|
-
return false;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
return true;
|
|
266
|
-
}
|
|
267
|
-
function toPascalCase(value) {
|
|
268
|
-
return value
|
|
269
|
-
.split(/[^a-zA-Z0-9]+/)
|
|
270
|
-
.filter(Boolean)
|
|
271
|
-
.map((part) => `${part[0].toUpperCase()}${part.slice(1)}`)
|
|
272
|
-
.join('');
|
|
273
|
-
}
|
|
274
|
-
function toCamelCase(value) {
|
|
275
|
-
const pascal = toPascalCase(value);
|
|
276
|
-
if (!pascal)
|
|
277
|
-
return '';
|
|
278
|
-
return `${pascal[0].toLowerCase()}${pascal.slice(1)}`;
|
|
279
|
-
}
|
|
280
|
-
function toSafeType(typeText, typeImportState) {
|
|
281
|
-
if (!typeText)
|
|
282
|
-
return 'unknown';
|
|
283
|
-
const normalized = normalizeWhitespace(typeText);
|
|
284
|
-
if (!normalized)
|
|
285
|
-
return 'unknown';
|
|
286
|
-
if (primitiveUnionRegex.test(normalized)) {
|
|
287
|
-
return normalized;
|
|
288
|
-
}
|
|
289
|
-
if (normalized.endsWith('[]')) {
|
|
290
|
-
const itemType = normalized.slice(0, -2).trim();
|
|
291
|
-
if (primitiveUnionRegex.test(itemType)) {
|
|
292
|
-
return `${itemType}[]`;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
if (canUseComplexType(normalized, typeImportState)) {
|
|
296
|
-
return normalized;
|
|
297
|
-
}
|
|
298
|
-
return 'unknown';
|
|
299
|
-
}
|
|
300
|
-
function getCEMManifestPath(cwd, packageJson) {
|
|
301
|
-
if (typeof packageJson.customElements === 'string' && packageJson.customElements.trim().length > 0) {
|
|
302
|
-
return (0, node_path_1.resolve)(cwd, packageJson.customElements);
|
|
303
|
-
}
|
|
304
|
-
return (0, node_path_1.resolve)(cwd, 'dist/custom-elements.json');
|
|
305
|
-
}
|
|
306
|
-
function collectCustomElements(manifest) {
|
|
307
|
-
var _a, _b;
|
|
308
|
-
const elements = [];
|
|
309
|
-
for (const moduleDefinition of (_a = manifest.modules) !== null && _a !== void 0 ? _a : []) {
|
|
310
|
-
for (const declaration of (_b = moduleDefinition.declarations) !== null && _b !== void 0 ? _b : []) {
|
|
311
|
-
if (declaration.customElement && declaration.tagName) {
|
|
312
|
-
elements.push(declaration);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
return elements;
|
|
317
|
-
}
|
|
318
|
-
function mergeUniqueByKey(base, extra, getKey) {
|
|
319
|
-
const merged = [...base];
|
|
320
|
-
const knownKeys = new Set(base
|
|
321
|
-
.map((item) => getKey(item))
|
|
322
|
-
.filter((item) => !!item));
|
|
323
|
-
for (const item of extra) {
|
|
324
|
-
const key = getKey(item);
|
|
325
|
-
if (!key || !knownKeys.has(key)) {
|
|
326
|
-
merged.push(item);
|
|
327
|
-
if (key)
|
|
328
|
-
knownKeys.add(key);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
return merged;
|
|
332
|
-
}
|
|
333
|
-
function mergeDeclarationMetadata(declaration, inheritedDeclaration) {
|
|
334
|
-
var _a, _b, _c, _d, _e, _f;
|
|
335
|
-
const declarationAttributes = (_a = declaration.attributes) !== null && _a !== void 0 ? _a : [];
|
|
336
|
-
const inheritedAttributes = (_b = inheritedDeclaration.attributes) !== null && _b !== void 0 ? _b : [];
|
|
337
|
-
const attributes = mergeUniqueByKey(declarationAttributes, inheritedAttributes, (attribute) => { var _a, _b; return normalizePropertyName((_b = (_a = attribute.fieldName) !== null && _a !== void 0 ? _a : attribute.name) !== null && _b !== void 0 ? _b : ''); });
|
|
338
|
-
const declarationMembers = (_c = declaration.members) !== null && _c !== void 0 ? _c : [];
|
|
339
|
-
const inheritedMembers = (_d = inheritedDeclaration.members) !== null && _d !== void 0 ? _d : [];
|
|
340
|
-
const members = mergeUniqueByKey(declarationMembers, inheritedMembers, (member) => { var _a; return normalizePropertyName((_a = member.name) !== null && _a !== void 0 ? _a : ''); });
|
|
341
|
-
const declarationEvents = (_e = declaration.events) !== null && _e !== void 0 ? _e : [];
|
|
342
|
-
const inheritedEvents = (_f = inheritedDeclaration.events) !== null && _f !== void 0 ? _f : [];
|
|
343
|
-
const events = mergeUniqueByKey(declarationEvents, inheritedEvents, (event) => { var _a; return normalizePropertyName((_a = event.name) !== null && _a !== void 0 ? _a : ''); });
|
|
344
|
-
return Object.assign(Object.assign({}, declaration), { attributes,
|
|
345
|
-
members,
|
|
346
|
-
events });
|
|
347
|
-
}
|
|
348
|
-
function createDeclarationLookup(manifest) {
|
|
349
|
-
var _a, _b;
|
|
350
|
-
const byTagAndName = new Map();
|
|
351
|
-
const byTag = new Map();
|
|
352
|
-
for (const moduleDefinition of (_a = manifest.modules) !== null && _a !== void 0 ? _a : []) {
|
|
353
|
-
for (const declaration of (_b = moduleDefinition.declarations) !== null && _b !== void 0 ? _b : []) {
|
|
354
|
-
if (!declaration.customElement || !declaration.tagName)
|
|
355
|
-
continue;
|
|
356
|
-
if (declaration.name) {
|
|
357
|
-
byTagAndName.set(`${declaration.tagName}::${declaration.name}`, declaration);
|
|
358
|
-
}
|
|
359
|
-
if (!byTag.has(declaration.tagName)) {
|
|
360
|
-
byTag.set(declaration.tagName, declaration);
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
return { byTagAndName, byTag };
|
|
365
|
-
}
|
|
366
|
-
function mergeFastInheritanceFromManifest(cwd, declarations) {
|
|
367
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
368
|
-
const fastManifestPath = (0, node_path_1.resolve)(cwd, 'ms-fast-components/custom-elements.json');
|
|
369
|
-
if (!(yield fileExists(fastManifestPath))) {
|
|
370
|
-
return declarations;
|
|
371
|
-
}
|
|
372
|
-
const fastManifest = JSON.parse(yield (0, promises_1.readFile)(fastManifestPath, 'utf8'));
|
|
373
|
-
const { byTagAndName, byTag } = createDeclarationLookup(fastManifest);
|
|
374
|
-
return declarations.map((declaration) => {
|
|
375
|
-
var _a, _b, _c, _d, _e, _f;
|
|
376
|
-
if (!declaration.tagName || ((_a = declaration.superclass) === null || _a === void 0 ? void 0 : _a.package) !== '@microsoft/fast-components') {
|
|
377
|
-
return declaration;
|
|
378
|
-
}
|
|
379
|
-
const byTagAndNameKey = `${declaration.tagName}::${(_b = declaration.name) !== null && _b !== void 0 ? _b : ''}`;
|
|
380
|
-
const inheritedDeclaration = (_f = (_c = byTagAndName.get(byTagAndNameKey)) !== 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);
|
|
381
|
-
if (!inheritedDeclaration) {
|
|
382
|
-
return declaration;
|
|
383
|
-
}
|
|
384
|
-
return mergeDeclarationMetadata(declaration, inheritedDeclaration);
|
|
385
|
-
});
|
|
386
|
-
});
|
|
387
|
-
}
|
|
388
|
-
function resolveTagPrefixes(packageName) {
|
|
389
|
-
const normalized = packageName.toLowerCase();
|
|
390
|
-
if (normalized === '@genesislcap/foundation-ui') {
|
|
391
|
-
return ['foundation'];
|
|
392
|
-
}
|
|
393
|
-
if (normalized.startsWith('@genesislcap/rapid-') || normalized.includes('/rapid-')) {
|
|
394
|
-
return ['rapid'];
|
|
395
|
-
}
|
|
396
|
-
if (normalized.includes('foundation-zero') || normalized.startsWith('@genesislcap/zero-')) {
|
|
397
|
-
return ['zero'];
|
|
398
|
-
}
|
|
399
|
-
// MF and generic foundation packages can switch prefixes at runtime.
|
|
400
|
-
return ['foundation', 'rapid', 'zero'];
|
|
401
|
-
}
|
|
402
|
-
function normalizeTagNames(tagName, packageName) {
|
|
403
|
-
const prefixToken = '%%prefix%%-';
|
|
404
|
-
if (!tagName.includes(prefixToken)) {
|
|
405
|
-
return [tagName];
|
|
406
|
-
}
|
|
407
|
-
const suffix = tagName.replace(prefixToken, '');
|
|
408
|
-
return resolveTagPrefixes(packageName).map((prefix) => `${prefix}-${suffix}`);
|
|
409
|
-
}
|
|
410
|
-
function toEventHandlerType(typeText, typeImportState) {
|
|
411
|
-
var _a;
|
|
412
|
-
if (!typeText) {
|
|
413
|
-
return '(event: CustomEvent<unknown>) => void';
|
|
414
|
-
}
|
|
415
|
-
const normalized = typeText.trim();
|
|
416
|
-
if (!normalized) {
|
|
417
|
-
return '(event: CustomEvent<unknown>) => void';
|
|
418
|
-
}
|
|
419
|
-
if (normalized === 'Event') {
|
|
420
|
-
return '(event: Event) => void';
|
|
421
|
-
}
|
|
422
|
-
if (normalized.startsWith('CustomEvent<')) {
|
|
423
|
-
const match = normalized.match(/^CustomEvent<(.+)>$/);
|
|
424
|
-
if (!match)
|
|
425
|
-
return '(event: CustomEvent<unknown>) => void';
|
|
426
|
-
const detailType = toSafeType((_a = match[1]) === null || _a === void 0 ? void 0 : _a.trim(), typeImportState);
|
|
427
|
-
return `(event: CustomEvent<${detailType}>) => void`;
|
|
428
|
-
}
|
|
429
|
-
if (normalized === 'CustomEvent') {
|
|
430
|
-
return '(event: CustomEvent<unknown>) => void';
|
|
431
|
-
}
|
|
432
|
-
return '(event: CustomEvent<unknown>) => void';
|
|
433
|
-
}
|
|
434
|
-
function buildElementProps(declaration, typeImportState) {
|
|
435
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
436
|
-
const propertyMap = new Map();
|
|
437
|
-
const eventMap = new Map();
|
|
438
|
-
const addProperty = (name, typeText) => {
|
|
439
|
-
if (!name)
|
|
440
|
-
return;
|
|
441
|
-
const normalizedName = normalizePropertyName(name);
|
|
442
|
-
if (!normalizedName)
|
|
443
|
-
return;
|
|
444
|
-
const safeType = toSafeType(typeText, typeImportState);
|
|
445
|
-
if (!propertyMap.has(normalizedName)) {
|
|
446
|
-
propertyMap.set(normalizedName, safeType);
|
|
447
|
-
}
|
|
448
|
-
};
|
|
449
|
-
for (const attribute of (_a = declaration.attributes) !== null && _a !== void 0 ? _a : []) {
|
|
450
|
-
// Prefer React-friendly property casing when available.
|
|
451
|
-
if (attribute.fieldName) {
|
|
452
|
-
addProperty(attribute.fieldName, (_b = attribute.type) === null || _b === void 0 ? void 0 : _b.text);
|
|
453
|
-
}
|
|
454
|
-
else if (attribute.name) {
|
|
455
|
-
addProperty(attribute.name, (_c = attribute.type) === null || _c === void 0 ? void 0 : _c.text);
|
|
456
|
-
if (attribute.name.includes('-')) {
|
|
457
|
-
const camelName = toCamelCase(attribute.name);
|
|
458
|
-
if (camelName) {
|
|
459
|
-
addProperty(camelName, (_d = attribute.type) === null || _d === void 0 ? void 0 : _d.text);
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
// Only include public fields that are reflected as attributes.
|
|
465
|
-
for (const member of (_e = declaration.members) !== null && _e !== void 0 ? _e : []) {
|
|
466
|
-
if (member.kind === 'field' &&
|
|
467
|
-
member.privacy !== 'private' &&
|
|
468
|
-
member.privacy !== 'protected' &&
|
|
469
|
-
member.attribute &&
|
|
470
|
-
member.name &&
|
|
471
|
-
!member.name.startsWith('_') &&
|
|
472
|
-
!member.name.startsWith('$')) {
|
|
473
|
-
// React canonical typing should expose property name (camelCase).
|
|
474
|
-
addProperty(member.name, (_f = member.type) === null || _f === void 0 ? void 0 : _f.text);
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
for (const event of (_g = declaration.events) !== null && _g !== void 0 ? _g : []) {
|
|
478
|
-
if (!event.name)
|
|
479
|
-
continue;
|
|
480
|
-
const normalizedEventName = normalizePropertyName(event.name);
|
|
481
|
-
if (!normalizedEventName)
|
|
482
|
-
continue;
|
|
483
|
-
const eventHandlerType = toEventHandlerType((_h = event.type) === null || _h === void 0 ? void 0 : _h.text, typeImportState);
|
|
484
|
-
const pascalName = toPascalCase(normalizedEventName);
|
|
485
|
-
if (pascalName) {
|
|
486
|
-
const handlerName = `on${pascalName}`;
|
|
487
|
-
if (!reactNativeEventHandlerNames.has(handlerName)) {
|
|
488
|
-
eventMap.set(handlerName, eventHandlerType);
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
const lines = [
|
|
493
|
-
'class?: string;',
|
|
494
|
-
'part?: string;',
|
|
495
|
-
'[key: `data-${string}`]: string | number | boolean | undefined;',
|
|
496
|
-
];
|
|
497
|
-
for (const [name, typeText] of propertyMap) {
|
|
498
|
-
lines.push(`'${escapeSingleQuotes(name)}'?: ${typeText};`);
|
|
499
|
-
}
|
|
500
|
-
for (const [name, handlerType] of eventMap) {
|
|
501
|
-
lines.push(`'${escapeSingleQuotes(name)}'?: ${handlerType};`);
|
|
502
|
-
}
|
|
503
|
-
return lines;
|
|
504
|
-
}
|
|
505
|
-
function generateDeclarations(packageName, declarations, typeImportState) {
|
|
506
|
-
const packagePrefix = getPackageTypePrefix(packageName);
|
|
507
|
-
const interfaceEntries = [];
|
|
508
|
-
const interfacesByTag = new Map();
|
|
509
|
-
let interfaceCounter = 0;
|
|
510
|
-
for (const declaration of declarations) {
|
|
511
|
-
const interfaceName = `${packagePrefix}ElementProps${interfaceCounter + 1}`;
|
|
512
|
-
interfaceCounter += 1;
|
|
513
|
-
const props = buildElementProps(declaration, typeImportState).map((line) => ` ${line}`);
|
|
514
|
-
const code = [` interface ${interfaceName} {`, ...props, ' }'].join('\n');
|
|
515
|
-
interfaceEntries.push({ interfaceName, code });
|
|
516
|
-
for (const tagName of normalizeTagNames(declaration.tagName, packageName)) {
|
|
517
|
-
if (!interfacesByTag.has(tagName)) {
|
|
518
|
-
interfacesByTag.set(tagName, interfaceName);
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
const intrinsicEntries = [...interfacesByTag.entries()]
|
|
523
|
-
.sort((a, b) => a[0].localeCompare(b[0]))
|
|
524
|
-
.map(([tagName, interfaceName]) => ` '${tagName}': ${interfaceName};`);
|
|
525
|
-
const elementInterfaces = interfaceEntries.map((entry) => entry.code.replace(`interface ${entry.interfaceName} {`, `interface ${entry.interfaceName} extends HTMLAttributes<HTMLElement> {`));
|
|
526
|
-
const importLines = [...typeImportState.usedImports.entries()]
|
|
527
|
-
.sort((a, b) => a[0].localeCompare(b[0]))
|
|
528
|
-
.map(([moduleSpecifier, identifiers]) => {
|
|
529
|
-
const sortedIdentifiers = [...identifiers].sort((a, b) => a.localeCompare(b));
|
|
530
|
-
return `import type { ${sortedIdentifiers.join(', ')} } from '${moduleSpecifier}';`;
|
|
531
|
-
});
|
|
532
|
-
return [
|
|
533
|
-
'/**',
|
|
534
|
-
' * AUTO-GENERATED FILE - DO NOT EDIT.',
|
|
535
|
-
` * Source package: ${packageName}`,
|
|
536
|
-
' * Generated from custom-elements manifest.',
|
|
537
|
-
' */',
|
|
538
|
-
'',
|
|
539
|
-
"import type { HTMLAttributes } from 'react';",
|
|
540
|
-
...importLines,
|
|
541
|
-
'',
|
|
542
|
-
"declare module 'react/jsx-runtime' {",
|
|
543
|
-
' namespace JSX {',
|
|
544
|
-
...elementInterfaces,
|
|
545
|
-
' interface IntrinsicElements {',
|
|
546
|
-
...intrinsicEntries,
|
|
547
|
-
' }',
|
|
548
|
-
' }',
|
|
549
|
-
'}',
|
|
550
|
-
'',
|
|
551
|
-
'export {};',
|
|
552
|
-
'',
|
|
553
|
-
].join('\n');
|
|
554
|
-
}
|
|
555
|
-
function fileExists(path) {
|
|
556
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
557
|
-
try {
|
|
558
|
-
yield (0, promises_1.stat)(path);
|
|
559
|
-
return true;
|
|
560
|
-
}
|
|
561
|
-
catch (_a) {
|
|
562
|
-
return false;
|
|
563
|
-
}
|
|
564
|
-
});
|
|
565
|
-
}
|
|
566
|
-
function addCanonicalReferenceFromValue(value, state) {
|
|
567
|
-
if (!value || typeof value !== 'object') {
|
|
568
|
-
return;
|
|
569
|
-
}
|
|
570
|
-
if (Array.isArray(value)) {
|
|
571
|
-
for (const item of value) {
|
|
572
|
-
addCanonicalReferenceFromValue(item, state);
|
|
573
|
-
}
|
|
574
|
-
return;
|
|
575
|
-
}
|
|
576
|
-
const record = value;
|
|
577
|
-
const canonicalReference = record.canonicalReference;
|
|
578
|
-
if (typeof canonicalReference === 'string') {
|
|
579
|
-
const match = canonicalReference.match(/^(@[^!]+)!([^:]+):/);
|
|
580
|
-
if (match) {
|
|
581
|
-
const moduleSpecifier = match[1];
|
|
582
|
-
const identifier = match[2];
|
|
583
|
-
if (identifier && /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(identifier)) {
|
|
584
|
-
registerTypeImport(state, identifier, moduleSpecifier);
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
for (const nestedValue of Object.values(record)) {
|
|
589
|
-
if (nestedValue && typeof nestedValue === 'object') {
|
|
590
|
-
addCanonicalReferenceFromValue(nestedValue, state);
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
function parseImportsFromDtsContent(content, state) {
|
|
595
|
-
var _a, _b, _c;
|
|
596
|
-
const importOrExportBlockRegex = /(?:import|export)\s+(?:type\s+)?\{([^}]+)\}\s+from\s+['"]([^'"]+)['"]/g;
|
|
597
|
-
for (const match of content.matchAll(importOrExportBlockRegex)) {
|
|
598
|
-
const importList = (_a = match[1]) !== null && _a !== void 0 ? _a : '';
|
|
599
|
-
const moduleSpecifier = (_b = match[2]) !== null && _b !== void 0 ? _b : '';
|
|
600
|
-
if (!isBareModuleSpecifier(moduleSpecifier))
|
|
601
|
-
continue;
|
|
602
|
-
for (const entryRaw of importList.split(',')) {
|
|
603
|
-
const entry = entryRaw.trim();
|
|
604
|
-
if (!entry)
|
|
605
|
-
continue;
|
|
606
|
-
const aliasMatch = entry.match(/^([A-Za-z_$][A-Za-z0-9_$]*)\s+as\s+([A-Za-z_$][A-Za-z0-9_$]*)$/);
|
|
607
|
-
if (aliasMatch) {
|
|
608
|
-
registerTypeImport(state, aliasMatch[2], moduleSpecifier);
|
|
609
|
-
continue;
|
|
610
|
-
}
|
|
611
|
-
if (/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(entry)) {
|
|
612
|
-
registerTypeImport(state, entry, moduleSpecifier);
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
const exportAllRegex = /export\s+\*\s+from\s+['"]([^'"]+)['"]/g;
|
|
617
|
-
for (const match of content.matchAll(exportAllRegex)) {
|
|
618
|
-
const moduleSpecifier = (_c = match[1]) !== null && _c !== void 0 ? _c : '';
|
|
619
|
-
if (!isBareModuleSpecifier(moduleSpecifier))
|
|
620
|
-
continue;
|
|
621
|
-
state.wildcardExportModules.add(moduleSpecifier);
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
function collectFilesRecursively(rootDirectory, isTargetFile) {
|
|
625
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
626
|
-
const files = [];
|
|
627
|
-
const queue = [rootDirectory];
|
|
628
|
-
while (queue.length) {
|
|
629
|
-
const currentDirectory = queue.pop();
|
|
630
|
-
const entries = yield (0, promises_1.readdir)(currentDirectory, { withFileTypes: true });
|
|
631
|
-
for (const entry of entries) {
|
|
632
|
-
const fullPath = (0, node_path_1.resolve)(currentDirectory, entry.name);
|
|
633
|
-
if (entry.isDirectory()) {
|
|
634
|
-
queue.push(fullPath);
|
|
635
|
-
}
|
|
636
|
-
else if (entry.isFile() && isTargetFile(entry.name)) {
|
|
637
|
-
files.push(fullPath);
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
return files;
|
|
642
|
-
});
|
|
643
|
-
}
|
|
644
|
-
function collectTypeMetadataFiles(distDirectory) {
|
|
645
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
646
|
-
const [apiJsonFiles, dtsFiles] = yield Promise.all([
|
|
647
|
-
collectFilesRecursively(distDirectory, (fileName) => fileName.endsWith('.api.json')),
|
|
648
|
-
collectFilesRecursively(distDirectory, (fileName) => fileName.endsWith('.d.ts')),
|
|
649
|
-
]);
|
|
650
|
-
return { apiJsonFiles, dtsFiles };
|
|
651
|
-
});
|
|
652
|
-
}
|
|
653
|
-
function parseApiJsonFiles(filePaths, state) {
|
|
654
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
655
|
-
for (const filePath of filePaths) {
|
|
656
|
-
const apiJson = JSON.parse(yield (0, promises_1.readFile)(filePath, 'utf8'));
|
|
657
|
-
addCanonicalReferenceFromValue(apiJson, state);
|
|
658
|
-
}
|
|
659
|
-
});
|
|
660
|
-
}
|
|
661
|
-
function parseDtsFiles(filePaths, state) {
|
|
662
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
663
|
-
for (const filePath of filePaths) {
|
|
664
|
-
const dtsContent = yield (0, promises_1.readFile)(filePath, 'utf8');
|
|
665
|
-
parseImportsFromDtsContent(dtsContent, state);
|
|
666
|
-
}
|
|
667
|
-
});
|
|
668
|
-
}
|
|
669
|
-
function mergeTypeImportStateInto(targetState, sourceState) {
|
|
670
|
-
for (const ambiguousIdentifier of sourceState.ambiguousIdentifiers) {
|
|
671
|
-
targetState.importsByIdentifier.delete(ambiguousIdentifier);
|
|
672
|
-
targetState.ambiguousIdentifiers.add(ambiguousIdentifier);
|
|
673
|
-
}
|
|
674
|
-
for (const [identifier, moduleSpecifier] of sourceState.importsByIdentifier) {
|
|
675
|
-
registerTypeImport(targetState, identifier, moduleSpecifier);
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
function findWorkspaceRoot(startDirectory) {
|
|
679
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
680
|
-
let currentDirectory = startDirectory;
|
|
681
|
-
while (true) {
|
|
682
|
-
const hasPackagesDirectory = yield fileExists((0, node_path_1.resolve)(currentDirectory, 'packages'));
|
|
683
|
-
const hasRootPackageJson = yield fileExists((0, node_path_1.resolve)(currentDirectory, 'package.json'));
|
|
684
|
-
if (hasPackagesDirectory && hasRootPackageJson) {
|
|
685
|
-
return currentDirectory;
|
|
686
|
-
}
|
|
687
|
-
const parentDirectory = (0, node_path_1.dirname)(currentDirectory);
|
|
688
|
-
if (parentDirectory === currentDirectory) {
|
|
689
|
-
return startDirectory;
|
|
690
|
-
}
|
|
691
|
-
currentDirectory = parentDirectory;
|
|
692
|
-
}
|
|
693
|
-
});
|
|
694
|
-
}
|
|
695
|
-
function getWorkspacePackageDirectoryByName(workspaceRoot, packageName) {
|
|
696
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
697
|
-
const packagesDirectory = (0, node_path_1.resolve)(workspaceRoot, 'packages');
|
|
698
|
-
if (!(yield fileExists(packagesDirectory))) {
|
|
699
|
-
return undefined;
|
|
700
|
-
}
|
|
701
|
-
const packageJsonFiles = yield collectFilesRecursively(packagesDirectory, (fileName) => fileName === 'package.json');
|
|
702
|
-
for (const packageJsonPath of packageJsonFiles) {
|
|
703
|
-
const packageJson = JSON.parse(yield (0, promises_1.readFile)(packageJsonPath, 'utf8'));
|
|
704
|
-
if (packageJson.name === packageName) {
|
|
705
|
-
return (0, node_path_1.dirname)(packageJsonPath);
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
return undefined;
|
|
709
|
-
});
|
|
710
|
-
}
|
|
711
|
-
function enrichFromWorkspaceWildcardExports(cwd, state) {
|
|
712
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
713
|
-
const workspaceRoot = yield findWorkspaceRoot(cwd);
|
|
714
|
-
const processedModules = new Set();
|
|
715
|
-
const modulesToProcess = [...state.wildcardExportModules].filter((moduleSpecifier) => moduleSpecifier.startsWith('@genesislcap/'));
|
|
716
|
-
while (modulesToProcess.length) {
|
|
717
|
-
const moduleSpecifier = modulesToProcess.pop();
|
|
718
|
-
if (processedModules.has(moduleSpecifier)) {
|
|
719
|
-
continue;
|
|
720
|
-
}
|
|
721
|
-
processedModules.add(moduleSpecifier);
|
|
722
|
-
const packageDirectory = yield getWorkspacePackageDirectoryByName(workspaceRoot, moduleSpecifier);
|
|
723
|
-
if (!packageDirectory) {
|
|
724
|
-
continue;
|
|
725
|
-
}
|
|
726
|
-
const distDirectory = (0, node_path_1.resolve)(packageDirectory, 'dist');
|
|
727
|
-
if (!(yield fileExists(distDirectory))) {
|
|
728
|
-
continue;
|
|
729
|
-
}
|
|
730
|
-
const referencedState = createTypeImportState();
|
|
731
|
-
const { apiJsonFiles, dtsFiles } = yield collectTypeMetadataFiles(distDirectory);
|
|
732
|
-
yield parseApiJsonFiles(apiJsonFiles, referencedState);
|
|
733
|
-
yield parseDtsFiles(dtsFiles, referencedState);
|
|
734
|
-
mergeTypeImportStateInto(state, referencedState);
|
|
735
|
-
for (const exportedModule of referencedState.wildcardExportModules) {
|
|
736
|
-
if (exportedModule.startsWith('@genesislcap/') && !processedModules.has(exportedModule)) {
|
|
737
|
-
modulesToProcess.push(exportedModule);
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
});
|
|
742
|
-
}
|
|
743
|
-
function buildTypeImportState(cwd) {
|
|
744
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
745
|
-
const state = createTypeImportState();
|
|
746
|
-
const distDirectory = (0, node_path_1.resolve)(cwd, 'dist');
|
|
747
|
-
if (!(yield fileExists(distDirectory))) {
|
|
748
|
-
return state;
|
|
749
|
-
}
|
|
750
|
-
const { apiJsonFiles, dtsFiles } = yield collectTypeMetadataFiles(distDirectory);
|
|
751
|
-
yield parseApiJsonFiles(apiJsonFiles, state);
|
|
752
|
-
yield parseDtsFiles(dtsFiles, state);
|
|
753
|
-
yield enrichFromWorkspaceWildcardExports(cwd, state);
|
|
754
|
-
return state;
|
|
755
|
-
});
|
|
756
|
-
}
|
|
757
|
-
function ensureReferenceInTypesFile(filePath, reactJsxRuntimePath) {
|
|
758
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
759
|
-
if (!(yield fileExists(filePath))) {
|
|
760
|
-
return;
|
|
761
|
-
}
|
|
762
|
-
const relativeReferencePath = (0, node_path_1.relative)((0, node_path_1.dirname)(filePath), reactJsxRuntimePath).replace(/\\/g, '/');
|
|
763
|
-
const normalizedReferencePath = relativeReferencePath.startsWith('.')
|
|
764
|
-
? relativeReferencePath
|
|
765
|
-
: `./${relativeReferencePath}`;
|
|
766
|
-
const referenceLine = `/// <reference path="${normalizedReferencePath}" />`;
|
|
767
|
-
const existingContent = yield (0, promises_1.readFile)(filePath, 'utf8');
|
|
768
|
-
if (!existingContent.includes(referenceLine)) {
|
|
769
|
-
yield (0, promises_1.writeFile)(filePath, `${referenceLine}\n${existingContent}`, 'utf8');
|
|
770
|
-
}
|
|
771
|
-
});
|
|
772
|
-
}
|
|
773
|
-
function generateReactJsxTypes(cwd) {
|
|
774
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
775
|
-
const packageJsonPath = (0, node_path_1.resolve)(cwd, 'package.json');
|
|
776
|
-
if (!(yield fileExists(packageJsonPath))) {
|
|
777
|
-
return { generated: false, reason: 'No package.json found.' };
|
|
778
|
-
}
|
|
779
|
-
const packageJson = JSON.parse(yield (0, promises_1.readFile)(packageJsonPath, 'utf8'));
|
|
780
|
-
const manifestPath = getCEMManifestPath(cwd, packageJson);
|
|
781
|
-
if (!(yield fileExists(manifestPath))) {
|
|
782
|
-
return { generated: false, reason: 'No custom elements manifest found.' };
|
|
783
|
-
}
|
|
784
|
-
const manifest = JSON.parse(yield (0, promises_1.readFile)(manifestPath, 'utf8'));
|
|
785
|
-
const declarations = collectCustomElements(manifest);
|
|
786
|
-
if (!declarations.length) {
|
|
787
|
-
return { generated: false, reason: 'No custom elements discovered in manifest.' };
|
|
788
|
-
}
|
|
789
|
-
const resolvedDeclarations = yield mergeFastInheritanceFromManifest(cwd, declarations);
|
|
790
|
-
const dtsRoot = (0, node_path_1.resolve)(cwd, 'dist/dts');
|
|
791
|
-
const outputPath = (0, node_path_1.resolve)(dtsRoot, GENERATED_FILE_NAME);
|
|
792
|
-
yield (0, promises_1.mkdir)((0, node_path_1.dirname)(outputPath), { recursive: true });
|
|
793
|
-
const packageName = typeof packageJson.name === 'string' ? packageJson.name : 'unknown-package';
|
|
794
|
-
const typeImportState = yield buildTypeImportState(cwd);
|
|
795
|
-
const content = generateDeclarations(packageName, resolvedDeclarations, typeImportState);
|
|
796
|
-
yield (0, promises_1.writeFile)(outputPath, content, 'utf8');
|
|
797
|
-
const candidateTypesPaths = new Set([(0, node_path_1.resolve)(cwd, 'dist/dts/index.d.ts')]);
|
|
798
|
-
if (typeof packageJson.types === 'string' && packageJson.types.endsWith('.d.ts')) {
|
|
799
|
-
candidateTypesPaths.add((0, node_path_1.resolve)(cwd, packageJson.types));
|
|
800
|
-
}
|
|
801
|
-
for (const typesPath of candidateTypesPaths) {
|
|
802
|
-
yield ensureReferenceInTypesFile(typesPath, outputPath);
|
|
803
|
-
}
|
|
804
|
-
return { generated: true, path: outputPath };
|
|
805
|
-
});
|
|
806
|
-
}
|