How to use the simpl-schema/package.json.version function in simpl-schema

To help you get started, we’ve selected a few simpl-schema examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vazco / meteor-universe-collection / check-dependencies.js View on Github external
/*
 * Quite hacky solution but works for now
 * Require strings must be statically analyzed, so no loops or conditional checks are possible
 * Indents on error messages are on purpose this way to look better in the console
 */

const supportedVersions = {
    simpleSchema: '1'
};

let simpleSchemaVersion;
try {
    simpleSchemaVersion = require('simpl-schema/package.json').version;
} catch (e) {
    throw new Error(
        `[universe-collection] simpl-schema must be installed.
                      You can do it with command:
                      npm i simpl-schema@${supportedVersions.simpleSchema}
    `);
}

if (!simpleSchemaVersion.startsWith(supportedVersions.simpleSchema)) {
    throw new Error(
        `[universe-collection] Installed simpl-schema version (${simpleSchemaVersion}) is not supported at the moment.
                      You can install compatible version with:
                      npm i simpl-schema@${supportedVersions.simpleSchema}
    `);
}