-
Notifications
You must be signed in to change notification settings - Fork 1.7k
script that uses Platform.script on command line changes when run via pub run #21008
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
Comments
This comment was originally written by @sethladd If there's another way to find out where my script (or even just my package) is on the filesystem, that would be fine. |
I think this means that I'll need to run all tests through pub. Thoughts? cc @devoncarew. |
In general a library shouldn't make assumptions about its layout on disk. Pub moves different pieces around considerably, runs it via HTTP, and in some cases (e.g. running from a snapshotted executable) the virtual files being run will have no relationship at all with their source files. We've been planning for a long time to add some means of inspecting and loading assets—this is why we originally created barback—but we haven't had the time to implement that and it doesn't look like we will in the near future. For now, I'm afraid there's no good way (other than transformers I guess) to refer to files in your package. Added AsDesigned label. |
This comment was originally written by [email protected] Somewhat unfortunate, as I think a use case like the one below is pretty valid.
Solution:
inside zendify.dart i can access: Thanks for listening. |
This issue has been moved to dart-lang/pub#1136. |
This issue was originally filed by @sethladd
(not sure if this is a bug or just my misunderstanding?)
I have a command-line utility that I'm writing. One of the things it does is read some of the files inside of itself. To do this, it does:
var path = Platform.script.toFilePath();
This works when I just run my script using
dart
. However, this fails when I run via pub run:~/Code/stagehand[copy-dir-of-files*]$ pub run stagehand
Unhandled exception:
Unsupported operation: Cannot extract a file path from a http URI
0 Uri.toFilePath (dart:core/uri.dart:1583)
1 WebStarterKitGenerator._loadFiles (package:stagehand/generators/webstarterkit.dart:25:42)
2 WebStarterKitGenerator.WebStarterKitGenerator (package:stagehand/generators/webstarterkit.dart:18:15)
3 generators (package:stagehand/stagehand.dart:20:36)
4 main (http://localhost:49605/stagehand.dart:20:27)
5 _startIsolate.isolateStartHandler (dart:isolate-patch/isolate_patch.dart:212)
6 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:122)
Why am I doing Platform.script.toFilePath() ? I need to get a list of files inside a directory of my package. So I figured I'd first found out where I am and them go into lib/
basically, I need to be able to list files inside of my package. The next few lines go a little something like this:
var script = new File(path);
var dir = script.parent;
var filesDir = new Directory([dir.path, '..', 'lib', 'generators',
'webstarterkit'].join(Platform.pathSeparator));
print(filesDir.existsSync());
print(filesDir.path);
Should I be able to do Platform.script.toFilePath() and still let users run this script via
pub run
?Thanks!
The text was updated successfully, but these errors were encountered: