@teambit/workspace 1.0.259 → 1.0.260

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
- import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.workspace_workspace@1.0.259/dist/workspace.composition.js';
2
- import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.workspace_workspace@1.0.259/dist/workspace.docs.mdx';
1
+ import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.workspace_workspace@1.0.260/dist/workspace.composition.js';
2
+ import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.workspace_workspace@1.0.260/dist/workspace.docs.mdx';
3
3
 
4
4
  export const compositions = [compositions_0];
5
5
  export const overview = [overview_0];
@@ -0,0 +1,18 @@
1
+ import { Command, CommandOptions } from '@teambit/cli';
2
+ import { Workspace } from './workspace';
3
+ export declare class UnuseCmd implements Command {
4
+ private workspace;
5
+ name: string;
6
+ group: string;
7
+ description: string;
8
+ arguments: {
9
+ name: string;
10
+ description: string;
11
+ }[];
12
+ alias: string;
13
+ options: CommandOptions;
14
+ loader: boolean;
15
+ remoteOp: boolean;
16
+ constructor(workspace: Workspace);
17
+ report([id]: [string]): Promise<any>;
18
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.UnuseCmd = void 0;
7
+ function _chalk() {
8
+ const data = _interopRequireDefault(require("chalk"));
9
+ _chalk = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
16
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
17
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
18
+ class UnuseCmd {
19
+ constructor(workspace) {
20
+ this.workspace = workspace;
21
+ _defineProperty(this, "name", 'unuse <component-id>');
22
+ _defineProperty(this, "group", 'collaborate');
23
+ _defineProperty(this, "description", 'unset aspects in the workspace config (opposite of "use" command)');
24
+ _defineProperty(this, "arguments", [{
25
+ name: 'component-id',
26
+ description: 'the component ID of the aspect'
27
+ }]);
28
+ _defineProperty(this, "alias", '');
29
+ _defineProperty(this, "options", []);
30
+ _defineProperty(this, "loader", true);
31
+ _defineProperty(this, "remoteOp", true);
32
+ }
33
+ async report([id]) {
34
+ const result = await this.workspace.unuse(id);
35
+ if (!result) return _chalk().default.yellow(`"${id}" was not found in the workspace.jsonc file.`);
36
+ return _chalk().default.green(`workspace.jsonc updated successfully! the aspect "${id}" has been removed.`);
37
+ }
38
+ }
39
+ exports.UnuseCmd = UnuseCmd;
40
+
41
+ //# sourceMappingURL=unuse.cmd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_chalk","data","_interopRequireDefault","require","obj","__esModule","default","_defineProperty","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","t","i","_toPrimitive","r","e","Symbol","toPrimitive","call","TypeError","String","Number","UnuseCmd","constructor","workspace","name","description","report","id","result","unuse","chalk","yellow","green","exports"],"sources":["unuse.cmd.ts"],"sourcesContent":["import { Command, CommandOptions } from '@teambit/cli';\nimport chalk from 'chalk';\nimport { Workspace } from './workspace';\n\nexport class UnuseCmd implements Command {\n name = 'unuse <component-id>';\n group = 'collaborate';\n description = 'unset aspects in the workspace config (opposite of \"use\" command)';\n arguments = [{ name: 'component-id', description: 'the component ID of the aspect' }];\n alias = '';\n options = [] as CommandOptions;\n loader = true;\n remoteOp = true;\n\n constructor(private workspace: Workspace) {}\n\n async report([id]: [string]): Promise<any> {\n const result = await this.workspace.unuse(id);\n if (!result) return chalk.yellow(`\"${id}\" was not found in the workspace.jsonc file.`);\n return chalk.green(`workspace.jsonc updated successfully! the aspect \"${id}\" has been removed.`);\n }\n}\n"],"mappings":";;;;;;AACA,SAAAA,OAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,MAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAA0B,SAAAC,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,SAAAG,gBAAAH,GAAA,EAAAI,GAAA,EAAAC,KAAA,IAAAD,GAAA,GAAAE,cAAA,CAAAF,GAAA,OAAAA,GAAA,IAAAJ,GAAA,IAAAO,MAAA,CAAAC,cAAA,CAAAR,GAAA,EAAAI,GAAA,IAAAC,KAAA,EAAAA,KAAA,EAAAI,UAAA,QAAAC,YAAA,QAAAC,QAAA,oBAAAX,GAAA,CAAAI,GAAA,IAAAC,KAAA,WAAAL,GAAA;AAAA,SAAAM,eAAAM,CAAA,QAAAC,CAAA,GAAAC,YAAA,CAAAF,CAAA,uCAAAC,CAAA,GAAAA,CAAA,GAAAA,CAAA;AAAA,SAAAC,aAAAF,CAAA,EAAAG,CAAA,2BAAAH,CAAA,KAAAA,CAAA,SAAAA,CAAA,MAAAI,CAAA,GAAAJ,CAAA,CAAAK,MAAA,CAAAC,WAAA,kBAAAF,CAAA,QAAAH,CAAA,GAAAG,CAAA,CAAAG,IAAA,CAAAP,CAAA,EAAAG,CAAA,uCAAAF,CAAA,SAAAA,CAAA,YAAAO,SAAA,yEAAAL,CAAA,GAAAM,MAAA,GAAAC,MAAA,EAAAV,CAAA;AAGnB,MAAMW,QAAQ,CAAoB;EAUvCC,WAAWA,CAASC,SAAoB,EAAE;IAAA,KAAtBA,SAAoB,GAApBA,SAAoB;IAAAtB,eAAA,eATjC,sBAAsB;IAAAA,eAAA,gBACrB,aAAa;IAAAA,eAAA,sBACP,mEAAmE;IAAAA,eAAA,oBACrE,CAAC;MAAEuB,IAAI,EAAE,cAAc;MAAEC,WAAW,EAAE;IAAiC,CAAC,CAAC;IAAAxB,eAAA,gBAC7E,EAAE;IAAAA,eAAA,kBACA,EAAE;IAAAA,eAAA,iBACH,IAAI;IAAAA,eAAA,mBACF,IAAI;EAE4B;EAE3C,MAAMyB,MAAMA,CAAC,CAACC,EAAE,CAAW,EAAgB;IACzC,MAAMC,MAAM,GAAG,MAAM,IAAI,CAACL,SAAS,CAACM,KAAK,CAACF,EAAE,CAAC;IAC7C,IAAI,CAACC,MAAM,EAAE,OAAOE,gBAAK,CAACC,MAAM,CAAE,IAAGJ,EAAG,8CAA6C,CAAC;IACtF,OAAOG,gBAAK,CAACE,KAAK,CAAE,qDAAoDL,EAAG,qBAAoB,CAAC;EAClG;AACF;AAACM,OAAA,CAAAZ,QAAA,GAAAA,QAAA","ignoreList":[]}
@@ -3,7 +3,7 @@ import type { PubsubMain } from '@teambit/pubsub';
3
3
  import { IssuesList } from '@teambit/component-issues';
4
4
  import type { AspectLoaderMain, AspectDefinition } from '@teambit/aspect-loader';
5
5
  import { ComponentMain, Component, ComponentFactory, InvalidComponent, ResolveAspectsOptions } from '@teambit/component';
6
- import { ComponentScopeDirMap } from '@teambit/config';
6
+ import { ComponentScopeDirMap, WorkspaceConfig } from '@teambit/config';
7
7
  import { DependencyResolverMain, DependencyList } from '@teambit/dependency-resolver';
8
8
  import { EnvsMain } from '@teambit/envs';
9
9
  import { GraphqlMain } from '@teambit/graphql';
@@ -287,7 +287,8 @@ export declare class Workspace implements ComponentFactory {
287
287
  clearAllComponentsCache(): void;
288
288
  clearComponentCache(id: ComponentID): void;
289
289
  warmCache(): Promise<void>;
290
- cleanFromConfig(ids: ComponentID[]): Promise<void>;
290
+ getWorkspaceConfig(): WorkspaceConfig;
291
+ cleanFromConfig(ids: ComponentID[]): Promise<boolean>;
291
292
  triggerOnComponentChange(id: ComponentID, files: PathOsBasedAbsolute[], removedFiles: PathOsBasedAbsolute[], watchOpts: WatchOptions): Promise<OnComponentEventResult[]>;
292
293
  triggerOnComponentAdd(id: ComponentID, watchOpts: WatchOptions): Promise<OnComponentEventResult[]>;
293
294
  triggerOnComponentRemove(id: ComponentID): Promise<OnComponentEventResult[]>;
@@ -362,6 +363,7 @@ export declare class Workspace implements ComponentFactory {
362
363
  importAndGetMany(ids: Array<ComponentID>, reason?: string, loadOpts?: ComponentLoadOptions, throwOnError?: boolean): Promise<Component[]>;
363
364
  importCurrentLaneIfMissing(): Promise<Lane | undefined>;
364
365
  use(aspectIdStr: string): Promise<string>;
366
+ unuse(aspectIdStr: string): Promise<boolean>;
365
367
  write(component: Component, rootPath?: string): Promise<void>;
366
368
  /**
367
369
  * @todo: the return path here is Linux when asking for relative and os-based when asking for absolute. fix this to be consistent.
package/dist/workspace.js CHANGED
@@ -884,14 +884,20 @@ it's possible that the version ${component.id.version} belong to ${idStr.split('
884
884
  async warmCache() {
885
885
  await this.list();
886
886
  }
887
- async cleanFromConfig(ids) {
887
+ getWorkspaceConfig() {
888
888
  const config = this.harmony.get('teambit.harmony/config');
889
889
  const workspaceConfig = config.workspaceConfig;
890
890
  if (!workspaceConfig) throw new Error('workspace config is missing from Config aspect');
891
- const hasChanged = ids.some(id => workspaceConfig.removeExtension(id.toStringWithoutVersion()));
891
+ return workspaceConfig;
892
+ }
893
+ async cleanFromConfig(ids) {
894
+ const workspaceConfig = this.getWorkspaceConfig();
895
+ const wereIdsRemoved = ids.map(id => workspaceConfig.removeExtension(id));
896
+ const hasChanged = wereIdsRemoved.some(isRemoved => isRemoved);
892
897
  if (hasChanged) await workspaceConfig.write({
893
898
  reasonForChange: 'remove components'
894
899
  });
900
+ return hasChanged;
895
901
  }
896
902
  async triggerOnComponentChange(id, files, removedFiles, watchOpts) {
897
903
  const component = await this.get(id);
@@ -1238,6 +1244,10 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
1238
1244
  const workspaceAspectsLoader = this.getWorkspaceAspectsLoader();
1239
1245
  return workspaceAspectsLoader.use(aspectIdStr);
1240
1246
  }
1247
+ async unuse(aspectIdStr) {
1248
+ const compId = await this.resolveComponentId(aspectIdStr);
1249
+ return this.cleanFromConfig([compId]);
1250
+ }
1241
1251
  async write(component, rootPath) {
1242
1252
  await Promise.all(component.filesystem.files.map(async file => {
1243
1253
  const pathToWrite = rootPath ? _path2().default.join(this.path, rootPath, file.relative) : file.path;
@@ -1478,8 +1488,8 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
1478
1488
  if (!(0, _legacyBitId().isValidScopeName)(scopeName)) {
1479
1489
  throw new (_legacyBitId().InvalidScopeName)(scopeName);
1480
1490
  }
1481
- const config = this.harmony.get('teambit.harmony/config');
1482
- config.workspaceConfig?.setExtension(_workspace().WorkspaceAspect.id, {
1491
+ const workspaceConfig = this.getWorkspaceConfig();
1492
+ workspaceConfig.setExtension(_workspace().WorkspaceAspect.id, {
1483
1493
  defaultScope: scopeName
1484
1494
  }, {
1485
1495
  mergeIntoExisting: true,
@@ -1490,7 +1500,7 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
1490
1500
  this.bitMap.updateDefaultScope(this.config.defaultScope, scopeName);
1491
1501
  }
1492
1502
  this.config.defaultScope = scopeName;
1493
- await config.workspaceConfig?.write({
1503
+ await workspaceConfig.write({
1494
1504
  reasonForChange: `default-scope (${scopeName})`
1495
1505
  });
1496
1506
  await this.bitMap.write('scope-set');