@teambit/variants 0.0.1327 → 0.0.1329

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,4 +1,4 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <testsuites tests="0" failures="0" errors="0" skipped="0">
3
- <testsuite name="teambit.workspace/variants@0.0.1327" tests="0" failures="0" errors="0" skipped="0"/>
3
+ <testsuite name="teambit.workspace/variants@0.0.1329" tests="0" failures="0" errors="0" skipped="0"/>
4
4
  </testsuites>
@@ -1 +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.workspace/variants-preview"]=n():e["teambit.workspace/variants-preview"]=n()}(self,(()=>(()=>{"use strict";var e={88558:function(e,n,t){var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(n,"__esModule",{value:!0}),n.default=n.Variants=void 0;var o=t(3427);Object.defineProperty(n,"Variants",{enumerable:!0,get:function(){return a(o).default}}),Object.defineProperty(n,"default",{enumerable:!0,get:function(){return a(o).default}})},3427:(e,n,t)=>{var a={id:"teambit.workspace/content/variants@1.95.9",homepage:"https://bit.dev/teambit/workspace/content/variants",exported:!0};Object.defineProperty(n,"__esModule",{value:!0}),n.default=d,s(t(41594));var o=t(5016),r=t(65682),i=["components"];function s(e){return e&&e.__esModule?e:{default:e}}function l(){return l=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a])}return e},l.apply(this,arguments)}function c(e,n){if(null==e)return{};var t,a,o=p(e,n);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);for(a=0;a<r.length;a++)t=r[a],n.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(o[t]=e[t])}return o}function p(e,n){if(null==e)return{};var t,a,o={},r=Object.keys(e);for(a=0;a<r.length;a++)t=r[a],n.indexOf(t)>=0||(o[t]=e[t]);return o}s.__bit_component=a,l.__bit_component=a,c.__bit_component=a,p.__bit_component=a;var m={},u="wrapper";function d(e){var n=e.components,t=c(e,i);return(0,o.mdx)(u,l({},m,t,{components:n,mdxType:"MDXLayout"}),(0,o.mdx)(r.MDXScopeProvider,{components:{},mdxType:"MDXScopeProvider"},(0,o.mdx)("h1",null,"Variants"),(0,o.mdx)("p",null,"'Variants' enables you to configure groups of components with ",(0,o.mdx)("a",{parentName:"p",href:"/components/component-config"},"Component configuration"),".\nComponents are selected using their common directory path or namespace, and applied, collectively, with configurations (i.e, pairs of Aspects and their corresponding configs)."),(0,o.mdx)("p",null,"Since each component can be selected more than once using different selectors, Variants looks for all available configurations and ",(0,o.mdx)("a",{parentName:"p",href:"#merging-configurations"},"merges them together"),"."),(0,o.mdx)("p",null,"Use Variants as an efficient alternative to manually configuring each component's ",(0,o.mdx)("inlineCode",{parentName:"p"},"component.json"),"."),(0,o.mdx)("h2",null,"Variants Selector Examples"),(0,o.mdx)("h3",null,"Configure components in a directory"),(0,o.mdx)("p",null,"To select a group of components using a directory path, use the relative path to the components' parent directory from the workspace root. In the following example, all components under the ",(0,o.mdx)("inlineCode",{parentName:"p"},"components/utility-functions")," directory\n(and any sub-directories) will be included in this set:"),(0,o.mdx)("p",null,"This examples configures all components contained in the ",(0,o.mdx)("inlineCode",{parentName:"p"},"design")," directory with the ",(0,o.mdx)("a",{parentName:"p",href:"/react"},"React env"),"."),(0,o.mdx)("pre",null,(0,o.mdx)("code",{parentName:"pre",className:"language-json"},'"teambit.workspace/variants": {\n "design": {\n "teambit.react/react": {}\n },\n}\n')),(0,o.mdx)("h3",null,"Configure components using Namespaces"),(0,o.mdx)("p",null,"This option is recommended as it decouples your components' configurations from the workspace's file structure. It handles components using fundamental definitions that pertain to function and purpose, via their namespace.\nThe namespace selector behaves like a glob pattern, with the component name (including its namespace) being the equivalent of a file path being matched against the pattern.\nSpecifically, this means that namespace selectors support the location-specific ",(0,o.mdx)("inlineCode",{parentName:"p"},"*")," matcher, and the 'anywhere' ",(0,o.mdx)("inlineCode",{parentName:"p"},"**")," matcher for matching the component name."),(0,o.mdx)("p",null,"In the following example, any component under the ",(0,o.mdx)("inlineCode",{parentName:"p"},"utility-functions")," namespace (and it's sub-namespaces) will be included in this rule set:"),(0,o.mdx)("pre",null,(0,o.mdx)("code",{parentName:"pre",className:"language-json"},'"teambit.workspace/variants": {\n "{utility-functions/**}": { // Match any component name starts with utility-functions\n "teambit.harmony/node": {}\n },\n}\n')),(0,o.mdx)("p",null,"In the following example however, only components ",(0,o.mdx)("strong",{parentName:"p"},"directly")," under the ",(0,o.mdx)("inlineCode",{parentName:"p"},"utility-functions")," namespace will be included in this rule set:"),(0,o.mdx)("pre",null,(0,o.mdx)("code",{parentName:"pre",className:"language-json"},'"teambit.workspace/variants": {\n "{utility-functions/*}": { // Match utility-functions/sort-array but not utility-functions/string/reverse\n "teambit.harmony/node": {}\n },\n}\n')),(0,o.mdx)("h3",null,"Grouping selectors"),(0,o.mdx)("p",null,"You can add several sets for the same variant configuration by grouping selectors together:"),(0,o.mdx)("pre",null,(0,o.mdx)("code",{parentName:"pre",className:"language-json",metastring:'title="Multiple directory paths"',title:'"Multiple',directory:!0,'paths"':!0},'"teambit.workspace/variants": {\n "components/utils, components/react-ui": {\n "teambit.harmony/node": {}\n },\n}\n')),(0,o.mdx)("pre",null,(0,o.mdx)("code",{parentName:"pre",className:"language-json",metastring:'title="Multiple namespaces"',title:'"Multiple','namespaces"':!0},'"teambit.workspace/variants": {\n "{utility-functions/**}, {react-ui/**}": {\n "teambit.harmony/node": {}\n },\n}\n')),(0,o.mdx)("pre",null,(0,o.mdx)("code",{parentName:"pre",className:"language-json",metastring:'title="Paths and namespaces"',title:'"Paths',and:!0,'namespaces"':!0},'"teambit.workspace/variants": {\n "{utility-functions/**}, {react-ui/**}, components/utils, components/react-ui": {\n "teambit.harmony/node": {}\n },\n}\n')),(0,o.mdx)("h3",null,"Exclude directories/components from a rule"),(0,o.mdx)("p",null,"Using the ",(0,o.mdx)("inlineCode",{parentName:"p"},"!")," deselector you can exclude a set of components from a selector.\nThe ",(0,o.mdx)("inlineCode",{parentName:"p"},"!")," deselector works both for directories and namespaces, for example:"),(0,o.mdx)("h4",null,"Exclude a sub-directory directory from a rule"),(0,o.mdx)("p",null,"For example, apply the ",(0,o.mdx)("inlineCode",{parentName:"p"},"teambit.harmony/node")," environment on the ",(0,o.mdx)("inlineCode",{parentName:"p"},"utility-functions")," set, but exclude the ",(0,o.mdx)("inlineCode",{parentName:"p"},"utility-functions/react-utils")," folder from that set:"),(0,o.mdx)("pre",null,(0,o.mdx)("code",{parentName:"pre",className:"language-json",metastring:'title="workspace.json',title:'"workspace.json'},'"teambit.workspace/variants": {\n "components/utility-functions, !components/utility-functions/react-utils": {\n "teambit.harmony/node": {}\n },\n}\n')),(0,o.mdx)("h4",null,"Exclude namespaces from a rule"),(0,o.mdx)("p",null,"The following example applies the ",(0,o.mdx)("inlineCode",{parentName:"p"},"teambit.harmony/node")," environment on every component under the ",(0,o.mdx)("inlineCode",{parentName:"p"},"utils")," namespace, but excludes the ",(0,o.mdx)("inlineCode",{parentName:"p"},"utils/react")," namespace and its children from this set:"),(0,o.mdx)("pre",null,(0,o.mdx)("code",{parentName:"pre",className:"language-json",metastring:'title="workspace.json',title:'"workspace.json'},'"teambit.workspace/variants": {\n "{utils/**}, !{utils/react/**}": {\n "teambit.harmony/node": {}\n },\n}\n')),(0,o.mdx)("h3",null,"Special Variants"),(0,o.mdx)("h4",null,"The Wildcard (","*",") variant"),(0,o.mdx)("p",null,"To select all components in your workspace use the wildcard variant ",(0,o.mdx)("inlineCode",{parentName:"p"},"*"),". This is useful when you want to apply very general configurations, especially default or backup configurations,\non all components. Using this selector can produce unexpected consequences if the rules aren't general enough, so we recommend using this selector sparingly!\nFor example:"),(0,o.mdx)("pre",null,(0,o.mdx)("code",{parentName:"pre",className:"language-json"},'"teambit.workspace/variants": {\n "*": {\n "teambit.harmony/node": {}\n },\n}\n')),(0,o.mdx)("h2",null,"Merging Configurations"),(0,o.mdx)("p",null,"The merging process is similar to the way CSS rules are handled. Rules are cascaded from the selected group to all its members. When the same component is applied with conflicting configs (using multiple selectors),\nthe most specific variant (selector) overrides the more general ones."),(0,o.mdx)("p",null,"In the following example, ",(0,o.mdx)("inlineCode",{parentName:"p"},"my-org.my-scope/ui/inputs/button")," is selected using two different selectors (",(0,o.mdx)("inlineCode",{parentName:"p"},"{ui\\**}")," and ",(0,o.mdx)("inlineCode",{parentName:"p"},"{*\\inputs\\**}"),"), and configured with conflicting configurations."),(0,o.mdx)("pre",null,(0,o.mdx)("code",{parentName:"pre",className:"language-json"},'{\n "teambit.workspace/variants": {\n "{ui/**}": {\n "teambit.preview/preview": {\n "disabled": true\n }\n },\n "{*/inputs/**}": {\n "teambit.preview/preview": {\n "disabled": false\n }\n }\n }\n}\n')),(0,o.mdx)("p",null,"The more specific selector ",(0,o.mdx)("inlineCode",{parentName:"p"},'"{*/inputs/*}"')," will override the more general one ",(0,o.mdx)("inlineCode",{parentName:"p"},'"{ui/**}"'),". This will result in configuring ",(0,o.mdx)("inlineCode",{parentName:"p"},"my-org.my-scope/ui/inputs/button")," with ",(0,o.mdx)("inlineCode",{parentName:"p"},'"teambit.preview/preview": {"disabled": false}'),"."),(0,o.mdx)("h2",null,"Variants Flags"),(0,o.mdx)("h3",null,"Propagate"),(0,o.mdx)("p",null,"When using selectors which can propagate down to sub-sets, such as with directory selectors (where all sub-directories are included) or {namespace/","*","*","} type selectors,\nyou can prevent this propagation for specific set of inheritors, by setting set the ",(0,o.mdx)("inlineCode",{parentName:"p"},"propogate")," value of an inheriting group of components to ",(0,o.mdx)("inlineCode",{parentName:"p"},"false"),".\nOnce bit sees ",(0,o.mdx)("inlineCode",{parentName:"p"},'"propagate": false')," it uses only the configuration for this set and does not inherit."),(0,o.mdx)("pre",null,(0,o.mdx)("code",{parentName:"pre",className:"language-json",metastring:'title="workspace.json',title:'"workspace.json'},'"teambit.workspace/variants": {\n "components/react": {\n "my-aspect2": {\n "aspect2-react-key": "aspect2-react-val"\n }\n },\n "components/react/ui": {\n "propagate": false, // take this config, and don\'t propagate parent configs down to here\n "my-aspect1": {\n "aspect1-react-ui-key": "aspect1-react-ui-val"\n }\n }\n}\n')),(0,o.mdx)("pre",null,(0,o.mdx)("code",{parentName:"pre",className:"language-json",metastring:'title="components/react/ui/button\'s calculated configuration"',title:"\"components/react/ui/button's",calculated:!0,'configuration"':!0},'{\n "my-aspect1": {\n "aspect1-react-ui-key": "aspect1-react-ui-val"\n }\n}\n')),(0,o.mdx)("h2",null,"Removing aspects"),(0,o.mdx)("blockquote",null,(0,o.mdx)("p",{parentName:"blockquote"},"Note: Once a component has been tagged, any aspect configured for that component ",(0,o.mdx)("strong",{parentName:"p"},"can only")," be removed from the component via the following ",(0,o.mdx)("inlineCode",{parentName:"p"},"remove")," method. (if you haven't exported yet then ",(0,o.mdx)("inlineCode",{parentName:"p"},"untag")," would reset the effect of the tag)")),(0,o.mdx)("p",null,"There are numerous scenarios where you would not want a specific aspect to be defined on a subgroup but you don't want to exclude the sub-group from upstream rules, or use the ",(0,o.mdx)("inlineCode",{parentName:"p"},"propagate: false")," flag, since you want to receive the\nother configurations from the parent group rule/s."),(0,o.mdx)("p",null,"In that case, removing a specific aspect can be achieved using ",(0,o.mdx)("inlineCode",{parentName:"p"},'"-"')," as the value for an aspect's configuration. This will remove this aspect from the current component set."),(0,o.mdx)("p",null,"For instance, the following will remove ",(0,o.mdx)("inlineCode",{parentName:"p"},"my-aspect2")," from components in the ",(0,o.mdx)("inlineCode",{parentName:"p"},"components/react/ui")," set, while still inheriting other configs such as the ",(0,o.mdx)("inlineCode",{parentName:"p"},"my-aspect3")," aspect."),(0,o.mdx)("pre",null,(0,o.mdx)("code",{parentName:"pre",className:"language-json",metastring:'title="workspace.json',title:'"workspace.json'},'"teambit.workspace/variants": {\n "components/react": {\n "my-aspect2": {\n "aspect2-react-key": "aspect2-react-val"\n },\n "my-aspect3": {\n "aspect3-react-key": "aspect3-react-val"\n }\n },\n "components/react/ui": {\n "my-aspect1": {\n "aspect1-react-ui-key": "aspect1-react-ui-val"\n },\n "my-aspect2": "-" // Remove my-aspect2 from this set\'s configuration\n }\n}\n')),(0,o.mdx)("pre",null,(0,o.mdx)("code",{parentName:"pre",className:"language-json",metastring:'title="components/react/ui/button\'s calculated configuration"',title:"\"components/react/ui/button's",calculated:!0,'configuration"':!0},'{\n "my-aspect1": {\n "aspect1-react-ui-key": "aspect1-react-ui-val"\n },\n "my-aspect3": {\n "aspect3-react-key": "aspect3-react-val"\n }\n}\n'))))}d.__bit_component=a,d.isMDXComponent=!0},76322:(e,n,t)=>{var a={id:"teambit.workspace/variants@0.0.1327",homepage:"https://bit.cloud/teambit/workspace/variants",exported:!0};function o(){const e=r(t(41594));return o=function(){return e},e}function r(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(n,"__esModule",{value:!0}),n.Logo=void 0,o.__bit_component=a,r.__bit_component=a;const i=()=>o().default.createElement("div",{style:{height:"100%",display:"flex",justifyContent:"center"}},o().default.createElement("img",{style:{width:70},src:"https://static.bit.dev/extensions-icons/variants.svg"}));i.__bit_component=a,n.Logo=i},5016:e=>{e.exports=MdxJsReact},41594:e=>{e.exports=React},65682:e=>{e.exports=TeambitMdxUiMdxScopeContext}},n={};function t(a){var o=n[a];if(void 0!==o)return o.exports;var r=n[a]={exports:{}};return e[a].call(r.exports,r,r.exports,t),r.exports}t.n=e=>{var n=e&&e.__esModule?()=>e.default:()=>e;return t.d(n,{a:n}),n},t.d=(e,n)=>{for(var a in n)t.o(n,a)&&!t.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:n[a]})},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 a={};t.r(a),t.d(a,{compositions:()=>h,compositions_metadata:()=>x,overview:()=>g});var o={};t.r(o),t.d(o,{default:()=>f});var r=t(76322),i=(t(41594),t(5016)),s=t(65682),l=t(88558),c=t.n(l),p=["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 a in t)({}).hasOwnProperty.call(t,a)&&(e[a]=t[a])}return e},m.apply(null,arguments)}var u={},d="wrapper";function f(e){var n=e.components,t=function(e,n){if(null==e)return{};var t,a,o=function(e,n){if(null==e)return{};var t={};for(var a in e)if({}.hasOwnProperty.call(e,a)){if(n.includes(a))continue;t[a]=e[a]}return t}(e,n);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);for(a=0;a<r.length;a++)t=r[a],n.includes(t)||{}.propertyIsEnumerable.call(e,t)&&(o[t]=e[t])}return o}(e,p);return(0,i.mdx)(d,m({},u,t,{components:n,mdxType:"MDXLayout"}),(0,i.mdx)(s.MDXScopeProvider,{components:{Variants:c()},mdxType:"MDXScopeProvider"},(0,i.mdx)(c(),{mdxType:"Variants"})))}f.isMDXComponent=!0;const h=[r],g=[o],x={compositions:[{displayName:"Logo",identifier:"Logo"}]};return a})()));
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.workspace/variants-preview"]=n():e["teambit.workspace/variants-preview"]=n()}(self,(()=>(()=>{"use strict";var e={88558:function(e,n,t){var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(n,"__esModule",{value:!0}),n.default=n.Variants=void 0;var o=t(3427);Object.defineProperty(n,"Variants",{enumerable:!0,get:function(){return a(o).default}}),Object.defineProperty(n,"default",{enumerable:!0,get:function(){return a(o).default}})},3427:(e,n,t)=>{var a={id:"teambit.workspace/content/variants@1.95.9",homepage:"https://bit.dev/teambit/workspace/content/variants",exported:!0};Object.defineProperty(n,"__esModule",{value:!0}),n.default=d,s(t(41594));var o=t(5016),r=t(65682),i=["components"];function s(e){return e&&e.__esModule?e:{default:e}}function l(){return l=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a])}return e},l.apply(this,arguments)}function c(e,n){if(null==e)return{};var t,a,o=p(e,n);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);for(a=0;a<r.length;a++)t=r[a],n.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(o[t]=e[t])}return o}function p(e,n){if(null==e)return{};var t,a,o={},r=Object.keys(e);for(a=0;a<r.length;a++)t=r[a],n.indexOf(t)>=0||(o[t]=e[t]);return o}s.__bit_component=a,l.__bit_component=a,c.__bit_component=a,p.__bit_component=a;var m={},u="wrapper";function d(e){var n=e.components,t=c(e,i);return(0,o.mdx)(u,l({},m,t,{components:n,mdxType:"MDXLayout"}),(0,o.mdx)(r.MDXScopeProvider,{components:{},mdxType:"MDXScopeProvider"},(0,o.mdx)("h1",null,"Variants"),(0,o.mdx)("p",null,"'Variants' enables you to configure groups of components with ",(0,o.mdx)("a",{parentName:"p",href:"/components/component-config"},"Component configuration"),".\nComponents are selected using their common directory path or namespace, and applied, collectively, with configurations (i.e, pairs of Aspects and their corresponding configs)."),(0,o.mdx)("p",null,"Since each component can be selected more than once using different selectors, Variants looks for all available configurations and ",(0,o.mdx)("a",{parentName:"p",href:"#merging-configurations"},"merges them together"),"."),(0,o.mdx)("p",null,"Use Variants as an efficient alternative to manually configuring each component's ",(0,o.mdx)("inlineCode",{parentName:"p"},"component.json"),"."),(0,o.mdx)("h2",null,"Variants Selector Examples"),(0,o.mdx)("h3",null,"Configure components in a directory"),(0,o.mdx)("p",null,"To select a group of components using a directory path, use the relative path to the components' parent directory from the workspace root. In the following example, all components under the ",(0,o.mdx)("inlineCode",{parentName:"p"},"components/utility-functions")," directory\n(and any sub-directories) will be included in this set:"),(0,o.mdx)("p",null,"This examples configures all components contained in the ",(0,o.mdx)("inlineCode",{parentName:"p"},"design")," directory with the ",(0,o.mdx)("a",{parentName:"p",href:"/react"},"React env"),"."),(0,o.mdx)("pre",null,(0,o.mdx)("code",{parentName:"pre",className:"language-json"},'"teambit.workspace/variants": {\n "design": {\n "teambit.react/react": {}\n },\n}\n')),(0,o.mdx)("h3",null,"Configure components using Namespaces"),(0,o.mdx)("p",null,"This option is recommended as it decouples your components' configurations from the workspace's file structure. It handles components using fundamental definitions that pertain to function and purpose, via their namespace.\nThe namespace selector behaves like a glob pattern, with the component name (including its namespace) being the equivalent of a file path being matched against the pattern.\nSpecifically, this means that namespace selectors support the location-specific ",(0,o.mdx)("inlineCode",{parentName:"p"},"*")," matcher, and the 'anywhere' ",(0,o.mdx)("inlineCode",{parentName:"p"},"**")," matcher for matching the component name."),(0,o.mdx)("p",null,"In the following example, any component under the ",(0,o.mdx)("inlineCode",{parentName:"p"},"utility-functions")," namespace (and it's sub-namespaces) will be included in this rule set:"),(0,o.mdx)("pre",null,(0,o.mdx)("code",{parentName:"pre",className:"language-json"},'"teambit.workspace/variants": {\n "{utility-functions/**}": { // Match any component name starts with utility-functions\n "teambit.harmony/node": {}\n },\n}\n')),(0,o.mdx)("p",null,"In the following example however, only components ",(0,o.mdx)("strong",{parentName:"p"},"directly")," under the ",(0,o.mdx)("inlineCode",{parentName:"p"},"utility-functions")," namespace will be included in this rule set:"),(0,o.mdx)("pre",null,(0,o.mdx)("code",{parentName:"pre",className:"language-json"},'"teambit.workspace/variants": {\n "{utility-functions/*}": { // Match utility-functions/sort-array but not utility-functions/string/reverse\n "teambit.harmony/node": {}\n },\n}\n')),(0,o.mdx)("h3",null,"Grouping selectors"),(0,o.mdx)("p",null,"You can add several sets for the same variant configuration by grouping selectors together:"),(0,o.mdx)("pre",null,(0,o.mdx)("code",{parentName:"pre",className:"language-json",metastring:'title="Multiple directory paths"',title:'"Multiple',directory:!0,'paths"':!0},'"teambit.workspace/variants": {\n "components/utils, components/react-ui": {\n "teambit.harmony/node": {}\n },\n}\n')),(0,o.mdx)("pre",null,(0,o.mdx)("code",{parentName:"pre",className:"language-json",metastring:'title="Multiple namespaces"',title:'"Multiple','namespaces"':!0},'"teambit.workspace/variants": {\n "{utility-functions/**}, {react-ui/**}": {\n "teambit.harmony/node": {}\n },\n}\n')),(0,o.mdx)("pre",null,(0,o.mdx)("code",{parentName:"pre",className:"language-json",metastring:'title="Paths and namespaces"',title:'"Paths',and:!0,'namespaces"':!0},'"teambit.workspace/variants": {\n "{utility-functions/**}, {react-ui/**}, components/utils, components/react-ui": {\n "teambit.harmony/node": {}\n },\n}\n')),(0,o.mdx)("h3",null,"Exclude directories/components from a rule"),(0,o.mdx)("p",null,"Using the ",(0,o.mdx)("inlineCode",{parentName:"p"},"!")," deselector you can exclude a set of components from a selector.\nThe ",(0,o.mdx)("inlineCode",{parentName:"p"},"!")," deselector works both for directories and namespaces, for example:"),(0,o.mdx)("h4",null,"Exclude a sub-directory directory from a rule"),(0,o.mdx)("p",null,"For example, apply the ",(0,o.mdx)("inlineCode",{parentName:"p"},"teambit.harmony/node")," environment on the ",(0,o.mdx)("inlineCode",{parentName:"p"},"utility-functions")," set, but exclude the ",(0,o.mdx)("inlineCode",{parentName:"p"},"utility-functions/react-utils")," folder from that set:"),(0,o.mdx)("pre",null,(0,o.mdx)("code",{parentName:"pre",className:"language-json",metastring:'title="workspace.json',title:'"workspace.json'},'"teambit.workspace/variants": {\n "components/utility-functions, !components/utility-functions/react-utils": {\n "teambit.harmony/node": {}\n },\n}\n')),(0,o.mdx)("h4",null,"Exclude namespaces from a rule"),(0,o.mdx)("p",null,"The following example applies the ",(0,o.mdx)("inlineCode",{parentName:"p"},"teambit.harmony/node")," environment on every component under the ",(0,o.mdx)("inlineCode",{parentName:"p"},"utils")," namespace, but excludes the ",(0,o.mdx)("inlineCode",{parentName:"p"},"utils/react")," namespace and its children from this set:"),(0,o.mdx)("pre",null,(0,o.mdx)("code",{parentName:"pre",className:"language-json",metastring:'title="workspace.json',title:'"workspace.json'},'"teambit.workspace/variants": {\n "{utils/**}, !{utils/react/**}": {\n "teambit.harmony/node": {}\n },\n}\n')),(0,o.mdx)("h3",null,"Special Variants"),(0,o.mdx)("h4",null,"The Wildcard (","*",") variant"),(0,o.mdx)("p",null,"To select all components in your workspace use the wildcard variant ",(0,o.mdx)("inlineCode",{parentName:"p"},"*"),". This is useful when you want to apply very general configurations, especially default or backup configurations,\non all components. Using this selector can produce unexpected consequences if the rules aren't general enough, so we recommend using this selector sparingly!\nFor example:"),(0,o.mdx)("pre",null,(0,o.mdx)("code",{parentName:"pre",className:"language-json"},'"teambit.workspace/variants": {\n "*": {\n "teambit.harmony/node": {}\n },\n}\n')),(0,o.mdx)("h2",null,"Merging Configurations"),(0,o.mdx)("p",null,"The merging process is similar to the way CSS rules are handled. Rules are cascaded from the selected group to all its members. When the same component is applied with conflicting configs (using multiple selectors),\nthe most specific variant (selector) overrides the more general ones."),(0,o.mdx)("p",null,"In the following example, ",(0,o.mdx)("inlineCode",{parentName:"p"},"my-org.my-scope/ui/inputs/button")," is selected using two different selectors (",(0,o.mdx)("inlineCode",{parentName:"p"},"{ui\\**}")," and ",(0,o.mdx)("inlineCode",{parentName:"p"},"{*\\inputs\\**}"),"), and configured with conflicting configurations."),(0,o.mdx)("pre",null,(0,o.mdx)("code",{parentName:"pre",className:"language-json"},'{\n "teambit.workspace/variants": {\n "{ui/**}": {\n "teambit.preview/preview": {\n "disabled": true\n }\n },\n "{*/inputs/**}": {\n "teambit.preview/preview": {\n "disabled": false\n }\n }\n }\n}\n')),(0,o.mdx)("p",null,"The more specific selector ",(0,o.mdx)("inlineCode",{parentName:"p"},'"{*/inputs/*}"')," will override the more general one ",(0,o.mdx)("inlineCode",{parentName:"p"},'"{ui/**}"'),". This will result in configuring ",(0,o.mdx)("inlineCode",{parentName:"p"},"my-org.my-scope/ui/inputs/button")," with ",(0,o.mdx)("inlineCode",{parentName:"p"},'"teambit.preview/preview": {"disabled": false}'),"."),(0,o.mdx)("h2",null,"Variants Flags"),(0,o.mdx)("h3",null,"Propagate"),(0,o.mdx)("p",null,"When using selectors which can propagate down to sub-sets, such as with directory selectors (where all sub-directories are included) or {namespace/","*","*","} type selectors,\nyou can prevent this propagation for specific set of inheritors, by setting set the ",(0,o.mdx)("inlineCode",{parentName:"p"},"propogate")," value of an inheriting group of components to ",(0,o.mdx)("inlineCode",{parentName:"p"},"false"),".\nOnce bit sees ",(0,o.mdx)("inlineCode",{parentName:"p"},'"propagate": false')," it uses only the configuration for this set and does not inherit."),(0,o.mdx)("pre",null,(0,o.mdx)("code",{parentName:"pre",className:"language-json",metastring:'title="workspace.json',title:'"workspace.json'},'"teambit.workspace/variants": {\n "components/react": {\n "my-aspect2": {\n "aspect2-react-key": "aspect2-react-val"\n }\n },\n "components/react/ui": {\n "propagate": false, // take this config, and don\'t propagate parent configs down to here\n "my-aspect1": {\n "aspect1-react-ui-key": "aspect1-react-ui-val"\n }\n }\n}\n')),(0,o.mdx)("pre",null,(0,o.mdx)("code",{parentName:"pre",className:"language-json",metastring:'title="components/react/ui/button\'s calculated configuration"',title:"\"components/react/ui/button's",calculated:!0,'configuration"':!0},'{\n "my-aspect1": {\n "aspect1-react-ui-key": "aspect1-react-ui-val"\n }\n}\n')),(0,o.mdx)("h2",null,"Removing aspects"),(0,o.mdx)("blockquote",null,(0,o.mdx)("p",{parentName:"blockquote"},"Note: Once a component has been tagged, any aspect configured for that component ",(0,o.mdx)("strong",{parentName:"p"},"can only")," be removed from the component via the following ",(0,o.mdx)("inlineCode",{parentName:"p"},"remove")," method. (if you haven't exported yet then ",(0,o.mdx)("inlineCode",{parentName:"p"},"untag")," would reset the effect of the tag)")),(0,o.mdx)("p",null,"There are numerous scenarios where you would not want a specific aspect to be defined on a subgroup but you don't want to exclude the sub-group from upstream rules, or use the ",(0,o.mdx)("inlineCode",{parentName:"p"},"propagate: false")," flag, since you want to receive the\nother configurations from the parent group rule/s."),(0,o.mdx)("p",null,"In that case, removing a specific aspect can be achieved using ",(0,o.mdx)("inlineCode",{parentName:"p"},'"-"')," as the value for an aspect's configuration. This will remove this aspect from the current component set."),(0,o.mdx)("p",null,"For instance, the following will remove ",(0,o.mdx)("inlineCode",{parentName:"p"},"my-aspect2")," from components in the ",(0,o.mdx)("inlineCode",{parentName:"p"},"components/react/ui")," set, while still inheriting other configs such as the ",(0,o.mdx)("inlineCode",{parentName:"p"},"my-aspect3")," aspect."),(0,o.mdx)("pre",null,(0,o.mdx)("code",{parentName:"pre",className:"language-json",metastring:'title="workspace.json',title:'"workspace.json'},'"teambit.workspace/variants": {\n "components/react": {\n "my-aspect2": {\n "aspect2-react-key": "aspect2-react-val"\n },\n "my-aspect3": {\n "aspect3-react-key": "aspect3-react-val"\n }\n },\n "components/react/ui": {\n "my-aspect1": {\n "aspect1-react-ui-key": "aspect1-react-ui-val"\n },\n "my-aspect2": "-" // Remove my-aspect2 from this set\'s configuration\n }\n}\n')),(0,o.mdx)("pre",null,(0,o.mdx)("code",{parentName:"pre",className:"language-json",metastring:'title="components/react/ui/button\'s calculated configuration"',title:"\"components/react/ui/button's",calculated:!0,'configuration"':!0},'{\n "my-aspect1": {\n "aspect1-react-ui-key": "aspect1-react-ui-val"\n },\n "my-aspect3": {\n "aspect3-react-key": "aspect3-react-val"\n }\n}\n'))))}d.__bit_component=a,d.isMDXComponent=!0},63060:(e,n,t)=>{var a={id:"teambit.workspace/variants@0.0.1329",homepage:"https://bit.cloud/teambit/workspace/variants",exported:!0};function o(){const e=r(t(41594));return o=function(){return e},e}function r(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(n,"__esModule",{value:!0}),n.Logo=void 0,o.__bit_component=a,r.__bit_component=a;const i=()=>o().default.createElement("div",{style:{height:"100%",display:"flex",justifyContent:"center"}},o().default.createElement("img",{style:{width:70},src:"https://static.bit.dev/extensions-icons/variants.svg"}));i.__bit_component=a,n.Logo=i},5016:e=>{e.exports=MdxJsReact},41594:e=>{e.exports=React},65682:e=>{e.exports=TeambitMdxUiMdxScopeContext}},n={};function t(a){var o=n[a];if(void 0!==o)return o.exports;var r=n[a]={exports:{}};return e[a].call(r.exports,r,r.exports,t),r.exports}t.n=e=>{var n=e&&e.__esModule?()=>e.default:()=>e;return t.d(n,{a:n}),n},t.d=(e,n)=>{for(var a in n)t.o(n,a)&&!t.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:n[a]})},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 a={};t.r(a),t.d(a,{compositions:()=>h,compositions_metadata:()=>x,overview:()=>g});var o={};t.r(o),t.d(o,{default:()=>f});var r=t(63060),i=(t(41594),t(5016)),s=t(65682),l=t(88558),c=t.n(l),p=["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 a in t)({}).hasOwnProperty.call(t,a)&&(e[a]=t[a])}return e},m.apply(null,arguments)}var u={},d="wrapper";function f(e){var n=e.components,t=function(e,n){if(null==e)return{};var t,a,o=function(e,n){if(null==e)return{};var t={};for(var a in e)if({}.hasOwnProperty.call(e,a)){if(n.includes(a))continue;t[a]=e[a]}return t}(e,n);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);for(a=0;a<r.length;a++)t=r[a],n.includes(t)||{}.propertyIsEnumerable.call(e,t)&&(o[t]=e[t])}return o}(e,p);return(0,i.mdx)(d,m({},u,t,{components:n,mdxType:"MDXLayout"}),(0,i.mdx)(s.MDXScopeProvider,{components:{Variants:c()},mdxType:"MDXScopeProvider"},(0,i.mdx)(c(),{mdxType:"Variants"})))}f.isMDXComponent=!0;const h=[r],g=[o],x={compositions:[{displayName:"Logo",identifier:"Logo"}]};return a})()));
@@ -869,7 +869,11 @@
869
869
  "character": 3
870
870
  },
871
871
  "name": "ExtensionDataList",
872
- "packageName": "@teambit/legacy/dist/consumer/config/extension-data"
872
+ "componentId": {
873
+ "scope": "teambit.legacy",
874
+ "name": "extension-data",
875
+ "version": "0.0.2"
876
+ }
873
877
  },
874
878
  "isOptional": false
875
879
  },
@@ -1549,7 +1553,11 @@
1549
1553
  "character": 1
1550
1554
  },
1551
1555
  "name": "ExtensionDataList",
1552
- "packageName": "@teambit/legacy/dist/consumer/config/extension-data"
1556
+ "componentId": {
1557
+ "scope": "teambit.legacy",
1558
+ "name": "extension-data",
1559
+ "version": "0.0.2"
1560
+ }
1553
1561
  },
1554
1562
  "modifiers": []
1555
1563
  },
@@ -1606,7 +1614,7 @@
1606
1614
  "componentId": {
1607
1615
  "scope": "teambit.workspace",
1608
1616
  "name": "variants",
1609
- "version": "0.0.1327"
1617
+ "version": "0.0.1329"
1610
1618
  },
1611
1619
  "taggedModuleExports": []
1612
1620
  }
@@ -1,5 +1,5 @@
1
- import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.workspace_variants@0.0.1327/dist/variants.composition.js';
2
- import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.workspace_variants@0.0.1327/dist/variants.docs.mdx';
1
+ import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.workspace_variants@0.0.1329/dist/variants.composition.js';
2
+ import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.workspace_variants@0.0.1329/dist/variants.docs.mdx';
3
3
 
4
4
  export const compositions = [compositions_0];
5
5
  export const overview = [overview_0];
@@ -1,5 +1,5 @@
1
1
  import type { ConfigMain } from '@teambit/config';
2
- import { ExtensionDataList } from '@teambit/legacy/dist/consumer/config/extension-data';
2
+ import { ExtensionDataList } from '@teambit/legacy.extension-data';
3
3
  import { PathLinuxRelative } from '@teambit/toolbox.path.path';
4
4
  import { MatchedPatternWithConfig } from '@teambit/workspace.modules.match-pattern';
5
5
  export type Patterns = {
@@ -18,9 +18,9 @@ function _config() {
18
18
  };
19
19
  return data;
20
20
  }
21
- function _extensionData() {
22
- const data = require("@teambit/legacy/dist/consumer/config/extension-data");
23
- _extensionData = function () {
21
+ function _legacy() {
22
+ const data = require("@teambit/legacy.extension-data");
23
+ _legacy = function () {
24
24
  return data;
25
25
  };
26
26
  return data;
@@ -112,7 +112,7 @@ class VariantsMain {
112
112
  propagate = false;
113
113
  }
114
114
  });
115
- const mergedExtensions = _extensionData().ExtensionDataList.mergeConfigs(extensionsToMerge);
115
+ const mergedExtensions = _legacy().ExtensionDataList.mergeConfigs(extensionsToMerge);
116
116
  const result = {
117
117
  defaultScope,
118
118
  extensions: mergedExtensions,
@@ -152,7 +152,7 @@ _defineProperty(VariantsMain, "runtime", _cli().MainRuntime);
152
152
  _defineProperty(VariantsMain, "dependencies", [_config().ConfigAspect]);
153
153
  function getExtensionFromPatternRawConfig(config) {
154
154
  const rawExtensions = (0, _lodash().omit)(config, INTERNAL_FIELDS);
155
- const extensions = _extensionData().ExtensionDataList.fromConfigObject(rawExtensions);
155
+ const extensions = _legacy().ExtensionDataList.fromConfigObject(rawExtensions);
156
156
  return extensions;
157
157
  }
158
158
  _variants().VariantsAspect.addRuntime(VariantsMain);
@@ -1 +1 @@
1
- {"version":3,"names":["_cli","data","require","_config","_extensionData","_commentJson","_lodash","_workspaceModules","_legacyBitId","_variants","_defineProperty","e","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","INTERNAL_FIELDS","VariantsMain","constructor","patterns","configAspect","validateConfig","forEach","patternConfig","pattern","defaultScope","isValidScopeName","InvalidScopeName","undefined","raw","byRootDirAndName","rootDir","componentName","matches","match","isMatchPattern","excluded","push","config","specificity","maxSpecificity","sortedMatches","sortMatchesBySpecificity","propagate","extensionsToMerge","getExtensionFromPatternRawConfig","mergedExtensions","ExtensionDataList","mergeConfigs","result","extensions","length","setExtension","variant","extensionId","extensionConfig","opts","newVariant","assign","VariantsAspect","id","overrideExisting","ignoreVersion","provider","exports","MainRuntime","ConfigAspect","rawExtensions","omit","fromConfigObject","addRuntime"],"sources":["variants.main.runtime.ts"],"sourcesContent":["import { MainRuntime } from '@teambit/cli';\nimport { ConfigAspect } from '@teambit/config';\nimport type { ConfigMain } from '@teambit/config';\nimport { ExtensionDataList } from '@teambit/legacy/dist/consumer/config/extension-data';\nimport { PathLinuxRelative } from '@teambit/toolbox.path.path';\nimport { assign } from 'comment-json';\nimport { omit, forEach } from 'lodash';\nimport {\n MatchedPatternWithConfig,\n isMatchPattern,\n sortMatchesBySpecificity,\n} from '@teambit/workspace.modules.match-pattern';\nimport { InvalidScopeName, isValidScopeName } from '@teambit/legacy-bit-id';\nimport { VariantsAspect } from './variants.aspect';\n\nexport type Patterns = { [pattern: string]: Record<string, any> };\n\nexport type VariantsComponentConfig = {\n propagate: boolean;\n exclude?: string[];\n defaultScope?: string;\n extensions: ExtensionDataList;\n maxSpecificity: number;\n sortedMatches: MatchedPatternWithConfig[];\n};\n\nconst INTERNAL_FIELDS = ['propagate', 'exclude', 'defaultScope'];\n\nexport class VariantsMain {\n static runtime = MainRuntime;\n static dependencies = [ConfigAspect];\n\n constructor(\n private patterns: Patterns,\n private configAspect: ConfigMain\n ) {\n this.validateConfig();\n }\n\n private validateConfig() {\n forEach(this.patterns, (patternConfig: Record<string, any>, pattern: string) => {\n if (patternConfig.defaultScope && !isValidScopeName(patternConfig.defaultScope)) {\n throw new InvalidScopeName(patternConfig.defaultScope, undefined, pattern);\n }\n });\n }\n\n raw(): Patterns {\n return this.patterns;\n }\n\n /**\n * Gets the config for specific component after merge all matching patterns of the component dir and id in the variants section\n * @param rootDir\n */\n byRootDirAndName(rootDir: PathLinuxRelative, componentName: string): VariantsComponentConfig | undefined {\n const matches: MatchedPatternWithConfig[] = [];\n forEach(this.patterns, (patternConfig, pattern) => {\n const match = isMatchPattern(rootDir, componentName, pattern);\n\n // Ignore matches with exclude matches\n if (match.match && !match.excluded) {\n matches.push({\n config: patternConfig,\n specificity: match.maxSpecificity,\n pattern: match.pattern,\n });\n }\n });\n\n const sortedMatches: MatchedPatternWithConfig[] = sortMatchesBySpecificity(matches);\n\n let defaultScope;\n let propagate = true;\n const extensionsToMerge: ExtensionDataList[] = [];\n sortedMatches.forEach((match) => {\n defaultScope = defaultScope || match.config.defaultScope;\n if (propagate) {\n extensionsToMerge.push(getExtensionFromPatternRawConfig(match.config));\n }\n if (match.config.propagate === false) {\n propagate = false;\n }\n });\n\n const mergedExtensions = ExtensionDataList.mergeConfigs(extensionsToMerge);\n const result = {\n defaultScope,\n extensions: mergedExtensions,\n propagate,\n maxSpecificity: sortedMatches.length ? sortedMatches[0].specificity : -1,\n sortedMatches,\n };\n return result;\n }\n\n /**\n * Updates the specified extension object of the specified variant.\n * @param {string} variant - The variant pattern.\n * @param {string} extensionId - The extension ID.\n * @param {Object} extensionConfig - The extension configuration.\n * @param {boolean} opts.overrideExisting - When true, any existing entries are overriden.\n */\n setExtension(variant: string, extensionId: string, extensionConfig: any, opts?: { overrideExisting?: boolean }) {\n const newVariant = this.patterns[variant] ?? {};\n assign(newVariant, { [extensionId]: extensionConfig });\n assign(this.patterns, { [variant]: newVariant });\n this.configAspect.setExtension(VariantsAspect.id, this.patterns, {\n overrideExisting: opts?.overrideExisting === true,\n ignoreVersion: true,\n });\n }\n\n static async provider([configAspect]: [ConfigMain], config) {\n return new VariantsMain(config, configAspect);\n }\n}\n\nfunction getExtensionFromPatternRawConfig(config: Record<string, any>) {\n const rawExtensions = omit(config, INTERNAL_FIELDS);\n const extensions = ExtensionDataList.fromConfigObject(rawExtensions);\n return extensions;\n}\n\nVariantsAspect.addRuntime(VariantsMain);\n"],"mappings":";;;;;;AAAA,SAAAA,KAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,IAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,QAAA;EAAA,MAA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I,CAAC,CAAC;IAC/C,IAAAK,qBAAM,EAACD,UAAU,EAAE;MAAE,CAACH,WAAW,GAAGC;IAAgB,CAAC,CAAC;IACtD,IAAAG,qBAAM,EAAC,IAAI,CAACvC,QAAQ,EAAE;MAAE,CAACkC,OAAO,GAAGI;IAAW,CAAC,CAAC;IAChD,IAAI,CAACrC,YAAY,CAACgC,YAAY,CAACO,0BAAc,CAACC,EAAE,EAAE,IAAI,CAACzC,QAAQ,EAAE;MAC/D0C,gBAAgB,EAAEL,IAAI,EAAEK,gBAAgB,KAAK,IAAI;MACjDC,aAAa,EAAE;IACjB,CAAC,CAAC;EACJ;EAEA,aAAaC,QAAQA,CAAC,CAAC3C,YAAY,CAAe,EAAEkB,MAAM,EAAE;IAC1D,OAAO,IAAIrB,YAAY,CAACqB,MAAM,EAAElB,YAAY,CAAC;EAC/C;AACF;AAAC4C,OAAA,CAAA/C,YAAA,GAAAA,YAAA;AAAApB,eAAA,CAxFYoB,YAAY,aACNgD,kBAAW;AAAApE,eAAA,CADjBoB,YAAY,kBAED,CAACiD,sBAAY,CAAC;AAwFtC,SAASrB,gCAAgCA,CAACP,MAA2B,EAAE;EACrE,MAAM6B,aAAa,GAAG,IAAAC,cAAI,EAAC9B,MAAM,EAAEtB,eAAe,CAAC;EACnD,MAAMkC,UAAU,GAAGH,kCAAiB,CAACsB,gBAAgB,CAACF,aAAa,CAAC;EACpE,OAAOjB,UAAU;AACnB;AAEAS,0BAAc,CAACW,UAAU,CAACrD,YAAY,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["_cli","data","require","_config","_legacy","_commentJson","_lodash","_workspaceModules","_legacyBitId","_variants","_defineProperty","e","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","INTERNAL_FIELDS","VariantsMain","constructor","patterns","configAspect","validateConfig","forEach","patternConfig","pattern","defaultScope","isValidScopeName","InvalidScopeName","undefined","raw","byRootDirAndName","rootDir","componentName","matches","match","isMatchPattern","excluded","push","config","specificity","maxSpecificity","sortedMatches","sortMatchesBySpecificity","propagate","extensionsToMerge","getExtensionFromPatternRawConfig","mergedExtensions","ExtensionDataList","mergeConfigs","result","extensions","length","setExtension","variant","extensionId","extensionConfig","opts","newVariant","assign","VariantsAspect","id","overrideExisting","ignoreVersion","provider","exports","MainRuntime","ConfigAspect","rawExtensions","omit","fromConfigObject","addRuntime"],"sources":["variants.main.runtime.ts"],"sourcesContent":["import { MainRuntime } from '@teambit/cli';\nimport { ConfigAspect } from '@teambit/config';\nimport type { ConfigMain } from '@teambit/config';\nimport { ExtensionDataList } from '@teambit/legacy.extension-data';\nimport { PathLinuxRelative } from '@teambit/toolbox.path.path';\nimport { assign } from 'comment-json';\nimport { omit, forEach } from 'lodash';\nimport {\n MatchedPatternWithConfig,\n isMatchPattern,\n sortMatchesBySpecificity,\n} from '@teambit/workspace.modules.match-pattern';\nimport { InvalidScopeName, isValidScopeName } from '@teambit/legacy-bit-id';\nimport { VariantsAspect } from './variants.aspect';\n\nexport type Patterns = { [pattern: string]: Record<string, any> };\n\nexport type VariantsComponentConfig = {\n propagate: boolean;\n exclude?: string[];\n defaultScope?: string;\n extensions: ExtensionDataList;\n maxSpecificity: number;\n sortedMatches: MatchedPatternWithConfig[];\n};\n\nconst INTERNAL_FIELDS = ['propagate', 'exclude', 'defaultScope'];\n\nexport class VariantsMain {\n static runtime = MainRuntime;\n static dependencies = [ConfigAspect];\n\n constructor(\n private patterns: Patterns,\n private configAspect: ConfigMain\n ) {\n this.validateConfig();\n }\n\n private validateConfig() {\n forEach(this.patterns, (patternConfig: Record<string, any>, pattern: string) => {\n if (patternConfig.defaultScope && !isValidScopeName(patternConfig.defaultScope)) {\n throw new InvalidScopeName(patternConfig.defaultScope, undefined, pattern);\n }\n });\n }\n\n raw(): Patterns {\n return this.patterns;\n }\n\n /**\n * Gets the config for specific component after merge all matching patterns of the component dir and id in the variants section\n * @param rootDir\n */\n byRootDirAndName(rootDir: PathLinuxRelative, componentName: string): VariantsComponentConfig | undefined {\n const matches: MatchedPatternWithConfig[] = [];\n forEach(this.patterns, (patternConfig, pattern) => {\n const match = isMatchPattern(rootDir, componentName, pattern);\n\n // Ignore matches with exclude matches\n if (match.match && !match.excluded) {\n matches.push({\n config: patternConfig,\n specificity: match.maxSpecificity,\n pattern: match.pattern,\n });\n }\n });\n\n const sortedMatches: MatchedPatternWithConfig[] = sortMatchesBySpecificity(matches);\n\n let defaultScope;\n let propagate = true;\n const extensionsToMerge: ExtensionDataList[] = [];\n sortedMatches.forEach((match) => {\n defaultScope = defaultScope || match.config.defaultScope;\n if (propagate) {\n extensionsToMerge.push(getExtensionFromPatternRawConfig(match.config));\n }\n if (match.config.propagate === false) {\n propagate = false;\n }\n });\n\n const mergedExtensions = ExtensionDataList.mergeConfigs(extensionsToMerge);\n const result = {\n defaultScope,\n extensions: mergedExtensions,\n propagate,\n maxSpecificity: sortedMatches.length ? sortedMatches[0].specificity : -1,\n sortedMatches,\n };\n return result;\n }\n\n /**\n * Updates the specified extension object of the specified variant.\n * @param {string} variant - The variant pattern.\n * @param {string} extensionId - The extension ID.\n * @param {Object} extensionConfig - The extension configuration.\n * @param {boolean} opts.overrideExisting - When true, any existing entries are overriden.\n */\n setExtension(variant: string, extensionId: string, extensionConfig: any, opts?: { overrideExisting?: boolean }) {\n const newVariant = this.patterns[variant] ?? {};\n assign(newVariant, { [extensionId]: extensionConfig });\n assign(this.patterns, { [variant]: newVariant });\n this.configAspect.setExtension(VariantsAspect.id, this.patterns, {\n overrideExisting: opts?.overrideExisting === true,\n ignoreVersion: true,\n });\n }\n\n static async provider([configAspect]: [ConfigMain], config) {\n return new VariantsMain(config, configAspect);\n }\n}\n\nfunction getExtensionFromPatternRawConfig(config: Record<string, any>) {\n const rawExtensions = omit(config, INTERNAL_FIELDS);\n const extensions = ExtensionDataList.fromConfigObject(rawExtensions);\n return extensions;\n}\n\nVariantsAspect.addRuntime(VariantsMain);\n"],"mappings":";;;;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AACA;AACA;AACA;EACEG,YAAYA,CAACC,OAAe,EAAEC,WAAmB,EAAEC,eAAoB,EAAEC,IAAqC,EAAE;IAC9G,MAAMC,UAAU,GAAG,IAAI,CAACtC,QAAQ,CAACkC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/C,IAAAK,qBAAM,EAACD,UAAU,EAAE;MAAE,CAACH,WAAW,GAAGC;IAAgB,CAAC,CAAC;IACtD,IAAAG,qBAAM,EAAC,IAAI,CAACvC,QAAQ,EAAE;MAAE,CAACkC,OAAO,GAAGI;IAAW,CAAC,CAAC;IAChD,IAAI,CAACrC,YAAY,CAACgC,YAAY,CAACO,0BAAc,CAACC,EAAE,EAAE,IAAI,CAACzC,QAAQ,EAAE;MAC/D0C,gBAAgB,EAAEL,IAAI,EAAEK,gBAAgB,KAAK,IAAI;MACjDC,aAAa,EAAE;IACjB,CAAC,CAAC;EACJ;EAEA,aAAaC,QAAQA,CAAC,CAAC3C,YAAY,CAAe,EAAEkB,MAAM,EAAE;IAC1D,OAAO,IAAIrB,YAAY,CAACqB,MAAM,EAAElB,YAAY,CAAC;EAC/C;AACF;AAAC4C,OAAA,CAAA/C,YAAA,GAAAA,YAAA;AAAApB,eAAA,CAxFYoB,YAAY,aACNgD,kBAAW;AAAApE,eAAA,CADjBoB,YAAY,kBAED,CAACiD,sBAAY,CAAC;AAwFtC,SAASrB,gCAAgCA,CAACP,MAA2B,EAAE;EACrE,MAAM6B,aAAa,GAAG,IAAAC,cAAI,EAAC9B,MAAM,EAAEtB,eAAe,CAAC;EACnD,MAAMkC,UAAU,GAAGH,2BAAiB,CAACsB,gBAAgB,CAACF,aAAa,CAAC;EACpE,OAAOjB,UAAU;AACnB;AAEAS,0BAAc,CAACW,UAAU,CAACrD,YAAY,CAAC","ignoreList":[]}
package/package.json CHANGED
@@ -1,20 +1,21 @@
1
1
  {
2
2
  "name": "@teambit/variants",
3
- "version": "0.0.1327",
3
+ "version": "0.0.1329",
4
4
  "homepage": "https://bit.cloud/teambit/workspace/variants",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.workspace",
8
8
  "name": "variants",
9
- "version": "0.0.1327"
9
+ "version": "0.0.1329"
10
10
  },
11
11
  "dependencies": {
12
12
  "comment-json": "3.0.3",
13
13
  "lodash": "4.17.21",
14
14
  "@teambit/harmony": "0.4.6",
15
15
  "@teambit/legacy-bit-id": "1.1.1",
16
- "@teambit/cli": "0.0.1060",
17
- "@teambit/config": "0.0.1234",
16
+ "@teambit/cli": "0.0.1062",
17
+ "@teambit/config": "0.0.1236",
18
+ "@teambit/legacy.extension-data": "0.0.2",
18
19
  "@teambit/toolbox.path.path": "0.0.4",
19
20
  "@teambit/workspace.modules.match-pattern": "0.0.505"
20
21
  },