Skip to content

Commit 12e6f3e

Browse files
committed
style: use selective imports for certs and zod
🤖 Generated with [OpenCode](https://opencode.ai) (Smart-router)
1 parent 7f02862 commit 12e6f3e

3 files changed

Lines changed: 17 additions & 17 deletions

File tree

src/cli.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ process.on("uncaughtException", err => {
5656
case "EACCES":
5757
console.error(
5858
"EACCES: run as administrator to use the default ports 443 and 80. " +
59-
"You can also change port with: `PORT=4433 serve ~/myproj` or `serve -p 4433 ~/myproj`.",
59+
"You can also change port with: `PORT=4433 serve ~/myproj` or `serve -p 4433 ~/myproj`.",
6060
)
6161
break
6262
case "EADDRINUSE":
6363
console.error(
6464
"EADDRINUSE: another service on your machine is using " +
65-
"the current port.\nStop it or change port with: " +
66-
"`PORT=4433 serve ~/myproj` or `serve -p 4433 ~/myproj`.",
65+
"the current port.\nStop it or change port with: " +
66+
"`PORT=4433 serve ~/myproj` or `serve -p 4433 ~/myproj`.",
6767
)
6868
break
6969
default:

src/env.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import z from "zod"
1+
import { z } from "zod"
22

33
export const envSchema = z.object({
44
PORT: z.coerce.number().min(1).max(65535).default(443),

test/test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import tls from "node:tls"
1111

1212
import appDataPathPkg from "appdata-path"
1313

14-
import * as certs from "../src/certs.ts"
14+
import { generate, getCerts, remove } from "../src/certs.ts"
1515
import { getEnv } from "../src/env.ts"
1616
import createServer from "../src/index.ts"
1717
import type { HttpsLocalhostApp } from "../src/index.ts"
@@ -90,26 +90,26 @@ async function makeRequest(
9090

9191
describe("Testing certs", { timeout: 300000 }, () => {
9292
afterEach(() => {
93-
certs.remove("test/custom-folder")
94-
certs.remove("test/custom folder")
93+
remove("test/custom-folder")
94+
remove("test/custom folder")
9595
delete process.env["CERT_PATH"]
9696
delete process.env["HOST"]
9797
})
9898

9999
it("can be uninstalled", () => {
100-
certs.remove()
100+
remove()
101101
})
102102

103103
it("uninstall is idempotent (doesn't fail if called twice)", () => {
104-
certs.remove()
104+
remove()
105105
})
106106

107107
it("can be installed", async () => {
108-
await certs.generate()
108+
await generate()
109109
})
110110

111111
it("can be installed at first run", async () => {
112-
certs.remove()
112+
remove()
113113

114114
app = createServer()
115115
app.get("/test/module", (_req: import("express").Request, res: import("express").Response) =>
@@ -134,13 +134,13 @@ describe("Testing certs", { timeout: 300000 }, () => {
134134

135135
it("crashes if certs doesn't exists in custom folder", async () => {
136136
const customCertPath = "test/custom-folder"
137-
await certs.generate({ appDataPath: customCertPath })
137+
await generate({ appDataPath: customCertPath })
138138
fs.unlinkSync("test/custom-folder/localhost.crt")
139139
fs.unlinkSync("test/custom-folder/localhost.key")
140140

141141
app = createServer({ certPath: customCertPath })
142142
await assert.rejects(app.listen(HTTPS_PORT), /Certificates are missing/)
143-
certs.remove(customCertPath)
143+
remove(customCertPath)
144144
})
145145

146146
it("support path with spaces", async () => {
@@ -153,17 +153,17 @@ describe("Testing certs", { timeout: 300000 }, () => {
153153

154154
await makeRequest("/test/module").then(res => assert(res.data === "TEST"))
155155
await closeServer(app.server)
156-
certs.remove("test/custom folder")
156+
remove("test/custom folder")
157157
})
158158

159159
it("provides the certificate", async () => {
160160
const env = getEnv()
161-
const appCerts = await certs.getCerts({
161+
const appCerts = await getCerts({
162162
domain: env.HOST,
163163
certPath: env.CERT_PATH,
164164
reinstall: env.REINSTALL,
165165
})
166-
const realCerts = await certs.getCerts({
166+
const realCerts = await getCerts({
167167
domain: env.HOST,
168168
certPath: env.CERT_PATH,
169169
reinstall: env.REINSTALL,
@@ -172,7 +172,7 @@ describe("Testing certs", { timeout: 300000 }, () => {
172172
})
173173

174174
it("works with environment domain", async () => {
175-
const appCerts = await certs.getCerts({ domain: "192.168.0.1" })
175+
const appCerts = await getCerts({ domain: "192.168.0.1" })
176176
const secureContext = tls.createSecureContext({
177177
cert: appCerts.cert,
178178
})

0 commit comments

Comments
 (0)