Skip to content

Allow Pubspec.yaml to supply missing SDK libraries (dart:io, dart:html, etc.) #37232

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
terrier989 opened this issue Jun 11, 2019 · 2 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. type-enhancement A request for a change that isn't a bug

Comments

@terrier989
Copy link

It would be helpful if something like this was possible:

dependency_overrides:
  "dart:io": universal_io

This would enable use packages like universal_io and universal_html without forking dependencies just to replace imports.

Proposed details:

  • The dependency override would be ignored if the target already supports dart:L.
  • The effect would be equal to replacing imports of dart:L with package:P/L.dart.
  • Behavior of configured imports would not be affected. Condition in if (dart.library.io) 'library.dart' would false in Dart2js even if dart:io was supplied with a dependency override.
@devoncarew devoncarew added the area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. label Jun 11, 2019
@devoncarew
Copy link
Member

I'm not sure where to best file this feature request - tentatively assigning to area-library.

@devoncarew devoncarew added the type-enhancement A request for a change that isn't a bug label Jun 11, 2019
@terrier989 terrier989 changed the title Support dependency overrides for dart:io and dart:html Allow Pubspec.yaml to supply missing SDK libraries (dart:io, dart:html, etc.) Jun 13, 2019
@terrier989
Copy link
Author

This feature could provide at least temporary help to Flutter web team, which seems to be thinking about cross-platform issues such as missing dart:io (#35969) and dart:developer (#36649). Angular would get server-side rendering in Dart VM (#225).

The proposal could be simplified by using prefix "__" for supplying SDK libraries ("__io", "__html", etc.). This feature would be just a preprocessor in the Dart frontend. In pseudo code:

when the preprocessor sees "import/export dart:L":
  if target SDK doesn't have library "dart:L" and Pub has added "__L:file://path" in ".packages" file:
    replace "dart:L" with "package:__L/L.dart"

With "__libraryName" convention, Pub doesn't need changes. Pub already generates ".packages" file when pubspec.yaml is:

dependency_overrides:
  # This supplies dart:io to Dart2js
  __io:
    git: "https://github.com/some/repository" # Package name must be "__io"

You wouldn't be able to use hosted packages (Pub would throw "package names must be equal"), but it can be fixed separately from this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

2 participants