Sha256: 3128614f039212e0b36f92d0b793edbca7453428337dd72060a66ae0109436e8

Contents?: true

Size: 1.37 KB

Versions: 10

Compression:

Stored size: 1.37 KB

Contents

import mm from 'micromatch';
import { resolve, sep } from 'path';
import { CreateFilter } from './pluginutils';
import ensureArray from './utils/ensureArray';

function getMatcherString(id: string, resolutionBase: string | false | null | undefined) {
	if (resolutionBase === false) {
		return id;
	}
	return resolve(...(typeof resolutionBase === 'string' ? [resolutionBase, id] : [id]));
}

const createFilter: CreateFilter = function createFilter(include?, exclude?, options?) {
	const resolutionBase = options && options.resolve;

	const getMatcher = (id: string | RegExp) => {
		return id instanceof RegExp
			? id
			: {
					test: mm.matcher(
						getMatcherString(id, resolutionBase)
							.split(sep)
							.join('/'),
						{ dot: true }
					)
			  };
	};

	const includeMatchers = ensureArray(include).map(getMatcher);
	const excludeMatchers = ensureArray(exclude).map(getMatcher);

	return function(id: string | any): boolean {
		if (typeof id !== 'string') return false;
		if (/\0/.test(id)) return false;

		id = id.split(sep).join('/');

		for (let i = 0; i < excludeMatchers.length; ++i) {
			const matcher = excludeMatchers[i];
			if (matcher.test(id)) return false;
		}

		for (let i = 0; i < includeMatchers.length; ++i) {
			const matcher = includeMatchers[i];
			if (matcher.test(id)) return true;
		}

		return !includeMatchers.length;
	};
};

export { createFilter as default };

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
condenser-0.3 lib/condenser/processors/node_modules/rollup-pluginutils/src/createFilter.ts
condenser-0.2 lib/condenser/processors/node_modules/rollup-pluginutils/src/createFilter.ts
condenser-0.1 lib/condenser/processors/node_modules/rollup-pluginutils/src/createFilter.ts
condenser-0.0.12 lib/condenser/processors/node_modules/rollup-pluginutils/src/createFilter.ts
condenser-0.0.11 lib/condenser/processors/node_modules/rollup-pluginutils/src/createFilter.ts
condenser-0.0.10 lib/condenser/processors/node_modules/rollup-pluginutils/src/createFilter.ts
condenser-0.0.9 lib/condenser/processors/node_modules/rollup-pluginutils/src/createFilter.ts
condenser-0.0.8 lib/condenser/processors/node_modules/rollup-pluginutils/src/createFilter.ts
condenser-0.0.7 lib/condenser/processors/node_modules/rollup-pluginutils/src/createFilter.ts
condenser-0.0.5 lib/condenser/processors/node_modules/rollup-pluginutils/src/createFilter.ts