@cloudflare/vite-plugin 0.1.3 → 0.1.5

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 (2) hide show
  1. package/dist/index.js +35 -26
  2. package/package.json +5 -5
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"],
@@ -8712,6 +8713,8 @@ var { env } = defineEnv({
8712
8713
  nodeCompat: true,
8713
8714
  presets: [cloudflare]
8714
8715
  });
8716
+ var nodeCompatExternals = new Set(env.external);
8717
+ var nodeCompatEntries = getNodeCompatEntries();
8715
8718
  function isNodeCompat(workerConfig) {
8716
8719
  if (workerConfig === void 0) {
8717
8720
  return false;
@@ -8735,24 +8738,6 @@ function isNodeCompat(workerConfig) {
8735
8738
  }
8736
8739
  return false;
8737
8740
  }
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
8741
  function injectGlobalCode(id, code) {
8757
8742
  const injectedCode = Object.entries(env.inject).map(([globalName, globalInject]) => {
8758
8743
  if (typeof globalInject === "string") {
@@ -8778,9 +8763,6 @@ globalThis.${globalName} = var_${globalName}.${exportName};
8778
8763
  map: modified.generateMap({ hires: "boundary", source: id })
8779
8764
  };
8780
8765
  }
8781
- function getNodeCompatExternals() {
8782
- return env.external;
8783
- }
8784
8766
  function resolveNodeJSImport(source) {
8785
8767
  const alias = env.alias[source];
8786
8768
  if (alias) {
@@ -8789,6 +8771,28 @@ function resolveNodeJSImport(source) {
8789
8771
  resolved: resolvePathSync(alias, { url: import.meta.url })
8790
8772
  };
8791
8773
  }
8774
+ if (nodeCompatEntries.has(source)) {
8775
+ return {
8776
+ unresolved: source,
8777
+ resolved: resolvePathSync(source, { url: import.meta.url })
8778
+ };
8779
+ }
8780
+ }
8781
+ function getNodeCompatEntries() {
8782
+ const entries = new Set(Object.values(env.alias));
8783
+ for (const globalInject of Object.values(env.inject)) {
8784
+ if (typeof globalInject === "string") {
8785
+ entries.add(globalInject);
8786
+ } else {
8787
+ assert6(
8788
+ globalInject[0] !== void 0,
8789
+ "Expected first element of globalInject to be defined"
8790
+ );
8791
+ entries.add(globalInject[0]);
8792
+ }
8793
+ }
8794
+ nodeCompatExternals.forEach((external) => entries.delete(external));
8795
+ return entries;
8792
8796
  }
8793
8797
 
8794
8798
  // src/plugin-config.ts
@@ -9101,9 +9105,9 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
9101
9105
  }
9102
9106
 
9103
9107
  // src/websockets.ts
9104
- import ws from "ws";
9108
+ import { WebSocketServer } from "ws";
9105
9109
  function handleWebSocket(httpServer, fetcher, logger) {
9106
- const nodeWebSocket = new ws.Server({ noServer: true });
9110
+ const nodeWebSocket = new WebSocketServer({ noServer: true });
9107
9111
  httpServer.on(
9108
9112
  "upgrade",
9109
9113
  async (request, socket, head) => {
@@ -9461,7 +9465,7 @@ function cloudflare2(pluginConfig = {}) {
9461
9465
  if (isNodeCompat(getWorkerConfig2(name2))) {
9462
9466
  return {
9463
9467
  resolve: {
9464
- builtins: getNodeCompatExternals()
9468
+ builtins: [...nodeCompatExternals]
9465
9469
  },
9466
9470
  optimizeDeps: {
9467
9471
  // This is a list of dependency entry-points that should be pre-bundled.
@@ -9469,7 +9473,8 @@ function cloudflare2(pluginConfig = {}) {
9469
9473
  // ready ahead the first request to the dev server.
9470
9474
  // Without this the dependency optimizer will try to bundle them on-the-fly in the middle of the first request,
9471
9475
  // which can potentially cause problems if it leads to previous pre-bundling to become stale and needing to be reloaded.
9472
- include: [...getNodeCompatEntries()],
9476
+ // TODO: work out how to re-enable pre-bundling of these
9477
+ // include: [...getNodeCompatEntries()],
9473
9478
  // This is a list of module specifiers that the dependency optimizer should not follow when doing import analysis.
9474
9479
  // 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
9480
  // Obviously we don't want/need the optimizer to try to process modules that are built-in;
@@ -9500,7 +9505,11 @@ function cloudflare2(pluginConfig = {}) {
9500
9505
  this.environment.depsOptimizer,
9501
9506
  "depsOptimizer is required in dev mode"
9502
9507
  );
9503
- return this.resolve(result.unresolved, importer, options);
9508
+ const { id } = this.environment.depsOptimizer.registerMissingImport(
9509
+ result.unresolved,
9510
+ result.resolved
9511
+ );
9512
+ return this.resolve(id, importer, options);
9504
9513
  }
9505
9514
  return this.resolve(result.resolved, importer, options);
9506
9515
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudflare/vite-plugin",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Cloudflare plugin for Vite",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -36,7 +36,7 @@
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",
39
+ "ws": "8.18.0",
40
40
  "miniflare": "3.20250214.0"
41
41
  },
42
42
  "devDependencies": {
@@ -50,10 +50,10 @@
50
50
  "undici": "^5.28.5",
51
51
  "vite": "^6.1.0",
52
52
  "vitest": "~3.0.5",
53
- "@cloudflare/mock-npm-registry": "0.0.0",
53
+ "@cloudflare/workers-shared": "0.14.3",
54
54
  "@cloudflare/workers-tsconfig": "0.0.0",
55
- "wrangler": "3.109.2",
56
- "@cloudflare/workers-shared": "0.14.3"
55
+ "wrangler": "3.109.3",
56
+ "@cloudflare/mock-npm-registry": "0.0.0"
57
57
  },
58
58
  "peerDependencies": {
59
59
  "vite": "^6.1.0",