@jsenv/https-local 3.2.44 → 3.5.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/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@jsenv/https-local",
3
- "version": "3.2.44",
3
+ "version": "3.5.0",
4
+ "type": "module",
4
5
  "description": "A programmatic way to generate locally trusted certificates",
5
6
  "repository": {
6
7
  "type": "git",
@@ -8,15 +9,17 @@
8
9
  "directory": "packages/tooling/https-local"
9
10
  },
10
11
  "license": "MIT",
11
- "type": "module",
12
+ "engines": {
13
+ "node": ">=20.0.0"
14
+ },
15
+ "bin": "./src/https_local_cli.mjs",
16
+ "main": "./src/main.js",
12
17
  "exports": {
13
18
  ".": {
14
19
  "import": "./src/main.js"
15
20
  },
16
21
  "./*": "./*"
17
22
  },
18
- "main": "./src/main.js",
19
- "bin": "./src/https_local_cli.mjs",
20
23
  "files": [
21
24
  "/src/"
22
25
  ],
@@ -38,7 +41,7 @@
38
41
  "@jsenv/humanize": "1.7.6",
39
42
  "@jsenv/urls": "2.9.8",
40
43
  "command-exists": "1.2.9",
41
- "node-forge": "1.3.3",
44
+ "node-forge": "1.4.0",
42
45
  "sudo-prompt": "9.2.1",
43
46
  "which": "6.0.1"
44
47
  },
@@ -46,10 +49,8 @@
46
49
  "@jsenv/assert": "../assert",
47
50
  "@jsenv/https-local": "./",
48
51
  "@jsenv/performance-impact": "../performance-impact",
49
- "playwright": "1.58.1"
50
- },
51
- "engines": {
52
- "node": ">=20.0.0"
52
+ "@jsenv/test": "../../related/test",
53
+ "playwright": "1.59.1"
53
54
  },
54
55
  "publishConfig": {
55
56
  "access": "public"
@@ -2,18 +2,29 @@
2
2
 
3
3
  import {
4
4
  installCertificateAuthority,
5
+ requestCertificate,
5
6
  uninstallCertificateAuthority,
6
7
  verifyHostsFile,
7
8
  } from "@jsenv/https-local";
9
+ import { writeFileSync } from "node:fs";
8
10
  import { parseArgs } from "node:util";
9
11
 
10
12
  const options = {
11
- help: {
13
+ "help": {
12
14
  type: "boolean",
13
15
  },
14
- trust: {
16
+ "trust": {
15
17
  type: "boolean",
16
18
  },
19
+ "certificate": {
20
+ type: "string",
21
+ },
22
+ "private-key": {
23
+ type: "string",
24
+ },
25
+ "hostnames": {
26
+ type: "string",
27
+ },
17
28
  };
18
29
  const { values, positionals } = parseArgs({
19
30
  options,
@@ -38,6 +49,12 @@ npx @jsenv/https-local uninstall
38
49
  npx @jsenv/https-local localhost-mapping
39
50
  Ensure localhost mapping to 127.0.0.1 is set on the filesystem
40
51
 
52
+ npx @jsenv/https-local generate
53
+ Generate a server certificate and write it to files
54
+ - certificate: Path where to write the certificate file (default: certificate.pem)
55
+ - private-key: Path where to write the private key file (default: private_key.pem)
56
+ - hostnames: Comma-separated list of hostnames (default: localhost)
57
+
41
58
  https://github.com/jsenv/core/tree/main/packages/tooling/https-local
42
59
 
43
60
  `);
@@ -77,6 +94,16 @@ const commandHandlers = {
77
94
  tryToUpdateHostsFile: true,
78
95
  });
79
96
  },
97
+ generate: async ({ certificate, "private-key": privateKey, hostnames }) => {
98
+ const certificateFilePath = certificate || "certificate.pem";
99
+ const privateKeyFilePath = privateKey || "private_key.pem";
100
+ const altNames = hostnames ? hostnames.split(",") : ["localhost"];
101
+ const result = requestCertificate({ altNames });
102
+ writeFileSync(certificateFilePath, result.certificate);
103
+ writeFileSync(privateKeyFilePath, result.privateKey);
104
+ console.log(`certificate written to ${certificateFilePath}`);
105
+ console.log(`private key written to ${privateKeyFilePath}`);
106
+ },
80
107
  };
81
108
 
82
109
  const [command] = positionals;