wrangler 0.0.0-e95bea2 → 0.0.0-e95e5a0

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 (93) hide show
  1. package/README.md +25 -14
  2. package/bin/wrangler.js +13 -1
  3. package/miniflare-dist/index.mjs +4886 -0
  4. package/package.json +33 -25
  5. package/pages/functions/buildPlugin.ts +92 -0
  6. package/pages/functions/buildWorker.ts +80 -4
  7. package/pages/functions/filepath-routing.test.ts +136 -25
  8. package/pages/functions/filepath-routing.ts +14 -3
  9. package/pages/functions/routes.ts +6 -1
  10. package/pages/functions/template-plugin.ts +146 -0
  11. package/pages/functions/template-worker.ts +21 -8
  12. package/src/__tests__/config-cache.test.ts +36 -0
  13. package/src/__tests__/configuration.test.ts +1179 -271
  14. package/src/__tests__/dev.test.tsx +382 -25
  15. package/src/__tests__/guess-worker-format.test.ts +28 -1
  16. package/src/__tests__/helpers/mock-account-id.ts +4 -0
  17. package/src/__tests__/helpers/mock-cfetch.ts +5 -1
  18. package/src/__tests__/helpers/mock-console.ts +20 -3
  19. package/src/__tests__/helpers/mock-dialogs.ts +26 -1
  20. package/src/__tests__/helpers/mock-http-server.ts +46 -0
  21. package/src/__tests__/helpers/mock-istty.ts +27 -0
  22. package/src/__tests__/helpers/mock-kv.ts +9 -16
  23. package/src/__tests__/helpers/mock-oauth-flow.ts +255 -0
  24. package/src/__tests__/helpers/run-in-tmp.ts +10 -0
  25. package/src/__tests__/helpers/write-worker-source.ts +31 -0
  26. package/src/__tests__/https-options.test.ts +5 -2
  27. package/src/__tests__/index.test.ts +27 -769
  28. package/src/__tests__/init.test.ts +1516 -0
  29. package/src/__tests__/jest.setup.ts +4 -4
  30. package/src/__tests__/kv.test.ts +172 -126
  31. package/src/__tests__/logger.test.ts +115 -0
  32. package/src/__tests__/pages.test.ts +311 -26
  33. package/src/__tests__/publish.test.ts +2946 -524
  34. package/src/__tests__/r2.test.ts +26 -10
  35. package/src/__tests__/route.test.ts +4 -4
  36. package/src/__tests__/secret.test.ts +55 -34
  37. package/src/__tests__/tail.test.ts +146 -20
  38. package/src/__tests__/user.test.ts +131 -0
  39. package/src/__tests__/whoami.test.tsx +26 -7
  40. package/src/bundle.ts +30 -3
  41. package/src/cfetch/internal.ts +9 -7
  42. package/src/cli.ts +5 -11
  43. package/src/config/README.md +7 -7
  44. package/src/config/config.ts +33 -78
  45. package/src/config/environment.ts +93 -4
  46. package/src/config/index.ts +15 -4
  47. package/src/config/validation-helpers.ts +202 -15
  48. package/src/config/validation.ts +530 -133
  49. package/src/config-cache.ts +45 -0
  50. package/src/create-worker-preview.ts +22 -13
  51. package/src/create-worker-upload-form.ts +32 -9
  52. package/src/dev/dev-vars.ts +36 -0
  53. package/src/dev/dev.tsx +136 -75
  54. package/src/dev/local.tsx +196 -125
  55. package/src/dev/remote.tsx +25 -13
  56. package/src/dev/use-esbuild.ts +23 -5
  57. package/src/dialogs.tsx +16 -6
  58. package/src/entry.ts +119 -11
  59. package/src/environment-variables.ts +3 -1
  60. package/src/errors.ts +11 -0
  61. package/src/https-options.ts +3 -2
  62. package/src/index.tsx +739 -400
  63. package/src/inspect.ts +17 -11
  64. package/src/intl-polyfill.d.ts +139 -0
  65. package/src/{kv/index.tsx → kv.ts} +8 -28
  66. package/src/logger.ts +66 -0
  67. package/src/miniflare-cli/README.md +30 -0
  68. package/src/miniflare-cli/enum-keys.ts +17 -0
  69. package/src/miniflare-cli/index.ts +41 -0
  70. package/src/miniflare-cli/request-context.ts +40 -0
  71. package/src/module-collection.ts +63 -58
  72. package/src/open-in-browser.ts +5 -4
  73. package/src/package-manager.ts +9 -8
  74. package/src/pages.tsx +883 -62
  75. package/src/parse.ts +1 -1
  76. package/src/proxy.ts +32 -21
  77. package/src/publish.ts +276 -161
  78. package/src/sites.tsx +88 -33
  79. package/src/tail/index.ts +2 -2
  80. package/src/tail/printing.ts +13 -8
  81. package/src/update-check.ts +19 -0
  82. package/src/user.tsx +231 -103
  83. package/src/whoami.tsx +2 -1
  84. package/src/worker.ts +15 -6
  85. package/templates/gitignore +171 -0
  86. package/templates/static-asset-facade.js +1 -1
  87. package/wrangler-dist/cli.js +22087 -49340
  88. package/src/__tests__/dev2.test.tsx +0 -152
  89. package/src/__tests__/helpers/mock-user.ts +0 -27
  90. package/src/__tests__/logout.test.ts +0 -50
  91. package/src/__tests__/sentry.test.ts +0 -146
  92. package/src/reporting.ts +0 -131
  93. package/wrangler-dist/cli.js.map +0 -7
@@ -2,6 +2,7 @@ import crypto from "node:crypto";
2
2
  import { readFile } from "node:fs/promises";
3
3
  import path from "node:path";
4
4
  import globToRegExp from "glob-to-regexp";
5
+ import { logger } from "./logger";
5
6
  import type { Config, ConfigModuleRuleType } from "./config";
6
7
  import type { CfModule, CfModuleType, CfScriptFormat } from "./worker";
7
8
  import type esbuild from "esbuild";
@@ -58,7 +59,7 @@ export default function createModuleCollector(props: {
58
59
  if (rule.type in completedRuleLocations) {
59
60
  if (rules[completedRuleLocations[rule.type]].fallthrough !== false) {
60
61
  if (index < (props.rules || []).length) {
61
- console.warn(
62
+ logger.warn(
62
63
  `The module rule at position ${index} (${JSON.stringify(
63
64
  rule
64
65
  )}) has the same type as a previous rule (at position ${
@@ -68,7 +69,7 @@ export default function createModuleCollector(props: {
68
69
  )}). This rule will be ignored. To the previous rule, add \`fallthrough = true\` to allow this one to also be used, or \`fallthrough = false\` to silence this warning.`
69
70
  );
70
71
  } else {
71
- console.warn(
72
+ logger.warn(
72
73
  `The default module rule ${JSON.stringify(
73
74
  rule
74
75
  )} has the same type as a previous rule (at position ${
@@ -102,7 +103,7 @@ export default function createModuleCollector(props: {
102
103
  modules.splice(0);
103
104
  });
104
105
 
105
- // ~ start legacy module specifier support ~
106
+ // ~ start legacy module specifier support ~
106
107
 
107
108
  // This section detects usage of "legacy" 1.x style module specifiers
108
109
  // and modifies them so they "work" in wrangler v2, but with a warning
@@ -117,62 +118,67 @@ export default function createModuleCollector(props: {
117
118
  });
118
119
  });
119
120
 
120
- build.onResolve(
121
- {
122
- filter: new RegExp(
123
- [...props.wrangler1xlegacyModuleReferences.fileNames]
124
- .map((fileName) => `^${fileName}$`)
125
- .join("|")
126
- ),
127
- },
128
- async (args: esbuild.OnResolveArgs) => {
129
- if (
130
- args.kind !== "import-statement" &&
131
- args.kind !== "require-call"
132
- ) {
133
- return;
134
- }
135
- // In the future, this will simply throw an error
136
- console.warn(
137
- `Deprecation warning: detected a legacy module import in "./${path.relative(
138
- process.cwd(),
139
- args.importer
140
- )}". This will stop working in the future. Replace references to "${
121
+ if (props.wrangler1xlegacyModuleReferences.fileNames.size > 0) {
122
+ build.onResolve(
123
+ {
124
+ filter: new RegExp(
125
+ "^(" +
126
+ [...props.wrangler1xlegacyModuleReferences.fileNames].join(
127
+ "|"
128
+ ) +
129
+ ")$"
130
+ ),
131
+ },
132
+ async (args: esbuild.OnResolveArgs) => {
133
+ if (
134
+ args.kind !== "import-statement" &&
135
+ args.kind !== "require-call"
136
+ ) {
137
+ return;
138
+ }
139
+ // In the future, this will simply throw an error
140
+ logger.warn(
141
+ `Deprecation: detected a legacy module import in "./${path.relative(
142
+ process.cwd(),
143
+ args.importer
144
+ )}". This will stop working in the future. Replace references to "${
145
+ args.path
146
+ }" with "./${args.path}";`
147
+ );
148
+
149
+ // take the file and massage it to a
150
+ // transportable/manageable format
151
+ const filePath = path.join(
152
+ props.wrangler1xlegacyModuleReferences.rootDirectory,
141
153
  args.path
142
- }" with "./${args.path}";`
143
- );
154
+ );
155
+ const fileContent = await readFile(filePath);
156
+ const fileHash = crypto
157
+ .createHash("sha1")
158
+ .update(fileContent)
159
+ .digest("hex");
160
+ const fileName = `./${fileHash}-${path.basename(args.path)}`;
144
161
 
145
- // take the file and massage it to a
146
- // transportable/manageable format
147
- const filePath = path.join(
148
- props.wrangler1xlegacyModuleReferences.rootDirectory,
149
- args.path
150
- );
151
- const fileContent = await readFile(filePath);
152
- const fileHash = crypto
153
- .createHash("sha1")
154
- .update(fileContent)
155
- .digest("hex");
156
- const fileName = `./${fileHash}-${path.basename(args.path)}`;
157
-
158
- const { rule } =
159
- rulesMatchers.find(({ regex }) => regex.test(fileName)) || {};
160
- if (rule) {
161
- // add the module to the array
162
- modules.push({
163
- name: fileName,
164
- content: fileContent,
165
- type: RuleTypeToModuleType[rule.type],
166
- });
167
- return {
168
- path: fileName, // change the reference to the changed module
169
- external: props.format === "modules", // mark it as external in the bundle
170
- namespace: `wrangler-module-${rule.type}`, // just a tag, this isn't strictly necessary
171
- watchFiles: [filePath], // we also add the file to esbuild's watch list
172
- };
162
+ const { rule } =
163
+ rulesMatchers.find(({ regex }) => regex.test(fileName)) || {};
164
+ if (rule) {
165
+ // add the module to the array
166
+ modules.push({
167
+ name: fileName,
168
+ content: fileContent,
169
+ type: RuleTypeToModuleType[rule.type],
170
+ });
171
+ return {
172
+ path: fileName, // change the reference to the changed module
173
+ external: props.format === "modules", // mark it as external in the bundle
174
+ namespace: `wrangler-module-${rule.type}`, // just a tag, this isn't strictly necessary
175
+ watchFiles: [filePath], // we also add the file to esbuild's watch list
176
+ };
177
+ }
173
178
  }
174
- }
175
- );
179
+ );
180
+ }
181
+
176
182
  // ~ end legacy module specifier support ~
177
183
 
178
184
  rules?.forEach((rule) => {
@@ -216,10 +222,9 @@ export default function createModuleCollector(props: {
216
222
  return {
217
223
  // We replace the the module with an identifier
218
224
  // that we'll separately add to the form upload
219
- // as part of [wasm_modules]/[text_blobs]. This identifier has to be a valid
225
+ // as part of [wasm_modules]/[text_blobs]/[data_blobs]. This identifier has to be a valid
220
226
  // JS identifier, so we replace all non alphanumeric characters
221
227
  // with an underscore.
222
- // TODO: what of "Data"?
223
228
  contents: `export default ${args.path.replace(
224
229
  /[^a-zA-Z0-9_$]/g,
225
230
  "_"
@@ -1,13 +1,14 @@
1
1
  import open from "open";
2
+ import { logger } from "./logger";
2
3
 
3
4
  /**
4
5
  * An extremely simple wrapper around the open command.
5
6
  * Specifically, it adds an 'error' event handler so that when this function
6
- * is called in environments where we can't open the browser (e.g. github codespaces,
7
- * stackblitz, remote servers), it doesn't just crash the process.
7
+ * is called in environments where we can't open the browser (e.g. GitHub Codespaces,
8
+ * StackBlitz, remote servers), it doesn't just crash the process.
8
9
  *
9
10
  * @param url the URL to point the browser at
10
- * @param options open a chromium-based browser instead of the default
11
+ * @param options open a Chromium-based browser instead of the default
11
12
  */
12
13
  export default async function openInBrowser(
13
14
  url: string,
@@ -20,6 +21,6 @@ export default async function openInBrowser(
20
21
  : undefined;
21
22
  const childProcess = await open(url, options);
22
23
  childProcess.on("error", () => {
23
- console.warn(`Failed to open ${url} in a browser`);
24
+ logger.warn(`Failed to open ${url} in a browser.`);
24
25
  });
25
26
  }
@@ -1,6 +1,7 @@
1
1
  import { existsSync } from "node:fs";
2
2
  import { join } from "node:path";
3
3
  import { execa, execaCommandSync } from "execa";
4
+ import { logger } from "./logger";
4
5
 
5
6
  export interface PackageManager {
6
7
  cwd: string;
@@ -16,26 +17,26 @@ export async function getPackageManager(cwd: string): Promise<PackageManager> {
16
17
 
17
18
  if (hasNpmLock) {
18
19
  if (hasNpm) {
19
- console.log(
20
+ logger.log(
20
21
  "Using npm as package manager, as there is already a package-lock.json file."
21
22
  );
22
23
  return { ...NpmPackageManager, cwd };
23
24
  } else if (hasYarn) {
24
- console.log("Using yarn as package manager.");
25
- console.warn(
25
+ logger.log("Using yarn as package manager.");
26
+ logger.warn(
26
27
  "There is already a package-lock.json file but could not find npm on the PATH."
27
28
  );
28
29
  return { ...YarnPackageManager, cwd };
29
30
  }
30
31
  } else if (hasYarnLock) {
31
32
  if (hasYarn) {
32
- console.log(
33
+ logger.log(
33
34
  "Using yarn as package manager, as there is already a yarn.lock file."
34
35
  );
35
36
  return { ...YarnPackageManager, cwd };
36
37
  } else if (hasNpm) {
37
- console.log("Using npm as package manager.");
38
- console.warn(
38
+ logger.log("Using npm as package manager.");
39
+ logger.warn(
39
40
  "There is already a yarn.lock file but could not find yarn on the PATH."
40
41
  );
41
42
  return { ...NpmPackageManager, cwd };
@@ -43,10 +44,10 @@ export async function getPackageManager(cwd: string): Promise<PackageManager> {
43
44
  }
44
45
 
45
46
  if (hasNpm) {
46
- console.log("Using npm as package manager.");
47
+ logger.log("Using npm as package manager.");
47
48
  return { ...NpmPackageManager, cwd };
48
49
  } else if (hasYarn) {
49
- console.log("Using yarn as package manager.");
50
+ logger.log("Using yarn as package manager.");
50
51
  return { ...YarnPackageManager, cwd };
51
52
  } else {
52
53
  throw new Error(