bencoveney / barrelsby

Automatic TypeScript barrels (index.ts files) for your entire code base

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

vjpr opened this issue · comments

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.

No activity has been seen recently, marking as stale. If this is a mistake please reach out to a collaborator

This is a valid issue. Shame there's an inactivity bot closing issues on an apparently-inactive repository. Premature optimization. 😞

@bencoveney

Confirmed this is still an issue...

commented

this is a known issue. a PR is welcome to be submitted and I've been working on a V3 that compiles to ESM compatible version as well. Its been done during my free time between work, travel, and personal responsibilities.

Is there a work around? If I generate all barrels and then on save, have it regenerate this happens to the barrels it already generated

commented

@nrgapple The workaround currently is to make sure you have the --delete flag on your automation commands

@nrgapple The workaround currently is to make sure you have the --delete flag on your automation commands

I've tried both with --delete flag in the command and "delete": true in the JSON settings file and neither helped. It turns valid index files into export * from './index' everywhere. Am I missing something?

No activity has been seen recently, marking as stale. If this is a mistake please reach out to a collaborator

No activity has been seen recently, marking as stale. If this is a mistake please reach out to a collaborator