esnode/resolve.js
/**
 * Analyze, resolve and transform path using specified options.
 *
 * @param options Resolve options.
 * @return Resolved path.
 * @author Oleksandr Dakal <oleksandr-dakal@project-kit.org>
 */
Analyze, resolve and transform path using specified options.
@param options Resolve options.
@return Resolved path.
@author Oleksandr Dakal 
Analyze resolve and transform path using specified options . @param options Resolve options . @return Resolved path . @author Oleksandr Dakal
function resolvePath({ path, file, root, scan, globs, files }) {
    let output = path;
    const glob = globs.find(({ alias }) => micromatch_1.isMatch(output, alias));
    if (glob && isGlobMappingValid(glob)) {
        const captures = micromatch_1.capture(glob.alias, output);
        const realLocations = glob.paths.map(pathGlob => {
            return path_1.posix.join(root, pathGlob.replace(/[*]{2}/g, () => captures.shift()));
        });
        if (scan) {
            output = realLocations.find(fileName => {
                return !!files.find(sourcePath => sourcePath.indexOf(fileName) > -1);
            });
            if (!output) {
                throw new Error(`Paths not found`);
            }
        }
        else {
            if (realLocations.length > 1) {
                logger_1.logger.warning('Path resolved only to first glob');
            }
            output = realLocations[0];
        }
        output = path_1.posix.relative(path_1.posix.dirname(file), output);
        if (output[0] !== '.') {
            output = `./${output}`;
        }
        if (output.indexOf(EXTERNAL_DELIMITER) > -1) {
            output = output.split(EXTERNAL_DELIMITER)[1];
        }
        logger_1.logger.debug(chalk_1.default.blue(`${path} => ${output}`));
    }
    return output;
}
function resolvePath ( { path , file , root , scan , globs , files } ) { let output = path ; const glob = globs . find ( ( { alias } ) => micromatch_1 . isMatch ( output , alias ) ) ; if ( glob && isGlobMappingValid ( glob ) ) { const captures = micromatch_1 . capture ( glob . alias , output ) ; const realLocations = glob . paths . map ( pathGlob => { return path_1 . posix . join ( root , pathGlob . replace ( / [*]{2} / g , ( ) => captures . shift ( ) ) ) ; } ) ; if ( scan ) { output = realLocations . find ( fileName => { return ! ! files . find ( sourcePath => sourcePath . indexOf ( fileName ) > - 1 ) ; } ) ; if ( ! output ) { throw new Error ( ` ` ) ; } } else { if ( realLocations . length > 1 ) { logger_1 . logger . warning ( 'Path resolved only to first glob' ) ; } output = realLocations [ 0 ] ; } output = path_1 . posix . relative ( path_1 . posix . dirname ( file ) , output ) ; if ( output [ 0 ] !== '.' ) { output = ` ${ output } ` ; } if ( output . indexOf ( EXTERNAL_DELIMITER ) > - 1 ) { output = output . split ( EXTERNAL_DELIMITER ) [ 1 ] ; } logger_1 . logger . debug ( chalk_1 . default . blue ( ` ${ path } ${ output } ` ) ) ; } return output ; }
Analyze, resolve and transform path using specified options.
Analyze resolve and transform path using specified options .
// Output path. // Find glob mapping by matching alias wildcard. // Check glob mapping validness. // Generate captures from glob. // Possible real locations. // Match to find suitable file from compiled and external sources. // When there are more than one path glob need to noitfy. // Only use first one. // Relative path from file to path target. // Same dir path. // Use node module resolution for external package. // Output debug: resolved alias.