Skip to content

Instantly share code, notes, and snippets.

@JamesMessinger
Last active March 1, 2017 23:12
Show Gist options
  • Save JamesMessinger/67f2e6cbd43d2245241e to your computer and use it in GitHub Desktop.
Save JamesMessinger/67f2e6cbd43d2245241e to your computer and use it in GitHub Desktop.

SailsJS v1.0

This is just a list of changes that I would like to see in SailsJS v1.0. Many of these are breaking changes, but this is a major version bump, so now is the time to make these changes. It’s worth the upgrade pain to make some much-needed improvements to the framework and remove some legacy bloat and code smell.

Top Priorities:

Upgrade to Express 4.0

  • Or Express 5.0, if it’s at least in beta by then

Trim-down SailsJS Core by moving a bunch of stuff to plug-ins (hooks)

  • Remove Grunt, EJS, and LESS from SailsJS Core
  • SailsJS Core should not include any build tool, view engine, or CSS preprocessor. These should all be plug-ins (hooks), so developers can choose whichever one they prefer - or none at all (useful for apps with no views - e.g. REST APIs)

Remove LoDash and Async globals

  • It’s bad practice to expose these as globals
    • It creates a tight dependency that prevents us from removing LoDash/Async at some point in the future
    • It creates a tight dependency to specific versions of LoDash/Async
    • If developers are using LoDash/Async in their apps, then they need to define their own dependency on these modules and require() them just like any other module
      • This allows developers to use a different version of LoDash/Async than we use inside SailsJS
      • This allows SailsJS to ditch LoDash/Async in the future if we want
  • Yeoman has way more community adoption, support, and testing than SailsJS generators do
  • Replace all of the SailsJS generators with Yeoman generators
  • Create a generic SailsJS-to-Yeoman adapter so that existing third-party SailsJS generators can still be used
  • The SailsJS CLI (e.g. sails new) will still work as it currently does, but it would spawn Yeoman under the hood
  • The sails new generator would give the user their choice of SailsJS plug-ins to install as part of their new app - such as Grunt vs Gulp, LESS vs SASS, EJS vs Handlebars, etc. In all cases, the user can choose “none”

/config/bootstrap.js becomes /bootstrap/*.js

  • The bootstrap.js file in the config folder feels like a hack. All of the other files in the config folder are simple JSON objects with config settings, but the bootstrap.js file is code that executes at startup
  • Some apps need to do several different things at startup, so the bootstrap.js file can quickly become cluttered
  • Instead, we will have a “bootstrap” folder. It will work very similar to the “config” folder, in that it can contain any number of files, and SailsJS will automatically run all of those files at startup. This allows for better code organization.
  • The signature for bootstrap files can be the same as it is now (a function with a callback param) or we can make it closer to the hooks signature

Add “staging” and “test” environments by default

  • These seem like incredibly common ones, so they should exist by default

Move /config/local.js to config/env/local.js

  • This is a minor change, but improves consistency
  • “local.js” is just a bunch of local overrides for the current environment, so it makes sense to be in the same folder as all the other environment files

Nice-to-Haves:

Upgrade to Node 4.0

  • Drop support for Node 0.x
  • This should be an easy sell, since Node 4 has an LTS plan, which makes it much more attractive for enterprise-grade server apps
  • This also gets us native ES6, without requiring a transpiler

Switch to Promises

  • All the places where Sails currently expects callbacks (hooks, bootstraps, middleware, etc.) should support promises
  • Promises are the future of async in JavaScript, especially once async/await is fully supported
  • We can either drop support for callbacks altogether, or we can support callbacks and promises

Switch to ES6 classes

  • All Controllers should inherit from a sails.Controller base class
  • All Models should inherit from a sails.Model base class
  • All Hooks should inherit from a sails.Hook base class
  • ES6 classes make it dead-simple for us to provide base-class functionality that can easily be overridden by developers
  • ES6 classes make it dead-simple for developers to conditionally call the base-class (super) implementation, rather than the all-or-nothing approach that Sails currently has
  • ES6 classes make it easy for us to provide utility functions & properties via static class members. (ES6 static members are inherited by derived classes)
  • ES6 classes give us a well-defined initialization step for each Controller/Model/Hook — the constructor
@mikermcneil
Copy link

Priority / Request Status in Sails v1
Upgrade to Express 4.0
Trim-down SailsJS Core by moving a bunch of stuff to plug-ins (hooks) (grunt, orm, and sockets hooks have been extrapolated)
Remove Grunt, EJS, and LESS from SailsJS Core (see above)
Remove LoDash and Async globals (you've always been able to disable globals, but now any automatic globalization you choose is based on direct dependencies of your app and is completely customizable version-wise)
Allow developers to use a different version of LoDash/Async than we use inside SailsJS (see above)
Switch to Yeoman Generators ✖️ (I used to aim for us to end up w/ yeoman, but I couldn't justify adding all of the additional dependencies, complexity, and maintenance burden to the standard command-line tool. That said, Sails v1.0 brings some major improvements and cleanup in sails-generate.)
Bootstrap changes? ✖️ (we have not made changes here for now-- mainly because of other priorities, but also because there are some open questions around how to neatly solve backwards-compatibility, and whether or not this can just better solved using hooks. I agree with you about it feeling kind of inconsistent though... Biggest plans in this area are around extending the hook spec to provide more lifecycle callbacks in a future minor version release)
Add “staging” and “test” environments by default ✖️ (Completely agree with you re: staging, just haven't gotten around to it yet. I'll try and squeeze that in! As for testing, we're planning to approach it slightly differently, and I actually just started some early work on that as part of a Sails Flagship package. We probably won't find time to trickle that down into the generally-available release yet though)
Move /config/local.js to config/env/local.js ✖️ (I'm open to a change here, but I'm not sure about the config/env/ folder, because I feel like that comes with some of its own inconsistencies: e.g. "do you have to have sails.config.environment set to local?")
But hey, speaking of locals (...err sort of) (see http://blog.sailsjs.com/post/150798442112/exposelocalstobrowser)
Upgrade to Node 4.0 (we support Node 0.10 through Node 7.0 in both Sails v0.12 and Sails v1.0)
Promises (now extended to other parts of sails core, and 300x performance optimized in Waterline -- see parley)
Switch to ES6 classes (we'll have to agree to disagree on this one. See https://twitter.com/mikermcneil/status/829552320522440704 and https://twitter.com/mikermcneil/status/832793522994417665)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment