in lib/src/global_packages.dart [598:686]
void _updateBinStubs(
Entrypoint entrypoint, Package package, List<String>? executables,
{required bool overwriteBinStubs, bool suggestIfNotOnPath = true}) {
// Remove any previously activated binstubs for this package, in case the
// list of executables has changed.
_deleteBinStubs(package.name);
if ((executables != null && executables.isEmpty) ||
package.pubspec.executables.isEmpty) {
return;
}
ensureDir(_binStubDir);
var installed = <String>[];
var collided = <String, String>{};
var allExecutables = ordered(package.pubspec.executables.keys);
for (var executable in allExecutables) {
if (executables != null && !executables.contains(executable)) continue;
var script = package.pubspec.executables[executable]!;
var previousPackage = _createBinStub(
package,
executable,
script,
overwrite: overwriteBinStubs,
snapshot: entrypoint.pathOfExecutable(
exec.Executable.adaptProgramName(package.name, script),
),
);
if (previousPackage != null) {
collided[executable] = previousPackage;
if (!overwriteBinStubs) continue;
}
installed.add(executable);
}
if (installed.isNotEmpty) {
var names = namedSequence('executable', installed.map(log.bold));
log.message('Installed $names.');
}
// Show errors for any collisions.
if (collided.isNotEmpty) {
for (var command in ordered(collided.keys)) {
if (overwriteBinStubs) {
log.warning('Replaced ${log.bold(command)} previously installed from '
'${log.bold(collided[command])}.');
} else {
log.warning('Executable ${log.bold(command)} was already installed '
'from ${log.bold(collided[command])}.');
}
}
if (!overwriteBinStubs) {
log.warning('Deactivate the other package(s) or activate '
'${log.bold(package.name)} using --overwrite.');
}
}
// Show errors for any unknown executables.
if (executables != null) {
var unknown = ordered(executables
.where((exe) => !package.pubspec.executables.keys.contains(exe)));
if (unknown.isNotEmpty) {
dataError("Unknown ${namedSequence('executable', unknown)}.");
}
}
// Show errors for any missing scripts.
// TODO(rnystrom): This can print false positives since a script may be
// produced by a transformer. Do something better.
var binFiles = package.executablePaths;
for (var executable in installed) {
var script = package.pubspec.executables[executable];
var scriptPath = p.join('bin', '$script.dart');
if (!binFiles.contains(scriptPath)) {
log.warning('Warning: Executable "$executable" runs "$scriptPath", '
'which was not found in ${log.bold(package.name)}.');
}
}
if (suggestIfNotOnPath && installed.isNotEmpty) {
_suggestIfNotOnPath(installed.first);
}
}