UNPKG

@teambit/isolator

Version:
61 lines (59 loc) 2.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.symlinkDependenciesToCapsules = symlinkDependenciesToCapsules; exports.symlinkOnCapsuleRoot = symlinkOnCapsuleRoot; function _pkgModules() { const data = require("@teambit/pkg.modules.component-package-name"); _pkgModules = function () { return data; }; return data; } function _path() { const data = _interopRequireDefault(require("path")); _path = function () { return data; }; return data; } function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } async function symlinkDependenciesToCapsules(capsules, capsuleList, logger) { logger.debug(`symlinkDependenciesToCapsules, ${capsules.length} capsules`); return Object.fromEntries(await Promise.all(capsules.map(capsule => { return symlinkComponent(capsule.component.state._consumer, capsuleList, logger); }))); } async function symlinkOnCapsuleRoot(capsuleList, logger, capsuleRoot) { const modulesPath = _path().default.join(capsuleRoot, 'node_modules'); return capsuleList.map(capsule => { const packageName = (0, _pkgModules().componentIdToPackageName)(capsule.component.state._consumer); const dest = _path().default.join(modulesPath, packageName); return { from: capsule.path, to: dest, packageName }; }); } async function symlinkComponent(component, capsuleList, logger) { const componentCapsule = capsuleList.getCapsuleIgnoreVersion(component.id); if (!componentCapsule) throw new Error(`unable to find the capsule for ${component.id.toString()}`); const allDeps = component.getAllDependenciesIds(); const linkResults = allDeps.reduce((acc, depId) => { // TODO: this is dangerous - we might have 2 capsules for the same component with different version, then we might link to the wrong place const devCapsule = capsuleList.getCapsuleIgnoreVersion(depId); if (!devCapsule) { // happens when a dependency is not in the workspace. (it gets installed via the package manager) logger.debug(`symlinkComponentToCapsule: unable to find the capsule for ${depId.toStringWithoutVersion()}. skipping`); return acc; } const packageName = (0, _pkgModules().componentIdToPackageName)(devCapsule.component.state._consumer); const devCapsulePath = devCapsule.path; acc[packageName] = `link:${devCapsulePath}`; return acc; }, {}); return [componentCapsule.path, linkResults]; } //# sourceMappingURL=symlink-dependencies-to-capsules.js.map