Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CP] Fix "dart pub publish" to 3rd-party package repository with path in the hosted-url #47815

Closed
jonasfj opened this issue Nov 30, 2021 · 7 comments
Labels
area-dart-cli Use area-dart-cli for issues related to the 'dart' command like tool. cherry-pick-approved Label for approved cherrypick request merge-to-stable

Comments

@jonasfj
Copy link
Member

jonasfj commented Nov 30, 2021

commit(s) to merge: sdk/+/221626 adds the following commit dart-lang/pub@b9edfa5 to pub (on-top of the previous cherry-pick).

merge instructions: Should merge clean.

What is the issue: Running dart pub publish with a custom pub package server that has a URL containing a path will not work.

What is the fix: Instead of uri.resolve('/api/versions/new') we do uri.resolve('api/versions/new'). Such that PUB_HOSTED_URL=https://pub.example.com/user becomes https://pub.example.com/user/api/versions/new.
Note, we've already normalized PUB_HOSTED_URL and publish_to URLs to always end in slash, if path is non-empty, see validateAndNormalizeHostedUrl.

Why cherrypick: Efforts of cloudsmith to finish support for publishing from pub command line is blocked this, as they have organization and repository embedded in the URL.

Risk: Small, the official pub repository URL doesn't have path segments so the change has no effect there.

/cc @mit-mit @whesse @athomas @vsmenon @devoncarew

@jonasfj jonasfj added the cherry-pick-review Issue that need cherry pick triage to approve label Nov 30, 2021
@athomas
Copy link
Member

athomas commented Dec 1, 2021

We have decided to not pick this change into 2.15.0. It will be released on dev and beta soon. This change arrived too late, has not rolled all the way, not being published on dev or other channels. The CP request is left open for consideration for 2.15.1.

@devoncarew
Copy link
Member

resolution: this is approved to cherry pick (in our first set of post-release cherry picks)

@devoncarew devoncarew added cherry-pick-approved Label for approved cherrypick request and removed cherry-pick-review Issue that need cherry pick triage to approve labels Dec 2, 2021
@a-siva a-siva added the area-dart-cli Use area-dart-cli for issues related to the 'dart' command like tool. label Jan 4, 2022
@devoncarew
Copy link
Member

I believe this was already cherry picked in, in 2.15.1 (https://github.com/flutter/flutter/wiki/Hotfixes-to-the-Stable-Channel#281-december-16-2021).

@Sunbreak
Copy link

https://github.com/woodemi/quick_blue/tree/reproduce/publish_to

`publish_to`: https://pub.dartlang.org 

flutter pub publish failed however

wangkun42@bogon quick_blue_platform_interface % echo $HTTPS_PROXY
127.0.0.1:1087
wangkun42@bogon quick_blue_platform_interface % echo $PUB_HOSTED_URL
https://pub.flutter-io.cn
wangkun42@bogon quick_blue_platform_interface % flutter2.8.x pub publish
Publishing quick_blue_platform_interface 0.3.2+1 to https://pub.dartlang.org:
|-- CHANGELOG.md
|-- LICENSE
|-- README.md
|-- lib
|   |-- method_channel_quick_blue.dart
|   |-- models.dart
|   '-- quick_blue_platform_interface.dart
'-- pubspec.yaml

Publishing is forever; packages cannot be unpublished.
Policy details are available at https://pub.dev/policy

Do you want to publish quick_blue_platform_interface 0.3.2+1 (y/N)? y
Uploading...
Invalid `publish_to` value: `https://pub.dartlang.org`.
pub finished with exit code 1

@jonasfj
Copy link
Member Author

jonasfj commented Mar 21, 2022

@Sunbreak, yeah, I just recalled that publish_to: is not allowed when published to pub.dev.
I would suggest doing: tool/publish.sh like:

#!/bin/bash

export PUB_HOSTED_URL="";
dart pub publish

Then using that instead of dart pub publish in your case..


Note. I'm pretty sure this is completely unrelated to the issue being discussed here.

@AlexV525
Copy link
Contributor

publish_to: is not allowed when published to pub.dev.

@jonasfj Is this intentional? When we're trying to use our mirror site, but want to publish the package to pub.dev forever, there's nothing else we can do.

@jonasfj
Copy link
Member Author

jonasfj commented May 11, 2022

@AlexV525 yes, it's intentional. Why would you want to include publish_to in a package that's going to be published on pub.dev

Then it would have to say: publish_to: https://pub.dev, which is the default, so why not omit it?

The motivation for forbidding it was that we once changed hostname from pub.dartlang.org to pub.dev. And in fact you'll see still pub.dartlang.org in pubspec.lock, it's also still the URL used by the client, we just moved the public website.
So it would be very confusing if the public website was pub.dev, but the publish_to: value was publish_to: https://pub.dartlang.org.
And it would get even more confusing when at some point we change the client to use pub.dev instead of pub.dartlang.org.

So if publishing to the default package repository, you have to omit publish_to. In general, the key is there so you avoid accidentally publishing to pub.dev. IMO, it's better to make a tool like tool/publish.sh that modifies your pubspec.yaml, creates a commit, git tag, pushes the git tag, and then publishes to pub.dev. That way you also ensure that you have the code tagged in github.


If you have a use-case where this makes sense, please open an issue/question on https://github.com/dart-lang/pub/issues explain the use-case and feel free to CC me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-dart-cli Use area-dart-cli for issues related to the 'dart' command like tool. cherry-pick-approved Label for approved cherrypick request merge-to-stable
Projects
None yet
Development

No branches or pull requests

6 participants