Skip to content

Commit

Permalink
fix(sourcemaps): Fix inline source map regex match pattern if no tags…
Browse files Browse the repository at this point in the history
… in match string. (#241)

Regex was:
`const inlineSourceMapRegex = /\/\/#
sourceMappingURL=data:application\/json;.*;base64,(.*)$/gm;`
Now:
`const inlineSourceMapRegex = /\/\/#
sourceMappingURL=data:application\/json;.*base64,(.*)$/gm;`

Remove the semicolon before base64.

Check that the results of mapFileName.split found /scripts/ before
indexing the array.
  • Loading branch information
chmeyer-ms authored Oct 22, 2024
1 parent 3c85cd3 commit 509d5b3
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/SourceMaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,18 @@ class SourceMapCache {

let mapJson;
if (this._inlineSourceMap) {
const inlineSourceMapRegex = /\/\/# sourceMappingURL=data:application\/json;.*;base64,(.*)$/gm;
const match = inlineSourceMapRegex.exec(mapFile.toString());
const sourceRoot = path.join(
this._localRoot ?? '',
path.dirname(mapFileName.split('\\scripts\\')[1])
);
const inlineSourceMapRegex = /\/\/# sourceMappingURL=data:application\/json;.*base64,(.*)$/gm;
const mapString = mapFile.toString();
const match = inlineSourceMapRegex.exec(mapString);
if (match && match.length > 1) {
const base64EncodedMap = match[1];
const decodedMap = Buffer.from(base64EncodedMap, 'base64').toString('utf8');
mapJson = JSON.parse(decodedMap);
mapJson.file = path.basename(mapFileName);
mapJson.sourceRoot = sourceRoot;
const parts = mapFileName.split('\\scripts\\');
if (parts.length > 1) {
mapJson.sourceRoot = path.join(this._localRoot ?? '', path.dirname(parts[1]));
}
} else {
throw new InlineSourceMapError(`Failed to load inline source maps for file: ${mapFileName}`);
}
Expand Down

0 comments on commit 509d5b3

Please sign in to comment.