Skip to content
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

[Package Importer] Dart Implementation #2130

Merged
merged 122 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 116 commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
5e570c5
Export nodePackageImporter
jamesnw Oct 25, 2023
d01b7ac
Initial Node Package Importer
jamesnw Oct 25, 2023
c01c999
Merge branch 'sass:main' into feature.package-importer
jamesnw Oct 26, 2023
2360346
Add case for NodePackageImporter so embedded host compiles
jamesnw Oct 26, 2023
f1ce3a1
Hook up embedded
jamesnw Oct 27, 2023
2609525
Resolving package root, return absolute paths
jamesnw Oct 27, 2023
b0b8dab
Add recursive parent directory lookup for resolving package root
jamesnw Oct 30, 2023
b7f50f4
FilesystemImporter constructor should be internal
jamesnw Oct 30, 2023
6895b57
Start package exports resolve implementation
jamesnw Nov 1, 2023
880ad5a
Exports algorithm
jamesnw Nov 1, 2023
02f6bcc
Exports parsing
jamesnw Nov 2, 2023
c1929f0
Move subprocedures inside class, make private
jamesnw Nov 2, 2023
ef994ab
Hook up package importers for legacy
jamesnw Nov 2, 2023
99990b1
Handle entrypoint cases
jamesnw Nov 3, 2023
8518c67
Add node package importer to async
jamesnw Nov 3, 2023
aed5ea4
Add logs for debugging tests
jamesnw Nov 3, 2023
e22bfef
Use platform-specific separators
jamesnw Nov 3, 2023
bc2d0a7
Handling parsing windows paths to file name
jamesnw Nov 3, 2023
7718e8a
Add logs for Windows troubleshooting
jamesnw Nov 3, 2023
1bcfb4c
Only prepend on non-Windows
jamesnw Nov 4, 2023
7dec6d9
Merge branch 'main' of https://github.com/sass/dart-sass into feature…
jamesnw Nov 4, 2023
e84ff35
Add wildcard expansion
jamesnw Nov 6, 2023
d5763c4
Disable wildcard matching
jamesnw Nov 6, 2023
d24da96
Revert to resolvePackageRoot working on Posix
jamesnw Nov 6, 2023
535481d
Windows pathing
jamesnw Nov 6, 2023
ada3782
Move parentDir logic to io
jamesnw Nov 7, 2023
60f9892
Try separate pathing for windows
jamesnw Nov 7, 2023
51e5bba
Enable wildcards
jamesnw Nov 7, 2023
c391990
Document functions
jamesnw Nov 7, 2023
787d261
Revert incorrect @internal, add CacheImporter.only
jamesnw Nov 8, 2023
851fa6f
Fix legacy importer order bug
jamesnw Nov 8, 2023
99d7ad2
Remove debug print
jamesnw Nov 8, 2023
e63fb1b
Don't throw if pkg not found, load package.json with windows-friendly…
jamesnw Nov 8, 2023
ce5caea
Add logging statements
jamesnw Nov 8, 2023
69ec0ab
Add logging statements, v2
jamesnw Nov 8, 2023
c0e85a8
Add logging statements, v3
jamesnw Nov 8, 2023
f1936d9
Add logging statements, v4
jamesnw Nov 9, 2023
8da2895
Uri.file > Uri.directory
jamesnw Nov 9, 2023
1688531
Convert path to Uri to filestring
jamesnw Nov 9, 2023
a162636
Use file path
jamesnw Nov 9, 2023
e44215b
More filepath usage
jamesnw Nov 9, 2023
e69ce0c
Inspect entry values
jamesnw Nov 9, 2023
afc32bb
Remove duplicated separators
jamesnw Nov 9, 2023
aa7c5f4
Remove scheme from containing url
jamesnw Nov 9, 2023
0549d2f
Remove log statements
jamesnw Nov 9, 2023
757309e
Documentation comments
jamesnw Nov 13, 2023
75de009
Use FilesystemImporter.canonicalize for file: URLs
jamesnw Nov 16, 2023
ece578e
Handle invalid URL
jamesnw Nov 17, 2023
c22c8ca
Create FilesystemImporter cwd singleton
jamesnw Nov 17, 2023
091ed1f
Add missed FilesystemImporter cwd's
jamesnw Nov 17, 2023
e0e42b6
Undo accidental self reference
jamesnw Nov 17, 2023
6175ce9
Switch NodePackageImporter type to JSSymbol
jamesnw Nov 17, 2023
c0a47cd
Change entry point logic
jamesnw Nov 22, 2023
d3431ea
Address review
jamesnw Dec 1, 2023
4cdd953
Remove separate _filesystemImporter fields for FilesystemImporter.cwd
jamesnw Dec 1, 2023
e847921
Remove unneeded import
jamesnw Dec 1, 2023
5e637de
Sync
jamesnw Dec 1, 2023
2575b86
Address review
jamesnw Dec 1, 2023
f0bd0c0
Use switch expression
jamesnw Dec 1, 2023
3916b23
More review
jamesnw Dec 1, 2023
b4f4342
Handle invalid json, update _resolvePackageRootValues
jamesnw Dec 1, 2023
fadd73a
Use null for empty subpath
jamesnw Dec 1, 2023
ac58863
List the multiple matches in error
jamesnw Dec 1, 2023
6f8aacc
Refactor multiple match logic
jamesnw Dec 1, 2023
2f49a34
Refactor _nodePackageExportsResolve
jamesnw Dec 4, 2023
b4015ee
Adjust _packageNameAndSubpath comment
jamesnw Dec 4, 2023
0571ae7
Adjust _resolvePackateRoot
jamesnw Dec 4, 2023
e18ca15
Throw error if exports has both path and non-path keys
jamesnw Dec 4, 2023
d95d7fc
Reduce indent
jamesnw Dec 4, 2023
123b693
Clean up file paths
jamesnw Dec 4, 2023
b1b78ad
Revert to naive concat for Windows tests
jamesnw Dec 4, 2023
afbfade
Another Windows attempt
jamesnw Dec 4, 2023
6167fd8
Try parsing containing URL for windows
jamesnw Dec 4, 2023
e3fc592
Remove unneeded parentDir
jamesnw Dec 5, 2023
c9c6473
Link to Node spec
jamesnw Dec 8, 2023
7f6d15a
Clean up errors
jamesnw Dec 8, 2023
e5f795a
Merge branch 'main' of github.com:oddbird/dart-sass into feature.pack…
jamesnw Dec 11, 2023
0676529
Merge branch 'main' of https://github.com/sass/dart-sass into feature…
jamesnw Dec 11, 2023
3ead339
Merge branch 'main' into feature.package-importer
jgerigmeyer Dec 15, 2023
f3f43d4
Move to NodePackageImporter as class
jamesnw Dec 19, 2023
485a71f
Fix embedded param
jamesnw Dec 19, 2023
ed58590
Switch posix url context for bare import specifiers
jamesnw Dec 20, 2023
da3694a
Try using containingURL directly
jgerigmeyer Dec 20, 2023
ed7fe62
temp try logging path for windows
jgerigmeyer Dec 20, 2023
c8406a4
More temp code for Windows debugging
jgerigmeyer Dec 20, 2023
ade6fe2
Try using baseUrl.path
jgerigmeyer Dec 20, 2023
5481ca6
manual attempt to coerce windows path
jgerigmeyer Dec 20, 2023
b106be1
Try skipping Uri.directory
jgerigmeyer Dec 20, 2023
02e8dd1
Merge branch 'main' of https://github.com/sass/dart-sass into feature…
jamesnw Jan 3, 2024
0d2f859
Remove Internal from class
jamesnw Jan 3, 2024
b686cc1
Progress on path/uri cleanup
jamesnw Jan 4, 2024
038b2f4
Use paths in _exportsToCheck
jamesnw Jan 4, 2024
924612a
Update docs
jamesnw Jan 4, 2024
31b59f4
Update exportsToCheck, packageNameAndSubpath
jamesnw Jan 5, 2024
aaadfc7
More review updates
jamesnw Jan 5, 2024
f0985f3
Handle paths in _nodePackageExportsResolve
jamesnw Jan 5, 2024
e1329cc
Remove unneeded fromUri
jamesnw Jan 5, 2024
c3b1c8b
Review updates
jamesnw Jan 5, 2024
15e33b9
Address review
jgerigmeyer Jan 5, 2024
397b789
Add missing file.
jgerigmeyer Jan 5, 2024
069b272
update copyrights
jgerigmeyer Jan 5, 2024
aa56d07
Address review
jamesnw Jan 5, 2024
e0c712e
Switch recursive resolvePackateRoot to while
jamesnw Jan 8, 2024
915d6d9
Differentiate path and directory
jamesnw Jan 8, 2024
a3ddb06
Update package name handling
jamesnw Jan 8, 2024
89e4dba
Convert URL targets to native paths
jamesnw Jan 8, 2024
e5c1773
Ensure 'as Object' is not null
jamesnw Jan 8, 2024
8441b3b
Merge branch 'main' of https://github.com/sass/dart-sass into feature…
jamesnw Jan 17, 2024
e04b109
Merge branch 'main' of https://github.com/sass/dart-sass into feature…
jamesnw Jan 18, 2024
4820ecc
Update errors and paths
jamesnw Jan 19, 2024
521b1cf
Review cleanup
jamesnw Jan 19, 2024
0d4f2c6
Don't reject invalid node package names
jamesnw Jan 19, 2024
0434343
Check for no entryPointPath or file system in constructor
jamesnw Jan 19, 2024
1cb845c
Private and document valid extensions
jamesnw Jan 19, 2024
125acf3
Move absolute path logic into constructor
jamesnw Jan 19, 2024
0a4aa2f
Remove unused import
jamesnw Jan 19, 2024
8e60938
Address review
jamesnw Jan 20, 2024
7f2132a
Expose Node Package Importer directly to JS
jamesnw Jan 20, 2024
c9f9bc9
typo
jgerigmeyer Jan 24, 2024
7779cbc
Merge branch 'main' into feature.package-importer
jgerigmeyer Jan 24, 2024
2f878b0
Update entry point to directory
jamesnw Feb 1, 2024
53472fd
Use parent directory of containing URL
jamesnw Feb 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/src/async_compile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import 'visitor/serialize.dart';
/// Like [compileAsync] in `lib/sass.dart`, but provides more options to support
/// the node-sass compatible API and the executable.
///
/// At most one of `importCache` and `nodeImporter` may be provided at once.
/// If both `importCache` and `nodeImporter` are provided, the importers in
/// `importCache` will be evaluated before `nodeImporter`.
Future<CompileResult> compileAsync(String path,
{Syntax? syntax,
Logger? logger,
Expand Down Expand Up @@ -56,7 +57,7 @@ Future<CompileResult> compileAsync(String path,
(syntax == null || syntax == Syntax.forPath(path))) {
importCache ??= AsyncImportCache.none(logger: logger);
stylesheet = (await importCache.importCanonical(
FilesystemImporter('.'), p.toUri(canonicalize(path)),
FilesystemImporter.cwd, p.toUri(canonicalize(path)),
originalUrl: p.toUri(path)))!;
} else {
stylesheet = Stylesheet.parse(
Expand All @@ -69,7 +70,7 @@ Future<CompileResult> compileAsync(String path,
logger,
importCache,
nodeImporter,
FilesystemImporter('.'),
FilesystemImporter.cwd,
functions,
style,
useSpaces,
Expand Down Expand Up @@ -121,7 +122,7 @@ Future<CompileResult> compileStringAsync(String source,
logger,
importCache,
nodeImporter,
importer ?? (isBrowser ? NoOpImporter() : FilesystemImporter('.')),
importer ?? (isBrowser ? NoOpImporter() : FilesystemImporter.cwd),
functions,
style,
useSpaces,
Expand Down
6 changes: 6 additions & 0 deletions lib/src/async_import_cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ final class AsyncImportCache {
: _importers = const [],
_logger = logger ?? const Logger.stderr();

/// Creates an import cache without any globally-available importers, and only
/// the passed in importers.
AsyncImportCache.only(Iterable<AsyncImporter> importers, {Logger? logger})
: _importers = List.unmodifiable(importers),
_logger = logger ?? const Logger.stderr();

/// Converts the user's [importers], [loadPaths], and [packageConfig]
/// options into a single list of importers.
static List<AsyncImporter> _toImporters(Iterable<AsyncImporter>? importers,
Expand Down
11 changes: 6 additions & 5 deletions lib/src/compile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// DO NOT EDIT. This file was generated from async_compile.dart.
// See tool/grind/synchronize.dart for details.
//
// Checksum: 5178e366228bde7854df12221393857bb3022628
// Checksum: a9421a2975e79ad591ae32474cd076e1379d0e75
//
// ignore_for_file: unused_import

Expand Down Expand Up @@ -35,7 +35,8 @@ import 'visitor/serialize.dart';
/// Like [compile] in `lib/sass.dart`, but provides more options to support
/// the node-sass compatible API and the executable.
///
/// At most one of `importCache` and `nodeImporter` may be provided at once.
/// If both `importCache` and `nodeImporter` are provided, the importers in
/// `importCache` will be evaluated before `nodeImporter`.
CompileResult compile(String path,
{Syntax? syntax,
Logger? logger,
Expand Down Expand Up @@ -65,7 +66,7 @@ CompileResult compile(String path,
(syntax == null || syntax == Syntax.forPath(path))) {
importCache ??= ImportCache.none(logger: logger);
stylesheet = importCache.importCanonical(
FilesystemImporter('.'), p.toUri(canonicalize(path)),
FilesystemImporter.cwd, p.toUri(canonicalize(path)),
originalUrl: p.toUri(path))!;
} else {
stylesheet = Stylesheet.parse(
Expand All @@ -78,7 +79,7 @@ CompileResult compile(String path,
logger,
importCache,
nodeImporter,
FilesystemImporter('.'),
FilesystemImporter.cwd,
functions,
style,
useSpaces,
Expand Down Expand Up @@ -130,7 +131,7 @@ CompileResult compileString(String source,
logger,
importCache,
nodeImporter,
importer ?? (isBrowser ? NoOpImporter() : FilesystemImporter('.')),
importer ?? (isBrowser ? NoOpImporter() : FilesystemImporter.cwd),
functions,
style,
useSpaces,
Expand Down
5 changes: 5 additions & 0 deletions lib/src/embedded/compilation_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:native_synchronization/mailbox.dart';
import 'package:path/path.dart' as p;
import 'package:protobuf/protobuf.dart';
import 'package:sass/sass.dart' as sass;
import 'package:sass/src/importer/node_package.dart' as npi;

import '../logger.dart';
import '../value/function.dart';
Expand Down Expand Up @@ -226,6 +227,10 @@ final class CompilationDispatcher {
case InboundMessage_CompileRequest_Importer_Importer.notSet:
_checkNoNonCanonicalScheme(importer);
return null;

case InboundMessage_CompileRequest_Importer_Importer.nodePackageImporter:
return npi.NodePackageImporter(
importer.nodePackageImporter.entryPointPath);
}
}

Expand Down
12 changes: 3 additions & 9 deletions lib/src/embedded/importer/file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ import '../../importer.dart';
import '../embedded_sass.pb.dart' hide SourceSpan;
import 'base.dart';

/// A filesystem importer to use for most implementation details of
/// [FileImporter].
///
/// This allows us to avoid duplicating logic between the two importers.
final _filesystemImporter = FilesystemImporter('.');

/// An importer that asks the host to resolve imports in a simplified,
/// file-system-centric way.
final class FileImporter extends ImporterBase {
Expand All @@ -21,7 +15,7 @@ final class FileImporter extends ImporterBase {
FileImporter(super.dispatcher, this._importerId);

Uri? canonicalize(Uri url) {
if (url.scheme == 'file') return _filesystemImporter.canonicalize(url);
if (url.scheme == 'file') return FilesystemImporter.cwd.canonicalize(url);

var request = OutboundMessage_FileImportRequest()
..importerId = _importerId
Expand All @@ -39,7 +33,7 @@ final class FileImporter extends ImporterBase {
throw 'The file importer must return a file: URL, was "$url"';
}

return _filesystemImporter.canonicalize(url);
return FilesystemImporter.cwd.canonicalize(url);

case InboundMessage_FileImportResponse_Result.error:
throw response.error;
Expand All @@ -49,7 +43,7 @@ final class FileImporter extends ImporterBase {
}
}

ImporterResult? load(Uri url) => _filesystemImporter.load(url);
ImporterResult? load(Uri url) => FilesystemImporter.cwd.load(url);

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

Expand Down
6 changes: 3 additions & 3 deletions lib/src/executable/compile_stylesheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Future<(int, String, String?)?> compileStylesheet(ExecutableOptions options,
Future<void> _compileStylesheetWithoutErrorHandling(ExecutableOptions options,
StylesheetGraph graph, String? source, String? destination,
{bool ifModified = false}) async {
var importer = FilesystemImporter('.');
var importer = FilesystemImporter.cwd;
if (ifModified) {
try {
if (source != null &&
Expand Down Expand Up @@ -102,7 +102,7 @@ Future<void> _compileStylesheetWithoutErrorHandling(ExecutableOptions options,
syntax: syntax,
logger: options.logger,
importCache: importCache,
importer: FilesystemImporter('.'),
importer: FilesystemImporter.cwd,
style: options.style,
quietDeps: options.quietDeps,
verbose: options.verbose,
Expand All @@ -127,7 +127,7 @@ Future<void> _compileStylesheetWithoutErrorHandling(ExecutableOptions options,
syntax: syntax,
logger: options.logger,
importCache: graph.importCache,
importer: FilesystemImporter('.'),
importer: FilesystemImporter.cwd,
style: options.style,
quietDeps: options.quietDeps,
verbose: options.verbose,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/executable/repl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Future<void> repl(ExecutableOptions options) async {
var repl = Repl(prompt: '>> ');
var logger = TrackingLogger(options.logger);
var evaluator = Evaluator(
importer: FilesystemImporter('.'),
importer: FilesystemImporter.cwd,
importCache: ImportCache(loadPaths: options.loadPaths, logger: logger),
logger: logger);
await for (String line in repl.runAsync()) {
Expand Down
6 changes: 3 additions & 3 deletions lib/src/executable/watch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Future<void> watch(ExecutableOptions options, StylesheetGraph graph) async {
var sourcesToDestinations = _sourcesToDestinations(options);
for (var source in sourcesToDestinations.keys) {
graph.addCanonical(
FilesystemImporter('.'), p.toUri(canonicalize(source)), p.toUri(source),
FilesystemImporter.cwd, p.toUri(canonicalize(source)), p.toUri(source),
recanonicalize: false);
}
var success = await compileStylesheets(options, graph, sourcesToDestinations,
Expand Down Expand Up @@ -130,7 +130,7 @@ final class _Watcher {
await compileStylesheets(_options, _graph, {path: destination},
ifModified: true);
var downstream = _graph.addCanonical(
FilesystemImporter('.'), _canonicalize(path), p.toUri(path));
FilesystemImporter.cwd, _canonicalize(path), p.toUri(path));
return await _recompileDownstream(downstream) && success;
}

Expand All @@ -144,7 +144,7 @@ final class _Watcher {
if (_destinationFor(path) case var destination?) _delete(destination);
}

var downstream = _graph.remove(FilesystemImporter('.'), url);
var downstream = _graph.remove(FilesystemImporter.cwd, url);
return await _recompileDownstream(downstream);
}

Expand Down
8 changes: 7 additions & 1 deletion lib/src/import_cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// DO NOT EDIT. This file was generated from async_import_cache.dart.
// See tool/grind/synchronize.dart for details.
//
// Checksum: 342e907cf10e1dd80d7045fc32db43c74376654e
// Checksum: d157b83599dbc07a80ac6cb5ffdf5dde03b60376
//
// ignore_for_file: unused_import

Expand Down Expand Up @@ -106,6 +106,12 @@ final class ImportCache {
: _importers = const [],
_logger = logger ?? const Logger.stderr();

/// Creates an import cache without any globally-available importers, and only
/// the passed in importers.
ImportCache.only(Iterable<Importer> importers, {Logger? logger})
: _importers = List.unmodifiable(importers),
_logger = logger ?? const Logger.stderr();

/// Converts the user's [importers], [loadPaths], and [packageConfig]
/// options into a single list of importers.
static List<Importer> _toImporters(Iterable<Importer>? importers,
Expand Down
3 changes: 3 additions & 0 deletions lib/src/importer/filesystem.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class FilesystemImporter extends Importer {
/// Creates an importer that loads files relative to [loadPath].
FilesystemImporter(String loadPath) : _loadPath = p.absolute(loadPath);

/// Creates an importer relative to the current working directory.
static final cwd = FilesystemImporter('.');

Uri? canonicalize(Uri url) {
if (url.scheme != 'file' && url.scheme != '') return null;
return resolveImportPath(p.join(_loadPath, p.fromUri(url)))
Expand Down
11 changes: 11 additions & 0 deletions lib/src/importer/js_node_package.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2024 Google Inc. 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.

/// The JS [NodePackageImporter] class that can be added to the
/// `importers` option to enable loading `pkg:` URLs from `node_modules`.
class JSNodePackageImporter {
jgerigmeyer marked this conversation as resolved.
Show resolved Hide resolved
final String? entryPointPath;

JSNodePackageImporter(this.entryPointPath);
}
16 changes: 5 additions & 11 deletions lib/src/importer/js_to_dart/async_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ import '../filesystem.dart';
import '../result.dart';
import '../utils.dart';

/// A filesystem importer to use for most implementation details of
/// [JSToDartAsyncFileImporter].
///
/// This allows us to avoid duplicating logic between the two importers.
final _filesystemImporter = FilesystemImporter('.');

/// A wrapper for a potentially-asynchronous JS API file importer that exposes
/// it as a Dart [AsyncImporter].
final class JSToDartAsyncFileImporter extends AsyncImporter {
Expand All @@ -32,7 +26,7 @@ final class JSToDartAsyncFileImporter extends AsyncImporter {
JSToDartAsyncFileImporter(this._findFileUrl);

FutureOr<Uri?> canonicalize(Uri url) async {
if (url.scheme == 'file') return _filesystemImporter.canonicalize(url);
if (url.scheme == 'file') return FilesystemImporter.cwd.canonicalize(url);

var result = wrapJSExceptions(() => _findFileUrl(
url.toString(),
Expand All @@ -52,16 +46,16 @@ final class JSToDartAsyncFileImporter extends AsyncImporter {
'"$url".'));
}

return _filesystemImporter.canonicalize(resultUrl);
return FilesystemImporter.cwd.canonicalize(resultUrl);
}

ImporterResult? load(Uri url) => _filesystemImporter.load(url);
ImporterResult? load(Uri url) => FilesystemImporter.cwd.load(url);

DateTime modificationTime(Uri url) =>
_filesystemImporter.modificationTime(url);
FilesystemImporter.cwd.modificationTime(url);

bool couldCanonicalize(Uri url, Uri canonicalUrl) =>
_filesystemImporter.couldCanonicalize(url, canonicalUrl);
FilesystemImporter.cwd.couldCanonicalize(url, canonicalUrl);

bool isNonCanonicalScheme(String scheme) => scheme != 'file';
}
16 changes: 5 additions & 11 deletions lib/src/importer/js_to_dart/file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ import '../../js/utils.dart';
import '../../util/nullable.dart';
import '../utils.dart';

/// A filesystem importer to use for most implementation details of
/// [JSToDartAsyncFileImporter].
///
/// This allows us to avoid duplicating logic between the two importers.
final _filesystemImporter = FilesystemImporter('.');

/// A wrapper for a potentially-asynchronous JS API file importer that exposes
/// it as a Dart [AsyncImporter].
final class JSToDartFileImporter extends Importer {
Expand All @@ -27,7 +21,7 @@ final class JSToDartFileImporter extends Importer {
JSToDartFileImporter(this._findFileUrl);

Uri? canonicalize(Uri url) {
if (url.scheme == 'file') return _filesystemImporter.canonicalize(url);
if (url.scheme == 'file') return FilesystemImporter.cwd.canonicalize(url);

var result = wrapJSExceptions(() => _findFileUrl(
url.toString(),
Expand All @@ -51,16 +45,16 @@ final class JSToDartFileImporter extends Importer {
'"$url".'));
}

return _filesystemImporter.canonicalize(resultUrl);
return FilesystemImporter.cwd.canonicalize(resultUrl);
}

ImporterResult? load(Uri url) => _filesystemImporter.load(url);
ImporterResult? load(Uri url) => FilesystemImporter.cwd.load(url);

DateTime modificationTime(Uri url) =>
_filesystemImporter.modificationTime(url);
FilesystemImporter.cwd.modificationTime(url);

bool couldCanonicalize(Uri url, Uri canonicalUrl) =>
_filesystemImporter.couldCanonicalize(url, canonicalUrl);
FilesystemImporter.cwd.couldCanonicalize(url, canonicalUrl);

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