<commit_before>import {
  isString,
  isFunction,
  each,
  has,
} from "underscore";

import { readAndWatchFileWithHash } from "../fs/watch.js";
import { matches as archMatches } from "../utils/archinfo.js";
import {
  pathJoin,
  pathRelative,
  pathNormalize,
  pathDirname,
  statOrNull as realStatOrNull,
  convertToOSPath,
  convertToPosixPath,
} from "../fs/files.js";

const nativeModulesMap = Object.create(null);
const nativeNames = Object.keys(process.binding("natives"));

// Node 0.10 does not include process as a built-in module, but later
// versions of Node do, and we provide a stub for it on the client.
nativeNames.push("process");

nativeNames.forEach(id => {
  if (id === "freelist" ||
      id.startsWith("internal/")) {
    return;
  }

  // When a native Node module is imported, we register a dependency on a
  // meteor-node-stubs/deps/* module of the same name, so that the
  // necessary stub modules will be included in the bundle. This alternate
  // identifier will not be imported at runtime, but the modules it
  // depends on are necessary for the original import to succeed.
  nativeModulesMap[id] =  "meteor-node-stubs/deps/" + id;
});

export default class Resolver {
  constructor({
    sourceRoot,
    targetArch,
    extensions = [".js", ".json"],
    nodeModulesPaths = [],
    watchSet = null,
    onPackageJson,
    onMissing,
    statOrNull = realStatOrNull,
  }) {
    this.sourceRoot = sourceRoot;
    this.extensions = extensions;
    this.targetArch = targetArch;
    this.nodeModulesPaths = nodeModulesPaths;
    this.watchSet = watchSet;
    this.onPackageJson = onPackageJson;
    this.onMissing = onMissing;
    this.statOrNull = statOrNull;

    this._resolveCache = new Map;
    this._statCache = new Map;
    this._pkgJsonCache = new Map;
  }

  static isTopLevel(id) {
    return "./".indexOf(id.charAt(0)) < 0;
  }

  static isNative(id) {
    return has(nativeModulesMap, id);
  }

  static getNativeStubId(id) {
    return nativeModulesMap[id] || null;
  }

  // Resolve the given module identifier to an object { path, stat } or
  // null, relative to an absolute parent path. The _seenDirPaths
  // parameter is for internal use only and should be ommitted.
  resolve(id, absParentPath, _seenDirPaths) {
    const byParentDir = this._resolveCache[id] || Object.create(null);
    const absParentDir = pathDirname(absParentPath);
    if (has(byParentDir, absParentDir)) {
      return byParentDir[absParentDir];
    }

    this._resolveCache[id] = byParentDir;

    let resolved =
      this._resolveAbsolute(id, absParentPath) ||
      this._resolveRelative(id, absParentPath) ||<commit_msg>Fix misuse of Map object in Resolver.prototype.resolve.<commit_after>import {
  isString,
  isFunction,
  each,
  has,
} from "underscore";

import { readAndWatchFileWithHash } from "../fs/watch.js";
import { matches as archMatches } from "../utils/archinfo.js";
import {
  pathJoin,
  pathRelative,
  pathNormalize,
  pathDirname,
  statOrNull as realStatOrNull,
  convertToOSPath,
  convertToPosixPath,
} from "../fs/files.js";

const nativeModulesMap = Object.create(null);
const nativeNames = Object.keys(process.binding("natives"));

// Node 0.10 does not include process as a built-in module, but later
// versions of Node do, and we provide a stub for it on the client.
nativeNames.push("process");

nativeNames.forEach(id => {
  if (id === "freelist" ||
      id.startsWith("internal/")) {
    return;
  }

  // When a native Node module is imported, we register a dependency on a
  // meteor-node-stubs/deps/* module of the same name, so that the
  // necessary stub modules will be included in the bundle. This alternate
  // identifier will not be imported at runtime, but the modules it
  // depends on are necessary for the original import to succeed.
  nativeModulesMap[id] =  "meteor-node-stubs/deps/" + id;
});

export default class Resolver {
  constructor({
    sourceRoot,
    targetArch,
    extensions = [".js", ".json"],
    nodeModulesPaths = [],
    watchSet = null,
    onPackageJson,
    onMissing,
    statOrNull = realStatOrNull,
  }) {
    this.sourceRoot = sourceRoot;
    this.extensions = extensions;
    this.targetArch = targetArch;
    this.nodeModulesPaths = nodeModulesPaths;
    this.watchSet = watchSet;
    this.onPackageJson = onPackageJson;
    this.onMissing = onMissing;
    this.statOrNull = statOrNull;

    this._resolveCache = new Map;
    this._statCache = new Map;
    this._pkgJsonCache = new Map;
  }

  static isTopLevel(id) {
    return "./".indexOf(id.charAt(0)) < 0;
  }

  static isNative(id) {
    return has(nativeModulesMap, id);
  }

  static getNativeStubId(id) {
    return nativeModulesMap[id] || null;
  }

  // Resolve the given module identifier to an object { path, stat } or
  // null, relative to an absolute parent path. The _seenDirPaths
  // parameter is for internal use only and should be ommitted.
  resolve(id, absParentPath, _seenDirPaths) {
    if (! this._resolveCache.has(id)) {
      this._resolveCache.set(id, Object.create(null));
    }

    const byParentDir = this._resolveCache.get(id);
    const absParentDir = pathDirname(absParentPath);
    if (has(byParentDir, absParentDir)) {
      return byParentDir[absParentDir];
    }

    let resolved =
      this._resolveAbsolute(id, absParentPath) ||
      this._resolveRelative(id, absParentPath) ||
{'fraction_non_alphanumeric': 0.11028592647604901, 'fraction_numerical': 0.001856665428889714, 'mean_word_length': 3.3939641109298533, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7190925', 'n_tokens_mistral': 1672, 'n_tokens_neox': 1656, 'n_words': 477}