Skip to content

Commit

Permalink
Only claim "package:" URLs are unsupported on Node (#637)
Browse files Browse the repository at this point in the history
Closes #630
  • Loading branch information
nex3 authored Apr 4, 2019
1 parent 9621979 commit 495c6f3
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 20 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

* Fix importing files relative to `package:`-imported files.

* Don't claim that "package:" URLs aren't supported when they actually are.

### Dart API

* Explicitly require that importers' `canonicalize()` methods be able to take
Expand Down
3 changes: 2 additions & 1 deletion lib/src/visitor/async_evaluate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import '../extend/extender.dart';
import '../importer.dart';
import '../importer/node.dart';
import '../importer/utils.dart';
import '../io.dart';
import '../logger.dart';
import '../parse/keyframe_selector.dart';
import '../syntax.dart';
Expand Down Expand Up @@ -851,7 +852,7 @@ class _EvaluateVisitor
if (tuple != null) return tuple;
}

if (url.startsWith('package:')) {
if (url.startsWith('package:') && isNode) {
// Special-case this error message, since it's tripped people up in the
// past.
throw "\"package:\" URLs aren't supported on this platform.";
Expand Down
5 changes: 3 additions & 2 deletions lib/src/visitor/evaluate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// DO NOT EDIT. This file was generated from async_evaluate.dart.
// See tool/synchronize.dart for details.
//
// Checksum: be2d44a3dc50defd98446d806b4c21bfe54a4ba9
// Checksum: e7642c8d4c838f0afe94b882794e81b0937ba1a1
//
// ignore_for_file: unused_import

Expand Down Expand Up @@ -36,6 +36,7 @@ import '../extend/extender.dart';
import '../importer.dart';
import '../importer/node.dart';
import '../importer/utils.dart';
import '../io.dart';
import '../logger.dart';
import '../parse/keyframe_selector.dart';
import '../syntax.dart';
Expand Down Expand Up @@ -851,7 +852,7 @@ class _EvaluateVisitor
if (tuple != null) return tuple;
}

if (url.startsWith('package:')) {
if (url.startsWith('package:') && isNode) {
// Special-case this error message, since it's tripped people up in the
// past.
throw "\"package:\" URLs aren't supported on this platform.";
Expand Down
18 changes: 18 additions & 0 deletions test/cli/dart/errors_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,29 @@
@TestOn('vm')

import 'package:test/test.dart';
import 'package:test_descriptor/test_descriptor.dart' as d;

import '../dart_test.dart';
import '../shared/errors.dart';

void main() {
setUpAll(ensureSnapshotUpToDate);
sharedTests(runSass);

test("for package urls", () async {
await d.file("test.scss", "@import 'package:nope/test';").create();

var sass = await runSass(["--no-unicode", "test.scss"]);
expect(
sass.stderr,
emitsInOrder([
"Error: Can't find stylesheet to import.",
" ,",
"1 | @import 'package:nope/test';",
" | ^^^^^^^^^^^^^^^^^^^",
" '",
" test.scss 1:9 root stylesheet"
]));
await sass.shouldExit(65);
});
}
18 changes: 18 additions & 0 deletions test/cli/node/errors_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@Tags(['node'])

import 'package:test/test.dart';
import 'package:test_descriptor/test_descriptor.dart' as d;

import '../../ensure_npm_package.dart';
import '../node_test.dart';
Expand All @@ -14,4 +15,21 @@ import '../shared/errors.dart';
void main() {
setUpAll(ensureNpmPackage);
sharedTests(runSass);

test("for package urls", () async {
await d.file("test.scss", "@import 'package:nope/test';").create();

var sass = await runSass(["--no-unicode", "test.scss"]);
expect(
sass.stderr,
emitsInOrder([
"Error: \"package:\" URLs aren't supported on this platform.",
" ,",
"1 | @import 'package:nope/test';",
" | ^^^^^^^^^^^^^^^^^^^",
" '",
" test.scss 1:9 root stylesheet"
]));
await sass.shouldExit(65);
});
}
17 changes: 0 additions & 17 deletions test/cli/shared/errors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,21 +113,4 @@ void sharedTests(Future<TestProcess> runSass(Iterable<String> arguments)) {
expect(sass.stderr, emitsThrough(contains("\.dart")));
await sass.shouldExit(65);
});

test("for package urls", () async {
await d.file("test.scss", "@import 'package:nope/test';").create();

var sass = await runSass(["--no-unicode", "test.scss"]);
expect(
sass.stderr,
emitsInOrder([
"Error: \"package:\" URLs aren't supported on this platform.",
" ,",
"1 | @import 'package:nope/test';",
" | ^^^^^^^^^^^^^^^^^^^",
" '",
" test.scss 1:9 root stylesheet"
]));
await sass.shouldExit(65);
});
}

0 comments on commit 495c6f3

Please sign in to comment.