@stencil/dev-server 5.0.0-next.0 → 5.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +105 -0
- package/dist/client/index.d.ts +9 -3
- package/dist/client/index.js +152 -84
- package/dist/connector.html +27 -20
- package/dist/index.d.mts +0 -3
- package/dist/index.mjs +348 -51
- package/dist/templates/directory-index.html +16 -6
- package/dist/templates/initial-load.html +142 -132
- package/dist/worker-thread.js +17 -15
- package/package.json +25 -19
- package/templates/directory-index.html +16 -6
- package/templates/initial-load.html +142 -132
- /package/{LICENSE.md → LICENSE} +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# @stencil/dev-server
|
|
2
|
+
|
|
3
|
+
Development server for Stencil with DOM-based Hot Module Replacement (HMR).
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install --save-dev @stencil/dev-server @stencil/core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
The dev server is configured via `stencil.config.ts` and started automatically with `stencil build --dev --watch --serve`.
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
// stencil.config.ts
|
|
17
|
+
import { Config } from '@stencil/core';
|
|
18
|
+
|
|
19
|
+
export const config: Config = {
|
|
20
|
+
devServer: {
|
|
21
|
+
port: 3333,
|
|
22
|
+
openBrowser: true,
|
|
23
|
+
reloadStrategy: 'pageReload', // or 'hmr'
|
|
24
|
+
},
|
|
25
|
+
outputTargets: [{ type: 'www' }],
|
|
26
|
+
};
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npx stencil build --dev --watch --serve
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Programmatic API
|
|
34
|
+
|
|
35
|
+
### `start(config, logger, watcher?)` — start the dev server
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { start } from '@stencil/dev-server';
|
|
39
|
+
import { createNodeLogger } from '@stencil/core/sys/node';
|
|
40
|
+
|
|
41
|
+
const server = await start(
|
|
42
|
+
{
|
|
43
|
+
root: './www', // directory to serve
|
|
44
|
+
port: 3333,
|
|
45
|
+
openBrowser: true,
|
|
46
|
+
reloadStrategy: 'hmr', // 'hmr' | 'pageReload' | null
|
|
47
|
+
},
|
|
48
|
+
createNodeLogger(),
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
console.log(`Listening at ${server.browserUrl}`);
|
|
52
|
+
|
|
53
|
+
// Shut down when done
|
|
54
|
+
await server.close();
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### With a Stencil compiler watcher (full HMR)
|
|
58
|
+
|
|
59
|
+
Pass a `CompilerWatcher` to connect build output to the dev server — file changes trigger HMR or a page reload automatically.
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import * as coreCompiler from '@stencil/core/compiler';
|
|
63
|
+
import { start } from '@stencil/dev-server';
|
|
64
|
+
import { createNodeLogger, createNodeSys } from '@stencil/core/sys/node';
|
|
65
|
+
|
|
66
|
+
const logger = createNodeLogger();
|
|
67
|
+
const sys = createNodeSys();
|
|
68
|
+
|
|
69
|
+
const { config } = await coreCompiler.loadConfig({
|
|
70
|
+
configPath: './stencil.config.ts',
|
|
71
|
+
logger,
|
|
72
|
+
sys,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const compiler = await coreCompiler.createCompiler(config);
|
|
76
|
+
const watcher = await compiler.createWatcher();
|
|
77
|
+
|
|
78
|
+
const server = await start(
|
|
79
|
+
{ root: './www', port: 3333, reloadStrategy: 'hmr' },
|
|
80
|
+
logger,
|
|
81
|
+
watcher,
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
// Start watching — builds trigger HMR updates in the browser
|
|
85
|
+
await watcher.start();
|
|
86
|
+
|
|
87
|
+
// To shut down:
|
|
88
|
+
// await watcher.close();
|
|
89
|
+
// await server.close();
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
The returned `DevServer` exposes `address`, `browserUrl`, `protocol`, `port`, `root`, and `close()`.
|
|
93
|
+
|
|
94
|
+
#### Key config options
|
|
95
|
+
|
|
96
|
+
| Option | Default | Description |
|
|
97
|
+
|---|---|---|
|
|
98
|
+
| `root` | `'.'` | Directory to serve files from |
|
|
99
|
+
| `port` | `3333` | Port to listen on |
|
|
100
|
+
| `address` | `'0.0.0.0'` | Network interface to bind |
|
|
101
|
+
| `reloadStrategy` | `'hmr'` | `'hmr'`, `'pageReload'`, or `null` to disable |
|
|
102
|
+
| `openBrowser` | `false` | Open browser on start |
|
|
103
|
+
| `https` | — | `{ cert, key }` to enable HTTPS |
|
|
104
|
+
| `worker` | `true` | Fork server into a child process (disable for debugging) |
|
|
105
|
+
| `ssr` | `false` | Server-side render each page on request (dev only - you must have a `ssr` output target setup) |
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { CompilerBuildResults, Diagnostic, HmrStyleUpdate, HotModuleReplacement, PrintLine } from "@stencil/core/compiler";
|
|
2
|
-
|
|
1
|
+
import { CompilerBuildResults, Diagnostic, HmrGlobalStyleUpdate, HmrStyleUpdate, HotModuleReplacement, PrintLine } from "@stencil/core/compiler";
|
|
3
2
|
//#region src/client/types.d.ts
|
|
4
3
|
interface DevClientWindow extends Window {
|
|
5
4
|
's-dev-server'?: boolean;
|
|
@@ -42,6 +41,7 @@ interface HmrResults {
|
|
|
42
41
|
updatedComponents: string[];
|
|
43
42
|
updatedExternalStyles: string[];
|
|
44
43
|
updatedInlineStyles: string[];
|
|
44
|
+
updatedGlobalStyles: string[];
|
|
45
45
|
updatedImages: string[];
|
|
46
46
|
versionId: string;
|
|
47
47
|
}
|
|
@@ -121,6 +121,12 @@ declare const initBuildProgress: (data: {
|
|
|
121
121
|
declare const initClientWebSocket: (win: DevClientWindow, config: DevClientConfig) => void;
|
|
122
122
|
//#endregion
|
|
123
123
|
//#region src/client/index.d.ts
|
|
124
|
+
/**
|
|
125
|
+
* Initialize the dev server client in the browser.
|
|
126
|
+
*
|
|
127
|
+
* @param win - the dev client window object
|
|
128
|
+
* @param config - the dev client configuration
|
|
129
|
+
*/
|
|
124
130
|
declare const initDevClient: (win: DevClientWindow, config: DevClientConfig) => void;
|
|
125
131
|
//#endregion
|
|
126
|
-
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 };
|
|
132
|
+
export { BUILD_LOG, BUILD_RESULTS, BUILD_STATUS, BuildLog, type CompilerBuildResults, DEV_SERVER_INIT_URL, DEV_SERVER_URL, DevClientConfig, DevClientWindow, DevServerEditor, DevServerMessage, type Diagnostic, type HmrGlobalStyleUpdate, 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 };
|
package/dist/client/index.js
CHANGED
|
@@ -14,58 +14,9 @@ const RECONNECT_ATTEMPTS = 1e3;
|
|
|
14
14
|
const RECONNECT_RETRY_MS = 2500;
|
|
15
15
|
const NORMAL_CLOSURE_CODE = 1e3;
|
|
16
16
|
const REQUEST_BUILD_RESULTS_INTERVAL_MS = 500;
|
|
17
|
-
|
|
18
17
|
//#endregion
|
|
19
|
-
//#region src/client/
|
|
20
|
-
|
|
21
|
-
* Client-side event system for dev server.
|
|
22
|
-
*/
|
|
23
|
-
const emitBuildLog = (win, buildLog) => {
|
|
24
|
-
win.dispatchEvent(new CustomEvent(BUILD_LOG, { detail: buildLog }));
|
|
25
|
-
};
|
|
26
|
-
const emitBuildResults = (win, buildResults) => {
|
|
27
|
-
win.dispatchEvent(new CustomEvent(BUILD_RESULTS, { detail: buildResults }));
|
|
28
|
-
};
|
|
29
|
-
const emitBuildStatus = (win, buildStatus) => {
|
|
30
|
-
win.dispatchEvent(new CustomEvent(BUILD_STATUS, { detail: buildStatus }));
|
|
31
|
-
};
|
|
32
|
-
const onBuildLog = (win, cb) => {
|
|
33
|
-
win.addEventListener(BUILD_LOG, ((ev) => {
|
|
34
|
-
cb(ev.detail);
|
|
35
|
-
}));
|
|
36
|
-
};
|
|
37
|
-
const onBuildResults = (win, cb) => {
|
|
38
|
-
win.addEventListener(BUILD_RESULTS, ((ev) => {
|
|
39
|
-
cb(ev.detail);
|
|
40
|
-
}));
|
|
41
|
-
};
|
|
42
|
-
const onBuildStatus = (win, cb) => {
|
|
43
|
-
win.addEventListener(BUILD_STATUS, ((ev) => {
|
|
44
|
-
cb(ev.detail);
|
|
45
|
-
}));
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
//#endregion
|
|
49
|
-
//#region ../../node_modules/.pnpm/style-inject@0.3.0/node_modules/style-inject/dist/style-inject.es.js
|
|
50
|
-
function styleInject(css, ref) {
|
|
51
|
-
if (ref === void 0) ref = {};
|
|
52
|
-
var insertAt = ref.insertAt;
|
|
53
|
-
if (!css || typeof document === "undefined") return;
|
|
54
|
-
var head = document.head || document.getElementsByTagName("head")[0];
|
|
55
|
-
var style = document.createElement("style");
|
|
56
|
-
style.type = "text/css";
|
|
57
|
-
if (insertAt === "top") if (head.firstChild) head.insertBefore(style, head.firstChild);
|
|
58
|
-
else head.appendChild(style);
|
|
59
|
-
else head.appendChild(style);
|
|
60
|
-
if (style.styleSheet) style.styleSheet.cssText = css;
|
|
61
|
-
else style.appendChild(document.createTextNode(css));
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
//#endregion
|
|
65
|
-
//#region src/client/error.css
|
|
66
|
-
var css_248z = "#dev-server-modal * {\n box-sizing: border-box !important;\n}\n\n/* Backdrop overlay */\n#dev-server-modal {\n direction: ltr !important;\n display: block;\n position: fixed !important;\n top: 0 !important;\n left: 0 !important;\n width: 100% !important;\n height: 100% !important;\n z-index: 99999 !important;\n margin: 0 !important;\n padding: 0 !important;\n background: rgba(0, 0, 0, 0.66) !important;\n overflow-y: auto !important;\n -webkit-overflow-scrolling: touch !important;\n font-family: -apple-system, 'Roboto', BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol' !important;\n font-size: 14px !important;\n line-height: 1.5 !important;\n -webkit-font-smoothing: antialiased;\n text-rendering: optimizeLegibility;\n text-size-adjust: none;\n word-wrap: break-word;\n user-select: auto;\n}\n\n/* Modal window */\n#dev-server-modal-inner {\n position: relative !important;\n max-width: 80vw !important;\n margin: 30px auto !important;\n padding: 25px !important;\n background-color: white !important;\n border-radius: 8px !important;\n box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5) !important;\n color: #333 !important;\n}\n\n.dev-server-diagnostic {\n margin: 20px !important;\n border: 1px solid #ddd !important;\n border-radius: 3px !important;\n}\n\n.dev-server-diagnostic-masthead {\n padding: 8px 12px 12px 12px !important;\n}\n\n.dev-server-diagnostic-title {\n margin: 0 !important;\n font-weight: bold !important;\n color: #222 !important;\n}\n\n.dev-server-diagnostic-message {\n margin-top: 4px !important;\n color: #555 !important;\n}\n\n.dev-server-diagnostic-file {\n position: relative !important;\n border-top: 1px solid #ddd !important;\n}\n\n.dev-server-diagnostic-file-header {\n display: block !important;\n padding: 5px 10px !important;\n color: #555 !important;\n border-bottom: 1px solid #ddd !important;\n border-top-left-radius: 2px !important;\n border-top-right-radius: 2px !important;\n background-color: #f9f9f9 !important;\n font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important;\n font-size: 12px !important;\n}\n\na.dev-server-diagnostic-file-header {\n color: #0000ee !important;\n text-decoration: underline !important;\n}\n\na.dev-server-diagnostic-file-header:hover {\n text-decoration: none !important;\n background-color: #f4f4f4 !important;\n}\n\n.dev-server-diagnostic-file-name {\n font-weight: bold !important;\n}\n\n.dev-server-diagnostic-blob {\n overflow-x: auto !important;\n overflow-y: hidden !important;\n border-bottom-right-radius: 3px !important;\n border-bottom-left-radius: 3px !important;\n}\n\n.dev-server-diagnostic-table {\n margin: 0 !important;\n padding: 0 !important;\n border-spacing: 0 !important;\n border-collapse: collapse !important;\n border-width: 0 !important;\n border-style: none !important;\n -moz-tab-size: 2;\n tab-size: 2;\n}\n\n.dev-server-diagnostic-table td,\n.dev-server-diagnostic-table th {\n padding: 0 !important;\n border-width: 0 !important;\n border-style: none !important;\n}\n\ntd.dev-server-diagnostic-blob-num {\n padding-right: 10px !important;\n padding-left: 10px !important;\n width: 1% !important;\n min-width: 50px !important;\n font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important;\n font-size: 12px !important;\n line-height: 20px !important;\n color: rgba(0, 0, 0, 0.3) !important;\n text-align: right !important;\n white-space: nowrap !important;\n vertical-align: top !important;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n user-select: none;\n border: solid #eee !important;\n border-width: 0 1px 0 0 !important;\n}\n\ntd.dev-server-diagnostic-blob-num::before {\n content: attr(data-line-number) !important;\n}\n\n.dev-server-diagnostic-error-line td.dev-server-diagnostic-blob-num {\n background-color: #ffdddd !important;\n border-color: #ffc9c9 !important;\n}\n\n.dev-server-diagnostic-error-line td.dev-server-diagnostic-blob-code {\n background: rgba(255, 221, 221, 0.25) !important;\n z-index: -1;\n}\n\n.dev-server-diagnostic-open-in-editor td.dev-server-diagnostic-blob-num:hover {\n cursor: pointer;\n background-color: #ffffe3 !important;\n font-weight: bold;\n}\n\n.dev-server-diagnostic-open-in-editor.dev-server-diagnostic-error-line td.dev-server-diagnostic-blob-num:hover {\n background-color: #ffdada !important;\n}\n\ntd.dev-server-diagnostic-blob-code {\n position: relative !important;\n padding-right: 10px !important;\n padding-left: 10px !important;\n line-height: 20px !important;\n vertical-align: top !important;\n overflow: visible !important;\n font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace !important;\n font-size: 12px !important;\n color: #333 !important;\n word-wrap: normal !important;\n white-space: pre !important;\n}\n\ntd.dev-server-diagnostic-blob-code::before {\n content: '' !important;\n}\n\n.dev-server-diagnostic-error-chr {\n position: relative !important;\n}\n\n.dev-server-diagnostic-error-chr::before {\n position: absolute !important;\n z-index: -1;\n top: -3px !important;\n left: 0px !important;\n width: 8px !important;\n height: 20px !important;\n background-color: #ffdddd !important;\n content: '' !important;\n}\n\n/**\n * GitHub Gist Theme\n * Author : Louis Barranqueiro - https://github.com/LouisBarranqueiro\n * https://highlightjs.org/\n */\n.hljs-comment,\n.hljs-meta {\n color: #969896;\n}\n\n.hljs-string,\n.hljs-variable,\n.hljs-template-variable,\n.hljs-strong,\n.hljs-emphasis,\n.hljs-quote {\n color: #df5000;\n}\n\n.hljs-keyword,\n.hljs-selector-tag,\n.hljs-type {\n color: #a71d5d;\n}\n\n.hljs-literal,\n.hljs-symbol,\n.hljs-bullet,\n.hljs-attribute {\n color: #0086b3;\n}\n\n.hljs-section,\n.hljs-name {\n color: #63a35c;\n}\n\n.hljs-tag {\n color: #333333;\n}\n\n.hljs-title,\n.hljs-attr,\n.hljs-selector-id,\n.hljs-selector-class,\n.hljs-selector-attr,\n.hljs-selector-pseudo {\n color: #795da3;\n}\n\n.hljs-addition {\n color: #55a532;\n background-color: #eaffea;\n}\n\n.hljs-deletion {\n color: #bd2c00;\n background-color: #ffecec;\n}\n\n.hljs-link {\n text-decoration: underline;\n}\n\n/* Error badge - bottom left corner indicator */\n.dev-server-error-badge {\n position: fixed !important;\n bottom: 20px !important;\n left: 20px !important;\n z-index: 99998 !important;\n display: flex !important;\n align-items: center !important;\n gap: 8px !important;\n padding: 10px 16px !important;\n background: #ff5555 !important;\n color: white !important;\n border: none !important;\n border-radius: 8px !important;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', sans-serif !important;\n font-size: 14px !important;\n font-weight: 600 !important;\n cursor: pointer !important;\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3) !important;\n transition: transform 0.2s, box-shadow 0.2s !important;\n}\n\n.dev-server-error-badge:hover {\n transform: translateY(-2px) !important;\n box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4) !important;\n}\n\n.error-badge-icon {\n display: flex !important;\n align-items: center !important;\n justify-content: center !important;\n width: 20px !important;\n height: 20px !important;\n background: white !important;\n color: #ff5555 !important;\n border-radius: 50% !important;\n font-weight: bold !important;\n font-size: 14px !important;\n}\n\n.error-badge-count {\n font-size: 14px !important;\n font-weight: 600 !important;\n}\n";
|
|
67
|
-
styleInject(css_248z);
|
|
68
|
-
|
|
18
|
+
//#region src/client/error.css?inline
|
|
19
|
+
var error_default = "#dev-server-modal * {\n box-sizing: border-box !important;\n}\n\n#dev-server-modal {\n -webkit-font-smoothing: antialiased;\n text-rendering: optimizelegibility;\n text-size-adjust: none;\n word-wrap: break-word;\n user-select: auto;\n display: block;\n z-index: 99999 !important;\n -webkit-overflow-scrolling: touch !important;\n direction: ltr !important;\n background: #000000a8 !important;\n width: 100% !important;\n height: 100% !important;\n margin: 0 !important;\n padding: 0 !important;\n font-family: -apple-system, Roboto, BlinkMacSystemFont, Segoe UI, Helvetica Neue, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol !important;\n font-size: 14px !important;\n line-height: 1.5 !important;\n position: fixed !important;\n top: 0 !important;\n left: 0 !important;\n overflow-y: auto !important;\n}\n\n#dev-server-modal-inner {\n color: #333 !important;\n background-color: #fff !important;\n border-radius: 8px !important;\n max-width: 80vw !important;\n margin: 30px auto !important;\n padding: 25px !important;\n position: relative !important;\n box-shadow: 0 10px 40px #00000080 !important;\n}\n\n.dev-server-diagnostic {\n border: 1px solid #ddd !important;\n border-radius: 3px !important;\n margin: 20px !important;\n}\n\n.dev-server-diagnostic-masthead {\n padding: 8px 12px 12px !important;\n}\n\n.dev-server-diagnostic-title {\n color: #222 !important;\n margin: 0 !important;\n font-weight: bold !important;\n}\n\n.dev-server-diagnostic-message {\n color: #555 !important;\n margin-top: 4px !important;\n}\n\n.dev-server-diagnostic-file {\n border-top: 1px solid #ddd !important;\n position: relative !important;\n}\n\n.dev-server-diagnostic-file-header {\n color: #555 !important;\n background-color: #f9f9f9 !important;\n border-bottom: 1px solid #ddd !important;\n border-top-left-radius: 2px !important;\n border-top-right-radius: 2px !important;\n padding: 5px 10px !important;\n font-family: Consolas, Liberation Mono, Menlo, Courier, monospace !important;\n font-size: 12px !important;\n display: block !important;\n}\n\na.dev-server-diagnostic-file-header {\n color: #00e !important;\n text-decoration: underline !important;\n}\n\na.dev-server-diagnostic-file-header:hover {\n background-color: #f4f4f4 !important;\n text-decoration: none !important;\n}\n\n.dev-server-diagnostic-file-name {\n font-weight: bold !important;\n}\n\n.dev-server-diagnostic-blob {\n border-bottom-right-radius: 3px !important;\n border-bottom-left-radius: 3px !important;\n overflow: auto hidden !important;\n}\n\n.dev-server-diagnostic-table {\n -moz-tab-size: 2;\n tab-size: 2;\n border-spacing: 0 !important;\n border-collapse: collapse !important;\n border-style: none !important;\n border-width: 0 !important;\n margin: 0 !important;\n padding: 0 !important;\n}\n\n.dev-server-diagnostic-table td, .dev-server-diagnostic-table th {\n border-style: none !important;\n border-width: 0 !important;\n padding: 0 !important;\n}\n\ntd.dev-server-diagnostic-blob-num {\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n user-select: none;\n color: #0000004d !important;\n text-align: right !important;\n white-space: nowrap !important;\n vertical-align: top !important;\n border: 0 solid #eee !important;\n border-right-width: 1px !important;\n width: 1% !important;\n min-width: 50px !important;\n padding-left: 10px !important;\n padding-right: 10px !important;\n font-family: Consolas, Liberation Mono, Menlo, Courier, monospace !important;\n font-size: 12px !important;\n line-height: 20px !important;\n}\n\ntd.dev-server-diagnostic-blob-num:before {\n content: attr(data-line-number) !important;\n}\n\n.dev-server-diagnostic-error-line td.dev-server-diagnostic-blob-num {\n background-color: #fdd !important;\n border-color: #ffc9c9 !important;\n}\n\n.dev-server-diagnostic-error-line td.dev-server-diagnostic-blob-code {\n background: #ffdddd40 !important;\n}\n\n.dev-server-diagnostic-open-in-editor td.dev-server-diagnostic-blob-num:hover {\n cursor: pointer;\n font-weight: bold;\n background-color: #ffffe3 !important;\n}\n\n.dev-server-diagnostic-open-in-editor.dev-server-diagnostic-error-line td.dev-server-diagnostic-blob-num:hover {\n background-color: #ffdada !important;\n}\n\ntd.dev-server-diagnostic-blob-code {\n vertical-align: top !important;\n color: #333 !important;\n word-wrap: normal !important;\n white-space: pre !important;\n padding-left: 10px !important;\n padding-right: 10px !important;\n font-family: Consolas, Liberation Mono, Menlo, Courier, monospace !important;\n font-size: 12px !important;\n line-height: 20px !important;\n position: relative !important;\n overflow: visible !important;\n}\n\ntd.dev-server-diagnostic-blob-code:before {\n content: \"\" !important;\n}\n\n.dev-server-diagnostic-error-chr {\n position: relative !important;\n}\n\n.dev-server-diagnostic-error-chr:before {\n z-index: -1;\n content: \"\" !important;\n background-color: #fdd !important;\n width: 8px !important;\n height: 20px !important;\n position: absolute !important;\n top: -3px !important;\n left: 0 !important;\n}\n\n.hljs-comment, .hljs-meta {\n color: #969896;\n}\n\n.hljs-string, .hljs-variable, .hljs-template-variable, .hljs-strong, .hljs-emphasis, .hljs-quote {\n color: #df5000;\n}\n\n.hljs-keyword, .hljs-selector-tag, .hljs-type {\n color: #a71d5d;\n}\n\n.hljs-literal, .hljs-symbol, .hljs-bullet, .hljs-attribute {\n color: #0086b3;\n}\n\n.hljs-section, .hljs-name {\n color: #63a35c;\n}\n\n.hljs-tag {\n color: #333;\n}\n\n.hljs-title, .hljs-attr, .hljs-selector-id, .hljs-selector-class, .hljs-selector-attr, .hljs-selector-pseudo {\n color: #795da3;\n}\n\n.hljs-addition {\n color: #55a532;\n background-color: #eaffea;\n}\n\n.hljs-deletion {\n color: #bd2c00;\n background-color: #ffecec;\n}\n\n.hljs-link {\n text-decoration: underline;\n}\n\n.dev-server-error-badge {\n z-index: 99998 !important;\n color: #fff !important;\n cursor: pointer !important;\n background: #f55 !important;\n border: none !important;\n border-radius: 8px !important;\n align-items: center !important;\n gap: 8px !important;\n padding: 10px 16px !important;\n font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica Neue, sans-serif !important;\n font-size: 14px !important;\n font-weight: 600 !important;\n transition: transform .2s, box-shadow .2s !important;\n display: flex !important;\n position: fixed !important;\n bottom: 20px !important;\n left: 20px !important;\n box-shadow: 0 4px 12px #0000004d !important;\n}\n\n.dev-server-error-badge:hover {\n transform: translateY(-2px) !important;\n box-shadow: 0 6px 16px #0006 !important;\n}\n\n.error-badge-icon {\n color: #f55 !important;\n background: #fff !important;\n border-radius: 50% !important;\n justify-content: center !important;\n align-items: center !important;\n width: 20px !important;\n height: 20px !important;\n font-size: 14px !important;\n font-weight: bold !important;\n display: flex !important;\n}\n\n.error-badge-count {\n font-size: 14px !important;\n font-weight: 600 !important;\n}\n";
|
|
69
20
|
//#endregion
|
|
70
21
|
//#region src/client/error.ts
|
|
71
22
|
let errorCount = 0;
|
|
@@ -194,7 +145,7 @@ const getDevServerModal = (doc, _openInEditor) => {
|
|
|
194
145
|
outer.id = DEV_SERVER_MODAL;
|
|
195
146
|
outer.setAttribute("role", "dialog");
|
|
196
147
|
doc.body.appendChild(outer);
|
|
197
|
-
outer.innerHTML = `<style>${
|
|
148
|
+
outer.innerHTML = `<style>${error_default}</style><div id="${DEV_SERVER_MODAL}-inner"></div>`;
|
|
198
149
|
const closeOnEsc = (e) => {
|
|
199
150
|
if (e.key === "Escape" || e.code === "Escape") closeDevServerModal(doc);
|
|
200
151
|
};
|
|
@@ -276,7 +227,7 @@ const highlightError = (text, errorCharStart, errorLength) => {
|
|
|
276
227
|
};
|
|
277
228
|
const prepareLines = (orgLines) => {
|
|
278
229
|
const lines = JSON.parse(JSON.stringify(orgLines));
|
|
279
|
-
for (let
|
|
230
|
+
for (let x = 0; x < 100; x++) {
|
|
280
231
|
if (!eachLineHasLeadingWhitespace(lines)) return lines;
|
|
281
232
|
for (let i = 0; i < lines.length; i++) {
|
|
282
233
|
lines[i].text = lines[i].text?.slice(1) ?? "";
|
|
@@ -297,7 +248,35 @@ const eachLineHasLeadingWhitespace = (lines) => {
|
|
|
297
248
|
};
|
|
298
249
|
const DEV_SERVER_MODAL = `dev-server-modal`;
|
|
299
250
|
const ERROR_BADGE_ID = "dev-server-error-badge";
|
|
300
|
-
|
|
251
|
+
//#endregion
|
|
252
|
+
//#region src/client/events.ts
|
|
253
|
+
/**
|
|
254
|
+
* Client-side event system for dev server.
|
|
255
|
+
*/
|
|
256
|
+
const emitBuildLog = (win, buildLog) => {
|
|
257
|
+
win.dispatchEvent(new CustomEvent(BUILD_LOG, { detail: buildLog }));
|
|
258
|
+
};
|
|
259
|
+
const emitBuildResults = (win, buildResults) => {
|
|
260
|
+
win.dispatchEvent(new CustomEvent(BUILD_RESULTS, { detail: buildResults }));
|
|
261
|
+
};
|
|
262
|
+
const emitBuildStatus = (win, buildStatus) => {
|
|
263
|
+
win.dispatchEvent(new CustomEvent(BUILD_STATUS, { detail: buildStatus }));
|
|
264
|
+
};
|
|
265
|
+
const onBuildLog = (win, cb) => {
|
|
266
|
+
win.addEventListener(BUILD_LOG, ((ev) => {
|
|
267
|
+
cb(ev.detail);
|
|
268
|
+
}));
|
|
269
|
+
};
|
|
270
|
+
const onBuildResults = (win, cb) => {
|
|
271
|
+
win.addEventListener(BUILD_RESULTS, ((ev) => {
|
|
272
|
+
cb(ev.detail);
|
|
273
|
+
}));
|
|
274
|
+
};
|
|
275
|
+
const onBuildStatus = (win, cb) => {
|
|
276
|
+
win.addEventListener(BUILD_STATUS, ((ev) => {
|
|
277
|
+
cb(ev.detail);
|
|
278
|
+
}));
|
|
279
|
+
};
|
|
301
280
|
//#endregion
|
|
302
281
|
//#region src/client/hmr/utils.ts
|
|
303
282
|
const getHmrHref = (versionId, fileName, testUrl) => {
|
|
@@ -350,7 +329,7 @@ const isLinkStylesheet = (elm) => elm.nodeName.toLowerCase() === "link" && !!elm
|
|
|
350
329
|
* @param elm the element to check
|
|
351
330
|
* @returns whether or not the element of interest is a template element
|
|
352
331
|
*/
|
|
353
|
-
const isTemplate = (elm) => elm.nodeName.toLowerCase() === "template" && !!elm.content && elm.content.nodeType ===
|
|
332
|
+
const isTemplate = (elm) => elm.nodeName.toLowerCase() === "template" && !!elm.content && elm.content.nodeType === 11;
|
|
354
333
|
/**
|
|
355
334
|
* Set a new hmr version ID into the `data-hmr` attribute on an element.
|
|
356
335
|
*
|
|
@@ -366,15 +345,14 @@ const setHmrAttr = (elm, versionId) => {
|
|
|
366
345
|
* @param elm the element to check
|
|
367
346
|
* @returns whether or not it has a shadow root
|
|
368
347
|
*/
|
|
369
|
-
const hasShadowRoot = (elm) => !!elm.shadowRoot && elm.shadowRoot.nodeType ===
|
|
348
|
+
const hasShadowRoot = (elm) => !!elm.shadowRoot && elm.shadowRoot.nodeType === 11 && elm.shadowRoot !== elm;
|
|
370
349
|
/**
|
|
371
350
|
* Determine whether or not an element is an element node
|
|
372
351
|
*
|
|
373
352
|
* @param elm the element to check
|
|
374
353
|
* @returns whether or not it is an element node
|
|
375
354
|
*/
|
|
376
|
-
const isElement = (elm) => !!elm && elm.nodeType ===
|
|
377
|
-
|
|
355
|
+
const isElement = (elm) => !!elm && elm.nodeType === 1 && !!elm.getAttribute;
|
|
378
356
|
//#endregion
|
|
379
357
|
//#region src/client/hmr/component.ts
|
|
380
358
|
const hmrComponents = (element, versionId, hmrTagNames) => {
|
|
@@ -393,7 +371,6 @@ const hmrComponent = (updatedTags, element, versionId, cmpTagName) => {
|
|
|
393
371
|
if (hasShadowRoot(element)) hmrComponent(updatedTags, element.shadowRoot, versionId, cmpTagName);
|
|
394
372
|
if (element.children) for (let i = 0; i < element.children.length; i++) hmrComponent(updatedTags, element.children[i], versionId, cmpTagName);
|
|
395
373
|
};
|
|
396
|
-
|
|
397
374
|
//#endregion
|
|
398
375
|
//#region src/client/hmr/image.ts
|
|
399
376
|
const hmrImages = (win, doc, versionId, imageFileNames) => {
|
|
@@ -419,9 +396,7 @@ const hmrStyleSheetImages = (cssImageProps, styleSheet, versionId, imageFileName
|
|
|
419
396
|
case CSSRule.STYLE_RULE:
|
|
420
397
|
hmrStyleSheetRuleImages(cssImageProps, cssRule, versionId, imageFileNames);
|
|
421
398
|
break;
|
|
422
|
-
case CSSRule.MEDIA_RULE:
|
|
423
|
-
hmrStyleSheetImages(cssImageProps, cssRule, versionId, imageFileNames);
|
|
424
|
-
break;
|
|
399
|
+
case CSSRule.MEDIA_RULE: hmrStyleSheetImages(cssImageProps, cssRule, versionId, imageFileNames);
|
|
425
400
|
}
|
|
426
401
|
}
|
|
427
402
|
} catch (e) {
|
|
@@ -484,7 +459,6 @@ const hmrUpdateStyleAttr = (elm, versionId, imageFileNames, oldStyleAttr) => {
|
|
|
484
459
|
}
|
|
485
460
|
});
|
|
486
461
|
};
|
|
487
|
-
|
|
488
462
|
//#endregion
|
|
489
463
|
//#region src/client/hmr/style.ts
|
|
490
464
|
const STYLE_ID_ATTR = "sty-id";
|
|
@@ -505,6 +479,43 @@ const hmrStylesheetLink = (styleSheetElm, versionId, cssFileName) => {
|
|
|
505
479
|
setHmrAttr(styleSheetElm, versionId);
|
|
506
480
|
}
|
|
507
481
|
};
|
|
482
|
+
const GLOBAL_LINK_ATTR = "data-hmr-global";
|
|
483
|
+
/**
|
|
484
|
+
* Apply live CSS text updates for `global-style` output targets. Each update is matched
|
|
485
|
+
* to the `<link rel="stylesheet">` that loads it (by fileName) and delivered as a
|
|
486
|
+
* `<style>` inserted immediately after that `<link>`, so multiple global stylesheets
|
|
487
|
+
* keep their original cascade order. The matching `<link>` is disabled once a patch takes over.
|
|
488
|
+
*
|
|
489
|
+
* @param doc - the document to apply updates to
|
|
490
|
+
* @param versionId - the HMR version identifier
|
|
491
|
+
* @param updates - the global style updates, one per changed output target
|
|
492
|
+
* @returns the fileNames that were updated
|
|
493
|
+
*/
|
|
494
|
+
const hmrGlobalStyleLinks = (doc, versionId, updates) => {
|
|
495
|
+
updates.forEach(({ fileName, styleText }) => {
|
|
496
|
+
const link = findMatchingStylesheetLink(doc, fileName);
|
|
497
|
+
if (link) link.disabled = true;
|
|
498
|
+
const existing = findGlobalStyleLinkPatch(doc, fileName);
|
|
499
|
+
if (existing) {
|
|
500
|
+
existing.innerHTML = styleText.replace(/\\n/g, "\n");
|
|
501
|
+
existing.setAttribute("data-hmr", versionId);
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
const styleElm = doc.createElement("style");
|
|
505
|
+
styleElm.innerHTML = styleText.replace(/\\n/g, "\n");
|
|
506
|
+
styleElm.setAttribute(GLOBAL_LINK_ATTR, fileName);
|
|
507
|
+
styleElm.setAttribute("data-hmr", versionId);
|
|
508
|
+
if (link?.parentNode) link.parentNode.insertBefore(styleElm, link.nextSibling);
|
|
509
|
+
else doc.head.appendChild(styleElm);
|
|
510
|
+
});
|
|
511
|
+
return updates.map((u) => u.fileName).sort();
|
|
512
|
+
};
|
|
513
|
+
const findGlobalStyleLinkPatch = (doc, fileName) => {
|
|
514
|
+
return Array.from(doc.head.querySelectorAll(`style[${GLOBAL_LINK_ATTR}]`)).find((s) => s.getAttribute(GLOBAL_LINK_ATTR) === fileName) ?? null;
|
|
515
|
+
};
|
|
516
|
+
const findMatchingStylesheetLink = (doc, fileName) => {
|
|
517
|
+
return Array.from(doc.querySelectorAll("link[rel=\"stylesheet\"]")).find((link) => getUrlFileName(link.getAttribute("href") ?? "") === fileName) ?? null;
|
|
518
|
+
};
|
|
508
519
|
const hmrInlineStyles = (elm, versionId, stylesUpdatedData) => {
|
|
509
520
|
const trackers = stylesUpdatedData.map((styleUpdate) => ({
|
|
510
521
|
styleUpdate,
|
|
@@ -519,6 +530,9 @@ const hmrInlineStyles = (elm, versionId, stylesUpdatedData) => {
|
|
|
519
530
|
};
|
|
520
531
|
/**
|
|
521
532
|
* Traverse the DOM looking for style elements to update or remove.
|
|
533
|
+
* @param elm - the element to start traversal from
|
|
534
|
+
* @param versionId - the HMR version identifier
|
|
535
|
+
* @param trackers - the style update trackers
|
|
522
536
|
*/
|
|
523
537
|
const hmrInlineStylesTraverse = (elm, versionId, trackers) => {
|
|
524
538
|
if (isElement(elm) && elm.nodeName.toLowerCase() === "style") trackers.forEach((tracker) => {
|
|
@@ -528,14 +542,19 @@ const hmrInlineStylesTraverse = (elm, versionId, trackers) => {
|
|
|
528
542
|
if (hasShadowRoot(elm)) hmrInlineStylesTraverse(elm.shadowRoot, versionId, trackers);
|
|
529
543
|
if (elm.children) for (let i = 0; i < elm.children.length; i++) hmrInlineStylesTraverse(elm.children[i], versionId, trackers);
|
|
530
544
|
};
|
|
545
|
+
const SLOT_FB_CSS = "slot-fb{display:contents}slot-fb[hidden]{display:none}";
|
|
531
546
|
/**
|
|
532
547
|
* Update or remove a style element based on the HMR update.
|
|
533
|
-
*
|
|
548
|
+
* @param elm - the style element to update
|
|
549
|
+
* @param versionId - the HMR version identifier
|
|
550
|
+
* @param stylesUpdated - the HMR style update data
|
|
551
|
+
* @returns true if this element matched and was processed
|
|
534
552
|
*/
|
|
535
553
|
const hmrStyleElement = (elm, versionId, stylesUpdated) => {
|
|
536
554
|
if (elm.getAttribute(STYLE_ID_ATTR) === stylesUpdated.styleId) {
|
|
537
555
|
if (stylesUpdated.styleText) {
|
|
538
|
-
|
|
556
|
+
const slotFbSuffix = elm.hasAttribute("data-slot-fb") ? SLOT_FB_CSS : "";
|
|
557
|
+
elm.innerHTML = stylesUpdated.styleText.replace(/\\n/g, "\n") + slotFbSuffix;
|
|
539
558
|
elm.setAttribute("data-hmr", versionId);
|
|
540
559
|
} else elm.remove();
|
|
541
560
|
return true;
|
|
@@ -545,6 +564,9 @@ const hmrStyleElement = (elm, versionId, stylesUpdated) => {
|
|
|
545
564
|
/**
|
|
546
565
|
* Find all component instances with the matching tag name and create style elements.
|
|
547
566
|
* Handles both shadow DOM components (style in shadow root) and scoped components (style in head).
|
|
567
|
+
* @param rootElm - the root element to search from
|
|
568
|
+
* @param versionId - the HMR version identifier
|
|
569
|
+
* @param styleUpdate - the HMR style update data
|
|
548
570
|
*/
|
|
549
571
|
const createStyleElementsForComponent = (rootElm, versionId, styleUpdate) => {
|
|
550
572
|
const { styleTag, styleId, styleText } = styleUpdate;
|
|
@@ -568,6 +590,9 @@ const createStyleElementsForComponent = (rootElm, versionId, styleUpdate) => {
|
|
|
568
590
|
};
|
|
569
591
|
/**
|
|
570
592
|
* Find all instances of a component by tag name, including in shadow roots.
|
|
593
|
+
* @param elm - the element to search from
|
|
594
|
+
* @param tagName - the tag name to search for
|
|
595
|
+
* @returns an array of matching elements
|
|
571
596
|
*/
|
|
572
597
|
const findComponentInstances = (elm, tagName) => {
|
|
573
598
|
const instances = [];
|
|
@@ -581,6 +606,10 @@ const findComponentInstancesTraverse = (elm, tagName, instances) => {
|
|
|
581
606
|
};
|
|
582
607
|
/**
|
|
583
608
|
* Create a new style element with the given content.
|
|
609
|
+
* @param container - the container to insert the style element into
|
|
610
|
+
* @param styleId - the style identifier
|
|
611
|
+
* @param styleText - the CSS content
|
|
612
|
+
* @param versionId - the HMR version identifier
|
|
584
613
|
*/
|
|
585
614
|
const createStyleElement = (container, styleId, styleText, versionId) => {
|
|
586
615
|
const styleElm = ("ownerDocument" in container ? container.ownerDocument : container.ownerDocument).createElement("style");
|
|
@@ -590,7 +619,6 @@ const createStyleElement = (container, styleId, styleText, versionId) => {
|
|
|
590
619
|
if (container.firstChild) container.insertBefore(styleElm, container.firstChild);
|
|
591
620
|
else container.appendChild(styleElm);
|
|
592
621
|
};
|
|
593
|
-
|
|
594
622
|
//#endregion
|
|
595
623
|
//#region src/client/hmr/window.ts
|
|
596
624
|
const hmrWindow = (data) => {
|
|
@@ -598,6 +626,7 @@ const hmrWindow = (data) => {
|
|
|
598
626
|
updatedComponents: [],
|
|
599
627
|
updatedExternalStyles: [],
|
|
600
628
|
updatedInlineStyles: [],
|
|
629
|
+
updatedGlobalStyles: [],
|
|
601
630
|
updatedImages: [],
|
|
602
631
|
versionId: ""
|
|
603
632
|
};
|
|
@@ -611,6 +640,7 @@ const hmrWindow = (data) => {
|
|
|
611
640
|
results.versionId = versionId;
|
|
612
641
|
if (hmr.componentsUpdated) results.updatedComponents = hmrComponents(documentElement, versionId, hmr.componentsUpdated);
|
|
613
642
|
if (hmr.inlineStylesUpdated) results.updatedInlineStyles = hmrInlineStyles(documentElement, versionId, hmr.inlineStylesUpdated);
|
|
643
|
+
if (hmr.globalStylesUpdated) results.updatedGlobalStyles = hmrGlobalStyleLinks(doc, versionId, hmr.globalStylesUpdated);
|
|
614
644
|
if (hmr.externalStylesUpdated) results.updatedExternalStyles = hmrExternalStyles(documentElement, versionId, hmr.externalStylesUpdated);
|
|
615
645
|
if (hmr.imagesUpdated) results.updatedImages = hmrImages(win, doc, versionId, hmr.imagesUpdated);
|
|
616
646
|
setHmrAttr(documentElement, versionId);
|
|
@@ -619,7 +649,6 @@ const hmrWindow = (data) => {
|
|
|
619
649
|
}
|
|
620
650
|
return results;
|
|
621
651
|
};
|
|
622
|
-
|
|
623
652
|
//#endregion
|
|
624
653
|
//#region src/client/logger.ts
|
|
625
654
|
const YELLOW = "#f39c12";
|
|
@@ -653,7 +682,6 @@ const logDiagnostic = (diag) => {
|
|
|
653
682
|
msg += diag.messageText;
|
|
654
683
|
log(color, prefix, msg);
|
|
655
684
|
};
|
|
656
|
-
|
|
657
685
|
//#endregion
|
|
658
686
|
//#region src/client/status.ts
|
|
659
687
|
/**
|
|
@@ -755,20 +783,20 @@ const initBuildProgress = (data) => {
|
|
|
755
783
|
clearTimeout(opacityTimerId);
|
|
756
784
|
clearTimeout(addBarTimerId);
|
|
757
785
|
clearTimeout(removeBarTimerId);
|
|
758
|
-
|
|
786
|
+
let progressBar = getProgressBar();
|
|
759
787
|
if (progressBar) {
|
|
760
788
|
if (currentProgress >= 1) progressBar.style.transform = `scaleX(1)`;
|
|
761
789
|
opacityTimerId = setTimeout(() => {
|
|
762
790
|
try {
|
|
763
|
-
|
|
791
|
+
progressBar = getProgressBar();
|
|
764
792
|
if (progressBar) progressBar.style.opacity = `0`;
|
|
765
|
-
} catch
|
|
793
|
+
} catch {}
|
|
766
794
|
}, 150);
|
|
767
795
|
removeBarTimerId = setTimeout(() => {
|
|
768
796
|
try {
|
|
769
|
-
|
|
797
|
+
progressBar = getProgressBar();
|
|
770
798
|
if (progressBar?.parentNode) progressBar.parentNode.removeChild(progressBar);
|
|
771
|
-
} catch
|
|
799
|
+
} catch {}
|
|
772
800
|
}, 1e3);
|
|
773
801
|
}
|
|
774
802
|
}
|
|
@@ -817,7 +845,6 @@ const initBuildProgress = (data) => {
|
|
|
817
845
|
doc.body.appendChild(progressBar);
|
|
818
846
|
}
|
|
819
847
|
};
|
|
820
|
-
|
|
821
848
|
//#endregion
|
|
822
849
|
//#region src/client/websocket.ts
|
|
823
850
|
/**
|
|
@@ -836,7 +863,7 @@ const initClientWebSocket = (win, config) => {
|
|
|
836
863
|
buildResultsRequests++;
|
|
837
864
|
if (!hasGottenBuildResults && this.readyState === WebSocket.OPEN && buildResultsRequests < 500) this.send(JSON.stringify({ requestBuildResults: true }));
|
|
838
865
|
else if (requestBuildResultsTmrId) clearInterval(requestBuildResultsTmrId);
|
|
839
|
-
},
|
|
866
|
+
}, 500);
|
|
840
867
|
if (reconnectTmrId) clearTimeout(reconnectTmrId);
|
|
841
868
|
}
|
|
842
869
|
function onError() {
|
|
@@ -844,7 +871,7 @@ const initClientWebSocket = (win, config) => {
|
|
|
844
871
|
}
|
|
845
872
|
function onClose(event) {
|
|
846
873
|
emitBuildStatus(win, "disabled");
|
|
847
|
-
if (event.code >
|
|
874
|
+
if (event.code > 1e3) logWarn("Dev Server", `web socket closed: ${event.code} ${event.reason}`);
|
|
848
875
|
else logDisabled("Dev Server", "Disconnected, attempting to reconnect...");
|
|
849
876
|
queueReconnect();
|
|
850
877
|
}
|
|
@@ -894,7 +921,7 @@ const initClientWebSocket = (win, config) => {
|
|
|
894
921
|
clientWs = null;
|
|
895
922
|
}
|
|
896
923
|
if (reconnectTmrId) clearTimeout(reconnectTmrId);
|
|
897
|
-
if (reconnectAttempts >=
|
|
924
|
+
if (reconnectAttempts >= 1e3) logWarn("Dev Server", "Canceling reconnect attempts");
|
|
898
925
|
else {
|
|
899
926
|
reconnectAttempts++;
|
|
900
927
|
reconnectTmrId = setTimeout(connect, RECONNECT_RETRY_MS);
|
|
@@ -903,37 +930,52 @@ const initClientWebSocket = (win, config) => {
|
|
|
903
930
|
}
|
|
904
931
|
connect();
|
|
905
932
|
};
|
|
906
|
-
|
|
907
933
|
//#endregion
|
|
908
934
|
//#region src/client/index.ts
|
|
909
935
|
/**
|
|
910
|
-
*
|
|
936
|
+
* Stencil Dev Server Client
|
|
911
937
|
*
|
|
912
938
|
* Browser-side HMR (Hot Module Replacement) client for Stencil dev server.
|
|
913
939
|
* Handles WebSocket communication, component updates, style updates, and image updates.
|
|
914
940
|
*
|
|
915
941
|
* This module runs in the browser and is injected into pages during development.
|
|
942
|
+
* @module @stencil/dev-server/client
|
|
943
|
+
*/
|
|
944
|
+
/**
|
|
945
|
+
* Initialize the app update handler for build results.
|
|
946
|
+
*
|
|
947
|
+
* @param win - the dev client window object
|
|
948
|
+
* @param config - the dev client configuration
|
|
916
949
|
*/
|
|
917
950
|
const initAppUpdate = (win, config) => {
|
|
918
951
|
onBuildResults(win, (buildResults) => {
|
|
919
952
|
appUpdate(win, config, buildResults);
|
|
920
953
|
});
|
|
921
954
|
};
|
|
955
|
+
/**
|
|
956
|
+
* Process app update based on build results.
|
|
957
|
+
*
|
|
958
|
+
* @param win - the dev client window object
|
|
959
|
+
* @param config - the dev client configuration
|
|
960
|
+
* @param buildResults - the compiler build results
|
|
961
|
+
*/
|
|
922
962
|
const appUpdate = (win, config, buildResults) => {
|
|
923
963
|
try {
|
|
924
964
|
if (buildResults.buildId === win["s-build-id"]) return;
|
|
925
965
|
win["s-build-id"] = buildResults.buildId;
|
|
926
966
|
clearAppErrorModal({ window: win });
|
|
927
967
|
if (buildResults.hasError) {
|
|
968
|
+
const hasEditors = Array.isArray(config.editors) && config.editors.length > 0;
|
|
928
969
|
const errorResults = appError({
|
|
929
970
|
window: win,
|
|
930
971
|
buildResults,
|
|
931
|
-
openInEditor:
|
|
932
|
-
const
|
|
972
|
+
openInEditor: hasEditors ? (data) => {
|
|
973
|
+
const params = new URLSearchParams({
|
|
933
974
|
file: data.file,
|
|
934
975
|
line: String(data.line),
|
|
935
976
|
column: String(data.column)
|
|
936
|
-
})
|
|
977
|
+
});
|
|
978
|
+
const url = `${OPEN_IN_EDITOR_URL}?${params.toString()}`;
|
|
937
979
|
win.fetch(url).catch((err) => {
|
|
938
980
|
console.error("Failed to open in editor:", err);
|
|
939
981
|
});
|
|
@@ -959,6 +1001,12 @@ const appUpdate = (win, config, buildResults) => {
|
|
|
959
1001
|
console.error(e);
|
|
960
1002
|
}
|
|
961
1003
|
};
|
|
1004
|
+
/**
|
|
1005
|
+
* Apply hot module replacement updates to the window.
|
|
1006
|
+
*
|
|
1007
|
+
* @param win - the browser window
|
|
1008
|
+
* @param hmr - the hot module replacement data
|
|
1009
|
+
*/
|
|
962
1010
|
const appHmr = (win, hmr) => {
|
|
963
1011
|
let shouldWindowReload = false;
|
|
964
1012
|
if (hmr.reloadStrategy === "pageReload") shouldWindowReload = true;
|
|
@@ -992,9 +1040,17 @@ const appHmr = (win, hmr) => {
|
|
|
992
1040
|
});
|
|
993
1041
|
if (results.updatedComponents.length > 0) logBuild(`Updated component${results.updatedComponents.length > 1 ? "s" : ""}: ${results.updatedComponents.join(", ")}`);
|
|
994
1042
|
if (results.updatedInlineStyles.length > 0) logBuild(`Updated styles: ${results.updatedInlineStyles.join(", ")}`);
|
|
1043
|
+
if (results.updatedGlobalStyles.length > 0) logBuild(`Updated global styles: ${results.updatedGlobalStyles.join(", ")}`);
|
|
995
1044
|
if (results.updatedExternalStyles.length > 0) logBuild(`Updated stylesheets: ${results.updatedExternalStyles.join(", ")}`);
|
|
996
1045
|
if (results.updatedImages.length > 0) logBuild(`Updated images: ${results.updatedImages.join(", ")}`);
|
|
997
1046
|
};
|
|
1047
|
+
/**
|
|
1048
|
+
* Reset the app state and unregister service workers.
|
|
1049
|
+
*
|
|
1050
|
+
* @param win - the dev client window object
|
|
1051
|
+
* @param config - the dev client configuration
|
|
1052
|
+
* @param cb - callback to invoke after reset
|
|
1053
|
+
*/
|
|
998
1054
|
const appReset = (win, config, cb) => {
|
|
999
1055
|
win.history.replaceState({}, "App", config.basePath);
|
|
1000
1056
|
if (!win.navigator.serviceWorker?.getRegistration) cb();
|
|
@@ -1009,6 +1065,12 @@ const appReset = (win, config, cb) => {
|
|
|
1009
1065
|
cb();
|
|
1010
1066
|
});
|
|
1011
1067
|
};
|
|
1068
|
+
/**
|
|
1069
|
+
* Initialize the dev server client in the browser.
|
|
1070
|
+
*
|
|
1071
|
+
* @param win - the dev client window object
|
|
1072
|
+
* @param config - the dev client configuration
|
|
1073
|
+
*/
|
|
1012
1074
|
const initDevClient = (win, config) => {
|
|
1013
1075
|
try {
|
|
1014
1076
|
if (win["s-dev-server"]) return;
|
|
@@ -1027,6 +1089,13 @@ const initDevClient = (win, config) => {
|
|
|
1027
1089
|
console.error(e);
|
|
1028
1090
|
}
|
|
1029
1091
|
};
|
|
1092
|
+
/**
|
|
1093
|
+
* Check if this is the initial dev server load.
|
|
1094
|
+
*
|
|
1095
|
+
* @param win - the dev client window object
|
|
1096
|
+
* @param config - the dev client configuration
|
|
1097
|
+
* @returns true if this is the initial load
|
|
1098
|
+
*/
|
|
1030
1099
|
const isInitialDevServerLoad = (win, config) => {
|
|
1031
1100
|
let pathname = win.location.pathname;
|
|
1032
1101
|
pathname = "/" + pathname.substring(config.basePath.length);
|
|
@@ -1045,6 +1114,5 @@ if (typeof appWindow !== "undefined" && typeof config !== "undefined") {
|
|
|
1045
1114
|
...config
|
|
1046
1115
|
});
|
|
1047
1116
|
}
|
|
1048
|
-
|
|
1049
1117
|
//#endregion
|
|
1050
|
-
export { BUILD_LOG, BUILD_RESULTS, BUILD_STATUS, DEV_SERVER_INIT_URL, DEV_SERVER_URL, NODE_TYPE_DOCUMENT_FRAGMENT, NODE_TYPE_ELEMENT, NORMAL_CLOSURE_CODE, OPEN_IN_EDITOR_URL, 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 };
|
|
1118
|
+
export { BUILD_LOG, BUILD_RESULTS, BUILD_STATUS, DEV_SERVER_INIT_URL, DEV_SERVER_URL, NODE_TYPE_DOCUMENT_FRAGMENT, NODE_TYPE_ELEMENT, NORMAL_CLOSURE_CODE, OPEN_IN_EDITOR_URL, 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 };
|