New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@teambit/workspace.modules.match-pattern

Package Overview
Dependencies
Maintainers
15
Versions
132
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@teambit/workspace.modules.match-pattern - npm Package Compare versions

Comparing version 0.0.507 to 0.0.508

24

dist/exceptions/dir-pattern-with-star.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.DirPatternWithStar = void 0;
const bit_error_1 = require("@teambit/bit-error");
class DirPatternWithStar extends bit_error_1.BitError {
constructor(pattern) {
super(`variant "${pattern}" is not valid. glob patterns are not supported for file paths. by default variants applied to all sub-directories`);
this.pattern = pattern;
}
function _bitError() {
const data = require("@teambit/bit-error");
_bitError = function () {
return data;
};
return data;
}
class DirPatternWithStar extends _bitError().BitError {
constructor(pattern) {
super(`variant "${pattern}" is not valid. glob patterns are not supported for file paths. by default variants applied to all sub-directories`);
this.pattern = pattern;
}
}
exports.DirPatternWithStar = DirPatternWithStar;
//# sourceMappingURL=dir-pattern-with-star.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DirPatternWithStar = void 0;
var dir_pattern_with_star_1 = require("./dir-pattern-with-star");
Object.defineProperty(exports, "DirPatternWithStar", { enumerable: true, get: function () { return dir_pattern_with_star_1.DirPatternWithStar; } });
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "DirPatternWithStar", {
enumerable: true,
get: function () {
return _dirPatternWithStar().DirPatternWithStar;
}
});
function _dirPatternWithStar() {
const data = require("./dir-pattern-with-star");
_dirPatternWithStar = function () {
return data;
};
return data;
}
//# sourceMappingURL=index.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.sortMatchesBySpecificity = exports.MATCH_ALL_ITEM = exports.isMatchPatternItem = exports.isMatchNamespacePatternItem = exports.isMatchPattern = exports.isMatchDirPatternItem = void 0;
var match_pattern_1 = require("./match-pattern");
Object.defineProperty(exports, "isMatchDirPatternItem", { enumerable: true, get: function () { return match_pattern_1.isMatchDirPatternItem; } });
Object.defineProperty(exports, "isMatchPattern", { enumerable: true, get: function () { return match_pattern_1.isMatchPattern; } });
Object.defineProperty(exports, "isMatchNamespacePatternItem", { enumerable: true, get: function () { return match_pattern_1.isMatchNamespacePatternItem; } });
Object.defineProperty(exports, "isMatchPatternItem", { enumerable: true, get: function () { return match_pattern_1.isMatchPatternItem; } });
Object.defineProperty(exports, "MATCH_ALL_ITEM", { enumerable: true, get: function () { return match_pattern_1.MATCH_ALL_ITEM; } });
Object.defineProperty(exports, "sortMatchesBySpecificity", { enumerable: true, get: function () { return match_pattern_1.sortMatchesBySpecificity; } });
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "MATCH_ALL_ITEM", {
enumerable: true,
get: function () {
return _matchPattern().MATCH_ALL_ITEM;
}
});
Object.defineProperty(exports, "MatchedPattern", {
enumerable: true,
get: function () {
return _matchPattern().MatchedPattern;
}
});
Object.defineProperty(exports, "MatchedPatternItem", {
enumerable: true,
get: function () {
return _matchPattern().MatchedPatternItem;
}
});
Object.defineProperty(exports, "MatchedPatternWithConfig", {
enumerable: true,
get: function () {
return _matchPattern().MatchedPatternWithConfig;
}
});
Object.defineProperty(exports, "isMatchDirPatternItem", {
enumerable: true,
get: function () {
return _matchPattern().isMatchDirPatternItem;
}
});
Object.defineProperty(exports, "isMatchNamespacePatternItem", {
enumerable: true,
get: function () {
return _matchPattern().isMatchNamespacePatternItem;
}
});
Object.defineProperty(exports, "isMatchPattern", {
enumerable: true,
get: function () {
return _matchPattern().isMatchPattern;
}
});
Object.defineProperty(exports, "isMatchPatternItem", {
enumerable: true,
get: function () {
return _matchPattern().isMatchPatternItem;
}
});
Object.defineProperty(exports, "sortMatchesBySpecificity", {
enumerable: true,
get: function () {
return _matchPattern().sortMatchesBySpecificity;
}
});
function _matchPattern() {
const data = require("./match-pattern");
_matchPattern = function () {
return data;
};
return data;
}
//# sourceMappingURL=index.js.map
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.EXCLUSION_SIGN = exports.MATCH_ALL_ITEM = exports.PATTERNS_DELIMITER = void 0;
exports.sortMatchesBySpecificity = sortMatchesBySpecificity;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.PATTERNS_DELIMITER = exports.MATCH_ALL_ITEM = exports.EXCLUSION_SIGN = void 0;
exports.isMatchDirPatternItem = isMatchDirPatternItem;
exports.isMatchNamespacePatternItem = isMatchNamespacePatternItem;
exports.isMatchPattern = isMatchPattern;
exports.isMatchPatternItem = isMatchPatternItem;
exports.isMatchDirPatternItem = isMatchDirPatternItem;
exports.isMatchNamespacePatternItem = isMatchNamespacePatternItem;
const toolbox_string_strip_trailing_char_1 = require("@teambit/toolbox.string.strip-trailing-char");
const toolbox_path_is_path_inside_1 = require("@teambit/toolbox.path.is-path-inside");
const minimatch_1 = __importDefault(require("minimatch"));
const lodash_1 = require("lodash");
const exceptions_1 = require("./exceptions");
exports.PATTERNS_DELIMITER = ',';
exports.MATCH_ALL_ITEM = '*';
exports.EXCLUSION_SIGN = '!';
exports.sortMatchesBySpecificity = sortMatchesBySpecificity;
function _toolboxString() {
const data = require("@teambit/toolbox.string.strip-trailing-char");
_toolboxString = function () {
return data;
};
return data;
}
function _toolboxPath() {
const data = require("@teambit/toolbox.path.is-path-inside");
_toolboxPath = function () {
return data;
};
return data;
}
function _minimatch() {
const data = _interopRequireDefault(require("minimatch"));
_minimatch = function () {
return data;
};
return data;
}
function _lodash() {
const data = require("lodash");
_lodash = function () {
return data;
};
return data;
}
function _exceptions() {
const data = require("./exceptions");
_exceptions = function () {
return data;
};
return data;
}
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const PATTERNS_DELIMITER = exports.PATTERNS_DELIMITER = ',';
const MATCH_ALL_ITEM = exports.MATCH_ALL_ITEM = '*';
const EXCLUSION_SIGN = exports.EXCLUSION_SIGN = '!';
function sortMatchesBySpecificity(matches) {
const sortedMatches = (0, lodash_1.sortBy)(matches, (0, lodash_1.property)('specificity')).reverse();
return sortedMatches;
const sortedMatches = (0, _lodash().sortBy)(matches, (0, _lodash().property)('specificity')).reverse();
return sortedMatches;
}
function isMatchPattern(rootDir, componentName, pattern) {
const patternItems = pattern.split(exports.PATTERNS_DELIMITER);
const matches = patternItems.map((item) => isMatchPatternItem(rootDir, componentName, item));
const defaultVal = {
match: false,
excluded: false,
specificity: -1,
pattern,
const patternItems = pattern.split(PATTERNS_DELIMITER);
const matches = patternItems.map(item => isMatchPatternItem(rootDir, componentName, item));
const defaultVal = {
match: false,
excluded: false,
specificity: -1,
pattern
};
const maxMatch = (0, _lodash().maxBy)(matches, match => match.specificity) || defaultVal;
const excluded = matches.some(match => match.match && match.excluded);
return {
match: maxMatch.match,
maxSpecificity: maxMatch.specificity,
excluded,
pattern
};
}
function isMatchPatternItem(rootDir, componentName, patternItem) {
const patternItemTrimmed = patternItem.trim();
// Special case for * (match all)
// We want to mark it with match true but the smallest specificity
if (patternItemTrimmed === MATCH_ALL_ITEM) {
return {
match: true,
specificity: 0,
excluded: false,
pattern: patternItem
};
const maxMatch = (0, lodash_1.maxBy)(matches, (match) => match.specificity) || defaultVal;
const excluded = matches.some((match) => match.match && match.excluded);
}
const {
excluded,
patternItemWithoutExcludeSign
} = parseExclusion(patternItemTrimmed);
if (isDirItem(patternItemWithoutExcludeSign)) {
if (patternItemWithoutExcludeSign.includes('*')) {
throw new (_exceptions().DirPatternWithStar)(patternItemWithoutExcludeSign);
}
return {
match: maxMatch.match,
maxSpecificity: maxMatch.specificity,
excluded,
pattern,
...isMatchDirPatternItem(rootDir, patternItemWithoutExcludeSign),
excluded
};
}
return {
...isMatchNamespacePatternItem(componentName, patternItemWithoutExcludeSign),
excluded
};
}
function isMatchPatternItem(rootDir, componentName, patternItem) {
const patternItemTrimmed = patternItem.trim();
// Special case for * (match all)
// We want to mark it with match true but the smallest specificity
if (patternItemTrimmed === exports.MATCH_ALL_ITEM) {
return {
match: true,
specificity: 0,
excluded: false,
pattern: patternItem,
};
}
const { excluded, patternItemWithoutExcludeSign } = parseExclusion(patternItemTrimmed);
if (isDirItem(patternItemWithoutExcludeSign)) {
if (patternItemWithoutExcludeSign.includes('*')) {
throw new exceptions_1.DirPatternWithStar(patternItemWithoutExcludeSign);
}
return Object.assign(Object.assign({}, isMatchDirPatternItem(rootDir, patternItemWithoutExcludeSign)), { excluded });
}
return Object.assign(Object.assign({}, isMatchNamespacePatternItem(componentName, patternItemWithoutExcludeSign)), { excluded });
}
function isMatchDirPatternItem(rootDir, patternItem) {
// remove trailing / (will work for windows as well since the workspace.json always contain linux format)
const patternItemStriped = (0, toolbox_string_strip_trailing_char_1.stripTrailingChar)(patternItem, '/').trim();
if ((0, toolbox_path_is_path_inside_1.isPathInside)(rootDir, patternItemStriped)) {
return {
match: true,
specificity: patternItemStriped.split('/').length,
pattern: patternItem,
};
}
// remove trailing / (will work for windows as well since the workspace.json always contain linux format)
const patternItemStriped = (0, _toolboxString().stripTrailingChar)(patternItem, '/').trim();
if ((0, _toolboxPath().isPathInside)(rootDir, patternItemStriped)) {
return {
match: false,
specificity: -1,
pattern: patternItem,
match: true,
specificity: patternItemStriped.split('/').length,
pattern: patternItem
};
}
return {
match: false,
specificity: -1,
pattern: patternItem
};
}
function isMatchNamespacePatternItem(componentName, patternItem) {
// remove trailing / (will work for windows as well since the workspace.json always contain linux format)
const withoutBrackets = patternItem.replace('{', '').replace('}', '').trim();
const patternItemStriped = (0, toolbox_string_strip_trailing_char_1.stripTrailingChar)(withoutBrackets, '/').trim();
let specificity = 0;
const splittedPattern = patternItemStriped.split('/');
const minimatchMatch = (0, minimatch_1.default)(componentName, patternItemStriped);
if (!minimatchMatch) {
return {
match: false,
specificity: -1,
pattern: patternItem,
};
}
splittedPattern.forEach((patternElement, index) => {
if (patternElement === '**') {
specificity += index / 20;
return;
}
if (patternElement === '*') {
specificity += index / 10;
return;
}
// Matching an exact element
specificity += 1;
});
// remove trailing / (will work for windows as well since the workspace.json always contain linux format)
const withoutBrackets = patternItem.replace('{', '').replace('}', '').trim();
const patternItemStriped = (0, _toolboxString().stripTrailingChar)(withoutBrackets, '/').trim();
let specificity = 0;
const splittedPattern = patternItemStriped.split('/');
const minimatchMatch = (0, _minimatch().default)(componentName, patternItemStriped);
if (!minimatchMatch) {
return {
match: minimatchMatch,
specificity,
pattern: patternItem,
match: false,
specificity: -1,
pattern: patternItem
};
}
splittedPattern.forEach((patternElement, index) => {
if (patternElement === '**') {
specificity += index / 20;
return;
}
if (patternElement === '*') {
specificity += index / 10;
return;
}
// Matching an exact element
specificity += 1;
});
return {
match: minimatchMatch,
specificity,
pattern: patternItem
};
}
function isDirItem(patternItem) {
return !patternItem.startsWith('{');
return !patternItem.startsWith('{');
}
function parseExclusion(patternItem) {
if (patternItem.startsWith(exports.EXCLUSION_SIGN)) {
return {
excluded: true,
patternItemWithoutExcludeSign: patternItem.replace('!', ''),
};
}
if (patternItem.startsWith(EXCLUSION_SIGN)) {
return {
excluded: false,
patternItemWithoutExcludeSign: patternItem,
excluded: true,
patternItemWithoutExcludeSign: patternItem.replace('!', '')
};
}
return {
excluded: false,
patternItemWithoutExcludeSign: patternItem
};
}
//# sourceMappingURL=match-pattern.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = require("chai");
const match_pattern_1 = require("./match-pattern");
function _chai() {
const data = require("chai");
_chai = function () {
return data;
};
return data;
}
function _matchPattern() {
const data = require("./match-pattern");
_matchPattern = function () {
return data;
};
return data;
}
describe('isMatchDirPatternItem', () => {
describe('item is matched', () => {
it('exact match', () => {
const res = (0, match_pattern_1.isMatchDirPatternItem)('bar', 'bar');
(0, chai_1.expect)(res.match).to.be.true;
(0, chai_1.expect)(res.specificity).to.equal(1);
});
it('pattern is part of dir', () => {
const res = (0, match_pattern_1.isMatchDirPatternItem)('bar/foo', 'bar');
(0, chai_1.expect)(res.match).to.be.true;
(0, chai_1.expect)(res.specificity).to.equal(1);
});
it('specificity is larger than 1', () => {
const res = (0, match_pattern_1.isMatchDirPatternItem)('bar/foo/baz', 'bar/foo');
(0, chai_1.expect)(res.match).to.be.true;
(0, chai_1.expect)(res.specificity).to.equal(2);
});
describe('item is matched', () => {
it('exact match', () => {
const res = (0, _matchPattern().isMatchDirPatternItem)('bar', 'bar');
(0, _chai().expect)(res.match).to.be.true;
(0, _chai().expect)(res.specificity).to.equal(1);
});
describe('item is not matched', () => {
it('simple unmatch', () => {
const res = (0, match_pattern_1.isMatchDirPatternItem)('abc', 'def');
(0, chai_1.expect)(res.match).to.be.false;
(0, chai_1.expect)(res.specificity).to.equal(-1);
});
it('same suffix only', () => {
const res = (0, match_pattern_1.isMatchDirPatternItem)('bar/foo', 'bzr/bar/foo');
(0, chai_1.expect)(res.match).to.be.false;
(0, chai_1.expect)(res.specificity).to.equal(-1);
});
it('dir is part of pattern item', () => {
const res = (0, match_pattern_1.isMatchDirPatternItem)('bar', 'bar/foo');
(0, chai_1.expect)(res.match).to.be.false;
(0, chai_1.expect)(res.specificity).to.equal(-1);
});
it('pattern is part of dir', () => {
const res = (0, _matchPattern().isMatchDirPatternItem)('bar/foo', 'bar');
(0, _chai().expect)(res.match).to.be.true;
(0, _chai().expect)(res.specificity).to.equal(1);
});
it('specificity is larger than 1', () => {
const res = (0, _matchPattern().isMatchDirPatternItem)('bar/foo/baz', 'bar/foo');
(0, _chai().expect)(res.match).to.be.true;
(0, _chai().expect)(res.specificity).to.equal(2);
});
});
describe('item is not matched', () => {
it('simple unmatch', () => {
const res = (0, _matchPattern().isMatchDirPatternItem)('abc', 'def');
(0, _chai().expect)(res.match).to.be.false;
(0, _chai().expect)(res.specificity).to.equal(-1);
});
it('same suffix only', () => {
const res = (0, _matchPattern().isMatchDirPatternItem)('bar/foo', 'bzr/bar/foo');
(0, _chai().expect)(res.match).to.be.false;
(0, _chai().expect)(res.specificity).to.equal(-1);
});
it('dir is part of pattern item', () => {
const res = (0, _matchPattern().isMatchDirPatternItem)('bar', 'bar/foo');
(0, _chai().expect)(res.match).to.be.false;
(0, _chai().expect)(res.specificity).to.equal(-1);
});
});
});
describe('isMatchNamespacePatternItem', () => {
describe('item is matched', () => {
it('exact match', () => {
const res = (0, match_pattern_1.isMatchNamespacePatternItem)('bar', '{bar}');
(0, chai_1.expect)(res.match).to.be.true;
(0, chai_1.expect)(res.specificity).to.equal(1);
});
it('pattern is part of name and ends with *', () => {
const res = (0, match_pattern_1.isMatchNamespacePatternItem)('bar/foo', '{bar/*}');
(0, chai_1.expect)(res.match).to.be.true;
(0, chai_1.expect)(res.specificity).to.equal(1.1);
});
it('pattern is part of name and ends with * and name has more parts', () => {
const res = (0, match_pattern_1.isMatchNamespacePatternItem)('bar/foo/baz', '{bar/*}');
(0, chai_1.expect)(res.match).to.be.false;
(0, chai_1.expect)(res.specificity).to.equal(-1);
});
it('pattern is part of name and ends with ** and name has more parts', () => {
const res = (0, match_pattern_1.isMatchNamespacePatternItem)('bar/foo/baz', '{bar/**}');
(0, chai_1.expect)(res.match).to.be.true;
(0, chai_1.expect)(res.specificity).to.equal(1.05);
});
it('specificity is larger than 1', () => {
const res = (0, match_pattern_1.isMatchNamespacePatternItem)('bar/foo/baz', '{bar/foo/*}');
(0, chai_1.expect)(res.match).to.be.true;
(0, chai_1.expect)(res.specificity).to.equal(2.2);
});
it('multiple *', () => {
const res = (0, match_pattern_1.isMatchNamespacePatternItem)('bar/foo/baz/goo', '{bar/*/baz/*}');
(0, chai_1.expect)(res.match).to.be.true;
(0, chai_1.expect)(res.specificity).to.equal(2.4);
});
it('using ** in the middle of the pattern', () => {
const res = (0, match_pattern_1.isMatchNamespacePatternItem)('bar/foo/moo/baz/goo', '{bar/**/baz/*}');
(0, chai_1.expect)(res.match).to.be.true;
const specificity = Math.round(res.specificity * 100) / 100;
(0, chai_1.expect)(specificity).to.equal(2.35);
});
describe('item is matched', () => {
it('exact match', () => {
const res = (0, _matchPattern().isMatchNamespacePatternItem)('bar', '{bar}');
(0, _chai().expect)(res.match).to.be.true;
(0, _chai().expect)(res.specificity).to.equal(1);
});
describe('item is not matched', () => {
it('simple unmatch', () => {
const res = (0, match_pattern_1.isMatchNamespacePatternItem)('abc', '{def}');
(0, chai_1.expect)(res.match).to.be.false;
(0, chai_1.expect)(res.specificity).to.equal(-1);
});
it('name is part of pattern item', () => {
const res = (0, match_pattern_1.isMatchNamespacePatternItem)('bar', '{bar/foo}');
(0, chai_1.expect)(res.match).to.be.false;
(0, chai_1.expect)(res.specificity).to.equal(-1);
});
it('pattern is part of name but not ends with *', () => {
const res = (0, match_pattern_1.isMatchNamespacePatternItem)('bar/foo', '{bar}');
(0, chai_1.expect)(res.match).to.be.false;
(0, chai_1.expect)(res.specificity).to.equal(-1);
});
it('diff in the middle', () => {
const res = (0, match_pattern_1.isMatchNamespacePatternItem)('bar/foo/baz', '{bar/goo/baz}');
(0, chai_1.expect)(res.match).to.be.false;
(0, chai_1.expect)(res.specificity).to.equal(-1);
});
it('same suffix only', () => {
const res = (0, match_pattern_1.isMatchNamespacePatternItem)('bar/foo', '{bzr/bar/foo}');
(0, chai_1.expect)(res.match).to.be.false;
(0, chai_1.expect)(res.specificity).to.equal(-1);
});
it('pattern is part of name and ends with *', () => {
const res = (0, _matchPattern().isMatchNamespacePatternItem)('bar/foo', '{bar/*}');
(0, _chai().expect)(res.match).to.be.true;
(0, _chai().expect)(res.specificity).to.equal(1.1);
});
it('pattern is part of name and ends with * and name has more parts', () => {
const res = (0, _matchPattern().isMatchNamespacePatternItem)('bar/foo/baz', '{bar/*}');
(0, _chai().expect)(res.match).to.be.false;
(0, _chai().expect)(res.specificity).to.equal(-1);
});
it('pattern is part of name and ends with ** and name has more parts', () => {
const res = (0, _matchPattern().isMatchNamespacePatternItem)('bar/foo/baz', '{bar/**}');
(0, _chai().expect)(res.match).to.be.true;
(0, _chai().expect)(res.specificity).to.equal(1.05);
});
it('specificity is larger than 1', () => {
const res = (0, _matchPattern().isMatchNamespacePatternItem)('bar/foo/baz', '{bar/foo/*}');
(0, _chai().expect)(res.match).to.be.true;
(0, _chai().expect)(res.specificity).to.equal(2.2);
});
it('multiple *', () => {
const res = (0, _matchPattern().isMatchNamespacePatternItem)('bar/foo/baz/goo', '{bar/*/baz/*}');
(0, _chai().expect)(res.match).to.be.true;
(0, _chai().expect)(res.specificity).to.equal(2.4);
});
it('using ** in the middle of the pattern', () => {
const res = (0, _matchPattern().isMatchNamespacePatternItem)('bar/foo/moo/baz/goo', '{bar/**/baz/*}');
(0, _chai().expect)(res.match).to.be.true;
const specificity = Math.round(res.specificity * 100) / 100;
(0, _chai().expect)(specificity).to.equal(2.35);
});
});
describe('item is not matched', () => {
it('simple unmatch', () => {
const res = (0, _matchPattern().isMatchNamespacePatternItem)('abc', '{def}');
(0, _chai().expect)(res.match).to.be.false;
(0, _chai().expect)(res.specificity).to.equal(-1);
});
it('name is part of pattern item', () => {
const res = (0, _matchPattern().isMatchNamespacePatternItem)('bar', '{bar/foo}');
(0, _chai().expect)(res.match).to.be.false;
(0, _chai().expect)(res.specificity).to.equal(-1);
});
it('pattern is part of name but not ends with *', () => {
const res = (0, _matchPattern().isMatchNamespacePatternItem)('bar/foo', '{bar}');
(0, _chai().expect)(res.match).to.be.false;
(0, _chai().expect)(res.specificity).to.equal(-1);
});
it('diff in the middle', () => {
const res = (0, _matchPattern().isMatchNamespacePatternItem)('bar/foo/baz', '{bar/goo/baz}');
(0, _chai().expect)(res.match).to.be.false;
(0, _chai().expect)(res.specificity).to.equal(-1);
});
it('same suffix only', () => {
const res = (0, _matchPattern().isMatchNamespacePatternItem)('bar/foo', '{bzr/bar/foo}');
(0, _chai().expect)(res.match).to.be.false;
(0, _chai().expect)(res.specificity).to.equal(-1);
});
});
});
describe('isMatchPatternItem', () => {
describe('match all', () => {
it('using match all pattern', () => {
const res = (0, match_pattern_1.isMatchPatternItem)('bar', 'name', match_pattern_1.MATCH_ALL_ITEM);
(0, chai_1.expect)(res.match).to.be.true;
(0, chai_1.expect)(res.specificity).to.equal(0);
});
describe('match all', () => {
it('using match all pattern', () => {
const res = (0, _matchPattern().isMatchPatternItem)('bar', 'name', _matchPattern().MATCH_ALL_ITEM);
(0, _chai().expect)(res.match).to.be.true;
(0, _chai().expect)(res.specificity).to.equal(0);
});
describe('excluded item', () => {
it('excluding by dir', () => {
const res = (0, match_pattern_1.isMatchPatternItem)('bar/foo', 'name', '!bar');
(0, chai_1.expect)(res.match).to.be.true;
(0, chai_1.expect)(res.excluded).to.be.true;
(0, chai_1.expect)(res.specificity).to.equal(1);
});
it('excluding by namespace', () => {
const res = (0, match_pattern_1.isMatchPatternItem)('bar/foo', 'my-namespace/name', '!{my-namespace/*}');
(0, chai_1.expect)(res.match).to.be.true;
(0, chai_1.expect)(res.excluded).to.be.true;
(0, chai_1.expect)(res.specificity).to.equal(1.1);
});
});
describe('excluded item', () => {
it('excluding by dir', () => {
const res = (0, _matchPattern().isMatchPatternItem)('bar/foo', 'name', '!bar');
(0, _chai().expect)(res.match).to.be.true;
(0, _chai().expect)(res.excluded).to.be.true;
(0, _chai().expect)(res.specificity).to.equal(1);
});
it('excluding by namespace', () => {
const res = (0, _matchPattern().isMatchPatternItem)('bar/foo', 'my-namespace/name', '!{my-namespace/*}');
(0, _chai().expect)(res.match).to.be.true;
(0, _chai().expect)(res.excluded).to.be.true;
(0, _chai().expect)(res.specificity).to.equal(1.1);
});
});
});
describe('isMatchPattern', () => {
describe('no matches at all', () => {
it('should return match false with maxSpecificity as -1', () => {
const res = (0, match_pattern_1.isMatchPattern)('bar', 'name', 'foo, baz');
(0, chai_1.expect)(res.match).to.be.false;
(0, chai_1.expect)(res.excluded).to.be.false;
(0, chai_1.expect)(res.maxSpecificity).to.equal(-1);
});
describe('no matches at all', () => {
it('should return match false with maxSpecificity as -1', () => {
const res = (0, _matchPattern().isMatchPattern)('bar', 'name', 'foo, baz');
(0, _chai().expect)(res.match).to.be.false;
(0, _chai().expect)(res.excluded).to.be.false;
(0, _chai().expect)(res.maxSpecificity).to.equal(-1);
});
describe('match one dir item', () => {
it('should return match true with the correct maxSpecificity', () => {
const res = (0, match_pattern_1.isMatchPattern)('bar/foo/baz', 'name', 'foo, bar/foo , baz');
(0, chai_1.expect)(res.match).to.be.true;
(0, chai_1.expect)(res.excluded).to.be.false;
(0, chai_1.expect)(res.maxSpecificity).to.equal(2);
});
});
describe('match one dir item', () => {
it('should return match true with the correct maxSpecificity', () => {
const res = (0, _matchPattern().isMatchPattern)('bar/foo/baz', 'name', 'foo, bar/foo , baz');
(0, _chai().expect)(res.match).to.be.true;
(0, _chai().expect)(res.excluded).to.be.false;
(0, _chai().expect)(res.maxSpecificity).to.equal(2);
});
describe('match more than one dir item', () => {
it('should return match true with the correct maxSpecificity', () => {
const res = (0, match_pattern_1.isMatchPattern)('bar/foo/baz', 'name', 'bar/foo, bar/foo/baz , baz, bar');
(0, chai_1.expect)(res.match).to.be.true;
(0, chai_1.expect)(res.excluded).to.be.false;
(0, chai_1.expect)(res.maxSpecificity).to.equal(3);
});
});
describe('match more than one dir item', () => {
it('should return match true with the correct maxSpecificity', () => {
const res = (0, _matchPattern().isMatchPattern)('bar/foo/baz', 'name', 'bar/foo, bar/foo/baz , baz, bar');
(0, _chai().expect)(res.match).to.be.true;
(0, _chai().expect)(res.excluded).to.be.false;
(0, _chai().expect)(res.maxSpecificity).to.equal(3);
});
describe('match more than one namespace item', () => {
it('should return match true with the correct maxSpecificity', () => {
const res = (0, match_pattern_1.isMatchPattern)('bar/foo/baz', 'namespace1/namespace2/name', '{namespace1/namespace2/name}, {namespace1/namespace2/*} , baz, bar');
(0, chai_1.expect)(res.match).to.be.true;
(0, chai_1.expect)(res.excluded).to.be.false;
(0, chai_1.expect)(res.maxSpecificity).to.equal(3);
});
});
describe('match more than one namespace item', () => {
it('should return match true with the correct maxSpecificity', () => {
const res = (0, _matchPattern().isMatchPattern)('bar/foo/baz', 'namespace1/namespace2/name', '{namespace1/namespace2/name}, {namespace1/namespace2/*} , baz, bar');
(0, _chai().expect)(res.match).to.be.true;
(0, _chai().expect)(res.excluded).to.be.false;
(0, _chai().expect)(res.maxSpecificity).to.equal(3);
});
describe('match more than one namespace item and more than one dir item', () => {
it('should return match true with the correct maxSpecificity', () => {
const res = (0, match_pattern_1.isMatchPattern)('bar/foo/baz/goo', 'namespace1/namespace2/name', '{namespace1/namespace2/name}, {namespace1/namespace2/*} , bar/foo, bar/foo/baz/goo , baz, bar');
(0, chai_1.expect)(res.match).to.be.true;
(0, chai_1.expect)(res.maxSpecificity).to.equal(4);
});
});
describe('match more than one namespace item and more than one dir item', () => {
it('should return match true with the correct maxSpecificity', () => {
const res = (0, _matchPattern().isMatchPattern)('bar/foo/baz/goo', 'namespace1/namespace2/name', '{namespace1/namespace2/name}, {namespace1/namespace2/*} , bar/foo, bar/foo/baz/goo , baz, bar');
(0, _chai().expect)(res.match).to.be.true;
(0, _chai().expect)(res.maxSpecificity).to.equal(4);
});
describe('match different rules and exclude', () => {
it('should return match true with the correct maxSpecificity', () => {
const res = (0, match_pattern_1.isMatchPattern)('bar/foo/baz/goo', 'namespace1/namespace2/name', '{namespace1/namespace2/name}, {namespace1/namespace2/*} , bar/foo, bar/foo/baz/goo , baz, bar, !bar/foo');
(0, chai_1.expect)(res.match).to.be.true;
(0, chai_1.expect)(res.excluded).to.be.true;
(0, chai_1.expect)(res.maxSpecificity).to.equal(4);
});
});
describe('match different rules and exclude', () => {
it('should return match true with the correct maxSpecificity', () => {
const res = (0, _matchPattern().isMatchPattern)('bar/foo/baz/goo', 'namespace1/namespace2/name', '{namespace1/namespace2/name}, {namespace1/namespace2/*} , bar/foo, bar/foo/baz/goo , baz, bar, !bar/foo');
(0, _chai().expect)(res.match).to.be.true;
(0, _chai().expect)(res.excluded).to.be.true;
(0, _chai().expect)(res.maxSpecificity).to.equal(4);
});
describe('special patterns', () => {
describe('only components without namespace', () => {
const pattern = '*,!{*/**}';
it('should match component without namespace', () => {
const res = (0, match_pattern_1.isMatchPattern)('bar/foo/baz/goo', 'comp-name', pattern);
(0, chai_1.expect)(res.match).to.be.true;
(0, chai_1.expect)(res.excluded).to.be.false;
(0, chai_1.expect)(res.maxSpecificity).to.equal(0);
});
it('should exclude component with one namespace', () => {
const res = (0, match_pattern_1.isMatchPattern)('bar/foo/baz/goo', 'namespace1/comp-name', pattern);
(0, chai_1.expect)(res.match).to.be.true;
(0, chai_1.expect)(res.excluded).to.be.true;
(0, chai_1.expect)(res.maxSpecificity).to.equal(0.05);
});
it('should exclude component with more than one namespace', () => {
const res = (0, match_pattern_1.isMatchPattern)('bar/foo/baz/goo', 'namespace1/namespace2/comp-name', pattern);
(0, chai_1.expect)(res.match).to.be.true;
(0, chai_1.expect)(res.excluded).to.be.true;
(0, chai_1.expect)(res.maxSpecificity).to.equal(0.05);
});
});
describe('only components with at least namespace', () => {
const pattern = '{*/**}';
it('should not match component without namespace', () => {
const res = (0, match_pattern_1.isMatchPattern)('bar/foo/baz/goo', 'comp-name', pattern);
(0, chai_1.expect)(res.match).to.be.false;
(0, chai_1.expect)(res.excluded).to.be.false;
(0, chai_1.expect)(res.maxSpecificity).to.equal(-1);
});
it('should match component with one namespace', () => {
const res = (0, match_pattern_1.isMatchPattern)('bar/foo/baz/goo', 'namespace1/comp-name', pattern);
(0, chai_1.expect)(res.match).to.be.true;
(0, chai_1.expect)(res.excluded).to.be.false;
(0, chai_1.expect)(res.maxSpecificity).to.equal(0.05);
});
it('should match component with more than one namespace', () => {
const res = (0, match_pattern_1.isMatchPattern)('bar/foo/baz/goo', 'namespace1/namespace2/comp-name', pattern);
(0, chai_1.expect)(res.match).to.be.true;
(0, chai_1.expect)(res.excluded).to.be.false;
(0, chai_1.expect)(res.maxSpecificity).to.equal(0.05);
});
});
});
describe('special patterns', () => {
describe('only components without namespace', () => {
const pattern = '*,!{*/**}';
it('should match component without namespace', () => {
const res = (0, _matchPattern().isMatchPattern)('bar/foo/baz/goo', 'comp-name', pattern);
(0, _chai().expect)(res.match).to.be.true;
(0, _chai().expect)(res.excluded).to.be.false;
(0, _chai().expect)(res.maxSpecificity).to.equal(0);
});
it('should exclude component with one namespace', () => {
const res = (0, _matchPattern().isMatchPattern)('bar/foo/baz/goo', 'namespace1/comp-name', pattern);
(0, _chai().expect)(res.match).to.be.true;
(0, _chai().expect)(res.excluded).to.be.true;
(0, _chai().expect)(res.maxSpecificity).to.equal(0.05);
});
it('should exclude component with more than one namespace', () => {
const res = (0, _matchPattern().isMatchPattern)('bar/foo/baz/goo', 'namespace1/namespace2/comp-name', pattern);
(0, _chai().expect)(res.match).to.be.true;
(0, _chai().expect)(res.excluded).to.be.true;
(0, _chai().expect)(res.maxSpecificity).to.equal(0.05);
});
});
describe('only components with at least namespace', () => {
const pattern = '{*/**}';
it('should not match component without namespace', () => {
const res = (0, _matchPattern().isMatchPattern)('bar/foo/baz/goo', 'comp-name', pattern);
(0, _chai().expect)(res.match).to.be.false;
(0, _chai().expect)(res.excluded).to.be.false;
(0, _chai().expect)(res.maxSpecificity).to.equal(-1);
});
it('should match component with one namespace', () => {
const res = (0, _matchPattern().isMatchPattern)('bar/foo/baz/goo', 'namespace1/comp-name', pattern);
(0, _chai().expect)(res.match).to.be.true;
(0, _chai().expect)(res.excluded).to.be.false;
(0, _chai().expect)(res.maxSpecificity).to.equal(0.05);
});
it('should match component with more than one namespace', () => {
const res = (0, _matchPattern().isMatchPattern)('bar/foo/baz/goo', 'namespace1/namespace2/comp-name', pattern);
(0, _chai().expect)(res.match).to.be.true;
(0, _chai().expect)(res.excluded).to.be.false;
(0, _chai().expect)(res.maxSpecificity).to.equal(0.05);
});
});
});
});
describe('sortMatchesBySpecificity', () => {
describe('descending sort', () => {
it('should descending sort matches by specificity', () => {
const match1 = {
specificity: 5,
config: {},
pattern: '',
};
const match2 = {
specificity: 3,
config: {},
pattern: '',
};
const match3 = {
specificity: 7,
config: {},
pattern: '',
};
const matches = [match1, match2, match3];
const res = (0, match_pattern_1.sortMatchesBySpecificity)(matches);
(0, chai_1.expect)(res[0].specificity).to.equal(7);
(0, chai_1.expect)(res[1].specificity).to.equal(5);
(0, chai_1.expect)(res[2].specificity).to.equal(3);
});
describe('descending sort', () => {
it('should descending sort matches by specificity', () => {
const match1 = {
specificity: 5,
config: {},
pattern: ''
};
const match2 = {
specificity: 3,
config: {},
pattern: ''
};
const match3 = {
specificity: 7,
config: {},
pattern: ''
};
const matches = [match1, match2, match3];
const res = (0, _matchPattern().sortMatchesBySpecificity)(matches);
(0, _chai().expect)(res[0].specificity).to.equal(7);
(0, _chai().expect)(res[1].specificity).to.equal(5);
(0, _chai().expect)(res[2].specificity).to.equal(3);
});
});
});
//# sourceMappingURL=match-pattern.spec.js.map
{
"name": "@teambit/workspace.modules.match-pattern",
"version": "0.0.507",
"version": "0.0.508",
"homepage": "https://bit.cloud/teambit/workspace/modules/match-pattern",

@@ -9,3 +9,3 @@ "main": "dist/index.js",

"name": "modules/match-pattern",
"version": "0.0.507"
"version": "0.0.508"
},

@@ -16,4 +16,4 @@ "dependencies": {

"@teambit/bit-error": "0.0.404",
"@teambit/toolbox.path.is-path-inside": "0.0.498",
"@teambit/toolbox.string.strip-trailing-char": "0.0.498"
"@teambit/toolbox.path.is-path-inside": "0.0.499",
"@teambit/toolbox.string.strip-trailing-char": "0.0.499"
},

@@ -26,4 +26,3 @@ "devDependencies": {

"@types/mocha": "9.1.0",
"@types/jest": "26.0.20",
"@types/node": "22.10.5"
"@teambit/node.envs.node-babel-mocha": "0.1.4"
},

@@ -30,0 +29,0 @@ "peerDependencies": {},

@@ -8,8 +8,8 @@ declare module '*.png' {

export const ReactComponent: FunctionComponent<SVGProps<SVGSVGElement> & { title?: string }>;
export const ReactComponent: FunctionComponent<
SVGProps<SVGSVGElement> & { title?: string }
>;
const src: string;
export default src;
}
// @TODO Gilad
declare module '*.jpg' {

@@ -31,1 +31,13 @@ const value: any;

}
declare module '*.otf' {
const value: any;
export = value;
}
declare module '*.woff' {
const value: any;
export = value;
}
declare module '*.woff2' {
const value: any;
export = value;
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc