When I create a sub folder in a Dart Project in Dart Editor, immediately a package subfolder is created inside this sub folder. I have not read anywhere that sub folders have a special meaning for the project structure, but it appears they do. Anybody knows more?
The package subfolder holds symlinks to your Pub packages. You can read more about Pub and Pub packages at http://pub.dartlang.org/doc/.
When you start a non-web project, the editor will automatically create package directories in your bin/ and test/ directories (but not in your lib/ directory). If you create a web project, a package directory is also created in the web/ folder.
If you add a Pub dependency in the pubspec.yaml file and run pub install, your will see that the package folders will contain symlinks to the Pub package you just installed. If you are using Dart Editor, pub install will automatically run once you modify your pubspec,yaml file.
If you create a subfolder inside any directory that contains one of these auto-generated package folders, the subfolder will get its own package directory. This way, you will have access to your Pub packages no matter how deeply you nest your code in a directory.
Shailen's answer is correct. I wanted to add a bit more, as the title of this question is "What relevance to folders have in a Dart project?"
Dart is designed to be very web friendly. Because there is no load path or classpath on the web, Dart apps must run without requiring an installation or pre-configuration of a local environment.
The only way you can link one file to another in Dart is via a URI. These URIs can be file URIs, and they can be relative. That means file A.dart can point to file B.dart via an absolute or relative path.
So, to answer you question, there is nothing special about a folder layout for Dart applications. The app will run as long as your Dart file can reference its dependencies via the same kind of linking rules that exist on the web (think <a href="" or <link src="").
However, pub (the Dart dependency manager) does make a few assumptions about package and application layout. If certain conventions are followed, pub can manage symlinks for you so that it's easier to reference 3rd party dependencies. Do you need to use pub? Nope, you can manually copy files around or manually manage symlinks. But pub certainly does make it easier to use packages, given the constraints of Dart's design (no load path, no classpath).
Related
In serverless.yml file, how can I include the modules from parent folder?
package:
include:
- ../node_modules/**
but the packaged zip file doesn't include the dependencies from parent node_modules folder. I have tried the plugin: https://www.npmjs.com/package/serverless-plugin-include-dependencies but it still doesn't work. None of dependencies from parent folder is packaged.
How can I change the dependencies folder directory when packaging my application? I also want to apply excluding devDependencies logic for the parent folder.
I'd suggest to package your functions individually in some side script & then run the serverless deploy.
Then you can easily fine-tune your packaging process and include the node_modules from your parent, excluding the dev dependencies.
package:
individually: true
functions:
sample:
package:
artifact: ../functions/sample/deploy/sample.zip
Another small benefit on this is, if you only want to update some function you can explicitly just repackage that one and run the serverless deploy much faster.
I am using Dart 1.3.6 SDK and generated a typical command line application with a bin directory. The bin directory automatically gets its packages directory. However, none of the subdirectories of the bin directory gets any packages directory. As such I cannot import packages such as http that I am trying to use.
According to Dart's literature I think bin, test, web and example directories should all generate packages in there sub-directories. Yes?
I got the info that pub get should create these directories. I just created the symlinks manually when they were missing.
https://code.google.com/p/dart/issues/detail?id=16947
So far "entry points" in sub directories are not supported:
See also:
https://code.google.com/p/dart/issues/detail?id=18589
https://code.google.com/p/dart/issues/detail?id=17596
Does anyone know why Dart Editor won't allow me to edit files located inside the packages folder? I originally had my library class files outside of that folder, but I thought the right way to do it was to put my library under that folder, so I did it and now I can't modify the files.
Everything in packages/ is (usually) a symlink to a possibly shared copy of a package, so if you edited a file in packages/ you'd be editing it for all your projects, which might be very not what you want.
If you'd like to edit multiple packages together, the best way to do it is to specify a dependency override that uses a path source, like so:
name: my_package
dependency_overrides:
my_other_package:
path: /Users/me/dart/my_other_package
This way any other dependency on that package will also load it from the specified path and pub won't complain that you have different sources for the same package. Then you can open both projects separately in the editor and the my_package will see the changes in my_other_package as you edit.
Using pub build will pick up packages/browser/dart.js but it won't pick up javascript files included from other libraries. How can you make pub build pick up those external javascript & css files?
You should put that files in assets.
On a discussion about Assets-only Pub Packages Bob Nystrom gave some explaination about browser package and pub build:
It has some gross special-case code to handle the JS files in the browser package. That's been in there since before the idea of an "asset" directory existed, and it got Grandfathered in.
I am using the Dart Eclipse plugin following this guide:
http://blog.dartwatch.com/2013/01/integrating-dart-into-eclipse-and-your.html
( without the Maven integration )
If I use the pubspec.yaml file, my project gets spammed with these packages symlinks.
( I am using the "Package Explorer" view from Eclipse )
I would like some control over where these files get created.
I would argue the web root directory and maybe a scripts directory should be enough.
Currently, no, there is no way to control which directories get "packages" directories and which don't. Pub will place "packages" directories in "bin", "example", "test", "tool", and "web", and any subdirectory of those.
Those are all of the directories where a package may be expected to have a Dart entrypoint. Since an entrypoint needs a "packages" directory next to it to be able to use "package:" imports, pub will place one there.
It won't place "packages" directories anywhere else.
I would argue the web root directory and maybe a scripts directory should be enough.
"tool" is pub's convention for a "scripts" directory.
I found the code that generates these directories in dart-sdk\util\pub\entrypoint.dart.
There is a method called: _linkSecondaryPackageDir.
If I add: if (path.basename(dir) != 'web') return;
The packages folder only gets created in the root folder and the web folder, just like I want.
I will test if this breaks anything and report back.