resolver

package
v0.19.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 11, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BuiltInNodeModules = map[string]bool{
	"_http_agent":         true,
	"_http_client":        true,
	"_http_common":        true,
	"_http_incoming":      true,
	"_http_outgoing":      true,
	"_http_server":        true,
	"_stream_duplex":      true,
	"_stream_passthrough": true,
	"_stream_readable":    true,
	"_stream_transform":   true,
	"_stream_wrap":        true,
	"_stream_writable":    true,
	"_tls_common":         true,
	"_tls_wrap":           true,
	"assert":              true,
	"assert/strict":       true,
	"async_hooks":         true,
	"buffer":              true,
	"child_process":       true,
	"cluster":             true,
	"console":             true,
	"constants":           true,
	"crypto":              true,
	"dgram":               true,
	"diagnostics_channel": true,
	"dns":                 true,
	"dns/promises":        true,
	"domain":              true,
	"events":              true,
	"fs":                  true,
	"fs/promises":         true,
	"http":                true,
	"http2":               true,
	"https":               true,
	"inspector":           true,
	"module":              true,
	"net":                 true,
	"os":                  true,
	"path":                true,
	"path/posix":          true,
	"path/win32":          true,
	"perf_hooks":          true,
	"process":             true,
	"punycode":            true,
	"querystring":         true,
	"readline":            true,
	"repl":                true,
	"stream":              true,
	"stream/consumers":    true,
	"stream/promises":     true,
	"stream/web":          true,
	"string_decoder":      true,
	"sys":                 true,
	"timers":              true,
	"timers/promises":     true,
	"tls":                 true,
	"trace_events":        true,
	"tty":                 true,
	"url":                 true,
	"util":                true,
	"util/types":          true,
	"v8":                  true,
	"vm":                  true,
	"wasi":                true,
	"worker_threads":      true,
	"zlib":                true,
}

This list can be obtained with the following command:

node --experimental-wasi-unstable-preview1 -p "[...require('module').builtinModules].join('\n')"

Be sure to use the *LATEST* version of node when updating this list!

Functions

func IsPackagePath added in v0.5.20

func IsPackagePath(path string) bool

Package paths are loaded from a "node_modules" directory. Non-package paths are relative or absolute paths.

func PrettyPath added in v0.16.13

func PrettyPath(fs fs.FS, path logger.Path) string

Types

type DataURL added in v0.8.57

type DataURL struct {
	// contains filtered or unexported fields
}

func ParseDataURL added in v0.8.57

func ParseDataURL(url string) (parsed DataURL, ok bool)

func (DataURL) DecodeData added in v0.8.57

func (parsed DataURL) DecodeData() (string, error)

func (DataURL) DecodeMIMEType added in v0.8.57

func (parsed DataURL) DecodeMIMEType() MIMEType

type DebugMeta added in v0.9.3

type DebugMeta struct {
	ModifiedImportPath string
	// contains filtered or unexported fields
}

func (DebugMeta) LogErrorMsg added in v0.11.10

func (dm DebugMeta) LogErrorMsg(log logger.Log, source *logger.Source, r logger.Range, text string, suggestion string, notes []logger.MsgData)

type MIMEType added in v0.8.57

type MIMEType uint8
const (
	MIMETypeUnsupported MIMEType = iota
	MIMETypeTextCSS
	MIMETypeTextJavaScript
	MIMETypeApplicationJSON
)

type PathPair added in v0.7.0

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 added in v0.7.0

func (pp *PathPair) HasSecondary() bool

type ResolveResult added in v0.4.6

type ResolveResult struct {
	PathPair PathPair

	// If this was resolved by a plugin, the plugin gets to store its data here
	PluginData interface{}

	DifferentCase *fs.DifferentCase

	// If present, any ES6 imports to this file can be considered to have no side
	// effects. This means they should be removed if unused.
	PrimarySideEffectsData *SideEffectsData

	// These are from "tsconfig.json"
	TSConfigJSX    config.TSConfigJSX
	TSConfig       *config.TSConfig
	TSAlwaysStrict *config.TSAlwaysStrict

	// This is the "type" field from "package.json"
	ModuleTypeData js_ast.ModuleTypeData

	IsExternal bool
}

type Resolver

type Resolver struct {
	// contains filtered or unexported fields
}

func NewResolver

func NewResolver(call config.APICall, fs fs.FS, log logger.Log, caches *cache.CacheSet, options *config.Options) *Resolver

func (*Resolver) ProbeResolvePackageAsRelative added in v0.8.12

func (res *Resolver) ProbeResolvePackageAsRelative(sourceDir string, importPath string, kind ast.ImportKind) (*ResolveResult, DebugMeta)

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.

func (*Resolver) Resolve

func (res *Resolver) Resolve(sourceDir string, importPath string, kind ast.ImportKind) (*ResolveResult, DebugMeta)

func (*Resolver) ResolveGlob added in v0.19.0

func (res *Resolver) ResolveGlob(sourceDir string, importPathPattern []helpers.GlobPart, kind ast.ImportKind, prettyPattern string) (map[string]ResolveResult, *logger.Msg)

This returns nil on failure and non-nil on success. Note that this may return an empty array to indicate a successful search that returned zero results.

type SideEffectsData added in v0.11.8

type SideEffectsData struct {
	Source *logger.Source

	// If non-empty, this false value came from a plugin
	PluginName string

	Range logger.Range

	// If true, "sideEffects" was an array. If false, "sideEffects" was false.
	IsSideEffectsArrayInJSON bool
}

type TSConfigJSON added in v0.7.22

type TSConfigJSON struct {
	AbsPath string

	// 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 *TSConfigPaths

	TSStrict       *config.TSAlwaysStrict
	TSAlwaysStrict *config.TSAlwaysStrict
	JSXSettings    config.TSConfigJSX
	Settings       config.TSConfig
	// contains filtered or unexported fields
}

func ParseTSConfigJSON added in v0.7.22

func ParseTSConfigJSON(
	log logger.Log,
	source logger.Source,
	jsonCache *cache.JSONCache,
	extends func(string, logger.Range) *TSConfigJSON,
) *TSConfigJSON

func (*TSConfigJSON) TSAlwaysStrictOrStrict added in v0.15.8

func (config *TSConfigJSON) TSAlwaysStrictOrStrict() *config.TSAlwaysStrict

type TSConfigPath added in v0.14.29

type TSConfigPath struct {
	Text string
	Loc  logger.Loc
}

type TSConfigPaths added in v0.14.29

type TSConfigPaths struct {
	Map map[string][]TSConfigPath

	// This may be different from the original "tsconfig.json" source if the
	// "paths" value is from another file via an "extends" clause.
	Source logger.Source
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL