wrangler 0.0.0-e3cab74 → 0.0.0-e3e3243

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 (66) hide show
  1. package/README.md +1 -1
  2. package/bin/wrangler.js +10 -1
  3. package/miniflare-dist/index.mjs +79 -0
  4. package/miniflare-dist/index.mjs.map +7 -0
  5. package/package.json +10 -7
  6. package/pages/functions/filepath-routing.test.ts +125 -25
  7. package/pages/functions/filepath-routing.ts +6 -3
  8. package/src/__tests__/configuration.test.ts +959 -324
  9. package/src/__tests__/dev.test.tsx +512 -84
  10. package/src/__tests__/guess-worker-format.test.ts +19 -17
  11. package/src/__tests__/helpers/mock-account-id.ts +22 -4
  12. package/src/__tests__/helpers/mock-cfetch.ts +3 -3
  13. package/src/__tests__/helpers/mock-console.ts +17 -9
  14. package/src/__tests__/helpers/mock-kv.ts +9 -16
  15. package/src/__tests__/helpers/mock-stdin.ts +103 -0
  16. package/src/__tests__/helpers/run-in-tmp.ts +3 -0
  17. package/src/__tests__/https-options.test.ts +127 -0
  18. package/src/__tests__/index.test.ts +128 -11
  19. package/src/__tests__/jest.setup.ts +16 -4
  20. package/src/__tests__/kv.test.ts +364 -125
  21. package/src/__tests__/logout.test.ts +15 -13
  22. package/src/__tests__/pages.test.ts +82 -0
  23. package/src/__tests__/publish.test.ts +1838 -735
  24. package/src/__tests__/r2.test.ts +4 -4
  25. package/src/__tests__/route.test.ts +45 -0
  26. package/src/__tests__/secret.test.ts +167 -68
  27. package/src/__tests__/tail.test.ts +2 -4
  28. package/src/__tests__/whoami.test.tsx +21 -7
  29. package/src/bundle.ts +27 -5
  30. package/src/cfetch/internal.ts +11 -5
  31. package/src/config/README.md +6 -6
  32. package/src/config/config.ts +54 -101
  33. package/src/config/environment.ts +67 -1
  34. package/src/config/index.ts +13 -3
  35. package/src/config/validation-helpers.ts +207 -23
  36. package/src/config/validation.ts +344 -129
  37. package/src/{api/preview.ts → create-worker-preview.ts} +39 -20
  38. package/src/{api/form_data.ts → create-worker-upload-form.ts} +1 -1
  39. package/src/dev/dev.tsx +392 -0
  40. package/src/dev/local.tsx +232 -0
  41. package/src/dev/remote.tsx +203 -0
  42. package/src/dev/use-esbuild.ts +104 -0
  43. package/src/entry.ts +192 -9
  44. package/src/https-options.ts +122 -0
  45. package/src/index.tsx +577 -515
  46. package/src/inspect.ts +9 -1
  47. package/src/intl-polyfill.d.ts +139 -0
  48. package/src/{kv.tsx → kv.ts} +97 -53
  49. package/src/miniflare-cli/README.md +30 -0
  50. package/src/miniflare-cli/enum-keys.ts +17 -0
  51. package/src/miniflare-cli/index.ts +37 -0
  52. package/src/module-collection.ts +90 -2
  53. package/src/open-in-browser.ts +14 -2
  54. package/src/pages.tsx +26 -10
  55. package/src/proxy.ts +104 -40
  56. package/src/publish.ts +53 -71
  57. package/src/reporting.ts +25 -9
  58. package/src/selfsigned.d.ts +29 -0
  59. package/src/sites.tsx +68 -29
  60. package/src/user.tsx +163 -85
  61. package/src/{api/worker.ts → worker.ts} +1 -24
  62. package/wrangler-dist/cli.js +5933 -3842
  63. package/wrangler-dist/cli.js.map +3 -3
  64. package/src/__tests__/helpers/mock-user.ts +0 -27
  65. package/src/dev.tsx +0 -961
  66. package/src/guess-worker-format.ts +0 -68
@@ -2,9 +2,12 @@ import { existsSync } from "node:fs";
2
2
  import os from "node:os";
3
3
  import path from "node:path";
4
4
  import fetchMock from "jest-fetch-mock";
5
- import { initialise } from "../user";
5
+ import {
6
+ reinitialiseAuthTokens,
7
+ USER_AUTH_CONFIG_FILE,
8
+ writeAuthConfigFile,
9
+ } from "../user";
6
10
  import { mockConsoleMethods } from "./helpers/mock-console";
7
- import { writeUserConfig } from "./helpers/mock-user";
8
11
  import { runInTempDir } from "./helpers/run-in-tmp";
9
12
  import { runWrangler } from "./helpers/run-wrangler";
10
13
 
@@ -14,14 +17,15 @@ describe("wrangler", () => {
14
17
 
15
18
  describe("logout", () => {
16
19
  it("should exit with a message stating the user is not logged in", async () => {
17
- await initialise();
18
20
  await runWrangler("logout");
19
21
  expect(std.out).toMatchInlineSnapshot(`"Not logged in, exiting..."`);
20
22
  });
21
23
 
22
24
  it("should logout user that has been properly logged in", async () => {
23
- writeUserConfig("some-oauth-tok", "some-refresh-tok");
24
-
25
+ writeAuthConfigFile({
26
+ oauth_token: "some-oauth-tok",
27
+ refresh_token: "some-refresh-tok",
28
+ });
25
29
  // Mock out the response for a request to revoke the auth tokens,
26
30
  // checking the form of the request is as expected.
27
31
  fetchMock.mockResponseOnce(async (req) => {
@@ -30,21 +34,19 @@ describe("wrangler", () => {
30
34
  return "";
31
35
  });
32
36
 
33
- await initialise();
37
+ // Now that we have changed the auth tokens in the wrangler.toml we must reinitialize the user auth state.
38
+ reinitialiseAuthTokens();
34
39
  await runWrangler("logout");
35
40
 
36
- expect(std.out).toMatchInlineSnapshot(`
37
- "💁 Wrangler is configured with an OAuth token. The token has been successfully revoked
38
- Removing ./home/.wrangler/config/default.toml.. success!"
39
- `);
41
+ expect(std.out).toMatchInlineSnapshot(`"Successfully logged out."`);
40
42
 
41
43
  // Make sure that we made the request to logout.
42
44
  expect(fetchMock).toHaveBeenCalledTimes(1);
43
45
 
44
46
  // Make sure that logout removed the config file containing the auth tokens.
45
- expect(
46
- existsSync(path.join(os.homedir(), ".wrangler/config/default.toml"))
47
- ).toBe(false);
47
+ expect(existsSync(path.join(os.homedir(), USER_AUTH_CONFIG_FILE))).toBe(
48
+ false
49
+ );
48
50
  });
49
51
  });
50
52
  });
@@ -0,0 +1,82 @@
1
+ import { execaSync } from "execa";
2
+ import { getPackageManager } from "../package-manager";
3
+ import { mockConsoleMethods } from "./helpers/mock-console";
4
+ import { runInTempDir } from "./helpers/run-in-tmp";
5
+ import { runWrangler } from "./helpers/run-wrangler";
6
+ import type { PackageManager } from "../package-manager";
7
+
8
+ describe("subcommand implicit help ran on imcomplete command execution", () => {
9
+ let mockPackageManager: PackageManager;
10
+ runInTempDir();
11
+
12
+ beforeEach(() => {
13
+ mockPackageManager = {
14
+ cwd: process.cwd(),
15
+ // @ts-expect-error we're making a fake package manager here
16
+ type: "mockpm",
17
+ addDevDeps: jest.fn(),
18
+ install: jest.fn(),
19
+ };
20
+ (getPackageManager as jest.Mock).mockResolvedValue(mockPackageManager);
21
+ });
22
+
23
+ const std = mockConsoleMethods();
24
+ function endEventLoop() {
25
+ return new Promise((resolve) => setImmediate(resolve));
26
+ }
27
+
28
+ it("should should display a list of available subcommands, for pages with no subcommand", async () => {
29
+ await runWrangler("pages");
30
+ await endEventLoop();
31
+
32
+ expect(std.out).toMatchInlineSnapshot(`
33
+ "wrangler pages
34
+
35
+ ⚡️ Configure Cloudflare Pages
36
+
37
+ Commands:
38
+ wrangler pages dev [directory] [-- command] 🧑‍💻 Develop your full-stack Pages application locally
39
+
40
+ Flags:
41
+ -c, --config Path to .toml configuration file [string]
42
+ -h, --help Show help [boolean]
43
+ -v, --version Show version number [boolean]
44
+ --legacy-env Use legacy environments [boolean]
45
+
46
+ 🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/wrangler2/issues/new/choose"
47
+ `);
48
+ });
49
+ });
50
+
51
+ describe("beta message for subcommands", () => {
52
+ const isWindows = process.platform === "win32";
53
+ it("should display for pages:dev", async () => {
54
+ try {
55
+ execaSync("npx", ["wrangler", "pages", "dev"], {
56
+ shell: isWindows,
57
+ env: { BROWSER: "none", ...process.env },
58
+ }).stderr;
59
+ } catch (e: unknown) {
60
+ expect(e).toMatchInlineSnapshot(`
61
+ [Error: Command failed with exit code 1: npx wrangler pages dev
62
+ 🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/wrangler2/issues/new/choose
63
+ Must specify a directory of static assets to serve or a command to run.]
64
+ `);
65
+ }
66
+ });
67
+
68
+ it("should display for pages:functions", async () => {
69
+ try {
70
+ execaSync("npx", ["wrangler", "pages", "functions"], {
71
+ shell: isWindows,
72
+ env: { BROWSER: "none", ...process.env },
73
+ }).stderr;
74
+ } catch (e: unknown) {
75
+ expect(e).toMatchInlineSnapshot(`
76
+ [Error: Command failed with exit code 1: npx wrangler pages functions
77
+ 🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/wrangler2/issues/new/choose
78
+ Must specify a directory of static assets to serve or a command to run.]
79
+ `);
80
+ }
81
+ });
82
+ });