From 8134bdcb6fdc9a497dc35b9278a827401e7c7ae7 Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Wed, 4 May 2022 14:46:48 +0100 Subject: [PATCH] fix: remove bold font from additional lines of warnings and errors Previously, when a warning or error was logged, the entire message was formatted in bold font. This change makes only the first line of the message bold, and the rest is formatted with a normal font. --- .changeset/itchy-windows-attack.md | 9 + packages/wrangler/src/__tests__/dev.test.tsx | 40 +-- .../src/__tests__/helpers/mock-console.ts | 2 + .../src/__tests__/https-options.test.ts | 5 +- packages/wrangler/src/__tests__/kv.test.ts | 10 +- .../wrangler/src/__tests__/publish.test.ts | 259 ++++++++++-------- .../wrangler/src/__tests__/whoami.test.tsx | 8 +- packages/wrangler/src/logger.ts | 18 +- 8 files changed, 212 insertions(+), 139 deletions(-) create mode 100644 .changeset/itchy-windows-attack.md diff --git a/.changeset/itchy-windows-attack.md b/.changeset/itchy-windows-attack.md new file mode 100644 index 000000000000..00ae6586af2b --- /dev/null +++ b/.changeset/itchy-windows-attack.md @@ -0,0 +1,9 @@ +--- +"wrangler": patch +--- + +fix: remove bold font from additional lines of warnings and errors + +Previously, when a warning or error was logged, the entire message +was formatted in bold font. This change makes only the first line of +the message bold, and the rest is formatted with a normal font. diff --git a/packages/wrangler/src/__tests__/dev.test.tsx b/packages/wrangler/src/__tests__/dev.test.tsx index 0da5cf944c8d..e7d7ad89f8e7 100644 --- a/packages/wrangler/src/__tests__/dev.test.tsx +++ b/packages/wrangler/src/__tests__/dev.test.tsx @@ -40,16 +40,17 @@ describe("wrangler dev", () => { expect(std.out).toMatchInlineSnapshot(`""`); expect(std.warn.replaceAll(currentDate, "")) .toMatchInlineSnapshot(` - "▲ [WARNING] No compatibility_date was specified. Using today's date: . - Add one to your wrangler.toml file: - \`\`\` - compatibility_date = \\"\\" - \`\`\` - or pass it in your terminal: - \`\`\` - --compatibility-date= - \`\`\` - See https://developers.cloudflare.com/workers/platform/compatibility-dates for more information. + "▲ [WARNING] No compatibility_date was specified. Using today's date: . + + Add one to your wrangler.toml file: + \`\`\` + compatibility_date = \\"\\" + \`\`\` + or pass it in your terminal: + \`\`\` + --compatibility-date= + \`\`\` + See https://developers.cloudflare.com/workers/platform/compatibility-dates for more information. " `); @@ -476,9 +477,10 @@ describe("wrangler dev", () => { ); expect(std.out).toMatchInlineSnapshot(`""`); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] Setting upstream-protocol to http is not currently implemented. - If this is required in your project, please add your use case to the following issue: - https://github.com/cloudflare/wrangler2/issues/583. + "▲ [WARNING] Setting upstream-protocol to http is not currently implemented. + + If this is required in your project, please add your use case to the following issue: + https://github.com/cloudflare/wrangler2/issues/583. " `); @@ -604,11 +606,13 @@ describe("wrangler dev", () => { expect((Dev as jest.Mock).mock.calls[0][0].ip).toEqual("localhost"); expect(std.out).toMatchInlineSnapshot(`""`); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] WARNING: You have Durable Object bindings that are not defined locally in the worker being developed. - Be aware that changes to the data stored in these Durable Objects will be permanent and affect the live instances. - Remote Durable Objects that are affected: - - {\\"name\\":\\"NAME_2\\",\\"class_name\\":\\"CLASS_2\\",\\"script_name\\":\\"SCRIPT_A\\"} - - {\\"name\\":\\"NAME_4\\",\\"class_name\\":\\"CLASS_4\\",\\"script_name\\":\\"SCRIPT_B\\"} + "▲ [WARNING] WARNING: You have Durable Object bindings that are not defined locally in the worker being developed. + + Be aware that changes to the data stored in these Durable Objects will be permanent and affect the + live instances. + Remote Durable Objects that are affected: + - {\\"name\\":\\"NAME_2\\",\\"class_name\\":\\"CLASS_2\\",\\"script_name\\":\\"SCRIPT_A\\"} + - {\\"name\\":\\"NAME_4\\",\\"class_name\\":\\"CLASS_4\\",\\"script_name\\":\\"SCRIPT_B\\"} " `); diff --git a/packages/wrangler/src/__tests__/helpers/mock-console.ts b/packages/wrangler/src/__tests__/helpers/mock-console.ts index 81c1b5fe5286..ccdfb81a2b58 100644 --- a/packages/wrangler/src/__tests__/helpers/mock-console.ts +++ b/packages/wrangler/src/__tests__/helpers/mock-console.ts @@ -1,4 +1,5 @@ import * as util from "node:util"; +import { logger } from "../../logger"; /** * We use this module to mock console methods, and optionally @@ -39,6 +40,7 @@ function captureCalls(spy: jest.SpyInstance): string { export function mockConsoleMethods() { beforeEach(() => { + logger.columns = 100; debugSpy = jest.spyOn(console, "debug").mockImplementation(); logSpy = jest.spyOn(console, "log").mockImplementation(); errorSpy = jest.spyOn(console, "error").mockImplementation(); diff --git a/packages/wrangler/src/__tests__/https-options.test.ts b/packages/wrangler/src/__tests__/https-options.test.ts index 29f0c6f22fcd..1ff7d73015d9 100644 --- a/packages/wrangler/src/__tests__/https-options.test.ts +++ b/packages/wrangler/src/__tests__/https-options.test.ts @@ -97,8 +97,9 @@ describe("getHttpsOptions()", () => { `"Generating new self-signed certificate..."` ); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] Unable to cache generated self-signed certificate in home/.wrangler/local-cert. - ERROR: Cannot write file + "▲ [WARNING] Unable to cache generated self-signed certificate in home/.wrangler/local-cert. + + ERROR: Cannot write file " `); diff --git a/packages/wrangler/src/__tests__/kv.test.ts b/packages/wrangler/src/__tests__/kv.test.ts index b755fae2c269..366569200d08 100644 --- a/packages/wrangler/src/__tests__/kv.test.ts +++ b/packages/wrangler/src/__tests__/kv.test.ts @@ -291,8 +291,9 @@ describe("wrangler", () => { --namespace-id The id of the namespace to delete [string] -e, --env Perform on a specific environment [string] --preview Interact with a preview namespace [boolean] - X [ERROR] Not able to delete namespace. - A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\". + X [ERROR] Not able to delete namespace. + + A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\". " `); @@ -1229,8 +1230,9 @@ describe("wrangler", () => { If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new." `); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] Unexpected key-value properties in \\"keys.json\\". - The item at index 4 contains unexpected properties: [\\"invalid\\"]. + "▲ [WARNING] Unexpected key-value properties in \\"keys.json\\". + + The item at index 4 contains unexpected properties: [\\"invalid\\"]. " `); diff --git a/packages/wrangler/src/__tests__/publish.test.ts b/packages/wrangler/src/__tests__/publish.test.ts index da7903d62423..c7419fb729b4 100644 --- a/packages/wrangler/src/__tests__/publish.test.ts +++ b/packages/wrangler/src/__tests__/publish.test.ts @@ -108,9 +108,11 @@ describe("publish", () => { test-name.test-sub-domain.workers.dev" `); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] It looks like you have used Wrangler 1's \`config\` command to login with an API token. - This is no longer supported in the current version of Wrangler. - If you wish to authenticate via an API token then please set the \`CLOUDFLARE_API_TOKEN\` environment variable. + "▲ [WARNING] It looks like you have used Wrangler 1's \`config\` command to login with an API token. + + This is no longer supported in the current version of Wrangler. + If you wish to authenticate via an API token then please set the \`CLOUDFLARE_API_TOKEN\` + environment variable. " `); @@ -189,15 +191,17 @@ describe("publish", () => { `); expect(std.err).toMatchInlineSnapshot(`""`); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] Processing wrangler.toml configuration: - - No environment found in configuration with name \\"some-env\\". - Before using \`--env=some-env\` there should be an equivalent environment section in the configuration. + "▲ [WARNING] Processing wrangler.toml configuration: + + - No environment found in configuration with name \\"some-env\\". + Before using \`--env=some-env\` there should be an equivalent environment section in the + configuration. + + Consider adding an environment configuration section to the wrangler.toml file: + \`\`\` + [env.some-env] + \`\`\` - Consider adding an environment configuration section to the wrangler.toml file: - \`\`\` - [env.some-env] - \`\`\` -  " `); @@ -256,8 +260,10 @@ describe("publish", () => { `); expect(std.err).toMatchInlineSnapshot(`""`); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] Processing wrangler.toml configuration: - - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in the future. DO NOT USE IN PRODUCTION. + "▲ [WARNING] Processing wrangler.toml configuration: + + - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in + the future. DO NOT USE IN PRODUCTION. " `); @@ -279,8 +285,10 @@ describe("publish", () => { `); expect(std.err).toMatchInlineSnapshot(`""`); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] Processing wrangler.toml configuration: - - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in the future. DO NOT USE IN PRODUCTION. + "▲ [WARNING] Processing wrangler.toml configuration: + + - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in + the future. DO NOT USE IN PRODUCTION. " `); @@ -432,8 +440,10 @@ describe("publish", () => { *another-boring-website.com (zone name: some-zone.com) example.com/some-route/* (zone id: JGHFHG654gjcj) more-examples.com/*", - "warn": "▲ [WARNING] Processing wrangler.toml configuration: - - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in the future. DO NOT USE IN PRODUCTION. + "warn": "▲ [WARNING] Processing wrangler.toml configuration: + + - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in + the future. DO NOT USE IN PRODUCTION. ", } @@ -571,13 +581,14 @@ describe("publish", () => { `); expect(std.err).toMatchInlineSnapshot(`""`); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] Processing wrangler.toml configuration: - - Deprecation: \\"build.upload.main\\": - Delete the \`build.upload.main\` and \`build.upload.dir\` fields. - Then add the top level \`main\` field to your configuration file: - \`\`\` - main = \\"dist/index.js\\" - \`\`\` + "▲ [WARNING] Processing wrangler.toml configuration: + + - Deprecation: \\"build.upload.main\\": + Delete the \`build.upload.main\` and \`build.upload.dir\` fields. + Then add the top level \`main\` field to your configuration file: + \`\`\` + main = \\"dist/index.js\\" + \`\`\` " `); @@ -605,15 +616,17 @@ describe("publish", () => { `); expect(std.err).toMatchInlineSnapshot(`""`); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] Processing ../wrangler.toml configuration: - - Deprecation: \\"build.upload.main\\": - Delete the \`build.upload.main\` and \`build.upload.dir\` fields. - Then add the top level \`main\` field to your configuration file: - \`\`\` - main = \\"foo/index.js\\" - \`\`\` - - Deprecation: \\"build.upload.dir\\": - Use the top level \\"main\\" field or a command-line argument to specify the entry-point for the Worker. + "▲ [WARNING] Processing ../wrangler.toml configuration: + + - Deprecation: \\"build.upload.main\\": + Delete the \`build.upload.main\` and \`build.upload.dir\` fields. + Then add the top level \`main\` field to your configuration file: + \`\`\` + main = \\"foo/index.js\\" + \`\`\` + - Deprecation: \\"build.upload.dir\\": + Use the top level \\"main\\" field or a command-line argument to specify the entry-point for the + Worker. " `); @@ -756,18 +769,21 @@ export default{ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new." `); expect(std.err).toMatchInlineSnapshot(` - "X [ERROR] Processing wrangler.toml configuration: - - \\"site.bucket\\" is a required field. + "X [ERROR] Processing wrangler.toml configuration: + + - \\"site.bucket\\" is a required field. " `); expect(normalizeSlashes(std.warn)).toMatchInlineSnapshot(` - "▲ [WARNING] Processing wrangler.toml configuration: - - Because you've defined a [site] configuration, we're defaulting to \\"workers-site\\" for the deprecated \`site.entry-point\`field. - Add the top level \`main\` field to your configuration file: - \`\`\` - main = \\"workers-site/index.js\\" - \`\`\` + "▲ [WARNING] Processing wrangler.toml configuration: + + - Because you've defined a [site] configuration, we're defaulting to \\"workers-site\\" for the + deprecated \`site.entry-point\`field. + Add the top level \`main\` field to your configuration file: + \`\`\` + main = \\"workers-site/index.js\\" + \`\`\` " `); @@ -810,12 +826,14 @@ export default{ Uploaded test-name (TIMINGS) Published test-name (TIMINGS) test-name.test-sub-domain.workers.dev", - "warn": "▲ [WARNING] Processing wrangler.toml configuration: - - Deprecation: \\"site.entry-point\\": - Delete the \`site.entry-point\` field, then add the top level \`main\` field to your configuration file: - \`\`\` - main = \\"index.js\\" - \`\`\` + "warn": "▲ [WARNING] Processing wrangler.toml configuration: + + - Deprecation: \\"site.entry-point\\": + Delete the \`site.entry-point\` field, then add the top level \`main\` field to your configuration + file: + \`\`\` + main = \\"index.js\\" + \`\`\` ", } @@ -862,12 +880,14 @@ export default{ `); expect(std.err).toMatchInlineSnapshot(`""`); expect(normalizeSlashes(std.warn)).toMatchInlineSnapshot(` - "▲ [WARNING] Processing my-site/wrangler.toml configuration: - - Deprecation: \\"site.entry-point\\": - Delete the \`site.entry-point\` field, then add the top level \`main\` field to your configuration file: - \`\`\` - main = \\"my-entry/index.js\\" - \`\`\` + "▲ [WARNING] Processing my-site/wrangler.toml configuration: + + - Deprecation: \\"site.entry-point\\": + Delete the \`site.entry-point\` field, then add the top level \`main\` field to your configuration + file: + \`\`\` + main = \\"my-entry/index.js\\" + \`\`\` " `); @@ -2612,8 +2632,10 @@ export default{ `); expect(std.err).toMatchInlineSnapshot(`""`); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] Processing wrangler.toml configuration: - - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in the future. DO NOT USE IN PRODUCTION. + "▲ [WARNING] Processing wrangler.toml configuration: + + - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in + the future. DO NOT USE IN PRODUCTION. " `); @@ -2668,8 +2690,10 @@ export default{ `); expect(std.err).toMatchInlineSnapshot(`""`); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] Processing wrangler.toml configuration: - - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in the future. DO NOT USE IN PRODUCTION. + "▲ [WARNING] Processing wrangler.toml configuration: + + - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in + the future. DO NOT USE IN PRODUCTION. " `); @@ -2717,8 +2741,10 @@ export default{ "out": "Uploaded test-name (TIMINGS) Published test-name (TIMINGS) test-name.test-sub-domain.workers.dev", - "warn": "▲ [WARNING] Processing wrangler.toml configuration: - - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in the future. DO NOT USE IN PRODUCTION. + "warn": "▲ [WARNING] Processing wrangler.toml configuration: + + - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in + the future. DO NOT USE IN PRODUCTION. ", } @@ -2779,8 +2805,10 @@ export default{ "out": "Uploaded test-name (xyz) (TIMINGS) Published test-name (xyz) (TIMINGS) xyz.test-name.test-sub-domain.workers.dev", - "warn": "▲ [WARNING] Processing wrangler.toml configuration: - - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in the future. DO NOT USE IN PRODUCTION. + "warn": "▲ [WARNING] Processing wrangler.toml configuration: + + - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in + the future. DO NOT USE IN PRODUCTION. ", } @@ -2942,8 +2970,9 @@ export default{ `); expect(std.err).toMatchInlineSnapshot(`""`); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] Processing wrangler.toml configuration: - - \\"unsafe\\" fields are experimental and may change or break at any time. + "▲ [WARNING] Processing wrangler.toml configuration: + + - \\"unsafe\\" fields are experimental and may change or break at any time. " `); @@ -3035,19 +3064,22 @@ export default{ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new." `); expect(std.err).toMatchInlineSnapshot(` - "X [ERROR] Processing wrangler.toml configuration: - - CONFLICTING_NAME_ONE assigned to Durable Object, KV Namespace, and R2 Bucket bindings. - - CONFLICTING_NAME_TWO assigned to Durable Object and KV Namespace bindings. - - CONFLICTING_NAME_THREE assigned to R2 Bucket, Text Blob, Unsafe, Environment Variable, WASM Module, and Data Blob bindings. - - CONFLICTING_NAME_FOUR assigned to Text Blob and Unsafe bindings. - - Bindings must have unique names, so that they can all be referenced in the worker. - Please change your bindings to have unique names. + "X [ERROR] Processing wrangler.toml configuration: + + - CONFLICTING_NAME_ONE assigned to Durable Object, KV Namespace, and R2 Bucket bindings. + - CONFLICTING_NAME_TWO assigned to Durable Object and KV Namespace bindings. + - CONFLICTING_NAME_THREE assigned to R2 Bucket, Text Blob, Unsafe, Environment Variable, WASM + Module, and Data Blob bindings. + - CONFLICTING_NAME_FOUR assigned to Text Blob and Unsafe bindings. + - Bindings must have unique names, so that they can all be referenced in the worker. + Please change your bindings to have unique names. " `); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] Processing wrangler.toml configuration: - - \\"unsafe\\" fields are experimental and may change or break at any time. + "▲ [WARNING] Processing wrangler.toml configuration: + + - \\"unsafe\\" fields are experimental and may change or break at any time. " `); @@ -3131,19 +3163,21 @@ export default{ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new." `); expect(std.err).toMatchInlineSnapshot(` - "X [ERROR] Processing wrangler.toml configuration: - - CONFLICTING_DURABLE_OBJECT_NAME assigned to multiple Durable Object bindings. - - CONFLICTING_KV_NAMESPACE_NAME assigned to multiple KV Namespace bindings. - - CONFLICTING_R2_BUCKET_NAME assigned to multiple R2 Bucket bindings. - - CONFLICTING_UNSAFE_NAME assigned to multiple Unsafe bindings. - - Bindings must have unique names, so that they can all be referenced in the worker. - Please change your bindings to have unique names. + "X [ERROR] Processing wrangler.toml configuration: + + - CONFLICTING_DURABLE_OBJECT_NAME assigned to multiple Durable Object bindings. + - CONFLICTING_KV_NAMESPACE_NAME assigned to multiple KV Namespace bindings. + - CONFLICTING_R2_BUCKET_NAME assigned to multiple R2 Bucket bindings. + - CONFLICTING_UNSAFE_NAME assigned to multiple Unsafe bindings. + - Bindings must have unique names, so that they can all be referenced in the worker. + Please change your bindings to have unique names. " `); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] Processing wrangler.toml configuration: - - \\"unsafe\\" fields are experimental and may change or break at any time. + "▲ [WARNING] Processing wrangler.toml configuration: + + - \\"unsafe\\" fields are experimental and may change or break at any time. " `); @@ -3263,21 +3297,24 @@ export default{ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new." `); expect(std.err).toMatchInlineSnapshot(` - "X [ERROR] Processing wrangler.toml configuration: - - CONFLICTING_DURABLE_OBJECT_NAME assigned to multiple Durable Object bindings. - - CONFLICTING_KV_NAMESPACE_NAME assigned to multiple KV Namespace bindings. - - CONFLICTING_R2_BUCKET_NAME assigned to multiple R2 Bucket bindings. - - CONFLICTING_NAME_THREE assigned to R2 Bucket, Text Blob, Unsafe, Environment Variable, WASM Module, and Data Blob bindings. - - CONFLICTING_NAME_FOUR assigned to R2 Bucket, Text Blob, and Unsafe bindings. - - CONFLICTING_UNSAFE_NAME assigned to multiple Unsafe bindings. - - Bindings must have unique names, so that they can all be referenced in the worker. - Please change your bindings to have unique names. + "X [ERROR] Processing wrangler.toml configuration: + + - CONFLICTING_DURABLE_OBJECT_NAME assigned to multiple Durable Object bindings. + - CONFLICTING_KV_NAMESPACE_NAME assigned to multiple KV Namespace bindings. + - CONFLICTING_R2_BUCKET_NAME assigned to multiple R2 Bucket bindings. + - CONFLICTING_NAME_THREE assigned to R2 Bucket, Text Blob, Unsafe, Environment Variable, WASM + Module, and Data Blob bindings. + - CONFLICTING_NAME_FOUR assigned to R2 Bucket, Text Blob, and Unsafe bindings. + - CONFLICTING_UNSAFE_NAME assigned to multiple Unsafe bindings. + - Bindings must have unique names, so that they can all be referenced in the worker. + Please change your bindings to have unique names. " `); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] Processing wrangler.toml configuration: - - \\"unsafe\\" fields are experimental and may change or break at any time. + "▲ [WARNING] Processing wrangler.toml configuration: + + - \\"unsafe\\" fields are experimental and may change or break at any time. " `); @@ -3850,8 +3887,9 @@ export default{ `); expect(std.err).toMatchInlineSnapshot(`""`); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] Processing wrangler.toml configuration: - - \\"unsafe\\" fields are experimental and may change or break at any time. + "▲ [WARNING] Processing wrangler.toml configuration: + + - \\"unsafe\\" fields are experimental and may change or break at any time. " `); @@ -3888,12 +3926,14 @@ export default{ `); expect(std.err).toMatchInlineSnapshot(`""`); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] Processing wrangler.toml configuration: - - \\"unsafe\\" fields are experimental and may change or break at any time. - - \\"unsafe.bindings[0]\\": {\\"name\\":\\"my-binding\\",\\"type\\":\\"plain_text\\",\\"text\\":\\"text\\"} - - The binding type \\"plain_text\\" is directly supported by wrangler. - Consider migrating this unsafe binding to a format for 'plain_text' bindings that is supported by wrangler for optimal support. - For more details, see https://developers.cloudflare.com/workers/cli-wrangler/configuration + "▲ [WARNING] Processing wrangler.toml configuration: + + - \\"unsafe\\" fields are experimental and may change or break at any time. + - \\"unsafe.bindings[0]\\": {\\"name\\":\\"my-binding\\",\\"type\\":\\"plain_text\\",\\"text\\":\\"text\\"} + - The binding type \\"plain_text\\" is directly supported by wrangler. + Consider migrating this unsafe binding to a format for 'plain_text' bindings that is + supported by wrangler for optimal support. + For more details, see https://developers.cloudflare.com/workers/cli-wrangler/configuration " `); @@ -3991,14 +4031,17 @@ export default{ `); expect(std.err).toMatchInlineSnapshot(`""`); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] Processing wrangler.toml configuration: - - Deprecation: The \`build.upload.rules\` config field is no longer used, the rules should be specified via the \`rules\` config field. Delete the \`build.upload\` field from the configuration file, and add this: - \`\`\` - [[rules]] - type = \\"Text\\" - globs = [ \\"**/*.file\\" ] - fallthrough = true - \`\`\` + "▲ [WARNING] Processing wrangler.toml configuration: + + - Deprecation: The \`build.upload.rules\` config field is no longer used, the rules should be + specified via the \`rules\` config field. Delete the \`build.upload\` field from the configuration + file, and add this: + \`\`\` + [[rules]] + type = \\"Text\\" + globs = [ \\"**/*.file\\" ] + fallthrough = true + \`\`\` " `); diff --git a/packages/wrangler/src/__tests__/whoami.test.tsx b/packages/wrangler/src/__tests__/whoami.test.tsx index 719ba381c2e5..0ea12c81bd3d 100644 --- a/packages/wrangler/src/__tests__/whoami.test.tsx +++ b/packages/wrangler/src/__tests__/whoami.test.tsx @@ -54,9 +54,11 @@ describe("getUserInfo()", () => { writeAuthConfigFile({ api_token: "API_TOKEN" }); await getUserInfo(); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] It looks like you have used Wrangler 1's \`config\` command to login with an API token. - This is no longer supported in the current version of Wrangler. - If you wish to authenticate via an API token then please set the \`CLOUDFLARE_API_TOKEN\` environment variable. + "▲ [WARNING] It looks like you have used Wrangler 1's \`config\` command to login with an API token. + + This is no longer supported in the current version of Wrangler. + If you wish to authenticate via an API token then please set the \`CLOUDFLARE_API_TOKEN\` + environment variable. " `); diff --git a/packages/wrangler/src/logger.ts b/packages/wrangler/src/logger.ts index 895b8ceafb28..15b6defb846f 100644 --- a/packages/wrangler/src/logger.ts +++ b/packages/wrangler/src/logger.ts @@ -21,6 +21,8 @@ const LOGGER_LEVEL_FORMAT_TYPE_MAP = { class Logger { constructor(public loggerLevel: LoggerLevel = "log") {} + columns = process.stdout.columns; + debug = (...args: unknown[]) => this.doLog("debug", args); log = (...args: unknown[]) => this.doLog("log", args); warn = (...args: unknown[]) => this.doLog("warn", args); @@ -32,16 +34,24 @@ class Logger { } } - formatMessage(level: LoggerLevel, text: string): string { + private formatMessage(level: LoggerLevel, message: string): string { const kind = LOGGER_LEVEL_FORMAT_TYPE_MAP[level]; if (kind) { - return formatMessagesSync([{ text }], { + // Format the message using the esbuild formatter. + // The first line of the message is the main `text`, + // subsequent lines are put into the `notes`. + const [firstLine, ...otherLines] = message.split("\n"); + const notes = + otherLines.length > 0 + ? otherLines.map((text) => ({ text })) + : undefined; + return formatMessagesSync([{ text: firstLine, notes }], { color: true, kind, - terminalWidth: process.stdout.columns, + terminalWidth: this.columns, })[0]; } else { - return text; + return message; } } }