wrangler 2.0.16 → 2.0.17

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.
@@ -73,9 +73,9 @@ describe("wrangler secret", () => {
73
73
  mockPutRequest({ name: `secret-name`, text: `hunter2` });
74
74
  await runWrangler("secret put secret-name --name script-name");
75
75
  expect(std.out).toMatchInlineSnapshot(`
76
- "🌀 Creating the secret for script script-name
77
- ✨ Success! Uploaded secret secret-name"
78
- `);
76
+ "🌀 Creating the secret for the Worker \\"script-name\\"
77
+ ✨ Success! Uploaded secret secret-name"
78
+ `);
79
79
  });
80
80
 
81
81
  it("should create a secret", async () => {
@@ -89,9 +89,9 @@ describe("wrangler secret", () => {
89
89
  await runWrangler("secret put the-key --name script-name");
90
90
 
91
91
  expect(std.out).toMatchInlineSnapshot(`
92
- "🌀 Creating the secret for script script-name
93
- ✨ Success! Uploaded secret the-key"
94
- `);
92
+ "🌀 Creating the secret for the Worker \\"script-name\\"
93
+ ✨ Success! Uploaded secret the-key"
94
+ `);
95
95
  expect(std.err).toMatchInlineSnapshot(`""`);
96
96
  });
97
97
 
@@ -112,9 +112,9 @@ describe("wrangler secret", () => {
112
112
  );
113
113
 
114
114
  expect(std.out).toMatchInlineSnapshot(`
115
- "🌀 Creating the secret for script script-name-some-env
116
- ✨ Success! Uploaded secret the-key"
117
- `);
115
+ "🌀 Creating the secret for the Worker \\"script-name-some-env\\"
116
+ ✨ Success! Uploaded secret the-key"
117
+ `);
118
118
  expect(std.err).toMatchInlineSnapshot(`""`);
119
119
  });
120
120
 
@@ -135,9 +135,9 @@ describe("wrangler secret", () => {
135
135
  );
136
136
 
137
137
  expect(std.out).toMatchInlineSnapshot(`
138
- "🌀 Creating the secret for script script-name (some-env)
139
- ✨ Success! Uploaded secret the-key"
140
- `);
138
+ "🌀 Creating the secret for the Worker \\"script-name\\" (some-env)
139
+ ✨ Success! Uploaded secret the-key"
140
+ `);
141
141
  expect(std.err).toMatchInlineSnapshot(`""`);
142
142
  });
143
143
 
@@ -149,15 +149,17 @@ describe("wrangler secret", () => {
149
149
  error = e as Error;
150
150
  }
151
151
  expect(std.out).toMatchInlineSnapshot(`
152
- "
153
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
154
- `);
152
+ "
153
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
154
+ `);
155
155
  expect(std.err).toMatchInlineSnapshot(`
156
- "X [ERROR] Missing script name
156
+ "X [ERROR] Required Worker name missing. Please specify the Worker name in wrangler.toml, or pass it as an argument with \`--name <worker-name>\`
157
157
 
158
- "
159
- `);
160
- expect(error).toMatchInlineSnapshot(`[Error: Missing script name]`);
158
+ "
159
+ `);
160
+ expect(error).toMatchInlineSnapshot(
161
+ `[Error: Required Worker name missing. Please specify the Worker name in wrangler.toml, or pass it as an argument with \`--name <worker-name>\`]`
162
+ );
161
163
  });
162
164
  });
163
165
 
@@ -176,9 +178,9 @@ describe("wrangler secret", () => {
176
178
  await runWrangler("secret put the-key --name script-name");
177
179
 
178
180
  expect(std.out).toMatchInlineSnapshot(`
179
- "🌀 Creating the secret for script script-name
180
- ✨ Success! Uploaded secret the-key"
181
- `);
181
+ "🌀 Creating the secret for the Worker \\"script-name\\"
182
+ ✨ Success! Uploaded secret the-key"
183
+ `);
182
184
  expect(std.warn).toMatchInlineSnapshot(`""`);
183
185
  expect(std.err).toMatchInlineSnapshot(`""`);
184
186
  });
@@ -190,9 +192,9 @@ describe("wrangler secret", () => {
190
192
  await runWrangler("secret put the-key --name script-name");
191
193
 
192
194
  expect(std.out).toMatchInlineSnapshot(`
193
- "🌀 Creating the secret for script script-name
194
- ✨ Success! Uploaded secret the-key"
195
- `);
195
+ "🌀 Creating the secret for the Worker \\"script-name\\"
196
+ ✨ Success! Uploaded secret the-key"
197
+ `);
196
198
  expect(std.warn).toMatchInlineSnapshot(`""`);
197
199
  expect(std.err).toMatchInlineSnapshot(`""`);
198
200
  });
@@ -205,9 +207,9 @@ describe("wrangler secret", () => {
205
207
  ).rejects.toThrowErrorMatchingInlineSnapshot(`"Error in stdin stream"`);
206
208
 
207
209
  expect(std.out).toMatchInlineSnapshot(`
208
- "
209
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
210
- `);
210
+ "
211
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
212
+ `);
211
213
  expect(std.warn).toMatchInlineSnapshot(`""`);
212
214
  });
213
215
 
@@ -244,9 +246,9 @@ describe("wrangler secret", () => {
244
246
  mockPutRequest({ name: "the-key", text: "the-secret" });
245
247
  await runWrangler("secret put the-key --name script-name");
246
248
  expect(std.out).toMatchInlineSnapshot(`
247
- "🌀 Creating the secret for script script-name
248
- ✨ Success! Uploaded secret the-key"
249
- `);
249
+ "🌀 Creating the secret for the Worker \\"script-name\\"
250
+ ✨ Success! Uploaded secret the-key"
251
+ `);
250
252
  expect(std.warn).toMatchInlineSnapshot(`""`);
251
253
  expect(std.err).toMatchInlineSnapshot(`""`);
252
254
  });
@@ -317,14 +319,14 @@ describe("wrangler secret", () => {
317
319
  it("should delete a secret", async () => {
318
320
  mockDeleteRequest({ scriptName: "script-name", secretName: "the-key" });
319
321
  mockConfirm({
320
- text: "Are you sure you want to permanently delete the variable the-key on the script script-name?",
322
+ text: "Are you sure you want to permanently delete the secret the-key on the Worker script-name?",
321
323
  result: true,
322
324
  });
323
325
  await runWrangler("secret delete the-key --name script-name");
324
326
  expect(std.out).toMatchInlineSnapshot(`
325
- "🌀 Deleting the secret the-key on script script-name
326
- ✨ Success! Deleted secret the-key"
327
- `);
327
+ "🌀 Deleting the secret the-key on the Worker script-name
328
+ ✨ Success! Deleted secret the-key"
329
+ `);
328
330
  expect(std.err).toMatchInlineSnapshot(`""`);
329
331
  });
330
332
 
@@ -335,16 +337,16 @@ describe("wrangler secret", () => {
335
337
  true
336
338
  );
337
339
  mockConfirm({
338
- text: "Are you sure you want to permanently delete the variable the-key on the script script-name-some-env?",
340
+ text: "Are you sure you want to permanently delete the secret the-key on the Worker script-name-some-env?",
339
341
  result: true,
340
342
  });
341
343
  await runWrangler(
342
344
  "secret delete the-key --name script-name --env some-env --legacy-env"
343
345
  );
344
346
  expect(std.out).toMatchInlineSnapshot(`
345
- "🌀 Deleting the secret the-key on script script-name-some-env
346
- ✨ Success! Deleted secret the-key"
347
- `);
347
+ "🌀 Deleting the secret the-key on the Worker script-name-some-env
348
+ ✨ Success! Deleted secret the-key"
349
+ `);
348
350
  expect(std.err).toMatchInlineSnapshot(`""`);
349
351
  });
350
352
 
@@ -354,16 +356,16 @@ describe("wrangler secret", () => {
354
356
  "some-env"
355
357
  );
356
358
  mockConfirm({
357
- text: "Are you sure you want to permanently delete the variable the-key on the script script-name (some-env)?",
359
+ text: "Are you sure you want to permanently delete the secret the-key on the Worker script-name (some-env)?",
358
360
  result: true,
359
361
  });
360
362
  await runWrangler(
361
363
  "secret delete the-key --name script-name --env some-env --legacy-env false"
362
364
  );
363
365
  expect(std.out).toMatchInlineSnapshot(`
364
- "🌀 Deleting the secret the-key on script script-name (some-env)
365
- ✨ Success! Deleted secret the-key"
366
- `);
366
+ "🌀 Deleting the secret the-key on the Worker script-name (some-env)
367
+ ✨ Success! Deleted secret the-key"
368
+ `);
367
369
  expect(std.err).toMatchInlineSnapshot(`""`);
368
370
  });
369
371
 
@@ -376,15 +378,17 @@ describe("wrangler secret", () => {
376
378
  error = e as Error;
377
379
  }
378
380
  expect(std.out).toMatchInlineSnapshot(`
379
- "
380
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
381
- `);
381
+ "
382
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
383
+ `);
382
384
  expect(std.err).toMatchInlineSnapshot(`
383
- "X [ERROR] Missing script name
385
+ "X [ERROR] Required Worker name missing. Please specify the Worker name in wrangler.toml, or pass it as an argument with \`--name <worker-name>\`
384
386
 
385
- "
386
- `);
387
- expect(error).toMatchInlineSnapshot(`[Error: Missing script name]`);
387
+ "
388
+ `);
389
+ expect(error).toMatchInlineSnapshot(
390
+ `[Error: Required Worker name missing. Please specify the Worker name in wrangler.toml, or pass it as an argument with \`--name <worker-name>\`]`
391
+ );
388
392
  });
389
393
  });
390
394
 
@@ -422,13 +426,13 @@ describe("wrangler secret", () => {
422
426
  mockListRequest({ scriptName: "script-name" });
423
427
  await runWrangler("secret list --name script-name");
424
428
  expect(std.out).toMatchInlineSnapshot(`
425
- "[
426
- {
427
- \\"name\\": \\"the-secret-name\\",
428
- \\"type\\": \\"secret_text\\"
429
- }
430
- ]"
431
- `);
429
+ "[
430
+ {
431
+ \\"name\\": \\"the-secret-name\\",
432
+ \\"type\\": \\"secret_text\\"
433
+ }
434
+ ]"
435
+ `);
432
436
  expect(std.err).toMatchInlineSnapshot(`""`);
433
437
  });
434
438
 
@@ -438,13 +442,13 @@ describe("wrangler secret", () => {
438
442
  "secret list --name script-name --env some-env --legacy-env"
439
443
  );
440
444
  expect(std.out).toMatchInlineSnapshot(`
441
- "[
442
- {
443
- \\"name\\": \\"the-secret-name\\",
444
- \\"type\\": \\"secret_text\\"
445
- }
446
- ]"
447
- `);
445
+ "[
446
+ {
447
+ \\"name\\": \\"the-secret-name\\",
448
+ \\"type\\": \\"secret_text\\"
449
+ }
450
+ ]"
451
+ `);
448
452
  expect(std.err).toMatchInlineSnapshot(`""`);
449
453
  });
450
454
 
@@ -454,13 +458,13 @@ describe("wrangler secret", () => {
454
458
  "secret list --name script-name --env some-env --legacy-env false"
455
459
  );
456
460
  expect(std.out).toMatchInlineSnapshot(`
457
- "[
458
- {
459
- \\"name\\": \\"the-secret-name\\",
460
- \\"type\\": \\"secret_text\\"
461
- }
462
- ]"
463
- `);
461
+ "[
462
+ {
463
+ \\"name\\": \\"the-secret-name\\",
464
+ \\"type\\": \\"secret_text\\"
465
+ }
466
+ ]"
467
+ `);
464
468
  expect(std.err).toMatchInlineSnapshot(`""`);
465
469
  });
466
470
 
@@ -472,15 +476,17 @@ describe("wrangler secret", () => {
472
476
  error = e as Error;
473
477
  }
474
478
  expect(std.out).toMatchInlineSnapshot(`
475
- "
476
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
477
- `);
479
+ "
480
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
481
+ `);
478
482
  expect(std.err).toMatchInlineSnapshot(`
479
- "X [ERROR] Missing script name
483
+ "X [ERROR] Required Worker name missing. Please specify the Worker name in wrangler.toml, or pass it as an argument with \`--name <worker-name>\`
480
484
 
481
- "
482
- `);
483
- expect(error).toMatchInlineSnapshot(`[Error: Missing script name]`);
485
+ "
486
+ `);
487
+ expect(error).toMatchInlineSnapshot(
488
+ `[Error: Required Worker name missing. Please specify the Worker name in wrangler.toml, or pass it as an argument with \`--name <worker-name>\`]`
489
+ );
484
490
  });
485
491
  });
486
492
  });
@@ -27,6 +27,14 @@ describe("tail", () => {
27
27
  * deletion, and connection.
28
28
  */
29
29
  describe("API interaction", () => {
30
+ it("should throw an error if name isn't provided", async () => {
31
+ await expect(
32
+ runWrangler("tail")
33
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
34
+ `"Required Worker name missing. Please specify the Worker name in wrangler.toml, or pass it as an argument with \`wrangler tail <worker-name>\`"`
35
+ );
36
+ });
37
+
30
38
  it("creates and then delete tails", async () => {
31
39
  const api = mockWebsocketAPIs();
32
40
  expect(api.requests.creation.count).toStrictEqual(0);
@@ -18,7 +18,7 @@ import type { Config } from "../config";
18
18
  import type { UserAuthConfig } from "../user";
19
19
 
20
20
  describe("User", () => {
21
- runInTempDir({ homedir: "./home" });
21
+ runInTempDir();
22
22
  const std = mockConsoleMethods();
23
23
  const {
24
24
  mockOAuthServerCallback,
@@ -94,13 +94,10 @@ describe("User", () => {
94
94
  // TODO: Improve OAuth mocking to handle `/token` endpoints from different calls
95
95
  it("should handle errors for failed token refresh", async () => {
96
96
  setIsTTY(false);
97
- mockOAuthServerCallback();
98
97
  writeAuthConfigFile({
99
98
  oauth_token: "hunter2",
100
99
  refresh_token: "Order 66",
101
100
  });
102
- mockGrantAuthorization({ respondWith: "success" });
103
-
104
101
  mockExchangeRefreshTokenForAccessToken({
105
102
  respondWith: "badResponse",
106
103
  });
@@ -109,7 +106,7 @@ describe("User", () => {
109
106
  await expect(
110
107
  requireAuth({} as Config)
111
108
  ).rejects.toThrowErrorMatchingInlineSnapshot(
112
- `"Did not login, quitting..."`
109
+ `"In a non-interactive environment, it's necessary to set a CLOUDFLARE_API_TOKEN environment variable for wrangler to work. Please go to https://developers.cloudflare.com/api/tokens/create/ for instructions on how to create an api token, and assign its value to CLOUDFLARE_API_TOKEN."`
113
110
  );
114
111
  });
115
112
 
@@ -16,7 +16,7 @@ import type { UserInfo } from "../whoami";
16
16
  describe("getUserInfo()", () => {
17
17
  const ENV_COPY = process.env;
18
18
 
19
- runInTempDir({ homedir: "./home" });
19
+ runInTempDir();
20
20
  const std = mockConsoleMethods();
21
21
  const { setIsTTY } = useMockIsTTY();
22
22
 
@@ -173,6 +173,16 @@ describe("getUserInfo()", () => {
173
173
 
174
174
  it("should display a warning message if the config file contains a legacy api_token field", async () => {
175
175
  writeAuthConfigFile({ api_token: "API_TOKEN" });
176
+ setMockResponse("/user", () => {
177
+ return { email: "user@example.com" };
178
+ });
179
+ setMockResponse("/accounts", () => {
180
+ return [
181
+ { name: "Account One", id: "account-1" },
182
+ { name: "Account Two", id: "account-2" },
183
+ { name: "Account Three", id: "account-3" },
184
+ ];
185
+ });
176
186
  await getUserInfo();
177
187
  expect(std.warn).toMatchInlineSnapshot(`
178
188
  "▲ [WARNING] It looks like you have used Wrangler 1's \`config\` command to login with an API token.
package/src/api/dev.ts CHANGED
@@ -43,7 +43,10 @@ export async function unstable_dev(script: string, options: DevOptions) {
43
43
  showInteractiveDevSession: false,
44
44
  });
45
45
  }).then((devServer) => {
46
- resolve({ stop: devServer.stop, fetch: devServer.fetch });
46
+ resolve({
47
+ stop: devServer.stop,
48
+ fetch: devServer.fetch,
49
+ });
47
50
  });
48
51
  });
49
52
  }
package/src/cli.ts CHANGED
@@ -24,4 +24,4 @@ if (typeof jest === "undefined" && require.main) {
24
24
  * It makes it possible to import wrangler from 'wrangler',
25
25
  * and call wrangler.unstable_dev().
26
26
  */
27
- module.exports = { unstable_dev };
27
+ export default { unstable_dev };
package/src/dev/local.tsx CHANGED
@@ -1,4 +1,4 @@
1
- import { spawn } from "node:child_process";
1
+ import { fork } from "node:child_process";
2
2
  import { realpathSync } from "node:fs";
3
3
  import { writeFile } from "node:fs/promises";
4
4
  import path from "node:path";
@@ -13,7 +13,7 @@ import type { AssetPaths } from "../sites";
13
13
  import type { CfWorkerInit, CfScriptFormat } from "../worker";
14
14
  import type { EsbuildBundle } from "./use-esbuild";
15
15
  import type { MiniflareOptions } from "miniflare";
16
-
16
+ import type { ChildProcess } from "node:child_process";
17
17
  interface LocalProps {
18
18
  name: string | undefined;
19
19
  bundle: EsbuildBundle | undefined;
@@ -67,7 +67,7 @@ function useLocalWorker({
67
67
  logLevel,
68
68
  }: LocalProps) {
69
69
  // TODO: pass vars via command line
70
- const local = useRef<ReturnType<typeof spawn>>();
70
+ const local = useRef<ChildProcess>();
71
71
  const removeSignalExitListener = useRef<() => void>();
72
72
  const [inspectorUrl, setInspectorUrl] = useState<string | undefined>();
73
73
  // if we're using local persistence for data, we should use the cwd
@@ -187,6 +187,7 @@ function useLocalWorker({
187
187
  compatibilityDate,
188
188
  compatibilityFlags,
189
189
  kvNamespaces: bindings.kv_namespaces?.map((kv) => kv.binding),
190
+ r2Buckets: bindings.r2_buckets?.map((r2) => r2.binding),
190
191
  durableObjects: Object.fromEntries(
191
192
  (bindings.durable_objects?.bindings ?? []).map<[string, string]>(
192
193
  (value) => [value.name, value.class_name]
@@ -236,43 +237,45 @@ function useLocalWorker({
236
237
  __dirname,
237
238
  "../miniflare-dist/index.mjs"
238
239
  );
239
- const optionsArg = JSON.stringify(options, null);
240
+ const miniflareOptions = JSON.stringify(options, null);
240
241
 
241
242
  logger.log("⎔ Starting a local server...");
242
- const localServerOptions = [
243
+ const nodeOptions = [
243
244
  "--experimental-vm-modules", // ensures that Miniflare can run ESM Workers
244
245
  "--no-warnings", // hide annoying Node warnings
245
- miniflareCLIPath,
246
- optionsArg,
247
246
  // "--log=VERBOSE", // uncomment this to Miniflare to log "everything"!
248
247
  ];
249
248
  if (inspect) {
250
- localServerOptions.push("--inspect"); // start Miniflare listening for a debugger to attach
249
+ nodeOptions.push("--inspect"); // start Miniflare listening for a debugger to attach
251
250
  }
252
- // spawn isn't technically synchronous here
253
- local.current = spawn("node", localServerOptions, {
254
- cwd: path.dirname(scriptPath),
251
+ const child = (local.current = fork(
252
+ miniflareCLIPath,
253
+ [miniflareOptions],
254
+ {
255
+ cwd: path.dirname(scriptPath),
256
+ execArgv: nodeOptions,
257
+ }
258
+ ));
259
+ child.on("message", (message) => {
260
+ if (message === "ready") {
261
+ onReady?.();
262
+ }
255
263
  });
256
- //TODO: instead of being lucky with spawn's timing, have miniflare-cli notify wrangler that it's ready in packages/wrangler/src/miniflare-cli/index.ts, after the mf.startScheduler promise resolves
257
- if (onReady) {
258
- await new Promise((resolve) => setTimeout(resolve, 500));
259
- onReady();
260
- }
261
264
 
262
- local.current.on("close", (code) => {
265
+ child.on("close", (code) => {
263
266
  if (code) {
264
267
  logger.log(`Miniflare process exited with code ${code}`);
265
268
  }
266
269
  });
267
270
 
268
- local.current.stdout?.on("data", (data: Buffer) => {
271
+ child.stdout?.on("data", (data: Buffer) => {
269
272
  process.stdout.write(data);
270
273
  });
271
274
 
272
275
  // parse the node inspector url (which may be received in chunks) from stderr
273
276
  let stderrData = "";
274
277
  let inspectorUrlFound = false;
275
- local.current.stderr?.on("data", (data: Buffer) => {
278
+ child.stderr?.on("data", (data: Buffer) => {
276
279
  if (!inspectorUrlFound) {
277
280
  stderrData += data.toString();
278
281
  const matches =
@@ -288,20 +291,20 @@ function useLocalWorker({
288
291
  process.stderr.write(data);
289
292
  });
290
293
 
291
- local.current.on("exit", (code) => {
294
+ child.on("exit", (code) => {
292
295
  if (code) {
293
296
  logger.error(`Miniflare process exited with code ${code}`);
294
297
  }
295
298
  });
296
299
 
297
- local.current.on("error", (error: Error) => {
300
+ child.on("error", (error: Error) => {
298
301
  logger.error(`Miniflare process failed to spawn`);
299
302
  logger.error(error);
300
303
  });
301
304
 
302
305
  removeSignalExitListener.current = onExit((_code, _signal) => {
303
306
  logger.log("⎔ Shutting down local server.");
304
- local.current?.kill();
307
+ child.kill();
305
308
  local.current = undefined;
306
309
  });
307
310
  }
@@ -328,6 +331,7 @@ function useLocalWorker({
328
331
  ip,
329
332
  bindings.durable_objects?.bindings,
330
333
  bindings.kv_namespaces,
334
+ bindings.r2_buckets,
331
335
  bindings.vars,
332
336
  bindings.services,
333
337
  compatibilityDate,
@@ -53,7 +53,7 @@ export function Remote(props: {
53
53
  zone: string | undefined;
54
54
  host: string | undefined;
55
55
  routes: Route[] | undefined;
56
- onReady?: () => void;
56
+ onReady?: (() => void) | undefined;
57
57
  }) {
58
58
  const [accountId, setAccountId] = useState(props.accountId);
59
59
  const accountChoicesRef = useRef<Promise<ChooseAccountItem[]>>();
@@ -158,7 +158,7 @@ export function useWorker(props: {
158
158
  zone: string | undefined;
159
159
  host: string | undefined;
160
160
  routes: Route[] | undefined;
161
- onReady?: () => void;
161
+ onReady: (() => void) | undefined;
162
162
  }): CfPreviewToken | undefined {
163
163
  const {
164
164
  name,
package/src/entry.ts CHANGED
@@ -39,7 +39,7 @@ export async function getEntry(
39
39
  ? path.resolve(config.site?.["entry-point"])
40
40
  : // site.entry-point could be a directory
41
41
  path.resolve(config.site?.["entry-point"], "index.js");
42
- } else if (args.assets) {
42
+ } else if (args.assets || config.assets) {
43
43
  file = path.resolve(__dirname, "../templates/no-op-worker.js");
44
44
  } else {
45
45
  throw new Error(
@@ -1,5 +1,5 @@
1
1
  import * as fs from "node:fs";
2
- import { homedir, networkInterfaces } from "node:os";
2
+ import os from "node:os";
3
3
  import * as path from "node:path";
4
4
  import { promisify } from "node:util";
5
5
  import { logger } from "./logger";
@@ -17,7 +17,7 @@ const ONE_DAY_IN_MS = 86400000;
17
17
  * The certificates are self-signed and generated locally, and cached in the `CERT_ROOT` directory.
18
18
  */
19
19
  export async function getHttpsOptions() {
20
- const certDirectory = path.join(homedir(), ".wrangler/local-cert");
20
+ const certDirectory = path.join(os.homedir(), ".wrangler/local-cert");
21
21
  const keyPath = path.join(certDirectory, "key.pem");
22
22
  const certPath = path.join(certDirectory, "cert.pem");
23
23
 
@@ -37,7 +37,10 @@ export async function getHttpsOptions() {
37
37
  } catch (e) {
38
38
  const message = e instanceof Error ? e.message : `${e}`;
39
39
  logger.warn(
40
- `Unable to cache generated self-signed certificate in ${certDirectory}.\n${message}`
40
+ `Unable to cache generated self-signed certificate in ${path.relative(
41
+ process.cwd(),
42
+ certDirectory
43
+ )}.\n${message}`
41
44
  );
42
45
  }
43
46
  return { key, cert };
@@ -114,7 +117,7 @@ async function generateCertificate() {
114
117
  */
115
118
  function getAccessibleHosts(ipv4 = false): string[] {
116
119
  const hosts: string[] = [];
117
- Object.values(networkInterfaces()).forEach((net) =>
120
+ Object.values(os.networkInterfaces()).forEach((net) =>
118
121
  net?.forEach(({ family, address }) => {
119
122
  if (!ipv4 || family === "IPv4") hosts.push(address);
120
123
  })