Open DanielDornhardt opened 10 years ago
@DanielDornhardt That's a very good question!
So the idea is to tell wether we are running from bundle or not. Your app's "main" is located in .meteor/local/build/server" and this path can be easily grabbed with
path.resolve('.')`. Of course it would be a little too naive, to relay on this data only. If we did so, you could tell that this solution relies on deployment-specific features.
Hopefully, there is another path we can access and that is the location of our node modules. Each such module has __dirname
property which tells us exactly where each module is located. It turns out that after the bundling process these modules goes within programs/server/npm/...
directory. More specifically this would be
bundle/programs/server/npm/altimeter/main/node_modules/altimeter
Note that path.resolve('.')
will result in bundle/programs/server
in this case, so it will be a substring of altimeter's
location.
On the contrary, when you run your app in your development environment, the node modules are not being copied anywhere. Instead they're located in corresponding packages directories. In this particular case that would be:
packages/altimeter/.npm/package/node_modules
or even
~/.meteorite/packages/altimeter/apendua/altimeter/[hash]/.npm/package/node_modules/altimeter
No matter what, there's no way it contains path.resolve('.')
as a prefix. Thanks to this feature you can easily tell that you're not running from bundle.
All this said I can now see that the test should be actually indexOf(...) !== 0
rather then indexOf(...) < 0
.
Hi, sorry, I don't have a lot of time right now - so thank you twice as much for the detailed explanation.
I think it would be useful to include this in the readme so people can see what the package is about.
I don't know enough about which different kind of deployments there could possibly be, and therefore I don't know if your way of detection would work in every case (maybe some people leave a meteor instance running handling the live data)?
With the explanation you gave it'd be easy for people to see if it's gonna be working for them or maybe they would give you feedback for some edge cases.
Sorry, I am too busy right now to add the documentation as a pull request, but thank you again for your detailed information and I think it'd be good stuff for the readme.
Thanks and best wishes!
Hi, as this is the important code right here:
Could you explain what altimeter.path.indexOf(path.resolve('.')) < 0; is meant to do, and why it would differ between a production and a development environment?
Sounds like a specific case of deployment to me - maybe others might find this useful too, but for me it'd be easier to decide if I'd know how it works (and if it would work for my dev- and live-environments).
Thanks & best wishes!