-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Detect dependency loops in module migrator
- Loading branch information
1 parent
dce67db
commit 8592cc3
Showing
6 changed files
with
120 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
## 2.0.4 | ||
* Detect dependency loops in module migrator fix. | ||
|
||
## 2.0.3 | ||
|
||
### Module Migrator | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2023 Google LLC | ||
// | ||
// Use of this source code is governed by an MIT-style | ||
// license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
/// A graph data structure to manage dependencies between URIs. | ||
/// | ||
/// This class allows adding, removing, and querying dependencies | ||
/// between source URIs and their imported paths. | ||
class DependencyGraph { | ||
final Map<Uri, Set<Uri>> _graph = {}; | ||
|
||
/// Adds a dependency relationship between source and importedPath. | ||
void add(Uri source, Uri importedPath) { | ||
_graph.putIfAbsent(source, () => {}).add(importedPath); | ||
} | ||
|
||
/// Removes a dependency relationship between source and importedPath. | ||
void remove(Uri source, Uri importedPath) { | ||
_graph[source]?.remove(importedPath); | ||
} | ||
|
||
/// Finds all dependencies of a given source. | ||
Set<Uri>? find(Uri source) { | ||
return _graph[source]; | ||
} | ||
|
||
/// Checks if a specific dependency exists. | ||
bool hasDependency(Uri source, Uri importedPath) { | ||
return _graph.containsKey(source) && _graph[source]!.contains(importedPath); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<==> arguments | ||
--migrate-deps | ||
|
||
<==> input/entrypoint.scss | ||
$a: red; | ||
@import "ejemplo"; | ||
a { | ||
background: $b; | ||
} | ||
|
||
<==> input/_ejemplo.scss | ||
$b: blue; | ||
a { | ||
color: $a; | ||
} | ||
|
||
<==> error.txt | ||
Error: Dependency loop detected: entrypoint -> ejemplo. | ||
To resolve this issue, consider either of the following: | ||
1. Remove the import statement that causes the dependency loop. | ||
2. Declare the variables used in the other stylesheet within the same stylesheet. | ||
|
||
, | ||
2 | @import "ejemplo"; | ||
| ^^^^^^^^^ | ||
' | ||
entrypoint.scss 2:9 root stylesheet | ||
Migration failed! |
24 changes: 24 additions & 0 deletions
24
test/migrators/module/namespace_references/loop_error_one_reference.hrx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<==> arguments | ||
--migrate-deps | ||
|
||
<==> input/entrypoint.scss | ||
$var1: 2; | ||
@import "library"; | ||
|
||
<==> input/_library.scss | ||
a { | ||
margin: $var1; | ||
} | ||
|
||
<==> error.txt | ||
Error: Dependency loop detected: entrypoint -> library. | ||
To resolve this issue, consider either of the following: | ||
1. Remove the import statement that causes the dependency loop. | ||
2. Declare the variables used in the other stylesheet within the same stylesheet. | ||
|
||
, | ||
2 | @import "library"; | ||
| ^^^^^^^^^ | ||
' | ||
entrypoint.scss 2:9 root stylesheet | ||
Migration failed! |