@teambit/workspace 0.0.590 → 0.0.594

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.
@@ -0,0 +1,25 @@
1
+ import { ComponentID } from '@teambit/component-id';
2
+ import LegacyBitMap from '@teambit/legacy/dist/consumer/bit-map';
3
+ import { Consumer } from '@teambit/legacy/dist/consumer';
4
+ import { GetBitMapComponentOptions } from '@teambit/legacy/dist/consumer/bit-map/bit-map';
5
+ import ComponentMap from '@teambit/legacy/dist/consumer/bit-map/component-map';
6
+ /**
7
+ * consider extracting to a new component.
8
+ * (pro: making Workspace aspect smaller. con: it's an implementation details of the workspace)
9
+ */
10
+ export declare class BitMap {
11
+ private legacyBitMap;
12
+ private consumer;
13
+ constructor(legacyBitMap: LegacyBitMap, consumer: Consumer);
14
+ /**
15
+ * adds component config to the .bitmap file.
16
+ * later, upon `bit tag`, the data is saved in the scope.
17
+ * returns a boolean indicating whether a chance has been made.
18
+ */
19
+ addComponentConfig(aspectId: string, id: ComponentID, config?: Record<string, any>): Promise<boolean>;
20
+ /**
21
+ * write .bitmap object to the filesystem
22
+ */
23
+ write(): Promise<void>;
24
+ getBitmapEntry(id: ComponentID, { ignoreVersion, ignoreScopeAndVersion }?: GetBitMapComponentOptions): ComponentMap;
25
+ }
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+
3
+ require("core-js/modules/es.promise.js");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.BitMap = void 0;
9
+
10
+ function _lodash() {
11
+ const data = require("lodash");
12
+
13
+ _lodash = function () {
14
+ return data;
15
+ };
16
+
17
+ return data;
18
+ }
19
+
20
+ /**
21
+ * consider extracting to a new component.
22
+ * (pro: making Workspace aspect smaller. con: it's an implementation details of the workspace)
23
+ */
24
+ class BitMap {
25
+ constructor(legacyBitMap, consumer) {
26
+ this.legacyBitMap = legacyBitMap;
27
+ this.consumer = consumer;
28
+ }
29
+ /**
30
+ * adds component config to the .bitmap file.
31
+ * later, upon `bit tag`, the data is saved in the scope.
32
+ * returns a boolean indicating whether a chance has been made.
33
+ */
34
+
35
+
36
+ async addComponentConfig(aspectId, id, config) {
37
+ if (!aspectId || typeof aspectId !== 'string') throw new Error(`expect aspectId to be string, got ${aspectId}`);
38
+ const bitMapEntry = this.getBitmapEntry(id, {
39
+ ignoreScopeAndVersion: true
40
+ });
41
+ const currentConfig = (bitMapEntry.config || (bitMapEntry.config = {}))[aspectId];
42
+
43
+ if ((0, _lodash().isEqual)(currentConfig, config)) {
44
+ return false; // no changes
45
+ }
46
+
47
+ if (!config) {
48
+ delete bitMapEntry.config[aspectId];
49
+ } else {
50
+ bitMapEntry.config[aspectId] = config;
51
+ }
52
+
53
+ this.legacyBitMap.markAsChanged();
54
+ await this.write();
55
+ return true; // changes have been made
56
+ }
57
+ /**
58
+ * write .bitmap object to the filesystem
59
+ */
60
+
61
+
62
+ async write() {
63
+ await this.consumer.writeBitMap();
64
+ }
65
+
66
+ getBitmapEntry(id, {
67
+ ignoreVersion,
68
+ ignoreScopeAndVersion
69
+ } = {}) {
70
+ return this.legacyBitMap.getComponent(id._legacy, {
71
+ ignoreVersion,
72
+ ignoreScopeAndVersion
73
+ });
74
+ }
75
+
76
+ }
77
+
78
+ exports.BitMap = BitMap;
79
+
80
+ //# sourceMappingURL=bit-map.js.map
@@ -0,0 +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"],"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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\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 chance 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 getBitmapEntry(\n id: ComponentID,\n { ignoreVersion, ignoreScopeAndVersion }: GetBitMapComponentOptions = {}\n ): ComponentMap {\n return this.legacyBitMap.getComponent(id._legacy, { ignoreVersion, ignoreScopeAndVersion });\n }\n}\n"]}
@@ -9,6 +9,7 @@ declare type InstallCmdOptions = {
9
9
  skipImport: boolean;
10
10
  updateExisting: boolean;
11
11
  savePrefix: string;
12
+ addMissingPeers: boolean;
12
13
  };
13
14
  export default class InstallCmd implements Command {
14
15
  /**
@@ -48,7 +48,7 @@ class InstallCmd {
48
48
  (0, _defineProperty2().default)(this, "alias", 'in');
49
49
  (0, _defineProperty2().default)(this, "group", 'development');
50
50
  (0, _defineProperty2().default)(this, "shortDescription", '');
51
- (0, _defineProperty2().default)(this, "options", [['v', 'variants <variants>', 'add packages to specific variants'], ['t', 'type [lifecycleType]', '"runtime" (default) or "peer" (dev is not a valid option)'], ['u', 'update-existing [updateExisting]', 'update existing dependencies version and types'], ['', 'save-prefix [savePrefix]', 'set the prefix to use when adding dependency to workspace.jsonc'], ['', 'skip-dedupe [skipDedupe]', 'do not dedupe dependencies on installation'], ['', 'skip-import [skipImport]', 'do not import bit objects post installation']]);
51
+ (0, _defineProperty2().default)(this, "options", [['v', 'variants <variants>', 'add packages to specific variants'], ['t', 'type [lifecycleType]', '"runtime" (default) or "peer" (dev is not a valid option)'], ['u', 'update-existing [updateExisting]', 'update existing dependencies version and types'], ['', 'save-prefix [savePrefix]', 'set the prefix to use when adding dependency to workspace.jsonc'], ['', 'skip-dedupe [skipDedupe]', 'do not dedupe dependencies on installation'], ['', 'skip-import [skipImport]', 'do not import bit objects post installation'], ['', 'add-missing-peers [addMissingPeers]', 'install all missing peer dependencies']]);
52
52
  }
53
53
 
54
54
  async report([packages = []], options) {
@@ -56,11 +56,12 @@ class InstallCmd {
56
56
  this.logger.console(`Resolving component dependencies for workspace: '${_chalk().default.cyan(this.workspace.name)}'`);
57
57
  const installOpts = {
58
58
  variants: options.variants,
59
- lifecycleType: options.type,
59
+ lifecycleType: options.addMissingPeers ? 'peer' : options.type,
60
60
  dedupe: !options.skipDedupe,
61
61
  import: !options.skipImport,
62
62
  updateExisting: options.updateExisting,
63
- savePrefix: options.savePrefix
63
+ savePrefix: options.savePrefix,
64
+ addMissingPeers: options.addMissingPeers
64
65
  };
65
66
  const components = await this.workspace.install(packages, installOpts);
66
67
  const endTime = Date.now();
@@ -1 +1 @@
1
- {"version":3,"sources":["install.cmd.tsx"],"names":["InstallCmd","constructor","workspace","logger","report","packages","options","startTime","Date","now","console","chalk","cyan","name","installOpts","variants","lifecycleType","type","dedupe","skipDedupe","import","skipImport","updateExisting","savePrefix","components","install","endTime","executionTime","calculateTime","toArray","length","to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AO,CAACgB,cALmB;AAM3CC,MAAAA,UAAU,EAAEjB,OAAO,CAACiB;AANuB,KAA7C;AAQA,UAAMC,UAAU,GAAG,MAAM,KAAKtB,SAAL,CAAeuB,OAAf,CAAuBpB,QAAvB,EAAiCS,WAAjC,CAAzB;AACA,UAAMY,OAAO,GAAGlB,IAAI,CAACC,GAAL,EAAhB;AACA,UAAMkB,aAAa,GAAGC,aAAa,CAACrB,SAAD,EAAYmB,OAAZ,CAAnC;AACA,WAAQ,0CAAyCf,iBAAMC,IAAN,CAC/CY,UAAU,CAACK,OAAX,GAAqBC,MAArB,CAA4BC,QAA5B,EAD+C,CAE/C,oBAAmBpB,iBAAMC,IAAN,CAAWe,aAAa,CAACI,QAAd,EAAX,CAAqC,UAF1D;AAGD;;AA5CgD;;;;AA+CnD,SAASH,aAAT,CAAuBrB,SAAvB,EAA0CmB,OAA1C,EAA2D;AACzD,QAAMM,IAAI,GAAGN,OAAO,GAAGnB,SAAvB;AACA,SAAOyB,IAAI,GAAG,IAAd;AACD","sourcesContent":["import { Command, CommandOptions } from '@teambit/cli';\nimport { WorkspaceDependencyLifecycleType } from '@teambit/dependency-resolver';\nimport { Logger } from '@teambit/logger';\nimport chalk from 'chalk';\n\nimport { Workspace, WorkspaceInstallOptions } from './workspace';\n\ntype InstallCmdOptions = {\n variants: string;\n type: WorkspaceDependencyLifecycleType;\n skipDedupe: boolean;\n skipImport: boolean;\n updateExisting: boolean;\n savePrefix: string;\n};\n\nexport default class InstallCmd implements Command {\n name = 'install [packages...]';\n description = 'install development workspace dependencies';\n alias = 'in';\n group = 'development';\n shortDescription = '';\n options = [\n ['v', 'variants <variants>', 'add packages to specific variants'],\n ['t', 'type [lifecycleType]', '\"runtime\" (default) or \"peer\" (dev is not a valid option)'],\n ['u', 'update-existing [updateExisting]', 'update existing dependencies version and types'],\n ['', 'save-prefix [savePrefix]', 'set the prefix to use when adding dependency to workspace.jsonc'],\n ['', 'skip-dedupe [skipDedupe]', 'do not dedupe dependencies on installation'],\n ['', 'skip-import [skipImport]', 'do not import bit objects post installation'],\n ] as CommandOptions;\n\n constructor(\n /**\n * workspace extension.\n */\n private workspace: Workspace,\n\n /**\n * logger extension.\n */\n private logger: Logger\n ) {}\n\n async report([packages = []]: [string[]], options: InstallCmdOptions) {\n const startTime = Date.now();\n this.logger.console(`Resolving component dependencies for workspace: '${chalk.cyan(this.workspace.name)}'`);\n const installOpts: WorkspaceInstallOptions = {\n variants: options.variants,\n lifecycleType: options.type,\n dedupe: !options.skipDedupe,\n import: !options.skipImport,\n updateExisting: options.updateExisting,\n savePrefix: options.savePrefix,\n };\n const components = await this.workspace.install(packages, installOpts);\n const endTime = Date.now();\n const executionTime = calculateTime(startTime, endTime);\n return `Successfully resolved dependencies for ${chalk.cyan(\n components.toArray().length.toString()\n )} component(s) in ${chalk.cyan(executionTime.toString())} seconds`;\n }\n}\n\nfunction calculateTime(startTime: number, endTime: number) {\n const diff = endTime - startTime;\n return diff / 1000;\n}\n"]}
1
+ {"version":3,"sources":["install.cmd.tsx"],"names":["InstallCmd","constructor","workspace","logger","report","packages","options","startTime","Date","now","console","chalk","cyan","name","installOpts","variants","lifecycleType","addMissingPeers","type","dedupe","skipDedupe","import","skipImport","updateExisting","savePrefix","components","install","endTime","executionTime","calculateTime","toArray","length","toString","diff"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAce,MAAMA,UAAN,CAAoC;AAgBjDC,EAAAA,WAAW;AACT;AACJ;AACA;AACYC,EAAAA,SAJC;AAMT;AACJ;AACA;AACYC,EAAAA,MATC,EAUT;AAAA,SANQD,SAMR,GANQA,SAMR;AAAA,SADQC,MACR,GADQA,MACR;AAAA,kDAzBK,uBAyBL;AAAA,yDAxBY,4CAwBZ;AAAA,mDAvBM,IAuBN;AAAA,mDAtBM,aAsBN;AAAA,8DArBiB,EAqBjB;AAAA,qDApBQ,CACR,CAAC,GAAD,EAAM,qBAAN,EAA6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AnC;AACA,WAAQ,0CAAyChB,iBAAMC,IAAN,CAC/Ca,UAAU,CAACK,OAAX,GAAqBC,MAArB,CAA4BC,QAA5B,EAD+C,CAE/C,oBAAmBrB,iBAAMC,IAAN,CAAWgB,aAAa,CAACI,QAAd,EAAX,CAAqC,UAF1D;AAGD;;AA9CgD;;;;AAiDnD,SAASH,aAAT,CAAuBtB,SAAvB,EAA0CoB,OAA1C,EAA2D;AACzD,QAAMM,IAAI,GAAGN,OAAO,GAAGpB,SAAvB;AACA,SAAO0B,IAAI,GAAG,IAAd;AACD","sourcesContent":["import { Command, CommandOptions } from '@teambit/cli';\nimport { WorkspaceDependencyLifecycleType } from '@teambit/dependency-resolver';\nimport { Logger } from '@teambit/logger';\nimport chalk from 'chalk';\n\nimport { Workspace, WorkspaceInstallOptions } from './workspace';\n\ntype InstallCmdOptions = {\n variants: string;\n type: WorkspaceDependencyLifecycleType;\n skipDedupe: boolean;\n skipImport: boolean;\n updateExisting: boolean;\n savePrefix: string;\n addMissingPeers: boolean;\n};\n\nexport default class InstallCmd implements Command {\n name = 'install [packages...]';\n description = 'install development workspace dependencies';\n alias = 'in';\n group = 'development';\n shortDescription = '';\n options = [\n ['v', 'variants <variants>', 'add packages to specific variants'],\n ['t', 'type [lifecycleType]', '\"runtime\" (default) or \"peer\" (dev is not a valid option)'],\n ['u', 'update-existing [updateExisting]', 'update existing dependencies version and types'],\n ['', 'save-prefix [savePrefix]', 'set the prefix to use when adding dependency to workspace.jsonc'],\n ['', 'skip-dedupe [skipDedupe]', 'do not dedupe dependencies on installation'],\n ['', 'skip-import [skipImport]', 'do not import bit objects post installation'],\n ['', 'add-missing-peers [addMissingPeers]', 'install all missing peer dependencies'],\n ] as CommandOptions;\n\n constructor(\n /**\n * workspace extension.\n */\n private workspace: Workspace,\n\n /**\n * logger extension.\n */\n private logger: Logger\n ) {}\n\n async report([packages = []]: [string[]], options: InstallCmdOptions) {\n const startTime = Date.now();\n this.logger.console(`Resolving component dependencies for workspace: '${chalk.cyan(this.workspace.name)}'`);\n const installOpts: WorkspaceInstallOptions = {\n variants: options.variants,\n lifecycleType: options.addMissingPeers ? 'peer' : options.type,\n dedupe: !options.skipDedupe,\n import: !options.skipImport,\n updateExisting: options.updateExisting,\n savePrefix: options.savePrefix,\n addMissingPeers: options.addMissingPeers,\n };\n const components = await this.workspace.install(packages, installOpts);\n const endTime = Date.now();\n const executionTime = calculateTime(startTime, endTime);\n return `Successfully resolved dependencies for ${chalk.cyan(\n components.toArray().length.toString()\n )} component(s) in ${chalk.cyan(executionTime.toString())} seconds`;\n }\n}\n\nfunction calculateTime(startTime: number, endTime: number) {\n const diff = endTime - startTime;\n return diff / 1000;\n}"]}
@@ -33,6 +33,7 @@ import { ComponentStatus } from './workspace-component/component-status';
33
33
  import { OnComponentAddSlot, OnComponentChangeSlot, OnComponentLoadSlot, OnComponentRemoveSlot, OnPreWatch, OnPreWatchSlot } from './workspace.provider';
34
34
  import { WorkspaceComponentLoader } from './workspace-component/workspace-component-loader';
35
35
  import { ShouldIgnoreFunc } from './build-graph-from-fs';
36
+ import { BitMap } from './bit-map';
36
37
  export declare type EjectConfResult = {
37
38
  configPath: string;
38
39
  };
@@ -44,6 +45,7 @@ export interface EjectConfOptions {
44
45
  override?: boolean;
45
46
  }
46
47
  export declare type WorkspaceInstallOptions = {
48
+ addMissingPeers?: boolean;
47
49
  variants?: string;
48
50
  lifecycleType?: WorkspaceDependencyLifecycleType;
49
51
  dedupe: boolean;
@@ -60,6 +62,9 @@ export declare type TrackData = {
60
62
  componentName?: string;
61
63
  mainFile?: string;
62
64
  defaultScope?: string;
65
+ config?: {
66
+ [aspectName: string]: any;
67
+ };
63
68
  };
64
69
  export declare type TrackResult = {
65
70
  componentName: string;
@@ -117,6 +122,7 @@ export declare class Workspace implements ComponentFactory {
117
122
  owner?: string;
118
123
  componentsScopeDirsMap: ComponentScopeDirMap;
119
124
  componentLoader: WorkspaceComponentLoader;
125
+ bitMap: BitMap;
120
126
  constructor(
121
127
  /**
122
128
  * private pubsub.
@@ -311,7 +317,6 @@ export declare class Workspace implements ComponentFactory {
311
317
  */
312
318
  private addOwnerToScopeName;
313
319
  write(rootPath: string, component: Component): Promise<void>;
314
- writeBitMap(): Promise<void>;
315
320
  /**
316
321
  * Get the component root dir in the file system (relative to workspace or full)
317
322
  * @param componentId
@@ -395,6 +400,7 @@ export declare class Workspace implements ComponentFactory {
395
400
  * @memberof Workspace
396
401
  */
397
402
  install(packages?: string[], options?: WorkspaceInstallOptions): Promise<ComponentMap<string>>;
403
+ private _addPackages;
398
404
  private _getComponentsWithDependencyPolicies;
399
405
  /**
400
406
  * Updates out-of-date dependencies in the workspace.
@@ -451,12 +457,6 @@ export declare class Workspace implements ComponentFactory {
451
457
  * @memberof Workspace
452
458
  */
453
459
  resolveExtensionsList(extensions: ExtensionDataList): Promise<void[]>;
454
- /**
455
- * adds component config to the .bitmap file.
456
- * later, upon `bit tag`, the data is saved in the scope.
457
- * returns a boolean indicating whether a chance has been made.
458
- */
459
- addComponentConfigToBitmap(aspectId: string, id: ComponentID, config?: Record<string, any>): Promise<boolean>;
460
460
  /**
461
461
  * This will mutate the original extensions list and make sure all extensions has the ids with the scope / default scope
462
462
  *
package/dist/workspace.js CHANGED
@@ -109,6 +109,16 @@ function _importer() {
109
109
  return data;
110
110
  }
111
111
 
112
+ function _bitError() {
113
+ const data = require("@teambit/bit-error");
114
+
115
+ _bitError = function () {
116
+ return data;
117
+ };
118
+
119
+ return data;
120
+ }
121
+
112
122
  function _dependencyResolver() {
113
123
  const data = require("@teambit/dependency-resolver");
114
124
 
@@ -289,16 +299,6 @@ function _componentIdToPackageName() {
289
299
  return data;
290
300
  }
291
301
 
292
- function _bitError() {
293
- const data = require("@teambit/bit-error");
294
-
295
- _bitError = function () {
296
- return data;
297
- };
298
-
299
- return data;
300
- }
301
-
302
302
  function _fsExtra() {
303
303
  const data = _interopRequireDefault(require("fs-extra"));
304
304
 
@@ -419,6 +419,17 @@ function _buildGraphFromFs() {
419
419
  return data;
420
420
  }
421
421
 
422
+ function _bitMap() {
423
+ const data = require("./bit-map");
424
+
425
+ _bitMap = function () {
426
+ return data;
427
+ };
428
+
429
+ return data;
430
+ }
431
+
432
+ /* eslint-disable max-lines */
422
433
  const ComponentAdded = 'componentAdded';
423
434
  exports.ComponentAdded = ComponentAdded;
424
435
  const ComponentChanged = 'componentChanged';
@@ -489,11 +500,13 @@ class Workspace {
489
500
  (0, _defineProperty2().default)(this, "owner", void 0);
490
501
  (0, _defineProperty2().default)(this, "componentsScopeDirsMap", void 0);
491
502
  (0, _defineProperty2().default)(this, "componentLoader", void 0);
503
+ (0, _defineProperty2().default)(this, "bitMap", void 0);
492
504
  (0, _defineProperty2().default)(this, "watcher", new (_watcher().Watcher)(this, this.pubsub));
493
505
  // TODO: refactor - prefer to avoid code inside the constructor.
494
506
  this.owner = (_this$config = this.config) === null || _this$config === void 0 ? void 0 : _this$config.defaultOwner;
495
507
  this.componentLoader = new (_workspaceComponentLoader().WorkspaceComponentLoader)(this, logger, dependencyResolver, envs);
496
- this.validateConfig(); // memoize this method to improve performance.
508
+ this.validateConfig();
509
+ this.bitMap = new (_bitMap().BitMap)(this.consumer.bitMap, this.consumer); // memoize this method to improve performance.
497
510
 
498
511
  this.componentDefaultScopeFromComponentDirAndNameWithoutConfigFile = (0, _memoizee().default)(this.componentDefaultScopeFromComponentDirAndNameWithoutConfigFile.bind(this), {
499
512
  primitive: true,
@@ -810,7 +823,7 @@ class Workspace {
810
823
  // new file. write these changes to the .bitmap file so then other processes have access to
811
824
  // this new file. If the .bitmap wasn't change, it won't do anything.
812
825
 
813
- await this.writeBitMap();
826
+ await this.bitMap.write();
814
827
  const onChangeEntries = this.onComponentChangeSlot.toArray(); // e.g. [ [ 'teambit.bit/compiler', [Function: bound onComponentChange] ] ]
815
828
 
816
829
  const results = [];
@@ -1035,7 +1048,7 @@ class Workspace {
1035
1048
  const addResults = await addComponent.add(); // @todo: the legacy commands have `consumer.onDestroy()` on command completion, it writes the
1036
1049
  // .bitmap file. workspace needs a similar mechanism. once done, remove the next line.
1037
1050
 
1038
- await this.writeBitMap();
1051
+ await this.bitMap.write();
1039
1052
  return addResults;
1040
1053
  }
1041
1054
  /**
@@ -1054,7 +1067,8 @@ class Workspace {
1054
1067
  id: trackData.componentName,
1055
1068
  main: trackData.mainFile,
1056
1069
  override: false,
1057
- defaultScope
1070
+ defaultScope,
1071
+ config: trackData.config
1058
1072
  });
1059
1073
  const result = await addComponent.add();
1060
1074
  const addedComponent = result.addedComponents[0];
@@ -1098,10 +1112,6 @@ class Workspace {
1098
1112
  await _fsExtra().default.outputFile(pathToWrite, file.contents);
1099
1113
  }));
1100
1114
  }
1101
-
1102
- async writeBitMap() {
1103
- await this.consumer.writeBitMap();
1104
- }
1105
1115
  /**
1106
1116
  * Get the component root dir in the file system (relative to workspace or full)
1107
1117
  * @param componentId
@@ -1450,10 +1460,22 @@ class Workspace {
1450
1460
  const scopeIds = scopeComps.map(aspect => aspect.id.toString());
1451
1461
  const workspaceAspects = await this.requireComponents(workspaceComps);
1452
1462
  const workspaceManifests = await this.aspectLoader.getManifestsFromRequireableExtensions(workspaceAspects, throwOnError);
1463
+ const potentialPluginsIndexes = (0, _lodash().compact)(workspaceManifests.map((manifest, index) => {
1464
+ if (this.aspectLoader.isValidAspect(manifest)) return undefined;
1465
+ return index;
1466
+ }));
1453
1467
  const manifestsIds = workspaceManifests.map(m => m.id);
1454
1468
  const scopeManifests = await this.scope.getManifestsGraphRecursively(scopeIds, (0, _lodash().compact)(manifestsIds), throwOnError);
1455
1469
  const allManifests = [...scopeManifests, ...workspaceManifests];
1456
- await this.aspectLoader.loadExtensionsByManifests(allManifests, throwOnError);
1470
+ await this.aspectLoader.loadExtensionsByManifests(allManifests, throwOnError); // Try require components for potential plugins
1471
+
1472
+ const pluginsWorkspaceComps = potentialPluginsIndexes.map(index => {
1473
+ return workspaceComps[index];
1474
+ }); // Do the require again now that the plugins defs already registered
1475
+
1476
+ const pluginsWorkspaceAspects = await this.requireComponents(pluginsWorkspaceComps);
1477
+ const pluginsWorkspaceManifests = await this.aspectLoader.getManifestsFromRequireableExtensions(pluginsWorkspaceAspects, throwOnError);
1478
+ await this.aspectLoader.loadExtensionsByManifests(pluginsWorkspaceManifests, throwOnError);
1457
1479
  return (0, _lodash().compact)(allManifests.map(manifest => manifest.id));
1458
1480
  }
1459
1481
  /**
@@ -1653,40 +1675,25 @@ class Workspace {
1653
1675
 
1654
1676
  async install(packages, options) {
1655
1677
  if (packages && packages.length) {
1656
- if (!(options !== null && options !== void 0 && options.variants) && (options === null || options === void 0 ? void 0 : options.lifecycleType) === 'dev') {
1657
- throw new (_exceptions3().DependencyTypeNotSupportedInPolicy)(options === null || options === void 0 ? void 0 : options.lifecycleType);
1658
- }
1659
-
1660
- this.logger.debug(`installing the following packages: ${packages.join()}`);
1661
- const resolver = await this.dependencyResolver.getVersionResolver();
1662
- const resolvedPackagesP = packages.map(packageName => resolver.resolveRemoteVersion(packageName, {
1663
- rootDir: this.path
1664
- }));
1665
- const resolvedPackages = await Promise.all(resolvedPackagesP);
1666
- const newWorkspacePolicyEntries = [];
1667
- resolvedPackages.forEach(resolvedPackage => {
1668
- if (resolvedPackage.version) {
1669
- const versionWithPrefix = this.dependencyResolver.getVersionWithSavePrefix(resolvedPackage.version, options === null || options === void 0 ? void 0 : options.savePrefix);
1670
- newWorkspacePolicyEntries.push({
1671
- dependencyId: resolvedPackage.packageName,
1672
- value: {
1673
- version: versionWithPrefix
1674
- },
1675
- lifecycleType: (options === null || options === void 0 ? void 0 : options.lifecycleType) || 'runtime'
1676
- });
1677
- }
1678
- });
1679
-
1680
- if (!(options !== null && options !== void 0 && options.variants)) {
1681
- var _options$updateExisti;
1682
-
1683
- this.dependencyResolver.addToRootPolicy(newWorkspacePolicyEntries, {
1684
- updateExisting: (_options$updateExisti = options === null || options === void 0 ? void 0 : options.updateExisting) !== null && _options$updateExisti !== void 0 ? _options$updateExisti : false
1685
- });
1686
- } else {// TODO: implement
1687
- }
1678
+ await this._addPackages(packages, options);
1679
+ }
1688
1680
 
1689
- await this.dependencyResolver.persistConfig(this.path);
1681
+ if (options !== null && options !== void 0 && options.addMissingPeers) {
1682
+ var _options$copyPeerToRu, _options$copyPeerToRu2;
1683
+
1684
+ const compDirMap = await this.getComponentsDirectory([]);
1685
+ const mergedRootPolicy = this.dependencyResolver.getWorkspacePolicy();
1686
+ const depsFilterFn = await this.generateFilterFnForDepsFromLocalRemote();
1687
+ const pmInstallOptions = {
1688
+ dedupe: options === null || options === void 0 ? void 0 : options.dedupe,
1689
+ copyPeerToRuntimeOnRoot: (_options$copyPeerToRu = options === null || options === void 0 ? void 0 : options.copyPeerToRuntimeOnRoot) !== null && _options$copyPeerToRu !== void 0 ? _options$copyPeerToRu : true,
1690
+ copyPeerToRuntimeOnComponents: (_options$copyPeerToRu2 = options === null || options === void 0 ? void 0 : options.copyPeerToRuntimeOnComponents) !== null && _options$copyPeerToRu2 !== void 0 ? _options$copyPeerToRu2 : false,
1691
+ dependencyFilterFn: depsFilterFn,
1692
+ overrides: this.dependencyResolver.config.overrides
1693
+ };
1694
+ const missingPeers = await this.dependencyResolver.getMissingPeerDependencies(this.path, mergedRootPolicy, compDirMap, pmInstallOptions);
1695
+ const missingPeerPackages = Object.entries(missingPeers).map(([peerName, range]) => `${peerName}@${range}`);
1696
+ await this._addPackages(missingPeerPackages, options);
1690
1697
  }
1691
1698
 
1692
1699
  if (options !== null && options !== void 0 && options.import) {
@@ -1698,6 +1705,43 @@ class Workspace {
1698
1705
  return this._installModules(options);
1699
1706
  }
1700
1707
 
1708
+ async _addPackages(packages, options) {
1709
+ if (!(options !== null && options !== void 0 && options.variants) && (options === null || options === void 0 ? void 0 : options.lifecycleType) === 'dev') {
1710
+ throw new (_exceptions3().DependencyTypeNotSupportedInPolicy)(options === null || options === void 0 ? void 0 : options.lifecycleType);
1711
+ }
1712
+
1713
+ this.logger.debug(`installing the following packages: ${packages.join()}`);
1714
+ const resolver = await this.dependencyResolver.getVersionResolver();
1715
+ const resolvedPackagesP = packages.map(packageName => resolver.resolveRemoteVersion(packageName, {
1716
+ rootDir: this.path
1717
+ }));
1718
+ const resolvedPackages = await Promise.all(resolvedPackagesP);
1719
+ const newWorkspacePolicyEntries = [];
1720
+ resolvedPackages.forEach(resolvedPackage => {
1721
+ if (resolvedPackage.version) {
1722
+ const versionWithPrefix = this.dependencyResolver.getVersionWithSavePrefix(resolvedPackage.version, options === null || options === void 0 ? void 0 : options.savePrefix);
1723
+ newWorkspacePolicyEntries.push({
1724
+ dependencyId: resolvedPackage.packageName,
1725
+ value: {
1726
+ version: versionWithPrefix
1727
+ },
1728
+ lifecycleType: (options === null || options === void 0 ? void 0 : options.lifecycleType) || 'runtime'
1729
+ });
1730
+ }
1731
+ });
1732
+
1733
+ if (!(options !== null && options !== void 0 && options.variants)) {
1734
+ var _options$updateExisti;
1735
+
1736
+ this.dependencyResolver.addToRootPolicy(newWorkspacePolicyEntries, {
1737
+ updateExisting: (_options$updateExisti = options === null || options === void 0 ? void 0 : options.updateExisting) !== null && _options$updateExisti !== void 0 ? _options$updateExisti : false
1738
+ });
1739
+ } else {// TODO: implement
1740
+ }
1741
+
1742
+ await this.dependencyResolver.persistConfig(this.path);
1743
+ }
1744
+
1701
1745
  async _getComponentsWithDependencyPolicies() {
1702
1746
  const allComponentIds = await this.listIds();
1703
1747
  const componentConfigFiles = {};
@@ -1800,7 +1844,7 @@ class Workspace {
1800
1844
  }
1801
1845
 
1802
1846
  async _installModules(options) {
1803
- var _options$copyPeerToRu, _options$copyPeerToRu2;
1847
+ var _options$copyPeerToRu3, _options$copyPeerToRu4;
1804
1848
 
1805
1849
  this.logger.console(`installing dependencies in workspace using ${_chalk().default.cyan(this.dependencyResolver.getPackageManagerName())}`);
1806
1850
  this.logger.debug(`installing dependencies in workspace with options`, options);
@@ -1812,8 +1856,8 @@ class Workspace {
1812
1856
  const depsFilterFn = await this.generateFilterFnForDepsFromLocalRemote();
1813
1857
  const pmInstallOptions = {
1814
1858
  dedupe: options === null || options === void 0 ? void 0 : options.dedupe,
1815
- copyPeerToRuntimeOnRoot: (_options$copyPeerToRu = options === null || options === void 0 ? void 0 : options.copyPeerToRuntimeOnRoot) !== null && _options$copyPeerToRu !== void 0 ? _options$copyPeerToRu : true,
1816
- copyPeerToRuntimeOnComponents: (_options$copyPeerToRu2 = options === null || options === void 0 ? void 0 : options.copyPeerToRuntimeOnComponents) !== null && _options$copyPeerToRu2 !== void 0 ? _options$copyPeerToRu2 : false,
1859
+ copyPeerToRuntimeOnRoot: (_options$copyPeerToRu3 = options === null || options === void 0 ? void 0 : options.copyPeerToRuntimeOnRoot) !== null && _options$copyPeerToRu3 !== void 0 ? _options$copyPeerToRu3 : true,
1860
+ copyPeerToRuntimeOnComponents: (_options$copyPeerToRu4 = options === null || options === void 0 ? void 0 : options.copyPeerToRuntimeOnComponents) !== null && _options$copyPeerToRu4 !== void 0 ? _options$copyPeerToRu4 : false,
1817
1861
  dependencyFilterFn: depsFilterFn,
1818
1862
  overrides: this.dependencyResolver.config.overrides
1819
1863
  };
@@ -2105,34 +2149,6 @@ your workspace.jsonc has this component-id set. you might want to remove/change
2105
2149
  });
2106
2150
  return Promise.all(resolveMergedExtensionsP);
2107
2151
  }
2108
- /**
2109
- * adds component config to the .bitmap file.
2110
- * later, upon `bit tag`, the data is saved in the scope.
2111
- * returns a boolean indicating whether a chance has been made.
2112
- */
2113
-
2114
-
2115
- async addComponentConfigToBitmap(aspectId, id, config) {
2116
- if (!aspectId || typeof aspectId !== 'string') throw new Error(`expect aspectId to be string, got ${aspectId}`);
2117
- const bitMapEntry = this.consumer.bitMap.getComponent(id._legacy, {
2118
- ignoreScopeAndVersion: true
2119
- });
2120
- const currentConfig = (bitMapEntry.config || (bitMapEntry.config = {}))[aspectId];
2121
-
2122
- if ((0, _lodash().isEqual)(currentConfig, config)) {
2123
- return false; // no changes
2124
- }
2125
-
2126
- if (!config) {
2127
- delete bitMapEntry.config[aspectId];
2128
- } else {
2129
- bitMapEntry.config[aspectId] = config;
2130
- }
2131
-
2132
- this.consumer.bitMap.markAsChanged();
2133
- await this.writeBitMap();
2134
- return true; // changes have been made
2135
- }
2136
2152
  /**
2137
2153
  * This will mutate the original extensions list and make sure all extensions has the ids with the scope / default scope
2138
2154
  *