@teambit/workspace 0.0.639 → 0.0.640

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.
@@ -42,10 +42,11 @@ class EnvsSetCmd {
42
42
 
43
43
  async report([pattern, env]) {
44
44
  const envId = await this.workspace.resolveComponentId(env);
45
- const components = await this.workspace.byPattern(pattern);
46
- await this.workspace.setEnvToComponents(envId, components);
45
+ const componentIds = await this.workspace.idsByPattern(pattern);
46
+ if (!componentIds.length) return _chalk().default.yellow(`unable to find any matching for ${_chalk().default.bold(pattern)} pattern`);
47
+ await this.workspace.setEnvToComponents(envId, componentIds);
47
48
  return `added ${_chalk().default.bold(envId.toString())} env to the following component(s):
48
- ${components.map(comp => comp.id.toString()).join('\n')}`;
49
+ ${componentIds.map(compId => compId.toString()).join('\n')}`;
49
50
  }
50
51
 
51
52
  }
@@ -1 +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"]}
1
+ {"version":3,"sources":["envs-set.cmd.ts"],"names":["EnvsSetCmd","constructor","workspace","report","pattern","env","envId","resolveComponentId","componentIds","idsByPattern","length","chalk","yellow","bold","setEnvToComponents","toString","map","compId","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,YAAY,GAAG,MAAM,KAAKN,SAAL,CAAeO,YAAf,CAA4BL,OAA5B,CAA3B;AACA,QAAI,CAACI,YAAY,CAACE,MAAlB,EAA0B,OAAOC,iBAAMC,MAAN,CAAc,mCAAkCD,iBAAME,IAAN,CAAWT,OAAX,CAAoB,UAApE,CAAP;AAC1B,UAAM,KAAKF,SAAL,CAAeY,kBAAf,CAAkCR,KAAlC,EAAyCE,YAAzC,CAAN;AACA,WAAQ,SAAQG,iBAAME,IAAN,CAAWP,KAAK,CAACS,QAAN,EAAX,CAA6B;AACjD,EAAEP,YAAY,CAACQ,GAAb,CAAkBC,MAAD,IAAYA,MAAM,CAACF,QAAP,EAA7B,EAAgDG,IAAhD,CAAqD,IAArD,CAA2D,EADzD;AAED;;AAfwC","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 componentIds = await this.workspace.idsByPattern(pattern);\n if (!componentIds.length) return chalk.yellow(`unable to find any matching for ${chalk.bold(pattern)} pattern`);\n await this.workspace.setEnvToComponents(envId, componentIds);\n return `added ${chalk.bold(envId.toString())} env to the following component(s):\n${componentIds.map((compId) => compId.toString()).join('\\n')}`;\n }\n}\n"]}
@@ -31,10 +31,10 @@ class EnvsUnsetCmd {
31
31
  }
32
32
 
33
33
  async report([pattern]) {
34
- const components = await this.workspace.byPattern(pattern);
34
+ const componentIds = await this.workspace.idsByPattern(pattern);
35
35
  const {
36
36
  changed
37
- } = await this.workspace.unsetEnvFromComponents(components);
37
+ } = await this.workspace.unsetEnvFromComponents(componentIds);
38
38
  return `successfully removed env from the following component(s):
39
39
  ${changed.map(id => id.toString()).join('\n')}`;
40
40
  }
@@ -1 +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"]}
1
+ {"version":3,"sources":["envs-unset.cmd.ts"],"names":["EnvsUnsetCmd","constructor","workspace","report","pattern","componentIds","idsByPattern","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,YAAY,GAAG,MAAM,KAAKH,SAAL,CAAeI,YAAf,CAA4BF,OAA5B,CAA3B;AACA,UAAM;AAAEG,MAAAA;AAAF,QAAc,MAAM,KAAKL,SAAL,CAAeM,sBAAf,CAAsCH,YAAtC,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 componentIds = await this.workspace.idsByPattern(pattern);\n const { changed } = await this.workspace.unsetEnvFromComponents(componentIds);\n return `successfully removed env from the following component(s):\n${changed.map((id) => id.toString()).join('\\n')}`;\n }\n}\n"]}
@@ -0,0 +1,14 @@
1
+ import { Command, CommandOptions } from '@teambit/cli';
2
+ import { Workspace } from './workspace';
3
+ export declare class PatternCommand implements Command {
4
+ private workspace;
5
+ name: string;
6
+ alias: string;
7
+ description: string;
8
+ group: string;
9
+ private: boolean;
10
+ options: CommandOptions;
11
+ constructor(workspace: Workspace);
12
+ report([pattern]: [string]): Promise<string>;
13
+ json([pattern]: [string]): Promise<import("@teambit/component-id").ComponentID[]>;
14
+ }
@@ -0,0 +1,61 @@
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.PatternCommand = 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 PatternCommand {
35
+ constructor(workspace) {
36
+ this.workspace = workspace;
37
+ (0, _defineProperty2().default)(this, "name", 'pattern <pattern>');
38
+ (0, _defineProperty2().default)(this, "alias", '');
39
+ (0, _defineProperty2().default)(this, "description", 'list the component ids matching the given pattern');
40
+ (0, _defineProperty2().default)(this, "group", 'development');
41
+ (0, _defineProperty2().default)(this, "private", false);
42
+ (0, _defineProperty2().default)(this, "options", [['j', 'json', 'return the output as JSON']]);
43
+ }
44
+
45
+ async report([pattern]) {
46
+ const ids = await this.workspace.idsByPattern(pattern);
47
+
48
+ const title = _chalk().default.green(`found ${_chalk().default.bold(ids.length.toString())} components matching the pattern`);
49
+
50
+ return `${title}\n${ids.join('\n')}`;
51
+ }
52
+
53
+ async json([pattern]) {
54
+ return this.workspace.idsByPattern(pattern);
55
+ }
56
+
57
+ }
58
+
59
+ exports.PatternCommand = PatternCommand;
60
+
61
+ //# sourceMappingURL=pattern.cmd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["pattern.cmd.ts"],"names":["PatternCommand","constructor","workspace","report","pattern","ids","idsByPattern","title","chalk","green","bold","length","toString","join","json"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGO,MAAMA,cAAN,CAAwC;AAQ7CC,EAAAA,WAAW,CAASC,SAAT,EAA+B;AAAA,SAAtBA,SAAsB,GAAtBA,SAAsB;AAAA,kDAPnC,mBAOmC;AAAA,mDANlC,EAMkC;AAAA,yDAL5B,mDAK4B;AAAA,mDAJlC,aAIkC;AAAA,qDAHhC,KAGgC;AAAA,qDAFhC,CAAC,CAAC,GAAD,EAAM,MAAN,EAAc,2BAAd,CAAD,CAEgC;AAAE;;AAEhC,QAANC,MAAM,CAAC,CAACC,OAAD,CAAD,EAAsB;AAChC,UAAMC,GAAG,GAAG,MAAM,KAAKH,SAAL,CAAeI,YAAf,CAA4BF,OAA5B,CAAlB;;AACA,UAAMG,KAAK,GAAGC,iBAAMC,KAAN,CAAa,SAAQD,iBAAME,IAAN,CAAWL,GAAG,CAACM,MAAJ,CAAWC,QAAX,EAAX,CAAkC,kCAAvD,CAAd;;AACA,WAAQ,GAAEL,KAAM,KAAIF,GAAG,CAACQ,IAAJ,CAAS,IAAT,CAAe,EAAnC;AACD;;AAES,QAAJC,IAAI,CAAC,CAACV,OAAD,CAAD,EAAsB;AAC9B,WAAO,KAAKF,SAAL,CAAeI,YAAf,CAA4BF,OAA5B,CAAP;AACD;;AAlB4C","sourcesContent":["import { Command, CommandOptions } from '@teambit/cli';\nimport chalk from 'chalk';\nimport { Workspace } from './workspace';\n\nexport class PatternCommand implements Command {\n name = 'pattern <pattern>';\n alias = '';\n description = 'list the component ids matching the given pattern';\n group = 'development';\n private = false;\n options = [['j', 'json', 'return the output as JSON']] as CommandOptions;\n\n constructor(private workspace: Workspace) {}\n\n async report([pattern]: [string]) {\n const ids = await this.workspace.idsByPattern(pattern);\n const title = chalk.green(`found ${chalk.bold(ids.length.toString())} components matching the pattern`);\n return `${title}\\n${ids.join('\\n')}`;\n }\n\n async json([pattern]: [string]) {\n return this.workspace.idsByPattern(pattern);\n }\n}\n"]}
@@ -281,6 +281,11 @@ export declare class Workspace implements ComponentFactory {
281
281
  * @param scope scope name.
282
282
  */
283
283
  byPattern(pattern: string, scope?: string): Promise<Component[]>;
284
+ /**
285
+ * get component-ids matching the given pattern. a pattern can have multiple patterns separated by a comma.
286
+ * it supports negate (!) character to exclude ids.
287
+ */
288
+ idsByPattern(pattern: string): Promise<ComponentID[]>;
284
289
  /**
285
290
  * useful for workspace commands, such as `bit build`, `bit compile`.
286
291
  * by default, it should be running on new and modified components.
@@ -496,11 +501,11 @@ export declare class Workspace implements ComponentFactory {
496
501
  * configure an environment to the given components in the .bitmap file, this configuration overrides other, such as
497
502
  * overrides in workspace.jsonc.
498
503
  */
499
- setEnvToComponents(envId: ComponentID, components: Component[]): Promise<void>;
504
+ setEnvToComponents(envId: ComponentID, componentIds: ComponentID[]): Promise<void>;
500
505
  /**
501
506
  * remove env configuration from the .bitmap file, so then other configuration, such as "variants" will take place
502
507
  */
503
- unsetEnvFromComponents(components: Component[]): Promise<{
508
+ unsetEnvFromComponents(ids: ComponentID[]): Promise<{
504
509
  changed: ComponentID[];
505
510
  unchanged: ComponentID[];
506
511
  }>;
package/dist/workspace.js CHANGED
@@ -14,6 +14,8 @@ require("core-js/modules/es.promise.js");
14
14
 
15
15
  require("core-js/modules/es.regexp.exec.js");
16
16
 
17
+ require("core-js/modules/es.string.trim.js");
18
+
17
19
  Object.defineProperty(exports, "__esModule", {
18
20
  value: true
19
21
  });
@@ -59,6 +61,16 @@ function _pMapSeries() {
59
61
  return data;
60
62
  }
61
63
 
64
+ function _multimatch() {
65
+ const data = _interopRequireDefault(require("multimatch"));
66
+
67
+ _multimatch = function () {
68
+ return data;
69
+ };
70
+
71
+ return data;
72
+ }
73
+
62
74
  function _aspectLoader() {
63
75
  const data = require("@teambit/aspect-loader");
64
76
 
@@ -1093,6 +1105,20 @@ class Workspace {
1093
1105
  const components = await this.getMany(targetIds);
1094
1106
  return components;
1095
1107
  }
1108
+ /**
1109
+ * get component-ids matching the given pattern. a pattern can have multiple patterns separated by a comma.
1110
+ * it supports negate (!) character to exclude ids.
1111
+ */
1112
+
1113
+
1114
+ async idsByPattern(pattern) {
1115
+ const ids = await this.listIds();
1116
+ const patterns = pattern.split(',').map(p => p.trim()); // check also as legacyId.toString, as it doesn't have the defaultScope
1117
+
1118
+ const idsToCheck = id => [id.toStringWithoutVersion(), id._legacy.toStringWithoutVersion()];
1119
+
1120
+ return ids.filter(id => (0, _multimatch().default)(idsToCheck(id), patterns).length);
1121
+ }
1096
1122
  /**
1097
1123
  * useful for workspace commands, such as `bit build`, `bit compile`.
1098
1124
  * by default, it should be running on new and modified components.
@@ -1889,8 +1915,13 @@ class Workspace {
1889
1915
  overrides: this.dependencyResolver.config.overrides
1890
1916
  };
1891
1917
  const missingPeers = await this.dependencyResolver.getMissingPeerDependencies(this.path, mergedRootPolicy, compDirMap, pmInstallOptions);
1892
- const missingPeerPackages = Object.entries(missingPeers).map(([peerName, range]) => `${peerName}@${range}`);
1893
- await this._addPackages(missingPeerPackages, options);
1918
+
1919
+ if (missingPeers) {
1920
+ const missingPeerPackages = Object.entries(missingPeers).map(([peerName, range]) => `${peerName}@${range}`);
1921
+ await this._addPackages(missingPeerPackages, options);
1922
+ } else {
1923
+ this.logger.console('No missing peer dependencies found.');
1924
+ }
1894
1925
  }
1895
1926
 
1896
1927
  if (options !== null && options !== void 0 && options.import) {
@@ -2419,13 +2450,13 @@ your workspace.jsonc has this component-id set. you might want to remove/change
2419
2450
  */
2420
2451
 
2421
2452
 
2422
- async setEnvToComponents(envId, components) {
2453
+ async setEnvToComponents(envId, componentIds) {
2423
2454
  const envIdStr = envId.toString();
2424
2455
  const existsOnWorkspace = await this.hasId(envId);
2425
2456
  const envIdStrNoVersion = envId.toStringWithoutVersion();
2426
- components.forEach(component => {
2427
- this.bitMap.addComponentConfig(component.id, existsOnWorkspace ? envIdStrNoVersion : envIdStr);
2428
- this.bitMap.addComponentConfig(component.id, _envs().EnvsAspect.id, {
2457
+ componentIds.forEach(componentId => {
2458
+ this.bitMap.addComponentConfig(componentId, existsOnWorkspace ? envIdStrNoVersion : envIdStr);
2459
+ this.bitMap.addComponentConfig(componentId, _envs().EnvsAspect.id, {
2429
2460
  env: envIdStrNoVersion
2430
2461
  });
2431
2462
  });
@@ -2436,24 +2467,24 @@ your workspace.jsonc has this component-id set. you might want to remove/change
2436
2467
  */
2437
2468
 
2438
2469
 
2439
- async unsetEnvFromComponents(components) {
2470
+ async unsetEnvFromComponents(ids) {
2440
2471
  const changed = [];
2441
2472
  const unchanged = [];
2442
- components.forEach(comp => {
2473
+ ids.forEach(id => {
2443
2474
  var _bitMapEntry$config;
2444
2475
 
2445
- const bitMapEntry = this.bitMap.getBitmapEntry(comp.id);
2476
+ const bitMapEntry = this.bitMap.getBitmapEntry(id);
2446
2477
  const envsAspect = (_bitMapEntry$config = bitMapEntry.config) === null || _bitMapEntry$config === void 0 ? void 0 : _bitMapEntry$config[_envs().EnvsAspect.id];
2447
2478
  const currentEnv = envsAspect && envsAspect !== _config().REMOVE_EXTENSION_SPECIAL_SIGN ? envsAspect.env : null;
2448
2479
 
2449
2480
  if (!currentEnv) {
2450
- unchanged.push(comp.id);
2481
+ unchanged.push(id);
2451
2482
  return;
2452
2483
  }
2453
2484
 
2454
- this.bitMap.removeComponentConfig(comp.id, currentEnv, false);
2455
- this.bitMap.removeComponentConfig(comp.id, _envs().EnvsAspect.id, false);
2456
- changed.push(comp.id);
2485
+ this.bitMap.removeComponentConfig(id, currentEnv, false);
2486
+ this.bitMap.removeComponentConfig(id, _envs().EnvsAspect.id, false);
2487
+ changed.push(id);
2457
2488
  });
2458
2489
  await this.bitMap.write();
2459
2490
  return {