<commit_before>import walk from 'walk';
import path from 'path';
import fs from 'fs';
import mime from 'mime-types';

const MAX_FILE_SIZE_BYTES = 15728640;
const DEFAULT_SKIPPED_ASSETS = [];

export default class FileSystemAssetLoader {
  constructor(options) {
    this.options = options;
    this.options.skippedAssets = this.options.skippedAssets || DEFAULT_SKIPPED_ASSETS;
  }
  findSnapshotResources(page, percyClient) {
    return new Promise((resolve, reject) => {
      const options = this.options;
      const buildDir = options.buildDir;
      const mountPath = `${options.mountPath || ''}/`;

      let isDirectory = false;
      try {
        isDirectory = fs.statSync(buildDir).isDirectory();
      } catch (err) {
        reject(err);
        return;
      }

      if (isDirectory) {
        const resources = [];
        let errors;
        walk.walkSync(buildDir, {
          followLinks: true,
          listeners: {
            file: function file(root, fileStats, next) {
              const absolutePath = path.join(root, fileStats.name);
              let resourceUrl = absolutePath.replace(buildDir, '');
              if (path.sep === '\\') {
                // Windows: transform filesystem backslashes into forward-slashes for the URL.
                resourceUrl = resourceUrl.replace(/\\/g, '/');
              }

              if (resourceUrl.charAt(0) === '/') {
                resourceUrl = resourceUrl.substr(1);
              }
              for (const assetPattern of options.skippedAssets) {
                if (resourceUrl.match(assetPattern)) {
                  next();
                  return;
                }
              }
              if (fs.statSync(absolutePath).size > MAX_FILE_SIZE_BYTES) {
                console.warn('\n[percy][WARNING] Skipping large file: ', resourceUrl); // eslint-disable-line no-console<commit_msg>Strip the buildDir from the resourceUrl after switching slashes<commit_after>import walk from 'walk';
import path from 'path';
import fs from 'fs';
import mime from 'mime-types';

const MAX_FILE_SIZE_BYTES = 15728640;
const DEFAULT_SKIPPED_ASSETS = [];

export default class FileSystemAssetLoader {
  constructor(options) {
    this.options = options;
    this.options.skippedAssets = this.options.skippedAssets || DEFAULT_SKIPPED_ASSETS;
  }
  findSnapshotResources(page, percyClient) {
    return new Promise((resolve, reject) => {
      const options = this.options;
      const buildDir = options.buildDir;
      const mountPath = `${options.mountPath || ''}/`;

      let isDirectory = false;
      try {
        isDirectory = fs.statSync(buildDir).isDirectory();
      } catch (err) {
        reject(err);
        return;
      }

      if (isDirectory) {
        const resources = [];
        let errors;
        walk.walkSync(buildDir, {
          followLinks: true,
          listeners: {
            file: function file(root, fileStats, next) {
              const absolutePath = path.join(root, fileStats.name);
              let resourceUrl = absolutePath;
              if (path.sep === '\\') {
                // Windows: transform filesystem backslashes into forward-slashes for the URL.
                resourceUrl = resourceUrl.replace(/\\/g, '/');
              }

              resourceUrl = resourceUrl.replace(buildDir, '');

              if (resourceUrl.charAt(0) === '/') {
                resourceUrl = resourceUrl.substr(1);
              }

              for (const assetPattern of options.skippedAssets) {
                if (resourceUrl.match(assetPattern)) {
                  next();
                  return;
                }
              }
              if (fs.statSync(absolutePath).size > MAX_FILE_SIZE_BYTES) {
                console.warn('\n[percy][WARNING] Skipping large file: ', resourceUrl); // eslint-disable-line no-console
{'fraction_non_alphanumeric': 0.11235370611183355, 'fraction_numerical': 0.005201560468140442, 'mean_word_length': 2.0475435816164818, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '638882', 'n_tokens_mistral': 1074, 'n_tokens_neox': 1032, 'n_words': 237}