Implicit Integration
In this guide, users will learn tips and recommendations on using OnePub with the Dart CLI tools.
OnePub supports both explicit and implicit integration.
Recommendation: It is recommended to use explicit Integration unless you have an Enterprise license.
Personally, we recommend using Explicit Integration as it allows the users to make the most of OnePub at the cost of a minor change to each of their pubspec.yaml files.
Explicit Integration
With explicit integration, a user needs to modify each pubspec.yaml
file that uses or publishes a private package.
Pros
Only requires the user to run
onepub login
and they are fully configuredusing
publish_to
in your pubspec stops the package from being accidentally published to pub.devDependencies work for other users without any environment configuration
No configuration is required for your IDE
Cons
Users need to explicitly configure each Private Dependency
Configure a package to be published to OnePub
You can edit your pubspec.yaml
file manually or use the onepub private
command. The outcome is the same, using the onepub command is faster.
Use the onepub private command.
Manually edit pubspec.yaml
Login to OnePub and copy the `publish_to:` url from the profile page:
Add a publish_to
key to your pubspec.yaml
.
Now publish your package
Configure a OnePub dependency
Once you have published a package to OnePub you are going to want to update your projects to use the package from OnePub.
You can either manually edit your pubspec.yaml
or use the onepub cli tools to do the work for you.
Use the onepub add command
To add or change a package dependency to get the package from OnePub run:
Use the --dev
switch to add the package as a dev dependency.
If the package already exists as a dependency the onepub will simply update the hosted-url to point to OnePub.
Manually configure a OnePub dependency
For each project that depends on a private package, you can add a hosted key.
Copy the 'publish_to' URL from your profile page:
Now paste it into the 'hosted' key for the package.
If your dart version is older than 2.15, then you must use the older hosted format.
Implicit Integration
Implicit Integration involves setting the PUB_HOSTED_URL environment variable.
Copy the publish_to
url from your profile page:
Now add the PUB_HOSTED_URL environment variable to your system.
Add an export statement to your ~/.bashrc file:
export PUB_HOSTED_URL=https://onepub.dev/api/xxxxxxx
Restart your shell and check the environment variable is available.
Once it is configured, all requests made by the pub command are sent to your OnePub private repo.
This method is still able to get public packages.
Pros
No need to configure each package and dependency
Restrict devs to only using packages from verified publishers (Enterprise Edition)
Constrain what packages your team can use via a OnePub curated list (Enterprise Edition)
Cons
Users need to configure an environment variable
Risk of users accidentally publishing a private to pub.dev
Last updated