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 js.Build sourcemap comment #12869

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

BrianLeishman
Copy link

https://esbuild.github.io/api/#sourcemap

esbuild sitemap option when set to "external" doesn't actually include the sitemap comment in the file (maybe it used to?). The "linked" option does do this, but I think we want to keep using external here since we want to generate our own source map comment still.

In this PR I update the code to simply add our source map comment vs trying to replace the existing one (as one doesn't exist.)

I also update the Sourcefile esbuild option to be the name of the given file in "assets" so that the source map will specify the actual file, vs just saying "stdin".

@CLAassistant
Copy link

CLAassistant commented Sep 20, 2024

CLA assistant check
All committers have signed the CLA.

@BrianLeishman
Copy link
Author

Created a small test repo just to showcase a forced console error with the correct file name and line number here: https://github.com/BrianLeishman/hugo-milkdown-esbuild

git clone https://github.com/BrianLeishman/hugo-milkdown-esbuild --recurse-submodules
cd hugo-milkdown-esbuild
npm ci
hugo server

image

@bep
Copy link
Member

bep commented Sep 21, 2024

Thanks for this. This looks good, but it has worked before (I remember testing it), and the reason it broke is because we don't have a proper test for it. So, we need that. If you add a test in the js_integration_test.go, I will merge.

@BrianLeishman
Copy link
Author

Sounds good! I did just realize though a few minutes ago that I am using the absolute path "assets" to determine the physical location of the input file, and I don't think that's right, but I'm not familiar enough yet with the hugo source to know how to resolve the real path (relative of the workspace) of a file in "assets".

I'll work on the test and the better file resolution now.

@BrianLeishman
Copy link
Author

Both of those changes should be good to go!

Resolve real location of file in assets fs on the os fs

Tested this by moving my "ts" folder to the root of the workspace, and mounting into "assets" view the module mounting config in hugo.toml, getting the correct path, and then testing again by removing the mount and placing directly in assets.

This was easier than expected since there was an example in the same file.

Source comment test

With the new comment assertion, the test fails if I undo my changes to the comment output, but passes with this update.

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