Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('bootstraps micromatch', () => {
// This is a workaround for https://github.com/tschaub/mock-fs/issues/213
// Because micromatch() loads packages dynamically which doesn't work if the filesystem is being mocked
// So we need to pre-load them now
require('micromatch').match('file.txt', '**/**')
})
compiler.plugin('make', (compilation, done) => {
jadeFiles = compiler.options.spike.files.jade
// get paths relative to root
const filesRelative = jadeFiles.map((f) => {
return f.replace(this.opts.root + '/', '')
})
// filter in files matching the user-defined matcher
const matchingFiles = mm.match(filesRelative, this.files)
// now we are going to build the link injector script
let mod = ''
// first, we require in all the matching jade files so that we have the
// contents ready to inject if needed
matchingFiles.map((f) => {
mod += `exports.${path.basename(f, '.jade')} = require('../${f}')\n`
})
// now we add the script that matches link clicks to templates
mod += `
const links = querySelectorAll('a')
links.map((l) => {
l.onclick = (e) => {
e.preventDefault()
return ctx => {
if (typeof move === 'function') {
move = move(ctx.meta.merged)
}
if (!move) return
for (const pattern in move) {
const matches = match.match(ctx.fileList, pattern)
if (matches.length > 0) {
const newName = move[pattern]
if (typeof newName === 'function') {
for (const match of matches) {
const file = ctx.file(match)
const fileName = newName(match)
// eslint-disable-next-line max-depth
if (fileName) {
ctx.deleteFile(match)
ctx.createFile(fileName, file)
}
}
} else if (typeof newName === 'string') {
const file = ctx.file(matches[0])
ctx.deleteFile(matches[0])
ctx.createFile(newName, file)
const options = args.find(arg => typeOf(arg) === 'object') || {};
const tasks = [];
for (const val of args) {
if (val === options) {
continue;
}
const type = typeOf(val);
switch (type) {
case 'function':
tasks.push(val);
continue;
case 'string':
if (isGlob(val) && !/\[anonymous \(\d*\)\]/.test(val)) {
const matches = mm.match(names, val);
if (!matches.length) {
throw new Error('glob pattern "' + val + '" does not match any registered tasks');
}
for (const name of matches) {
tasks.push(resolveTask(this.tasks, name, options));
}
} else {
tasks.push(resolveTask(this.tasks, val, options));
}
break;
default: {
throw new TypeError(`task argument type "${type}" is not supported`);
}
}
return excludePatterns.reduce((accum, pattern) => micromatch.match(accum, pattern), included)
}) as KeyedPaths
(accum, pattern) => accum.concat(micromatch.match(paths, pattern)),
[] as Path[]
return depTypes(types).reduce(function(acc, type) {
var keys = depsKeys(pkg, type);
var res = mm.match(keys, pattern || '*');
return acc.concat(res);
}, []);
};
_.each(srcGlobs.src, glob => {
result = mm.match(result, glob);
});
exports.match = function match(fp, pattern, options) {
return mm.match(fp, pattern, options);
};