resolvePackageConfigFile static method
Returns the .dart_tool/package_config.json that dart run uses in
workingDirectory (default: the current directory): the first one
found in it or in a parent directory. Returns null if there's none.
Used by runDartVM to pass --packages explicitly for a kernel
entrypoint (see its packageConfig parameter).
Implementation
static File? resolvePackageConfigFile({String? workingDirectory}) {
// Normalized: `Directory.parent` is lexical, so for an un-normalized path
// (`/a/pkg/../other`) the walk would visit `/a/pkg`, which isn't an
// ancestor of `/a/other`, and could pick up the wrong package config.
var dir = Directory(
pack_path.normalize(
(workingDirectory != null
? Directory(workingDirectory)
: Directory.current)
.absolute
.path,
),
);
while (true) {
var file = _packageConfigFile(dir);
if (file.existsSync()) return file;
var parent = dir.parent;
// The root directory is its own parent:
if (parent.path == dir.path) return null;
dir = parent;
}
}