@teambit/variants 0.0.1174 → 0.0.1175

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.1174" tests="0" failures="0" errors="0" skipped="0"/>
3
+ <testsuite name="teambit.workspace/variants@0.0.1175" 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={40841: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(64978);Object.defineProperty(n,"Variants",{enumerable:!0,get:function(){return a(o).default}}),Object.defineProperty(n,"default",{enumerable:!0,get:function(){return a(o).default}})},64978:(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},49475:(e,n,t)=>{var a={id:"teambit.workspace/variants@0.0.1174",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(49475),i=(t(41594),t(5016)),s=t(65682),l=t(40841),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.indexOf(a)>=0)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.indexOf(t)>=0||{}.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={79783: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(2324);Object.defineProperty(n,"Variants",{enumerable:!0,get:function(){return a(o).default}}),Object.defineProperty(n,"default",{enumerable:!0,get:function(){return a(o).default}})},2324:(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},3202:(e,n,t)=>{var a={id:"teambit.workspace/variants@0.0.1175",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(3202),i=(t(41594),t(5016)),s=t(65682),l=t(79783),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.indexOf(a)>=0)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.indexOf(t)>=0||{}.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})()));
@@ -118,11 +118,7 @@
118
118
  "line": 33,
119
119
  "character": 65
120
120
  },
121
- "name": "ConfigMain",
122
- "componentId": {
123
- "scope": "teambit.harmony",
124
- "name": "config"
125
- }
121
+ "name": "ConfigMain"
126
122
  },
127
123
  "isOptional": false,
128
124
  "isSpread": false
@@ -207,8 +203,7 @@
207
203
  "line": 53,
208
204
  "character": 29
209
205
  },
210
- "name": "PathLinuxRelative",
211
- "packageName": "@teambit/legacy/dist/utils/path"
206
+ "name": "PathLinuxRelative"
212
207
  },
213
208
  "isOptional": false,
214
209
  "isSpread": false
@@ -249,8 +244,7 @@
249
244
  "line": 53,
250
245
  "character": 72
251
246
  },
252
- "name": "VariantsComponentConfig",
253
- "internalFilePath": "variants.main.runtime.ts"
247
+ "name": "VariantsComponentConfig"
254
248
  },
255
249
  {
256
250
  "__schema": "KeywordTypeSchema",
@@ -513,11 +507,7 @@
513
507
  "line": 111,
514
508
  "character": 42
515
509
  },
516
- "name": "ConfigMain",
517
- "componentId": {
518
- "scope": "teambit.harmony",
519
- "name": "config"
520
- }
510
+ "name": "ConfigMain"
521
511
  }
522
512
  ]
523
513
  },
@@ -923,12 +913,7 @@
923
913
  "line": 24,
924
914
  "character": 18
925
915
  },
926
- "name": "MatchedPatternWithConfig",
927
- "componentId": {
928
- "scope": "teambit.workspace",
929
- "name": "modules/match-pattern",
930
- "version": "0.0.505"
931
- }
916
+ "name": "MatchedPatternWithConfig"
932
917
  }
933
918
  },
934
919
  "isOptional": false
@@ -1033,11 +1018,7 @@
1033
1018
  "line": 33,
1034
1019
  "character": 65
1035
1020
  },
1036
- "name": "ConfigMain",
1037
- "componentId": {
1038
- "scope": "teambit.harmony",
1039
- "name": "config"
1040
- }
1021
+ "name": "ConfigMain"
1041
1022
  },
1042
1023
  "isOptional": false,
1043
1024
  "isSpread": false
@@ -1122,8 +1103,7 @@
1122
1103
  "line": 53,
1123
1104
  "character": 29
1124
1105
  },
1125
- "name": "PathLinuxRelative",
1126
- "packageName": "@teambit/legacy/dist/utils/path"
1106
+ "name": "PathLinuxRelative"
1127
1107
  },
1128
1108
  "isOptional": false,
1129
1109
  "isSpread": false
@@ -1164,8 +1144,7 @@
1164
1144
  "line": 53,
1165
1145
  "character": 72
1166
1146
  },
1167
- "name": "VariantsComponentConfig",
1168
- "internalFilePath": "variants.main.runtime.ts"
1147
+ "name": "VariantsComponentConfig"
1169
1148
  },
1170
1149
  {
1171
1150
  "__schema": "KeywordTypeSchema",
@@ -1428,11 +1407,7 @@
1428
1407
  "line": 111,
1429
1408
  "character": 42
1430
1409
  },
1431
- "name": "ConfigMain",
1432
- "componentId": {
1433
- "scope": "teambit.harmony",
1434
- "name": "config"
1435
- }
1410
+ "name": "ConfigMain"
1436
1411
  }
1437
1412
  ]
1438
1413
  },
@@ -1628,7 +1603,7 @@
1628
1603
  "componentId": {
1629
1604
  "scope": "teambit.workspace",
1630
1605
  "name": "variants",
1631
- "version": "0.0.1174"
1606
+ "version": "0.0.1175"
1632
1607
  },
1633
1608
  "taggedModuleExports": []
1634
1609
  }
@@ -1,5 +1,5 @@
1
- import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.workspace_variants@0.0.1174/dist/variants.composition.js';
2
- import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.workspace_variants@0.0.1174/dist/variants.docs.mdx';
1
+ import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.workspace_variants@0.0.1175/dist/variants.composition.js';
2
+ import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.workspace_variants@0.0.1175/dist/variants.docs.mdx';
3
3
 
4
4
  export const compositions = [compositions_0];
5
5
  export const overview = [overview_0];
@@ -1,6 +1,6 @@
1
1
  import type { ConfigMain } from '@teambit/config';
2
2
  import { ExtensionDataList } from '@teambit/legacy/dist/consumer/config/extension-data';
3
- import { PathLinuxRelative } from '@teambit/legacy/dist/utils/path';
3
+ import { PathLinuxRelative } from '@teambit/toolbox.path.path';
4
4
  import { MatchedPatternWithConfig } from '@teambit/workspace.modules.match-pattern';
5
5
  export type Patterns = {
6
6
  [pattern: string]: Record<string, any>;
@@ -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/legacy/dist/utils/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(private patterns: Patterns, private configAspect: ConfigMain) {\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,MAAAF,IAAA,GAAAC,OAAA;EAAAC,OAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAG,eAAA;EAAA,MAAAH,IAAA,GAAAC,OAAA;EAAAE,cAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAI,aAAA;EAAA,MAAAJ,IAAA,GAAAC,OAAA;EAAAG,YAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,QAAA;EAAA,MAAAL,IAAA,GAAAC,OAAA;EAAAI,OAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAM,kBAAA;EAAA,MAAAN,IAAA,GAAAC,OAAA;EAAAK,iBAAA,YAAAA,CAAA;IAAA,OAAAN,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAKA,SAAAO,aAAA;EAAA,MAAAP,IAAA,GAAAC,OAAA;EAAAM,YAAA,Y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ASrB,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","_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(private patterns: Patterns, private configAspect: ConfigMain) {\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,MAAAF,IAAA,GAAAC,OAAA;EAAAC,OAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAG,eAAA;EAAA,MAAAH,IAAA,GAAAC,OAAA;EAAAE,cAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAI,aAAA;EAAA,MAAAJ,IAAA,GAAAC,OAAA;EAAAG,YAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,QAAA;EAAA,MAAAL,IAAA,GAAAC,OAAA;EAAAI,OAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAM,kBAAA;EAAA,MAAAN,IA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EAC/C;AACF;AAAC4C,OAAA,CAAA/C,YAAA,GAAAA,YAAA;AAAApB,eAAA,CArFYoB,YAAY,aACNgD,kBAAW;AAAApE,eAAA,CADjBoB,YAAY,kBAED,CAACiD,sBAAY,CAAC;AAqFtC,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":[]}
package/package.json CHANGED
@@ -1,20 +1,21 @@
1
1
  {
2
2
  "name": "@teambit/variants",
3
- "version": "0.0.1174",
3
+ "version": "0.0.1175",
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.1174"
9
+ "version": "0.0.1175"
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.907",
17
- "@teambit/config": "0.0.1081",
16
+ "@teambit/cli": "0.0.908",
17
+ "@teambit/config": "0.0.1082",
18
+ "@teambit/toolbox.path.path": "0.0.2",
18
19
  "@teambit/workspace.modules.match-pattern": "0.0.505"
19
20
  },
20
21
  "devDependencies": {
@@ -22,7 +23,7 @@
22
23
  "@types/mocha": "9.1.0",
23
24
  "chai": "4.3.0",
24
25
  "@teambit/workspace.content.variants": "1.95.9",
25
- "@teambit/harmony.envs.core-aspect-env": "0.0.39"
26
+ "@teambit/harmony.envs.core-aspect-env": "0.0.42"
26
27
  },
27
28
  "peerDependencies": {
28
29
  "react": "^17.0.0 || ^18.0.0",