scp-next 1.0.19 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## Unreleased
4
+
5
+ - Added opt-in, repeatable `--post-upload-command` commands for CLI uploads and configured
6
+ upload jobs.
7
+ - Added library `postUploadCommands`, `client.exec()`, `ExecResult`, and typed
8
+ `RemoteCommandError` APIs.
9
+ - Kept remote command execution separate from SFTP, sequential, disabled for downloads and dry
10
+ runs, and fail-fast on non-zero exit codes.
11
+ - Added bounded command output capture, CLI failure propagation, secret redaction, and mock-based
12
+ coverage for upload failure, ordering, command failure, dry-run, and connection cleanup.
13
+
3
14
  ## 1.0.19
4
15
 
5
16
  - Refined README structure for clearer installation, quick start, basic usage, advanced usage,
@@ -9,7 +20,7 @@
9
20
  - Clarified SSH agent usage, `SSH_AUTH_SOCK`, timeout behavior, and configuration-file
10
21
  recommendations.
11
22
  - Expanded GitHub Pages documentation with CLI, library, and configuration options.
12
- - Moved release notes under `docs/release-notes/` for cleaner documentation organization.
23
+ - Moved release notes under `guides/release-notes/` for cleaner documentation organization.
13
24
 
14
25
  ## 1.0.14
15
26
 
package/README.md CHANGED
@@ -19,25 +19,27 @@
19
19
  It uses SFTP internally through `ssh2-sftp-client` instead of implementing SCP or SFTP protocols manually.
20
20
  Developer documentation is available at [GitHub Pages](https://chengchuu.github.io/scp-next/).
21
21
 
22
+ ## Features
23
+
24
+ - Upload and download files or directories recursively.
25
+ - CLI usage with clear `<source> <destination>` operands.
26
+ - ESM `import` and CommonJS `require` support.
27
+ - JSON configuration files, named profiles, and configured jobs.
28
+ - Reusable transfer client.
29
+ - Optional sequential remote commands after a successful upload.
30
+
22
31
  ## Contents
23
32
 
24
33
  - [Installation](#installation)
25
34
  - [Quick Start](#quick-start)
26
- - [Basic Usage](#basic-usage)
35
+ - [CLI Usage](#cli-usage)
27
36
  - [CLI Options](#cli-options)
28
37
  - [Library Usage](#library-usage)
29
38
  - [Library Options](#library-options)
30
39
  - [Advanced Usage](#advanced-usage)
31
40
  - [Configuration File Options](#configuration-file-options)
32
41
  - [Environment Variables](#environment-variables)
33
-
34
- ## Features
35
-
36
- - Upload and download files or directories recursively.
37
- - CLI usage with clear `<source> <destination>` operands.
38
- - ESM `import` and CommonJS `require` support.
39
- - JSON configuration files, named profiles, and configured jobs.
40
- - Reusable transfer client.
42
+ - [User Guides](#user-guides)
41
43
 
42
44
  ## Installation
43
45
 
@@ -99,7 +101,7 @@ await upload({
99
101
  });
100
102
  ```
101
103
 
102
- ## Basic Usage
104
+ ## CLI Usage
103
105
 
104
106
  ### CLI Syntax
105
107
 
@@ -144,6 +146,21 @@ scp-next upload ./dist /var/www/example \
144
146
  --verbose
145
147
  ```
146
148
 
149
+ Run commands after a successful upload:
150
+
151
+ ```bash
152
+ scp-next upload ./dist /var/www/example \
153
+ --host your-host \
154
+ --username your-username \
155
+ --recursive \
156
+ --post-upload-command "cd /var/www/example && npm install --omit=dev" \
157
+ --post-upload-command "pm2 reload example"
158
+ ```
159
+
160
+ `--post-upload-command` is repeatable and upload-only. Commands run sequentially on the
161
+ remote server with the SSH user's permissions. The first non-zero exit code stops the sequence
162
+ and makes the CLI exit non-zero. A missing exit status is also treated as failure.
163
+
147
164
  Use an encrypted private key:
148
165
 
149
166
  ```bash
@@ -201,6 +218,7 @@ scp-next run download-logs --config ./scp-next.config.json
201
218
  | `--create-directories` | Create missing destination directories. Enabled by default. |
202
219
  | `--no-create-directories` | Disable automatic destination directory creation. |
203
220
  | `--dry-run` | Resolve and validate the operation without connecting or transferring. |
221
+ | `--post-upload-command <command>` | Run a remote command after a successful upload. Repeatable. |
204
222
  | `--timeout <milliseconds>` | SSH connection ready timeout in milliseconds. |
205
223
  | `--verbose` | Print non-sensitive diagnostic details. |
206
224
  | `--quiet` | Disable progress and non-error output. |
@@ -223,7 +241,11 @@ await upload({
223
241
  localPath: "./dist",
224
242
  remotePath: "/var/www/example",
225
243
  recursive: true,
226
- overwrite: true
244
+ overwrite: true,
245
+ postUploadCommands: [
246
+ "cd /var/www/example && npm install --omit=dev",
247
+ "pm2 reload example"
248
+ ]
227
249
  });
228
250
  ```
229
251
 
@@ -262,6 +284,8 @@ const client = createClient({
262
284
  try {
263
285
  await client.connect();
264
286
  await client.upload("./dist", "/var/www/example", { recursive: true });
287
+ const result = await client.exec("pm2 reload example");
288
+ console.log(result.stdout);
265
289
  await client.download("/var/log/example.log", "./logs/example.log");
266
290
  } finally {
267
291
  await client.close();
@@ -292,26 +316,33 @@ await upload({
292
316
 
293
317
  ### Library Options
294
318
 
295
- | Field | Used by | Description |
296
- | ------------------- | ----------------- | ------------------------------------------------------------ |
297
- | `host` | server | SSH server host. |
298
- | `port` | server | SSH server port. Defaults to `22`. |
299
- | `username` | server | SSH username. |
300
- | `password` | server | SSH password. |
301
- | `privateKey` | server | Private-key content as a string or Buffer. |
302
- | `privateKeyFile` | server | Private-key file path. |
303
- | `passphrase` | server | Passphrase for an encrypted private key. |
304
- | `agent` | server | SSH agent socket path. |
305
- | `hostFingerprint` | server | Expected server host-key SHA-256 fingerprint. |
306
- | `knownHostsFile` | server | Known-hosts file for host verification. |
307
- | `localPath` | upload/download | Local source for upload or local destination for download. |
308
- | `remotePath` | upload/download | Remote destination for upload or remote source for download. |
309
- | `recursive` | transfer | Transfer directories recursively. Defaults to `false`. |
310
- | `overwrite` | transfer | Allow replacing existing files. |
311
- | `createDirectories` | transfer | Create missing destination directories. Defaults to `true`. |
312
- | `dryRun` | transfer | Validate and plan without modifying local or remote files. |
313
- | `timeout` | server/transfer | SSH connection ready timeout in milliseconds. |
314
- | `onProgress` | transfer | Progress callback for file and directory transfers. |
319
+ | Field | Used by | Description |
320
+ | ------------------- | --------------- | ------------------------------------------------------------ |
321
+ | `host` | server | SSH server host. |
322
+ | `port` | server | SSH server port. Defaults to `22`. |
323
+ | `username` | server | SSH username. |
324
+ | `password` | server | SSH password. |
325
+ | `privateKey` | server | Private-key content as a string or Buffer. |
326
+ | `privateKeyFile` | server | Private-key file path. |
327
+ | `passphrase` | server | Passphrase for an encrypted private key. |
328
+ | `agent` | server | SSH agent socket path. |
329
+ | `hostFingerprint` | server | Expected server host-key SHA-256 fingerprint. |
330
+ | `knownHostsFile` | server | Known-hosts file for host verification. |
331
+ | `localPath` | upload/download | Local source for upload or local destination for download. |
332
+ | `remotePath` | upload/download | Remote destination for upload or remote source for download. |
333
+ | `recursive` | transfer | Transfer directories recursively. Defaults to `false`. |
334
+ | `overwrite` | transfer | Allow replacing existing files. |
335
+ | `createDirectories` | transfer | Create missing destination directories. Defaults to `true`. |
336
+ | `dryRun` | transfer | Validate and plan without modifying local or remote files. |
337
+ | `timeout` | server/transfer | SSH connection ready timeout in milliseconds. |
338
+ | `postUploadCommands` | upload | Remote command strings run sequentially after success. |
339
+ | `onProgress` | transfer | Progress callback for file and directory transfers. |
340
+
341
+ `client.exec(command, options)` returns `ExecResult` with `stdout`, `stderr`, `exitCode`,
342
+ and an optional signal. Its optional `timeout` is command-specific; `failOnStderr` can treat
343
+ stderr output as failure even when the exit code is zero. `maxBuffer` limits combined captured
344
+ output and defaults to 10 MiB. A timeout closes the SSH channel; whether the remote process is
345
+ terminated depends on the SSH server.
315
346
 
316
347
  ## Advanced Usage
317
348
 
@@ -417,7 +448,11 @@ Jobs use `source` and `destination`; the `operation` determines which path is lo
417
448
  "source": "./dist",
418
449
  "destination": "/var/www/example",
419
450
  "recursive": true,
420
- "overwrite": true
451
+ "overwrite": true,
452
+ "postUploadCommands": [
453
+ "cd /var/www/example && npm install --omit=dev",
454
+ "pm2 reload example"
455
+ ]
421
456
  },
422
457
  "download-logs": {
423
458
  "operation": "download",
@@ -532,7 +567,7 @@ Interactive terminals display concise progress. Progress is disabled with `--qui
532
567
 
533
568
  ### Dry Run
534
569
 
535
- `--dry-run` resolves configuration and validates local paths and transfer direction without connecting to the remote server or modifying local/remote files.
570
+ `--dry-run` resolves configuration and validates local paths and transfer direction without connecting to the remote server, transferring files, or executing post-upload commands. Planned post-upload commands are shown with known and recognizable secret values redacted.
536
571
 
537
572
  ```text
538
573
  Dry run: upload
@@ -540,6 +575,10 @@ Source: ./dist
540
575
  Destination: your-username@your-host:/var/www/example
541
576
  Recursive: yes
542
577
  Overwrite: yes
578
+
579
+ Post-upload commands:
580
+ 1. cd /var/www/example && npm install --omit=dev
581
+ 2. pm2 reload example
543
582
  ```
544
583
 
545
584
  ## Error Handling
@@ -552,6 +591,7 @@ Public typed errors:
552
591
  - `AuthenticationError`
553
592
  - `ConnectionError`
554
593
  - `TransferError`
594
+ - `RemoteCommandError`
555
595
  - `FileSystemError`
556
596
  - `HostVerificationError`
557
597
 
@@ -581,7 +621,7 @@ try {
581
621
  Primary functions:
582
622
 
583
623
  ```ts
584
- upload(options: UploadOptions): Promise<void>
624
+ upload(options: UploadOptions): Promise<ExecResult[]>
585
625
  download(options: DownloadOptions): Promise<void>
586
626
  createClient(options: ScpServerOptions): ScpNextClient
587
627
  copy(options: CopyOptions): Promise<void>
@@ -589,6 +629,18 @@ copy(options: CopyOptions): Promise<void>
589
629
 
590
630
  Upload and download APIs use explicit `localPath` and `remotePath` names.
591
631
  The optional generic `copy()` API accepts typed local/remote endpoint objects.
632
+ `ScpNextClient.exec(command, options)` executes one command directly through SSH.
633
+
634
+ Post-upload execution is disabled unless `postUploadCommands` is present. Commands are sent
635
+ directly to the remote SSH server, never through a local shell, and never run for downloads or
636
+ dry runs. Do not put passwords, tokens, or other secrets directly in command strings; command
637
+ output may also contain application data. `scp-next` redacts known credentials and common secret
638
+ assignment forms from CLI logs and errors.
639
+
640
+ ## User Guides
641
+
642
+ - [English](https://github.com/chengchuu/scp-next/blob/main/guides/release-notes/introducing-scp-next-v1.0.19-en.md)
643
+ - [简体中文](https://github.com/chengchuu/scp-next/blob/main/guides/release-notes/introducing-scp-next-v1.0.19-zh.md)
592
644
 
593
645
  ## Development
594
646
 
@@ -598,6 +650,8 @@ npm run typecheck
598
650
  npm run lint
599
651
  npm test
600
652
  npm run build
653
+ npm run docs:links
654
+ npm run docs:build
601
655
  npm pack --dry-run
602
656
  ```
603
657
 
@@ -605,7 +659,9 @@ npm pack --dry-run
605
659
 
606
660
  ## Publishing
607
661
 
608
- The published package includes `dist`, README, license, changelog, and docs. The CLI entry is `dist/cli/index.js` and contains a Node.js shebang.
662
+ The published package includes `dist`, README, license, changelog, and handwritten guides. The CLI
663
+ entry is `dist/cli/index.js` and contains a Node.js shebang. `npm run docs:build` generates the
664
+ GitHub Pages artifact under `docs/`; do not edit or commit that output directly.
609
665
 
610
666
  ## Transfer Mechanism
611
667