@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
43 lines (42 loc) • 1.88 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "isProjectEmpty", {
enumerable: true,
get: function() {
return isProjectEmpty;
}
});
const _devkit = require("@nx/devkit");
const _nodepath = require("node:path");
const _getprojectentrypointpaths = require("./get-project-entry-point-paths");
const _buildfilenames = require("../path-utils/build-file-names");
const _fileextensions = require("../constants/file-extensions");
const _hassourcefileextension = require("../path-utils/has-source-file-extension");
const primaryEntryFilenames = (0, _buildfilenames.buildFileNames)(_fileextensions.primaryEntryBaseNames);
function isProjectEmpty(tree, project) {
const sourceRoot = project.sourceRoot || project.root;
const indexCandidates = new Set((0, _getprojectentrypointpaths.getProjectEntryPointPaths)(tree, project).map((candidate)=>(0, _devkit.normalizePath)(candidate)));
if (indexCandidates.size === 0) {
indexCandidates.add((0, _devkit.normalizePath)(_nodepath.posix.join(sourceRoot, primaryEntryFilenames[0])));
}
// Don't use cache for isProjectEmpty check as we need the current state
let hasNonIndexSourceFiles = false;
(0, _devkit.visitNotIgnoredFiles)(tree, sourceRoot, (filePath)=>{
if (hasNonIndexSourceFiles) {
return; // Short-circuit if we already found a non-index file
}
const normalizedFilePath = (0, _devkit.normalizePath)(filePath);
const isSourceFile = (0, _hassourcefileextension.hasSourceFileExtension)(normalizedFilePath);
if (!isSourceFile) {
return;
}
if (indexCandidates.has(normalizedFilePath)) {
return;
}
hasNonIndexSourceFiles = true;
});
return !hasNonIndexSourceFiles;
}
//# sourceMappingURL=is-project-empty.js.map