@basaltkit/deploy 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -53,13 +53,18 @@ What is true of one server only (a port taken there, another branch) goes in
53
53
  pnpm install
54
54
  pnpm exec basalt-deploy env # writes the .env (asks once), starts the containers, validates
55
55
 
56
- # once, as an administrator:
57
- sudo pnpm exec basalt-deploy install --user=<app user> # Apache vhost, /var/lib/basalt/<app>
56
+ # once, as an administrator (node on the file: root often has no pnpm on its PATH):
57
+ sudo node node_modules/@basaltkit/deploy/dist/bin.js install --user=<app user> # Apache vhost, /var/lib/basalt/<app>
58
58
 
59
59
  # then, every deploy, as the app user:
60
60
  pnpm exec basalt-deploy run
61
61
  ```
62
62
 
63
+ `run` pulls the code itself. Store the git credentials once
64
+ (`git config credential.helper store && git fetch`, or a read-only deploy key):
65
+ preflight probes the remote with prompts disabled, warns at a terminal and
66
+ stops before anything changes when nobody can type them (cron, CI).
67
+
63
68
  The TLS certificate is yours to issue (`certbot --dns-cloudflare -d <domain> -d '*.<domain>'`);
64
69
  every deploy checks it.
65
70
 
@@ -76,6 +81,14 @@ every deploy checks it.
76
81
 
77
82
  `--skip=fetch,backup,tls`, `--config=<file>`, `--overrides=<file>`.
78
83
 
84
+ ## What runs by default
85
+
86
+ - `prisma migrate deploy` — when `build.prisma` lists a config, or `migrate.central: true`.
87
+ - `tenant:migrate` — only with `migrate.tenants`.
88
+ - The dump before migrating — when something is migrated and there is a
89
+ Postgres to dump (dedicated, or a `postgres://` URL in the `.env`);
90
+ `backup.beforeMigrate` forces it either way. `plan` says why when it is skipped.
91
+
79
92
  ## What it refuses to do
80
93
 
81
94
  Each of these is a check that runs on every deploy, written after a production
package/dist/apache.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { join } from 'node:path';
2
2
  import { vhostName } from './config.js';
3
- import { DeployError } from './context.js';
3
+ import { DeployError, INSTALL_COMMAND } from './context.js';
4
4
  import { lineDiff } from './diff.js';
5
5
  /**
6
6
  * The Apache target (RFC 0006 §11.3): the vhost is written ONLY by `install`,
@@ -76,7 +76,7 @@ export async function apachePreflight(ctx, port) {
76
76
  const enabled = await host.stat(paths.enabled);
77
77
  const available = await host.readFile(paths.available);
78
78
  if (!enabled && available === undefined) {
79
- return [{ id: 'proxy', level: 'error', message: `no Apache vhost ${paths.file} yet`, fix: 'sudo pnpm exec basalt-deploy install (once per server)' }];
79
+ return [{ id: 'proxy', level: 'error', message: `no Apache vhost ${paths.file} yet`, fix: `${INSTALL_COMMAND} (once per server)` }];
80
80
  }
81
81
  if (!enabled) {
82
82
  findings.push({ id: 'proxy', level: 'error', message: `${paths.file} is in sites-available but not enabled`, fix: `sudo a2ensite ${paths.file} && sudo systemctl reload apache2` });
@@ -91,7 +91,7 @@ export async function apachePreflight(ctx, port) {
91
91
  id: 'C2',
92
92
  level: 'error',
93
93
  message: `sites-enabled/${paths.file} is a regular file, not a link to sites-available — ${same ? 'identical today, but edits to sites-available will not be served' : 'and it DIFFERS from sites-available: Apache serves the copy'}`,
94
- fix: 'sudo pnpm exec basalt-deploy install (replaces it with a link, after showing the diff)',
94
+ fix: `${INSTALL_COMMAND} (replaces it with a link, after showing the diff)`,
95
95
  });
96
96
  }
97
97
  else if (enabled.kind === 'symlink') {
@@ -110,7 +110,7 @@ export async function apachePreflight(ctx, port) {
110
110
  id: 'C1',
111
111
  level: 'error',
112
112
  message: `the vhost proxies to 127.0.0.1:${proxied}, but the app listens on ${port}`,
113
- fix: 'sudo pnpm exec basalt-deploy install (shows the diff and rewrites it)',
113
+ fix: `${INSTALL_COMMAND} (shows the diff and rewrites it)`,
114
114
  });
115
115
  }
116
116
  }
@@ -120,7 +120,7 @@ export async function apachePreflight(ctx, port) {
120
120
  id: 'vhost',
121
121
  level: 'warning',
122
122
  message: `the installed vhost differs from what install would write (not changed — audit only):\n${diff.map((l) => ` ${l}`).join('\n')}`,
123
- fix: 'to apply: sudo pnpm exec basalt-deploy install',
123
+ fix: `to apply: ${INSTALL_COMMAND}`,
124
124
  });
125
125
  }
126
126
  }
package/dist/cli.js CHANGED
@@ -12,7 +12,8 @@ export const USAGE = `basalt-deploy — deploy this Basalt app on this server (R
12
12
  basalt-deploy env the .env and the dedicated infra only (first setup)
13
13
  basalt-deploy rollback [--to=<sha>] back to the last healthy release (code only)
14
14
  basalt-deploy status the last releases and the process
15
- sudo basalt-deploy install --user=<name> once per server: vhost, state directory
15
+ sudo node node_modules/@basaltkit/deploy/dist/bin.js install --user=<name>
16
+ once per server, as root: vhost, state directory
16
17
 
17
18
  Options:
18
19
  --config=<file> default deploy.config.ts
package/dist/context.d.ts CHANGED
@@ -19,6 +19,11 @@ export interface Finding {
19
19
  /** One line the operator can act on. */
20
20
  fix?: string;
21
21
  }
22
+ /**
23
+ * How an administrator runs `install`. `node` on the file, not `pnpm exec`:
24
+ * root often has no pnpm on its PATH (a per-user install, corepack).
25
+ */
26
+ export declare const INSTALL_COMMAND = "sudo node node_modules/@basaltkit/deploy/dist/bin.js install --user=\"$USER\"";
22
27
  export declare const errors: (findings: Finding[]) => Finding[];
23
28
  export declare function report(host: Host, findings: Finding[]): void;
24
29
  export declare function detectPackageManager(host: Host, dir: string): Promise<DeployContext['pm']>;
package/dist/context.js CHANGED
@@ -1,4 +1,9 @@
1
1
  import { join } from 'node:path';
2
+ /**
3
+ * How an administrator runs `install`. `node` on the file, not `pnpm exec`:
4
+ * root often has no pnpm on its PATH (a per-user install, corepack).
5
+ */
6
+ export const INSTALL_COMMAND = 'sudo node node_modules/@basaltkit/deploy/dist/bin.js install --user="$USER"';
2
7
  export const errors = (findings) => findings.filter((f) => f.level === 'error');
3
8
  export function report(host, findings) {
4
9
  for (const finding of findings) {
package/dist/host.d.ts CHANGED
@@ -43,6 +43,8 @@ export interface Host {
43
43
  }>;
44
44
  /** The environment the deploy itself was started with (answers for non-interactive runs). */
45
45
  env: Readonly<Record<string, string | undefined>>;
46
+ /** Whether a person can answer a prompt (a terminal, not CI). */
47
+ interactive(): boolean;
46
48
  uid(): number;
47
49
  out: Output;
48
50
  }
package/dist/host.js CHANGED
@@ -23,6 +23,7 @@ export function nodeHost(output = consoleOutput()) {
23
23
  out: output,
24
24
  env: process.env,
25
25
  uid: () => (typeof process.getuid === 'function' ? process.getuid() : -1),
26
+ interactive: () => Boolean(process.stdin.isTTY) && !process.env['CI'],
26
27
  now: () => new Date(),
27
28
  randomHex: (bytes) => randomBytes(bytes).toString('hex'),
28
29
  sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
@@ -18,6 +18,20 @@ export interface Preflight {
18
18
  values: Map<string, string>;
19
19
  }
20
20
  export declare function preflight(ctx: DeployContext, options?: RunOptions): Promise<Preflight>;
21
+ /** `prisma migrate deploy` runs when asked to, or — unsaid — when the app generates a Prisma client. */
22
+ export declare function migratesCentral(config: DeployContext['config']): boolean;
23
+ /**
24
+ * Whether the pre-migration dump runs, and why not when it does not. Unsaid,
25
+ * it runs when there is something to migrate AND a Postgres to dump: the
26
+ * dedicated one, or a `postgres…` URL in the `.env`. Explicitly on, a missing
27
+ * database is the backup step's error to report.
28
+ */
29
+ export declare function backupDecision(config: DeployContext['config'], values: Map<string, string>, skip?: Iterable<string>): {
30
+ run: true;
31
+ } | {
32
+ run: false;
33
+ why: string;
34
+ };
21
35
  export declare function plan(ctx: DeployContext, options?: RunOptions): Promise<number>;
22
36
  /** `basalt-deploy env` — the .env and the infra only (first setup, before `install`). */
23
37
  export declare function envCommand(ctx: DeployContext): Promise<number>;
package/dist/pipeline.js CHANGED
@@ -3,7 +3,7 @@ import { apacheInstall, apachePreflight, vhostPaths } from './apache.js';
3
3
  import { backupDatabase, restoreCommand } from './backup.js';
4
4
  import { tlsFindings, toolingFindings } from './checks.js';
5
5
  import { processName } from './config.js';
6
- import { DeployError, errors, report } from './context.js';
6
+ import { DeployError, errors, INSTALL_COMMAND, report } from './context.js';
7
7
  import { checkSchema, coercionFindings, policyFindings } from './env-check.js';
8
8
  import { answerQuestions, describeEnv, planEnv, readEnv, syntaxFindings, writeEnv } from './env-step.js';
9
9
  import { envValues } from './dotenv.js';
@@ -11,8 +11,13 @@ import { applyInfra, describeInfra, planInfra } from './infra.js';
11
11
  import { pm2List, pm2Preflight, pm2Release, resolvePort } from './pm2.js';
12
12
  import { lastGood, migrationNames, readReleases, recordRelease } from './state.js';
13
13
  export const SKIPPABLE = ['fetch', 'backup', 'tls'];
14
- async function git(ctx, args) {
15
- const result = await ctx.host.exec('git', args, { cwd: ctx.dir });
14
+ /**
15
+ * Never a credential prompt: one in the middle of a deploy hangs cron and CI,
16
+ * and interrupts a person half-way. With nobody to answer, git fails instead.
17
+ */
18
+ const NO_PROMPT = { GIT_TERMINAL_PROMPT: '0', GCM_INTERACTIVE: 'never', GIT_SSH_COMMAND: 'ssh -o BatchMode=yes' };
19
+ async function git(ctx, args, options = {}) {
20
+ const result = await ctx.host.exec('git', args, { cwd: ctx.dir, ...(options.noPrompt ? { env: NO_PROMPT } : {}) });
16
21
  if (result.code !== 0)
17
22
  throw new DeployError(`git ${args[0]} failed: ${result.stderr.trim()}`);
18
23
  return result.stdout.trim();
@@ -44,15 +49,63 @@ export async function preflight(ctx, options = {}) {
44
49
  const wanted = ctx.config.branch ?? 'main';
45
50
  if (branch !== wanted)
46
51
  findings.push({ id: 'git', level: 'error', message: `the checkout is on "${branch}", the deploy tracks "${wanted}"`, fix: `git checkout ${wanted}` });
52
+ if (!options.skip?.includes('fetch'))
53
+ findings.push(...await remoteFindings(ctx));
47
54
  }
48
55
  return { findings, port, values };
49
56
  }
57
+ const CREDENTIALS = /terminal prompts disabled|could not read (Username|Password)|Authentication failed|Permission denied \(publickey|Host key verification failed|Invalid username or (password|token)/i;
58
+ /** Can the fetch reach the branch without asking anyone for anything? */
59
+ async function remoteFindings(ctx) {
60
+ const remote = ctx.config.remote ?? 'origin';
61
+ const branch = ctx.config.branch ?? 'main';
62
+ const probe = await ctx.host.exec('git', ['ls-remote', '--exit-code', remote, `refs/heads/${branch}`], { cwd: ctx.dir, env: NO_PROMPT });
63
+ if (probe.code === 0)
64
+ return [];
65
+ if (probe.code === 2)
66
+ return [{ id: 'git', level: 'error', message: `the branch "${branch}" does not exist on ${remote}` }];
67
+ const reason = probe.stderr.trim().split('\n').find((l) => l.trim()) ?? `exit ${probe.code}`;
68
+ if (CREDENTIALS.test(probe.stderr)) {
69
+ const fix = 'store them once: git config credential.helper store && git fetch (or a read-only deploy key and an ssh remote)';
70
+ return ctx.host.interactive()
71
+ ? [{ id: 'git', level: 'warning', message: `${remote} needs credentials: the fetch will ask for them`, fix }]
72
+ : [{ id: 'git', level: 'error', message: `${remote} needs credentials and nobody can type them here (no terminal)`, fix }];
73
+ }
74
+ return [{ id: 'git', level: 'warning', message: `could not reach ${remote}: ${reason}`, fix: '--skip=fetch deploys the code already in the checkout' }];
75
+ }
50
76
  function stopOnErrors(ctx, findings, what) {
51
77
  report(ctx.host, findings);
52
78
  const blocking = errors(findings);
53
79
  if (blocking.length > 0)
54
80
  throw new DeployError(`${what}: ${blocking.length} problem(s) above — nothing was changed`, blocking);
55
81
  }
82
+ // ── what runs by default ───────────────────────────────────────────────────
83
+ /** `prisma migrate deploy` runs when asked to, or — unsaid — when the app generates a Prisma client. */
84
+ export function migratesCentral(config) {
85
+ return config.migrate?.central ?? (config.build?.prisma?.length ?? 0) > 0;
86
+ }
87
+ const migratesAnything = (config) => migratesCentral(config) || Boolean(config.migrate?.tenants);
88
+ /**
89
+ * Whether the pre-migration dump runs, and why not when it does not. Unsaid,
90
+ * it runs when there is something to migrate AND a Postgres to dump: the
91
+ * dedicated one, or a `postgres…` URL in the `.env`. Explicitly on, a missing
92
+ * database is the backup step's error to report.
93
+ */
94
+ export function backupDecision(config, values, skip = []) {
95
+ if ([...skip].includes('backup'))
96
+ return { run: false, why: '--skip=backup' };
97
+ const wanted = config.backup?.beforeMigrate;
98
+ if (wanted === false)
99
+ return { run: false, why: 'backup.beforeMigrate is false' };
100
+ if (wanted === true)
101
+ return { run: true };
102
+ if (!migratesAnything(config))
103
+ return { run: false, why: 'nothing to migrate' };
104
+ if (config.infra?.kind === 'docker' && config.infra.postgres)
105
+ return { run: true };
106
+ const url = values.get(config.backup?.urlKey ?? 'DATABASE_URL') ?? '';
107
+ return /^postgres(ql)?:\/\//.test(url) ? { run: true } : { run: false, why: 'no Postgres database in the .env' };
108
+ }
56
109
  // ── the building blocks ────────────────────────────────────────────────────
57
110
  async function prepareEnv(ctx, port) {
58
111
  const document = await readEnv(ctx);
@@ -88,7 +141,7 @@ async function validate(ctx, values) {
88
141
  async function migrate(ctx, values) {
89
142
  const { host, pm } = ctx;
90
143
  const env = { cwd: ctx.dir, stream: true, env: Object.fromEntries(values) };
91
- if (ctx.config.migrate?.central !== false) {
144
+ if (migratesCentral(ctx.config)) {
92
145
  host.out.info(`${pm} exec prisma migrate deploy`);
93
146
  const central = await host.exec(pm, ['exec', 'prisma', 'migrate', 'deploy'], env);
94
147
  if (central.code !== 0)
@@ -102,6 +155,8 @@ async function migrate(ctx, values) {
102
155
  if (result.code !== 0)
103
156
  throw new DeployError('the tenant migrations failed');
104
157
  }
158
+ if (!migratesAnything(ctx.config))
159
+ host.out.info('nothing to migrate (no build.prisma, no migrate.tenants)');
105
160
  }
106
161
  async function healthy(ctx, port) {
107
162
  const { host, config } = ctx;
@@ -136,6 +191,26 @@ async function restoreCode(ctx, sha, values) {
136
191
  await git(ctx, ['reset', '--hard', sha]);
137
192
  await build(ctx, values);
138
193
  }
194
+ /** The env step's summary: what changed, or that nothing did. */
195
+ function reportEnv(ctx, plan) {
196
+ const lines = describeEnv(plan);
197
+ if (lines.length === 0)
198
+ ctx.host.out.ok(`${ctx.config.env.file ?? '.env'} unchanged`);
199
+ for (const line of lines)
200
+ ctx.host.out.info(line);
201
+ }
202
+ async function infraStep(ctx, infra) {
203
+ stopOnErrors(ctx, await applyInfra(ctx, infra), 'infra');
204
+ if (infra.services.length === 0)
205
+ ctx.host.out.ok('nothing to start (external infra)');
206
+ else
207
+ ctx.host.out.ok(`${infra.services.map((s) => s.container).join(', ')} healthy; credentials accepted${ctx.config.infra?.kind === 'docker' && ctx.config.infra.minio?.buckets.length ? '; buckets in place' : ''}`);
208
+ }
209
+ async function validateStep(ctx, values) {
210
+ stopOnErrors(ctx, await validate(ctx, values), 'validate');
211
+ const schema = ctx.config.env.schema;
212
+ ctx.host.out.ok(schema ? `${ctx.config.env.file ?? '.env'} is valid for ${schema}` : `${ctx.config.env.file ?? '.env'}: syntax and policy only (no env.schema configured)`);
213
+ }
139
214
  // ── commands ───────────────────────────────────────────────────────────────
140
215
  export async function plan(ctx, options = {}) {
141
216
  const checked = await step(ctx, 'preflight', () => preflight(ctx, options));
@@ -150,8 +225,10 @@ export async function plan(ctx, options = {}) {
150
225
  ...describeInfra(infra).map((l) => `infra: ${l}`),
151
226
  `build: ${pm} install (frozen), ${(config.build?.prisma ?? []).map((c) => `prisma generate --config ${c}`).join(', ') || 'no prisma'}${config.build?.web ? `, ${config.build.web} build` : ''}`,
152
227
  `validate: ${config.env.schema ?? '(no schema configured)'} against the new .env`,
153
- options.skip?.includes('backup') || config.backup?.beforeMigrate === false ? 'backup: skipped' : `backup: pg_dump → ${config.backup?.dir ?? 'backups/predeploy'} (keep ${config.backup?.keep ?? 10})`,
154
- `migrate: ${config.migrate?.central === false ? '' : 'prisma migrate deploy'}${config.migrate?.tenants ? ' + tenant:migrate' : ''}`,
228
+ ((decision) => decision.run
229
+ ? `backup: pg_dump → ${config.backup?.dir ?? 'backups/predeploy'} (keep ${config.backup?.keep ?? 10})`
230
+ : `backup: skipped (${decision.why})`)(backupDecision(config, checked.values, options.skip ?? [])),
231
+ `migrate: ${[migratesCentral(config) ? 'prisma migrate deploy' : '', config.migrate?.tenants ? 'tenant:migrate' : ''].filter(Boolean).join(' + ') || 'nothing configured'}`,
155
232
  `release: pm2 ${processName(config)} on 127.0.0.1:${checked.port}`,
156
233
  `health: http://127.0.0.1:${checked.port}${config.health?.path ?? '/health'} (Host: ${config.domain})${config.proxy?.kind === 'apache' && config.health?.public !== false ? `, then https://${config.domain}${config.proxy.apiPrefix}${config.health?.path ?? '/health'}` : ''}`,
157
234
  ];
@@ -169,11 +246,10 @@ export async function envCommand(ctx) {
169
246
  const missing = await answerQuestions(ctx, env);
170
247
  if (missing.length > 0)
171
248
  throw new DeployError(`no answer for ${missing.join(', ')} (no terminal to ask): set them in the environment of this command`);
172
- for (const line of describeEnv(env))
173
- ctx.host.out.info(line);
249
+ reportEnv(ctx, env);
174
250
  await writeEnv(ctx, env);
175
- await step(ctx, 'infra', async () => stopOnErrors(ctx, await applyInfra(ctx, infra), 'infra'));
176
- await step(ctx, 'validate', async () => stopOnErrors(ctx, await validate(ctx, env.values), 'validate'));
251
+ await step(ctx, 'infra', () => infraStep(ctx, infra));
252
+ await step(ctx, 'validate', () => validateStep(ctx, env.values));
177
253
  ctx.host.out.ok(`.env ready (PORT=${port})`);
178
254
  return 0;
179
255
  }
@@ -186,7 +262,7 @@ export async function run(ctx, options = {}) {
186
262
  const previous = await git(ctx, ['rev-parse', 'HEAD']);
187
263
  if (!skip.has('fetch')) {
188
264
  await step(ctx, 'fetch', async () => {
189
- await git(ctx, ['fetch', '--quiet', config.remote ?? 'origin', config.branch ?? 'main']);
265
+ await git(ctx, ['fetch', '--quiet', config.remote ?? 'origin', config.branch ?? 'main'], { noPrompt: !host.interactive() });
190
266
  await git(ctx, ['merge', '--ff-only', `${config.remote ?? 'origin'}/${config.branch ?? 'main'}`]);
191
267
  });
192
268
  }
@@ -204,17 +280,21 @@ export async function run(ctx, options = {}) {
204
280
  const missing = await answerQuestions(ctx, prepared.env);
205
281
  if (missing.length > 0)
206
282
  throw new DeployError(`no answer for ${missing.join(', ')} (no terminal to ask): set them in the environment of this command`);
207
- for (const line of describeEnv(prepared.env))
208
- host.out.info(line);
283
+ reportEnv(ctx, prepared.env);
209
284
  await writeEnv(ctx, prepared.env);
210
285
  values = prepared.env.values;
211
- await step(ctx, 'infra', async () => stopOnErrors(ctx, await applyInfra(ctx, infra), 'infra'));
286
+ await step(ctx, 'infra', () => infraStep(ctx, infra));
212
287
  await step(ctx, 'build', () => build(ctx, values));
213
- await step(ctx, 'validate', async () => stopOnErrors(ctx, await validate(ctx, values), 'validate'));
214
- if (!skip.has('backup') && config.backup?.beforeMigrate !== false) {
288
+ await step(ctx, 'validate', () => validateStep(ctx, values));
289
+ const backup = backupDecision(config, values, skip);
290
+ if (backup.run) {
215
291
  release.backup = await step(ctx, 'backup', () => backupDatabase(ctx, values, infra, sha));
216
292
  host.out.ok(release.backup);
217
293
  }
294
+ else {
295
+ host.out.step('backup');
296
+ host.out.info(`skipped: ${backup.why}`);
297
+ }
218
298
  await step(ctx, 'migrate', () => migrate(ctx, values));
219
299
  }
220
300
  catch (error) {
@@ -243,7 +323,7 @@ export async function run(ctx, options = {}) {
243
323
  return 1;
244
324
  };
245
325
  try {
246
- await step(ctx, 'release', () => pm2Release(ctx, values));
326
+ host.out.ok(await step(ctx, 'release', () => pm2Release(ctx, values)));
247
327
  }
248
328
  catch (error) {
249
329
  return recover(error.message);
@@ -265,7 +345,7 @@ export async function run(ctx, options = {}) {
265
345
  async function rollbackTo(ctx, sha, values, port) {
266
346
  await restoreCode(ctx, sha, values);
267
347
  ctx.host.out.step(`release ${sha.slice(0, 7)}`);
268
- await pm2Release(ctx, values);
348
+ ctx.host.out.ok(await pm2Release(ctx, values));
269
349
  if (await healthy(ctx, port))
270
350
  ctx.host.out.ok(`back on ${sha.slice(0, 7)}`);
271
351
  else
@@ -314,7 +394,7 @@ export async function status(ctx) {
314
394
  export async function install(ctx, user) {
315
395
  const { host, config } = ctx;
316
396
  if (host.uid() !== 0)
317
- throw new DeployError('install needs root: sudo pnpm exec basalt-deploy install --user=<app user>');
397
+ throw new DeployError(`install needs root: ${INSTALL_COMMAND}`);
318
398
  if (!user || user === 'root')
319
399
  throw new DeployError('install needs the unprivileged user the deploys run as: --user=<name> (never root)');
320
400
  const port = Number(envValues(await readEnv(ctx)).get('PORT'));
package/dist/pm2.d.ts CHANGED
@@ -19,5 +19,5 @@ export declare function pm2Preflight(ctx: DeployContext, port: number): Promise<
19
19
  * `.env`, as it does in development; only what PM2 itself must know is passed.
20
20
  */
21
21
  export declare function processEnv(host: DeployContext['host'], env: Map<string, string>): Record<string, string>;
22
- /** Starts, restarts or re-creates the process. */
23
- export declare function pm2Release(ctx: DeployContext, env: Map<string, string>): Promise<void>;
22
+ /** Starts, restarts or re-creates the process; says which. */
23
+ export declare function pm2Release(ctx: DeployContext, env: Map<string, string>): Promise<string>;
package/dist/pm2.js CHANGED
@@ -81,7 +81,7 @@ export function processEnv(host, env) {
81
81
  out['PM2_HOME'] = pm2Home;
82
82
  return out;
83
83
  }
84
- /** Starts, restarts or re-creates the process. */
84
+ /** Starts, restarts or re-creates the process; says which. */
85
85
  export async function pm2Release(ctx, env) {
86
86
  const { host } = ctx;
87
87
  const name = processName(ctx.config);
@@ -91,13 +91,17 @@ export async function pm2Release(ctx, env) {
91
91
  host.out.info(`pm2 delete ${name} (it ran from ${ours.cwd})`);
92
92
  await must(ctx, ['delete', name], options);
93
93
  }
94
+ let done;
94
95
  if (ours && ours.cwd === ctx.dir) {
95
96
  await must(ctx, ['restart', name, '--update-env'], options);
97
+ done = `${name} restarted`;
96
98
  }
97
99
  else {
98
100
  await must(ctx, ['start', ctx.pm, '--name', name, '--cwd', ctx.dir, '--', 'run', ctx.config.runtime.script], options);
101
+ done = ours ? `${name} re-created in ${ctx.dir}` : `${name} started`;
99
102
  }
100
103
  await must(ctx, ['save'], options);
104
+ return `${done} (${ctx.pm} run ${ctx.config.runtime.script}, port ${env.get('PORT') ?? '?'})`;
101
105
  }
102
106
  async function must(ctx, args, options) {
103
107
  const result = await ctx.host.exec('pm2', args, options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@basaltkit/deploy",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "engines": {
5
5
  "node": ">=22.5.0"
6
6
  },