Skip to content

Commit cb7be32

Browse files
authored
chore: export types for using it in configuration files (#1733)
* chore: export types for using it in configuration files docs: add example for typed config * chore: run fmt * fix: wrong config comment
1 parent 4a79266 commit cb7be32

File tree

20 files changed

+65
-2
lines changed

20 files changed

+65
-2
lines changed

.changeset/proud-scissors-trade.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@builder.io/mitosis': patch
3+
---
4+
5+
[all] export `types.ts` to enable `@type` comment for JS like this: `/** @type {import('@builder.io/mitosis').ToReactOptions} */`

e2e/e2e-app/mitosis.config.cjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @type {import('@builder.io/mitosis'.MitosisConfig)}
2+
* @type {import('@builder.io/mitosis').MitosisConfig}
33
*/
44
module.exports = {
55
files: 'src/**',
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './generate';
2+
export * from './types';

packages/core/src/generators/angular/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -858,3 +858,5 @@ const tryFormat = (str: string, parser: string) => {
858858
}
859859
return str;
860860
};
861+
862+
export * from './types';
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './generator';
2+
export * from './types';
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './generator';
2+
export * from './types';
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './generator';
2+
export * from './types';
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './generate';
2+
export * from './types';
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './generate';
2+
export * from './types';
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './generator';
2+
export * from './types';

packages/core/src/generators/qwik/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export { addCommonStyles, addComponent, createFileSet } from './component';
22
export type { FileSet, QwikOptions } from './component';
33
export { componentToQwik } from './component-generator';
44
export { File } from './src-generator';
5+
export * from './types';

packages/core/src/generators/react-native/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,5 @@ export const componentToReactNative: TranspilerGenerator<Partial<ToReactNativeOp
293293

294294
return componentToReact({ ...options, type: 'native' })({ component: json, path });
295295
};
296+
297+
export * from './types';
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './generator';
2+
export * from './types';

packages/core/src/generators/solid/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,5 @@ export const componentToSolid: TranspilerGenerator<Partial<ToSolidOptions>> =
270270
}
271271
return str;
272272
};
273+
274+
export * from './types';
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './component';
2+
export * from './types';
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export { componentToSvelte } from './svelte';
2+
export * from './types';
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './generator';
2+
export * from './types';
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './generator';
2+
export * from './types';
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './generator';
2+
export * from './types';

packages/docs/src/routes/docs/configuration/index.mdx

+39-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,45 @@ title: Configuration - Mitosis
66

77
## Mitosis Configuration
88

9-
In the root of the project, from which you run mitosis, you can add a `mitosis.config.js` file that will be read by Mitosis. You can also specify a config file by option: `--config=<file>`.
9+
In the root of the project, from which you run mitosis,
10+
you can add a `mitosis.config.js` file that will be read by Mitosis.
11+
You can also specify a config file by option: `--config=<file>`.
12+
An example might look like this:
13+
14+
````js react-options.cjs
15+
// react-options.cjs
16+
17+
/** @type {import('@builder.io/mitosis').ToReactOptions} */
18+
module.exports = {
19+
typescript: true
20+
};
21+
````
22+
23+
````js vue-options.cjs
24+
// vue-options.cjs
25+
26+
/** @type {import('@builder.io/mitosis').ToVueOptions} */
27+
module.exports = {
28+
typescript: true
29+
};
30+
````
31+
32+
````js mitosis-config.cjs
33+
// mitosis-config.cjs
34+
const react = require('./react-options.cjs');
35+
const vue = require('./vue-options.cjs');
36+
37+
/** @type {import('@builder.io/mitosis').MitosisConfig} */
38+
module.exports = {
39+
files: 'src/**',
40+
targets: ['vue', 'react'],
41+
options: {
42+
react,
43+
vue
44+
}
45+
};
46+
````
47+
1048

1149
The `mitosis.config.js` file uses the [MitosisConfig](https://github.com/BuilderIO/mitosis/blob/main/packages/core/src/types/config.ts#L22) type:
1250

0 commit comments

Comments
 (0)