wrangler 2.2.1 → 2.2.2

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,6 @@
1
1
  {
2
2
  "name": "wrangler",
3
- "version": "2.2.1",
3
+ "version": "2.2.2",
4
4
  "description": "Command-line interface for all things Cloudflare Workers",
5
5
  "keywords": [
6
6
  "wrangler",
@@ -66,7 +66,7 @@ describe("deployments", () => {
66
66
  Created on: 2021-01-01T00:00:00.000000Z
67
67
  Author: Jean-Luc-Picard@federation.org
68
68
  Source: Wrangler
69
- 🟩Active"
69
+ 🟩 Active"
70
70
  `);
71
71
  });
72
72
 
@@ -85,7 +85,7 @@ describe("deployments", () => {
85
85
  Created on: 2021-01-01T00:00:00.000000Z
86
86
  Author: Jean-Luc-Picard@federation.org
87
87
  Source: Wrangler
88
- 🟩Active"
88
+ 🟩 Active"
89
89
  `);
90
90
  });
91
91
  });
@@ -7607,7 +7607,7 @@ function mockGetQueueMissing(expectedQueueName: string) {
7607
7607
  `/accounts/:accountId/workers/queues/${expectedQueueName}`,
7608
7608
  "GET",
7609
7609
  ([_url, _accountId]) => {
7610
- throw { code: 100123 };
7610
+ throw { code: 11000 };
7611
7611
  }
7612
7612
  );
7613
7613
  return requests;
@@ -1,5 +1,7 @@
1
1
  import * as fs from "node:fs";
2
2
  import { rest } from "msw";
3
+ import prettyBytes from "pretty-bytes";
4
+ import { MAX_UPLOAD_SIZE } from "../r2/constants";
3
5
  import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
4
6
  import { mockConsoleMethods } from "./helpers/mock-console";
5
7
  import { msw, mswSuccessR2handlers } from "./helpers/msw";
@@ -276,7 +278,7 @@ describe("r2", () => {
276
278
  `);
277
279
  });
278
280
 
279
- it("should upload R2 object from bucket", async () => {
281
+ it("should upload R2 object to bucket", async () => {
280
282
  fs.writeFileSync("wormhole-img.png", "passageway");
281
283
  await runWrangler(
282
284
  `r2 object put bucketName-object-test/wormhole-img.png --file ./wormhole-img.png`
@@ -288,6 +290,21 @@ describe("r2", () => {
288
290
  `);
289
291
  });
290
292
 
293
+ it("should fail to upload R2 object to bucket if too large", async () => {
294
+ const TOO_BIG_FILE_SIZE = MAX_UPLOAD_SIZE + 1024 * 1024;
295
+ fs.writeFileSync("wormhole-img.png", Buffer.alloc(TOO_BIG_FILE_SIZE));
296
+ await expect(
297
+ runWrangler(
298
+ `r2 object put bucketName-object-test/wormhole-img.png --file ./wormhole-img.png`
299
+ )
300
+ ).rejects.toThrowErrorMatchingInlineSnapshot(`
301
+ "Error: Wrangler only supports uploading files up to ${prettyBytes(
302
+ MAX_UPLOAD_SIZE
303
+ )} in size
304
+ wormhole-img.png is ${prettyBytes(TOO_BIG_FILE_SIZE)} in size"
305
+ `);
306
+ });
307
+
291
308
  it("should pass all fetch option flags into requestInit & check request inputs", async () => {
292
309
  msw.use(
293
310
  rest.put(
@@ -100,8 +100,8 @@ describe("generateTypes()", () => {
100
100
  expect(std.out).toMatchInlineSnapshot(`
101
101
  "interface Env {
102
102
  TEST_KV_NAMESPACE: KVNamespace;
103
- SOMETHING: asdasdfasdf;
104
- ANOTHER: thing;
103
+ SOMETHING: \\"asdasdfasdf\\";
104
+ ANOTHER: \\"thing\\";
105
105
  OBJECT_VAR: {\\"enterprise\\":\\"1701-D\\",\\"activeDuty\\":true,\\"captian\\":\\"Picard\\"};
106
106
  DURABLE_TEST1: DurableObjectNamespace;
107
107
  DURABLE_TEST2: DurableObjectNamespace;
@@ -52,7 +52,7 @@ Author: ${versions.metadata.author_email}
52
52
  Source: ${sourceStr(versions.metadata.source)}\n`
53
53
  );
54
54
 
55
- versionMessages[0] += "🟩Active";
55
+ versionMessages[0] += "🟩 Active";
56
56
  logger.log(...versionMessages.reverse());
57
57
  }
58
58
 
@@ -997,7 +997,7 @@ async function ensureQueuesExist(config: Config) {
997
997
  await getQueue(config, queue);
998
998
  } catch (err) {
999
999
  const queueErr = err as FetchError;
1000
- if (queueErr.code === 100123) {
1000
+ if (queueErr.code === 11000) {
1001
1001
  // queue_not_found
1002
1002
  throw new Error(
1003
1003
  `Queue "${queue}" does not exist. To create it, run: wrangler queues create ${queue}`
@@ -0,0 +1,4 @@
1
+ /**
2
+ * The maximum file size we can upload using the V4 API.
3
+ */
4
+ export const MAX_UPLOAD_SIZE = 300 * 1024 * 1024;
package/src/r2/index.ts CHANGED
@@ -1,11 +1,14 @@
1
1
  import * as fs from "node:fs";
2
2
  import * as stream from "node:stream";
3
3
 
4
+ import prettyBytes from "pretty-bytes";
4
5
  import { readConfig } from "../config";
6
+ import { FatalError } from "../errors";
5
7
  import { CommandLineArgsError, printWranglerBanner } from "../index";
6
8
  import { logger } from "../logger";
7
9
  import * as metrics from "../metrics";
8
10
  import { requireAuth } from "../user";
11
+ import { MAX_UPLOAD_SIZE } from "./constants";
9
12
  import {
10
13
  bucketAndKeyFromObjectPath,
11
14
  createR2Bucket,
@@ -176,6 +179,15 @@ export const r2: BuilderCallback<unknown, unknown> = (r2Yargs) => {
176
179
  objectSize = object.byteLength;
177
180
  }
178
181
 
182
+ if (objectSize > MAX_UPLOAD_SIZE) {
183
+ throw new FatalError(
184
+ `Error: Wrangler only supports uploading files up to ${prettyBytes(
185
+ MAX_UPLOAD_SIZE
186
+ )} in size\n${key} is ${prettyBytes(objectSize)} in size`,
187
+ 1
188
+ );
189
+ }
190
+
179
191
  logger.log(`Creating object "${key}" in bucket "${bucket}".`);
180
192
  await putR2Object(accountId, bucket, key, object, {
181
193
  ...options,
@@ -30,7 +30,7 @@ export async function generateTypes(
30
30
  typeof varValue === "number" ||
31
31
  typeof varValue === "boolean"
32
32
  ) {
33
- envTypeStructure.push(` ${varName}: ${varValue};`);
33
+ envTypeStructure.push(` ${varName}: "${varValue}";`);
34
34
  }
35
35
  if (typeof varValue === "object" && varValue !== null) {
36
36
  envTypeStructure.push(` ${varName}: ${JSON.stringify(varValue)};`);
@@ -141159,7 +141159,7 @@ var import_websocket_server = __toESM(require_websocket_server2(), 1);
141159
141159
  var wrapper_default = import_websocket.default;
141160
141160
 
141161
141161
  // package.json
141162
- var version = "2.2.1";
141162
+ var version = "2.2.2";
141163
141163
  var package_default = {
141164
141164
  name: "wrangler",
141165
141165
  version,
@@ -154154,7 +154154,7 @@ Author: ${versions.metadata.author_email}
154154
154154
  Source: ${sourceStr(versions.metadata.source)}
154155
154155
  `
154156
154156
  );
154157
- versionMessages[0] += "\u{1F7E9}Active";
154157
+ versionMessages[0] += "\u{1F7E9} Active";
154158
154158
  logger.log(...versionMessages.reverse());
154159
154159
  }
154160
154160
  function sourceStr(source) {
@@ -159879,7 +159879,7 @@ async function ensureQueuesExist(config) {
159879
159879
  await getQueue(config, queue);
159880
159880
  } catch (err2) {
159881
159881
  const queueErr = err2;
159882
- if (queueErr.code === 100123) {
159882
+ if (queueErr.code === 11e3) {
159883
159883
  throw new Error(
159884
159884
  `Queue "${queue}" does not exist. To create it, run: wrangler queues create ${queue}`
159885
159885
  );
@@ -160881,6 +160881,10 @@ init_import_meta_url();
160881
160881
  var fs13 = __toESM(require("node:fs"));
160882
160882
  var stream = __toESM(require("node:stream"));
160883
160883
 
160884
+ // src/r2/constants.ts
160885
+ init_import_meta_url();
160886
+ var MAX_UPLOAD_SIZE = 300 * 1024 * 1024;
160887
+
160884
160888
  // src/r2/helpers.ts
160885
160889
  init_import_meta_url();
160886
160890
  var import_node_stream = require("node:stream");
@@ -161084,6 +161088,15 @@ var r2 = (r2Yargs) => {
161084
161088
  });
161085
161089
  objectSize = object.byteLength;
161086
161090
  }
161091
+ if (objectSize > MAX_UPLOAD_SIZE) {
161092
+ throw new FatalError(
161093
+ `Error: Wrangler only supports uploading files up to ${prettyBytes(
161094
+ MAX_UPLOAD_SIZE
161095
+ )} in size
161096
+ ${key2} is ${prettyBytes(objectSize)} in size`,
161097
+ 1
161098
+ );
161099
+ }
161087
161100
  logger.log(`Creating object "${key2}" in bucket "${bucket}".`);
161088
161101
  await putR2Object(accountId, bucket, key2, object, {
161089
161102
  ...options6,
@@ -161786,7 +161799,7 @@ async function generateTypes(configToDTS, config) {
161786
161799
  for (const varName in configToDTS.vars) {
161787
161800
  const varValue = configToDTS.vars[varName];
161788
161801
  if (typeof varValue === "string" || typeof varValue === "number" || typeof varValue === "boolean") {
161789
- envTypeStructure.push(` ${varName}: ${varValue};`);
161802
+ envTypeStructure.push(` ${varName}: "${varValue}";`);
161790
161803
  }
161791
161804
  if (typeof varValue === "object" && varValue !== null) {
161792
161805
  envTypeStructure.push(` ${varName}: ${JSON.stringify(varValue)};`);