@cloudflare/vite-plugin 1.13.13 → 1.13.15

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/dist/index.d.ts CHANGED
@@ -20,8 +20,6 @@ interface AuxiliaryWorkerConfig extends BaseWorkerConfig {
20
20
  interface Experimental {
21
21
  /** Experimental support for handling the _headers and _redirects files during Vite dev mode. */
22
22
  headersAndRedirectsDevModeSupport?: boolean;
23
- /** Experimental support for remote bindings (where bindings configured with `remote: true` access remote resources). */
24
- remoteBindings?: boolean;
25
23
  }
26
24
  interface PluginConfig extends EntryWorkerConfig {
27
25
  auxiliaryWorkers?: AuxiliaryWorkerConfig[];
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/plugin-config.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;;;AA0BU,KANE,YAAA,GAMgB,OAAQ,GAAA;EAI1B,IAAA,EAAA,MAAA;AAA8C,CAAA;AAWxD,UAnBU,gBAAA,CAmBoB;EAAA,eAAA,CAAA,EAAA;IACV,IAAA,CAAA,EAAA,MAAA;;;UAhBV,iBAAA,SAA0B,gBAeE,CAAA;EAAiB,UAAA,CAAA,EAAA,MAAA;;UAX7C,qBAAA,SAA8B;;AC6CxC;UDzCU,YAAA,CCyCgB;;mCAAwC,CAAA,EAAA,OAAA;EAAM;;;UDlCvD,YAAA,SAAqB;qBAClB;iBACJ;;iBAEA;;;;;AAzBhB;AAAsD;AAE5B;AAI0B;AAII;AAWxD;AAA8B,iBCkCd,UAAA,CDlCc,YAAA,CAAA,ECkCW,YDlCX,CAAA,ECkC+B,IAAA,CAAK,MDlCpC,EAAA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/plugin-config.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;;;AA0BU,KANE,YAAA,GAMgB,OAAQ,GAAA;EAI1B,IAAA,EAAA,MAAA;AAA8C,CAAA;AASxD,UAjBU,gBAAA,CAiBoB;EAAA,eAAA,CAAA,EAAA;IACV,IAAA,CAAA,EAAA,MAAA;;;UAdV,iBAAA,SAA0B,gBAaE,CAAA;EAAiB,UAAA,CAAA,EAAA,MAAA;;UAT7C,qBAAA,SAA8B;;AC+CxC;UD3CU,YAAA,CC2CgB;;mCAAwC,CAAA,EAAA,OAAA;;UDtCjD,YAAA,SAAqB;qBAClB;iBACJ;;iBAEA;;;;;AAvBhB;AAAsD;AAE5B;AAI0B;AAII;AASxD;AAA8B,iBCsCd,UAAA,CDtCc,YAAA,CAAA,ECsCW,YDtCX,CAAA,ECsC+B,IAAA,CAAK,MDtCpC,EAAA"}
package/dist/index.js CHANGED
@@ -754,6 +754,7 @@ async function constructBuildCommand(options, logger) {
754
754
  const platform = options.platform ?? "linux/amd64";
755
755
  const buildCmd = [
756
756
  "build",
757
+ "--load",
757
758
  "-t",
758
759
  options.tag,
759
760
  "--platform",
@@ -957,8 +958,8 @@ const runDockerCmdWithOutput = (dockerPath, args) => {
957
958
  throw new UserError(`Failed running docker command: ${error.message}. Command: ${dockerPath} ${args.join(" ")}`);
958
959
  }
959
960
  };
960
- /** throws when docker is not installed */
961
- const verifyDockerInstalled = async (dockerPath, isDev = true) => {
961
+ /** Checks whether docker is running on the system */
962
+ const isDockerRunning = async (dockerPath) => {
962
963
  try {
963
964
  await runDockerCmd(dockerPath, ["info"], [
964
965
  "inherit",
@@ -966,9 +967,14 @@ const verifyDockerInstalled = async (dockerPath, isDev = true) => {
966
967
  "pipe"
967
968
  ]);
968
969
  } catch {
969
- throw new UserError(`The Docker CLI could not be launched. Please ensure that the Docker CLI is installed and the daemon is running.
970
- Other container tooling that is compatible with the Docker CLI and engine may work, but is not yet guaranteed to do so. You can specify an executable with the environment variable WRANGLER_DOCKER_BIN and a socket with DOCKER_HOST.${isDev ? "\nTo suppress this error if you do not intend on triggering any container instances, set dev.enable_containers to false in your Wrangler config or passing in --enable-containers=false." : ""}`);
970
+ return false;
971
971
  }
972
+ return true;
973
+ };
974
+ /** throws when docker is not installed */
975
+ const verifyDockerInstalled = async (dockerPath, isDev = true) => {
976
+ if (!await isDockerRunning(dockerPath)) throw new UserError(`The Docker CLI could not be launched. Please ensure that the Docker CLI is installed and the daemon is running.
977
+ Other container tooling that is compatible with the Docker CLI and engine may work, but is not yet guaranteed to do so. You can specify an executable with the environment variable WRANGLER_DOCKER_BIN and a socket with DOCKER_HOST.${isDev ? "\nTo suppress this error if you do not intend on triggering any container instances, set dev.enable_containers to false in your Wrangler config or passing in --enable-containers=false." : ""}`);
972
978
  };
973
979
  function isDir(inputPath) {
974
980
  return statSync(inputPath).isDirectory();
@@ -6886,15 +6892,18 @@ function withTrailingSlash$1(path$3) {
6886
6892
  }
6887
6893
  function createRequestHandler(handler) {
6888
6894
  return async (req, res, next) => {
6895
+ let request$1;
6889
6896
  try {
6890
6897
  if (req.originalUrl) req.url = req.originalUrl;
6891
- let response = await handler(toMiniflareRequest(createRequest(req, res)), req);
6898
+ request$1 = createRequest(req, res);
6899
+ let response = await handler(toMiniflareRequest(request$1), req);
6892
6900
  if (req.httpVersionMajor === 2) {
6893
6901
  response = new Response$1(response.body, response);
6894
6902
  response.headers.delete("transfer-encoding");
6895
6903
  }
6896
6904
  await sendResponse(res, response);
6897
6905
  } catch (error) {
6906
+ if (request$1?.signal.aborted) return;
6898
6907
  next(error);
6899
6908
  }
6900
6909
  };
@@ -6909,7 +6918,8 @@ function toMiniflareRequest(request$1) {
6909
6918
  method: request$1.method,
6910
6919
  headers: [["accept-encoding", "identity"], ...request$1.headers],
6911
6920
  body: request$1.body,
6912
- duplex: "half"
6921
+ duplex: "half",
6922
+ signal: request$1.signal
6913
6923
  });
6914
6924
  }
6915
6925
 
@@ -8469,10 +8479,10 @@ async function getDevMiniflareOptions(config) {
8469
8479
  const workersFromConfig = resolvedPluginConfig.type === "workers" ? await Promise.all(Object.entries(resolvedPluginConfig.workers).map(async ([environmentName, workerConfig]) => {
8470
8480
  const bindings = unstable_convertConfigBindingsToStartWorkerBindings(workerConfig);
8471
8481
  const preExistingRemoteProxySession = workerConfig.configPath ? remoteProxySessionsDataMap.get(workerConfig.configPath) : void 0;
8472
- const remoteProxySessionData = resolvedPluginConfig.experimental.remoteBindings ?? true ? await maybeStartOrUpdateRemoteProxySession({
8482
+ const remoteProxySessionData = await maybeStartOrUpdateRemoteProxySession({
8473
8483
  name: workerConfig.name,
8474
8484
  bindings: bindings ?? {}
8475
- }, preExistingRemoteProxySession ?? null) : void 0;
8485
+ }, preExistingRemoteProxySession ?? null);
8476
8486
  if (workerConfig.configPath && remoteProxySessionData) remoteProxySessionsDataMap.set(workerConfig.configPath, remoteProxySessionData);
8477
8487
  let containerBuildId;
8478
8488
  if (workerConfig.containers?.length && workerConfig.dev.enable_containers) {
@@ -8491,7 +8501,6 @@ async function getDevMiniflareOptions(config) {
8491
8501
  assets: void 0
8492
8502
  }, resolvedPluginConfig.cloudflareEnv, {
8493
8503
  remoteProxyConnectionString: remoteProxySessionData?.session?.remoteProxyConnectionString,
8494
- remoteBindingsEnabled: resolvedPluginConfig.experimental.remoteBindings ?? true,
8495
8504
  containerBuildId
8496
8505
  });
8497
8506
  const { externalWorkers: externalWorkers$1 } = miniflareWorkerOptions;
@@ -8547,11 +8556,7 @@ async function getDevMiniflareOptions(config) {
8547
8556
  inspectorPort: inspectorPort === false ? void 0 : inspectorPort,
8548
8557
  unsafeDevRegistryPath: getDefaultDevRegistryPath(),
8549
8558
  unsafeTriggerHandlers: true,
8550
- handleRuntimeStdio(stdout, stderr) {
8551
- const decoder = new TextDecoder();
8552
- stdout.forEach((data$1) => logger.info(decoder.decode(data$1)));
8553
- stderr.forEach((error) => logger.logWithLevel(LogLevel.ERROR, decoder.decode(error)));
8554
- },
8559
+ handleStructuredLogs: getStructuredLogsLogger(logger),
8555
8560
  defaultPersistRoot: getPersistenceRoot(resolvedViteConfig.root, resolvedPluginConfig.persistState),
8556
8561
  workers: [
8557
8562
  ...assetWorkers,
@@ -8645,10 +8650,10 @@ async function getPreviewMiniflareOptions(config) {
8645
8650
  const workers = (await Promise.all(resolvedPluginConfig.workers.map(async (workerConfig, i$1) => {
8646
8651
  const bindings = unstable_convertConfigBindingsToStartWorkerBindings(workerConfig);
8647
8652
  const preExistingRemoteProxySessionData = workerConfig.configPath ? remoteProxySessionsDataMap.get(workerConfig.configPath) : void 0;
8648
- const remoteProxySessionData = resolvedPluginConfig.experimental.remoteBindings ?? true ? await maybeStartOrUpdateRemoteProxySession({
8653
+ const remoteProxySessionData = await maybeStartOrUpdateRemoteProxySession({
8649
8654
  name: workerConfig.name,
8650
8655
  bindings: bindings ?? {}
8651
- }, preExistingRemoteProxySessionData ?? null) : void 0;
8656
+ }, preExistingRemoteProxySessionData ?? null);
8652
8657
  if (workerConfig.configPath && remoteProxySessionData) remoteProxySessionsDataMap.set(workerConfig.configPath, remoteProxySessionData);
8653
8658
  let containerBuildId;
8654
8659
  if (workerConfig.containers?.length && workerConfig.dev.enable_containers) {
@@ -8664,7 +8669,6 @@ async function getPreviewMiniflareOptions(config) {
8664
8669
  }
8665
8670
  const miniflareWorkerOptions = unstable_getMiniflareWorkerOptions(workerConfig, void 0, {
8666
8671
  remoteProxyConnectionString: remoteProxySessionData?.session?.remoteProxyConnectionString,
8667
- remoteBindingsEnabled: resolvedPluginConfig.experimental.remoteBindings ?? true,
8668
8672
  containerBuildId
8669
8673
  });
8670
8674
  const { externalWorkers } = miniflareWorkerOptions;
@@ -8691,11 +8695,7 @@ async function getPreviewMiniflareOptions(config) {
8691
8695
  inspectorPort: inspectorPort === false ? void 0 : inspectorPort,
8692
8696
  unsafeDevRegistryPath: getDefaultDevRegistryPath(),
8693
8697
  unsafeTriggerHandlers: true,
8694
- handleRuntimeStdio(stdout, stderr) {
8695
- const decoder = new TextDecoder();
8696
- stdout.forEach((data$1) => logger.info(decoder.decode(data$1)));
8697
- stderr.forEach((error) => logger.logWithLevel(LogLevel.ERROR, decoder.decode(error)));
8698
- },
8698
+ handleStructuredLogs: getStructuredLogsLogger(logger),
8699
8699
  defaultPersistRoot: getPersistenceRoot(resolvedViteConfig.root, resolvedPluginConfig.persistState),
8700
8700
  workers
8701
8701
  },
@@ -8728,6 +8728,19 @@ function miniflareLogLevelFromViteLogLevel(level = "info") {
8728
8728
  case "silent": return LogLevel.NONE;
8729
8729
  }
8730
8730
  }
8731
+ /**
8732
+ * Generates a log handler to be passed as the `handleStructuredLogs` option to miniflare
8733
+ *
8734
+ * @param logger the vite logger to use
8735
+ * @returns the log handler to pass to miniflare
8736
+ */
8737
+ function getStructuredLogsLogger(logger) {
8738
+ return ({ level, message }) => {
8739
+ if (level === "warn") return logger.warn(message);
8740
+ if (level === "error") return logger.logWithLevel(LogLevel.ERROR, message);
8741
+ return logger.info(message);
8742
+ };
8743
+ }
8731
8744
 
8732
8745
  //#endregion
8733
8746
  //#region ../workers-shared/utils/configuration/parseStaticRouting.ts
@@ -15710,6 +15723,8 @@ function handleWebSocket(httpServer, getFetcher) {
15710
15723
  //#region src/index.ts
15711
15724
  const debuglog = util.debuglog("@cloudflare:vite-plugin");
15712
15725
  let workersConfigsWarningShown = false;
15726
+ /** Used to track whether hooks are being called because of a server restart or a server close event. */
15727
+ let restartingServer = false;
15713
15728
  let miniflare;
15714
15729
  /**
15715
15730
  * Vite plugin that enables a full-featured integration between Vite and the Cloudflare Workers runtime.
@@ -15721,8 +15736,6 @@ let miniflare;
15721
15736
  function cloudflare(pluginConfig = {}) {
15722
15737
  const ctx = new PluginContext();
15723
15738
  let containerImageTagsSeen = /* @__PURE__ */ new Set();
15724
- /** Used to track whether hooks are being called because of a server restart or a server close event. */
15725
- let restartingServer = false;
15726
15739
  return [
15727
15740
  {
15728
15741
  name: "vite-plugin-cloudflare",