@knapsack/renderer-react 4.71.19--canary.5222.d399d3c.0 → 4.71.19--canary.5325.d5f1abb.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. package/dist/analyze/infer-spec.test.d.ts +2 -0
  2. package/dist/analyze/infer-spec.test.d.ts.map +1 -0
  3. package/dist/analyze/infer-spec.test.js +112 -0
  4. package/dist/analyze/infer-spec.test.js.map +1 -0
  5. package/dist/analyze/mui.test.d.ts +2 -0
  6. package/dist/analyze/mui.test.d.ts.map +1 -0
  7. package/dist/analyze/mui.test.js +60 -0
  8. package/dist/analyze/mui.test.js.map +1 -0
  9. package/dist/analyze/pkg-basic.test.d.ts +2 -0
  10. package/dist/analyze/pkg-basic.test.d.ts.map +1 -0
  11. package/dist/analyze/pkg-basic.test.js +33 -0
  12. package/dist/analyze/pkg-basic.test.js.map +1 -0
  13. package/dist/analyze/pkg-diff-types.test.d.ts +2 -0
  14. package/dist/analyze/pkg-diff-types.test.d.ts.map +1 -0
  15. package/dist/analyze/pkg-diff-types.test.js +43 -0
  16. package/dist/analyze/pkg-diff-types.test.js.map +1 -0
  17. package/dist/renderer-react.d.ts.map +1 -1
  18. package/dist/renderer-react.js +8 -9
  19. package/dist/renderer-react.js.map +1 -1
  20. package/package.json +14 -16
  21. package/dist/analyze/index.d.mts +0 -2
  22. package/dist/analyze/index.d.mts.map +0 -1
  23. package/dist/analyze/index.mjs +0 -2
  24. package/dist/analyze/index.mjs.map +0 -1
  25. package/dist/analyze/infer-spec-fixtures/components.d.ts +0 -99
  26. package/dist/analyze/infer-spec-fixtures/components.d.ts.map +0 -1
  27. package/dist/analyze/infer-spec-fixtures/components.js +0 -59
  28. package/dist/analyze/infer-spec-fixtures/components.js.map +0 -1
  29. package/dist/analyze/infer-spec-fixtures/index.d.mts +0 -2
  30. package/dist/analyze/infer-spec-fixtures/index.d.mts.map +0 -1
  31. package/dist/analyze/infer-spec-fixtures/index.mjs +0 -2
  32. package/dist/analyze/infer-spec-fixtures/index.mjs.map +0 -1
  33. package/dist/analyze/infer-spec.d.mts +0 -27
  34. package/dist/analyze/infer-spec.d.mts.map +0 -1
  35. package/dist/analyze/infer-spec.mjs +0 -98
  36. package/dist/analyze/infer-spec.mjs.map +0 -1
  37. package/dist/analyze/infer-spec.test.d.mts +0 -2
  38. package/dist/analyze/infer-spec.test.d.mts.map +0 -1
  39. package/dist/analyze/infer-spec.test.mjs +0 -217
  40. package/dist/analyze/infer-spec.test.mjs.map +0 -1
  41. package/dist/analyze/mui.test.d.mts +0 -2
  42. package/dist/analyze/mui.test.d.mts.map +0 -1
  43. package/dist/analyze/mui.test.mjs +0 -88
  44. package/dist/analyze/mui.test.mjs.map +0 -1
  45. package/dist/analyze/pkg-basic.test.d.mts +0 -2
  46. package/dist/analyze/pkg-basic.test.d.mts.map +0 -1
  47. package/dist/analyze/pkg-basic.test.mjs +0 -28
  48. package/dist/analyze/pkg-basic.test.mjs.map +0 -1
  49. package/dist/analyze/pkg-diff-types.test.d.mts +0 -2
  50. package/dist/analyze/pkg-diff-types.test.d.mts.map +0 -1
  51. package/dist/analyze/pkg-diff-types.test.mjs +0 -29
  52. package/dist/analyze/pkg-diff-types.test.mjs.map +0 -1
  53. package/dist/analyze/utils/importer.d.mts +0 -17
  54. package/dist/analyze/utils/importer.d.mts.map +0 -1
  55. package/dist/analyze/utils/importer.mjs +0 -80
  56. package/dist/analyze/utils/importer.mjs.map +0 -1
  57. package/dist/analyze/utils/react-component-analyzer.d.mts +0 -24
  58. package/dist/analyze/utils/react-component-analyzer.d.mts.map +0 -1
  59. package/dist/analyze/utils/react-component-analyzer.mjs +0 -154
  60. package/dist/analyze/utils/react-component-analyzer.mjs.map +0 -1
  61. package/turbo.json +0 -9
  62. /package/{.eslintrc.cjs → .eslintrc.js} +0 -0
@@ -1,59 +0,0 @@
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.CounterComponent = exports.ListComponent = exports.OnlyPropTypesComponent = exports.TitleComponent = exports.RenderPropsComponent = exports.ComplexComponent = exports.Button = void 0;
7
- const jsx_runtime_1 = require("react/jsx-runtime");
8
- const react_1 = __importDefault(require("react"));
9
- const prop_types_1 = __importDefault(require("prop-types"));
10
- const Button = ({ variant, size, disabled, onClick, status, type, tabIndex, role, children, }) => ((0, jsx_runtime_1.jsx)("button", { onClick: onClick, disabled: disabled, type: "button", tabIndex: tabIndex, role: role, children: children || 'Click me' }));
11
- exports.Button = Button;
12
- const ComplexComponent = ({ users, config, }) => ((0, jsx_runtime_1.jsx)("div", { children: users.map((user) => ((0, jsx_runtime_1.jsx)("div", { children: user.name }, user.id))) }));
13
- exports.ComplexComponent = ComplexComponent;
14
- const RenderPropsComponent = ({ renderHeader, renderContent, footer, }) => ((0, jsx_runtime_1.jsxs)("div", { children: [renderHeader(), renderContent({ count: 0 }), footer] }));
15
- exports.RenderPropsComponent = RenderPropsComponent;
16
- const TitleComponent = ({ title, subtitle, }) => ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("h1", { children: title }), subtitle && (0, jsx_runtime_1.jsx)("h2", { children: subtitle })] }));
17
- exports.TitleComponent = TitleComponent;
18
- exports.TitleComponent.propTypes = {
19
- title: prop_types_1.default.string.isRequired,
20
- subtitle: prop_types_1.default.string,
21
- };
22
- // Example with only PropTypes
23
- const OnlyPropTypesComponent = ({ title }) => ((0, jsx_runtime_1.jsx)("div", { children: title }));
24
- exports.OnlyPropTypesComponent = OnlyPropTypesComponent;
25
- exports.OnlyPropTypesComponent.propTypes = {
26
- title: prop_types_1.default.string.isRequired,
27
- };
28
- const ListComponent = ({ items, renderItem, }) => ((0, jsx_runtime_1.jsx)("ul", { children: items.map((item, index) => ((0, jsx_runtime_1.jsx)("li", { children: renderItem(item) }, JSON.stringify(item)))) }));
29
- exports.ListComponent = ListComponent;
30
- class CounterComponent extends react_1.default.Component {
31
- constructor({ initialCount, variant }) {
32
- super({ initialCount, variant });
33
- this.handleIncrement = () => {
34
- const { step = 1 } = this.props;
35
- this.setState((prevState) => ({
36
- count: prevState.count + step,
37
- }));
38
- };
39
- this.handleDecrement = () => {
40
- const { step = 1 } = this.props;
41
- this.setState((prevState) => ({
42
- count: prevState.count - step,
43
- }));
44
- };
45
- this.state = {
46
- count: initialCount,
47
- };
48
- }
49
- render() {
50
- const { label, variant } = this.props;
51
- const { count } = this.state;
52
- return ((0, jsx_runtime_1.jsxs)("div", { children: [label && (0, jsx_runtime_1.jsx)("span", { children: label }), (0, jsx_runtime_1.jsx)("button", { type: "button", onClick: this.handleDecrement, children: "-" }), (0, jsx_runtime_1.jsx)("span", { children: count }), (0, jsx_runtime_1.jsx)("button", { type: "button", onClick: this.handleIncrement, children: "+" })] }));
53
- }
54
- }
55
- exports.CounterComponent = CounterComponent;
56
- CounterComponent.defaultProps = {
57
- step: 1,
58
- };
59
- //# sourceMappingURL=components.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"components.js","sourceRoot":"","sources":["../../../src/analyze/infer-spec-fixtures/components.tsx"],"names":[],"mappings":";;;;;;;AAAA,kDAAyC;AACzC,4DAAmC;AA2B5B,MAAM,MAAM,GAAG,CAAC,EACrB,OAAO,EACP,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,MAAM,EACN,IAAI,EACJ,QAAQ,EACR,IAAI,EACJ,QAAQ,GACI,EAAe,EAAE,CAAC,CAC9B,mCACE,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAC,QAAQ,EACb,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,IAAI,YAET,QAAQ,IAAI,UAAU,GAChB,CACV,CAAC;AApBW,QAAA,MAAM,UAoBjB;AAiBK,MAAM,gBAAgB,GAAG,CAAC,EAC/B,KAAK,EACL,MAAM,GACO,EAAe,EAAE,CAAC,CAC/B,0CACG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,E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,AAFkB,CAEjB"}
@@ -1,2 +0,0 @@
1
- export { Button, ComplexComponent, RenderPropsComponent, TitleComponent, OnlyPropTypesComponent, ListComponent, CounterComponent, } from './components.js';
2
- //# sourceMappingURL=index.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/analyze/infer-spec-fixtures/index.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,gBAAgB,EAChB,oBAAoB,EACpB,cAAc,EACd,sBAAsB,EACtB,aAAa,EACb,gBAAgB,GACjB,MAAM,iBAAiB,CAAC"}
@@ -1,2 +0,0 @@
1
- export { Button, ComplexComponent, RenderPropsComponent, TitleComponent, OnlyPropTypesComponent, ListComponent, CounterComponent, } from './components.js';
2
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/analyze/infer-spec-fixtures/index.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,gBAAgB,EAChB,oBAAoB,EACpB,cAAc,EACd,sBAAsB,EACtB,aAAa,EACb,gBAAgB,GACjB,MAAM,iBAAiB,CAAC"}
@@ -1,27 +0,0 @@
1
- export declare function inferSpec({ path, namedExport, resolveFrom, pkgPathAliases, }: {
2
- path: string;
3
- namedExport?: string;
4
- resolveFrom?: string;
5
- pkgPathAliases?: Record<string, string>;
6
- }): Promise<{
7
- ksTemplateSpec: {
8
- isInferred: true;
9
- hidePropsTable: true;
10
- hideSlotsTable: true;
11
- extraDocs: {
12
- id: string;
13
- title: string;
14
- description?: string;
15
- tableRows?: {
16
- [columnTitle: string]: string;
17
- }[];
18
- }[];
19
- props: import("@knapsack/types").JsonSchemaObject;
20
- slots: {
21
- [name: string]: import("@knapsack/types").KsSlotInfo;
22
- };
23
- };
24
- props: import("./utils/react-component-analyzer.mjs").ComponentProps;
25
- slots: import("./utils/react-component-analyzer.mjs").SlotInfo[];
26
- }>;
27
- //# sourceMappingURL=infer-spec.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"infer-spec.d.mts","sourceRoot":"","sources":["../../src/analyze/infer-spec.mts"],"names":[],"mappings":"AAIA,wBAAsB,SAAS,CAAC,EAC9B,IAAI,EACJ,WAAW,EACX,WAA2B,EAC3B,cAAc,GACf,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACzC;;;;;;;;;;;;;;;;;;;;GAwGA"}
@@ -1,98 +0,0 @@
1
- import { convertToSpec } from '@knapsack/spec-utils';
2
- import { analyzeComponent } from './utils/react-component-analyzer.mjs';
3
- export async function inferSpec({ path, namedExport, resolveFrom = process.cwd(), pkgPathAliases, }) {
4
- const { props: componentProps, slots: componentSlots } = await analyzeComponent({
5
- fileName: path,
6
- exportName: namedExport,
7
- pkgPathAliases,
8
- resolveFromDir: resolveFrom,
9
- });
10
- const props = {
11
- $schema: 'http://json-schema.org/draft-07/schema',
12
- type: 'object',
13
- required: [],
14
- properties: {},
15
- };
16
- const slots = componentSlots.reduce((acc, slot) => {
17
- acc[slot.title] = slot;
18
- return acc;
19
- }, {});
20
- const extraDocs = [];
21
- // @TODO: Add overview table for react renderer
22
- // https://linear.app/knapsack/issue/KSP-5870/update-react-renderer-api-docs-to-include-overview
23
- // Path is currently the full path to the file, we need to get the package name from the path
24
- // // Add component overview
25
- // extraDocs.push({
26
- // id: 'overview',
27
- // title: 'Overview',
28
- // description: '',
29
- // tableRows: [
30
- // {
31
- // Title: 'Package',
32
- // Description: `\`${path}\``,
33
- // },
34
- // {
35
- // Title: 'Named Export',
36
- // Description: `\`${namedExport}\``,
37
- // },
38
- // ],
39
- // });
40
- // Process props
41
- const propsTableRows = [];
42
- Object.entries(componentProps).forEach(([propName, propDetails]) => {
43
- const { required, typeInfo: propTypeInfo } = propDetails;
44
- if (propTypeInfo) {
45
- const { prop } = convertToSpec({
46
- typeInfo: propTypeInfo,
47
- trustRequiredProps: false,
48
- });
49
- if (prop) {
50
- props.properties[propName] = prop;
51
- if (propDetails.description) {
52
- props.properties[propName].description = propDetails.description;
53
- }
54
- if (required) {
55
- props.required.push(propName);
56
- }
57
- }
58
- propsTableRows.push({
59
- 'Prop Name': `\`${propName}\``,
60
- Type: `\`${propTypeInfo.tsRawType || propTypeInfo.type || 'unknown'}\``,
61
- Required: required ? 'Yes' : 'No',
62
- Description: propDetails.description || '',
63
- });
64
- }
65
- });
66
- if (propsTableRows.length) {
67
- extraDocs.push({
68
- id: 'props',
69
- title: 'Props',
70
- description: '',
71
- tableRows: propsTableRows,
72
- });
73
- }
74
- if (Object.keys(slots).length) {
75
- extraDocs.push({
76
- id: 'slots',
77
- title: 'Slots',
78
- description: '',
79
- tableRows: Object.entries(slots).map(([slotName, slot]) => ({
80
- 'Slot Name': `\`${slotName}\``,
81
- 'Slot Title': slot.title,
82
- })),
83
- });
84
- }
85
- return {
86
- ksTemplateSpec: {
87
- isInferred: true,
88
- hidePropsTable: true,
89
- hideSlotsTable: true,
90
- extraDocs,
91
- props,
92
- slots,
93
- },
94
- props: componentProps,
95
- slots: componentSlots,
96
- };
97
- }
98
- //# sourceMappingURL=infer-spec.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"infer-spec.mjs","sourceRoot":"","sources":["../../src/analyze/infer-spec.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAExE,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,EAC9B,IAAI,EACJ,WAAW,EACX,WAAW,GAAG,OAAO,CAAC,GAAG,EAAE,EAC3B,cAAc,GAMf;IACC,MAAM,EAAE,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,cAAc,EAAE,GACpD,MAAM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AO;QACL,cAAc,EAAE;YACd,UAAU,EAAE,IAAI;YAChB,cAAc,EAAE,IAAI;YACpB,cAAc,EAAE,IAAI;YACpB,SAAS;YACT,KAAK;YACL,KAAK;SACmB;QAC1B,KAAK,EAAE,cAAc;QACrB,KAAK,EAAE,cAAc;KACtB,CAAC;AACJ,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=infer-spec.test.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"infer-spec.test.d.mts","sourceRoot":"","sources":["../../src/analyze/infer-spec.test.mts"],"names":[],"mappings":""}
@@ -1,217 +0,0 @@
1
- import test from 'ava';
2
- import { isOptionsProp, isFunctionProp, isBooleanProp, isStringProp, } from '@knapsack/types';
3
- import { validateSpec } from '@knapsack/app/renderers';
4
- import { inferSpec } from './infer-spec.mjs';
5
- test('infer types in packages with different files name for types', async (t) => {
6
- const { ksTemplateSpec: spec } = await inferSpec({
7
- path: '@knapsack/sandbox-components/react',
8
- namedExport: 'Button',
9
- resolveFrom: import.meta.dirname,
10
- });
11
- if (!spec) {
12
- t.fail(`Spec could not be inferred`);
13
- return;
14
- }
15
- t.truthy(spec);
16
- t.deepEqual(Object.keys(spec.props.properties).sort(), ['label', 'mode', 'size', 'type'].sort());
17
- if (isOptionsProp(spec.props.properties.size)) {
18
- t.deepEqual(spec.props.properties.size.enum, ['small', 'medium', 'large']);
19
- }
20
- else {
21
- t.fail(`size prop should be an options prop`);
22
- }
23
- if (isOptionsProp(spec.props.properties.type)) {
24
- t.deepEqual(spec.props.properties.type.enum, ['filled', 'outlined']);
25
- }
26
- else {
27
- t.fail(`type prop should be an options prop`);
28
- }
29
- if (isOptionsProp(spec.props.properties.mode)) {
30
- t.deepEqual(spec.props.properties.mode.enum, [
31
- 'default',
32
- 'success',
33
- 'error',
34
- 'warning',
35
- ]);
36
- }
37
- else {
38
- t.fail(`mode prop should be an options prop`);
39
- }
40
- });
41
- test('infer types in packages from tsx files', async (t) => {
42
- const { ksTemplateSpec: spec } = await inferSpec({
43
- path: '@knapsack/renderer-react-components/src/test-fixtures/button.tsx',
44
- namedExport: 'Button',
45
- resolveFrom: import.meta.dirname,
46
- });
47
- t.truthy(spec);
48
- const { ok, message } = validateSpec(spec);
49
- t.log(message);
50
- t.is(ok, true, message);
51
- });
52
- test('inferDocs card.tsx with types', async (t) => {
53
- const { ksTemplateSpec: spec } = await inferSpec({
54
- path: '@knapsack/renderer-react-components/test-fixtures',
55
- namedExport: 'Card',
56
- resolveFrom: process.cwd(),
57
- });
58
- const expectedSpec = {
59
- props: {
60
- $schema: 'http://json-schema.org/draft-07/schema',
61
- type: 'object',
62
- required: ['cardBody', 'items'],
63
- properties: {
64
- textAlign: {
65
- type: 'string',
66
- enum: ['left', 'center', 'right'],
67
- },
68
- imgSrc: {
69
- type: 'string',
70
- },
71
- isDark: {
72
- type: 'boolean',
73
- // @todo We lost proper default value when the source switched from `.tsx` to being from a package, which results in analyzing a `.d.ts` files... which doesn't have default values.
74
- // default: true,
75
- },
76
- cardTitle: {
77
- type: 'string',
78
- },
79
- cardSubTitle: {
80
- type: 'string',
81
- },
82
- cardBody: {
83
- type: 'string',
84
- },
85
- handleIt: {
86
- typeof: 'function',
87
- tsType: '(x: string) => boolean',
88
- },
89
- items: {
90
- tsType: '{ id: string; title: string; description?: string;}[]',
91
- },
92
- },
93
- },
94
- slots: {
95
- children: {
96
- description: 'Goes in footer',
97
- title: 'children',
98
- },
99
- header: {
100
- title: 'header',
101
- },
102
- },
103
- };
104
- if (!spec) {
105
- t.fail('Spec could not be inferred');
106
- return;
107
- }
108
- const { ok, message } = validateSpec(spec);
109
- t.log(message);
110
- t.is(ok, true, message);
111
- const { handleIt } = spec.props.properties;
112
- t.truthy(handleIt);
113
- if (isFunctionProp(handleIt)) {
114
- t.is(handleIt.tsType, '(x: string) => boolean');
115
- }
116
- else {
117
- t.fail('handleIt should be a function prop');
118
- }
119
- t.like(spec, expectedSpec);
120
- });
121
- test('infer types for Knapsack Avatar', async (t) => {
122
- const { ksTemplateSpec: spec } = await inferSpec({
123
- path: '@knapsack/toby',
124
- namedExport: 'Avatar',
125
- resolveFrom: process.cwd(),
126
- });
127
- const { label } = spec.props.properties;
128
- t.truthy(label);
129
- if (isStringProp(label)) {
130
- t.is(label.type, 'string', 'label should be a string');
131
- }
132
- else {
133
- t.fail('label should be a string');
134
- }
135
- const { ok, message } = validateSpec(spec);
136
- t.log(message);
137
- t.is(ok, true, message);
138
- });
139
- test('infer types for Knapsack SchemaForm', async (t) => {
140
- const { ksTemplateSpec: spec } = await inferSpec({
141
- path: '@knapsack/toby/schema-form',
142
- namedExport: 'SchemaForm',
143
- resolveFrom: process.cwd(),
144
- });
145
- const { submitLabel } = spec.props.properties;
146
- t.truthy(submitLabel);
147
- if (isStringProp(submitLabel)) {
148
- t.is(submitLabel.type, 'string', 'submitLabel should be a string');
149
- }
150
- else {
151
- t.fail('submitLabel should be a string');
152
- }
153
- const { ok, message } = validateSpec(spec);
154
- t.log(message);
155
- t.is(ok, true, message);
156
- });
157
- test('infer types for Modal', async (t) => {
158
- const { ksTemplateSpec: spec } = await inferSpec({
159
- path: '@knapsack/toby',
160
- namedExport: 'Modal',
161
- resolveFrom: process.cwd(),
162
- });
163
- const { instantOpen } = spec.props.properties;
164
- t.truthy(instantOpen);
165
- if (isBooleanProp(instantOpen)) {
166
- t.is(instantOpen.type, 'boolean', 'instantOpen should be a boolean');
167
- }
168
- else {
169
- t.fail('instantOpen should be a boolean');
170
- }
171
- const { ok, message } = validateSpec(spec);
172
- t.is(ok, true, message);
173
- });
174
- test('infer types for Collapse', async (t) => {
175
- const { ksTemplateSpec: spec } = await inferSpec({
176
- path: '@knapsack/toby',
177
- namedExport: 'Collapse',
178
- resolveFrom: process.cwd(),
179
- });
180
- const { depth } = spec.props.properties;
181
- t.truthy(depth);
182
- if (isOptionsProp(depth)) {
183
- t.deepEqual(depth.enum, [1, 2, 3, 4]);
184
- }
185
- else {
186
- t.fail('depth should be an options prop');
187
- }
188
- const { ok, message } = validateSpec(spec);
189
- t.is(ok, true, message);
190
- });
191
- test.only('infer types for Panel', async (t) => {
192
- const { ksTemplateSpec: spec } = await inferSpec({
193
- path: '@knapsack/toby',
194
- namedExport: 'Panel',
195
- resolveFrom: process.cwd(),
196
- });
197
- const { size } = spec.props.properties;
198
- if (isOptionsProp(size)) {
199
- t.deepEqual(size.enum, ['default', 'narrow', 'wide']);
200
- }
201
- else {
202
- t.fail('size should be an options prop');
203
- }
204
- // ensure that tabs isn't inadvertently included in the slots
205
- if ('tabs' in spec.slots) {
206
- t.fail('tabs should not be in the slots');
207
- }
208
- if ('title' in spec.slots) {
209
- t.pass('title should be in the slots');
210
- }
211
- if ('children' in spec.props.properties) {
212
- t.fail('children should not be in the props');
213
- }
214
- const { ok, message } = validateSpec(spec);
215
- t.is(ok, true, message);
216
- });
217
- //# sourceMappingURL=infer-spec.test.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"infer-spec.test.mjs","sourceRoot":"","sources":["../../src/analyze/infer-spec.test.mts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,KAAK,CAAC;AACvB,OAAO,EACL,aAAa,EACb,cAAc,EAEd,aAAa,EACb,YAAY,GACb,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,IAAI,CAAC,6DAA6D,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IAC9E,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE,GAAG,MAAM,SAAS,CAAC;QAC/C,IAAI,EAAE,oCAAoC;QAC1C,WAAW,EAAE,QAAQ;QACrB,WAAW,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO;KACjC,CAAC,CAAC;IACH,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,CAAC,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;QACrC,OAAO;IACT,C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,CAAC,CAAC;IAC5C,CAAC;IACD,IAAI,OAAO,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;QAC1B,CAAC,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;IACzC,CAAC;IAED,IAAI,UAAU,IAAI,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC;QACxC,CAAC,CAAC,IAAI,CAAC,qCAAqC,CAAC,CAAC;IAChD,CAAC;IAED,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;IAC3C,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AAC1B,CAAC,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=mui.test.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mui.test.d.mts","sourceRoot":"","sources":["../../src/analyze/mui.test.mts"],"names":[],"mappings":""}
@@ -1,88 +0,0 @@
1
- import test from 'ava';
2
- import { isStringProp, isOptionsProp, isNumberProp, isBooleanProp, } from '@knapsack/types';
3
- import { validateSpec } from '@knapsack/app/renderers';
4
- import { inferSpec } from './infer-spec.mjs';
5
- test('MUI strings with extra quotes', async (t) => {
6
- const { ksTemplateSpec: spec } = await inferSpec({
7
- path: '@mui/x-data-grid',
8
- namedExport: 'DataGrid',
9
- resolveFrom: process.cwd(),
10
- });
11
- if (!spec) {
12
- t.fail('Could not infer spec');
13
- return;
14
- }
15
- Object.entries(spec.props.properties).forEach(([propName, prop]) => {
16
- if (isStringProp(prop) || isOptionsProp(prop)) {
17
- if (typeof prop.default === 'string') {
18
- t.true(!prop.default.startsWith('"') && !prop.default.endsWith('"'), `prop "${propName}" has a default that should not be quoted: ${prop.default} - ${JSON.stringify(prop)}`);
19
- }
20
- }
21
- if (isOptionsProp(prop)) {
22
- if (prop.default) {
23
- t.true(prop.enum.includes(prop.default), `For prop "${propName}", the default value "${prop.default}" is not in the enum: ${prop.enum}`);
24
- }
25
- prop.enum.forEach((option) => {
26
- t.true(typeof option === 'string' &&
27
- !option.startsWith('"') &&
28
- !option.endsWith('"'), `option should not be quoted: ${option}`);
29
- });
30
- }
31
- if (isNumberProp(prop) && prop.default) {
32
- const ok = t.is(typeof prop.default, 'number', `prop "${propName}" default should be a number: ${prop.default}`);
33
- if (!ok) {
34
- t.log(prop);
35
- }
36
- }
37
- if (isBooleanProp(prop) && prop.default) {
38
- const ok = t.is(typeof prop.default, 'boolean', `prop "${propName}" should be a boolean: ${prop.default}`);
39
- if (!ok) {
40
- t.log(prop);
41
- }
42
- }
43
- });
44
- const { ok, message } = validateSpec(spec);
45
- t.log(message);
46
- t.is(ok, true, message);
47
- });
48
- test('infer types for MUI Button', async (t) => {
49
- const { ksTemplateSpec: spec } = await inferSpec({
50
- path: '@mui/material',
51
- namedExport: 'Button',
52
- resolveFrom: process.cwd(),
53
- });
54
- if (!spec) {
55
- t.fail('Could not infer spec');
56
- return;
57
- }
58
- const isDisabled = spec.props.properties.disabled;
59
- if (!isDisabled) {
60
- t.fail('Could not find disabled prop');
61
- }
62
- t.is(isDisabled.type, 'boolean', 'disabled prop should be a boolean');
63
- });
64
- test('infer types for MUI RadioGroup', async (t) => {
65
- const { ksTemplateSpec: spec } = await inferSpec({
66
- path: '@mui/material',
67
- namedExport: 'RadioGroup',
68
- resolveFrom: process.cwd(),
69
- });
70
- if (!spec) {
71
- t.fail('Could not infer spec');
72
- return;
73
- }
74
- const { className } = spec.props.properties;
75
- if (!className) {
76
- t.fail('Could not find className prop');
77
- }
78
- if (isStringProp(className)) {
79
- t.is(className.type, 'string', 'className prop should be a string');
80
- }
81
- else {
82
- t.fail('className prop should be a string');
83
- }
84
- const { ok, message } = validateSpec(spec);
85
- t.log(message);
86
- t.is(ok, true, message);
87
- });
88
- //# sourceMappingURL=mui.test.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mui.test.mjs","sourceRoot":"","sources":["../../src/analyze/mui.test.m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;QACf,CAAC,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAC;IAC1C,CAAC;IAED,IAAI,YAAY,CAAC,SAAS,CAAC,EAAE,CAAC;QAC5B,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,QAAQ,EAAE,mCAAmC,CAAC,CAAC;IACtE,CAAC;SAAM,CAAC;QACN,CAAC,CAAC,IAAI,CAAC,mCAAmC,CAAC,CAAC;IAC9C,CAAC;IAED,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;IAC3C,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACf,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AAC1B,CAAC,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=pkg-basic.test.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pkg-basic.test.d.mts","sourceRoot":"","sources":["../../src/analyze/pkg-basic.test.mts"],"names":[],"mappings":""}
@@ -1,28 +0,0 @@
1
- import test from 'ava';
2
- import { isStringProp, isOptionsProp } from '@knapsack/types';
3
- import { inferSpec } from './infer-spec.mjs';
4
- test('infer types in basic packages', async (t) => {
5
- const { ksTemplateSpec: spec } = await inferSpec({
6
- path: '@knapsack/renderer-react-components/test-fixtures',
7
- namedExport: 'Button',
8
- resolveFrom: import.meta.dirname,
9
- });
10
- if (!spec) {
11
- t.fail(`Spec could not be inferred`);
12
- return;
13
- }
14
- t.deepEqual(Object.keys(spec.props.properties).sort(), ['size', 'text'].sort());
15
- if (!isStringProp(spec.props.properties.text)) {
16
- t.log(spec.props.properties.text);
17
- t.fail(`text prop should be a string`);
18
- return;
19
- }
20
- if (!isOptionsProp(spec.props.properties.size)) {
21
- t.log(spec.props.properties.size);
22
- t.fail(`size prop should be an options prop`);
23
- return;
24
- }
25
- t.deepEqual(spec.props.properties.size.enum, ['small', 'medium', 'large']);
26
- t.is(spec.slots.children.title, 'children', `Should detect "children" slot`);
27
- });
28
- //# sourceMappingURL=pkg-basic.test.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pkg-basic.test.mjs","sourceRoot":"","sources":["../../src/analyze/pkg-basic.test.mts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,KAAK,CAAC;AACvB,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,IAAI,CAAC,+BAA+B,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IAChD,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE,GAAG,MAAM,SAAS,CAAC;QAC/C,IAAI,EAAE,mDAAmD;QACzD,WAAW,EAAE,QAAQ;QACrB,WAAW,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO;KACjC,CAAC,CAAC;IACH,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,CAAC,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;QACrC,OAAO;IACT,CAAC;IACD,CAAC,CAAC,SAAS,CACT,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI,EAAE,EACzC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,CACxB,CAAC;IACF,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9C,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAClC,CAAC,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;QACvC,OAAO;IACT,CAAC;IACD,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QAC/C,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAClC,CAAC,CAAC,IAAI,CAAC,qCAAqC,CAAC,CAAC;QAC9C,OAAO;IACT,CAAC;IACD,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;IAC3E,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,UAAU,EAAE,+BAA+B,CAAC,CAAC;AAC/E,CAAC,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=pkg-diff-types.test.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pkg-diff-types.test.d.mts","sourceRoot":"","sources":["../../src/analyze/pkg-diff-types.test.mts"],"names":[],"mappings":""}
@@ -1,29 +0,0 @@
1
- import test from 'ava';
2
- import { isOptionsProp, isStringProp } from '@knapsack/types';
3
- import { inferSpec } from './infer-spec.mjs';
4
- test('infer types in packages with different files name for types', async (t) => {
5
- const { ksTemplateSpec: spec } = await inferSpec({
6
- path: '@knapsack/renderer-react-components/test-fixtures',
7
- namedExport: 'Button',
8
- resolveFrom: import.meta.dirname,
9
- });
10
- if (!spec) {
11
- t.fail(`Spec could not be inferred`);
12
- return;
13
- }
14
- t.truthy(spec);
15
- t.deepEqual(Object.keys(spec.props.properties).sort(), ['size', 'text'].sort());
16
- if (!isStringProp(spec.props.properties.text)) {
17
- t.log(spec.props.properties.text);
18
- t.fail(`text prop should be a string`);
19
- return;
20
- }
21
- if (!isOptionsProp(spec.props.properties.size)) {
22
- t.log(spec.props.properties.size);
23
- t.fail(`size prop should be an options prop`);
24
- return;
25
- }
26
- t.deepEqual(spec.props.properties.size.enum, ['small', 'medium', 'large']);
27
- t.is(spec.slots.children.title, 'children', `Should detect "children" slot`);
28
- });
29
- //# sourceMappingURL=pkg-diff-types.test.mjs.map