accurate bytesInOutput for css that includes urls #2091
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes #2071
Problem statement
Bytes in output is based on
len(compileResult.CSS)
which is the result of the printer. And it includes the hash inside the url instead of the actual path.Example:
div{ background: url(hashthats25characterslong); }
That leads to a wrong value for
bytesInOutput
Solution
Right before adding
bytesInOutput
to the meta file, we loop over files that have parts in the current chunk (i.e that are imported from the current chunk):This is my first PR in esbuild, so I don't have enough knowledge about the internals to make a cleaner fix. But here are some thoughts/questions I had while working on this:
fmt.Sprintf("%sA%08d", args.uniqueKeyPrefix, args.sourceIndex)
withA
for asset and 8 bytes int representing the index of the asset + the unique key prefix that's 16 bytes long. --> that's 25 byteschunk.jsonMetadataChunkCallback
with a parameter that's the final output size. So it is possible to add a similar function for bytes in output. But it's useless unless we can avoid calculating the offset and defer calculating the bytes in output to a later stage