-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
[Proposal] Federate core hooks #3504
base: master
Are you sure you want to change the base?
Conversation
I would prefer the second solution which I find the neatest |
@yannbertrand ok awesome, same here. Thanks! |
I like the |
I like the B option too, but what about the option D, showing in the terminal the hooks that you can enable/disable, and you only need to select or unselect them. More or less I think that it would work like the B option but a little bit more visual, for the new people that arrives to Sails could be a better way to understand what's going on. Don't you think? |
yeah! I also like B the most... |
@Josebaseba A more interactive |
@mikermcneil Could the Sails generate could then for example write a custom The core hook disabling is already done via that so just thought extending that to handle core hook federation made sense. Something like: .sailsrc{
"hooks": [
"csrf",
"grunt",
"blueprints",
"pubsub",
"sockets" // automatically added for `pubsub`
]
} and, optionally read from
|
I like B too! |
@Salakar This is supported today pretty much as you're suggesting using the
|
@mikermcneil You're right, it should also do the removing of the hooks also. In general the generator / cli I think should provide a clear picture of what the core hooks are, what optional features that specific core hook can have (soft dependencies) and what hard dependencies are required. Initially, from my experience this has been a guessing game, disable X hook wait for sails to load and maybe throw an error about missing a core hook. (perhaps just needed more documentation) Something else that could be good is preset core hook configurations, i.e. api, web, worker and so on for the common use cases, and then proceeding to optionally customise chosen preset. Internally we have a repo for each of those configurations that we clone as a base project. But lately we tend to use this sails generator for api project configurations, the generator makes life so much easier. Another random thought, sorry 😸 - for on the sails site, a customise build wizard on the getting started guide that generates the Praise the almighty text wall. \o/ |
@Salakar agreed- we need a declarative encoding of hard and soft hook interdependence. The first step towards that is formally documenting it in the various hooks (e.g. https://github.com/balderdashy/sails/tree/master/lib/hooks/responses#dependencies). I've tried to use that format as a standard template for the core hooks I've made it through so far-- still some left go do.
That sounds awesome! I'd rather not add a react dependency to the Sails site right now (we're already loading Angular on the page), but this sounds like it'd be a really helpful tool.
That's helpful, thanks. I think that would be a good v1 enhancement to spec out. I'd be 100% down to make something like |
By the way, @everyone: Thanks! There's been some great feedback and ideas so far. If you haven't chimed in yet, please feel free to share your use case and any related thoughts on usage. This will be a key part of the Sails v1 release later this year, so it's important we get it right. The next step is to start detailing everything that would need to happen in tests, docs, generators, and Sails core for this to get implemented. I won't have time to look over this until after we release v0.12, but in the mean time you can help move this along by putting together a list of where the various changes would need to take place in sails-generate-new, sails, and sails-docs and posting it here. Once we've got all the usage details like exit conditions and so forth specified here, I'll merge this proposal in to the backlog. Then we can start writing code and get this into core asap! |
As an addition, here's a few relevant snippets of the conversation @sgress454 and I just had about this:
The reason I bring this in here is in the context of a more general discussion about hook dependencies. There really aren't that many hard, required hook dependencies (most dependencies are optional). But if we were to indicate them declaratively as part of the hook spec (I'm talking just hard dependencies, not optional ones), it would make for a much better experience when disabling/enabling core hooks in your apps and for higher-level tooling.
|
@mikermcneil i would prefer an extra package by hook... does core hook could be replaced by a custom one and interact with other's core: |
@atiertant totally agree! If I'm understanding you correctly, what you're suggesting will work in the currently released version of Sails-- just be sure to take a look at sails-hook-orm's package.json and include the |
@atiertant @AlexisNo @yannbertrand @Josebaseba @RWOverdijk @japel @Salakar Hey y'all, this is now implemented on the |
HI Mike, I just tested it like this:
Notice the "empty" space between helpers and policies. I wonder if this might be an issue.
|
Now that I'm thinking it more, does removing grunt makes the views not publishable? I noticed also that the assets folder is not there, neither. What would become the "public" folder when running without grunt? BTW, adding a views/homepage.ejs, fixes the routing issue, and it just works ok. |
@luislobo Thanks for your feedback!
We're currently not generating the homepage when ORM and Sockets hooks are disabled, for the simple reason that the current homepage has text on it that talks about generating an API and accessing it via WebSockets. There's a TODO in the generator to come up with a stripped-down version of the homepage; I'll make sure it gets added to our list (or at the very least, that the default
The empty spot is probably for the "PubSub" hook, which is
Good call, thanks for the heads up! |
I just got the list typing sails ;) From: notifications@github.comSent: December 5, 2016 10:11 AMTo: sails@noreply.github.comReply-to: reply@reply.github.comCc: luislobo@gmail.com; mention@noreply.github.comSubject: Re: [balderdashy/sails] [Proposal] Federate core hooks (#3504) @luislobo Thanks for your feedback!
The home page is not generated. no /view/homepage.ejs exists, so, a message is shown: error: Ignoring attempt to bind route (/) to unknown view: homepage
We're currently not generating the homepage when ORM and Sockets hooks are disabled, for the simple reason that the current homepage has text on it that talks about generating an API and accessing it via WebSockets. There's a TODO in the generator to come up with a stripped-down version of the homepage; I'll make sure it gets added to our list (or at the very least, that the default / route is not generated in these circumstances).
Also, when you go to sails console, an empty entry is shown in the list of hooks:
The empty spot is probably for pubsub, which is false in this scenario since it turns itself off if ORM or sockets is not available. I'm curious as to how you're generating that list?
the --without parameter should be documented in the sails new --help
Good call, thanks for the heads up!
—You are receiving this because you were mentioned.Reply to this email directly, view it on GitHub, or mute the thread.
|
Federate core hooks
This is the first pass at a proposal for how we could go about implementing custom builds of Sails. This is something we've been working towards for a long time, and it will likely not make it into the v0.12 release. But it is something that we plan to implement this year.
1. Installing core hooks
Goal: to provide a lighter customizable install of Sails.
Currently, while any/all hooks can be disabled in Sails, all core hooks and their dependencies are still bundled as part of Sails core. This is ideal for the basic default install, but annoying when you are running
npm install
locally in a Sails app and you aren't using half of the stuff you're waiting to install. Plus, if you aren't using Socket.io-powered features, you shouldn't have to wait for the native dependencies of sails-hook-sockets to compile (and furthermore, you shouldn't have to worry about ensuring your server isnode-gyp
-ready).I see three major solutions to solve this:
(A) Do it like Grunt
We could have sails-generate-new add the appropriate versions of hooks as dependencies in new Sails apps' package.json files. This is great because it completely separates hooks from Sails core, but the major downside is that now there are a whole bunch of new version strings to keep track of in your application. This is very similar to what happens with
grunt-contrib-*
dependencies, and much like a Grunt plugin is pretty much useless without Grunt installed, a Sails hook is pretty much useless without Sails core installed.(B) Do it like Lodash
A slightly more well-rounded variation on (A) is to do all that, but make it optional. In other words, the
sails
npm package continues to bundle all standalone core hooks as dependencies, and continues to house the command-line tool. But you could also install the npm package calledsails-core
(which is _just_ Sails core) directly in your project. It would include any core hooks we didn’t pull out as separate packages, and it would be a dependency ofsails
. Similarly, we'd modifysails-generate-new
to support custom builds for new Sails apps-- potentially something like:(C) Preinstall
Alternatively, we could get into some weird, hair-raising experimental stuff. Let me preface this by saying I don't know whether this even would work or not, it's just an idea. But here goes:
We could use an NPM preinstall script to install all core hooks as dependencies of Sails core itself, but only in certain situations; i.e. probably only if Sails is being installed globally AND the
sails_dont_install_core_hooks
environment variable is not set to something truthy. Otherwise, the preinstall script would look for special notation under thesails
namespace in the package.json file to determine which hooks should be set up as dependencies of this local Sails app, then modify the Sails package.json file so that the appropriate hook dependencies are installed.In other words, everything would work as-is, and your project would still depend on a version of Sails directly in its package.json file, with no direct dependencies on hooks. And when you run
npm install
in your project (e.g. on a new laptop or server), all core hooks would still be installed. But if you had included special notation in your package.json file, only the core hooks you specified would be installed and enabled.2. Which hooks?
Regardless of which installation strategy from above is being used, we could pull out a only a small subset of certain major hooks: e.g.
orm
,blueprints
,grunt
, andsockets
(and eventually,http
andviews
). Also there are certain hooks (likelogger
) that could easily just be swallowed to become part of Sails core directly (since they're used inside of Sails core outside of hook code anyways).3. Repos
There is a maintenance burden to having separate repos for different aspects of Sails core. The strategy from point #2 would make this easier, and probably worth it, but it's still something to consider. We also don't necessarily have to use separate repos for different hooks to make them separate NPM packages-- but making that work would take some research into how other projects of our scale have done it cleanly. If we only pull out the heaviest hooks as mentioned above, this becomes less of a big deal.
I look forward to reading your feedback. In particular, if you've run into a use case where you needed this in the past, it'd be helpful to hear more about that. Thanks!