@teambit/envs 1.0.108 → 1.0.109
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/artifacts/preview/teambit_envs_envs-preview.js +1 -0
- package/dist/{preview-1703647408454.js → preview-1703698405864.js} +2 -2
- package/package.json +23 -23
- package/env-definition.ts +0 -50
- package/env-interface.ts +0 -5
- package/env-service-list.ts +0 -31
- package/env.fragment.ts +0 -35
- package/env.plugin.ts +0 -60
- package/environment.ts +0 -236
- package/environments.aspect.ts +0 -5
- package/environments.graphql.ts +0 -27
- package/environments.main.runtime.ts +0 -1058
- package/index.ts +0 -29
@@ -0,0 +1 @@
|
|
1
|
+
!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports["teambit.envs/envs-preview"]=n():e["teambit.envs/envs-preview"]=n()}(self,(()=>(()=>{"use strict";var e={79043:(e,n,t)=>{var o={id:"teambit.envs/envs@1.0.109",homepage:"https://bit.cloud/teambit/envs/envs",exported:!0};function r(){const e=a(t(87363));return r=function(){return e},e}function a(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(n,"__esModule",{value:!0}),n.Logo=void 0,r.__bit_component=o,a.__bit_component=o;const s=()=>r().default.createElement("div",{style:{height:"100%",display:"flex",justifyContent:"center"}},r().default.createElement("img",{style:{width:70},src:"https://static.bit.dev/extensions-icons/env.svg"}));s.__bit_component=o,n.Logo=s},81282:(e,n,t)=>{var o={id:"teambit.envs/aspect-docs/envs@0.0.165",homepage:"https://bit.cloud/teambit/envs/aspect-docs/envs",exported:!0};Object.defineProperty(n,"__esModule",{value:!0}),n.default=d,s(t(87363));var r=t(40040),a=["components"];function s(e){return e&&e.__esModule?e:{default:e}}function i(){return i=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},i.apply(this,arguments)}function m(e,n){if(null==e)return{};var t,o,r=l(e,n);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(o=0;o<a.length;o++)t=a[o],n.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(r[t]=e[t])}return r}function l(e,n){if(null==e)return{};var t,o,r={},a=Object.keys(e);for(o=0;o<a.length;o++)t=a[o],n.indexOf(t)>=0||(r[t]=e[t]);return r}s.__bit_component=o,i.__bit_component=o,m.__bit_component=o,l.__bit_component=o;var c={},p="wrapper";function d(e){var n=e.components,t=m(e,a);return(0,r.mdx)(p,i({},c,t,{components:n,mdxType:"MDXLayout"}),(0,r.mdx)("p",null,"The Envs aspect runs Bit environments and environment services, and defines their structure."),(0,r.mdx)("p",null,"A Bit environment is a development environment encapsulated in a Bit component. Just like other components, Bit environments can be instantly added to your workspace to start developing, testing, and building components with zero configurations.\nDifferent environments can be easily applied to multiple components in a workspace, and can be easily extended or customized to fit your needs and development stack. For example, try the React environment to start developing React components in your workspace.\nLike all Bit components, Bit environments are reusable, so you can share them across projects and teams to greatly speed up and standardize development."),(0,r.mdx)("h4",null,"Example"),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-json"},'// Using the \'Node\' and \'React\' environments for different components in a Bit workspace.\n{\n "teambit.workspace/variants": {\n "components/ui": {\n "teambit.react/react": {}\n },\n "components/utils": {\n "teambit.harmony/node": {}\n }\n }\n}\n')),(0,r.mdx)("h4",null,"Features"),(0,r.mdx)("ul",null,(0,r.mdx)("li",{parentName:"ul"},(0,r.mdx)("p",{parentName:"li"},(0,r.mdx)("strong",{parentName:"p"},"Blazing fast environment setup"),": Setting up an environment requires nothing more than configuring a workspace to use a Bit extension.\nGet started in seconds and focus on the thing that matters most - delivering great features.")),(0,r.mdx)("li",{parentName:"ul"},(0,r.mdx)("p",{parentName:"li"},(0,r.mdx)("strong",{parentName:"p"},"Multiple environments in a single workspace"),": No need to constantly switch between workspaces as different environments,\nset to handle different components, can all be used in parallel in a single workspace.")),(0,r.mdx)("li",{parentName:"ul"},(0,r.mdx)("p",{parentName:"li"},(0,r.mdx)("strong",{parentName:"p"},"Less to learn"),": Using a pre-configured environment extension means you don't have to get into all the details of your build tooling.\nThat's a especially important when onboarding a new developer to your team.")),(0,r.mdx)("li",{parentName:"ul"},(0,r.mdx)("p",{parentName:"li"},(0,r.mdx)("strong",{parentName:"p"},"Customizable and extensible"),": Environments can be extended to add or override configurations.\nQuickly add your own modifications to get an environment that best suits your needs.\nExport your environment extension to a remote scope to have it available to all your team.")),(0,r.mdx)("li",{parentName:"ul"},(0,r.mdx)("p",{parentName:"li"},(0,r.mdx)("strong",{parentName:"p"},"Standardized development"),": Sharing and reusing environments makes it easier to maintain consistency in development across multiple decoupled Bit workspaces.")),(0,r.mdx)("li",{parentName:"ul"},(0,r.mdx)("p",{parentName:"li"},(0,r.mdx)("strong",{parentName:"p"},"Easy to maintain"),": Get your environment's latest updates with just a simple ",(0,r.mdx)("inlineCode",{parentName:"p"},"bit import")," command. Roll-back as easily, if needed."))),(0,r.mdx)("h2",null,"CLI reference"),(0,r.mdx)("p",null,"Bit environments make use of Bit's CLI to execute their different services. That means, ",(0,r.mdx)("inlineCode",{parentName:"p"},"bit test"),", for example, may execute different test runners, depending on the environment in use."),(0,r.mdx)("h4",null,"start"),(0,r.mdx)("p",null,"Runs the development serve (that includes running the Workspace UI)."),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-shell"},"// run the dev server\nbit start\n")),(0,r.mdx)("h4",null,"build"),(0,r.mdx)("p",null,"Runs the build pipeline (without tagging components with a new release version)."),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-shell"},"bit build\n")),(0,r.mdx)("h4",null,"test"),(0,r.mdx)("p",null,"Runs all tests."),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-shell"},"bit test\n")),(0,r.mdx)("h4",null,"compile"),(0,r.mdx)("p",null,"Compiles all components."),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-shell"},"bit compile\n")),(0,r.mdx)("h4",null,"lint"),(0,r.mdx)("p",null,"Get lint results for all components."),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-shell"},"bit lint\n")),(0,r.mdx)("h2",null,"Usage"),(0,r.mdx)("h3",null,"Setting a default environment for the workspace"),(0,r.mdx)("p",null,"Environments can only be configured using the ",(0,r.mdx)("inlineCode",{parentName:"p"},"teambit.workspace/variants")," workspace API. That means the ",(0,r.mdx)("inlineCode",{parentName:"p"},"teambit.workspace/workspace")," cannot be utilized to set an environment as the default for all components. To achieve a similar result, select all components using the ",(0,r.mdx)("inlineCode",{parentName:"p"},"*")," wildcard."),(0,r.mdx)("p",null,"For example:"),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-json"},'{\n "teambit.workspace/variants": {\n "*": {\n "teambit.react/react": {}\n }\n }\n}\n')),(0,r.mdx)("blockquote",null,(0,r.mdx)("p",{style:{color:"#c31313"}},"Never use the '*' wildcard in a workspace that uses multiple environments!"),"Instead, use exclusive namespaces or directories to select and configure each group of components to use its own environment (see an example in the next section)."),(0,r.mdx)("br",null),(0,r.mdx)("br",null),(0,r.mdx)("p",null,"To learn more, see the 'Troubleshooting' section."),(0,r.mdx)("blockquote",null,(0,r.mdx)("p",{parentName:"blockquote"},"A single component (with the same version) cannot use more than a single environment.")),(0,r.mdx)("h3",null,"Setting multiple environments"),(0,r.mdx)("p",null,"A single workspace can use different environments for different sets of components. Setting an environment on a specific group of components is done by selecting the group and applying the environment. This is done using ",(0,r.mdx)("inlineCode",{parentName:"p"},"teambit.workspace/variants"),"."),(0,r.mdx)("p",null,"For example, to set the Node and React environments on two sets of components (selected by their directory):"),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-json"},'{\n "teambit.workspace/variants": {\n "components/ui": {\n "teambit.react/react": {}\n },\n "components/utils": {\n "teambit.harmony/node": {}\n }\n }\n}\n')),(0,r.mdx)("h3",null,"Extending an environment"),(0,r.mdx)("blockquote",null,(0,r.mdx)("p",{parentName:"blockquote"},"This section goes through the steps of extending the 'main runtime'.\nSee the 'Runtime Environment' section to learn how to extend multiple runtime environments.")),(0,r.mdx)("p",null,"An environment extension is a component that extends an existing environment. An extension file will have the ",(0,r.mdx)("inlineCode",{parentName:"p"},".extension.ts")," suffix as a convention."),(0,r.mdx)("blockquote",null,(0,r.mdx)("p",{parentName:"blockquote"},"The ",(0,r.mdx)("inlineCode",{parentName:"p"},"*.extensions.ts")," pattern should only be used when no other 'runtime environment' is being extended other than the 'main runtime.' For more details, see the 'runtime environments' section.")),(0,r.mdx)("p",null,"To create and use an environment extension:"),(0,r.mdx)("ol",null,(0,r.mdx)("li",{parentName:"ol"},"Create the extension files"),(0,r.mdx)("li",{parentName:"ol"},"Use and extend an existing environment"),(0,r.mdx)("li",{parentName:"ol"},"Track the new component"),(0,r.mdx)("li",{parentName:"ol"},"Use the new extension component ID to set it in the workspace configuration file"),(0,r.mdx)("li",{parentName:"ol"},"(Optional) Tag the new component"),(0,r.mdx)("li",{parentName:"ol"},"(Optional) Export the component the make it available to be used by others")),(0,r.mdx)("h4",null,"1. Create the environment extension files"),(0,r.mdx)("p",null,"We'll start by creating a new extension:"),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-shell"},"// In the workspace's root directory\nmkdir -p extensions/custom-react\ntouch extensions/custom-react/custom-react.extension.ts\ntouch extensions/custom-react/index.ts\n")),(0,r.mdx)("h4",null,"2. Use an existing environment to extend it"),(0,r.mdx)("blockquote",null,(0,r.mdx)("p",{parentName:"blockquote"},"The below code uses the React environment as an example.")),(0,r.mdx)("p",null,"Our files will have the following code (the code below will only extend the ",(0,r.mdx)("inlineCode",{parentName:"p"},"@teambit.react/react")," environment without changing its configurations):"),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-tsx"},"// custom-react.extension.ts\n\n// Import from the Environments aspect to register this extension as an environment\nimport { EnvsMain, EnvsAspect } from '@teambit/envs';\n// Import from the React aspect to extend it\nimport { ReactAspect, ReactMain } from '@teambit/react';\n\nexport class CustomReactExtension {\n constructor(private react: ReactMain) {}\n\n // Set the necessary dependencies to be injected (by Bit) into the following 'provider' function\n static dependencies: any = [EnvsAspect, ReactAspect];\n\n static async provider([envs, react]: [EnvsMain, ReactMain]) {\n // The 'compose' methods to compose the overrides into a single environment\n const customReactEnv = react.compose([\n // This is were the environment's 'transformers' will be used to customize it\n ]);\n\n // Register this extension as an environment using the \"registerEnv\" slot (provided by the Environments aspect).\n envs.registerEnv(customReactEnv);\n\n return new CustomReactExtension(react);\n }\n}\n")),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-ts"},"// index.ts\n\nimport { CustomReactExtension } from './custom-react.extension';\nexport { CustomReactExtension };\nexport default CustomReactExtension;\n")),(0,r.mdx)("h4",null,"3. Track the extension component"),(0,r.mdx)("p",null,"We'll then track the new component (with the 'my-extensions' namespace):"),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-shell"},"bit add extensions/custom-react -n my-extensions\n")),(0,r.mdx)("h4",null,"4. Set the extension component in the workspace config file"),(0,r.mdx)("p",null,"Our extension component now has a component ID that can be used in our ",(0,r.mdx)("inlineCode",{parentName:"p"},"workspace.jsonc")," configuration file:"),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-json"},'{\n "teambit.workspace/workspace": {\n "name": "my-workspace",\n "icon": "https://image.flaticon.com/icons/svg/185/185034.svg",\n "defaultScope": "my-org.my-extensions"\n },\n "teambit.workspace/variants": {\n "*": {\n "my-org.my-extensions/custom-react": {}\n }\n }\n}\n')),(0,r.mdx)("h3",null,"The anatomy of an environment extension"),(0,r.mdx)("p",null,"An environment extension uses the following Bit components to extend an existing environment, and to register itself as an environment:"),(0,r.mdx)("ul",null,(0,r.mdx)("li",{parentName:"ul"},(0,r.mdx)("p",{parentName:"li"},"The ",(0,r.mdx)("strong",{parentName:"p"},'"base" environment')," (e.g, ",(0,r.mdx)("inlineCode",{parentName:"p"},"@teambit/react"),") is extended and customized using its override methods. Each override method, or \"environment transformer\", corresponds to a Bit extension component used by the environment (e.g, the TypeScript component). Using an 'environment transformer' will add new configurations to the relevant Bit component and will override any conflicting ones.",(0,r.mdx)("br",null)," The full list of available 'environment transformers' can be seen in the specific environment's documentation (see: React, React Native, Node).")),(0,r.mdx)("li",{parentName:"ul"},(0,r.mdx)("p",{parentName:"li"},"The ",(0,r.mdx)("strong",{parentName:"p"},"'Environments' component")," (",(0,r.mdx)("inlineCode",{parentName:"p"},"@teambit/envs"),") is used to:"),(0,r.mdx)("ol",{parentName:"li"},(0,r.mdx)("li",{parentName:"ol"},'Register the new environment using its "slot"'),(0,r.mdx)("li",{parentName:"ol"},'Override a "service handler". This is done to replace a Bit component used by an environment service. For example, to set the "compiler" service handler to use Babel instead of TypeScript')))),(0,r.mdx)("h4",null,"Override the config for a Bit component used by the environment"),(0,r.mdx)("blockquote",null,(0,r.mdx)("p",{parentName:"blockquote"},"The current Envs API will soon be replaced.")),(0,r.mdx)("p",null,"The example below is of a React environment extension. This new environment overrides React's DevServer configuration by setting a new Webpack configuration file."),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-tsx"},"// custom-react.extension.ts\n\n// Import from the Environments aspect to register this extension as an environment\nimport { EnvsMain, EnvsAspect } from '@teambit/envs';\n// Import from the React aspect to extend it and override its DevServer config\nimport { ReactAspect, ReactMain } from '@teambit/react';\n\nconst newWebpackConfig = require('./webpack/new-webpack-config');\n\nexport class CustomReactExtension {\n constructor(private react: ReactMain) {}\n\n // Set the necessary dependencies to be injected (by Bit) into the following 'provider' function\n static dependencies: any = [EnvsAspect, ReactAspect];\n\n static async provider([envs, react]: [EnvsMain, ReactMain]) {\n // The 'compose' methods to compose the overrides into a single environment\n const customReactEnv = react.compose([\n\n // Override the Webpack configs of the DevServer aspect\n react.overrideDevServerConfig(newWebpackRules);\n\n ]);\n\n // Register this extension as an environment using the \"registerEnv\" slot (provided by the Environments aspect).\n envs.registerEnv(customReactEnv);\n\n return new CustomReactExtension(react);\n }\n}\n")),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-ts"},"// index.ts\nimport { CustomReactExtension } from './custom-react.extension';\nexport { CustomReactExtension };\nexport default CustomReactExtension;\n")),(0,r.mdx)("blockquote",null,(0,r.mdx)("p",{parentName:"blockquote"},"The 'provider' method will be executed by Bit. Its Bit aspects dependencies are set in the ",(0,r.mdx)("inlineCode",{parentName:"p"},"dependencies")," variable, and will be injected into the method upon execution.")),(0,r.mdx)("h4",null,"Override a 'service handler' to replace a component used by the environment"),(0,r.mdx)("p",null,"The example below is of a React environment extension. This new environment overrides the 'service handler' for the compiler service. It replaces the Bit aspect used by it, TypeScript, with another Bit aspect, Babel."),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-tsx"},"// custom-react.extension.ts\n\n// Import from the Environments aspect to register this extension as an environment\nimport { EnvsMain, EnvsAspect } from '@teambit/envs';\n// Import from the React aspect to extend it and override its DevServer config\nimport { ReactAspect, ReactMain } from '@teambit/react';\n// Import the Babel aspect to configure it and set it as the new compiler\nimport { BabelAspect, BabelMain } from '@teambit.compilation/babel';\n\nconst babelConfig = require('./babel/babel-config');\n\nexport class CustomReactExtension {\n constructor(private react: ReactMain) {}\n\n // Set the necessary dependencies to be injected (by Bit) into the following 'provider' function\n static dependencies: any = [EnvsAspect, ReactAspect, BabelAspect];\n\n static async provider([envs, react, babel]: [EnvsMain, ReactMain, BabelMain]) {\n // Create a new Babel compiler with the 'babelConfig' configurations\n const babelCompiler = babel.createCompiler({\n babelTransformOptions: babelConfig,\n });\n\n // Use the 'override' method provided by the 'environments' aspect (not the React aspect)\n const compilerOverride = envs.override({\n getCompiler: () => {\n return babelCompiler;\n },\n });\n\n // Compose the overrides into a single environment\n const customReactEnv = react.compose([compilerOverride]);\n\n // Register this extension as an environment using the \"registerEnv\" slot (provided by the 'environments' aspect).\n envs.registerEnv(customReactEnv);\n\n return new CustomReactExtension(react);\n }\n}\n")),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-ts"},"// index.ts\nimport { CustomReactExtension } from './custom-react.extension';\nexport { CustomReactExtension };\nexport default CustomReactExtension;\n")),(0,r.mdx)("h2",null,"Concepts and tools"),(0,r.mdx)("h3",null,"Environment Services"),(0,r.mdx)("p",null,'To become a "one-stop-shop" for components, an environment "bundles" together different Environment Services provided by various Bit aspect components. These Environment Services enable other Bit aspects to integrate into Bit\'s component life-cycle features.'),(0,r.mdx)("p",null,"For example, the 'Tester' service (",(0,r.mdx)("inlineCode",{parentName:"p"},"@teambit.defender/tester"),") enables the React environment (",(0,r.mdx)("inlineCode",{parentName:"p"},"@teambit.react/react"),") to set 'Jest' (",(0,r.mdx)("inlineCode",{parentName:"p"},"teambit.defender/jest"),") as the default test runner for its components. This will enable Jest to be executed on the ",(0,r.mdx)("inlineCode",{parentName:"p"},"bbit test")," command, to be run as a pre-tag check, to output results using Bit's logger, and even to display the generated logs in the Workspace and Scope UIs (to name just a few examples)."),(0,r.mdx)("img",{src:"https://storage.googleapis.com/docs-images/react_env_ex.png",alt:"React env using Jest with the tester service",style:{width:"50%",minWidth:500}}),(0,r.mdx)("blockquote",null,(0,r.mdx)("h5",{parentName:"blockquote"},"Services VS Build Tasks"),(0,r.mdx)("p",{parentName:"blockquote"},"Environment Services which are executed either by the development server, or via the CLI, are not identical\nto Build Tasks that run as part of the Build Pipeline.\nFor example, the TypeScript configurations used for compilation by the development server are not the same as the ones used for a component's build process.")),(0,r.mdx)("h4",null,"Compiler"),(0,r.mdx)("p",null,"Runs the environment's selected compiler (for example, TypeScript)."),(0,r.mdx)("h4",null,"Tester"),(0,r.mdx)("p",null,"Runs the environment's selected test runner (for example, Jest)"),(0,r.mdx)("h4",null,"Linter"),(0,r.mdx)("p",null,"Runs the environment's selected linter (for example, ESLint)"),(0,r.mdx)("h4",null,"Documentation"),(0,r.mdx)("p",null,"Sets the template for the auto-generated component documentation, as well as the API for customizing component docs."),(0,r.mdx)("h4",null,"Build pipeline (CI)"),(0,r.mdx)("p",null,"Sets the sequence of build tasks to run before a component is tagged with a new version."),(0,r.mdx)("h4",null,"DevServer"),(0,r.mdx)("p",null,"Bundles all components and runs a server to display them, live (using \"hot reloading\") in the workspace UI. This includes rendering the 'compositions' as well as the documentation shown in the 'Overview' tab."),(0,r.mdx)("blockquote",null,(0,r.mdx)("p",{parentName:"blockquote"},"Even though different types of components, e.g. React and Node components, run on different servers (one for each environment) the workspace is explored and navigated through as if it where a single server.")),(0,r.mdx)("h4",null,"Package"),(0,r.mdx)("p",null,"Generates the node module package for components, with properties set by the environment."),(0,r.mdx)("h4",null,"Dependencies"),(0,r.mdx)("p",null,"Sets the default dependencies (as well as their version and type) for each component handled by the environment. That includes peer dependencies used for runtime (for example, ",(0,r.mdx)("inlineCode",{parentName:"p"},"react-dom"),") and dev dependencies (for example, ",(0,r.mdx)("inlineCode",{parentName:"p"},"@types/react"),")."),(0,r.mdx)("h4",null,"Bundler"),(0,r.mdx)("p",null,"Bundles components (compositions, docs, etc.) using the environment's bundler and bundling configurations. The generated assets are use both in development (when running the development server) and when exploring component's tagged releases (for example, in the scope UI)."),(0,r.mdx)("h3",null,"Service Handlers"),(0,r.mdx)("p",null,"Service Handlers are the link that binds an environment to the various Environment Services. They are methods in the Environment class that set an Environment Service to use a specific Bit extension component or a configuration file."),(0,r.mdx)("p",null,"For example, the React environment uses the Service Handler ",(0,r.mdx)("inlineCode",{parentName:"p"},"getCompiler()")," to configure the Compiler Environment Service to run the TypeScript extension component."),(0,r.mdx)("p",null,"Environment services run on various events. Whenever a service runs, it executes its corresponding service handler which consequently runs the configured aspect (in the previous example, that would be TypeScript)."),(0,r.mdx)("p",null,"Different components in a Bit workspace may use different environments. That means environment services need to execute their corresponding service handlers in the specific environment applied on the component currently being processed."),(0,r.mdx)("p",null,"For example, if ",(0,r.mdx)("em",{parentName:"p"},"component A")," uses the Node environment then the Compiler service processing that component, will execute the Service Handler (in that case, ",(0,r.mdx)("inlineCode",{parentName:"p"},"getCompiler"),") found in the Node environment."),(0,r.mdx)("h3",null,"List of service handlers"),(0,r.mdx)("h4",null,"getTester"),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-ts"},"getTester(...args : any[]): Tester\n")),(0,r.mdx)("p",null,"Returns a test runner to be used by the Tester service."),(0,r.mdx)("p",null,"For example:"),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-ts"},"export class ReactEnv implements Environment {\n constructor(\n // ...\n\n // The Jest Aspect\n private jestAspect: JestMain\n ) {}\n\n // ...\n\n getTester(jestConfigPath: string, jestModule = jest): Tester {\n const jestConfig = require.resolve('./jest/jest.config');\n return this.jestAspect.createTester(jestConfig);\n }\n}\n")),(0,r.mdx)("h4",null,"getCompiler"),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-ts"},"getCompiler(...args : any[]): Compiler\n")),(0,r.mdx)("p",null,"Returns a compiler to be used by the Compiler service."),(0,r.mdx)("p",null,"For example:"),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-ts"},"export class ReactEnv implements Environment {\n\nconstructor(\n // ...\n\n // The TypeScript aspect\n private tsAspect: TypescriptMain\n){}\n\n// ...\n\ngetCompiler() {\n const tsConfig = require.resolve('./typescript/tsconfig.json')\n return this.tsAspect.createCompiler(tsConfig);\n}\n")),(0,r.mdx)("h4",null,"getLinter"),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-ts"},"getLinter(...args : any[]): Linter\n")),(0,r.mdx)("p",null,"Returns a linter to be used by the Linter service."),(0,r.mdx)("p",null,"For example:"),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-ts"},"export class ReactEnv implements Environment {\n\n constructor(){\n // ...\n\n // The ESLint aspect\n private eslint: ESLintMain\n }\n\n // ...\n\n getLinter() {\n const eslintConfig = require.resolve('./eslint/eslintrc')\n return this.eslint.createLinter({\n config: eslintConfig,\n // resolve all plugins from the react environment\n pluginPath: __dirname,\n });\n }\n}\n")),(0,r.mdx)("h4",null,"getDevServer"),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-ts"},"getDevServer(...args : any[]): DevServer\n")),(0,r.mdx)("p",null,"Returns a DevServer to be used by the DevServer service. (A DevServer is essentially the combination of the bundler configurations, together with a specified 'listen' port number)"),(0,r.mdx)("p",null,"For example:"),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-ts"},"export class ReactEnv implements Environment {\n constructor(\n // ...\n\n // The Webpack aspect\n private webpack: WebpackMain\n ) {}\n\n // ...\n\n getDevServer(): DevServer {\n const withDocs = Object.assign(context, {\n entry: context.entry.concat([require.resolve('./docs')]),\n });\n return this.webpack.createDevServer(withDocs, webpackConfig);\n }\n}\n")),(0,r.mdx)("blockquote",null,(0,r.mdx)("p",{parentName:"blockquote"},"The above example runs the dev server with the environment's documentation template.")),(0,r.mdx)("h4",null,"getDocsTemplate"),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-ts"},"getDocsTemplate(...args : any[]): string\n")),(0,r.mdx)("p",null,"Returns the path to the documentation template files, to be used by the Documentation service."),(0,r.mdx)("p",null,"For example (see docs files ",(0,r.mdx)("a",{parentName:"p",href:"https://github.com/teambit/bit/tree/master/scopes/react/react/docs"},"here"),"):"),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-ts"},"export class ReactEnv implements Environment {\n // ...\n\n getDocsTemplate() {\n return require.resolve('./docs');\n }\n}\n")),(0,r.mdx)("h4",null,"getPackageJsonProps"),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-ts"},"getPackageJsonProps(...args : any[]): object\n")),(0,r.mdx)("p",null,"Returns an object that defines the ",(0,r.mdx)("inlineCode",{parentName:"p"},"package.json")," properties of the packages generated for components handled by this environment. This configuration is used by the Packager service."),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-ts"},"export class ReactEnv implements Environment {\n // ...\n\n getPackageJsonProps() {\n return {\n main: 'dist/{main}.js',\n types: '{main}.ts',\n };\n }\n}\n")),(0,r.mdx)("blockquote",null,(0,r.mdx)("p",{parentName:"blockquote"},"As with any other 'merging' process, the properties defined in the above returned object will be added to configurations set by Bit.\nConflicting properties will be overridden by the properties that are set here.\nConfigurations that are set here may also be overridden, either by the 'pkg aspect' or by workspace configurations set using the 'variants API'.")),(0,r.mdx)("h4",null,"getDependencies"),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-ts"},"getDependencies(component: any): Promise<DependencyList>\n")),(0,r.mdx)("p",null,"Returns an object that defines the default dependencies for components handled by this environment. The returned object is used by the Dependencies service."),(0,r.mdx)("p",null,"For example:"),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-ts"},"export class ReactEnv implements Environment {\n // ...\n\n async getDependencies() {\n return {\n dependencies: {\n react: '-',\n },\n devDependencies: {\n '@types/react': '16.9.43',\n '@types/jest': '~26.0.9',\n },\n peerDependencies: {\n react: '^16.13.1',\n 'react-dom': '^16.13.1',\n },\n };\n }\n}\n")),(0,r.mdx)("blockquote",null,(0,r.mdx)("p",{parentName:"blockquote"},"As with any other 'merging' process, the properties defined in the above returned object will be added to configurations set by Bit.\nConflicting properties will be overridden by the properties that are set here.\nConfigurations that are set here may also be overridden, either by the 'Dependency Resolver aspect' or by workspace configurations set using the 'variants API'.")),(0,r.mdx)("h4",null,"getBuildPipe"),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-ts"},"getBuildPipe(...args : any[]): BuildTask[]\n")),(0,r.mdx)("p",null,"Returns an array of build tasks to be used by the Builder service. Tasks will be added after and before Bit's pre-configured build tasks."),(0,r.mdx)("p",null,"For example:"),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-ts"},"export class ReactEnv implements Environment {\n constructor(\n // ...\n\n // The Compiler aspect\n private compiler: CompilerMain,\n\n // The Tester aspect\n private tester: TesterMain\n ) {}\n\n getBuildPipe(): BuildTask[] {\n return [this.compiler.createTask('StencilCompiler', this.getCompiler()), this.tester.task];\n }\n}\n")),(0,r.mdx)("h2",null,"Extending multiple runtime environments"),(0,r.mdx)("p",null,"An environment may operate in multiple runtime environments: 'Main', which runs on the server and 'UI' and 'Preview', which run on the browser.\nEach runtime environment runs all files that are named with its corresponding file pattern."),(0,r.mdx)("p",null,'An environment extension that runs on multiple runtimes is called "Aspect" an will have the following file structure:'),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre"},"|-- env-extension\n |-- env-extension.main.ts\n |-- env-extension.ui.tsx\n |-- env-extension.preview.tsx\n |-- env.extension.aspect.ts\n")),(0,r.mdx)("h3",null,"Registering an environment as an aspect"),(0,r.mdx)("p",null,"Create a ",(0,r.mdx)("inlineCode",{parentName:"p"},"*.aspect.ts")," file:"),(0,r.mdx)("p",null,"For example:"),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-shell"},"touch path/to/extension/env-extension.aspect.ts\n")),(0,r.mdx)("p",null,"Place the following lines to register your environment as a multiple runtime extension (a.k.a, an Aspect):"),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-ts"},"// env-extension.aspect.ts\n\nimport { Aspect } from '@teambit/harmony';\n\nexport const ReactWithProvidersAspect = Aspect.create({\n // The ID should be your component's ID\n // Make sure to track your extension component before registering it as an Aspect\n id: 'my-scope.react-with-providers',\n});\n")),(0,r.mdx)("h3",null,"Registering a runtime extension"),(0,r.mdx)("p",null,"An aspect is a collection of multiple extensions, each extending a specific runtime."),(0,r.mdx)("p",null,"Register each runtime extension to its corresponding runtime, using the ",(0,r.mdx)("inlineCode",{parentName:"p"},"addRuntime")," method."),(0,r.mdx)("p",null,"For example:"),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-typescript"},"// react-extension.preview.ts\n\nimport { PreviewRuntime } from '@teambit/preview';\nimport { ReactAspect, ReactPreview } from '@teambit/react';\nimport { ReactExtensionAspect } from './react-with-providers.aspect';\n\nexport class ReactExtensionPreview {\n static runtime = PreviewRuntime;\n\n static dependencies = [ReactAspect];\n\n static async provider([react]: [ReactPreview]) {\n return new ReactExtensionPreview();\n }\n}\n\nReactExtensionAspect.addRuntime(ReactExtensionPreview);\n")),(0,r.mdx)("h3",null,"Runtime environments"),(0,r.mdx)("h4",null,"Main"),(0,r.mdx)("p",null,(0,r.mdx)("inlineCode",{parentName:"p"},"*.main.runtime.ts")),(0,r.mdx)("p",null,"Node files that run in a node runtime environments and outputs to the terminal."),(0,r.mdx)("p",null,(0,r.mdx)("strong",{parentName:"p"},"Example:"),"\nThe React environment TypeScript compiler will be extended in the main runtime."),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-typescript"},"// react-extension.main.ts\n\nimport { MainRuntime } from '@teambit/cli';\nimport { EnvsAspect, EnvsMain } from '@teambit/envs';\nimport { ReactAspect, ReactMain } from '@teambit/react';\nimport { ReactExtensionAspect } from './react-extension.aspect';\n\nconst tsconfig = require('./typescript/tsconfig.json');\n\nexport class ReactExtensionMain {\n constructor(private react: ReactMain, private envs: EnvsMain) {}\n\n icon() {\n return 'https://static.bit.dev/extensions-icons/react.svg';\n }\n\n static runtime = MainRuntime;\n\n static dependencies = [ReactAspect, EnvsAspect];\n\n static async provider([react, envs]: [ReactMain, EnvsMain]) {\n const reactExtension = envs.compose(react, [react.overrideTsConfig(tsconfig)]);\n envs.registerEnv(reactExtension);\n return new ReactWithProvidersMain(react, envs);\n }\n}\n\nReactExtensionAspect.addRuntime(ReactExtensionMain);\n")),(0,r.mdx)("h4",null,"UI"),(0,r.mdx)("p",null,(0,r.mdx)("inlineCode",{parentName:"p"},"*.ui.runtime.[ts,js,jsx,tsx]")),(0,r.mdx)("p",null,"JSX files that run in the browser, as part of the Workspace/Scope UI bundle that is being served by the development server."),(0,r.mdx)("h4",null,"Preview"),(0,r.mdx)("p",null,(0,r.mdx)("inlineCode",{parentName:"p"},"*.preview.runtime.*")),(0,r.mdx)("p",null,"These files are served by the environment's server, as part of the environment's preview bundle (i.e, the component compositions and documentation).\n(The 'preview' runtime is rendered in the Workspace/Scope UI using an iframe.)"),(0,r.mdx)("p",null,(0,r.mdx)("strong",{parentName:"p"},"Example:"),'\nA new composition provider that will "wrap" every composition using that environment will be added using the preview runtime since it is part of the component compositions (which are being served to the browser by the environment\'s server).'),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-typescript"},"// react-extension.preview.ts\n\nimport { PreviewRuntime } from '@teambit/preview';\nimport { ReactAspect, ReactPreview } from '@teambit/react';\nimport { ReactExtensionAspect } from './react-with-providers.aspect';\nimport { Center } from './my-providers/center';\n\nexport class ReactExtensionPreview {\n static runtime = PreviewRuntime;\n\n static dependencies = [ReactAspect];\n\n static async provider([react]: [ReactPreview]) {\n react.registerProvider(Center);\n\n return new ReactExtensionPreview();\n }\n}\n\nReactExtensionAspect.addRuntime(ReactExtensionPreview);\n")),(0,r.mdx)("h2",null,"Troubleshooting"),(0,r.mdx)("p",null,(0,r.mdx)("strong",{parentName:"p"},"Problem:")," Components that are configured to use a specific environment, use the workspace's default environment, instead."),(0,r.mdx)("p",null,"For example:"),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-json"},'{\n "teambit.workspace/variants": {\n "*": {\n "teambit.react/react": {}\n },\n "components/utils": {\n "teambit.harmony/node": {}\n }\n }\n}\n')),(0,r.mdx)("p",null,"In the above example, components in the ",(0,r.mdx)("inlineCode",{parentName:"p"},"components/utils")," directory are set to use the Node environment.\nSince that selection is more specific than the one done using the ",(0,r.mdx)("inlineCode",{parentName:"p"},"*")," wildcard selector, it is expected to override it."),(0,r.mdx)("p",null,(0,r.mdx)("strong",{parentName:"p"},"Understanding the problem:"),"\nTo select the right configurations for each component, the 'Variants' aspect sorts all workspace configurations, from the most specific to the most general.\nThe first configuration set on an aspect (the most specific one) will be the one that is selected for that aspect.\nThat means, once Variants encounters configurations for an aspect, it stops looking for additional configurations for that specific aspect."),(0,r.mdx)("p",null,"Each environment is considered as a different aspect, even though they are all under the \"environments\" category and can only be used once per component.\n'Variants' does not understand categories, only individual aspects and therefore, cannot override one environment with a different environment."),(0,r.mdx)("p",null,(0,r.mdx)("strong",{parentName:"p"},"Solution #1:")),(0,r.mdx)("p",null,"Remove the ",(0,r.mdx)("inlineCode",{parentName:"p"},"*")," general selection and use only specific and exclusive selectors to configure environments\n(that means your workspace directories/ namespaces need to be structured in a way that enables complete selection of all components using selectors that are exclusive)."),(0,r.mdx)("p",null,"For example:"),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-json"},'{\n "teambit.workspace/variants": {\n "components/react": {\n "teambit.react/react": {}\n },\n "components/utils": {\n "teambit.harmony/node": {}\n }\n }\n}\n')),(0,r.mdx)("p",null,(0,r.mdx)("strong",{parentName:"p"},"Solution #2:"),"\nConfigure the environment using the Envs config API."),(0,r.mdx)("p",null,"Example:"),(0,r.mdx)("pre",null,(0,r.mdx)("code",{parentName:"pre",className:"language-json"},'{\n "teambit.workspace/variants": {\n "*": {\n "teambit.react/react": {}\n },\n "components/utils": {\n "teambit.harmony/node": {},\n "teambit.envs/envs": {\n "env": "teambit.harmony/node"\n }\n }\n }\n}\n')),(0,r.mdx)("blockquote",null,(0,r.mdx)("p",{parentName:"blockquote"},"Notice how the Node environment was added also as a standalone aspect, to ensure that it is registered as a dependency of the selected components.")),(0,r.mdx)("hr",null))}d.__bit_component=o,d.isMDXComponent=!0},29600:(e,n,t)=>{Object.defineProperty(n,"S",{enumerable:!0,get:function(){return o.default}});var o=r(t(81282));function r(e){return e&&e.__esModule?e:{default:e}}r.__bit_component={id:"teambit.envs/aspect-docs/envs@0.0.165",homepage:"https://bit.cloud/teambit/envs/aspect-docs/envs",exported:!0}},40040:e=>{e.exports=MdxJsReact},87363:e=>{e.exports=React}},n={};function t(o){var r=n[o];if(void 0!==r)return r.exports;var a=n[o]={exports:{}};return e[o](a,a.exports,t),a.exports}t.d=(e,n)=>{for(var o in n)t.o(n,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:n[o]})},t.o=(e,n)=>Object.prototype.hasOwnProperty.call(e,n),t.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};return(()=>{t.r(o),t.d(o,{compositions:()=>d,compositions_metadata:()=>x,overview:()=>u});var e={};t.r(e),t.d(e,{default:()=>p});var n=t(79043),r=(t(87363),t(40040));const a=TeambitMdxUiMdxScopeContext;var s=t(29600),i=["components"];function m(){return m=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},m.apply(this,arguments)}var l={},c="wrapper";function p(e){var n=e.components,t=function(e,n){if(null==e)return{};var t,o,r=function(e,n){if(null==e)return{};var t,o,r={},a=Object.keys(e);for(o=0;o<a.length;o++)t=a[o],n.indexOf(t)>=0||(r[t]=e[t]);return r}(e,n);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(o=0;o<a.length;o++)t=a[o],n.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(r[t]=e[t])}return r}(e,i);return(0,r.mdx)(c,m({},l,t,{components:n,mdxType:"MDXLayout"}),(0,r.mdx)(a.MDXScopeProvider,{components:{Envs:s.S},mdxType:"MDXScopeProvider"},(0,r.mdx)(s.S,{mdxType:"Envs"})))}p.isMDXComponent=!0;const d=[n],u=[e],x={compositions:[{displayName:"Logo",identifier:"Logo"}]}})(),o})()));
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.envs_envs@1.0.
|
2
|
-
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.envs_envs@1.0.
|
1
|
+
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.envs_envs@1.0.109/dist/env.composition.js';
|
2
|
+
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.envs_envs@1.0.109/dist/envs.docs.mdx';
|
3
3
|
|
4
4
|
export const compositions = [compositions_0];
|
5
5
|
export const overview = [overview_0];
|
package/package.json
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "@teambit/envs",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.109",
|
4
4
|
"homepage": "https://bit.cloud/teambit/envs/envs",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"componentId": {
|
7
7
|
"scope": "teambit.envs",
|
8
8
|
"name": "envs",
|
9
|
-
"version": "1.0.
|
9
|
+
"version": "1.0.109"
|
10
10
|
},
|
11
11
|
"dependencies": {
|
12
12
|
"chalk": "2.4.2",
|
@@ -19,27 +19,27 @@
|
|
19
19
|
"@teambit/harmony": "0.4.6",
|
20
20
|
"@teambit/bit-error": "0.0.404",
|
21
21
|
"@teambit/component-id": "1.2.0",
|
22
|
-
"@teambit/component": "1.0.
|
23
|
-
"@teambit/aspect-loader": "1.0.
|
24
|
-
"@teambit/cli": "0.0.
|
25
|
-
"@teambit/logger": "0.0.
|
26
|
-
"@teambit/worker": "0.0.
|
27
|
-
"@teambit/builder": "1.0.
|
28
|
-
"@teambit/bundler": "1.0.
|
29
|
-
"@teambit/compiler": "1.0.
|
30
|
-
"@teambit/dependency-resolver": "1.0.
|
31
|
-
"@teambit/formatter": "1.0.
|
32
|
-
"@teambit/isolator": "1.0.
|
33
|
-
"@teambit/linter": "1.0.
|
34
|
-
"@teambit/pkg": "1.0.
|
35
|
-
"@teambit/preview": "1.0.
|
36
|
-
"@teambit/schema": "1.0.
|
37
|
-
"@teambit/tester": "1.0.
|
38
|
-
"@teambit/webpack": "1.0.
|
39
|
-
"@teambit/graphql": "1.0.
|
40
|
-
"@teambit/bit": "1.6.
|
22
|
+
"@teambit/component": "1.0.109",
|
23
|
+
"@teambit/aspect-loader": "1.0.109",
|
24
|
+
"@teambit/cli": "0.0.841",
|
25
|
+
"@teambit/logger": "0.0.934",
|
26
|
+
"@teambit/worker": "0.0.1145",
|
27
|
+
"@teambit/builder": "1.0.109",
|
28
|
+
"@teambit/bundler": "1.0.109",
|
29
|
+
"@teambit/compiler": "1.0.109",
|
30
|
+
"@teambit/dependency-resolver": "1.0.109",
|
31
|
+
"@teambit/formatter": "1.0.109",
|
32
|
+
"@teambit/isolator": "1.0.109",
|
33
|
+
"@teambit/linter": "1.0.109",
|
34
|
+
"@teambit/pkg": "1.0.109",
|
35
|
+
"@teambit/preview": "1.0.109",
|
36
|
+
"@teambit/schema": "1.0.109",
|
37
|
+
"@teambit/tester": "1.0.109",
|
38
|
+
"@teambit/webpack": "1.0.109",
|
39
|
+
"@teambit/graphql": "1.0.109",
|
40
|
+
"@teambit/bit": "1.6.2",
|
41
41
|
"@teambit/component-issues": "0.0.138",
|
42
|
-
"@teambit/issues": "1.0.
|
42
|
+
"@teambit/issues": "1.0.109",
|
43
43
|
"@teambit/cli-table": "0.0.46"
|
44
44
|
},
|
45
45
|
"devDependencies": {
|
@@ -47,7 +47,7 @@
|
|
47
47
|
"@types/mocha": "9.1.0",
|
48
48
|
"@types/jest": "^29.2.2",
|
49
49
|
"@types/testing-library__jest-dom": "^5.9.5",
|
50
|
-
"@teambit/harmony.envs.core-aspect-env": "0.0.
|
50
|
+
"@teambit/harmony.envs.core-aspect-env": "0.0.14",
|
51
51
|
"@teambit/envs.aspect-docs.envs": "0.0.165"
|
52
52
|
},
|
53
53
|
"peerDependencies": {
|
package/env-definition.ts
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
import { Environment } from './environment';
|
2
|
-
|
3
|
-
/**
|
4
|
-
* API for component development environment.
|
5
|
-
*/
|
6
|
-
export class EnvDefinition {
|
7
|
-
constructor(
|
8
|
-
/**
|
9
|
-
* id of the env.
|
10
|
-
*/
|
11
|
-
readonly id: string,
|
12
|
-
|
13
|
-
/**
|
14
|
-
* env instance.
|
15
|
-
*/
|
16
|
-
readonly env: Environment
|
17
|
-
) {}
|
18
|
-
|
19
|
-
/**
|
20
|
-
* get icon of the env.
|
21
|
-
*/
|
22
|
-
get icon() {
|
23
|
-
// TODO: refactor this away from here.
|
24
|
-
const defaultIcon = `https://static.bit.dev/extensions-icons/default.svg`;
|
25
|
-
return this.env.icon || defaultIcon;
|
26
|
-
}
|
27
|
-
|
28
|
-
/**
|
29
|
-
* get the name of the env.
|
30
|
-
*/
|
31
|
-
get name() {
|
32
|
-
return this.env.name;
|
33
|
-
}
|
34
|
-
|
35
|
-
/**
|
36
|
-
* get the description of the env.
|
37
|
-
*/
|
38
|
-
get description() {
|
39
|
-
return this.env.description;
|
40
|
-
}
|
41
|
-
|
42
|
-
toObject() {
|
43
|
-
return {
|
44
|
-
id: this.id,
|
45
|
-
description: this.description,
|
46
|
-
name: this.name,
|
47
|
-
icon: this.icon,
|
48
|
-
};
|
49
|
-
}
|
50
|
-
}
|
package/env-interface.ts
DELETED
package/env-service-list.ts
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
import { EnvDefinition } from './env-definition';
|
2
|
-
import { EnvService } from './services';
|
3
|
-
|
4
|
-
export class EnvServiceList {
|
5
|
-
constructor(
|
6
|
-
/**
|
7
|
-
* environment
|
8
|
-
*/
|
9
|
-
readonly env: EnvDefinition,
|
10
|
-
|
11
|
-
/**
|
12
|
-
* services available on the env.
|
13
|
-
*/
|
14
|
-
readonly services: [string, EnvService<any>][]
|
15
|
-
) {}
|
16
|
-
|
17
|
-
toObject() {
|
18
|
-
return {
|
19
|
-
env: this.env.toObject(),
|
20
|
-
services: this.services.map(([id, service]) => {
|
21
|
-
return {
|
22
|
-
id,
|
23
|
-
name: service.name,
|
24
|
-
description: service.description,
|
25
|
-
// @ts-ignore
|
26
|
-
data: service.getDescriptor(this.env),
|
27
|
-
};
|
28
|
-
}),
|
29
|
-
};
|
30
|
-
}
|
31
|
-
}
|
package/env.fragment.ts
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
import { ShowFragment, Component } from '@teambit/component';
|
2
|
-
import chalk from 'chalk';
|
3
|
-
import { EnvsMain } from './environments.main.runtime';
|
4
|
-
|
5
|
-
export class EnvFragment implements ShowFragment {
|
6
|
-
constructor(private envs: EnvsMain) {}
|
7
|
-
|
8
|
-
readonly title = 'env';
|
9
|
-
|
10
|
-
async renderRow(component: Component) {
|
11
|
-
const envId = await this.getEnvId(component);
|
12
|
-
const isLoaded = this.envs.isEnvRegistered(envId);
|
13
|
-
return {
|
14
|
-
title: this.title,
|
15
|
-
content: isLoaded ? envId : `${envId} ${chalk.red('(not loaded)')}`,
|
16
|
-
};
|
17
|
-
}
|
18
|
-
|
19
|
-
async json(component: Component) {
|
20
|
-
const envId = await this.getEnvId(component);
|
21
|
-
return {
|
22
|
-
title: this.title,
|
23
|
-
json: envId,
|
24
|
-
};
|
25
|
-
}
|
26
|
-
|
27
|
-
private async getEnvId(component: Component) {
|
28
|
-
// don't use this.envs.getEnv(). otherwise, it'll throw an error when running bit-show on a remote component
|
29
|
-
// where the env can't register to the slot.
|
30
|
-
// return this.envs.getEnvId(component);
|
31
|
-
return (await this.envs.calculateEnvId(component)).toString();
|
32
|
-
}
|
33
|
-
|
34
|
-
weight = 3;
|
35
|
-
}
|
package/env.plugin.ts
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
import { PluginDefinition } from '@teambit/aspect-loader';
|
2
|
-
import { Aspect, Harmony } from '@teambit/harmony';
|
3
|
-
import { ComponentID } from '@teambit/component';
|
4
|
-
import { WorkerMain } from '@teambit/worker';
|
5
|
-
import { MainRuntime } from '@teambit/cli';
|
6
|
-
import { LoggerMain } from '@teambit/logger';
|
7
|
-
import { flatten } from 'lodash';
|
8
|
-
import { ServiceHandlerContext as EnvContext } from './services/service-handler-context';
|
9
|
-
import { Env } from './env-interface';
|
10
|
-
import { EnvsRegistry, ServicesRegistry } from './environments.main.runtime';
|
11
|
-
|
12
|
-
export class EnvPlugin implements PluginDefinition {
|
13
|
-
constructor(
|
14
|
-
private envSlot: EnvsRegistry,
|
15
|
-
private servicesRegistry: ServicesRegistry,
|
16
|
-
private loggerMain: LoggerMain,
|
17
|
-
private workerMain: WorkerMain,
|
18
|
-
private harmony: Harmony
|
19
|
-
) {}
|
20
|
-
|
21
|
-
pattern = '*.bit-env.*';
|
22
|
-
|
23
|
-
runtimes = [MainRuntime.name];
|
24
|
-
|
25
|
-
private createContext(envId: ComponentID) {
|
26
|
-
return new EnvContext(envId, this.loggerMain, this.workerMain, this.harmony);
|
27
|
-
}
|
28
|
-
|
29
|
-
private transformToLegacyEnv(envId: string, env: Env) {
|
30
|
-
const envComponentId = ComponentID.fromString(envId);
|
31
|
-
const envContext = this.createContext(envComponentId);
|
32
|
-
const allServices = flatten(this.servicesRegistry.values());
|
33
|
-
const transformers = allServices.reduce((acc, service) => {
|
34
|
-
if (!service.transform) return acc;
|
35
|
-
const currTransformer = service.transform(env, envContext);
|
36
|
-
if (!currTransformer) return acc;
|
37
|
-
return { ...acc, ...currTransformer };
|
38
|
-
}, {});
|
39
|
-
|
40
|
-
if (!env.preview && !env.compiler) return undefined;
|
41
|
-
|
42
|
-
return {
|
43
|
-
...transformers,
|
44
|
-
name: env.name,
|
45
|
-
icon: env.icon,
|
46
|
-
__getDescriptor: async () => {
|
47
|
-
return {
|
48
|
-
type: env.name,
|
49
|
-
};
|
50
|
-
},
|
51
|
-
id: envId,
|
52
|
-
};
|
53
|
-
}
|
54
|
-
|
55
|
-
register(object: any, aspect: Aspect) {
|
56
|
-
const env = this.transformToLegacyEnv(aspect.id, object);
|
57
|
-
if (!env) return undefined;
|
58
|
-
return this.envSlot.register(env);
|
59
|
-
}
|
60
|
-
}
|
package/environment.ts
DELETED
@@ -1,236 +0,0 @@
|
|
1
|
-
// TODO: @gilad refactor to an abstract env.
|
2
|
-
import type { Linter, LinterContext } from '@teambit/linter';
|
3
|
-
import type { Formatter, FormatterContext } from '@teambit/formatter';
|
4
|
-
import type { Tester } from '@teambit/tester';
|
5
|
-
import type { Compiler } from '@teambit/compiler';
|
6
|
-
import type { Bundler, BundlerContext, DevServer, DevServerContext } from '@teambit/bundler';
|
7
|
-
import type { BuildTask } from '@teambit/builder';
|
8
|
-
import type { SchemaExtractor } from '@teambit/schema';
|
9
|
-
import type { WebpackConfigTransformer } from '@teambit/webpack';
|
10
|
-
import type { PackageJsonProps } from '@teambit/pkg';
|
11
|
-
import type { DependencyDetector, EnvPolicyConfigObject } from '@teambit/dependency-resolver';
|
12
|
-
import type { Capsule } from '@teambit/isolator';
|
13
|
-
import type { Component } from '@teambit/component';
|
14
|
-
import { EnvPreviewConfig } from '@teambit/preview';
|
15
|
-
|
16
|
-
export type EnvDescriptor = {
|
17
|
-
type: string;
|
18
|
-
};
|
19
|
-
|
20
|
-
/**
|
21
|
-
* add a custom type and include all properties from within the environment.
|
22
|
-
*/
|
23
|
-
export interface Environment {
|
24
|
-
/**
|
25
|
-
* name of the environment.
|
26
|
-
*/
|
27
|
-
name?: string;
|
28
|
-
|
29
|
-
/**
|
30
|
-
* description of the environment.
|
31
|
-
*/
|
32
|
-
description?: string;
|
33
|
-
|
34
|
-
/**
|
35
|
-
* icon of the environment.
|
36
|
-
*/
|
37
|
-
icon?: string;
|
38
|
-
|
39
|
-
[key: string]: any; // :TODO need to define an abstract type for service handlers (now using any)
|
40
|
-
|
41
|
-
/**
|
42
|
-
* Returns the Environment descriptor
|
43
|
-
* Required for any task
|
44
|
-
*/
|
45
|
-
__getDescriptor?: () => Promise<EnvDescriptor>;
|
46
|
-
|
47
|
-
/**
|
48
|
-
* Returns a schema generator instance
|
49
|
-
*/
|
50
|
-
getSchemaExtractor?: (config?: any, tsserverPath?: string, contextPath?: string) => SchemaExtractor;
|
51
|
-
|
52
|
-
/**
|
53
|
-
* Returns the dev patterns to match doc files
|
54
|
-
*/
|
55
|
-
getDocsDevPatterns?: (component: Component) => string[];
|
56
|
-
|
57
|
-
/**
|
58
|
-
* Returns the dev patterns to match composition files
|
59
|
-
*/
|
60
|
-
getCompositionsDevPatterns?: (component: Component) => string[];
|
61
|
-
|
62
|
-
/**
|
63
|
-
* Returns additional dev patterns for the component.
|
64
|
-
* Patterns that were provided by getDocsDevPatterns, getTestsDevPatterns will be considered as dev files as well, without need to add them here.
|
65
|
-
*/
|
66
|
-
getDevPatterns?: (component: Component) => string[];
|
67
|
-
}
|
68
|
-
|
69
|
-
export interface DependenciesEnv extends Environment {
|
70
|
-
/**
|
71
|
-
* Returns the list of dependencies
|
72
|
-
* Required for any task
|
73
|
-
*/
|
74
|
-
getDependencies?: () => EnvPolicyConfigObject | Promise<EnvPolicyConfigObject>;
|
75
|
-
|
76
|
-
/**
|
77
|
-
* Returns a list of additional test host dependencies
|
78
|
-
* this will be added to the tester context
|
79
|
-
* This can be used in cases when you want specific dependencies to be resolved from the env during testing
|
80
|
-
* but you don't want these dependencies as peer dependencies of the component (as they are not used during runtime)
|
81
|
-
* An example for this is @angular/compiler, which during running tests you want to resolve from the env, but you don't
|
82
|
-
* need it during component runtime.
|
83
|
-
*/
|
84
|
-
getAdditionalTestHostDependencies?: () => string[] | Promise<string[]>;
|
85
|
-
|
86
|
-
/**
|
87
|
-
* Returns a list of additional host dependencies
|
88
|
-
* this list will be provided as globals on the window after bit preview bundle
|
89
|
-
* by default bit will merge this list with the peers from the getDependencies function
|
90
|
-
*/
|
91
|
-
getAdditionalHostDependencies?: () => string[] | Promise<string[]>;
|
92
|
-
|
93
|
-
/**
|
94
|
-
* Returns a list of dependency detectors
|
95
|
-
* this list will be used to detect all the dependencies in each file of the component
|
96
|
-
*/
|
97
|
-
getDepDetectors?: () => DependencyDetector[] | null;
|
98
|
-
}
|
99
|
-
|
100
|
-
export type GetNpmIgnoreContext = {
|
101
|
-
capsule: Capsule;
|
102
|
-
component: Component;
|
103
|
-
};
|
104
|
-
export interface PackageEnv extends Environment {
|
105
|
-
/**
|
106
|
-
* define the package json properties to add to each component.
|
107
|
-
* Used by `bit link` to augment package.json with new properties
|
108
|
-
*/
|
109
|
-
getPackageJsonProps?: () => PackageJsonProps;
|
110
|
-
|
111
|
-
/**
|
112
|
-
* return `.npmignore` entries to be written before packing the component
|
113
|
-
*/
|
114
|
-
getNpmIgnore?: (npmIgnoreContext?: GetNpmIgnoreContext) => string[];
|
115
|
-
}
|
116
|
-
|
117
|
-
export interface LinterEnv extends Environment {
|
118
|
-
/**
|
119
|
-
* Returns & configures the linter to use (ESLint, ...)
|
120
|
-
* Required for `bit lint`
|
121
|
-
*/
|
122
|
-
getLinter?: (context: LinterContext, transformers: any[]) => Linter;
|
123
|
-
}
|
124
|
-
|
125
|
-
export interface FormatterEnv extends Environment {
|
126
|
-
/**
|
127
|
-
* Returns & configures the formatter to use (prettier, ...)
|
128
|
-
* Required for `bit format`
|
129
|
-
*/
|
130
|
-
getFormatter?: (context: FormatterContext, transformers: any[]) => Formatter;
|
131
|
-
}
|
132
|
-
|
133
|
-
export interface PreviewEnv extends Environment {
|
134
|
-
/**
|
135
|
-
* Returns a paths to a function which mounts a given component to DOM
|
136
|
-
* Required for `bit start` & `bit build`
|
137
|
-
*/
|
138
|
-
getMounter?: () => string;
|
139
|
-
|
140
|
-
/**
|
141
|
-
* Returns a path to a docs template.
|
142
|
-
* Required for `bit start` & `bit build`
|
143
|
-
*/
|
144
|
-
getDocsTemplate?: () => string;
|
145
|
-
|
146
|
-
/**
|
147
|
-
* Returns a bundler for the preview.
|
148
|
-
* Required for `bit build` & `bit start`
|
149
|
-
*/
|
150
|
-
getBundler?: (context: BundlerContext, transformers: any[]) => Promise<Bundler>;
|
151
|
-
|
152
|
-
/**
|
153
|
-
* Returns preview config like the strategy name to use when bundling the components for the preview
|
154
|
-
*/
|
155
|
-
getPreviewConfig?: () => EnvPreviewConfig;
|
156
|
-
|
157
|
-
/**
|
158
|
-
* Returns a bundler for the env template.
|
159
|
-
* this bundler will be used to bundle the docs/compositions (or other preview) apps
|
160
|
-
* Required for `bit build` & `bit tag`
|
161
|
-
*/
|
162
|
-
getTemplateBundler?: (context: BundlerContext, transformers?: any[]) => Promise<Bundler>;
|
163
|
-
}
|
164
|
-
|
165
|
-
export type PipeServiceModifiersMap = Record<string, PipeServiceModifier>;
|
166
|
-
|
167
|
-
export interface PipeServiceModifier {
|
168
|
-
transformers?: Function[];
|
169
|
-
module?: any;
|
170
|
-
}
|
171
|
-
|
172
|
-
export interface BuilderEnv extends PreviewEnv {
|
173
|
-
/**
|
174
|
-
* @deprecated Fatal: a breaking API was introduced. Use getBuildPipe() instead.
|
175
|
-
*/
|
176
|
-
getPipe?: () => BuildTask[];
|
177
|
-
|
178
|
-
/**
|
179
|
-
* Returns the component build pipeline
|
180
|
-
* Either `getBuildPipe`, `getTagPipe`, or `getSnapPipe` is required for `bit build`
|
181
|
-
*/
|
182
|
-
getBuildPipe?: (modifiersMap?: PipeServiceModifiersMap) => BuildTask[];
|
183
|
-
|
184
|
-
/**
|
185
|
-
* Returns the component tag pipeline
|
186
|
-
* Either `getBuildPipe`, `getTagPipe`, or `getSnapPipe` is required for `bit build`
|
187
|
-
*/
|
188
|
-
getTagPipe?: (modifiersMap?: PipeServiceModifiersMap) => BuildTask[];
|
189
|
-
|
190
|
-
/**
|
191
|
-
* Returns the component snap pipeline
|
192
|
-
* Either `getBuildPipe`, `getTagPipe`, or `getSnapPipe` is required for `bit build`
|
193
|
-
*/
|
194
|
-
getSnapPipe?: (modifiersMap?: PipeServiceModifiersMap) => BuildTask[];
|
195
|
-
}
|
196
|
-
|
197
|
-
export interface TesterEnv extends Environment {
|
198
|
-
/**
|
199
|
-
* Returns a tester
|
200
|
-
* Required for `bit start` & `bit test`
|
201
|
-
*/
|
202
|
-
getTester?: (path: string, tester: any) => Tester;
|
203
|
-
|
204
|
-
/**
|
205
|
-
* Returns the dev patterns to match test files
|
206
|
-
*/
|
207
|
-
getTestsDevPatterns?: (component: Component) => string[];
|
208
|
-
}
|
209
|
-
|
210
|
-
export interface CompilerEnv {
|
211
|
-
/**
|
212
|
-
* Returns a compiler
|
213
|
-
* Required for making and reading dists, especially for `bit compile`
|
214
|
-
*/
|
215
|
-
getCompiler: () => Compiler;
|
216
|
-
}
|
217
|
-
|
218
|
-
export function hasCompiler(obj: Environment): obj is CompilerEnv {
|
219
|
-
return typeof obj.getCompiler === 'function';
|
220
|
-
}
|
221
|
-
|
222
|
-
export interface DevEnv extends PreviewEnv {
|
223
|
-
/**
|
224
|
-
* Required for `bit start`
|
225
|
-
*/
|
226
|
-
getDevEnvId?: (context?: any) => string;
|
227
|
-
|
228
|
-
/**
|
229
|
-
* Returns and configures the dev server
|
230
|
-
* Required for `bit start`
|
231
|
-
*/
|
232
|
-
getDevServer?: (
|
233
|
-
context: DevServerContext,
|
234
|
-
transformers: WebpackConfigTransformer[]
|
235
|
-
) => DevServer | Promise<DevServer>;
|
236
|
-
}
|
package/environments.aspect.ts
DELETED
package/environments.graphql.ts
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
import { Component } from '@teambit/component';
|
2
|
-
import { Schema } from '@teambit/graphql';
|
3
|
-
import gql from 'graphql-tag';
|
4
|
-
|
5
|
-
import { EnvsMain } from './environments.main.runtime';
|
6
|
-
|
7
|
-
export function environmentsSchema(environments: EnvsMain): Schema {
|
8
|
-
return {
|
9
|
-
typeDefs: gql`
|
10
|
-
extend type Component {
|
11
|
-
env: ExtensionDescriptor
|
12
|
-
}
|
13
|
-
|
14
|
-
type ExtensionDescriptor {
|
15
|
-
id: String
|
16
|
-
icon: String
|
17
|
-
}
|
18
|
-
`,
|
19
|
-
resolvers: {
|
20
|
-
Component: {
|
21
|
-
env: (component: Component) => {
|
22
|
-
return environments.getDescriptor(component);
|
23
|
-
},
|
24
|
-
},
|
25
|
-
},
|
26
|
-
};
|
27
|
-
}
|