@volcano.dev/cli 0.0.4

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/LICENSE ADDED
@@ -0,0 +1,184 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and
10
+ distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright
13
+ owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other entities
16
+ that control, are controlled by, or are under common control with that entity.
17
+ For the purposes of this definition, "control" means (i) the power, direct or
18
+ indirect, to cause the direction or management of such entity, whether by
19
+ contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
20
+ outstanding shares, or (iii) beneficial ownership of such entity.
21
+
22
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
23
+ permissions granted by this License.
24
+
25
+ "Source" form shall mean the preferred form for making modifications, including
26
+ but not limited to software source code, documentation source, and configuration
27
+ files.
28
+
29
+ "Object" form shall mean any form resulting from mechanical transformation or
30
+ translation of a Source form, including but not limited to compiled object code,
31
+ generated documentation, and conversions to other media types.
32
+
33
+ "Work" shall mean the work of authorship, whether in Source or Object form,
34
+ made available under the License, as indicated by a copyright notice that is
35
+ included in or attached to the work (an example is provided in the Appendix
36
+ below).
37
+
38
+ "Derivative Works" shall mean any work, whether in Source or Object form, that
39
+ is based on (or derived from) the Work and for which the editorial revisions,
40
+ annotations, elaborations, or other modifications represent, as a whole, an
41
+ original work of authorship. For the purposes of this License, Derivative Works
42
+ shall not include works that remain separable from, or merely link (or bind by
43
+ name) to the interfaces of, the Work and Derivative Works thereof.
44
+
45
+ "Contribution" shall mean any work of authorship, including the original version
46
+ of the Work and any modifications or additions to that Work or Derivative Works
47
+ thereof, that is intentionally submitted to Licensor for inclusion in the Work
48
+ by the copyright owner or by an individual or Legal Entity authorized to submit
49
+ on behalf of the copyright owner. For the purposes of this definition,
50
+ "submitted" means any form of electronic, verbal, or written communication sent
51
+ to the Licensor or its representatives, including but not limited to
52
+ communication on electronic mailing lists, source code control systems, and
53
+ issue tracking systems that are managed by, or on behalf of, the Licensor for
54
+ the purpose of discussing and improving the Work, but excluding communication
55
+ that is conspicuously marked or otherwise designated in writing by the copyright
56
+ owner as "Not a Contribution."
57
+
58
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf
59
+ of whom a Contribution has been received by Licensor and subsequently
60
+ incorporated within the Work.
61
+
62
+ 2. Grant of Copyright License. Subject to the terms and conditions of this
63
+ License, each Contributor hereby grants to You a perpetual, worldwide,
64
+ non-exclusive, no-charge, royalty-free, irrevocable copyright license to
65
+ reproduce, prepare Derivative Works of, publicly display, publicly perform,
66
+ sublicense, and distribute the Work and such Derivative Works in Source or
67
+ Object form.
68
+
69
+ 3. Grant of Patent License. Subject to the terms and conditions of this License,
70
+ each Contributor hereby grants to You a perpetual, worldwide, non-exclusive,
71
+ no-charge, royalty-free, irrevocable (except as stated in this section) patent
72
+ license to make, have made, use, offer to sell, sell, import, and otherwise
73
+ transfer the Work, where such license applies only to those patent claims
74
+ licensable by such Contributor that are necessarily infringed by their
75
+ Contribution(s) alone or by combination of their Contribution(s) with the Work
76
+ to which such Contribution(s) was submitted. If You institute patent litigation
77
+ against any entity (including a cross-claim or counterclaim in a lawsuit)
78
+ alleging that the Work or a Contribution incorporated within the Work
79
+ constitutes direct or contributory patent infringement, then any patent licenses
80
+ granted to You under this License for that Work shall terminate as of the date
81
+ such litigation is filed.
82
+
83
+ 4. Redistribution. You may reproduce and distribute copies of the Work or
84
+ Derivative Works thereof in any medium, with or without modifications, and in
85
+ Source or Object form, provided that You meet the following conditions:
86
+
87
+ (a) You must give any other recipients of the Work or Derivative Works a copy of
88
+ this License; and
89
+
90
+ (b) You must cause any modified files to carry prominent notices stating that
91
+ You changed the files; and
92
+
93
+ (c) You must retain, in the Source form of any Derivative Works that You
94
+ distribute, all copyright, patent, trademark, and attribution notices from the
95
+ Source form of the Work, excluding those notices that do not pertain to any part
96
+ of the Derivative Works; and
97
+
98
+ (d) If the Work includes a "NOTICE" text file as part of its distribution, then
99
+ any Derivative Works that You distribute must include a readable copy of the
100
+ attribution notices contained within such NOTICE file, excluding those notices
101
+ that do not pertain to any part of the Derivative Works, in at least one of the
102
+ following places: within a NOTICE text file distributed as part of the
103
+ Derivative Works; within the Source form or documentation, if provided along
104
+ with the Derivative Works; or, within a display generated by the Derivative
105
+ Works, if and wherever such third-party notices normally appear. The contents of
106
+ the NOTICE file are for informational purposes only and do not modify the
107
+ License. You may add Your own attribution notices within Derivative Works that
108
+ You distribute, alongside or as an addendum to the NOTICE text from the Work,
109
+ provided that such additional attribution notices cannot be construed as
110
+ modifying the License.
111
+
112
+ You may add Your own copyright statement to Your modifications and may provide
113
+ additional or different license terms and conditions for use, reproduction, or
114
+ distribution of Your modifications, or for any such Derivative Works as a whole,
115
+ provided Your use, reproduction, and distribution of the Work otherwise complies
116
+ with the conditions stated in this License.
117
+
118
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any
119
+ Contribution intentionally submitted for inclusion in the Work by You to the
120
+ Licensor shall be under the terms and conditions of this License, without any
121
+ additional terms or conditions. Notwithstanding the above, nothing herein shall
122
+ supersede or modify the terms of any separate license agreement you may have
123
+ executed with Licensor regarding such Contributions.
124
+
125
+ 6. Trademarks. This License does not grant permission to use the trade names,
126
+ trademarks, service marks, or product names of the Licensor, except as required
127
+ for reasonable and customary use in describing the origin of the Work and
128
+ reproducing the content of the NOTICE file.
129
+
130
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
131
+ writing, Licensor provides the Work (and each Contributor provides its
132
+ Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
133
+ KIND, either express or implied, including, without limitation, any warranties
134
+ or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
135
+ PARTICULAR PURPOSE. You are solely responsible for determining the
136
+ appropriateness of using or redistributing the Work and assume any risks
137
+ associated with Your exercise of permissions under this License.
138
+
139
+ 8. Limitation of Liability. In no event and under no legal theory, whether in
140
+ tort (including negligence), contract, or otherwise, unless required by
141
+ applicable law (such as deliberate and grossly negligent acts) or agreed to in
142
+ writing, shall any Contributor be liable to You for damages, including any
143
+ direct, indirect, special, incidental, or consequential damages of any character
144
+ arising as a result of this License or out of the use or inability to use the
145
+ Work (including but not limited to damages for loss of goodwill, work stoppage,
146
+ computer failure or malfunction, or any and all other commercial damages or
147
+ losses), even if such Contributor has been advised of the possibility of such
148
+ damages.
149
+
150
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or
151
+ Derivative Works thereof, You may choose to offer, and charge a fee for,
152
+ acceptance of support, warranty, indemnity, or other liability obligations
153
+ and/or rights consistent with this License. However, in accepting such
154
+ obligations, You may act only on Your own behalf and on Your sole
155
+ responsibility, not on behalf of any other Contributor, and only if You agree to
156
+ indemnify, defend, and hold each Contributor harmless for any liability incurred
157
+ by, or claims asserted against, such Contributor by reason of your accepting any
158
+ such warranty or additional liability.
159
+
160
+ END OF TERMS AND CONDITIONS
161
+
162
+ APPENDIX: How to apply the Apache License to your work.
163
+
164
+ To apply the Apache License to your work, attach the following boilerplate
165
+ notice, with the fields enclosed by brackets "[]" replaced with your own
166
+ identifying information. (Don't include the brackets!) The text should be
167
+ enclosed in the appropriate comment syntax for the file format. We also
168
+ recommend that a file or class name and description of purpose be included on
169
+ the same "printed page" as the copyright notice for easier identification within
170
+ third-party archives.
171
+
172
+ Copyright 2026 Kong Inc.
173
+
174
+ Licensed under the Apache License, Version 2.0 (the "License");
175
+ you may not use this file except in compliance with the License.
176
+ You may obtain a copy of the License at
177
+
178
+ http://www.apache.org/licenses/LICENSE-2.0
179
+
180
+ Unless required by applicable law or agreed to in writing, software
181
+ distributed under the License is distributed on an "AS IS" BASIS,
182
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
183
+ See the License for the specific language governing permissions and
184
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,144 @@
1
+ # volcano-cli
2
+
3
+ `volcano` is the command-line client for Volcano, Kong's hosting platform.
4
+ It provides local development workflows and hosted API commands from a
5
+ standalone Go CLI.
6
+
7
+ ## Quickstart
8
+
9
+ Install the latest published release:
10
+
11
+ ```bash
12
+ curl -fsSL https://github.com/Kong/volcano-cli/releases/latest/download/install.sh | bash
13
+ ```
14
+
15
+ Or install from npm:
16
+
17
+ ```bash
18
+ npm install -g @volcano.dev/cli
19
+ volcano --help
20
+ ```
21
+
22
+ The npm package is a thin wrapper: its `postinstall` step downloads the
23
+ platform-specific binary from the matching GitHub Release and verifies it
24
+ against that release's `SHA256SUMS`. Set `VOLCANO_SKIP_DOWNLOAD=1` to skip the
25
+ download (it is fetched on first run instead).
26
+
27
+ Build from source:
28
+
29
+ ```bash
30
+ make build
31
+ ./volcano --help
32
+ ./volcano --version
33
+ make test
34
+ ```
35
+
36
+ From the CLI checkout, create an empty sibling project directory and run it:
37
+
38
+ ```bash
39
+ VOLCANO_CLI="$(pwd)/volcano"
40
+ mkdir ../volcano-quickstart
41
+ cd ../volcano-quickstart
42
+ "$VOLCANO_CLI" init javascript
43
+ "$VOLCANO_CLI" start
44
+ "$VOLCANO_CLI" variables deploy
45
+ "$VOLCANO_CLI" functions deploy --all
46
+ "$VOLCANO_CLI" config deploy
47
+ "$VOLCANO_CLI" migrations deploy --all -d app
48
+ ```
49
+
50
+ `volcano init` without a template creates a base scaffold (environment
51
+ files, migrations directory, and README). Use a template to add
52
+ language-specific files: `javascript` (aliases: `js`, `node`, `nodejs`),
53
+ `nextjs`, `python`, or `ruby`.
54
+
55
+ ## Authentication
56
+
57
+ New to Volcano? Create an account from the CLI:
58
+
59
+ ```bash
60
+ volcano signup
61
+ ```
62
+
63
+ `volcano signup` prefills your email from `git config --global user.email`
64
+ when available (press Enter to accept, or type a different address), then
65
+ opens Volcano's web signup flow in your browser. Once you finish in the
66
+ browser, the CLI completes the device-authorization handshake and saves your
67
+ credentials to `~/.volcano/config.json` — so a single command signs you up
68
+ **and** logs you in.
69
+
70
+ Already have an account? Authenticate with `volcano login`:
71
+
72
+ ```bash
73
+ # Browser-based login (default)
74
+ volcano login
75
+
76
+ # Token-based login (for CI/CD)
77
+ volcano login --token pk-xxxxxxxxxx
78
+
79
+ # Or skip login entirely with an environment variable
80
+ export VOLCANO_TOKEN=pk-xxxxxxxxxx
81
+ ```
82
+
83
+ Log out at any time (this deletes local credentials but does not revoke the
84
+ token — revoke it in the Volcano dashboard to fully cut off access):
85
+
86
+ ```bash
87
+ volcano logout
88
+ ```
89
+
90
+ To target a non-production environment, set `VOLCANO_API_URL` to that backend's
91
+ API endpoint. `volcano signup` then opens the signup page on the **same**
92
+ environment the API points at — it follows the device-flow verification URL,
93
+ just like `volcano login` — so you normally don't need anything else. Set
94
+ `VOLCANO_WEB_URL` only to force a specific web origin.
95
+
96
+ ## Project configuration (`volcano-config.yaml`)
97
+
98
+ `volcano config deploy` reconciles declarative project configuration
99
+ (`volcano/volcano-config.yaml` or `./volcano-config.yaml`) against the active
100
+ target — the same manifest applies to local mode and cloud.
101
+
102
+ Functions may declare scheduled invocations. `name` and `cron` are required;
103
+ `enabled` (default `true`), `payload`, and `regions` are optional. A function
104
+ entry is valid if it sets `public` **or** declares at least one scheduler.
105
+
106
+ ```yaml
107
+ version: 1
108
+ functions:
109
+ - name: hello
110
+ public: false
111
+ schedulers:
112
+ - name: refresh-cache # required, unique per function (the reconcile key)
113
+ cron: "*/5 * * * *"
114
+ enabled: true
115
+ payload: { job: refresh }
116
+ regions: [us-east-1] # omit to let the server pick one deployed region
117
+ ```
118
+
119
+ Reconciliation follows one rule that mirrors the server: **fields you declare
120
+ are enforced; fields you omit are left server-managed.** An omitted `enabled`,
121
+ `payload`, or `regions` keeps whatever the scheduler already has on the server
122
+ (on first create the server applies its defaults — `enabled: true`, an empty
123
+ payload, and one chosen region). In particular, `config deploy` will not
124
+ re-enable a scheduler you disabled out of band unless the manifest sets
125
+ `enabled: true`. `cron` is always required and enforced.
126
+
127
+ Reconciliation is also **non-destructive**: it creates and updates the
128
+ schedulers a function declares (matched by `name`, preserving the scheduler ID)
129
+ but never deletes or disables one. A scheduler the manifest no longer declares
130
+ is left running; to remove or disable one, use the imperative commands
131
+ (`volcano functions schedulers delete` / `disable`).
132
+
133
+ ## Contributing
134
+
135
+ See `CONTRIBUTING.md` for local workflows, generated-code guidance, release
136
+ notes, and pull request expectations. Participation is governed by
137
+ `CODE_OF_CONDUCT.md`.
138
+
139
+ If you believe you have found a security vulnerability, do not open a public
140
+ issue. Follow `SECURITY.md` instead.
141
+
142
+ ## License
143
+
144
+ Volcano CLI is licensed under the Apache License, Version 2.0. See `LICENSE`.
package/bin/volcano.js ADDED
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ // Launcher shim: exec the platform-specific Volcano CLI binary, forwarding all
5
+ // arguments, stdio, and the exit code. If the binary is missing (e.g. install
6
+ // ran with --ignore-scripts, or the postinstall download failed) it is fetched
7
+ // and verified on demand.
8
+
9
+ const fs = require('fs');
10
+ const { spawn } = require('child_process');
11
+ const { binaryPath, ensureBinary } = require('../scripts/npm/download.js');
12
+
13
+ async function resolveBinary() {
14
+ try {
15
+ const bin = binaryPath();
16
+ if (fs.existsSync(bin)) {
17
+ return bin;
18
+ }
19
+ return await ensureBinary();
20
+ } catch (err) {
21
+ // Covers both download failures and unsupported platforms: binaryPath() ->
22
+ // resolveTarget() throws for e.g. Windows arm64, which passes the
23
+ // package.json os/cpu gate but has no published binary.
24
+ console.error(`volcano: could not obtain the CLI binary: ${err.message}`);
25
+ console.error(
26
+ 'Install it manually from https://github.com/Kong/volcano-cli/releases ' +
27
+ 'or re-install the package.'
28
+ );
29
+ process.exit(1);
30
+ }
31
+ }
32
+
33
+ async function main() {
34
+ const bin = await resolveBinary();
35
+ const child = spawn(bin, process.argv.slice(2), { stdio: 'inherit' });
36
+
37
+ child.on('error', (err) => {
38
+ console.error(`volcano: failed to launch binary: ${err.message}`);
39
+ process.exit(1);
40
+ });
41
+
42
+ child.on('exit', (code, signal) => {
43
+ if (signal) {
44
+ // Re-raise the signal so the parent reflects the child's termination.
45
+ process.kill(process.pid, signal);
46
+ return;
47
+ }
48
+ process.exit(code == null ? 1 : code);
49
+ });
50
+ }
51
+
52
+ main().catch((err) => {
53
+ // Last-resort guard so failures never surface as an unhandled rejection.
54
+ console.error(`volcano: ${err.message}`);
55
+ process.exit(1);
56
+ });
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@volcano.dev/cli",
3
+ "version": "0.0.4",
4
+ "description": "Command-line client for Volcano, Kong's hosting platform.",
5
+ "keywords": [
6
+ "volcano",
7
+ "kong",
8
+ "cli"
9
+ ],
10
+ "homepage": "https://github.com/Kong/volcano-cli#readme",
11
+ "bugs": {
12
+ "url": "https://github.com/Kong/volcano-cli/issues"
13
+ },
14
+ "license": "Apache-2.0",
15
+ "type": "commonjs",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/Kong/volcano-cli.git"
19
+ },
20
+ "bin": {
21
+ "volcano": "bin/volcano.js"
22
+ },
23
+ "files": [
24
+ "bin/volcano.js",
25
+ "scripts/npm/"
26
+ ],
27
+ "scripts": {
28
+ "postinstall": "node scripts/npm/install.js",
29
+ "prepublishOnly": "node -e \"if (require('./package.json').version === '0.0.0') { console.error('Refusing to publish version 0.0.0; set the real version first (npm version <x.y.z>).'); process.exit(1); }\""
30
+ },
31
+ "engines": {
32
+ "node": ">=18"
33
+ },
34
+ "os": [
35
+ "linux",
36
+ "darwin",
37
+ "win32"
38
+ ],
39
+ "cpu": [
40
+ "x64",
41
+ "arm64"
42
+ ],
43
+ "publishConfig": {
44
+ "access": "public"
45
+ }
46
+ }
@@ -0,0 +1,198 @@
1
+ 'use strict';
2
+
3
+ // Shared helpers for downloading and verifying the platform-specific Volcano
4
+ // CLI binary from GitHub Releases. Used by the postinstall script
5
+ // (scripts/npm/install.js) and, as a self-healing fallback, by the launcher
6
+ // shim (bin/volcano.js).
7
+
8
+ const fs = require('fs');
9
+ const path = require('path');
10
+ const http = require('http');
11
+ const https = require('https');
12
+ const crypto = require('crypto');
13
+ const { pipeline } = require('stream');
14
+ const { promisify } = require('util');
15
+
16
+ const streamPipeline = promisify(pipeline);
17
+
18
+ const pkg = require('../../package.json');
19
+
20
+ // Allow pointing at a mirror (kept consistent with scripts/install-volcano.sh).
21
+ const RELEASES_BASE = (
22
+ process.env.VOLCANO_GITHUB_RELEASES_URL ||
23
+ 'https://github.com/Kong/volcano-cli/releases'
24
+ ).replace(/\/+$/, '');
25
+
26
+ // Map Node's platform-arch to the release asset target id.
27
+ const TARGETS = {
28
+ 'linux-x64': 'linux-amd64',
29
+ 'linux-arm64': 'linux-arm64',
30
+ 'darwin-x64': 'macos-amd64',
31
+ 'darwin-arm64': 'macos-arm64',
32
+ 'win32-x64': 'windows-amd64',
33
+ };
34
+
35
+ function resolveTarget() {
36
+ const key = `${process.platform}-${process.arch}`;
37
+ const target = TARGETS[key];
38
+ if (!target) {
39
+ throw new Error(
40
+ `Unsupported platform "${key}". Volcano CLI ships binaries for: ` +
41
+ `${Object.keys(TARGETS).join(', ')}.`
42
+ );
43
+ }
44
+ return target;
45
+ }
46
+
47
+ function binaryExt() {
48
+ return process.platform === 'win32' ? '.exe' : '';
49
+ }
50
+
51
+ function assetName() {
52
+ return `volcano-${resolveTarget()}${binaryExt()}`;
53
+ }
54
+
55
+ // Absolute path where the downloaded binary lives (next to the launcher shim).
56
+ function binaryPath() {
57
+ return path.join(__dirname, '..', '..', 'bin', assetName());
58
+ }
59
+
60
+ function releaseTag() {
61
+ // The npm package version maps 1:1 to the GitHub release tag `v<version>`.
62
+ return `v${pkg.version}`;
63
+ }
64
+
65
+ function get(url, redirects = 0) {
66
+ return new Promise((resolve, reject) => {
67
+ if (redirects > 10) {
68
+ reject(new Error(`Too many redirects while fetching ${url}`));
69
+ return;
70
+ }
71
+ let protocol;
72
+ try {
73
+ protocol = new URL(url).protocol;
74
+ } catch (err) {
75
+ reject(new Error(`Invalid download URL "${url}": ${err.message}`));
76
+ return;
77
+ }
78
+ // Pick the client by scheme so an http:// mirror
79
+ // (VOLCANO_GITHUB_RELEASES_URL) works too.
80
+ const client = protocol === 'https:' ? https : protocol === 'http:' ? http : null;
81
+ if (!client) {
82
+ reject(new Error(`Unsupported URL scheme "${protocol}" for ${url}; use http or https.`));
83
+ return;
84
+ }
85
+ const req = client.get(
86
+ url,
87
+ { headers: { 'User-Agent': `volcano-cli-npm/${pkg.version}` } },
88
+ (res) => {
89
+ const { statusCode, headers } = res;
90
+ if (statusCode >= 300 && statusCode < 400 && headers.location) {
91
+ res.resume();
92
+ const next = new URL(headers.location, url).toString();
93
+ resolve(get(next, redirects + 1));
94
+ return;
95
+ }
96
+ if (statusCode !== 200) {
97
+ res.resume();
98
+ reject(new Error(`Request to ${url} failed with status ${statusCode}`));
99
+ return;
100
+ }
101
+ resolve(res);
102
+ }
103
+ );
104
+ req.on('error', reject);
105
+ req.setTimeout(60000, () => {
106
+ req.destroy(new Error(`Request to ${url} timed out`));
107
+ });
108
+ });
109
+ }
110
+
111
+ async function getText(url) {
112
+ const res = await get(url);
113
+ const chunks = [];
114
+ for await (const chunk of res) chunks.push(chunk);
115
+ return Buffer.concat(chunks).toString('utf8');
116
+ }
117
+
118
+ // Parse a `shasum -a 256` style manifest and return the hex digest for `name`.
119
+ function parseChecksum(manifest, name) {
120
+ const lines = manifest.split('\n');
121
+ for (const line of lines) {
122
+ const match = line.trim().match(/^([a-fA-F0-9]{64})\s+\*?(.+)$/);
123
+ if (match && match[2].trim() === name) {
124
+ return match[1].toLowerCase();
125
+ }
126
+ }
127
+ return null;
128
+ }
129
+
130
+ async function downloadToFile(url, dest) {
131
+ const tmp = `${dest}.download-${process.pid}`;
132
+ try {
133
+ const res = await get(url);
134
+ await streamPipeline(res, fs.createWriteStream(tmp));
135
+ // Hash the fully-written file so we verify exactly what landed on disk
136
+ // (also avoids the flowing-mode subtleties of hashing mid-stream).
137
+ const hash = crypto.createHash('sha256');
138
+ await streamPipeline(fs.createReadStream(tmp), hash);
139
+ const digest = hash.digest('hex');
140
+ // rename does not overwrite an existing destination on Windows, so clear it
141
+ // first (also covers a check-then-write race and force re-downloads).
142
+ fs.rmSync(dest, { force: true });
143
+ fs.renameSync(tmp, dest);
144
+ return digest;
145
+ } catch (err) {
146
+ // Never leave a partial download behind.
147
+ fs.rmSync(tmp, { force: true });
148
+ throw err;
149
+ }
150
+ }
151
+
152
+ // Download the correct binary for the current platform and verify its checksum
153
+ // against the release's SHA256SUMS manifest. Idempotent: no-op if present.
154
+ async function ensureBinary({ force = false } = {}) {
155
+ const dest = binaryPath();
156
+ if (!force && fs.existsSync(dest)) {
157
+ return dest;
158
+ }
159
+
160
+ if (pkg.version === '0.0.0') {
161
+ throw new Error(
162
+ 'No published binary for development version 0.0.0; build from source ' +
163
+ 'with `make build` or install a released version.'
164
+ );
165
+ }
166
+
167
+ const name = assetName();
168
+ const tag = releaseTag();
169
+ const base = `${RELEASES_BASE}/download/${tag}`;
170
+
171
+ const manifest = await getText(`${base}/SHA256SUMS`);
172
+ const expected = parseChecksum(manifest, name);
173
+ if (!expected) {
174
+ throw new Error(`No SHA256 checksum for ${name} in ${tag}/SHA256SUMS`);
175
+ }
176
+
177
+ fs.mkdirSync(path.dirname(dest), { recursive: true });
178
+ const actual = (await downloadToFile(`${base}/${name}`, dest)).toLowerCase();
179
+ if (actual !== expected) {
180
+ fs.rmSync(dest, { force: true });
181
+ throw new Error(
182
+ `Checksum mismatch for ${name}: expected ${expected}, got ${actual}`
183
+ );
184
+ }
185
+
186
+ if (process.platform !== 'win32') {
187
+ fs.chmodSync(dest, 0o755);
188
+ }
189
+ return dest;
190
+ }
191
+
192
+ module.exports = {
193
+ resolveTarget,
194
+ assetName,
195
+ binaryPath,
196
+ releaseTag,
197
+ ensureBinary,
198
+ };
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ // npm postinstall hook: download the platform-specific Volcano CLI binary.
5
+ //
6
+ // Failures here are non-fatal so that `npm install` still succeeds in
7
+ // restricted/offline environments (or with `--ignore-scripts`). In that case
8
+ // the launcher shim (bin/volcano.js) downloads the binary on first use.
9
+
10
+ const { ensureBinary, resolveTarget } = require('./download.js');
11
+ const pkg = require('../../package.json');
12
+
13
+ async function main() {
14
+ if (process.env.VOLCANO_SKIP_DOWNLOAD === '1') {
15
+ console.log('Skipping Volcano CLI download (VOLCANO_SKIP_DOWNLOAD=1).');
16
+ return;
17
+ }
18
+
19
+ // No release exists for the placeholder version, so skip quietly for anyone
20
+ // running `npm install` in a source checkout (the publish workflow stamps a
21
+ // real version before publishing).
22
+ if (pkg.version === '0.0.0') {
23
+ console.log('Skipping Volcano CLI download for development version 0.0.0.');
24
+ return;
25
+ }
26
+
27
+ const target = resolveTarget();
28
+ const binary = await ensureBinary();
29
+ console.log(`Installed Volcano CLI (${target}) -> ${binary}`);
30
+ }
31
+
32
+ main().catch((err) => {
33
+ console.warn(`Warning: could not download the Volcano CLI binary: ${err.message}`);
34
+ console.warn('It will be downloaded automatically the first time you run "volcano".');
35
+ // Exit 0 so installation does not hard-fail; the shim self-heals on first run.
36
+ process.exit(0);
37
+ });