@teambit/workspace 0.0.565 → 0.0.569

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.
Files changed (67) hide show
  1. package/__snapshots__/pick-outdated-pkgs.spec.ts.snap +88 -0
  2. package/component-config-file/component-config-file.ts +98 -0
  3. package/component-config-file/exceptions/already-exists.ts +7 -0
  4. package/component-config-file/exceptions/index.ts +1 -0
  5. package/component-config-file/index.ts +2 -0
  6. package/component-tree.widget.tsx +16 -0
  7. package/dist/__snapshots__/pick-outdated-pkgs.spec.js.snap +88 -0
  8. package/dist/__snapshots__/pick-outdated-pkgs.spec.ts.snap +88 -0
  9. package/dist/pick-outdated-pkgs.d.ts +12 -0
  10. package/dist/pick-outdated-pkgs.js +201 -0
  11. package/dist/pick-outdated-pkgs.js.map +1 -0
  12. package/dist/pick-outdated-pkgs.spec.d.ts +1 -0
  13. package/dist/pick-outdated-pkgs.spec.js +64 -0
  14. package/dist/pick-outdated-pkgs.spec.js.map +1 -0
  15. package/dist/update.cmd.d.ts +24 -0
  16. package/dist/update.cmd.js +48 -0
  17. package/dist/update.cmd.js.map +1 -0
  18. package/dist/workspace.d.ts +14 -0
  19. package/dist/workspace.js +117 -2
  20. package/dist/workspace.js.map +1 -1
  21. package/dist/workspace.provider.js +11 -1
  22. package/dist/workspace.provider.js.map +1 -1
  23. package/eject-conf.cmd.tsx +62 -0
  24. package/events/index.ts +3 -0
  25. package/events/on-component-add-event.ts +14 -0
  26. package/events/on-component-change-event.ts +14 -0
  27. package/events/on-component-removed-event.ts +14 -0
  28. package/exceptions/dependency-type-not-supported-in-policy.ts +7 -0
  29. package/exceptions/incorrect-env-aspect.ts +8 -0
  30. package/exceptions/index.ts +1 -0
  31. package/install.cmd.tsx +67 -0
  32. package/link/component-list-links.ts +50 -0
  33. package/link/core-aspects-links.ts +50 -0
  34. package/link/get-package-name-from-target.ts +5 -0
  35. package/link/index.ts +1 -0
  36. package/link/link-row.ts +20 -0
  37. package/link/link-to-dir.ts +13 -0
  38. package/link/link.cmd.ts +96 -0
  39. package/link/nested-deps-in-nm-links.ts +47 -0
  40. package/link/rewire-row.ts +17 -0
  41. package/list.cmd.tsx +30 -0
  42. package/package-tar/teambit-workspace-0.0.569.tgz +0 -0
  43. package/package.json +54 -65
  44. package/types/asset.d.ts +29 -0
  45. package/types/style.d.ts +42 -0
  46. package/ui/index.ts +1 -0
  47. package/ui/workspace/default-component.ts +7 -0
  48. package/ui/workspace/index.ts +1 -0
  49. package/ui/workspace/use-workspace.ts +193 -0
  50. package/ui/workspace/workspace-context.tsx +5 -0
  51. package/ui/workspace/workspace-model.ts +66 -0
  52. package/ui/workspace/workspace-overview/index.ts +1 -0
  53. package/ui/workspace/workspace-overview/workspace-overview.tsx +21 -0
  54. package/ui/workspace/workspace-provider.tsx +23 -0
  55. package/ui/workspace/workspace.tsx +99 -0
  56. package/ui/workspace-components-drawer/index.ts +1 -0
  57. package/ui/workspace-components-drawer/workspace-components.drawer.tsx +49 -0
  58. package/update.cmd.tsx +30 -0
  59. package/watch/check-types.ts +5 -0
  60. package/watch/output-formatter.ts +50 -0
  61. package/watch/watch.cmd.tsx +142 -0
  62. package/watch/watcher.ts +289 -0
  63. package/workspace-component/component-status.ts +67 -0
  64. package/workspace-component/index.ts +2 -0
  65. package/workspace-component/workspace-component-loader.ts +276 -0
  66. package/workspace-component/workspace-component.ts +51 -0
  67. package/workspace.ui.runtime.tsx +215 -0
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+
3
+ function _pickOutdatedPkgs() {
4
+ const data = require("./pick-outdated-pkgs");
5
+
6
+ _pickOutdatedPkgs = function () {
7
+ return data;
8
+ };
9
+
10
+ return data;
11
+ }
12
+
13
+ describe('makeOutdatedPkgChoices', () => {
14
+ it('should render choices in correct order', () => {
15
+ const choices = (0, _pickOutdatedPkgs().makeOutdatedPkgChoices)([{
16
+ name: 'zoo',
17
+ currentRange: '1.0.0',
18
+ latestRange: '1.1.0',
19
+ source: 'rootPolicy',
20
+ targetField: 'devDependencies'
21
+ }, {
22
+ name: 'qar',
23
+ currentRange: '1.0.0',
24
+ latestRange: '1.1.0',
25
+ source: 'rootPolicy',
26
+ targetField: 'dependencies'
27
+ }, {
28
+ name: 'foo',
29
+ currentRange: '1.0.0',
30
+ latestRange: '2.0.0',
31
+ source: 'rootPolicy',
32
+ targetField: 'dependencies'
33
+ }, {
34
+ name: 'bar',
35
+ currentRange: '1.0.0',
36
+ latestRange: '1.1.0',
37
+ source: 'rootPolicy',
38
+ targetField: 'peerDependencies'
39
+ }]); // @ts-ignore
40
+
41
+ expect(choices).toMatchSnapshot();
42
+ });
43
+ it('should render choices with context information', () => {
44
+ const choices = (0, _pickOutdatedPkgs().makeOutdatedPkgChoices)([{
45
+ name: 'foo',
46
+ currentRange: '1.0.0',
47
+ latestRange: '2.0.0',
48
+ source: 'component',
49
+ componentId: 'comp1',
50
+ targetField: 'dependencies'
51
+ }, {
52
+ name: 'bar',
53
+ currentRange: '1.0.0',
54
+ latestRange: '1.1.0',
55
+ source: 'variants',
56
+ variantPattern: '{comp2}',
57
+ targetField: 'peerDependencies'
58
+ }]); // @ts-ignore
59
+
60
+ expect(choices).toMatchSnapshot();
61
+ });
62
+ });
63
+
64
+ //# sourceMappingURL=pick-outdated-pkgs.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["pick-outdated-pkgs.spec.ts"],"names":["describe","it","choices","name","currentRange","latestRange","source","targetField","expect","toMatchSnapshot","componentId","variantPattern"],"mappings":";;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEAA,QAAQ,CAAC,wBAAD,EAA2B,MAAM;AACvCC,EAAAA,EAAE,CAAC,wCAAD,EAA2C,MAAM;AACjD,UAAMC,OAAO,GAAG,gDAAuB,CACrC;AACEC,MAAAA,IAAI,EAAE,KADR;AAEEC,MAAAA,YAAY,EAAE,OAFhB;AAGEC,MAAAA,WAAW,EAAE,OAHf;AAIEC,MAAAA,MAAM,EAAE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CAAgBO,eAAhB;AACD,GArBC,CAAF;AAsBD,CAzDO,CAAR","sourcesContent":["import { makeOutdatedPkgChoices } from './pick-outdated-pkgs';\n\ndescribe('makeOutdatedPkgChoices', () => {\n it('should render choices in correct order', () => {\n const choices = makeOutdatedPkgChoices([\n {\n name: 'zoo',\n currentRange: '1.0.0',\n latestRange: '1.1.0',\n source: 'rootPolicy',\n targetField: 'devDependencies',\n },\n {\n name: 'qar',\n currentRange: '1.0.0',\n latestRange: '1.1.0',\n source: 'rootPolicy',\n targetField: 'dependencies',\n },\n {\n name: 'foo',\n currentRange: '1.0.0',\n latestRange: '2.0.0',\n source: 'rootPolicy',\n targetField: 'dependencies',\n },\n {\n name: 'bar',\n currentRange: '1.0.0',\n latestRange: '1.1.0',\n source: 'rootPolicy',\n targetField: 'peerDependencies',\n },\n ]);\n // @ts-ignore\n expect(choices).toMatchSnapshot();\n });\n it('should render choices with context information', () => {\n const choices = makeOutdatedPkgChoices([\n {\n name: 'foo',\n currentRange: '1.0.0',\n latestRange: '2.0.0',\n source: 'component',\n componentId: 'comp1',\n targetField: 'dependencies',\n },\n {\n name: 'bar',\n currentRange: '1.0.0',\n latestRange: '1.1.0',\n source: 'variants',\n variantPattern: '{comp2}',\n targetField: 'peerDependencies',\n },\n ]);\n // @ts-ignore\n expect(choices).toMatchSnapshot();\n });\n});\n"]}
@@ -0,0 +1,24 @@
1
+ import { Command, CommandOptions } from '@teambit/cli';
2
+ import { Workspace } from './workspace';
3
+ declare type UpdateCmdOptions = {
4
+ yes?: boolean;
5
+ };
6
+ export default class UpdateCmd implements Command {
7
+ /**
8
+ * workspace extension.
9
+ */
10
+ private workspace;
11
+ name: string;
12
+ description: string;
13
+ alias: string;
14
+ group: string;
15
+ shortDescription: string;
16
+ options: CommandOptions;
17
+ constructor(
18
+ /**
19
+ * workspace extension.
20
+ */
21
+ workspace: Workspace);
22
+ report(args: [string[]], options: UpdateCmdOptions): Promise<string>;
23
+ }
24
+ export {};
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ require("core-js/modules/es.promise.js");
6
+
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ exports.default = void 0;
11
+
12
+ function _defineProperty2() {
13
+ const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
14
+
15
+ _defineProperty2 = function () {
16
+ return data;
17
+ };
18
+
19
+ return data;
20
+ }
21
+
22
+ class UpdateCmd {
23
+ constructor(
24
+ /**
25
+ * workspace extension.
26
+ */
27
+ workspace) {
28
+ this.workspace = workspace;
29
+ (0, _defineProperty2().default)(this, "name", 'update');
30
+ (0, _defineProperty2().default)(this, "description", 'update dependencies');
31
+ (0, _defineProperty2().default)(this, "alias", 'up');
32
+ (0, _defineProperty2().default)(this, "group", 'development');
33
+ (0, _defineProperty2().default)(this, "shortDescription", '');
34
+ (0, _defineProperty2().default)(this, "options", [['y', 'yes', 'automatically update all outdated packages']]);
35
+ }
36
+
37
+ async report(args, options) {
38
+ await this.workspace.updateDependencies({
39
+ all: options.yes === true
40
+ });
41
+ return '';
42
+ }
43
+
44
+ }
45
+
46
+ exports.default = UpdateCmd;
47
+
48
+ //# sourceMappingURL=update.cmd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["update.cmd.tsx"],"names":["UpdateCmd","constructor","workspace","report","args","options","updateDependencies","all","yes"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAQe,MAAMA,SAAN,CAAmC;AAQhDC,EAAAA,WAAW;AACT;AACJ;AACA;AACYC,EAAAA,SAJC,EAKT;AAAA,SADQA,SACR,GADQA,SACR;AAAA,kDAZK,QAYL;AAAA,yDAXY,qBAWZ;AAAA,mDAVM,IAUN;AAAA,mDATM,aASN;AAAA,8DARiB,EAQjB;AAAA,qDAPQ,CAAC,CAAC,GAAD,EAAM,KAAN,EAAa,4CAAb,CAAD,CAOR;AAAE;;AAEQ,QAANC,MAAM,CAACC,IAAD,EAAmBC,OAAnB,EAA8C;AACxD,UAAM,KAAKH,SAAL,CAAeI,kBAAf,CAAkC;AACtCC,MAAAA,GAAG,EAAEF,OAAO,CAACG,GAAR,KAAgB;AADiB,KAAlC,CAAN;AAGA,WAAO,EAAP;AACD;;AApB+C","sourcesContent":["import { Command, CommandOptions } from '@teambit/cli';\n\nimport { Workspace } from './workspace';\n\ntype UpdateCmdOptions = {\n yes?: boolean;\n};\n\nexport default class UpdateCmd implements Command {\n name = 'update';\n description = 'update dependencies';\n alias = 'up';\n group = 'development';\n shortDescription = '';\n options = [['y', 'yes', 'automatically update all outdated packages']] as CommandOptions;\n\n constructor(\n /**\n * workspace extension.\n */\n private workspace: Workspace\n ) {}\n\n async report(args: [string[]], options: UpdateCmdOptions) {\n await this.workspace.updateDependencies({\n all: options.yes === true,\n });\n return '';\n }\n}\n"]}
@@ -53,6 +53,7 @@ export declare type WorkspaceInstallOptions = {
53
53
  updateExisting: boolean;
54
54
  savePrefix?: string;
55
55
  };
56
+ export declare type ModulesInstallOptions = Omit<WorkspaceInstallOptions, 'updateExisting' | 'lifecycleType' | 'import'>;
56
57
  export declare type WorkspaceLinkOptions = LinkingOptions;
57
58
  export declare type TrackData = {
58
59
  rootDir: PathOsBasedRelative;
@@ -384,6 +385,19 @@ export declare class Workspace implements ComponentFactory {
384
385
  * @memberof Workspace
385
386
  */
386
387
  install(packages?: string[], options?: WorkspaceInstallOptions): Promise<ComponentMap<string>>;
388
+ private _getComponentsWithDependencyPolicies;
389
+ /**
390
+ * Updates out-of-date dependencies in the workspace.
391
+ *
392
+ * @param options.all {Boolean} updates all outdated dependencies without showing a prompt.
393
+ */
394
+ updateDependencies(options: {
395
+ all: boolean;
396
+ }): Promise<ComponentMap<string>>;
397
+ private _variantPatternsToDepPolicesDict;
398
+ private _updateVariantsPolicies;
399
+ private _saveManyComponentConfigFiles;
400
+ private _installModules;
387
401
  link(options?: WorkspaceLinkOptions): Promise<LinkResults>;
388
402
  /**
389
403
  * Generate a filter to pass to the installer
package/dist/workspace.js CHANGED
@@ -359,6 +359,16 @@ function _exceptions3() {
359
359
  return data;
360
360
  }
361
361
 
362
+ function _pickOutdatedPkgs() {
363
+ const data = require("./pick-outdated-pkgs");
364
+
365
+ _pickOutdatedPkgs = function () {
366
+ return data;
367
+ };
368
+
369
+ return data;
370
+ }
371
+
362
372
  function _watcher() {
363
373
  const data = require("./watch/watcher");
364
374
 
@@ -1600,8 +1610,6 @@ class Workspace {
1600
1610
 
1601
1611
 
1602
1612
  async install(packages, options) {
1603
- var _options$copyPeerToRu, _options$copyPeerToRu2;
1604
-
1605
1613
  if (packages && packages.length) {
1606
1614
  if (!(options !== null && options !== void 0 && options.variants) && (options === null || options === void 0 ? void 0 : options.lifecycleType) === 'dev') {
1607
1615
  throw new (_exceptions3().DependencyTypeNotSupportedInPolicy)(options === null || options === void 0 ? void 0 : options.lifecycleType);
@@ -1645,6 +1653,113 @@ class Workspace {
1645
1653
  this.logger.consoleSuccess();
1646
1654
  }
1647
1655
 
1656
+ return this._installModules(options);
1657
+ }
1658
+
1659
+ async _getComponentsWithDependencyPolicies() {
1660
+ const allComponentIds = await this.listIds();
1661
+ const componentConfigFiles = {};
1662
+ const componentPoliciesById = {};
1663
+ (await Promise.all(allComponentIds.map(componentId => this.componentConfigFile(componentId)))).forEach((componentConfigFile, index) => {
1664
+ if (!componentConfigFile) return;
1665
+ const depResolverConfig = componentConfigFile.aspects.get(_dependencyResolver().DependencyResolverAspect.id);
1666
+ if (!depResolverConfig) return;
1667
+ const componentId = allComponentIds[index].toString();
1668
+ componentConfigFiles[componentId] = componentConfigFile;
1669
+ componentPoliciesById[componentId] = depResolverConfig.config.policy;
1670
+ });
1671
+ return {
1672
+ componentConfigFiles,
1673
+ componentPoliciesById
1674
+ };
1675
+ }
1676
+ /**
1677
+ * Updates out-of-date dependencies in the workspace.
1678
+ *
1679
+ * @param options.all {Boolean} updates all outdated dependencies without showing a prompt.
1680
+ */
1681
+
1682
+
1683
+ async updateDependencies(options) {
1684
+ const {
1685
+ componentConfigFiles,
1686
+ componentPoliciesById
1687
+ } = await this._getComponentsWithDependencyPolicies();
1688
+ const variantPatterns = this.variants.raw();
1689
+
1690
+ const variantPoliciesByPatterns = this._variantPatternsToDepPolicesDict(variantPatterns);
1691
+
1692
+ const outdatedPkgs = await this.dependencyResolver.getOutdatedPkgsFromPolicies({
1693
+ rootDir: this.path,
1694
+ variantPoliciesByPatterns,
1695
+ componentPoliciesById
1696
+ });
1697
+ let outdatedPkgsToUpdate;
1698
+
1699
+ if (options.all) {
1700
+ outdatedPkgsToUpdate = outdatedPkgs;
1701
+ } else {
1702
+ this.logger.off();
1703
+ outdatedPkgsToUpdate = await (0, _pickOutdatedPkgs().pickOutdatedPkgs)(outdatedPkgs);
1704
+ this.logger.on();
1705
+ }
1706
+
1707
+ const {
1708
+ updatedVariants,
1709
+ updatedComponents
1710
+ } = this.dependencyResolver.applyUpdates(outdatedPkgsToUpdate, {
1711
+ variantPoliciesByPatterns,
1712
+ componentPoliciesById
1713
+ });
1714
+ await this._updateVariantsPolicies(variantPatterns, updatedVariants);
1715
+ const updatedComponentConfigFiles = Object.values((0, _lodash().pick)(componentConfigFiles, updatedComponents));
1716
+ await this._saveManyComponentConfigFiles(updatedComponentConfigFiles);
1717
+ await this._reloadConsumer();
1718
+ return this._installModules({
1719
+ dedupe: true
1720
+ });
1721
+ }
1722
+
1723
+ _variantPatternsToDepPolicesDict(variantPatterns) {
1724
+ const variantPoliciesByPatterns = {};
1725
+
1726
+ for (const [variantPattern, extensions] of Object.entries(variantPatterns)) {
1727
+ var _extensions$Dependenc;
1728
+
1729
+ if ((_extensions$Dependenc = extensions[_dependencyResolver().DependencyResolverAspect.id]) !== null && _extensions$Dependenc !== void 0 && _extensions$Dependenc.policy) {
1730
+ var _extensions$Dependenc2;
1731
+
1732
+ variantPoliciesByPatterns[variantPattern] = (_extensions$Dependenc2 = extensions[_dependencyResolver().DependencyResolverAspect.id]) === null || _extensions$Dependenc2 === void 0 ? void 0 : _extensions$Dependenc2.policy;
1733
+ }
1734
+ }
1735
+
1736
+ return variantPoliciesByPatterns;
1737
+ }
1738
+
1739
+ _updateVariantsPolicies(variantPatterns, updateVariantPolicies) {
1740
+ for (const variantPattern of updateVariantPolicies) {
1741
+ this.variants.setExtension(variantPattern, _dependencyResolver().DependencyResolverAspect.id, variantPatterns[variantPattern][_dependencyResolver().DependencyResolverAspect.id], {
1742
+ overrideExisting: true
1743
+ });
1744
+ }
1745
+
1746
+ return this.dependencyResolver.persistConfig(this.path);
1747
+ }
1748
+
1749
+ async _saveManyComponentConfigFiles(componentConfigFiles) {
1750
+ await Promise.all(Array.from(componentConfigFiles).map(async componentConfigFile => {
1751
+ const componentDir = this.componentDir(componentConfigFile.componentId, {
1752
+ ignoreVersion: true
1753
+ });
1754
+ await componentConfigFile.write(componentDir, {
1755
+ override: true
1756
+ });
1757
+ }));
1758
+ }
1759
+
1760
+ async _installModules(options) {
1761
+ var _options$copyPeerToRu, _options$copyPeerToRu2;
1762
+
1648
1763
  this.logger.console(`installing dependencies in workspace using ${_chalk().default.cyan(this.dependencyResolver.getPackageManagerName())}`);
1649
1764
  this.logger.debug(`installing dependencies in workspace with options`, options);
1650
1765
  this.clearCache(); // TODO: pass get install options