lib/resolver/package.js
function resolveId(details, filepath) {
  let id = '';

  if ('string' == typeof filepath) {
    // Only version if more than one package
    const version = details.id.includes(versionDelimiter) ? versionDelimiter + details.version : '';
    const versioned = (id, stripExtension) => {
      // Strip extension
      if (stripExtension) id = id.replace(path.extname(id), '');
      return (process.platform == 'win32' ? id.replace(/\\/g, '/') : id) + version;
    };

    // Resolve aliases
    id = alias.resolve(filepath, details.aliases);
    // Ignore disabled (false)
    id = id || filepath;
    // Return if resolved id
    if (!isFilepath(id)) return versioned(id, false);
    // Resolve alias to id (also handles main => id)
    id = alias.resolveReverse(id, details.aliases);
    // Return if resolved id
    if (!isFilepath(id)) return versioned(id, false);

    // Resolve ids from project root if nested project package
    const pkgpath = details.isNestedProjectPackage
      ? process.cwd()
      : // Resolve ids from node_modules root if npm package
        details.isNpmPackage ? details.dirname : details.pkgpath;

    [...details.paths, pkgpath].some(sourcepath => {
      if (filepath.includes(sourcepath)) {
        id = path.relative(sourcepath, filepath);
        return true;
      }
    });

    return versioned(id, true);
  }

  return id;
}
function resolveId(details, filepath) {
  let id = '';

  if ('string' == typeof filepath) {
    // Only version if more than one package
    const version = details.id.includes(versionDelimiter) ? versionDelimiter + details.version : '';
    const versioned = (id, stripExtension) => {
      // Strip extension
      if (stripExtension) id = id.replace(path.extname(id), '');
      return (process.platform == 'win32' ? id.replace(/\\/g, '/') : id) + version;
    };

    // Resolve aliases
    id = alias.resolve(filepath, details.aliases);
    // Ignore disabled (false)
    id = id || filepath;
    // Return if resolved id
    if (!isFilepath(id)) return versioned(id, false);
    // Resolve alias to id (also handles main => id)
    id = alias.resolveReverse(id, details.aliases);
    // Return if resolved id
    if (!isFilepath(id)) return versioned(id, false);

    // Resolve ids from project root if nested project package
    const pkgpath = details.isNestedProjectPackage
      ? process.cwd()
      : // Resolve ids from node_modules root if npm package
        details.isNpmPackage ? details.dirname : details.pkgpath;

    [...details.paths, pkgpath].some(sourcepath => {
      if (filepath.includes(sourcepath)) {
        id = path.relative(sourcepath, filepath);
        return true;
      }
    });

    return versioned(id, true);
  }

  return id;
}
function resolveId ( details , filepath ) { let id = '' ; if ( 'string' == typeof filepath ) { // Only version if more than one package const version = details . id . includes ( versionDelimiter ) ? versionDelimiter + details . version : '' ; const versioned = ( id , stripExtension ) => { // Strip extension if ( stripExtension ) id = id . replace ( path . extname ( id ) , '' ) ; return ( process . platform == 'win32' ? id . replace ( / \\ / g , '/' ) : id ) + version ; } ; // Resolve aliases id = alias . resolve ( filepath , details . aliases ) ; // Ignore disabled (false) id = id || filepath ; // Return if resolved id if ( ! isFilepath ( id ) ) return versioned ( id , false ) ; // Resolve alias to id (also handles main => id) id = alias . resolveReverse ( id , details . aliases ) ; // Return if resolved id if ( ! isFilepath ( id ) ) return versioned ( id , false ) ; // Resolve ids from project root if nested project package const pkgpath = details . isNestedProjectPackage ? process . cwd ( ) : // Resolve ids from node_modules root if npm package details . isNpmPackage ? details . dirname : details . pkgpath ; [ ... details . paths , pkgpath ] . some ( sourcepath => { if ( filepath . includes ( sourcepath ) ) { id = path . relative ( sourcepath , filepath ) ; return true ; } } ) ; return versioned ( id , true ) ; } return id ; }
Resolve id for 'filepath'
@param {Object} details
@param {String} filepath
@returns {String}
Resolve id for filepath