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 source maps relative file lookup for source javascript file. #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MaicoTimmerman
Copy link

@MaicoTimmerman MaicoTimmerman commented Jun 19, 2020

We are using the ant-design-vue package with source maps, which depends on this package. During compilation there seem to be some problems with the source maps as generated with the compiled source.

The error is as follows:

Module Warning (from ./node_modules/source-map-loader/index.js):
(Emitted value instead of an instance of Error) Cannot find source file 'MutationObserver.js': Error: Can't resolve './MutationObserver.js' in '/home/maico/IdeaProjects/viaduct/node_modules/mutationobserver-shim/dist'

I took a look at the source map that is generated by the closure compiler, which currently looks like:

{
"version":3,
"file":"",
"lineCount":16,
"mappings":"...omitted...",
"sources":["MutationObserver.js"],
"names":["...omitted..."]
}

From the source map spec I know that the file field should contain the name of the minified file, in this case mutationobserver.min.js, however it seems closure compiler does not fill that.

The main problem here is that the sources field should point to the original source file, relative to the source map file. As I'm unfamiliar with closure compiler and didn't see options to change the sources to ["../MutationObserver.js"], I've moved the minified file and the relevant source map to the same folder as the original javascript file. This seems a more future proof solution than manually adding the .. to the path, as the source map will still be correct after a recompile.

P.S. I was unable to run the full test suite on master, it seems gunit:main is not able to run on my local machine. I didn't look into the cause of that, meaning it didn't run for my changes.

@MaicoTimmerman
Copy link
Author

@megawac Do you have the time to take a look at these changes?

@megawac
Copy link
Owner

megawac commented Jul 10, 2020

Yeah the version of grunt we're using is super old (like 6 years) and with its subdeps changing underneath it it likely caused the test cases to break. I'll take a look at this this afternoon however I'm a bit confused why this would cause issues for ant tooling? Have you verified this fix works?

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.

None yet

2 participants