@runeditrun/rer 0.2.79 → 0.2.80
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 +17 -3
- package/cli/README.md +25 -13
- package/cli/authoring.mjs +14 -0
- package/cli/contract.mjs +25 -5
- package/cli/demo-host.mjs +4 -2
- package/cli/dev-identity.mjs +2 -2
- package/cli/export.mjs +1 -1
- package/cli/inspect.mjs +38 -2
- package/cli/main.mjs +8 -2
- package/cli/managed-server.mjs +1 -1
- package/cli/parse.mjs +7 -6
- package/cli/portability-worker.mjs +2 -1
- package/cli/portability.mjs +6 -2
- package/cli/production-auth.mjs +2 -1
- package/cli/production-mail.mjs +36 -9
- package/cli/project.mjs +5 -14
- package/cli/release.mjs +2 -1
- package/cli/site-preview.mjs +4 -1
- package/cli/site.mjs +3 -2
- package/edition-authoring/adopt.mjs +39 -0
- package/edition-authoring/base-acknowledgements.mjs +24 -0
- package/edition-authoring/base-copies.mjs +418 -0
- package/edition-authoring/cli.mjs +85 -0
- package/edition-authoring/copy-checkout.mjs +69 -0
- package/edition-authoring/files.mjs +15 -2
- package/edition-authoring/lock.mjs +48 -0
- package/edition-authoring/offline-git.mjs +28 -0
- package/edition-authoring/parent-comparison.mjs +77 -0
- package/edition-authoring/projection-lock.mjs +38 -0
- package/edition-authoring/release.mjs +48 -0
- package/edition-authoring/sources.mjs +114 -0
- package/edition-authoring/updates.mjs +105 -0
- package/global/CHANGELOG.md +12 -0
- package/global/README.md +17 -3
- package/global/cli/install.mjs +3 -1
- package/global/main.mjs +9 -12
- package/modules/container/build.mjs +1 -1
- package/modules/d1-transport/index.mjs +68 -21
- package/modules/demo/README.md +8 -2
- package/modules/demo/declaration.mjs +21 -0
- package/modules/demo/input-path.mjs +18 -0
- package/modules/demo/label.d.mts +1 -1
- package/modules/demo/label.mjs +10 -5
- package/modules/demo/navigation.mjs +32 -0
- package/modules/demo/run-url.mjs +9 -0
- package/modules/demo/vite.d.mts +7 -2
- package/modules/demo/vite.mjs +17 -2
- package/modules/demo-host/README.md +5 -3
- package/modules/demo-host/page-style.mjs +2 -2
- package/modules/demo-host/pages.mjs +3 -3
- package/modules/demo-host/plan.mjs +6 -4
- package/modules/demo-host/theme.mjs +5 -2
- package/modules/deploy-kit/README.md +19 -15
- package/modules/deploy-kit/owner-cli.mjs +1 -1
- package/modules/deploy-kit/readiness-window.mjs +3 -3
- package/modules/erasure/README.md +10 -5
- package/modules/import-kit/src/d1/README.md +15 -9
- package/modules/import-kit/src/d1/apply.ts +10 -6
- package/modules/import-kit/src/d1/atomic-prefix.ts +64 -0
- package/modules/import-kit/src/d1/budget.ts +48 -26
- package/modules/import-kit/src/d1/compressed-plan.ts +9 -2
- package/modules/import-kit/src/d1/database.ts +2 -1
- package/modules/import-kit/src/d1/jobs.ts +2 -1
- package/modules/import-kit/src/d1/plans.ts +4 -2
- package/modules/import-kit/src/d1/verified-plan.ts +63 -0
- package/modules/integrations/core/README.md +2 -2
- package/modules/mail/README.md +4 -3
- package/modules/mail/pnpm-lock.yaml +16 -0
- package/modules/operator-auth/accounts/native.mjs +3 -1
- package/modules/operator-auth/accounts/provider-control.mjs +7 -4
- package/modules/operator-auth/accounts/provider-setup.mjs +34 -0
- package/modules/operator-auth/accounts/settings-page.mjs +13 -4
- package/modules/operator-auth/conformance/README.md +1 -1
- package/modules/operator-auth/dev/index.mjs +22 -4
- package/modules/operator-auth/dev/refusal.mjs +19 -0
- package/modules/operator-auth/docs/README.md +6 -5
- package/modules/operator-auth/docs/tanstack-start.md +1 -1
- package/modules/operator-auth/docs/vite-spa.md +5 -6
- package/modules/operator-auth/index.d.mts +1 -1
- package/modules/operator-auth/page.mjs +14 -0
- package/modules/operator-auth/representation.mjs +83 -0
- package/modules/operator-auth/routes.mjs +25 -2
- package/modules/portability/README.md +91 -14
- package/modules/portability/bookkeeping.mjs +3 -3
- package/modules/portability/bridge.mjs +5 -4
- package/modules/portability/catalogue.mjs +12 -8
- package/modules/portability/cli.mjs +5 -1
- package/modules/portability/export.mjs +5 -11
- package/modules/portability/format.mjs +7 -1
- package/modules/portability/http-errors.mjs +51 -0
- package/modules/portability/http.mjs +4 -1
- package/modules/portability/import-lease.mjs +13 -2
- package/modules/portability/import.mjs +10 -0
- package/modules/portability/index.d.mts +3 -0
- package/modules/portability/references.mjs +20 -0
- package/modules/portability/schema-identity.mjs +13 -0
- package/modules/portability/schema-legacy.mjs +21 -0
- package/modules/portability/sqlite-tokens.mjs +121 -0
- package/modules/release/README.md +20 -9
- package/modules/release/github-verify.mjs +30 -9
- package/modules/site/docs-search/search.css +1 -1
- package/onboarding/README.md +16 -4
- package/onboarding/adapter.mjs +5 -1
- package/onboarding/schema/SETUP.schema.json +26 -1
- package/onboarding/schema/business-field-inputs.mjs +37 -0
- package/onboarding/schema/json-schema.mjs +6 -2
- package/onboarding/schema/setup-validation.mjs +20 -3
- package/onboarding/server.mjs +1 -1
- package/onboarding/setup-manifest.mjs +2 -0
- package/onboarding/start-origin-diagnostic.mjs +24 -0
- package/onboarding/ui/style.css +9 -9
- package/package.json +1 -1
- package/scripts/publish-check/README.md +1 -1
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import {manifest} from './manifest.mjs';
|
|
4
|
+
import {snapshot} from './sources.mjs';
|
|
5
|
+
import {parentFiles, parentIdentities} from './parent-comparison.mjs';
|
|
6
|
+
import {hash, json, git, tracked, fresh, writeTree} from './files.mjs';
|
|
7
|
+
|
|
8
|
+
function diff(before, after) {
|
|
9
|
+
return [...new Set([...Object.keys(before), ...Object.keys(after)])].sort()
|
|
10
|
+
.filter(name => json(before[name]) !== json(after[name]))
|
|
11
|
+
.map(name => ({path: name, change: !(name in before) ? 'added' : !(name in after) ? 'removed' : 'modified', before: before[name] ?? null, after: after[name] ?? null}));
|
|
12
|
+
}
|
|
13
|
+
export function changes(before, after) {
|
|
14
|
+
return {
|
|
15
|
+
files: diff(before.files, after.files),
|
|
16
|
+
metadata: diff(Object.fromEntries(Object.entries(before).filter(([k]) => k !== 'files')),
|
|
17
|
+
Object.fromEntries(Object.entries(after).filter(([k]) => k !== 'files'))),
|
|
18
|
+
meaning: 'Origins are comparison baselines; changing an origin does not assert adoption or local byte equality.',
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function baseline(root, id) {
|
|
22
|
+
const recipe = manifest(root);
|
|
23
|
+
const component = recipe.components.find(c => c.id === id);
|
|
24
|
+
const ref = id === 'parent' ? recipe.parent && {...recipe.parent, excludeSnapshots: true}
|
|
25
|
+
: component?.source.kind === 'git' ? component.source : component?.source.origin;
|
|
26
|
+
if (!ref) throw Error('Selected component has no comparison baseline');
|
|
27
|
+
const saved = snapshot(root, ref);
|
|
28
|
+
const lock = JSON.parse(fs.readFileSync(path.join(root, 'sources.lock.json')));
|
|
29
|
+
const expected = id === 'parent' ? lock.parent : lock.components.find(c => c.id === id)?.baseline;
|
|
30
|
+
if (!expected || saved.key !== expected.key || saved.digest !== expected.digest || hash(json(saved)) !== expected.sha256) {
|
|
31
|
+
throw Error('Baseline differs from lock; inspect selection before extracting or comparing');
|
|
32
|
+
}
|
|
33
|
+
return {component, ref, saved};
|
|
34
|
+
}
|
|
35
|
+
export function extract(root, id, destination) {
|
|
36
|
+
const output = fresh(destination, root);
|
|
37
|
+
const {saved} = baseline(root, id);
|
|
38
|
+
writeTree(output, saved.files);
|
|
39
|
+
return {output, origin: saved.origin, digest: saved.digest, files: Object.keys(saved.files).length};
|
|
40
|
+
}
|
|
41
|
+
function identities(files) {
|
|
42
|
+
return Object.fromEntries(Object.entries(files).map(([name, file]) => [name,
|
|
43
|
+
{sha256: hash(Buffer.from(file.data, 'base64')), executable: file.executable}]));
|
|
44
|
+
}
|
|
45
|
+
// The most specific mapping owns a local file; one origin file may have several
|
|
46
|
+
// local copies, and each copy is compared with that origin file on its own.
|
|
47
|
+
function owner(mappings, name) {
|
|
48
|
+
let found = null;
|
|
49
|
+
for (const mapping of mappings) {
|
|
50
|
+
if (name !== mapping.path && !name.startsWith(mapping.path + '/')) continue;
|
|
51
|
+
if (found?.path === mapping.path && found.originPath !== mapping.originPath) throw Error(`Ambiguous comparison mappings for ${mapping.path}`);
|
|
52
|
+
if (!found || mapping.path.length > found.path.length) found = mapping;
|
|
53
|
+
}
|
|
54
|
+
return found;
|
|
55
|
+
}
|
|
56
|
+
function mappedChanges(mappings, before, editionFiles) {
|
|
57
|
+
const result = [];
|
|
58
|
+
for (const [name, file] of Object.entries(editionFiles)) {
|
|
59
|
+
const mapping = owner(mappings, name);
|
|
60
|
+
if (!mapping) continue;
|
|
61
|
+
const target = mapping.originPath + name.slice(mapping.path.length);
|
|
62
|
+
const after = identities({[name]: file})[name];
|
|
63
|
+
if (json(before[target]) !== json(after)) result.push({path: target, localPath: name, change: before[target] ? 'modified' : 'added', before: before[target] ?? null, after});
|
|
64
|
+
}
|
|
65
|
+
for (const mapping of mappings) for (const [target, identity] of Object.entries(before)) {
|
|
66
|
+
if (target !== mapping.originPath && !target.startsWith(mapping.originPath + '/')) continue;
|
|
67
|
+
const name = mapping.path + target.slice(mapping.originPath.length);
|
|
68
|
+
if (!(name in editionFiles) && owner(mappings, name) === mapping) result.push({path: target, localPath: name, change: 'removed', before: identity, after: null});
|
|
69
|
+
}
|
|
70
|
+
return result.sort((a, b) => a.path.localeCompare(b.path) || a.localPath.localeCompare(b.localPath));
|
|
71
|
+
}
|
|
72
|
+
export function compare(root, id, candidate, currentRoot = root) {
|
|
73
|
+
const {component, ref, saved} = baseline(root, id);
|
|
74
|
+
const repository = fs.realpathSync(candidate);
|
|
75
|
+
if (fs.realpathSync(git(repository, 'rev-parse', '--show-toplevel')) !== repository) throw Error('Candidate must be a Git repository root');
|
|
76
|
+
if (git(repository, 'status', '--porcelain', '--untracked-files=all')) throw Error('Candidate must be clean and committed');
|
|
77
|
+
// Incoming source is the candidate's own Git source; it never inherits a projection identity.
|
|
78
|
+
const incoming = snapshot(root, {...ref, projection: undefined, repository, revision: git(repository, 'rev-parse', 'HEAD')});
|
|
79
|
+
if (!component) {
|
|
80
|
+
const normalize = parentIdentities(root, saved);
|
|
81
|
+
const before = normalize(saved.files), current = normalize(parentFiles(currentRoot));
|
|
82
|
+
return {component: 'parent', baseline: {origin: saved.origin, digest: saved.digest},
|
|
83
|
+
incoming: {origin: incoming.origin, digest: incoming.digest},
|
|
84
|
+
upstreamChanges: diff(before, normalize(incoming.files)),
|
|
85
|
+
localChanges: diff(before, current), currentFiles: current, mappings: null,
|
|
86
|
+
meaning: 'Whole-parent comparison reads independent incoming Git source and current tracked source. Only exact planned projection identities and planned omissions are normalized; all other bytes, modes, additions and removals remain visible. This does not judge compatibility, owner intent, or adoption.',
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
if (currentRoot !== root) throw Error('An independent current checkout is supported only for parent comparison');
|
|
90
|
+
const selected = component.source;
|
|
91
|
+
if (selected.workspace) throw Error('Promote or commit workspace source before comparing immutable selections');
|
|
92
|
+
const editionFiles = tracked(root);
|
|
93
|
+
const mappings = selected.kind === 'git' ? [] : selected.mappings || [];
|
|
94
|
+
const owned = selected.kind === 'local' ? Object.fromEntries(Object.entries(editionFiles)
|
|
95
|
+
.filter(([name]) => selected.paths.some(p => name === p || name.startsWith(p + '/')))) : saved.files;
|
|
96
|
+
const before = identities(saved.files);
|
|
97
|
+
return {component: id, baseline: {origin: saved.origin, digest: saved.digest},
|
|
98
|
+
incoming: {origin: incoming.origin, digest: incoming.digest},
|
|
99
|
+
upstreamChanges: diff(before, identities(incoming.files)),
|
|
100
|
+
// Never guess correspondence for dispersed or deeply rewritten local source.
|
|
101
|
+
localChanges: selected.kind === 'git' ? [] : mappings.length ? mappedChanges(mappings, before, editionFiles) : null,
|
|
102
|
+
currentFiles: identities(owned), mappings,
|
|
103
|
+
meaning: 'Current source may intentionally differ. Local comparison uses explicit mappings only; each local copy is compared with its own origin file. This does not judge compatibility, owner intent, or adoption.',
|
|
104
|
+
};
|
|
105
|
+
}
|
package/global/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.80
|
|
4
|
+
|
|
5
|
+
- Healthy doctor now exits 0 when local settings are present.
|
|
6
|
+
- Restore installation archives using SQL-aware schema identity and an object inventory; ignore SQL comments while preserving behavioral schema checks and staged file validation.
|
|
7
|
+
- Expose edition adoption and `refresh-base` in the packaged CLI, preserve adaptation acknowledgements and offline provenance, and retire absent singleton Base copies.
|
|
8
|
+
- Accept a successful exact-SHA branch push or dispatch Verify for releases, including when a duplicate main run failed; reuse qualified branch verification in seed workflows.
|
|
9
|
+
- Keep harness ingress listeners bound across Worker generations and let test runtimes own ephemeral ports.
|
|
10
|
+
- Link demo exits to the seed's canonical Run chooser, bootstrap pinned demo commands, and improve shared header, link and minimum text sizes.
|
|
11
|
+
- Limit Business profile hints to declared public input names and reject credential-shaped hints and duplicate field claims.
|
|
12
|
+
- Update compatible dependencies while retaining Node 22.20.0 and pnpm 10.12.4; pnpm 10.34.7 is not adopted.
|
|
13
|
+
- Give Chromium apt attempts separate deadlines and clean up timed-out attempts and cache payloads.
|
|
14
|
+
|
|
3
15
|
## 0.2.79
|
|
4
16
|
|
|
5
17
|
- Reuse bounded keep-alive connections in the local dev proxy and retry stale connections for bodyless reads.
|
package/global/README.md
CHANGED
|
@@ -4,6 +4,17 @@
|
|
|
4
4
|
Run Edit Run checkout: every verb runs that checkout's own pinned copy, so a
|
|
5
5
|
checkout always gets the behaviour it was built and tested with.
|
|
6
6
|
|
|
7
|
+
For source authors, `rer adopt-edition` adds a recipe and lock to existing tracked
|
|
8
|
+
seed source while preserving copy/composition provenance. `rer refresh-base
|
|
9
|
+
--ref FULL_COMMIT` refreshes recorded Base copies with the seed's pinned package;
|
|
10
|
+
no vendored authoring CLI is needed. Base source comes from a temporary clone of
|
|
11
|
+
`https://github.com/runeditrun/base.git` unless the seed declares another source
|
|
12
|
+
or you pass `--base CHECKOUT`. Offline refresh requires `--offline --base CHECKOUT`.
|
|
13
|
+
Both verbs have effect-free `--help` and newline-delimited `--json` events.
|
|
14
|
+
Review source changes and run edition tests before committing. See the
|
|
15
|
+
[edition authoring guide](https://github.com/runeditrun/base/blob/main/export/EDITION-AUTHORING.md)
|
|
16
|
+
for adoption, refusal behavior, JSON fields and the original Base-checkout form.
|
|
17
|
+
|
|
7
18
|
## Install
|
|
8
19
|
|
|
9
20
|
Start a seed from an empty folder, with or without Node:
|
|
@@ -244,8 +255,11 @@ which inside `pnpm run` is the pinned copy in `node_modules/.bin`, so
|
|
|
244
255
|
`pnpm install --frozen-lockfile && pnpm run build` needs no global `rer`. A global
|
|
245
256
|
`rer` hands every verb to the pinned package, launching included. Until
|
|
246
257
|
`node_modules` holds the pinned version (a fresh clone, or a pulled pin change),
|
|
247
|
-
|
|
248
|
-
started at once share that one install.
|
|
258
|
+
commands that run project code install it first (the frozen `pnpm install`),
|
|
259
|
+
then run it; commands started at once share that one install. Help, version,
|
|
260
|
+
read-only `doctor`, and `release sign`, `release receipt` and `release keygen`
|
|
261
|
+
do not install dependencies. The release producer still bootstraps before it
|
|
262
|
+
runs project build or verification scripts.
|
|
249
263
|
Every dependency install, `rer release`'s included, receives an allowlisted
|
|
250
264
|
environment: the shell, locale, terminal and temporary-folder variables, `CI`,
|
|
251
265
|
`TZ`, `SSH_AUTH_SOCK`, `NODE_OPTIONS`, `NODE_EXTRA_CA_CERTS`, `XDG_*`, proxy
|
|
@@ -514,7 +528,7 @@ The current MCP `next_question` filters out owner items. When an owner summary
|
|
|
514
528
|
is supplied, the CLI displays its browser link and refuses to answer it.
|
|
515
529
|
|
|
516
530
|
The four deterministic adapter implementations and their native output formats
|
|
517
|
-
are described in [the adapter guide](cli/business/vendors/README.md). Their
|
|
531
|
+
are described in [the adapter guide](https://github.com/runeditrun/base/blob/main/cli/business/vendors/README.md). Their
|
|
518
532
|
presence does not enable export until the seed import authority and remaining
|
|
519
533
|
transport contracts are connected.
|
|
520
534
|
|
package/global/cli/install.mjs
CHANGED
|
@@ -8,6 +8,7 @@ import { ownManifest, ownRoot, packageDigest, packageFileList } from '../package
|
|
|
8
8
|
import { installRecord, launcherOwner, launcherScript, layout } from './layout.mjs';
|
|
9
9
|
import { pathAdvice } from './path-link.mjs';
|
|
10
10
|
import { runningDoor } from '../../cli/door.mjs';
|
|
11
|
+
import { channelOf } from './status.mjs';
|
|
11
12
|
|
|
12
13
|
async function readLink(path) { try { return await readlink(path); } catch (error) { if (['ENOENT', 'EINVAL'].includes(error.code)) return undefined; throw error; } }
|
|
13
14
|
|
|
@@ -49,7 +50,8 @@ async function closing(paths) {
|
|
|
49
50
|
|
|
50
51
|
export async function install({ quiet = false } = {}) {
|
|
51
52
|
const paths = layout(), manifest = ownManifest(), digest = await packageDigest(ownRoot);
|
|
52
|
-
const name = `${manifest.version}-${digest.slice(0, 8)}
|
|
53
|
+
const name = `${manifest.version}-${digest.slice(0, 8)}`;
|
|
54
|
+
const channel = (process.env.RER_INSTALL_CHANNEL ?? (await channelOf(paths)).channel) === 'script' ? 'script' : 'npx';
|
|
53
55
|
const launcher = await launcherOwner(paths.launcher);
|
|
54
56
|
if (launcher.state === 'foreign') {
|
|
55
57
|
process.stderr.write(`rer cli install: ${paths.launcher} already exists and was not written by rer cli install (it may be the unrelated npm package "rer"). Nothing was changed. Remove or rename it, then run the install again.\n`);
|
package/global/main.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { checkoutBootstrap, checkoutVerbs } from '../cli/contract.mjs';
|
|
2
2
|
import { dispatcher, locate, pinnedPackage, unsupportedMessage } from './checkout.mjs';
|
|
3
3
|
import { delegate } from './delegate.mjs';
|
|
4
4
|
import { localDefaults } from './launch/local-defaults.mjs';
|
|
@@ -15,7 +15,8 @@ ${repositoryHelp}
|
|
|
15
15
|
|
|
16
16
|
Inside a project (the nearest OPERATIONS.json at or above this folder, or --cwd DIR),
|
|
17
17
|
every verb runs that checkout's own pinned rer: the @runeditrun/rer version its package.json
|
|
18
|
-
pins (installed first
|
|
18
|
+
pins (installed first for commands that run project code when node_modules holds another),
|
|
19
|
+
else its vendored scripts/rer.mjs.
|
|
19
20
|
|
|
20
21
|
rer dev Launch a first-party checkout with no setup steps: installs dependencies,
|
|
21
22
|
sets up a local owner and a free port when needed, starts the app and prints
|
|
@@ -44,17 +45,13 @@ pins (installed first by any verb when node_modules holds another), else its ven
|
|
|
44
45
|
Run COMMAND once this computer's job queue admits it (heavy package scripts
|
|
45
46
|
of a checkout that pins the rer package use it).
|
|
46
47
|
|
|
47
|
-
Checkout verbs:
|
|
48
|
-
import, doctor, describe, check, release, listing. Run rer VERB --help in a checkout for its flags.
|
|
48
|
+
Checkout verbs: ${Object.keys(checkoutVerbs).join(', ')}, listing. Run rer VERB --help in a checkout for its flags.
|
|
49
49
|
`;
|
|
50
50
|
|
|
51
|
-
// The checkout verbs that install the pinned package before they run when
|
|
52
|
-
// node_modules holds another version or none (dev installs it in its launch).
|
|
53
|
-
const installsFirst = new Set([...Object.keys(verbs), 'signin', 'release'].filter(verb => !['dev', 'doctor'].includes(verb)));
|
|
54
|
-
|
|
55
51
|
export async function main(argv) {
|
|
56
52
|
handleBrokenPipes();
|
|
57
53
|
const [verb] = argv;
|
|
54
|
+
const installsFirst = checkoutBootstrap(argv) === 'before';
|
|
58
55
|
if (verb === '--version' || verb === '-v') return (await import('./version.mjs')).versionCommand(argv);
|
|
59
56
|
if (verb === 'queue' && argv.length === 2 && argv[1] === '--help') {
|
|
60
57
|
process.stdout.write('Usage: rer queue NAME -- COMMAND [ARGS]\nRun COMMAND once this computer\'s job queue admits it.\n');
|
|
@@ -102,7 +99,7 @@ export async function main(argv) {
|
|
|
102
99
|
const code = await (await import('./browser-runtime.mjs')).browserPreflight(target.root, target.args);
|
|
103
100
|
if (code !== undefined) return code;
|
|
104
101
|
}
|
|
105
|
-
const bootstrap = pinnedPackage(target.root)?.ready === false && installsFirst
|
|
102
|
+
const bootstrap = pinnedPackage(target.root)?.ready === false && installsFirst;
|
|
106
103
|
if ((bootstrap || ['install', 'setup', 'dev', 'preview', 'build', 'verify'].includes(verb)) && !argv.includes('--help') && !argv.includes('--stop')) {
|
|
107
104
|
const { parse } = await import('../cli/parse.mjs');
|
|
108
105
|
// The door's launch marker belongs to launchDev, which consumes it before
|
|
@@ -125,13 +122,13 @@ export async function main(argv) {
|
|
|
125
122
|
}
|
|
126
123
|
// A checkout that pins its own rer package runs all of it, launching included.
|
|
127
124
|
// Until node_modules holds the pinned version (a fresh clone, or a pulled pin
|
|
128
|
-
// change),
|
|
125
|
+
// change), a command that runs project code installs it with the frozen lockfile and then
|
|
129
126
|
// runs the pinned verb, so a fresh clone checks and a changed pin deploys with
|
|
130
127
|
// the pinned bytes; the zero-setup launch installs it first.
|
|
131
128
|
// Verbs started at once share one install, and one whose pin already looks
|
|
132
129
|
// installed waits for an install still running.
|
|
133
130
|
const pinned = first && mode !== 'package' ? pinnedPackage(target.root) : undefined;
|
|
134
|
-
if (pinned && !pinned.ready && !argv.includes('--help') && installsFirst
|
|
131
|
+
if (pinned && !pinned.ready && !argv.includes('--help') && installsFirst) {
|
|
135
132
|
const { installPinned } = await import('./launch/install-pinned.mjs'), { LaunchFailure } = await import('./launch/failure.mjs');
|
|
136
133
|
try { await installPinned(target.root); }
|
|
137
134
|
catch (failure) {
|
|
@@ -142,7 +139,7 @@ export async function main(argv) {
|
|
|
142
139
|
return failure.exitCode;
|
|
143
140
|
}
|
|
144
141
|
}
|
|
145
|
-
if (mode === 'package' && installsFirst
|
|
142
|
+
if (mode === 'package' && installsFirst) await (await import('./launch/install-pinned.mjs')).settledPin(target.root);
|
|
146
143
|
if (verb === 'describe' && !argv.includes('--help')) return (await import('./cli/describe.mjs')).describeCommand(target);
|
|
147
144
|
if (first && dispatcher(target.root).mode !== 'bundled' && verb === 'verify' && !argv.includes('--help') && !argv.includes('--site')) {
|
|
148
145
|
const code = await (await import('./browser-runtime.mjs')).browserPreflight(target.root, target.args);
|
|
@@ -91,7 +91,7 @@ async function buildImage(root, { output = join(root,'.rer/container/image'), en
|
|
|
91
91
|
}
|
|
92
92
|
const base = resolve(import.meta.dirname,'../..');
|
|
93
93
|
for (const path of ['modules/container','modules/portability','modules/d1-transport','modules/deploy-kit','cli/scheduled.mjs','cli/jsonc.mjs','modules/integrations/core/public-address.ts']) { await mkdir(join(output,'runtime',path,'..'),{recursive:true}); await cp(join(base,path),join(output,'runtime',path),{recursive:true,filter:path => !path.includes('/tests/')}); }
|
|
94
|
-
const dependencies = { ws:'8.
|
|
94
|
+
const dependencies = { ws:'8.22.0', ...(engine === 'workerd' ? { miniflare:'5.20260907.0-alpha' } : {}) };
|
|
95
95
|
await writeFile(join(output,'runtime/package.json'),JSON.stringify({private:true,type:'module',dependencies}));
|
|
96
96
|
await writeFile(join(output,'Dockerfile'),`FROM node:26.8.1-bookworm-slim\nRUN apt-get update && apt-get install -y --no-install-recommends util-linux ca-certificates && apt-get clean\nRUN mkdir -p /private /archive\nWORKDIR /runtime\nCOPY runtime/package.json ./package.json\nRUN npm install --omit=dev --no-audit --no-fund\nCOPY runtime/ /runtime/\nCOPY app/ /app/\nENV NODE_ENV=production PORT=8080 WRANGLER_SEND_METRICS=false\nEXPOSE 8080\nVOLUME /data\nENTRYPOINT ["sh", "/runtime/modules/container/entrypoint.sh"]\n`);
|
|
97
97
|
return { output,manifest };
|
|
@@ -26,7 +26,7 @@ function parameters(sql) {
|
|
|
26
26
|
* and decoded in SQLite. Stored values and transaction boundaries are unchanged.
|
|
27
27
|
* Values whose encoding exceeds D1's bind ceiling remain native; rpcBytes then
|
|
28
28
|
* accounts for their effect on the ENTIRE call, never just that parameter. */
|
|
29
|
-
|
|
29
|
+
function encodeSql(statement) {
|
|
30
30
|
const { sql, params = [] } = statement;
|
|
31
31
|
if (!params.some(value => typeof value === 'string' && wide.test(value))) return { sql, params };
|
|
32
32
|
const tokens = parameters(sql), values = [...params], replacements = new Set();
|
|
@@ -57,33 +57,78 @@ export function wireSql(statement) {
|
|
|
57
57
|
return result;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
// Weak keys retain work only while the caller retains a statement. Snapshots
|
|
61
|
+
// validate replaced arrays and in-place changes; mutable binding objects bypass
|
|
62
|
+
// reuse because their JSON representation can change without changing identity.
|
|
63
|
+
const representations = new WeakMap();
|
|
64
|
+
const primitive = value => value === null || !['object', 'function'].includes(typeof value);
|
|
65
|
+
function representation(statement) {
|
|
66
|
+
const { sql, params = [] } = statement;
|
|
67
|
+
if (typeof sql !== 'string' || !Array.isArray(params) || !params.every(primitive)) return { sql, params };
|
|
68
|
+
const prior = representations.get(statement);
|
|
69
|
+
if (prior && prior.sql === sql && prior.params.length === params.length && params.every((value, index) => Object.is(value, prior.params[index]))) return prior;
|
|
70
|
+
const current = { sql, params: [...params] };
|
|
71
|
+
representations.set(statement, current);
|
|
72
|
+
return current;
|
|
73
|
+
}
|
|
74
|
+
const encoded = record => record.encoded ??= encodeSql(record);
|
|
75
|
+
function publicQuery(record, statement) {
|
|
76
|
+
const query = encoded(record);
|
|
77
|
+
// Public callers may mutate returned SQL and bindings. Never expose cached
|
|
78
|
+
// encoded state; retain the native parameter alias when no encoding occurred.
|
|
79
|
+
const result = { sql: query.sql, params: query.params === record.params ? statement.params ?? [] : [...query.params] };
|
|
80
|
+
if (result.params.every(primitive)) representations.set(result, { sql: result.sql, params: [...result.params], rawSize: record.encodedSize });
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
export function wireSql(statement) { return publicQuery(representation(statement), statement); }
|
|
84
|
+
|
|
60
85
|
/** A conservative size of D1's JSON request plus RPC envelope. A single wide
|
|
61
86
|
* character makes workerd serialize every UTF-16 code unit in the call at two
|
|
62
87
|
* bytes. UTF-8 also matters independently for provider payload limits. */
|
|
63
|
-
|
|
64
|
-
let utf8 =
|
|
88
|
+
function contribution(statement) {
|
|
89
|
+
let utf8 = 0, units = 0, hasWide = false;
|
|
65
90
|
const add = text => { utf8 += bytes(text); units += text.length; hasWide ||= wide.test(text); };
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
91
|
+
add('{"sql":' + JSON.stringify(statement.sql) + ',"params":[');
|
|
92
|
+
for (const value of statement.params ?? []) {
|
|
93
|
+
if (value instanceof ArrayBuffer || ArrayBuffer.isView(value)) {
|
|
94
|
+
// D1 sends binary bindings as numeric arrays. Four bytes per element is
|
|
95
|
+
// conservative and avoids constructing a second large byte array.
|
|
96
|
+
const size = 3 + value.byteLength * 4; utf8 += size; units += size;
|
|
97
|
+
} else add(JSON.stringify(value) + ',');
|
|
98
|
+
}
|
|
99
|
+
add(']},');
|
|
100
|
+
return { utf8, units, hasWide };
|
|
101
|
+
}
|
|
102
|
+
function combined(records, encode = false) {
|
|
103
|
+
let utf8 = 2, units = 2, hasWide = false;
|
|
104
|
+
for (const record of records) {
|
|
105
|
+
let size;
|
|
106
|
+
if (encode) {
|
|
107
|
+
const query = encoded(record);
|
|
108
|
+
size = record.encodedSize ??= query.params === record.params ? record.rawSize ??= contribution(record) : contribution(query);
|
|
109
|
+
} else size = record.rawSize ??= contribution(record);
|
|
110
|
+
utf8 += size.utf8; units += size.units; hasWide ||= size.hasWide;
|
|
76
111
|
}
|
|
77
112
|
return { utf8, units, hasWide };
|
|
78
113
|
}
|
|
114
|
+
export function rpcSize(statements) { return combined(statements.map(representation)); }
|
|
79
115
|
export const rpcSizeBytes = ({ utf8, units, hasWide }) => 4096 + Math.max(utf8, units * (hasWide ? 2 : 1));
|
|
80
116
|
export const rpcBytes = statements => rpcSizeBytes(rpcSize(statements));
|
|
81
117
|
|
|
82
|
-
|
|
83
|
-
const
|
|
118
|
+
function selectBatch(statements) {
|
|
119
|
+
const records = statements.map(representation), queries = records.map(encoded);
|
|
120
|
+
const nativeBytes = rpcSizeBytes(combined(records)), encodedBytes = rpcSizeBytes(combined(records, true));
|
|
84
121
|
// Dense CJK may be smaller as native two-byte text than as six-byte escapes.
|
|
85
|
-
//
|
|
86
|
-
return
|
|
122
|
+
// One wide value affects the complete call; ties retain encoded selection.
|
|
123
|
+
return nativeBytes < encodedBytes ? { queries: statements, bytes: nativeBytes, encoded: false, records } : { queries, bytes: encodedBytes, encoded: true, records };
|
|
124
|
+
}
|
|
125
|
+
export function wireBatch(statements) {
|
|
126
|
+
const selection = selectBatch(statements);
|
|
127
|
+
return selection.encoded ? selection.records.map((record, index) => publicQuery(record, statements[index])) : statements;
|
|
128
|
+
}
|
|
129
|
+
function sameQuery(left, right) {
|
|
130
|
+
const a = left.params ?? [], b = right.params ?? [];
|
|
131
|
+
return left.sql === right.sql && a.length === b.length && a.every((value, index) => primitive(value) && Object.is(value, b[index]));
|
|
87
132
|
}
|
|
88
133
|
|
|
89
134
|
/** Adapt only D1's prepare/batch boundary; native statements supplied by a
|
|
@@ -91,7 +136,7 @@ export function wireBatch(statements) {
|
|
|
91
136
|
export function wireDatabase(db) {
|
|
92
137
|
const statements = new WeakMap();
|
|
93
138
|
const prepare = (sql, params = []) => {
|
|
94
|
-
const original = { sql, params },
|
|
139
|
+
const original = { sql, params }, selection = selectBatch([original]), query = selection.queries[0];
|
|
95
140
|
const native = params.length ? db.prepare(query.sql).bind(...query.params) : db.prepare(sql);
|
|
96
141
|
const wrapped = new Proxy(native, { get(target, key) {
|
|
97
142
|
if (key === 'bind') return (...values) => prepare(sql, values);
|
|
@@ -102,19 +147,21 @@ export function wireDatabase(db) {
|
|
|
102
147
|
};
|
|
103
148
|
return typeof value === 'function' ? value.bind(target) : value;
|
|
104
149
|
} });
|
|
105
|
-
statements.set(wrapped, { native, query, original });
|
|
150
|
+
statements.set(wrapped, { native, query: { sql: query.sql, params: [...query.params] }, original });
|
|
106
151
|
return wrapped;
|
|
107
152
|
};
|
|
108
153
|
return new Proxy(db, { get(target, key) {
|
|
109
154
|
if (key === 'prepare') return prepare;
|
|
110
155
|
if (key === 'batch') return members => {
|
|
111
156
|
const known = members.map(member => statements.get(member));
|
|
112
|
-
const
|
|
113
|
-
|
|
157
|
+
const selection = selectBatch(known.filter(Boolean).map(member => member.original));
|
|
158
|
+
const queries = selection.queries;
|
|
159
|
+
if (selection.bytes > RPC_LIMIT) throw new Error('D1_RPC_TRANSPORT_LIMIT');
|
|
114
160
|
let index = 0;
|
|
115
161
|
return db.batch(members.map((member, i) => {
|
|
116
162
|
if (!known[i]) return member;
|
|
117
163
|
const query = queries[index++];
|
|
164
|
+
if (sameQuery(query, known[i].query)) return known[i].native;
|
|
118
165
|
return query.params?.length ? db.prepare(query.sql).bind(...query.params) : db.prepare(query.sql);
|
|
119
166
|
}));
|
|
120
167
|
};
|
package/modules/demo/README.md
CHANGED
|
@@ -28,11 +28,17 @@ Production build/deploy refuses that setting; ordinary builds keep real effects.
|
|
|
28
28
|
Put `data-rer-name` on the product's text label, for example
|
|
29
29
|
`<span data-rer-name>Uptime</span>`, to show **Uptime Demo** in its nav.
|
|
30
30
|
The same attribute shows **Uptime Dev** under the local dev wrapper. No bar,
|
|
31
|
-
layout offset or timer is injected.
|
|
31
|
+
layout offset or timer is injected. In demo mode a **Run <Seed>** link sits
|
|
32
|
+
beside each marked navigation label and opens `https://<domain>/run`. The
|
|
33
|
+
existing `demoSockets()` Vite plugin supplies the public `name` and canonical
|
|
34
|
+
run-site `domain` from `deploy-demo.json` and the command adapter's
|
|
35
|
+
`site.declaration` (normally `deploy-site.json`); an explicit HTTPS `/run`
|
|
36
|
+
`runUrl` in the demo declaration takes precedence and is validated for both
|
|
37
|
+
local and hosted demos. No per-seed link is required. CSS adds the label suffix without
|
|
32
38
|
changing the application's hydrated text; CSP allows exact hashes only.
|
|
33
39
|
|
|
34
40
|
Public sockets, WebSockets and event streams remain usable for checks. The
|
|
35
41
|
local sockets guard and hosted egress retain a small direct mail/SMS denylist;
|
|
36
42
|
use the effect helper for such sends. Hosted demos keep their isolated
|
|
37
43
|
container, Turnstile, per-IP start limit, TTL/idle end and maximum instances.
|
|
38
|
-
See [adoption and hosting](
|
|
44
|
+
See [adoption and hosting](https://github.com/runeditrun/base/blob/main/export/DEMO.md).
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { containedInput } from './input-path.mjs';
|
|
3
|
+
import { pathToFileURL } from 'node:url';
|
|
4
|
+
|
|
5
|
+
export async function demoRunDeclaration(declaration, { root, adapter, read } = {}) {
|
|
6
|
+
if (declaration.runUrl !== undefined) return declaration;
|
|
7
|
+
read ??= async path => JSON.parse(await readFile(await containedInput(root, path), 'utf8'));
|
|
8
|
+
let bare = false;
|
|
9
|
+
if (adapter === undefined) {
|
|
10
|
+
let operations;
|
|
11
|
+
try { operations = await read('OPERATIONS.json'); }
|
|
12
|
+
catch (error) { if (error.code !== 'ENOENT') throw error; bare = true; }
|
|
13
|
+
if (operations?.seedContract) adapter = (await import(pathToFileURL(await containedInput(root, operations.seedContract.adapter)).href)).commandAdapter;
|
|
14
|
+
}
|
|
15
|
+
const path = adapter?.site?.declaration ?? (bare ? 'deploy-site.json' : undefined);
|
|
16
|
+
if (!path) return declaration;
|
|
17
|
+
let site;
|
|
18
|
+
try { site = await read(path); }
|
|
19
|
+
catch (error) { if (!bare || error.code !== 'ENOENT') throw error; }
|
|
20
|
+
return site ? { ...declaration, runUrl: `https://${site.domain}/run` } : declaration;
|
|
21
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { lstat, realpath } from 'node:fs/promises';
|
|
2
|
+
import { isAbsolute, relative, resolve, sep } from 'node:path';
|
|
3
|
+
|
|
4
|
+
// The CLI and standalone Vite copy share checkout-path resolution. The CLI
|
|
5
|
+
// supplies its public diagnostics; other callers retain filesystem errors.
|
|
6
|
+
export async function containedInput(root, path, { optional = false, privateFile = false, refuse = message => new Error(message), missing = (_message, error) => error } = {}) {
|
|
7
|
+
if (typeof path !== 'string' || !path || isAbsolute(path) || path.split(/[\\/]/).some(part => part === '..' || part === '')) throw refuse('Path must be a contained checkout path without traversal.');
|
|
8
|
+
const checkout = await realpath(root), destination = resolve(checkout, path), parts = relative(checkout, destination).split(sep);
|
|
9
|
+
let current = checkout;
|
|
10
|
+
for (let i = 0; i < parts.length; i++) {
|
|
11
|
+
current = resolve(current, parts[i]);
|
|
12
|
+
let status; try { status = await lstat(current); } catch (error) { if (error.code === 'ENOENT' && optional) return destination; if (error.code === 'ENOENT') throw missing(`Missing input file: ${path}. See the project operating documentation.`, error); throw error; }
|
|
13
|
+
if (status.isSymbolicLink()) throw refuse(`Symlink refused at ${path}; preserve it and resolve placement first.`);
|
|
14
|
+
if (i < parts.length - 1 && !status.isDirectory()) throw refuse(`Unsafe path ancestor for ${path}.`);
|
|
15
|
+
if (privateFile && i === parts.length - 1 && (!status.isFile() || status.nlink !== 1 || (status.mode & 0o077) !== 0 || (process.getuid && status.uid !== process.getuid()))) throw refuse(`Input must be an owned regular private file (0600): ${path}.`);
|
|
16
|
+
}
|
|
17
|
+
return destination;
|
|
18
|
+
}
|
package/modules/demo/label.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** Suffix the document title and the text marked data-rer-name, without a bar. */
|
|
2
|
-
export function decorateLabel(response: Response, mode: 'Demo' | 'Dev'): Promise<Response>;
|
|
2
|
+
export function decorateLabel(response: Response, mode: 'Demo' | 'Dev', exit?: { name: string; url: string } | null): Promise<Response>;
|
package/modules/demo/label.mjs
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { allow, sha256 } from '../operator-auth/csp.mjs';
|
|
2
|
+
import { NAVIGATION_SCRIPT, NAVIGATION_STYLE } from './navigation.mjs';
|
|
3
|
+
|
|
4
|
+
const escape = value => String(value).replace(/[&<>"']/g, character => `&#${character.charCodeAt(0)};`);
|
|
2
5
|
|
|
3
6
|
// CSS leaves React's text alone during hydration. The title observer handles
|
|
4
7
|
// client-side route changes, whose head manager writes a fresh title. The script
|
|
@@ -6,25 +9,27 @@ import { allow, sha256 } from '../operator-auth/csp.mjs';
|
|
|
6
9
|
// on the label's style element, never as code.
|
|
7
10
|
const SCRIPT = "(()=>{const suffix=document.querySelector('style[data-rer-label]').dataset.rerLabel,update=()=>{const base=document.title.replace(/\\s*(?:Demo|Dev)$/,''),title=(base?base+' ':'')+suffix;if(document.title!==title)document.title=title};update();new MutationObserver(update).observe(document.head,{childList:true,subtree:true,characterData:true})})()";
|
|
8
11
|
|
|
9
|
-
export async function decorateLabel(response, mode) {
|
|
12
|
+
export async function decorateLabel(response, mode, exit = import.meta.rerDemo) {
|
|
10
13
|
if (!response.body || !response.headers.get('content-type')?.toLowerCase().startsWith('text/html')) return response;
|
|
11
14
|
const suffix = mode === 'Demo' ? 'Demo' : 'Dev';
|
|
12
|
-
const style = `[data-rer-name]::after{content:" ${suffix}"}`;
|
|
15
|
+
const style = `[data-rer-name]::after{content:" ${suffix}"}${suffix === 'Demo' && exit ? NAVIGATION_STYLE : ''}`;
|
|
16
|
+
const script = SCRIPT + ';' + (suffix === 'Demo' && exit ? NAVIGATION_SCRIPT : '');
|
|
13
17
|
const html = await response.text();
|
|
14
18
|
if (html.includes('data-rer-label=')) return new Response(html, response);
|
|
15
19
|
const headers = new Headers(response.headers);
|
|
16
20
|
let policy = headers.get('content-security-policy');
|
|
17
21
|
if (policy) {
|
|
18
22
|
policy = allow(policy, 'style-src', await sha256(style));
|
|
19
|
-
headers.set('content-security-policy', allow(policy, 'script-src', await sha256(
|
|
23
|
+
headers.set('content-security-policy', allow(policy, 'script-src', await sha256(script)));
|
|
20
24
|
}
|
|
21
25
|
headers.delete('content-length');
|
|
22
26
|
headers.delete('etag');
|
|
23
|
-
const
|
|
27
|
+
const metadata = suffix === 'Demo' && exit ? ` data-rer-product="${escape(exit.name)}" data-rer-run="${escape(exit.url)}"` : '';
|
|
28
|
+
const addition = `<style data-rer-label="${suffix}"${metadata}>${style}</style><script>${script}</script>`;
|
|
24
29
|
const titled = html.replace(/(<title\b[^>]*>)([\s\S]*?)(<\/title>)/i, (_, open, title, close) => {
|
|
25
30
|
const base = title.replace(/\s*(?:Demo|Dev)$/, '');
|
|
26
31
|
return `${open}${base ? `${base} ` : ''}${suffix}${close}`;
|
|
27
32
|
});
|
|
28
|
-
const body = /<\/head\s*>/i.test(titled) ? titled.replace(/<\/head\s*>/i, `${addition}</head>`) : addition + titled;
|
|
33
|
+
const body = /<\/head\s*>/i.test(titled) ? titled.replace(/<\/head\s*>/i, () => `${addition}</head>`) : addition + titled;
|
|
29
34
|
return new Response(body, { status: response.status, statusText: response.statusText, headers });
|
|
30
35
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Runs after the app's initial hydration, then follows its client navigation.
|
|
2
|
+
// Each exit belongs beside an existing marked product label, never in a bar.
|
|
3
|
+
export const NAVIGATION_SCRIPT = `(() => {
|
|
4
|
+
const settings = document.querySelector('style[data-rer-label]');
|
|
5
|
+
if (!settings.dataset.rerRun) return;
|
|
6
|
+
const update = () => {
|
|
7
|
+
for (const label of document.querySelectorAll('[data-rer-name]')) {
|
|
8
|
+
const position = label.closest('a,button') ?? label;
|
|
9
|
+
if (position.nextElementSibling?.hasAttribute('data-rer-demo-exit')) continue;
|
|
10
|
+
const link = document.createElement('a');
|
|
11
|
+
link.setAttribute('data-rer-demo-exit', '');
|
|
12
|
+
link.href = settings.dataset.rerRun;
|
|
13
|
+
link.textContent = 'Run ' + settings.dataset.rerProduct;
|
|
14
|
+
position.after(link);
|
|
15
|
+
const layout = getComputedStyle(position.parentElement);
|
|
16
|
+
if (label.scrollWidth > label.clientWidth && layout.display.includes('flex') && layout.flexWrap === 'nowrap') {
|
|
17
|
+
link.style.width = 'min-content';
|
|
18
|
+
link.style.whiteSpace = 'normal';
|
|
19
|
+
link.style.textAlign = 'center';
|
|
20
|
+
link.style.marginInlineStart = '0';
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const start = () => {
|
|
25
|
+
update();
|
|
26
|
+
new MutationObserver(update).observe(document.body, { childList: true, subtree: true });
|
|
27
|
+
};
|
|
28
|
+
const ready = () => window.requestAnimationFrame(() => window.requestAnimationFrame(start));
|
|
29
|
+
if (document.readyState === 'complete') ready();
|
|
30
|
+
else window.addEventListener('load', ready, { once: true });
|
|
31
|
+
})()`;
|
|
32
|
+
export const NAVIGATION_STYLE = '[data-rer-demo-exit]{display:inline-block;flex-shrink:0;margin-inline-start:.5em;color:var(--rer-link,inherit);font:inherit;font-size:13px;font-weight:400;line-height:1.5;white-space:nowrap;text-decoration:underline;text-underline-offset:3px}[data-rer-demo-exit]:focus-visible{outline:2px solid var(--rer-focus,currentColor);outline-offset:3px}';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Shared by Vite and the hosted plan; this file also travels with src/modules/demo.
|
|
2
|
+
export function demoRunUrl(value) {
|
|
3
|
+
if (typeof value !== 'string' || !/^https:\/\//i.test(value) || /[\s\p{Cc}\\]/u.test(value)) throw new Error('invalid-demo-run-url');
|
|
4
|
+
let run;
|
|
5
|
+
try { run = new URL(value); } catch { throw new Error('invalid-demo-run-url'); }
|
|
6
|
+
if (run.protocol !== 'https:' || run.username || run.password || run.pathname !== '/run' || run.search || run.hash) throw new Error('invalid-demo-run-url');
|
|
7
|
+
if (run.hostname.length > 253 || !/^(?!www\.)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z][a-z0-9-]{0,62}$/.test(run.hostname)) throw new Error('invalid-site-domain');
|
|
8
|
+
return run.href;
|
|
9
|
+
}
|
package/modules/demo/vite.d.mts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
export function demoSockets(): {
|
|
1
|
+
/** Supplies public demo navigation metadata and guards local demo sockets. */
|
|
2
|
+
export function demoSockets(): {
|
|
3
|
+
name: string;
|
|
4
|
+
enforce: 'pre';
|
|
5
|
+
config(config: { root?: string }, environment: { command: string }): Promise<object>;
|
|
6
|
+
resolveId(id: string): string | undefined;
|
|
7
|
+
};
|
package/modules/demo/vite.mjs
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { fileURLToPath } from 'node:url';
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
import { demoRunDeclaration } from './declaration.mjs';
|
|
5
|
+
import { demoRunUrl } from './run-url.mjs';
|
|
2
6
|
|
|
3
7
|
// A module namespace cannot be patched at runtime, so under `rer demo`
|
|
4
8
|
// (RER_DEMO=1) Vite hands the Worker's `cloudflare:sockets` imports the guarded
|
|
@@ -8,10 +12,21 @@ export function demoSockets() {
|
|
|
8
12
|
const on = () => process.env.RER_DEMO === '1';
|
|
9
13
|
return {
|
|
10
14
|
name: 'rer-demo-sockets',
|
|
11
|
-
apply: 'serve',
|
|
12
15
|
enforce: 'pre',
|
|
13
16
|
// Vite resolves a Worker's builtin import only when an alias names it.
|
|
14
|
-
config
|
|
17
|
+
async config(config, { command }) {
|
|
18
|
+
let declaration;
|
|
19
|
+
try { declaration = JSON.parse(await readFile(resolve(config.root ?? process.cwd(), 'deploy-demo.json'), 'utf8')); }
|
|
20
|
+
catch (error) {
|
|
21
|
+
if (error.code !== 'ENOENT') throw error;
|
|
22
|
+
if (on()) throw new Error('rer demo needs deploy-demo.json with the product name and canonical run-site domain. See DEMO.md.');
|
|
23
|
+
}
|
|
24
|
+
const resolved = declaration && await demoRunDeclaration(declaration, { root: config.root ?? process.cwd() });
|
|
25
|
+
return {
|
|
26
|
+
define: { 'import.meta.rerDemo': JSON.stringify(resolved ? { name: resolved.name, url: demoRunUrl(resolved.runUrl === undefined ? `https://${resolved.domain}/run` : resolved.runUrl) } : null) },
|
|
27
|
+
...(on() && command === 'serve' ? { resolve: { alias: [{ find: /^cloudflare:sockets$/, replacement: 'cloudflare:sockets' }] } } : {}),
|
|
28
|
+
};
|
|
29
|
+
},
|
|
15
30
|
resolveId(id) {
|
|
16
31
|
if (on() && id === 'cloudflare:sockets') return guarded;
|
|
17
32
|
},
|