@cloudflare/vite-plugin 0.0.0-fce80ae8c → 0.0.0-fd9dff833

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 +89 -66
  2. package/package.json +6 -6
package/dist/index.js CHANGED
@@ -1200,7 +1200,6 @@ var cloudflareBuiltInModules = [
1200
1200
  "cloudflare:workflows"
1201
1201
  ];
1202
1202
  var defaultConditions = ["workerd", "module", "browser"];
1203
- var target = "es2022";
1204
1203
  function createCloudflareEnvironmentOptions(workerConfig, userConfig, environmentName) {
1205
1204
  return {
1206
1205
  resolve: {
@@ -1221,7 +1220,7 @@ function createCloudflareEnvironmentOptions(workerConfig, userConfig, environmen
1221
1220
  createEnvironment(name2, config) {
1222
1221
  return new vite2.BuildEnvironment(name2, config);
1223
1222
  },
1224
- target,
1223
+ target: "es2022",
1225
1224
  // We need to enable `emitAssets` in order to support additional modules defined by `rules`
1226
1225
  emitAssets: true,
1227
1226
  outDir: getOutputDirectory(userConfig, environmentName),
@@ -1242,7 +1241,6 @@ function createCloudflareEnvironmentOptions(workerConfig, userConfig, environmen
1242
1241
  exclude: [...cloudflareBuiltInModules],
1243
1242
  esbuildOptions: {
1244
1243
  platform: "neutral",
1245
- target,
1246
1244
  conditions: [...defaultConditions, "development"],
1247
1245
  resolveExtensions: [
1248
1246
  ".mjs",
@@ -7535,14 +7533,14 @@ codes.ERR_INVALID_PACKAGE_TARGET = createError(
7535
7533
  * @param {boolean} [isImport=false]
7536
7534
  * @param {string} [base]
7537
7535
  */
7538
- (packagePath, key, target2, isImport = false, base = void 0) => {
7539
- const relatedError = typeof target2 === "string" && !isImport && target2.length > 0 && !target2.startsWith("./");
7536
+ (packagePath, key, target, isImport = false, base = void 0) => {
7537
+ const relatedError = typeof target === "string" && !isImport && target.length > 0 && !target.startsWith("./");
7540
7538
  if (key === ".") {
7541
7539
  assert5(isImport === false);
7542
- return `Invalid "exports" main target ${JSON.stringify(target2)} defined in the package config ${packagePath}package.json${base ? ` imported from ${base}` : ""}${relatedError ? '; targets must start with "./"' : ""}`;
7540
+ return `Invalid "exports" main target ${JSON.stringify(target)} defined in the package config ${packagePath}package.json${base ? ` imported from ${base}` : ""}${relatedError ? '; targets must start with "./"' : ""}`;
7543
7541
  }
7544
7542
  return `Invalid "${isImport ? "imports" : "exports"}" target ${JSON.stringify(
7545
- target2
7543
+ target
7546
7544
  )} defined for '${key}' in the package config ${packagePath}package.json${base ? ` imported from ${base}` : ""}${relatedError ? '; targets must start with "./"' : ""}`;
7547
7545
  },
7548
7546
  Error
@@ -7938,14 +7936,14 @@ var patternRegEx = /\*/g;
7938
7936
  var encodedSeparatorRegEx = /%2f|%5c/i;
7939
7937
  var emittedPackageWarnings = /* @__PURE__ */ new Set();
7940
7938
  var doubleSlashRegEx = /[/\\]{2}/;
7941
- function emitInvalidSegmentDeprecation(target2, request, match, packageJsonUrl, internal, base, isTarget) {
7939
+ function emitInvalidSegmentDeprecation(target, request, match, packageJsonUrl, internal, base, isTarget) {
7942
7940
  if (process$1.noDeprecation) {
7943
7941
  return;
7944
7942
  }
7945
7943
  const pjsonPath = fileURLToPath$1(packageJsonUrl);
7946
- const double = doubleSlashRegEx.exec(isTarget ? target2 : request) !== null;
7944
+ const double = doubleSlashRegEx.exec(isTarget ? target : request) !== null;
7947
7945
  process$1.emitWarning(
7948
- `Use of deprecated ${double ? "double slash" : "leading or trailing slash matching"} resolving "${target2}" for module request "${request}" ${request === match ? "" : `matched to "${match}" `}in the "${internal ? "imports" : "exports"}" field module resolution of the package at ${pjsonPath}${base ? ` imported from ${fileURLToPath$1(base)}` : ""}.`,
7946
+ `Use of deprecated ${double ? "double slash" : "leading or trailing slash matching"} resolving "${target}" for module request "${request}" ${request === match ? "" : `matched to "${match}" `}in the "${internal ? "imports" : "exports"}" field module resolution of the package at ${pjsonPath}${base ? ` imported from ${fileURLToPath$1(base)}` : ""}.`,
7949
7947
  "DeprecationWarning",
7950
7948
  "DEP0166"
7951
7949
  );
@@ -8103,47 +8101,47 @@ function throwInvalidSubpath(request, match, packageJsonUrl, internal, base) {
8103
8101
  base && fileURLToPath$1(base)
8104
8102
  );
8105
8103
  }
8106
- function invalidPackageTarget(subpath, target2, packageJsonUrl, internal, base) {
8107
- target2 = typeof target2 === "object" && target2 !== null ? JSON.stringify(target2, null, "") : `${target2}`;
8104
+ function invalidPackageTarget(subpath, target, packageJsonUrl, internal, base) {
8105
+ target = typeof target === "object" && target !== null ? JSON.stringify(target, null, "") : `${target}`;
8108
8106
  return new ERR_INVALID_PACKAGE_TARGET(
8109
8107
  fileURLToPath$1(new URL$1(".", packageJsonUrl)),
8110
8108
  subpath,
8111
- target2,
8109
+ target,
8112
8110
  internal,
8113
8111
  base && fileURLToPath$1(base)
8114
8112
  );
8115
8113
  }
8116
- function resolvePackageTargetString(target2, subpath, match, packageJsonUrl, base, pattern, internal, isPathMap, conditions) {
8117
- if (subpath !== "" && !pattern && target2[target2.length - 1] !== "/")
8118
- throw invalidPackageTarget(match, target2, packageJsonUrl, internal, base);
8119
- if (!target2.startsWith("./")) {
8120
- if (internal && !target2.startsWith("../") && !target2.startsWith("/")) {
8114
+ function resolvePackageTargetString(target, subpath, match, packageJsonUrl, base, pattern, internal, isPathMap, conditions) {
8115
+ if (subpath !== "" && !pattern && target[target.length - 1] !== "/")
8116
+ throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
8117
+ if (!target.startsWith("./")) {
8118
+ if (internal && !target.startsWith("../") && !target.startsWith("/")) {
8121
8119
  let isURL = false;
8122
8120
  try {
8123
- new URL$1(target2);
8121
+ new URL$1(target);
8124
8122
  isURL = true;
8125
8123
  } catch {
8126
8124
  }
8127
8125
  if (!isURL) {
8128
8126
  const exportTarget = pattern ? RegExpPrototypeSymbolReplace.call(
8129
8127
  patternRegEx,
8130
- target2,
8128
+ target,
8131
8129
  () => subpath
8132
- ) : target2 + subpath;
8130
+ ) : target + subpath;
8133
8131
  return packageResolve(exportTarget, packageJsonUrl, conditions);
8134
8132
  }
8135
8133
  }
8136
- throw invalidPackageTarget(match, target2, packageJsonUrl, internal, base);
8134
+ throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
8137
8135
  }
8138
- if (invalidSegmentRegEx.exec(target2.slice(2)) !== null) {
8139
- if (deprecatedInvalidSegmentRegEx.exec(target2.slice(2)) === null) {
8136
+ if (invalidSegmentRegEx.exec(target.slice(2)) !== null) {
8137
+ if (deprecatedInvalidSegmentRegEx.exec(target.slice(2)) === null) {
8140
8138
  if (!isPathMap) {
8141
8139
  const request = pattern ? match.replace("*", () => subpath) : match + subpath;
8142
8140
  const resolvedTarget = pattern ? RegExpPrototypeSymbolReplace.call(
8143
8141
  patternRegEx,
8144
- target2,
8142
+ target,
8145
8143
  () => subpath
8146
- ) : target2;
8144
+ ) : target;
8147
8145
  emitInvalidSegmentDeprecation(
8148
8146
  resolvedTarget,
8149
8147
  request,
@@ -8155,14 +8153,14 @@ function resolvePackageTargetString(target2, subpath, match, packageJsonUrl, bas
8155
8153
  );
8156
8154
  }
8157
8155
  } else {
8158
- throw invalidPackageTarget(match, target2, packageJsonUrl, internal, base);
8156
+ throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
8159
8157
  }
8160
8158
  }
8161
- const resolved = new URL$1(target2, packageJsonUrl);
8159
+ const resolved = new URL$1(target, packageJsonUrl);
8162
8160
  const resolvedPath = resolved.pathname;
8163
8161
  const packagePath = new URL$1(".", packageJsonUrl).pathname;
8164
8162
  if (!resolvedPath.startsWith(packagePath))
8165
- throw invalidPackageTarget(match, target2, packageJsonUrl, internal, base);
8163
+ throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
8166
8164
  if (subpath === "") return resolved;
8167
8165
  if (invalidSegmentRegEx.exec(subpath) !== null) {
8168
8166
  const request = pattern ? match.replace("*", () => subpath) : match + subpath;
@@ -8170,9 +8168,9 @@ function resolvePackageTargetString(target2, subpath, match, packageJsonUrl, bas
8170
8168
  if (!isPathMap) {
8171
8169
  const resolvedTarget = pattern ? RegExpPrototypeSymbolReplace.call(
8172
8170
  patternRegEx,
8173
- target2,
8171
+ target,
8174
8172
  () => subpath
8175
- ) : target2;
8173
+ ) : target;
8176
8174
  emitInvalidSegmentDeprecation(
8177
8175
  resolvedTarget,
8178
8176
  request,
@@ -8203,10 +8201,10 @@ function isArrayIndex(key) {
8203
8201
  if (`${keyNumber}` !== key) return false;
8204
8202
  return keyNumber >= 0 && keyNumber < 4294967295;
8205
8203
  }
8206
- function resolvePackageTarget(packageJsonUrl, target2, subpath, packageSubpath, base, pattern, internal, isPathMap, conditions) {
8207
- if (typeof target2 === "string") {
8204
+ function resolvePackageTarget(packageJsonUrl, target, subpath, packageSubpath, base, pattern, internal, isPathMap, conditions) {
8205
+ if (typeof target === "string") {
8208
8206
  return resolvePackageTargetString(
8209
- target2,
8207
+ target,
8210
8208
  subpath,
8211
8209
  packageSubpath,
8212
8210
  packageJsonUrl,
@@ -8217,8 +8215,8 @@ function resolvePackageTarget(packageJsonUrl, target2, subpath, packageSubpath,
8217
8215
  conditions
8218
8216
  );
8219
8217
  }
8220
- if (Array.isArray(target2)) {
8221
- const targetList = target2;
8218
+ if (Array.isArray(target)) {
8219
+ const targetList = target;
8222
8220
  if (targetList.length === 0) return null;
8223
8221
  let lastException;
8224
8222
  let i = -1;
@@ -8258,8 +8256,8 @@ function resolvePackageTarget(packageJsonUrl, target2, subpath, packageSubpath,
8258
8256
  }
8259
8257
  throw lastException;
8260
8258
  }
8261
- if (typeof target2 === "object" && target2 !== null) {
8262
- const keys = Object.getOwnPropertyNames(target2);
8259
+ if (typeof target === "object" && target !== null) {
8260
+ const keys = Object.getOwnPropertyNames(target);
8263
8261
  let i = -1;
8264
8262
  while (++i < keys.length) {
8265
8263
  const key = keys[i];
@@ -8277,7 +8275,7 @@ function resolvePackageTarget(packageJsonUrl, target2, subpath, packageSubpath,
8277
8275
  if (key === "default" || conditions && conditions.has(key)) {
8278
8276
  const conditionalTarget = (
8279
8277
  /** @type {unknown} */
8280
- target2[key]
8278
+ target[key]
8281
8279
  );
8282
8280
  const resolveResult = resolvePackageTarget(
8283
8281
  packageJsonUrl,
@@ -8296,12 +8294,12 @@ function resolvePackageTarget(packageJsonUrl, target2, subpath, packageSubpath,
8296
8294
  }
8297
8295
  return null;
8298
8296
  }
8299
- if (target2 === null) {
8297
+ if (target === null) {
8300
8298
  return null;
8301
8299
  }
8302
8300
  throw invalidPackageTarget(
8303
8301
  packageSubpath,
8304
- target2,
8302
+ target,
8305
8303
  packageJsonUrl,
8306
8304
  internal,
8307
8305
  base
@@ -8348,10 +8346,10 @@ function packageExportsResolve(packageJsonUrl, packageSubpath, packageConfig, ba
8348
8346
  exports = { ".": exports };
8349
8347
  }
8350
8348
  if (own.call(exports, packageSubpath) && !packageSubpath.includes("*") && !packageSubpath.endsWith("/")) {
8351
- const target2 = exports[packageSubpath];
8349
+ const target = exports[packageSubpath];
8352
8350
  const resolveResult = resolvePackageTarget(
8353
8351
  packageJsonUrl,
8354
- target2,
8352
+ target,
8355
8353
  "",
8356
8354
  packageSubpath,
8357
8355
  base,
@@ -8391,13 +8389,13 @@ function packageExportsResolve(packageJsonUrl, packageSubpath, packageConfig, ba
8391
8389
  }
8392
8390
  }
8393
8391
  if (bestMatch) {
8394
- const target2 = (
8392
+ const target = (
8395
8393
  /** @type {unknown} */
8396
8394
  exports[bestMatch]
8397
8395
  );
8398
8396
  const resolveResult = resolvePackageTarget(
8399
8397
  packageJsonUrl,
8400
- target2,
8398
+ target,
8401
8399
  bestMatchSubpath,
8402
8400
  bestMatch,
8403
8401
  base,
@@ -8472,10 +8470,10 @@ function packageImportsResolve(name2, base, conditions) {
8472
8470
  }
8473
8471
  }
8474
8472
  if (bestMatch) {
8475
- const target2 = imports[bestMatch];
8473
+ const target = imports[bestMatch];
8476
8474
  const resolveResult = resolvePackageTarget(
8477
8475
  packageJsonUrl,
8478
- target2,
8476
+ target,
8479
8477
  bestMatchSubpath,
8480
8478
  bestMatch,
8481
8479
  base,
@@ -9037,17 +9035,6 @@ function getWorkerConfig(configPath, env2, opts) {
9037
9035
  };
9038
9036
  }
9039
9037
  assert7(config.main, missingFieldErrorMessage(`'main'`, configPath, env2));
9040
- const mainStat = fs4.statSync(config.main, { throwIfNoEntry: false });
9041
- if (!mainStat) {
9042
- throw new Error(
9043
- `The provided Wrangler config main field (${config.main}) doesn't point to an existing file`
9044
- );
9045
- }
9046
- if (mainStat.isDirectory()) {
9047
- throw new Error(
9048
- `The provided Wrangler config main field (${config.main}) points to a directory, it needs to point to a file instead`
9049
- );
9050
- }
9051
9038
  return {
9052
9039
  type: "worker",
9053
9040
  raw,
@@ -9148,9 +9135,8 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
9148
9135
  }
9149
9136
 
9150
9137
  // src/websockets.ts
9151
- import { coupleWebSocket } from "miniflare";
9152
9138
  import { WebSocketServer } from "ws";
9153
- function handleWebSocket(httpServer, fetcher) {
9139
+ function handleWebSocket(httpServer, fetcher, logger) {
9154
9140
  const nodeWebSocket = new WebSocketServer({ noServer: true });
9155
9141
  httpServer.on(
9156
9142
  "upgrade",
@@ -9174,7 +9160,34 @@ function handleWebSocket(httpServer, fetcher) {
9174
9160
  socket,
9175
9161
  head,
9176
9162
  async (clientWebSocket) => {
9177
- coupleWebSocket(clientWebSocket, workerWebSocket);
9163
+ workerWebSocket.accept();
9164
+ workerWebSocket.addEventListener("message", (event) => {
9165
+ clientWebSocket.send(event.data);
9166
+ });
9167
+ workerWebSocket.addEventListener("error", (event) => {
9168
+ logger.error(
9169
+ `WebSocket error:
9170
+ ${event.error?.stack || event.error?.message}`,
9171
+ { error: event.error }
9172
+ );
9173
+ });
9174
+ workerWebSocket.addEventListener("close", () => {
9175
+ clientWebSocket.close();
9176
+ });
9177
+ clientWebSocket.on("message", (data2, isBinary) => {
9178
+ workerWebSocket.send(
9179
+ isBinary ? Array.isArray(data2) ? Buffer.concat(data2) : data2 : data2.toString()
9180
+ );
9181
+ });
9182
+ clientWebSocket.on("error", (error) => {
9183
+ logger.error(`WebSocket error:
9184
+ ${error.stack || error.message}`, {
9185
+ error
9186
+ });
9187
+ });
9188
+ clientWebSocket.on("close", () => {
9189
+ workerWebSocket.close();
9190
+ });
9178
9191
  nodeWebSocket.emit("connection", clientWebSocket, request);
9179
9192
  }
9180
9193
  );
@@ -9367,7 +9380,11 @@ function cloudflare2(pluginConfig = {}) {
9367
9380
  },
9368
9381
  { alwaysCallNext: false }
9369
9382
  );
9370
- handleWebSocket(viteDevServer.httpServer, entryWorker.fetch);
9383
+ handleWebSocket(
9384
+ viteDevServer.httpServer,
9385
+ entryWorker.fetch,
9386
+ viteDevServer.config.logger
9387
+ );
9371
9388
  return () => {
9372
9389
  viteDevServer.middlewares.use((req, res, next) => {
9373
9390
  middleware(req, res, next);
@@ -9389,10 +9406,16 @@ function cloudflare2(pluginConfig = {}) {
9389
9406
  },
9390
9407
  { alwaysCallNext: false }
9391
9408
  );
9392
- handleWebSocket(vitePreviewServer.httpServer, miniflare2.dispatchFetch);
9393
- vitePreviewServer.middlewares.use((req, res, next) => {
9394
- middleware(req, res, next);
9395
- });
9409
+ handleWebSocket(
9410
+ vitePreviewServer.httpServer,
9411
+ miniflare2.dispatchFetch,
9412
+ vitePreviewServer.config.logger
9413
+ );
9414
+ return () => {
9415
+ vitePreviewServer.middlewares.use((req, res, next) => {
9416
+ middleware(req, res, next);
9417
+ });
9418
+ };
9396
9419
  }
9397
9420
  },
9398
9421
  // Plugin to support `CompiledWasm` modules
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudflare/vite-plugin",
3
- "version": "0.0.0-fce80ae8c",
3
+ "version": "0.0.0-fd9dff833",
4
4
  "description": "Cloudflare plugin for Vite",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -38,8 +38,8 @@
38
38
  "tinyglobby": "^0.2.12",
39
39
  "unenv": "2.0.0-rc.1",
40
40
  "ws": "8.18.0",
41
- "miniflare": "0.0.0-fce80ae8c",
42
- "wrangler": "0.0.0-fce80ae8c"
41
+ "miniflare": "0.0.0-fd9dff833",
42
+ "wrangler": "0.0.0-fd9dff833"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@cloudflare/workers-types": "^4.20250317.0",
@@ -53,12 +53,12 @@
53
53
  "vite": "^6.1.0",
54
54
  "vitest": "~3.0.5",
55
55
  "@cloudflare/mock-npm-registry": "0.0.0",
56
- "@cloudflare/workers-tsconfig": "0.0.0",
57
- "@cloudflare/workers-shared": "0.0.0-fce80ae8c"
56
+ "@cloudflare/workers-shared": "0.0.0-fd9dff833",
57
+ "@cloudflare/workers-tsconfig": "0.0.0"
58
58
  },
59
59
  "peerDependencies": {
60
60
  "vite": "^6.1.0",
61
- "wrangler": "^3.101.0 || ^4.0.0"
61
+ "wrangler": "^3.101.0"
62
62
  },
63
63
  "publishConfig": {
64
64
  "access": "public"