@runeditrun/rer 0.2.111 → 0.2.112
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 +15 -2
- package/cli/README.md +56 -0
- package/cli/deploy-command.mjs +2 -0
- package/cli/deploy-policy.mjs +17 -0
- package/cli/lifecycle.mjs +2 -0
- package/cli/portability.mjs +3 -3
- package/global/CHANGELOG.md +19 -0
- package/global/README.md +15 -2
- package/global/cli/install.mjs +1 -1
- package/global/main.mjs +3 -0
- package/global/run.mjs +15 -2
- package/install.sh +3 -0
- package/modules/portability/progress.mjs +12 -10
- package/onboarding/commands.mjs +17 -8
- package/onboarding/migration-progress.mjs +69 -0
- package/onboarding/operator-migrations.mjs +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ Allow roughly 500 MB–1 GB of downloads and 1–3 GB of disk space for a first
|
|
|
5
5
|
<!-- END COLD RUN BUDGET -->
|
|
6
6
|
|
|
7
7
|
`rer` is the Run Edit Run command. Install it once, then run `rer <verb>` in any
|
|
8
|
-
Run Edit Run checkout:
|
|
8
|
+
Run Edit Run checkout: project verbs run that checkout's own pinned copy, so a
|
|
9
9
|
checkout always gets the behaviour it was built and tested with.
|
|
10
10
|
|
|
11
11
|
For source authors, `rer adopt-edition` adds a recipe and lock to existing tracked
|
|
@@ -47,7 +47,20 @@ changing PATH: a child installer cannot change its parent shell’s PATH, and ba
|
|
|
47
47
|
`~/.local/bin`, its closing lines give one required step: the
|
|
48
48
|
`export PATH="$HOME/.local/bin:$PATH"` line to run now and add to your shell
|
|
49
49
|
startup file, or `rer cli path` (by its absolute launcher) for other shells.
|
|
50
|
-
|
|
50
|
+
To run a downloaded JavaScript tool, open its folder in the terminal and use
|
|
51
|
+
`"$HOME/.local/bin/rer" run --script ./tool.mjs` followed by its arguments.
|
|
52
|
+
For example, from Downloads the Oncall PagerDuty exporter runs with:
|
|
53
|
+
|
|
54
|
+
```sh
|
|
55
|
+
"$HOME/.local/bin/rer" run --script ./oncall-export.mjs pagerduty
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
`--script` uses the Node running `rer`, including the installer's private Node;
|
|
59
|
+
it needs no checkout, pnpm or separate Node installation. The file path is
|
|
60
|
+
relative to the current folder, or to `--cwd DIR` when supplied before
|
|
61
|
+
`--script`. Remaining arguments go directly to the file. A package script
|
|
62
|
+
(`rer run NAME`) continues to use the checkout's pinned Node and pnpm.
|
|
63
|
+
The app start also fits on one line:
|
|
51
64
|
|
|
52
65
|
```sh
|
|
53
66
|
curl -fsSL https://runeditrun.com/install.sh | sh -s -- dev just-every/run-inkwell
|
package/cli/README.md
CHANGED
|
@@ -468,6 +468,62 @@ retirement and preserve the environment, checkout and env-file in recovery
|
|
|
468
468
|
commands. Retirement can be finished with `rer deploy --unset-secret SETUP_TOKEN`
|
|
469
469
|
plus the same `--environment`, `--env-file` and `--cwd` arguments.
|
|
470
470
|
|
|
471
|
+
A seed may declare an optional `commandAdapter.deployPolicy` function:
|
|
472
|
+
|
|
473
|
+
```js
|
|
474
|
+
import { missing } from '@runeditrun/rer/errors';
|
|
475
|
+
|
|
476
|
+
const deployPolicy = async ({ root, options, environment, env, bindings,
|
|
477
|
+
declaration, declarationPath }) => {
|
|
478
|
+
// Normalize any seed-specific choices in a local copy, then validate the
|
|
479
|
+
// applicable operation. Binding values already resolve declared env aliases.
|
|
480
|
+
if (options.setSecret && env.MAIL_MODE === 'off'
|
|
481
|
+
&& options.setSecret.split(',').some(name => name === 'OUTBOUND_TOKEN' && bindings[name]?.trim())) {
|
|
482
|
+
throw missing('Credentials are not bound while email is off.');
|
|
483
|
+
}
|
|
484
|
+
};
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
The public application `rer deploy` door awaits this hook once, before dispatching
|
|
488
|
+
any build, custom deploy hook or owner-account provider operation, including
|
|
489
|
+
account/subdomain lookup and receipt recovery. It runs for ordinary deploy,
|
|
490
|
+
`--dry-run`, `--set-secret`, `--unset-secret`, `--rotate-secret`,
|
|
491
|
+
`--reopen-installation-key` and `--remove`; the seed chooses which policy applies
|
|
492
|
+
to each operation, allowing cleanup where appropriate. Run-site, hosted-demo and
|
|
493
|
+
independent-command doors retain their own contracts. A policy must stay local:
|
|
494
|
+
no provider calls, build, settings writes or secret output.
|
|
495
|
+
|
|
496
|
+
`options` is a copy of the parsed CLI options: repeated/comma-separated secret
|
|
497
|
+
flags have their usual deduplicated binding-name list. `environment` defaults to
|
|
498
|
+
`production`. `env` is the effective deploy environment (process environment,
|
|
499
|
+
then the owned `--env-file` override, then existing declared owner/generated
|
|
500
|
+
input supply). `bindings` starts with declaration `vars` and overlays nonblank
|
|
501
|
+
secret values under their declared Worker binding names, using each secret's
|
|
502
|
+
`environment` mapping. For example, `{binding:'OUTBOUND_TOKEN',
|
|
503
|
+
environment:'EMAIL_API_KEY'}` exposes `env.EMAIL_API_KEY` as
|
|
504
|
+
`bindings.OUTBOUND_TOKEN`; ambient `env.OUTBOUND_TOKEN` cannot override that
|
|
505
|
+
mapping. These are proposed local inputs, not a read of existing hosted secrets.
|
|
506
|
+
`root`, `declaration` and checkout-relative `declarationPath` name the selected
|
|
507
|
+
checkout and deploy declaration. Values are private; do not log them.
|
|
508
|
+
|
|
509
|
+
This is a validation hook: treat inputs as read-only; its return value is ignored.
|
|
510
|
+
Seed-specific provider enums and additional aliases remain the seed's job:
|
|
511
|
+
normalize them into a local copy before checking policy. Keep any deploy hook's
|
|
512
|
+
existing runtime normalization. A successful policy returns normally; throw a
|
|
513
|
+
`RerError` from the same rer copy/package to refuse. `missing(message)` gives exit
|
|
514
|
+
3 and JSON `error` with `code:"missing_input"`, `message`, `exitCode:3`, followed
|
|
515
|
+
by `result` with `ok:false`, `exitCode:3`; `refuse(message)` retains the existing
|
|
516
|
+
exit-4 `safety_refusal`. Other errors retain the existing command-failure path.
|
|
517
|
+
A refusal stops before any provider contact. A declared non-function policy is
|
|
518
|
+
an invalid invocation (exit 2).
|
|
519
|
+
|
|
520
|
+
Seeds without this optional hook keep the existing contract: secret mutations
|
|
521
|
+
use the owner-account controller's declaration, value and ownership checks,
|
|
522
|
+
without invoking the application's build/deploy hook or the full-deploy
|
|
523
|
+
production-auth preflight. Full deployments still run that shared preflight.
|
|
524
|
+
No seed-specific mail policy is inferred. Low-level kit/controller callers remain
|
|
525
|
+
responsible for their own policy; this hook belongs to the public CLI adapter.
|
|
526
|
+
|
|
471
527
|
## Local business signals
|
|
472
528
|
|
|
473
529
|
`rer business scan [DIR...] [--json]` reads local source and configuration names;
|
package/cli/deploy-command.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { requireProductionAuth, mailOffNotice } from './production-auth.mjs';
|
|
2
|
+
import { enforceDeployPolicy } from './deploy-policy.mjs';
|
|
2
3
|
import { observedReadiness } from '../modules/deploy-kit/readiness-window.mjs';
|
|
3
4
|
import { readFile, readdir } from 'node:fs/promises';
|
|
4
5
|
import { contained } from './project.mjs';
|
|
@@ -80,6 +81,7 @@ export async function deployCommand(context) {
|
|
|
80
81
|
if (local) throw refuse(`${path} names the local-only key ${local} as a deploy binding or secret. Remove it; local dev keys never reach a deployment.`);
|
|
81
82
|
deployGuide(declaration);
|
|
82
83
|
const settings = adapter.hooks?.secrets ?? adapter.settings;
|
|
84
|
+
await enforceDeployPolicy({ ...context, declaration, declarationPath: path, settings });
|
|
83
85
|
// Required secrets have been checked; retain the production sign-in guidance.
|
|
84
86
|
const dryRun = async (result, { planned = true, extraNeeded } = {}) => {
|
|
85
87
|
const production = await deployEnvironment({ root, options, declaration, setupManifest, settings, localOnlyKeys });
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { deployEnvironment } from './deploy-inputs.mjs';
|
|
2
|
+
import { invalid } from './errors.mjs';
|
|
3
|
+
|
|
4
|
+
// Seed policy is separate from uploading: secret-only commands bypass the
|
|
5
|
+
// deploy hook, but must not bypass a seed's applicable local input policy.
|
|
6
|
+
export async function enforceDeployPolicy({ adapter, root, options, setupManifest, localOnlyKeys, declaration, declarationPath, settings }) {
|
|
7
|
+
if (adapter.deployPolicy === undefined) return;
|
|
8
|
+
if (typeof adapter.deployPolicy !== 'function') throw invalid('The adapter deployPolicy must be a function.');
|
|
9
|
+
const { env } = await deployEnvironment({ root, options, declaration, setupManifest, settings, localOnlyKeys });
|
|
10
|
+
// Resolve declared environment aliases before policy sees Worker bindings.
|
|
11
|
+
// Arbitrary ambient binding-name values never override an explicit mapping.
|
|
12
|
+
const bindings = { ...declaration.vars };
|
|
13
|
+
for (const secret of declaration.secrets ?? []) {
|
|
14
|
+
if (env[secret.environment]?.trim()) bindings[secret.binding] = env[secret.environment];
|
|
15
|
+
}
|
|
16
|
+
await adapter.deployPolicy({ root, options: { ...options }, environment: options.environment ?? 'production', env, bindings, declaration, declarationPath });
|
|
17
|
+
}
|
package/cli/lifecycle.mjs
CHANGED
|
@@ -163,6 +163,8 @@ async function runLifecycle(project, options, out, deployRedaction) {
|
|
|
163
163
|
const deployNeeds = await hostedNeeds(project);
|
|
164
164
|
if (options.json) out.event('setup-ready', { url, setupUrl: url+'/setup', ...(deployNeeds.length ? { neededForDeploy: deployNeeds } : {}) });
|
|
165
165
|
else {
|
|
166
|
+
const { checkoutPath } = await shared('step-failure.mjs');
|
|
167
|
+
out.human(`Setup complete: ${state.migrationsApplied ? `${state.migrationsApplied} migration${state.migrationsApplied === 1 ? '' : 's'} applied` : 'database already up to date'}, owner set up. Full output: ${store.redact(checkoutPath(project.root, store.logPath))}`);
|
|
166
168
|
out.human(`RER_SETUP_READY ${url}`); out.human(`Next: rer dev opens ${url} signed in as the owner; first-run setup finishes at ${url}/setup. rer preview prints a one-time native owner link on loopback; rer demo also prints a separate native owner entry.`);
|
|
167
169
|
if (deployNeeds.length) out.human(['To host it on your own Cloudflare account later, rer deploy needs:', ...deployNeeds.map(item => ` - ${item}`), 'Set them in your environment or a private (mode 0600) file passed with --env-file, then check with rer deploy --dry-run.'].join('\n'));
|
|
168
170
|
}
|
package/cli/portability.mjs
CHANGED
|
@@ -73,11 +73,11 @@ export function localPortability({ database, binding = 'DB', buckets = {}, polic
|
|
|
73
73
|
if(unverifiedSchemaRecovery)await nativeWorker(store,'schema-recovery-preflight',input,signal);
|
|
74
74
|
const {nativeApply}=await nativeWorker(store,'migration-preflight',input,signal);
|
|
75
75
|
// Local migrations need no provider account: wrangler runs without credentials.
|
|
76
|
-
//
|
|
77
|
-
//
|
|
76
|
+
// The shared runner shows its progress (a count every ten migrations) and leaves out its
|
|
77
|
+
// own info lines, which only confuse a local backup; warnings and errors print.
|
|
78
78
|
const { dependencyEnvironment } = await shared('dependency-environment.mjs');
|
|
79
79
|
if(nativeApply)await store.run('Applying local data migrations', 'pnpm', ['exec', 'wrangler', 'd1', 'migrations', 'apply', database, '--local', '--persist-to', '.wrangler/state', '--config', 'wrangler.jsonc'], {
|
|
80
|
-
cwd: root, signal, env: { ...dependencyEnvironment(), RER_LOCAL_OPERATION: operationToken, WRANGLER_SEND_METRICS: 'false'
|
|
80
|
+
cwd: root, signal, env: { ...dependencyEnvironment(), RER_LOCAL_OPERATION: operationToken, WRANGLER_SEND_METRICS: 'false' },
|
|
81
81
|
});
|
|
82
82
|
const receipt=await nativeWorker(store,direction,input,signal);
|
|
83
83
|
if(legacyRecovery)receipt.output=relative(root,legacyRecovery.output);
|
package/global/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.112
|
|
4
|
+
|
|
5
|
+
### Downloaded tools and export progress
|
|
6
|
+
|
|
7
|
+
- `rer run --script FILE [ARGS...]` runs a downloaded JavaScript file with the Node running rer, including the installer's private Node, outside a project checkout and without `node` or pnpm on PATH. It preserves the working folder, arguments and exit status; `--cwd DIR` before `--script` selects the folder. Package scripts (`rer run NAME`) continue to use the checkout's pinned runtime. The installer and local instructions show this door; it becomes available when the installed rer is upgraded.
|
|
8
|
+
- Local installation export labels allocated disk space separately from archive size and leaves building time indeterminate until the total work is known. It no longer forecasts archive size or building time from unused database pages and temporary state; known-total writing and staging phases retain their progress estimates. CLI progress only; the archive format is unchanged.
|
|
9
|
+
|
|
10
|
+
### Setup, import and export migration output
|
|
11
|
+
|
|
12
|
+
- `wrangler d1 migrations apply` run through rer's command runner, including a seed's setup, import or export adapter, shows `Applying migrations N/M` every ten migrations, warnings and errors, and one `Applied N migrations. Full output: <log>` summary. Repeated tables and boilerplate stay in the full log. A failed migration names itself and keeps wrangler's error and log path; an error without a failed row is associated with the first listed migration that did not finish. Shared local import and export now show this progress instead of silencing the whole apply.
|
|
13
|
+
- A finished `rer setup` adds a result line before `RER_SETUP_READY`: the number of migrations applied (or that the database is already up to date), owner setup and the full-output log path. Seeds get these command-runner and setup changes after adopting this rer through their pinned CLI.
|
|
14
|
+
|
|
15
|
+
### Optional seed deploy policy
|
|
16
|
+
|
|
17
|
+
- Application `rer deploy` awaits optional `commandAdapter.deployPolicy({ root, options, environment, env, bindings, declaration, declarationPath })` once after basic CLI-option and declaration checks, before downstream deploy validation, builds, custom deploy hooks or owner-account provider contact, including secret-only updates and receipt recovery. `env` carries effective proposed local inputs; `bindings` overlays declaration vars with nonblank secrets mapped from their declared environment names, so an ambient binding-name value cannot override an explicit mapping. These are proposed inputs, not hosted secret readback.
|
|
18
|
+
- The hook is local validation: inputs are read-only, its return value is ignored, and it must make no provider calls, builds, settings writes or secret output. A seed can reject applicable operations with `missing(message)` from the same rer copy/package (exit 3, `missing_input`); `refuse(message)` retains exit 4. Seeds without the hook keep their existing deployment checks. This releases CLI support only: each seed must adopt the CLI and implement its own policy, including normalization of its provider choices and aliases. No seed-specific mail policy is inferred, and this release establishes no installed mail-OFF or deployed behavior.
|
|
19
|
+
|
|
20
|
+
Code and documentation only: the actual diff adds no migration. Nothing here establishes seed adoption or changes a deployed seed; each seed must adopt and deploy its own changes.
|
|
21
|
+
|
|
3
22
|
## 0.2.111
|
|
4
23
|
|
|
5
24
|
### `rer size`: statement size and growth with data
|
package/global/README.md
CHANGED
|
@@ -5,7 +5,7 @@ Allow roughly 500 MB–1 GB of downloads and 1–3 GB of disk space for a first
|
|
|
5
5
|
<!-- END COLD RUN BUDGET -->
|
|
6
6
|
|
|
7
7
|
`rer` is the Run Edit Run command. Install it once, then run `rer <verb>` in any
|
|
8
|
-
Run Edit Run checkout:
|
|
8
|
+
Run Edit Run checkout: project verbs run that checkout's own pinned copy, so a
|
|
9
9
|
checkout always gets the behaviour it was built and tested with.
|
|
10
10
|
|
|
11
11
|
For source authors, `rer adopt-edition` adds a recipe and lock to existing tracked
|
|
@@ -47,7 +47,20 @@ changing PATH: a child installer cannot change its parent shell’s PATH, and ba
|
|
|
47
47
|
`~/.local/bin`, its closing lines give one required step: the
|
|
48
48
|
`export PATH="$HOME/.local/bin:$PATH"` line to run now and add to your shell
|
|
49
49
|
startup file, or `rer cli path` (by its absolute launcher) for other shells.
|
|
50
|
-
|
|
50
|
+
To run a downloaded JavaScript tool, open its folder in the terminal and use
|
|
51
|
+
`"$HOME/.local/bin/rer" run --script ./tool.mjs` followed by its arguments.
|
|
52
|
+
For example, from Downloads the Oncall PagerDuty exporter runs with:
|
|
53
|
+
|
|
54
|
+
```sh
|
|
55
|
+
"$HOME/.local/bin/rer" run --script ./oncall-export.mjs pagerduty
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
`--script` uses the Node running `rer`, including the installer's private Node;
|
|
59
|
+
it needs no checkout, pnpm or separate Node installation. The file path is
|
|
60
|
+
relative to the current folder, or to `--cwd DIR` when supplied before
|
|
61
|
+
`--script`. Remaining arguments go directly to the file. A package script
|
|
62
|
+
(`rer run NAME`) continues to use the checkout's pinned Node and pnpm.
|
|
63
|
+
The app start also fits on one line:
|
|
51
64
|
|
|
52
65
|
```sh
|
|
53
66
|
curl -fsSL https://runeditrun.com/install.sh | sh -s -- dev just-every/run-inkwell
|
package/global/cli/install.mjs
CHANGED
|
@@ -44,7 +44,7 @@ async function writeLauncher(paths) {
|
|
|
44
44
|
const shellQuote = value => "'" + value.replaceAll("'", "'\"'\"'") + "'";
|
|
45
45
|
async function closing(paths) {
|
|
46
46
|
const notices = await pathAdvice(paths, process.env, { includeShellStep: false });
|
|
47
|
-
return (notices ? notices + '\n' : '') + (process.env.RER_INSTALL_NO_NEXT ? '' : `
|
|
47
|
+
return (notices ? notices + '\n' : '') + (process.env.RER_INSTALL_NO_NEXT ? '' : `Run a downloaded JavaScript tool with the installed runtime: ${shellQuote(paths.launcher)} run --script ./tool.mjs [ARGS...]\nNext, start an app: ${shellQuote(paths.launcher)} dev <owner>/<repo>\n`);
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
export async function install({ quiet = false } = {}) {
|
package/global/main.mjs
CHANGED
|
@@ -28,6 +28,9 @@ else its vendored scripts/rer.mjs.
|
|
|
28
28
|
rer run SCRIPT [ARGS]
|
|
29
29
|
Run a package.json script with the pnpm and Node the checkout pins (rer keeps
|
|
30
30
|
them off PATH): where a project's docs say pnpm run X, run rer run X.
|
|
31
|
+
rer run --script FILE [ARGS]
|
|
32
|
+
Run a downloaded JavaScript file with rer's Node, including its private runtime.
|
|
33
|
+
Works outside a checkout; FILE is relative to here (or --cwd DIR).
|
|
31
34
|
rer list [DIR] The checkouts in DIR (default: here), newest first, with whether rer dev can
|
|
32
35
|
launch them, whether they are set up, and their running URL. --json for data.
|
|
33
36
|
rer business ... Set up your business once and share its name, logo and brand colour
|
package/global/run.mjs
CHANGED
|
@@ -6,14 +6,18 @@
|
|
|
6
6
|
import { spawn } from 'node:child_process';
|
|
7
7
|
import { readFile } from 'node:fs/promises';
|
|
8
8
|
import { constants } from 'node:os';
|
|
9
|
-
import { delimiter, dirname, join } from 'node:path';
|
|
9
|
+
import { delimiter, dirname, join, resolve } from 'node:path';
|
|
10
10
|
import { locate } from './checkout.mjs';
|
|
11
11
|
import { shared } from '../cli/shared.mjs';
|
|
12
12
|
|
|
13
13
|
export const runUsage = `Usage: rer run [--cwd DIR] [SCRIPT [ARGS...]]
|
|
14
|
+
rer run [--cwd DIR] --script FILE [ARGS...]
|
|
14
15
|
Runs a package.json script of this checkout as pnpm run SCRIPT ARGS would, with the
|
|
15
16
|
pnpm and Node the checkout pins (rer keeps them off PATH). Without SCRIPT it lists
|
|
16
17
|
the scripts. Where a project's docs say pnpm run X -- ARGS, run rer run X -- ARGS.
|
|
18
|
+
With --script, runs a JavaScript file with the Node running rer, including the
|
|
19
|
+
installer's private runtime. No checkout or package manager is needed. FILE is
|
|
20
|
+
relative to the current folder (or --cwd DIR); remaining arguments go to the file.
|
|
17
21
|
`;
|
|
18
22
|
|
|
19
23
|
// The checkout's pinned Node, when it differs from this one (RER_NODE_AUTO=0 keeps this one).
|
|
@@ -38,6 +42,11 @@ export async function runScript(args) {
|
|
|
38
42
|
if (!cwd?.trim() || cwd.startsWith('-')) { process.stderr.write(`A folder is required for --cwd.\n${runUsage}`); return 2; }
|
|
39
43
|
args = args.slice(2);
|
|
40
44
|
}
|
|
45
|
+
if (args[0] === '--script') {
|
|
46
|
+
const file = args[1];
|
|
47
|
+
if (!file?.trim() || file.startsWith('-')) { process.stderr.write(`A file is required for --script.\n${runUsage}`); return 2; }
|
|
48
|
+
return runChild(process.execPath, [resolve(cwd ?? '.', file), ...args.slice(2)], cwd ?? process.cwd());
|
|
49
|
+
}
|
|
41
50
|
const target = locate(cwd ? ['run', '--cwd', cwd] : ['run']);
|
|
42
51
|
if (!target.root || !['first-party', 'independent'].includes(target.profile)) {
|
|
43
52
|
process.stderr.write(`rer run runs inside a checkout: a folder with OPERATIONS.json at or above this one, or --cwd DIR.\n`);
|
|
@@ -62,7 +71,11 @@ export async function runScript(args) {
|
|
|
62
71
|
}
|
|
63
72
|
const { toolCommand } = await shared('tool-command.mjs');
|
|
64
73
|
const [program, parameters] = toolCommand('pnpm', ['run', '--silent', ...args], process.env);
|
|
65
|
-
|
|
74
|
+
return runChild(program, parameters, target.root);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async function runChild(program, parameters, cwd) {
|
|
78
|
+
const child = spawn(program, parameters, { cwd, env: process.env, stdio: 'inherit' });
|
|
66
79
|
const forward = new Map(['SIGINT', 'SIGTERM', 'SIGHUP'].map(signal => [signal, () => child.kill(signal)]));
|
|
67
80
|
for (const [signal, handler] of forward) process.on(signal, handler);
|
|
68
81
|
try {
|
package/install.sh
CHANGED
|
@@ -178,6 +178,9 @@ NODE
|
|
|
178
178
|
if [ -n "$path_step" ]; then RER_INSTALLER_PATH_STEP=1; export RER_INSTALLER_PATH_STEP; fi
|
|
179
179
|
status=0
|
|
180
180
|
"$HOME/.local/bin/rer" "$@" || status=$?
|
|
181
|
+
if [ "$1" != business ]; then
|
|
182
|
+
printf 'Run a downloaded JavaScript tool with the installed runtime: "%s/.local/bin/rer" run --script ./tool.mjs [ARGS...]\n' "$HOME"
|
|
183
|
+
fi
|
|
181
184
|
if [ -n "$path_step" ]; then
|
|
182
185
|
printf '\nRequired next step: %s/.local/bin is not on your PATH, so a bare `rer` in a new terminal says "rer: command not found". Run this in the terminal you will use, and add the same line to your shell startup file (~/.zshrc for zsh, ~/.bashrc for bash):\n export PATH="$HOME/.local/bin:$PATH"\nOther shells, such as fish: run %s/.local/bin/rer cli path to see the line for yours. Until then, start rer with %s/.local/bin/rer. This installer changes no shell file.\n' "$HOME" "$HOME" "$HOME"
|
|
183
186
|
fi
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { skippedTablesLine } from './bookkeeping.mjs';
|
|
2
2
|
// Human progress for a long export or import. The caller sends events; this turns
|
|
3
3
|
// them into at most one line every few seconds, with an estimate of the time left
|
|
4
|
-
// once a phase has two samples. The first and last line of every
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
|
|
4
|
+
// once a phase has two samples and a known total. The first and last line of every
|
|
5
|
+
// phase always show. Local disk allocation includes free pages and transient state;
|
|
6
|
+
// it cannot predict archive bytes or building time.
|
|
7
|
+
// Import rate measured on a 1.2 GB archive on a loaded machine (2234 s).
|
|
8
|
+
const IMPORT_RATE = 550_000;
|
|
8
9
|
const UNITS = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
9
10
|
export function formatBytes(bytes) {
|
|
10
11
|
let value = bytes, unit = 0;
|
|
@@ -18,16 +19,15 @@ export function formatDuration(seconds) {
|
|
|
18
19
|
}
|
|
19
20
|
const left = seconds => `, ${formatDuration(seconds)} left`;
|
|
20
21
|
export function transferProgress(report, { interval = 3000, now = () => performance.now() } = {}) {
|
|
21
|
-
let phase, first, printed = -Infinity
|
|
22
|
+
let phase, first, printed = -Infinity;
|
|
22
23
|
const line = event => {
|
|
23
|
-
const bytes = event.bytes === undefined ? '' : ` (${formatBytes(event.bytes)}
|
|
24
|
+
const bytes = event.bytes === undefined ? '' : ` (${formatBytes(event.bytes)})`;
|
|
24
25
|
const parts = event.total === undefined ? `${event.parts} part${event.parts === 1 ? '' : 's'} so far` : `${event.parts} of ${event.total} parts`;
|
|
25
26
|
// Seconds left, from the rate since the phase's first sample.
|
|
26
27
|
const eta = () => {
|
|
27
28
|
const seconds = (now() - first.time) / 1000;
|
|
28
29
|
if (event === first.event || seconds <= 0 || event.parts === event.total) return '';
|
|
29
30
|
if (event.total !== undefined && event.parts > first.event.parts) return left((event.total - event.parts) * seconds / (event.parts - first.event.parts));
|
|
30
|
-
if (event.phase === 'building' && expected && event.bytes > first.event.bytes && event.bytes < expected) return left((expected - event.bytes) * seconds / (event.bytes - first.event.bytes));
|
|
31
31
|
return '';
|
|
32
32
|
};
|
|
33
33
|
switch (event.phase) {
|
|
@@ -42,9 +42,11 @@ export function transferProgress(report, { interval = 3000, now = () => performa
|
|
|
42
42
|
if(event.phase==='schema-unverified') { report('Schema unverified: '+JSON.stringify(event.receipt)); return; }
|
|
43
43
|
if (event.phase === 'skipped') { report(skippedTablesLine(event.tables)); return; }
|
|
44
44
|
if (event.phase === 'start') {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
if (event.direction === 'export') {
|
|
46
|
+
report(`Exporting local data (${formatBytes(event.bytes)} on disk). Archive size and time remaining are not known yet. Progress follows every few seconds.`);
|
|
47
|
+
} else {
|
|
48
|
+
report(`Restoring a ${formatBytes(event.bytes)} archive. ${event.bytes / IMPORT_RATE < 45 ? 'This takes under a minute.' : `An archive this size usually takes ${formatDuration(event.bytes / IMPORT_RATE)}; a busy machine takes longer. Progress follows every few seconds.`}`);
|
|
49
|
+
}
|
|
48
50
|
printed = now();
|
|
49
51
|
return;
|
|
50
52
|
}
|
package/onboarding/commands.mjs
CHANGED
|
@@ -11,6 +11,7 @@ import { waitForReadiness } from './readiness.mjs';
|
|
|
11
11
|
import { commandCustody } from './command-custody.mjs';
|
|
12
12
|
import { createProcessBaseline, createProcessScope, inheritedScopeTokens, processScopeEnvironment } from './process-scope.mjs';
|
|
13
13
|
import { toolCommand } from './tool-command.mjs';
|
|
14
|
+
import { isWranglerMigrationApply, wranglerMigrationView } from './migration-progress.mjs';
|
|
14
15
|
|
|
15
16
|
export async function createCommands(directory,state,{terminal=text=>writeSync(1,text),spawn=spawnChild,queue:queuePolicy,custodyToken,onWaiting}={}) {
|
|
16
17
|
let policy=queuePolicy?await commandPolicy():{environment:{},close:async()=>{}};
|
|
@@ -38,12 +39,13 @@ export async function createCommands(directory,state,{terminal=text=>writeSync(1
|
|
|
38
39
|
else if(error.code!=='EAGAIN'&&error.code!=='EWOULDBLOCK')throw error;
|
|
39
40
|
}
|
|
40
41
|
};
|
|
41
|
-
|
|
42
|
+
// `logText` is what the setup log keeps when a command's view shows less than it printed.
|
|
43
|
+
const emit=(text,logText=text)=>{
|
|
44
|
+
if(logText&&!closed)log.write(logText);
|
|
42
45
|
if(!text)return;
|
|
43
46
|
// Store a bounded text tail as lines; fragment writes do not multiply entries.
|
|
44
47
|
const textTail=((state.logs||[]).join('\n')+text).slice(-65536);
|
|
45
48
|
state.logs=textTail.split('\n').slice(-400);
|
|
46
|
-
if(!closed)log.write(text);
|
|
47
49
|
writeTerminal(text);
|
|
48
50
|
};
|
|
49
51
|
// A line that lists secret NAMES keeps each name whole: a name is not a secret, even when a value
|
|
@@ -65,14 +67,16 @@ export async function createCommands(directory,state,{terminal=text=>writeSync(1
|
|
|
65
67
|
const step=stepDiagnostic({name:redaction.redact(String(label)),command:capture?.display,exitCode:detail.code,signal:detail.signal,output:lines,log:redaction.redact(checkoutPath(capture?.cwd,logPath))});
|
|
66
68
|
return Object.assign(commandFailure(`${redaction.redact(String(label))}: ${status}.${detail.lastHealth?` Last health: ${redaction.redact(String(detail.lastHealth))}.`:''}\nCommand: ${capture?.display ?? '(none: the step failed inside rer)'}\nLast output (up to 40 lines):\n${lines.length?lines.slice(-40).join('\n'):'(no output)'}\nLog: ${redaction.redact(logPath)}`,{childExitCode:detail.code,signal:detail.signal,step}),{childExitCode:detail.code,signal:detail.signal});
|
|
67
69
|
};
|
|
68
|
-
const track=(label,child,ownershipScope)=>{
|
|
70
|
+
const track=(label,child,ownershipScope,view)=>{
|
|
69
71
|
if(captures.has(child))return child;
|
|
70
72
|
let resolveClose,resolveError,resolveExit;
|
|
71
73
|
const capture={tail:'',scope:signal,closed:new Promise(resolve=>{resolveClose=resolve;}),failed:new Promise(resolve=>{resolveError=resolve;}),exited:new Promise(resolve=>{resolveExit=resolve;})};
|
|
72
74
|
capture.custody=commandCustody(child,ownershipScope);
|
|
73
75
|
// Redact in arrival order across both descriptors: their concatenation is what
|
|
74
76
|
// reaches the shared page, disk and terminal sinks.
|
|
75
|
-
|
|
77
|
+
// A command's view (see migration-progress.mjs) shortens what the terminal, page and
|
|
78
|
+
// failure tail show; the log keeps every byte.
|
|
79
|
+
const filter=redaction.stream(text=>{const shown=view?view.write(text):text;capture.tail=(capture.tail+shown).slice(-32768);emit(shown,text);});
|
|
76
80
|
capture.snapshot=()=> (capture.tail+filter.snapshot()).slice(-32768);
|
|
77
81
|
const sources=[child.stdout,child.stderr].filter(Boolean),data=chunk=>filter.write(chunk);
|
|
78
82
|
for(const source of sources)source.on('data',data);
|
|
@@ -85,7 +89,9 @@ export async function createCommands(directory,state,{terminal=text=>writeSync(1
|
|
|
85
89
|
clearTimeout(capture.stopTimer);
|
|
86
90
|
child.removeListener('exit',exited);if(!capture.exitResult)exited(code,terminationSignal);
|
|
87
91
|
for(const source of sources)source.removeListener('data',data);
|
|
88
|
-
filter.end();
|
|
92
|
+
filter.end();
|
|
93
|
+
if(view){const rest=view.end();capture.tail=(capture.tail+rest).slice(-32768);emit(rest,'');Object.assign(state,view.facts?.());}
|
|
94
|
+
active.delete(child);if(!capture.custody)managed.delete(child);resolveClose({code,signal:terminationSignal,error,errorCode:capture.errorCode});
|
|
89
95
|
};
|
|
90
96
|
child.once('close',finish);
|
|
91
97
|
captures.set(child,capture);
|
|
@@ -133,7 +139,7 @@ export async function createCommands(directory,state,{terminal=text=>writeSync(1
|
|
|
133
139
|
state.step=announced;if(!repeated)report(label);
|
|
134
140
|
// Name the executable by default; only a caller's explicit safe display may
|
|
135
141
|
// include arguments. Raw argv can contain private positional values.
|
|
136
|
-
const {signal:providedSignal,afterCommand,onChild,heavy,phase,display,...native}=options;
|
|
142
|
+
const {signal:providedSignal,afterCommand,onChild,heavy,phase,display,view,...native}=options;
|
|
137
143
|
const commandSignal=signal&&providedSignal?AbortSignal.any([signal,providedSignal]):providedSignal||signal;
|
|
138
144
|
if(commandSignal?.aborted)throw failure(label,{reason:'cancel'});
|
|
139
145
|
const ownershipScope=createProcessScope(custodyBaseline);redaction.addSecrets([ownershipScope.token,...inheritedScopeTokens(process.env),...inheritedScopeTokens(native.env)]);
|
|
@@ -141,7 +147,7 @@ export async function createCommands(directory,state,{terminal=text=>writeSync(1
|
|
|
141
147
|
const child=spawn(program,argv,{...native,env:processScopeEnvironment(ownershipScope,{...(native.env??process.env),...policy.environment,...(custodyToken?{RER_ONBOARDING_PROCESS_OWNER:[...inheritedScopeTokens(native.env??process.env),custodyToken].join(',')}:{})}),shell:false,detached:process.platform!=='win32',stdio:[Array.isArray(native.stdio)?native.stdio[0]:'ignore','pipe','pipe',...(native.stdio?.includes('ipc')?['ipc']:[])]});
|
|
142
148
|
onChild?.(child);
|
|
143
149
|
ownershipRecords.set(child,{pid:child.pid,token:ownershipScope.token});
|
|
144
|
-
track(label,child,ownershipScope);
|
|
150
|
+
track(label,child,ownershipScope,view?.());
|
|
145
151
|
Object.assign(captures.get(child),{cwd:native.cwd??process.cwd(),display:redaction.redact(String(display??command))});
|
|
146
152
|
const cancel=()=>{void stopCommand(child);};
|
|
147
153
|
commandSignal?.addEventListener('abort',cancel,{once:true});if(commandSignal?.aborted)cancel();
|
|
@@ -158,12 +164,15 @@ export async function createCommands(directory,state,{terminal=text=>writeSync(1
|
|
|
158
164
|
spawn:spawnCommand,
|
|
159
165
|
async stop(child){await stopCommand(child);await captures.get(child)?.closed;const scope=captures.get(child)?.scope;if(![...managed].some(other=>captures.get(other).scope===scope)){const actions=cleanups.get(scope)??[];cleanups.delete(scope);for(const action of actions)await action();}},
|
|
160
166
|
async run(label,command,args=[],options={}) {
|
|
167
|
+
// Any caller's `wrangler d1 migrations apply` (the setup hooks, a seed's own export and import) shows
|
|
168
|
+
// a count instead of wrangler's table redrawn per migration; the log keeps every byte and is named in the summary.
|
|
169
|
+
if(!options.view&&isWranglerMigrationApply(command,args))options={...options,view:()=>wranglerMigrationView({log:redaction.redact(checkoutPath(options.cwd??process.cwd(),logPath))})};
|
|
161
170
|
if(queuePolicy && options.heavy !== false) {
|
|
162
171
|
let queuedChild;
|
|
163
172
|
const commandSignal=signal&&options.signal?AbortSignal.any([signal,options.signal]):options.signal||signal;
|
|
164
173
|
const result = await queuedCommand(command,args,{...options,verb:queuePolicy.verb,signal:commandSignal,originalCI:policy.ci,
|
|
165
174
|
label:await queueLabel(options.cwd??process.cwd(),queuePolicy.verb,options.phase??'command'),report,onWaiting,maxWait:queuePolicy.maxWait,queueOptions:queuePolicy.sampler?{sampler:queuePolicy.sampler}:undefined,
|
|
166
|
-
spawn:(program,argv,native)=>(queuedChild=spawnCommand(label,program,argv,{...native,onChild:options.onChild,display:options.display})),cleanup:async(child,result)=>{await stopCommand(child);await options.afterCommand?.(result);}});
|
|
175
|
+
spawn:(program,argv,native)=>(queuedChild=spawnCommand(label,program,argv,{...native,onChild:options.onChild,display:options.display,view:options.view})),cleanup:async(child,result)=>{await stopCommand(child);await options.afterCommand?.(result);}});
|
|
167
176
|
if(result?.timedOut)throw busyRefusal({...result,reason:redaction.redact(String(result.reason))},{verb:queuePolicy.verb,maxWait:queuePolicy.maxWait??maxWaitSeconds});
|
|
168
177
|
if(result){if(result.code!==0)throw failure(label,result,captures.get(queuedChild));return result;}
|
|
169
178
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// What a person sees while `wrangler d1 migrations apply` runs. Wrangler redraws
|
|
2
|
+
// its whole migration table after every migration it applies, so 75 migrations
|
|
3
|
+
// print the first one's name 76 times and about 1.2 MB in all. The command's
|
|
4
|
+
// full output stays in the setup log and in failure diagnostics' source; the
|
|
5
|
+
// terminal and shared page get a count every ten migrations, anything that is
|
|
6
|
+
// not a table row, wrangler's own boilerplate or an earlier-seen line (warnings,
|
|
7
|
+
// errors), and one summary. Wrangler names the migration that failed only for
|
|
8
|
+
// some errors (a SQL syntax error is just its message), so the view names the
|
|
9
|
+
// first migration of the list that never showed a check mark when an error came.
|
|
10
|
+
|
|
11
|
+
const TABLE_LINE = /^[┌├└│─]/;
|
|
12
|
+
const STEP = 10;
|
|
13
|
+
// Wrangler's per-migration "🚣 37 commands executed successfully." differs every time, so repeats are not caught.
|
|
14
|
+
const PER_MIGRATION = /^🚣 \d+ commands? executed successfully\.?$/;
|
|
15
|
+
// What wrangler says around every apply, whatever it applies: its banner, where the database is, how to reach
|
|
16
|
+
// a remote one, the confirmation it answers itself in CI.
|
|
17
|
+
const BOILERPLATE = /^(\u26C5\uFE0F?\s*wrangler\b|Resource location:|Use --remote if you want|Migrations to be applied:|\? About to apply \d+ migration|Your database may not be available|🤖 Using fallback value|🌀 (Executing on|To execute on)|✅ No migrations to apply)/u;
|
|
18
|
+
|
|
19
|
+
export function isWranglerMigrationApply(command, args = []) {
|
|
20
|
+
const words = [command, ...args].map(String);
|
|
21
|
+
const tool = words.findIndex(word => /(^|[\\/])wrangler(\.js)?$/.test(word));
|
|
22
|
+
if (tool < 0) return false;
|
|
23
|
+
const rest = words.slice(tool + 1);
|
|
24
|
+
return rest.some((word, index) => word === 'd1' && rest[index + 1] === 'migrations' && rest[index + 2] === 'apply');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// One view per command: write(text) returns the text to show, end() the rest.
|
|
28
|
+
// The summary names the log that keeps wrangler's full output: { log }.
|
|
29
|
+
export function wranglerMigrationView({ log } = {}) {
|
|
30
|
+
let pending = '', total = 0, announced = 0, failed = false, errored = false;
|
|
31
|
+
const applied = new Set(), seen = new Set(), names = [];
|
|
32
|
+
const shown = [];
|
|
33
|
+
const progress = () => `Applying migrations ${applied.size}/${Math.max(total, applied.size)}`;
|
|
34
|
+
const line = text => {
|
|
35
|
+
if (TABLE_LINE.test(text)) {
|
|
36
|
+
if (!text.startsWith('│')) return;
|
|
37
|
+
const cells = text.split('│').slice(1, -1).map(cell => cell.trim());
|
|
38
|
+
if (cells[0] === 'name') return;
|
|
39
|
+
if (cells.length === 1) { total += 1; if (!names.includes(cells[0])) names.push(cells[0]); return; }
|
|
40
|
+
if (cells[1].includes('❌')) { failed = true; shown.push(`Migration ${cells[0]} failed.`); return; }
|
|
41
|
+
if (cells[1].includes('✅') && !applied.has(cells[0])) {
|
|
42
|
+
applied.add(cells[0]);
|
|
43
|
+
if (applied.size % STEP === 0 && applied.size > announced) { announced = applied.size; shown.push(progress()); }
|
|
44
|
+
}
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const trimmed = text.trim();
|
|
48
|
+
if (/\[ERROR\]/.test(trimmed)) errored = true;
|
|
49
|
+
if (!trimmed || PER_MIGRATION.test(trimmed) || BOILERPLATE.test(trimmed) || seen.has(trimmed)) return;
|
|
50
|
+
seen.add(trimmed);
|
|
51
|
+
shown.push(text);
|
|
52
|
+
};
|
|
53
|
+
const drain = () => { const text = shown.length ? shown.join('\n') + '\n' : ''; shown.length = 0; return text; };
|
|
54
|
+
return {
|
|
55
|
+
write(text) {
|
|
56
|
+
const lines = (pending + text).split('\n');
|
|
57
|
+
pending = lines.pop();
|
|
58
|
+
for (const item of lines) line(item);
|
|
59
|
+
return drain();
|
|
60
|
+
},
|
|
61
|
+
end() {
|
|
62
|
+
if (pending) { line(pending); pending = ''; }
|
|
63
|
+
if (errored && !failed && names[applied.size]) shown.push(`Migration ${names[applied.size]} failed.`);
|
|
64
|
+
if (applied.size) shown.push(`Applied ${applied.size} migration${applied.size === 1 ? '' : 's'}.${log ? ` Full output: ${log}` : ''}`);
|
|
65
|
+
return drain();
|
|
66
|
+
},
|
|
67
|
+
facts: () => ({ migrationsApplied: applied.size }),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
@@ -48,5 +48,6 @@ export async function migrateOperator(context, database) {
|
|
|
48
48
|
const after = await appliedNames(state, table);
|
|
49
49
|
const applied = names.filter(name => !before.has(name) && after.has(name));
|
|
50
50
|
if (applied.length) store.report(`Applied local migrations: ${applied.join(', ')}`);
|
|
51
|
+
if (store.state) store.state.migrationsApplied = applied.length;
|
|
51
52
|
} finally { await unlink(path); }
|
|
52
53
|
}
|