-
-
Notifications
You must be signed in to change notification settings - Fork 372
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
Update sourcemap paths when concatenating source files. #809
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #809 +/- ##
==========================================
+ Coverage 82.35% 82.55% +0.20%
==========================================
Files 33 33
Lines 1139 1158 +19
==========================================
+ Hits 938 956 +18
- Misses 201 202 +1 ☔ View full report in Codecov by Sentry. |
Regarding the Ruff output:
Thoughts on these points? |
Ruff's complaint about
This is just the default pylint PLR09 limit, which I think is unreasonable for real-world, complex software. The recommendation in pylint to "fix" this is to create NamedTuples to group some arguments. In some cases, that might make sense, but here I think all it would do is obfuscate the code to satisfy the linter. |
When building a package from source files, the built source files get concatenated together before being post-processed by Django. Prior to Django 4.0, the post-processing step would normalize `url(...)` entries in CSS by looking it up in storage and replacing the path with the hashed version. Starting in Django 4.0, post-processing would do the same for sourcemaps. This can break when concatenating either CSS or JavaScript files, since Pipeline may produce a built package file that's in a different directory from one or more built source files. Django would fail to find the file and raise an error. We now include sourcemap normalization as part of the concatenation process. This is using a similar approach to `url(...)` normalization, but now consolidated into the `Compressor.concatenate()` function. This has been updated to take arguments controlling the concatenation process, such as a regex for capturing paths to normalize. The regex for capturing sourcemap lines is built to be spec-compliant, and is currently more broad than what Django looks for during post-processing. This will help avoid potential issues as Django makes changes to their process. The old functions (`concatenate_and_rewrite()`) and old default behavior has been left intact, but with runtime deprecation warnings, so that any code specializing Pipeline will continue to work. This helps ensure this change is API-compatible and non-breaking. See issue jazzband#808 for more details on the problem and the solution.
2e44a6d
to
fd1c033
Compare
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me now. Not sure if anyone else wants to review as well.
would it be possible to get this released to pypi soon? I have a number of sites impacted by this, and would like to update them to django 4.2 before 3.2 losses LTS |
We're just waiting for approval on being able to perform a release. We'd like to get this released quickly as well. |
When building a package from source files, the built source files get concatenated together before being post-processed by Django. Prior to Django 4.0, the post-processing step would normalize
url(...)
entries in CSS by looking it up in storage and replacing the path with the hashed version.Starting in Django 4.0, post-processing would do the same for sourcemaps. This can break when concatenating either CSS or JavaScript files, since Pipeline may produce a built package file that's in a different directory from one or more built source files. Django would fail to find the file and raise an error.
We now include sourcemap normalization as part of the concatenation process. This is using a similar approach to
url(...)
normalization, but now consolidated into theCompressor.concatenate()
function. This has been updated to take arguments controlling the contenation process, such as a regex for capturing paths to normalize.The regex for capturing sourcemap lines is built to be spec-compliant, and is currently more broad than what Django looks for during post-processing. This will help avoid potential issues as Django makes changes to their process.
The old functions (
concatenate_and_rewrite()
) and old default behavior has been left intact, but with runtime deprecation warnings, so that any code specializing Pipeline will continue to work. This helps ensure this change is API-compatible and non-breaking.See issue #808 for more details on the problem and the solution.
Testing
Ran
tox
. All unit tests passed.Tested this locally in three different projects using Pipeline and exhibiting this
problem on Django 4.0+. Verified that packaging worked as expected, with corrected
sourcemap paths.