@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
74 lines (73 loc) • 2.52 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
clearCompilerPathsCache: function() {
return clearCompilerPathsCache;
},
readCompilerPaths: function() {
return readCompilerPaths;
}
});
const _devkit = require("@nx/devkit");
const _treecache = require("../tree-cache");
/**
* Reads the TypeScript compiler path mappings from tsconfig files at the workspace root.
* Tries tsconfig.base.json, tsconfig.json, and any tsconfig.*.json files.
*
* Results are cached to avoid repeated file system operations.
*
* @param tree - The virtual file system tree
* @returns The paths object or null if unavailable
*/ // Cache for TypeScript compiler paths to avoid repeated parsing of tsconfig files
let compilerPathsCache = undefined;
function readCompilerPaths(tree) {
// Return cached value if available
if (compilerPathsCache !== undefined) {
return compilerPathsCache;
}
// Try common tsconfig files in order of preference
const tsconfigFiles = [
'tsconfig.base.json',
'tsconfig.json'
];
// Add any tsconfig.*.json files found at the root
const rootFiles = _treecache.treeReadCache.children(tree, '');
const additionalTsconfigFiles = rootFiles.filter((file)=>file.startsWith('tsconfig.') && file.endsWith('.json')).filter((file)=>!tsconfigFiles.includes(file));
const allTsconfigFiles = [
...tsconfigFiles,
...additionalTsconfigFiles
];
for (const tsconfigPath of allTsconfigFiles){
if (!tree.exists(tsconfigPath)) {
continue;
}
try {
const tsconfigContent = _treecache.treeReadCache.read(tree, tsconfigPath, 'utf-8');
if (!tsconfigContent) {
continue;
}
const tsconfig = JSON.parse(tsconfigContent);
const paths = tsconfig.compilerOptions?.paths;
if (typeof paths === 'object' && paths) {
compilerPathsCache = paths;
return paths;
}
} catch (error) {
_devkit.logger.warn(`Could not parse ${tsconfigPath}: ${error}`);
}
}
compilerPathsCache = null;
return null;
}
function clearCompilerPathsCache() {
compilerPathsCache = undefined;
}
//# sourceMappingURL=read-compiler-paths.js.map