wrangler 2.12.3 → 2.13.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 +1 -1
- package/src/__tests__/configuration.test.ts +14 -12
- package/src/__tests__/deployments.test.ts +335 -95
- package/src/__tests__/helpers/msw/handlers/deployments.ts +70 -3
- package/src/__tests__/helpers/msw/index.ts +4 -2
- package/src/__tests__/index.test.ts +10 -4
- package/src/__tests__/jest.setup.ts +4 -0
- package/src/__tests__/mtls-certificates.test.ts +5 -2
- package/src/__tests__/publish.test.ts +138 -59
- package/src/__tests__/queues.test.ts +5 -2
- package/src/__tests__/tsconfig.tsbuildinfo +1 -1
- package/src/bundle.ts +10 -0
- package/src/config/environment.ts +3 -0
- package/src/config/validation.ts +3 -1
- package/src/create-worker-upload-form.ts +1 -1
- package/src/d1/migrations/apply.tsx +2 -1
- package/src/deployments.ts +260 -8
- package/src/index.ts +75 -22
- package/src/init.ts +144 -135
- package/src/metrics/send-event.ts +2 -1
- package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
- package/src/publish/publish.ts +7 -18
- package/src/queues/cli/commands/consumer/add.ts +6 -0
- package/src/queues/client.ts +1 -0
- package/wrangler-dist/cli.d.ts +2 -0
- package/wrangler-dist/cli.js +7984 -7762
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
1
2
|
import fetchMock from "jest-fetch-mock";
|
|
2
3
|
import { MockWebSocket } from "./helpers/mock-web-socket";
|
|
3
4
|
import { msw } from "./helpers/msw";
|
|
4
5
|
|
|
6
|
+
//turn off chalk for tests due to inconsistencies between operating systems
|
|
7
|
+
chalk.level = 0;
|
|
8
|
+
|
|
5
9
|
/**
|
|
6
10
|
* The relative path between the bundled code and the Wrangler package.
|
|
7
11
|
* This is used as a reliable way to compute paths relative to the Wrangler package
|
|
@@ -385,14 +385,17 @@ describe("wrangler", () => {
|
|
|
385
385
|
wrangler logout 🚪 Logout from Cloudflare
|
|
386
386
|
wrangler whoami 🕵️ Retrieve your user info and test your auth config
|
|
387
387
|
wrangler types 📝 Generate types from bindings & module rules in config
|
|
388
|
-
wrangler deployments 🚢
|
|
388
|
+
wrangler deployments 🚢 List and view details for deployments
|
|
389
|
+
wrangler rollback [deployment-id] 🔙 Rollback a deployment
|
|
389
390
|
|
|
390
391
|
Flags:
|
|
391
392
|
-j, --experimental-json-config Experimental: Support wrangler.json [boolean]
|
|
392
393
|
-c, --config Path to .toml configuration file [string]
|
|
393
394
|
-e, --env Environment to use for operations and .env files [string]
|
|
394
395
|
-h, --help Show help [boolean]
|
|
395
|
-
-v, --version Show version number [boolean]
|
|
396
|
+
-v, --version Show version number [boolean]
|
|
397
|
+
|
|
398
|
+
🚧\`wrangler rollback\` is a beta command. Please report any issues to https://github.com/cloudflare/workers-sdk/issues/new/choose"
|
|
396
399
|
`);
|
|
397
400
|
});
|
|
398
401
|
});
|
|
@@ -32,7 +32,7 @@ import {
|
|
|
32
32
|
createFetchResult,
|
|
33
33
|
msw,
|
|
34
34
|
mswSuccessDeployments,
|
|
35
|
-
|
|
35
|
+
mswSuccessDeploymentScriptMetadata,
|
|
36
36
|
} from "./helpers/msw";
|
|
37
37
|
import { FileReaderSync } from "./helpers/msw/read-file-sync";
|
|
38
38
|
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
@@ -89,7 +89,7 @@ describe("publish", () => {
|
|
|
89
89
|
);
|
|
90
90
|
writeWorkerSource();
|
|
91
91
|
mockSubDomainRequest();
|
|
92
|
-
mockUploadWorkerRequest({ expectedType: "esm"
|
|
92
|
+
mockUploadWorkerRequest({ expectedType: "esm" });
|
|
93
93
|
mockOAuthServerCallback();
|
|
94
94
|
|
|
95
95
|
await runWrangler("publish ./index");
|
|
@@ -1341,6 +1341,32 @@ export default{
|
|
|
1341
1341
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1342
1342
|
});
|
|
1343
1343
|
|
|
1344
|
+
it("should allow cloudflare module import", async () => {
|
|
1345
|
+
writeWranglerToml();
|
|
1346
|
+
fs.writeFileSync(
|
|
1347
|
+
"./index.js",
|
|
1348
|
+
`
|
|
1349
|
+
import { EmailMessage } from "cloudflare:email";
|
|
1350
|
+
export default{
|
|
1351
|
+
fetch(){
|
|
1352
|
+
return new Response("all done");
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
`
|
|
1356
|
+
);
|
|
1357
|
+
mockUploadWorkerRequest();
|
|
1358
|
+
mockSubDomainRequest();
|
|
1359
|
+
await runWrangler("publish index.js");
|
|
1360
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
1361
|
+
"Total Upload: xx KiB / gzip: xx KiB
|
|
1362
|
+
Uploaded test-name (TIMINGS)
|
|
1363
|
+
Published test-name (TIMINGS)
|
|
1364
|
+
https://test-name.test-sub-domain.workers.dev
|
|
1365
|
+
Current Deployment ID: Galaxy-Class"
|
|
1366
|
+
`);
|
|
1367
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1368
|
+
});
|
|
1369
|
+
|
|
1344
1370
|
it("should be able to transpile entry-points in sub-directories (esm)", async () => {
|
|
1345
1371
|
writeWranglerToml();
|
|
1346
1372
|
writeWorkerSource({ basePath: "./src" });
|
|
@@ -7324,54 +7350,6 @@ export default{
|
|
|
7324
7350
|
});
|
|
7325
7351
|
});
|
|
7326
7352
|
|
|
7327
|
-
it("should publish if the last deployed source check fails", async () => {
|
|
7328
|
-
writeWorkerSource();
|
|
7329
|
-
writeWranglerToml();
|
|
7330
|
-
mockSubDomainRequest();
|
|
7331
|
-
mockUploadWorkerRequest();
|
|
7332
|
-
msw.use(
|
|
7333
|
-
rest.get(
|
|
7334
|
-
"*/accounts/:accountId/workers/deployments/by-script/:scriptTag",
|
|
7335
|
-
(_, res, ctx) => {
|
|
7336
|
-
return res(
|
|
7337
|
-
ctx.json(
|
|
7338
|
-
createFetchResult({
|
|
7339
|
-
latest: { number: "2" },
|
|
7340
|
-
})
|
|
7341
|
-
)
|
|
7342
|
-
);
|
|
7343
|
-
}
|
|
7344
|
-
),
|
|
7345
|
-
rest.get(
|
|
7346
|
-
"*/accounts/:accountId/workers/services/:scriptName",
|
|
7347
|
-
(_, res, ctx) => {
|
|
7348
|
-
return res(
|
|
7349
|
-
ctx.json(
|
|
7350
|
-
createFetchResult(null, false, [
|
|
7351
|
-
{ code: 10090, message: "workers.api.error.service_not_found" },
|
|
7352
|
-
])
|
|
7353
|
-
)
|
|
7354
|
-
);
|
|
7355
|
-
}
|
|
7356
|
-
)
|
|
7357
|
-
);
|
|
7358
|
-
|
|
7359
|
-
await runWrangler("publish index.js");
|
|
7360
|
-
expect(std).toMatchInlineSnapshot(`
|
|
7361
|
-
Object {
|
|
7362
|
-
"debug": "",
|
|
7363
|
-
"err": "",
|
|
7364
|
-
"info": "",
|
|
7365
|
-
"out": "Total Upload: xx KiB / gzip: xx KiB
|
|
7366
|
-
Uploaded test-name (TIMINGS)
|
|
7367
|
-
Published test-name (TIMINGS)
|
|
7368
|
-
https://test-name.test-sub-domain.workers.dev
|
|
7369
|
-
Current Deployment ID: undefined",
|
|
7370
|
-
"warn": "",
|
|
7371
|
-
}
|
|
7372
|
-
`);
|
|
7373
|
-
});
|
|
7374
|
-
|
|
7375
7353
|
it("should not publish if there's any other kind of error when checking deployment source", async () => {
|
|
7376
7354
|
writeWorkerSource();
|
|
7377
7355
|
writeWranglerToml();
|
|
@@ -7481,6 +7459,83 @@ export default{
|
|
|
7481
7459
|
`);
|
|
7482
7460
|
});
|
|
7483
7461
|
|
|
7462
|
+
it("should support queue consumer concurrency with a max concurrency specified", async () => {
|
|
7463
|
+
writeWranglerToml({
|
|
7464
|
+
queues: {
|
|
7465
|
+
consumers: [
|
|
7466
|
+
{
|
|
7467
|
+
queue: "queue1",
|
|
7468
|
+
dead_letter_queue: "myDLQ",
|
|
7469
|
+
max_batch_size: 5,
|
|
7470
|
+
max_batch_timeout: 3,
|
|
7471
|
+
max_retries: 10,
|
|
7472
|
+
max_concurrency: 5,
|
|
7473
|
+
},
|
|
7474
|
+
],
|
|
7475
|
+
},
|
|
7476
|
+
});
|
|
7477
|
+
await fs.promises.writeFile("index.js", `export default {};`);
|
|
7478
|
+
mockSubDomainRequest();
|
|
7479
|
+
mockUploadWorkerRequest();
|
|
7480
|
+
mockGetQueue("queue1");
|
|
7481
|
+
mockPutQueueConsumer("queue1", "test-name", {
|
|
7482
|
+
dead_letter_queue: "myDLQ",
|
|
7483
|
+
settings: {
|
|
7484
|
+
batch_size: 5,
|
|
7485
|
+
max_retries: 10,
|
|
7486
|
+
max_wait_time_ms: 3000,
|
|
7487
|
+
max_concurrency: 5,
|
|
7488
|
+
},
|
|
7489
|
+
});
|
|
7490
|
+
await runWrangler("publish index.js");
|
|
7491
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
7492
|
+
"Total Upload: xx KiB / gzip: xx KiB
|
|
7493
|
+
Uploaded test-name (TIMINGS)
|
|
7494
|
+
Published test-name (TIMINGS)
|
|
7495
|
+
https://test-name.test-sub-domain.workers.dev
|
|
7496
|
+
Consumer for queue1
|
|
7497
|
+
Current Deployment ID: Galaxy-Class"
|
|
7498
|
+
`);
|
|
7499
|
+
});
|
|
7500
|
+
|
|
7501
|
+
it("should support queue consumer concurrency with a null max concurrency", async () => {
|
|
7502
|
+
writeWranglerToml({
|
|
7503
|
+
queues: {
|
|
7504
|
+
consumers: [
|
|
7505
|
+
{
|
|
7506
|
+
queue: "queue1",
|
|
7507
|
+
dead_letter_queue: "myDLQ",
|
|
7508
|
+
max_batch_size: 5,
|
|
7509
|
+
max_batch_timeout: 3,
|
|
7510
|
+
max_retries: 10,
|
|
7511
|
+
max_concurrency: null,
|
|
7512
|
+
},
|
|
7513
|
+
],
|
|
7514
|
+
},
|
|
7515
|
+
});
|
|
7516
|
+
await fs.promises.writeFile("index.js", `export default {};`);
|
|
7517
|
+
mockSubDomainRequest();
|
|
7518
|
+
mockUploadWorkerRequest();
|
|
7519
|
+
mockGetQueue("queue1");
|
|
7520
|
+
mockPutQueueConsumer("queue1", "test-name", {
|
|
7521
|
+
dead_letter_queue: "myDLQ",
|
|
7522
|
+
settings: {
|
|
7523
|
+
batch_size: 5,
|
|
7524
|
+
max_retries: 10,
|
|
7525
|
+
max_wait_time_ms: 3000,
|
|
7526
|
+
},
|
|
7527
|
+
});
|
|
7528
|
+
await runWrangler("publish index.js");
|
|
7529
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
7530
|
+
"Total Upload: xx KiB / gzip: xx KiB
|
|
7531
|
+
Uploaded test-name (TIMINGS)
|
|
7532
|
+
Published test-name (TIMINGS)
|
|
7533
|
+
https://test-name.test-sub-domain.workers.dev
|
|
7534
|
+
Consumer for queue1
|
|
7535
|
+
Current Deployment ID: Galaxy-Class"
|
|
7536
|
+
`);
|
|
7537
|
+
});
|
|
7538
|
+
|
|
7484
7539
|
it("consumer should error when a queue doesn't exist", async () => {
|
|
7485
7540
|
writeWranglerToml({
|
|
7486
7541
|
queues: {
|
|
@@ -7609,6 +7664,33 @@ export default{
|
|
|
7609
7664
|
`);
|
|
7610
7665
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
7611
7666
|
});
|
|
7667
|
+
|
|
7668
|
+
it("should send keepVars when `keep_vars = true`", async () => {
|
|
7669
|
+
process.env = {
|
|
7670
|
+
CLOUDFLARE_API_TOKEN: "hunter2",
|
|
7671
|
+
CLOUDFLARE_ACCOUNT_ID: "some-account-id",
|
|
7672
|
+
};
|
|
7673
|
+
setIsTTY(false);
|
|
7674
|
+
writeWranglerToml({
|
|
7675
|
+
keep_vars: true,
|
|
7676
|
+
});
|
|
7677
|
+
writeWorkerSource();
|
|
7678
|
+
mockSubDomainRequest();
|
|
7679
|
+
mockUploadWorkerRequest({ keepVars: true });
|
|
7680
|
+
mockOAuthServerCallback();
|
|
7681
|
+
mockGetMemberships([]);
|
|
7682
|
+
|
|
7683
|
+
await runWrangler("publish index.js");
|
|
7684
|
+
|
|
7685
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
7686
|
+
"Total Upload: xx KiB / gzip: xx KiB
|
|
7687
|
+
Uploaded test-name (TIMINGS)
|
|
7688
|
+
Published test-name (TIMINGS)
|
|
7689
|
+
https://test-name.test-sub-domain.workers.dev
|
|
7690
|
+
Current Deployment ID: Galaxy-Class"
|
|
7691
|
+
`);
|
|
7692
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
7693
|
+
});
|
|
7612
7694
|
});
|
|
7613
7695
|
});
|
|
7614
7696
|
|
|
@@ -7630,7 +7712,7 @@ function mockDeploymentsListRequest() {
|
|
|
7630
7712
|
}
|
|
7631
7713
|
|
|
7632
7714
|
function mockLastDeploymentRequest() {
|
|
7633
|
-
msw.use(...
|
|
7715
|
+
msw.use(...mswSuccessDeploymentScriptMetadata);
|
|
7634
7716
|
}
|
|
7635
7717
|
|
|
7636
7718
|
/** Create a mock handler for the request to upload a worker script. */
|
|
@@ -7648,7 +7730,6 @@ function mockUploadWorkerRequest(
|
|
|
7648
7730
|
expectedUnsafeMetaData?: Record<string, string>;
|
|
7649
7731
|
env?: string;
|
|
7650
7732
|
legacyEnv?: boolean;
|
|
7651
|
-
sendScriptIds?: boolean;
|
|
7652
7733
|
keepVars?: boolean;
|
|
7653
7734
|
tag?: string;
|
|
7654
7735
|
} = {}
|
|
@@ -7666,7 +7747,6 @@ function mockUploadWorkerRequest(
|
|
|
7666
7747
|
legacyEnv = false,
|
|
7667
7748
|
expectedMigrations,
|
|
7668
7749
|
expectedUnsafeMetaData,
|
|
7669
|
-
sendScriptIds,
|
|
7670
7750
|
keepVars,
|
|
7671
7751
|
} = options;
|
|
7672
7752
|
if (env && !legacyEnv) {
|
|
@@ -7748,12 +7828,11 @@ function mockUploadWorkerRequest(
|
|
|
7748
7828
|
ctx.json(
|
|
7749
7829
|
createFetchResult({
|
|
7750
7830
|
available_on_subdomain,
|
|
7751
|
-
|
|
7752
|
-
|
|
7753
|
-
|
|
7754
|
-
|
|
7755
|
-
|
|
7756
|
-
}),
|
|
7831
|
+
id: "abc12345",
|
|
7832
|
+
etag: "etag98765",
|
|
7833
|
+
pipeline_hash: "hash9999",
|
|
7834
|
+
tag: "sample-tag",
|
|
7835
|
+
deployment_id: "Galaxy-Class",
|
|
7757
7836
|
})
|
|
7758
7837
|
)
|
|
7759
7838
|
);
|
|
@@ -351,7 +351,8 @@ describe("wrangler", () => {
|
|
|
351
351
|
--batch-size Maximum number of messages per batch [number]
|
|
352
352
|
--batch-timeout Maximum number of seconds to wait to fill a batch with messages [number]
|
|
353
353
|
--message-retries Maximum number of retries for each message [number]
|
|
354
|
-
--dead-letter-queue Queue to send messages that failed to be consumed [string]
|
|
354
|
+
--dead-letter-queue Queue to send messages that failed to be consumed [string]
|
|
355
|
+
--max-concurrency The maximum number of concurrent consumer Worker invocations. Must be a positive integer [number]"
|
|
355
356
|
`);
|
|
356
357
|
});
|
|
357
358
|
|
|
@@ -363,6 +364,7 @@ describe("wrangler", () => {
|
|
|
363
364
|
batch_size: undefined,
|
|
364
365
|
max_retries: undefined,
|
|
365
366
|
max_wait_time_ms: undefined,
|
|
367
|
+
max_concurrency: undefined,
|
|
366
368
|
},
|
|
367
369
|
dead_letter_queue: undefined,
|
|
368
370
|
};
|
|
@@ -382,13 +384,14 @@ describe("wrangler", () => {
|
|
|
382
384
|
batch_size: 20,
|
|
383
385
|
max_retries: 3,
|
|
384
386
|
max_wait_time_ms: 10 * 1000,
|
|
387
|
+
max_concurrency: 3,
|
|
385
388
|
},
|
|
386
389
|
dead_letter_queue: "myDLQ",
|
|
387
390
|
};
|
|
388
391
|
mockPostRequest("testQueue", expectedBody);
|
|
389
392
|
|
|
390
393
|
await runWrangler(
|
|
391
|
-
"queues consumer add testQueue testScript --env myEnv --batch-size 20 --batch-timeout 10 --message-retries 3 --dead-letter-queue myDLQ"
|
|
394
|
+
"queues consumer add testQueue testScript --env myEnv --batch-size 20 --batch-timeout 10 --message-retries 3 --max-concurrency 3 --dead-letter-queue myDLQ"
|
|
392
395
|
);
|
|
393
396
|
expect(std.out).toMatchInlineSnapshot(`
|
|
394
397
|
"Adding consumer to queue testQueue.
|