wrangler 2.4.0 → 2.4.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wrangler",
3
- "version": "2.4.0",
3
+ "version": "2.4.1",
4
4
  "description": "Command-line interface for all things Cloudflare Workers",
5
5
  "keywords": [
6
6
  "wrangler",
@@ -119,7 +119,7 @@
119
119
  "@databases/sql": "^3.2.0",
120
120
  "@iarna/toml": "^3.0.0",
121
121
  "@microsoft/api-extractor": "^7.28.3",
122
- "@miniflare/tre": "^3.0.0-next.6",
122
+ "@miniflare/tre": "^3.0.0-next.7",
123
123
  "@types/better-sqlite3": "^7.6.0",
124
124
  "@types/busboy": "^1.5.0",
125
125
  "@types/command-exists": "^1.2.0",
@@ -1208,6 +1208,7 @@ describe("wrangler dev", () => {
1208
1208
  --node-compat Enable node.js compatibility [boolean]
1209
1209
  --persist Enable persistence for local mode, using default path: .wrangler/state [boolean]
1210
1210
  --persist-to Specify directory to use for local persistence (implies --persist) [string]
1211
+ --live-reload Auto reload HTML pages when change is detected in local mode [boolean]
1211
1212
  --test-scheduled Test scheduled events by visiting /__scheduled in browser [boolean] [default: false]
1212
1213
  --log-level Specify logging level [choices: \\"debug\\", \\"info\\", \\"log\\", \\"warn\\", \\"error\\", \\"none\\"] [default: \\"log\\"]",
1213
1214
  "warn": "",
@@ -364,7 +364,7 @@ describe("metrics", () => {
364
364
 
365
365
  expect(std.out).toMatchInlineSnapshot(`
366
366
  "Usage metrics tracking has changed since you last granted permission.
367
- Your choice has been saved in the following file: home/.wrangler/config/metrics.json.
367
+ Your choice has been saved in the following file: test-xdg-config/metrics.json.
368
368
 
369
369
  You can override the user level setting for a project in \`wrangler.toml\`:
370
370
 
package/src/bundle.ts CHANGED
@@ -97,7 +97,6 @@ export async function bundleWorker(
97
97
  targetConsumer: "dev" | "publish";
98
98
  local: boolean;
99
99
  testScheduled?: boolean;
100
- experimentalLocalStubCache?: boolean;
101
100
  inject?: string[];
102
101
  loader?: Record<string, string>;
103
102
  sourcemap?: esbuild.CommonOptions["sourcemap"];
@@ -125,7 +124,6 @@ export async function bundleWorker(
125
124
  firstPartyWorkerDevFacade,
126
125
  targetConsumer,
127
126
  testScheduled,
128
- experimentalLocalStubCache,
129
127
  inject: injectOption,
130
128
  loader,
131
129
  sourcemap,
@@ -277,11 +275,6 @@ export async function bundleWorker(
277
275
 
278
276
  const inject: string[] = injectOption ?? [];
279
277
  if (checkFetch) inject.push(checkedFetchFileToInject);
280
- if (experimentalLocalStubCache) {
281
- inject.push(
282
- path.resolve(getBasePath(), "templates/experimental-local-cache-stubs.js")
283
- );
284
- }
285
278
 
286
279
  const buildOptions: esbuild.BuildOptions & { metafile: true } = {
287
280
  entryPoints: [inputEntry.file],
package/src/dev/dev.tsx CHANGED
@@ -288,7 +288,6 @@ function DevSession(props: DevSessionProps) {
288
288
  // Enable the bundling to know whether we are using dev or publish
289
289
  targetConsumer: "dev",
290
290
  testScheduled: props.testScheduled ?? false,
291
- experimentalLocalStubCache: props.local && props.experimentalLocal,
292
291
  });
293
292
 
294
293
  // TODO(queues) support remote wrangler dev
package/src/dev/local.tsx CHANGED
@@ -20,6 +20,7 @@ import { waitForPortToBeAvailable } from "../proxy";
20
20
  import { requireAuth } from "../user";
21
21
  import type { Config } from "../config";
22
22
  import type { WorkerRegistry } from "../dev-registry";
23
+ import type { LoggerLevel } from "../logger";
23
24
  import type { EnablePagesAssetsServiceBindingOptions } from "../miniflare-cli";
24
25
  import type { AssetPaths } from "../sites";
25
26
  import type {
@@ -39,6 +40,7 @@ import type { EsbuildBundle } from "./use-esbuild";
39
40
  import type {
40
41
  Miniflare as Miniflare3Type,
41
42
  MiniflareOptions as Miniflare3Options,
43
+ Log as Miniflare3LogType,
42
44
  CloudflareFetch,
43
45
  } from "@miniflare/tre";
44
46
  import type { MiniflareOptions } from "miniflare";
@@ -228,10 +230,12 @@ function useLocalWorker({
228
230
  });
229
231
 
230
232
  if (experimentalLocal) {
231
- const mf3Options = await transformLocalOptions({
233
+ const log = await buildMiniflare3Logger(logPrefix);
234
+ const mf3Options = await transformMf2OptionsToMf3Options({
232
235
  miniflare2Options: options,
233
236
  format,
234
237
  bundle,
238
+ log,
235
239
  kvNamespaces: bindings?.kv_namespaces,
236
240
  r2Buckets: bindings?.r2_buckets,
237
241
  authenticatedAccountId: accountId,
@@ -243,7 +247,7 @@ function useLocalWorker({
243
247
 
244
248
  if (current === undefined) {
245
249
  // If we don't have an active Miniflare instance, create a new one
246
- const Miniflare = await getMiniflare3Constructor();
250
+ const { Miniflare } = await getMiniflare3();
247
251
  if (abortController.signal.aborted) return;
248
252
  const mf = new Miniflare(mf3Options);
249
253
  experimentalLocalRef.current = mf;
@@ -750,6 +754,9 @@ export interface SetupMiniflare3Options {
750
754
  format: CfScriptFormat;
751
755
  bundle: EsbuildBundle;
752
756
 
757
+ // Miniflare's logger
758
+ log: Miniflare3LogType;
759
+
753
760
  // Miniflare 3 accepts namespace/bucket names in addition to binding names.
754
761
  // This means multiple workers persisting to the same location can have
755
762
  // different binding names for the same namespace/bucket. Therefore, we need
@@ -763,13 +770,30 @@ export interface SetupMiniflare3Options {
763
770
  authenticatedAccountId: string | true | undefined;
764
771
  // Whether to read/write from/to real KV namespaces
765
772
  kvRemote: boolean | undefined;
773
+
774
+ // Port to start DevTools inspector server on
766
775
  inspectorPort: number;
767
776
  }
768
777
 
769
- export async function transformLocalOptions({
778
+ export async function buildMiniflare3Logger(
779
+ logPrefix?: string
780
+ ): Promise<Miniflare3LogType> {
781
+ const { Log, NoOpLog, LogLevel } = await getMiniflare3();
782
+
783
+ let level = logger.loggerLevel.toUpperCase() as Uppercase<LoggerLevel>;
784
+ if (level === "LOG") level = "INFO";
785
+ const logLevel = LogLevel[level];
786
+
787
+ return logLevel === LogLevel.NONE
788
+ ? new NoOpLog()
789
+ : new Log(logLevel, { prefix: logPrefix });
790
+ }
791
+
792
+ export async function transformMf2OptionsToMf3Options({
770
793
  miniflare2Options,
771
794
  format,
772
795
  bundle,
796
+ log,
773
797
  kvNamespaces,
774
798
  r2Buckets,
775
799
  authenticatedAccountId,
@@ -802,6 +826,7 @@ export async function transformLocalOptions({
802
826
  inspectorPort,
803
827
  verbose: true,
804
828
  cloudflareFetch,
829
+ log,
805
830
  };
806
831
 
807
832
  if (format === "modules") {
@@ -850,13 +875,10 @@ export async function transformLocalOptions({
850
875
 
851
876
  // Caching of the `npx-import`ed `@miniflare/tre` package
852
877
  // eslint-disable-next-line @typescript-eslint/consistent-type-imports
853
- let Miniflare: typeof import("@miniflare/tre").Miniflare;
854
- export async function getMiniflare3Constructor(): Promise<typeof Miniflare> {
855
- if (Miniflare === undefined) {
856
- ({ Miniflare } = await npxImport<
857
- // eslint-disable-next-line @typescript-eslint/consistent-type-imports
858
- typeof import("@miniflare/tre")
859
- >("@miniflare/tre@3.0.0-next.6"));
860
- }
861
- return Miniflare;
878
+ let miniflare3Module: typeof import("@miniflare/tre");
879
+ export async function getMiniflare3(): Promise<
880
+ // eslint-disable-next-line @typescript-eslint/consistent-type-imports
881
+ typeof import("@miniflare/tre")
882
+ > {
883
+ return (miniflare3Module ??= await npxImport("@miniflare/tre@3.0.0-next.7"));
862
884
  }
@@ -17,10 +17,11 @@ import { logger } from "../logger";
17
17
  import { waitForPortToBeAvailable } from "../proxy";
18
18
  import {
19
19
  setupBindings,
20
- getMiniflare3Constructor,
20
+ getMiniflare3,
21
+ buildMiniflare3Logger,
21
22
  setupMiniflareOptions,
22
23
  setupNodeOptions,
23
- transformLocalOptions,
24
+ transformMf2OptionsToMf3Options,
24
25
  } from "./local";
25
26
  import { startRemoteServer } from "./remote";
26
27
  import { validateDevProps } from "./validate-dev-props";
@@ -98,7 +99,6 @@ export async function startDevServer(
98
99
  services: props.bindings.services,
99
100
  firstPartyWorkerDevFacade: props.firstPartyWorker,
100
101
  testScheduled: props.testScheduled,
101
- experimentalLocalStubCache: props.experimentalLocal,
102
102
  });
103
103
 
104
104
  if (props.local) {
@@ -206,7 +206,6 @@ async function runEsbuild({
206
206
  services,
207
207
  firstPartyWorkerDevFacade,
208
208
  testScheduled,
209
- experimentalLocalStubCache,
210
209
  }: {
211
210
  entry: Entry;
212
211
  destination: string | undefined;
@@ -225,7 +224,6 @@ async function runEsbuild({
225
224
  workerDefinitions: WorkerRegistry;
226
225
  firstPartyWorkerDevFacade: boolean | undefined;
227
226
  testScheduled?: boolean;
228
- experimentalLocalStubCache: boolean | undefined;
229
227
  }): Promise<EsbuildBundle | undefined> {
230
228
  if (!destination) return;
231
229
 
@@ -266,7 +264,6 @@ async function runEsbuild({
266
264
  targetConsumer: "dev", // We are starting a dev server
267
265
  local: true,
268
266
  testScheduled,
269
- experimentalLocalStubCache,
270
267
  });
271
268
 
272
269
  return {
@@ -400,17 +397,19 @@ export async function startLocalServer({
400
397
  });
401
398
 
402
399
  if (experimentalLocal) {
403
- const mf3Options = await transformLocalOptions({
400
+ const log = await buildMiniflare3Logger(logPrefix);
401
+ const mf3Options = await transformMf2OptionsToMf3Options({
404
402
  miniflare2Options: options,
405
403
  format,
406
404
  bundle,
405
+ log,
407
406
  kvNamespaces: bindings?.kv_namespaces,
408
407
  r2Buckets: bindings?.r2_buckets,
409
408
  authenticatedAccountId: accountId,
410
409
  kvRemote: experimentalLocalRemoteKv,
411
410
  inspectorPort,
412
411
  });
413
- const Miniflare = await getMiniflare3Constructor();
412
+ const { Miniflare } = await getMiniflare3();
414
413
  const mf = new Miniflare(mf3Options);
415
414
  const runtimeURL = await mf.ready;
416
415
  experimentalLocalRef = mf;
@@ -41,7 +41,6 @@ export function useEsbuild({
41
41
  local,
42
42
  targetConsumer,
43
43
  testScheduled,
44
- experimentalLocalStubCache,
45
44
  }: {
46
45
  entry: Entry;
47
46
  destination: string | undefined;
@@ -63,7 +62,6 @@ export function useEsbuild({
63
62
  local: boolean;
64
63
  targetConsumer: "dev" | "publish";
65
64
  testScheduled: boolean;
66
- experimentalLocalStubCache: boolean | undefined;
67
65
  }): EsbuildBundle | undefined {
68
66
  const [bundle, setBundle] = useState<EsbuildBundle>();
69
67
  const { exit } = useApp();
@@ -136,7 +134,6 @@ export function useEsbuild({
136
134
  local,
137
135
  targetConsumer,
138
136
  testScheduled,
139
- experimentalLocalStubCache,
140
137
  });
141
138
 
142
139
  // Capture the `stop()` method to use as the `useEffect()` destructor.
@@ -198,7 +195,6 @@ export function useEsbuild({
198
195
  local,
199
196
  targetConsumer,
200
197
  testScheduled,
201
- experimentalLocalStubCache,
202
198
  ]);
203
199
  return bundle;
204
200
  }
package/src/dev.tsx CHANGED
@@ -1,4 +1,5 @@
1
1
  import path from "node:path";
2
+ import chalk from "chalk";
2
3
  import { watch } from "chokidar";
3
4
  import getPort from "get-port";
4
5
  import { render } from "ink";
@@ -288,11 +289,20 @@ export function devOptions(yargs: Argv<CommonYargsOptions>): Argv<DevArgs> {
288
289
  requiresArg: true,
289
290
  })
290
291
  .option("live-reload", {
291
- // TODO: Add back in once we have remote `--live-reload`
292
- hidden: true,
293
- // describe: "Auto reload HTML pages when change is detected",
292
+ describe:
293
+ "Auto reload HTML pages when change is detected in local mode",
294
294
  type: "boolean",
295
295
  })
296
+ .check((argv) => {
297
+ const local = argv["local"] || argv["experimental-local"];
298
+ if (argv["live-reload"] && !local) {
299
+ throw new Error(
300
+ "--live-reload is only supported in local mode. " +
301
+ "Please enable either --local or --experimental-local."
302
+ );
303
+ }
304
+ return true;
305
+ })
296
306
  .option("inspect", {
297
307
  describe: "Enable dev tools",
298
308
  type: "boolean",
@@ -369,6 +379,16 @@ export async function startDev(args: StartDevOptions) {
369
379
  }
370
380
  await printWranglerBanner();
371
381
 
382
+ if (args.local && process.platform !== "win32") {
383
+ logger.info(
384
+ chalk.magenta(
385
+ `Want to try out the next version of local mode using the open-source Workers runtime?\nSwitch out --local for ${chalk.bold(
386
+ "--experimental-local"
387
+ )} and let us know what you think at https://discord.gg/cloudflaredev !`
388
+ )
389
+ );
390
+ }
391
+
372
392
  const configPath =
373
393
  (args.config as ConfigPath) ||
374
394
  ((args.script &&
@@ -1,11 +1,11 @@
1
1
  import { randomUUID } from "node:crypto";
2
2
  import { readFileSync, mkdirSync, writeFileSync } from "node:fs";
3
- import os from "node:os";
4
3
  import path from "node:path";
5
4
  import { fetchResult } from "../cfetch";
6
5
  import { getConfigCache, saveToConfigCache } from "../config-cache";
7
6
  import { confirm } from "../dialogs";
8
7
  import { getEnvironmentVariableFactory } from "../environment-variables";
8
+ import { getGlobalWranglerConfigPath } from "../global-wrangler-config-path";
9
9
  import { CI } from "../is-ci";
10
10
  import isInteractive from "../is-interactive";
11
11
  import { logger } from "../logger";
@@ -167,7 +167,7 @@ export function readMetricsConfig(): MetricsConfigFile {
167
167
  * Get the path to the metrics config file.
168
168
  */
169
169
  function getMetricsConfigPath(): string {
170
- return path.resolve(os.homedir(), ".wrangler/config/metrics.json");
170
+ return path.resolve(getGlobalWranglerConfigPath(), "metrics.json");
171
171
  }
172
172
 
173
173
  /**
@@ -487,7 +487,6 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
487
487
  // This could potentially cause issues as we no longer have identical behaviour between dev and publish?
488
488
  targetConsumer: "publish",
489
489
  local: false,
490
- experimentalLocalStubCache: false,
491
490
  }
492
491
  );
493
492