@b12k/caddy 0.0.0-stage → 2.11.7-v.0

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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Bogdan Kolesnyk
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,139 @@
1
- # Temporary Holding Version
1
+ # The missing npm wrapper for [Caddy](https://caddyserver.com)
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [Caddy](https://caddyserver.com) is a web server and reverse proxy with automatic HTTPS.
4
+
5
+ This library is a thin wrapper which automatically downloads the correct Caddy binary for your platform on install, verifies its SHA-512 checksum, and exposes it as a CLI command.
6
+
7
+ ## Installation
8
+
9
+ Typically installed as a dev dependency:
10
+
11
+ **Local (project)**
12
+
13
+ ```bash
14
+ npm install --save-dev @b12k/caddy
15
+ ```
16
+
17
+ Recent npm versions require approving dependency install scripts. Approve this package so its postinstall script can download the Caddy binary:
18
+
19
+ ```bash
20
+ npm approve-scripts @b12k/caddy
21
+ ```
22
+
23
+ ```bash
24
+ pnpm add -D --allow-build=@b12k/caddy @b12k/caddy
25
+ ```
26
+
27
+ pnpm 11 and later require the `--allow-build` flag so this package's postinstall script can download the Caddy binary.
28
+
29
+ ```bash
30
+ yarn add --dev @b12k/caddy
31
+ ```
32
+
33
+ **Global**
34
+
35
+ ```bash
36
+ npm install -g --allow-scripts=@b12k/caddy @b12k/caddy
37
+ ```
38
+
39
+ Global npm installs cannot use `npm approve-scripts`; use `--allow-scripts` instead.
40
+
41
+ ```bash
42
+ pnpm add -g --allow-build=@b12k/caddy @b12k/caddy
43
+ ```
44
+
45
+ pnpm 11 and later require the `--allow-build` flag during global install as well.
46
+
47
+ ```bash
48
+ yarn global add @b12k/caddy
49
+ ```
50
+
51
+ The postinstall script downloads the standard Caddy binary for your platform from the [official GitHub release](https://github.com/caddyserver/caddy/releases). Custom builds and additional plugins are not included.
52
+
53
+ If you already installed with npm or pnpm and the build was blocked, approve and rebuild it:
54
+
55
+ ```bash
56
+ npm approve-scripts @b12k/caddy
57
+ npm rebuild @b12k/caddy
58
+ ```
59
+
60
+ ```bash
61
+ pnpm approve-builds @b12k/caddy
62
+ pnpm rebuild @b12k/caddy
63
+ ```
64
+
65
+ ## Usage
66
+
67
+ See the [Caddy CLI documentation](https://caddyserver.com/docs/command-line) for the full list of commands and flags.
68
+
69
+ **Local install**
70
+
71
+ ```bash
72
+ npx caddy run --config Caddyfile
73
+ ```
74
+
75
+ ```bash
76
+ pnpm exec caddy run --config Caddyfile
77
+ ```
78
+
79
+ ```bash
80
+ yarn caddy run --config Caddyfile
81
+ ```
82
+
83
+ **Global install**
84
+
85
+ ```bash
86
+ caddy run --config Caddyfile
87
+ ```
88
+
89
+ **`package.json` script**
90
+
91
+ ```json
92
+ { "scripts": { "serve": "caddy run --config Caddyfile" } }
93
+ ```
94
+
95
+ To serve the current directory without a Caddyfile:
96
+
97
+ ```bash
98
+ pnpm exec caddy file-server --listen localhost:8080
99
+ ```
100
+
101
+ To check the installed binary version:
102
+
103
+ ```bash
104
+ pnpm exec caddy version
105
+ ```
106
+
107
+ ## Troubleshooting
108
+
109
+ If the binary fails to install, re-run with `--foreground-scripts` to see the postinstall output:
110
+
111
+ ```bash
112
+ npm install --save-dev @b12k/caddy --foreground-scripts
113
+ ```
114
+
115
+ ```bash
116
+ pnpm add -D --allow-build=@b12k/caddy @b12k/caddy --foreground-scripts
117
+ ```
118
+
119
+ ```bash
120
+ yarn add --dev @b12k/caddy --foreground-scripts
121
+ ```
122
+
123
+ ## Supported platforms
124
+
125
+ - Linux — x64, arm64
126
+ - macOS — x64, arm64
127
+ - Windows — x64, arm64
128
+
129
+ ## Version
130
+
131
+ The npm package version mirrors the Caddy release version, with a wrapper revision suffix (for example, `2.11.7-v.0`).
132
+
133
+ To install a different Caddy release, define it in `.caddy-version` as `v2.11.7` or `2.11.7` before installing the package. The file is read from the install command's initial working directory (`INIT_CWD`), or the current working directory when `INIT_CWD` is unset.
134
+
135
+ If you add or change `.caddy-version` after installing, run from that directory:
136
+
137
+ ```bash
138
+ pnpm exec caddy-install
139
+ ```
package/dist/cli.js ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env node
2
+ import { spawn } from "node:child_process";
3
+ import { access } from "node:fs/promises";
4
+ import update_notifier from "update-notifier";
5
+ import { binaryPath, name as external_config_js_name, version } from "./config.js";
6
+ import { logError } from "./log.js";
7
+ function setErrorExitCode(errorName, metaInfo) {
8
+ try {
9
+ logError(errorName, metaInfo);
10
+ } catch {
11
+ process.exitCode = 1;
12
+ }
13
+ }
14
+ update_notifier({
15
+ pkg: {
16
+ name: external_config_js_name,
17
+ version: version
18
+ },
19
+ shouldNotifyInNpmScript: true,
20
+ updateCheckInterval: 86400000
21
+ }).notify({
22
+ defer: false
23
+ });
24
+ let canSpawn = true;
25
+ try {
26
+ await access(binaryPath);
27
+ } catch {
28
+ setErrorExitCode('binaryNotFound');
29
+ canSpawn = false;
30
+ }
31
+ if (canSpawn) {
32
+ const childProcess = spawn(binaryPath, process.argv.slice(2), {
33
+ stdio: 'inherit'
34
+ });
35
+ childProcess.on('error', (error)=>{
36
+ setErrorExitCode('executionFailed', error.message);
37
+ });
38
+ childProcess.on('exit', (code, signal)=>{
39
+ if (signal) return void process.kill(process.pid, signal);
40
+ process.exitCode = code ?? 1;
41
+ });
42
+ }
package/dist/config.js ADDED
@@ -0,0 +1,50 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import node_path from "node:path";
3
+ import package_0 from "../package.json" with {
4
+ type: "json"
5
+ };
6
+ const platform = 'win32' === process.platform ? 'windows' : process.platform;
7
+ const isWindows = 'windows' === platform;
8
+ const { arch: architecture } = process;
9
+ const { name: config_name, version: version } = package_0;
10
+ const [defaultVersion = ''] = version.split('-', 1);
11
+ const versionFileName = '.caddy-version';
12
+ const versionFilePath = node_path.join(process.env['INIT_CWD'] ?? process.cwd(), versionFileName);
13
+ let versionOverride;
14
+ try {
15
+ const fileContents = await readFile(versionFilePath, 'utf8');
16
+ versionOverride = fileContents.trim().replace(/^v/u, '');
17
+ } catch (error) {
18
+ if (!(error instanceof Error && 'code' in error && 'ENOENT' === error.code)) {
19
+ const message = Error.isError(error) ? error.message : 'Unknown error.';
20
+ throw new Error(`Failed to read ${versionFileName}: ${message}`, {
21
+ cause: error
22
+ });
23
+ }
24
+ versionOverride = '';
25
+ }
26
+ const libraryVersion = versionOverride || defaultVersion;
27
+ const currentDirectory = import.meta.dirname;
28
+ const libraryName = 'caddy';
29
+ const binaryExtension = isWindows ? '.exe' : '';
30
+ const binaryFileName = `${libraryName}${binaryExtension}`;
31
+ const binaryPath = node_path.join(currentDirectory, binaryFileName);
32
+ const archiveExtension = isWindows ? '.zip' : '.tar.gz';
33
+ const archivePlatform = 'darwin' === platform ? 'mac' : platform;
34
+ const archiveArchitecture = 'x64' === architecture ? 'amd64' : architecture;
35
+ const archiveFileName = `${libraryName}_${libraryVersion}_${archivePlatform}_${archiveArchitecture}${archiveExtension}`;
36
+ const checksumsFileName = `${libraryName}_${libraryVersion}_checksums.txt`;
37
+ const caddyGithubUrl = `https://github.com/caddyserver/caddy/releases/download/v${libraryVersion}`;
38
+ const archiveGithubUrl = `${caddyGithubUrl}/${archiveFileName}`;
39
+ const checksumsGithubUrl = `${caddyGithubUrl}/${checksumsFileName}`;
40
+ const archivePath = node_path.join(currentDirectory, archiveFileName);
41
+ const supportedPlatforms = [
42
+ 'darwin',
43
+ 'windows',
44
+ 'linux'
45
+ ];
46
+ const supportedArchitectures = [
47
+ 'x64',
48
+ 'arm64'
49
+ ];
50
+ export { architecture, archiveFileName, archiveGithubUrl, archivePath, binaryPath, checksumsGithubUrl, config_name as name, currentDirectory, libraryName, libraryVersion, platform, supportedArchitectures, supportedPlatforms, version };
package/dist/errors.js ADDED
@@ -0,0 +1,27 @@
1
+ const ERRORS_BY_KEY = {
2
+ binaryNotFound: {
3
+ instruction: 'Try re-installing the library.',
4
+ message: 'Binary not found.'
5
+ },
6
+ executionFailed: {
7
+ instruction: 'Try re-installing the library.',
8
+ message: 'Failed to execute the binary.'
9
+ },
10
+ installationFailed: {
11
+ instruction: '',
12
+ message: 'Failed to install the binary.'
13
+ },
14
+ unsupportedArchitecture: {
15
+ instruction: 'Supported architectures are x64 and arm64.',
16
+ message: 'Unsupported architecture.'
17
+ },
18
+ unsupportedArchiveFormat: {
19
+ instruction: 'Supported archive formats are .zip and .tar.gz.',
20
+ message: 'Unsupported archive format.'
21
+ },
22
+ unsupportedPlatform: {
23
+ instruction: 'Supported platforms are darwin, windows and linux.',
24
+ message: 'Unsupported platform.'
25
+ }
26
+ };
27
+ export { ERRORS_BY_KEY };
@@ -0,0 +1,23 @@
1
+ import { execFile } from "node:child_process";
2
+ import { promisify } from "node:util";
3
+ import { extract } from "tar";
4
+ import { logError } from "./log.js";
5
+ const execFileAsync = promisify(execFile);
6
+ async function extractArchive(archivePath, targetDirectoryPath) {
7
+ if (archivePath.endsWith('.zip')) {
8
+ const quotedArchivePath = `'${archivePath.replaceAll("'", "''")}'`;
9
+ const quotedTargetDirectoryPath = `'${targetDirectoryPath.replaceAll("'", "''")}'`;
10
+ await execFileAsync('powershell.exe', [
11
+ '-NoProfile',
12
+ '-Command',
13
+ `Expand-Archive -LiteralPath ${quotedArchivePath} -DestinationPath ${quotedTargetDirectoryPath} -Force`
14
+ ]);
15
+ return;
16
+ }
17
+ if (archivePath.endsWith('.tar.gz')) return void await extract({
18
+ cwd: targetDirectoryPath,
19
+ file: archivePath
20
+ });
21
+ logError('unsupportedArchiveFormat', archivePath);
22
+ }
23
+ export { extractArchive };
package/dist/log.js ADDED
@@ -0,0 +1,19 @@
1
+ import boxen from "boxen";
2
+ import { libraryName } from "./config.js";
3
+ import { ERRORS_BY_KEY } from "./errors.js";
4
+ function log(message, options) {
5
+ console.log(boxen(message, options));
6
+ }
7
+ const errorPrefix = `[${libraryName}]`;
8
+ function logError(errorName, metaInfo) {
9
+ const error = ERRORS_BY_KEY[errorName];
10
+ let logMessage = error.message;
11
+ if (error.instruction) logMessage += `\n\n${error.instruction}`;
12
+ if (metaInfo) logMessage += `\n\n${metaInfo}`;
13
+ log(logMessage, {
14
+ borderColor: 'red',
15
+ title: errorPrefix
16
+ });
17
+ throw new Error(`${errorPrefix} ${error.message}`);
18
+ }
19
+ export { log, logError };
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env node
2
+ import { createHash } from "node:crypto";
3
+ import { createWriteStream } from "node:fs";
4
+ import { readFile, rm } from "node:fs/promises";
5
+ import { pipeline } from "node:stream/promises";
6
+ import { architecture, archiveFileName, archiveGithubUrl, archivePath, binaryPath, checksumsGithubUrl, currentDirectory, libraryName, platform, supportedArchitectures, supportedPlatforms } from "./config.js";
7
+ import { extractArchive } from "./extract-archive.js";
8
+ import { log, logError } from "./log.js";
9
+ const DOWNLOAD_TIMEOUT_MS = 300000;
10
+ if (!supportedPlatforms.includes(platform)) logError('unsupportedPlatform');
11
+ if (!supportedArchitectures.includes(architecture)) logError('unsupportedArchitecture');
12
+ async function createFetchResponse(url) {
13
+ const response = await fetch(url, {
14
+ signal: AbortSignal.timeout(DOWNLOAD_TIMEOUT_MS)
15
+ });
16
+ if (!response.ok) throw new Error(String(response.status));
17
+ return response;
18
+ }
19
+ async function downloadArchive() {
20
+ log(archiveGithubUrl, {
21
+ borderColor: 'green',
22
+ title: `${libraryName}:download`
23
+ });
24
+ const response = await createFetchResponse(archiveGithubUrl);
25
+ if (!response.body) throw new Error('Archive download returned no body.');
26
+ log(archivePath, {
27
+ borderColor: 'green',
28
+ title: `${libraryName}:save`
29
+ });
30
+ await pipeline(response.body, createWriteStream(archivePath));
31
+ }
32
+ async function ensureArchiveChecksum() {
33
+ log(checksumsGithubUrl, {
34
+ borderColor: 'green',
35
+ title: `${libraryName}:verify`
36
+ });
37
+ const response = await createFetchResponse(checksumsGithubUrl);
38
+ const checksums = await response.text();
39
+ const checksum = checksums.split('\n').find((line)=>line.endsWith(` ${archiveFileName}`))?.split(/\s+/u, 1)[0];
40
+ if (!checksum) throw new Error(`Checksum not found for ${archiveFileName}.`);
41
+ const archive = await readFile(archivePath);
42
+ const actualChecksum = createHash('sha512').update(archive).digest('hex');
43
+ if (actualChecksum !== checksum) throw new Error(`Checksum mismatch for ${archiveFileName}.`);
44
+ }
45
+ async function install() {
46
+ await downloadArchive();
47
+ await ensureArchiveChecksum();
48
+ log(currentDirectory, {
49
+ borderColor: 'green',
50
+ title: `${libraryName}:extract`
51
+ });
52
+ await extractArchive(archivePath, currentDirectory);
53
+ log(binaryPath, {
54
+ borderColor: 'green',
55
+ title: `${libraryName}:installed`
56
+ });
57
+ }
58
+ async function installWithCleanup() {
59
+ try {
60
+ await install();
61
+ } finally{
62
+ await rm(archivePath, {
63
+ force: true
64
+ });
65
+ }
66
+ }
67
+ try {
68
+ await installWithCleanup();
69
+ } catch (error) {
70
+ let message = 'Unknown error.';
71
+ if (Error.isError(error)) message = error.message;
72
+ logError('installationFailed', message);
73
+ }
package/package.json CHANGED
@@ -1,6 +1,93 @@
1
1
  {
2
2
  "name": "@b12k/caddy",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "2.11.7-v.0",
4
+ "description": "The missing NPM wrapper for Caddy",
5
+ "keywords": [
6
+ "automatic-https",
7
+ "caddy",
8
+ "cli",
9
+ "development",
10
+ "http",
11
+ "https",
12
+ "npm",
13
+ "reverse-proxy",
14
+ "server",
15
+ "static-files",
16
+ "web-server",
17
+ "wrapper"
18
+ ],
19
+ "license": "MIT",
20
+ "author": "Bogdan Kolesnyk",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/b12k/caddy.git"
24
+ },
25
+ "bin": {
26
+ "caddy": "dist/cli.js",
27
+ "caddy-install": "dist/postinstall.js"
28
+ },
29
+ "files": [
30
+ "dist",
31
+ "scripts"
32
+ ],
33
+ "type": "module",
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
37
+ "scripts": {
38
+ "build": "rslib",
39
+ "check": "run-p -l check:*",
40
+ "check:format": "oxfmt . --check",
41
+ "check:scripts": "oxlint",
42
+ "check:types": "tsc --noEmit",
43
+ "deps:check": "ncu -e 2 -c 1",
44
+ "deps:update": "ncu -du --doctorInstall \"pnpm deps:update:install\" --doctorTest \"pnpm deps:update:doctor\" -c 1",
45
+ "deps:update:doctor": "run-p -l check:types check:scripts build",
46
+ "deps:update:install": "pnpm i --no-frozen-lockfile",
47
+ "dev": "rslib --watch",
48
+ "fix": "run-s -l fix:*",
49
+ "fix:format": "oxfmt . --write",
50
+ "fix:scripts": "oxlint --fix",
51
+ "ga:notify": "tsx .github/notify.ts",
52
+ "ga:update-caddy": "tsx .github/update-caddy.ts",
53
+ "husky:commit-msg": "commitlint",
54
+ "husky:pre-commit": "lint-staged",
55
+ "husky:pre-push": "branch-name-lint",
56
+ "postinstall": "node scripts/postinstall.js",
57
+ "prepack": "run-p check build",
58
+ "prepare": "husky",
59
+ "release": "release-it --preRelease=v"
60
+ },
61
+ "dependencies": {
62
+ "boxen": "9.0.0",
63
+ "pnpm": "12.16.1",
64
+ "tar": "7.5.22",
65
+ "update-notifier": "7.3.1"
66
+ },
67
+ "devDependencies": {
68
+ "@b12k/branch-name-lint": "1.3.0",
69
+ "@commitlint/config-conventional": "21.2.4",
70
+ "@release-it/conventional-changelog": "12.0.2",
71
+ "@rslib/core": "1.0.5",
72
+ "@types/node": "26.6.6",
73
+ "@types/semver": "7.8.0",
74
+ "@types/update-notifier": "6.0.9",
75
+ "commitlint": "21.2.4",
76
+ "eslint-plugin-perfectionist": "5.13.0",
77
+ "husky": "9.1.7",
78
+ "lint-staged": "17.6.0",
79
+ "npm-check-updates": "23.1.1",
80
+ "npm-run-all2": "9.0.4",
81
+ "oxfmt": "0.75.0",
82
+ "oxlint": "1.90.0",
83
+ "oxlint-tsgolint": "7.0.2005",
84
+ "release-it": "21.1.2",
85
+ "semver": "7.8.5",
86
+ "tsx": "4.23.15",
87
+ "typescript": "7.0.2"
88
+ },
89
+ "engines": {
90
+ "node": ">=24"
91
+ },
92
+ "packageManager": "pnpm@12.16.1"
93
+ }
@@ -0,0 +1,7 @@
1
+ import path from 'node:path';
2
+ import { pathToFileURL } from 'node:url';
3
+
4
+ const directory = import.meta.dirname;
5
+ // oxlint-disable-next-line unicorn/no-process-exit
6
+ if (!directory.includes('node_modules')) process.exit(0);
7
+ await import(pathToFileURL(path.join(directory, '../dist/postinstall.js')).href);