wrangler 2.12.2 → 2.12.3

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.
Files changed (33) hide show
  1. package/package.json +4 -3
  2. package/src/__tests__/d1/execute.test.ts +2 -0
  3. package/src/__tests__/d1/migrate.test.ts +2 -0
  4. package/src/__tests__/delete.test.ts +6 -0
  5. package/src/__tests__/dev.test.tsx +71 -56
  6. package/src/__tests__/helpers/mock-console.ts +6 -0
  7. package/src/__tests__/helpers/worker-scripts/parent-worker.js +4 -1
  8. package/src/__tests__/init.test.ts +127 -96
  9. package/src/__tests__/kv.test.ts +9 -9
  10. package/src/__tests__/middleware.scheduled.test.ts +2 -2
  11. package/src/__tests__/middleware.test.ts +2 -2
  12. package/src/__tests__/pages/deployment-list.test.ts +2 -0
  13. package/src/__tests__/pages/project-list.test.ts +2 -0
  14. package/src/__tests__/pages/project-upload.test.ts +43 -24
  15. package/src/__tests__/pages/publish.test.ts +69 -69
  16. package/src/__tests__/publish.test.ts +138 -97
  17. package/src/__tests__/pubsub.test.ts +3 -0
  18. package/src/__tests__/tsconfig.tsbuildinfo +1 -1
  19. package/src/__tests__/worker-namespace.test.ts +1 -0
  20. package/src/d1/backups.tsx +15 -11
  21. package/src/d1/create.tsx +20 -16
  22. package/src/d1/execute.tsx +21 -18
  23. package/src/d1/list.tsx +2 -2
  24. package/src/d1/migrations/apply.tsx +33 -28
  25. package/src/d1/migrations/create.tsx +15 -12
  26. package/src/d1/migrations/list.tsx +10 -7
  27. package/src/pages/deployments.tsx +3 -5
  28. package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
  29. package/src/pages/projects.tsx +2 -5
  30. package/src/pages/upload.tsx +29 -9
  31. package/src/utils/render.ts +93 -0
  32. package/templates/d1-beta-facade.js +3 -0
  33. package/wrangler-dist/cli.js +225 -146
@@ -200,7 +200,7 @@ export const upload = async (
200
200
  let attempts = 0;
201
201
  const getMissingHashes = async (skipCaching: boolean): Promise<string[]> => {
202
202
  if (skipCaching) {
203
- console.debug("Force skipping cache");
203
+ logger.debug("Force skipping cache");
204
204
  return files.map(({ hash }) => hash);
205
205
  }
206
206
 
@@ -276,9 +276,7 @@ export const upload = async (
276
276
  }
277
277
 
278
278
  let counter = fileMap.size - sortedFiles.length;
279
- const { rerender, unmount } = render(
280
- <Progress done={counter} total={fileMap.size} />
281
- );
279
+ const { rerender, unmount } = renderProgress(counter, fileMap.size);
282
280
 
283
281
  const queue = new PQueue({ concurrency: BULK_UPLOAD_CONCURRENCY });
284
282
 
@@ -302,7 +300,7 @@ export const upload = async (
302
300
  );
303
301
 
304
302
  try {
305
- console.debug("POST /pages/assets/upload");
303
+ logger.debug("POST /pages/assets/upload");
306
304
  const res = await fetchResult(`/pages/assets/upload`, {
307
305
  method: "POST",
308
306
  headers: {
@@ -311,10 +309,10 @@ export const upload = async (
311
309
  },
312
310
  body: JSON.stringify(payload),
313
311
  });
314
- console.debug("result:", res);
312
+ logger.debug("result:", res);
315
313
  } catch (e) {
316
314
  if (attempts < MAX_UPLOAD_ATTEMPTS) {
317
- console.debug("failed:", e, "retrying...");
315
+ logger.debug("failed:", e, "retrying...");
318
316
  // Exponential backoff, 1 second first time, then 2 second, then 4 second etc.
319
317
  await new Promise((resolvePromise) =>
320
318
  setTimeout(resolvePromise, Math.pow(2, attempts++) * 1000)
@@ -326,7 +324,7 @@ export const upload = async (
326
324
  }
327
325
  return doUpload();
328
326
  } else {
329
- console.debug("failed:", e);
327
+ logger.debug("failed:", e);
330
328
  throw e;
331
329
  }
332
330
  }
@@ -336,7 +334,7 @@ export const upload = async (
336
334
  doUpload().then(
337
335
  () => {
338
336
  counter += bucket.files.length;
339
- rerender(<Progress done={counter} total={fileMap.size} />);
337
+ rerender(counter, fileMap.size);
340
338
  },
341
339
  (error) => {
342
340
  return Promise.reject(
@@ -437,6 +435,28 @@ function formatTime(duration: number) {
437
435
  return `(${(duration / 1000).toFixed(2)} sec)`;
438
436
  }
439
437
 
438
+ function renderProgress(done: number, total: number) {
439
+ if (isInteractive()) {
440
+ const { rerender, unmount } = render(
441
+ <Progress done={done} total={total} />
442
+ );
443
+ return {
444
+ // eslint-disable-next-line no-shadow
445
+ rerender(done: number, total: number) {
446
+ rerender(<Progress done={done} total={total} />);
447
+ },
448
+ unmount,
449
+ };
450
+ } else {
451
+ // eslint-disable-next-line no-shadow
452
+ const rerender = (done: number, total: number) => {
453
+ logger.log(`Uploading... (${done}/${total})`);
454
+ };
455
+ rerender(done, total);
456
+ return { rerender, unmount() {} };
457
+ }
458
+ }
459
+
440
460
  function Progress({ done, total }: { done: number; total: number }) {
441
461
  return (
442
462
  <>
@@ -0,0 +1,93 @@
1
+ import { EventEmitter } from "events";
2
+ import { render as inkRender } from "ink";
3
+ import type { ReactElement } from "react";
4
+ import type { WriteStream } from "tty";
5
+
6
+ export function renderToString(tree: ReactElement): string {
7
+ const { output, cleanup } = render(tree);
8
+ cleanup();
9
+ return output;
10
+ }
11
+
12
+ // The code below is mostly copied from ink-render-string.
13
+ // See https://github.com/zhanwang626/ink-render-string.git.
14
+
15
+ // MIT License
16
+
17
+ // Copyright (c) 2021 Zhan Wang
18
+
19
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
20
+ // of this software and associated documentation files (the "Software"), to deal
21
+ // in the Software without restriction, including without limitation the rights
22
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23
+ // copies of the Software, and to permit persons to whom the Software is
24
+ // furnished to do so, subject to the following conditions:
25
+
26
+ // The above copyright notice and this permission notice shall be included in all
27
+ // copies or substantial portions of the Software.
28
+
29
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35
+ // SOFTWARE.
36
+
37
+ interface Instance {
38
+ output: string;
39
+ unmount: () => void;
40
+ cleanup: () => void;
41
+ stdout: OutputStream;
42
+ stderr: OutputStream;
43
+ frames: string[];
44
+ }
45
+
46
+ const LASTFRAME_UNDEFINED = "value of stdout.lastframe() is undefined";
47
+
48
+ export class OutputStream extends EventEmitter {
49
+ readonly frames: string[] = [];
50
+ private _lastFrame?: string;
51
+
52
+ get columns(): number {
53
+ return this._originalStream.columns;
54
+ }
55
+ get rows(): number {
56
+ return this._originalStream.rows;
57
+ }
58
+
59
+ constructor(private _originalStream: WriteStream) {
60
+ super();
61
+ }
62
+
63
+ write = (frame: string) => {
64
+ this.frames.push(frame);
65
+ this._lastFrame = frame;
66
+ };
67
+
68
+ lastFrame = () => {
69
+ return this._lastFrame;
70
+ };
71
+ }
72
+
73
+ export const render = (tree: ReactElement): Instance => {
74
+ const stdout = new OutputStream(process.stdout);
75
+ const stderr = new OutputStream(process.stderr);
76
+
77
+ const instance = inkRender(tree, {
78
+ stdout: stdout as unknown as WriteStream,
79
+ stderr: stderr as unknown as WriteStream,
80
+ debug: true,
81
+ exitOnCtrlC: false,
82
+ patchConsole: false,
83
+ });
84
+
85
+ return {
86
+ output: stdout.lastFrame() || LASTFRAME_UNDEFINED,
87
+ stdout,
88
+ stderr,
89
+ cleanup: instance.cleanup,
90
+ unmount: instance.unmount,
91
+ frames: stdout.frames,
92
+ };
93
+ };
@@ -237,5 +237,8 @@ var shim_default = {
237
237
  async trace(traces, env, ctx) {
238
238
  return worker.trace(traces, getMaskedEnv(env), ctx);
239
239
  },
240
+ async email(message, env, ctx) {
241
+ return worker.email(message, getMaskedEnv(env), ctx);
242
+ },
240
243
  };
241
244
  export { shim_default as default };