pandastrike / jsck

JSON Schema Compiled checK
MIT License
160 stars 14 forks source link

Make JSCK client-friendly by removing dynamic require statements #85

Closed jackwanders closed 9 years ago

jackwanders commented 9 years ago

JSCK is a great JSON schema validator, but at the moment, it cannot be included in a client application that is written in CommonJS and bundled with browserify (https://github.com/substack/node-browserify/issues/377).

Looking through the source, it appeared that the dynamic requires existed primarily for convenience; create an array of module names and then iterate over said array, requiring each module. These array iterations can be easily replaced with an array of static require statements.

The one impacting change in this pull request is the removal of the lazy_require getters in src/index.coffee. While this does mean that the modules for both draft specs are now always required when running this package in Node, I believe it's a small price to pay to make JSCK more easily useable in client applications. However, if the ability to lazily require the specs is important enough, it would be a simple matter to have two separate methods, one that creates a getter for ./draft3 and one for ./draft4, keeping the static require statements intact.

automatthew commented 9 years ago

Looks great. Thanks.

automatthew commented 9 years ago

@gilesbowkett or I will do a release soon.

jackwanders commented 9 years ago

:+1: Thanks, @automatthew.