WDK logoWDK documentation

Worklet Bundler API Reference

API for @tetherto/wdk-worklet-bundler

API Reference

Package: @tetherto/wdk-worklet-bundler

Configuration Types

WdkBundleConfig

WdkBundleConfig is the public configuration shape for wdk.config.js.

WdkBundleConfig Shape
interface WdkBundleConfig {
  networks: Record<string, { package: string }>
  protocols?: Record<string, { package: string; [key: string]: unknown }>
  modules?: Record<string, {
    package: string
    factory?: string
    events?: string[]
  }>
  preloadModules?: string[]
  transport?: 'hrpc' | 'jsonrpc'
  output?: {
    bundle?: string
    types?: string
    addons?: {
      ios?: string
      macos?: string
      android?: string
    }
    addonsYml?: string
  }
  options?: {
    minify?: boolean
    sourceMaps?: boolean
    targets?: string[]
    linkAddons?: boolean
    platforms?: Array<'ios' | 'macos' | 'android'>
    swiftTarget?: string
    convertEsmToCjs?: boolean
  }
}

modules is generated only for HRPC through beta.7. JSON-RPC entry generation ignores that map. JSON-RPC otherwise defaults addon linking and ESM-to-CJS conversion to true; HRPC defaults both to false.

Beta.7 declares output.types, options.minify, and options.sourceMaps, but its bundle generator does not honor those fields. Declarations are always written to ./.wdk/index.d.ts; minify and sourceMaps do not control bare-pack output. JSON-RPC ESM-to-CJS conversion minifies independently.

ResolvedConfig

ResolvedConfig extends WdkBundleConfig with absolute filesystem paths produced by loadConfig().

ResolvedConfig Additions
interface ResolvedConfig extends WdkBundleConfig {
  configPath: string
  projectRoot: string
  resolvedOutput: {
    bundle: string
    types: string
    addons: {
      ios: string
      macos: string
      android: string
    }
    addonsYml: string
  }
}

Dependency Helpers

FunctionDescriptionReturns
validateDependencies(modules, projectRoot)Resolve configured packages and report which modules are installed or missing.ValidationResult
detectPackageManager(projectRoot)Detect whether the project uses npm, yarn, or pnpm.'npm', 'yarn', or 'pnpm'
generateInstallCommand(missing, packageManager?)Build the command string used to install missing dependencies.string
installDependencies(missing, projectRoot, options?)Install missing dependencies with the detected or selected package manager.InstallResult
generateUninstallCommand(packages, packageManager?)Build the command string used to remove packages.string
uninstallDependencies(packages, projectRoot, options?)Remove packages with the detected or selected package manager.UninstallResult

validateDependencies(modules, projectRoot)

Use this helper to confirm that the packages listed in wdk.config.js are already resolvable from the host project.

Validate Missing Dependencies
import { validateDependencies } from '@tetherto/wdk-worklet-bundler'

const result = validateDependencies(
  ['@tetherto/wdk-wallet-btc', '@tetherto/pear-wrk-wdk'],
  process.cwd()
)

ValidationResult contains:

  • valid (boolean)
  • installed (ModuleInfo[])
  • missing (string[])

detectPackageManager(projectRoot)

Use this helper when you need the same package-manager detection logic that the CLI uses before install or uninstall flows.

Detect The Package Manager
import { detectPackageManager } from '@tetherto/wdk-worklet-bundler'

const packageManager = detectPackageManager(process.cwd())

generateInstallCommand(missing, packageManager?)

Build the install command string without mutating the project:

Generate An Install Command
import { generateInstallCommand } from '@tetherto/wdk-worklet-bundler'

const command = generateInstallCommand(
  ['@tetherto/wdk-wallet-btc', '@tetherto/pear-wrk-wdk'],
  'npm'
)

installDependencies(missing, projectRoot, options?)

Run the install flow from code when you want the same dependency installation behavior as generate --install.

generateUninstallCommand(packages, packageManager?)

Build the uninstall command string without mutating the project.

uninstallDependencies(packages, projectRoot, options?)

Run the uninstall flow from code and receive a structured UninstallResult.

Bundle Generation

FunctionDescriptionReturns
loadConfig(configPath?)Load, validate, and resolve a wdk.config.js file into absolute paths.Promise\<ResolvedConfig\>
generateBundle(config, options?)Generate the entrypoint, imports, bundle, and optional type output.Promise\<GenerateBundleResult\>
generateSourceFiles(config, options?)Generate the source entrypoint and related artifacts without bundling.Promise\<{ entryPath: string }\>
generateEntryPoint(config, outputDir)Generate an HRPC Bare worklet entrypoint file.Promise\<string\>
generateJsonRpcEntryPoint(config, outputDir)Generate a JSON-RPC Bare worklet entrypoint file.Promise\<string\>
linkAddons(config, options?)Link native addons for selected platforms with bare-link.Promise\<LinkAddonsResult\>
generateAddonsYml(iosAddonsDir, swiftTarget, outputPath)Generate the BareKit Swift addon dependency file.void
generateWalletModulesCode(config)Generate the wallet-module section inserted into the entrypoint.string

loadConfig(configPath?)

loadConfig() searches for wdk.config.js when no explicit path is supplied, validates the public config shape, and resolves the output paths relative to the config file directory.

Load The Resolved Config
import { loadConfig } from '@tetherto/wdk-worklet-bundler'

const config = await loadConfig()

generateBundle(config, options?)

Use generateBundle() when you want the same bundle workflow that powers the CLI generate command.

GenerateBundleOptions supports:

  • dryRun
  • verbose
  • silent
  • skipTypes
  • skipGeneration
  • deferOptionalPeers? (boolean): When omitted or true, pass missing peers marked optional through bare-pack --defer. Beta.7 checks root, nested, scoped, and symlinked package trees before treating an optional peer as missing. Set this option to false to require absent optional imports at build time.

deferOptionalPeers is a per-run API option. It is not a WdkBundleConfig field and cannot be set in wdk.config.js.

GenerateBundleResult contains:

  • success
  • bundlePath
  • typesPath
  • bundleSize
  • duration
  • error?
  • missingModule?

In beta.7, typesPath can reflect a configured output.types path even though the declaration file is still written to ./.wdk/index.d.ts.

Generate A Bundle Programmatically
import { generateBundle, loadConfig } from '@tetherto/wdk-worklet-bundler'

const config = await loadConfig('./wdk.config.js')
const result = await generateBundle(config, { verbose: true })

generateSourceFiles(config, options?)

Use generateSourceFiles() when you want the generated entrypoint without the final bare-pack step.

generateEntryPoint(config, outputDir)

Use generateEntryPoint() when you need the generated HRPC Bare entrypoint written to a chosen output directory. This path includes configured generic modules and their lifecycle/event wiring.

In beta.3, the generated entrypoint suspends and resumes both the bare-http1 and bare-https global agents when the Bare runtime emits suspend and resume.

generateJsonRpcEntryPoint(config, outputDir)

Generate the framed JSON-RPC entrypoint used by native hosts. Through beta.7 this path includes wallet and protocol managers but not generic modules.

linkAddons(config, options?)

Link required Bare addons for iOS, macOS, Android, or a selected subset. LinkAddonsOptions supports platforms, verbose, and silent. The result contains success, duration, platforms, and optional error.

When iOS is selected, addon linking also calls generateAddonsYml() with config.options.swiftTarget or the default target name app.

generateAddonsYml(iosAddonsDir, swiftTarget, outputPath)

Generate the addons.yml dependency list expected by BareKit Swift from linked iOS XCFrameworks.

generateWalletModulesCode(config)

Use generateWalletModulesCode() when you only need the generated wallet-module section for inspection or custom generator flows.

CLI Commands

The published CLI exposes these commands through wdk-worklet-bundler:

CommandDescriptionKey Options
generateGenerate a WDK bundle from configuration.--config, --install, --keep-artifacts, --dry-run, --no-types, --source-only, --skip-generation, --transport, --link-addons, --skip-link-addons, --platforms, --no-esm-to-cjs, --no-defer-optional-peers, --verbose
initCreate a new wdk.config.js file.--yes
validateValidate configuration without building.--config
list-modulesList available WDK modules.--json
cleanRemove the generated .wdk folder.--yes

For the end-to-end config workflow and transport defaults, see the Worklet Bundler configuration guide.

Beta.7 applies --transport after loadConfig() resolves output paths. The flag changes entrypoint generation but does not recompute the default bundle filename. Set transport in wdk.config.js, or configure output.bundle explicitly when using the flag.


Need Help?

On this page