Skip to content

Commit 8b20dfc

Browse files
committed
Remove FilesystemImporter.cwd
This also removes the implicit addition of the current working directory as a load path in various circumstances.
1 parent 96a1b66 commit 8b20dfc

File tree

12 files changed

+55
-55
lines changed

12 files changed

+55
-55
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
after them, as in `$a -$b`, are now forbidden due to being highly ambiguous
1919
between `$a - $b` and `$a (-$b)`.
2020

21+
* **Breaking change:** The current working directory is no longer ever
22+
implicitly added as a load path. You can add it explicitly with
23+
`--load-path=.` or similar options in the APIs.
24+
2125
* **Potentially breaking bug fix:** In some cases involving a `:has()` selector
2226
with a leading combinator being `@extend`ed by a selector that contained its
2327
own combinators, `@extend` used to generate incorrect selectors. This has been
@@ -85,7 +89,11 @@
8589
* **Breaking change:** Remove the unnamed `Callable()` and `AsyncCallable()`
8690
constructors. Use `Callable.function()` and `AsyncCallable.function()`
8791
instead.
88-
92+
93+
* **Breaking change:** Remove `FilesystemImporter.cwd`. Instead use
94+
`FilesystemImporter.noLoadPath` if you don't need to add the current working
95+
directory as a load path, or `FilesystemImporter('.')` if you do.
96+
8997
* **Breaking change:** Remove `Deprecation.calcInterp`. This was never actually
9098
emitted as a deprecation.
9199

lib/src/async_compile.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Future<CompileResult> compileAsync(
6565
(syntax == null || syntax == Syntax.forPath(path))) {
6666
importCache ??= AsyncImportCache.none();
6767
stylesheet = (await importCache.importCanonical(
68-
FilesystemImporter.cwd,
68+
FilesystemImporter.noLoadPath,
6969
p.toUri(canonicalize(path)),
7070
originalUrl: p.toUri(path),
7171
))!;
@@ -82,7 +82,7 @@ Future<CompileResult> compileAsync(
8282
logger,
8383
importCache,
8484
nodeImporter,
85-
FilesystemImporter.cwd,
85+
FilesystemImporter.noLoadPath,
8686
functions,
8787
style,
8888
useSpaces,
@@ -151,7 +151,7 @@ Future<CompileResult> compileStringAsync(
151151
logger,
152152
importCache,
153153
nodeImporter,
154-
importer ?? (isBrowser ? NoOpImporter() : FilesystemImporter.cwd),
154+
importer ?? (isBrowser ? NoOpImporter() : FilesystemImporter.noLoadPath),
155155
functions,
156156
style,
157157
useSpaces,

lib/src/compile.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ CompileResult compile(
7474
(syntax == null || syntax == Syntax.forPath(path))) {
7575
importCache ??= ImportCache.none();
7676
stylesheet = importCache.importCanonical(
77-
FilesystemImporter.cwd,
77+
FilesystemImporter.noLoadPath,
7878
p.toUri(canonicalize(path)),
7979
originalUrl: p.toUri(path),
8080
)!;
@@ -91,7 +91,7 @@ CompileResult compile(
9191
logger,
9292
importCache,
9393
nodeImporter,
94-
FilesystemImporter.cwd,
94+
FilesystemImporter.noLoadPath,
9595
functions,
9696
style,
9797
useSpaces,
@@ -160,7 +160,7 @@ CompileResult compileString(
160160
logger,
161161
importCache,
162162
nodeImporter,
163-
importer ?? (isBrowser ? NoOpImporter() : FilesystemImporter.cwd),
163+
importer ?? (isBrowser ? NoOpImporter() : FilesystemImporter.noLoadPath),
164164
functions,
165165
style,
166166
useSpaces,

lib/src/embedded/importer/file.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ final class FileImporter extends ImporterBase {
1818
FileImporter(super.dispatcher, this._importerId);
1919

2020
Uri? canonicalize(Uri url) {
21-
if (url.scheme == 'file') return FilesystemImporter.cwd.canonicalize(url);
21+
if (url.scheme == 'file') {
22+
return FilesystemImporter.noLoadPath.canonicalize(url);
23+
}
2224

2325
var request = OutboundMessage_FileImportRequest()
2426
..importerId = _importerId
@@ -38,7 +40,7 @@ final class FileImporter extends ImporterBase {
3840
throw 'The file importer must return a file: URL, was "$url"';
3941
}
4042

41-
return FilesystemImporter.cwd.canonicalize(url);
43+
return FilesystemImporter.noLoadPath.canonicalize(url);
4244

4345
case InboundMessage_FileImportResponse_Result.error:
4446
throw response.error;
@@ -48,7 +50,7 @@ final class FileImporter extends ImporterBase {
4850
}
4951
}
5052

51-
ImporterResult? load(Uri url) => FilesystemImporter.cwd.load(url);
53+
ImporterResult? load(Uri url) => FilesystemImporter.noLoadPath.load(url);
5254

5355
bool isNonCanonicalScheme(String scheme) => scheme != 'file';
5456

lib/src/executable/compile_stylesheet.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Future<void> _compileStylesheetWithoutErrorHandling(
8888
String? destination, {
8989
bool ifModified = false,
9090
}) async {
91-
var importer = FilesystemImporter.cwd;
91+
var importer = FilesystemImporter.noLoadPath;
9292
if (ifModified) {
9393
try {
9494
if (source != null &&
@@ -128,7 +128,7 @@ Future<void> _compileStylesheetWithoutErrorHandling(
128128
syntax: syntax,
129129
logger: options.logger,
130130
importCache: importCache,
131-
importer: FilesystemImporter.cwd,
131+
importer: FilesystemImporter.noLoadPath,
132132
style: options.style,
133133
quietDeps: options.quietDeps,
134134
verbose: options.verbose,
@@ -163,7 +163,7 @@ Future<void> _compileStylesheetWithoutErrorHandling(
163163
syntax: syntax,
164164
logger: options.logger,
165165
importCache: graph.importCache,
166-
importer: FilesystemImporter.cwd,
166+
importer: FilesystemImporter.noLoadPath,
167167
style: options.style,
168168
quietDeps: options.quietDeps,
169169
verbose: options.verbose,

lib/src/executable/repl.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Future<void> repl(ExecutableOptions options) async {
4444
}
4545

4646
var evaluator = Evaluator(
47-
importer: FilesystemImporter.cwd,
47+
importer: FilesystemImporter('.'),
4848
importCache: ImportCache(
4949
importers: options.pkgImporters,
5050
loadPaths: options.loadPaths,

lib/src/executable/watch.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Future<void> watch(ExecutableOptions options, StylesheetGraph graph) async {
4343
var sourcesToDestinations = _sourcesToDestinations(options);
4444
for (var source in sourcesToDestinations.keys) {
4545
graph.addCanonical(
46-
FilesystemImporter.cwd,
46+
FilesystemImporter.noLoadPath,
4747
p.toUri(canonicalize(source)),
4848
p.toUri(source),
4949
recanonicalize: false,
@@ -154,7 +154,7 @@ final class _Watcher {
154154
var destination = _destinationFor(path);
155155
if (destination != null) _toRecompile[path] = destination;
156156
var downstream = _graph.addCanonical(
157-
FilesystemImporter.cwd,
157+
FilesystemImporter.noLoadPath,
158158
_canonicalize(path),
159159
p.toUri(path),
160160
);
@@ -174,7 +174,7 @@ final class _Watcher {
174174
}
175175
}
176176

177-
var downstream = _graph.remove(FilesystemImporter.cwd, url);
177+
var downstream = _graph.remove(FilesystemImporter.noLoadPath, url);
178178
_recompileDownstream(downstream);
179179
}
180180

lib/src/importer/filesystem.dart

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,32 +35,14 @@ final class FilesystemImporter extends Importer {
3535
: _loadPath = p.absolute(loadPath),
3636
_loadPathDeprecated = false;
3737

38-
FilesystemImporter._deprecated(String loadPath)
39-
: _loadPath = p.absolute(loadPath),
40-
_loadPathDeprecated = true;
41-
4238
/// Creates an importer that _only_ loads absolute `file:` URLs and URLs
4339
/// relative to the current file.
4440
FilesystemImporter._noLoadPath()
4541
: _loadPath = null,
4642
_loadPathDeprecated = false;
4743

48-
/// A [FilesystemImporter] that loads files relative to the current working
49-
/// directory.
50-
///
51-
/// Historically, this was the best default for supporting `file:` URL loads
52-
/// when the load path didn't matter. However, adding the current working
53-
/// directory to the load path wasn't always desirable, so it's no longer
54-
/// recommended. Instead, either use [FilesystemImporter.noLoadPath] if the
55-
/// load path doesn't matter, or `FilesystemImporter('.')` to explicitly
56-
/// preserve the existing behavior.
57-
@Deprecated(
58-
"Use FilesystemImporter.noLoadPath or FilesystemImporter('.') instead.",
59-
)
60-
static final cwd = FilesystemImporter._deprecated('.');
61-
62-
/// Creates an importer that _only_ loads absolute `file:` URLs and URLs
63-
/// relative to the current file.
44+
/// An importer that _only_ loads absolute `file:` URLs and URLs relative to
45+
/// the current file.
6446
static final noLoadPath = FilesystemImporter._noLoadPath();
6547

6648
Uri? canonicalize(Uri url) {

lib/src/importer/js_to_dart/async_file.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ final class JSToDartAsyncFileImporter extends AsyncImporter {
2727
JSToDartAsyncFileImporter(this._findFileUrl);
2828

2929
FutureOr<Uri?> canonicalize(Uri url) async {
30-
if (url.scheme == 'file') return FilesystemImporter.cwd.canonicalize(url);
30+
if (url.scheme == 'file') {
31+
return FilesystemImporter.noLoadPath.canonicalize(url);
32+
}
3133

3234
var result = wrapJSExceptions(
3335
() => _findFileUrl(url.toString(), canonicalizeContext),
@@ -48,16 +50,16 @@ final class JSToDartAsyncFileImporter extends AsyncImporter {
4850
);
4951
}
5052

51-
return FilesystemImporter.cwd.canonicalize(resultUrl);
53+
return FilesystemImporter.noLoadPath.canonicalize(resultUrl);
5254
}
5355

54-
ImporterResult? load(Uri url) => FilesystemImporter.cwd.load(url);
56+
ImporterResult? load(Uri url) => FilesystemImporter.noLoadPath.load(url);
5557

5658
DateTime modificationTime(Uri url) =>
57-
FilesystemImporter.cwd.modificationTime(url);
59+
FilesystemImporter.noLoadPath.modificationTime(url);
5860

5961
bool couldCanonicalize(Uri url, Uri canonicalUrl) =>
60-
FilesystemImporter.cwd.couldCanonicalize(url, canonicalUrl);
62+
FilesystemImporter.noLoadPath.couldCanonicalize(url, canonicalUrl);
6163

6264
bool isNonCanonicalScheme(String scheme) => scheme != 'file';
6365
}

lib/src/importer/js_to_dart/file.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ final class JSToDartFileImporter extends Importer {
2222
JSToDartFileImporter(this._findFileUrl);
2323

2424
Uri? canonicalize(Uri url) {
25-
if (url.scheme == 'file') return FilesystemImporter.cwd.canonicalize(url);
25+
if (url.scheme == 'file') {
26+
return FilesystemImporter.noLoadPath.canonicalize(url);
27+
}
2628

2729
var result = wrapJSExceptions(
2830
() => _findFileUrl(url.toString(), canonicalizeContext),
@@ -50,16 +52,16 @@ final class JSToDartFileImporter extends Importer {
5052
);
5153
}
5254

53-
return FilesystemImporter.cwd.canonicalize(resultUrl);
55+
return FilesystemImporter.noLoadPath.canonicalize(resultUrl);
5456
}
5557

56-
ImporterResult? load(Uri url) => FilesystemImporter.cwd.load(url);
58+
ImporterResult? load(Uri url) => FilesystemImporter.noLoadPath.load(url);
5759

5860
DateTime modificationTime(Uri url) =>
59-
FilesystemImporter.cwd.modificationTime(url);
61+
FilesystemImporter.noLoadPath.modificationTime(url);
6062

6163
bool couldCanonicalize(Uri url, Uri canonicalUrl) =>
62-
FilesystemImporter.cwd.couldCanonicalize(url, canonicalUrl);
64+
FilesystemImporter.noLoadPath.couldCanonicalize(url, canonicalUrl);
6365

6466
bool isNonCanonicalScheme(String scheme) => scheme != 'file';
6567
}

0 commit comments

Comments
 (0)