wrangler 2.1.4 → 2.1.6

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 (46) hide show
  1. package/miniflare-dist/index.mjs +4 -1
  2. package/package.json +1 -1
  3. package/src/__tests__/api-dev.test.ts +3 -3
  4. package/src/__tests__/api-devregistry.test.js +56 -0
  5. package/src/__tests__/configuration.test.ts +3 -0
  6. package/src/__tests__/dev.test.tsx +39 -1
  7. package/src/__tests__/helpers/worker-scripts/child-wrangler.toml +1 -0
  8. package/src/__tests__/helpers/{hello-world-worker.js → worker-scripts/hello-world-worker.js} +0 -0
  9. package/src/__tests__/helpers/worker-scripts/hello-world-wrangler.toml +1 -0
  10. package/src/__tests__/helpers/worker-scripts/parent-worker.js +8 -0
  11. package/src/__tests__/helpers/worker-scripts/parent-wrangler.toml +5 -0
  12. package/src/__tests__/init.test.ts +72 -0
  13. package/src/__tests__/middleware.scheduled.test.ts +135 -0
  14. package/src/__tests__/middleware.test.ts +703 -745
  15. package/src/__tests__/pages.test.ts +35 -40
  16. package/src/__tests__/publish.test.ts +57 -1
  17. package/src/api/dev.ts +2 -0
  18. package/src/bundle.ts +14 -16
  19. package/src/config/config.ts +12 -0
  20. package/src/config/validation.ts +9 -0
  21. package/src/create-worker-upload-form.ts +3 -2
  22. package/src/dev/dev.tsx +12 -21
  23. package/src/dev/local.tsx +1 -0
  24. package/src/dev/remote.tsx +38 -50
  25. package/src/dev/start-server.ts +43 -8
  26. package/src/dev/use-esbuild.ts +4 -0
  27. package/src/dev-registry.tsx +30 -0
  28. package/src/dev.tsx +21 -3
  29. package/src/index.tsx +8 -1
  30. package/src/init.ts +3 -1
  31. package/src/inspect.ts +26 -26
  32. package/src/miniflare-cli/assets.ts +8 -1
  33. package/src/pages/constants.ts +2 -1
  34. package/src/pages/dev.tsx +133 -10
  35. package/src/pages/errors.ts +48 -4
  36. package/src/pages/functions/routes-transformation.ts +1 -14
  37. package/src/pages/functions/routes-validation.test.ts +403 -0
  38. package/src/pages/functions/routes-validation.ts +202 -0
  39. package/src/pages/functions.tsx +4 -18
  40. package/src/pages/publish.tsx +6 -22
  41. package/src/publish.ts +3 -1
  42. package/src/worker.ts +1 -1
  43. package/templates/middleware/middleware-scheduled.ts +2 -1
  44. package/templates/pages-dev-pipeline.ts +35 -0
  45. package/wrangler-dist/cli.d.ts +2 -0
  46. package/wrangler-dist/cli.js +611 -353
@@ -2,11 +2,9 @@ import { existsSync, lstatSync, readFileSync, writeFileSync } from "node:fs";
2
2
  import path from "node:path";
3
3
  import { FatalError } from "../errors";
4
4
  import { logger } from "../logger";
5
- import { isInPagesCI, ROUTES_SPEC_VERSION } from "./constants";
6
- import {
7
- isRoutesJSONSpec,
8
- optimizeRoutesJSONSpec,
9
- } from "./functions/routes-transformation";
5
+ import { isInPagesCI } from "./constants";
6
+ import { optimizeRoutesJSONSpec } from "./functions/routes-transformation";
7
+ import { validateRoutes } from "./functions/routes-validation";
10
8
  import { pagesBetaWarning } from "./utils";
11
9
  import type { YargsOptionsToInterface } from "./types";
12
10
  import type { Argv } from "yargs";
@@ -68,19 +66,7 @@ export async function OptimizeRoutesHandler({
68
66
 
69
67
  const routes = JSON.parse(routesFileContents);
70
68
 
71
- if (!isRoutesJSONSpec(routes)) {
72
- throw new FatalError(
73
- `
74
- Invalid _routes.json file found at: ${routesPath}. Please make sure the JSON object has the following format:
75
- {
76
- version: ${ROUTES_SPEC_VERSION};
77
- include: string[];
78
- exclude: string[];
79
- }
80
- `,
81
- 1
82
- );
83
- }
69
+ validateRoutes(routes, routesPath);
84
70
 
85
71
  const optimizedRoutes = optimizeRoutesJSONSpec(routes);
86
72
  const optimizedRoutesContents = JSON.stringify(optimizedRoutes);
@@ -15,9 +15,9 @@ import { logger } from "../logger";
15
15
  import * as metrics from "../metrics";
16
16
  import { requireAuth } from "../user";
17
17
  import { buildFunctions } from "./build";
18
- import { PAGES_CONFIG_CACHE_FILENAME, ROUTES_SPEC_VERSION } from "./constants";
18
+ import { PAGES_CONFIG_CACHE_FILENAME } from "./constants";
19
19
  import { FunctionsNoRoutesError, getFunctionsNoRoutesWarning } from "./errors";
20
- import { isRoutesJSONSpec } from "./functions/routes-transformation";
20
+ import { validateRoutes } from "./functions/routes-validation";
21
21
  import { listProjects } from "./projects";
22
22
  import { upload } from "./upload";
23
23
  import { pagesBetaWarning } from "./utils";
@@ -343,7 +343,8 @@ export const Handler = async ({
343
343
  if (_routesCustom) {
344
344
  // user provided a custom _routes.json file
345
345
  try {
346
- validateRoutesFile(_routesCustom, join(directory, "_routes.json"));
346
+ const routesCustomJSON = JSON.parse(_routesCustom);
347
+ validateRoutes(routesCustomJSON, join(directory, "_routes.json"));
347
348
 
348
349
  formData.append(
349
350
  "_routes.json",
@@ -380,7 +381,8 @@ export const Handler = async ({
380
381
  if (_routesCustom) {
381
382
  // user provided a custom _routes.json file
382
383
  try {
383
- validateRoutesFile(_routesCustom, join(directory, "_routes.json"));
384
+ const routesCustomJSON = JSON.parse(_routesCustom);
385
+ validateRoutes(routesCustomJSON, join(directory, "_routes.json"));
384
386
 
385
387
  formData.append(
386
388
  "_routes.json",
@@ -415,21 +417,3 @@ export const Handler = async ({
415
417
  );
416
418
  await metrics.sendMetricsEvent("create pages deployment");
417
419
  };
418
-
419
- function validateRoutesFile(_routes: string, routesPath: string) {
420
- const routes = JSON.parse(_routes);
421
-
422
- if (!isRoutesJSONSpec(routes)) {
423
- throw new FatalError(
424
- `Invalid _routes.json file found at: ${routesPath}. Please make sure the JSON object has the following format:
425
- {
426
- version: ${ROUTES_SPEC_VERSION};
427
- include: string[];
428
- exclude: string[];
429
- }
430
- and that at least one include rule is provided.
431
- `,
432
- 1
433
- );
434
- }
435
- }
package/src/publish.ts CHANGED
@@ -50,6 +50,7 @@ type Props = {
50
50
  outDir: string | undefined;
51
51
  dryRun: boolean | undefined;
52
52
  noBundle: boolean | undefined;
53
+ keepVars: boolean | undefined;
53
54
  };
54
55
 
55
56
  type RouteObject = ZoneIdRoute | ZoneNameRoute | CustomDomainRoute;
@@ -288,6 +289,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
288
289
 
289
290
  const jsxFactory = props.jsxFactory || config.jsx_factory;
290
291
  const jsxFragment = props.jsxFragment || config.jsx_fragment;
292
+ const keepVars = props.keepVars ?? config.keep_vars;
291
293
 
292
294
  const minify = props.minify ?? config.minify;
293
295
 
@@ -502,7 +504,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
502
504
  compatibility_flags:
503
505
  props.compatibilityFlags ?? config.compatibility_flags,
504
506
  usage_model: config.usage_model,
505
- keep_bindings: true,
507
+ keepVars,
506
508
  };
507
509
 
508
510
  // As this is not deterministic for testing, we detect if in a jest environment and run asynchronously
package/src/worker.ts CHANGED
@@ -191,7 +191,7 @@ export interface CfWorkerInit {
191
191
  compatibility_date: string | undefined;
192
192
  compatibility_flags: string[] | undefined;
193
193
  usage_model: "bundled" | "unbound" | undefined;
194
- keep_bindings: boolean | undefined;
194
+ keepVars: boolean | undefined;
195
195
  }
196
196
 
197
197
  export interface CfWorkerContext {
@@ -6,7 +6,8 @@ const scheduled: Middleware = async (request, env, _ctx, middlewareCtx) => {
6
6
  if (url.pathname === "/__scheduled") {
7
7
  const cron = url.searchParams.get("cron") ?? "";
8
8
  await middlewareCtx.dispatch("scheduled", { cron });
9
- return new Response("OK");
9
+
10
+ return new Response("Ran scheduled event");
10
11
  }
11
12
  return middlewareCtx.next(request, env);
12
13
  };
@@ -0,0 +1,35 @@
1
+ // @ts-ignore entry point will get replaced
2
+ import worker from "__ENTRY_POINT__";
3
+ // @ts-ignore entry point will get replaced
4
+ export * from "__ENTRY_POINT__";
5
+
6
+ const transformToRegex = (filter: string) => {
7
+ return filter.replace("*", ".*");
8
+ };
9
+
10
+ const routes = {
11
+ // @ts-ignore routes are injected
12
+ include: __ROUTES__.include.map(transformToRegex),
13
+ // @ts-ignore routes are injected
14
+ exclude: __ROUTES__.exclude.map(transformToRegex) || [],
15
+ };
16
+
17
+ export default {
18
+ fetch(request, env, context) {
19
+ const { pathname } = new URL(request.url);
20
+
21
+ for (const exclude of routes.exclude) {
22
+ if (pathname.match(exclude)) {
23
+ return env.ASSETS.fetch(request);
24
+ }
25
+ }
26
+
27
+ for (const include of routes.include) {
28
+ if (pathname.match(include)) {
29
+ return worker.fetch(request, env, context);
30
+ }
31
+ }
32
+
33
+ return env.ASSETS.fetch(request);
34
+ },
35
+ };
@@ -43,6 +43,7 @@ declare interface DevOptions {
43
43
  env?: string;
44
44
  ip?: string;
45
45
  port?: number;
46
+ noBundle?: boolean;
46
47
  inspectorPort?: number;
47
48
  localProtocol?: "http" | "https";
48
49
  assets?: string;
@@ -83,6 +84,7 @@ declare interface DevOptions {
83
84
  enablePagesAssetsServiceBinding?: EnablePagesAssetsServiceBindingOptions;
84
85
  _?: (string | number)[];
85
86
  $0?: string;
87
+ testScheduled?: boolean;
86
88
  }
87
89
 
88
90
  declare interface EnablePagesAssetsServiceBindingOptions {