function resolveBazel(importee, importer, baseDir = process.cwd(), resolve = require.resolve, root = rootDir) {
  log_verbose(`resolving '${importee}' from ${importer}`);

  function resolveInRootDir(importee) {
    var candidate = path.join(baseDir, root, importee);
    log_verbose(`try to resolve '${importee}' at '${candidate}'`);
    try {
      var result = resolve(candidate);
      return result;
    } catch (e) {
      return undefined;
    }
  }

  // Since mappings are always in POSIX paths, when comparing the importee to mappings
  // we should normalize the importee.
  // Having it normalized is also useful to determine relative paths.
  const normalizedImportee = importee.replace(/\\/g, '/');

  // If import is fully qualified then resolve it directly
  if (fileExists(importee)) {
    log_verbose(`resolved fully qualified '${importee}'`);
    return importee;
  }

  // process.cwd() is the execroot and ends up looking something like
  // `.../2c2a834fcea131eff2d962ffe20e1c87/bazel-sandbox/872535243457386053/execroot/<workspace_name>`
  // from that path to the es6 output is
  // `<bin_dir_path>/<build_file_dirname>/<label_name>.es6` from there, sources
  // from the user's workspace are under `<path_to_source>` and sources from external
  // workspaces are under `external/<external_workspace_name>/<path_to_source>`
  var resolved;
  if (normalizedImportee.startsWith('./') || normalizedImportee.startsWith('../')) {
    // relative import
    if (importer) {
      let importerRootRelative = path.dirname(importer);
      const relative = path.relative(path.join(baseDir, root), importerRootRelative);
      if (!relative.startsWith('.')) {
        importerRootRelative = relative;
      }
      resolved = path.join(importerRootRelative, importee);
    } else {
      throw new Error('cannot resolve relative paths without an importer');
    }
    if (resolved) resolved = resolveInRootDir(resolved);
  }

  if (!resolved) {
    // possible workspace import or external import if importee matches a module
    // mapping
    for (const k in moduleMappings) {
      if (normalizedImportee == k || normalizedImportee.startsWith(k + '/')) {
        // replace the root module name on a mappings match
        // note that the module_root attribute is intended to be used for type-checking
        // so it uses eg. "index.d.ts". At runtime, we have only index.js, so we strip the
        // .d.ts suffix and let node require.resolve do its thing.
        var v = moduleMappings[k].replace(/\.d\.ts$/, '');
        const mappedImportee = path.join(v, normalizedImportee.slice(k.length + 1));
        log_verbose(`module mapped '${importee}' to '${mappedImportee}'`);
        resolved = resolveInRootDir(mappedImportee);
        if (resolved) break;
      }
    }
  }

  if (!resolved) {
    // workspace import
    const userWorkspacePath = path.relative(workspaceName, importee);
    resolved = resolveInRootDir(userWorkspacePath.startsWith('..') ? importee : userWorkspacePath);
  }

  if (resolved) {
    log_verbose(`resolved to ${resolved}`);
  } else {
    log_verbose(`allowing rollup to resolve '${importee}' with node module resolution`);
  }

  return resolved;
}
// modules based on a mapping of short names to paths.
modules based on a mapping of short names to paths.
modules based on a mapping of short names to paths .
function resolveBazel(importee, importer, baseDir = process.cwd(), resolve = require.resolve, root = rootDir) {
  log_verbose(`resolving '${importee}' from ${importer}`);
  function resolveInRootDir(importee) {
    var candidate = path.join(baseDir, root, importee);
    log_verbose(`try to resolve '${importee}' at '${candidate}'`);
    try {
      var result = resolve(candidate);
      return result;
    } catch (e) {
      return undefined;
    }
  }
  const normalizedImportee = importee.replace(/\\/g, '/');
  if (fileExists(importee)) {
    log_verbose(`resolved fully qualified '${importee}'`);
    return importee;
  }
  var resolved;
  if (normalizedImportee.startsWith('./') || normalizedImportee.startsWith('../')) {
    if (importer) {
      let importerRootRelative = path.dirname(importer);
      const relative = path.relative(path.join(baseDir, root), importerRootRelative);
      if (!relative.startsWith('.')) {
        importerRootRelative = relative;
      }
      resolved = path.join(importerRootRelative, importee);
    } else {
      throw new Error('cannot resolve relative paths without an importer');
    }
    if (resolved) resolved = resolveInRootDir(resolved);
  }
  if (!resolved) {
    for (const k in moduleMappings) {
      if (normalizedImportee == k || normalizedImportee.startsWith(k + '/')) {
        var v = moduleMappings[k].replace(/\.d\.ts$/, '');
        const mappedImportee = path.join(v, normalizedImportee.slice(k.length + 1));
        log_verbose(`module mapped '${importee}' to '${mappedImportee}'`);
        resolved = resolveInRootDir(mappedImportee);
        if (resolved) break;
      }
    }
  }
  if (!resolved) {
    const userWorkspacePath = path.relative(workspaceName, importee);
    resolved = resolveInRootDir(userWorkspacePath.startsWith('..') ? importee : userWorkspacePath);
  }
  if (resolved) {
    log_verbose(`resolved to ${resolved}`);
  } else {
    log_verbose(`allowing rollup to resolve '${importee}' with node module resolution`);
  }
  return resolved;
}
function resolveBazel ( importee , importer , baseDir = process . cwd ( ) , resolve = require . resolve , root = rootDir ) { log_verbose ( ` ${ importee } ${ importer } ` ) ; function resolveInRootDir ( importee ) { var candidate = path . join ( baseDir , root , importee ) ; log_verbose ( ` ${ importee } ${ candidate } ` ) ; try { var result = resolve ( candidate ) ; return result ; } catch ( e ) { return undefined ; } } const normalizedImportee = importee . replace ( / \\ / g , '/' ) ; if ( fileExists ( importee ) ) { log_verbose ( ` ${ importee } ` ) ; return importee ; } var resolved ; if ( normalizedImportee . startsWith ( './' ) || normalizedImportee . startsWith ( '../' ) ) { if ( importer ) { let importerRootRelative = path . dirname ( importer ) ; const relative = path . relative ( path . join ( baseDir , root ) , importerRootRelative ) ; if ( ! relative . startsWith ( '.' ) ) { importerRootRelative = relative ; } resolved = path . join ( importerRootRelative , importee ) ; } else { throw new Error ( 'cannot resolve relative paths without an importer' ) ; } if ( resolved ) resolved = resolveInRootDir ( resolved ) ; } if ( ! resolved ) { for ( const k in moduleMappings ) { if ( normalizedImportee == k || normalizedImportee . startsWith ( k + '/' ) ) { var v = moduleMappings [ k ] . replace ( / \.d\.ts$ / , '' ) ; const mappedImportee = path . join ( v , normalizedImportee . slice ( k . length + 1 ) ) ; log_verbose ( ` ${ importee } ${ mappedImportee } ` ) ; resolved = resolveInRootDir ( mappedImportee ) ; if ( resolved ) break ; } } } if ( ! resolved ) { const userWorkspacePath = path . relative ( workspaceName , importee ) ; resolved = resolveInRootDir ( userWorkspacePath . startsWith ( '..' ) ? importee : userWorkspacePath ) ; } if ( resolved ) { log_verbose ( ` ${ resolved } ` ) ; } else { log_verbose ( ` ${ importee } ` ) ; } return resolved ; }
modules based on a mapping of short names to paths.
modules based on a mapping of short names to paths .
// Since mappings are always in POSIX paths, when comparing the importee to mappings // we should normalize the importee. // Having it normalized is also useful to determine relative paths. // If import is fully qualified then resolve it directly // process.cwd() is the execroot and ends up looking something like // `.../2c2a834fcea131eff2d962ffe20e1c87/bazel-sandbox/872535243457386053/execroot/<workspace_name>` // from that path to the es6 output is // `<bin_dir_path>/<build_file_dirname>/<label_name>.es6` from there, sources // from the user's workspace are under `<path_to_source>` and sources from external // workspaces are under `external/<external_workspace_name>/<path_to_source>` // relative import // possible workspace import or external import if importee matches a module // mapping // replace the root module name on a mappings match // note that the module_root attribute is intended to be used for type-checking // so it uses eg. "index.d.ts". At runtime, we have only index.js, so we strip the // .d.ts suffix and let node require.resolve do its thing. // workspace import