@knapsack/renderer-react 4.71.17--canary.5251.cc77be8.0 → 4.71.17--canary.5261.959b319.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/ava.config.cjs +7 -1
  3. package/dist/analyze/infer-spec.test.d.ts +2 -0
  4. package/dist/analyze/infer-spec.test.d.ts.map +1 -0
  5. package/dist/analyze/infer-spec.test.js +112 -0
  6. package/dist/analyze/infer-spec.test.js.map +1 -0
  7. package/dist/analyze/mui.test.d.ts +2 -0
  8. package/dist/analyze/mui.test.d.ts.map +1 -0
  9. package/dist/analyze/mui.test.js +60 -0
  10. package/dist/analyze/mui.test.js.map +1 -0
  11. package/dist/analyze/pkg-basic.test.d.ts +2 -0
  12. package/dist/analyze/pkg-basic.test.d.ts.map +1 -0
  13. package/dist/analyze/pkg-basic.test.js +33 -0
  14. package/dist/analyze/pkg-basic.test.js.map +1 -0
  15. package/dist/analyze/pkg-diff-types.test.d.ts +2 -0
  16. package/dist/analyze/pkg-diff-types.test.d.ts.map +1 -0
  17. package/dist/analyze/pkg-diff-types.test.js +43 -0
  18. package/dist/analyze/pkg-diff-types.test.js.map +1 -0
  19. package/dist/client/init.d.mts +2 -2
  20. package/dist/client/init.d.mts.map +1 -0
  21. package/dist/client/init.mjs +39 -3
  22. package/dist/client/init.mjs.map +1 -1
  23. package/dist/index.d.ts +3 -45
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +16 -31
  26. package/dist/index.js.map +1 -1
  27. package/dist/react-creators.d.ts +20 -0
  28. package/dist/react-creators.d.ts.map +1 -0
  29. package/dist/react-creators.js +170 -0
  30. package/dist/react-creators.js.map +1 -0
  31. package/dist/{index.d.mts → renderer-react.d.ts} +2 -5
  32. package/dist/renderer-react.d.ts.map +1 -0
  33. package/dist/renderer-react.js +569 -0
  34. package/dist/renderer-react.js.map +1 -0
  35. package/dist/types.d.ts +19 -0
  36. package/dist/types.d.ts.map +1 -0
  37. package/dist/types.js +5 -0
  38. package/dist/types.js.map +1 -0
  39. package/dist/utils.d.ts +28 -0
  40. package/dist/utils.d.ts.map +1 -0
  41. package/dist/utils.js +500 -0
  42. package/dist/utils.js.map +1 -0
  43. package/dist/utils.test.d.ts +2 -0
  44. package/dist/utils.test.d.ts.map +1 -0
  45. package/dist/utils.test.js +59 -0
  46. package/dist/utils.test.js.map +1 -0
  47. package/package.json +23 -27
  48. package/prototype-template.d.mts +3 -0
  49. package/prototype-template.mjs +3 -0
  50. package/test-fixtures/pkg-diff-types/button.js +10 -0
  51. package/test-fixtures/pkg-diff-types/package.json +4 -0
  52. package/test-fixtures/pkg-diff-types/readme.md +1 -0
  53. package/test-fixtures/pkg-diff-types/types/button.d.ts +5 -0
  54. package/tsconfig.json +2 -2
  55. package/dist/client/init.d.ts +0 -2
  56. package/dist/client/init.js +0 -5
  57. package/dist/client/init.js.map +0 -1
  58. package/dist/demo-wrapper.d.mts +0 -7
  59. package/dist/demo-wrapper.d.ts +0 -7
  60. package/dist/demo-wrapper.js +0 -2
  61. package/dist/demo-wrapper.js.map +0 -1
  62. package/dist/demo-wrapper.mjs +0 -2
  63. package/dist/demo-wrapper.mjs.map +0 -1
  64. package/dist/error-catcher.d.mts +0 -20
  65. package/dist/error-catcher.d.ts +0 -20
  66. package/dist/error-catcher.js +0 -2
  67. package/dist/error-catcher.js.map +0 -1
  68. package/dist/error-catcher.mjs +0 -2
  69. package/dist/error-catcher.mjs.map +0 -1
  70. package/dist/index.mjs +0 -33
  71. package/dist/index.mjs.map +0 -1
  72. package/dist/prototype-template.d.mts +0 -7
  73. package/dist/prototype-template.d.ts +0 -7
  74. package/dist/prototype-template.js +0 -2
  75. package/dist/prototype-template.js.map +0 -1
  76. package/dist/prototype-template.mjs +0 -2
  77. package/dist/prototype-template.mjs.map +0 -1
  78. package/dist/types-CivTHEEo.d.mts +0 -10
  79. package/dist/types-CivTHEEo.d.ts +0 -10
  80. package/tsup.config.cjs +0 -5
@@ -0,0 +1,28 @@
1
+ import { KsTemplateSpec } from '@knapsack/types';
2
+ type GetSpecParams = {
3
+ src: string;
4
+ exportName?: string;
5
+ };
6
+ export declare const demoAppName = "DemoApp";
7
+ export declare function getUsage(data: {
8
+ templateName: string;
9
+ props?: Record<string, unknown>;
10
+ children?: string;
11
+ extraProps?: {
12
+ key: string;
13
+ value: string;
14
+ }[];
15
+ format?: boolean;
16
+ }): Promise<string>;
17
+ export declare function getDemoAppUsage({ children, imports, format, }: {
18
+ children: string;
19
+ imports?: string;
20
+ format?: boolean;
21
+ }): Promise<string>;
22
+ export declare const clearInferSpecCache: () => void;
23
+ export declare function getReactDocs(opt: GetSpecParams & {
24
+ resolveFromDir: string;
25
+ }): Promise<KsTemplateSpec | false>;
26
+ export declare function copyReactAssets(distDirAbsolute: string, publicPath: string): Promise<string[]>;
27
+ export {};
28
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,cAAc,EAA+B,MAAM,iBAAiB,CAAC;AAE9E,KAAK,aAAa,GAAG;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAmEF,eAAO,MAAM,WAAW,YAAY,CAAC;AAmBrC,wBAAsB,QAAQ,CAAC,IAAI,EAAE;IACnC,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE;QACX,GAAG,EAAE,MAAM,CAAC;QACZ,KAAK,EAAE,MAAM,CAAC;KACf,EAAE,CAAC;IACJ,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,GAAG,OAAO,CAAC,MAAM,CAAC,CAyDlB;AAED,wBAAsB,eAAe,CAAC,EACpC,QAAQ,EACR,OAAO,EACP,MAAM,GACP,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,GAAG,OAAO,CAAC,MAAM,CAAC,CAUlB;AAuZD,eAAO,MAAM,mBAAmB,YAG/B,CAAC;AAuCF,wBAAsB,YAAY,CAChC,GAAG,EAAE,aAAa,GAAG;IACnB,cAAc,EAAE,MAAM,CAAC;CACxB,GACA,OAAO,CAAC,cAAc,GAAG,KAAK,CAAC,CAIjC;AAED,wBAAsB,eAAe,CACnC,eAAe,EAAE,MAAM,EACvB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,MAAM,EAAE,CAAC,CA2DnB"}
package/dist/utils.js ADDED
@@ -0,0 +1,500 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.clearInferSpecCache = exports.demoAppName = void 0;
7
+ exports.getUsage = getUsage;
8
+ exports.getDemoAppUsage = getDemoAppUsage;
9
+ exports.getReactDocs = getReactDocs;
10
+ exports.copyReactAssets = copyReactAssets;
11
+ const app_1 = require("@knapsack/app");
12
+ const file_utils_1 = require("@knapsack/file-utils");
13
+ const utils_1 = require("@knapsack/utils");
14
+ const path_1 = __importDefault(require("path"));
15
+ const types_1 = require("@knapsack/types");
16
+ function renderUsageTemplate({ templateName, attributes, children, }) {
17
+ return `
18
+ <${templateName}
19
+ ${attributes}
20
+ ${children
21
+ ? `>
22
+ ${children}
23
+ </${templateName}>`
24
+ : '/>'}
25
+ `;
26
+ }
27
+ exports.demoAppName = 'DemoApp';
28
+ function renderDemoAppTemplate({ imports = '', children, }) {
29
+ return `${imports}
30
+
31
+ function ${exports.demoAppName}() {
32
+ return (
33
+ ${children}
34
+ )
35
+ }
36
+ `;
37
+ }
38
+ async function getUsage(data) {
39
+ const props = Object.keys(data.props || {}).map((key) => {
40
+ const value = data.props[key];
41
+ return {
42
+ key,
43
+ value,
44
+ };
45
+ });
46
+ const { templateName, children, extraProps = [] } = data;
47
+ if (!templateName) {
48
+ throw new Error(`Cannot getUsage of a React Component when no "templateName" is provided.`);
49
+ }
50
+ const attributes = props.map(({ key, value }) => {
51
+ switch (typeof value) {
52
+ case 'string':
53
+ // Is this a function like `() => {}` but not a "sizes" attribute for an image like `(min-width: 400px) 50vw, 100vw`?
54
+ if (value.startsWith('(') && value.includes('=>')) {
55
+ return `${key}={${value}}`;
56
+ }
57
+ return `${key}="${value}"`;
58
+ case 'boolean':
59
+ return value ? `${key}` : `${key}={${value}}`;
60
+ default:
61
+ return `${key}={${JSON.stringify(value)}}`;
62
+ }
63
+ });
64
+ const extraAttributes = [];
65
+ const slotProps = {};
66
+ extraProps.forEach(({ key, value }) => {
67
+ var _a;
68
+ slotProps[key] = (_a = slotProps[key]) !== null && _a !== void 0 ? _a : [];
69
+ slotProps[key].push(value);
70
+ });
71
+ Object.entries(slotProps).forEach(([key, values]) => {
72
+ const value = values.length === 1 ? values[0] : `<>${values.join('\n')}</>`;
73
+ extraAttributes.push(`${key}={${value}}`);
74
+ });
75
+ const result = renderUsageTemplate({
76
+ templateName,
77
+ attributes: [...attributes, ...extraAttributes].join(' '),
78
+ children,
79
+ });
80
+ return data.format
81
+ ? (0, file_utils_1.formatCode)({
82
+ contents: result,
83
+ path: 'x.tsx', // doing this to set format language
84
+ })
85
+ .then((code) => code.trim())
86
+ .catch(() => result.trim()) // if format fails, just return the unformatted code
87
+ : result.trim();
88
+ }
89
+ async function getDemoAppUsage({ children, imports, format, }) {
90
+ const code = renderDemoAppTemplate({
91
+ children,
92
+ imports,
93
+ });
94
+ if (!format)
95
+ return code;
96
+ return (0, file_utils_1.formatCode)({
97
+ contents: code,
98
+ path: 'x.tsx', // doing this to set format language
99
+ });
100
+ }
101
+ async function getTypeScriptInfoFromFile({ src }) {
102
+ const tsConfigPath = await (0, file_utils_1.findUp)('tsconfig.json', {
103
+ cwd: path_1.default.dirname(src),
104
+ });
105
+ const rdTs = await import('react-docgen-typescript');
106
+ const config = {
107
+ shouldExtractLiteralValuesFromEnum: true,
108
+ savePropValueAsString: true,
109
+ skipChildrenPropWithoutDoc: false,
110
+ // In addition to the ones listed here, which had not strangely included these below ~ https://github.com/styleguidist/react-docgen-typescript/blob/287e7012843cb26fed8f4bd8ee24e462c25a1414/src/parser.ts#L308
111
+ customComponentTypes: ['VoidFunctionComponent', 'VFC'],
112
+ };
113
+ const parse = tsConfigPath
114
+ ? rdTs.withCustomConfig(tsConfigPath, config).parse
115
+ : rdTs.withDefaultConfig(config).parse;
116
+ return {
117
+ info: parse(src),
118
+ };
119
+ }
120
+ function extractSpecFromTypeScriptInfo({ info: results, exportName, }) {
121
+ try {
122
+ if (!results)
123
+ return false;
124
+ const spec = {
125
+ props: {
126
+ $schema: 'http://json-schema.org/draft-07/schema',
127
+ type: 'object',
128
+ required: [],
129
+ properties: {},
130
+ },
131
+ slots: {
132
+ // children: {
133
+ // title: 'children',
134
+ // },
135
+ },
136
+ };
137
+ const isDefaultExport = !exportName || exportName === 'default';
138
+ // if `isDefaultExport` then we just grab last result since `export default` TENDS to be last. that'll we can do really...
139
+ const result = isDefaultExport
140
+ ? results.at(-1)
141
+ : results.find((r) => r.displayName === exportName);
142
+ // log.inspect({ result, isDefaultExport, exportName }, 'ts result');
143
+ if (!result)
144
+ return false;
145
+ const { displayName } = result;
146
+ // log.inspect({ result }, 'result');
147
+ Object.entries((result === null || result === void 0 ? void 0 : result.props) || {}).forEach(([propName, propDef]) => {
148
+ var _a, _b, _c, _d, _e;
149
+ const { name, description, defaultValue, required, type, parent } = propDef;
150
+ // `type.name` can include `| undefined` if tsConfig has `strict: true`. So we need to handle these scenarios:
151
+ // `string` or `string | undefined`
152
+ // `'left' | 'right'` or `'left' | 'right' | undefined`
153
+ const propType = (_a = type === null || type === void 0 ? void 0 : type.name) === null || _a === void 0 ? void 0 : _a.replace('| undefined', '').replace(/<.*/g, '').trim();
154
+ switch (propType) {
155
+ case 'string':
156
+ spec.props.properties[propName] = {
157
+ type: 'string',
158
+ };
159
+ break;
160
+ case 'number':
161
+ spec.props.properties[propName] = {
162
+ type: 'number',
163
+ };
164
+ break;
165
+ case 'boolean':
166
+ case 'bool':
167
+ if (defaultValue && 'value' in defaultValue) {
168
+ // comes in as `'true'` - this turns it to `true`
169
+ defaultValue.value = defaultValue.value === 'true';
170
+ }
171
+ spec.props.properties[propName] = {
172
+ type: 'boolean',
173
+ };
174
+ break;
175
+ case 'enum':
176
+ spec.props.properties[propName] = {
177
+ type: 'string',
178
+ // yes there is a double "value" & yes it is confusing
179
+ enum: [
180
+ // ensure list is unique
181
+ ...new Set(type.value.flatMap(({ value }) => {
182
+ if (!value)
183
+ return [];
184
+ const item = (0, utils_1.removeWrappingDoubleQuotes)(value.trim());
185
+ if (item === 'undefined') {
186
+ return [];
187
+ }
188
+ return [item];
189
+ })),
190
+ ],
191
+ };
192
+ break;
193
+ case 'ReactNode':
194
+ case 'React.ReactNode':
195
+ case 'React.ReactElement':
196
+ case 'ReactElement':
197
+ spec.slots[propName] = {
198
+ title: propName,
199
+ };
200
+ if (description) {
201
+ spec.slots[propName] = {
202
+ ...spec.slots[propName],
203
+ description,
204
+ };
205
+ }
206
+ break;
207
+ case 'VFC':
208
+ case 'FC':
209
+ spec.slots[propName] = {
210
+ title: propName,
211
+ description: description || 'A reference to a component',
212
+ isTemplateReference: true,
213
+ allowOnlyOne: true,
214
+ disallowText: true,
215
+ };
216
+ break;
217
+ default: {
218
+ if ((_b = type === null || type === void 0 ? void 0 : type.name) === null || _b === void 0 ? void 0 : _b.startsWith('(')) {
219
+ // functions
220
+ spec.props.properties[propName] = {
221
+ // description: `\`${type.name}\` ${description}`,
222
+ typeof: 'function',
223
+ tsType: (_c = propDef === null || propDef === void 0 ? void 0 : propDef.type) === null || _c === void 0 ? void 0 : _c.name,
224
+ };
225
+ }
226
+ else if ((_d = type === null || type === void 0 ? void 0 : type.name) === null || _d === void 0 ? void 0 : _d.includes('|')) {
227
+ // enums / unions (multi-choice strings)
228
+ // comes in like this: `{ name: '"option1" | "option2" | "option3"' }`
229
+ const options = type.name.split('|').flatMap((enumItem) => {
230
+ if (!enumItem)
231
+ return [];
232
+ const item = (0, utils_1.removeWrappingDoubleQuotes)(enumItem.trim());
233
+ if (item === 'undefined') {
234
+ return [];
235
+ }
236
+ return [item];
237
+ });
238
+ if (options === null || options === void 0 ? void 0 : options.length) {
239
+ spec.props.properties[propName] = {
240
+ type: 'string',
241
+ // ensuring list is unique
242
+ enum: [...new Set(options)],
243
+ };
244
+ }
245
+ }
246
+ else {
247
+ spec.props.properties[propName] = {
248
+ tsType: (_e = propDef === null || propDef === void 0 ? void 0 : propDef.type) === null || _e === void 0 ? void 0 : _e.name,
249
+ };
250
+ }
251
+ }
252
+ }
253
+ // assigning info that all would have
254
+ if (spec.props.properties[propName]) {
255
+ if (required)
256
+ spec.props.required.push(propName);
257
+ if (description && !spec.props.properties[propName].description) {
258
+ spec.props.properties[propName].description = description;
259
+ }
260
+ if (defaultValue && 'value' in defaultValue) {
261
+ if ((0, types_1.isNumberProp)(spec.props.properties[propName])) {
262
+ spec.props.properties[propName].default = parseFloat(defaultValue.value);
263
+ }
264
+ else {
265
+ spec.props.properties[propName].default =
266
+ (0, utils_1.removeWrappingDoubleQuotes)(defaultValue.value);
267
+ }
268
+ }
269
+ }
270
+ // console.log('type', type);
271
+ });
272
+ return spec;
273
+ }
274
+ catch (error) {
275
+ app_1.log.verbose('Could not infer spec from React TypeScript file', {
276
+ exportName,
277
+ error,
278
+ }, 'react renderer');
279
+ return false;
280
+ }
281
+ }
282
+ async function getPropTypesInfoFromFile({ src }) {
283
+ const reactDocs = await import('react-docgen');
284
+ const { builtinResolvers } = reactDocs;
285
+ const fileSrc = await (0, file_utils_1.readFile)(src);
286
+ const { FindExportedDefinitionsResolver } = builtinResolvers;
287
+ const results = reactDocs.parse(fileSrc, {
288
+ resolver: new FindExportedDefinitionsResolver(),
289
+ handlers: null,
290
+ filename: src,
291
+ // babelrc: false,
292
+ });
293
+ return {
294
+ info: results,
295
+ };
296
+ }
297
+ function extractSpecFromPropTypesInfo({ info: results, exportName, }) {
298
+ try {
299
+ const isDefaultExport = !exportName || exportName === 'default';
300
+ // if `isDefaultExport` then we just grab last result since `export default` TENDS to be last. that'll we can do really...
301
+ const result = isDefaultExport
302
+ ? results.pop()
303
+ : results.find((r) => r.displayName === exportName);
304
+ // log.inspect(results, 'JSX PropTypes Results');
305
+ // console.log(JSON.stringify(result, null, ' '));
306
+ const spec = {
307
+ isInferred: true,
308
+ props: {
309
+ $schema: 'http://json-schema.org/draft-07/schema',
310
+ type: 'object',
311
+ required: [],
312
+ properties: {},
313
+ },
314
+ slots: {},
315
+ };
316
+ Object.entries((result === null || result === void 0 ? void 0 : result.props) || {}).forEach(([propName, propDef]) => {
317
+ var _a;
318
+ const { required, description, defaultValue } = propDef;
319
+ switch ((_a = propDef === null || propDef === void 0 ? void 0 : propDef.type) === null || _a === void 0 ? void 0 : _a.name) {
320
+ case 'string':
321
+ spec.props.properties[propName] = {
322
+ type: 'string',
323
+ };
324
+ break;
325
+ case 'func':
326
+ spec.props.properties[propName] = {
327
+ type: 'string',
328
+ };
329
+ break;
330
+ case 'bool':
331
+ spec.props.properties[propName] = {
332
+ type: 'boolean',
333
+ };
334
+ break;
335
+ case 'node':
336
+ spec.slots[propName] = {
337
+ title: propName,
338
+ description,
339
+ };
340
+ }
341
+ // assigning info that all would have
342
+ if (spec.props.properties[propName]) {
343
+ if (required)
344
+ spec.props.required.push(propName);
345
+ if (description && !spec.props.properties[propName].description) {
346
+ spec.props.properties[propName].description = description;
347
+ }
348
+ if (defaultValue && 'value' in defaultValue) {
349
+ spec.props.properties[propName].default =
350
+ typeof defaultValue.value === 'string'
351
+ ? (0, utils_1.removeWrappingDoubleQuotes)(defaultValue.value)
352
+ : defaultValue.value;
353
+ }
354
+ }
355
+ });
356
+ return spec;
357
+ }
358
+ catch (error) {
359
+ app_1.log.verbose('Could not infer spec from React PropTypes', {
360
+ exportName,
361
+ error,
362
+ }, 'react renderer');
363
+ return false;
364
+ }
365
+ }
366
+ function cleanUpSpec({ spec, }) {
367
+ var _a;
368
+ if (spec === false)
369
+ return spec;
370
+ // ok to mutate b/c spec was just created before passing in here
371
+ Object.entries(((_a = spec === null || spec === void 0 ? void 0 : spec.props) === null || _a === void 0 ? void 0 : _a.properties) || {}).forEach(([propName, prop]) => {
372
+ if ((0, types_1.isOptionsProp)(prop)) {
373
+ // If the default is not in the enum, it should not be there
374
+ // OR the enum is wrong
375
+ if (!prop.enum.includes(prop.default)) {
376
+ prop.default = undefined;
377
+ }
378
+ }
379
+ });
380
+ return spec;
381
+ }
382
+ async function getReactModuleInfoUncached({ src: unknownSrc, resolveFromDir, }) {
383
+ const typesInfo = await (0, file_utils_1.resolvePath)({
384
+ path: unknownSrc,
385
+ resolveFromDir,
386
+ resolveType: 'types',
387
+ });
388
+ if (typesInfo.exists) {
389
+ const typeScriptInfo = await getTypeScriptInfoFromFile({
390
+ src: typesInfo.absolutePath,
391
+ });
392
+ if (typeScriptInfo) {
393
+ return {
394
+ type: 'typescript',
395
+ info: typeScriptInfo.info,
396
+ };
397
+ }
398
+ }
399
+ const jsInfo = await (0, file_utils_1.resolvePath)({
400
+ path: unknownSrc,
401
+ resolveFromDir,
402
+ });
403
+ if (!jsInfo.exists)
404
+ return { type: 'unknown' };
405
+ const { ext } = path_1.default.parse(jsInfo.absolutePath);
406
+ switch (ext) {
407
+ case '.jsx': {
408
+ const propTypesInfo = await getPropTypesInfoFromFile({
409
+ src: jsInfo.absolutePath,
410
+ });
411
+ return {
412
+ type: 'propTypes',
413
+ info: propTypesInfo.info,
414
+ };
415
+ }
416
+ case '.ts':
417
+ case '.tsx': {
418
+ const typeScriptInfo = await getTypeScriptInfoFromFile({
419
+ src: jsInfo.absolutePath,
420
+ });
421
+ return {
422
+ type: 'typescript',
423
+ info: typeScriptInfo.info,
424
+ };
425
+ }
426
+ default:
427
+ return {
428
+ type: 'unknown',
429
+ };
430
+ }
431
+ }
432
+ const getReactModuleInfoCache = new Map();
433
+ const clearInferSpecCache = () => {
434
+ app_1.log.info(`Clearing React TypeScript inferSpec cache...`);
435
+ getReactModuleInfoCache.clear();
436
+ };
437
+ exports.clearInferSpecCache = clearInferSpecCache;
438
+ async function getReactModuleInfo(args) {
439
+ const cacheKey = JSON.stringify(args);
440
+ if (!getReactModuleInfoCache.has(cacheKey)) {
441
+ getReactModuleInfoCache.set(cacheKey, getReactModuleInfoUncached(args));
442
+ }
443
+ return getReactModuleInfoCache.get(cacheKey);
444
+ }
445
+ async function getReactSpec({ src, exportName, resolveFromDir, }) {
446
+ const reactModuleInfo = await getReactModuleInfo({
447
+ src,
448
+ resolveFromDir,
449
+ });
450
+ switch (reactModuleInfo.type) {
451
+ case 'typescript':
452
+ return extractSpecFromTypeScriptInfo({
453
+ info: reactModuleInfo.info,
454
+ exportName,
455
+ });
456
+ case 'propTypes':
457
+ return extractSpecFromPropTypesInfo({
458
+ info: reactModuleInfo.info,
459
+ exportName,
460
+ });
461
+ case 'unknown':
462
+ default:
463
+ return false;
464
+ }
465
+ }
466
+ async function getReactDocs(opt) {
467
+ return cleanUpSpec({
468
+ spec: await getReactSpec(opt),
469
+ });
470
+ }
471
+ async function copyReactAssets(distDirAbsolute, publicPath) {
472
+ try {
473
+ const { version: reactVersion } = (0, file_utils_1.getModulePkgJson)('react');
474
+ const { version: reactDomVersion } = (0, file_utils_1.getModulePkgJson)('react-dom');
475
+ // switch to resolving the root NPM package dir vs the entire file via require.resolve
476
+ // workaround due to NPM packages using the exports field; prevents these from being auto-resolved
477
+ const reactRoot = path_1.default.dirname(require.resolve('react', {
478
+ paths: [process.cwd()],
479
+ }));
480
+ const reactDomRoot = path_1.default.dirname(require.resolve('react-dom', {
481
+ paths: [process.cwd()],
482
+ }));
483
+ await Promise.all([
484
+ (0, file_utils_1.copy)(path_1.default.join(reactRoot, 'umd/react.development.js'), path_1.default.join(distDirAbsolute, `react.development.${reactVersion}.js`)),
485
+ (0, file_utils_1.copy)(path_1.default.join(reactRoot, 'umd/react.production.min.js'), path_1.default.join(distDirAbsolute, `react.production.min.${reactVersion}.js`)),
486
+ (0, file_utils_1.copy)(path_1.default.join(reactDomRoot, 'umd/react-dom.production.min.js'), path_1.default.join(distDirAbsolute, `react-dom.production.min.${reactDomVersion}.js`)),
487
+ (0, file_utils_1.copy)(path_1.default.join(reactDomRoot, 'umd/react-dom.development.js'), path_1.default.join(distDirAbsolute, `react-dom.development.${reactDomVersion}.js`)),
488
+ ]);
489
+ const reactFileSuffix = process.env.NODE_ENV === 'production' ? 'production.min' : 'development';
490
+ return [
491
+ path_1.default.join(publicPath, `react.${reactFileSuffix}.${reactVersion}.js`),
492
+ path_1.default.join(publicPath, `react-dom.${reactFileSuffix}.${reactDomVersion}.js`),
493
+ ];
494
+ }
495
+ catch (error) {
496
+ app_1.log.warn('Error trying to copy "react" and "react-dom" JS files, are they installed? We want to use your exact versions.', error, 'templateRenderer:react');
497
+ process.exit(1);
498
+ }
499
+ }
500
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;AA2GA,4BAkEC;AAED,0CAkBC;AAicD,oCAQC;AAED,0CA8DC;AA1sBD,uCAAoC;AACpC,qDAO8B;AAC9B,2CAA6D;AAC7D,gDAAwB;AAMxB,2CAA8E;AAmD9E,SAAS,mBAAmB,CAAC,EAC3B,YAAY,EACZ,UAAU,EACV,QAAQ,GAKT;IACC,OAAO;OACF,YAAY;QACX,UAAU;QAEV,QAAQ;QACN,CAAC,CAAC;UACF,QAAQ;UACR,YAAY,GAAG;QACf,CAAC,CAAC,IACN;GACH,CAAC;AACJ,CAAC;AACY,QAAA,WAAW,GAAG,SAAS,CAAC;AAErC,SAAS,qBAAqB,CAAC,EAC7B,OAAO,GAAG,EAAE,EACZ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,iCAAiC,CAAC,EAC1D,cAAI,CAAC,IAAI,CACP,eAAe,EACf,4BAA4B,eAAe,KAAK,CACjD,CACF;YACD,IAAA,iBAAI,EACF,cAAI,CAAC,IAAI,CAAC,YAAY,EAAE,8BAA8B,CAAC,EACvD,cAAI,CAAC,IAAI,CACP,eAAe,EACf,yBAAyB,eAAe,KAAK,CAC9C,CACF;SACF,CAAC,CAAC;QACH,MAAM,eAAe,GACnB,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,aAAa,CAAC;QAE3E,OAAO;YACL,cAAI,CAAC,IAAI,CAAC,UAAU,EAAE,SAAS,eAAe,IAAI,YAAY,KAAK,CAAC;YACpE,cAAI,CAAC,IAAI,CACP,UAAU,EACV,aAAa,eAAe,IAAI,eAAe,KAAK,CACrD;SACF,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,SAAG,CAAC,IAAI,CACN,gHAAgH,EAChH,KAAK,EACL,wBAAwB,CACzB,CAAC;QACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=utils.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.test.d.ts","sourceRoot":"","sources":["../src/utils.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const ava_1 = __importDefault(require("ava"));
7
+ const utils_1 = require("./utils");
8
+ (0, ava_1.default)('renderer-react usage template a', async (t) => {
9
+ const actual = await (0, utils_1.getUsage)({
10
+ templateName: 'Button',
11
+ props: {
12
+ type: 'primary',
13
+ isDark: true,
14
+ data: [
15
+ {
16
+ first: 'John',
17
+ last: 'Doe',
18
+ },
19
+ {
20
+ first: 'Jane',
21
+ last: 'Doe',
22
+ },
23
+ ],
24
+ },
25
+ children: 'Some Text',
26
+ format: true,
27
+ });
28
+ t.snapshot(actual);
29
+ });
30
+ (0, ava_1.default)('renderer-react usage template b', async (t) => {
31
+ const actual = await (0, utils_1.getUsage)({
32
+ templateName: 'Button',
33
+ props: {
34
+ type: 'primary',
35
+ isDark: true,
36
+ },
37
+ children: 'Click me',
38
+ extraProps: [
39
+ {
40
+ key: 'icon',
41
+ value: '<Icon type="add" />',
42
+ },
43
+ {
44
+ key: 'handleClick',
45
+ value: '() => {console.log("Clicked!")}',
46
+ },
47
+ ],
48
+ format: true,
49
+ });
50
+ t.snapshot(actual);
51
+ });
52
+ (0, ava_1.default)('renderer-react usage template c', async (t) => {
53
+ const actual = await (0, utils_1.getUsage)({
54
+ templateName: 'Button',
55
+ format: true,
56
+ });
57
+ t.snapshot(actual);
58
+ });
59
+ //# sourceMappingURL=utils.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.test.js","sourceRoot":"","sources":["../src/utils.test.ts"],"names":[],"mappings":";;;;;AAAA,8CAAuB;AACvB,mCAAmC;AAEnC,IAAA,aAAI,EAAC,iCAAiC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IAClD,MAAM,MAAM,GAAG,MAAM,IAAA,gBAAQ,EAAC;QAC5B,YAAY,EAAE,QAAQ;QACtB,KAAK,EAAE;YACL,IAAI,EAAE,SAAS;YACf,MAAM,EAAE,IAAI;YACZ,IAAI,EAAE;gBACJ;oBACE,KAAK,EAAE,MAAM;oBACb,IAAI,EAAE,KAAK;iBACZ;gBACD;oBACE,KAAK,EAAE,MAAM;oBACb,IAAI,EAAE,KAAK;iBACZ;aACF;SACF;QACD,QAAQ,EAAE,WAAW;QACrB,MAAM,EAAE,IAAI;KACb,CAAC,CAAC;IAEH,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AACrB,CAAC,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