@teambit/react 1.0.413 → 1.0.414
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/artifacts/env-template/public/314.3776669ccd7cd7f3b7a8.js +690 -0
- package/artifacts/env-template/public/453.042e4d7752cf6b24cd7e.js +41 -0
- package/artifacts/env-template/public/769.df90c4d201536c9ea25a.js +232 -0
- package/artifacts/env-template/public/871.9a7e9061377f8f261632.js +257 -0
- package/artifacts/env-template/public/assets-manifest.json +58 -0
- package/artifacts/env-template/public/compositions.ef44d8276571593058c5.js +1 -0
- package/artifacts/env-template/public/compositions.html +2 -0
- package/artifacts/env-template/public/overview.6663b8bc3c313bd891a1.js +1 -0
- package/artifacts/env-template/public/overview.html +2 -0
- package/artifacts/env-template/public/peers.08335d0674add8f38167.js +1 -0
- package/artifacts/env-template/public/preview-root.2182a25a76a310169ca9.js +1 -0
- package/artifacts/env-template/public/static/css/314.3571d7f7.css +1 -0
- package/artifacts/env-template/public/static/css/compositions.7f2d907d.css +1 -0
- package/artifacts/env-template/public/static/css/preview-root.ebd38a13.css +1 -0
- package/dist/{preview-1727148128138.js → preview-1727262607766.js} +2 -2
- package/package.json +39 -39
- package/index.ts +0 -12
- package/react.api.transformer.ts +0 -53
- package/react.aspect.ts +0 -7
- package/react.env.ts +0 -640
- package/react.graphql.ts +0 -52
- package/react.main.runtime.ts +0 -476
- package/react.preview.runtime.ts +0 -55
- package/react.schema.ts +0 -111
- package/react.templates.ts +0 -28
- /package/{compositions-1727148128138.js → compositions-1727262607766.js} +0 -0
- /package/{overview-1727148128138.js → overview-1727262607766.js} +0 -0
package/react.main.runtime.ts
DELETED
|
@@ -1,476 +0,0 @@
|
|
|
1
|
-
import type { DevFilesMain } from '@teambit/dev-files';
|
|
2
|
-
import { DevFilesAspect } from '@teambit/dev-files';
|
|
3
|
-
import { Harmony } from '@teambit/harmony';
|
|
4
|
-
import { merge, omit } from 'lodash';
|
|
5
|
-
import { MainRuntime } from '@teambit/cli';
|
|
6
|
-
import type { CompilerMain } from '@teambit/compiler';
|
|
7
|
-
import { CompilerAspect, Compiler } from '@teambit/compiler';
|
|
8
|
-
import { BuildTask } from '@teambit/builder';
|
|
9
|
-
import { Component, ComponentID } from '@teambit/component';
|
|
10
|
-
import { EnvsAspect, EnvsMain, EnvTransformer, Environment, EnvContext } from '@teambit/envs';
|
|
11
|
-
import type { GraphqlMain } from '@teambit/graphql';
|
|
12
|
-
import { GraphqlAspect } from '@teambit/graphql';
|
|
13
|
-
import type { PkgMain, PackageJsonProps } from '@teambit/pkg';
|
|
14
|
-
import { SchemaMain, SchemaAspect } from '@teambit/schema';
|
|
15
|
-
import { PkgAspect } from '@teambit/pkg';
|
|
16
|
-
import type { TesterMain } from '@teambit/tester';
|
|
17
|
-
import { TesterAspect } from '@teambit/tester';
|
|
18
|
-
import type { TypescriptMain, TsCompilerOptionsWithoutTsConfig, TsConfigTransformer } from '@teambit/typescript';
|
|
19
|
-
import { TypescriptAspect } from '@teambit/typescript';
|
|
20
|
-
import type { WebpackMain, Configuration, WebpackConfigTransformer } from '@teambit/webpack';
|
|
21
|
-
import { WebpackAspect } from '@teambit/webpack';
|
|
22
|
-
import { GeneratorAspect, GeneratorMain } from '@teambit/generator';
|
|
23
|
-
import { Workspace, WorkspaceAspect } from '@teambit/workspace';
|
|
24
|
-
import { DevServerContext, BundlerContext } from '@teambit/bundler';
|
|
25
|
-
import { DependencyResolverAspect, DependencyResolverMain, EnvPolicyConfigObject } from '@teambit/dependency-resolver';
|
|
26
|
-
import ts from 'typescript';
|
|
27
|
-
import { ApplicationAspect, ApplicationMain } from '@teambit/application';
|
|
28
|
-
import { FormatterContext } from '@teambit/formatter';
|
|
29
|
-
import { LinterContext } from '@teambit/linter';
|
|
30
|
-
import { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';
|
|
31
|
-
import { EslintConfigTransformer } from '@teambit/defender.eslint.config-mutator';
|
|
32
|
-
import { WorkerAspect, WorkerMain } from '@teambit/worker';
|
|
33
|
-
|
|
34
|
-
import { ReactAspect } from './react.aspect';
|
|
35
|
-
import { ReactEnv } from './react.env';
|
|
36
|
-
import { ReactAppType } from './apps/web';
|
|
37
|
-
import { reactSchema } from './react.graphql';
|
|
38
|
-
import { getTemplates } from './react.templates';
|
|
39
|
-
import { ReactAppOptions } from './apps/web/react-app-options';
|
|
40
|
-
import { ReactSchema } from './react.schema';
|
|
41
|
-
import { ReactAPITransformer } from './react.api.transformer';
|
|
42
|
-
import { PrettierConfigTransformer } from '@teambit/defender.prettier.config-mutator';
|
|
43
|
-
|
|
44
|
-
type ReactDeps = [
|
|
45
|
-
EnvsMain,
|
|
46
|
-
TypescriptMain,
|
|
47
|
-
CompilerMain,
|
|
48
|
-
WebpackMain,
|
|
49
|
-
Workspace,
|
|
50
|
-
GraphqlMain,
|
|
51
|
-
PkgMain,
|
|
52
|
-
TesterMain,
|
|
53
|
-
ApplicationMain,
|
|
54
|
-
GeneratorMain,
|
|
55
|
-
DependencyResolverMain,
|
|
56
|
-
LoggerMain,
|
|
57
|
-
SchemaMain,
|
|
58
|
-
WorkerMain,
|
|
59
|
-
DevFilesMain
|
|
60
|
-
];
|
|
61
|
-
|
|
62
|
-
export type ReactMainConfig = {
|
|
63
|
-
/**
|
|
64
|
-
* configure the react env compiler.
|
|
65
|
-
* can be configured to either TypeScript ('ts') or Babel ('babel').
|
|
66
|
-
*/
|
|
67
|
-
compiler: 'babel' | 'ts';
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* configure the component tester.
|
|
71
|
-
* can be either Jest ('jest') or Mocha ('mocha')
|
|
72
|
-
*/
|
|
73
|
-
tester: 'jest' | 'mocha';
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* version of React to configure.
|
|
77
|
-
*/
|
|
78
|
-
reactVersion: string;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
export type UseWebpackModifiers = {
|
|
82
|
-
previewConfig?: WebpackConfigTransformer[];
|
|
83
|
-
devServerConfig?: WebpackConfigTransformer[];
|
|
84
|
-
webpackModulePath?: string;
|
|
85
|
-
webpackDevServerModulePath?: string;
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
export type UseTypescriptModifiers = {
|
|
89
|
-
buildConfig?: TsConfigTransformer[];
|
|
90
|
-
devConfig?: TsConfigTransformer[];
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
export type UseEslintModifiers = {
|
|
94
|
-
transformers: EslintConfigTransformer[];
|
|
95
|
-
};
|
|
96
|
-
export type UsePrettierModifiers = {
|
|
97
|
-
transformers: PrettierConfigTransformer[];
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
export class ReactMain {
|
|
101
|
-
constructor(
|
|
102
|
-
/**
|
|
103
|
-
* an instance of the React env.
|
|
104
|
-
*/
|
|
105
|
-
readonly reactEnv: ReactEnv,
|
|
106
|
-
|
|
107
|
-
private envs: EnvsMain,
|
|
108
|
-
|
|
109
|
-
private application: ApplicationMain,
|
|
110
|
-
|
|
111
|
-
private reactAppType: ReactAppType,
|
|
112
|
-
|
|
113
|
-
private dependencyResolver: DependencyResolverMain,
|
|
114
|
-
|
|
115
|
-
private logger: Logger
|
|
116
|
-
) {}
|
|
117
|
-
|
|
118
|
-
readonly env = this.reactEnv;
|
|
119
|
-
|
|
120
|
-
getReactAppType(name: string) {
|
|
121
|
-
return new ReactAppType(name, this.reactEnv, this.logger, this.dependencyResolver);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* use this to register apps programmatically.
|
|
126
|
-
*/
|
|
127
|
-
async registerApp(reactApp: ReactAppOptions) {
|
|
128
|
-
return this.application.registerApp(this.reactAppType.createApp(reactApp));
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* override the env's typescript config for both dev and build time.
|
|
133
|
-
* Replaces both overrideTsConfig (devConfig) and overrideBuildTsConfig (buildConfig)
|
|
134
|
-
*/
|
|
135
|
-
useTypescript(modifiers?: UseTypescriptModifiers, tsModule: any = ts) {
|
|
136
|
-
const overrides: any = {};
|
|
137
|
-
const devTransformers = modifiers?.devConfig;
|
|
138
|
-
if (devTransformers) {
|
|
139
|
-
overrides.getCompiler = () => this.reactEnv.getCompiler(devTransformers, tsModule);
|
|
140
|
-
}
|
|
141
|
-
const buildTransformers = modifiers?.buildConfig;
|
|
142
|
-
if (buildTransformers) {
|
|
143
|
-
const buildPipeModifiers = {
|
|
144
|
-
tsModifier: {
|
|
145
|
-
transformers: buildTransformers,
|
|
146
|
-
module: tsModule,
|
|
147
|
-
},
|
|
148
|
-
};
|
|
149
|
-
overrides.getBuildPipe = () => this.reactEnv.getBuildPipe(buildPipeModifiers);
|
|
150
|
-
}
|
|
151
|
-
return this.envs.override(overrides);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* @deprecated use useTypescript()
|
|
156
|
-
* override the TS config of the React environment.
|
|
157
|
-
* @param tsModule typeof `ts` module instance.
|
|
158
|
-
*/
|
|
159
|
-
overrideTsConfig(
|
|
160
|
-
tsconfig: Record<string, any> = {},
|
|
161
|
-
compilerOptions: Partial<TsCompilerOptionsWithoutTsConfig> = {},
|
|
162
|
-
tsModule: any = ts
|
|
163
|
-
) {
|
|
164
|
-
const transformer: TsConfigTransformer = (configMutator) => {
|
|
165
|
-
configMutator.mergeTsConfig(tsconfig);
|
|
166
|
-
configMutator.raw.compileJs = compilerOptions.compileJs ?? configMutator.raw.compileJs;
|
|
167
|
-
configMutator.raw.compileJsx = compilerOptions.compileJsx ?? configMutator.raw.compileJsx;
|
|
168
|
-
if (compilerOptions.types) {
|
|
169
|
-
configMutator.addTypes(compilerOptions.types);
|
|
170
|
-
}
|
|
171
|
-
const genericCompilerOptions = omit(compilerOptions, ['types', 'compileJs', 'compileJsx']);
|
|
172
|
-
configMutator.raw = Object.assign(configMutator.raw, genericCompilerOptions);
|
|
173
|
-
return configMutator;
|
|
174
|
-
};
|
|
175
|
-
// return this.envs.override({
|
|
176
|
-
// getCompiler: () => this.reactEnv.getCompiler([transformer], tsModule),
|
|
177
|
-
// });
|
|
178
|
-
return this.useTypescript({ devConfig: [transformer] }, tsModule);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Override the Bit documentation link. See docs: https://bit.dev/refrence/docs/doc-templates
|
|
183
|
-
*/
|
|
184
|
-
overrideDocsTemplate(templatePath: string) {
|
|
185
|
-
return this.envs.override({
|
|
186
|
-
getDevEnvId: (context: DevServerContext) => this.reactEnv.getDevEnvId(context.envDefinition.id),
|
|
187
|
-
getDocsTemplate: () => templatePath,
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* @deprecated use useTypescript()
|
|
193
|
-
* override the build tsconfig.
|
|
194
|
-
*/
|
|
195
|
-
overrideBuildTsConfig(
|
|
196
|
-
tsconfig: Record<string, any> = {},
|
|
197
|
-
compilerOptions: Partial<TsCompilerOptionsWithoutTsConfig> = {},
|
|
198
|
-
tsModule: any = ts
|
|
199
|
-
) {
|
|
200
|
-
const transformer: TsConfigTransformer = (configMutator) => {
|
|
201
|
-
configMutator.mergeTsConfig(tsconfig);
|
|
202
|
-
configMutator.raw.compileJs = compilerOptions.compileJs ?? configMutator.raw.compileJs;
|
|
203
|
-
configMutator.raw.compileJsx = compilerOptions.compileJsx ?? configMutator.raw.compileJsx;
|
|
204
|
-
if (compilerOptions.types) {
|
|
205
|
-
configMutator.addTypes(compilerOptions.types);
|
|
206
|
-
}
|
|
207
|
-
const genericCompilerOptions = omit(compilerOptions, ['types', 'compileJs', 'compileJsx']);
|
|
208
|
-
configMutator.raw = Object.assign(configMutator.raw, genericCompilerOptions);
|
|
209
|
-
return configMutator;
|
|
210
|
-
};
|
|
211
|
-
// return this.envs.override({
|
|
212
|
-
// getBuildPipe: () => this.reactEnv.getBuildPipe([transformer], tsModule),
|
|
213
|
-
// });
|
|
214
|
-
return this.useTypescript({ buildConfig: [transformer] }, tsModule);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* override the env's dev server and preview webpack configurations.
|
|
219
|
-
* Replaces both overrideDevServerConfig and overridePreviewConfig
|
|
220
|
-
*/
|
|
221
|
-
useWebpack(modifiers?: UseWebpackModifiers): EnvTransformer {
|
|
222
|
-
const overrides: any = {};
|
|
223
|
-
const devServerTransformers = modifiers?.devServerConfig;
|
|
224
|
-
if (devServerTransformers || modifiers?.webpackModulePath || modifiers?.webpackDevServerModulePath) {
|
|
225
|
-
overrides.getDevServer = (context: DevServerContext) =>
|
|
226
|
-
this.reactEnv.getDevServer(
|
|
227
|
-
context,
|
|
228
|
-
devServerTransformers,
|
|
229
|
-
modifiers?.webpackModulePath,
|
|
230
|
-
modifiers?.webpackDevServerModulePath
|
|
231
|
-
);
|
|
232
|
-
overrides.getDevEnvId = (context: DevServerContext) => this.reactEnv.getDevEnvId(context.envDefinition.id);
|
|
233
|
-
}
|
|
234
|
-
const previewTransformers = modifiers?.previewConfig;
|
|
235
|
-
if (previewTransformers || modifiers?.webpackModulePath) {
|
|
236
|
-
overrides.getBundler = (context: BundlerContext) =>
|
|
237
|
-
this.reactEnv.getBundler(context, previewTransformers, modifiers?.webpackModulePath);
|
|
238
|
-
}
|
|
239
|
-
return this.envs.override(overrides);
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* An API to mutate the prettier config
|
|
244
|
-
* @param modifiers
|
|
245
|
-
* @returns
|
|
246
|
-
*/
|
|
247
|
-
useEslint(modifiers?: UseEslintModifiers): EnvTransformer {
|
|
248
|
-
const transformers = modifiers?.transformers || [];
|
|
249
|
-
return this.envs.override({
|
|
250
|
-
getLinter: (context: LinterContext) => this.reactEnv.getLinter(context, transformers),
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* An API to mutate the prettier config
|
|
256
|
-
* @param modifiers
|
|
257
|
-
* @returns
|
|
258
|
-
*/
|
|
259
|
-
usePrettier(modifiers?: UsePrettierModifiers): EnvTransformer {
|
|
260
|
-
const transformers = modifiers?.transformers || [];
|
|
261
|
-
return this.envs.override({
|
|
262
|
-
getFormatter: (context: FormatterContext) => this.reactEnv.getFormatter(context, transformers),
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* @deprecated use useWebpack()
|
|
268
|
-
* override the dev server webpack config.
|
|
269
|
-
*/
|
|
270
|
-
overrideDevServerConfig(config: Configuration) {
|
|
271
|
-
const transformer: WebpackConfigTransformer = (configMutator) => {
|
|
272
|
-
return configMutator.merge([config]);
|
|
273
|
-
};
|
|
274
|
-
|
|
275
|
-
return this.envs.override({
|
|
276
|
-
getDevServer: (context: DevServerContext) => this.reactEnv.getDevServer(context, [transformer]),
|
|
277
|
-
getDevEnvId: (context: DevServerContext) => this.reactEnv.getDevEnvId(context.envDefinition.id),
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
* @deprecated use useWebpack()
|
|
283
|
-
* override the preview webpack config.
|
|
284
|
-
*/
|
|
285
|
-
overridePreviewConfig(config: Configuration) {
|
|
286
|
-
const transformer: WebpackConfigTransformer = (configMutator) => {
|
|
287
|
-
return configMutator.merge([config]);
|
|
288
|
-
};
|
|
289
|
-
return this.envs.override({
|
|
290
|
-
getBundler: (context: BundlerContext) => this.reactEnv.getBundler(context, [transformer]),
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
overrideMounter(mounterPath: string) {
|
|
295
|
-
return this.envs.override({
|
|
296
|
-
getMounter: () => {
|
|
297
|
-
return mounterPath;
|
|
298
|
-
},
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* create a new composition of the react environment.
|
|
304
|
-
*/
|
|
305
|
-
compose(transformers: EnvTransformer[], targetEnv: Environment = {}) {
|
|
306
|
-
return this.envs.compose(this.envs.merge(targetEnv, this.reactEnv), transformers);
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
/**
|
|
310
|
-
* override the jest configuration.
|
|
311
|
-
* @param jestConfigPath {typeof jest} absolute path to jest.config.json.
|
|
312
|
-
* @param jestModulePath absolute path to jest
|
|
313
|
-
*/
|
|
314
|
-
overrideJestConfig(jestConfigPath: string, jestModulePath?: string) {
|
|
315
|
-
const buildTransformers = [() => jestConfigPath];
|
|
316
|
-
return this.envs.override({
|
|
317
|
-
getTester: () => this.reactEnv.getTester(jestConfigPath, jestModulePath),
|
|
318
|
-
getBuildPipe: () =>
|
|
319
|
-
this.reactEnv.getBuildPipe({ jestModifier: { transformers: buildTransformers, module: jestModulePath } }),
|
|
320
|
-
});
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
/**
|
|
324
|
-
* override the build pipeline of the component environment.
|
|
325
|
-
*/
|
|
326
|
-
overrideBuildPipe(tasks: BuildTask[]) {
|
|
327
|
-
return this.envs.override({
|
|
328
|
-
getBuildPipe: () => tasks,
|
|
329
|
-
});
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
/**
|
|
333
|
-
* override the compiler tasks inside the build pipeline of the component environment.
|
|
334
|
-
*/
|
|
335
|
-
overrideCompilerTasks(tasks: BuildTask[]) {
|
|
336
|
-
const pipeWithoutCompiler = this.reactEnv.getBuildPipeWithoutCompiler();
|
|
337
|
-
|
|
338
|
-
return this.envs.override({
|
|
339
|
-
getBuildPipe: () => [...tasks, ...pipeWithoutCompiler],
|
|
340
|
-
});
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
/**
|
|
344
|
-
* override the dependency configuration of the component environment.
|
|
345
|
-
*/
|
|
346
|
-
overrideDependencies(dependencyPolicy: EnvPolicyConfigObject) {
|
|
347
|
-
return this.envs.override({
|
|
348
|
-
getDependencies: async () => {
|
|
349
|
-
const reactDeps = await this.reactEnv.getDependencies();
|
|
350
|
-
return merge(reactDeps, dependencyPolicy);
|
|
351
|
-
},
|
|
352
|
-
});
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
* override the workspace compiler.
|
|
357
|
-
*/
|
|
358
|
-
overrideCompiler(compiler: Compiler) {
|
|
359
|
-
return this.envs.override({
|
|
360
|
-
getCompiler: () => {
|
|
361
|
-
return compiler;
|
|
362
|
-
},
|
|
363
|
-
});
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
/**
|
|
367
|
-
* TODO: @gilad we need to implement this.
|
|
368
|
-
*/
|
|
369
|
-
overrideEslintConfig() {}
|
|
370
|
-
|
|
371
|
-
/**
|
|
372
|
-
* override the package json props of the component environment.
|
|
373
|
-
*/
|
|
374
|
-
overridePackageJsonProps(props: PackageJsonProps) {
|
|
375
|
-
return this.envs.override({
|
|
376
|
-
getPackageJsonProps: () => {
|
|
377
|
-
return {
|
|
378
|
-
...this.reactEnv.getPackageJsonProps(),
|
|
379
|
-
...props,
|
|
380
|
-
};
|
|
381
|
-
},
|
|
382
|
-
});
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
/**
|
|
386
|
-
* returns doc adjusted specifically for react components.
|
|
387
|
-
*/
|
|
388
|
-
getDocs(component: Component) {
|
|
389
|
-
const docsArray = component.state._consumer.docs;
|
|
390
|
-
if (!docsArray || !docsArray[0]) {
|
|
391
|
-
return null;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
const docs = docsArray[0];
|
|
395
|
-
|
|
396
|
-
return {
|
|
397
|
-
abstract: docs.description,
|
|
398
|
-
filePath: docs.filePath,
|
|
399
|
-
properties: docs.properties,
|
|
400
|
-
};
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
static runtime = MainRuntime;
|
|
404
|
-
static dependencies = [
|
|
405
|
-
EnvsAspect,
|
|
406
|
-
TypescriptAspect,
|
|
407
|
-
CompilerAspect,
|
|
408
|
-
WebpackAspect,
|
|
409
|
-
WorkspaceAspect,
|
|
410
|
-
GraphqlAspect,
|
|
411
|
-
PkgAspect,
|
|
412
|
-
TesterAspect,
|
|
413
|
-
ApplicationAspect,
|
|
414
|
-
GeneratorAspect,
|
|
415
|
-
DependencyResolverAspect,
|
|
416
|
-
LoggerAspect,
|
|
417
|
-
SchemaAspect,
|
|
418
|
-
WorkerAspect,
|
|
419
|
-
DevFilesAspect,
|
|
420
|
-
];
|
|
421
|
-
|
|
422
|
-
static async provider(
|
|
423
|
-
[
|
|
424
|
-
envs,
|
|
425
|
-
tsAspect,
|
|
426
|
-
compiler,
|
|
427
|
-
webpack,
|
|
428
|
-
workspace,
|
|
429
|
-
graphql,
|
|
430
|
-
pkg,
|
|
431
|
-
tester,
|
|
432
|
-
application,
|
|
433
|
-
generator,
|
|
434
|
-
dependencyResolver,
|
|
435
|
-
loggerMain,
|
|
436
|
-
schemaMain,
|
|
437
|
-
workerMain,
|
|
438
|
-
devFilesMain,
|
|
439
|
-
]: ReactDeps,
|
|
440
|
-
config: ReactMainConfig,
|
|
441
|
-
slots,
|
|
442
|
-
harmony: Harmony
|
|
443
|
-
) {
|
|
444
|
-
const logger = loggerMain.createLogger(ReactAspect.id);
|
|
445
|
-
const reactEnv = new ReactEnv(
|
|
446
|
-
tsAspect,
|
|
447
|
-
compiler,
|
|
448
|
-
webpack,
|
|
449
|
-
workspace,
|
|
450
|
-
workerMain,
|
|
451
|
-
pkg,
|
|
452
|
-
tester,
|
|
453
|
-
config,
|
|
454
|
-
dependencyResolver,
|
|
455
|
-
devFilesMain,
|
|
456
|
-
logger,
|
|
457
|
-
CompilerAspect.id
|
|
458
|
-
);
|
|
459
|
-
const appType = new ReactAppType('react-app', reactEnv, logger, dependencyResolver);
|
|
460
|
-
const react = new ReactMain(reactEnv, envs, application, appType, dependencyResolver, logger);
|
|
461
|
-
graphql.register(reactSchema(react));
|
|
462
|
-
envs.registerEnv(reactEnv);
|
|
463
|
-
if (generator) {
|
|
464
|
-
const envContext = new EnvContext(ComponentID.fromString(ReactAspect.id), loggerMain, workerMain, harmony);
|
|
465
|
-
generator.registerComponentTemplate(getTemplates(envContext));
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
if (application) application.registerAppType(appType);
|
|
469
|
-
if (schemaMain) schemaMain.registerSchemaClass(ReactSchema);
|
|
470
|
-
if (tsAspect) tsAspect.registerApiTransformer([new ReactAPITransformer()]);
|
|
471
|
-
|
|
472
|
-
return react;
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
ReactAspect.addRuntime(ReactMain);
|
package/react.preview.runtime.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { ComponentType } from 'react';
|
|
2
|
-
import flatten from 'lodash.flatten';
|
|
3
|
-
import { SlotRegistry, Slot } from '@teambit/harmony';
|
|
4
|
-
import { PreviewAspect, PreviewPreview, PreviewRuntime, RenderingContextProvider } from '@teambit/preview';
|
|
5
|
-
import { HighlighterProvider } from '@teambit/react.ui.highlighter-provider';
|
|
6
|
-
import { ReactAspect } from './react.aspect';
|
|
7
|
-
|
|
8
|
-
export type Provider = ComponentType<{}>;
|
|
9
|
-
export type ProviderSlot = SlotRegistry<Provider[]>;
|
|
10
|
-
|
|
11
|
-
export class ReactPreview {
|
|
12
|
-
constructor(private preview: PreviewPreview, private providerSlot: ProviderSlot) {}
|
|
13
|
-
|
|
14
|
-
registerProvider(provider: Provider[]) {
|
|
15
|
-
this.providerSlot.register(provider);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
getRenderingContext: RenderingContextProvider = ({ aspectsFilter }) => {
|
|
19
|
-
let entries = this.providerSlot.toArray();
|
|
20
|
-
|
|
21
|
-
if (aspectsFilter) {
|
|
22
|
-
const allowedAspects = new Set(aspectsFilter);
|
|
23
|
-
allowedAspects.add(ReactAspect.id);
|
|
24
|
-
|
|
25
|
-
entries = entries.filter(([aspectId]) => allowedAspects.has(aspectId));
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const providers = flatten(entries.map(([, provider]) => provider));
|
|
29
|
-
|
|
30
|
-
return {
|
|
31
|
-
providers,
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
static runtime = PreviewRuntime;
|
|
36
|
-
|
|
37
|
-
static slots = [Slot.withType<Provider>()];
|
|
38
|
-
|
|
39
|
-
static dependencies = [PreviewAspect];
|
|
40
|
-
|
|
41
|
-
static async provider([preview]: [PreviewPreview], config, [providerSlot]: [ProviderSlot]) {
|
|
42
|
-
const reactPreview = new ReactPreview(preview, providerSlot);
|
|
43
|
-
|
|
44
|
-
// @ts-ignore
|
|
45
|
-
reactPreview.registerProvider([HighlighterProvider]);
|
|
46
|
-
|
|
47
|
-
preview.registerRenderContext(reactPreview.getRenderingContext);
|
|
48
|
-
|
|
49
|
-
return reactPreview;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
ReactAspect.addRuntime(ReactPreview);
|
|
54
|
-
|
|
55
|
-
export default ReactPreview;
|
package/react.schema.ts
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DocSchema,
|
|
3
|
-
FunctionLikeSchema,
|
|
4
|
-
Location,
|
|
5
|
-
Modifier,
|
|
6
|
-
ParameterSchema,
|
|
7
|
-
SchemaNode,
|
|
8
|
-
SchemaRegistry,
|
|
9
|
-
TagName,
|
|
10
|
-
TypeRefSchema,
|
|
11
|
-
} from '@teambit/semantics.entities.semantic-schema';
|
|
12
|
-
import chalk from 'chalk';
|
|
13
|
-
import { compact } from 'lodash';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* function-like can be a function, method, arrow-function, variable-function, etc.
|
|
17
|
-
*/
|
|
18
|
-
export class ReactSchema extends SchemaNode {
|
|
19
|
-
readonly returnType: SchemaNode;
|
|
20
|
-
|
|
21
|
-
readonly props?: ParameterSchema;
|
|
22
|
-
|
|
23
|
-
readonly doc?: DocSchema;
|
|
24
|
-
|
|
25
|
-
readonly signature?: string | undefined;
|
|
26
|
-
|
|
27
|
-
constructor(
|
|
28
|
-
readonly location: Location,
|
|
29
|
-
readonly name: string,
|
|
30
|
-
returnType: TypeRefSchema,
|
|
31
|
-
props?: ParameterSchema<TypeRefSchema>,
|
|
32
|
-
signature?: string,
|
|
33
|
-
readonly modifiers: Modifier[] = [],
|
|
34
|
-
doc?: DocSchema,
|
|
35
|
-
readonly typeParams?: string[]
|
|
36
|
-
) {
|
|
37
|
-
super();
|
|
38
|
-
this.props = props;
|
|
39
|
-
this.returnType = returnType;
|
|
40
|
-
this.doc = doc;
|
|
41
|
-
this.signature = signature || FunctionLikeSchema.createSignature(name, compact([props]), returnType);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
getNodes() {
|
|
45
|
-
return compact([this.props, this.returnType]);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
toString(options?: { color?: boolean }): string {
|
|
49
|
-
const bold = options?.color ? chalk.bold : (x: string) => x;
|
|
50
|
-
|
|
51
|
-
const paramsStr = this.props?.toString();
|
|
52
|
-
const typeParamsStr = this.typeParams ? `<${this.typeParams.join(', ')}>` : '';
|
|
53
|
-
return `${this.modifiersToString()}${typeParamsStr}${bold(this.name)}(${paramsStr}): ${this.returnType.toString()}`;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
toFullSignature(options?: { showDocs?: boolean }): string {
|
|
57
|
-
let signature = '';
|
|
58
|
-
|
|
59
|
-
if (this.doc && options?.showDocs) {
|
|
60
|
-
signature += `${this.doc.toFullSignature()}\n`;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const modifiersStr = this.modifiersToString();
|
|
64
|
-
const typeParamsStr = this.typeParams ? `<${this.typeParams.join(', ')}>` : '';
|
|
65
|
-
const paramsStr = this.props ? this.props.toFullSignature() : '';
|
|
66
|
-
|
|
67
|
-
const returnTypeStr = this.returnType.toFullSignature();
|
|
68
|
-
|
|
69
|
-
signature += `${modifiersStr}const ${this.name}${typeParamsStr} = (${paramsStr}): ${returnTypeStr};`;
|
|
70
|
-
|
|
71
|
-
return signature;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
isDeprecated(): boolean {
|
|
75
|
-
return Boolean(this.doc?.hasTag(TagName.deprecated));
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
isPrivate(): boolean {
|
|
79
|
-
return Boolean(this.modifiers.find((m) => m === 'private') || this.doc?.hasTag(TagName.private));
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
private modifiersToString() {
|
|
83
|
-
const modifiersToPrint = this.modifiers.filter((modifier) => modifier !== 'export');
|
|
84
|
-
return modifiersToPrint.length ? `${modifiersToPrint.join(' ')} ` : '';
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
toObject() {
|
|
88
|
-
return {
|
|
89
|
-
...super.toObject(),
|
|
90
|
-
name: this.name,
|
|
91
|
-
props: this.props?.toObject(),
|
|
92
|
-
returnType: this.returnType.toObject(),
|
|
93
|
-
signature: this.signature,
|
|
94
|
-
modifiers: this.modifiers,
|
|
95
|
-
doc: this.doc?.toObject(),
|
|
96
|
-
typeParams: this.typeParams,
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
static fromObject(obj: Record<string, any>): ReactSchema {
|
|
101
|
-
const location = obj.location;
|
|
102
|
-
const name = obj.name;
|
|
103
|
-
const props = obj.props ? ParameterSchema.fromObject<TypeRefSchema>(obj.props) : undefined;
|
|
104
|
-
const returnType = SchemaRegistry.fromObject(obj.returnType);
|
|
105
|
-
const signature = obj.signature;
|
|
106
|
-
const modifiers = obj.modifiers;
|
|
107
|
-
const doc = obj.doc ? DocSchema.fromObject(obj.doc) : undefined;
|
|
108
|
-
const typeParams = obj.typeParams;
|
|
109
|
-
return new ReactSchema(location, name, returnType, props, signature, modifiers, doc, typeParams);
|
|
110
|
-
}
|
|
111
|
-
}
|
package/react.templates.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ReactComponentTemplate,
|
|
3
|
-
ReactHookTemplate,
|
|
4
|
-
ReactWebpackTemplate,
|
|
5
|
-
ReactViteTemplate,
|
|
6
|
-
ReactJSComponentTemplate,
|
|
7
|
-
ReactEnvTemplate,
|
|
8
|
-
ThemeTemplate,
|
|
9
|
-
} from '@bitdev/react.generators.react-templates';
|
|
10
|
-
import { EnvContext } from '@teambit/envs';
|
|
11
|
-
import { ComponentTemplate, TemplateList } from '@teambit/generator';
|
|
12
|
-
|
|
13
|
-
const templateListHandler = TemplateList.from([
|
|
14
|
-
ReactComponentTemplate.from({ env: 'bitdev.react/react-env' }),
|
|
15
|
-
ReactViteTemplate.from({ env: 'bitdev.react/react-env' }),
|
|
16
|
-
ReactHookTemplate.from({ env: 'bitdev.react/react-env' }),
|
|
17
|
-
ThemeTemplate.from({ env: 'bitdev.react/react-env' }),
|
|
18
|
-
// ReactContextTemplate.from({ env: 'bitdev.react/react-env' }),
|
|
19
|
-
ReactWebpackTemplate.from({ env: 'bitdev.react/react-env' }),
|
|
20
|
-
// ReactWebpackAppTemplate.from({ env: 'bitdev.react/react-env' }),
|
|
21
|
-
ReactJSComponentTemplate.from({ env: 'bitdev.react/react-env' }),
|
|
22
|
-
ReactEnvTemplate.from(),
|
|
23
|
-
]);
|
|
24
|
-
|
|
25
|
-
export function getTemplates(envContext: EnvContext): ComponentTemplate[] {
|
|
26
|
-
const templateList = templateListHandler(envContext);
|
|
27
|
-
return templateList.compute();
|
|
28
|
-
}
|
|
File without changes
|
|
File without changes
|