How to use glob-parent - 7 common examples

To help you get started, we’ve selected a few glob-parent 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 zinserjan / mocha-webpack / src / cli / prepareWebpack.js View on Github external
reasons: false,
      source: false,
      errorDetails: true,
      chunkOrigins: false,
      colors: options.colors,
    },
    state: false, // show bundle valid / invalid
  });

  const webpackPlugins = [webpackInfoPlugin];

  if (glob || existsDirSync(file)) {
    const globPattern = glob ? file : directoryToGlob(file, options);

    const matcher = anymatch(globPattern);
    const parent = globParent(globPattern);
    const directory = path.resolve(parent);

    const context = normalizePath(path.relative(tmpPath, directory));
    const recursive = globPattern.indexOf('**') !== -1; // or via options.recursive?

    const optionsHash = hash.MD5(options); // eslint-disable-line new-cap

    const entryFilePath = path.join(tmpPath, `${optionsHash}-entry.js`);
    const outputFilePath = path.join(tmpPath, optionsHash, `${optionsHash}-output.js`);

    function matchModule(mod) { // eslint-disable-line no-inner-declarations
      // normalize path to match glob
      const correctedPath = path.join(parent, mod);
      return matcher(correctedPath);
    }
github zinserjan / mocha-webpack / src / util / glob.js View on Github external
export const ensureGlob = (entry: string, recursive: boolean = false, pattern: string = '*.js'): string => {
  const normalized = normalizePath(entry);

  if (isGlob(normalized)) {
    return normalized;
  } else if (isDirectory(normalized)) {
    if (!isGlob(pattern)) {
      throw new Error(`Provided Glob ${pattern} is not a valid glob pattern`);
    }

    const parent = globParent(pattern);
    if (parent !== '.' || pattern.indexOf('**') !== -1) {
      throw new Error(`Provided Glob ${pattern} must be a file pattern like *.js`);
    }

    const globstar = recursive ? '**/' : '';

    return `${normalized}/${globstar}${pattern}`;
  }
  return normalized;
};
github zinserjan / mocha-webpack / src / cli / prepareWebpack.js View on Github external
function directoryToGlob(directory, options) {
  const { recursive, glob } = options;

  let fileGlob = defaultFilePattern;

  if (glob) {
    if (!isGlob(glob)) {
      throw new Error(`Provided Glob ${glob} is not a valid glob pattern`);
    }

    const parent = globParent(glob);

    if (parent !== '.' || glob.indexOf('**') !== -1) {
      throw new Error(`Provided Glob ${glob} must be a file pattern like *.js`);
    }

    fileGlob = glob;
  }


  const normalizedPath = normalizePath(directory);
  const globstar = recursive ? '**/' : '';
  const filePattern = [globstar, fileGlob].join('');

  return `${normalizedPath}/${filePattern}`;
}
github tomchentw / babel-multi-env / src / parseCLI.js View on Github external
_.partial(_.map, _, input => {
    let output = glob.sync(input, GLOB_OPTIONS);
    if (!output.length) {
      output = [input];
    }
    const parent = globParent(input);
    return _.map(output, filename => ({
      parent,
      filename
    }));
  })
)(argv.given);
github shannonmoeller / ygor / packages / files / src / files.js View on Github external
export function find(pattern, options = {}) {
	const patterns = [].concat(pattern || []);
	const parent = globParent(patterns[0]);
	const cwd = path.resolve(process.cwd(), options.cwd || '');
	const workdir = `${path.resolve(cwd, parent)}/`;

	const globOptions = {
		absolute: true,
		...options,
		cwd,
	};

	let paths = glob(patterns, globOptions).then((x) =>
		x.map((y) => path.resolve(y))
	);

	if (options.sort !== false) {
		paths = paths.then((x) => x.sort());
	}
github dsherret / ts-morph / packages / common / src / fileSystem / FileUtils.ts View on Github external
static getGlobDir(glob: string) {
        return globParent(glob);
    }
}
github dsherret / ts-morph / src / utils / FileUtils.ts View on Github external
static getGlobDir(glob: string) {
        return globParent(glob);
    }
}

glob-parent

Extract the non-magic parent path from a glob string.

ISC
Latest version published 3 years ago

Package Health Score

71 / 100
Full package analysis

Popular glob-parent functions