jspin

package
v0.3.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: 15 Imported by: 0 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

Overview

Package jspin vendors pre-bundled ESM builds of npm packages for the islands of an app (REQ-ISL-07). `gx pin <pkg>@<version>` fetches the build and the builds it imports from the ESM CDN, stores them in js/vendor/ and records the integrity of each file in gx.lock. The island bundler resolves a bare import to the vendored file. Node is never involved.

Index

Constants

View Source
const DefaultCDN = "https://cdn.jsdelivr.net"

DefaultCDN is the ESM CDN. Its /npm/<pkg>@<version>/+esm address answers with one ES module that imports its dependencies by the same kind of address.

View Source
const TypesFile = VendorDir + "/pins.d.ts"

TypesFile declares each pinned package for the TypeScript check.

View Source
const VendorDir = "js/vendor"

VendorDir is the directory of the vendored files, relative to the app.

Variables

This section is empty.

Functions

func SaveLock

func SaveLock(root string, lock Lock) error

SaveLock merges the js section into gx.lock without touching other sections.

func UsesNodeModules

func UsesNodeModules(root string) bool

UsesNodeModules reports whether the app resolves imports as node does: it has a package.json and a node_modules directory. The bundler then leaves every import to its own resolution.

func Verify

func Verify(root string, lock Lock) error

Verify checks every vendored file against gx.lock (SI-10). A missing or changed file, or a pin whose entry file has no hash, is an error that stops the build.

Types

type Entry

type Entry struct {
	Version string `json:"version"`
	// File is the vendored entry file, relative to the app.
	File string `json:"file"`
}

Entry is one pinned import specifier.

type Lock

type Lock struct {
	// Pins maps an import specifier ("echarts", "echarts/core") to its pin.
	Pins map[string]Entry `json:"pins"`
	// Files maps each vendored file to its integrity: "sha256-" and the
	// base64 form of the hash.
	Files map[string]string `json:"files"`
}

Lock is the "js" section of gx.lock.

func LoadLock

func LoadLock(root string) (Lock, error)

LoadLock reads the js section of gx.lock. An app with no pin gets an empty lock.

type Options

type Options struct {
	// Dir is the app directory.
	Dir string
	// Spec is <pkg>@<version>, with an optional subpath.
	Spec string
	// BaseURL overrides the CDN. The default is the esm mirror of gx.toml,
	// then DefaultCDN.
	BaseURL string
	// Client is the HTTP client. The default client honours HTTPS_PROXY.
	Client *http.Client
}

Options configure one pin.

type Result

type Result struct {
	Specifier string
	Version   string
	// Files lists the vendored files of the pin, relative to the app.
	Files []string
	// Removed lists the vendored files that no pin uses after this pin:
	// the files of the version that the pin replaced.
	Removed []string
}

Result reports one pin.

func Pin

func Pin(ctx context.Context, opt Options) (*Result, error)

Pin fetches a package and every module it imports, stores them and records them in gx.lock.

Jump to

Keyboard shortcuts

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