UNPKG

@ts-dev-tools/core

Version:
46 lines (45 loc) 2.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createTestPackagesDir = createTestPackagesDir; const node_fs_1 = require("node:fs"); const node_path_1 = require("node:path"); const PackageJson_1 = require("../services/PackageJson"); const PluginService_1 = require("../services/PluginService"); const cli_1 = require("./cli"); const file_system_1 = require("./file-system"); const test_project_1 = require("./test-project"); async function createTestPackagesProject(projectDir) { const originalPackagesPath = (0, node_path_1.resolve)(__dirname, "../../.."); const projectDirPackages = (0, node_path_1.resolve)(projectDir, "packages"); await (0, file_system_1.copyFolder)(originalPackagesPath, projectDirPackages); const projectDirPackagesFiles = (0, node_fs_1.readdirSync)(projectDirPackages); for (const projectDirPackagesFile of projectDirPackagesFiles) { const packagePath = (0, node_path_1.resolve)(projectDirPackages, projectDirPackagesFile); if (!(0, node_fs_1.lstatSync)(packagePath).isDirectory()) { continue; } const packageJson = PackageJson_1.PackageJson.fromDirPath(packagePath); const content = packageJson.getContent(); if (content.dependencies) { for (const packageName of Object.keys(content.dependencies)) { if (PluginService_1.PluginService.packageNameIsPlugin(packageName)) { const pluginShortName = PluginService_1.PluginService.getPluginShortname(packageName); const dependencyPath = (0, node_path_1.resolve)((0, node_path_1.join)(packagePath, "..", pluginShortName)); content.dependencies[packageName] = `file://${dependencyPath}`; } } packageJson.setContent(content); } await (0, cli_1.safeExec)(packagePath, "npm install"); } } /** * Create a full file structure for testing ts-dev-tools packages installation * This function is not using cache to prevents drift between current code and test code * @param projectDir path where to prepare packages * @returns packages directory path */ async function createTestPackagesDir(filename) { const testPackagesFileName = filename.replace(".spec.ts", `-test-packages.spec.ts`); return (0, test_project_1.createProjectForTestFile)(testPackagesFileName, false, createTestPackagesProject); }