How to use the @parcel/utils.isGlob function in @parcel/utils

To help you get started, we’ve selected a few @parcel/utils 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 parcel-bundler / parcel / packages / resolvers / default / src / DefaultResolver.js View on Github external
lookupAlias(aliases, filename, dir) {
    // First, try looking up the exact filename
    let alias = aliases[filename];
    if (alias == null) {
      // Otherwise, try replacing glob keys
      for (let key in aliases) {
        let val = aliases[key];
        if (typeof val === 'string' && isGlob(key)) {
          let re = micromatch.makeRe(key, {capture: true});
          if (re.test(filename)) {
            alias = filename.replace(re, val);
            break;
          }
        }
      }
    }

    if (typeof alias === 'string') {
      return this.resolveFilename(alias, dir);
    } else if (alias === false) {
      return false;
    }

    return null;
github parcel-bundler / parcel / packages / core / core / src / RequestGraph.js View on Github external
async resolveEntry(entryRequestNode: EntryRequestNode) {
    let result = await this.entryResolver.resolveEntry(entryRequestNode.value);

    // Connect files like package.json that affect the entry
    // resolution so we invalidate when they change.
    for (let file of result.files) {
      this.connectFile(entryRequestNode, file.filePath);
    }

    // If the entry specifier is a glob, add a glob node so
    // we invalidate when a new file matches.
    if (isGlob(entryRequestNode.value)) {
      this.connectGlob(entryRequestNode, entryRequestNode.value);
    }

    this.onEntryRequestComplete(entryRequestNode.value, result.entries);
  }
github parcel-bundler / parcel / packages / resolvers / default / src / DefaultResolver.js View on Github external
async resolve({
    filename,
    parent,
    isURL,
    env,
  }: {|
    filename: FilePath,
    parent: ?FilePath,
    isURL: boolean,
    env: Environment,
  |}) {
    // Check if this is a glob
    if (isGlob(filename)) {
      if (parent == null) {
        throw new Error('Globs can only be required from a parent file');
      }
      return {path: path.resolve(path.dirname(parent), filename)};
    }

    // Get file extensions to search
    let extensions = this.extensions.slice();

    if (parent) {
      // parent's extension given high priority
      let parentExt = path.extname(parent);
      extensions = [parentExt, ...extensions.filter(ext => ext !== parentExt)];
    }

    extensions.unshift('');
github parcel-bundler / parcel / packages / core / core / src / EntryResolver.js View on Github external
async resolveEntry(entry: FilePath): Promise {
    if (isGlob(entry)) {
      let files = await glob(entry, this.fs, {
        absolute: true,
        onlyFiles: false,
      });
      let results = await Promise.all(files.map(f => this.resolveEntry(f)));
      return results.reduce(
        (p, res) => ({
          entries: p.entries.concat(res.entries),
          files: p.files.concat(res.files),
        }),
        {entries: [], files: []},
      );
    }

    let stat;
    try {
github parcel-bundler / parcel / packages / transformers / stylus / src / StylusTransformer.js View on Github external
visitImport(imported) {
      let importedPath = imported.path.first.string;

      if (!deps.has(importedPath)) {
        if (isGlob(importedPath)) {
          deps.set(
            importedPath,
            glob(
              path.resolve(path.dirname(filepath), importedPath),
              parcelOptions.inputFS,
              {
                onlyFiles: true,
              },
            ).then(entries =>
              Promise.all(
                entries.map(entry =>
                  resolve(
                    filepath,
                    './' + path.relative(path.dirname(filepath), entry),
                  ),
                ),