server

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 59 Imported by: 0

Documentation

Index

Constants

View Source
const DEBUG = false

production mode

View Source
const (
	MB = 1 << 20
)

Variables

View Source
var VERSION = "v137"

may be changed 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 (storage *BuildMetaDB) Delete(key string) (err error)

func (*BuildMetaDB) Get

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

func (*BuildMetaDB) Put

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

type BuildOutput

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

type BuildQueue

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

BuildQueue schedules build tasks of esm.sh

func NewBuildQueue

func NewBuildQueue(concurrency int) *BuildQueue

func (*BuildQueue) Add

func (q *BuildQueue) Add(ctx *BuildContext) chan BuildOutput

Add adds a new build task to the queue.

func (*BuildQueue) Snapshot

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

type BuildTask

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

type BundleMode

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

type Config

type Config struct {
	Port                uint16                       `json:"port"`
	TlsPort             uint16                       `json:"tlsPort"`
	CustomLandingPage   LandingPageOptions           `json:"customLandingPage"`
	WorkDir             string                       `json:"workDir"`
	CorsAllowOrigins    []string                     `json:"corsAllowOrigins"`
	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"`
	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 Database

type Database interface {
	Get(key string) (value []byte, err error)
	Put(key string, value []byte) (err error)
	Delete(key string) (err error)
	Close() (err error)
}

deprecated

func OpenBoltDB

func OpenBoltDB(filename string) (Database, error)

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 `json:"lang"`
	Code  string `json:"code"`
	Error string `json:"error"`
}

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 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 Stat

type Stat struct {
	Records int64
}

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