@selvajs/cli 4.8.0-beta.10 → 4.8.0-beta.11
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 +7 -12
- package/package.json +4 -1
- package/src/checks/boot.js +18 -16
- package/src/checks/config.js +4 -12
- package/src/checks/runtime.js +289 -0
- package/src/cli.js +1 -1
- package/src/commands/create.js +11 -20
- package/src/commands/doctor.js +34 -51
- package/src/commands/init.js +7 -12
- package/src/commands/migrate.js +92 -43
- package/src/commands/pm2.js +12 -21
- package/src/deployment-package.js +44 -3
- package/src/env.js +12 -23
- package/src/paths.js +2 -3
- package/src/prompts.js +4 -14
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
// than in either command — two copies drifted once already, and the pm2 pin is
|
|
4
4
|
// exactly the field where a silent difference costs the most.
|
|
5
5
|
|
|
6
|
+
import { readFileSync } from 'node:fs';
|
|
7
|
+
import { join, dirname } from 'node:path';
|
|
8
|
+
import { fileURLToPath } from 'node:url';
|
|
9
|
+
|
|
6
10
|
/**
|
|
7
11
|
* pm2 is pinned exactly, not caret-ranged.
|
|
8
12
|
*
|
|
@@ -10,8 +14,29 @@
|
|
|
10
14
|
* two deployments installed a week apart resolve differently, and the newer one
|
|
11
15
|
* silently adopts the daemon the older one started — the skew `ensurePm2InSync`
|
|
12
16
|
* has to detect and, in the daemon-is-newer direction, cannot repair (#118).
|
|
17
|
+
*
|
|
18
|
+
* Read from this package's own devDependencies rather than written here as a
|
|
19
|
+
* literal. Dependabot scans manifests, not source, so a literal is invisible to
|
|
20
|
+
* it — this pin sat on 5.4.3 while upstream reached 7.x, which is precisely the
|
|
21
|
+
* drift operators point at when they argue for distro packages instead.
|
|
22
|
+
* `checkPinIsExact` keeps the manifest entry from being loosened to a range.
|
|
13
23
|
*/
|
|
14
|
-
const PM2_VERSION =
|
|
24
|
+
const PM2_VERSION = readPinnedPm2Version();
|
|
25
|
+
|
|
26
|
+
function readPinnedPm2Version() {
|
|
27
|
+
const manifest = JSON.parse(
|
|
28
|
+
readFileSync(join(dirname(fileURLToPath(import.meta.url)), '..', 'package.json'), 'utf8')
|
|
29
|
+
);
|
|
30
|
+
const pinned = manifest.devDependencies?.pm2;
|
|
31
|
+
if (!pinned || !/^\d+\.\d+\.\d+$/.test(pinned)) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
`@selvajs/cli devDependencies.pm2 must be an exact version, got ${JSON.stringify(pinned)}. ` +
|
|
34
|
+
`Every deployment this CLI scaffolds inherits it, and a range there lets two ` +
|
|
35
|
+
`installs resolve different pm2s that then fight over one daemon.`
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
return pinned;
|
|
39
|
+
}
|
|
15
40
|
|
|
16
41
|
const SCRIPTS = {
|
|
17
42
|
start: 'selva start',
|
|
@@ -33,6 +58,21 @@ const DEPENDENCIES = {
|
|
|
33
58
|
pm2: PM2_VERSION
|
|
34
59
|
};
|
|
35
60
|
|
|
61
|
+
/**
|
|
62
|
+
* npm `overrides` forced onto every deployment — security patches for
|
|
63
|
+
* transitive deps whose direct parent hasn't picked up the fix yet. Each entry
|
|
64
|
+
* is a temporary shim: remove it once the parent ships the fixed version on
|
|
65
|
+
* its own (the override then matches what would install anyway, so removal is
|
|
66
|
+
* cleanup, never urgent).
|
|
67
|
+
*
|
|
68
|
+
* js-yaml: pm2 <= 7.0.3 pins 4.3.0, which carries the quadratic-complexity
|
|
69
|
+
* DoS advisories (GHSA-5p4m-2wfm-xmqj and friends); the fix landed in 4.3.1.
|
|
70
|
+
* Drop when pm2's own js-yaml dependency reaches >= 4.3.1.
|
|
71
|
+
*/
|
|
72
|
+
export const OVERRIDES = {
|
|
73
|
+
'js-yaml': '^4.3.1'
|
|
74
|
+
};
|
|
75
|
+
|
|
36
76
|
/**
|
|
37
77
|
* Legacy `@selvajs/*` packages that a deployment may still list. Each was
|
|
38
78
|
* either renamed or folded into `@selvajs/selva`; `migrate` drops them and
|
|
@@ -68,7 +108,8 @@ export function buildDeploymentPackageJson({ name, version = '0.1.0', engines })
|
|
|
68
108
|
private: true,
|
|
69
109
|
type: 'module',
|
|
70
110
|
scripts: { ...SCRIPTS },
|
|
71
|
-
dependencies: { ...DEPENDENCIES }
|
|
111
|
+
dependencies: { ...DEPENDENCIES },
|
|
112
|
+
overrides: { ...OVERRIDES }
|
|
72
113
|
};
|
|
73
114
|
if (engines && typeof engines === 'object') pkg.engines = { ...engines };
|
|
74
115
|
return pkg;
|
|
@@ -86,11 +127,11 @@ export const CANONICAL_FIELDS = new Set([
|
|
|
86
127
|
'type',
|
|
87
128
|
'scripts',
|
|
88
129
|
'dependencies',
|
|
130
|
+
'overrides',
|
|
89
131
|
'engines'
|
|
90
132
|
]);
|
|
91
133
|
|
|
92
134
|
export function sanitizePackageName(name) {
|
|
93
|
-
// npm package names: lowercase, no spaces, limited punctuation.
|
|
94
135
|
return (
|
|
95
136
|
String(name ?? '')
|
|
96
137
|
.toLowerCase()
|
package/src/env.js
CHANGED
|
@@ -2,13 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
import { readFileSync, writeFileSync, existsSync } from 'node:fs';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* reports them and `selva migrate` rewrites them. Keep in sync with that list,
|
|
10
|
-
* and drop an entry when the server stops reading it.
|
|
11
|
-
*/
|
|
5
|
+
// Old env name → its replacement, for keys renamed without changing meaning.
|
|
6
|
+
// The server still reads each old name for one minor version and warns at
|
|
7
|
+
// boot; keep this in sync with the server's list and drop an entry once the
|
|
8
|
+
// server stops reading it.
|
|
12
9
|
export const RENAMED_ENV_VARS = {
|
|
13
10
|
COMPUTE_DEFINITION_BYTE_CACHE_MB: 'COMPUTE_DEFINITION_CACHE_MB',
|
|
14
11
|
COMPUTE_RESPONSE_CACHE_MB: 'COMPUTE_SOLVE_CACHE_MB',
|
|
@@ -16,16 +13,12 @@ export const RENAMED_ENV_VARS = {
|
|
|
16
13
|
MAX_SOLVE_DURATION_MS: 'COMPUTE_SOLVE_DEADLINE_MS'
|
|
17
14
|
};
|
|
18
15
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
* rewritten by renaming a key. `selva doctor` reports these; migrate leaves
|
|
22
|
-
* them alone rather than guessing.
|
|
23
|
-
*/
|
|
16
|
+
// Deprecated vars whose replacement changes the VALUE too, so a simple key
|
|
17
|
+
// rename can't migrate them — `selva migrate` leaves these alone rather than guessing.
|
|
24
18
|
export const REPLACED_ENV_VARS = {
|
|
25
19
|
SELVA_FLAG_COMPUTE_DEBUG_VERBOSE: 'SELVA_FLAG_COMPUTE_DEBUG=verbose'
|
|
26
20
|
};
|
|
27
21
|
|
|
28
|
-
// Parse a .env file into { key: value }. Preserves nothing else.
|
|
29
22
|
export function parseEnv(text) {
|
|
30
23
|
const out = {};
|
|
31
24
|
for (const rawLine of text.split(/\r?\n/)) {
|
|
@@ -51,7 +44,6 @@ export function readEnvFile(path) {
|
|
|
51
44
|
return parseEnv(readFileSync(path, 'utf8'));
|
|
52
45
|
}
|
|
53
46
|
|
|
54
|
-
// Merge values into template: preserve structure, rewrite in-place, append new keys.
|
|
55
47
|
export function mergeEnv(template, values) {
|
|
56
48
|
const seen = new Set();
|
|
57
49
|
const lines = template.split(/\r?\n/);
|
|
@@ -92,7 +84,6 @@ export function mergeEnv(template, values) {
|
|
|
92
84
|
out.push(...appended);
|
|
93
85
|
}
|
|
94
86
|
|
|
95
|
-
// Ensure single trailing newline (shell append mishap guard).
|
|
96
87
|
while (out.length > 0 && out[out.length - 1] === '') out.pop();
|
|
97
88
|
return out.join('\n') + '\n';
|
|
98
89
|
}
|
|
@@ -102,17 +93,15 @@ export function writeEnvFile(path, template, values) {
|
|
|
102
93
|
}
|
|
103
94
|
|
|
104
95
|
/**
|
|
105
|
-
* Rewrite deprecated keys to their current names, in place.
|
|
106
|
-
*
|
|
107
|
-
* spacing survive, so an operator's tuned file stays recognisably theirs.
|
|
96
|
+
* Rewrite deprecated keys to their current names, in place. Only the key is
|
|
97
|
+
* touched — value, comments, ordering, and spacing survive.
|
|
108
98
|
*
|
|
109
99
|
* A key already present under its new name is left alone and its old line is
|
|
110
|
-
* dropped: the server resolves
|
|
111
|
-
*
|
|
100
|
+
* dropped: the server resolves new-name-wins, so keeping both would preserve
|
|
101
|
+
* a line that does nothing.
|
|
112
102
|
*
|
|
113
|
-
* Returns `{ text, changes }
|
|
114
|
-
* | 'dropped']` per line acted on
|
|
115
|
-
* current and nothing should be written.
|
|
103
|
+
* Returns `{ text, changes }`, `changes` being `[oldName, newName, 'renamed'
|
|
104
|
+
* | 'dropped']` per line acted on. Empty means the file was already current.
|
|
116
105
|
*/
|
|
117
106
|
export function renameEnvKeys(text, renames) {
|
|
118
107
|
const present = new Set(Object.keys(parseEnv(text)));
|
package/src/paths.js
CHANGED
|
@@ -65,9 +65,8 @@ export function readEnvTemplate(dir) {
|
|
|
65
65
|
return '';
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
//
|
|
69
|
-
//
|
|
70
|
-
// CLI doesn't require it — `selva init` is allowed to fix a partial install.
|
|
68
|
+
// Either .env or ecosystem.config.cjs is enough — selva.config.js and
|
|
69
|
+
// node_modules are expected too, but init should still fix a partial install.
|
|
71
70
|
export function isDeploymentDir(dir) {
|
|
72
71
|
return existsSync(join(dir, '.env')) || existsSync(join(dir, 'ecosystem.config.cjs'));
|
|
73
72
|
}
|
package/src/prompts.js
CHANGED
|
@@ -18,9 +18,7 @@ export function collectConfigFromEnv(env = process.env) {
|
|
|
18
18
|
'local',
|
|
19
19
|
'SELVA_AUTH_PROVIDER'
|
|
20
20
|
);
|
|
21
|
-
//
|
|
22
|
-
// for all three" default. Header-auth has no data layer, so it falls
|
|
23
|
-
// through to local unless explicitly overridden.
|
|
21
|
+
// Header-auth has no data layer, so it falls through to local unless overridden.
|
|
24
22
|
const dataDefault = auth === 'header' ? 'local' : auth;
|
|
25
23
|
const data = pick(
|
|
26
24
|
env.SELVA_DATA_PROVIDER,
|
|
@@ -72,7 +70,6 @@ export function collectConfigFromEnv(env = process.env) {
|
|
|
72
70
|
values.HEADER_AUTH_DISPLAY_NAME_HEADER = env.HEADER_AUTH_DISPLAY_NAME_HEADER;
|
|
73
71
|
}
|
|
74
72
|
|
|
75
|
-
// ── Bootstrap admin ──────────────────────────────────────────────────
|
|
76
73
|
const adminRequired = auth === 'header' || tenancy === 'multi';
|
|
77
74
|
const adminEmail = env.BOOTSTRAP_INSTANCE_ADMIN_EMAIL || '';
|
|
78
75
|
if (adminRequired && !adminEmail) {
|
|
@@ -127,15 +124,11 @@ function requireEnv(env, name) {
|
|
|
127
124
|
return v;
|
|
128
125
|
}
|
|
129
126
|
|
|
130
|
-
// Run full interactive prompt sequence; return env vars. Caller decides merge vs fresh.
|
|
131
|
-
// `defaults` pre-populates prompts (cheap re-run).
|
|
132
127
|
export async function collectConfig({ defaults = {}, mode = 'create' } = {}) {
|
|
133
128
|
const isInit = mode === 'init';
|
|
134
129
|
|
|
135
130
|
p.intro(pc.bgCyan(pc.black(isInit ? ' selva init ' : ' Selva — new deployment ')));
|
|
136
131
|
|
|
137
|
-
// Brand prompts (SELVA_BRAND_NAME / COPYRIGHT_NAME / TAGLINE / DESCRIPTION)
|
|
138
|
-
|
|
139
132
|
const tenancy = await p.select({
|
|
140
133
|
message: 'Tenancy mode',
|
|
141
134
|
initialValue: defaults.SELVA_TENANCY ?? 'single',
|
|
@@ -169,7 +162,6 @@ export async function collectConfig({ defaults = {}, mode = 'create' } = {}) {
|
|
|
169
162
|
});
|
|
170
163
|
cancelOn(auth);
|
|
171
164
|
|
|
172
|
-
// Header-auth: auth-only; user must pick separate data/storage backend.
|
|
173
165
|
let data;
|
|
174
166
|
let storage;
|
|
175
167
|
if (auth === 'header') {
|
|
@@ -197,7 +189,6 @@ export async function collectConfig({ defaults = {}, mode = 'create' } = {}) {
|
|
|
197
189
|
cancelOn(storageChoice);
|
|
198
190
|
storage = storageChoice;
|
|
199
191
|
} else {
|
|
200
|
-
// Operators usually want same backend for all three; ask once, default the others.
|
|
201
192
|
const mixProviders = await p.confirm({
|
|
202
193
|
message: `Use ${pc.cyan(auth)} for data and storage too?`,
|
|
203
194
|
initialValue: pickSameProviderDefault(defaults, auth)
|
|
@@ -281,7 +272,6 @@ export async function collectConfig({ defaults = {}, mode = 'create' } = {}) {
|
|
|
281
272
|
}
|
|
282
273
|
|
|
283
274
|
if (auth === 'header') {
|
|
284
|
-
// HEADER_AUTH_DATA_DIR: ask only if data provider isn't local (fallback available).
|
|
285
275
|
if (data !== 'local') {
|
|
286
276
|
const dataDir = await p.text({
|
|
287
277
|
message: 'HEADER_AUTH_DATA_DIR — directory for header-allowlist.json',
|
|
@@ -330,7 +320,7 @@ export async function collectConfig({ defaults = {}, mode = 'create' } = {}) {
|
|
|
330
320
|
providerValues.HEADER_AUTH_DISPLAY_NAME_HEADER = stringValue(display);
|
|
331
321
|
}
|
|
332
322
|
|
|
333
|
-
//
|
|
323
|
+
// Not enforced — a Docker network can still route to the container on another host.
|
|
334
324
|
const bindLoopback = await p.confirm({
|
|
335
325
|
message: 'Bind the app to 127.0.0.1 only? (recommended for header-auth)',
|
|
336
326
|
initialValue: !defaults.HOST || defaults.HOST === '127.0.0.1' || defaults.HOST === 'localhost'
|
|
@@ -339,7 +329,6 @@ export async function collectConfig({ defaults = {}, mode = 'create' } = {}) {
|
|
|
339
329
|
providerValues.HOST = bindLoopback ? '127.0.0.1' : stringValue(defaults.HOST);
|
|
340
330
|
}
|
|
341
331
|
|
|
342
|
-
// Bootstrap admin (checked only while no admin exists; safe to leave set).
|
|
343
332
|
if (auth === 'header') {
|
|
344
333
|
p.note(
|
|
345
334
|
[
|
|
@@ -494,10 +483,11 @@ export async function collectConfig({ defaults = {}, mode = 'create' } = {}) {
|
|
|
494
483
|
return values;
|
|
495
484
|
}
|
|
496
485
|
|
|
497
|
-
// Init: default to "same provider" only if current .env already shows that.
|
|
498
486
|
function pickSameProviderDefault(defaults, auth) {
|
|
499
487
|
const data = defaults.SELVA_DATA_PROVIDER ?? auth;
|
|
500
488
|
const storage = defaults.SELVA_STORAGE_PROVIDER ?? auth;
|
|
489
|
+
// No existing defaults means a fresh `create`, not a re-prompted `init` — default to
|
|
490
|
+
// "same provider for all three" since there's nothing yet to disagree with auth.
|
|
501
491
|
if (!defaults.SELVA_DATA_PROVIDER && !defaults.SELVA_STORAGE_PROVIDER) return true;
|
|
502
492
|
return data === auth && storage === auth;
|
|
503
493
|
}
|