@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
34 lines (33 loc) • 1.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "deriveProjectDirectoryFromSource", {
enumerable: true,
get: function() {
return deriveProjectDirectoryFromSource;
}
});
const _nodepath = require("node:path");
function deriveProjectDirectoryFromSource(sourceFilePath, sourceProject) {
const sourceRoot = sourceProject.sourceRoot || sourceProject.root;
const baseDir = sourceProject.projectType === 'application' ? 'app' : 'lib';
// Get the path relative to source root
const relativeToSourceRoot = _nodepath.posix.relative(sourceRoot, sourceFilePath);
// Check if the file is within the base directory (lib or app)
const baseDirPrefix = baseDir + '/';
if (!relativeToSourceRoot.startsWith(baseDirPrefix)) {
// File is not in the expected base directory, return undefined
return undefined;
}
// Remove the base directory prefix
const afterBaseDir = relativeToSourceRoot.substring(baseDirPrefix.length);
// Get the directory part (without the filename)
const dirPath = _nodepath.posix.dirname(afterBaseDir);
// If dirPath is '.' it means the file is directly in the base directory
if (dirPath === '.') {
return undefined;
}
return dirPath;
}
//# sourceMappingURL=derive-project-directory-from-source.js.map