Skip to content

Introduce: dart pub add --dry-run --json #3333

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

Open
jonasfj opened this issue Mar 7, 2022 · 5 comments
Open

Introduce: dart pub add --dry-run --json #3333

jonasfj opened this issue Mar 7, 2022 · 5 comments
Labels
type-enhancement A request for a change that isn't a bug

Comments

@jonasfj
Copy link
Member

jonasfj commented Mar 7, 2022

We probably want dart pub add --dry-run --json to output something along the lines of:

$ dart pub add pem --dry-run --json
{
  // Text representation of the changes made, this includes multiple lines.
  // This may also include warnings of outdated, discontinued, retracted packages, etc.
  // This is intended as human readable text that printed to a log, a debug log, or simply ignored and discarded.
  "summary": "+ meta 1.7.0\n+ pem 2.0.0\n+ petitparser 4.4.0\nWill change 3 dependencies.\n",
  // Changes to be made to files on disk
  "changes": [
    {
      "file": "pubspec.yaml",
      "edits": [
        // compatible with SourceEdit for analysis_server
        {"offset": 100, "length": 0, "replacement": "  pem: ^2.0.0\n"},
      ],
    },
  ],
}

Just like other dart pub commands this will:

  • Require pubspec.yaml and pubspec.lock to be located in CWD (or specified using dart pub add ... --directory path/to/myapp/),
  • Modify files in $PUB_CACHE (notably caching version listings).
@sigurdm
Copy link
Contributor

sigurdm commented Mar 8, 2022

Do we know how SourceEdit computes offsets? Is it dart string based (number of utf16 code-units) or byte-offset in the file (or something else entirely?)

@jonasfj
Copy link
Member Author

jonasfj commented Mar 9, 2022

I'm closing this because it's unclear if this will be useful for analysis_server. The problem is that even if analysis_server can inject the fix into pubspec.yaml and pubspec.lock, it won't be able to patch .dart_tool/package_config.json, or download package files into $PUB_CACHE. Thus, the UX of this through analysis_server won't be great.

Anyone who needs this feel free to reopen.

@jonasfj
Copy link
Member Author

jonasfj commented May 12, 2022

Hmm, on second thought if the IDE only updates pubspec.yaml, then the IDE should encourage the user to run dart pub get because modification-times has changed. So maybe this isn't such a bad option, it's just that user will have to save pubspec.yaml and run dart pub get -- but other proposals for quick-fix (dart-lang/sdk#48998) also ends up involving this.

@jonasfj
Copy link
Member Author

jonasfj commented May 12, 2022

@pq what is the time budget available for generating a quick-fix? How fast would dart pub add --json --dry-run have to be, for this to be an option?

@sigurdm sigurdm reopened this May 12, 2022
@pq
Copy link
Member

pq commented May 12, 2022

We haven't measured this but it should be very fast. The rub is that until fixes are calculated, we can't communicate (via an affordance in the IDE) that there are fixes available. For example:

image

RE: analysis server integration, I do wonder if we couldn't cache the result. In that case we might be able to tolerate a slow(er) first response with the promise of subsequent results being instantaneous.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

3 participants