@teambit/install 1.0.384 → 1.0.386

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.
@@ -67,6 +67,7 @@ export declare class InstallMain {
67
67
  private ipcEvents;
68
68
  private harmony;
69
69
  private visitedAspects;
70
+ private oldNonLoadedEnvs;
70
71
  constructor(dependencyResolver: DependencyResolverMain, logger: Logger, workspace: Workspace, variants: VariantsMain, compiler: CompilerMain, envs: EnvsMain, wsConfigFiles: WorkspaceConfigFilesMain, aspectLoader: AspectLoaderMain, app: ApplicationMain, generator: GeneratorMain, preLinkSlot: PreLinkSlot, preInstallSlot: PreInstallSlot, postInstallSlot: PostInstallSlot, ipcEvents: IpcEventsMain, harmony: Harmony);
71
72
  /**
72
73
  * Install dependencies for all components in the workspace
@@ -110,6 +111,9 @@ export declare class InstallMain {
110
111
  * @returns
111
112
  */
112
113
  private reloadMovedEnvs;
114
+ private reloadNonLoadedEnvs;
115
+ private reloadEnvs;
116
+ private reloadAspects;
113
117
  private _getComponentsManifestsAndRootPolicy;
114
118
  /**
115
119
  * The function `tryWriteConfigFiles` attempts to write workspace config files, and if it fails, it logs an error
@@ -125,6 +129,7 @@ export declare class InstallMain {
125
129
  private _getMissingPackagesWithoutRootDeps;
126
130
  private _getAllMissingPackages;
127
131
  private _getComponentsManifests;
132
+ setOldNonLoadedEnvs(): string[];
128
133
  /**
129
134
  * This function returns a list of old non-loaded environments names.
130
135
  * @returns an array of strings called `oldNonLoadedEnvs`. This array contains the names of environment variables that
@@ -186,6 +186,13 @@ function _componentPackageVersion() {
186
186
  };
187
187
  return data;
188
188
  }
189
+ function _aspectLoader() {
190
+ const data = require("@teambit/aspect-loader");
191
+ _aspectLoader = function () {
192
+ return data;
193
+ };
194
+ return data;
195
+ }
189
196
  function _objectHash() {
190
197
  const data = _interopRequireDefault(require("object-hash"));
191
198
  _objectHash = function () {
@@ -242,13 +249,6 @@ function _update() {
242
249
  };
243
250
  return data;
244
251
  }
245
- function _aspectLoader() {
246
- const data = require("@teambit/aspect-loader");
247
- _aspectLoader = function () {
248
- return data;
249
- };
250
- return data;
251
- }
252
252
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
253
253
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
254
254
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -275,6 +275,7 @@ class InstallMain {
275
275
  this.ipcEvents = ipcEvents;
276
276
  this.harmony = harmony;
277
277
  _defineProperty(this, "visitedAspects", new Set());
278
+ _defineProperty(this, "oldNonLoadedEnvs", []);
278
279
  }
279
280
  /**
280
281
  * Install dependencies for all components in the workspace
@@ -476,7 +477,9 @@ class InstallMain {
476
477
  }, pmInstallOptions);
477
478
  let cacheCleared = false;
478
479
  await this.linkCodemods(compDirMap);
480
+ const oldNonLoadedEnvs = this.setOldNonLoadedEnvs();
479
481
  await this.reloadMovedEnvs();
482
+ await this.reloadNonLoadedEnvs();
480
483
  const shouldClearCacheOnInstall = this.shouldClearCacheOnInstall();
481
484
  if (options?.compile ?? true) {
482
485
  const compileStartTime = process.hrtime();
@@ -486,9 +489,8 @@ class InstallMain {
486
489
  // We need to clear cache before compiling the components or it might compile them with the default env
487
490
  // incorrectly in case the env was not loaded correctly before the installation.
488
491
  // We don't want to clear the failed to load envs because we want to show the warning at the end
489
- await this.workspace.clearCache({
490
- skipClearFailedToLoadEnvs: true
491
- });
492
+ // await this.workspace.clearCache({ skipClearFailedToLoadEnvs: true });
493
+ await this.workspace.clearCache();
492
494
  cacheCleared = true;
493
495
  }
494
496
  await this.compiler.compileOnWorkspace([], {
@@ -507,7 +509,6 @@ class InstallMain {
507
509
  }
508
510
  if (!dependenciesChanged) break;
509
511
  if (!options?.recurringInstall) break;
510
- const oldNonLoadedEnvs = this.getOldNonLoadedEnvs();
511
512
  if (!oldNonLoadedEnvs.length) break;
512
513
  prevManifests.add(manifestsHash(current.manifests));
513
514
  // If we run compile we do the clear cache before the compilation so no need to clean it again (it's an expensive
@@ -577,10 +578,16 @@ class InstallMain {
577
578
  return !regularPathExists || !resolvedPathExists;
578
579
  });
579
580
  const idsToLoad = movedEnvs.map(env => env.id);
580
- // const envPlugin = this.envs.getEnvPlugin();
581
-
582
- if (idsToLoad.length && this.workspace) {
583
- const componentIdsToLoad = idsToLoad.map(id => _component().ComponentID.fromString(id));
581
+ const componentIdsToLoad = idsToLoad.map(id => _component().ComponentID.fromString(id));
582
+ await this.reloadEnvs(componentIdsToLoad);
583
+ }
584
+ async reloadNonLoadedEnvs() {
585
+ const nonLoadedEnvs = this.envs.getFailedToLoadEnvs();
586
+ const componentIdsToLoad = nonLoadedEnvs.map(id => _component().ComponentID.fromString(id));
587
+ await this.reloadEnvs(componentIdsToLoad);
588
+ }
589
+ async reloadEnvs(componentIdsToLoad) {
590
+ if (componentIdsToLoad.length && this.workspace) {
584
591
  const aspects = await this.workspace.resolveAspects(undefined, componentIdsToLoad, {
585
592
  requestedOnly: true,
586
593
  excludeCore: true,
@@ -590,21 +597,34 @@ class InstallMain {
590
597
  // This is a bug in the flow and should be fixed.
591
598
  // skipDeps: true,
592
599
  });
593
- const loadedPlugins = (0, _lodash().compact)(await Promise.all(aspects.map(aspectDef => {
594
- const localPath = aspectDef.aspectPath;
595
- const component = aspectDef.component;
596
- if (!component) return undefined;
597
- const plugins = this.aspectLoader.getPlugins(component, localPath);
598
- if (plugins.has()) {
599
- return plugins.load(_cli().MainRuntime.name);
600
- }
601
- })));
602
- await Promise.all(loadedPlugins.map(plugin => {
603
- const runtime = plugin.getRuntime(_cli().MainRuntime);
604
- return runtime?.provider(undefined, undefined, undefined, this.harmony);
600
+ // This is a very special case which we need to compile our envs before loading them correctly.
601
+ const grouped = (0, _lodash().groupBy)(aspects, aspectDef => {
602
+ return aspectDef.component?.id.toStringWithoutVersion() === 'bitdev.general/envs/bit-env';
603
+ });
604
+ await this.reloadAspects(grouped.true || []);
605
+ const otherEnvs = grouped.false || [];
606
+ await Promise.all(otherEnvs.map(async aspectDef => {
607
+ const id = aspectDef.component?.id;
608
+ if (!id) return;
609
+ await this.workspace.clearComponentCache(id);
605
610
  }));
611
+ await this.reloadAspects(grouped.false || []);
606
612
  }
607
- return movedEnvs;
613
+ }
614
+ async reloadAspects(aspects) {
615
+ const loadedPlugins = (0, _lodash().compact)(await Promise.all(aspects.map(aspectDef => {
616
+ const localPath = aspectDef.aspectPath;
617
+ const component = aspectDef.component;
618
+ if (!component) return undefined;
619
+ const plugins = this.aspectLoader.getPlugins(component, localPath);
620
+ if (plugins.has()) {
621
+ return plugins.load(_cli().MainRuntime.name);
622
+ }
623
+ })));
624
+ await Promise.all(loadedPlugins.map(plugin => {
625
+ const runtime = plugin.getRuntime(_cli().MainRuntime);
626
+ return runtime?.provider(undefined, undefined, undefined, this.harmony);
627
+ }));
608
628
  }
609
629
  async _getComponentsManifestsAndRootPolicy(installer, options) {
610
630
  const mergedRootPolicy = await this.addConfiguredAspectsToWorkspacePolicy();
@@ -755,6 +775,13 @@ class InstallMain {
755
775
  manifests
756
776
  };
757
777
  }
778
+ setOldNonLoadedEnvs() {
779
+ const nonLoadedEnvs = this.envs.getFailedToLoadEnvs();
780
+ const envsWithoutManifest = Array.from(this.dependencyResolver.envsWithoutManifest);
781
+ const oldNonLoadedEnvs = (0, _lodash().intersection)(nonLoadedEnvs, envsWithoutManifest);
782
+ this.oldNonLoadedEnvs = oldNonLoadedEnvs;
783
+ return oldNonLoadedEnvs;
784
+ }
758
785
 
759
786
  /**
760
787
  * This function returns a list of old non-loaded environments names.
@@ -764,10 +791,7 @@ class InstallMain {
764
791
  * correctly
765
792
  */
766
793
  getOldNonLoadedEnvs() {
767
- const nonLoadedEnvs = this.envs.getFailedToLoadEnvs();
768
- const envsWithoutManifest = Array.from(this.dependencyResolver.envsWithoutManifest);
769
- const oldNonLoadedEnvs = (0, _lodash().intersection)(nonLoadedEnvs, envsWithoutManifest);
770
- return oldNonLoadedEnvs;
794
+ return this.oldNonLoadedEnvs;
771
795
  }
772
796
  async _updateRootDirs(rootDirs) {
773
797
  try {