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 ¶
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.
const TypesFile = VendorDir + "/pins.d.ts"
TypesFile declares each pinned package for the TypeScript check.
const VendorDir = "js/vendor"
VendorDir is the directory of the vendored files, relative to the app.
Variables ¶
This section is empty.
Functions ¶
func UsesNodeModules ¶
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.
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.
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.