Skip to content

Commit

Permalink
fixup! preserved map source urls better
Browse files Browse the repository at this point in the history
  • Loading branch information
connor4312 committed Jan 31, 2020
1 parent fad67cf commit b7557b7
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 32 deletions.
1 change: 0 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const sourcemaps = require('gulp-sourcemaps');
const ts = require('gulp-typescript');
const rename = require('gulp-rename');
const merge = require('merge2');
const prettier = require('gulp-prettier');
const typescript = require('typescript');
const vsce = require('vsce');
const webpack = require('webpack');
Expand Down
23 changes: 0 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@
"gulp": "^4.0.2",
"gulp-eslint": "^6.0.0",
"gulp-filter": "^6.0.0",
"gulp-prettier": "^2.3.0",
"gulp-rename": "^1.4.0",
"gulp-replace": "^1.0.0",
"gulp-sourcemaps": "^2.6.5",
Expand All @@ -128,6 +127,7 @@
"mocha-multi-reporters": "^1.1.7",
"npm-run-all": "^4.1.5",
"nyc": "^14.1.1",
"prettier": "^1.19.1",
"puppeteer": "^1.20.0",
"request": "^2.88.0",
"request-promise-native": "^1.0.7",
Expand Down
17 changes: 10 additions & 7 deletions src/adapter/sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { MapUsingProjection } from '../common/datastructure/mapUsingProjection';
import { assert, logger } from '../common/logging/logger';
import { SourceMapFactory } from '../common/sourceMaps/sourceMapFactory';
import { LogTag } from '../common/logging';
import { fixDriveLetterAndSlashes } from '../common/pathUtils';
import Cdp from '../cdp/api';

const localize = nls.loadMessageBundle();
Expand Down Expand Up @@ -665,24 +664,28 @@ export class SourceContainer {
compiled._sourceMapSourceByUrl = new Map();
const todo: Promise<void>[] = [];
for (const url of map.sources) {
const resolvedUrl = fixDriveLetterAndSlashes(url);
const content = map.sourceContentFor(url) ?? undefined;
const absolutePath = await this.sourcePathResolver.urlToAbsolutePath({ url, map });
const resolvedUrl =
(absolutePath && utils.absolutePathToFileUrl(absolutePath)) || map.computedSourceUrl(url);

let source = this._sourceMapSourcesByUrl.get(resolvedUrl);
const isNew = !source;
if (!source) {
const absolutePath = await this.sourcePathResolver.urlToAbsolutePath({ url, map });
logger.verbose(LogTag.RuntimeSourceCreate, 'Creating source from source map', {
inputUrl: resolvedUrl,
inputUrl: url,
inputMap: map.metadata,
absolutePath,
compiledUrl: compiled.url(),
resolvedUrl,
sourceMapSources: map.sources,
});

// Note: we can support recursive source maps here if we parse sourceMapUrl comment.
const fileUrl = absolutePath && utils.absolutePathToFileUrl(absolutePath);
const content = map.sourceContentFor(url) ?? undefined;

source = new Source(
this,
fileUrl || url,
resolvedUrl,
absolutePath,
content !== undefined
? () => Promise.resolve(content)
Expand Down
16 changes: 16 additions & 0 deletions src/common/sourceMaps/sourceMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
MappingItem,
BasicSourceMapConsumer,
} from 'source-map';
import { completeUrlEscapingRoot } from '../urlUtils';
import { fixDriveLetterAndSlashes } from '../pathUtils';

export interface ISourceMapMetadata {
sourceMapUrl: string;
Expand Down Expand Up @@ -56,6 +58,20 @@ export class SourceMap implements BasicSourceMapConsumer {
return this.original.sourcesContent;
}

/**
* Gets the source URL computed from the compiled path and the source root.
*/
public computedSourceUrl(sourceUrl: string) {
return fixDriveLetterAndSlashes(
completeUrlEscapingRoot(
this.metadata.sourceMapUrl.startsWith('data:')
? this.metadata.compiledPath
: this.metadata.sourceMapUrl,
this.sourceRoot + sourceUrl,
),
);
}

/**
* @inheritdoc
*/
Expand Down

0 comments on commit b7557b7

Please sign in to comment.