UNPKG

@nxworker/workspace

Version:

Nx plugin providing generators for managing workspace files, including the move-file generator for safely moving files between projects while updating all imports

54 lines (53 loc) 3.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "executeMove", { enumerable: true, get: function() { return executeMove; } }); const _devkit = require("@nx/devkit"); const _updatemovedfileimportsifneeded = require("../import-updates/update-moved-file-imports-if-needed"); const _updatetargetprojectimportsifneeded = require("../import-updates/update-target-project-imports-if-needed"); const _ensureexportifneeded = require("../export-management/ensure-export-if-needed"); const _checkforunexportedrelativedependencies = require("../validation/check-for-unexported-relative-dependencies"); const _createtargetfile = require("./create-target-file"); const _handlemovestrategy = require("./handle-move-strategy"); const _finalizemove = require("./finalize-move"); async function executeMove(tree, options, projects, getProjectGraphAsync, ctx, cachedTreeExists, updateProjectSourceFilesCache, updateFileExistenceCache, getProjectSourceFiles, getCachedDependentProjects, skipFinalization = false) { const { normalizedSource, normalizedTarget, sourceProjectName, targetProjectName, fileContent, sourceImportPath } = ctx; _devkit.logger.verbose(`Moving ${normalizedSource} (project: ${sourceProjectName}) to ${normalizedTarget} (project: ${targetProjectName})`); (0, _createtargetfile.createTargetFile)(tree, normalizedTarget, fileContent, updateFileExistenceCache); // Check for unexported relative dependencies when moving to a different project if (!ctx.isSameProject) { const unexportedDeps = (0, _checkforunexportedrelativedependencies.checkForUnexportedRelativeDependencies)(tree, normalizedSource, ctx.sourceProject, cachedTreeExists); if (unexportedDeps.length > 0) { _devkit.logger.warn(`File "${normalizedSource}" has ${unexportedDeps.length} relative ${unexportedDeps.length === 1 ? 'dependency' : 'dependencies'} that ${unexportedDeps.length === 1 ? 'is' : 'are'} not exported from project "${sourceProjectName}":`); for (const dep of unexportedDeps){ _devkit.logger.warn(` - ${dep.specifier} (${dep.relativePathInProject})`); } _devkit.logger.warn(`After the move, imports to these dependencies will be updated to use the project alias/path, ` + `but they are not exported from "${sourceProjectName}". ` + `Consider exporting these files from the project's entry point or moving them together.`); } } // Update cache incrementally for projects that will be modified // This is more efficient than invalidating and re-scanning the entire project const sourceProject = projects.get(sourceProjectName); const targetProject = projects.get(targetProjectName); if (sourceProject) { updateProjectSourceFilesCache(sourceProject.root, normalizedSource, targetProjectName === sourceProjectName ? normalizedTarget : null); } if (targetProject && targetProject.root !== sourceProject?.root) { updateProjectSourceFilesCache(targetProject.root, '', normalizedTarget); } (0, _updatemovedfileimportsifneeded.updateMovedFileImportsIfNeeded)(tree, ctx, cachedTreeExists); await (0, _handlemovestrategy.handleMoveStrategy)(tree, getProjectGraphAsync, projects, ctx, getCachedDependentProjects, getProjectSourceFiles, cachedTreeExists); const sourceIdentifier = sourceImportPath || normalizedSource; (0, _updatetargetprojectimportsifneeded.updateTargetProjectImportsIfNeeded)(tree, ctx, sourceIdentifier, getProjectSourceFiles); (0, _ensureexportifneeded.ensureExportIfNeeded)(tree, ctx, options, cachedTreeExists); if (!skipFinalization) { await (0, _finalizemove.finalizeMove)(tree, normalizedSource, options); } } //# sourceMappingURL=execute-move.js.map