Skip to content

Commit

Permalink
drop package_resolver dependency and remove packageRoot support (flut…
Browse files Browse the repository at this point in the history
  • Loading branch information
jakemac53 authored Mar 3, 2020
1 parent 668233a commit ebdb2c0
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ sudo: true

dart:
- dev
- 2.4.0
- 2.7.0

dart_task:
- test: -p chrome,vm
Expand Down
11 changes: 8 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
## 2.0.0-dev
## 2.0.0

* **Breaking** The `sdkRoot` argument must be an `Uri`. Use `Uri.parse` for use
### Breaking Changes

* Removed dependency on `package_resolver` and changed the apis to accept a
`Map<String, Uri>` which maps package names to the base uri to resolve the
`package:` uris for those packages.
* The `sdkRoot` argument must be an `Uri`. Use `Uri.parse` for use
cases previously passing a `String`.
* **Breaking** The deprecated `packageRoot` argument has been removed.
* The deprecated `packageRoot` argument has been removed.

## 1.1.5

Expand Down
33 changes: 12 additions & 21 deletions lib/source_map_stack_trace.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:package_resolver/package_resolver.dart';
import 'package:path/path.dart' as p;
import 'package:source_maps/source_maps.dart';
import 'package:stack_trace/stack_trace.dart';
Expand All @@ -13,19 +12,18 @@ import 'package:stack_trace/stack_trace.dart';
/// [minified] indicates whether or not the dart2js code was minified. If it
/// hasn't, this tries to clean up the stack frame member names.
///
/// If [packageResolver] is passed, it's used to reconstruct `package:` URIs for
/// stack frames that come from packages.
/// The [packageMap] maps package names to the base uri used to resolve the
/// `package:` uris for those packages. It is used to it's used to reconstruct
/// `package:` URIs for stack frames that come from packages.
///
/// [sdkRoot] is the URI surfaced in the stack traces for SDK libraries.
/// If it's passed, stack frames from the SDK will have `dart:` URLs.
StackTrace mapStackTrace(Mapping sourceMap, StackTrace stackTrace,
{bool minified = false, SyncPackageResolver packageResolver, Uri sdkRoot}) {
{bool minified = false, Map<String, Uri> packageMap, Uri sdkRoot}) {
if (stackTrace is Chain) {
return Chain(stackTrace.traces.map((trace) {
return Trace.from(mapStackTrace(sourceMap, trace,
minified: minified,
packageResolver: packageResolver,
sdkRoot: sdkRoot));
minified: minified, packageMap: packageMap, sdkRoot: sdkRoot));
}));
}

Expand All @@ -52,21 +50,14 @@ StackTrace mapStackTrace(Mapping sourceMap, StackTrace stackTrace,
var sourceUrl = span.sourceUrl.toString();
if (sdkRoot != null && p.url.isWithin(sdkLib, sourceUrl)) {
sourceUrl = 'dart:' + p.url.relative(sourceUrl, from: sdkLib);
} else if (packageResolver != null) {
if (packageResolver.packageRoot != null &&
p.url.isWithin(packageResolver.packageRoot.toString(), sourceUrl)) {
sourceUrl = 'package:' +
p.url.relative(sourceUrl,
from: packageResolver.packageRoot.toString());
} else if (packageResolver.packageConfigMap != null) {
for (var package in packageResolver.packageConfigMap.keys) {
var packageUrl = packageResolver.packageConfigMap[package].toString();
if (!p.url.isWithin(packageUrl, sourceUrl)) continue;
} else if (packageMap != null) {
for (var package in packageMap.keys) {
var packageUrl = packageMap[package].toString();
if (!p.url.isWithin(packageUrl, sourceUrl)) continue;

sourceUrl =
'package:$package/' + p.url.relative(sourceUrl, from: packageUrl);
break;
}
sourceUrl =
'package:$package/' + p.url.relative(sourceUrl, from: packageUrl);
break;
}
}

Expand Down
22 changes: 16 additions & 6 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
name: source_map_stack_trace
version: 2.0.0-dev

version: 2.0.0
description: A package for applying source maps to stack traces.
author: Dart Team <[email protected]>
homepage: https://github.com/dart-lang/source_map_stack_trace

environment:
sdk: '>=2.4.0 <3.0.0'
sdk: '>=2.7.0 <3.0.0'

dependencies:
package_resolver: ^1.0.0
path: ^1.0.0
stack_trace: ^1.0.0
source_maps: ^0.10.2

dev_dependencies:
source_span: ^1.6.0
test: ^1.12.0
pedantic: ^1.0.0

dependency_overrides:
test_core: ^0.3.0
# Required to get a valid pub solve until package:test updates
test_core:
git:
url: https://github.com/dart-lang/test.git
ref: drop-package-resolver
path: pkgs/test_core
test:
git:
url: https://github.com/dart-lang/test.git
ref: drop-package-resolver
path: pkgs/test
package_config: ^1.9.1

42 changes: 11 additions & 31 deletions test/source_map_stack_trace_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:package_resolver/package_resolver.dart';
import 'package:path/path.dart' as p;
import 'package:source_maps/source_maps.dart';
import 'package:source_span/source_span.dart';
Expand All @@ -20,6 +19,11 @@ final _simpleMapping = parseJson((SourceMapBuilder()
SourceLocation(18, line: 15, column: 0), '\n' * 10)))
.build('foo.dart.js.map'));

final _packageMap = {
'bar': Uri.parse('packages/bar'),
'foo': Uri.parse('packages/foo'),
};

void main() {
test('maps a JS line and column to a Dart line and span', () {
var trace = Trace.parse('foo.dart.js 10:11 foo');
Expand Down Expand Up @@ -89,9 +93,7 @@ bar.dart.js 10:11 foo

var bundle = [sourceMapJson1, sourceMapJson2];
var mapping = parseJsonExtended(bundle);
var frames = _mapTrace(mapping, trace,
packageResolver: SyncPackageResolver.root('packages/'))
.frames;
var frames = _mapTrace(mapping, trace, packageMap: _packageMap).frames;

expect(frames.length, equals(3));

Expand Down Expand Up @@ -127,26 +129,6 @@ bar.dart.js 10:11 foo
expect(frame.column, equals(4));
});

test('uses package: URIs for frames within packageResolver.packageRoot', () {
var trace = Trace.parse('foo.dart.js 10 foo');
var builder = SourceMapBuilder()
..addSpan(
SourceMapSpan.identifier(
SourceLocation(1,
line: 1, column: 3, sourceUrl: 'packages/foo/foo.dart'),
'qux'),
SourceSpan(SourceLocation(8, line: 5, column: 0),
SourceLocation(12, line: 9, column: 1), '\n' * 4));

var mapping = parseJson(builder.build('foo.dart.js.map'));
var mappedTrace = _mapTrace(mapping, trace,
packageResolver: SyncPackageResolver.root('packages/'));
var frame = mappedTrace.frames.first;
expect(frame.uri, equals(Uri.parse('package:foo/foo.dart')));
expect(frame.line, equals(2));
expect(frame.column, equals(4));
});

test('uses package: URIs for frames within a packageResolver.packageMap URL',
() {
var trace = Trace.parse('foo.dart.js 10 foo');
Expand All @@ -160,9 +142,7 @@ bar.dart.js 10:11 foo
SourceLocation(12, line: 9, column: 1), '\n' * 4));

var mapping = parseJson(builder.build('foo.dart.js.map'));
var mappedTrace = _mapTrace(mapping, trace,
packageResolver:
SyncPackageResolver.config({'foo': Uri.parse('packages/foo')}));
var mappedTrace = _mapTrace(mapping, trace, packageMap: _packageMap);
var frame = mappedTrace.frames.first;
expect(frame.uri, equals(Uri.parse('package:foo/foo.dart')));
expect(frame.line, equals(2));
Expand Down Expand Up @@ -264,17 +244,17 @@ bar.dart.js 10:11 foo
/// Like [mapStackTrace], but is guaranteed to return a [Trace] so it can be
/// inspected.
Trace _mapTrace(Mapping sourceMap, StackTrace stackTrace,
{bool minified = false, SyncPackageResolver packageResolver, Uri sdkRoot}) {
{bool minified = false, Map<String, Uri> packageMap, Uri sdkRoot}) {
return Trace.from(mapStackTrace(sourceMap, stackTrace,
minified: minified, packageResolver: packageResolver, sdkRoot: sdkRoot));
minified: minified, packageMap: packageMap, sdkRoot: sdkRoot));
}

/// Like [mapStackTrace], but is guaranteed to return a [Chain] so it can be
/// inspected.
Chain _mapChain(Mapping sourceMap, StackTrace stackTrace,
{bool minified = false, SyncPackageResolver packageResolver, Uri sdkRoot}) {
{bool minified = false, Map<String, Uri> packageMap, Uri sdkRoot}) {
return Chain.forTrace(mapStackTrace(sourceMap, stackTrace,
minified: minified, packageResolver: packageResolver, sdkRoot: sdkRoot));
minified: minified, packageMap: packageMap, sdkRoot: sdkRoot));
}

/// Runs the mapper's prettification logic on [member] and returns the result.
Expand Down

0 comments on commit ebdb2c0

Please sign in to comment.