Skip to content
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

Create a plugin to be able to require non chainy namespaced modules #14

Open
balupton opened this issue Jun 24, 2014 · 3 comments
Open

Comments

@balupton
Copy link
Member

Considering we can now do module.exports.extension = {}, it would be nice if we could require standard npm modules too. I'm thinking this could be a plugin that is added to the chainy package. It would allow us to do the following:

require('chainy').create().require('lodash.flatten set log')
    .set([1,[2,3],4]).flatten().log() // [1,2,3,4]

The potential for this is to finally stop having framework specific plugins being created, instead we can just update existing modules with the required configuration, that then works in different frameworks.

It would also allow us to create our own cli tools using chainy, then have them themselves be chainy plugins too, without the chainy-plugin- namespace. E.g. geojson-github-communities bevry docpad chainyjs could be a CLI tool, but also a chainy plugin without the need for chainy-plugin-geojsongithubcommunities. Instead, you do chainy install geojson-github-communities, and in chainy .require('geojson-github-communities') and it works as expected. Probably attempting for a chainy-plugin first, and then falling back on without one if not.

One side issue here, is that things like chainy-plugin-map etc, use this.create(), now this inheritance is important as it allows for greater debugging due to the tracking of children and parents. If we were to do require('chainy-core').create() it is now true that the plugin would be standalone, but it would lose it's inheritance abilities. Perhaps what we need is this: require('chainy-core').create().inherit(this), which then sets up the parent etc, while maintaining standalone abilities.

@balupton
Copy link
Member Author

balupton commented Aug 3, 2014

This may become part of the core I think, as it is such a fundamental use case. Or plugin, eitherway.

If this becomes part of the core, we will need to think about the default type. For instance take the example case, lodash.flatten has the implied extension type of action, however it is never explicitly set. Adding a default type can be quite problematic.


Another consideration is breaking the autoload plugin, how will it know what to require? Perhaps it can scan the package.json files of every dependency for a chainy-plugin keyword, but that requires package author cooperation. However, this is probably better than the current approach.


Perhaps we need to do something like requireExtensionsOfType('action', 'lodash.flatten'), but then it puts the grunt work on the user, which isn't cool.

@balupton
Copy link
Member Author

balupton commented Aug 3, 2014

/cc @JedWatson — keen to get your feedback on this

@pflannery
Copy link

I was wondering if http://jspm.io/ would suit this as it lets you load from github, npm, commonjs and it's own repo. Its also server\client agnostic so could be a good solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants