@teambit/workspace 0.0.599 → 0.0.601

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/bit-map.d.ts CHANGED
@@ -16,7 +16,8 @@ export declare class BitMap {
16
16
  * later, upon `bit tag`, the data is saved in the scope.
17
17
  * returns a boolean indicating whether a change has been made.
18
18
  */
19
- addComponentConfig(aspectId: string, id: ComponentID, config?: Record<string, any>): Promise<boolean>;
19
+ addComponentConfig(id: ComponentID, aspectId: string, config?: Record<string, any>): boolean;
20
+ removeComponentConfig(id: ComponentID, aspectId: string): boolean;
20
21
  /**
21
22
  * write .bitmap object to the filesystem
22
23
  */
package/dist/bit-map.js CHANGED
@@ -33,7 +33,7 @@ class BitMap {
33
33
  */
34
34
 
35
35
 
36
- async addComponentConfig(aspectId, id, config) {
36
+ addComponentConfig(id, aspectId, config = {}) {
37
37
  if (!aspectId || typeof aspectId !== 'string') throw new Error(`expect aspectId to be string, got ${aspectId}`);
38
38
  const bitMapEntry = this.getBitmapEntry(id, {
39
39
  ignoreScopeAndVersion: true
@@ -51,7 +51,22 @@ class BitMap {
51
51
  }
52
52
 
53
53
  this.legacyBitMap.markAsChanged();
54
- await this.write();
54
+ return true; // changes have been made
55
+ }
56
+
57
+ removeComponentConfig(id, aspectId) {
58
+ if (!aspectId || typeof aspectId !== 'string') throw new Error(`expect aspectId to be string, got ${aspectId}`);
59
+ const bitMapEntry = this.getBitmapEntry(id, {
60
+ ignoreScopeAndVersion: true
61
+ });
62
+ const currentConfig = (bitMapEntry.config || (bitMapEntry.config = {}))[aspectId];
63
+
64
+ if (!currentConfig) {
65
+ return false; // no changes
66
+ }
67
+
68
+ delete bitMapEntry.config[aspectId];
69
+ this.legacyBitMap.markAsChanged();
55
70
  return true; // changes have been made
56
71
  }
57
72
  /**
@@ -1 +1 @@
1
- {"version":3,"sources":["bit-map.ts"],"names":["BitMap","constructor","legacyBitMap","consumer","addComponentConfig","aspectId","id","config","Error","bitMapEntry","getBitmapEntry","ignoreScopeAndVersion","currentConfig","markAsChanged","write","writeBitMap","ignoreVersion","getComponent","_legacy","renameNewComponent","sourceId","targetId","hasVersion","toString","removeComponent","setComponent"],"mappings":";;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAMA;AACA;AACA;AACA;AACO,MAAMA,MAAN,CAAa;AAClBC,EAAAA,WAAW,CAASC,YAAT,EAA6CC,QAA7C,EAAiE;AAAA,SAAxDD,YAAwD,GAAxDA,YAAwD;AAAA,SAApBC,QAAoB,GAApBA,QAAoB;AAAE;AAE9E;AACF;AACA;AACA;AACA;;;AAC0B,QAAlBC,kBAAkB,CAACC,QAAD,EAAmBC,EAAnB,EAAoCC,MAApC,EAAoF;AAC1G,QAAI,CAACF,QAAD,IAAa,OAAOA,QAAP,KAAoB,QAArC,EAA+C,MAAM,IAAIG,KAAJ,CAAW,qCAAoCH,QAAS,EAAxD,CAAN;AAC/C,UAAMI,WAAW,GAAG,KAAKC,cAAL,CAAoBJ,EAApB,EAAwB;AAAEK,MAAAA,qBAAqB,EAAE;AAAzB,KAAxB,CAApB;AACA,UAAMC,aAAa,GAAG,CAACH,WAAW,CAACF,MAAb,KAACE,WAAW,CAACF,MAAb,GAAwB,EAAxB,GAA4BF,QAA5B,CAAtB;;AACA,QAAI,uBAAQO,aAAR,EAAuBL,MAAvB,CAAJ,EAAoC;AAClC,aAAO,KAAP,CADkC,CACpB;AACf;;AACD,QAAI,CAACA,MAAL,EAAa;AACX,aAAOE,WAAW,CAACF,MAAZ,CAAmBF,QAAnB,CAAP;AACD,KAFD,MAEO;AACLI,MAAAA,WAAW,CAACF,MAAZ,CAAmBF,QAAnB,IAA+BE,MAA/B;AACD;;AACD,SAAKL,YAAL,CAAkBW,aAAlB;AACA,UAAM,KAAKC,KAAL,EAAN;AACA,WAAO,IAAP,CAd0G,CAc7F;AACd;AAED;AACF;AACA;;;AACa,QAALA,KAAK,GAAG;AACZ,UAAM,KAAKX,QAAL,CAAcY,WAAd,EAAN;AACD;AAED;AACF;AACA;;;AACEL,EAAAA,cAAc,CACZJ,EADY,EAEZ;AAAEU,IAAAA,aAAF;AAAiBL,IAAAA;AAAjB,MAAsE,EAF1D,EAGE;AACd,WAAO,KAAKT,YAAL,CAAkBe,YAAlB,CAA+BX,EAAE,CAACY,OAAlC,EAA2C;AAAEF,MAAAA,aAAF;AAAiBL,MAAAA;AAAjB,KAA3C,CAAP;AACD;AAED;AACF;AACA;;;AACEQ,EAAAA,kBAAkB,CAACC,QAAD,EAAwBC,QAAxB,EAA+C;AAC/D,UAAMZ,WAAW,GAAG,KAAKC,cAAL,CAAoBU,QAApB,CAApB;;AACA,QAAIX,WAAW,CAACH,EAAZ,CAAegB,UAAf,EAAJ,EAAiC;AAC/B,YAAM,IAAId,KAAJ,CAAW,kDAAiDC,WAAW,CAACH,EAAZ,CAAeiB,QAAf,EAA0B,EAAtF,CAAN;AACD;;AACD,SAAKrB,YAAL,CAAkBsB,eAAlB,CAAkCf,WAAW,CAACH,EAA9C;AACAG,IAAAA,WAAW,CAACH,EAAZ,GAAiBe,QAAQ,CAACH,OAA1B;AACA,SAAKhB,YAAL,CAAkBuB,YAAlB,CAA+BhB,WAAW,CAACH,EAA3C,EAA+CG,WAA/C;AACD;;AArDiB","sourcesContent":["import { isEqual } from 'lodash';\nimport { ComponentID } from '@teambit/component-id';\nimport LegacyBitMap from '@teambit/legacy/dist/consumer/bit-map';\nimport { Consumer } from '@teambit/legacy/dist/consumer';\nimport { GetBitMapComponentOptions } from '@teambit/legacy/dist/consumer/bit-map/bit-map';\nimport ComponentMap from '@teambit/legacy/dist/consumer/bit-map/component-map';\n/**\n * consider extracting to a new component.\n * (pro: making Workspace aspect smaller. con: it's an implementation details of the workspace)\n */\nexport class BitMap {\n constructor(private legacyBitMap: LegacyBitMap, private consumer: Consumer) {}\n\n /**\n * adds component config to the .bitmap file.\n * later, upon `bit tag`, the data is saved in the scope.\n * returns a boolean indicating whether a change has been made.\n */\n async addComponentConfig(aspectId: string, id: ComponentID, config?: Record<string, any>): Promise<boolean> {\n if (!aspectId || typeof aspectId !== 'string') throw new Error(`expect aspectId to be string, got ${aspectId}`);\n const bitMapEntry = this.getBitmapEntry(id, { ignoreScopeAndVersion: true });\n const currentConfig = (bitMapEntry.config ||= {})[aspectId];\n if (isEqual(currentConfig, config)) {\n return false; // no changes\n }\n if (!config) {\n delete bitMapEntry.config[aspectId];\n } else {\n bitMapEntry.config[aspectId] = config;\n }\n this.legacyBitMap.markAsChanged();\n await this.write();\n return true; // changes have been made\n }\n\n /**\n * write .bitmap object to the filesystem\n */\n async write() {\n await this.consumer.writeBitMap();\n }\n\n /**\n * get the data saved in the .bitmap file for this component-id.\n */\n getBitmapEntry(\n id: ComponentID,\n { ignoreVersion, ignoreScopeAndVersion }: GetBitMapComponentOptions = {}\n ): ComponentMap {\n return this.legacyBitMap.getComponent(id._legacy, { ignoreVersion, ignoreScopeAndVersion });\n }\n\n /**\n * components that were not tagged yet are safe to rename them from the .bitmap file.\n */\n renameNewComponent(sourceId: ComponentID, targetId: ComponentID) {\n const bitMapEntry = this.getBitmapEntry(sourceId);\n if (bitMapEntry.id.hasVersion()) {\n throw new Error(`unable to rename tagged or exported component: ${bitMapEntry.id.toString()}`);\n }\n this.legacyBitMap.removeComponent(bitMapEntry.id);\n bitMapEntry.id = targetId._legacy;\n this.legacyBitMap.setComponent(bitMapEntry.id, bitMapEntry);\n }\n}\n"]}
1
+ {"version":3,"sources":["bit-map.ts"],"names":["BitMap","constructor","legacyBitMap","consumer","addComponentConfig","id","aspectId","config","Error","bitMapEntry","getBitmapEntry","ignoreScopeAndVersion","currentConfig","markAsChanged","removeComponentConfig","write","writeBitMap","ignoreVersion","getComponent","_legacy","renameNewComponent","sourceId","targetId","hasVersion","toString","removeComponent","setComponent"],"mappings":"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","sourcesContent":["import { isEqual } from 'lodash';\nimport { ComponentID } from '@teambit/component-id';\nimport LegacyBitMap from '@teambit/legacy/dist/consumer/bit-map';\nimport { Consumer } from '@teambit/legacy/dist/consumer';\nimport { GetBitMapComponentOptions } from '@teambit/legacy/dist/consumer/bit-map/bit-map';\nimport ComponentMap from '@teambit/legacy/dist/consumer/bit-map/component-map';\n/**\n * consider extracting to a new component.\n * (pro: making Workspace aspect smaller. con: it's an implementation details of the workspace)\n */\nexport class BitMap {\n constructor(private legacyBitMap: LegacyBitMap, private consumer: Consumer) {}\n\n /**\n * adds component config to the .bitmap file.\n * later, upon `bit tag`, the data is saved in the scope.\n * returns a boolean indicating whether a change has been made.\n */\n addComponentConfig(id: ComponentID, aspectId: string, config: Record<string, any> = {}): boolean {\n if (!aspectId || typeof aspectId !== 'string') throw new Error(`expect aspectId to be string, got ${aspectId}`);\n const bitMapEntry = this.getBitmapEntry(id, { ignoreScopeAndVersion: true });\n const currentConfig = (bitMapEntry.config ||= {})[aspectId];\n if (isEqual(currentConfig, config)) {\n return false; // no changes\n }\n if (!config) {\n delete bitMapEntry.config[aspectId];\n } else {\n bitMapEntry.config[aspectId] = config;\n }\n this.legacyBitMap.markAsChanged();\n\n return true; // changes have been made\n }\n\n removeComponentConfig(id: ComponentID, aspectId: string): boolean {\n if (!aspectId || typeof aspectId !== 'string') throw new Error(`expect aspectId to be string, got ${aspectId}`);\n const bitMapEntry = this.getBitmapEntry(id, { ignoreScopeAndVersion: true });\n const currentConfig = (bitMapEntry.config ||= {})[aspectId];\n if (!currentConfig) {\n return false; // no changes\n }\n delete bitMapEntry.config[aspectId];\n this.legacyBitMap.markAsChanged();\n\n return true; // changes have been made\n }\n\n /**\n * write .bitmap object to the filesystem\n */\n async write() {\n await this.consumer.writeBitMap();\n }\n\n /**\n * get the data saved in the .bitmap file for this component-id.\n */\n getBitmapEntry(\n id: ComponentID,\n { ignoreVersion, ignoreScopeAndVersion }: GetBitMapComponentOptions = {}\n ): ComponentMap {\n return this.legacyBitMap.getComponent(id._legacy, { ignoreVersion, ignoreScopeAndVersion });\n }\n\n /**\n * components that were not tagged yet are safe to rename them from the .bitmap file.\n */\n renameNewComponent(sourceId: ComponentID, targetId: ComponentID) {\n const bitMapEntry = this.getBitmapEntry(sourceId);\n if (bitMapEntry.id.hasVersion()) {\n throw new Error(`unable to rename tagged or exported component: ${bitMapEntry.id.toString()}`);\n }\n this.legacyBitMap.removeComponent(bitMapEntry.id);\n bitMapEntry.id = targetId._legacy;\n this.legacyBitMap.setComponent(bitMapEntry.id, bitMapEntry);\n }\n}"]}
@@ -0,0 +1,11 @@
1
+ import { Command } from '@teambit/cli';
2
+ import { Workspace } from '../workspace';
3
+ export declare class EnvsSetCmd implements Command {
4
+ private workspace;
5
+ name: string;
6
+ description: string;
7
+ options: never[];
8
+ group: string;
9
+ constructor(workspace: Workspace);
10
+ report([pattern, env]: [string, string]): Promise<string>;
11
+ }
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ require("core-js/modules/es.array.iterator.js");
6
+
7
+ require("core-js/modules/es.promise.js");
8
+
9
+ Object.defineProperty(exports, "__esModule", {
10
+ value: true
11
+ });
12
+ exports.EnvsSetCmd = void 0;
13
+
14
+ function _defineProperty2() {
15
+ const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
16
+
17
+ _defineProperty2 = function () {
18
+ return data;
19
+ };
20
+
21
+ return data;
22
+ }
23
+
24
+ function _chalk() {
25
+ const data = _interopRequireDefault(require("chalk"));
26
+
27
+ _chalk = function () {
28
+ return data;
29
+ };
30
+
31
+ return data;
32
+ }
33
+
34
+ class EnvsSetCmd {
35
+ constructor(workspace) {
36
+ this.workspace = workspace;
37
+ (0, _defineProperty2().default)(this, "name", 'set <pattern> <env>');
38
+ (0, _defineProperty2().default)(this, "description", 'set an environment to component(s)');
39
+ (0, _defineProperty2().default)(this, "options", []);
40
+ (0, _defineProperty2().default)(this, "group", 'development');
41
+ }
42
+
43
+ async report([pattern, env]) {
44
+ const envId = await this.workspace.resolveComponentId(env);
45
+ const components = await this.workspace.byPattern(pattern);
46
+ await this.workspace.setEnvToComponents(envId, components);
47
+ return `added ${_chalk().default.bold(envId.toString())} env to the following component(s):
48
+ ${components.map(comp => comp.id.toString()).join('\n')}`;
49
+ }
50
+
51
+ }
52
+
53
+ exports.EnvsSetCmd = EnvsSetCmd;
54
+
55
+ //# sourceMappingURL=envs-set.cmd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["envs-set.cmd.ts"],"names":["EnvsSetCmd","constructor","workspace","report","pattern","env","envId","resolveComponentId","components","byPattern","setEnvToComponents","chalk","bold","toString","map","comp","id","join"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGO,MAAMA,UAAN,CAAoC;AAMzCC,EAAAA,WAAW,CAASC,SAAT,EAA+B;AAAA,SAAtBA,SAAsB,GAAtBA,SAAsB;AAAA,kDALnC,qBAKmC;AAAA,yDAJ5B,oCAI4B;AAAA,qDAHhC,EAGgC;AAAA,mDAFlC,aAEkC;AAAE;;AAEhC,QAANC,MAAM,CAAC,CAACC,OAAD,EAAUC,GAAV,CAAD,EAAmC;AAC7C,UAAMC,KAAK,GAAG,MAAM,KAAKJ,SAAL,CAAeK,kBAAf,CAAkCF,GAAlC,CAApB;AACA,UAAMG,UAAU,GAAG,MAAM,KAAKN,SAAL,CAAeO,SAAf,CAAyBL,OAAzB,CAAzB;AACA,UAAM,KAAKF,SAAL,CAAeQ,kBAAf,CAAkCJ,KAAlC,EAAyCE,UAAzC,CAAN;AACA,WAAQ,SAAQG,iBAAMC,IAAN,CAAWN,KAAK,CAACO,QAAN,EAAX,CAA6B;AACjD,EAAEL,UAAU,CAACM,GAAX,CAAgBC,IAAD,IAAUA,IAAI,CAACC,EAAL,CAAQH,QAAR,EAAzB,EAA6CI,IAA7C,CAAkD,IAAlD,CAAwD,EADtD;AAED;;AAdwC","sourcesContent":["import { Command } from '@teambit/cli';\nimport chalk from 'chalk';\nimport { Workspace } from '../workspace';\n\nexport class EnvsSetCmd implements Command {\n name = 'set <pattern> <env>';\n description = 'set an environment to component(s)';\n options = [];\n group = 'development';\n\n constructor(private workspace: Workspace) {}\n\n async report([pattern, env]: [string, string]) {\n const envId = await this.workspace.resolveComponentId(env);\n const components = await this.workspace.byPattern(pattern);\n await this.workspace.setEnvToComponents(envId, components);\n return `added ${chalk.bold(envId.toString())} env to the following component(s):\n${components.map((comp) => comp.id.toString()).join('\\n')}`;\n }\n}\n"]}
@@ -0,0 +1,11 @@
1
+ import { Command } from '@teambit/cli';
2
+ import { Workspace } from '../workspace';
3
+ export declare class EnvsUnsetCmd implements Command {
4
+ private workspace;
5
+ name: string;
6
+ description: string;
7
+ options: never[];
8
+ group: string;
9
+ constructor(workspace: Workspace);
10
+ report([pattern]: [string]): Promise<string>;
11
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ require("core-js/modules/es.array.iterator.js");
6
+
7
+ require("core-js/modules/es.promise.js");
8
+
9
+ Object.defineProperty(exports, "__esModule", {
10
+ value: true
11
+ });
12
+ exports.EnvsUnsetCmd = void 0;
13
+
14
+ function _defineProperty2() {
15
+ const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
16
+
17
+ _defineProperty2 = function () {
18
+ return data;
19
+ };
20
+
21
+ return data;
22
+ }
23
+
24
+ class EnvsUnsetCmd {
25
+ constructor(workspace) {
26
+ this.workspace = workspace;
27
+ (0, _defineProperty2().default)(this, "name", 'unset <pattern>');
28
+ (0, _defineProperty2().default)(this, "description", 'unset an environment from component(s)');
29
+ (0, _defineProperty2().default)(this, "options", []);
30
+ (0, _defineProperty2().default)(this, "group", 'development');
31
+ }
32
+
33
+ async report([pattern]) {
34
+ const components = await this.workspace.byPattern(pattern);
35
+ const {
36
+ changed
37
+ } = await this.workspace.unsetEnvFromComponents(components);
38
+ return `successfully removed env from the following component(s):
39
+ ${changed.map(id => id.toString()).join('\n')}`;
40
+ }
41
+
42
+ }
43
+
44
+ exports.EnvsUnsetCmd = EnvsUnsetCmd;
45
+
46
+ //# sourceMappingURL=envs-unset.cmd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["envs-unset.cmd.ts"],"names":["EnvsUnsetCmd","constructor","workspace","report","pattern","components","byPattern","changed","unsetEnvFromComponents","map","id","toString","join"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAGO,MAAMA,YAAN,CAAsC;AAM3CC,EAAAA,WAAW,CAASC,SAAT,EAA+B;AAAA,SAAtBA,SAAsB,GAAtBA,SAAsB;AAAA,kDALnC,iBAKmC;AAAA,yDAJ5B,wCAI4B;AAAA,qDAHhC,EAGgC;AAAA,mDAFlC,aAEkC;AAAE;;AAEhC,QAANC,MAAM,CAAC,CAACC,OAAD,CAAD,EAAsB;AAChC,UAAMC,UAAU,GAAG,MAAM,KAAKH,SAAL,CAAeI,SAAf,CAAyBF,OAAzB,CAAzB;AACA,UAAM;AAAEG,MAAAA;AAAF,QAAc,MAAM,KAAKL,SAAL,CAAeM,sBAAf,CAAsCH,UAAtC,CAA1B;AACA,WAAQ;AACZ,EAAEE,OAAO,CAACE,GAAR,CAAaC,EAAD,IAAQA,EAAE,CAACC,QAAH,EAApB,EAAmCC,IAAnC,CAAwC,IAAxC,CAA8C,EAD5C;AAED;;AAb0C","sourcesContent":["import { Command } from '@teambit/cli';\nimport { Workspace } from '../workspace';\n\nexport class EnvsUnsetCmd implements Command {\n name = 'unset <pattern>';\n description = 'unset an environment from component(s)';\n options = [];\n group = 'development';\n\n constructor(private workspace: Workspace) {}\n\n async report([pattern]: [string]) {\n const components = await this.workspace.byPattern(pattern);\n const { changed } = await this.workspace.unsetEnvFromComponents(components);\n return `successfully removed env from the following component(s):\n${changed.map((id) => id.toString()).join('\\n')}`;\n }\n}\n"]}
@@ -350,16 +350,13 @@ export declare class Workspace implements ComponentFactory {
350
350
  private componentDefaultScopeFromComponentDirAndNameWithoutConfigFile;
351
351
  /**
352
352
  * Calculate the component config based on:
353
+ * the config property in the .bitmap file
353
354
  * the component.json file in the component folder
354
355
  * matching pattern in the variants config
355
356
  * defaults extensions from workspace config
356
- *
357
- * @param {ComponentID} componentId
358
- * @param {Component} [componentFromScope]
359
- * @returns {Promise<ExtensionDataList>}
360
- * @memberof Workspace
361
357
  */
362
358
  componentExtensions(componentId: ComponentID, componentFromScope?: Component): Promise<ExtensionDataList>;
359
+ private filterEnvsFromExtensionsIfNeeded;
363
360
  triggerOnPreWatch(componentIds: ComponentID[], watchOpts: WatchOptions): Promise<void>;
364
361
  /**
365
362
  * This will mutate the entries with extensionId prop to have resolved legacy id
@@ -479,5 +476,17 @@ export declare class Workspace implements ComponentFactory {
479
476
  * @param {string[]} the list of packages that should be removed from dependencies.
480
477
  */
481
478
  uninstallDependencies(packages: string[]): Promise<ComponentMap<string>>;
479
+ /**
480
+ * configure an environment to the given components in the .bitmap file, this configuration overrides other, such as
481
+ * overrides in workspace.jsonc.
482
+ */
483
+ setEnvToComponents(envId: ComponentID, components: Component[]): Promise<void>;
484
+ /**
485
+ * remove env configuration from the .bitmap file, so then other configuration, such as "variants" will take place
486
+ */
487
+ unsetEnvFromComponents(components: Component[]): Promise<{
488
+ changed: ComponentID[];
489
+ unchanged: ComponentID[];
490
+ }>;
482
491
  }
483
492
  export default Workspace;
package/dist/workspace.js CHANGED
@@ -1226,19 +1226,15 @@ class Workspace {
1226
1226
  }
1227
1227
  /**
1228
1228
  * Calculate the component config based on:
1229
+ * the config property in the .bitmap file
1229
1230
  * the component.json file in the component folder
1230
1231
  * matching pattern in the variants config
1231
1232
  * defaults extensions from workspace config
1232
- *
1233
- * @param {ComponentID} componentId
1234
- * @param {Component} [componentFromScope]
1235
- * @returns {Promise<ExtensionDataList>}
1236
- * @memberof Workspace
1237
1233
  */
1238
1234
 
1239
1235
 
1240
1236
  async componentExtensions(componentId, componentFromScope) {
1241
- var _componentFromScope$c, _componentConfigFile$, _variantConfig$propag;
1237
+ var _componentFromScope$c, _componentConfigFile$, _variantConfig$propag, _wsDefaultExtensions;
1242
1238
 
1243
1239
  // TODO: consider caching this result
1244
1240
  let configFileExtensions;
@@ -1278,54 +1274,83 @@ class Workspace {
1278
1274
 
1279
1275
 
1280
1276
  const extensionsToMerge = [];
1277
+ let envWasFoundPreviously = false;
1278
+
1279
+ const addAndLoadExtensions = async extensions => {
1280
+ const extsWithoutRemoved = extensions.filterRemovedExtensions();
1281
+ const selfInMergedExtensions = extsWithoutRemoved.findExtension(componentId._legacy.toStringWithoutScopeAndVersion(), true, true);
1282
+ const extsWithoutSelf = selfInMergedExtensions !== null && selfInMergedExtensions !== void 0 && selfInMergedExtensions.extensionId ? extsWithoutRemoved.remove(selfInMergedExtensions.extensionId) : extsWithoutRemoved;
1283
+ await this.loadExtensions(extsWithoutSelf);
1284
+ const {
1285
+ extensionDataListFiltered,
1286
+ envIsCurrentlySet
1287
+ } = this.filterEnvsFromExtensionsIfNeeded(extsWithoutSelf, envWasFoundPreviously);
1288
+ if (envIsCurrentlySet) envWasFoundPreviously = true;
1289
+ extensionsToMerge.push(extensionDataListFiltered);
1290
+ };
1281
1291
 
1282
1292
  if (bitMapExtensions) {
1283
1293
  const extensionsDataEntries = Object.keys(bitMapExtensions).map(aspectId => new (_extensionData().ExtensionDataEntry)(aspectId, undefined, aspectId, bitMapExtensions[aspectId]));
1284
1294
  const extensionDataList = new (_extensionData().ExtensionDataList)(...extensionsDataEntries);
1285
- extensionsToMerge.push(extensionDataList);
1295
+ await addAndLoadExtensions(extensionDataList);
1286
1296
  }
1287
1297
 
1288
1298
  if (configFileExtensions) {
1289
- extensionsToMerge.push(configFileExtensions);
1299
+ await addAndLoadExtensions(configFileExtensions);
1290
1300
  }
1291
1301
 
1292
1302
  let continuePropagating = (_componentConfigFile$ = componentConfigFile === null || componentConfigFile === void 0 ? void 0 : componentConfigFile.propagate) !== null && _componentConfigFile$ !== void 0 ? _componentConfigFile$ : true;
1293
1303
 
1294
1304
  if (variantsExtensions && continuePropagating) {
1295
1305
  // Put it in the start to make sure the config file is stronger
1296
- extensionsToMerge.push(variantsExtensions);
1306
+ await addAndLoadExtensions(variantsExtensions);
1297
1307
  }
1298
1308
 
1299
1309
  continuePropagating = continuePropagating && ((_variantConfig$propag = variantConfig === null || variantConfig === void 0 ? void 0 : variantConfig.propagate) !== null && _variantConfig$propag !== void 0 ? _variantConfig$propag : true); // Do not apply default extensions on the default extensions (it will create infinite loop when loading them)
1300
1310
 
1301
- const isDefaultExtension = wsDefaultExtensions.findExtension(componentId.toString(), true, true);
1311
+ const isDefaultExtension = (_wsDefaultExtensions = wsDefaultExtensions) === null || _wsDefaultExtensions === void 0 ? void 0 : _wsDefaultExtensions.findExtension(componentId.toString(), true, true);
1302
1312
 
1303
1313
  if (wsDefaultExtensions && continuePropagating && !isDefaultExtension) {
1304
1314
  // Put it in the start to make sure the config file is stronger
1305
- extensionsToMerge.push(wsDefaultExtensions);
1315
+ await addAndLoadExtensions(wsDefaultExtensions);
1306
1316
  } // It's before the scope extensions, since there is no need to resolve extensions from scope they are already resolved
1307
1317
  // await Promise.all(extensionsToMerge.map((extensions) => this.resolveExtensionsList(extensions)));
1308
1318
 
1309
1319
 
1310
1320
  if (mergeFromScope && continuePropagating) {
1311
- extensionsToMerge.push(scopeExtensions);
1321
+ await addAndLoadExtensions(scopeExtensions);
1312
1322
  } // It's important to do this resolution before the merge, otherwise we have issues with extensions
1313
1323
  // coming from scope with local scope name, as opposed to the same extension comes from the workspace with default scope name
1314
1324
 
1315
1325
 
1316
- const promises = extensionsToMerge.map(list => this.resolveExtensionListIds(list));
1317
- await Promise.all(promises);
1318
-
1319
- let mergedExtensions = _extensionData().ExtensionDataList.mergeConfigs(extensionsToMerge).filterRemovedExtensions(); // remove self from merged extensions
1320
-
1326
+ await Promise.all(extensionsToMerge.map(list => this.resolveExtensionListIds(list)));
1327
+ return _extensionData().ExtensionDataList.mergeConfigs(extensionsToMerge);
1328
+ }
1321
1329
 
1322
- const selfInMergedExtensions = mergedExtensions.findExtension(componentId._legacy.toStringWithoutScopeAndVersion(), true, true);
1330
+ filterEnvsFromExtensionsIfNeeded(extensionDataList, envWasFoundPreviously) {
1331
+ const envAspect = extensionDataList.findExtension(_envs().EnvsAspect.id);
1332
+ const envFromEnvsAspect = envAspect === null || envAspect === void 0 ? void 0 : envAspect.config.env;
1333
+ const [envsNotFromEnvsAspect, nonEnvs] = (0, _lodash().partition)(extensionDataList, ext => this.envs.isEnvRegistered(ext.stringId));
1334
+ const extensionDataListFiltered = new (_extensionData().ExtensionDataList)(...nonEnvs);
1335
+ const envIsCurrentlySet = envFromEnvsAspect || envsNotFromEnvsAspect.length;
1336
+ const shouldIgnoreCurrentEnv = envIsCurrentlySet && envWasFoundPreviously;
1323
1337
 
1324
- if (selfInMergedExtensions && selfInMergedExtensions.extensionId) {
1325
- mergedExtensions = mergedExtensions.remove(selfInMergedExtensions.extensionId);
1338
+ if (shouldIgnoreCurrentEnv) {
1339
+ // still, aspect env may have other data other then config.env.
1340
+ if (envAspect) {
1341
+ delete envAspect.config.env;
1342
+ extensionDataListFiltered.push(envAspect);
1343
+ }
1344
+ } else {
1345
+ // add the envs
1346
+ if (envAspect) extensionDataListFiltered.push(envAspect);
1347
+ extensionDataListFiltered.push(...envsNotFromEnvsAspect);
1326
1348
  }
1327
1349
 
1328
- return mergedExtensions;
1350
+ return {
1351
+ extensionDataListFiltered,
1352
+ envIsCurrentlySet
1353
+ };
1329
1354
  }
1330
1355
 
1331
1356
  async triggerOnPreWatch(componentIds, watchOpts) {
@@ -2199,6 +2224,51 @@ your workspace.jsonc has this component-id set. you might want to remove/change
2199
2224
  dedupe: true
2200
2225
  });
2201
2226
  }
2227
+ /**
2228
+ * configure an environment to the given components in the .bitmap file, this configuration overrides other, such as
2229
+ * overrides in workspace.jsonc.
2230
+ */
2231
+
2232
+
2233
+ async setEnvToComponents(envId, components) {
2234
+ const envIdStr = envId.toString();
2235
+ components.forEach(component => {
2236
+ this.bitMap.addComponentConfig(component.id, envIdStr);
2237
+ this.bitMap.addComponentConfig(component.id, _envs().EnvsAspect.id, {
2238
+ env: envIdStr
2239
+ });
2240
+ });
2241
+ await this.bitMap.write();
2242
+ }
2243
+ /**
2244
+ * remove env configuration from the .bitmap file, so then other configuration, such as "variants" will take place
2245
+ */
2246
+
2247
+
2248
+ async unsetEnvFromComponents(components) {
2249
+ const changed = [];
2250
+ const unchanged = [];
2251
+ components.forEach(comp => {
2252
+ var _bitMapEntry$config, _bitMapEntry$config$E;
2253
+
2254
+ const bitMapEntry = this.bitMap.getBitmapEntry(comp.id);
2255
+ const currentEnv = (_bitMapEntry$config = bitMapEntry.config) === null || _bitMapEntry$config === void 0 ? void 0 : (_bitMapEntry$config$E = _bitMapEntry$config[_envs().EnvsAspect.id]) === null || _bitMapEntry$config$E === void 0 ? void 0 : _bitMapEntry$config$E.env;
2256
+
2257
+ if (!currentEnv) {
2258
+ unchanged.push(comp.id);
2259
+ return;
2260
+ }
2261
+
2262
+ this.bitMap.removeComponentConfig(comp.id, currentEnv);
2263
+ this.bitMap.removeComponentConfig(comp.id, _envs().EnvsAspect.id);
2264
+ changed.push(comp.id);
2265
+ });
2266
+ await this.bitMap.write();
2267
+ return {
2268
+ changed,
2269
+ unchanged
2270
+ };
2271
+ }
2202
2272
 
2203
2273
  }
2204
2274
  /**