How to use the @ts-morph/common.FileUtils.getDirPath function in @ts-morph/common

To help you get started, we’ve selected a few @ts-morph/common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dsherret / ts-morph / packages / ts-morph / src / factories / DirectoryCache.ts View on Github external
addDirectory(directory: Directory) {
        const path = directory.getPath();
        const parentDirPath = FileUtils.getDirPath(path);
        const isRootDir = parentDirPath === path;

        // remove any orphans that have a loaded parent
        for (const orphanDir of this.orphanDirs.getValues()) {
            const orphanDirPath = orphanDir.getPath();
            const orphanDirParentPath = FileUtils.getDirPath(orphanDirPath);
            const isOrphanRootDir = orphanDirParentPath === orphanDirPath;
            if (!isOrphanRootDir && orphanDirParentPath === path)
                this.orphanDirs.removeByKey(orphanDirPath);
        }

        if (!isRootDir)
            this.addToDirectoriesByDirPath(directory);

        if (!this.has(parentDirPath))
            this.orphanDirs.set(path, directory);
github dsherret / ts-morph / packages / ts-morph / src / factories / DirectoryCache.ts View on Github external
addDirectory(directory: Directory) {
        const path = directory.getPath();
        const parentDirPath = FileUtils.getDirPath(path);
        const isRootDir = parentDirPath === path;

        // remove any orphans that have a loaded parent
        for (const orphanDir of this.orphanDirs.getValues()) {
            const orphanDirPath = orphanDir.getPath();
            const orphanDirParentPath = FileUtils.getDirPath(orphanDirPath);
            const isOrphanRootDir = orphanDirParentPath === orphanDirPath;
            if (!isOrphanRootDir && orphanDirParentPath === path)
                this.orphanDirs.removeByKey(orphanDirPath);
        }

        if (!isRootDir)
            this.addToDirectoriesByDirPath(directory);

        if (!this.has(parentDirPath))
            this.orphanDirs.set(path, directory);

        this.directoriesByPath.set(path, directory);
        if (!this.context.fileSystemWrapper.directoryExistsSync(path))
            this.context.fileSystemWrapper.queueMkdir(path);

        for (const orphanDir of this.orphanDirs.getValues()) {
github dsherret / ts-morph / packages / ts-morph / src / factories / DirectoryCache.ts View on Github external
private removeFromDirectoriesByDirPath(dirPath: string) {
        if (FileUtils.isRootDirPath(dirPath))
            return;
        const parentDirPath = FileUtils.getDirPath(dirPath);
        const directories = this.directoriesByDirPath.get(parentDirPath);
        if (directories == null)
            return;
        directories.removeByKey(FileUtils.getBaseName(dirPath));

        // clean up
        if (!directories.hasItems())
            this.directoriesByDirPath.removeByKey(parentDirPath);
    }
github dsherret / ts-morph / packages / ts-morph / src / factories / DirectoryCache.ts View on Github external
private addToDirectoriesByDirPath(directory: Directory) {
        if (FileUtils.isRootDirPath(directory.getPath()))
            return;
        const parentDirPath = FileUtils.getDirPath(directory.getPath());
        const directories = this.directoriesByDirPath.getOrCreate(parentDirPath,
            () => new SortedKeyValueArray(item => item.getBaseName(), LocaleStringComparer.instance));
        directories.set(directory);
    }
github dsherret / ts-morph / packages / ts-morph / src / factories / InProjectCoordinator.ts View on Github external
function* getAncestorsUpToOneInProject(dir: Directory): IterableIterator {
            if (FileUtils.isRootDirPath(dir.getPath()))
                return;
            const parentDirPath = FileUtils.getDirPath(dir.getPath());
            const parentDir = compilerFactory.getDirectoryFromCacheOnlyIfInCache(parentDirPath);
            if (parentDir == null)
                return;

            yield parentDir;

            if (!inProjectCoordinator.isDirectoryInProject(parentDir))
                yield* getAncestorsUpToOneInProject(parentDir);
        }
    }
github dsherret / ts-morph / packages / ts-morph / src / factories / DirectoryCache.ts View on Github external
private fillParentsOfDirPath(dirPath: string) {
        const passedDirPaths: string[] = [];
        let parentDir = FileUtils.getDirPath(dirPath);
        while (dirPath !== parentDir) {
            dirPath = parentDir;
            parentDir = FileUtils.getDirPath(dirPath);
            if (this.directoriesByPath.has(dirPath)) {
                for (const currentDirPath of passedDirPaths)
                    this.createDirectory(currentDirPath);
                break;
            }

            passedDirPaths.unshift(dirPath);
        }
    }
}