checkGlobalInstallPermissions method

Future<({bool hasPermissions, String? npmPrefix})> checkGlobalInstallPermissions()

Check global install permissions.

Implementation

Future<({bool hasPermissions, String? npmPrefix})>
checkGlobalInstallPermissions() async {
  try {
    final prefix = await _getInstallationPrefix();
    if (prefix == null) {
      return (hasPermissions: false, npmPrefix: null);
    }

    try {
      // Check write access
      final dir = Directory(prefix);
      if (dir.existsSync()) {
        return (hasPermissions: true, npmPrefix: prefix);
      }
      return (hasPermissions: false, npmPrefix: prefix);
    } catch (_) {
      return (hasPermissions: false, npmPrefix: prefix);
    }
  } catch (_) {
    return (hasPermissions: false, npmPrefix: null);
  }
}