@cloudflare/vite-plugin 0.0.0-39933740e → 0.0.0-3b384e28c

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.
@@ -1985,7 +1985,7 @@ var we = class {
1985
1985
  this.hasWritten || this.readyAnalytics && (this.hasWritten = true, this.readyAnalytics.logEvent({ version: 1, accountId: this.data.accountId, indexId: this.data.scriptId?.toString(), doubles: [this.data.requestTime ?? -1, this.data.coloId ?? -1, this.data.metalId ?? -1, this.data.coloTier ?? -1, this.data.userWorkerAhead === void 0 ? -1 : Number(this.data.userWorkerAhead)], blobs: [this.data.hostname?.substring(0, 256), this.data.dispatchtype, this.data.error?.substring(0, 256), this.data.version, this.data.coloRegion] }));
1986
1986
  }
1987
1987
  };
1988
- var On = (t4) => ({ invoke_user_worker_ahead_of_assets: t4?.invoke_user_worker_ahead_of_assets ?? false, has_user_worker: t4?.has_user_worker ?? false, account_id: t4?.account_id ?? -1, script_id: t4?.script_id ?? -1 });
1988
+ var On = (t4) => ({ invoke_user_worker_ahead_of_assets: t4?.invoke_user_worker_ahead_of_assets ?? false, has_user_worker: t4?.has_user_worker ?? false, account_id: t4?.account_id ?? -1, script_id: t4?.script_id ?? -1, debug: t4?.debug ?? false });
1989
1989
  var Bc = { async fetch(t4, e, n) {
1990
1990
  let r, o = false, s = new we(e.ANALYTICS), i = new ue(e.UNSAFE_PERFORMANCE), a = i.now();
1991
1991
  try {
package/dist/index.js CHANGED
@@ -485,11 +485,12 @@ var require_mime = __commonJS({
485
485
  });
486
486
 
487
487
  // src/index.ts
488
- import assert9 from "node:assert";
488
+ import assert10 from "node:assert";
489
489
  import * as fs5 from "node:fs";
490
490
  import * as fsp2 from "node:fs/promises";
491
491
  import * as path9 from "node:path";
492
- import { createMiddleware } from "@hattip/adapter-node";
492
+ import { createRequest, sendResponse } from "@mjackson/node-fetch-server";
493
+ import replace from "@rollup/plugin-replace";
493
494
 
494
495
  // ../../node_modules/.pnpm/@jridgewell+sourcemap-codec@1.5.0/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
495
496
  var comma = ",".charCodeAt(0);
@@ -1557,7 +1558,7 @@ var MagicString = class _MagicString {
1557
1558
 
1558
1559
  // src/index.ts
1559
1560
  import { Miniflare } from "miniflare";
1560
- import colors2 from "picocolors";
1561
+ import colors3 from "picocolors";
1561
1562
  import * as vite7 from "vite";
1562
1563
 
1563
1564
  // src/constants.ts
@@ -5783,7 +5784,8 @@ var z = /* @__PURE__ */ Object.freeze({
5783
5784
  // ../workers-shared/utils/types.ts
5784
5785
  var InternalConfigSchema = z.object({
5785
5786
  account_id: z.number().optional(),
5786
- script_id: z.number().optional()
5787
+ script_id: z.number().optional(),
5788
+ debug: z.boolean().optional()
5787
5789
  });
5788
5790
  var RouterConfigSchema = z.object({
5789
5791
  invoke_user_worker_ahead_of_assets: z.boolean().optional(),
@@ -5831,14 +5833,14 @@ var AssetConfigSchema = z.object({
5831
5833
  });
5832
5834
 
5833
5835
  // src/asset-config.ts
5834
- function hasAssetsConfigChanged(resolvedPluginConfig, resolvedViteConfig, changedFile) {
5836
+ function hasAssetsConfigChanged(resolvedPluginConfig, resolvedViteConfig, changedFilePath) {
5835
5837
  if (!resolvedPluginConfig.experimental?.headersAndRedirectsDevModeSupport) {
5836
5838
  return false;
5837
5839
  }
5838
5840
  return [
5839
5841
  getRedirectsConfigPath(resolvedViteConfig),
5840
5842
  getHeadersConfigPath(resolvedViteConfig)
5841
- ].includes(path.resolve(changedFile));
5843
+ ].includes(changedFilePath);
5842
5844
  }
5843
5845
  function getAssetsConfig(resolvedPluginConfig, entryWorkerConfig, resolvedConfig) {
5844
5846
  const assetsConfig = resolvedPluginConfig.type === "assets-only" ? resolvedPluginConfig.config.assets : entryWorkerConfig?.assets;
@@ -12879,6 +12881,15 @@ function isNodeCompat(workerConfig) {
12879
12881
  }
12880
12882
  return false;
12881
12883
  }
12884
+ function isNodeAls(workerConfig) {
12885
+ return workerConfig !== void 0 && getNodeCompat(
12886
+ workerConfig.compatibility_date,
12887
+ workerConfig.compatibility_flags ?? []
12888
+ ).mode === "als";
12889
+ }
12890
+ function isNodeAlsModule(path10) {
12891
+ return /^(node:)?async_hooks$/.test(path10);
12892
+ }
12882
12893
  function injectGlobalCode(id, code) {
12883
12894
  const injectedCode = Object.entries(env.inject).map(([globalName, globalInject]) => {
12884
12895
  if (typeof globalInject === "string") {
@@ -12909,7 +12920,7 @@ globalThis.${globalName} = var_${globalName}.${exportName};
12909
12920
  }
12910
12921
  function resolveNodeJSImport(source) {
12911
12922
  const alias = env.alias[source];
12912
- if (alias) {
12923
+ if (alias && !nodeCompatExternals.has(alias)) {
12913
12924
  return {
12914
12925
  unresolved: alias,
12915
12926
  resolved: resolvePathSync(alias, { url: import.meta.url })
@@ -13018,19 +13029,6 @@ function toMiniflareRequest(request) {
13018
13029
  duplex: "half"
13019
13030
  });
13020
13031
  }
13021
- function nodeHeadersToWebHeaders(nodeHeaders) {
13022
- const headers = new Headers();
13023
- for (const [key, value] of Object.entries(nodeHeaders)) {
13024
- if (typeof value === "string") {
13025
- headers.append(key, value);
13026
- } else if (Array.isArray(value)) {
13027
- for (const item of value) {
13028
- headers.append(key, item);
13029
- }
13030
- }
13031
- }
13032
- return headers;
13033
- }
13034
13032
  var postfixRE = /[?#].*$/;
13035
13033
  function cleanUrl(url) {
13036
13034
  return url.replace(postfixRE, "");
@@ -13344,6 +13342,7 @@ import {
13344
13342
  LogLevel,
13345
13343
  Response as MiniflareResponse
13346
13344
  } from "miniflare";
13345
+ import colors2 from "picocolors";
13347
13346
  import { globSync } from "tinyglobby";
13348
13347
  import "vite";
13349
13348
  import { unstable_getMiniflareWorkerOptions } from "wrangler";
@@ -13448,6 +13447,29 @@ function getEntryWorkerConfig(resolvedPluginConfig) {
13448
13447
  }
13449
13448
  return resolvedPluginConfig.workers[resolvedPluginConfig.entryWorkerEnvironmentName];
13450
13449
  }
13450
+ function filterTails(tails, userWorkers, log) {
13451
+ return tails?.filter((tailService) => {
13452
+ let name;
13453
+ if (typeof tailService === "string") {
13454
+ name = tailService;
13455
+ } else if (typeof tailService === "object" && "name" in tailService && typeof tailService.name === "string") {
13456
+ name = tailService.name;
13457
+ } else {
13458
+ return true;
13459
+ }
13460
+ const found = userWorkers.some((w) => w.name === name);
13461
+ if (!found) {
13462
+ log(
13463
+ colors2.dim(
13464
+ colors2.yellow(
13465
+ `Tail consumer "${name}" was not found in your config. Make sure you add it if you'd like to simulate receiving tail events locally.`
13466
+ )
13467
+ )
13468
+ );
13469
+ }
13470
+ return found;
13471
+ });
13472
+ }
13451
13473
  function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspectorPort) {
13452
13474
  const resolvedViteConfig = viteDevServer.config;
13453
13475
  const entryWorkerConfig = getEntryWorkerConfig(resolvedPluginConfig);
@@ -13639,6 +13661,11 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspectorPo
13639
13661
  }
13640
13662
  return {
13641
13663
  ...workerOptions,
13664
+ tails: filterTails(
13665
+ workerOptions.tails,
13666
+ userWorkers,
13667
+ viteDevServer.config.logger.warn
13668
+ ),
13642
13669
  modules: [
13643
13670
  {
13644
13671
  type: "ESModule",
@@ -13729,6 +13756,11 @@ function getPreviewMiniflareOptions(vitePreviewServer, workerConfigs, persistSta
13729
13756
  return [
13730
13757
  {
13731
13758
  ...workerOptions,
13759
+ tails: filterTails(
13760
+ workerOptions.tails,
13761
+ workerConfigs,
13762
+ vitePreviewServer.config.logger.warn
13763
+ ),
13732
13764
  name: workerOptions.name ?? config.name,
13733
13765
  unsafeInspectorProxy: inspectorPort !== false,
13734
13766
  ...miniflareWorkerOptions.main ? getPreviewModules(miniflareWorkerOptions.main, modulesRules) : { modules: true, script: "" }
@@ -13828,8 +13860,7 @@ var nonApplicableWorkerConfigs = {
13828
13860
  "preserve_file_names",
13829
13861
  "rules",
13830
13862
  "site",
13831
- "tsconfig",
13832
- "upload_source_maps"
13863
+ "tsconfig"
13833
13864
  ]
13834
13865
  };
13835
13866
  var nullableNonApplicable = [
@@ -13840,8 +13871,7 @@ var nullableNonApplicable = [
13840
13871
  "no_bundle",
13841
13872
  "preserve_file_names",
13842
13873
  "site",
13843
- "tsconfig",
13844
- "upload_source_maps"
13874
+ "tsconfig"
13845
13875
  ];
13846
13876
  function readWorkerConfig(configPath, env2) {
13847
13877
  const nonApplicable = {
@@ -14139,6 +14169,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
14139
14169
  }
14140
14170
 
14141
14171
  // src/websockets.ts
14172
+ import { createHeaders } from "@mjackson/node-fetch-server";
14142
14173
  import { coupleWebSocket } from "miniflare";
14143
14174
  import { WebSocketServer } from "ws";
14144
14175
  function handleWebSocket(httpServer, getFetcher) {
@@ -14150,7 +14181,7 @@ function handleWebSocket(httpServer, getFetcher) {
14150
14181
  if (request.headers["sec-websocket-protocol"]?.startsWith("vite")) {
14151
14182
  return;
14152
14183
  }
14153
- const headers = nodeHeadersToWebHeaders(request.headers);
14184
+ const headers = createHeaders(request);
14154
14185
  const fetcher = await getFetcher();
14155
14186
  const response = await fetcher(url, {
14156
14187
  headers,
@@ -14174,6 +14205,57 @@ function handleWebSocket(httpServer, getFetcher) {
14174
14205
  );
14175
14206
  }
14176
14207
 
14208
+ // src/worker-environments-validation.ts
14209
+ import assert9 from "node:assert";
14210
+ function validateWorkerEnvironmentsResolvedConfigs(resolvedPluginConfig, resolvedViteConfig) {
14211
+ const workersEnvironmentNames = Object.keys(resolvedPluginConfig.workers);
14212
+ const disallowedEnvsConfigs = /* @__PURE__ */ new Map();
14213
+ for (const envName of workersEnvironmentNames) {
14214
+ const workerEnvConfig = resolvedViteConfig.environments[envName];
14215
+ assert9(workerEnvConfig, `Missing environment config for "${envName}"`);
14216
+ const { optimizeDeps, resolve: resolve7 } = workerEnvConfig;
14217
+ const disallowedConfig = {};
14218
+ const disallowedOptimizeDepsExcludeEntries = (optimizeDeps.exclude ?? []).filter((entry) => {
14219
+ if (cloudflareBuiltInModules.includes(entry)) {
14220
+ return false;
14221
+ }
14222
+ if (isNodeAlsModule(entry) && isNodeAls(resolvedPluginConfig.workers[envName])) {
14223
+ return false;
14224
+ }
14225
+ if (NODEJS_MODULES_RE.test(entry) && isNodeCompat(resolvedPluginConfig.workers[envName])) {
14226
+ return false;
14227
+ }
14228
+ return true;
14229
+ });
14230
+ if (disallowedOptimizeDepsExcludeEntries.length > 0) {
14231
+ disallowedConfig.optimizeDepsExclude = disallowedOptimizeDepsExcludeEntries;
14232
+ }
14233
+ if (resolve7.external === true || resolve7.external.length > 0) {
14234
+ disallowedConfig.resolveExternal = resolve7.external;
14235
+ }
14236
+ if (Object.keys(disallowedConfig).length > 0) {
14237
+ disallowedEnvsConfigs.set(envName, disallowedConfig);
14238
+ }
14239
+ }
14240
+ if (disallowedEnvsConfigs.size > 0) {
14241
+ const errorMessage = `The following environment configurations are incompatible with the Cloudflare Vite plugin:
14242
+ ${[
14243
+ ...disallowedEnvsConfigs
14244
+ ].map(
14245
+ ([envName, disallowedConfig]) => [
14246
+ disallowedConfig.optimizeDepsExclude ? ` - "${envName}" environment: \`optimizeDeps.exclude\`: ${JSON.stringify(disallowedConfig.optimizeDepsExclude)}
14247
+ ` : null,
14248
+ disallowedConfig.resolveExternal ? ` - "${envName}" environment: \`resolve.external\`: ${JSON.stringify(disallowedConfig.resolveExternal)}
14249
+ ` : null
14250
+ ].join("")
14251
+ ).join(
14252
+ ""
14253
+ )}To resolve this issue, avoid setting \`optimizeDeps.exclude\` and \`resolve.external\` in your Cloudflare Worker environments.
14254
+ `;
14255
+ throw new Error(errorMessage);
14256
+ }
14257
+ }
14258
+
14177
14259
  // src/index.ts
14178
14260
  var workersConfigsWarningShown = false;
14179
14261
  var miniflare;
@@ -14244,7 +14326,7 @@ function cloudflare2(pluginConfig = {}) {
14244
14326
  resolvedPluginConfig.workers
14245
14327
  ).map((environmentName) => {
14246
14328
  const environment = builder.environments[environmentName];
14247
- assert9(
14329
+ assert10(
14248
14330
  environment,
14249
14331
  `${environmentName} environment not found`
14250
14332
  );
@@ -14265,6 +14347,12 @@ function cloudflare2(pluginConfig = {}) {
14265
14347
  },
14266
14348
  configResolved(config) {
14267
14349
  resolvedViteConfig = config;
14350
+ if (resolvedPluginConfig?.type === "workers") {
14351
+ validateWorkerEnvironmentsResolvedConfigs(
14352
+ resolvedPluginConfig,
14353
+ resolvedViteConfig
14354
+ );
14355
+ }
14268
14356
  },
14269
14357
  generateBundle(_, bundle) {
14270
14358
  let config;
@@ -14285,7 +14373,7 @@ function cloudflare2(pluginConfig = {}) {
14285
14373
  if (isEntryWorker && hasClientBuild) {
14286
14374
  const workerOutputDirectory = this.environment.config.build.outDir;
14287
14375
  const clientOutputDirectory = resolvedViteConfig.environments.client?.build.outDir;
14288
- assert9(
14376
+ assert10(
14289
14377
  clientOutputDirectory,
14290
14378
  "Unexpected error: client output directory is undefined"
14291
14379
  );
@@ -14349,29 +14437,23 @@ function cloudflare2(pluginConfig = {}) {
14349
14437
  }
14350
14438
  },
14351
14439
  hotUpdate(options) {
14352
- if (
14353
- // Vite normalizes `options.file` so we use `path.resolve` for Windows compatibility
14354
- resolvedPluginConfig.configPaths.has(path9.resolve(options.file)) || hasAssetsConfigChanged(
14355
- resolvedPluginConfig,
14356
- resolvedViteConfig,
14357
- options.file
14358
- )
14359
- ) {
14440
+ const changedFilePath = path9.resolve(options.file);
14441
+ if (resolvedPluginConfig.configPaths.has(changedFilePath) || hasDotDevDotVarsFileChanged(resolvedPluginConfig, changedFilePath) || hasAssetsConfigChanged(
14442
+ resolvedPluginConfig,
14443
+ resolvedViteConfig,
14444
+ changedFilePath
14445
+ )) {
14360
14446
  options.server.restart();
14361
14447
  return [];
14362
14448
  }
14363
14449
  },
14364
14450
  async configureServer(viteDevServer) {
14365
- assert9(
14366
- viteDevServer.httpServer,
14367
- "Unexpected error: No Vite HTTP server"
14368
- );
14369
14451
  const inputInspectorPort = await getInputInspectorPortOption(
14370
14452
  pluginConfig,
14371
14453
  viteDevServer
14372
14454
  );
14373
- if (miniflare) {
14374
- await miniflare.setOptions(
14455
+ if (!miniflare) {
14456
+ miniflare = new Miniflare(
14375
14457
  getDevMiniflareOptions(
14376
14458
  resolvedPluginConfig,
14377
14459
  viteDevServer,
@@ -14379,7 +14461,7 @@ function cloudflare2(pluginConfig = {}) {
14379
14461
  )
14380
14462
  );
14381
14463
  } else {
14382
- miniflare = new Miniflare(
14464
+ await miniflare.setOptions(
14383
14465
  getDevMiniflareOptions(
14384
14466
  resolvedPluginConfig,
14385
14467
  viteDevServer,
@@ -14388,24 +14470,32 @@ function cloudflare2(pluginConfig = {}) {
14388
14470
  );
14389
14471
  }
14390
14472
  await initRunners(resolvedPluginConfig, viteDevServer, miniflare);
14391
- const middleware = createMiddleware(
14392
- async ({ request }) => {
14393
- assert9(miniflare, `Miniflare not defined`);
14473
+ if (viteDevServer.httpServer) {
14474
+ handleWebSocket(viteDevServer.httpServer, async () => {
14475
+ assert10(miniflare, `Miniflare not defined`);
14394
14476
  const routerWorker = await getRouterWorker(miniflare);
14395
- return routerWorker.fetch(toMiniflareRequest(request), {
14396
- redirect: "manual"
14397
- });
14398
- },
14399
- { alwaysCallNext: false }
14400
- );
14401
- handleWebSocket(viteDevServer.httpServer, async () => {
14402
- assert9(miniflare, `Miniflare not defined`);
14403
- const routerWorker = await getRouterWorker(miniflare);
14404
- return routerWorker.fetch;
14405
- });
14477
+ return routerWorker.fetch;
14478
+ });
14479
+ }
14406
14480
  return () => {
14407
- viteDevServer.middlewares.use((req, res, next) => {
14408
- middleware(req, res, next);
14481
+ viteDevServer.middlewares.use(async (req, res, next) => {
14482
+ try {
14483
+ assert10(miniflare, `Miniflare not defined`);
14484
+ const routerWorker = await getRouterWorker(miniflare);
14485
+ const request = createRequest(req, res);
14486
+ const response = await routerWorker.fetch(
14487
+ toMiniflareRequest(request),
14488
+ {
14489
+ redirect: "manual"
14490
+ }
14491
+ );
14492
+ if (req.httpVersionMajor === 2) {
14493
+ response.headers.delete("transfer-encoding");
14494
+ }
14495
+ await sendResponse(res, response);
14496
+ } catch (error) {
14497
+ next(error);
14498
+ }
14409
14499
  });
14410
14500
  };
14411
14501
  },
@@ -14423,20 +14513,24 @@ function cloudflare2(pluginConfig = {}) {
14423
14513
  inputInspectorPort
14424
14514
  )
14425
14515
  );
14426
- const middleware = createMiddleware(
14427
- ({ request }) => {
14428
- return miniflare2.dispatchFetch(toMiniflareRequest(request), {
14429
- redirect: "manual"
14430
- });
14431
- },
14432
- { alwaysCallNext: false }
14433
- );
14434
14516
  handleWebSocket(
14435
14517
  vitePreviewServer.httpServer,
14436
14518
  () => miniflare2.dispatchFetch
14437
14519
  );
14438
- vitePreviewServer.middlewares.use((req, res, next) => {
14439
- middleware(req, res, next);
14520
+ vitePreviewServer.middlewares.use(async (req, res, next) => {
14521
+ try {
14522
+ const request = createRequest(req, res);
14523
+ const response = await miniflare2.dispatchFetch(
14524
+ toMiniflareRequest(request),
14525
+ { redirect: "manual" }
14526
+ );
14527
+ if (req.httpVersionMajor === 2) {
14528
+ response.headers.delete("transfer-encoding");
14529
+ }
14530
+ await sendResponse(res, response);
14531
+ } catch (error) {
14532
+ next(error);
14533
+ }
14440
14534
  });
14441
14535
  }
14442
14536
  },
@@ -14499,7 +14593,7 @@ function cloudflare2(pluginConfig = {}) {
14499
14593
  for (const match of matches) {
14500
14594
  magicString ??= new MagicString(code);
14501
14595
  const [full, _, modulePath] = match;
14502
- assert9(
14596
+ assert10(
14503
14597
  modulePath,
14504
14598
  `Unexpected error: module path not found in reference ${full}.`
14505
14599
  );
@@ -14545,6 +14639,18 @@ function cloudflare2(pluginConfig = {}) {
14545
14639
  configEnvironment(name) {
14546
14640
  if (isNodeCompat(getWorkerConfig2(name))) {
14547
14641
  return {
14642
+ build: {
14643
+ rollupOptions: {
14644
+ plugins: [
14645
+ replace({
14646
+ "process.env.NODE_ENV": JSON.stringify(
14647
+ process.env.NODE_ENV ?? "production"
14648
+ ),
14649
+ preventAssignment: true
14650
+ })
14651
+ ]
14652
+ }
14653
+ },
14548
14654
  resolve: {
14549
14655
  builtins: [...nodeCompatExternals]
14550
14656
  },
@@ -14572,7 +14678,7 @@ function cloudflare2(pluginConfig = {}) {
14572
14678
  return this.resolve(source, importer, options);
14573
14679
  }
14574
14680
  if (this.environment.mode === "dev") {
14575
- assert9(
14681
+ assert10(
14576
14682
  this.environment.depsOptimizer,
14577
14683
  "depsOptimizer is required in dev mode"
14578
14684
  );
@@ -14586,7 +14692,9 @@ function cloudflare2(pluginConfig = {}) {
14586
14692
  },
14587
14693
  async transform(code, id) {
14588
14694
  const workerConfig = getWorkerConfig2(this.environment.name);
14589
- assert9(workerConfig, "Expected a worker config");
14695
+ if (!workerConfig) {
14696
+ return;
14697
+ }
14590
14698
  const resolvedId = await this.resolve(workerConfig.main);
14591
14699
  if (id === resolvedId?.id) {
14592
14700
  return injectGlobalCode(id, code);
@@ -14615,6 +14723,25 @@ function cloudflare2(pluginConfig = {}) {
14615
14723
  );
14616
14724
  }
14617
14725
  },
14726
+ // Plugin that handles Node.js Async Local Storage (ALS) compatibility support for Vite Environments that are hosted in Cloudflare Workers.
14727
+ {
14728
+ name: "vite-plugin-cloudflare:nodejs-als",
14729
+ apply(_config, env2) {
14730
+ return !env2.isPreview;
14731
+ },
14732
+ configEnvironment(name, config) {
14733
+ if (isNodeAls(getWorkerConfig2(name))) {
14734
+ return {
14735
+ resolve: {
14736
+ builtins: ["async_hooks", "node:async_hooks"]
14737
+ },
14738
+ optimizeDeps: {
14739
+ exclude: ["async_hooks", "node:async_hooks"]
14740
+ }
14741
+ };
14742
+ }
14743
+ }
14744
+ },
14618
14745
  // Plugin that provides an __debug path for debugging the Cloudflare Workers.
14619
14746
  {
14620
14747
  name: "vite-plugin-cloudflare:debug",
@@ -14644,7 +14771,7 @@ function cloudflare2(pluginConfig = {}) {
14644
14771
  addDebugToVitePrintUrls(vitePreviewServer);
14645
14772
  }
14646
14773
  const workerNames = workerConfigs.map((worker) => {
14647
- assert9(worker.name, "Expected the Worker to have a name");
14774
+ assert10(worker.name, "Expected the Worker to have a name");
14648
14775
  return worker.name;
14649
14776
  });
14650
14777
  vitePreviewServer.middlewares.use(async (req, res, next) => {
@@ -14680,6 +14807,9 @@ function cloudflare2(pluginConfig = {}) {
14680
14807
  build.onResolve(
14681
14808
  { filter: NODEJS_MODULES_RE },
14682
14809
  ({ path: path10, importer }) => {
14810
+ if (isNodeAls(workerConfig) && isNodeAlsModule(path10)) {
14811
+ return;
14812
+ }
14683
14813
  const nodeJsCompatWarnings = nodeJsCompatWarningsMap.get(workerConfig);
14684
14814
  nodeJsCompatWarnings?.registerImport(path10, importer);
14685
14815
  return { path: path10, external: true };
@@ -14709,6 +14839,9 @@ function cloudflare2(pluginConfig = {}) {
14709
14839
  async resolveId(source, importer) {
14710
14840
  const workerConfig = getWorkerConfig2(this.environment.name);
14711
14841
  if (workerConfig && !isNodeCompat(workerConfig)) {
14842
+ if (isNodeAls(workerConfig) && isNodeAlsModule(source)) {
14843
+ return;
14844
+ }
14712
14845
  const nodeJsCompatWarnings = nodeJsCompatWarningsMap.get(workerConfig);
14713
14846
  if (nodejsBuiltins.has(source)) {
14714
14847
  nodeJsCompatWarnings?.registerImport(source, importer);
@@ -14722,15 +14855,21 @@ function cloudflare2(pluginConfig = {}) {
14722
14855
  }
14723
14856
  ];
14724
14857
  function getWorkerConfig2(environmentName) {
14725
- assert9(resolvedPluginConfig, "Expected resolvedPluginConfig to be defined");
14858
+ assert10(resolvedPluginConfig, "Expected resolvedPluginConfig to be defined");
14726
14859
  return resolvedPluginConfig.type !== "assets-only" ? resolvedPluginConfig.workers[environmentName] : void 0;
14727
14860
  }
14728
14861
  }
14729
14862
  async function getInputInspectorPortOption(pluginConfig, viteServer) {
14863
+ if (pluginConfig.inspectorPort === void 0 || pluginConfig.inspectorPort === 0) {
14864
+ const resolvedInspectorPort = await getResolvedInspectorPort(pluginConfig);
14865
+ if (resolvedInspectorPort !== null) {
14866
+ return resolvedInspectorPort;
14867
+ }
14868
+ }
14730
14869
  const inputInspectorPort = pluginConfig.inspectorPort ?? await getFirstAvailablePort(DEFAULT_INSPECTOR_PORT);
14731
14870
  if (pluginConfig.inspectorPort === void 0 && inputInspectorPort !== DEFAULT_INSPECTOR_PORT) {
14732
14871
  viteServer.config.logger.warn(
14733
- colors2.dim(
14872
+ colors3.dim(
14734
14873
  `Default inspector port ${DEFAULT_INSPECTOR_PORT} not available, using ${inputInspectorPort} instead
14735
14874
  `
14736
14875
  )
@@ -14756,6 +14895,19 @@ function getDotDevDotVarsContent(configPath, cloudflareEnv) {
14756
14895
  }
14757
14896
  return null;
14758
14897
  }
14898
+ function hasDotDevDotVarsFileChanged(resolvedPluginConfig, changedFilePath) {
14899
+ return [...resolvedPluginConfig.configPaths].some((configPath) => {
14900
+ const dotDevDotVars = path9.join(path9.dirname(configPath), ".dev.vars");
14901
+ if (dotDevDotVars === changedFilePath) {
14902
+ return true;
14903
+ }
14904
+ if (resolvedPluginConfig.cloudflareEnv) {
14905
+ const dotDevDotVarsForEnv = `${dotDevDotVars}.${resolvedPluginConfig.cloudflareEnv}`;
14906
+ return dotDevDotVarsForEnv === changedFilePath;
14907
+ }
14908
+ return false;
14909
+ });
14910
+ }
14759
14911
  export {
14760
14912
  cloudflare2 as cloudflare
14761
14913
  };
@@ -29,7 +29,7 @@ function stripInternalEnv(internalEnv) {
29
29
  return userEnv;
30
30
  }
31
31
 
32
- // ../../node_modules/.pnpm/vite@6.1.0_@types+node@18.19.76_jiti@2.4.2_lightningcss@1.29.2/node_modules/vite/dist/node/module-runner.js
32
+ // ../../node_modules/.pnpm/vite@6.1.0_@types+node@20.17.32_jiti@2.4.2_lightningcss@1.29.2/node_modules/vite/dist/node/module-runner.js
33
33
  var VALID_ID_PREFIX = "/@id/";
34
34
  var NULL_BYTE_PLACEHOLDER = "__x00__";
35
35
  var SOURCEMAPPING_URL = "sourceMa";
@@ -1394,13 +1394,6 @@ async function createModuleRunner(env, webSocket, viteRoot) {
1394
1394
  },
1395
1395
  {
1396
1396
  async runInlinedModule(context, transformed, module) {
1397
- if (module.file.includes("/node_modules") && !module.file.includes("/node_modules/.vite")) {
1398
- throw new Error(
1399
- `[Error] Trying to import non-prebundled module (only prebundled modules are allowed): ${module.id}
1400
-
1401
- (have you excluded the module via \`optimizeDeps.exclude\`?)`
1402
- );
1403
- }
1404
1397
  const codeDefinition = `'use strict';async (${Object.keys(context).join(
1405
1398
  ","
1406
1399
  )})=>{{`;
@@ -1426,13 +1419,6 @@ async function createModuleRunner(env, webSocket, viteRoot) {
1426
1419
  )
1427
1420
  });
1428
1421
  }
1429
- if (!additionalModuleRE.test(filepath) && filepath.includes("/node_modules") && !filepath.includes("/node_modules/.vite")) {
1430
- throw new Error(
1431
- `[Error] Trying to import non-prebundled module (only prebundled modules are allowed): ${filepath}
1432
-
1433
- (have you externalized the module via \`resolve.external\`?)`
1434
- );
1435
- }
1436
1422
  filepath = filepath.replace(/^file:\/\//, "");
1437
1423
  return import(filepath);
1438
1424
  }
@@ -1449,20 +1435,21 @@ async function getWorkerEntryExport(path, entrypoint) {
1449
1435
  }
1450
1436
 
1451
1437
  // src/runner-worker/index.ts
1438
+ var IGNORED_KEYS = ["self", "tailStream"];
1452
1439
  var WORKER_ENTRYPOINT_KEYS = [
1453
1440
  "fetch",
1441
+ "queue",
1454
1442
  "tail",
1443
+ "test",
1455
1444
  "trace",
1456
- "scheduled",
1457
- "queue",
1458
- "test"
1445
+ "scheduled"
1459
1446
  ];
1460
1447
  var DURABLE_OBJECT_KEYS = [
1461
- "fetch",
1462
1448
  "alarm",
1463
- "webSocketMessage",
1449
+ "fetch",
1464
1450
  "webSocketClose",
1465
- "webSocketError"
1451
+ "webSocketError",
1452
+ "webSocketMessage"
1466
1453
  ];
1467
1454
  var WORKFLOW_ENTRYPOINT_KEYS = ["run"];
1468
1455
  var entryPath = "";
@@ -1527,7 +1514,7 @@ function createWorkerEntrypointWrapper(entrypoint) {
1527
1514
  if (value !== void 0) {
1528
1515
  return value;
1529
1516
  }
1530
- if (key === "self" || typeof key === "symbol" || DURABLE_OBJECT_KEYS.includes(key)) {
1517
+ if (typeof key === "symbol" || IGNORED_KEYS.includes(key) || DURABLE_OBJECT_KEYS.includes(key)) {
1531
1518
  return;
1532
1519
  }
1533
1520
  const property = getWorkerEntrypointRpcProperty.call(
@@ -1625,7 +1612,7 @@ function createDurableObjectWrapper(className) {
1625
1612
  if (value !== void 0) {
1626
1613
  return value;
1627
1614
  }
1628
- if (key === "self" || typeof key === "symbol" || WORKER_ENTRYPOINT_KEYS.includes(key)) {
1615
+ if (typeof key === "symbol" || IGNORED_KEYS.includes(key) || WORKER_ENTRYPOINT_KEYS.includes(key)) {
1629
1616
  return;
1630
1617
  }
1631
1618
  const property = getDurableObjectRpcProperty.call(