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

Version 3.1.0 corrupting sourceURL index maps and producing broken javascript #812

Open
longhotsummer opened this issue May 12, 2024 · 1 comment

Comments

@longhotsummer
Copy link

Version 3.1.0 of django-pipeline looks like it is producing JS which isn't valid.

My input JS file has code like this (initial contents of eval() removed for simplicity):

eval("... return range;\n}\n//# sourceMappingURL=index.js.map\n\n//# sourceURL=webpack://indigo/./node_modules/dom-anchor-text-position/lib/index.js?");

That is being transformed by django-pipeline into this (note the /# sourceURL at the end should be //# but is now /#):

eval("... return range;\n}\n//# sourceMappingURL=lib/index.js.map\n\n/# sourceURL=webpack:/indigo/node_modules/dom-anchor-text-position/lib/index.js?");

The problem is that /# is now interpreted as a regular expression, not as a comment, which causes the call to eval() to fail, because it's not a valid regex:

/# sourceURL=webpack:/indigo/node_modules/dom-anchor-text-position/lib/index.js?

Reverting to 3.0.0 fixes the problem.

@tomka
Copy link

tomka commented Jan 22, 2025

We encounter a related problem: we use the numjs library and the source mapping URL rewrites introduced in fd1c033 (#808) break its JavaScript file, both the regular one and the minified version: On line 17784 of numjs sources have:

var sourceURL = '//# sourceURL=' +

This gets replaced by django-pipeline with

var sourceURL = '//# sourceURL=../../libs/numjs/' +

In the minified version, which we usually use, a second problem arises in addition to that, which results in breaking the whole library. django-pipeline replaces

var n=o("path"),e=o("./read"),t=n.join(n.resolve(r),"./data");

with

var n=o("path"),e=o("./read"),t=n.join(n.resolve(r),"../../data");

This is probably due to the first match of sourceURL and everyting being on a single line.

My configuration for this package in django-pipeline looks like this:

{
  'source_filenames': 'libs/numjs/numjs.min.js',
  'output_filename': 'js/libs/numjs-lib.js'
}

Is there a way of fixing this without downgrading to 3.0.0 (because we want to e.g. use new Django versions)?

Maybe it would be helpful if this rewriting can be enabled/disabled per package or at least skip sourceURL assignments that are inside quotes (i.e. are a string)?

tomka added a commit to catmaid/CATMAID that referenced this issue Jan 22, 2025
Django-pipeline rewrites relative URLs for source map files since v3.1.
This leads to problems with our NumJS version, because rewriting
relative paths breaks the module loading logic of NumJS.

Currently, this rewriting can't be disabled and there didn't seem a good
way to monkey-patch django-pipeline. Therefore, we adapt the NumJS
source file to add a space in order to trick django-pipeline. This
commit changes:

var sourceURL = '//# sourceURL=' +

to

var sourceURL = '// # sourceURL=' +

This doesn't break our usage of NumJS and avoids the rewriting, because
its regular expression matches on "//# sourceURL".

This GitHub comment explains this in more detail:

jazzband/django-pipeline#812 (comment)
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

No branches or pull requests

2 participants