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

fix: Only copy pre-compiled themes once #1184

Merged
merged 9 commits into from
Feb 18, 2025
Merged

Conversation

gadenbuie
Copy link
Member

Currently, when a pre-compiled theme is used, we re-use {tempdir()}/bslib-precompiled-5 but copy files from bslib to the temp directory every time the pre-compiled theme is used.

This PR refactors bs_theme_dependencies() to pull out the core logic (either use a precompiled theme or compile the theme via Sass) into helper functions, which clarifies the flow.

Then, if we've already prepared the full dependency in the temp directory, we re-use the prepared dependency on subsequent calls to bs_theme_dependencies().

Closes #1154. The issue seen there arises when we copy files out of the package but the package is stored with all files having read-only (400) permissions. This doesn't cause problems until bs_theme_dependencies() is called for a second time, where we end up trying to overwrite existing files. This is a partial fix in the sense that nix will still complain about being unable to remove temp files, but we can't solve that entirely from bslib anyway.

@gadenbuie gadenbuie requested a review from cpsievert February 11, 2025 15:20
}

version <- theme_version(theme)
deps_hash <- rlang::hash(htmlDependencies(as_sass(theme)))
Copy link
Member Author

Choose a reason for hiding this comment

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

This is probably over-thinking things. The one way that the theme could change between calls is if the Bootstrap JavaScript assets change. Taking the hash of the dependencies was intended to catch this, but we'd actually have to hash the files themselves. Not sure if it's worth it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not hard, maybe still not worth it: 58f62cd

@gadenbuie gadenbuie merged commit ee34398 into main Feb 18, 2025
@gadenbuie gadenbuie deleted the fix/1154-copy-precompiled-once branch February 18, 2025 14:08
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.

bslib dependencies fail during file copy when installed read-only
2 participants