@teambit/react 0.0.558 → 0.0.562

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.
@@ -1 +1 @@
1
- {"version":3,"sources":["react.env.ts"],"names":["AspectEnvType","defaultTsConfig","require","buildTsConfig","eslintConfig","prettierConfig","ReactEnv","constructor","jestAspect","tsAspect","compiler","webpack","workspace","pkg","tester","config","eslint","prettier","getTsConfig","targetTsConfig","getBuildTsConfig","getTester","jestConfigPath","jestModulePath","resolve","createTester","getTsCompilerOptions","mode","tsconfig","pathToSource","__dirname","replace","compileJs","compileJsx","types","getTsCompiler","transformers","tsModule","ts","tsCompileOptions","createCompiler","getCompiler","getLinter","context","defaultTransformer","configMutator","addExtensionTypes","allTransformers","createLinter","pluginPath","getFormatter","createFormatter","getFileMap","components","local","reduce","index","component","state","filesystem","files","forEach","file","path","id","toString","homepage","fullName","ComponentUrl","toUrl","writeFileMap","fileMap","Math","random","substr","JSON","stringify","getDevEnvId","ReactAspect","getSchemaExtractor","createSchemaExtractor","getDevServer","baseConfig","envDevConfig","componentsDirs","getComponentsModulesDirectories","componentDevConfig","merged","merge","createDevServer","getBundler","baseProdConfig","componentProdConfig","createPreviewBundler","dirs","map","getModulePath","absPath","getEntriesFromWebpackConfig","entry","Array","isArray","entries","acc","push","getDocsTemplate","getMounter","getPackageJsonProps","getDependencies","dependencies","react","devDependencies","peerDependencies","getBuildPipe","modifiers","tsModifier","getCompilerTask","module","task","tsCompiler","createTask","__getDescriptor","type"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AA0BA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AA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AAa,GAFD;AAGZ,mBAAW;AAHC,OADT;AAML;AACAC,MAAAA,eAAe,EAAE;AACfD,QAAAA,KAAK,EAAE,GADQ;AAEf,qBAAa,GAFE;AAGf,wBAAgB,GAHD;AAIf,uBAAe,SAJA;AAKf,wBAAgB,SALD;AAMf,4BAAoB,SANL;AAOf,uBAAe,SAPA;AAQf;AACA;AACA,0BAAkB,SAVH;AAWf,4CAAoC;AAXrB,OAPZ;AAoBLE,MAAAA,gBAAgB,EAAE;AAChBF,QAAAA,KAAK,EAAE,oBADS;AAEhB,qBAAa;AAFG;AApBb,KAAP;AAyBD;AAED;AACF;AACA;;;AACEG,EAAAA,YAAY,CAACC,SAAgC,GAAG,EAApC,EAAqD;AAAA;;AAC/D,UAAM9E,YAAmC,GACvC,CAAC8E,SAAD,aAACA,SAAD,gDAACA,SAAS,CAAEC,UAAZ,0DAAC,sBAAuB/E,YAAxB,KAAyE,EAD3E;AAEA,WAAO,CAAC,KAAKgF,eAAL,CAAqBhF,YAArB,EAAmC,CAAA8E,SAAS,SAAT,IAAAA,SAAS,WAAT,sCAAAA,SAAS,CAAEC,UAAX,kFAAuBE,MAAvB,KAAiC/E,qBAApE,CAAD,EAA0E,KAAKxB,MAAL,CAAYwG,IAAtF,CAAP;AACD;;AAEOF,EAAAA,eAAe,CAAChF,YAAmC,GAAG,EAAvC,EAA2CC,QAAQ,GAAGC,qBAAtD,EAA0D;AAC/E,UAAMiF,UAAU,GAAG,KAAKpF,aAAL,CAAmB,OAAnB,EAA4BC,YAA5B,EAA0CC,QAA1C,CAAnB;AACA,WAAO,KAAK3B,QAAL,CAAc8G,UAAd,CAAyB,YAAzB,EAAuCD,UAAvC,CAAP;AACD;;AAEoB,QAAfE,eAAe,GAAG;AACtB,WAAO;AACLC,MAAAA,IAAI,EAAE1H;AADD,KAAP;AAGD;;AAhSH","sourcesContent":["import ts, { TsConfigSourceFile } from 'typescript';\nimport { tmpdir } from 'os';\nimport { Component } from '@teambit/component';\nimport { ComponentUrl } from '@teambit/component.modules.component-url';\nimport { BuildTask } from '@teambit/builder';\nimport { merge } from 'lodash';\nimport { Bundler, BundlerContext, DevServer, DevServerContext } from '@teambit/bundler';\nimport { CompilerMain } from '@teambit/compiler';\nimport {\n BuilderEnv,\n CompilerEnv,\n DependenciesEnv,\n DevEnv,\n LinterEnv,\n PackageEnv,\n TesterEnv,\n FormatterEnv,\n PipeServiceModifier,\n PipeServiceModifiersMap,\n} from '@teambit/envs';\nimport { JestMain } from '@teambit/jest';\nimport { PkgMain } from '@teambit/pkg';\nimport { Tester, TesterMain } from '@teambit/tester';\nimport { TsConfigTransformer, TypescriptMain } from '@teambit/typescript';\nimport type { TypeScriptCompilerOptions } from '@teambit/typescript';\nimport { WebpackConfigTransformer, WebpackMain } from '@teambit/webpack';\nimport { Workspace } from '@teambit/workspace';\nimport { ESLintMain, EslintConfigTransformer } from '@teambit/eslint';\nimport { PrettierConfigTransformer, PrettierMain } from '@teambit/prettier';\nimport { Linter, LinterContext } from '@teambit/linter';\nimport { Formatter, FormatterContext } from '@teambit/formatter';\nimport { pathNormalizeToLinux } from '@teambit/legacy/dist/utils';\nimport type { ComponentMeta } from '@teambit/react.babel.bit-react-transformer';\nimport { SchemaExtractor } from '@teambit/schema';\nimport { join, resolve } from 'path';\nimport { outputFileSync } from 'fs-extra';\nimport { Configuration } from 'webpack';\n// Makes sure the @teambit/react.ui.docs-app is a dependency\n// TODO: remove this import once we can set policy from component to component with workspace version. Then set it via the component.json\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nimport { ReactMainConfig } from './react.main.runtime';\nimport { ReactAspect } from './react.aspect';\n\n// webpack configs for both components and envs\nimport basePreviewConfigFactory from './webpack/webpack.config.base';\nimport basePreviewProdConfigFactory from './webpack/webpack.config.base.prod';\n\n// webpack configs for envs only\n// import devPreviewConfigFactory from './webpack/webpack.config.preview.dev';\nimport envPreviewDevConfigFactory from './webpack/webpack.config.env.dev';\n\n// webpack configs for components only\nimport componentPreviewProdConfigFactory from './webpack/webpack.config.component.prod';\nimport componentPreviewDevConfigFactory from './webpack/webpack.config.component.dev';\n\nexport const AspectEnvType = 'react';\nconst defaultTsConfig = require('./typescript/tsconfig.json');\nconst buildTsConfig = require('./typescript/tsconfig.build.json');\nconst eslintConfig = require('./eslint/eslintrc');\nconst prettierConfig = require('./prettier/prettier.config.js');\n\n// TODO: move to be taken from the key mode of compiler context\ntype CompilerMode = 'build' | 'dev';\n\ntype GetBuildPipeModifiers = PipeServiceModifiersMap & {\n tsModifier?: PipeServiceModifier;\n};\n\n/**\n * a component environment built for [React](https://reactjs.org) .\n */\nexport class ReactEnv\n implements TesterEnv, CompilerEnv, LinterEnv, DevEnv, BuilderEnv, DependenciesEnv, PackageEnv, FormatterEnv\n{\n constructor(\n /**\n * jest extension\n */\n private jestAspect: JestMain,\n\n /**\n * typescript extension.\n */\n private tsAspect: TypescriptMain,\n\n /**\n * compiler extension.\n */\n private compiler: CompilerMain,\n\n /**\n * webpack extension.\n */\n private webpack: WebpackMain,\n\n /**\n * workspace extension.\n */\n private workspace: Workspace,\n\n /**\n * pkg extension.\n */\n private pkg: PkgMain,\n\n /**\n * tester extension\n */\n private tester: TesterMain,\n\n private config: ReactMainConfig,\n\n private eslint: ESLintMain,\n\n private prettier: PrettierMain\n ) {}\n\n getTsConfig(targetTsConfig?: TsConfigSourceFile): TsConfigSourceFile {\n return targetTsConfig ? merge({}, defaultTsConfig, targetTsConfig) : defaultTsConfig;\n }\n\n getBuildTsConfig(targetTsConfig?: TsConfigSourceFile): TsConfigSourceFile {\n return targetTsConfig ? merge({}, buildTsConfig, targetTsConfig) : buildTsConfig;\n }\n\n /**\n * returns a component tester.\n */\n getTester(jestConfigPath: string, jestModulePath?: string): Tester {\n const config = jestConfigPath || require.resolve('./jest/jest.config');\n return this.jestAspect.createTester(config, jestModulePath || require.resolve('jest'));\n }\n\n private getTsCompilerOptions(mode: CompilerMode = 'dev'): TypeScriptCompilerOptions {\n const tsconfig = mode === 'dev' ? defaultTsConfig : buildTsConfig;\n const pathToSource = pathNormalizeToLinux(__dirname).replace('/dist/', '/src/');\n const compileJs = true;\n const compileJsx = true;\n return {\n tsconfig,\n // TODO: @david please remove this line and refactor to be something that makes sense.\n types: [resolve(pathToSource, './typescript/style.d.ts'), resolve(pathToSource, './typescript/asset.d.ts')],\n compileJs,\n compileJsx,\n };\n }\n\n private getTsCompiler(mode: CompilerMode = 'dev', transformers: TsConfigTransformer[] = [], tsModule = ts) {\n const tsCompileOptions = this.getTsCompilerOptions(mode);\n return this.tsAspect.createCompiler(tsCompileOptions, transformers, tsModule);\n }\n\n getCompiler(transformers: TsConfigTransformer[] = [], tsModule = ts) {\n return this.getTsCompiler('dev', transformers, tsModule);\n }\n\n /**\n * returns and configures the component linter.\n */\n getLinter(context: LinterContext, transformers: EslintConfigTransformer[] = []): Linter {\n const defaultTransformer: EslintConfigTransformer = (configMutator) => {\n configMutator.addExtensionTypes(['.md', '.mdx']);\n return configMutator;\n };\n\n const allTransformers = [defaultTransformer, ...transformers];\n\n return this.eslint.createLinter(\n context,\n {\n config: eslintConfig,\n // resolve all plugins from the react environment.\n pluginPath: __dirname,\n },\n allTransformers\n );\n }\n\n /**\n * returns and configures the component formatter.\n */\n getFormatter(context: FormatterContext, transformers: PrettierConfigTransformer[] = []): Formatter {\n return this.prettier.createFormatter(\n context,\n {\n config: prettierConfig,\n },\n transformers\n );\n }\n\n private getFileMap(components: Component[], local = false) {\n return components.reduce<{ [key: string]: ComponentMeta }>((index, component: Component) => {\n component.state.filesystem.files.forEach((file) => {\n index[file.path] = {\n id: component.id.toString(),\n homepage: local ? `/${component.id.fullName}` : ComponentUrl.toUrl(component.id),\n };\n });\n\n return index;\n }, {});\n }\n\n private writeFileMap(components: Component[], local?: boolean) {\n const fileMap = this.getFileMap(components, local);\n const path = join(tmpdir(), `${Math.random().toString(36).substr(2, 9)}.json`);\n outputFileSync(path, JSON.stringify(fileMap));\n return path;\n }\n\n /**\n * required for `bit start`\n */\n getDevEnvId(id?: string) {\n if (typeof id !== 'string') return ReactAspect.id;\n return id || ReactAspect.id;\n }\n\n /**\n * get a schema generator instance configured with the correct tsconfig.\n */\n getSchemaExtractor(tsconfig: TsConfigSourceFile): SchemaExtractor {\n return this.tsAspect.createSchemaExtractor(this.getTsConfig(tsconfig));\n }\n\n /**\n * returns and configures the React component dev server.\n * required for `bit start`\n */\n getDevServer(context: DevServerContext, transformers: WebpackConfigTransformer[] = []): DevServer {\n const baseConfig = basePreviewConfigFactory(false);\n const envDevConfig = envPreviewDevConfigFactory(context.id);\n const componentsDirs = this.getComponentsModulesDirectories(context.components);\n // const fileMapPath = this.writeFileMap(context.components, true);\n // const componentDevConfig = componentPreviewDevConfigFactory(fileMapPath, this.workspace.path);\n // const componentDevConfig = componentPreviewDevConfigFactory(this.workspace.path, context.id);\n const componentDevConfig = componentPreviewDevConfigFactory(this.workspace.path, context.id, componentsDirs);\n\n const defaultTransformer: WebpackConfigTransformer = (configMutator) => {\n const merged = configMutator.merge([baseConfig, envDevConfig, componentDevConfig]);\n return merged;\n };\n\n return this.webpack.createDevServer(context, [defaultTransformer, ...transformers]);\n }\n\n async getBundler(context: BundlerContext, transformers: WebpackConfigTransformer[] = []): Promise<Bundler> {\n // const fileMapPath = this.writeFileMap(context.components);\n const baseConfig = basePreviewConfigFactory(true);\n const baseProdConfig = basePreviewProdConfigFactory();\n // const componentProdConfig = componentPreviewProdConfigFactory(fileMapPath);\n const componentProdConfig = componentPreviewProdConfigFactory();\n\n const defaultTransformer: WebpackConfigTransformer = (configMutator) => {\n const merged = configMutator.merge([baseConfig, baseProdConfig, componentProdConfig]);\n return merged;\n };\n\n return this.webpack.createPreviewBundler(context, [defaultTransformer, ...transformers]);\n }\n\n private getComponentsModulesDirectories(components: Component[]): string[] {\n const dirs = components.map((component) => {\n return this.pkg.getModulePath(component, { absPath: true });\n });\n return dirs;\n }\n\n private getEntriesFromWebpackConfig(config?: Configuration): string[] {\n if (!config || !config.entry) {\n return [];\n }\n if (typeof config.entry === 'string') {\n return [config.entry];\n }\n if (Array.isArray(config.entry)) {\n let entries: string[] = [];\n entries = config.entry.reduce((acc, entry) => {\n if (typeof entry === 'string') {\n acc.push(entry);\n }\n return acc;\n }, entries);\n return entries;\n }\n return [];\n }\n\n /**\n * returns a path to a docs template.\n */\n getDocsTemplate() {\n return require.resolve('@teambit/react.ui.docs-app');\n }\n\n icon = 'https://static.bit.dev/extensions-icons/react.svg';\n\n /**\n * returns a paths to a function which mounts a given component to DOM\n */\n getMounter() {\n return require.resolve('./mount');\n }\n\n /**\n * define the package json properties to add to each component.\n */\n getPackageJsonProps() {\n return this.tsAspect.getPackageJsonProps();\n }\n\n /**\n * adds dependencies to all configured components.\n */\n getDependencies() {\n return {\n dependencies: {\n react: '-',\n 'react-dom': '-',\n 'core-js': '^3.0.0',\n },\n // TODO: add this only if using ts\n devDependencies: {\n react: '-',\n 'react-dom': '-',\n '@types/mocha': '-',\n '@types/node': '12.20.4',\n '@types/react': '^17.0.8',\n '@types/react-dom': '^17.0.5',\n '@types/jest': '^26.0.0',\n // '@types/react-router-dom': '^5.0.0', // TODO - should not be here (!)\n // This is added as dev dep since our jest file transformer uses babel plugins that require this to be installed\n '@babel/runtime': '7.12.18',\n '@types/testing-library__jest-dom': '5.9.5',\n },\n peerDependencies: {\n react: '^16.8.0 || ^17.0.0',\n 'react-dom': '^16.8.0 || ^17.0.0',\n },\n };\n }\n\n /**\n * returns the component build pipeline.\n */\n getBuildPipe(modifiers: GetBuildPipeModifiers = {}): BuildTask[] {\n const transformers: TsConfigTransformer[] =\n (modifiers?.tsModifier?.transformers as any as TsConfigTransformer[]) || [];\n return [this.getCompilerTask(transformers, modifiers?.tsModifier?.module || ts), this.tester.task];\n }\n\n private getCompilerTask(transformers: TsConfigTransformer[] = [], tsModule = ts) {\n const tsCompiler = this.getTsCompiler('build', transformers, tsModule);\n return this.compiler.createTask('TSCompiler', tsCompiler);\n }\n\n async __getDescriptor() {\n return {\n type: AspectEnvType,\n };\n }\n}\n"]}
1
+ {"version":3,"sources":["react.env.ts"],"names":["AspectEnvType","defaultTsConfig","require","buildTsConfig","eslintConfig","prettierConfig","ReactEnv","constructor","jestAspect","tsAspect","compiler","webpack","workspace","pkg","tester","config","eslint","prettier","getTsConfig","targetTsConfig","getBuildTsConfig","getTester","jestConfigPath","jestModulePath","resolve","createTester","getTsCompilerOptions","mode","tsconfig","pathToSource","__dirname","replace","compileJs","compileJsx","types","getTsCompiler","transformers","tsModule","ts","tsCompileOptions","createCompiler","getCompiler","getLinter","context","defaultTransformer","configMutator","addExtensionTypes","allTransformers","createLinter","pluginPath","getFormatter","createFormatter","getFileMap","components","local","reduce","index","component","state","filesystem","files","forEach","file","path","id","toString","homepage","fullName","ComponentUrl","toUrl","writeFileMap","fileMap","Math","random","substr","JSON","stringify","getDevEnvId","ReactAspect","getSchemaExtractor","createSchemaExtractor","getDevServer","baseConfig","envDevConfig","componentsDirs","getComponentsModulesDirectories","componentDevConfig","merged","merge","createDevServer","getBundler","baseProdConfig","componentProdConfig","createPreviewBundler","dirs","map","getModulePath","absPath","getEntriesFromWebpackConfig","entry","Array","isArray","entries","acc","push","getDocsTemplate","getMounter","getPackageJsonProps","getDependencies","dependencies","react","devDependencies","peerDependencies","getBuildPipe","modifiers","tsModifier","getCompilerTask","module","task","tsCompiler","createTask","__getDescriptor","type"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AA0BA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAMA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AA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AAGf,wBAAgB,GAHD;AAIf,uBAAe,SAJA;AAKf,wBAAgB,SALD;AAMf,4BAAoB,SANL;AAOf,uBAAe,SAPA;AAQf;AACA;AACA,0BAAkB,SAVH;AAWf,4CAAoC;AAXrB,OAPZ;AAoBLE,MAAAA,gBAAgB,EAAE;AAChBF,QAAAA,KAAK,EAAE,oBADS;AAEhB,qBAAa;AAFG;AApBb,KAAP;AAyBD;AAED;AACF;AACA;;;AACEG,EAAAA,YAAY,CAACC,SAAgC,GAAG,EAApC,EAAqD;AAAA;;AAC/D,UAAM9E,YAAmC,GACvC,CAAC8E,SAAD,aAACA,SAAD,gDAACA,SAAS,CAAEC,UAAZ,0DAAC,sBAAuB/E,YAAxB,KAAyE,EAD3E;AAEA,WAAO,CAAC,KAAKgF,eAAL,CAAqBhF,YAArB,EAAmC,CAAA8E,SAAS,SAAT,IAAAA,SAAS,WAAT,sCAAAA,SAAS,CAAEC,UAAX,kFAAuBE,MAAvB,KAAiC/E,qBAApE,CAAD,EAA0E,KAAKxB,MAAL,CAAYwG,IAAtF,CAAP;AACD;;AAEOF,EAAAA,eAAe,CAAChF,YAAmC,GAAG,EAAvC,EAA2CC,QAAQ,GAAGC,qBAAtD,EAA0D;AAC/E,UAAMiF,UAAU,GAAG,KAAKpF,aAAL,CAAmB,OAAnB,EAA4BC,YAA5B,EAA0CC,QAA1C,CAAnB;AACA,WAAO,KAAK3B,QAAL,CAAc8G,UAAd,CAAyB,YAAzB,EAAuCD,UAAvC,CAAP;AACD;;AAEoB,QAAfE,eAAe,GAAG;AACtB,WAAO;AACLC,MAAAA,IAAI,EAAE1H;AADD,KAAP;AAGD;;AAhSH","sourcesContent":["import ts, { TsConfigSourceFile } from 'typescript';\nimport { tmpdir } from 'os';\nimport { Component } from '@teambit/component';\nimport { ComponentUrl } from '@teambit/component.modules.component-url';\nimport { BuildTask } from '@teambit/builder';\nimport { merge } from 'lodash';\nimport { Bundler, BundlerContext, DevServer, DevServerContext } from '@teambit/bundler';\nimport { CompilerMain } from '@teambit/compiler';\nimport {\n BuilderEnv,\n CompilerEnv,\n DependenciesEnv,\n DevEnv,\n LinterEnv,\n PackageEnv,\n TesterEnv,\n FormatterEnv,\n PipeServiceModifier,\n PipeServiceModifiersMap,\n} from '@teambit/envs';\nimport { JestMain } from '@teambit/jest';\nimport { PkgMain } from '@teambit/pkg';\nimport { Tester, TesterMain } from '@teambit/tester';\nimport { TsConfigTransformer, TypescriptMain } from '@teambit/typescript';\nimport type { TypeScriptCompilerOptions } from '@teambit/typescript';\nimport { WebpackConfigTransformer, WebpackMain } from '@teambit/webpack';\nimport { Workspace } from '@teambit/workspace';\nimport { ESLintMain, EslintConfigTransformer } from '@teambit/eslint';\nimport { PrettierConfigTransformer, PrettierMain } from '@teambit/prettier';\nimport { Linter, LinterContext } from '@teambit/linter';\nimport { Formatter, FormatterContext } from '@teambit/formatter';\nimport { pathNormalizeToLinux } from '@teambit/legacy/dist/utils';\nimport type { ComponentMeta } from '@teambit/react.ui.highlighter.component-metadata.bit-component-meta';\nimport { SchemaExtractor } from '@teambit/schema';\nimport { join, resolve } from 'path';\nimport { outputFileSync } from 'fs-extra';\nimport { Configuration } from 'webpack';\n// Makes sure the @teambit/react.ui.docs-app is a dependency\n// TODO: remove this import once we can set policy from component to component with workspace version. Then set it via the component.json\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nimport { ReactMainConfig } from './react.main.runtime';\nimport { ReactAspect } from './react.aspect';\n\n// webpack configs for both components and envs\nimport basePreviewConfigFactory from './webpack/webpack.config.base';\nimport basePreviewProdConfigFactory from './webpack/webpack.config.base.prod';\n\n// webpack configs for envs only\n// import devPreviewConfigFactory from './webpack/webpack.config.preview.dev';\nimport envPreviewDevConfigFactory from './webpack/webpack.config.env.dev';\n\n// webpack configs for components only\nimport componentPreviewProdConfigFactory from './webpack/webpack.config.component.prod';\nimport componentPreviewDevConfigFactory from './webpack/webpack.config.component.dev';\n\nexport const AspectEnvType = 'react';\nconst defaultTsConfig = require('./typescript/tsconfig.json');\nconst buildTsConfig = require('./typescript/tsconfig.build.json');\nconst eslintConfig = require('./eslint/eslintrc');\nconst prettierConfig = require('./prettier/prettier.config.js');\n\n// TODO: move to be taken from the key mode of compiler context\ntype CompilerMode = 'build' | 'dev';\n\ntype GetBuildPipeModifiers = PipeServiceModifiersMap & {\n tsModifier?: PipeServiceModifier;\n};\n\n/**\n * a component environment built for [React](https://reactjs.org) .\n */\nexport class ReactEnv\n implements TesterEnv, CompilerEnv, LinterEnv, DevEnv, BuilderEnv, DependenciesEnv, PackageEnv, FormatterEnv\n{\n constructor(\n /**\n * jest extension\n */\n private jestAspect: JestMain,\n\n /**\n * typescript extension.\n */\n private tsAspect: TypescriptMain,\n\n /**\n * compiler extension.\n */\n private compiler: CompilerMain,\n\n /**\n * webpack extension.\n */\n private webpack: WebpackMain,\n\n /**\n * workspace extension.\n */\n private workspace: Workspace,\n\n /**\n * pkg extension.\n */\n private pkg: PkgMain,\n\n /**\n * tester extension\n */\n private tester: TesterMain,\n\n private config: ReactMainConfig,\n\n private eslint: ESLintMain,\n\n private prettier: PrettierMain\n ) {}\n\n getTsConfig(targetTsConfig?: TsConfigSourceFile): TsConfigSourceFile {\n return targetTsConfig ? merge({}, defaultTsConfig, targetTsConfig) : defaultTsConfig;\n }\n\n getBuildTsConfig(targetTsConfig?: TsConfigSourceFile): TsConfigSourceFile {\n return targetTsConfig ? merge({}, buildTsConfig, targetTsConfig) : buildTsConfig;\n }\n\n /**\n * returns a component tester.\n */\n getTester(jestConfigPath: string, jestModulePath?: string): Tester {\n const config = jestConfigPath || require.resolve('./jest/jest.config');\n return this.jestAspect.createTester(config, jestModulePath || require.resolve('jest'));\n }\n\n private getTsCompilerOptions(mode: CompilerMode = 'dev'): TypeScriptCompilerOptions {\n const tsconfig = mode === 'dev' ? defaultTsConfig : buildTsConfig;\n const pathToSource = pathNormalizeToLinux(__dirname).replace('/dist/', '/src/');\n const compileJs = true;\n const compileJsx = true;\n return {\n tsconfig,\n // TODO: @david please remove this line and refactor to be something that makes sense.\n types: [resolve(pathToSource, './typescript/style.d.ts'), resolve(pathToSource, './typescript/asset.d.ts')],\n compileJs,\n compileJsx,\n };\n }\n\n private getTsCompiler(mode: CompilerMode = 'dev', transformers: TsConfigTransformer[] = [], tsModule = ts) {\n const tsCompileOptions = this.getTsCompilerOptions(mode);\n return this.tsAspect.createCompiler(tsCompileOptions, transformers, tsModule);\n }\n\n getCompiler(transformers: TsConfigTransformer[] = [], tsModule = ts) {\n return this.getTsCompiler('dev', transformers, tsModule);\n }\n\n /**\n * returns and configures the component linter.\n */\n getLinter(context: LinterContext, transformers: EslintConfigTransformer[] = []): Linter {\n const defaultTransformer: EslintConfigTransformer = (configMutator) => {\n configMutator.addExtensionTypes(['.md', '.mdx']);\n return configMutator;\n };\n\n const allTransformers = [defaultTransformer, ...transformers];\n\n return this.eslint.createLinter(\n context,\n {\n config: eslintConfig,\n // resolve all plugins from the react environment.\n pluginPath: __dirname,\n },\n allTransformers\n );\n }\n\n /**\n * returns and configures the component formatter.\n */\n getFormatter(context: FormatterContext, transformers: PrettierConfigTransformer[] = []): Formatter {\n return this.prettier.createFormatter(\n context,\n {\n config: prettierConfig,\n },\n transformers\n );\n }\n\n private getFileMap(components: Component[], local = false) {\n return components.reduce<{ [key: string]: ComponentMeta }>((index, component: Component) => {\n component.state.filesystem.files.forEach((file) => {\n index[file.path] = {\n id: component.id.toString(),\n homepage: local ? `/${component.id.fullName}` : ComponentUrl.toUrl(component.id),\n };\n });\n\n return index;\n }, {});\n }\n\n private writeFileMap(components: Component[], local?: boolean) {\n const fileMap = this.getFileMap(components, local);\n const path = join(tmpdir(), `${Math.random().toString(36).substr(2, 9)}.json`);\n outputFileSync(path, JSON.stringify(fileMap));\n return path;\n }\n\n /**\n * required for `bit start`\n */\n getDevEnvId(id?: string) {\n if (typeof id !== 'string') return ReactAspect.id;\n return id || ReactAspect.id;\n }\n\n /**\n * get a schema generator instance configured with the correct tsconfig.\n */\n getSchemaExtractor(tsconfig: TsConfigSourceFile): SchemaExtractor {\n return this.tsAspect.createSchemaExtractor(this.getTsConfig(tsconfig));\n }\n\n /**\n * returns and configures the React component dev server.\n * required for `bit start`\n */\n getDevServer(context: DevServerContext, transformers: WebpackConfigTransformer[] = []): DevServer {\n const baseConfig = basePreviewConfigFactory(false);\n const envDevConfig = envPreviewDevConfigFactory(context.id);\n const componentsDirs = this.getComponentsModulesDirectories(context.components);\n // const fileMapPath = this.writeFileMap(context.components, true);\n // const componentDevConfig = componentPreviewDevConfigFactory(fileMapPath, this.workspace.path);\n // const componentDevConfig = componentPreviewDevConfigFactory(this.workspace.path, context.id);\n const componentDevConfig = componentPreviewDevConfigFactory(this.workspace.path, context.id, componentsDirs);\n\n const defaultTransformer: WebpackConfigTransformer = (configMutator) => {\n const merged = configMutator.merge([baseConfig, envDevConfig, componentDevConfig]);\n return merged;\n };\n\n return this.webpack.createDevServer(context, [defaultTransformer, ...transformers]);\n }\n\n async getBundler(context: BundlerContext, transformers: WebpackConfigTransformer[] = []): Promise<Bundler> {\n // const fileMapPath = this.writeFileMap(context.components);\n const baseConfig = basePreviewConfigFactory(true);\n const baseProdConfig = basePreviewProdConfigFactory();\n // const componentProdConfig = componentPreviewProdConfigFactory(fileMapPath);\n const componentProdConfig = componentPreviewProdConfigFactory();\n\n const defaultTransformer: WebpackConfigTransformer = (configMutator) => {\n const merged = configMutator.merge([baseConfig, baseProdConfig, componentProdConfig]);\n return merged;\n };\n\n return this.webpack.createPreviewBundler(context, [defaultTransformer, ...transformers]);\n }\n\n private getComponentsModulesDirectories(components: Component[]): string[] {\n const dirs = components.map((component) => {\n return this.pkg.getModulePath(component, { absPath: true });\n });\n return dirs;\n }\n\n private getEntriesFromWebpackConfig(config?: Configuration): string[] {\n if (!config || !config.entry) {\n return [];\n }\n if (typeof config.entry === 'string') {\n return [config.entry];\n }\n if (Array.isArray(config.entry)) {\n let entries: string[] = [];\n entries = config.entry.reduce((acc, entry) => {\n if (typeof entry === 'string') {\n acc.push(entry);\n }\n return acc;\n }, entries);\n return entries;\n }\n return [];\n }\n\n /**\n * returns a path to a docs template.\n */\n getDocsTemplate() {\n return require.resolve('@teambit/react.ui.docs-app');\n }\n\n icon = 'https://static.bit.dev/extensions-icons/react.svg';\n\n /**\n * returns a paths to a function which mounts a given component to DOM\n */\n getMounter() {\n return require.resolve('./mount');\n }\n\n /**\n * define the package json properties to add to each component.\n */\n getPackageJsonProps() {\n return this.tsAspect.getPackageJsonProps();\n }\n\n /**\n * adds dependencies to all configured components.\n */\n getDependencies() {\n return {\n dependencies: {\n react: '-',\n 'react-dom': '-',\n 'core-js': '^3.0.0',\n },\n // TODO: add this only if using ts\n devDependencies: {\n react: '-',\n 'react-dom': '-',\n '@types/mocha': '-',\n '@types/node': '12.20.4',\n '@types/react': '^17.0.8',\n '@types/react-dom': '^17.0.5',\n '@types/jest': '^26.0.0',\n // '@types/react-router-dom': '^5.0.0', // TODO - should not be here (!)\n // This is added as dev dep since our jest file transformer uses babel plugins that require this to be installed\n '@babel/runtime': '7.12.18',\n '@types/testing-library__jest-dom': '5.9.5',\n },\n peerDependencies: {\n react: '^16.8.0 || ^17.0.0',\n 'react-dom': '^16.8.0 || ^17.0.0',\n },\n };\n }\n\n /**\n * returns the component build pipeline.\n */\n getBuildPipe(modifiers: GetBuildPipeModifiers = {}): BuildTask[] {\n const transformers: TsConfigTransformer[] =\n (modifiers?.tsModifier?.transformers as any as TsConfigTransformer[]) || [];\n return [this.getCompilerTask(transformers, modifiers?.tsModifier?.module || ts), this.tester.task];\n }\n\n private getCompilerTask(transformers: TsConfigTransformer[] = [], tsModule = ts) {\n const tsCompiler = this.getTsCompiler('build', transformers, tsModule);\n return this.compiler.createTask('TSCompiler', tsCompiler);\n }\n\n async __getDescriptor() {\n return {\n type: AspectEnvType,\n };\n }\n}\n"]}
@@ -0,0 +1,12 @@
1
+ // Using object
2
+ import '@teambit/react.eslint-config-bit-react';
3
+
4
+ module.exports = {
5
+ extends: [require.resolve('@teambit/react.eslint-config-bit-react')],
6
+ parserOptions: {
7
+ // parser: require.resolve('@typescript-eslint/parser'),
8
+ // createDefaultProgram: true,
9
+ // resolve the env tsconfig.
10
+ project: require.resolve('../typescript/tsconfig.json'),
11
+ },
12
+ };
@@ -0,0 +1,12 @@
1
+ // This is a custom Jest transformer turning style imports into empty objects.
2
+ // http://facebook.github.io/jest/docs/en/webpack.html
3
+
4
+ module.exports = {
5
+ process() {
6
+ return 'module.exports = {};';
7
+ },
8
+ getCacheKey() {
9
+ // The output is always the same.
10
+ return 'cssTransform';
11
+ },
12
+ };
@@ -0,0 +1,38 @@
1
+ const path = require('path');
2
+ const camelcase = require('camelcase');
3
+
4
+ // This is a custom Jest transformer turning file imports into filenames.
5
+ // http://facebook.github.io/jest/docs/en/webpack.html
6
+
7
+ module.exports = {
8
+ process(src, filename) {
9
+ const assetFilename = JSON.stringify(path.basename(filename));
10
+
11
+ if (filename.match(/\.svg$/)) {
12
+ // Based on how SVGR generates a component name:
13
+ // https://github.com/smooth-code/svgr/blob/01b194cf967347d43d4cbe6b434404731b87cf27/packages/core/src/state.js#L6
14
+ const pascalCaseFilename = camelcase(path.parse(filename).name, {
15
+ pascalCase: true,
16
+ });
17
+ const componentName = `Svg${pascalCaseFilename}`;
18
+ return `const React = require('react');
19
+ module.exports = {
20
+ __esModule: true,
21
+ default: ${assetFilename},
22
+ ReactComponent: React.forwardRef(function ${componentName}(props, ref) {
23
+ return {
24
+ $$typeof: Symbol.for('react.element'),
25
+ type: 'svg',
26
+ ref: ref,
27
+ key: null,
28
+ props: Object.assign({}, props, {
29
+ children: ${assetFilename}
30
+ })
31
+ };
32
+ }),
33
+ };`;
34
+ }
35
+
36
+ return `module.exports = ${assetFilename};`;
37
+ },
38
+ };
@@ -0,0 +1,30 @@
1
+ module.exports = {
2
+ // "roots": [
3
+ // "<rootDir>/src"
4
+ // ],
5
+ // "collectCoverageFrom": [
6
+ // "src/**/*.{js,jsx,ts,tsx}",
7
+ // "!src/**/*.d.ts"
8
+ // ],
9
+ setupFiles: [require.resolve('react-app-polyfill/jsdom')],
10
+ setupFilesAfterEnv: [require.resolve('./setupTests.js')],
11
+ // "testMatch": [
12
+ // "<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}",
13
+ // "<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}"
14
+ // ],
15
+ testEnvironment: require.resolve('jest-environment-jsdom'),
16
+ transform: {
17
+ '^.+\\.(js|jsx|ts|tsx)$': require.resolve('./transformer'),
18
+ '^.+\\.css$': require.resolve('./css-transform.js'),
19
+ '^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': require.resolve('./file-transform.js'),
20
+ // '^(?!.*\\.(svg|png|jpg|jpeg|gif|webp|woff|ttf|woff2)$)': require.resolve('./file-transform.js'),
21
+ },
22
+ transformIgnorePatterns: ['[/\\\\]node_modules[/\\\\].+\\.(js|jsx|ts|tsx)$', '^.+\\.module\\.(css|sass|scss)$'],
23
+ modulePaths: [],
24
+ moduleNameMapper: {
25
+ '^react-native$': require.resolve('react-native-web'),
26
+ '^.+\\.module\\.(css|sass|scss)$': require.resolve('identity-obj-proxy'),
27
+ },
28
+ moduleFileExtensions: ['web.js', 'js', 'web.ts', 'ts', 'web.tsx', 'tsx', 'json', 'web.jsx', 'jsx', 'node'],
29
+ // watchPlugins: [require.resolve('jest-watch-typeahead/filename'), require.resolve('jest-watch-typeahead/testname')],
30
+ };
@@ -0,0 +1,7 @@
1
+ // add babel-polyfill.
2
+ // require('babel-polyfill');
3
+ // jest-dom adds custom jest matchers for asserting on DOM nodes.
4
+ // allows you to do things like:
5
+ // expect(element).toHaveTextContent(/react/i)
6
+ // learn more: https://github.com/testing-library/jest-dom
7
+ require('@testing-library/jest-dom/extend-expect');
@@ -0,0 +1,41 @@
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/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/react",
3
- "version": "0.0.558",
3
+ "version": "0.0.562",
4
4
  "homepage": "https://bit.dev/teambit/react/react",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.react",
8
8
  "name": "react",
9
- "version": "0.0.558"
9
+ "version": "0.0.562"
10
10
  },
11
11
  "dependencies": {
12
12
  "react-error-boundary": "^3.0.0",
@@ -79,46 +79,47 @@
79
79
  "@teambit/react.instructions.react.adding-compositions": "0.0.6",
80
80
  "@teambit/react.instructions.react.adding-tests": "0.0.6",
81
81
  "@teambit/design.ui.pages.standalone-not-found-page": "0.0.354",
82
- "@teambit/preview": "0.0.558",
83
- "@teambit/react.ui.error-fallback": "0.0.89",
84
- "@teambit/react.ui.loader-fallback": "0.0.67",
85
- "@teambit/compositions.ui.hooks.use-composition": "0.0.142",
82
+ "@teambit/preview": "0.0.562",
83
+ "@teambit/react.ui.error-fallback": "0.0.91",
84
+ "@teambit/react.ui.loader-fallback": "0.0.69",
85
+ "@teambit/compositions.ui.hooks.use-composition": "0.0.144",
86
86
  "@teambit/design.ui.input.option-button": "0.0.26",
87
87
  "@teambit/design.ui.tooltip": "0.0.352",
88
- "@teambit/application": "0.0.200",
89
- "@teambit/bundler": "0.0.558",
90
- "@teambit/builder": "0.0.558",
91
- "@teambit/isolator": "0.0.558",
92
- "@teambit/toolbox.network.get-port": "0.0.92",
93
- "@teambit/compiler": "0.0.558",
94
- "@teambit/component.modules.component-url": "0.0.99",
95
- "@teambit/component": "0.0.558",
96
- "@teambit/envs": "0.0.558",
97
- "@teambit/eslint": "0.0.558",
98
- "@teambit/formatter": "0.0.109",
99
- "@teambit/jest": "0.0.558",
100
- "@teambit/linter": "0.0.558",
101
- "@teambit/pkg": "0.0.558",
102
- "@teambit/prettier": "0.0.109",
103
- "@teambit/react.babel.bit-react-transformer": "0.0.472",
104
- "@teambit/schema": "0.0.558",
105
- "@teambit/tester": "0.0.558",
106
- "@teambit/typescript": "0.0.558",
107
- "@teambit/webpack": "0.0.558",
108
- "@teambit/workspace": "0.0.558",
109
- "@teambit/cli": "0.0.388",
110
- "@teambit/dependency-resolver": "0.0.558",
111
- "@teambit/generator": "0.0.558",
112
- "@teambit/graphql": "0.0.558",
113
- "@teambit/react.ui.highlighter-provider": "0.0.152",
114
- "@teambit/compositions": "0.0.558",
115
- "@teambit/ui": "0.0.558",
116
- "@teambit/react.eslint-config-bit-react": "0.0.465",
117
- "@teambit/mdx.modules.mdx-loader": "0.0.466",
118
- "@teambit/webpack.modules.generate-style-loaders": "0.0.82",
119
- "@teambit/webpack.modules.style-regexps": "0.0.111",
120
- "@teambit/component-id": "0.0.378",
121
- "@teambit/config": "0.0.399"
88
+ "@teambit/application": "0.0.204",
89
+ "@teambit/bundler": "0.0.562",
90
+ "@teambit/builder": "0.0.562",
91
+ "@teambit/isolator": "0.0.562",
92
+ "@teambit/toolbox.network.get-port": "0.0.94",
93
+ "@teambit/compiler": "0.0.562",
94
+ "@teambit/component.modules.component-url": "0.0.101",
95
+ "@teambit/component": "0.0.562",
96
+ "@teambit/envs": "0.0.562",
97
+ "@teambit/eslint": "0.0.562",
98
+ "@teambit/formatter": "0.0.113",
99
+ "@teambit/jest": "0.0.562",
100
+ "@teambit/linter": "0.0.562",
101
+ "@teambit/pkg": "0.0.562",
102
+ "@teambit/prettier": "0.0.113",
103
+ "@teambit/react.ui.highlighter.component-metadata.bit-component-meta": "0.0.1",
104
+ "@teambit/schema": "0.0.562",
105
+ "@teambit/tester": "0.0.562",
106
+ "@teambit/typescript": "0.0.562",
107
+ "@teambit/webpack": "0.0.562",
108
+ "@teambit/workspace": "0.0.562",
109
+ "@teambit/cli": "0.0.390",
110
+ "@teambit/dependency-resolver": "0.0.562",
111
+ "@teambit/generator": "0.0.562",
112
+ "@teambit/graphql": "0.0.562",
113
+ "@teambit/react.ui.highlighter-provider": "0.0.155",
114
+ "@teambit/compositions": "0.0.562",
115
+ "@teambit/ui": "0.0.562",
116
+ "@teambit/react.eslint-config-bit-react": "0.0.468",
117
+ "@teambit/mdx.modules.mdx-loader": "0.0.468",
118
+ "@teambit/react.babel.bit-react-transformer": "0.0.475",
119
+ "@teambit/webpack.modules.generate-style-loaders": "0.0.84",
120
+ "@teambit/webpack.modules.style-regexps": "0.0.113",
121
+ "@teambit/component-id": "0.0.380",
122
+ "@teambit/config": "0.0.402"
122
123
  },
123
124
  "devDependencies": {
124
125
  "@types/react": "^17.0.8",
@@ -133,10 +134,10 @@
133
134
  "@types/mocha": "5.2.7",
134
135
  "@types/testing-library__jest-dom": "5.9.5",
135
136
  "@types/jest": "^26.0.0",
136
- "@teambit/react.aspect-docs.react": "0.0.107"
137
+ "@teambit/react.aspect-docs.react": "0.0.109"
137
138
  },
138
139
  "peerDependencies": {
139
- "@teambit/legacy": "1.0.174",
140
+ "@teambit/legacy": "1.0.176",
140
141
  "react-dom": "^16.8.0 || ^17.0.0",
141
142
  "react": "^16.8.0 || ^17.0.0"
142
143
  },
@@ -198,7 +199,7 @@
198
199
  "@types/jest": "^26.0.0"
199
200
  },
200
201
  "peerDependencies": {
201
- "@teambit/legacy": "1.0.174",
202
+ "@teambit/legacy": "1.0.176",
202
203
  "react-dom": "^16.8.0 || ^17.0.0",
203
204
  "react": "^16.8.0 || ^17.0.0"
204
205
  }
@@ -207,10 +208,37 @@
207
208
  "files": [
208
209
  "dist",
209
210
  "!dist/tsconfig.tsbuildinfo",
210
- "README.md",
211
- "README.mdx",
212
- "*.js",
213
- "*.json"
211
+ "**/*.md",
212
+ "**/*.mdx",
213
+ "**/*.js",
214
+ "**/*.json",
215
+ "**/*.sass",
216
+ "**/*.scss",
217
+ "**/*.less",
218
+ "**/*.css",
219
+ "**/*.css",
220
+ "**/*.jpeg",
221
+ "**/*.gif"
214
222
  ],
215
- "private": false
223
+ "private": false,
224
+ "engines": {
225
+ "node": ">=12.22.0"
226
+ },
227
+ "repository": {
228
+ "type": "git",
229
+ "url": "https://github.com/teambit/bit"
230
+ },
231
+ "keywords": [
232
+ "bit",
233
+ "bit-aspect",
234
+ "components",
235
+ "collaboration",
236
+ "web",
237
+ "react",
238
+ "react-components",
239
+ "angular",
240
+ "angular-components",
241
+ "vue",
242
+ "vue-components"
243
+ ]
216
244
  }
@@ -0,0 +1,5 @@
1
+ module.exports = {
2
+ trailingComma: 'es5',
3
+ tabWidth: 2,
4
+ singleQuote: true,
5
+ };
package/react.docs.mdx ADDED
@@ -0,0 +1,8 @@
1
+ ---
2
+ description: A Bit development environment for React Components
3
+ labels: ['react', 'environment', 'env', 'aspect', 'extension']
4
+ ---
5
+
6
+ import { ReactAspect } from '@teambit/react.aspect-docs.react';
7
+
8
+ <ReactAspect />
@@ -0,0 +1,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "lib": [
4
+ "es2019", "DOM", "ES6" ,"DOM.Iterable"
5
+ ],
6
+ "target": "es2015",
7
+ "module": "commonjs",
8
+ "jsx": "react",
9
+ "allowJs": true,
10
+ "composite": true,
11
+ "declaration": true,
12
+ "sourceMap": true,
13
+ "skipLibCheck": true,
14
+ "outDir": "dist",
15
+ "moduleResolution": "node",
16
+ "esModuleInterop": true,
17
+ "rootDir": "."
18
+ },
19
+ "exclude": [
20
+ "dist"
21
+ ]
22
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "compilerOptions": {
3
+ "lib": [
4
+ "es2019", "DOM", "ES6" ,"DOM.Iterable"
5
+ ],
6
+ "target": "es2015",
7
+ "module": "commonjs",
8
+ "jsx": "react",
9
+ "declaration": true,
10
+ "sourceMap": true,
11
+ "skipLibCheck": true,
12
+ "moduleResolution": "node",
13
+ "esModuleInterop": true
14
+ },
15
+ "exclude": [
16
+ "dist"
17
+ ]
18
+ }
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Copyright (c) 2015-present, Facebook, Inc.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ const friendlySyntaxErrorLabel = 'Syntax error:';
8
+
9
+ function isLikelyASyntaxError(message) {
10
+ return message.indexOf(friendlySyntaxErrorLabel) !== -1;
11
+ }
12
+
13
+ // Cleans up webpack error messages.
14
+ function formatMessage(error) {
15
+ let message = error.message;
16
+ let lines = message.split('\n');
17
+
18
+ // Strip webpack-added headers off errors/warnings
19
+ // https://github.com/webpack/webpack/blob/master/lib/ModuleError.js
20
+ lines = lines.filter((line) => !/Module [A-z ]+\(from/.test(line));
21
+
22
+ // Transform parsing error into syntax error
23
+ // TODO: move this to our ESLint formatter?
24
+ lines = lines.map((line) => {
25
+ const parsingError = /Line (\d+):(?:(\d+):)?\s*Parsing error: (.+)$/.exec(line);
26
+ if (!parsingError) {
27
+ return line;
28
+ }
29
+ const [, errorLine, errorColumn, errorMessage] = parsingError;
30
+ return `${friendlySyntaxErrorLabel} ${errorMessage} (${errorLine}:${errorColumn})`;
31
+ });
32
+
33
+ message = lines.join('\n');
34
+ // Smoosh syntax errors (commonly found in CSS)
35
+ message = message.replace(/SyntaxError\s+\((\d+):(\d+)\)\s*(.+?)\n/g, `${friendlySyntaxErrorLabel} $3 ($1:$2)\n`);
36
+ // Clean up export errors
37
+ message = message.replace(
38
+ /^.*export '(.+?)' was not found in '(.+?)'.*$/gm,
39
+ `Attempted import error: '$1' is not exported from '$2'.`
40
+ );
41
+ message = message.replace(
42
+ /^.*export 'default' \(imported as '(.+?)'\) was not found in '(.+?)'.*$/gm,
43
+ `Attempted import error: '$2' does not contain a default export (imported as '$1').`
44
+ );
45
+ message = message.replace(
46
+ /^.*export '(.+?)' \(imported as '(.+?)'\) was not found in '(.+?)'.*$/gm,
47
+ `Attempted import error: '$1' is not exported from '$3' (imported as '$2').`
48
+ );
49
+ lines = message.split('\n');
50
+
51
+ // Remove leading newline
52
+ if (lines.length > 2 && lines[1].trim() === '') {
53
+ lines.splice(1, 1);
54
+ }
55
+ // Clean up file name
56
+ lines[0] = lines[0].replace(/^(.*) \d+:\d+-\d+$/, '$1');
57
+
58
+ // Cleans up verbose "module not found" messages for files and packages.
59
+ if (lines[1] && lines[1].indexOf('Module not found: ') === 0) {
60
+ lines = [
61
+ lines[0],
62
+ lines[1].replace('Error: ', '').replace('Module not found: Cannot find file:', 'Cannot find file:'),
63
+ ];
64
+ }
65
+
66
+ // Add helpful message for users trying to use Sass for the first time
67
+ if (lines[1] && lines[1].match(/Cannot find module.+node-sass/)) {
68
+ lines[1] = 'To import Sass files, you first need to install node-sass.\n';
69
+ lines[1] += 'Run `npm install node-sass` or `yarn add node-sass` inside your workspace.';
70
+ }
71
+
72
+ message = lines.join('\n');
73
+ // Internal stacks are generally useless so we strip them... with the
74
+ // exception of stacks containing `webpack:` because they're normally
75
+ // from user code generated by webpack. For more information see
76
+ // https://github.com/facebook/create-react-app/pull/1050
77
+ message = message.replace(/^\s*at\s((?!webpack:).)*:\d+:\d+[\s)]*(\n|$)/gm, ''); // at ... ...:x:y
78
+ message = message.replace(/^\s*at\s<anonymous>(\n|$)/gm, ''); // at <anonymous>
79
+ lines = message.split('\n');
80
+
81
+ // Remove duplicated newlines
82
+ lines = lines.filter(
83
+ (line, index, arr) => index === 0 || line.trim() !== '' || line.trim() !== arr[index - 1].trim()
84
+ );
85
+
86
+ // Reassemble the message
87
+ message = lines.join('\n');
88
+ return message.trim();
89
+ }
90
+
91
+ function formatWebpackMessages(json) {
92
+ const formattedErrors = json.errors.map(formatMessage);
93
+ const formattedWarnings = json.warnings.map(formatMessage);
94
+ const result = { errors: formattedErrors, warnings: formattedWarnings };
95
+ if (result.errors.some(isLikelyASyntaxError)) {
96
+ // If there are any syntax errors, show just them.
97
+ result.errors = result.errors.filter(isLikelyASyntaxError);
98
+ }
99
+ return result;
100
+ }
101
+
102
+ module.exports = formatWebpackMessages;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Copyright (c) 2015-present, Facebook, Inc.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ // TODO: we might want to make this injectable to support DEV-time non-root URLs.
8
+ module.exports = '/__open-stack-frame-in-editor';
@@ -0,0 +1,274 @@
1
+ /* eslint-disable promise/catch-or-return */
2
+ /**
3
+ * Copyright (c) 2015-present, Facebook, Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ const stripAnsi = require('strip-ansi');
9
+ const ErrorOverlay = require('react-error-overlay');
10
+ const url = require('url');
11
+ const launchEditorEndpoint = require('./launch-editor-endpoint');
12
+ const formatWebpackMessages = require('./format-webpack-messages');
13
+
14
+ ErrorOverlay.setEditorHandler(function editorHandler(errorLocation) {
15
+ // Keep this sync with errorOverlayMiddleware.js
16
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
17
+ fetch(
18
+ `${launchEditorEndpoint}?fileName=${window.encodeURIComponent(
19
+ errorLocation.fileName
20
+ )}&lineNumber=${window.encodeURIComponent(errorLocation.lineNumber || 1)}&colNumber=${window.encodeURIComponent(
21
+ errorLocation.colNumber || 1
22
+ )}`
23
+ );
24
+ });
25
+
26
+ // We need to keep track of if there has been a runtime error.
27
+ // Essentially, we cannot guarantee application state was not corrupted by the
28
+ // runtime error. To prevent confusing behavior, we forcibly reload the entire
29
+ // application. This is handled below when we are notified of a compile (code
30
+ // change).
31
+ // See https://github.com/facebook/create-react-app/issues/3096
32
+ let hadRuntimeError = false;
33
+ ErrorOverlay.startReportingRuntimeErrors({
34
+ onError() {
35
+ hadRuntimeError = true;
36
+ },
37
+ filename: '/static/js/bundle.js',
38
+ });
39
+
40
+ if (module.hot && typeof module.hot.dispose === 'function') {
41
+ module.hot.dispose(function () {
42
+ // TODO: why do we need this?
43
+ ErrorOverlay.stopReportingRuntimeErrors();
44
+ });
45
+ }
46
+
47
+ // Connect to WebpackDevServer via a socket.
48
+ const querystring = module.id.substring(module.id.indexOf('?'));
49
+ const urlParams = new URLSearchParams(querystring);
50
+
51
+ const connection = new WebSocket(
52
+ url.format({
53
+ protocol: window.location.protocol === 'https:' ? 'wss' : 'ws',
54
+ hostname: window.location.hostname,
55
+ port: window.location.port,
56
+ // Hardcoded in WebpackDevServer
57
+ pathname: urlParams.get('sockPath') || '/sockjs-node',
58
+ // pathname: '_hmr/teambit.bad-jokes/extensions/harmony-react',
59
+ slashes: true,
60
+ })
61
+ );
62
+
63
+ // Unlike WebpackDevServer client, we won't try to reconnect
64
+ // to avoid spamming the console. Disconnect usually happens
65
+ // when developer stops the server.
66
+ connection.onclose = function () {
67
+ // eslint-disable-next-line no-console
68
+ if (typeof console !== 'undefined' && typeof console.info === 'function') {
69
+ // eslint-disable-next-line no-console
70
+ console.info('The development server has disconnected.\nRefresh the page if necessary.');
71
+ }
72
+ };
73
+
74
+ // Remember some state related to hot module replacement.
75
+ let isFirstCompilation = true;
76
+ let mostRecentCompilationHash = null;
77
+ let hasCompileErrors = false;
78
+
79
+ function clearOutdatedErrors() {
80
+ // Clean up outdated compile errors, if any.
81
+ // eslint-disable-next-line no-console
82
+ if (typeof console !== 'undefined' && typeof console.clear === 'function') {
83
+ if (hasCompileErrors) {
84
+ // eslint-disable-next-line no-console
85
+ console.clear();
86
+ }
87
+ }
88
+ }
89
+
90
+ // Successful compilation.
91
+ function handleSuccess() {
92
+ clearOutdatedErrors();
93
+
94
+ const isHotUpdate = !isFirstCompilation;
95
+ isFirstCompilation = false;
96
+ hasCompileErrors = false;
97
+
98
+ // Attempt to apply hot updates or reload.
99
+ if (isHotUpdate) {
100
+ tryApplyUpdates(function onHotUpdateSuccess() {
101
+ // Only dismiss it when we're sure it's a hot update.
102
+ // Otherwise it would flicker right before the reload.
103
+ tryDismissErrorOverlay();
104
+ });
105
+ }
106
+ }
107
+
108
+ // Compilation with warnings (e.g. ESLint).
109
+ function handleWarnings(warnings) {
110
+ clearOutdatedErrors();
111
+
112
+ const isHotUpdate = !isFirstCompilation;
113
+ isFirstCompilation = false;
114
+ hasCompileErrors = false;
115
+
116
+ function printWarnings() {
117
+ // Print warnings to the console.
118
+ const formatted = formatWebpackMessages({
119
+ warnings,
120
+ errors: [],
121
+ });
122
+
123
+ // eslint-disable-next-line no-console
124
+ if (typeof console !== 'undefined' && typeof console.warn === 'function') {
125
+ // eslint-disable-next-line no-plusplus
126
+ for (let i = 0; i < formatted.warnings.length; i++) {
127
+ if (i === 5) {
128
+ // eslint-disable-next-line
129
+ console.warn('There were more warnings in other files.\n' + 'You can find a complete log in the terminal.');
130
+ break;
131
+ }
132
+ // eslint-disable-next-line no-console
133
+ console.warn(stripAnsi(formatted.warnings[i]));
134
+ }
135
+ }
136
+ }
137
+
138
+ printWarnings();
139
+
140
+ // Attempt to apply hot updates or reload.
141
+ if (isHotUpdate) {
142
+ tryApplyUpdates(function onSuccessfulHotUpdate() {
143
+ // Only dismiss it when we're sure it's a hot update.
144
+ // Otherwise it would flicker right before the reload.
145
+ tryDismissErrorOverlay();
146
+ });
147
+ }
148
+ }
149
+
150
+ // Compilation with errors (e.g. syntax error or missing modules).
151
+ function handleErrors(errors) {
152
+ clearOutdatedErrors();
153
+
154
+ isFirstCompilation = false;
155
+ hasCompileErrors = true;
156
+
157
+ // "Massage" webpack messages.
158
+ const formatted = formatWebpackMessages({
159
+ errors,
160
+ warnings: [],
161
+ });
162
+
163
+ // Only show the first error.
164
+ ErrorOverlay.reportBuildError(formatted.errors[0]);
165
+
166
+ // Also log them to the console.
167
+ // eslint-disable-next-line no-console
168
+ if (typeof console !== 'undefined' && typeof console.error === 'function') {
169
+ // eslint-disable-next-line no-plusplus
170
+ for (let i = 0; i < formatted.errors.length; i++) {
171
+ // eslint-disable-next-line no-console
172
+ console.error(stripAnsi(formatted.errors[i]));
173
+ }
174
+ }
175
+
176
+ // Do not attempt to reload now.
177
+ // We will reload on next success instead.
178
+ }
179
+
180
+ function tryDismissErrorOverlay() {
181
+ if (!hasCompileErrors) {
182
+ ErrorOverlay.dismissBuildError();
183
+ }
184
+ }
185
+
186
+ // There is a newer version of the code available.
187
+ function handleAvailableHash(hash) {
188
+ // Update last known compilation hash.
189
+ mostRecentCompilationHash = hash;
190
+ }
191
+
192
+ // Handle messages from the server.
193
+ connection.onmessage = function (e) {
194
+ const message = JSON.parse(e.data);
195
+ switch (message.type) {
196
+ case 'hash':
197
+ handleAvailableHash(message.data);
198
+ break;
199
+ case 'still-ok':
200
+ case 'ok':
201
+ handleSuccess();
202
+ break;
203
+ case 'content-changed':
204
+ // Triggered when a file from `contentBase` changed.
205
+ window.location.reload();
206
+ break;
207
+ case 'warnings':
208
+ handleWarnings(message.data);
209
+ break;
210
+ case 'errors':
211
+ handleErrors(message.data);
212
+ break;
213
+ default:
214
+ // Do nothing.
215
+ }
216
+ };
217
+
218
+ // Is there a newer version of this code available?
219
+ function isUpdateAvailable() {
220
+ /* globals __webpack_hash__ */
221
+ // __webpack_hash__ is the hash of the current compilation.
222
+ // It's a global variable injected by webpack.
223
+ return mostRecentCompilationHash !== __webpack_hash__;
224
+ }
225
+
226
+ // webpack disallows updates in other states.
227
+ function canApplyUpdates() {
228
+ return module.hot.status() === 'idle';
229
+ }
230
+
231
+ // Attempt to update code on the fly, fall back to a hard reload.
232
+ function tryApplyUpdates(onHotUpdateSuccess) {
233
+ if (!module.hot) {
234
+ // HotModuleReplacementPlugin is not in webpack configuration.
235
+ window.location.reload();
236
+ return;
237
+ }
238
+
239
+ if (!isUpdateAvailable() || !canApplyUpdates()) {
240
+ return;
241
+ }
242
+
243
+ function handleApplyUpdates(err, updatedModules) {
244
+ if (err || !updatedModules || hadRuntimeError) {
245
+ window.location.reload();
246
+ return;
247
+ }
248
+
249
+ if (typeof onHotUpdateSuccess === 'function') {
250
+ // Maybe we want to do something.
251
+ onHotUpdateSuccess();
252
+ }
253
+
254
+ if (isUpdateAvailable()) {
255
+ // While we were updating, there was a new update! Do it again.
256
+ tryApplyUpdates();
257
+ }
258
+ }
259
+
260
+ // https://webpack.github.io/docs/hot-module-replacement.html#check
261
+ const result = module.hot.check(/* autoApply */ true, handleApplyUpdates);
262
+
263
+ // // webpack 2 returns a Promise instead of invoking a callback
264
+ if (result && result.then) {
265
+ result.then(
266
+ function (updatedModules) {
267
+ handleApplyUpdates(null, updatedModules);
268
+ },
269
+ function (err) {
270
+ handleApplyUpdates(err, null);
271
+ }
272
+ );
273
+ }
274
+ }
@@ -0,0 +1,16 @@
1
+ // @remove-on-eject-begin
2
+ /**
3
+ * Copyright (c) 2015-present, Facebook, Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ // @remove-on-eject-end
9
+ 'use strict';
10
+
11
+ const { dismissRuntimeErrors, reportRuntimeError } = require('react-error-overlay');
12
+
13
+ module.exports = {
14
+ clearRuntimeErrors: dismissRuntimeErrors,
15
+ handleRuntimeError: reportRuntimeError,
16
+ };