Skip to content

Commit

Permalink
Exports algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesnw committed Nov 1, 2023
1 parent 6895b57 commit 880ad5a
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/src/importer/node_package.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ Uri? resolvePackageExports(Uri packageRoot, String subpath,
var resolvedIndexpaths =
_nodePackageExportsResolve(packageRoot, subpathIndexVariants, exports);

if (resolvedIndexpaths.length == 1) return resolvedPaths.first;
if (resolvedIndexpaths.length == 1) return resolvedIndexpaths.first;
if (resolvedIndexpaths.length > 1) {
throw "Unable to determine which of multiple potential"
"resolutions found for $subpath in $packageName should be used.";
Expand All @@ -169,10 +169,18 @@ List<Uri> _nodePackageExportsResolve(
Uri packageRoot, List<String> subpathVariants, Object exports) {
Uri? processVariant(String subpath) {
if (subpath == '') {
// main export
Object? mainExport = _getMainExport(exports);
if (mainExport == null) return null;
return _packageTargetResolve(subpath, exports, packageRoot);
return _packageTargetResolve(subpath, mainExport, packageRoot);
} else {
if (exports is Map<String, dynamic> &&
exports.keys.every((key) => key.startsWith('.'))) {
var matchKey = "./$subpath";
if (exports.containsKey(matchKey)) {
return _packageTargetResolve(
matchKey, exports[matchKey] as Object, packageRoot);
}
}
}
return null;
}
Expand Down

0 comments on commit 880ad5a

Please sign in to comment.