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

Support using convict in a (browserify-based) browser context #47

Closed
ronjouch opened this issue Dec 5, 2014 · 4 comments
Closed

Support using convict in a (browserify-based) browser context #47

ronjouch opened this issue Dec 5, 2014 · 4 comments

Comments

@ronjouch
Copy link
Contributor

ronjouch commented Dec 5, 2014

Hi.

I'm trying to use your package in a browserify setup, but because conf.loadFile('some.json') calls various fs methods (fs.statSync, fs.readdirSync), it fails in the browser.

→ Is it something that sounds feasible with convict (or maybe with a browserify transform?), or do you suggest going for another package / custom solution?

Thanks for the help, and sorry for posting this as an issue, it's more of a question to which "we do not and will not support that" can be a fine answer.

@madarche
Copy link
Collaborator

@ronjouch convict in itself does not require fs operations, and anyway those are ignored by default by browserify, cf. https://github.com/substack/browserify-handbook#ignoring-and-excluding : "browserify already 'ignores' the 'fs' module by returning an empty object".

Nevertheless convict has dependencies over cjson to load filesystem files. And cjson, in turn, requires the path module. So ignoring the path module with browserify may make it possible to use convict in browser.

@ronjouch
Copy link
Contributor Author

@madarche thanks for the response! Yes that's part of the path I followed and I'm now using convict for an application at work. In case that helps someone, the path I followed was:

  • Ignore the system and file modules (in Gulp, adding two .ignore('system').ignore('file') calls).
  • Use brfs to ensure the fs.loadFileSync schema-loading calls are inlined at build time rather than done at runtime.
  • Add a level of indirection using superagent to support loading configuration "from a .json URL". The XHR callback just parses the response and calls your .load() method. I considered proposing a patch to your library, but the changes were getting invasive and I doubt you'd have merged them.

@madarche
Copy link
Collaborator

@ronjouch thanks for the answer. I agree with you that we should not widen convict scope and add new functionalities, we should follow the Node aesthetic.

Nevertheless:

  • if using convict in a browser context proves to be useful in your experience, a PR for documenting in the README.md how to do it would be worthwhile
  • if you think that convict could be improved to more easily "plug" other modules on it, please explain how, PR welcomed

Cheers

@ghost
Copy link

ghost commented Sep 4, 2015

There are a few things preventing this from being browserified:

  • dep uses v8-specific Error functions. Works on Chrome. Doesn't anywhere else.
  • convict.load now uses fstat, which isn't implemented by brfs

Either drop the browserify support or fix these issues. Browserify-ability requires a lot of work and greatly limits your choices, so I also suggest adding some karma/phantomjs-based tests so you can catch issues early.

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