@teambit/dependency-resolver 1.0.338 → 1.0.339

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.
@@ -221,7 +221,12 @@ export declare class DependencyResolverMain {
221
221
  getPackageName(component: Component): string;
222
222
  getDepResolverData(component: Component): DependencyResolverComponentData | undefined;
223
223
  calcPackageName(component: Component): string;
224
- getRuntimeModulePath(component: Component, isInWorkspace?: boolean): string;
224
+ getRuntimeModulePathInWorkspace(component: Component, opts: {
225
+ workspacePath: string;
226
+ rootComponentsPath: string;
227
+ }): string;
228
+ getRuntimeModulePathInCapsules(component: Component): string;
229
+ _getRuntimeModulePath(component: Component, rootComponentsRelativePath?: string): string;
225
230
  /**
226
231
  * returns the package path in the /node_modules/ folder
227
232
  * In case you call this in order to run the code from the path, please refer to the `getRuntimeModulePath` API
@@ -44,9 +44,9 @@ function _bit() {
44
44
  };
45
45
  return data;
46
46
  }
47
- function _bitRoots() {
48
- const data = require("@teambit/bit-roots");
49
- _bitRoots = function () {
47
+ function _workspace() {
48
+ const data = require("@teambit/workspace.root-components");
49
+ _workspace = function () {
50
50
  return data;
51
51
  };
52
52
  return data;
@@ -632,17 +632,35 @@ class DependencyResolverMain {
632
632
  return (0, _pkgModules().componentIdToPackageName)(component.state._consumer);
633
633
  }
634
634
 
635
+ /*
636
+ * Returns the location where the component is installed with its peer dependencies inside a workspace.
637
+ * This is used in cases you want to actually run the components and make sure all the dependencies (especially peers) are resolved correctly
638
+ */
639
+ getRuntimeModulePathInWorkspace(component, opts) {
640
+ const rootComponentsRelativePath = (0, _path().relative)(opts.workspacePath, opts.rootComponentsPath);
641
+ return this._getRuntimeModulePath(component, rootComponentsRelativePath);
642
+ }
643
+
644
+ /*
645
+ * Returns the location where the component is installed with its peer dependencies inside capsules.
646
+ * This is used in cases you want to actually run the components and make sure all the dependencies (especially peers) are resolved correctly
647
+ */
648
+ getRuntimeModulePathInCapsules(component) {
649
+ return this._getRuntimeModulePath(component);
650
+ }
651
+
635
652
  /*
636
653
  * Returns the location where the component is installed with its peer dependencies
637
654
  * This is used in cases you want to actually run the components and make sure all the dependencies (especially peers) are resolved correctly
638
655
  */
639
- getRuntimeModulePath(component, isInWorkspace = false) {
656
+ _getRuntimeModulePath(component, rootComponentsRelativePath) {
640
657
  if (!this.hasRootComponents()) {
641
658
  const modulePath = this.getModulePath(component);
642
659
  return modulePath;
643
660
  }
644
661
  const pkgName = this.getPackageName(component);
645
- const selfRootDir = (0, _bitRoots().getRelativeRootComponentDir)(!isInWorkspace ? component.id.toString() : component.id.toStringWithoutVersion());
662
+ const getRelativeRootComponentDir = _workspace().getRootComponentDir.bind(null, rootComponentsRelativePath ?? '');
663
+ const selfRootDir = getRelativeRootComponentDir(rootComponentsRelativePath == null ? component.id.toString() : component.id.toStringWithoutVersion());
646
664
  // In case the component is it's own root we want to load it from it's own root folder
647
665
  if (_fsExtra().default.pathExistsSync(selfRootDir)) {
648
666
  const innerDir = (0, _path().join)(selfRootDir, 'node_modules', pkgName);
@@ -652,7 +670,7 @@ class DependencyResolverMain {
652
670
  return this.getModulePath(component);
653
671
  }
654
672
  const envId = this.envs.getEnvId(component);
655
- const dirInEnvRoot = (0, _path().join)((0, _bitRoots().getRelativeRootComponentDir)(envId), 'node_modules', pkgName);
673
+ const dirInEnvRoot = (0, _path().join)(getRelativeRootComponentDir(envId), 'node_modules', pkgName);
656
674
  if (_fsExtra().default.pathExistsSync(dirInEnvRoot)) return dirInEnvRoot;
657
675
  return this.getModulePath(component);
658
676
  }