@cloudflare/vite-plugin 0.0.0-ab4dcff48 → 0.0.0-acd42a849

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.
@@ -2072,8 +2072,8 @@ var Ve = class {
2072
2072
  };
2073
2073
  var Yn = "public, max-age=0, must-revalidate";
2074
2074
  function Jn(t, e, n) {
2075
- let r = new Headers({ "Content-Type": e, ETag: `"${t}"` });
2076
- return Ds(n) && r.append("Cache-Control", Yn), r;
2075
+ let r = new Headers({ ETag: `"${t}"` });
2076
+ return e !== void 0 && r.append("Content-Type", e), Ds(n) && r.append("Cache-Control", Yn), r;
2077
2077
  }
2078
2078
  function Ds(t) {
2079
2079
  return !t.headers.has("Authorization") && !t.headers.has("Range");
@@ -2280,7 +2280,7 @@ var Kn = class extends Us {
2280
2280
  async unstable_getByETag(t) {
2281
2281
  let e = await Wn(this.env.ASSETS_KV_NAMESPACE, t);
2282
2282
  if (!e || !e.value) throw new Error(`Requested asset ${t} exists in the asset manifest but not in the KV namespace.`);
2283
- return { readableStream: e.value, contentType: e.metadata?.contentType ?? "application/octet-stream" };
2283
+ return { readableStream: e.value, contentType: e.metadata?.contentType };
2284
2284
  }
2285
2285
  async unstable_getByPathname(t) {
2286
2286
  let e = await this.unstable_exists(t);
package/dist/index.js CHANGED
@@ -1238,6 +1238,7 @@ function createCloudflareEnvironmentOptions(workerConfig, userConfig, environmen
1238
1238
  // Note: ssr pre-bundling is opt-in and we need to enable it by setting `noDiscovery` to false
1239
1239
  noDiscovery: false,
1240
1240
  entries: workerConfig.main,
1241
+ exclude: [...cloudflareBuiltInModules],
1241
1242
  esbuildOptions: {
1242
1243
  platform: "neutral",
1243
1244
  conditions: [...defaultConditions, "development"],
@@ -1363,7 +1364,12 @@ import * as fs2 from "node:fs";
1363
1364
  import * as fsp from "node:fs/promises";
1364
1365
  import * as path3 from "node:path";
1365
1366
  import { fileURLToPath } from "node:url";
1366
- import { Log, LogLevel, Response as MiniflareResponse } from "miniflare";
1367
+ import {
1368
+ kCurrentWorker,
1369
+ Log,
1370
+ LogLevel,
1371
+ Response as MiniflareResponse
1372
+ } from "miniflare";
1367
1373
  import "vite";
1368
1374
  import {
1369
1375
  unstable_getMiniflareWorkerOptions,
@@ -1397,11 +1403,10 @@ function getWorkerToWorkerEntrypointNamesMap(workers) {
1397
1403
  );
1398
1404
  for (const worker of workers) {
1399
1405
  for (const value of Object.values(worker.serviceBindings ?? {})) {
1400
- if (typeof value === "object" && "name" in value && typeof value.name === "string" && value.entrypoint !== void 0 && value.entrypoint !== "default") {
1401
- const entrypointNames = workerToWorkerEntrypointNamesMap.get(
1402
- value.name
1403
- );
1404
- assert4(entrypointNames, missingWorkerErrorMessage(value.name));
1406
+ if (typeof value === "object" && "name" in value && value.entrypoint !== void 0 && value.entrypoint !== "default") {
1407
+ const targetWorkerName = value.name === kCurrentWorker ? worker.name : value.name;
1408
+ const entrypointNames = workerToWorkerEntrypointNamesMap.get(targetWorkerName);
1409
+ assert4(entrypointNames, missingWorkerErrorMessage(targetWorkerName));
1405
1410
  entrypointNames.add(value.entrypoint);
1406
1411
  }
1407
1412
  }
@@ -8712,6 +8717,8 @@ var { env } = defineEnv({
8712
8717
  nodeCompat: true,
8713
8718
  presets: [cloudflare]
8714
8719
  });
8720
+ var nodeCompatExternals = new Set(env.external);
8721
+ var nodeCompatEntries = getNodeCompatEntries();
8715
8722
  function isNodeCompat(workerConfig) {
8716
8723
  if (workerConfig === void 0) {
8717
8724
  return false;
@@ -8735,24 +8742,6 @@ function isNodeCompat(workerConfig) {
8735
8742
  }
8736
8743
  return false;
8737
8744
  }
8738
- function getNodeCompatEntries() {
8739
- const entries = new Set(Object.values(env.alias));
8740
- for (const globalInject of Object.values(env.inject)) {
8741
- if (typeof globalInject === "string") {
8742
- entries.add(globalInject);
8743
- } else {
8744
- assert6(
8745
- globalInject[0] !== void 0,
8746
- "Expected first element of globalInject to be defined"
8747
- );
8748
- entries.add(globalInject[0]);
8749
- }
8750
- }
8751
- for (const external of env.external) {
8752
- entries.delete(external);
8753
- }
8754
- return entries;
8755
- }
8756
8745
  function injectGlobalCode(id, code) {
8757
8746
  const injectedCode = Object.entries(env.inject).map(([globalName, globalInject]) => {
8758
8747
  if (typeof globalInject === "string") {
@@ -8778,9 +8767,6 @@ globalThis.${globalName} = var_${globalName}.${exportName};
8778
8767
  map: modified.generateMap({ hires: "boundary", source: id })
8779
8768
  };
8780
8769
  }
8781
- function getNodeCompatExternals() {
8782
- return env.external;
8783
- }
8784
8770
  function resolveNodeJSImport(source) {
8785
8771
  const alias = env.alias[source];
8786
8772
  if (alias) {
@@ -8789,6 +8775,28 @@ function resolveNodeJSImport(source) {
8789
8775
  resolved: resolvePathSync(alias, { url: import.meta.url })
8790
8776
  };
8791
8777
  }
8778
+ if (nodeCompatEntries.has(source)) {
8779
+ return {
8780
+ unresolved: source,
8781
+ resolved: resolvePathSync(source, { url: import.meta.url })
8782
+ };
8783
+ }
8784
+ }
8785
+ function getNodeCompatEntries() {
8786
+ const entries = new Set(Object.values(env.alias));
8787
+ for (const globalInject of Object.values(env.inject)) {
8788
+ if (typeof globalInject === "string") {
8789
+ entries.add(globalInject);
8790
+ } else {
8791
+ assert6(
8792
+ globalInject[0] !== void 0,
8793
+ "Expected first element of globalInject to be defined"
8794
+ );
8795
+ entries.add(globalInject[0]);
8796
+ }
8797
+ }
8798
+ nodeCompatExternals.forEach((external) => entries.delete(external));
8799
+ return entries;
8792
8800
  }
8793
8801
 
8794
8802
  // src/plugin-config.ts
@@ -9101,9 +9109,9 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
9101
9109
  }
9102
9110
 
9103
9111
  // src/websockets.ts
9104
- import ws from "ws";
9112
+ import { WebSocketServer } from "ws";
9105
9113
  function handleWebSocket(httpServer, fetcher, logger) {
9106
- const nodeWebSocket = new ws.Server({ noServer: true });
9114
+ const nodeWebSocket = new WebSocketServer({ noServer: true });
9107
9115
  httpServer.on(
9108
9116
  "upgrade",
9109
9117
  async (request, socket, head) => {
@@ -9212,7 +9220,7 @@ function cloudflare2(pluginConfig = {}) {
9212
9220
  }
9213
9221
  } : void 0,
9214
9222
  builder: {
9215
- async buildApp(builder) {
9223
+ buildApp: userConfig.builder?.buildApp ?? (async (builder) => {
9216
9224
  const clientEnvironment = builder.environments.client;
9217
9225
  const defaultHtmlPath = path7.resolve(
9218
9226
  builder.config.root,
@@ -9238,7 +9246,7 @@ function cloudflare2(pluginConfig = {}) {
9238
9246
  )
9239
9247
  );
9240
9248
  }
9241
- }
9249
+ })
9242
9250
  }
9243
9251
  };
9244
9252
  },
@@ -9461,7 +9469,7 @@ function cloudflare2(pluginConfig = {}) {
9461
9469
  if (isNodeCompat(getWorkerConfig2(name2))) {
9462
9470
  return {
9463
9471
  resolve: {
9464
- builtins: getNodeCompatExternals()
9472
+ builtins: [...nodeCompatExternals]
9465
9473
  },
9466
9474
  optimizeDeps: {
9467
9475
  // This is a list of dependency entry-points that should be pre-bundled.
@@ -9469,7 +9477,8 @@ function cloudflare2(pluginConfig = {}) {
9469
9477
  // ready ahead the first request to the dev server.
9470
9478
  // Without this the dependency optimizer will try to bundle them on-the-fly in the middle of the first request,
9471
9479
  // which can potentially cause problems if it leads to previous pre-bundling to become stale and needing to be reloaded.
9472
- include: [...getNodeCompatEntries()],
9480
+ // TODO: work out how to re-enable pre-bundling of these
9481
+ // include: [...getNodeCompatEntries()],
9473
9482
  // This is a list of module specifiers that the dependency optimizer should not follow when doing import analysis.
9474
9483
  // In this case we provide a list of all the Node.js modules, both those built-in to workerd and those that will be polyfilled.
9475
9484
  // Obviously we don't want/need the optimizer to try to process modules that are built-in;
@@ -9500,7 +9509,11 @@ function cloudflare2(pluginConfig = {}) {
9500
9509
  this.environment.depsOptimizer,
9501
9510
  "depsOptimizer is required in dev mode"
9502
9511
  );
9503
- return this.resolve(result.unresolved, importer, options);
9512
+ const { id } = this.environment.depsOptimizer.registerMissingImport(
9513
+ result.unresolved,
9514
+ result.resolved
9515
+ );
9516
+ return this.resolve(id, importer, options);
9504
9517
  }
9505
9518
  return this.resolve(result.resolved, importer, options);
9506
9519
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudflare/vite-plugin",
3
- "version": "0.0.0-ab4dcff48",
3
+ "version": "0.0.0-acd42a849",
4
4
  "description": "Cloudflare plugin for Vite",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -36,8 +36,8 @@
36
36
  "@cloudflare/unenv-preset": "1.1.1",
37
37
  "@hattip/adapter-node": "^0.0.49",
38
38
  "unenv": "2.0.0-rc.1",
39
- "ws": "^8.18.0",
40
- "miniflare": "0.0.0-ab4dcff48"
39
+ "ws": "8.18.0",
40
+ "miniflare": "0.0.0-acd42a849"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@cloudflare/workers-types": "^4.20250214.0",
@@ -51,9 +51,9 @@
51
51
  "vite": "^6.1.0",
52
52
  "vitest": "~3.0.5",
53
53
  "@cloudflare/mock-npm-registry": "0.0.0",
54
- "@cloudflare/workers-shared": "0.0.0-ab4dcff48",
54
+ "@cloudflare/workers-shared": "0.0.0-acd42a849",
55
55
  "@cloudflare/workers-tsconfig": "0.0.0",
56
- "wrangler": "0.0.0-ab4dcff48"
56
+ "wrangler": "0.0.0-acd42a849"
57
57
  },
58
58
  "peerDependencies": {
59
59
  "vite": "^6.1.0",