pub_server 0.1.5

  • Readme
  • Changelog
  • Example
  • Installing
  • 55

Provides re-usable code for making a Dart package repository server. The package:pub_server/shelf_pubserver.dart library provides a shelf HTTP handler which provides the HTTP API used by the pub client. One can use different backend implementations by implementing the PackageRepository interface of the package:pub_server/repository.dart library.

Example pub repository server #

An experimental pub server based on a file system can be found in example/example.dart. It uses a filesystem-based PackageRepository for storing packages and has a read-only fallback to the real site, if a package is not available locally. This allows one to use all packages and have additional ones, on top of the publicly available packages, available only locally.

It can be run as follows

~ $ git clone
~ $ cd pub_server
~/pub_server $ pub get
~/pub_server $ dart example/example.dart -d /tmp/package-db
Listening on http://localhost:8080

To make the pub client use this repository configure your shell via:

    $ export PUB_HOSTED_URL=http://localhost:8080

Using it for uploading new packages to the locally running server or downloading packages locally available or via a fallback to is as easy as:

~/foobar $ export PUB_HOSTED_URL=http://localhost:8080
~/foobar $ pub get
~/foobar $ pub publish
Publishing x 0.1.0 to http://localhost:8080:
|-- ...
'-- pubspec.yaml

Looks great! Are you ready to upload your package (y/n)? y
Successfully uploaded package.

The fact that the pub publish command requires you to grant it oauth2 access - which requires a Google account - is due to the fact that the pub publish cannot work without authentication or with another authentication scheme. But the information sent by the pub client is not used for this local server at the moment.

NOTE: This is package is an alpha version and is not recommended for production use.

0.1.5 #

  • Differentiate between client- and server-side upload issues.

0.1.4+2 #

  • Drop support for Dart 1.x.

0.1.4+1 #

  • Support Dart 2 stable releases.

  • Support latest release of package:pub_semver.

0.1.4 #

  • Dart 2 support with dart2_constant.

0.1.3 #

  • now has more specific return type: Future<Stream<List<int>>>.

  • Fix incorrect boundary parsing during upload.

  • Update minimum Dart SDK to 1.23.0.

0.1.2 #

  • Add support for generic exceptions raised e.g. due to pubspec.yaml validation failure.

0.1.1+4 #

  • Support the latest version of pkg/shelf.

0.1.1+3 #

  • Support the latest release of pub_semver.

0.1.1+2 #

  • Fixed null comparision.

0.1.1+1 #

  • Updated dependencies.

0.1.1 #

  • Return "400 Bad Request" in case the version number encoded in the URL is not a valid semantic version

0.1.0 #

Initial release.


// Copyright (c) 2014, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:io';

import 'package:args/args.dart';
import 'package:logging/logging.dart';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as shelf_io;
import 'package:http/http.dart' as http;
import 'package:pub_server/shelf_pubserver.dart';

import 'src/examples/cow_repository.dart';
import 'src/examples/file_repository.dart';
import 'src/examples/http_proxy_repository.dart';

final Uri pubDartLangOrg = Uri.parse('');

main(List<String> args) {
  var parser = argsParser();
  var results = parser.parse(args);

  var directory = results['directory'] as String;
  var host = results['host'] as String;
  var port = int.parse(results['port'] as String);
  var standalone = results['standalone'] as bool;

  if ( > 0) {
    print('Got unexpected arguments: "${' ')}".\n\nUsage:\n');

  runPubServer(directory, host, port, standalone);

runPubServer(String baseDir, String host, int port, bool standalone) {
  var client = new http.Client();

  var local = new FileRepository(baseDir);
  var remote = new HttpProxyRepository(client, pubDartLangOrg);
  var cow = new CopyAndWriteRepository(local, remote, standalone);

  var server = new ShelfPubServer(cow);
  print('Listening on http://$host:$port\n'
      'To make the pub client use this repository configure your shell via:\n'
      '    \$ export PUB_HOSTED_URL=http://$host:$port\n'

  return shelf_io.serve(
      const Pipeline()

ArgParser argsParser() {
  var parser = new ArgParser();

      abbr: 'd', defaultsTo: 'pub_server-repository-data');

  parser.addOption('host', abbr: 'h', defaultsTo: 'localhost');

  parser.addOption('port', abbr: 'p', defaultsTo: '8080');
  parser.addFlag('standalone', abbr: 's', defaultsTo: false);
  return parser;

void setupLogger() {
  Logger.root.onRecord.listen((LogRecord record) {
    var head = '${record.time} ${record.level} ${record.loggerName}';
    var tail = record.stackTrace != null ? '\n${record.stackTrace}' : '';
    print('$head ${record.message} $tail');

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  pub_server: ^0.1.5

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:pub_server/repository.dart';
import 'package:pub_server/shelf_pubserver.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Apr 8, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6

Health suggestions

Fix lib/shelf_pubserver.dart. (-14.39 points)

Analysis of lib/shelf_pubserver.dart reported 31 hints, including:

line 19 col 24: Unnecessary new keyword.

line 131 col 40: Unnecessary new keyword.

line 134 col 7: Unnecessary new keyword.

line 137 col 7: Unnecessary new keyword.

line 140 col 7: Unnecessary new keyword.

Fix lib/repository.dart. (-3.93 points)

Analysis of lib/repository.dart reported 8 hints, including:

line 27 col 15: Unnecessary new keyword.

line 112 col 7: Unnecessary new keyword.

line 133 col 13: Unnecessary new keyword.

line 147 col 13: Unnecessary new keyword.

line 151 col 13: Unnecessary new keyword.

Maintenance suggestions

Package is getting outdated. (-61.10 points)

The package was last published 84 weeks ago.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev <3.0.0
dart2_constant ^1.0.1 1.0.2+dart2
http_parser ^3.0.0 3.1.4
logging >=0.9.3 <1.0.0 0.11.4
mime >=0.9.3 <0.10.0 0.9.6+3
pub_semver ^1.1.0 1.4.4
shelf >=0.5.6 <0.8.0 0.7.5
yaml ^2.1.2 2.2.0
Transitive dependencies
async 2.4.1
charcode 1.1.3
collection 1.14.12
meta 1.1.8
source_span 1.7.0
stack_trace 1.9.3
stream_channel 2.0.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
archive >=1.0.0 <3.0.0
args ^1.4.0
http ^0.11.0
path ^1.5.1 1.6.4
test ^1.3.0