@teambit/react 1.0.219 → 1.0.221

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.
Files changed (29) hide show
  1. package/dist/{preview-1712174136349.js → preview-1712287228511.js} +2 -2
  2. package/dist/react.env.js +0 -3
  3. package/dist/react.env.js.map +1 -1
  4. package/index.ts +12 -0
  5. package/package.json +30 -30
  6. package/react.api.transformer.ts +53 -0
  7. package/react.aspect.ts +7 -0
  8. package/react.env.ts +606 -0
  9. package/react.graphql.ts +52 -0
  10. package/react.main.runtime.ts +472 -0
  11. package/react.preview.runtime.ts +54 -0
  12. package/react.schema.ts +93 -0
  13. package/react.templates.ts +28 -0
  14. package/artifacts/env-template/public/310.8db029366a3258c07bf7.js +0 -998
  15. package/artifacts/env-template/public/359.0a1f1ff12be5124a0f7c.js +0 -255
  16. package/artifacts/env-template/public/700.f5fce5db582bd65bc0df.js +0 -216
  17. package/artifacts/env-template/public/851.d2664a57f5d46b636e5f.js +0 -41
  18. package/artifacts/env-template/public/assets-manifest.json +0 -58
  19. package/artifacts/env-template/public/compositions.5386e223afcf59d078da.js +0 -17
  20. package/artifacts/env-template/public/compositions.html +0 -2
  21. package/artifacts/env-template/public/overview.9ba07a416fd2c326c30d.js +0 -5
  22. package/artifacts/env-template/public/overview.html +0 -2
  23. package/artifacts/env-template/public/peers.b0b3d89b456852b4159a.js +0 -1
  24. package/artifacts/env-template/public/preview-root.93da260e5cd4522c90ed.js +0 -1
  25. package/artifacts/env-template/public/static/css/310.cdd78dee.css +0 -1
  26. package/artifacts/env-template/public/static/css/compositions.2a7f63f9.css +0 -1
  27. package/artifacts/env-template/public/static/css/preview-root.5fd7d59d.css +0 -1
  28. /package/{compositions-1712174136349.js → compositions-1712287228511.js} +0 -0
  29. /package/{overview-1712174136349.js → overview-1712287228511.js} +0 -0
package/react.env.ts ADDED
@@ -0,0 +1,606 @@
1
+ import ts, { TsConfigSourceFile } from 'typescript';
2
+ import { tmpdir } from 'os';
3
+ import { Component } from '@teambit/component';
4
+ import { ESLint as ESLintLib } from 'eslint';
5
+ import { ComponentUrl } from '@teambit/component.modules.component-url';
6
+ import { BuildTask, CAPSULE_ARTIFACTS_DIR } from '@teambit/builder';
7
+ import { merge, cloneDeep } from 'lodash';
8
+ import { Bundler, BundlerContext, DevServer, DevServerContext } from '@teambit/bundler';
9
+ import { COMPONENT_PREVIEW_STRATEGY_NAME, PreviewStrategyName } from '@teambit/preview';
10
+ import { PrettierConfigWriter, PrettierFormatter } from '@teambit/defender.prettier-formatter';
11
+ import {
12
+ PrettierConfigMutator,
13
+ PrettierConfigTransformContext,
14
+ PrettierConfigTransformer,
15
+ } from '@teambit/defender.prettier.config-mutator';
16
+ import { TypescriptConfigWriter } from '@teambit/typescript.typescript-compiler';
17
+ import { EslintConfigWriter, ESLintLinter } from '@teambit/defender.eslint-linter';
18
+ import type { ESLintOptions } from '@teambit/defender.eslint-linter';
19
+ import { CompilerMain } from '@teambit/compiler';
20
+ import {
21
+ BuilderEnv,
22
+ CompilerEnv,
23
+ DependenciesEnv,
24
+ DevEnv,
25
+ LinterEnv,
26
+ PackageEnv,
27
+ TesterEnv,
28
+ FormatterEnv,
29
+ PipeServiceModifier,
30
+ PipeServiceModifiersMap,
31
+ } from '@teambit/envs';
32
+ import { JestMain } from '@teambit/jest';
33
+ import { PackageJsonProps, PkgMain } from '@teambit/pkg';
34
+ import { Tester, TesterMain } from '@teambit/tester';
35
+ import { TsConfigTransformer, TypescriptMain } from '@teambit/typescript';
36
+ import type { TypeScriptCompilerOptions } from '@teambit/typescript';
37
+ import { WebpackConfigTransformer, WebpackMain } from '@teambit/webpack';
38
+ import { Workspace } from '@teambit/workspace';
39
+ import {
40
+ EslintConfigMutator,
41
+ EslintConfigTransformContext,
42
+ EslintConfigTransformer,
43
+ } from '@teambit/defender.eslint.config-mutator';
44
+ import { DependencyResolverMain } from '@teambit/dependency-resolver';
45
+ import { Linter, LinterContext } from '@teambit/linter';
46
+ import { Formatter, FormatterContext } from '@teambit/formatter';
47
+ import { pathNormalizeToLinux } from '@teambit/legacy/dist/utils';
48
+ import type { ComponentMeta } from '@teambit/react.ui.highlighter.component-metadata.bit-component-meta';
49
+ import { SchemaExtractor } from '@teambit/schema';
50
+ import { join, resolve } from 'path';
51
+ import { outputFileSync } from 'fs-extra';
52
+ import { Logger } from '@teambit/logger';
53
+ import { ConfigWriterEntry } from '@teambit/workspace-config-files';
54
+
55
+ // ensure reactEnv depends on compositions-app
56
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
57
+ import { CompositionsApp } from '@teambit/react.ui.compositions-app';
58
+ // ensure reactEnv depends on docs-app
59
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
60
+ import DocsApps from '@teambit/react.ui.docs-app';
61
+ import type { ReactMainConfig } from './react.main.runtime';
62
+ import { ReactAspect } from './react.aspect';
63
+ // webpack configs for both components and envs
64
+ import basePreviewConfigFactory from './webpack/webpack.config.base';
65
+ import basePreviewProdConfigFactory from './webpack/webpack.config.base.prod';
66
+
67
+ // webpack configs for envs only
68
+ // import devPreviewConfigFactory from './webpack/webpack.config.preview.dev';
69
+ import envPreviewDevConfigFactory from './webpack/webpack.config.env.dev';
70
+ import { templateWebpackConfigFactory } from './webpack/webpack.config.env.template';
71
+
72
+ // webpack configs for components only
73
+ import componentPreviewProdConfigFactory from './webpack/webpack.config.component.prod';
74
+ import componentPreviewDevConfigFactory from './webpack/webpack.config.component.dev';
75
+
76
+ export const ReactEnvType = 'react';
77
+ const defaultTsConfig = require('./typescript/tsconfig.json');
78
+ const buildTsConfig = require('./typescript/tsconfig.build.json');
79
+ const eslintConfig = require('./eslint/eslintrc');
80
+ const prettierConfig = require('./prettier/prettier.config');
81
+
82
+ // TODO: move to be taken from the key mode of compiler context
83
+ type CompilerMode = 'build' | 'dev';
84
+
85
+ type GetBuildPipeModifiers = PipeServiceModifiersMap & {
86
+ tsModifier?: PipeServiceModifier;
87
+ };
88
+
89
+ /**
90
+ * a component environment built for [React](https://reactjs.org) .
91
+ */
92
+ export class ReactEnv
93
+ implements TesterEnv, CompilerEnv, LinterEnv, DevEnv, BuilderEnv, DependenciesEnv, PackageEnv, FormatterEnv
94
+ {
95
+ constructor(
96
+ /**
97
+ * jest extension
98
+ */
99
+ private jestAspect: JestMain,
100
+
101
+ /**
102
+ * typescript extension.
103
+ */
104
+ protected tsAspect: TypescriptMain,
105
+
106
+ /**
107
+ * compiler extension.
108
+ */
109
+ private compiler: CompilerMain,
110
+
111
+ /**
112
+ * webpack extension.
113
+ */
114
+ private webpack: WebpackMain,
115
+
116
+ /**
117
+ * workspace extension.
118
+ */
119
+ private workspace: Workspace,
120
+
121
+ /**
122
+ * pkg extension.
123
+ */
124
+ private pkg: PkgMain,
125
+
126
+ /**
127
+ * tester extension
128
+ */
129
+ private tester: TesterMain,
130
+
131
+ private config: ReactMainConfig,
132
+
133
+ private dependencyResolver: DependencyResolverMain,
134
+
135
+ private logger: Logger,
136
+
137
+ private compilerAspectId: string
138
+ ) {}
139
+
140
+ getTsConfig(targetTsConfig?: TsConfigSourceFile): TsConfigSourceFile {
141
+ return targetTsConfig ? merge({}, defaultTsConfig, targetTsConfig) : defaultTsConfig;
142
+ }
143
+
144
+ getBuildTsConfig(targetTsConfig?: TsConfigSourceFile): TsConfigSourceFile {
145
+ return targetTsConfig ? merge({}, buildTsConfig, targetTsConfig) : buildTsConfig;
146
+ }
147
+
148
+ /**
149
+ * @deprecated use createCjsJestTester()
150
+ */
151
+ getCjsJestTester(jestConfigPath?: string, jestModulePath?: string): Tester {
152
+ return this.createCjsJestTester(jestConfigPath, jestModulePath);
153
+ }
154
+
155
+ /**
156
+ * Get a jest tester instance with react config and cjs configs
157
+ * @param jestConfigPath
158
+ * @param jestModulePath
159
+ * @returns
160
+ */
161
+ createCjsJestTester(jestConfigPath?: string, jestModulePath?: string): Tester {
162
+ const pathToSource = pathNormalizeToLinux(__dirname).replace('/dist', '');
163
+ const defaultConfig = join(pathToSource, './jest/jest.cjs.config.js');
164
+ const config = jestConfigPath || defaultConfig;
165
+ return this.jestAspect.createTester(config, jestModulePath || require.resolve('jest'));
166
+ }
167
+
168
+ /**
169
+ * @deprecated use createEsmJestTester()
170
+ */
171
+ getEsmJestTester(jestConfigPath?: string, jestModulePath?: string): Tester {
172
+ return this.createEsmJestTester(jestConfigPath, jestModulePath);
173
+ }
174
+
175
+ /**
176
+ * Get a jest tester instance with react config and esm configs
177
+ * @param jestConfigPath
178
+ * @param jestModulePath
179
+ * @returns
180
+ */
181
+ createEsmJestTester(jestConfigPath?: string, jestModulePath?: string): Tester {
182
+ const pathToSource = pathNormalizeToLinux(__dirname).replace('/dist', '');
183
+ const defaultConfig = join(pathToSource, './jest/jest.esm.config.js');
184
+ const config = jestConfigPath || defaultConfig;
185
+ return this.jestAspect.createTester(config, jestModulePath || require.resolve('jest'));
186
+ }
187
+
188
+ /**
189
+ * returns a component tester.
190
+ */
191
+ getTester(jestConfigPath: string, jestModulePath?: string): Tester {
192
+ // return this.createEsmJestTester(jestConfigPath, jestModulePath);
193
+ return this.createCjsJestTester(jestConfigPath, jestModulePath);
194
+ }
195
+
196
+ private createTsCompilerOptions(mode: CompilerMode = 'dev'): TypeScriptCompilerOptions {
197
+ const tsconfig = mode === 'dev' ? cloneDeep(defaultTsConfig) : cloneDeep(buildTsConfig);
198
+ const pathToSource = pathNormalizeToLinux(__dirname).replace('/dist/', '/src/');
199
+ const compileJs = true;
200
+ const compileJsx = true;
201
+ return {
202
+ tsconfig,
203
+ // TODO: @david please remove this line and refactor to be something that makes sense.
204
+ types: [resolve(pathToSource, './typescript/style.d.ts'), resolve(pathToSource, './typescript/asset.d.ts')],
205
+ compileJs,
206
+ compileJsx,
207
+ };
208
+ }
209
+
210
+ /**
211
+ * @deprecated use createTsCjsCompiler()
212
+ */
213
+ getTsCjsCompiler(mode: CompilerMode = 'dev', transformers: TsConfigTransformer[] = [], tsModule = ts) {
214
+ return this.createTsCjsCompiler(mode, transformers, tsModule);
215
+ }
216
+
217
+ /**
218
+ * Get a compiler instance with react config and set it to cjs module
219
+ * @param mode
220
+ * @param transformers
221
+ * @param tsModule
222
+ * @returns
223
+ */
224
+ createTsCjsCompiler(mode: CompilerMode = 'dev', transformers: TsConfigTransformer[] = [], tsModule = ts) {
225
+ const tsCompileOptions = this.createTsCompilerOptions(mode);
226
+ return this.tsAspect.createCjsCompiler(tsCompileOptions, transformers, tsModule);
227
+ }
228
+
229
+ /**
230
+ * @deprecated use createTsEsmCompiler()
231
+ */
232
+ getTsEsmCompiler(mode: CompilerMode = 'dev', transformers: TsConfigTransformer[] = [], tsModule = ts) {
233
+ this.createTsEsmCompiler(mode, transformers, tsModule);
234
+ }
235
+
236
+ /**
237
+ * Get a compiler instance with react config and set it to esm module
238
+ * @param mode
239
+ * @param transformers
240
+ * @param tsModule
241
+ * @returns
242
+ */
243
+ createTsEsmCompiler(mode: CompilerMode = 'dev', transformers: TsConfigTransformer[] = [], tsModule = ts) {
244
+ const tsCompileOptions = this.createTsCompilerOptions(mode);
245
+ return this.tsAspect.createEsmCompiler(tsCompileOptions, transformers, tsModule);
246
+ }
247
+
248
+ getCompiler(transformers: TsConfigTransformer[] = [], tsModule = ts) {
249
+ // return this.getTsEsmCompiler('dev', transformers, tsModule);
250
+ return this.createTsCjsCompiler('dev', transformers, tsModule);
251
+ }
252
+
253
+ private getEslintOptions(options: ESLintLib.Options, pluginPath: string, context: LinterContext): ESLintOptions {
254
+ const mergedConfig: ESLintLib.Options = {
255
+ // @ts-ignore - this is a bug in the @types/eslint types
256
+ overrideConfig: options,
257
+ extensions: context.extensionFormats,
258
+ useEslintrc: false,
259
+ // TODO: this should be probably be replaced with resolve-plugins-relative-to
260
+ // https://eslint.org/docs/latest/use/command-line-interface#--resolve-plugins-relative-to
261
+ cwd: pluginPath,
262
+ fix: !!context.fix,
263
+ fixTypes: context.fixTypes,
264
+ };
265
+ return Object.assign({}, options, { config: mergedConfig, extensions: context.extensionFormats });
266
+ }
267
+
268
+ /**
269
+ * returns and configures the component linter.
270
+ */
271
+ getLinter(context: LinterContext, transformers: EslintConfigTransformer[] = []): Linter {
272
+ const tsconfigPath = require.resolve('./typescript/tsconfig.json');
273
+
274
+ // resolve all plugins from the react environment.
275
+ const mergedOptions = this.getEslintOptions(eslintConfig, __dirname, context);
276
+ const configMutator = new EslintConfigMutator(mergedOptions);
277
+ const transformerContext: EslintConfigTransformContext = { fix: !!context.fix };
278
+ configMutator.addExtensionTypes(['.md', '.mdx']);
279
+ configMutator.setTsConfig(tsconfigPath);
280
+ const afterMutation = runTransformersWithContext(configMutator.clone(), transformers, transformerContext);
281
+ return ESLintLinter.create(afterMutation.raw, { logger: this.logger });
282
+ }
283
+
284
+ /**
285
+ * returns and configures the component formatter.
286
+ */
287
+ getFormatter(context: FormatterContext, transformers: PrettierConfigTransformer[] = []): Formatter {
288
+ const configMutator = new PrettierConfigMutator(prettierConfig);
289
+ const transformerContext: PrettierConfigTransformContext = { check: !!context?.check };
290
+ const afterMutation = runTransformersWithContext(configMutator.clone(), transformers, transformerContext);
291
+ return PrettierFormatter.create({ config: afterMutation.raw }, { logger: this.logger });
292
+ }
293
+
294
+ private getFileMap(components: Component[], local = false) {
295
+ return components.reduce<{ [key: string]: ComponentMeta }>((index, component: Component) => {
296
+ component.state.filesystem.files.forEach((file) => {
297
+ index[file.path] = {
298
+ id: component.id.toString(),
299
+ homepage: local ? `/${component.id.fullName}` : ComponentUrl.toUrl(component.id),
300
+ };
301
+ });
302
+
303
+ return index;
304
+ }, {});
305
+ }
306
+
307
+ private writeFileMap(components: Component[], local?: boolean) {
308
+ const fileMap = this.getFileMap(components, local);
309
+ const path = join(tmpdir(), `${Math.random().toString(36).slice(2, 11)}.json`);
310
+ outputFileSync(path, JSON.stringify(fileMap));
311
+ return path;
312
+ }
313
+
314
+ /**
315
+ * required for `bit start`
316
+ */
317
+ getDevEnvId(id?: string) {
318
+ if (typeof id !== 'string') return ReactAspect.id;
319
+ return id || ReactAspect.id;
320
+ }
321
+
322
+ /**
323
+ * get a schema generator instance configured with the correct tsconfig.
324
+ */
325
+ getSchemaExtractor(tsconfig: TsConfigSourceFile, tsserverPath?: string, contextPath?: string): SchemaExtractor {
326
+ return this.tsAspect.createSchemaExtractor(this.getTsConfig(tsconfig), tsserverPath, contextPath);
327
+ }
328
+
329
+ /**
330
+ * returns and configures the React component dev server.
331
+ * required for `bit start`
332
+ */
333
+ getDevServer(
334
+ context: DevServerContext,
335
+ transformers: WebpackConfigTransformer[] = [],
336
+ webpackModulePath?: string,
337
+ webpackDevServerModulePath?: string
338
+ ): DevServer {
339
+ const baseConfig = basePreviewConfigFactory(false);
340
+ const envDevConfig = envPreviewDevConfigFactory(context.id);
341
+ const componentDevConfig = componentPreviewDevConfigFactory(this.workspace.path, context.id);
342
+
343
+ const defaultTransformer: WebpackConfigTransformer = (configMutator) => {
344
+ const merged = configMutator.merge([baseConfig, envDevConfig, componentDevConfig]);
345
+ return merged;
346
+ };
347
+
348
+ return this.webpack.createDevServer(
349
+ context,
350
+ [defaultTransformer, ...transformers],
351
+ webpackModulePath,
352
+ webpackDevServerModulePath
353
+ );
354
+ }
355
+
356
+ async getBundler(
357
+ context: BundlerContext,
358
+ transformers: WebpackConfigTransformer[] = [],
359
+ webpackModulePath?: string
360
+ ): Promise<Bundler> {
361
+ return this.createComponentsWebpackBundler(context, transformers, webpackModulePath);
362
+ }
363
+
364
+ async createComponentsWebpackBundler(
365
+ context: BundlerContext,
366
+ transformers: WebpackConfigTransformer[] = [],
367
+ webpackModulePath?: string
368
+ ): Promise<Bundler> {
369
+ const baseConfig = basePreviewConfigFactory(!context.development);
370
+ const baseProdConfig = basePreviewProdConfigFactory(context.development);
371
+ const componentProdConfig = componentPreviewProdConfigFactory();
372
+
373
+ const defaultTransformer: WebpackConfigTransformer = (configMutator) => {
374
+ const merged = configMutator.merge([baseConfig, baseProdConfig, componentProdConfig]);
375
+ return merged;
376
+ };
377
+ const mergedTransformers = [defaultTransformer, ...transformers];
378
+ return this.createWebpackBundler(context, mergedTransformers, webpackModulePath);
379
+ }
380
+
381
+ async createTemplateWebpackBundler(
382
+ context: BundlerContext,
383
+ transformers: WebpackConfigTransformer[] = [],
384
+ webpackModulePath?: string
385
+ ): Promise<Bundler> {
386
+ const baseConfig = basePreviewConfigFactory(!context.development);
387
+ const baseProdConfig = basePreviewProdConfigFactory(context.development);
388
+ const templateConfig = templateWebpackConfigFactory();
389
+
390
+ const defaultTransformer: WebpackConfigTransformer = (configMutator) => {
391
+ const merged = configMutator.merge([baseConfig, baseProdConfig, templateConfig]);
392
+ return merged;
393
+ };
394
+ const mergedTransformers = [defaultTransformer, ...transformers];
395
+ return this.createWebpackBundler(context, mergedTransformers, webpackModulePath);
396
+ }
397
+
398
+ private async createWebpackBundler(
399
+ context: BundlerContext,
400
+ transformers: WebpackConfigTransformer[] = [],
401
+ webpackModulePath?: string
402
+ ): Promise<Bundler> {
403
+ return this.webpack.createBundler(context, transformers, undefined, webpackModulePath);
404
+ }
405
+
406
+ getAdditionalHostDependencies(): string[] {
407
+ return ['@teambit/mdx.ui.mdx-scope-context', '@mdx-js/react', 'react', 'react-dom'];
408
+ }
409
+
410
+ /**
411
+ * returns a path to a docs template.
412
+ */
413
+ getDocsTemplate() {
414
+ return require.resolve('@teambit/react.ui.docs-app');
415
+ }
416
+
417
+ icon = 'https://static.bit.dev/extensions-icons/react.svg';
418
+
419
+ /**
420
+ * returns the path to the compositions template
421
+ */
422
+ getMounter() {
423
+ return require.resolve('@teambit/react.ui.compositions-app');
424
+ }
425
+
426
+ getPreviewConfig() {
427
+ return {
428
+ strategyName: COMPONENT_PREVIEW_STRATEGY_NAME as PreviewStrategyName,
429
+ splitComponentBundle: true,
430
+ isScaling: true,
431
+ };
432
+ }
433
+
434
+ /**
435
+ * define the package json properties to add to each component.
436
+ */
437
+ getPackageJsonProps(): PackageJsonProps {
438
+ // React compile by default to esm, so uses type module
439
+ // return this.getEsmPackageJsonProps();
440
+ return this.getCjsPackageJsonProps();
441
+ }
442
+
443
+ /**
444
+ * @deprecated use createCjsPackageJsonProps()
445
+ */
446
+ getCjsPackageJsonProps(): PackageJsonProps {
447
+ return this.createCjsPackageJsonProps();
448
+ }
449
+
450
+ /**
451
+ * Get the default package.json props for a cjs component
452
+ * @returns
453
+ */
454
+ createCjsPackageJsonProps(): PackageJsonProps {
455
+ return this.tsAspect.getCjsPackageJsonProps();
456
+ }
457
+
458
+ /**
459
+ * @deprecated use createEsmPackageJsonProps()
460
+ */
461
+ getEsmPackageJsonProps(): PackageJsonProps {
462
+ return this.createEsmPackageJsonProps();
463
+ }
464
+
465
+ /**
466
+ * Get the default package.json props for an esm component
467
+ * @returns
468
+ */
469
+ createEsmPackageJsonProps(): PackageJsonProps {
470
+ return this.tsAspect.getEsmPackageJsonProps();
471
+ }
472
+
473
+ getNpmIgnore() {
474
+ return [`${CAPSULE_ARTIFACTS_DIR}/`];
475
+ }
476
+
477
+ /**
478
+ * adds dependencies to all configured components.
479
+ */
480
+ getDependencies() {
481
+ return {
482
+ dependencies: {
483
+ react: '-',
484
+ 'react-dom': '-',
485
+ 'core-js': '^3.0.0',
486
+ },
487
+ // TODO: add this only if using ts
488
+ devDependencies: {
489
+ react: '-',
490
+ 'react-dom': '-',
491
+ '@types/mocha': '-',
492
+ '@types/node': '12.20.4',
493
+ '@types/react': '^17.0.8',
494
+ '@types/react-dom': '^17.0.5',
495
+ '@types/jest': '^26.0.0',
496
+ // This is added as dev dep since our jest file transformer uses babel plugins that require this to be installed
497
+ '@babel/runtime': '7.20.0',
498
+ '@types/testing-library__jest-dom': '5.9.5',
499
+ },
500
+ peerDependencies: {
501
+ react: '^16.8.0 || ^17.0.0',
502
+ 'react-dom': '^16.8.0 || ^17.0.0',
503
+ },
504
+ };
505
+ }
506
+
507
+ /**
508
+ * returns the component build pipeline.
509
+ */
510
+ getBuildPipe(modifiers: GetBuildPipeModifiers = {}): BuildTask[] {
511
+ const transformers: Function[] = modifiers?.tsModifier?.transformers || [];
512
+ return [this.createCjsCompilerTask(transformers, modifiers?.tsModifier?.module || ts), this.tester.task];
513
+ }
514
+
515
+ /**
516
+ * @deprecated use createBuildPipeWithoutCompiler()
517
+ */
518
+ getBuildPipeWithoutCompiler(): BuildTask[] {
519
+ return this.createBuildPipeWithoutCompiler();
520
+ }
521
+
522
+ /**
523
+ * Get the react build pipeline without the compilation task.
524
+ * This help in cases you want to only replace the compilation task with something else
525
+ * @returns
526
+ */
527
+ createBuildPipeWithoutCompiler(): BuildTask[] {
528
+ const pipeWithoutCompiler = this.getBuildPipe().filter((task) => task.aspectId !== this.compilerAspectId);
529
+ return pipeWithoutCompiler;
530
+ }
531
+
532
+ /**
533
+ * @deprecated use createEsmCompilerTask()
534
+ */
535
+ getEsmCompilerTask(transformers: TsConfigTransformer[] = [], tsModule = ts) {
536
+ return this.createEsmCompilerTask(transformers as Function[], tsModule);
537
+ }
538
+
539
+ /**
540
+ * Get a compiler task with react config and set to esm module
541
+ * @param transformers
542
+ * @param tsModule
543
+ * @returns
544
+ */
545
+ createEsmCompilerTask(transformers: Function[] = [], tsModule = ts) {
546
+ const tsCompiler = this.createTsEsmCompiler('build', transformers as TsConfigTransformer[], tsModule);
547
+ return this.compiler.createTask('TSCompiler', tsCompiler);
548
+ }
549
+
550
+ /**
551
+ * @deprecated use createCjsCompilerTask()
552
+ * */
553
+ getCjsCompilerTask(transformers: TsConfigTransformer[] = [], tsModule = ts) {
554
+ return this.createCjsCompilerTask(transformers as Function[], tsModule);
555
+ }
556
+
557
+ /**
558
+ * Get a compiler task with react config and set to cjs module
559
+ * @param transformers
560
+ * @param tsModule
561
+ * @returns
562
+ */
563
+ createCjsCompilerTask(transformers: Function[] = [], tsModule = ts) {
564
+ const tsCompiler = this.createTsCjsCompiler('build', transformers as TsConfigTransformer[], tsModule);
565
+ return this.compiler.createTask('TSCompiler', tsCompiler);
566
+ }
567
+
568
+ workspaceConfig(): ConfigWriterEntry[] {
569
+ return [
570
+ TypescriptConfigWriter.create(
571
+ {
572
+ tsconfig: require.resolve('./typescript/tsconfig.cjs.json'),
573
+ // types: resolveTypes(__dirname, ["./types"]),
574
+ },
575
+ this.logger
576
+ ),
577
+ EslintConfigWriter.create(
578
+ {
579
+ configPath: require.resolve('./eslint/eslintrc.js'),
580
+ tsconfig: require.resolve('./typescript/tsconfig.cjs.json'),
581
+ },
582
+ this.logger
583
+ ),
584
+ PrettierConfigWriter.create(
585
+ {
586
+ configPath: require.resolve('./prettier/prettier.config.js'),
587
+ },
588
+ this.logger
589
+ ),
590
+ ];
591
+ }
592
+
593
+ async __getDescriptor() {
594
+ return {
595
+ type: ReactEnvType,
596
+ };
597
+ }
598
+ }
599
+
600
+ export function runTransformersWithContext<P, T extends Function, C>(config: P, transformers: T[] = [], context: C): P {
601
+ if (!Array.isArray(transformers)) return config;
602
+ const newConfig = transformers.reduce((acc, transformer) => {
603
+ return transformer(acc, context);
604
+ }, config);
605
+ return newConfig;
606
+ }
@@ -0,0 +1,52 @@
1
+ import { ComponentFactory } from '@teambit/component';
2
+ import { gql } from 'graphql-tag';
3
+
4
+ import { ReactMain } from './react.main.runtime';
5
+
6
+ export function reactSchema(react: ReactMain) {
7
+ return {
8
+ typeDefs: gql`
9
+ extend type ComponentHost {
10
+ getDocs(id: String!): ReactDocs
11
+ }
12
+
13
+ type ReactDocs {
14
+ abstract: String
15
+ filePath: String
16
+ properties: [Property]
17
+ }
18
+
19
+ type Property {
20
+ name: String
21
+ description: String
22
+ required: Boolean
23
+ type: String
24
+ defaultValue: DefaultValue
25
+ }
26
+
27
+ type DefaultValue {
28
+ value: String
29
+ computed: Boolean
30
+ }
31
+ `,
32
+ resolvers: {
33
+ ComponentHost: {
34
+ getDocs: async (host: ComponentFactory, { id }: { id: string }) => {
35
+ const componentId = await host.resolveComponentId(id);
36
+ const component = await host.get(componentId);
37
+ const empty = {
38
+ abstract: '',
39
+ filePath: '',
40
+ properties: [],
41
+ };
42
+
43
+ if (!component) return empty;
44
+ const docs = react.getDocs(component);
45
+ if (!docs) return empty;
46
+
47
+ return docs;
48
+ },
49
+ },
50
+ },
51
+ };
52
+ }