Fix SourceMaps not including the original *.ts files
Issue
Source maps were not including references to the original TypeScript (.ts) files, but rather were referencing the rewritten JavaScript (.js) files from the build process. This issue occurred during the updateDistEsm script execution, which modifies JavaScript files to replace tslib references with shims (to support IE).
Root Cause
In the updateDistEsm.js script, when generating new source maps, it was setting the source property to the path of the JavaScript file being processed:
var newMap = theString.generateMap({
source: inputFile.toString(), // This was incorrectly pointing to the JS file
file: mapFile,
includeContent: true,
hires: false
});
This caused the source maps to reference the JavaScript files instead of the original TypeScript files.
Solution
Modified the source map generation process to:
- Read the existing source map to extract the original TypeScript sources
- Generate a new source map with the modifications
- Preserve the original sources and sourcesContent from the existing map
- Update the map file with these preserved sources
Additional Improvements
- Added robust error handling for cases where source maps don't exist or are invalid
- Ensured the code works correctly in all scenarios (existing maps, missing maps, corrupted maps)
- Added comprehensive test cases to verify all edge cases:
- Preserving TypeScript source references in existing maps
- Handling cases where source maps don't exist
- Gracefully recovering from corrupted/invalid source maps
Testing
Created a test script (test-sourcemap.js) that simulates the source map update process and verifies that TypeScript references are preserved in all scenarios.
Fixes #2440.
[!WARNING]
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
googlechromelabs.github.io
- Triggering command:
node install.mjs(dns block)https://storage.googleapis.com/chrome-for-testing-public/136.0.7103.92/linux64/chrome-headless-shell-linux64.ziphttps://storage.googleapis.com/chrome-for-testing-public/136.0.7103.92/linux64/chrome-linux64.zip
- Triggering command:
node install.mjs(http block)If you need me to access, download, or install something from one of these locations, you can either:
- Configure Actions setup steps to set up my environment, which run before the firewall is enabled
- Add the appropriate URLs or hosts to my firewall allow list
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.