How to use the @parcel/fs.exists function in @parcel/fs

To help you get started, we’ve selected a few @parcel/fs 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 / src / core / utils / config.js View on Github external
async function resolve(filepath, filenames, root = path.parse(filepath).root) {
  filepath = path.dirname(filepath);

  // Don't traverse above the module root
  if (filepath === root || path.basename(filepath) === 'node_modules') {
    return null;
  }

  for (const filename of filenames) {
    let file = path.join(filepath, filename);
    let exists = existsCache.has(file)
      ? existsCache.get(file)
      : await fs.exists(file);
    if (exists) {
      existsCache.set(file, true);
      return file;
    }
  }

  return resolve(filepath, filenames, root);
}
github parcel-bundler / parcel / packages / core / parcel-bundler / src / utils / config.js View on Github external
async function resolve(filepath, filenames, root = path.parse(filepath).root) {
  filepath = path.dirname(filepath);

  // Don't traverse above the module root
  if (filepath === root || path.basename(filepath) === 'node_modules') {
    return null;
  }

  for (const filename of filenames) {
    let file = path.join(filepath, filename);
    let exists = existsCache.has(file)
      ? existsCache.get(file)
      : await fs.exists(file);
    if (exists) {
      existsCache.set(file, true);
      return file;
    }
  }

  return resolve(filepath, filenames, root);
}
github parcel-bundler / parcel / src / core / test-utils / src / index.js View on Github external
Array.from(b.assets).sort()[0].basename
          ? -1
          : 1
    );
    assert.equal(
      bundle.childBundles.size,
      childBundles.length,
      'expected number of child bundles mismatched'
    );
    await Promise.all(
      childBundles.map((b, i) => assertBundleTree(children[i], b))
    );
  }

  if (/js|css/.test(bundle.type)) {
    assert(await fs.exists(bundle.name), 'expected file does not exist');
  }
}
github parcel-bundler / parcel / packages / core / repl / src / parcel / ParcelWorker.js View on Github external
async getZip() {
    const zip = new JSZip();
    for (let f of await fastGlob('/src/*')) {
      zip.file(f, await fs.readFile(f, 'utf8'));
    }

    if (await fs.exists('/dist')) {
      for (let f of await fastGlob('/dist/**/*')) {
        zip.file(f, await fs.readFile(f, 'utf8'));
      }
    }

    return zip.generateAsync({type: 'uint8array'});
  }
}