How to use the @hapi/somever.match function in @hapi/somever

To help you get started, we’ve selected a few @hapi/somever 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 hapipal / toys / test / index.js View on Github external
'use strict';

// Load modules

const EventEmitter = require('events');
const Stream = require('stream');
const Lab = require('@hapi/lab');
const Code = require('@hapi/code');
const Somever = require('@hapi/somever');
const Boom = require('@hapi/boom');
const Hoek = require('@hapi/hoek');
const Toys = require('..');

const Hapi = Somever.match(process.version, '>=12') ? require('@hapi/hapi-19') : require('@hapi/hapi');

// Test shortcuts

const lab = exports.lab = Lab.script();
const describe = lab.describe;
const it = lab.it;
const expect = Code.expect;

describe('Toys', () => {

    describe('withRouteDefaults()', () => {

        const defaults = {
            a: 1,
            b: 2,
            c: {
github hapijs / hapi / lib / server.js View on Github external
}

                item = Config.apply('plugin', item);

                const name = item.plugin.name || item.plugin.pkg.name;
                const clone = this._clone(name);

                clone.realm.modifiers.route.prefix = item.routes.prefix || options.routes.prefix;
                clone.realm.modifiers.route.vhost = item.routes.vhost || options.routes.vhost;
                clone.realm.pluginOptions = item.options || {};

                // Validate requirements

                const requirements = item.plugin.requirements;
                Hoek.assert(!requirements.node || Somever.match(process.version, requirements.node), 'Plugin', name, 'requires node version', requirements.node, 'but found', process.version);
                Hoek.assert(!requirements.hapi || Somever.match(this.version, requirements.hapi), 'Plugin', name, 'requires hapi version', requirements.hapi, 'but found', this.version);

                // Protect against multiple registrations

                if (this._core.registrations[name]) {
                    if (item.plugin.once ||
                        item.once ||
                        options.once) {

                        continue;
                    }

                    Hoek.assert(item.plugin.multiple, 'Plugin', name, 'already registered');
                }
                else {
                    this._core.registrations[name] = {
                        version: item.plugin.version || item.plugin.pkg.version,
github hapijs / hapi / lib / server.js View on Github external
item = Object.assign({}, item);         // Shallow cloned
                }

                item = Config.apply('plugin', item);

                const name = item.plugin.name || item.plugin.pkg.name;
                const clone = this._clone(name);

                clone.realm.modifiers.route.prefix = item.routes.prefix || options.routes.prefix;
                clone.realm.modifiers.route.vhost = item.routes.vhost || options.routes.vhost;
                clone.realm.pluginOptions = item.options || {};

                // Validate requirements

                const requirements = item.plugin.requirements;
                Hoek.assert(!requirements.node || Somever.match(process.version, requirements.node), 'Plugin', name, 'requires node version', requirements.node, 'but found', process.version);
                Hoek.assert(!requirements.hapi || Somever.match(this.version, requirements.hapi), 'Plugin', name, 'requires hapi version', requirements.hapi, 'but found', this.version);

                // Protect against multiple registrations

                if (this._core.registrations[name]) {
                    if (item.plugin.once ||
                        item.once ||
                        options.once) {

                        continue;
                    }

                    Hoek.assert(item.plugin.multiple, 'Plugin', name, 'already registered');
                }
                else {
                    this._core.registrations[name] = {
github hapijs / hapi / lib / core.js View on Github external
_validateDeps() {

        for (const { deps, plugin } of this.dependencies) {
            for (const dep in deps) {
                const version = deps[dep];
                Hoek.assert(this.registrations[dep], 'Plugin', plugin, 'missing dependency', dep);
                Hoek.assert(version === '*' || Somever.match(this.registrations[dep].version, version), 'Plugin', plugin, 'requires', dep, 'version', version, 'but found', this.registrations[dep].version);
            }
        }
    }
github hapipal / lalalambda / lib / serverless.js View on Github external
const fnConfig = sls.service.getFunction(id);

            Hoek.assert(!fnConfig.handler, `Lambda "${id}" already has a handler configured in the serverless config.`);

            const { settings } = lambdas.get(id);

            Hoek.merge(fnConfig, {
                ...settings,
                handler: Path.posix.join(BUILD_FOLDER, `${id}.handler`)
            });

            const runtime = fnConfig.runtime || sls.service.provider.runtime;

            Hoek.assert(runtime && runtime.startsWith('nodejs'), `Lambda "${id}" must be configured with a nodejs runtime.`);
            Hoek.assert(Somever.match(runtime.slice(6), '>=8.10'), `Lambda "${id}" must be configured with a nodejs runtime >=8.10.`);
        }
    }

@hapi/somever

Semantic versioning rules parser

BSD-3-Clause
Latest version published 2 years ago

Package Health Score

68 / 100
Full package analysis

Popular @hapi/somever functions