@stencil/dev-server 5.0.0-alpha.9 → 5.0.0-beta.1
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 +0 -1
- package/dist/client/index.js +7 -7
- package/dist/index.d.mts +0 -1
- package/dist/index.mjs +63 -27
- package/package.json +10 -11
- /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
package/dist/client/index.js
CHANGED
|
@@ -16,7 +16,7 @@ const NORMAL_CLOSURE_CODE = 1e3;
|
|
|
16
16
|
const REQUEST_BUILD_RESULTS_INTERVAL_MS = 500;
|
|
17
17
|
//#endregion
|
|
18
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
|
|
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";
|
|
20
20
|
//#endregion
|
|
21
21
|
//#region src/client/error.ts
|
|
22
22
|
let errorCount = 0;
|
|
@@ -396,9 +396,7 @@ const hmrStyleSheetImages = (cssImageProps, styleSheet, versionId, imageFileName
|
|
|
396
396
|
case CSSRule.STYLE_RULE:
|
|
397
397
|
hmrStyleSheetRuleImages(cssImageProps, cssRule, versionId, imageFileNames);
|
|
398
398
|
break;
|
|
399
|
-
case CSSRule.MEDIA_RULE:
|
|
400
|
-
hmrStyleSheetImages(cssImageProps, cssRule, versionId, imageFileNames);
|
|
401
|
-
break;
|
|
399
|
+
case CSSRule.MEDIA_RULE: hmrStyleSheetImages(cssImageProps, cssRule, versionId, imageFileNames);
|
|
402
400
|
}
|
|
403
401
|
}
|
|
404
402
|
} catch (e) {
|
|
@@ -928,15 +926,17 @@ const appUpdate = (win, config, buildResults) => {
|
|
|
928
926
|
win["s-build-id"] = buildResults.buildId;
|
|
929
927
|
clearAppErrorModal({ window: win });
|
|
930
928
|
if (buildResults.hasError) {
|
|
929
|
+
const hasEditors = Array.isArray(config.editors) && config.editors.length > 0;
|
|
931
930
|
const errorResults = appError({
|
|
932
931
|
window: win,
|
|
933
932
|
buildResults,
|
|
934
|
-
openInEditor:
|
|
935
|
-
const
|
|
933
|
+
openInEditor: hasEditors ? (data) => {
|
|
934
|
+
const params = new URLSearchParams({
|
|
936
935
|
file: data.file,
|
|
937
936
|
line: String(data.line),
|
|
938
937
|
column: String(data.column)
|
|
939
|
-
})
|
|
938
|
+
});
|
|
939
|
+
const url = `${OPEN_IN_EDITOR_URL}?${params.toString()}`;
|
|
940
940
|
win.fetch(url).catch((err) => {
|
|
941
941
|
console.error("Failed to open in editor:", err);
|
|
942
942
|
});
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { CompilerBuildResults, CompilerRequestResponse, CompilerWatcher, DevServer, DevServerConfig, DevServerConfig as DevServerConfig$1, Logger, StencilDevServerConfig } from "@stencil/core/compiler";
|
|
2
|
-
|
|
3
2
|
//#region src/server/types.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Internal dev server message protocol for communication between
|
package/dist/index.mjs
CHANGED
|
@@ -544,8 +544,11 @@ const generateDevPreview = (buildResults, filterDirPath) => {
|
|
|
544
544
|
h1 { font-size: 1rem; font-weight: 500; margin: 0 0 2rem; color: color-mix(in oklab, CanvasText 90%, Canvas 10%); }
|
|
545
545
|
.component { border: 1px solid color-mix(in oklab, CanvasText 20%, Canvas 80%); border-radius: 6px; margin-bottom: 1.5rem; overflow: hidden; }
|
|
546
546
|
.component-header { padding: 0.5rem 1rem; background: color-mix(in oklab, CanvasText 5%, Canvas 95%); font-family: monospace; font-size: 0.875rem; }
|
|
547
|
+
.component-description { margin: 0; padding: 0.75rem 1rem 0; font-size: 0.875rem; color: color-mix(in oklab, CanvasText 70%, Canvas 30%); }
|
|
547
548
|
.component-preview { padding: 1.5rem; }
|
|
548
549
|
.component-preview + .component-preview { border-top: 1px dashed color-mix(in oklab, CanvasText 20%, Canvas 80%); }
|
|
550
|
+
.preview-note { margin: 0.75rem 0 0; font-size: 0.8125rem; color: color-mix(in oklab, CanvasText 50%, Canvas 50%); }
|
|
551
|
+
.preview-note code { font-size: 0.8125rem; }
|
|
549
552
|
</style>
|
|
550
553
|
${[loaderUrl ? ` <script type="module" src="${loaderUrl}"><\/script>` : "", ...globalCssUrls.map((url) => ` <link rel="stylesheet" href="${url}">`)].filter(Boolean).join("\n")}
|
|
551
554
|
</head>
|
|
@@ -557,12 +560,17 @@ ${sections.join("\n")}
|
|
|
557
560
|
};
|
|
558
561
|
const renderComponentSection = (component) => {
|
|
559
562
|
const snippets = getUsageSnippets(component);
|
|
560
|
-
const previews = snippets.length > 0 ? snippets.map((html) => ` <div class="component-preview">\n ${html}\n </div>`).join("\n") : ` <div class="component-preview"
|
|
563
|
+
const previews = snippets.length > 0 ? snippets.map((html) => ` <div class="component-preview">\n ${html}\n </div>`).join("\n") : ` <div class="component-preview">
|
|
564
|
+
<${component.tagName}></${component.tagName}>
|
|
565
|
+
<p class="preview-note">No demos found - add usage examples to <code>usage/*.md</code> (fenced ```html``` blocks) to customize this preview.</p>
|
|
566
|
+
</div>`;
|
|
567
|
+
const description = component.docs.text.trim() ? `\n <p class="component-description">${escapeHtml(component.docs.text.trim())}</p>` : "";
|
|
561
568
|
return ` <div class="component">
|
|
562
|
-
<div class="component-header"><${component.tagName}></div
|
|
569
|
+
<div class="component-header"><${component.tagName}></div>${description}
|
|
563
570
|
${previews}
|
|
564
571
|
</div>`;
|
|
565
572
|
};
|
|
573
|
+
const escapeHtml = (unsafe) => unsafe.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
566
574
|
const getUsageSnippets = (component) => {
|
|
567
575
|
const usageDir = path.join(path.dirname(component.sourceFilePath), "usage");
|
|
568
576
|
try {
|
|
@@ -975,11 +983,14 @@ function updateStyleUrls(url, oldCss) {
|
|
|
975
983
|
return newCss;
|
|
976
984
|
}
|
|
977
985
|
function appendDevServerClientScript(devServerConfig, req, content) {
|
|
978
|
-
|
|
986
|
+
const devServerClientUrl = getDevServerClientUrl(devServerConfig, req.headers?.["x-forwarded-host"] ?? req.host, req.headers?.["x-forwarded-proto"]);
|
|
987
|
+
return appendDevServerClientIframe(content, `<iframe title="Stencil Dev Server Connector ${VERSION} ⚡" src="${devServerClientUrl}" style="display:block;width:0;height:0;border:0;visibility:hidden" aria-hidden="true"></iframe>`);
|
|
979
988
|
}
|
|
980
989
|
function appendDevServerClientIframe(content, iframe) {
|
|
981
|
-
|
|
982
|
-
if (
|
|
990
|
+
const bodyIndex = content.lastIndexOf("</body>");
|
|
991
|
+
if (bodyIndex !== -1) return content.slice(0, bodyIndex) + iframe + content.slice(bodyIndex);
|
|
992
|
+
const htmlIndex = content.lastIndexOf("</html>");
|
|
993
|
+
if (htmlIndex !== -1) return content.slice(0, htmlIndex) + iframe + content.slice(htmlIndex);
|
|
983
994
|
return `${content}${iframe}`;
|
|
984
995
|
}
|
|
985
996
|
async function serveDevClient(devServerConfig, serverCtx, req, res) {
|
|
@@ -1052,9 +1063,7 @@ async function serveDirectoryIndex(devServerConfig, serverCtx, req, res) {
|
|
|
1052
1063
|
if (!req.pathname.endsWith("/")) return serverCtx.serve302(req, res, req.pathname + "/");
|
|
1053
1064
|
try {
|
|
1054
1065
|
const dirFilePaths = await serverCtx.sys.readDir(req.filePath);
|
|
1055
|
-
|
|
1056
|
-
const hasHtml = dirFilePaths.some((f) => f.endsWith(".html") || f.endsWith(".htm"));
|
|
1057
|
-
if (hasTsx && !hasHtml) return serveDevPreview(devServerConfig, serverCtx, req, res, req.filePath);
|
|
1066
|
+
if (dirFilePaths.some((f) => f.endsWith(".tsx")) && !await hasNestedHtmlFile(serverCtx.sys, dirFilePaths)) return serveDevPreview(devServerConfig, serverCtx, req, res, req.filePath);
|
|
1058
1067
|
if (req.pathname === "/" || req.pathname === devServerConfig.basePath) {
|
|
1059
1068
|
const srcPath = path.join(req.filePath, "src");
|
|
1060
1069
|
try {
|
|
@@ -1082,9 +1091,28 @@ async function serveDirectoryIndex(devServerConfig, serverCtx, req, res) {
|
|
|
1082
1091
|
return serverCtx.serve404(req, res, "serveDirectoryIndex");
|
|
1083
1092
|
}
|
|
1084
1093
|
}
|
|
1094
|
+
/**
|
|
1095
|
+
* Recursively checks a directory (and its subdirectories) for any .html/.htm file.
|
|
1096
|
+
* Used to decide whether the auto-generated component preview should be shown, or
|
|
1097
|
+
* the default file-listing view (since a nested html file likely means a custom
|
|
1098
|
+
* preview/demo page already exists somewhere in the tree).
|
|
1099
|
+
* @param sys The dev server's compiler system, used to read directories and stat files.
|
|
1100
|
+
* @param dirFilePaths The full paths of entries in the directory to check.
|
|
1101
|
+
* @returns true if an html file exists at this level or in any subdirectory.
|
|
1102
|
+
*/
|
|
1103
|
+
async function hasNestedHtmlFile(sys, dirFilePaths) {
|
|
1104
|
+
const subDirPaths = [];
|
|
1105
|
+
for (const filePath of dirFilePaths) {
|
|
1106
|
+
if (filePath.endsWith(".html") || filePath.endsWith(".htm")) return true;
|
|
1107
|
+
if ((await sys.stat(filePath)).isDirectory) subDirPaths.push(filePath);
|
|
1108
|
+
}
|
|
1109
|
+
for (const subDirPath of subDirPaths) if (await hasNestedHtmlFile(sys, await sys.readDir(subDirPath))) return true;
|
|
1110
|
+
return false;
|
|
1111
|
+
}
|
|
1085
1112
|
async function serveDevPreview(devServerConfig, serverCtx, req, res, filterDirPath) {
|
|
1086
1113
|
try {
|
|
1087
|
-
const
|
|
1114
|
+
const buildResults = await serverCtx.getBuildResults();
|
|
1115
|
+
const html = appendDevServerClientScript(devServerConfig, req, generateDevPreview(buildResults, filterDirPath));
|
|
1088
1116
|
const buf = Buffer.from(html, "utf-8");
|
|
1089
1117
|
serverCtx.logRequest(req, 200);
|
|
1090
1118
|
res.writeHead(200, responseHeaders({
|
|
@@ -1305,7 +1333,8 @@ function initServerProcess(sendMsg) {
|
|
|
1305
1333
|
* @returns Function to send messages from main to worker process
|
|
1306
1334
|
*/
|
|
1307
1335
|
function initServerProcessWorkerProxy(sendToMain) {
|
|
1308
|
-
|
|
1336
|
+
const workerPath = path.join(import.meta.dirname, "worker-thread.js");
|
|
1337
|
+
const forkOpts = {
|
|
1309
1338
|
execArgv: process.execArgv.filter((v) => !/^--(debug|inspect)/.test(v)),
|
|
1310
1339
|
env: process.env,
|
|
1311
1340
|
cwd: process.cwd(),
|
|
@@ -1315,7 +1344,8 @@ function initServerProcessWorkerProxy(sendToMain) {
|
|
|
1315
1344
|
"pipe",
|
|
1316
1345
|
"ipc"
|
|
1317
1346
|
]
|
|
1318
|
-
}
|
|
1347
|
+
};
|
|
1348
|
+
let serverProcess = fork(workerPath, [], forkOpts);
|
|
1319
1349
|
/**
|
|
1320
1350
|
* Send a message from main to the worker process
|
|
1321
1351
|
*
|
|
@@ -1466,27 +1496,33 @@ function startServer(devServerConfig, logger, watcher, initServerProcessFn, reso
|
|
|
1466
1496
|
resolve(devServer);
|
|
1467
1497
|
};
|
|
1468
1498
|
const requestLog = (msg) => {
|
|
1469
|
-
if (devServerConfig.logRequests && msg.requestLog)
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1499
|
+
if (devServerConfig.logRequests && msg.requestLog) {
|
|
1500
|
+
if (msg.requestLog.status >= 500) logger.info(logger.red(`${msg.requestLog.method} ${msg.requestLog.url} (${msg.requestLog.status})`));
|
|
1501
|
+
else if (msg.requestLog.status >= 400) logger.info(logger.dim(logger.red(`${msg.requestLog.method} ${msg.requestLog.url} (${msg.requestLog.status})`)));
|
|
1502
|
+
else if (msg.requestLog.status >= 300) logger.info(logger.dim(logger.magenta(`${msg.requestLog.method} ${msg.requestLog.url} (${msg.requestLog.status})`)));
|
|
1503
|
+
else logger.info(logger.dim(`${logger.cyan(msg.requestLog.method)} ${msg.requestLog.url}`));
|
|
1504
|
+
}
|
|
1473
1505
|
};
|
|
1474
1506
|
const serverError = async (msg) => {
|
|
1475
|
-
if (msg.error)
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1507
|
+
if (msg.error) {
|
|
1508
|
+
if (hasStarted) logger.error(msg.error.message + " " + msg.error.stack);
|
|
1509
|
+
else {
|
|
1510
|
+
await close();
|
|
1511
|
+
reject(msg.error.message);
|
|
1512
|
+
}
|
|
1479
1513
|
}
|
|
1480
1514
|
};
|
|
1481
1515
|
const requestBuildResults = () => {
|
|
1482
|
-
if (sendToServer)
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1516
|
+
if (sendToServer) {
|
|
1517
|
+
if (lastBuildResults != null) {
|
|
1518
|
+
const msg = {
|
|
1519
|
+
buildResults: { ...lastBuildResults },
|
|
1520
|
+
isActivelyBuilding
|
|
1521
|
+
};
|
|
1522
|
+
delete msg.buildResults.hmr;
|
|
1523
|
+
sendToServer(msg);
|
|
1524
|
+
} else sendToServer({ isActivelyBuilding: true });
|
|
1525
|
+
}
|
|
1490
1526
|
};
|
|
1491
1527
|
const compilerRequest = async (compilerRequestPath) => {
|
|
1492
1528
|
if (watcher?.request && sendToServer) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stencil/dev-server",
|
|
3
|
-
"version": "5.0.0-
|
|
3
|
+
"version": "5.0.0-beta.1",
|
|
4
4
|
"description": "Development server for Stencil with DOM-based HMR",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dev server",
|
|
@@ -35,21 +35,20 @@
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"launch-editor": "^2.
|
|
38
|
+
"launch-editor": "^2.14.1",
|
|
39
39
|
"open": "^11.0.0",
|
|
40
|
-
"ws": "^8.
|
|
40
|
+
"ws": "^8.21.3"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@tsdown/css": "
|
|
44
|
-
"@types/ws": "^8.
|
|
45
|
-
"tsdown": "
|
|
46
|
-
"typescript": ">
|
|
47
|
-
"vitest": "^4.1.
|
|
48
|
-
"vitest-environment-stencil": "^1.
|
|
49
|
-
"@stencil/core": "5.0.0-alpha.9"
|
|
43
|
+
"@tsdown/css": "^0.22.14",
|
|
44
|
+
"@types/ws": "^8.18.1",
|
|
45
|
+
"tsdown": "^0.22.14",
|
|
46
|
+
"typescript": ">5.0.0 <7.0.0",
|
|
47
|
+
"vitest": "^4.1.10",
|
|
48
|
+
"vitest-environment-stencil": "^1.14.0"
|
|
50
49
|
},
|
|
51
50
|
"peerDependencies": {
|
|
52
|
-
"@stencil/core": "^5.0.0-
|
|
51
|
+
"@stencil/core": "^5.0.0 || 5.0.0-beta.1"
|
|
53
52
|
},
|
|
54
53
|
"volta": {
|
|
55
54
|
"extends": "../../package.json"
|
/package/{LICENSE.md → LICENSE}
RENAMED
|
File without changes
|