Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
vjpr opened this issue Mar 4, 2021 · 10 comments
Open

Comments

@vjpr
Copy link

vjpr commented Mar 4, 2021

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.

@vjpr vjpr changed the title `--delete breaks Without --delete, if barrel file already exists, then it doesn't work properly Mar 4, 2021
@github-actions
Copy link

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

@jfairley
Copy link

jfairley commented Mar 9, 2022

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

@bencoveney

@FFdhorkin
Copy link

Confirmed this is still an issue...

@BitForger
Copy link
Collaborator

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.

@nrgapple
Copy link

nrgapple commented Jan 13, 2023

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

@BitForger
Copy link
Collaborator

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

@Brozgar
Copy link

Brozgar commented Jan 20, 2023

@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?

@github-actions
Copy link

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

@github-actions
Copy link

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

@adi518
Copy link

adi518 commented Sep 16, 2024

I found another bug when using this tool programmatically (see #680). If you pass the delete flag without passing noHeader: false (which strangely defaults to true). It won't purge correctly and the result would be the same as running again without the delete flag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants