Reference
Package Exports
Bascik ships as a single npm package, @bascik/bascik, with a small set of subpath exports. There is no large SDK surface: the package exposes configuration helpers for your build, a hosting adapter contract for deployment targets, a portable request-execution runtime for serverless hosts, and safe-HTML helpers for your scripts. Everything else is the bascik CLI.
Export map
| Import specifier | Purpose | Where it is documented |
|---|---|---|
@bascik/bascik | Main entry: the same exports as /config (defineConfig, composeSiteUrl and the configuration types) | Configuration |
@bascik/bascik/config | defineConfig plus the full BascikConfig type for bascik.config.ts | Configuration |
@bascik/bascik/runtime | Host-neutral request execution: buffered and streamed page composition, deadline-bounded invocation, and API route dispatch | Custom Adapters, Server Architecture |
@bascik/bascik/adapter | Hosting adapter contract: defineAdapter, the SiteGraph types, and site-graph readers | Custom Adapters |
@bascik/bascik/html | Safe HTML for server, stream and build scripts: html, raw, esc, safeUrl, json | HTML Helpers, Security |
@bascik/bascik
The main entry resolves to the same module as /config. Most projects only ever import defineConfig from it (or from /config).
import { defineConfig, composeSiteUrl } from "@bascik/bascik";
export default defineConfig({
base: "/docs/",
}); defineConfig(config)returns the config unchanged, typed asBascikConfig, so your editor surfaces every option with inline docs.composeSiteUrl(siteUrl, base, pathname)joins a site origin, the base path and a page path into an absolute URL (composeSiteUrl("https://example.com", "/docs/", "/about")giveshttps://example.com/docs/about).
The main entry also exports the types of the scripts Bascik calls:
BuildScript: the default export of adata-bascik-buildordata-bascik-build-oncescript, which returns a string or anhtmlvalue (or a promise of either).RoutesScript: the default export of adata-bascik-routesscript, which returns route objects (RouteEntry).ServerScript: the default export of adata-bascik-serverordata-bascik-streamscript, called with theRequest, aServerScriptContext(remoteIpandplatform) and{ signal }.
The editor's TypeScript errors in script tags and bascik --check --typescript type a type="text/typescript" script's default export with these, so a script does not import them: a server or stream script imports nothing from @bascik/bascik but @bascik/bascik/html. Use them where code outside a script needs the shape, such as a unit test that calls a handler.
The CLI itself is not importable: run it through the bascik command.
@bascik/bascik/config
The config subpath is the recommended import for bascik.config.ts. It exports defineConfig and re-exports every configuration type, including BascikConfig.
import { defineConfig } from "@bascik/bascik/config";
export default defineConfig({
generate: { sitemapLastmod: true },
}); @bascik/bascik/runtime
The runtime subpath is the portable request-execution engine that the built-in Node server and every hosting adapter share. It has zero Node builtins, so it bundles cleanly for serverless and edge platforms. Adapter authors use it to serve dynamic pages and API routes from a compiled site graph.
Key functions:
composeBufferedResponse(plan, run, signal)composes a fully bufferedUint8Arraybody for a page whosedata-bascik-serverjobs all resolve before the response starts.streamComposedResponse(plan, run, writer, options)drives the two-phase streamer:serverjobs resolve before commit,streamjobs run with bounded lookahead after headers are sent. Astreamjob whose runner resolves to an async iterable (a script that yields) is written one chunk at a time. Returns aComposedStreamerwithready,commit,done,signal, andtoReadableStream().invokeWithDeadline(handler, options)runs a handler under a timeout and an upstreamAbortSignal, settling exactly once. Once the deadline fires or the upstream aborts, the result is a timeout or an abort even if the handler settles afterwards.invokeLoadedWithDeadline(load, call, options)does the same with a module load under the same deadline, andcreateAbortGate(signal)is the settlement rule both use. Withchunks: true, a handler that returns a generator givesresult.sourceinstead ofresult.value: aScriptChunkSourcepulled one value at a time under the same deadline, which counts only the time a pull is pending.scriptChunkOutput(source, print, fail)turns it into the chunks of a job, andcollectScriptJobOutput(output)joins them.scriptJobOutput(invoked, policy)turns an invocation's result into the job's output by the rule every host shares: a value is printed, stripped of ANSI escapes and given its component's class names; a value that is not markup is refused; a failure followsscripts.onServerScriptError.settleScriptOutput(result, yielded, policy)is the same for one result. TheScriptOutputPolicynames what is the host's own: its log, its description of a failure, its error class, and how it remembers a script's first refused value.scriptTimeoutError(ms)builds theScript execution timed out after Nmserror that server, stream and component scripts report on every host.dispatchApiHandler(module, request, context, options)dispatches a webRequestto an API route module's exported methods, handlingHEAD,OPTIONS, and theAllowheader.
The runtime also exports the shared response policy (dynamicPageHeaders, mergeHandlerHeaders, stripRepresentationHeaders, errorResponse, internalErrorPage, SECURITY_HEADERS) and pure route matching (matchApiRoute, sortApiRoutes, pageLookupCandidates, isUnsafePathname, hasHiddenSegment).
@bascik/bascik/adapter
The adapter subpath defines the hosting adapter contract. A custom adapter is a module whose default export is created with defineAdapter; bascik --build --target <name> loads it and calls its build hook with an AdapterBuildContext containing the compiled site graph.
import {
defineAdapter,
type AdapterBuildContext,
type AdapterBuildResult,
} from "@bascik/bascik/adapter";
export default defineAdapter({
name: "my-cloud",
async build(context: AdapterBuildContext): Promise<AdapterBuildResult> {
// Read context.graph, copy context.distDir assets, emit a runtime entrypoint.
return { publicDir: `${context.outDir}/public` };
},
}); It also exports the site-graph readers used inside adapters: readSiteGraph, pageAliasesFor, detectPublicCollisions, isPublicAssetPath, and splitDistPageIntoSegments. Importing @bascik/bascik/adapter does not read bascik.config; it loads through CommonJS require or ESM import, and readSiteGraph loads the config on first call.
See Custom Adapters for the full tutorial and API reference.
@bascik/bascik/html
The html subpath is the one export meant for server and stream scripts (build scripts may use it too). It holds plain functions that build HTML safely: the html tagged template, which escapes each value for where it lands and refuses places escaping cannot make safe, plus raw, esc, safeUrl, json, isHtml and HtmlError.
<script data-bascik-server>
import { html } from "@bascik/bascik/html";
export default function (request) {
const q = new URL(request.url).searchParams.get("q") ?? "";
return html`<p>You searched for ${q}</p>`;
}
</script> It has no Node builtins, so the Cloudflare adapter bundles it into the Worker. See HTML Helpers for the API reference and Security for how it fits with the rest of a site's protection.