// Returns the path of this file relative to "outbase", which is then ready to
// be joined with the absolute output directory path. The directory and name
// components are returned separately for convenience.
//
// This makes sure to have the directory end in a slash so that it can be
// substituted into a path template without necessarily having a "/" after it.
// Extra slashes should get cleaned up automatically when we join it with the
// output directory.
Returns the path of this file relative to "outbase", which is then ready to
be joined with the absolute output directory path. The directory and name
components are returned separately for convenience.

This makes sure to have the directory end in a slash so that it can be
substituted into a path template without necessarily having a "/" after it.
Extra slashes should get cleaned up automatically when we join it with the
output directory.
// Returns the path of this file relative to " outbase " which is then ready to // be joined with the absolute output directory path . The directory and name // components are returned separately for convenience . // // This makes sure to have the directory end in a slash so that it can be // substituted into a path template without necessarily having a " / " after it . // Extra slashes should get cleaned up automatically when we join it with the // output directory .
func (c *linkerContext) pathRelativeToOutbase(
	sourceIndex uint32,
	entryPointBit uint,
	stdExt string,
	avoidIndex bool,
) (relDir string, baseName string, baseExt string) {
	file := &c.graph.Files[sourceIndex]
	relDir = "/"
	baseExt = stdExt
	if c.options.AbsOutputFile != "" {
		baseName = c.fs.Base(c.options.AbsOutputFile)
		ext := c.fs.Ext(baseName)
		baseName = baseName[:len(baseName)-len(ext)]
		if _, ok := file.InputFile.Repr.(*graph.CSSRepr); ok || stdExt != c.options.OutputExtensionCSS {
			baseExt = ext
		}
		return
	}
	absPath := file.InputFile.Source.KeyPath.Text
	isCustomOutputPath := false
	if outPath := c.graph.EntryPoints()[entryPointBit].OutputPath; outPath != "" {
		absPath = outPath
		if !c.fs.IsAbs(absPath) {
			absPath = c.fs.Join(c.options.AbsOutputBase, absPath)
		}
		isCustomOutputPath = true
	} else if file.InputFile.Source.KeyPath.Namespace != "file" {
		dir, base, _ := logger.PlatformIndependentPathDirBaseExt(absPath)
		if avoidIndex && base == "index" {
			_, base, _ = logger.PlatformIndependentPathDirBaseExt(dir)
		}
		baseName = sanitizeFilePathForVirtualModulePath(base)
		return
	} else {
		if avoidIndex {
			base := c.fs.Base(absPath)
			base = base[:len(base)-len(c.fs.Ext(base))]
			if base == "index" {
				absPath = c.fs.Dir(absPath)
			}
		}
	}
	relPath, ok := c.fs.Rel(c.options.AbsOutputBase, absPath)
	if !ok {
		baseName = c.fs.Base(absPath)
	} else {
		relDir = c.fs.Dir(relPath) + "/"
		baseName = c.fs.Base(relPath)
		relDir = strings.ReplaceAll(relDir, "\\", "/")
		 Note that we can't just strip any leading "../" because that could
		 cause two separate entry point paths to collide. For example, there
		 could be both "src/index.js" and "../src/index.js" as entry points.
		dotDotCount := 0
		for strings.HasPrefix(relDir[dotDotCount*3:], "../") {
			dotDotCount++
		}
		if dotDotCount > 0 {
			 The use of "_.._" here is somewhat arbitrary but it is unlikely to
			 collide with a folder named by a human and it works on Windows
			 (Windows doesn't like names that end with a "."). And not starting
			 with a "." means that it will not be hidden on Unix.
			relDir = strings.Repeat("_.._/", dotDotCount) + relDir[dotDotCount*3:]
		}
		relDir = "/" + relDir
	}
	 Strip the file extension if the output path is an input file
	if !isCustomOutputPath {
		ext := c.fs.Ext(baseName)
		baseName = baseName[:len(baseName)-len(ext)]
	}
	return
}
func ( c * linkerContext ) pathRelativeToOutbase ( sourceIndex uint32 , entryPointBit uint , stdExt string , avoidIndex bool , ) ( relDir string , baseName string , baseExt string ) { file := & c . graph . Files [ sourceIndex ] relDir = " " baseExt = stdExt if c . options . AbsOutputFile != " " { baseName = c . fs . Base ( c . options . AbsOutputFile ) ext := c . fs . Ext ( baseName ) baseName = baseName [ : len ( baseName ) - len ( ext ) ] if _ , ok := file . InputFile . Repr . ( * graph . CSSRepr ) ; ok || stdExt != c . options . OutputExtensionCSS { baseExt = ext } return } absPath := file . InputFile . Source . KeyPath . Text isCustomOutputPath := false if outPath := c . graph . EntryPoints ( ) [ entryPointBit ] . OutputPath ; outPath != " " { absPath = outPath if ! c . fs . IsAbs ( absPath ) { absPath = c . fs . Join ( c . options . AbsOutputBase , absPath ) } isCustomOutputPath = true } else if file . InputFile . Source . KeyPath . Namespace != " " { dir , base , _ := logger . PlatformIndependentPathDirBaseExt ( absPath ) if avoidIndex && base == " " { _ , base , _ = logger . PlatformIndependentPathDirBaseExt ( dir ) } baseName = sanitizeFilePathForVirtualModulePath ( base ) return } else { if avoidIndex { base := c . fs . Base ( absPath ) base = base [ : len ( base ) - len ( c . fs . Ext ( base ) ) ] if base == " " { absPath = c . fs . Dir ( absPath ) } } } relPath , ok := c . fs . Rel ( c . options . AbsOutputBase , absPath ) if ! ok { baseName = c . fs . Base ( absPath ) } else { relDir = c . fs . Dir ( relPath ) + " " baseName = c . fs . Base ( relPath ) relDir = strings . ReplaceAll ( relDir , " \\ " , " " ) dotDotCount := 0 for strings . HasPrefix ( relDir [ dotDotCount * 3 : ] , " " ) { dotDotCount ++ } if dotDotCount > 0 { relDir = strings . Repeat ( " " , dotDotCount ) + relDir [ dotDotCount * 3 : ] } relDir = " " + relDir } if ! isCustomOutputPath { ext := c . fs . Ext ( baseName ) baseName = baseName [ : len ( baseName ) - len ( ext ) ] } return }
Returns the path of this file relative to "outbase", which is then ready to
be joined with the absolute output directory path.
Returns the path of this file relative to " outbase " which is then ready to be joined with the absolute output directory path .
// If the output path was configured explicitly, use it verbatim // Strip off the extension // Use the extension from the explicit output file path. However, don't do // that if this is a CSS chunk but the entry point file is not CSS. In that // case use the standard extension. This happens when importing CSS into JS. // Use the configured output path if present // Come up with a path for virtual paths (i.e. non-file-system paths) // Heuristic: If the file is named something like "index.js", then use // the name of the parent directory instead. This helps avoid the // situation where many chunks are named "index" because of people // dynamically-importing npm packages that make use of node's implicit // "index" file name feature. // Try to get a relative path to the base directory // This can fail in some situations such as on different drives on // Windows. In that case we just use the file name. // Now we finally have a relative path // Use platform-independent slashes // Replace leading "../" so we don't try to write outside of the output // directory. This normally can't happen because "AbsOutputBase" is // automatically computed to contain all entry point files, but it can // happen if someone sets it manually via the "outbase" API option. // // Note that we can't just strip any leading "../" because that could // cause two separate entry point paths to collide. For example, there // could be both "src/index.js" and "../src/index.js" as entry points. // The use of "_.._" here is somewhat arbitrary but it is unlikely to // collide with a folder named by a human and it works on Windows // (Windows doesn't like names that end with a "."). And not starting // with a "." means that it will not be hidden on Unix. // Strip the file extension if the output path is an input file