Skip to content

Commit 978e5e4

Browse files
authored
Merge pull request #1526 from sass/file-importer-result
Replace FileImporterResult with a plain URL
2 parents d667843 + 2d56fe0 commit 978e5e4

5 files changed

Lines changed: 23 additions & 122 deletions

File tree

.github/workflows/ci.yml

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,9 @@ jobs:
3636
- uses: dart-lang/setup-dart@v1
3737
with: {sdk: "${{ matrix.dart_channel }}"}
3838
- run: dart pub get
39-
- name: Set up sass-spec
40-
run: tool/github-action/check-out-sass-spec.sh
41-
env:
42-
PR_BRANCH: "${{ github.base_ref }}"
43-
CURRENT_REF: "${{ github.ref }}"
44-
PR_BODY: "${{ github.event.pull_request.body }}"
39+
- name: Check out sass-spec
40+
uses: sass/clone-linked-repo@v1
41+
with: {repo: sass/sass-spec}
4542
- uses: actions/setup-node@v2
4643
with: {node-version: "${{ env.DEFAULT_NODE_VERSION }}"}
4744
- run: npm install
@@ -86,11 +83,8 @@ jobs:
8683
- run: npm install
8784

8885
- name: Check out sass-spec
89-
run: tool/github-action/check-out-sass-spec.sh
90-
env:
91-
PR_BRANCH: "${{ github.base_ref }}"
92-
CURRENT_REF: "${{ github.ref }}"
93-
PR_BODY: "${{ github.event.pull_request.body }}"
86+
uses: sass/clone-linked-repo@v1
87+
with: {repo: sass/sass-spec}
9488

9589
- name: Build JS
9690
run: dart pub run grinder pkg-npm-dev
@@ -100,7 +94,10 @@ jobs:
10094
working-directory: sass-spec
10195

10296
- name: Check out Sass specification
103-
run: git clone https://github.com/sass/sass.git language --depth 1
97+
uses: sass/clone-linked-repo@v1
98+
with:
99+
repo: sass/sass
100+
path: language
104101

105102
- name: Run tests
106103
run: npm run js-api-spec -- --sassSassRepo ../language

lib/src/importer/node_to_dart/async_file.dart

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@ import 'dart:async';
66

77
import 'package:node_interop/js.dart';
88
import 'package:node_interop/util.dart';
9-
import 'package:path/path.dart' as p;
109

11-
import '../../io.dart' as io;
1210
import '../../node/importer.dart';
11+
import '../../node/url.dart';
1312
import '../../node/utils.dart';
14-
import '../../syntax.dart';
1513
import '../async.dart';
1614
import '../filesystem.dart';
1715
import '../result.dart';
@@ -29,9 +27,6 @@ class NodeToDartAsyncFileImporter extends AsyncImporter {
2927
/// The wrapped `findFileUrl` function.
3028
final Object? Function(String, CanonicalizeOptions) _findFileUrl;
3129

32-
/// A map from canonical URLs to the `sourceMapUrl`s associated with them.
33-
final _sourceMapUrls = <Uri, Uri>{};
34-
3530
NodeToDartAsyncFileImporter(this._findFileUrl);
3631

3732
FutureOr<Uri?> canonicalize(Uri url) async {
@@ -41,36 +36,21 @@ class NodeToDartAsyncFileImporter extends AsyncImporter {
4136
url.toString(), CanonicalizeOptions(fromImport: fromImport));
4237
if (isPromise(result)) result = await promiseToFuture(result as Promise);
4338
if (result == null) return null;
44-
45-
result as NodeFileImporterResult;
46-
var dartUrl = result.url;
47-
var sourceMapUrl = result.sourceMapUrl;
48-
if (dartUrl == null) {
49-
jsThrow(JsError(
50-
"The findFileUrl() method must return an object a url field."));
39+
if (!isJSUrl(result)) {
40+
jsThrow(JsError("The findFileUrl() method must return a URL."));
5141
}
5242

53-
var resultUrl = jsToDartUrl(dartUrl);
43+
var resultUrl = jsToDartUrl(result as JSUrl);
5444
if (resultUrl.scheme != 'file') {
5545
jsThrow(JsError(
5646
'The findFileUrl() must return a URL with scheme file://, was '
5747
'"$url".'));
5848
}
5949

60-
var canonical = _filesystemImporter.canonicalize(resultUrl);
61-
if (canonical == null) return null;
62-
if (sourceMapUrl != null) {
63-
_sourceMapUrls[canonical] = jsToDartUrl(sourceMapUrl);
64-
}
65-
66-
return canonical;
50+
return _filesystemImporter.canonicalize(resultUrl);
6751
}
6852

69-
ImporterResult? load(Uri url) {
70-
var path = p.fromUri(url);
71-
return ImporterResult(io.readFile(path),
72-
sourceMapUrl: _sourceMapUrls[url] ?? url, syntax: Syntax.forPath(path));
73-
}
53+
ImporterResult? load(Uri url) => _filesystemImporter.load(url);
7454

7555
DateTime modificationTime(Uri url) =>
7656
_filesystemImporter.modificationTime(url);

lib/src/importer/node_to_dart/file.dart

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
// https://opensource.org/licenses/MIT.
44

55
import 'package:node_interop/js.dart';
6-
import 'package:path/path.dart' as p;
76

8-
import '../../io.dart' as io;
97
import '../../importer.dart';
108
import '../../node/importer.dart';
9+
import '../../node/url.dart';
1110
import '../../node/utils.dart';
12-
import '../../syntax.dart';
1311
import '../filesystem.dart';
1412
import '../result.dart';
1513
import '../utils.dart';
@@ -26,9 +24,6 @@ class NodeToDartFileImporter extends Importer {
2624
/// The wrapped `findFileUrl` function.
2725
final Object? Function(String, CanonicalizeOptions) _findFileUrl;
2826

29-
/// A map from canonical URLs to the `sourceMapUrl`s associated with them.
30-
final _sourceMapUrls = <Uri, Uri>{};
31-
3227
NodeToDartFileImporter(this._findFileUrl);
3328

3429
Uri? canonicalize(Uri url) {
@@ -40,39 +35,23 @@ class NodeToDartFileImporter extends Importer {
4035

4136
if (isPromise(result)) {
4237
jsThrow(JsError(
43-
"The canonicalize() function can't return a Promise for synchronous "
38+
"The findFileUrl() function can't return a Promise for synchron "
4439
"compile functions."));
40+
} else if (!isJSUrl(result)) {
41+
jsThrow(JsError("The findFileUrl() method must return a URL."));
4542
}
4643

47-
result as NodeFileImporterResult;
48-
var dartUrl = result.url;
49-
var sourceMapUrl = result.sourceMapUrl;
50-
if (dartUrl == null) {
51-
jsThrow(JsError(
52-
"The findFileUrl() method must return an object a url field."));
53-
}
54-
55-
var resultUrl = jsToDartUrl(dartUrl);
44+
var resultUrl = jsToDartUrl(result as JSUrl);
5645
if (resultUrl.scheme != 'file') {
5746
jsThrow(JsError(
5847
'The findFileUrl() must return a URL with scheme file://, was '
5948
'"$url".'));
6049
}
6150

62-
var canonical = _filesystemImporter.canonicalize(resultUrl);
63-
if (canonical == null) return null;
64-
if (sourceMapUrl != null) {
65-
_sourceMapUrls[canonical] = jsToDartUrl(sourceMapUrl);
66-
}
67-
68-
return canonical;
51+
return _filesystemImporter.canonicalize(resultUrl);
6952
}
7053

71-
ImporterResult? load(Uri url) {
72-
var path = p.fromUri(url);
73-
return ImporterResult(io.readFile(path),
74-
sourceMapUrl: _sourceMapUrls[url] ?? url, syntax: Syntax.forPath(path));
75-
}
54+
ImporterResult? load(Uri url) => _filesystemImporter.load(url);
7655

7756
DateTime modificationTime(Uri url) =>
7857
_filesystemImporter.modificationTime(url);

lib/src/node/importer.dart

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import 'url.dart';
1111
class NodeImporter {
1212
external Object? Function(String, CanonicalizeOptions)? get canonicalize;
1313
external Object? Function(JSUrl)? get load;
14-
external NodeFileImporterResult? Function(String, CanonicalizeOptions)?
15-
get findFileUrl;
14+
external Object? Function(String, CanonicalizeOptions)? get findFileUrl;
1615
}
1716

1817
@JS()
@@ -30,10 +29,3 @@ class NodeImporterResult {
3029
external String? get syntax;
3130
external JSUrl? get sourceMapUrl;
3231
}
33-
34-
@JS()
35-
@anonymous
36-
class NodeFileImporterResult {
37-
external JSUrl? get url;
38-
external JSUrl? get sourceMapUrl;
39-
}

tool/github-action/check-out-sass-spec.sh

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)