@teambit/variants 0.0.693 → 0.0.695
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants.js.map +1 -1
- package/dist/index.js +0 -3
- package/dist/index.js.map +1 -1
- package/dist/variants.aspect.js +0 -5
- package/dist/variants.aspect.js.map +1 -1
- package/dist/variants.composition.js +0 -6
- package/dist/variants.composition.js.map +1 -1
- package/dist/variants.main.runtime.js +5 -57
- package/dist/variants.main.runtime.js.map +1 -1
- package/dist/variants.provider.js +2 -0
- package/dist/variants.provider.js.map +1 -1
- package/package-tar/teambit-variants-0.0.695.tgz +0 -0
- package/package.json +5 -5
- package/{preview-1666312873430.js → preview-1666669368175.js} +2 -2
- package/package-tar/teambit-variants-0.0.693.tgz +0 -0
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["EXT_NAME"],"sources":["constants.ts"],"sourcesContent":["export const EXT_NAME = 'teambit.workspace/variants';\n"],"mappings":";;;;;;AAAO,MAAMA,QAAQ,GAAG,
|
|
1
|
+
{"version":3,"names":["EXT_NAME"],"sources":["constants.ts"],"sourcesContent":["export const EXT_NAME = 'teambit.workspace/variants';\n"],"mappings":";;;;;;AAAO,MAAMA,QAAQ,GAAG,4BAA4B;AAAC"}
|
package/dist/index.js
CHANGED
|
@@ -9,14 +9,11 @@ Object.defineProperty(exports, "VariantsAspect", {
|
|
|
9
9
|
return _variants().VariantsAspect;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
-
|
|
13
12
|
function _variants() {
|
|
14
13
|
const data = require("./variants.aspect");
|
|
15
|
-
|
|
16
14
|
_variants = function () {
|
|
17
15
|
return data;
|
|
18
16
|
};
|
|
19
|
-
|
|
20
17
|
return data;
|
|
21
18
|
}
|
|
22
19
|
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export type { VariantsMain, Patterns } from './variants.main.runtime';\nexport { VariantsAspect } from './variants.aspect';\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export type { VariantsMain, Patterns } from './variants.main.runtime';\nexport { VariantsAspect } from './variants.aspect';\n"],"mappings":";;;;;;;;;;;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA"}
|
package/dist/variants.aspect.js
CHANGED
|
@@ -4,21 +4,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.VariantsAspect = void 0;
|
|
7
|
-
|
|
8
7
|
function _harmony() {
|
|
9
8
|
const data = require("@teambit/harmony");
|
|
10
|
-
|
|
11
9
|
_harmony = function () {
|
|
12
10
|
return data;
|
|
13
11
|
};
|
|
14
|
-
|
|
15
12
|
return data;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
const VariantsAspect = _harmony().Aspect.create({
|
|
19
15
|
id: 'teambit.workspace/variants'
|
|
20
16
|
});
|
|
21
|
-
|
|
22
17
|
exports.VariantsAspect = VariantsAspect;
|
|
23
18
|
|
|
24
19
|
//# sourceMappingURL=variants.aspect.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["VariantsAspect","Aspect","create","id"],"sources":["variants.aspect.ts"],"sourcesContent":["import { Aspect } from '@teambit/harmony';\n\nexport const VariantsAspect = Aspect.create({\n id: 'teambit.workspace/variants',\n});\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["VariantsAspect","Aspect","create","id"],"sources":["variants.aspect.ts"],"sourcesContent":["import { Aspect } from '@teambit/harmony';\n\nexport const VariantsAspect = Aspect.create({\n id: 'teambit.workspace/variants',\n});\n"],"mappings":";;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEO,MAAMA,cAAc,GAAGC,iBAAM,CAACC,MAAM,CAAC;EAC1CC,EAAE,EAAE;AACN,CAAC,CAAC;AAAC"}
|
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.Logo = void 0;
|
|
9
|
-
|
|
10
8
|
function _react() {
|
|
11
9
|
const data = _interopRequireDefault(require("react"));
|
|
12
|
-
|
|
13
10
|
_react = function () {
|
|
14
11
|
return data;
|
|
15
12
|
};
|
|
16
|
-
|
|
17
13
|
return data;
|
|
18
14
|
}
|
|
19
|
-
|
|
20
15
|
const Logo = () => /*#__PURE__*/_react().default.createElement("div", {
|
|
21
16
|
style: {
|
|
22
17
|
height: '100%',
|
|
@@ -29,7 +24,6 @@ const Logo = () => /*#__PURE__*/_react().default.createElement("div", {
|
|
|
29
24
|
},
|
|
30
25
|
src: "https://static.bit.dev/extensions-icons/variants.svg"
|
|
31
26
|
}));
|
|
32
|
-
|
|
33
27
|
exports.Logo = Logo;
|
|
34
28
|
|
|
35
29
|
//# sourceMappingURL=variants.composition.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Logo","height","display","justifyContent","width"],"sources":["variants.composition.tsx"],"sourcesContent":["import React from 'react';\n\nexport const Logo = () => (\n <div style={{ height: '100%', display: 'flex', justifyContent: 'center' }}>\n <img style={{ width: 70 }} src=\"https://static.bit.dev/extensions-icons/variants.svg\" />\n </div>\n);\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["Logo","height","display","justifyContent","width"],"sources":["variants.composition.tsx"],"sourcesContent":["import React from 'react';\n\nexport const Logo = () => (\n <div style={{ height: '100%', display: 'flex', justifyContent: 'center' }}>\n <img style={{ width: 70 }} src=\"https://static.bit.dev/extensions-icons/variants.svg\" />\n </div>\n);\n"],"mappings":";;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEO,MAAMA,IAAI,GAAG,mBAClB;EAAK,KAAK,EAAE;IAAEC,MAAM,EAAE,MAAM;IAAEC,OAAO,EAAE,MAAM;IAAEC,cAAc,EAAE;EAAS;AAAE,gBACxE;EAAK,KAAK,EAAE;IAAEC,KAAK,EAAE;EAAG,CAAE;EAAC,GAAG,EAAC;AAAsD,EAAG,CAE3F;AAAC"}
|
|
@@ -1,120 +1,84 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
require("core-js/modules/es.array.iterator.js");
|
|
6
|
-
|
|
7
5
|
require("core-js/modules/es.promise.js");
|
|
8
|
-
|
|
9
6
|
require("core-js/modules/es.regexp.exec.js");
|
|
10
|
-
|
|
11
7
|
Object.defineProperty(exports, "__esModule", {
|
|
12
8
|
value: true
|
|
13
9
|
});
|
|
14
10
|
exports.VariantsMain = void 0;
|
|
15
|
-
|
|
16
11
|
function _defineProperty2() {
|
|
17
12
|
const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
18
|
-
|
|
19
13
|
_defineProperty2 = function () {
|
|
20
14
|
return data;
|
|
21
15
|
};
|
|
22
|
-
|
|
23
16
|
return data;
|
|
24
17
|
}
|
|
25
|
-
|
|
26
18
|
function _cli() {
|
|
27
19
|
const data = require("@teambit/cli");
|
|
28
|
-
|
|
29
20
|
_cli = function () {
|
|
30
21
|
return data;
|
|
31
22
|
};
|
|
32
|
-
|
|
33
23
|
return data;
|
|
34
24
|
}
|
|
35
|
-
|
|
36
25
|
function _config() {
|
|
37
26
|
const data = require("@teambit/config");
|
|
38
|
-
|
|
39
27
|
_config = function () {
|
|
40
28
|
return data;
|
|
41
29
|
};
|
|
42
|
-
|
|
43
30
|
return data;
|
|
44
31
|
}
|
|
45
|
-
|
|
46
32
|
function _consumerOverrides() {
|
|
47
33
|
const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/config/consumer-overrides"));
|
|
48
|
-
|
|
49
34
|
_consumerOverrides = function () {
|
|
50
35
|
return data;
|
|
51
36
|
};
|
|
52
|
-
|
|
53
37
|
return data;
|
|
54
38
|
}
|
|
55
|
-
|
|
56
39
|
function _extensionData() {
|
|
57
40
|
const data = require("@teambit/legacy/dist/consumer/config/extension-data");
|
|
58
|
-
|
|
59
41
|
_extensionData = function () {
|
|
60
42
|
return data;
|
|
61
43
|
};
|
|
62
|
-
|
|
63
44
|
return data;
|
|
64
45
|
}
|
|
65
|
-
|
|
66
46
|
function _commentJson() {
|
|
67
47
|
const data = require("comment-json");
|
|
68
|
-
|
|
69
48
|
_commentJson = function () {
|
|
70
49
|
return data;
|
|
71
50
|
};
|
|
72
|
-
|
|
73
51
|
return data;
|
|
74
52
|
}
|
|
75
|
-
|
|
76
53
|
function _lodash() {
|
|
77
54
|
const data = require("lodash");
|
|
78
|
-
|
|
79
55
|
_lodash = function () {
|
|
80
56
|
return data;
|
|
81
57
|
};
|
|
82
|
-
|
|
83
58
|
return data;
|
|
84
59
|
}
|
|
85
|
-
|
|
86
60
|
function _workspaceModules() {
|
|
87
61
|
const data = require("@teambit/workspace.modules.match-pattern");
|
|
88
|
-
|
|
89
62
|
_workspaceModules = function () {
|
|
90
63
|
return data;
|
|
91
64
|
};
|
|
92
|
-
|
|
93
65
|
return data;
|
|
94
66
|
}
|
|
95
|
-
|
|
96
67
|
function _legacyBitId() {
|
|
97
68
|
const data = require("@teambit/legacy-bit-id");
|
|
98
|
-
|
|
99
69
|
_legacyBitId = function () {
|
|
100
70
|
return data;
|
|
101
71
|
};
|
|
102
|
-
|
|
103
72
|
return data;
|
|
104
73
|
}
|
|
105
|
-
|
|
106
74
|
function _variants() {
|
|
107
75
|
const data = require("./variants.aspect");
|
|
108
|
-
|
|
109
76
|
_variants = function () {
|
|
110
77
|
return data;
|
|
111
78
|
};
|
|
112
|
-
|
|
113
79
|
return data;
|
|
114
80
|
}
|
|
115
|
-
|
|
116
81
|
const INTERNAL_FIELDS = ['propagate', 'exclude', 'defaultScope'];
|
|
117
|
-
|
|
118
82
|
class VariantsMain {
|
|
119
83
|
constructor(patterns, configAspect) {
|
|
120
84
|
this.patterns = patterns;
|
|
@@ -123,7 +87,6 @@ class VariantsMain {
|
|
|
123
87
|
this._loadedLegacy = _consumerOverrides().default.load(this.patterns);
|
|
124
88
|
this.validateConfig();
|
|
125
89
|
}
|
|
126
|
-
|
|
127
90
|
validateConfig() {
|
|
128
91
|
(0, _lodash().forEach)(this.patterns, (patternConfig, pattern) => {
|
|
129
92
|
if (patternConfig.defaultScope && !(0, _legacyBitId().isValidScopeName)(patternConfig.defaultScope)) {
|
|
@@ -131,30 +94,28 @@ class VariantsMain {
|
|
|
131
94
|
}
|
|
132
95
|
});
|
|
133
96
|
}
|
|
134
|
-
|
|
135
97
|
raw() {
|
|
136
98
|
return this.patterns;
|
|
137
99
|
}
|
|
100
|
+
|
|
138
101
|
/**
|
|
139
102
|
* Get all the patterns defined in the variants section of the workspace as the legacy ConsumerOverrides format
|
|
140
103
|
*/
|
|
141
|
-
|
|
142
|
-
|
|
143
104
|
legacy() {
|
|
144
105
|
// return ConsumerOverrides.load(this.patterns);
|
|
145
106
|
return this._loadedLegacy;
|
|
146
107
|
}
|
|
108
|
+
|
|
147
109
|
/**
|
|
148
110
|
* Gets the config for specific component after merge all matching patterns of the component dir and id in the variants section
|
|
149
111
|
* @param rootDir
|
|
150
112
|
*/
|
|
151
|
-
|
|
152
|
-
|
|
153
113
|
byRootDirAndName(rootDir, componentName) {
|
|
154
114
|
const matches = [];
|
|
155
115
|
(0, _lodash().forEach)(this.patterns, (patternConfig, pattern) => {
|
|
156
|
-
const match = (0, _workspaceModules().isMatchPattern)(rootDir, componentName, pattern);
|
|
116
|
+
const match = (0, _workspaceModules().isMatchPattern)(rootDir, componentName, pattern);
|
|
157
117
|
|
|
118
|
+
// Ignore matches with exclude matches
|
|
158
119
|
if (match.match && !match.excluded) {
|
|
159
120
|
matches.push({
|
|
160
121
|
config: patternConfig,
|
|
@@ -169,18 +130,14 @@ class VariantsMain {
|
|
|
169
130
|
const extensionsToMerge = [];
|
|
170
131
|
sortedMatches.forEach(match => {
|
|
171
132
|
defaultScope = defaultScope || match.config.defaultScope;
|
|
172
|
-
|
|
173
133
|
if (propagate) {
|
|
174
134
|
extensionsToMerge.push(getExtensionFromPatternRawConfig(match.config));
|
|
175
135
|
}
|
|
176
|
-
|
|
177
136
|
if (match.config.propagate === false) {
|
|
178
137
|
propagate = false;
|
|
179
138
|
}
|
|
180
139
|
});
|
|
181
|
-
|
|
182
140
|
const mergedExtensions = _extensionData().ExtensionDataList.mergeConfigs(extensionsToMerge);
|
|
183
|
-
|
|
184
141
|
const result = {
|
|
185
142
|
defaultScope,
|
|
186
143
|
extensions: mergedExtensions,
|
|
@@ -190,6 +147,7 @@ class VariantsMain {
|
|
|
190
147
|
};
|
|
191
148
|
return result;
|
|
192
149
|
}
|
|
150
|
+
|
|
193
151
|
/**
|
|
194
152
|
* Updates the specified extension object of the specified variant.
|
|
195
153
|
* @param {string} variant - The variant pattern.
|
|
@@ -197,11 +155,8 @@ class VariantsMain {
|
|
|
197
155
|
* @param {Object} extensionConfig - The extension configuration.
|
|
198
156
|
* @param {boolean} opts.overrideExisting - When true, any existing entries are overriden.
|
|
199
157
|
*/
|
|
200
|
-
|
|
201
|
-
|
|
202
158
|
setExtension(variant, extensionId, extensionConfig, opts) {
|
|
203
159
|
var _this$patterns$varian;
|
|
204
|
-
|
|
205
160
|
const newVariant = (_this$patterns$varian = this.patterns[variant]) !== null && _this$patterns$varian !== void 0 ? _this$patterns$varian : {};
|
|
206
161
|
(0, _commentJson().assign)(newVariant, {
|
|
207
162
|
[extensionId]: extensionConfig
|
|
@@ -214,25 +169,18 @@ class VariantsMain {
|
|
|
214
169
|
ignoreVersion: true
|
|
215
170
|
});
|
|
216
171
|
}
|
|
217
|
-
|
|
218
172
|
static async provider([configAspect], config) {
|
|
219
173
|
return new VariantsMain(config, configAspect);
|
|
220
174
|
}
|
|
221
|
-
|
|
222
175
|
}
|
|
223
|
-
|
|
224
176
|
exports.VariantsMain = VariantsMain;
|
|
225
177
|
(0, _defineProperty2().default)(VariantsMain, "runtime", _cli().MainRuntime);
|
|
226
178
|
(0, _defineProperty2().default)(VariantsMain, "dependencies", [_config().ConfigAspect]);
|
|
227
|
-
|
|
228
179
|
function getExtensionFromPatternRawConfig(config) {
|
|
229
180
|
const rawExtensions = (0, _lodash().omit)(config, INTERNAL_FIELDS);
|
|
230
|
-
|
|
231
181
|
const extensions = _extensionData().ExtensionDataList.fromConfigObject(rawExtensions);
|
|
232
|
-
|
|
233
182
|
return extensions;
|
|
234
183
|
}
|
|
235
|
-
|
|
236
184
|
_variants().VariantsAspect.addRuntime(VariantsMain);
|
|
237
185
|
|
|
238
186
|
//# sourceMappingURL=variants.main.runtime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["INTERNAL_FIELDS","VariantsMain","constructor","patterns","configAspect","_loadedLegacy","ConsumerOverrides","load","validateConfig","forEach","patternConfig","pattern","defaultScope","isValidScopeName","InvalidScopeName","undefined","raw","legacy","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","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 ConsumerOverrides from '@teambit/legacy/dist/consumer/config/consumer-overrides';\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 _loadedLegacy: ConsumerOverrides;\n\n constructor(private patterns: Patterns, private configAspect: ConfigMain) {\n this._loadedLegacy = ConsumerOverrides.load(this.patterns);\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 * Get all the patterns defined in the variants section of the workspace as the legacy ConsumerOverrides format\n */\n legacy(): ConsumerOverrides {\n // return ConsumerOverrides.load(this.patterns);\n return this._loadedLegacy;\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":"
|
|
1
|
+
{"version":3,"names":["INTERNAL_FIELDS","VariantsMain","constructor","patterns","configAspect","_loadedLegacy","ConsumerOverrides","load","validateConfig","forEach","patternConfig","pattern","defaultScope","isValidScopeName","InvalidScopeName","undefined","raw","legacy","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","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 ConsumerOverrides from '@teambit/legacy/dist/consumer/config/consumer-overrides';\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 _loadedLegacy: ConsumerOverrides;\n\n constructor(private patterns: Patterns, private configAspect: ConfigMain) {\n this._loadedLegacy = ConsumerOverrides.load(this.patterns);\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 * Get all the patterns defined in the variants section of the workspace as the legacy ConsumerOverrides format\n */\n legacy(): ConsumerOverrides {\n // return ConsumerOverrides.load(this.patterns);\n return this._loadedLegacy;\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;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAKA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAaA,MAAMA,eAAe,GAAG,CAAC,WAAW,EAAE,SAAS,EAAE,cAAc,CAAC;AAEzD,MAAMC,YAAY,CAAC;EAMxBC,WAAW,CAASC,QAAkB,EAAUC,YAAwB,EAAE;IAAA,KAAtDD,QAAkB,GAAlBA,QAAkB;IAAA,KAAUC,YAAwB,GAAxBA,YAAwB;IAAA;IACtE,IAAI,CAACC,aAAa,GAAGC,4BAAiB,CAACC,IAAI,CAAC,IAAI,CAACJ,QAAQ,CAAC;IAC1D,IAAI,CAACK,cAAc,EAAE;EACvB;EAEQA,cAAc,GAAG;IACvB,IAAAC,iBAAO,EAAC,IAAI,CAACN,QAAQ,EAAE,CAACO,aAAkC,EAAEC,OAAe,KAAK;MAC9E,IAAID,aAAa,CAACE,YAAY,IAAI,CAAC,IAAAC,+BAAgB,EAACH,aAAa,CAACE,YAAY,CAAC,EAAE;QAC/E,MAAM,KAAIE,+BAAgB,EAACJ,aAAa,CAACE,YAAY,EAAEG,SAAS,EAAEJ,OAAO,CAAC;MAC5E;IACF,CAAC,CAAC;EACJ;EAEAK,GAAG,GAAa;IACd,OAAO,IAAI,CAACb,QAAQ;EACtB;;EAEA;AACF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AAY,CAAC"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// import { Variants, Patterns } from './variants.extension';
|
|
2
2
|
// import { Config } from '../config';
|
|
3
|
+
|
|
3
4
|
// export type VariantsDeps = [Config];
|
|
5
|
+
|
|
4
6
|
// export async function provideVariants([hostConfig]: VariantsDeps, config: Patterns) {
|
|
5
7
|
// const variants = new Variants(config, hostConfig);
|
|
6
8
|
// // TODO: fix when config become maybe
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["variants.provider.ts"],"sourcesContent":["// import { Variants, Patterns } from './variants.extension';\n// import { Config } from '../config';\n\n// export type VariantsDeps = [Config];\n\n// export async function provideVariants([hostConfig]: VariantsDeps, config: Patterns) {\n// const variants = new Variants(config, hostConfig);\n// // TODO: fix when config become maybe\n// if (hostConfig.type) {\n// hostConfig.registerGetVariantsConfig(variants.legacy.bind(variants));\n// }\n// return variants;\n// }\n"],"mappings":"AAAA;AACA
|
|
1
|
+
{"version":3,"names":[],"sources":["variants.provider.ts"],"sourcesContent":["// import { Variants, Patterns } from './variants.extension';\n// import { Config } from '../config';\n\n// export type VariantsDeps = [Config];\n\n// export async function provideVariants([hostConfig]: VariantsDeps, config: Patterns) {\n// const variants = new Variants(config, hostConfig);\n// // TODO: fix when config become maybe\n// if (hostConfig.type) {\n// hostConfig.registerGetVariantsConfig(variants.legacy.bind(variants));\n// }\n// return variants;\n// }\n"],"mappings":"AAAA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA"}
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/variants",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.695",
|
|
4
4
|
"homepage": "https://bit.dev/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.
|
|
9
|
+
"version": "0.0.695"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"comment-json": "3.0.3",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"@babel/runtime": "7.12.18",
|
|
15
15
|
"core-js": "^3.0.0",
|
|
16
16
|
"@teambit/harmony": "0.3.3",
|
|
17
|
-
"@teambit/cli": "0.0.
|
|
18
|
-
"@teambit/config": "0.0.
|
|
17
|
+
"@teambit/cli": "0.0.592",
|
|
18
|
+
"@teambit/config": "0.0.605",
|
|
19
19
|
"@teambit/legacy-bit-id": "0.0.414",
|
|
20
20
|
"@teambit/workspace.modules.match-pattern": "0.0.495"
|
|
21
21
|
},
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"@teambit/workspace.content.variants": "1.95.9"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@teambit/legacy": "1.0.
|
|
33
|
+
"@teambit/legacy": "1.0.375",
|
|
34
34
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
35
35
|
"react": "^16.8.0 || ^17.0.0"
|
|
36
36
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.workspace_variants@0.0.
|
|
2
|
-
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.workspace_variants@0.0.
|
|
1
|
+
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.workspace_variants@0.0.695/dist/variants.composition.js';
|
|
2
|
+
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.workspace_variants@0.0.695/dist/variants.docs.mdx';
|
|
3
3
|
|
|
4
4
|
export const compositions = [compositions_0];
|
|
5
5
|
export const overview = [overview_0];
|
|
Binary file
|