@teambit/react 0.0.554 → 0.0.558
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/dist/mount.d.ts +5 -0
- package/dist/react-app-options.d.ts +25 -0
- package/dist/react.env.d.ts +87 -1
- package/dist/react.main.runtime.d.ts +89 -1
- package/package.json +51 -43
- package/tsconfig.json +1 -2
- package/compositions-app.tsx +0 -31
- package/eslint/eslintrc.js +0 -12
- package/highlighter-widget.tsx +0 -19
- package/index.ts +0 -9
- package/jest/css-transform.js +0 -12
- package/jest/file-transform.js +0 -38
- package/jest/jest.config.js +0 -30
- package/jest/setupTests.js +0 -7
- package/jest/transformer.js +0 -41
- package/mount.tsx +0 -17
- package/package-tar/teambit-react-0.0.554.tgz +0 -0
- package/prettier/prettier.config.js +0 -5
- package/react-app-options.ts +0 -45
- package/react.app-type.ts +0 -19
- package/react.application.ts +0 -96
- package/react.aspect.ts +0 -5
- package/react.composition.tsx +0 -7
- package/react.docs.mdx +0 -8
- package/react.env.ts +0 -363
- package/react.graphql.ts +0 -52
- package/react.main.runtime.ts +0 -437
- package/react.preview.runtime.ts +0 -44
- package/react.templates.ts +0 -29
- package/react.ui.runtime.tsx +0 -35
- package/templates/react-app/files/app-root.ts +0 -10
- package/templates/react-app/files/app.ts +0 -30
- package/templates/react-app/files/aspect.ts +0 -10
- package/templates/react-app/files/compositions.ts +0 -11
- package/templates/react-app/files/doc.ts +0 -29
- package/templates/react-app/files/index.ts +0 -10
- package/templates/react-app/files/main.runtime.ts +0 -22
- package/templates/react-app/index.ts +0 -47
- package/templates/react-component/files/component.ts +0 -25
- package/templates/react-component/files/composition.ts +0 -16
- package/templates/react-component/files/docs.ts +0 -32
- package/templates/react-component/files/test.ts +0 -19
- package/templates/react-component/index.ts +0 -40
- package/templates/react-component-js/files/component.ts +0 -18
- package/templates/react-component-js/files/composition.ts +0 -16
- package/templates/react-component-js/files/docs.ts +0 -32
- package/templates/react-component-js/files/test.ts +0 -21
- package/templates/react-component-js/index.ts +0 -38
- package/templates/react-context/files/composition.ts +0 -27
- package/templates/react-context/files/context-provider.ts +0 -27
- package/templates/react-context/files/context.ts +0 -21
- package/templates/react-context/files/docs.ts +0 -51
- package/templates/react-context/files/test.ts +0 -18
- package/templates/react-context/index.ts +0 -32
- package/templates/react-env/files/aspect.ts +0 -10
- package/templates/react-env/files/doc.ts +0 -163
- package/templates/react-env/files/index.ts +0 -10
- package/templates/react-env/files/jest.config.ts +0 -21
- package/templates/react-env/files/main.runtime.ts +0 -84
- package/templates/react-env/files/preview.runtime.ts +0 -27
- package/templates/react-env/files/typescript.config.ts +0 -21
- package/templates/react-env/files/webpack.config.ts +0 -48
- package/templates/react-env/index.ts +0 -51
- package/templates/react-hook/files/component.ts +0 -16
- package/templates/react-hook/files/composition.ts +0 -23
- package/templates/react-hook/files/docs.ts +0 -33
- package/templates/react-hook/files/test.ts +0 -20
- package/templates/react-hook/index.ts +0 -21
- package/templates/react-workspace/index.ts +0 -27
- package/templates/react-workspace-app/index.ts +0 -20
- package/templates/react-workspace-deprecated/index.ts +0 -28
- package/templates/react-workspace-lib/index.ts +0 -21
- package/templates/workspace-common/files/eslint-config.ts +0 -6
- package/templates/workspace-common/files/git-ignore.ts +0 -113
- package/templates/workspace-common/files/prettier-config.ts +0 -5
- package/templates/workspace-common/files/readme-file.ts +0 -36
- package/templates/workspace-common/files/ts-config.ts +0 -7
- package/templates/workspace-common/files/types/asset.ts +0 -28
- package/templates/workspace-common/files/types/style.ts +0 -43
- package/templates/workspace-common/files/workspace-config.ts +0 -58
- package/templates/workspace-common/generate-files.ts +0 -51
- package/templates/workspace-common/index.ts +0 -1
- package/types/asset.d.ts +0 -29
- package/types/style.d.ts +0 -42
- package/typescript/asset.d.ts +0 -29
- package/typescript/style.d.ts +0 -42
- package/typescript/tsconfig.build.json +0 -22
- package/typescript/tsconfig.json +0 -18
- package/webpack/format-webpack-messages.js +0 -102
- package/webpack/launch-editor-endpoint.js +0 -8
- package/webpack/postcss.config.ts +0 -21
- package/webpack/react-hot-dev-client.js +0 -274
- package/webpack/refresh.js +0 -16
- package/webpack/webpack.config.base.prod.ts +0 -123
- package/webpack/webpack.config.base.ts +0 -365
- package/webpack/webpack.config.component.dev.ts +0 -104
- package/webpack/webpack.config.component.prod.ts +0 -39
- package/webpack/webpack.config.env.dev.ts +0 -21
package/jest/transformer.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/* eslint-disable global-require */
|
|
2
|
-
const { transform } = require('@babel/core');
|
|
3
|
-
|
|
4
|
-
const presets = [
|
|
5
|
-
require('@babel/preset-react'),
|
|
6
|
-
require('@babel/preset-typescript'),
|
|
7
|
-
require('babel-preset-jest'),
|
|
8
|
-
[
|
|
9
|
-
require('@babel/preset-env'),
|
|
10
|
-
{
|
|
11
|
-
targets: {
|
|
12
|
-
node: 12,
|
|
13
|
-
},
|
|
14
|
-
useBuiltIns: 'usage',
|
|
15
|
-
corejs: 3,
|
|
16
|
-
},
|
|
17
|
-
],
|
|
18
|
-
];
|
|
19
|
-
const plugins = [
|
|
20
|
-
[require('@babel/plugin-transform-modules-commonjs')],
|
|
21
|
-
[require('babel-plugin-transform-typescript-metadata')],
|
|
22
|
-
[require('@babel/plugin-proposal-decorators'), { legacy: true }],
|
|
23
|
-
[require('@babel/plugin-transform-runtime')],
|
|
24
|
-
[require('@babel/plugin-proposal-object-rest-spread')],
|
|
25
|
-
[require('@babel/plugin-proposal-class-properties')],
|
|
26
|
-
];
|
|
27
|
-
|
|
28
|
-
module.exports = {
|
|
29
|
-
process(src, filename) {
|
|
30
|
-
const result = transform(src, {
|
|
31
|
-
sourceMap: 'inline',
|
|
32
|
-
filename,
|
|
33
|
-
presets,
|
|
34
|
-
plugins,
|
|
35
|
-
babelrc: false,
|
|
36
|
-
configFile: false,
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
return result ? result.code : src;
|
|
40
|
-
},
|
|
41
|
-
};
|
package/mount.tsx
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import ReactDOM from 'react-dom';
|
|
3
|
-
import { RenderingContext } from '@teambit/preview';
|
|
4
|
-
|
|
5
|
-
import { CompositionsApp } from './compositions-app';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* this mounts compositions into the DOM in the component preview.
|
|
9
|
-
* this function can be overridden through ReactAspect.overrideCompositionsMounter() API
|
|
10
|
-
* to apply custom logic for component DOM mounting.
|
|
11
|
-
*/
|
|
12
|
-
export default (Composition: React.ComponentType, previewContext: RenderingContext) => {
|
|
13
|
-
ReactDOM.render(
|
|
14
|
-
<CompositionsApp Composition={Composition} previewContext={previewContext} />,
|
|
15
|
-
document.getElementById('root')
|
|
16
|
-
);
|
|
17
|
-
};
|
|
Binary file
|
package/react-app-options.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { Bundler, DevServer } from '@teambit/bundler';
|
|
2
|
-
import { DeployContext } from '@teambit/application';
|
|
3
|
-
|
|
4
|
-
export type ReactAppOptions = {
|
|
5
|
-
/**
|
|
6
|
-
* name of the application.
|
|
7
|
-
*/
|
|
8
|
-
name: string;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* path to entry files of the application.
|
|
12
|
-
*/
|
|
13
|
-
entry: string[];
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* use server-side rendering for the app.
|
|
17
|
-
*/
|
|
18
|
-
ssr?: boolean;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* instance of bundler to use.
|
|
22
|
-
*/
|
|
23
|
-
bundler?: Bundler;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* instance of dev server to use.
|
|
27
|
-
*/
|
|
28
|
-
devServer?: DevServer;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* deploy function.
|
|
32
|
-
*/
|
|
33
|
-
deploy?: (context: DeployContext) => Promise<void>;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* prerender routes of application (will create static file for the route)
|
|
37
|
-
* e.g ['/plugins', '/learn', '/docs/quick-start]
|
|
38
|
-
*/
|
|
39
|
-
prerenderRoutes?: string[];
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* ranges of ports to use to run the app server.
|
|
43
|
-
*/
|
|
44
|
-
portRange?: number[];
|
|
45
|
-
};
|
package/react.app-type.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { ApplicationType } from '@teambit/application';
|
|
2
|
-
import { ReactEnv } from './react.env';
|
|
3
|
-
import { ReactAppOptions } from './react-app-options';
|
|
4
|
-
import { ReactApp } from './react.application';
|
|
5
|
-
|
|
6
|
-
export class ReactAppType implements ApplicationType<ReactAppOptions> {
|
|
7
|
-
constructor(readonly name: string, private reactEnv: ReactEnv) {}
|
|
8
|
-
|
|
9
|
-
createApp(options: ReactAppOptions) {
|
|
10
|
-
return new ReactApp(
|
|
11
|
-
options.name,
|
|
12
|
-
options.entry,
|
|
13
|
-
options.portRange || [3000, 4000],
|
|
14
|
-
this.reactEnv,
|
|
15
|
-
options.deploy,
|
|
16
|
-
options.prerenderRoutes
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
}
|
package/react.application.ts
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import PrerenderSPAPlugin from '@dreysolano/prerender-spa-plugin';
|
|
2
|
-
import { join, basename } from 'path';
|
|
3
|
-
import { Capsule } from '@teambit/isolator';
|
|
4
|
-
import { Application, AppContext, DeployContext } from '@teambit/application';
|
|
5
|
-
import { BuildContext } from '@teambit/builder';
|
|
6
|
-
import { Bundler, BundlerContext, DevServerContext } from '@teambit/bundler';
|
|
7
|
-
import { Port } from '@teambit/toolbox.network.get-port';
|
|
8
|
-
import { ReactEnv } from './react.env';
|
|
9
|
-
|
|
10
|
-
export class ReactApp implements Application {
|
|
11
|
-
constructor(
|
|
12
|
-
readonly name: string,
|
|
13
|
-
readonly entry: string[],
|
|
14
|
-
readonly portRange: number[],
|
|
15
|
-
private reactEnv: ReactEnv,
|
|
16
|
-
readonly deploy?: (context: DeployContext) => Promise<void>,
|
|
17
|
-
readonly prerenderRoutes?: string[]
|
|
18
|
-
) {}
|
|
19
|
-
|
|
20
|
-
applicationType = 'react';
|
|
21
|
-
|
|
22
|
-
async run(context: AppContext): Promise<number> {
|
|
23
|
-
const devServerContext = this.getDevServerContext(context);
|
|
24
|
-
const devServer = this.reactEnv.getDevServer(devServerContext, [
|
|
25
|
-
(configMutator) => {
|
|
26
|
-
// configMutator.addTopLevel('output', { publicPath: `/public/${this.name}` });
|
|
27
|
-
configMutator.addTopLevel('devServer', {
|
|
28
|
-
historyApiFallback: {
|
|
29
|
-
index: '/index.html',
|
|
30
|
-
disableDotRule: true,
|
|
31
|
-
},
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
if (!configMutator.raw.output) configMutator.raw.output = {};
|
|
35
|
-
configMutator.raw.output.publicPath = '/';
|
|
36
|
-
|
|
37
|
-
return configMutator;
|
|
38
|
-
},
|
|
39
|
-
]);
|
|
40
|
-
const [from, to] = this.portRange;
|
|
41
|
-
const port = await Port.getPort(from, to);
|
|
42
|
-
await devServer.listen(port);
|
|
43
|
-
return port;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async build(context: BuildContext, aspectId: string, appCapsule: Capsule): Promise<DeployContext> {
|
|
47
|
-
const reactEnv: ReactEnv = context.env;
|
|
48
|
-
const publicDir = join('applications', this.name, 'build');
|
|
49
|
-
const outputPath = join(appCapsule.path, publicDir);
|
|
50
|
-
const { distDir } = reactEnv.getCompiler();
|
|
51
|
-
const entries = this.entry.map((entry) => require.resolve(`${appCapsule.path}/${distDir}/${basename(entry)}`));
|
|
52
|
-
const bundlerContext: BundlerContext = Object.assign(context, {
|
|
53
|
-
targets: [
|
|
54
|
-
{
|
|
55
|
-
components: [appCapsule?.component],
|
|
56
|
-
entries,
|
|
57
|
-
outputPath,
|
|
58
|
-
},
|
|
59
|
-
],
|
|
60
|
-
entry: [],
|
|
61
|
-
rootPath: '/',
|
|
62
|
-
});
|
|
63
|
-
const bundler: Bundler = await reactEnv.getBundler(bundlerContext, [
|
|
64
|
-
(configMutator) => {
|
|
65
|
-
configMutator.addTopLevel('output', { path: join(outputPath, 'public'), publicPath: `/` });
|
|
66
|
-
configMutator.addPlugin(
|
|
67
|
-
new PrerenderSPAPlugin({
|
|
68
|
-
staticDir: join(outputPath, 'public'),
|
|
69
|
-
routes: this.prerenderRoutes,
|
|
70
|
-
postProcess(renderedRoute) {
|
|
71
|
-
renderedRoute.outputPath = join(outputPath, 'public', `${renderedRoute.originalRoute}.html`);
|
|
72
|
-
return renderedRoute;
|
|
73
|
-
},
|
|
74
|
-
})
|
|
75
|
-
);
|
|
76
|
-
return configMutator;
|
|
77
|
-
},
|
|
78
|
-
]);
|
|
79
|
-
await bundler.run();
|
|
80
|
-
const deployContext = Object.assign(context, {
|
|
81
|
-
applicationType: this.applicationType,
|
|
82
|
-
aspectId,
|
|
83
|
-
publicDir: join(appCapsule.path, publicDir, 'public'),
|
|
84
|
-
});
|
|
85
|
-
return deployContext;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
private getDevServerContext(context: AppContext): DevServerContext {
|
|
89
|
-
return Object.assign(context, {
|
|
90
|
-
entry: this.entry,
|
|
91
|
-
rootPath: '',
|
|
92
|
-
publicPath: `public/${this.name}`,
|
|
93
|
-
title: this.name,
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
}
|
package/react.aspect.ts
DELETED
package/react.composition.tsx
DELETED
package/react.docs.mdx
DELETED
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
|
-
}
|