peerigon/alamid-schema

Proposal for loading plugins

Closed this issue · 4 comments

I think it would be a more comfortable API for users of this module if plugins could be loaded like this

const Schema = require('alamid-schema');
Schema.use('validation');

rather than

const Schema = require('alamid-schema');
Schema.use(require("alamid-schema/plugins/validation"));

Imho this is more readable. The required steps to load this plugin can easily be done by alamid-schema.

topa commented

I think this depends whether plugins should be shipped with alamid-schema or if they can be installed via npm.

meaku commented

I think this depends whether plugins should be shipped with alamid-schema or if they can be installed via npm.

That's correct. Autoloading is pain in the ass and we want to provide a generic interface no matter where the plugin is coming from. @jhnns noted that's is also a problem for bundlers and path resolving is pain.

Publishing validation as separate plugin might be an option. But for now we should keep it the way it is.
Cool @flootr?

jhnns commented

Yep, your proposal looks nice for the user, but I think there are more problems under the hood. Inside alamid-schema, you'd need code like

function use(path) {
    var plugin = require("../../" + path);
}

Because

  • that's a synchronous dynamic require which is impossible with ES2015 and cumbersome with webpack and browserify
  • and it depends on the node_modules structure which changed from npm@2 to npm@3

Publishing validation as separate plugin might be an option. But for now we should keep it the way it is.

Yeah, after some thoughts I think for now it's best to keep it like it is.