wrangler 0.0.0-e3cab74 → 0.0.0-e452a35

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 (102) hide show
  1. package/Cloudflare_CA.pem +18 -0
  2. package/README.md +27 -14
  3. package/bin/wrangler.js +49 -5
  4. package/miniflare-dist/index.mjs +4886 -0
  5. package/package.json +42 -28
  6. package/pages/functions/buildPlugin.ts +105 -0
  7. package/pages/functions/buildWorker.ts +93 -4
  8. package/pages/functions/filepath-routing.test.ts +136 -25
  9. package/pages/functions/filepath-routing.ts +14 -3
  10. package/pages/functions/routes.ts +6 -1
  11. package/pages/functions/template-plugin.ts +147 -0
  12. package/pages/functions/template-worker.ts +21 -8
  13. package/src/__tests__/config-cache.test.ts +36 -0
  14. package/src/__tests__/configuration.test.ts +1514 -367
  15. package/src/__tests__/dev.test.tsx +870 -84
  16. package/src/__tests__/guess-worker-format.test.ts +37 -18
  17. package/src/__tests__/helpers/mock-account-id.ts +22 -4
  18. package/src/__tests__/helpers/mock-cfetch.ts +8 -4
  19. package/src/__tests__/helpers/mock-console.ts +35 -10
  20. package/src/__tests__/helpers/mock-dialogs.ts +26 -1
  21. package/src/__tests__/helpers/mock-http-server.ts +46 -0
  22. package/src/__tests__/helpers/mock-istty.ts +27 -0
  23. package/src/__tests__/helpers/mock-kv.ts +9 -16
  24. package/src/__tests__/helpers/mock-oauth-flow.ts +255 -0
  25. package/src/__tests__/helpers/mock-stdin.ts +103 -0
  26. package/src/__tests__/helpers/run-in-tmp.ts +10 -0
  27. package/src/__tests__/helpers/write-worker-source.ts +31 -0
  28. package/src/__tests__/https-options.test.ts +130 -0
  29. package/src/__tests__/index.test.ts +137 -747
  30. package/src/__tests__/init.test.ts +1557 -0
  31. package/src/__tests__/jest.setup.ts +28 -8
  32. package/src/__tests__/kv.test.ts +598 -258
  33. package/src/__tests__/logger.test.ts +115 -0
  34. package/src/__tests__/pages.test.ts +657 -0
  35. package/src/__tests__/parse.test.ts +8 -0
  36. package/src/__tests__/publish.test.ts +4003 -941
  37. package/src/__tests__/r2.test.ts +69 -34
  38. package/src/__tests__/route.test.ts +45 -0
  39. package/src/__tests__/secret.test.ts +228 -73
  40. package/src/__tests__/tail.test.ts +146 -20
  41. package/src/__tests__/user.test.ts +131 -0
  42. package/src/__tests__/whoami.test.tsx +26 -7
  43. package/src/abort.d.ts +3 -0
  44. package/src/bundle.ts +74 -7
  45. package/src/cfetch/index.ts +21 -4
  46. package/src/cfetch/internal.ts +20 -14
  47. package/src/cli.ts +5 -11
  48. package/src/config/README.md +7 -7
  49. package/src/config/config.ts +69 -100
  50. package/src/config/environment.ts +119 -4
  51. package/src/config/index.ts +177 -4
  52. package/src/config/validation-helpers.ts +228 -23
  53. package/src/config/validation.ts +687 -174
  54. package/src/config-cache.ts +45 -0
  55. package/src/{api/preview.ts → create-worker-preview.ts} +74 -36
  56. package/src/{api/form_data.ts → create-worker-upload-form.ts} +55 -18
  57. package/src/dev/dev-vars.ts +36 -0
  58. package/src/dev/dev.tsx +422 -0
  59. package/src/dev/local.tsx +318 -0
  60. package/src/dev/remote.tsx +227 -0
  61. package/src/dev/use-esbuild.ts +118 -0
  62. package/src/dialogs.tsx +16 -6
  63. package/src/durable.ts +102 -0
  64. package/src/entry.ts +279 -14
  65. package/src/environment-variables.ts +3 -1
  66. package/src/errors.ts +11 -0
  67. package/src/https-options.ts +123 -0
  68. package/src/index.tsx +1268 -806
  69. package/src/inspect.ts +64 -11
  70. package/src/intl-polyfill.d.ts +139 -0
  71. package/src/{kv.tsx → kv.ts} +195 -62
  72. package/src/logger.ts +66 -0
  73. package/src/miniflare-cli/README.md +30 -0
  74. package/src/miniflare-cli/enum-keys.ts +17 -0
  75. package/src/miniflare-cli/index.ts +41 -0
  76. package/src/miniflare-cli/request-context.ts +40 -0
  77. package/src/module-collection.ts +94 -6
  78. package/src/open-in-browser.ts +9 -3
  79. package/src/package-manager.ts +9 -8
  80. package/src/pages.tsx +1057 -75
  81. package/src/parse.ts +24 -5
  82. package/src/proxy.ts +143 -54
  83. package/src/publish.ts +444 -229
  84. package/src/selfsigned.d.ts +29 -0
  85. package/src/sites.tsx +98 -44
  86. package/src/tail/index.ts +2 -2
  87. package/src/tail/printing.ts +13 -8
  88. package/src/update-check.ts +19 -0
  89. package/src/user.tsx +263 -109
  90. package/src/whoami.tsx +2 -1
  91. package/src/{api/worker.ts → worker.ts} +24 -30
  92. package/templates/gitignore +171 -0
  93. package/templates/new-worker.ts +16 -1
  94. package/templates/static-asset-facade.js +1 -1
  95. package/wrangler-dist/cli.js +55345 -69246
  96. package/src/__tests__/helpers/mock-user.ts +0 -27
  97. package/src/__tests__/logout.test.ts +0 -50
  98. package/src/__tests__/sentry.test.ts +0 -146
  99. package/src/dev.tsx +0 -961
  100. package/src/guess-worker-format.ts +0 -68
  101. package/src/reporting.ts +0 -115
  102. package/wrangler-dist/cli.js.map +0 -7
@@ -1,68 +0,0 @@
1
- import assert from "node:assert";
2
- import { build } from "esbuild";
3
- import type { CfScriptFormat } from "./api/worker";
4
- import type { Entry } from "./entry";
5
- import type { Metafile } from "esbuild";
6
-
7
- /**
8
- * A function to "guess" the type of worker.
9
- * We do this by running a lightweight build of the actual script,
10
- * and looking at the metafile generated by esbuild. If it has a default
11
- * export (or really, any exports), that means it's a "modules" worker.
12
- * Else, it's a "service-worker" worker. This seems hacky, but works remarkably
13
- * well in practice.
14
- */
15
- export default async function guessWorkerFormat(
16
- entry: Entry,
17
- hint: CfScriptFormat | undefined
18
- ): Promise<CfScriptFormat> {
19
- const result = await build({
20
- entryPoints: [entry.file],
21
- absWorkingDir: entry.directory,
22
- metafile: true,
23
- bundle: false,
24
- format: "esm",
25
- write: false,
26
- });
27
- // result.metafile is defined because of the `metafile: true` option above.
28
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
29
- const metafile = result.metafile!;
30
- const entryPoints = Object.entries(metafile.outputs).filter(
31
- ([_path, output]) => output.entryPoint !== undefined
32
- );
33
- assert(
34
- entryPoints.length > 0,
35
- `Cannot find entry-point "${entry.file}" in generated bundle.` +
36
- listEntryPoints(entryPoints)
37
- );
38
- assert(
39
- entryPoints.length < 2,
40
- "More than one entry-point found for generated bundle." +
41
- listEntryPoints(entryPoints)
42
- );
43
- const guessedWorkerFormat =
44
- entryPoints[0][1].exports.length > 0 ? "modules" : "service-worker";
45
-
46
- if (hint) {
47
- if (hint !== guessedWorkerFormat) {
48
- if (hint === "service-worker") {
49
- throw new Error(
50
- "You configured this worker to be a 'service-worker', but the file you are trying to build appears to have ES module exports. Please pass `--format modules`, or simply remove the configuration."
51
- );
52
- } else {
53
- throw new Error(
54
- "You configured this worker to be 'modules', but the file you are trying to build doesn't export a handler. Please pass `--format service-worker`, or simply remove the configuration."
55
- );
56
- }
57
- }
58
- }
59
- return guessedWorkerFormat;
60
- }
61
-
62
- function listEntryPoints(
63
- outputs: [string, ValueOf<Metafile["outputs"]>][]
64
- ): string {
65
- return outputs.map(([_input, output]) => output.entryPoint).join("\n");
66
- }
67
-
68
- type ValueOf<T> = T[keyof T];
package/src/reporting.ts DELETED
@@ -1,115 +0,0 @@
1
- import { appendFile, readFile } from "fs/promises";
2
- import * as fs from "node:fs";
3
- import os from "node:os";
4
- import path from "path/posix";
5
- import TOML from "@iarna/toml";
6
- import { RewriteFrames } from "@sentry/integrations";
7
- import {
8
- captureException,
9
- getCurrentHub,
10
- startTransaction,
11
- init,
12
- Integrations,
13
- setContext,
14
- } from "@sentry/node";
15
- import { execaSync } from "execa";
16
- import prompts from "prompts";
17
- import * as pkj from "../package.json";
18
-
19
- export function initReporting() {
20
- init({
21
- release: `${pkj.name}@${pkj.version}`,
22
- initialScope: {
23
- tags: { [pkj.name]: pkj.version },
24
- },
25
- dsn: "https://5089b76bf8a64a9c949bf5c2b5e8003c@o51786.ingest.sentry.io/6190959",
26
- tracesSampleRate: 1.0,
27
- integrations: [
28
- new RewriteFrames({
29
- root: "",
30
- prefix: "/",
31
- }),
32
- new Integrations.Http({ tracing: true }),
33
- ],
34
- });
35
-
36
- setContext("System Information", {
37
- OS: process.platform,
38
- node: process.version,
39
- npm: execaSync("npm", ["--version"]).stdout,
40
- wrangler: pkj.version,
41
- });
42
- }
43
-
44
- async function appendReportingDecision(userInput: "true" | "false") {
45
- const homePath = path.join(os.homedir(), ".wrangler/config/");
46
- fs.mkdirSync(homePath, { recursive: true });
47
- await appendFile(
48
- path.join(homePath, "reporting.toml"),
49
- `error_tracking_opt = ${userInput} # Sentry \nerror_tracking_opt_date = ${new Date().toISOString()} # Sentry Date Decision \n`,
50
- { encoding: "utf-8" }
51
- );
52
- }
53
-
54
- function exceptionTransaction(error: Error, origin = "") {
55
- const transaction = startTransaction({
56
- op: origin,
57
- name: error.name,
58
- });
59
- captureException(error);
60
- transaction.finish();
61
- }
62
-
63
- export async function reportError(err: Error, origin = "") {
64
- if (!process.stdout.isTTY) return await appendReportingDecision("false");
65
-
66
- const errorTrackingOpt = await reportingPermission();
67
-
68
- if (errorTrackingOpt === undefined) {
69
- const userInput = await prompts.prompt({
70
- type: "select",
71
- name: "sentryDecision",
72
- message: "Would you like to submit a report when an error occurs?",
73
- choices: [
74
- { title: "Always", value: true },
75
- { title: "Yes", value: "once" },
76
- { title: "No", value: false },
77
- ],
78
- initial: 2,
79
- });
80
-
81
- if (userInput.sentryDecision === "once") {
82
- exceptionTransaction(err, origin);
83
- return;
84
- }
85
-
86
- userInput.sentryDecision
87
- ? await appendReportingDecision("true")
88
- : await appendReportingDecision("false");
89
- }
90
-
91
- if (!errorTrackingOpt) {
92
- const sentryClient = getCurrentHub().getClient();
93
- if (sentryClient !== undefined) sentryClient.getOptions().enabled = false;
94
- }
95
-
96
- exceptionTransaction(err, origin);
97
- }
98
-
99
- async function reportingPermission() {
100
- if (
101
- !fs.existsSync(path.join(os.homedir(), ".wrangler/config/reporting.toml"))
102
- )
103
- return undefined;
104
-
105
- const reportingTOML = TOML.parse(
106
- await readFile(path.join(os.homedir(), ".wrangler/config/reporting.toml"), {
107
- encoding: "utf-8",
108
- })
109
- );
110
- const { error_tracking_opt } = reportingTOML as {
111
- error_tracking_opt: string | undefined;
112
- };
113
-
114
- return error_tracking_opt;
115
- }