Skip to content

Without --delete, if barrel file already exists, then it doesn't work properly #153

Description

@vjpr

Using:

barrelsby -sqSD -d ./src"

if barrel doesn't exist:

export * from './modules/chrome/chrome.model'
export * from './modules/chrome/chrome.resolver'
export * from './modules/chrome/chrome.service'
export * from './modules/chrome/test'
export * from './modules/user/user.resolver'
export * from './modules/user/user.service'

if barrel already exists:

export * from './index'

The error is here:

// Get any typescript modules contained at any depth in the current directory.
function getModules(directory, logger, local) {
    logger(`Getting modules @ ${directory.path}`);
    if (directory.barrel) {
        // If theres a barrel then use that as it *should* contain descendant modules.
        logger(`Found existing barrel @ ${directory.barrel.path}`);
        return [directory.barrel]; <------------------------------------
    }
    const files = [].concat(directory.files);
    if (!local) {
        directory.directories.forEach((childDirectory) => {
            // Recurse.
            files.push(...getModules(childDirectory, logger, local));
        });
    }
    // Only return files that look like TypeScript modules.
    return files.filter((file) => file.name.match(utilities_1.isTypeScriptFile));
}

What is the purpose of returning early?

// If theres a barrel then use that as it should contain descendant modules.

Why should we assume it contains descendent modules...what if someone has added one?

directory.barrel only contains {name, path} of the a barrel file. Is this some sort of regression? I can't figure it out.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions