unpub 1.0.0

Unpub build pub

Unpub is a private Dart Pub server for Enterprise, with a simple web interface to search and view packages information.

Screenshot

Usage via command line #

pub global activate unpub
unpub --database mongodb://localhost:27017/dart_pub # Replace this with production database uri

Unpub use mongodb as meta information store and file system as package(tarball) store by default.

Dart API is also available for further customization.

Usage via Dart API #

Example #

import 'package:unpub/unpub.dart' as unpub;

main(List<String> args) async {
  var basedir = '/path/to/basedir'; // Base directory to save pacakges
  var db = 'mongodb://localhost:27017/dart_pub'; // MongoDB uri

  var metaStore = unpub.MongoStore(db);
  await metaStore.db.open();

  var packageStore = unpub.FileStore(basedir);

  var app = unpub.App(
    metaStore: metaStore,
    packageStore: packageStore,
  );

  var server = await app.serve('0.0.0.0', 4000);
  print('Serving at http://${server.address.host}:${server.port}');
}

More options #

var app = unpub.App(
  // Specify upstream url, use https://pub.dev by default
  upstream: 'https://some-faster-mirror-of-pub-dev',

  // Http proxy to call googleapis to get uploader email
  googleapisProxy: 'http://i-can-visit-google'

  // If specified, unpub will use this email as uploader instead of requesting googleapis
  overrideUploaderEmail: 'dart-pub@my-company.com'
);

Package validator #

Naming conflicts is a common issue for private registry. A reasonable solution is to add prefix to reduce conflict probability.

With uploadValidator you could check if uploaded package is valid.

var app = unpub.App(
  // ...
  uploadValidator: (Map<String, dynamic> pubspec, String uploaderEmail) {
    // Only allow packages with some specified prefixes to be uploaded
    var prefix = 'my_awesome_prefix_';
    var name = pubspec['name'] as String;
    if (!name.startsWith(prefix)) {
      throw 'Package name should starts with $prefix';
    }

    // Also, you can check if uploader email is valid
    if (!uploaderEmail.endsWith('@your-company.com')) {
      throw 'Uploader email invalid';
    }
  }
);

Customize meta and package Store #

Unpub is designed to be extensible. It is quite easy to customize your own meta store and package store.

class MyAwesomeMetaStore extends unpub.MetaStore {
  // Implement methods of MetaStore abstract class
  // ...
}

class MyAwesomePackageStore extends unpub.PackageStore {
  // ...
}

// Then use it
var app = unpub.App(
  metaStore: MyAwesomeMetaStore(),
  packageStore: MyAwesomePackageStore(),
)

Alternatives #

  • pub-dev: Source code of pub.dev, which should be deployed at Google Cloud Platform.
  • pub_server: An alpha version of pub server provided by Dart team.

Credits #

Web page styles are mostly imported from https://pub.dev directly.

License #

MIT

1.0.0 #

0.4.0 #

0.3.0 #

0.2.2 #

0.2.1 #

0.2.0 #

  • Refactor
  • Semver whitelist

0.1.1 #

  • Get email via Google APIs
  • Upload validator

0.1.0 #

  • pub get
  • pub publish with permission check

0.0.1 #

  • Initial version, created by Stagehand

example/main.dart

import 'package:unpub/unpub.dart' as unpub;

main(List<String> args) async {
  var basedir = '/path/to/basedir'; // Base directory to save pacakges
  var db = 'mongodb://localhost:27017/dart_pub'; // MongoDB uri

  var metaStore = unpub.MongoStore(db);
  await metaStore.db.open();

  var packageStore = unpub.FileStore(basedir);

  var app = unpub.App(
    metaStore: metaStore,
    packageStore: packageStore,
  );

  var server = await app.serve('0.0.0.0', 4000);
  print('Serving at http://${server.address.host}:${server.port}');
}

Use this package as an executable

1. Install it

You can install the package from the command line:


$ pub global activate unpub

2. Use it

The package has the following executables:


$ unpub

Use this package as a library

1. Depend on it

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


dependencies:
  unpub: ^1.0.0

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:unpub/unpub.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
19
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
57
Learn more about scoring.

We analyzed this package on Jul 20, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, other

Primary library: package:unpub/unpub.dart with components: io.

Health issues and suggestions

Document public APIs. (-1 points)

59 out of 59 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/src/models.g.dart. (-0.50 points)

Analysis of lib/src/models.g.dart reported 1 hint:

line 60 col 22: The function '_$UnpubPackageToJson' isn't used.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (googleapis).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.3.0 <3.0.0
archive ^2.0.8 2.0.10
args ^1.5.1 1.5.2
googleapis ^0.53.0 0.53.0 0.54.0
http ^0.12.0 0.12.0+2
http_parser ^3.1.3 3.1.3
intl ^0.15.8 0.15.8
json_annotation ^2.1.0 2.4.0
logging ^0.11.3 0.11.3+2
meta ^1.1.7 1.1.7
mime ^0.9.6+3 0.9.6+3
mongo_dart ^0.3.4 0.3.5
path ^1.6.2 1.6.2
pub_semver ^1.4.2 1.4.2
shelf ^0.7.5 0.7.5
shelf_router ^0.7.0 0.7.1
yaml ^2.1.15 2.1.16
Transitive dependencies
_discoveryapis_commons 0.1.8+1
async 2.3.0
bson 0.3.2
charcode 1.1.2
convert 2.1.1
crypto 2.0.6
fixnum 0.10.9
http_methods 1.0.0
mongo_dart_query 0.3.2
more 1.18.0
pool 1.4.0
source_span 1.5.5
stack_trace 1.9.3
stream_channel 2.0.0
string_scanner 1.0.4
term_glyph 1.1.0
typed_data 1.1.6
uuid 2.0.2
Dev dependencies
build_runner ^1.0.0
collection ^1.14.11 1.14.11
dart_style ^1.2.7
json_serializable ^2.0.0
pedantic ^1.0.0 1.8.0+1
shelf_router_generator ^0.7.1
test ^1.6.1

Admin