UNPKG

@ts-dev-tools/core

Version:
64 lines (63 loc) 3.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SymlinkDependenciesService = void 0; const node_fs_1 = require("node:fs"); const node_path_1 = require("node:path"); const PackageJson_1 = require("./PackageJson"); const PackageManagerService_1 = require("./PackageManagerService"); const PluginService_1 = require("./PluginService"); class SymlinkDependenciesService { constructor() { } static DEPENDENCIES_FOLDER = "node_modules"; static async executeSymlinking(absoluteProjectDir) { console.info(`Symlinking dev dependencies...`); const installedPlugins = PluginService_1.PluginService.getInstalledPlugins(absoluteProjectDir); for (const plugin of installedPlugins) { await SymlinkDependenciesService.symlinkPluginDependencies(absoluteProjectDir, plugin); } console.info(`Symlinking dev dependencies done!`); } static async symlinkPluginDependencies(absoluteProjectDir, plugin) { const pluginDependencies = SymlinkDependenciesService.getPluginDependencies(plugin); const projectDependencyPath = (0, node_path_1.join)(absoluteProjectDir, SymlinkDependenciesService.DEPENDENCIES_FOLDER); const pluginDependenciesPath = await SymlinkDependenciesService.getPluginDependenciesPath(absoluteProjectDir, plugin, pluginDependencies); if (projectDependencyPath === pluginDependenciesPath) { console.info(`- Skipping symlinking ${plugin.shortname} dependencies, already in node_modules`); return; } for (const pluginDependency of pluginDependencies) { const pluginDependencyPath = (0, node_path_1.join)(pluginDependenciesPath, pluginDependency); if (!(0, node_fs_1.existsSync)(pluginDependencyPath)) { continue; } const projectPluginDependencyPath = (0, node_path_1.join)(projectDependencyPath, pluginDependency); if ((0, node_fs_1.existsSync)(projectPluginDependencyPath)) { continue; } console.info(`- Symlinking ${pluginDependency}`); SymlinkDependenciesService.symlinkDependency(pluginDependencyPath, projectPluginDependencyPath); } } static getPluginDependencies(plugin) { const pluginPackageJson = PackageJson_1.PackageJson.fromDirPath(plugin.path); return pluginPackageJson.getDependenciesPackageNames(); } static async getPluginDependenciesPath(absoluteProjectDir, plugin, pluginDependencies) { const pluginDependenciesPath = (0, node_path_1.join)(plugin.path, SymlinkDependenciesService.DEPENDENCIES_FOLDER); if ((0, node_fs_1.existsSync)(pluginDependenciesPath)) { const hasAnyPluginDependency = pluginDependencies.some((pluginDependency) => (0, node_fs_1.existsSync)((0, node_path_1.join)(pluginDependenciesPath, pluginDependency))); if (hasAnyPluginDependency) { return pluginDependenciesPath; } } return await PackageManagerService_1.PackageManagerService.getNodeModulesPath(absoluteProjectDir); } static symlinkDependency(pluginDependencyPath, projectPluginDependencyPath) { const pluginDependencyParentFolder = (0, node_path_1.join)(projectPluginDependencyPath, ".."); if (!(0, node_fs_1.existsSync)(pluginDependencyParentFolder)) { (0, node_fs_1.mkdirSync)(pluginDependencyParentFolder, { recursive: true }); } (0, node_fs_1.symlinkSync)(pluginDependencyPath, projectPluginDependencyPath); } } exports.SymlinkDependenciesService = SymlinkDependenciesService;