///
///
///
///
import type { WatchOptions } from 'chokidar';
import type { EventEmitter } from 'events';
import type fs from 'fs';
import type { Readable } from 'stream';
import type { BundleConfig, EnvironmentConfig, HooksPlugin, LwrLockerConfig, NormalizedLwrErrorRoute, NormalizedLwrGlobalConfig, NormalizedLwrRoute, ResolverModuleRecord, BundleConfigOverrides, RouteHandlers, AssetConfig, I18NConfig, ModuleRegistryConfig } from './config.js';
import type { AssetReference, CompiledView, DirectToCoreProxy, PublicViewRegistry, ViewProvider, ViewRegistry, ViewTransformPlugin } from './views.js';
export * from './lwr-shim.js';
export * from './config.js';
export * from './cli.js';
export * from './server.js';
export * from './views.js';
export * from './serviceAPI/serviceAPI.js';
export * from './serviceAPI/loaderPlugins/loaderPlugins.js';
export * from './serviceAPI/handleStaleModule/handleStaleModule.js';
export * from './serviceAPI/appMetadata/appMetadata.js';
export type Json = undefined | null | boolean | number | string | Json[] | {
[prop: string]: Json;
};
export type JsonCompatible = {
[P in keyof T]: T[P] extends Json ? T[P] : Pick extends Required> ? never : JsonCompatible;
};
export type WithOptional = Omit & Partial>;
export type Specifier = string;
export type Version = string;
export interface AbstractModuleId {
specifier: string;
namespace?: string;
name?: string;
importer?: string;
version?: Version;
}
export interface ModuleId {
id: string;
specifier: string;
namespace?: string;
name: string;
version: Version;
}
export interface ModuleJson {
specifier: string;
version?: Version;
ownHash?: string;
links: {
self: string;
};
}
export interface ModuleJsonDefinition {
specifier: string;
version: Version;
ownHash: string;
dependencies: ModuleJson[];
format: ModuleFormat;
minified: boolean;
code: string;
metadata?: object;
}
export interface ImportMetadata {
imports: ImportMetadataImports;
index?: ImportMetadataIndex;
}
export interface ImportMetadataImports {
[uri: string]: string[];
}
export interface ImportMetadataIndex {
[specifier: string]: string;
}
export type ModuleEntry = FsModuleEntry | VirtualModuleEntry;
interface BaseModuleEntry {
id: string;
entry: string;
virtual?: boolean;
external?: boolean;
scope?: string;
specifier: Specifier;
version: Version;
interchangeable?: boolean;
src?: string;
}
export interface FsModuleEntry extends BaseModuleEntry {
virtual?: false;
}
export interface VirtualModuleEntry extends BaseModuleEntry {
virtual: true;
}
export interface BaseModuleReference {
scope?: string;
namespace?: string;
name: string;
specifier: string;
version: Version;
interchangeable?: boolean;
externalSrc?: string;
external?: boolean;
}
export interface ImportModuleReference extends BaseModuleReference {
sourceSpecifier: Specifier;
locations: SourceLocation[];
}
interface DynamicImportLocation {
location: SourceLocation;
importLocation: SourceLocation;
}
export interface BaseDynamicModuleReference extends BaseModuleReference {
sourceSpecifier: Specifier;
moduleNameType: ModuleNameType;
}
export interface DynamicImportReference extends BaseDynamicModuleReference {
locations: DynamicImportLocation[];
}
export interface ModuleRecord {
imports?: ImportModuleReference[];
dynamicImports?: DynamicImportReference[];
importMeta?: ImportMeta[];
}
export interface ChildHashObject {
[specifier: string]: string;
}
export interface SignatureRecord {
hashes?: ChildHashObject;
}
export interface ModuleSource extends ModuleId {
ownHash: string;
originalSource: string;
moduleEntry: ModuleEntry;
}
export interface ModuleCompiled extends ModuleSource {
compiledSource: string;
compiledMetadata?: CompiledMetadata;
}
export interface ModuleDefinition extends ModuleCompiled {
moduleRecord: ModuleRecord;
}
export interface LinkedModuleDefinitionConfig {
minified: boolean;
}
export interface LinkedModuleDefinition extends ModuleDefinition, BaseModuleReference {
linkedSource: string;
linkedModuleRecord: ModuleRecord;
linkedConfig: LinkedModuleDefinitionConfig;
runtimeEnvironment: RuntimeEnvironment;
runtimeParams: RuntimeParams;
}
export interface CodeSource {
code: string;
sourcemap?: string;
}
export interface SignedSource extends CodeSource {
signedCode?: string;
}
export type CompatMode = '0' | '1';
export type ModuleFormat = 'esm' | 'amd';
export interface ServerModeConfig {
format: ModuleFormat;
bundle: boolean;
minify: boolean;
compat: CompatMode;
watchFiles: boolean;
debug: boolean;
i18n: I18NConfig;
hmrEnabled: boolean;
immutableAssets: boolean;
env: {
NODE_ENV: string;
};
featureFlags: FeatureFlags;
}
export interface FeatureFlags extends Record | undefined> {
ASSETS_ON_LAMBDA?: boolean;
BUNDLE_CACHE_SIZE?: string;
LEGACY_LOADER?: boolean;
EXPERIMENTAL_UNVERSIONED_ALIASES?: boolean;
ENABLE_NONCE?: boolean;
MAX_VIEW_CACHE_TTL?: string;
REEVALUATE_MODULES?: boolean;
SSR_LOADER_PER_REQUEST?: boolean;
EXPERIMENTAL_ASSET_HEADERS?: string;
SSR_COMPILER_ENABLED?: boolean;
VIEW_CACHE_SIZE?: string;
}
export interface RuntimeEnvironment extends ServerModeConfig {
apiVersion: string;
lwrVersion: string;
debug: boolean;
serverMode: string;
basePath: string;
defaultAssetPath: string;
}
export interface SourceMapRuntimeEnvironment extends RuntimeEnvironment {
sourceMapUrl?: string;
}
export type RuntimeParams = Record | DirectToCoreProxy> & {
requestCache?: Record;
};
export interface EnvironmentContext {
basePath: string;
locale: string;
assetBasePath: string;
uiBasePath: string;
}
export interface ModuleIdentity {
signature: string;
moduleId: AbstractModuleId;
}
export interface MappingIdentity {
moduleIds: AbstractModuleId[];
}
export interface ResourceIdentity {
signature: string;
resourceId: ResourceIdentifier;
}
export interface AssetIdentity {
assetId: AssetIdentifier;
signature: string;
immutable: boolean;
}
export interface RuntimeContext {
runtimeEnvironment: RuntimeEnvironment;
runtimeParams: RuntimeParams;
}
export interface BootstrapRuntimeEnvironment extends RuntimeEnvironment {
bootstrapImports?: string[];
bootstrapDynamicImports?: string[];
}
export type { WatchOptions } from 'chokidar';
export interface WatcherFactory {
createFileWatcher(options?: WatchOptions): Watcher;
setupWatcher(onModuleChange: Function): Watcher;
}
export interface Watcher extends EventEmitter {
add(paths: string | ReadonlyArray): void;
unwatch(paths: string | ReadonlyArray): void;
getWatched(): {
[directory: string]: string[];
};
on(event: 'add' | 'addDir' | 'change', listener: (path: string, stats?: fs.Stats) => void): this;
on(event: 'all', listener: (eventName: 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir', path: string, stats?: fs.Stats) => void): this;
on(event: 'error', listener: (error: Error) => void): this;
on(event: 'raw', listener: (eventName: string, path: string, details: Record) => void): this;
on(event: 'ready', listener: () => void): this;
on(event: 'unlink' | 'unlinkDir', listener: (path: string) => void): this;
on(event: string, listener: (...args: unknown[]) => void): this;
}
export interface LwrAppObserver {
onModuleDefinitionChange(listener: (event: ModuleDefinitionChangedEvent) => void): void;
onModuleSourceChange(listener: (event: ModuleSourceChangedEvent) => void): void;
onViewSourceChange(listener: (event: ViewSourceChangedEvent) => void): void;
onAssetSourceChange(listener: (event: AssetSourceChangedEvent) => void): void;
}
export interface LwrAppEmitter {
notifyModuleDefinitionChanged(payload: LinkedModuleDefinition): void;
notifyModuleSourceChanged(payload: ModuleCompiled): void;
notifyViewSourceChanged(payload: CompiledView): void;
notifyAssetSourceChanged(payload: AssetSource): void;
}
export type EVENT_MODULE_DEFINITION_CHANGED = 'module_definition_changed';
export interface ModuleDefinitionChangedEvent {
eventType: EVENT_MODULE_DEFINITION_CHANGED;
payload: LinkedModuleDefinition;
}
export type EVENT_MODULE_SOURCE_CHANGED = 'module_source_changed';
export type EVENT_ASSET_SOURCE_CHANGED = 'asset_source_changed';
export type EVENT_VIEW_SOURCE_CHANGED = 'view_source_changed';
export interface ModuleSourceChangedEvent {
eventType: EVENT_MODULE_SOURCE_CHANGED;
payload: ModuleCompiled;
}
export interface ViewSourceChangedEvent {
eventType: EVENT_VIEW_SOURCE_CHANGED;
payload: CompiledView;
}
export interface AssetSourceChangedEvent {
eventType: EVENT_ASSET_SOURCE_CHANGED;
payload: AssetSource;
}
export interface ModuleProvider {
name: string;
getModule(moduleId: T, runtimeParams?: RuntimeParams): Promise;
getModuleEntry(moduleId: T, runtimeParams?: RuntimeParams): Promise;
}
export type LwrService = ModuleProvider | ResourceProvider | ViewProvider | AssetProvider | HooksPlugin | AssetTransformPlugin | ViewTransformPlugin;
export interface ServiceCtor = {}> {
new (providerConfig: R, serviceProviderConfig?: any, ...args: any[]): T;
}
export interface BundleSigner {
getBundleSignature(moduleId: Required>, runtimeEnvironment: RuntimeEnvironment, runtimeParams: RuntimeParams, exclude?: string[] | undefined): Promise;
}
export interface ModuleRegistry {
name: string;
addModuleProviders(registries: ModuleProvider[]): void;
setBundleSigner(bundleSigner: BundleSigner): void;
getLinkedModule(moduleId: T, runtimeEnvironment: RuntimeEnvironment, runtimeParams?: RuntimeParams): Promise;
getModule(moduleId: T, runtimeParams?: RuntimeParams): Promise;
getModuleEntry(moduleId: AbstractModuleId, runtimeParams?: RuntimeParams): Promise;
resolveModuleUri(moduleId: Required>, runtimeEnvironment: R, runtimeParams?: RuntimeParams, signature?: S): Promise;
resolveModuleUriSync(moduleId: Required>, signature: S, runtimeEnvironment: R, runtimeParams?: RuntimeParams): string;
getConfig(): ModuleRegistryConfig;
getPublicApi(): PublicModuleRegistry;
}
export type PublicModuleRegistry = Pick;
export interface BundleProvider {
name: string;
bundle(moduleId: T, runtimeEnvironment: R, runtimeParams: RuntimeParams, configOverrides?: BundleConfig): Promise;
}
export interface ModuleBundler {
addBundleProviders(providers: BundleProvider[]): void;
addBundleTransformers(transformers: UriTransformPlugin[]): void;
getModuleBundle(moduleId: T, runtimeEnvironment: R, runtimeParams?: RuntimeParams, bundleConfigOverrides?: BundleConfigOverrides): Promise;
resolveModuleUri(moduleId: Required>, runtimeEnvironment: RuntimeEnvironment, runtimeParams?: RuntimeParams, signature?: string): Promise;
getConfig(): BundleConfig;
getPublicApi(): PublicModuleBundler;
}
export type PublicModuleBundler = Pick;
export interface BundleRecord {
imports?: BaseModuleReference[];
dynamicImports?: BaseDynamicModuleReference[];
includedModules: string[];
}
export interface BundleDefinition extends ModuleId {
getCode: () => Promise;
config: BundleConfig;
map?: any;
bundleRecord: BundleRecord;
src?: string;
srcOverride?: string;
integrity?: string;
}
export interface ProviderAppConfig {
modules: ResolverModuleRecord[];
routes: NormalizedLwrRoute[];
errorRoutes: NormalizedLwrErrorRoute[];
basePath: string;
rootDir: string;
contentDir: string;
layoutsDir: string;
cacheDir: string;
locker: LwrLockerConfig;
amdLoader: string;
esmLoader: string;
environment?: EnvironmentConfig;
bundleConfig: BundleConfig;
assets: AssetConfig[];
i18n: I18NConfig;
}
export interface ProviderContext {
appObserver: Pick;
appEmitter: Pick;
moduleRegistry: PublicModuleRegistry;
moduleBundler: PublicModuleBundler;
resourceRegistry: PublicResourceRegistry;
viewRegistry: PublicViewRegistry;
assetRegistry: PublicAssetRegistry;
config: ProviderAppConfig;
runtimeEnvironment: RuntimeEnvironment;
watcherFactory?: WatcherFactory;
siteMetadata?: SiteMetadata;
}
export interface ResourceIdentifier {
specifier: string;
version?: Version;
}
export interface AssetIdentifier {
specifier: string;
type?: AssetType;
importer?: string;
}
export interface UriDefinition {
uri: string;
immutable: boolean;
artifactType: ArtifactType;
entry: string;
external?: boolean;
}
export type ResourceType = 'application/javascript' | 'application/json' | 'text/css' | 'lwr-importmap' | 'module' | string;
export interface ResourceDefinition {
specifier?: string;
type: ResourceType;
src?: string;
entry?: string;
inline?: boolean;
async?: boolean;
defer?: boolean;
nonce?: string;
content?: string;
stream?: () => Readable;
isPreload?: boolean;
version?: string;
integrity?: string;
}
export interface AssetMetadata {
assetReferences?: AssetReference[];
}
export interface AssetSource {
entry: string;
ext: string;
mime: string | false;
ownHash: string;
content: (encoding?: BufferEncoding) => string | Buffer;
uri?: string;
metadata?: AssetMetadata;
type?: AssetType;
noTransform?: boolean;
}
export type AssetType = 'asset' | 'content-asset' | 'external' | 'unknown';
export interface AssetDefinition extends AssetSource {
uri: string;
type: AssetType;
stream: (encoding?: BufferEncoding) => Readable;
}
export type ResourceJson = Pick;
export interface ResourceProvider {
name: string;
getResource(resourceIdentity: R, runtimeEnvironment: T, runtimeParams?: RuntimeParams): Promise;
}
export interface AssetProvider {
name: string;
getAsset(assetIdentifier: AssetIdentifier): Promise;
}
export type ArtifactType = 'asset' | 'bundle' | 'resource';
export type ArtifactDefinition = AssetDefinition | BundleDefinition | ResourceDefinition;
export type AssetTransformSourceHook = (assetSource: AssetSource, runtimeEnvironment: RuntimeEnvironment) => Promise;
export type AssetTransformSourceHookReturn = undefined | {
source: string | Buffer;
metadata?: AssetMetadata;
};
export type UriTransformHook = (uri: UriDefinition, artifactDef?: ArtifactDefinition, runtimeEnvironment?: RuntimeEnvironment) => Promise;
export type UriTransformHookReturn = undefined | UriDefinition;
export interface UriTransformHooks {
transformUri: UriTransformHook;
}
export interface UriTransformPlugin extends UriTransformHooks {
name: string;
}
export type AssetUriTransformHook = (uri: UriDefinition, assetDef: AssetDefinition, runtimeEnvironment: RuntimeEnvironment) => Promise;
export interface AssetTransformHooks {
transformUri: AssetUriTransformHook;
transformSource: AssetTransformSourceHook;
}
export interface AssetTransformPlugin extends Partial {
name: string;
}
export interface ResourceRegistry {
name: string;
addResourceProviders(provider: ResourceProvider[]): void;
addResourceTransformers(provider: UriTransformPlugin[]): void;
getResource(resourceIdentity: R, runtimeEnvironment: T, runtimeParams?: RuntimeParams): Promise;
resolveResourceUri(resourceIdentity: R, runtimeEnvironment: T): Promise;
getPublicApi(): PublicResourceRegistry;
}
export type PublicResourceRegistry = Pick;
export interface AssetRegistry {
name: string;
addAssetProviders(provider: AssetProvider[]): void;
addAssetTransformers(transformers: (AssetTransformPlugin | UriTransformPlugin)[]): void;
getAsset(resourceIdentity: R, runtimeEnvironment: T, includeMetadata?: boolean): Promise;
resolveAssetUri(resourceIdentity: R, runtimeEnvironment: T): Promise;
getPublicApi(): PublicAssetRegistry;
}
export type PublicAssetRegistry = Pick;
export interface LwcCompilerConfig {
name: string;
namespace?: string;
filename: string;
enableLightningWebSecurityTransforms?: boolean;
scopedStyles?: boolean;
}
export type SourceMap = string | null | undefined;
export interface CompiledMetadata {
imports?: Import[];
dynamicImports?: DynamicImport[];
importMeta?: ImportMeta[];
}
export interface SourceLocation {
startColumn: number;
endColumn: number;
}
export interface Import {
moduleSpecifier: string;
location: SourceLocation;
}
export type ModuleNameType = 'string' | 'unresolved';
export interface DynamicImport {
moduleSpecifier: string;
location: SourceLocation;
importLocation: SourceLocation;
moduleNameType: ModuleNameType;
}
export interface ImportMeta {
statement: string;
location: SourceLocation;
}
export interface CompilerResult {
code: string;
map?: SourceMap;
metadata?: CompiledMetadata;
}
export interface BundleFiles {
[filename: string]: string;
}
interface ImportMetaEnv {
[key: string]: any;
SSR: boolean;
}
declare global {
interface ImportMeta {
readonly env: ImportMetaEnv;
}
}
export type ServerData = {
[prop: string]: Json;
};
export interface ClientBootstrapConfig {
appId?: string;
bootstrapModule: string;
requiredModules?: string[];
autoBoot: boolean;
preloadModules?: string[];
rootComponent?: string;
rootComponents?: string[];
serverData?: ServerData;
customInit?: Function;
onError?: Function;
baseUrl?: string;
initDeferDOM?: boolean;
endpoints?: Endpoints;
imports?: ImportMetadataImports;
index?: ImportMetadataIndex;
metricsConfig?: MetricsConfig;
importMappings?: object;
env?: any;
onInitApp?: Function;
}
export type GlobalThis = {
LWR: ClientBootstrapConfig;
[key: string]: unknown;
};
export interface Endpoints {
uris: Record;
modifiers?: Record;
}
export interface BootstrapJson {
ownHash: string;
resources: ResourceJson[];
modules: ModuleJson[];
workers: {
[id: string]: ModuleJson;
};
}
export interface MetricsConfig {
enableModuleFetchTracking?: boolean;
enableMappingFetchTracking?: boolean;
}
export interface ServerContext {
appObserver: LwrAppObserver;
appEmitter: LwrAppEmitter;
moduleRegistry: ModuleRegistry;
moduleBundler: ModuleBundler;
viewRegistry: ViewRegistry;
resourceRegistry: ResourceRegistry;
assetRegistry: AssetRegistry;
watcherFactory?: WatcherFactory;
siteMetadata?: SiteMetadata;
appConfig: NormalizedLwrGlobalConfig;
runtimeEnvironment: RuntimeEnvironment;
routeHandlers: RouteHandlers;
}
export interface Observer {
next: (value: V) => void;
error: (error: Error) => void;
complete: () => void;
}
export interface Observable {
next: (value: V) => void;
error: (error: Error) => void;
complete: () => void;
subscribe: (obs: Observer, replay?: boolean) => Unsubscriber;
}
export interface Unsubscriber {
unsubscribe: () => void;
}
export interface GraphOptions {
includeUris?: boolean;
includeLinkedDefinitions?: boolean;
depth: GraphDepthOptions;
}
export interface IncludeIdHook {
(moduleReference: BaseModuleReference): boolean;
}
export interface GraphDepthOptions {
static: GraphDepth;
dynamic: number;
includeId?: IncludeIdHook;
}
export type GraphDepth = 'all' | 'direct' | 'none';
export interface FlatGraphNode {
specifier: Specifier;
static: Specifier[];
dynamicRefs: Specifier[];
}
export interface GraphNode {
static: Specifier[];
dynamic: Specifier[];
}
export type URIMap = Record;
export type LinkedModuleDefinitionMap = Record;
export interface FlattenedModuleGraphs {
graphs: FlatGraphNode[];
uriMap: URIMap;
linkedDefinitions: LinkedModuleDefinitionMap;
}
export type ImportMapImports = {
[key: string]: string;
};
/**
* Spec-shaped import map object (https://github.com/WICG/import-maps).
* Shared by legacy resolution, esmLoader, and LWR.importMap public API typing.
*/
export interface ImportMap {
imports?: ImportMapImports;
scopes?: {
[key: string]: ImportMapImports;
};
default?: string;
}
/** Flat script-URL → module specifiers form for LWR.importMap() runtime updates. */
export type ImportMapUpdate = Record;
export interface LwrBuilderOverwriteOptions {
storeName?: boolean;
contentOnly?: boolean;
}
export interface LwrStringBuilder {
append(content: string): LwrStringBuilder;
appendLeft(index: number, content: string): LwrStringBuilder;
appendRight(index: number, content: string): LwrStringBuilder;
clone(): LwrStringBuilder;
move(start: number, end: number, index: number): LwrStringBuilder;
overwrite(start: number, end: number, content: string, options?: boolean | LwrBuilderOverwriteOptions): LwrStringBuilder;
prepend(content: string): LwrStringBuilder;
prependLeft(index: number, content: string): LwrStringBuilder;
prependRight(index: number, content: string): LwrStringBuilder;
remove(start: number, end: number): LwrStringBuilder;
slice(start: number, end: number): string;
snip(start: number, end: number): LwrStringBuilder;
trim(charType?: string): LwrStringBuilder;
trimStart(charType?: string): LwrStringBuilder;
trimEnd(charType?: string): LwrStringBuilder;
trimLines(): LwrStringBuilder;
lastChar(): string;
lastLine(): string;
isEmpty(): boolean;
length(): number;
toString(): string;
original: string;
}
export interface DecisionTree {
/**
* Insert an artifact into the tree based on a path of decisions
*/
insert(siteArtifactId: string, artifact: Artifact, debug?: boolean, localeFallbacks?: Record): void;
/**
* Retrieve an artifact from the tree based on a path of decisions
*/
find(siteArtifactId: string | Partial, debug?: boolean, ssr?: boolean, localeId?: string): Artifact | undefined;
}
export interface SiteMetadata {
/**
* Get the path that all site metadata is relative to
*/
getSiteRootDir(): string;
/**
* Get the current metadata about the pre-built module bundles for the site.
*/
getSiteBundles(): SiteBundles;
/**
* Get the current debug metadata about the pre-built module bundles for the site.
*/
getDebugSiteBundles(): SiteBundles;
/**
* Get the current metadata about the pre-built resources for the site.
*/
getSiteResources(): SiteResources;
/**
* Get the current debug metadata about the pre-built resources for the site.
*/
getDebugSiteResources(): SiteResources;
/**
* Get the current metadata about the pre-built assets for the site.
*/
getSiteAssets(): SiteAssets;
/**
* To save out metadata for the current site
* @param staticRoot
* @returns
*/
persistSiteMetadata(): Promise;
/**
* Get get decision tree to figure out the best site bundle to use.
*/
getSiteBundlesDecisionTree(): DecisionTree;
/**
* Get get decision tree to figure out the best site resource to use.
*/
getSiteResourcesDecisionTree(): DecisionTree;
}
export interface SiteBundles {
bundles: Record;
}
export interface SiteResources {
resources: Record;
}
export interface SiteAssets {
assets: Record;
}
export interface SiteArtifact {
path: string;
mimeType?: string;
integrity?: string;
}
export interface SiteResource extends SiteArtifact {
inline?: boolean;
}
export interface SiteBundle extends SiteArtifact {
version?: Version;
imports: string[];
dynamicImports?: string[];
includedModules?: string[];
}
//# sourceMappingURL=index.d.ts.map