Skip to content

Add an option to skip the platform check for specific packages - #2420

Merged
natebosch merged 6 commits into
masterfrom
skip-platform-checks
Sep 4, 2019
Merged

natebosch merged 6 commits into
masterfrom
skip-platform-checks

Conversation

@natebosch

@natebosch natebosch commented Aug 21, 2019 •

Copy link
Copy Markdown
Member

Flutter web must allow some dart:io import in package:flutter, but
adding dart:io to the DartPlatform causes the module crawling to
pick the imports in some cases - we want the DartPlatform to match the
libraries.json that will be used by DDC and kernel in terms of which
libraries are supported, but to avoid the failures for bad imports.

The kernel and DDC workers have always allowed imports to missing
dart: libraries with stubbed implementations that will throw if they are
used at runtime. The restrictions on imports are implemented in the
build systems instead of the compilers. This argument allows loosening
the restriction in specific flutter packages while keeping the handrails for
user code.

Flutter web must allow some `dart:io` import in `package:flutter`, but
adding `dart:io` to the `DartPlatform` causes the module crawling to
pick the imports in some cases - we want the `DartPlatform` to match the
`libraries.json` that will be used by DDC and kernel.
@googlebot googlebot added the cla: yes Google is happy with the PR contributors label Aug 21, 2019

@grouma grouma left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I trust this is the correct thing to do but can you add some more context? I don't follow why libraries.json contains the valid information to make this work.

@jonahwilliams

Copy link
Copy Markdown

Friendly bump :)

@jakemac53

Copy link
Copy Markdown
Contributor

Flutter web must allow some dart:io import in package:flutter

This seems like the core issue? Can we not remove those imports (or hide them behind conditional imports?)

@jonahwilliams

Copy link
Copy Markdown

It's not a trivial change: flutter/flutter#38773

@natebosch

Copy link
Copy Markdown
Member Author

can you add some more context?

I updated the first comment on the PR and will make the commit message match.

Can we not remove those imports

In the long term I hope we will so that we can restore the build system restrictions on imports since it's friendlier to users. In the short term I think this is the right change.

@jakemac53

Copy link
Copy Markdown
Contributor

We could potentially make it take a whitelist of packages to allow these imports in instead of disabling the check entirely?

I am concerned people will be really confused when their app starts throwing at runtime due to some transitive dep that is trying to use dart:io....

@natebosch

Copy link
Copy Markdown
Member Author

@jonahwilliams - I'll take a stab at adding a Set<String> ignorePlatformCheckPackages argument where you could pass {'flutter'} to ease the concerns about UX - would that work for you?

@jonahwilliams

Copy link
Copy Markdown

As a short term solution, either should be fine.

As for the long-term behavior of build_runner/ddc in the presence of dart:io/unsupported libraries, I'm not convinced that the current build_runner behavior is any less confusing than the resulting (potential) runtime exceptions. I think this behavior should be re-evaluated and potentially include some UXR work from Flutter.

@jakemac53

Copy link
Copy Markdown
Contributor

While it is true that we would refuse to compile an app that might actually work, the same could be said for all static errors. Skipping these import checks is basically equivalent to allowing imports to a non-existent uri and then only failing at runtime if you tried to actually use that library.

Improving the ergonomics of platform specific code would certainly be good, but I think that would have to happen at the language level. We could also work on the error messages etc to be more intuitive.

@jonahwilliams

Copy link
Copy Markdown

What is the path forward here?

I understand that I'm asking for a quick hack, but this shouldn't effect anyone besides the flutter tool. We should not be putting the dart:io problem on the critical path for flutter web

@jakemac53

Copy link
Copy Markdown
Contributor

I think the short term fix we should shoot for is allowing a (hopefully temporary) whitelist of packages that are allowed to ignore the import checks.

@natebosch

Copy link
Copy Markdown
Member Author

@jonahwilliams - can you try with the latest packages from this branch? You'll need to override both build_web_compilers and build_modules and change the boolean argument into skipPlatformCheckPackages: {'flutter'}

@jonahwilliams

Copy link
Copy Markdown

Will do

@natebosch natebosch changed the title Add an option to skip the platform check Add an option to skip the platform check for specific packages Sep 4, 2019
@natebosch
natebosch merged commit 7330d7f into master Sep 4, 2019
@natebosch
natebosch deleted the skip-platform-checks branch September 4, 2019 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes Google is happy with the PR contributors

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants