package resolver
import "github.com/evanw/esbuild/internal/resolver"
Index ¶
- Variables
- func IsInsideNodeModules(path string) bool
- func IsPackagePath(path string) bool
- type AlternativeApproach
- type DataURL
- func ParseDataURL(url string) (parsed DataURL, ok bool)
- func (parsed DataURL) DecodeData() (string, error)
- func (parsed DataURL) DecodeMIMEType() MIMEType
- type DebugMeta
- type IgnoreIfUnusedData
- type MIMEType
- type PathPair
- type ResolveResult
- type Resolver
- type TSConfigJSON
Variables ¶
var BuiltInNodeModules = map[string]bool{ "assert": true, "async_hooks": true, "buffer": true, "child_process": true, "cluster": true, "console": true, "constants": true, "crypto": true, "dgram": true, "dns": true, "domain": true, "events": true, "fs": true, "http": true, "http2": true, "https": true, "inspector": true, "module": true, "net": true, "os": true, "path": true, "perf_hooks": true, "process": true, "punycode": true, "querystring": true, "readline": true, "repl": true, "stream": true, "string_decoder": true, "sys": true, "timers": true, "tls": true, "trace_events": true, "tty": true, "url": true, "util": true, "v8": true, "vm": true, "worker_threads": true, "zlib": true, }
Functions ¶
func IsInsideNodeModules ¶
func IsPackagePath ¶
Package paths are loaded from a "node_modules" directory. Non-package paths are relative or absolute paths.
Types ¶
type AlternativeApproach ¶
type AlternativeApproach uint8
const ( AlternativeApproachNone AlternativeApproach = iota AlternativeApproachImport AlternativeApproachRequire )
type DataURL ¶
type DataURL struct {
// contains filtered or unexported fields
}
func ParseDataURL ¶
func (DataURL) DecodeData ¶
func (DataURL) DecodeMIMEType ¶
type DebugMeta ¶
type DebugMeta struct {
// contains filtered or unexported fields
}
func (DebugMeta) Notes ¶
type IgnoreIfUnusedData ¶
type IgnoreIfUnusedData struct { Source *logger.Source Range logger.Range // If true, "sideEffects" was an array. If false, "sideEffects" was false. IsSideEffectsArrayInJSON bool }
type MIMEType ¶
type MIMEType uint8
const ( MIMETypeUnsupported MIMEType = iota MIMETypeTextCSS MIMETypeTextJavaScript MIMETypeApplicationJSON )
type PathPair ¶
type PathPair struct { // Either secondary will be empty, or primary will be "module" and secondary // will be "main" Primary logger.Path Secondary logger.Path }
Path resolution is a mess. One tricky issue is the "module" override for the "main" field in "package.json" files. Bundlers generally prefer "module" over "main" but that breaks packages that export a function in "main" for use with "require()", since resolving to "module" means an object will be returned. We attempt to handle this automatically by having import statements resolve to "module" but switch that out later for "main" if "require()" is used too.
func (*PathPair) HasSecondary ¶
type ResolveResult ¶
type ResolveResult struct { PathPair PathPair // If this was resolved by a plugin, the plugin gets to store its data here PluginData interface{} // If not empty, these should override the default values JSXFactory []string // Default if empty: "React.createElement" JSXFragment []string // Default if empty: "React.Fragment" DifferentCase *fs.DifferentCase // If true, any ES6 imports to this file can be considered to have no side // effects. This means they should be removed if unused. IgnorePrimaryIfUnused *IgnoreIfUnusedData IsExternal bool // If true, the class field transform should use Object.defineProperty(). UseDefineForClassFieldsTS bool // If true, unused imports are retained in TypeScript code. This matches the // behavior of the "importsNotUsedAsValues" field in "tsconfig.json" when the // value is not "remove". PreserveUnusedImportsTS bool // This is the "type" field from "package.json" ModuleType config.ModuleType }
type Resolver ¶
type Resolver interface { Resolve(sourceDir string, importPath string, kind ast.ImportKind) (result *ResolveResult, debug DebugMeta) ResolveAbs(absPath string) *ResolveResult PrettyPath(path logger.Path) string // This tries to run "Resolve" on a package path as a relative path. If // successful, the user just forgot a leading "./" in front of the path. ProbeResolvePackageAsRelative(sourceDir string, importPath string, kind ast.ImportKind) *ResolveResult }
func NewResolver ¶
type TSConfigJSON ¶
type TSConfigJSON struct { // The absolute path of "compilerOptions.baseUrl" BaseURL *string // This is used if "Paths" is non-nil. It's equal to "BaseURL" except if // "BaseURL" is missing, in which case it is as if "BaseURL" was ".". This // is to implement the "paths without baseUrl" feature from TypeScript 4.1. // More info: https://github.com/microsoft/TypeScript/issues/31869 BaseURLForPaths string // The verbatim values of "compilerOptions.paths". The keys are patterns to // match and the values are arrays of fallback paths to search. Each key and // each fallback path can optionally have a single "*" wildcard character. // If both the key and the value have a wildcard, the substring matched by // the wildcard is substituted into the fallback path. The keys represent // module-style path names and the fallback paths are relative to the // "baseUrl" value in the "tsconfig.json" file. Paths map[string][]string JSXFactory []string JSXFragmentFactory []string UseDefineForClassFields bool PreserveImportsNotUsedAsValues bool }
func ParseTSConfigJSON ¶
func ParseTSConfigJSON( log logger.Log, source logger.Source, jsonCache *cache.JSONCache, extends func(string, logger.Range) *TSConfigJSON, ) *TSConfigJSON
Source Files ¶
dataurl.go package_json.go resolver.go tsconfig_json.go
- Version
- v0.11.1
- Published
- Mar 29, 2021
- Platform
- windows/amd64
- Imports
- 18 packages
- Last checked
- 16 minutes ago –
Tools for package owners.