How to use the @parcel/fs.stat 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 / resolver / src / Resolver.js View on Github external
return {filePath: builtins[filename]};
    }

    let parts = this.getModuleParts(filename);
    let root = path.parse(dir).root;

    while (dir !== root) {
      // Skip node_modules directories
      if (path.basename(dir) === 'node_modules') {
        dir = path.dirname(dir);
      }

      try {
        // First, check if the module directory exists. This prevents a lot of unnecessary checks later.
        let moduleDir = path.join(dir, 'node_modules', parts[0]);
        let stats = await fs.stat(moduleDir);
        if (stats.isDirectory()) {
          return {
            moduleName: parts[0],
            subPath: parts[1],
            moduleDir: moduleDir,
            filePath: path.join(dir, 'node_modules', filename)
          };
        }
      } catch (err) {
        // ignore
      }

      // Move up a directory
      dir = path.dirname(dir);
    }
  }
github parcel-bundler / parcel / packages / core / parcel-bundler / src / FSCache.js View on Github external
async read(filename) {
    if (this.invalidated.has(filename)) {
      return null;
    }

    let cacheFile = this.getCacheFile(filename);

    try {
      let stats = await fs.stat(filename);
      let cacheStats = await fs.stat(cacheFile);

      if (stats.mtime > cacheStats.mtime) {
        return null;
      }

      let json = await fs.readFile(cacheFile);
      let data = JSON.parse(json);
      if (!(await this.checkDepMtimes(data))) {
        return null;
      }

      return data;
    } catch (err) {
      return null;
    }
github parcel-bundler / parcel / packages / core / parcel-bundler / src / FSCache.js View on Github external
async getLastModified(filename) {
    if (isGlob(filename)) {
      let files = await glob(filename, {
        onlyFiles: true,
      });

      return (
        await Promise.all(
          files.map(file => fs.stat(file).then(({mtime}) => mtime.getTime())),
        )
      ).reduce((a, b) => Math.max(a, b), 0);
    }
    return (await fs.stat(filename)).mtime.getTime();
  }
github parcel-bundler / parcel / src / core / cache / src / FSCache.js View on Github external
async read(filename) {
    if (this.invalidated.has(filename)) {
      return null;
    }

    let cacheFile = this.getCacheFile(filename);

    try {
      let stats = await fs.stat(filename);
      let cacheStats = await fs.stat(cacheFile);

      if (stats.mtime > cacheStats.mtime) {
        return null;
      }

      let json = await fs.readFile(cacheFile);
      let data = JSON.parse(json);
      if (!(await this.checkDepMtimes(data))) {
        return null;
      }

      return data;
    } catch (err) {
      return null;
    }
  }
github parcel-bundler / parcel / packages / core / parcel-bundler / src / FSCache.js View on Github external
          files.map(file => fs.stat(file).then(({mtime}) => mtime.getTime())),
        )
github parcel-bundler / parcel / src / core / cache / src / FSCache.js View on Github external
        files.map(file => fs.stat(file).then(({mtime}) => mtime.getTime()))
      )).reduce((a, b) => Math.max(a, b), 0);
github parcel-bundler / parcel / src / core / cache / src / FSCache.js View on Github external
async getLastModified(filename) {
    if (isGlob(filename)) {
      let files = await glob(filename, {
        onlyFiles: true
      });

      return (await Promise.all(
        files.map(file => fs.stat(file).then(({mtime}) => mtime.getTime()))
      )).reduce((a, b) => Math.max(a, b), 0);
    }
    return (await fs.stat(filename)).mtime.getTime();
  }
github parcel-bundler / parcel / packages / core / parcel-bundler / src / FSCache.js View on Github external
async read(filename) {
    if (this.invalidated.has(filename)) {
      return null;
    }

    let cacheFile = this.getCacheFile(filename);

    try {
      let stats = await fs.stat(filename);
      let cacheStats = await fs.stat(cacheFile);

      if (stats.mtime > cacheStats.mtime) {
        return null;
      }

      let json = await fs.readFile(cacheFile);
      let data = JSON.parse(json);
      if (!(await this.checkDepMtimes(data))) {
        return null;
      }

      return data;
    } catch (err) {
      return null;
    }
  }