Skip to content

Commit 73cbc9e

Browse files
authored
Fix a crash with orphan import-only files (#177)
Previously we just used the rule URL from the orphan import-only's last `@forward` rule directly, but that only works when that URL is relative to a load path or the orphan is in the same directory as the file depending on it. We now build a new dependency URL after resolving the old rule URL into its canonical form.
1 parent 73d5d49 commit 73cbc9e

File tree

4 files changed

+41
-7
lines changed

4 files changed

+41
-7
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 1.3.4
2+
3+
### Module Migrator
4+
5+
* Fix a crash when resolving references to orphan import-only files in a
6+
different directory from the file depending on them.
7+
18
## 1.3.3
29

310
* No user-visible changes.

lib/src/migrators/module.dart

+11-6
Original file line numberDiff line numberDiff line change
@@ -761,13 +761,18 @@ class _ModuleMigrationVisitor extends MigrationVisitor {
761761

762762
for (var import in dynamicImports) {
763763
var ruleUrl = import.url;
764-
var canonicalImport = importCache
765-
.canonicalize(Uri.parse(ruleUrl),
766-
baseImporter: importer, forImport: true)
767-
?.item2;
764+
var tuple = importCache.canonicalize(Uri.parse(ruleUrl),
765+
baseImporter: importer, forImport: true);
766+
var canonicalImport = tuple?.item2;
768767
if (references.orphanImportOnlyFiles.containsKey(canonicalImport)) {
769-
ruleUrl =
770-
references.orphanImportOnlyFiles[canonicalImport]?.url.toString();
768+
var url = references.orphanImportOnlyFiles[canonicalImport]?.url;
769+
if (url != null) {
770+
var canonicalRedirect = importCache
771+
.canonicalize(url,
772+
baseImporter: tuple.item1, baseUrl: canonicalImport)
773+
.item2;
774+
ruleUrl = _absoluteUrlToDependency(canonicalRedirect).item1;
775+
}
771776
}
772777

773778
if (ruleUrl != null) {

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: sass_migrator
2-
version: 1.3.3
2+
version: 1.3.4
33
description: A tool for running migrations on Sass files
44
author: Jennifer Thakar <[email protected]>
55
homepage: https://github.com/sass/migrator
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<==> arguments
2+
--migrate-deps
3+
4+
<==> input/entrypoint.scss
5+
@import "some/library/old";
6+
7+
a {
8+
b: $lib-variable;
9+
}
10+
11+
<==> input/some/library/_old.import.scss
12+
@forward "new" as lib-*;
13+
14+
<==> input/some/library/_new.scss
15+
$variable: green;
16+
17+
<==> output/entrypoint.scss
18+
@use "some/library/new";
19+
20+
a {
21+
b: new.$variable;
22+
}

0 commit comments

Comments
 (0)