Parcel: Runtimes map to incorrect source files in source maps

Created on 22 Nov 2020  ยท  5Comments  ยท  Source: parcel-bundler/parcel

๐Ÿ› bug report

Currently whenever a runtime asset gets created it maps to the runtime plugin in the sourcemap instead of the actual runtime asset.

The reason I've opened this issue is to provide some more context and figure out a proper solution for this as it'll require some reworking in the core logic of runtimes and/or asset requests

Example:

Screenshot 2020-11-22 at 16 37 15

๐Ÿค” Expected Behavior

Should map to the runtime's generated code.

๐Ÿ˜ฏ Current Behavior

Maps to the source code of the runtime plugin

๐Ÿ’ Possible Solution

I've got 2 ideas on how to fix this:

  • Allow returning a sourcemap in the runtime plugin or generate one in applyRuntimes, both is currently impossible as AssetRequestInput has no sourcemap value.

  • Implement some layer of virtual fs and create the files virtually.

๐Ÿ”ฆ Context

Trying to fix the remaining source map bugs

๐Ÿ’ป Code Sample

import parcel from 'url:./parcel.webp';

console.log('test');

๐ŸŒ Your Environment

Current v2 branch

Bug Confirmed Bug Source Maps โœจ Parcel 2

Most helpful comment

I like the idea of returning a source map from runtimes as part of assetrequestinput. But in most cases the source map should basically be an empty map that's 1:1 with the code, so maybe in the transformer when AssetRequestInput has a code property it could automatically generate an empty map if none is available?

All 5 comments

I like the idea of returning a source map from runtimes as part of assetrequestinput. But in most cases the source map should basically be an empty map that's 1:1 with the code, so maybe in the transformer when AssetRequestInput has a code property it could automatically generate an empty map if none is available?

@devongovett the main issue is the actual source content being incorrect so should I inline that source content into the 1:1 map? Not sure what cache size impact of that would be (on second thought we'd need to store this somewhere regardless of what we do)?

Another issue I see with this is that it will need to reference some kind of unique/generated filepath that doesn't actually exist in the sourcemap as we deduplicate source references in the sourcemap library. I assume it'll be fine but could cause issues.

Change the RuntimeAsset type to contain resolveFromDir instead of filePath, then the path could be ${dir}/${md5(code)}.js (md5(code) is also the asset id)?

Yeah that seems reasonable

this issue is still in v1 version~

Was this page helpful?
0 / 5 - 0 ratings