@foliwake/cli 0.0.0-stage → 0.7.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/CHANGELOG.md +56 -0
- package/LICENSE +202 -0
- package/README.md +654 -2
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +9 -0
- package/dist/command-words.d.ts +13 -0
- package/dist/command-words.js +53 -0
- package/dist/commands/account/keys/create.d.ts +12 -0
- package/dist/commands/account/keys/create.js +36 -0
- package/dist/commands/account/keys/list.d.ts +9 -0
- package/dist/commands/account/keys/list.js +23 -0
- package/dist/commands/account/keys/revoke.d.ts +12 -0
- package/dist/commands/account/keys/revoke.js +15 -0
- package/dist/commands/branch/bootstrap.d.ts +11 -0
- package/dist/commands/branch/bootstrap.js +23 -0
- package/dist/commands/branch/delete.d.ts +17 -0
- package/dist/commands/branch/delete.js +38 -0
- package/dist/commands/branch/history.d.ts +14 -0
- package/dist/commands/branch/history.js +24 -0
- package/dist/commands/branch/list.d.ts +11 -0
- package/dist/commands/branch/list.js +15 -0
- package/dist/commands/branch/update.d.ts +19 -0
- package/dist/commands/branch/update.js +49 -0
- package/dist/commands/code/deploy.d.ts +15 -0
- package/dist/commands/code/deploy.js +78 -0
- package/dist/commands/code/prepare.d.ts +13 -0
- package/dist/commands/code/prepare.js +54 -0
- package/dist/commands/code/release.d.ts +19 -0
- package/dist/commands/code/release.js +51 -0
- package/dist/commands/code/rollback.d.ts +17 -0
- package/dist/commands/code/rollback.js +38 -0
- package/dist/commands/connect.d.ts +19 -0
- package/dist/commands/connect.js +100 -0
- package/dist/commands/create.d.ts +32 -0
- package/dist/commands/create.js +171 -0
- package/dist/commands/credential/list.d.ts +10 -0
- package/dist/commands/credential/list.js +21 -0
- package/dist/commands/credential/rm.d.ts +12 -0
- package/dist/commands/credential/rm.js +18 -0
- package/dist/commands/credential/set.d.ts +15 -0
- package/dist/commands/credential/set.js +58 -0
- package/dist/commands/dev.d.ts +30 -0
- package/dist/commands/dev.js +144 -0
- package/dist/commands/login.d.ts +20 -0
- package/dist/commands/login.js +94 -0
- package/dist/commands/logout.d.ts +14 -0
- package/dist/commands/logout.js +61 -0
- package/dist/commands/migration/commit.d.ts +13 -0
- package/dist/commands/migration/commit.js +42 -0
- package/dist/commands/migration/prepare.d.ts +18 -0
- package/dist/commands/migration/prepare.js +53 -0
- package/dist/commands/operation/cancel.d.ts +14 -0
- package/dist/commands/operation/cancel.js +21 -0
- package/dist/commands/operation/get.d.ts +14 -0
- package/dist/commands/operation/get.js +26 -0
- package/dist/commands/operation/list.d.ts +12 -0
- package/dist/commands/operation/list.js +25 -0
- package/dist/commands/operation/recover.d.ts +20 -0
- package/dist/commands/operation/recover.js +61 -0
- package/dist/commands/page/changes.d.ts +13 -0
- package/dist/commands/page/changes.js +26 -0
- package/dist/commands/page/check.d.ts +12 -0
- package/dist/commands/page/check.js +25 -0
- package/dist/commands/page/replace.d.ts +13 -0
- package/dist/commands/page/replace.js +59 -0
- package/dist/commands/page/unpreview.d.ts +17 -0
- package/dist/commands/page/unpreview.js +54 -0
- package/dist/commands/page/unpublish.d.ts +18 -0
- package/dist/commands/page/unpublish.js +36 -0
- package/dist/commands/project/preview.d.ts +8 -0
- package/dist/commands/project/preview.js +20 -0
- package/dist/commands/project/publish.d.ts +16 -0
- package/dist/commands/project/publish.js +40 -0
- package/dist/commands/project/unpublish.d.ts +16 -0
- package/dist/commands/project/unpublish.js +33 -0
- package/dist/commands/release/rollback.d.ts +17 -0
- package/dist/commands/release/rollback.js +38 -0
- package/dist/commands/servers/index.d.ts +20 -0
- package/dist/commands/servers/index.js +36 -0
- package/dist/commands/servers/use.d.ts +11 -0
- package/dist/commands/servers/use.js +30 -0
- package/dist/commands/site/adopt.d.ts +11 -0
- package/dist/commands/site/adopt.js +21 -0
- package/dist/commands/site/create.d.ts +18 -0
- package/dist/commands/site/create.js +61 -0
- package/dist/commands/site/edit.d.ts +11 -0
- package/dist/commands/site/edit.js +56 -0
- package/dist/commands/site/history.d.ts +11 -0
- package/dist/commands/site/history.js +25 -0
- package/dist/commands/site/link.d.ts +15 -0
- package/dist/commands/site/link.js +35 -0
- package/dist/commands/site/list.d.ts +9 -0
- package/dist/commands/site/list.js +29 -0
- package/dist/commands/site/reset-storage.d.ts +15 -0
- package/dist/commands/site/reset-storage.js +61 -0
- package/dist/commands/site/set.d.ts +16 -0
- package/dist/commands/site/set.js +45 -0
- package/dist/commands/site/show.d.ts +10 -0
- package/dist/commands/site/show.js +19 -0
- package/dist/commands/site/status.d.ts +11 -0
- package/dist/commands/site/status.js +15 -0
- package/dist/commands/site/unlink.d.ts +11 -0
- package/dist/commands/site/unlink.js +28 -0
- package/dist/commands/source/add.d.ts +32 -0
- package/dist/commands/source/add.js +103 -0
- package/dist/commands/source/adopt-pages.d.ts +14 -0
- package/dist/commands/source/adopt-pages.js +30 -0
- package/dist/commands/source/check.d.ts +17 -0
- package/dist/commands/source/check.js +52 -0
- package/dist/commands/source/list.d.ts +11 -0
- package/dist/commands/source/list.js +15 -0
- package/dist/commands/source/mappings/check.d.ts +13 -0
- package/dist/commands/source/mappings/check.js +69 -0
- package/dist/commands/source/pending.d.ts +12 -0
- package/dist/commands/source/pending.js +25 -0
- package/dist/commands/source/plugins.d.ts +6 -0
- package/dist/commands/source/plugins.js +17 -0
- package/dist/commands/source/sync.d.ts +16 -0
- package/dist/commands/source/sync.js +58 -0
- package/dist/commands/whoami.d.ts +6 -0
- package/dist/commands/whoami.js +22 -0
- package/dist/connect-prompts.d.ts +16 -0
- package/dist/connect-prompts.js +24 -0
- package/dist/connect.d.ts +133 -0
- package/dist/connect.js +416 -0
- package/dist/core-command.d.ts +99 -0
- package/dist/core-command.js +332 -0
- package/dist/core-types.d.ts +21 -0
- package/dist/core-types.js +1 -0
- package/dist/create-connect.d.ts +26 -0
- package/dist/create-connect.js +93 -0
- package/dist/dev/code-watcher.d.ts +66 -0
- package/dist/dev/code-watcher.js +254 -0
- package/dist/dev/dev-checks.d.ts +14 -0
- package/dist/dev/dev-checks.js +138 -0
- package/dist/dev/dev-reload.d.ts +51 -0
- package/dist/dev/dev-reload.js +345 -0
- package/dist/dev/flags.d.ts +19 -0
- package/dist/dev/flags.js +54 -0
- package/dist/dev/html.d.ts +30 -0
- package/dist/dev/html.js +106 -0
- package/dist/dev/kit-files.d.ts +7 -0
- package/dist/dev/kit-files.js +33 -0
- package/dist/dev/local-code.d.ts +22 -0
- package/dist/dev/local-code.js +101 -0
- package/dist/dev/remote-config.d.ts +57 -0
- package/dist/dev/remote-config.js +100 -0
- package/dist/dev/remote-dev.d.ts +41 -0
- package/dist/dev/remote-dev.js +527 -0
- package/dist/dev/remote-fetch.d.ts +5 -0
- package/dist/dev/remote-fetch.js +36 -0
- package/dist/dev/remote-html.d.ts +10 -0
- package/dist/dev/remote-html.js +60 -0
- package/dist/dev/remote-page.d.ts +34 -0
- package/dist/dev/remote-page.js +183 -0
- package/dist/dev/remote-routes.d.ts +63 -0
- package/dist/dev/remote-routes.js +114 -0
- package/dist/dev/signal-stop.d.ts +17 -0
- package/dist/dev/signal-stop.js +46 -0
- package/dist/dev/start.d.ts +18 -0
- package/dist/dev/start.js +80 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +8 -0
- package/dist/lib/diagnostics.d.ts +15 -0
- package/dist/lib/diagnostics.js +12 -0
- package/dist/lib/front-matter.d.ts +6 -0
- package/dist/lib/front-matter.js +59 -0
- package/dist/lib/operation-result.d.ts +3 -0
- package/dist/lib/operation-result.js +16 -0
- package/dist/lib/problem-groups.d.ts +27 -0
- package/dist/lib/problem-groups.js +49 -0
- package/dist/lib/problems.d.ts +50 -0
- package/dist/lib/problems.js +94 -0
- package/dist/lib/prompts.d.ts +38 -0
- package/dist/lib/prompts.js +77 -0
- package/dist/lib/result-types.d.ts +198 -0
- package/dist/lib/result-types.js +3 -0
- package/dist/lib/rules.d.ts +15 -0
- package/dist/lib/rules.js +26 -0
- package/dist/lib/summaries.d.ts +19 -0
- package/dist/lib/summaries.js +22 -0
- package/dist/lib/sync-problems.d.ts +21 -0
- package/dist/lib/sync-problems.js +19 -0
- package/dist/local-runtime.d.ts +78 -0
- package/dist/local-runtime.js +11 -0
- package/dist/local-target.d.ts +6 -0
- package/dist/local-target.js +23 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +40 -0
- package/dist/project-preview.d.ts +35 -0
- package/dist/project-preview.js +156 -0
- package/dist/project-publish.d.ts +28 -0
- package/dist/project-publish.js +173 -0
- package/dist/remote/connection.d.ts +8 -0
- package/dist/remote/connection.js +19 -0
- package/dist/remote/core-failure.d.ts +8 -0
- package/dist/remote/core-failure.js +15 -0
- package/dist/remote/credentials.d.ts +15 -0
- package/dist/remote/credentials.js +112 -0
- package/dist/remote/device-login.d.ts +33 -0
- package/dist/remote/device-login.js +161 -0
- package/dist/remote/remote-caller.d.ts +14 -0
- package/dist/remote/remote-caller.js +52 -0
- package/dist/remote/rpc-wire.d.ts +18 -0
- package/dist/remote/rpc-wire.js +57 -0
- package/dist/remote/servers.d.ts +80 -0
- package/dist/remote/servers.js +162 -0
- package/dist/remote/session.d.ts +53 -0
- package/dist/remote/session.js +132 -0
- package/dist/remote/sign-in-here.d.ts +5 -0
- package/dist/remote/sign-in-here.js +33 -0
- package/dist/remote/sign-in.d.ts +25 -0
- package/dist/remote/sign-in.js +55 -0
- package/dist/remote/wait-slices.d.ts +16 -0
- package/dist/remote/wait-slices.js +21 -0
- package/dist/render/add.d.ts +3 -0
- package/dist/render/add.js +9 -0
- package/dist/render/branch-write.d.ts +9 -0
- package/dist/render/branch-write.js +28 -0
- package/dist/render/branches.d.ts +5 -0
- package/dist/render/branches.js +28 -0
- package/dist/render/credentials.d.ts +5 -0
- package/dist/render/credentials.js +39 -0
- package/dist/render/operation-result.d.ts +16 -0
- package/dist/render/operation-result.js +65 -0
- package/dist/render/operation.d.ts +7 -0
- package/dist/render/operation.js +15 -0
- package/dist/render/page-changes.d.ts +3 -0
- package/dist/render/page-changes.js +36 -0
- package/dist/render/pending.d.ts +3 -0
- package/dist/render/pending.js +46 -0
- package/dist/render/plugin-list.d.ts +3 -0
- package/dist/render/plugin-list.js +30 -0
- package/dist/render/probe.d.ts +3 -0
- package/dist/render/probe.js +61 -0
- package/dist/render/problems.d.ts +35 -0
- package/dist/render/problems.js +64 -0
- package/dist/render/recovery.d.ts +2 -0
- package/dist/render/recovery.js +36 -0
- package/dist/render/reset-storage.d.ts +4 -0
- package/dist/render/reset-storage.js +70 -0
- package/dist/render/site-status.d.ts +2 -0
- package/dist/render/site-status.js +81 -0
- package/dist/render/source-list.d.ts +2 -0
- package/dist/render/source-list.js +37 -0
- package/dist/render/sync.d.ts +5 -0
- package/dist/render/sync.js +66 -0
- package/dist/settings.d.ts +10 -0
- package/dist/settings.js +45 -0
- package/dist/site-entry-edit.d.ts +5 -0
- package/dist/site-entry-edit.js +44 -0
- package/dist/source-entry.d.ts +32 -0
- package/dist/source-entry.js +89 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.js +10 -0
- package/package.json +112 -3
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
// Watches the local frontend code of `foliwake dev --watch`: components/,
|
|
2
|
+
// scripts/ and styles/ under the code root (the same directories the dev
|
|
3
|
+
// server serves). Local files only: nothing here reads the network or the
|
|
4
|
+
// store.
|
|
5
|
+
//
|
|
6
|
+
// Change detection is Chokidar 6 (exact pin). Foliwake chooses its backend
|
|
7
|
+
// (resolveWatchPolling): stat polling on macOS, native fs.watch events
|
|
8
|
+
// elsewhere, with an explicit override. What is reported stays ours: the
|
|
9
|
+
// cwd-relative posix paths whose content (SHA-256) appeared, changed or
|
|
10
|
+
// disappeared, so a touch, an identical rewrite or a duplicate event reports
|
|
11
|
+
// nothing, and the files present at start are the baseline.
|
|
12
|
+
import { createHash } from 'node:crypto';
|
|
13
|
+
import { readFile } from 'node:fs/promises';
|
|
14
|
+
import path from 'node:path';
|
|
15
|
+
import { watch as chokidarWatch } from 'chokidar';
|
|
16
|
+
import { CODE_FILE_EXTENSIONS } from '@foliwake/site-check/formats/code-files';
|
|
17
|
+
/** The code directories served (and watched) under the code root. */
|
|
18
|
+
export const CODE_DIRECTORIES = ['components', 'scripts', 'styles', 'templates'];
|
|
19
|
+
/** The file types served from them. */
|
|
20
|
+
export const CODE_EXTENSIONS = CODE_FILE_EXTENSIONS;
|
|
21
|
+
/** Default polling interval (ms) when polling is chosen. */
|
|
22
|
+
export const DEFAULT_CODE_POLLING_INTERVAL_MS = 1000;
|
|
23
|
+
const TRUE_VALUES = ['1', 'true', 'yes'];
|
|
24
|
+
const FALSE_VALUES = ['0', 'false', 'no'];
|
|
25
|
+
/** Chokidar 6's own reading of CHOKIDAR_USEPOLLING: 0/false off, any other non-empty value on. */
|
|
26
|
+
function chokidarEnvPolling(value) {
|
|
27
|
+
const lower = value.toLowerCase();
|
|
28
|
+
return lower === 'false' || lower === '0' ? false : lower !== '';
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Chooses polling or native events for the code watcher. Precedence (first that is set wins):
|
|
32
|
+
* 1. the command line: `dev --watch --watch-polling` / `--no-watch-polling`;
|
|
33
|
+
* 2. FOLIWAKE_WATCH_POLLING=1|true|yes or 0|false|no (any other value is ignored and reported);
|
|
34
|
+
* 3. CHOKIDAR_USEPOLLING (Chokidar's own variable; same reading as Chokidar);
|
|
35
|
+
* 4. the platform: polling on macOS (native directory events / FSEvents were measured silent
|
|
36
|
+
* on a development Mac), native events elsewhere (Linux measured; Windows not measured).
|
|
37
|
+
* The watcher is always created with this decision: createCodeWatcher hides CHOKIDAR_USEPOLLING
|
|
38
|
+
* and CHOKIDAR_INTERVAL from Chokidar, which would otherwise override it.
|
|
39
|
+
*/
|
|
40
|
+
export function resolveWatchPolling({ option, env = process.env, platform = process.platform, } = {}) {
|
|
41
|
+
const raw = env.FOLIWAKE_WATCH_POLLING;
|
|
42
|
+
const value = raw?.trim().toLowerCase();
|
|
43
|
+
const foliwake = value && TRUE_VALUES.includes(value) ? true : value && FALSE_VALUES.includes(value) ? false : undefined;
|
|
44
|
+
const invalid = value && foliwake === undefined ? raw : undefined;
|
|
45
|
+
const chokidarRaw = env.CHOKIDAR_USEPOLLING;
|
|
46
|
+
const chokidar = chokidarRaw === undefined ? undefined : chokidarEnvPolling(chokidarRaw);
|
|
47
|
+
const mode = (polling) => (polling ? 'polling' : 'native events');
|
|
48
|
+
const done = (usePolling, source, why, overridden) => ({
|
|
49
|
+
usePolling,
|
|
50
|
+
source,
|
|
51
|
+
description: `${mode(usePolling)} (${why}${overridden.length ? `; overrides ${overridden.join(', ')}` : ''})`,
|
|
52
|
+
overridden,
|
|
53
|
+
...(invalid === undefined ? {} : { invalid }),
|
|
54
|
+
});
|
|
55
|
+
const envOverridden = (...names) => names.filter(([, v]) => v !== undefined).map(([n]) => n);
|
|
56
|
+
if (option !== undefined) {
|
|
57
|
+
return done(option, 'option', option ? '--watch-polling' : '--no-watch-polling', envOverridden(['FOLIWAKE_WATCH_POLLING', foliwake], ['CHOKIDAR_USEPOLLING', chokidarRaw]));
|
|
58
|
+
}
|
|
59
|
+
if (foliwake !== undefined)
|
|
60
|
+
return done(foliwake, 'env', `FOLIWAKE_WATCH_POLLING=${raw}`, envOverridden(['CHOKIDAR_USEPOLLING', chokidarRaw]));
|
|
61
|
+
if (chokidar !== undefined)
|
|
62
|
+
return done(chokidar, 'chokidar-env', `CHOKIDAR_USEPOLLING=${chokidarRaw}`, []);
|
|
63
|
+
const usePolling = platform === 'darwin';
|
|
64
|
+
return done(usePolling, 'platform', usePolling
|
|
65
|
+
? 'macOS default; --no-watch-polling or FOLIWAKE_WATCH_POLLING=0 for native events'
|
|
66
|
+
: `${platform} default; --watch-polling or FOLIWAKE_WATCH_POLLING=1 to poll`, []);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Creates the Chokidar watcher with our decision only. Chokidar 6 reads CHOKIDAR_USEPOLLING and
|
|
70
|
+
* CHOKIDAR_INTERVAL synchronously in its constructor and lets them override code options; both are
|
|
71
|
+
* hidden from this process's environment for that synchronous call only (restored right after;
|
|
72
|
+
* the parent shell is never affected). Their effect is already part of resolveWatchPolling.
|
|
73
|
+
*/
|
|
74
|
+
function watchWithOurSettings(cwd, options) {
|
|
75
|
+
const saved = [];
|
|
76
|
+
for (const name of ['CHOKIDAR_USEPOLLING', 'CHOKIDAR_INTERVAL']) {
|
|
77
|
+
const value = process.env[name];
|
|
78
|
+
if (value !== undefined) {
|
|
79
|
+
saved.push([name, value]);
|
|
80
|
+
delete process.env[name];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
return chokidarWatch(cwd, options);
|
|
85
|
+
}
|
|
86
|
+
finally {
|
|
87
|
+
for (const [name, value] of saved)
|
|
88
|
+
process.env[name] = value;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/** A block's examples: `components/<name>/<name>.example.md`. */
|
|
92
|
+
function isExampleFile(relative) {
|
|
93
|
+
const match = /^components\/([a-z][a-z0-9-]*)\/([a-z][a-z0-9-]*)\.example\.md$/.exec(relative);
|
|
94
|
+
return match !== null && match[1] === match[2];
|
|
95
|
+
}
|
|
96
|
+
/** Whether a cwd-relative posix path is watched code (no dot segments, served extension) or a block example. */
|
|
97
|
+
export function isCodeFile(relative) {
|
|
98
|
+
const segments = relative.split('/');
|
|
99
|
+
if (segments.length < 2 || !CODE_DIRECTORIES.includes(segments[0]))
|
|
100
|
+
return false;
|
|
101
|
+
if (segments.some((segment) => segment === '' || segment.startsWith('.')))
|
|
102
|
+
return false;
|
|
103
|
+
return CODE_EXTENSIONS.includes(path.posix.extname(relative)) || isExampleFile(relative);
|
|
104
|
+
}
|
|
105
|
+
export function createCodeWatcher({ cwd, onChange, onError = () => { }, usePolling, pollingIntervalMs = DEFAULT_CODE_POLLING_INTERVAL_MS, eventDelayMs = 50, }) {
|
|
106
|
+
const known = new Map(); // relative -> SHA-256
|
|
107
|
+
const pending = new Set();
|
|
108
|
+
let watcher = null;
|
|
109
|
+
let stopped = false;
|
|
110
|
+
let ready = false;
|
|
111
|
+
let timer = null;
|
|
112
|
+
let queue = Promise.resolve();
|
|
113
|
+
const relativeOf = (absolute) => path.relative(cwd, absolute).split(path.sep).join('/');
|
|
114
|
+
// Only the code roots, no dot segments; files must have a served extension.
|
|
115
|
+
// Chokidar may ask first without stats: a path is kept unless its name alone rules it out.
|
|
116
|
+
function ignored(absolute, stats) {
|
|
117
|
+
const relative = relativeOf(absolute);
|
|
118
|
+
if (relative === '')
|
|
119
|
+
return false;
|
|
120
|
+
if (relative.startsWith('..') || path.isAbsolute(relative))
|
|
121
|
+
return true;
|
|
122
|
+
const segments = relative.split('/');
|
|
123
|
+
if (!CODE_DIRECTORIES.includes(segments[0]))
|
|
124
|
+
return true;
|
|
125
|
+
if (segments.some((segment) => segment.startsWith('.')))
|
|
126
|
+
return true;
|
|
127
|
+
if (stats?.isFile())
|
|
128
|
+
return !isCodeFile(relative);
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
async function digestOf(relative) {
|
|
132
|
+
try {
|
|
133
|
+
return createHash('sha256')
|
|
134
|
+
.update(await readFile(path.join(cwd, ...relative.split('/'))))
|
|
135
|
+
.digest('hex');
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
return null; // gone (or unreadable): reported as removed if it was known
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
async function compare(files) {
|
|
142
|
+
const changed = [];
|
|
143
|
+
for (const file of files) {
|
|
144
|
+
const next = await digestOf(file);
|
|
145
|
+
if (next === null) {
|
|
146
|
+
if (known.delete(file))
|
|
147
|
+
changed.push(file);
|
|
148
|
+
}
|
|
149
|
+
else if (next !== known.get(file)) {
|
|
150
|
+
known.set(file, next);
|
|
151
|
+
changed.push(file);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return changed.sort();
|
|
155
|
+
}
|
|
156
|
+
// Batches are compared one after another, so `known` is never updated concurrently.
|
|
157
|
+
function flush() {
|
|
158
|
+
const run = queue.then(async () => {
|
|
159
|
+
const files = [...pending];
|
|
160
|
+
pending.clear();
|
|
161
|
+
const changed = await compare(files);
|
|
162
|
+
if (changed.length && ready && !stopped)
|
|
163
|
+
onChange(changed);
|
|
164
|
+
return changed;
|
|
165
|
+
});
|
|
166
|
+
queue = run.catch(() => undefined);
|
|
167
|
+
return run;
|
|
168
|
+
}
|
|
169
|
+
function schedule() {
|
|
170
|
+
if (!ready || stopped || timer)
|
|
171
|
+
return;
|
|
172
|
+
timer = setTimeout(() => {
|
|
173
|
+
timer = null;
|
|
174
|
+
flush().catch(onError);
|
|
175
|
+
}, eventDelayMs);
|
|
176
|
+
}
|
|
177
|
+
function note(absolute) {
|
|
178
|
+
const relative = relativeOf(absolute);
|
|
179
|
+
if (!isCodeFile(relative))
|
|
180
|
+
return;
|
|
181
|
+
pending.add(relative);
|
|
182
|
+
schedule();
|
|
183
|
+
}
|
|
184
|
+
function noteDirectoryRemoved(absolute) {
|
|
185
|
+
const prefix = `${relativeOf(absolute)}/`;
|
|
186
|
+
for (const file of known.keys())
|
|
187
|
+
if (file.startsWith(prefix))
|
|
188
|
+
pending.add(file);
|
|
189
|
+
schedule();
|
|
190
|
+
}
|
|
191
|
+
return {
|
|
192
|
+
async start() {
|
|
193
|
+
// The code root itself is watched (everything outside the three roots is ignored without
|
|
194
|
+
// descending), so a root created later, or removed and recreated, is picked up.
|
|
195
|
+
watcher = watchWithOurSettings(cwd, {
|
|
196
|
+
ignored,
|
|
197
|
+
ignoreInitial: false,
|
|
198
|
+
persistent: true,
|
|
199
|
+
// 'polling': Chokidar's stat scheduler; 'auto': fs.watch (recursive on macOS/Windows,
|
|
200
|
+
// per directory elsewhere). `atomic` stays at Chokidar's default (off with polling): an
|
|
201
|
+
// editor's tmp + rename arrives as unlink + add of the same path within one batch, and
|
|
202
|
+
// the content hash reports it once.
|
|
203
|
+
backend: usePolling ? 'polling' : 'auto',
|
|
204
|
+
pollingInterval: pollingIntervalMs,
|
|
205
|
+
pollingBinaryInterval: pollingIntervalMs,
|
|
206
|
+
});
|
|
207
|
+
watcher.on('add', note).on('change', note).on('unlink', note).on('unlinkDir', noteDirectoryRemoved);
|
|
208
|
+
watcher.on('error', (error) => onError(Object.assign(new Error(`code watcher: ${error?.message ?? error}`), { cause: error })));
|
|
209
|
+
await new Promise((resolve) => watcher.once('ready', () => resolve()));
|
|
210
|
+
await compare([...pending]); // the baseline: nothing is reported for files present at start
|
|
211
|
+
pending.clear();
|
|
212
|
+
ready = true;
|
|
213
|
+
},
|
|
214
|
+
async rescan() {
|
|
215
|
+
for (const file of known.keys())
|
|
216
|
+
pending.add(file);
|
|
217
|
+
for (const [dir, names] of Object.entries(watcher?.getWatched() ?? {})) {
|
|
218
|
+
for (const name of names) {
|
|
219
|
+
const relative = relativeOf(path.join(dir, name));
|
|
220
|
+
if (isCodeFile(relative))
|
|
221
|
+
pending.add(relative);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return flush();
|
|
225
|
+
},
|
|
226
|
+
async stop() {
|
|
227
|
+
stopped = true;
|
|
228
|
+
if (timer)
|
|
229
|
+
clearTimeout(timer);
|
|
230
|
+
timer = null;
|
|
231
|
+
const w = watcher;
|
|
232
|
+
watcher = null;
|
|
233
|
+
if (w)
|
|
234
|
+
await w.close();
|
|
235
|
+
await queue;
|
|
236
|
+
},
|
|
237
|
+
backend: () => watcher?.options.backend ?? null,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* The code watcher of `dev --watch` (local and remote mode): decides polling vs native events
|
|
242
|
+
* (resolveWatchPolling, `polling` = the CLI flag), logs the decision and what it overrode, and
|
|
243
|
+
* creates the watcher. `log` receives one line without the command tag.
|
|
244
|
+
*/
|
|
245
|
+
export function createLiveCodeWatcher({ polling, log, ...options }) {
|
|
246
|
+
const mode = resolveWatchPolling(polling === undefined ? {} : { option: polling });
|
|
247
|
+
if (mode.invalid !== undefined)
|
|
248
|
+
log(`FOLIWAKE_WATCH_POLLING=${mode.invalid} is not 1/0/true/false/yes/no; ignored`);
|
|
249
|
+
log(`code watching: ${mode.description}`);
|
|
250
|
+
if (process.env.CHOKIDAR_INTERVAL !== undefined)
|
|
251
|
+
log(`CHOKIDAR_INTERVAL is ignored: code polling runs every ` +
|
|
252
|
+
`${options.pollingIntervalMs ?? DEFAULT_CODE_POLLING_INTERVAL_MS} ms`);
|
|
253
|
+
return createCodeWatcher({ ...options, usePolling: mode.usePolling });
|
|
254
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Diagnostic } from '@foliwake/site-check/formats/diagnostics';
|
|
2
|
+
import type { DevProblem } from './dev-reload.js';
|
|
3
|
+
/** A diagnostic file as the terminal prints it (code-root relative); never an absolute path. */
|
|
4
|
+
export declare function projectRelative(file: string): string;
|
|
5
|
+
export declare function toProblem(d: Diagnostic): DevProblem;
|
|
6
|
+
export interface DevChecker {
|
|
7
|
+
check(): Promise<DevProblem[]>;
|
|
8
|
+
}
|
|
9
|
+
/** The descriptor problems of the working folder, by the platform's rules. */
|
|
10
|
+
export declare function descriptorDiagnostics(cwd: string): Promise<Diagnostic[]>;
|
|
11
|
+
/** Problems of the working files; module checks are cached by content digest. */
|
|
12
|
+
export declare function createDevChecker({ cwd }: {
|
|
13
|
+
cwd: string;
|
|
14
|
+
}): DevChecker;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// The problems `foliwake dev --remote --watch` reports after a change (terminal and browser overlay): the
|
|
2
|
+
// component descriptor (the rules of @foliwake/site-check) and a syntax check of the JavaScript modules under
|
|
3
|
+
// components/ and scripts/. Content is remote, so there are no content errors here. Messages carry
|
|
4
|
+
// project-relative paths only.
|
|
5
|
+
import { spawn } from 'node:child_process';
|
|
6
|
+
import { createHash } from 'node:crypto';
|
|
7
|
+
import { readdir, readFile } from 'node:fs/promises';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { checkDescriptor } from '@foliwake/site-check/descriptor-check';
|
|
10
|
+
import { HTML_CONTRACT } from '@foliwake/site-check/formats/constants';
|
|
11
|
+
const SYNTAX_TIMEOUT_MS = 10000;
|
|
12
|
+
const SYNTAX_PARALLEL = 4;
|
|
13
|
+
/** A diagnostic file as the terminal prints it (code-root relative); never an absolute path. */
|
|
14
|
+
export function projectRelative(file) {
|
|
15
|
+
return path.isAbsolute(file) ? path.basename(file) : file.split(path.sep).join('/');
|
|
16
|
+
}
|
|
17
|
+
export function toProblem(d) {
|
|
18
|
+
const scope = [d.component, d.field].filter((v) => v != null).join(' ');
|
|
19
|
+
return {
|
|
20
|
+
file: projectRelative(d.file),
|
|
21
|
+
line: d.line,
|
|
22
|
+
column: d.column,
|
|
23
|
+
code: d.code,
|
|
24
|
+
message: scope ? `${scope}: ${d.message}` : d.message,
|
|
25
|
+
fix: d.fix,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
// Parses one module with `node --check` (stdin, module goal): nothing is executed.
|
|
29
|
+
function checkModuleSource(source) {
|
|
30
|
+
return new Promise((resolve) => {
|
|
31
|
+
const env = { ...process.env };
|
|
32
|
+
delete env.NODE_OPTIONS;
|
|
33
|
+
const child = spawn(process.execPath, ['--input-type=module', '--check', '-'], {
|
|
34
|
+
stdio: ['pipe', 'ignore', 'pipe'],
|
|
35
|
+
env,
|
|
36
|
+
});
|
|
37
|
+
let stderr = '';
|
|
38
|
+
const timer = setTimeout(() => child.kill(), SYNTAX_TIMEOUT_MS);
|
|
39
|
+
child.stderr.setEncoding('utf8').on('data', (chunk) => {
|
|
40
|
+
if (stderr.length < 20000)
|
|
41
|
+
stderr += chunk;
|
|
42
|
+
});
|
|
43
|
+
child.on('error', () => {
|
|
44
|
+
clearTimeout(timer);
|
|
45
|
+
resolve(null); // cannot check here: the browser still reports load errors
|
|
46
|
+
});
|
|
47
|
+
child.on('close', (code) => {
|
|
48
|
+
clearTimeout(timer);
|
|
49
|
+
if (code === 0)
|
|
50
|
+
return resolve(null);
|
|
51
|
+
const lines = stderr.split('\n');
|
|
52
|
+
const at = /^\[stdin\]:(\d+)/.exec(lines[0] ?? '');
|
|
53
|
+
const caretLine = lines.findIndex((l, i) => i > 1 && /^\s*\^+\s*$/.test(l));
|
|
54
|
+
const column = caretLine >= 0 ? lines[caretLine].indexOf('^') + 1 : null;
|
|
55
|
+
const message = lines.find((l) => /^[A-Za-z]*Error\b/.test(l)) ?? 'The module cannot be parsed.';
|
|
56
|
+
resolve({ line: at ? Number(at[1]) : null, column, message: message.trim() });
|
|
57
|
+
});
|
|
58
|
+
child.stdin.on('error', () => { });
|
|
59
|
+
child.stdin.end(source);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
async function listModules(cwd) {
|
|
63
|
+
const found = [];
|
|
64
|
+
const walk = async (absolute, relative) => {
|
|
65
|
+
let entries;
|
|
66
|
+
try {
|
|
67
|
+
entries = await readdir(absolute, { withFileTypes: true });
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
for (const entry of entries) {
|
|
73
|
+
if (entry.name.startsWith('.'))
|
|
74
|
+
continue;
|
|
75
|
+
const child = `${relative}/${entry.name}`;
|
|
76
|
+
if (entry.isDirectory())
|
|
77
|
+
await walk(path.join(absolute, entry.name), child);
|
|
78
|
+
else if (entry.isFile() && entry.name.endsWith('.js'))
|
|
79
|
+
found.push(child);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
for (const dir of ['components', 'scripts'])
|
|
83
|
+
await walk(path.join(cwd, dir), dir);
|
|
84
|
+
return found.sort();
|
|
85
|
+
}
|
|
86
|
+
/** The descriptor problems of the working folder, by the platform's rules. */
|
|
87
|
+
export function descriptorDiagnostics(cwd) {
|
|
88
|
+
return checkDescriptor({ cwd, htmlContract: HTML_CONTRACT });
|
|
89
|
+
}
|
|
90
|
+
/** Problems of the working files; module checks are cached by content digest. */
|
|
91
|
+
export function createDevChecker({ cwd }) {
|
|
92
|
+
const syntaxCache = new Map();
|
|
93
|
+
async function moduleProblems() {
|
|
94
|
+
const files = await listModules(cwd);
|
|
95
|
+
for (const cached of [...syntaxCache.keys()])
|
|
96
|
+
if (!files.includes(cached))
|
|
97
|
+
syntaxCache.delete(cached);
|
|
98
|
+
const queue = [...files];
|
|
99
|
+
const worker = async () => {
|
|
100
|
+
for (let file = queue.shift(); file !== undefined; file = queue.shift()) {
|
|
101
|
+
let source;
|
|
102
|
+
try {
|
|
103
|
+
source = await readFile(path.join(cwd, ...file.split('/')), 'utf8');
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
syntaxCache.delete(file);
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
const digest = createHash('sha256').update(source).digest('hex');
|
|
110
|
+
if (syntaxCache.get(file)?.digest === digest)
|
|
111
|
+
continue;
|
|
112
|
+
const failure = await checkModuleSource(source);
|
|
113
|
+
syntaxCache.set(file, {
|
|
114
|
+
digest,
|
|
115
|
+
problem: failure && {
|
|
116
|
+
file,
|
|
117
|
+
line: failure.line,
|
|
118
|
+
column: failure.column,
|
|
119
|
+
code: 'DEV_MODULE_SYNTAX',
|
|
120
|
+
message: failure.message,
|
|
121
|
+
fix: 'Correct the JavaScript syntax at this position and save.',
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
await Promise.all(Array.from({ length: SYNTAX_PARALLEL }, worker));
|
|
127
|
+
return files.flatMap((file) => {
|
|
128
|
+
const problem = syntaxCache.get(file)?.problem;
|
|
129
|
+
return problem ? [problem] : [];
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
async check() {
|
|
134
|
+
const [descriptor, modules] = await Promise.all([descriptorDiagnostics(cwd), moduleProblems()]);
|
|
135
|
+
return [...descriptor.filter((d) => d.severity === 'error').map(toProblem), ...modules];
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
+
export declare const DEV_EVENTS_PATH = "/_dev/events";
|
|
3
|
+
export declare const DEV_CLIENT_PATH = "/_dev/reload.js";
|
|
4
|
+
export declare const DEFAULT_RELOAD_DEBOUNCE_MS = 200;
|
|
5
|
+
/** One problem shown in the browser overlay and in the terminal (project-relative file only). */
|
|
6
|
+
export interface DevProblem {
|
|
7
|
+
file: string;
|
|
8
|
+
line: number | null;
|
|
9
|
+
column: number | null;
|
|
10
|
+
code: string;
|
|
11
|
+
message: string;
|
|
12
|
+
fix: string | null;
|
|
13
|
+
}
|
|
14
|
+
export interface ReloadHubOptions {
|
|
15
|
+
/** quiet window that merges several saves into one reload (default 200 ms) */
|
|
16
|
+
debounceMs?: number;
|
|
17
|
+
/** the current problems (descriptor, module syntax, content errors); called once per flush */
|
|
18
|
+
check: () => Promise<DevProblem[]>;
|
|
19
|
+
log?: (text: string) => void;
|
|
20
|
+
}
|
|
21
|
+
export interface ReloadEvent {
|
|
22
|
+
files: string[];
|
|
23
|
+
problems: DevProblem[];
|
|
24
|
+
/** change generation after this flush (starts at 0, +1 per flush) */
|
|
25
|
+
generation: number;
|
|
26
|
+
}
|
|
27
|
+
export interface ReloadHub {
|
|
28
|
+
readonly serverId: string;
|
|
29
|
+
/** The current change generation: 0 at start, +1 for every flushed (sent) change set. */
|
|
30
|
+
generation(): number;
|
|
31
|
+
/** Files changed (cwd-relative posix); merged into the next debounced reload. */
|
|
32
|
+
notify(files: readonly string[]): void;
|
|
33
|
+
/** Computes the problems now (startup baseline); later streams get them in `hello`. */
|
|
34
|
+
refresh(): Promise<DevProblem[]>;
|
|
35
|
+
problems(): DevProblem[];
|
|
36
|
+
handleEvents(req: IncomingMessage, res: ServerResponse): void;
|
|
37
|
+
/** Open event streams (tests). */
|
|
38
|
+
clientCount(): number;
|
|
39
|
+
/** Resolves after each reload is sent (tests and logs). */
|
|
40
|
+
onReload(listener: (event: ReloadEvent) => void): () => void;
|
|
41
|
+
stop(): void;
|
|
42
|
+
}
|
|
43
|
+
export declare function formatProblem(p: DevProblem): string;
|
|
44
|
+
export declare function createReloadHub({ debounceMs, check, log, }: ReloadHubOptions): ReloadHub;
|
|
45
|
+
/**
|
|
46
|
+
* The one place a dev client is added to an HTML document (any dev page source).
|
|
47
|
+
* `generation` is the hub's change generation when the document was produced;
|
|
48
|
+
* the client reloads when the server's generation differs after (re)connecting.
|
|
49
|
+
*/
|
|
50
|
+
export declare function injectDevClient(html: string, generation?: number | null): string;
|
|
51
|
+
export declare const DEV_CLIENT_SCRIPT = "// foliwake dev --watch: reload after changes, show problems.\n(function () {\n 'use strict';\n if (window.__foliwakeDevClient) return;\n window.__foliwakeDevClient = true;\n var serverId = null;\n // The change generation this page was rendered at (null: unknown, e.g. an\n // older tag); compared with every hello so changes made while disconnected\n // are not missed.\n var pageGeneration = (function () {\n var s = document.currentScript;\n var g = s && s.getAttribute('data-generation');\n return g != null && /^\\d+$/.test(g) ? Number(g) : null;\n })();\n var source = null;\n var attempts = 0;\n var serverProblems = [];\n var browserProblems = [];\n var dismissed = false;\n\n function rel(url) {\n try {\n var u = new URL(url, location.href);\n return u.origin === location.origin ? u.pathname.replace(/^\\//, '') : u.href;\n } catch (e) { return String(url); }\n }\n function addBrowserProblem(p) {\n var key = p.file + '|' + p.message;\n for (var i = 0; i < browserProblems.length; i++) if (browserProblems[i].key === key) return;\n p.key = key;\n browserProblems.push(p);\n render();\n }\n function el(tag, text, style) {\n var e = document.createElement(tag);\n if (text != null) e.textContent = text;\n if (style) e.setAttribute('style', style);\n return e;\n }\n function render() {\n var all = serverProblems.concat(browserProblems);\n var old = document.querySelector('[data-foliwake-dev-overlay]');\n if (old) old.remove();\n if (!all.length || dismissed || !document.body) return;\n var box = el('div', null, 'position:fixed;left:0;right:0;bottom:0;z-index:2147483647;max-height:50vh;' +\n 'overflow:auto;background:#fff5f5;color:#1b1b1b;border-top:4px solid #b00020;' +\n 'font:14px/1.45 system-ui,sans-serif;padding:12px 16px;box-shadow:0 -4px 16px rgba(0,0,0,.2)');\n box.setAttribute('data-foliwake-dev-overlay', '');\n box.setAttribute('role', 'alert');\n var close = el('button', 'Dismiss', 'float:right;font:inherit');\n close.type = 'button';\n close.addEventListener('click', function () { dismissed = true; render(); });\n box.appendChild(close);\n box.appendChild(el('strong', 'foliwake dev: ' + all.length + ' problem(s)'));\n var list = el('ol', null, 'margin:6px 0;padding-left:20px');\n all.forEach(function (p) {\n var li = el('li', null, 'margin:0 0 6px');\n li.setAttribute('data-file', p.file);\n var where = p.file + (p.line != null ? ':' + p.line + (p.column != null ? ':' + p.column : '') : '');\n li.appendChild(el('code', where, 'font:13px ui-monospace,Menlo,monospace;font-weight:600'));\n li.appendChild(document.createTextNode(' ' + (p.code ? p.code + ': ' : '') + p.message));\n if (p.fix) li.appendChild(el('div', 'Fix: ' + p.fix));\n list.appendChild(li);\n });\n box.appendChild(list);\n var after = 'Fix the file and save it: the page reloads by itself. All diagnostics: /_dev/diagnostics';\n box.appendChild(el('div', after, 'color:#555'));\n document.body.appendChild(box);\n }\n\n window.addEventListener('error', function (event) {\n var t = event.target;\n if (t && t !== window && (t.tagName === 'SCRIPT' || t.tagName === 'LINK')) {\n var url = t.src || t.href;\n addBrowserProblem({\n file: rel(url), line: null, column: null, code: 'DEV_LOAD_FAILED',\n message: (t.tagName === 'SCRIPT' ? 'Script' : 'Stylesheet') + ' failed to load.',\n fix: 'Check that the file exists and is served (see the terminal).'\n });\n return;\n }\n addBrowserProblem({\n file: event.filename ? rel(event.filename) : '(page)', line: event.lineno || null,\n column: event.colno || null, code: 'DEV_SCRIPT_ERROR', message: String(event.message || 'Uncaught error'),\n fix: null\n });\n }, true);\n window.addEventListener('unhandledrejection', function (event) {\n var r = event.reason;\n addBrowserProblem({\n file: '(page)', line: null, column: null, code: 'DEV_UNHANDLED_REJECTION',\n message: String(r && r.message ? r.name + ': ' + r.message : r), fix: null\n });\n });\n function scanComponents(root) {\n var scope = root || document;\n var failed = scope.querySelectorAll ? scope.querySelectorAll('[data-component-status=\"error\"]') : [];\n for (var i = 0; i < failed.length; i++) {\n var name = failed[i].getAttribute('data-component') || '?';\n addBrowserProblem({\n file: 'components/' + name, line: null, column: null, code: 'DEV_COMPONENT_FAILED',\n message: 'Component \"' + name + '\" failed in the browser; the console has the loader error.',\n fix: 'Fix the component files (or components/components.json) and save.'\n });\n }\n }\n // Problems the server found in this page itself (for example a remote page\n // that the local components cannot render with foliwake dev --remote).\n function pageProblems() {\n var blocks = document.querySelectorAll('script[type=\"application/json\"][data-foliwake-dev-problems]');\n for (var i = 0; i < blocks.length; i++) {\n var list;\n try { list = JSON.parse(blocks[i].textContent || '[]'); } catch (e) { continue; }\n if (!Array.isArray(list)) continue;\n list.forEach(function (p) {\n if (!p || typeof p.message !== 'string') return;\n addBrowserProblem({\n file: String(p.file || '(page)'), line: p.line == null ? null : p.line,\n column: p.column == null ? null : p.column, code: String(p.code || ''), message: p.message,\n fix: p.fix == null ? null : String(p.fix)\n });\n });\n }\n }\n function observe() {\n pageProblems();\n scanComponents(document);\n var watched = { subtree: true, attributes: true, attributeFilter: ['data-component-status'] };\n new MutationObserver(function () { scanComponents(document); }).observe(document.documentElement, watched);\n render();\n }\n if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', observe); else observe();\n\n function reconnectLater() {\n window.__foliwakeDevConnected = false;\n if (source) source.close();\n source = null;\n attempts++;\n if (attempts > 60) return; // about 10 minutes, then stop; refresh by hand\n setTimeout(connect, Math.min(1000 * Math.pow(2, attempts - 1), 10000));\n }\n function connect() {\n source = new EventSource('/_dev/events');\n source.addEventListener('hello', function (e) {\n var data = JSON.parse(e.data);\n if (serverId && data.serverId !== serverId) { location.reload(); return; }\n if (typeof data.generation === 'number') {\n if (pageGeneration !== null && data.generation !== pageGeneration) { location.reload(); return; }\n // An established connection without a page generation adopts the server's.\n if (pageGeneration === null && serverId) { location.reload(); return; }\n pageGeneration = data.generation;\n }\n serverId = data.serverId;\n attempts = 0;\n window.__foliwakeDevConnected = true;\n serverProblems = data.problems || [];\n render();\n });\n source.addEventListener('reload', function () { location.reload(); });\n source.addEventListener('bye', function () { reconnectLater(); });\n // Our own bounded backoff instead of EventSource's endless 1 s retries.\n source.onerror = function () { reconnectLater(); };\n }\n connect();\n})();\n";
|