How to use the @parcel/fs.readFile 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 / packages / core / parcel-bundler / src / assets / RustAsset.js View on Github external
async collectDependencies() {
    // Read deps file
    let contents = await fs.readFile(this.depsPath, 'utf8');
    let dir = path.dirname(this.name);

    let deps = contents
      .split('\n')
      .filter(Boolean)
      .slice(1);

    for (let dep of deps) {
      dep = path.resolve(dir, dep.slice(0, dep.indexOf(': ')));
      if (dep !== this.name) {
        this.addDependency(dep, {includedInParent: true});
      }
    }
  }
github parcel-bundler / parcel / packages / core / parcel-bundler / src / Resolver.js View on Github external
async readPackage(dir) {
    let file = path.join(dir, 'package.json');
    if (this.packageCache.has(file)) {
      return this.packageCache.get(file);
    }

    let json = await fs.readFile(file, 'utf8');
    let pkg = JSON.parse(json);

    pkg.pkgfile = file;
    pkg.pkgdir = dir;

    // If the package has a `source` field, check if it is behind a symlink.
    // If so, we treat the module as source code rather than a pre-compiled module.
    if (pkg.source) {
      let realpath = await fs.realpath(file);
      if (realpath === file) {
        delete pkg.source;
      }
    }

    this.packageCache.set(file, pkg);
    return pkg;
github parcel-bundler / parcel / packages / core / parcel-bundler / src / assets / KotlinAsset.js View on Github external
.slice(3);
    let dir = path.join(os.tmpdir(), id);
    let filename = path.join(dir, id + '.js');

    await fs.mkdirp(dir);

    await kotlinCompiler.compile({
      output: filename,
      sources: [this.name],
      moduleKind: 'commonjs',
      noStdlib: false,
      metaInfo: true,
      sourceMaps: this.options.sourceMaps,
    });

    let source = await fs.readFile(filename, 'utf8');
    let sourceMap;
    if (this.options.sourceMaps) {
      sourceMap = await fs.readFile(filename + '.map', 'utf8');

      sourceMap = JSON.parse(sourceMap);
      sourceMap.sources = [this.relativeName];
      sourceMap.sourcesContent = [this.contents];

      // remove source map url
      source = source.substring(0, source.lastIndexOf('//# sourceMappingURL'));
    }

    // delete temp directory
    await fs.rimraf(dir);

    return [
github parcel-bundler / parcel / src / core / resolver / src / Resolver.js View on Github external
async readPackage(dir) {
    let file = path.join(dir, 'package.json');
    if (this.packageCache.has(file)) {
      return this.packageCache.get(file);
    }

    let json = await fs.readFile(file, 'utf8');
    let pkg = JSON.parse(json);

    pkg.pkgfile = file;
    pkg.pkgdir = dir;

    // If the package has a `source` field, check if it is behind a symlink.
    // If so, we treat the module as source code rather than a pre-compiled module.
    if (pkg.source) {
      let realpath = await fs.realpath(file);
      if (realpath === file) {
        delete pkg.source;
      }
    }

    this.packageCache.set(file, pkg);
    return pkg;
github parcel-bundler / parcel / packages / core / parcel-bundler / src / transforms / babel / babelrc.js View on Github external
async function getIgnoreConfig(asset) {
  let ignoreFile = await asset.getConfig(['.babelignore'], {
    load: false,
  });

  if (!ignoreFile) {
    return null;
  }

  let data = await fs.readFile(ignoreFile, 'utf8');
  let patterns = data
    .split('\n')
    .map(line => line.replace(/#.*$/, '').trim())
    .filter(Boolean);

  return {ignore: patterns};
}
github parcel-bundler / parcel / packages / core / parcel-bundler / src / Asset.js View on Github external
async load() {
    return fs.readFile(this.name, this.encoding);
  }