server

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 63 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const DEBUG = false

production mode

View Source
const (
	MB = 1 << 20
)

Variables

View Source
var VERSION = "PROD"

defined by `-ldflags`

Functions

func Start

func Start()

Start starts the esm.sh server

Types

type AllowList

type AllowList struct {
	Packages []string `json:"packages"`
	Scopes   []string `json:"scopes"`
}

func (*AllowList) IsEmpty

func (allowList *AllowList) IsEmpty() bool

func (*AllowList) IsPackageAllowed

func (allowList *AllowList) IsPackageAllowed(moduleName string) bool

IsPackageAllowed Checking if the package is allowed. The `packages` list is the highest priority allow rule to match, so the `includes` list in the `scopes` list won't take effect if the package is allowed in `packages` list

type BanList

type BanList struct {
	Packages []string   `json:"packages"`
	Scopes   []BanScope `json:"scopes"`
}

func (*BanList) IsEmpty

func (banList *BanList) IsEmpty() bool

func (*BanList) IsPackageBanned

func (banList *BanList) IsPackageBanned(moduleName string) bool

IsPackageBanned Checking if the package is banned. The `packages` list is the highest priority ban rule to match, so the `excludes` list in the `scopes` list won't take effect if the package is banned in `packages` list

type BanScope

type BanScope struct {
	Name     string   `json:"name"`
	Excludes []string `json:"excludes"`
}

type BuildArgs

type BuildArgs struct {
	Alias             map[string]string
	Deps              map[string]string
	External          set.ReadOnlySet[string]
	Conditions        []string
	KeepNames         bool
	IgnoreAnnotations bool
	ExternalRequire   bool
}

type BuildContext

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

func (*BuildContext) Build

func (ctx *BuildContext) Build(buildCtx context.Context) (meta *BuildMeta, err error)

func (*BuildContext) Context

func (ctx *BuildContext) Context() context.Context

func (*BuildContext) Exists

func (ctx *BuildContext) Exists() (meta *BuildMeta, ok bool, err error)

func (*BuildContext) Path

func (ctx *BuildContext) Path() string

type BuildEntry

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

BuildEntry represents the build entrypoints of a module

type BuildMeta

type BuildMeta struct {
	CJS           bool
	CSSInJS       bool
	TypesOnly     bool
	ExportDefault bool
	CSSEntry      string
	Dts           string
	Imports       []string
	Integrity     string
}

type BuildMetaDB

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

func NewBuildMetaDB

func NewBuildMetaDB(backStorage storage.Storage) *BuildMetaDB

func (*BuildMetaDB) Delete

func (db *BuildMetaDB) Delete(key string) (err error)

func (*BuildMetaDB) Get

func (db *BuildMetaDB) Get(key string) (value []byte, err error)

func (*BuildMetaDB) Put

func (db *BuildMetaDB) Put(key string, value []byte) (err error)

type BuildQueue

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

BuildQueue runs builds in FIFO order, sharing results for the same requested path.

func NewBuildQueue

func NewBuildQueue(concurrency int, timeout time.Duration) *BuildQueue

func (*BuildQueue) Build added in v0.2.0

func (q *BuildQueue) Build(ctx context.Context, build *BuildContext) (*BuildMeta, error)

Build waits for a shared build. Canceling the wait leaves the build running.

func (*BuildQueue) Snapshot

func (q *BuildQueue) Snapshot() []map[string]any

type BundleMode

type BundleMode uint8
const (
	BundleDefault BundleMode = iota
	BundleDeps
	BundleFalse
)

type Config

type Config struct {
	Port                uint16                       `json:"port"`
	TlsPort             uint16                       `json:"tlsPort"`
	CdnOrigin           string                       `json:"cdnOrigin"`
	CustomLandingPage   LandingPageOptions           `json:"customLandingPage"`
	WorkDir             string                       `json:"workDir"`
	CorsAllowOrigins    []string                     `json:"corsAllowOrigins"`
	TrustedProxies      []netip.Prefix               `json:"trustedProxies"`
	AllowList           AllowList                    `json:"allowList"`
	BanList             BanList                      `json:"banList"`
	BuildConcurrency    uint16                       `json:"buildConcurrency"`
	BuildWaitTime       uint16                       `json:"buildWaitTime"`
	BuildTimeout        uint16                       `json:"buildTimeout"`
	Storage             storage.StorageOptions       `json:"storage"`
	LogDir              string                       `json:"logDir"`
	LogLevel            string                       `json:"logLevel"`
	AccessLog           bool                         `json:"accessLog"`
	NpmRegistry         string                       `json:"npmRegistry"`
	NpmBackupRegistry   string                       `json:"npmBackupRegistry"`
	NpmToken            string                       `json:"npmToken"`
	NpmUser             string                       `json:"npmUser"`
	NpmPassword         string                       `json:"npmPassword"`
	NpmScopedRegistries map[string]NpmRegistryConfig `json:"npmScopedRegistries"`
	NpmQueryCacheTTL    uint32                       `json:"npmQueryCacheTTL"`
	PurgeAPI            PurgeAPIConfig               `json:"purgeAPI"`
	MinifyRaw           json.RawMessage              `json:"minify"`
	SourceMapRaw        json.RawMessage              `json:"sourceMap"`
	CompressRaw         json.RawMessage              `json:"compress"`
	Minify              bool                         `json:"-"`
	SourceMap           bool                         `json:"-"`
	Compress            bool                         `json:"-"`
}

Config represents the configuration of esm.sh server.

func DefaultConfig

func DefaultConfig() *Config

func LoadConfig

func LoadConfig(filename string) (*Config, error)

LoadConfig loads config from the given file. Panic if failed to load.

type DiskStatus

type DiskStatus uint8
const (
	DiskStatusError DiskStatus = iota
	DiskStatusOk
	DiskStatusLow
	DiskStatusFull
)

type EsmPath

type EsmPath struct {
	GhPrefix   bool
	PrPrefix   bool
	PkgName    string
	PkgVersion string
	SubPath    string
}

func (EsmPath) Package

func (p EsmPath) Package() npm.Package

func (EsmPath) PackageId

func (p EsmPath) PackageId() string

func (EsmPath) String

func (p EsmPath) String() string

type GitRef

type GitRef struct {
	Ref string
	Sha string
}

type LandingPageOptions

type LandingPageOptions struct {
	Origin string   `json:"origin"`
	Assets []string `json:"assets"`
}

type LegacyBuildMeta

type LegacyBuildMeta struct {
	EsmId string `json:"esmId,omitempty"`
	Dts   string `json:"dts,omitempty"`
	Code  string `json:"code"`
}

type LoaderOutput

type LoaderOutput struct {
	Lang string
	Code string
}

type NpmRC

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

func DefaultNpmRC

func DefaultNpmRC() *NpmRC

func (*NpmRC) StoreDir

func (rc *NpmRC) StoreDir() string

type NpmRegistry

type NpmRegistry struct {
	NpmRegistryConfig
	// contains filtered or unexported fields
}

type NpmRegistryConfig

type NpmRegistryConfig struct {
	Registry       string `json:"registry"`
	BackupRegistry string `json:"backupRegistry"`
	Token          string `json:"token"`
	User           string `json:"user"`
	Password       string `json:"password"`
}

type PurgeAPIConfig added in v0.2.0

type PurgeAPIConfig struct {
	EnableRaw          json.RawMessage `json:"enable"`
	GithubClientID     string          `json:"githubClientId"`
	GithubClientSecret string          `json:"githubClientSecret"`
	CloudflareZoneID   string          `json:"cloudflareZoneId"`
	CloudflareAPIToken string          `json:"cloudflareApiToken"`
	Enable             bool            `json:"-"`
}

type Ref

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

type ResolvedTransformOptions

type ResolvedTransformOptions struct {
	TransformOptions
	// contains filtered or unexported fields
}

type RouteKind

type RouteKind uint8
const (
	// module entry
	EsmEntry RouteKind = iota
	// js/css build
	EsmBuild
	// source map
	EsmSourceMap
	// *.d.ts
	EsmDts
	// package raw file
	RawFile
)

type TransformOptions

type TransformOptions struct {
	Filename        string          `json:"filename"`
	Lang            string          `json:"lang"`
	Code            string          `json:"code"`
	ImportMapRaw    json.RawMessage `json:"importMap"`
	JSXImportSource string          `json:"jsxImportSource"`
	Target          string          `json:"target"`
	SourceMap       string          `json:"sourceMap"`
	Minify          bool            `json:"minify"`
}

type TransformOutput

type TransformOutput struct {
	Code string `json:"code"`
	Map  string `json:"map"`
}

type TsImportKind

type TsImportKind uint8
const (
	TsReferenceTypes TsImportKind = iota
	TsReferencePath
	TsImportDecl
	TsImportCall
	TsDeclareModule
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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