UNPKG

@stencil/dev-server

Version:

Development server for Stencil with DOM-based HMR

126 lines (125 loc) 4.78 kB
import { CompilerBuildResults, Diagnostic, HmrStyleUpdate, HotModuleReplacement, PrintLine } from "@stencil/core/compiler"; //#region src/client/types.d.ts interface DevClientWindow extends Window { 's-dev-server'?: boolean; 's-initial-load'?: boolean; 's-build-id'?: number; devServerConfig?: DevClientConfig; WebSocket: typeof WebSocket; } interface DevClientConfig { basePath: string; editors: DevServerEditor[]; reloadStrategy: 'hmr' | 'pageReload' | null; socketUrl?: string; } interface DevServerEditor { id: string; name?: string; } interface DevServerMessage { buildResults?: CompilerBuildResults; buildLog?: BuildLog; isActivelyBuilding?: boolean; requestBuildResults?: boolean; } interface BuildLog { buildId: number; messages: string[]; progress: number; } interface HostElement extends Element { 's-hmr'?: (versionId: string) => void; } interface OpenInEditorData { file?: string; line?: number; column?: number; editor?: string; } interface HmrResults { updatedComponents: string[]; updatedExternalStyles: string[]; updatedInlineStyles: string[]; updatedImages: string[]; versionId: string; } //#endregion //#region src/client/constants.d.ts /** * Client-side constants for dev server. */ declare const DEV_SERVER_URL = "/~dev-server"; declare const DEV_SERVER_INIT_URL = "/~dev-server-init"; declare const OPEN_IN_EDITOR_URL = "/~dev-server-open-in-editor"; declare const BUILD_LOG = "devserver:buildlog"; declare const BUILD_RESULTS = "devserver:buildresults"; declare const BUILD_STATUS = "devserver:buildstatus"; declare const NODE_TYPE_ELEMENT = 1; declare const NODE_TYPE_DOCUMENT_FRAGMENT = 11; declare const RECONNECT_ATTEMPTS = 1000; declare const RECONNECT_RETRY_MS = 2500; declare const NORMAL_CLOSURE_CODE = 1000; declare const REQUEST_BUILD_RESULTS_INTERVAL_MS = 500; //#endregion //#region src/client/error.d.ts interface AppErrorData { window: Window; buildResults: any; openInEditor?: OpenInEditorCallback; } type OpenInEditorCallback = (data: { file: string; line: number; column: number; }) => void; interface AppErrorResults { diagnostics: Diagnostic[]; status: null | string; } declare const appError: (data: AppErrorData) => AppErrorResults; declare const clearAppErrorModal: (data: { window: Window; }) => void; //#endregion //#region src/client/events.d.ts declare const emitBuildLog: (win: Window, buildLog: BuildLog) => void; declare const emitBuildResults: (win: Window, buildResults: CompilerBuildResults) => void; declare const emitBuildStatus: (win: Window, buildStatus: string) => void; declare const onBuildLog: (win: Window, cb: (buildLog: BuildLog) => void) => void; declare const onBuildResults: (win: Window, cb: (buildResults: CompilerBuildResults) => void) => void; declare const onBuildStatus: (win: Window, cb: (buildStatus: string) => void) => void; //#endregion //#region src/client/hmr/window.d.ts interface HmrWindowData { window: Window; hmr: HotModuleReplacement; } declare const hmrWindow: (data: HmrWindowData) => HmrResults; //#endregion //#region src/client/logger.d.ts declare const logBuild: (msg: string) => void; declare const logReload: (msg: string) => void; declare const logWarn: (prefix: string, msg: string) => void; declare const logDisabled: (prefix: string, msg: string) => void; declare const logDiagnostic: (diag: Diagnostic) => void; //#endregion //#region src/client/status.d.ts /** * Build status and favicon utilities for dev server client. */ declare const initBuildStatus: (data: { window: Window; }) => void; declare const updateFavIcon: (linkElm: HTMLLinkElement, status: string) => void; declare const initBuildProgress: (data: { window: Window; }) => void; //#endregion //#region src/client/websocket.d.ts declare const initClientWebSocket: (win: DevClientWindow, config: DevClientConfig) => void; //#endregion //#region src/client/index.d.ts declare const initDevClient: (win: DevClientWindow, config: DevClientConfig) => void; //#endregion export { BUILD_LOG, BUILD_RESULTS, BUILD_STATUS, BuildLog, type CompilerBuildResults, DEV_SERVER_INIT_URL, DEV_SERVER_URL, DevClientConfig, DevClientWindow, DevServerEditor, DevServerMessage, type Diagnostic, HmrResults, type HmrStyleUpdate, HostElement, type HotModuleReplacement, NODE_TYPE_DOCUMENT_FRAGMENT, NODE_TYPE_ELEMENT, NORMAL_CLOSURE_CODE, OPEN_IN_EDITOR_URL, OpenInEditorData, type PrintLine, RECONNECT_ATTEMPTS, RECONNECT_RETRY_MS, REQUEST_BUILD_RESULTS_INTERVAL_MS, appError, clearAppErrorModal, emitBuildLog, emitBuildResults, emitBuildStatus, hmrWindow, initBuildProgress, initBuildStatus, initClientWebSocket, initDevClient, logBuild, logDiagnostic, logDisabled, logReload, logWarn, onBuildLog, onBuildResults, onBuildStatus, updateFavIcon };