-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve importing files through load paths and node_modules #102
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
24ed9b4
Throw an error when generating different results for the same file
nex3 632c6ce
Track the original importers for canonical URLs
nex3 71e890c
Use more local information in _ModuleMigrationVisitor.visitImport
nex3 1dc1126
Stop being fancy about migrateDependencies in the module migrator
nex3 735ed4b
Properly load relative imports from within node_modules
nex3 5eec0d8
Properly migrate relative imports from within node_modules
nex3 7381703
Don't migrate files through load paths or node_modules
nex3 064fb22
Code review changes
nex3 95d5d9f
Fix a broken test
nex3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,34 @@ | ||
// Copyright 2019 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. | ||
|
||
import 'package:path/path.dart' as p; | ||
import 'package:sass/sass.dart'; | ||
|
||
import '../utils.dart'; | ||
import 'reversible_importer.dart'; | ||
|
||
/// A version of [FilesystemImporter] that implements [ReversibleImporter] as | ||
/// well. | ||
class ReversibleFilesystemImporter extends Importer | ||
implements ReversibleImporter { | ||
/// The wrapped importer to which this delegates. | ||
final FilesystemImporter _inner; | ||
|
||
/// The path relative to which this importer looks for files. | ||
final String _loadPath; | ||
|
||
ReversibleFilesystemImporter(this._loadPath) | ||
: _inner = FilesystemImporter(_loadPath); | ||
|
||
Uri decanonicalize(Uri canonicalUrl) => cleanBasename( | ||
p.toUri(p.relative(p.fromUri(canonicalUrl), from: _loadPath))); | ||
|
||
Uri canonicalize(Uri url) => _inner.canonicalize(url); | ||
|
||
ImporterResult load(Uri canonicalUrl) => _inner.load(canonicalUrl); | ||
|
||
String toString() => _inner.toString(); | ||
} |
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,18 @@ | ||
// Copyright 2019 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. | ||
|
||
import 'package:sass/sass.dart'; | ||
|
||
/// An [Importer] interface that supports converting canonical URLs back into | ||
/// their non-canonical forms. | ||
abstract class ReversibleImporter implements Importer { | ||
/// Converts [canonicalUrl] into a non-canonical form. | ||
/// | ||
/// Callers should only call this with [canonicalUrl]s returned by this | ||
/// importer. Implementors must guarantee that calling | ||
/// `canonicalize(decanonicalize(url))` will return the original `url`. | ||
Uri decanonicalize(Uri canonicalUrl); | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why this is not also a
ReversibleFilesystemImporter
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
URLs that are relative to the entrypoint should always be converted to relative URLs. In fact, generating a
@use
whose URL is relative to the working directory would be incorrect, since the working directory is not on the load path.