Skip to content

Conversation

lucdar
Copy link

@lucdar lucdar commented Apr 19, 2025

When cleaning the dist directory before moving build artifacts from the staging area, if a .git file exists, it should not be removed. This allows Trunk to build into a git worktree, for example.

This behavior also exists in Vite which was introduced in this PR. Part of their justification is that a .git file could not be generated by Vite, but I'm not sure if this invariant holds for Trunk.

Copy link
Collaborator

@ctron ctron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable and looks good to me.

Might be cool to have a list instead of "or".

@lucdar
Copy link
Author

lucdar commented Apr 22, 2025

Something like this?

if [STAGE_DIR, ".git"].iter().any(|s| entry.file_name() == *s) {
    continue;
}

I also tried using contains but converting the OsString to a &&str is a little cumbersome:

if [STAGE_DIR, ".git"].contains(&&*entry.file_name().to_string_lossy()) {
    continue;
}

I feel like the "or" is a little more readable than either of these, but there might be a better way that what I have here.

@ctron
Copy link
Collaborator

ctron commented Apr 24, 2025

I though about adding a const list, and the using that list. So that, later on, that can easily be extended.

@duke-m
Copy link
Contributor

duke-m commented May 12, 2025

what about having something (sketched) like this in pub struct clean and using it here:

    #[arg(short, long, env = "TRUNK_CLEAN_PRESERVE_FILES")]
    pub preserve_files: Option<Vec<String>>

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

Successfully merging this pull request may close these issues.

3 participants