@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
29 lines (28 loc) • 1.36 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "updateImportsToRelative", {
enumerable: true,
get: function() {
return updateImportsToRelative;
}
});
const _nodepath = require("node:path");
const _jscodeshiftutils = require("../jscodeshift-utils");
const _getrelativeimportspecifier = require("../path-utils/get-relative-import-specifier");
function updateImportsToRelative(tree, project, sourceImportPath, targetRelativePath, excludeFilePaths, getProjectSourceFilesFn) {
const excludeSet = new Set(excludeFilePaths);
const sourceFiles = getProjectSourceFilesFn(tree, project.root);
for (const normalizedFilePath of sourceFiles){
if (excludeSet.has(normalizedFilePath)) {
continue;
}
const projectRoot = project.sourceRoot || project.root;
const targetFilePath = _nodepath.posix.join(projectRoot, targetRelativePath);
const relativeSpecifier = (0, _getrelativeimportspecifier.getRelativeImportSpecifier)(normalizedFilePath, targetFilePath);
// Use jscodeshift to update imports from source import path to relative path
(0, _jscodeshiftutils.updateImportSpecifier)(tree, normalizedFilePath, sourceImportPath, relativeSpecifier);
}
}
//# sourceMappingURL=update-imports-to-relative.js.map