@teambit/react 0.0.555 → 0.0.556

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 (94) hide show
  1. package/package.json +49 -43
  2. package/compositions-app.tsx +0 -31
  3. package/eslint/eslintrc.js +0 -12
  4. package/highlighter-widget.tsx +0 -19
  5. package/index.ts +0 -9
  6. package/jest/css-transform.js +0 -12
  7. package/jest/file-transform.js +0 -38
  8. package/jest/jest.config.js +0 -30
  9. package/jest/setupTests.js +0 -7
  10. package/jest/transformer.js +0 -41
  11. package/mount.tsx +0 -17
  12. package/package-tar/teambit-react-0.0.555.tgz +0 -0
  13. package/prettier/prettier.config.js +0 -5
  14. package/react-app-options.ts +0 -45
  15. package/react.app-type.ts +0 -19
  16. package/react.application.ts +0 -96
  17. package/react.aspect.ts +0 -5
  18. package/react.composition.tsx +0 -7
  19. package/react.docs.mdx +0 -8
  20. package/react.env.ts +0 -363
  21. package/react.graphql.ts +0 -52
  22. package/react.main.runtime.ts +0 -437
  23. package/react.preview.runtime.ts +0 -44
  24. package/react.templates.ts +0 -29
  25. package/react.ui.runtime.tsx +0 -35
  26. package/templates/react-app/files/app-root.ts +0 -10
  27. package/templates/react-app/files/app.ts +0 -30
  28. package/templates/react-app/files/aspect.ts +0 -10
  29. package/templates/react-app/files/compositions.ts +0 -11
  30. package/templates/react-app/files/doc.ts +0 -29
  31. package/templates/react-app/files/index.ts +0 -10
  32. package/templates/react-app/files/main.runtime.ts +0 -22
  33. package/templates/react-app/index.ts +0 -47
  34. package/templates/react-component/files/component.ts +0 -25
  35. package/templates/react-component/files/composition.ts +0 -16
  36. package/templates/react-component/files/docs.ts +0 -32
  37. package/templates/react-component/files/test.ts +0 -19
  38. package/templates/react-component/index.ts +0 -40
  39. package/templates/react-component-js/files/component.ts +0 -18
  40. package/templates/react-component-js/files/composition.ts +0 -16
  41. package/templates/react-component-js/files/docs.ts +0 -32
  42. package/templates/react-component-js/files/test.ts +0 -21
  43. package/templates/react-component-js/index.ts +0 -38
  44. package/templates/react-context/files/composition.ts +0 -27
  45. package/templates/react-context/files/context-provider.ts +0 -27
  46. package/templates/react-context/files/context.ts +0 -21
  47. package/templates/react-context/files/docs.ts +0 -51
  48. package/templates/react-context/files/test.ts +0 -18
  49. package/templates/react-context/index.ts +0 -32
  50. package/templates/react-env/files/aspect.ts +0 -10
  51. package/templates/react-env/files/doc.ts +0 -163
  52. package/templates/react-env/files/index.ts +0 -10
  53. package/templates/react-env/files/jest.config.ts +0 -21
  54. package/templates/react-env/files/main.runtime.ts +0 -84
  55. package/templates/react-env/files/preview.runtime.ts +0 -27
  56. package/templates/react-env/files/typescript.config.ts +0 -21
  57. package/templates/react-env/files/webpack.config.ts +0 -48
  58. package/templates/react-env/index.ts +0 -51
  59. package/templates/react-hook/files/component.ts +0 -16
  60. package/templates/react-hook/files/composition.ts +0 -23
  61. package/templates/react-hook/files/docs.ts +0 -33
  62. package/templates/react-hook/files/test.ts +0 -20
  63. package/templates/react-hook/index.ts +0 -21
  64. package/templates/react-workspace/index.ts +0 -27
  65. package/templates/react-workspace-app/index.ts +0 -20
  66. package/templates/react-workspace-deprecated/index.ts +0 -28
  67. package/templates/react-workspace-lib/index.ts +0 -21
  68. package/templates/workspace-common/files/eslint-config.ts +0 -6
  69. package/templates/workspace-common/files/git-ignore.ts +0 -113
  70. package/templates/workspace-common/files/prettier-config.ts +0 -5
  71. package/templates/workspace-common/files/readme-file.ts +0 -36
  72. package/templates/workspace-common/files/ts-config.ts +0 -7
  73. package/templates/workspace-common/files/types/asset.ts +0 -28
  74. package/templates/workspace-common/files/types/style.ts +0 -43
  75. package/templates/workspace-common/files/workspace-config.ts +0 -58
  76. package/templates/workspace-common/generate-files.ts +0 -51
  77. package/templates/workspace-common/index.ts +0 -1
  78. package/tsconfig.json +0 -34
  79. package/types/asset.d.ts +0 -29
  80. package/types/style.d.ts +0 -42
  81. package/typescript/asset.d.ts +0 -29
  82. package/typescript/style.d.ts +0 -42
  83. package/typescript/tsconfig.build.json +0 -22
  84. package/typescript/tsconfig.json +0 -18
  85. package/webpack/format-webpack-messages.js +0 -102
  86. package/webpack/launch-editor-endpoint.js +0 -8
  87. package/webpack/postcss.config.ts +0 -21
  88. package/webpack/react-hot-dev-client.js +0 -274
  89. package/webpack/refresh.js +0 -16
  90. package/webpack/webpack.config.base.prod.ts +0 -123
  91. package/webpack/webpack.config.base.ts +0 -365
  92. package/webpack/webpack.config.component.dev.ts +0 -104
  93. package/webpack/webpack.config.component.prod.ts +0 -39
  94. package/webpack/webpack.config.env.dev.ts +0 -21
package/react.env.ts DELETED
@@ -1,363 +0,0 @@
1
- import ts, { TsConfigSourceFile } from 'typescript';
2
- import { tmpdir } from 'os';
3
- import { Component } from '@teambit/component';
4
- import { ComponentUrl } from '@teambit/component.modules.component-url';
5
- import { BuildTask } from '@teambit/builder';
6
- import { merge } from 'lodash';
7
- import { Bundler, BundlerContext, DevServer, DevServerContext } from '@teambit/bundler';
8
- import { CompilerMain } from '@teambit/compiler';
9
- import {
10
- BuilderEnv,
11
- CompilerEnv,
12
- DependenciesEnv,
13
- DevEnv,
14
- LinterEnv,
15
- PackageEnv,
16
- TesterEnv,
17
- FormatterEnv,
18
- PipeServiceModifier,
19
- PipeServiceModifiersMap,
20
- } from '@teambit/envs';
21
- import { JestMain } from '@teambit/jest';
22
- import { PkgMain } from '@teambit/pkg';
23
- import { Tester, TesterMain } from '@teambit/tester';
24
- import { TsConfigTransformer, TypescriptMain } from '@teambit/typescript';
25
- import type { TypeScriptCompilerOptions } from '@teambit/typescript';
26
- import { WebpackConfigTransformer, WebpackMain } from '@teambit/webpack';
27
- import { Workspace } from '@teambit/workspace';
28
- import { ESLintMain, EslintConfigTransformer } from '@teambit/eslint';
29
- import { PrettierConfigTransformer, PrettierMain } from '@teambit/prettier';
30
- import { Linter, LinterContext } from '@teambit/linter';
31
- import { Formatter, FormatterContext } from '@teambit/formatter';
32
- import { pathNormalizeToLinux } from '@teambit/legacy/dist/utils';
33
- import type { ComponentMeta } from '@teambit/react.babel.bit-react-transformer';
34
- import { SchemaExtractor } from '@teambit/schema';
35
- import { join, resolve } from 'path';
36
- import { outputFileSync } from 'fs-extra';
37
- import { Configuration } from 'webpack';
38
- // Makes sure the @teambit/react.ui.docs-app is a dependency
39
- // TODO: remove this import once we can set policy from component to component with workspace version. Then set it via the component.json
40
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
41
- import { ReactMainConfig } from './react.main.runtime';
42
- import { ReactAspect } from './react.aspect';
43
-
44
- // webpack configs for both components and envs
45
- import basePreviewConfigFactory from './webpack/webpack.config.base';
46
- import basePreviewProdConfigFactory from './webpack/webpack.config.base.prod';
47
-
48
- // webpack configs for envs only
49
- // import devPreviewConfigFactory from './webpack/webpack.config.preview.dev';
50
- import envPreviewDevConfigFactory from './webpack/webpack.config.env.dev';
51
-
52
- // webpack configs for components only
53
- import componentPreviewProdConfigFactory from './webpack/webpack.config.component.prod';
54
- import componentPreviewDevConfigFactory from './webpack/webpack.config.component.dev';
55
-
56
- export const AspectEnvType = 'react';
57
- const defaultTsConfig = require('./typescript/tsconfig.json');
58
- const buildTsConfig = require('./typescript/tsconfig.build.json');
59
- const eslintConfig = require('./eslint/eslintrc');
60
- const prettierConfig = require('./prettier/prettier.config.js');
61
-
62
- // TODO: move to be taken from the key mode of compiler context
63
- type CompilerMode = 'build' | 'dev';
64
-
65
- type GetBuildPipeModifiers = PipeServiceModifiersMap & {
66
- tsModifier?: PipeServiceModifier;
67
- };
68
-
69
- /**
70
- * a component environment built for [React](https://reactjs.org) .
71
- */
72
- export class ReactEnv
73
- implements TesterEnv, CompilerEnv, LinterEnv, DevEnv, BuilderEnv, DependenciesEnv, PackageEnv, FormatterEnv
74
- {
75
- constructor(
76
- /**
77
- * jest extension
78
- */
79
- private jestAspect: JestMain,
80
-
81
- /**
82
- * typescript extension.
83
- */
84
- private tsAspect: TypescriptMain,
85
-
86
- /**
87
- * compiler extension.
88
- */
89
- private compiler: CompilerMain,
90
-
91
- /**
92
- * webpack extension.
93
- */
94
- private webpack: WebpackMain,
95
-
96
- /**
97
- * workspace extension.
98
- */
99
- private workspace: Workspace,
100
-
101
- /**
102
- * pkg extension.
103
- */
104
- private pkg: PkgMain,
105
-
106
- /**
107
- * tester extension
108
- */
109
- private tester: TesterMain,
110
-
111
- private config: ReactMainConfig,
112
-
113
- private eslint: ESLintMain,
114
-
115
- private prettier: PrettierMain
116
- ) {}
117
-
118
- getTsConfig(targetTsConfig?: TsConfigSourceFile): TsConfigSourceFile {
119
- return targetTsConfig ? merge({}, defaultTsConfig, targetTsConfig) : defaultTsConfig;
120
- }
121
-
122
- getBuildTsConfig(targetTsConfig?: TsConfigSourceFile): TsConfigSourceFile {
123
- return targetTsConfig ? merge({}, buildTsConfig, targetTsConfig) : buildTsConfig;
124
- }
125
-
126
- /**
127
- * returns a component tester.
128
- */
129
- getTester(jestConfigPath: string, jestModulePath?: string): Tester {
130
- const config = jestConfigPath || require.resolve('./jest/jest.config');
131
- return this.jestAspect.createTester(config, jestModulePath || require.resolve('jest'));
132
- }
133
-
134
- private getTsCompilerOptions(mode: CompilerMode = 'dev'): TypeScriptCompilerOptions {
135
- const tsconfig = mode === 'dev' ? defaultTsConfig : buildTsConfig;
136
- const pathToSource = pathNormalizeToLinux(__dirname).replace('/dist/', '/src/');
137
- const compileJs = true;
138
- const compileJsx = true;
139
- return {
140
- tsconfig,
141
- // TODO: @david please remove this line and refactor to be something that makes sense.
142
- types: [resolve(pathToSource, './typescript/style.d.ts'), resolve(pathToSource, './typescript/asset.d.ts')],
143
- compileJs,
144
- compileJsx,
145
- };
146
- }
147
-
148
- private getTsCompiler(mode: CompilerMode = 'dev', transformers: TsConfigTransformer[] = [], tsModule = ts) {
149
- const tsCompileOptions = this.getTsCompilerOptions(mode);
150
- return this.tsAspect.createCompiler(tsCompileOptions, transformers, tsModule);
151
- }
152
-
153
- getCompiler(transformers: TsConfigTransformer[] = [], tsModule = ts) {
154
- return this.getTsCompiler('dev', transformers, tsModule);
155
- }
156
-
157
- /**
158
- * returns and configures the component linter.
159
- */
160
- getLinter(context: LinterContext, transformers: EslintConfigTransformer[] = []): Linter {
161
- const defaultTransformer: EslintConfigTransformer = (configMutator) => {
162
- configMutator.addExtensionTypes(['.md', '.mdx']);
163
- return configMutator;
164
- };
165
-
166
- const allTransformers = [defaultTransformer, ...transformers];
167
-
168
- return this.eslint.createLinter(
169
- context,
170
- {
171
- config: eslintConfig,
172
- // resolve all plugins from the react environment.
173
- pluginPath: __dirname,
174
- },
175
- allTransformers
176
- );
177
- }
178
-
179
- /**
180
- * returns and configures the component formatter.
181
- */
182
- getFormatter(context: FormatterContext, transformers: PrettierConfigTransformer[] = []): Formatter {
183
- return this.prettier.createFormatter(
184
- context,
185
- {
186
- config: prettierConfig,
187
- },
188
- transformers
189
- );
190
- }
191
-
192
- private getFileMap(components: Component[], local = false) {
193
- return components.reduce<{ [key: string]: ComponentMeta }>((index, component: Component) => {
194
- component.state.filesystem.files.forEach((file) => {
195
- index[file.path] = {
196
- id: component.id.toString(),
197
- homepage: local ? `/${component.id.fullName}` : ComponentUrl.toUrl(component.id),
198
- };
199
- });
200
-
201
- return index;
202
- }, {});
203
- }
204
-
205
- private writeFileMap(components: Component[], local?: boolean) {
206
- const fileMap = this.getFileMap(components, local);
207
- const path = join(tmpdir(), `${Math.random().toString(36).substr(2, 9)}.json`);
208
- outputFileSync(path, JSON.stringify(fileMap));
209
- return path;
210
- }
211
-
212
- /**
213
- * required for `bit start`
214
- */
215
- getDevEnvId(id?: string) {
216
- if (typeof id !== 'string') return ReactAspect.id;
217
- return id || ReactAspect.id;
218
- }
219
-
220
- /**
221
- * get a schema generator instance configured with the correct tsconfig.
222
- */
223
- getSchemaExtractor(tsconfig: TsConfigSourceFile): SchemaExtractor {
224
- return this.tsAspect.createSchemaExtractor(this.getTsConfig(tsconfig));
225
- }
226
-
227
- /**
228
- * returns and configures the React component dev server.
229
- * required for `bit start`
230
- */
231
- getDevServer(context: DevServerContext, transformers: WebpackConfigTransformer[] = []): DevServer {
232
- const baseConfig = basePreviewConfigFactory(false);
233
- const envDevConfig = envPreviewDevConfigFactory(context.id);
234
- const componentsDirs = this.getComponentsModulesDirectories(context.components);
235
- // const fileMapPath = this.writeFileMap(context.components, true);
236
- // const componentDevConfig = componentPreviewDevConfigFactory(fileMapPath, this.workspace.path);
237
- // const componentDevConfig = componentPreviewDevConfigFactory(this.workspace.path, context.id);
238
- const componentDevConfig = componentPreviewDevConfigFactory(this.workspace.path, context.id, componentsDirs);
239
-
240
- const defaultTransformer: WebpackConfigTransformer = (configMutator) => {
241
- const merged = configMutator.merge([baseConfig, envDevConfig, componentDevConfig]);
242
- return merged;
243
- };
244
-
245
- return this.webpack.createDevServer(context, [defaultTransformer, ...transformers]);
246
- }
247
-
248
- async getBundler(context: BundlerContext, transformers: WebpackConfigTransformer[] = []): Promise<Bundler> {
249
- // const fileMapPath = this.writeFileMap(context.components);
250
- const baseConfig = basePreviewConfigFactory(true);
251
- const baseProdConfig = basePreviewProdConfigFactory();
252
- // const componentProdConfig = componentPreviewProdConfigFactory(fileMapPath);
253
- const componentProdConfig = componentPreviewProdConfigFactory();
254
-
255
- const defaultTransformer: WebpackConfigTransformer = (configMutator) => {
256
- const merged = configMutator.merge([baseConfig, baseProdConfig, componentProdConfig]);
257
- return merged;
258
- };
259
-
260
- return this.webpack.createPreviewBundler(context, [defaultTransformer, ...transformers]);
261
- }
262
-
263
- private getComponentsModulesDirectories(components: Component[]): string[] {
264
- const dirs = components.map((component) => {
265
- return this.pkg.getModulePath(component, { absPath: true });
266
- });
267
- return dirs;
268
- }
269
-
270
- private getEntriesFromWebpackConfig(config?: Configuration): string[] {
271
- if (!config || !config.entry) {
272
- return [];
273
- }
274
- if (typeof config.entry === 'string') {
275
- return [config.entry];
276
- }
277
- if (Array.isArray(config.entry)) {
278
- let entries: string[] = [];
279
- entries = config.entry.reduce((acc, entry) => {
280
- if (typeof entry === 'string') {
281
- acc.push(entry);
282
- }
283
- return acc;
284
- }, entries);
285
- return entries;
286
- }
287
- return [];
288
- }
289
-
290
- /**
291
- * returns a path to a docs template.
292
- */
293
- getDocsTemplate() {
294
- return require.resolve('@teambit/react.ui.docs-app');
295
- }
296
-
297
- icon = 'https://static.bit.dev/extensions-icons/react.svg';
298
-
299
- /**
300
- * returns a paths to a function which mounts a given component to DOM
301
- */
302
- getMounter() {
303
- return require.resolve('./mount');
304
- }
305
-
306
- /**
307
- * define the package json properties to add to each component.
308
- */
309
- getPackageJsonProps() {
310
- return this.tsAspect.getPackageJsonProps();
311
- }
312
-
313
- /**
314
- * adds dependencies to all configured components.
315
- */
316
- getDependencies() {
317
- return {
318
- dependencies: {
319
- react: '-',
320
- 'react-dom': '-',
321
- 'core-js': '^3.0.0',
322
- },
323
- // TODO: add this only if using ts
324
- devDependencies: {
325
- react: '-',
326
- 'react-dom': '-',
327
- '@types/mocha': '-',
328
- '@types/node': '12.20.4',
329
- '@types/react': '^17.0.8',
330
- '@types/react-dom': '^17.0.5',
331
- '@types/jest': '^26.0.0',
332
- // '@types/react-router-dom': '^5.0.0', // TODO - should not be here (!)
333
- // This is added as dev dep since our jest file transformer uses babel plugins that require this to be installed
334
- '@babel/runtime': '7.12.18',
335
- '@types/testing-library__jest-dom': '5.9.5',
336
- },
337
- peerDependencies: {
338
- react: '^16.8.0 || ^17.0.0',
339
- 'react-dom': '^16.8.0 || ^17.0.0',
340
- },
341
- };
342
- }
343
-
344
- /**
345
- * returns the component build pipeline.
346
- */
347
- getBuildPipe(modifiers: GetBuildPipeModifiers = {}): BuildTask[] {
348
- const transformers: TsConfigTransformer[] =
349
- (modifiers?.tsModifier?.transformers as any as TsConfigTransformer[]) || [];
350
- return [this.getCompilerTask(transformers, modifiers?.tsModifier?.module || ts), this.tester.task];
351
- }
352
-
353
- private getCompilerTask(transformers: TsConfigTransformer[] = [], tsModule = ts) {
354
- const tsCompiler = this.getTsCompiler('build', transformers, tsModule);
355
- return this.compiler.createTask('TSCompiler', tsCompiler);
356
- }
357
-
358
- async __getDescriptor() {
359
- return {
360
- type: AspectEnvType,
361
- };
362
- }
363
- }
package/react.graphql.ts DELETED
@@ -1,52 +0,0 @@
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
- }