diff --git a/.changeset/ready-humans-thank.md b/.changeset/ready-humans-thank.md new file mode 100644 index 000000000000..296010930657 --- /dev/null +++ b/.changeset/ready-humans-thank.md @@ -0,0 +1,5 @@ +--- +"wrangler": patch +--- + +add extra logging to user log-in flow for diagnosing failed login requests diff --git a/packages/create-cloudflare/tsconfig.json b/packages/create-cloudflare/tsconfig.json index 4cc1c6a96f7f..e369248865cd 100644 --- a/packages/create-cloudflare/tsconfig.json +++ b/packages/create-cloudflare/tsconfig.json @@ -14,7 +14,7 @@ "compilerOptions": { "target": "ESNext", "module": "preserve", - "moduleResolution": "node", + "moduleResolution": "bundler", "allowJs": true, "strict": true, "esModuleInterop": true, diff --git a/packages/workers-utils/tests/vitest.setup.ts b/packages/workers-utils/tests/vitest.setup.ts deleted file mode 100644 index ecbcbaa12014..000000000000 --- a/packages/workers-utils/tests/vitest.setup.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { afterEach, vi } from "vitest"; - -afterEach(() => { - // It is important that we clear mocks between tests to avoid leakage. - vi.clearAllMocks(); -}); diff --git a/packages/workers-utils/vitest.config.mts b/packages/workers-utils/vitest.config.mts index 3a626b828c38..cd09d35c0be6 100644 --- a/packages/workers-utils/vitest.config.mts +++ b/packages/workers-utils/vitest.config.mts @@ -5,16 +5,14 @@ export default defineConfig({ test: { testTimeout: 15_000, pool: "forks", - retry: 0, include: ["**/tests/**/*.test.ts"], - setupFiles: path.resolve(__dirname, "tests/vitest.setup.ts"), globalSetup: path.resolve(__dirname, "tests/vitest.global.ts"), reporters: ["default"], - globals: true, snapshotFormat: { escapeString: true, printBasicPrototype: true, }, unstubEnvs: true, + mockReset: true, }, }); diff --git a/packages/wrangler/src/__tests__/deploy.test.ts b/packages/wrangler/src/__tests__/deploy.test.ts index d7131f78f611..3bbeda16fa58 100644 --- a/packages/wrangler/src/__tests__/deploy.test.ts +++ b/packages/wrangler/src/__tests__/deploy.test.ts @@ -733,15 +733,21 @@ describe("deploy", () => { https://test-name.test-sub-domain.workers.dev Current Version ID: Galaxy-Class" `); - expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] It looks like you have used Wrangler v1'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. + // The current working directory is replaced with `` to make the snapshot consistent across environments + // But since the actual working directory could be a long string on some operating systems it is possible that the string gets wrapped to a new line. + // To avoid failures across different environments, we remove any newline before `` in the snapshot. + expect(std.warn.replaceAll(/from[ \r\n]+/g, "from ")) + .toMatchInlineSnapshot(` + "▲ [WARNING] It looks like you have used Wrangler v1's \`config\` command to login with an API token - " - `); + from /home/.config/.wrangler/config/default.toml. + 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. + + " + `); expect(std.err).toMatchInlineSnapshot(`""`); }); diff --git a/packages/wrangler/src/__tests__/whoami.test.ts b/packages/wrangler/src/__tests__/whoami.test.ts index 0c43b56f8eb2..9d1ea018fc35 100644 --- a/packages/wrangler/src/__tests__/whoami.test.ts +++ b/packages/wrangler/src/__tests__/whoami.test.ts @@ -198,9 +198,14 @@ describe("getUserInfo(COMPLIANCE_REGION_CONFIG_UNKNOWN)", () => { writeAuthConfigFile({ api_token: "API_TOKEN" }); await getUserInfo(COMPLIANCE_REGION_CONFIG_UNKNOWN); - expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] It looks like you have used Wrangler v1's \`config\` command to login with an API token. - + // The current working directory is replaced with `` to make the snapshot consistent across environments + // But since the actual working directory could be a long string on some operating systems it is possible that the string gets wrapped to a new line. + // To avoid failures across different environments, we remove any newline before `` in the snapshot. + expect(std.warn.replaceAll(/from[ \r\n]+/g, "from ")) + .toMatchInlineSnapshot(` + "▲ [WARNING] It looks like you have used Wrangler v1's \`config\` command to login with an API token + + from /home/.config/.wrangler/config/default.toml. 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/user/user.ts b/packages/wrangler/src/user/user.ts index 820f5541cefb..119d2bf5fa4b 100644 --- a/packages/wrangler/src/user/user.ts +++ b/packages/wrangler/src/user/user.ts @@ -422,7 +422,8 @@ function getAuthTokens(config?: UserAuthConfig): AuthTokens | undefined { }; } else if (api_token) { logger.warn( - "It looks like you have used Wrangler v1's `config` command to login with an API token.\n" + + "It looks like you have used Wrangler v1's `config` command to login with an API token\n" + + `from ${config === undefined ? getAuthConfigFilePath() : "in-memory config"}.\n` + "This is no longer supported in the current version of Wrangler.\n" + "If you wish to authenticate via an API token then please set the `CLOUDFLARE_API_TOKEN` environment variable." ); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4942711cab0a..7afe4c804725 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -40,7 +40,7 @@ catalogs: specifier: ^1.5.2 version: 1.5.2 typescript: - specifier: ^5.8.3 + specifier: ~5.8.3 version: 5.8.3 undici: specifier: 7.14.0 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 9ba8efea9831..a0fe279431ed 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -24,7 +24,7 @@ catalog: "@vitest/ui": ~3.2.0 # rimraf@6 requires node 20 or >=22 rimraf: "^6.0.1" - typescript: "^5.8.3" + typescript: "~5.8.3" undici: "7.14.0" # Override undici-types from @types/node so that the Cloudflare SDK typings match our installed # version of Undici diff --git a/turbo.json b/turbo.json index 20377dd0304c..b26568ea78ad 100644 --- a/turbo.json +++ b/turbo.json @@ -5,17 +5,18 @@ }, "globalEnv": ["CI_OS", "NODE_VERSION"], "globalPassThroughEnv": [ - "NODE_EXTRA_CA_CERTS", "CI", - "VSCODE_INSPECTOR_OPTIONS", - "WRANGLER_LOG_PATH", - "TEST_REPORT_PATH", "CLOUDFLARE_CONTAINER_REGISTRY", "DOCKER_HOST", - "WRANGLER_DOCKER_HOST", - "WRANGLER_LOG", + "LOCAL_TESTS_WITHOUT_DOCKER", + "NODE_EXTRA_CA_CERTS", + "PWD", + "TEST_REPORT_PATH", + "VSCODE_INSPECTOR_OPTIONS", "WRANGLER_API_ENVIRONMENT", - "LOCAL_TESTS_WITHOUT_DOCKER" + "WRANGLER_DOCKER_HOST", + "WRANGLER_LOG_PATH", + "WRANGLER_LOG" ], "tasks": { "dev": {