@cloudflare/vite-plugin 0.0.0-8b510e896 → 0.0.0-8c313f145

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
@@ -489,7 +489,8 @@ 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
@@ -1588,7 +1589,7 @@ function matchAdditionalModule(source) {
1588
1589
  return null;
1589
1590
  }
1590
1591
  function createModuleReference(type, id) {
1591
- return `__CLOUDFLARE_MODULE__${type}__${id}__`;
1592
+ return `__CLOUDFLARE_MODULE__${type}__${id}__CLOUDFLARE_MODULE__`;
1592
1593
  }
1593
1594
 
1594
1595
  // src/asset-config.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 })
@@ -12982,7 +12993,7 @@ var NodeJsCompatWarnings = class {
12982
12993
  // src/shared.ts
12983
12994
  var UNKNOWN_HOST = "http://localhost";
12984
12995
  var INIT_PATH = "/__vite_plugin_cloudflare_init__";
12985
- var ADDITIONAL_MODULE_PATTERN = `__CLOUDFLARE_MODULE__(${ADDITIONAL_MODULE_TYPES.join("|")})__(.*?)__`;
12996
+ var ADDITIONAL_MODULE_PATTERN = `__CLOUDFLARE_MODULE__(${ADDITIONAL_MODULE_TYPES.join("|")})__(.*?)__CLOUDFLARE_MODULE__`;
12986
12997
  var additionalModuleRE = new RegExp(ADDITIONAL_MODULE_PATTERN);
12987
12998
  var additionalModuleGlobalRE = new RegExp(
12988
12999
  ADDITIONAL_MODULE_PATTERN,
@@ -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,12 +13342,13 @@ 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";
13350
- function getPersistence(root, persistState) {
13349
+ function getPersistenceRoot(root, persistState) {
13351
13350
  if (persistState === false) {
13352
- return {};
13351
+ return;
13353
13352
  }
13354
13353
  const defaultPersistPath = ".wrangler/state";
13355
13354
  const persistPath = path6.resolve(
@@ -13357,14 +13356,7 @@ function getPersistence(root, persistState) {
13357
13356
  typeof persistState === "object" ? persistState.path : defaultPersistPath,
13358
13357
  "v3"
13359
13358
  );
13360
- return {
13361
- cachePersist: path6.join(persistPath, "cache"),
13362
- d1Persist: path6.join(persistPath, "d1"),
13363
- durableObjectsPersist: path6.join(persistPath, "do"),
13364
- kvPersist: path6.join(persistPath, "kv"),
13365
- r2Persist: path6.join(persistPath, "r2"),
13366
- workflowsPersist: path6.join(persistPath, "workflows")
13367
- };
13359
+ return persistPath;
13368
13360
  }
13369
13361
  function missingWorkerErrorMessage(workerName) {
13370
13362
  return `${workerName} does not match a worker name.`;
@@ -13448,6 +13440,29 @@ function getEntryWorkerConfig(resolvedPluginConfig) {
13448
13440
  }
13449
13441
  return resolvedPluginConfig.workers[resolvedPluginConfig.entryWorkerEnvironmentName];
13450
13442
  }
13443
+ function filterTails(tails, userWorkers, log) {
13444
+ return tails?.filter((tailService) => {
13445
+ let name;
13446
+ if (typeof tailService === "string") {
13447
+ name = tailService;
13448
+ } else if (typeof tailService === "object" && "name" in tailService && typeof tailService.name === "string") {
13449
+ name = tailService.name;
13450
+ } else {
13451
+ return true;
13452
+ }
13453
+ const found = userWorkers.some((w) => w.name === name);
13454
+ if (!found) {
13455
+ log(
13456
+ colors2.dim(
13457
+ colors2.yellow(
13458
+ `Tail consumer "${name}" was not found in your config. Make sure you add it if you'd like to simulate receiving tail events locally.`
13459
+ )
13460
+ )
13461
+ );
13462
+ }
13463
+ return found;
13464
+ });
13465
+ }
13451
13466
  function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspectorPort) {
13452
13467
  const resolvedViteConfig = viteDevServer.config;
13453
13468
  const entryWorkerConfig = getEntryWorkerConfig(resolvedPluginConfig);
@@ -13591,7 +13606,7 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspectorPo
13591
13606
  (error) => logger.logWithLevel(LogLevel.ERROR, decoder.decode(error))
13592
13607
  );
13593
13608
  },
13594
- ...getPersistence(
13609
+ defaultPersistRoot: getPersistenceRoot(
13595
13610
  resolvedViteConfig.root,
13596
13611
  resolvedPluginConfig.persistState
13597
13612
  ),
@@ -13639,6 +13654,11 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspectorPo
13639
13654
  }
13640
13655
  return {
13641
13656
  ...workerOptions,
13657
+ tails: filterTails(
13658
+ workerOptions.tails,
13659
+ userWorkers,
13660
+ viteDevServer.config.logger.warn
13661
+ ),
13642
13662
  modules: [
13643
13663
  {
13644
13664
  type: "ESModule",
@@ -13729,6 +13749,11 @@ function getPreviewMiniflareOptions(vitePreviewServer, workerConfigs, persistSta
13729
13749
  return [
13730
13750
  {
13731
13751
  ...workerOptions,
13752
+ tails: filterTails(
13753
+ workerOptions.tails,
13754
+ workerConfigs,
13755
+ vitePreviewServer.config.logger.warn
13756
+ ),
13732
13757
  name: workerOptions.name ?? config.name,
13733
13758
  unsafeInspectorProxy: inspectorPort !== false,
13734
13759
  ...miniflareWorkerOptions.main ? getPreviewModules(miniflareWorkerOptions.main, modulesRules) : { modules: true, script: "" }
@@ -13748,7 +13773,10 @@ function getPreviewMiniflareOptions(vitePreviewServer, workerConfigs, persistSta
13748
13773
  (error) => logger.logWithLevel(LogLevel.ERROR, decoder.decode(error))
13749
13774
  );
13750
13775
  },
13751
- ...getPersistence(resolvedViteConfig.root, persistState),
13776
+ defaultPersistRoot: getPersistenceRoot(
13777
+ resolvedViteConfig.root,
13778
+ persistState
13779
+ ),
13752
13780
  workers
13753
13781
  };
13754
13782
  }
@@ -13828,8 +13856,7 @@ var nonApplicableWorkerConfigs = {
13828
13856
  "preserve_file_names",
13829
13857
  "rules",
13830
13858
  "site",
13831
- "tsconfig",
13832
- "upload_source_maps"
13859
+ "tsconfig"
13833
13860
  ]
13834
13861
  };
13835
13862
  var nullableNonApplicable = [
@@ -13840,8 +13867,7 @@ var nullableNonApplicable = [
13840
13867
  "no_bundle",
13841
13868
  "preserve_file_names",
13842
13869
  "site",
13843
- "tsconfig",
13844
- "upload_source_maps"
13870
+ "tsconfig"
13845
13871
  ];
13846
13872
  function readWorkerConfig(configPath, env2) {
13847
13873
  const nonApplicable = {
@@ -14139,6 +14165,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
14139
14165
  }
14140
14166
 
14141
14167
  // src/websockets.ts
14168
+ import { createHeaders } from "@mjackson/node-fetch-server";
14142
14169
  import { coupleWebSocket } from "miniflare";
14143
14170
  import { WebSocketServer } from "ws";
14144
14171
  function handleWebSocket(httpServer, getFetcher) {
@@ -14150,7 +14177,7 @@ function handleWebSocket(httpServer, getFetcher) {
14150
14177
  if (request.headers["sec-websocket-protocol"]?.startsWith("vite")) {
14151
14178
  return;
14152
14179
  }
14153
- const headers = nodeHeadersToWebHeaders(request.headers);
14180
+ const headers = createHeaders(request);
14154
14181
  const fetcher = await getFetcher();
14155
14182
  const response = await fetcher(url, {
14156
14183
  headers,
@@ -14182,12 +14209,15 @@ function validateWorkerEnvironmentsResolvedConfigs(resolvedPluginConfig, resolve
14182
14209
  for (const envName of workersEnvironmentNames) {
14183
14210
  const workerEnvConfig = resolvedViteConfig.environments[envName];
14184
14211
  assert9(workerEnvConfig, `Missing environment config for "${envName}"`);
14185
- const { optimizeDeps, resolve: resolve8 } = workerEnvConfig;
14212
+ const { optimizeDeps, resolve: resolve7 } = workerEnvConfig;
14186
14213
  const disallowedConfig = {};
14187
14214
  const disallowedOptimizeDepsExcludeEntries = (optimizeDeps.exclude ?? []).filter((entry) => {
14188
14215
  if (cloudflareBuiltInModules.includes(entry)) {
14189
14216
  return false;
14190
14217
  }
14218
+ if (isNodeAlsModule(entry) && isNodeAls(resolvedPluginConfig.workers[envName])) {
14219
+ return false;
14220
+ }
14191
14221
  if (NODEJS_MODULES_RE.test(entry) && isNodeCompat(resolvedPluginConfig.workers[envName])) {
14192
14222
  return false;
14193
14223
  }
@@ -14196,8 +14226,8 @@ function validateWorkerEnvironmentsResolvedConfigs(resolvedPluginConfig, resolve
14196
14226
  if (disallowedOptimizeDepsExcludeEntries.length > 0) {
14197
14227
  disallowedConfig.optimizeDepsExclude = disallowedOptimizeDepsExcludeEntries;
14198
14228
  }
14199
- if (resolve8.external === true || resolve8.external.length > 0) {
14200
- disallowedConfig.resolveExternal = resolve8.external;
14229
+ if (resolve7.external === true || resolve7.external.length > 0) {
14230
+ disallowedConfig.resolveExternal = resolve7.external;
14201
14231
  }
14202
14232
  if (Object.keys(disallowedConfig).length > 0) {
14203
14233
  disallowedEnvsConfigs.set(envName, disallowedConfig);
@@ -14403,29 +14433,23 @@ function cloudflare2(pluginConfig = {}) {
14403
14433
  }
14404
14434
  },
14405
14435
  hotUpdate(options) {
14406
- if (
14407
- // Vite normalizes `options.file` so we use `path.resolve` for Windows compatibility
14408
- resolvedPluginConfig.configPaths.has(path9.resolve(options.file)) || hasAssetsConfigChanged(
14409
- resolvedPluginConfig,
14410
- resolvedViteConfig,
14411
- options.file
14412
- )
14413
- ) {
14436
+ const changedFilePath = path9.resolve(options.file);
14437
+ if (resolvedPluginConfig.configPaths.has(changedFilePath) || hasDotDevDotVarsFileChanged(resolvedPluginConfig, changedFilePath) || hasAssetsConfigChanged(
14438
+ resolvedPluginConfig,
14439
+ resolvedViteConfig,
14440
+ changedFilePath
14441
+ )) {
14414
14442
  options.server.restart();
14415
14443
  return [];
14416
14444
  }
14417
14445
  },
14418
14446
  async configureServer(viteDevServer) {
14419
- assert10(
14420
- viteDevServer.httpServer,
14421
- "Unexpected error: No Vite HTTP server"
14422
- );
14423
14447
  const inputInspectorPort = await getInputInspectorPortOption(
14424
14448
  pluginConfig,
14425
14449
  viteDevServer
14426
14450
  );
14427
- if (miniflare) {
14428
- await miniflare.setOptions(
14451
+ if (!miniflare) {
14452
+ miniflare = new Miniflare(
14429
14453
  getDevMiniflareOptions(
14430
14454
  resolvedPluginConfig,
14431
14455
  viteDevServer,
@@ -14433,7 +14457,7 @@ function cloudflare2(pluginConfig = {}) {
14433
14457
  )
14434
14458
  );
14435
14459
  } else {
14436
- miniflare = new Miniflare(
14460
+ await miniflare.setOptions(
14437
14461
  getDevMiniflareOptions(
14438
14462
  resolvedPluginConfig,
14439
14463
  viteDevServer,
@@ -14442,24 +14466,32 @@ function cloudflare2(pluginConfig = {}) {
14442
14466
  );
14443
14467
  }
14444
14468
  await initRunners(resolvedPluginConfig, viteDevServer, miniflare);
14445
- const middleware = createMiddleware(
14446
- async ({ request }) => {
14469
+ if (viteDevServer.httpServer) {
14470
+ handleWebSocket(viteDevServer.httpServer, async () => {
14447
14471
  assert10(miniflare, `Miniflare not defined`);
14448
14472
  const routerWorker = await getRouterWorker(miniflare);
14449
- return routerWorker.fetch(toMiniflareRequest(request), {
14450
- redirect: "manual"
14451
- });
14452
- },
14453
- { alwaysCallNext: false }
14454
- );
14455
- handleWebSocket(viteDevServer.httpServer, async () => {
14456
- assert10(miniflare, `Miniflare not defined`);
14457
- const routerWorker = await getRouterWorker(miniflare);
14458
- return routerWorker.fetch;
14459
- });
14473
+ return routerWorker.fetch;
14474
+ });
14475
+ }
14460
14476
  return () => {
14461
- viteDevServer.middlewares.use((req, res, next) => {
14462
- middleware(req, res, next);
14477
+ viteDevServer.middlewares.use(async (req, res, next) => {
14478
+ try {
14479
+ assert10(miniflare, `Miniflare not defined`);
14480
+ const routerWorker = await getRouterWorker(miniflare);
14481
+ const request = createRequest(req, res);
14482
+ const response = await routerWorker.fetch(
14483
+ toMiniflareRequest(request),
14484
+ {
14485
+ redirect: "manual"
14486
+ }
14487
+ );
14488
+ if (req.httpVersionMajor === 2) {
14489
+ response.headers.delete("transfer-encoding");
14490
+ }
14491
+ await sendResponse(res, response);
14492
+ } catch (error) {
14493
+ next(error);
14494
+ }
14463
14495
  });
14464
14496
  };
14465
14497
  },
@@ -14477,20 +14509,24 @@ function cloudflare2(pluginConfig = {}) {
14477
14509
  inputInspectorPort
14478
14510
  )
14479
14511
  );
14480
- const middleware = createMiddleware(
14481
- ({ request }) => {
14482
- return miniflare2.dispatchFetch(toMiniflareRequest(request), {
14483
- redirect: "manual"
14484
- });
14485
- },
14486
- { alwaysCallNext: false }
14487
- );
14488
14512
  handleWebSocket(
14489
14513
  vitePreviewServer.httpServer,
14490
14514
  () => miniflare2.dispatchFetch
14491
14515
  );
14492
- vitePreviewServer.middlewares.use((req, res, next) => {
14493
- middleware(req, res, next);
14516
+ vitePreviewServer.middlewares.use(async (req, res, next) => {
14517
+ try {
14518
+ const request = createRequest(req, res);
14519
+ const response = await miniflare2.dispatchFetch(
14520
+ toMiniflareRequest(request),
14521
+ { redirect: "manual" }
14522
+ );
14523
+ if (req.httpVersionMajor === 2) {
14524
+ response.headers.delete("transfer-encoding");
14525
+ }
14526
+ await sendResponse(res, response);
14527
+ } catch (error) {
14528
+ next(error);
14529
+ }
14494
14530
  });
14495
14531
  }
14496
14532
  },
@@ -14599,6 +14635,18 @@ function cloudflare2(pluginConfig = {}) {
14599
14635
  configEnvironment(name) {
14600
14636
  if (isNodeCompat(getWorkerConfig2(name))) {
14601
14637
  return {
14638
+ build: {
14639
+ rollupOptions: {
14640
+ plugins: [
14641
+ replace({
14642
+ "process.env.NODE_ENV": JSON.stringify(
14643
+ process.env.NODE_ENV ?? "production"
14644
+ ),
14645
+ preventAssignment: true
14646
+ })
14647
+ ]
14648
+ }
14649
+ },
14602
14650
  resolve: {
14603
14651
  builtins: [...nodeCompatExternals]
14604
14652
  },
@@ -14640,7 +14688,9 @@ function cloudflare2(pluginConfig = {}) {
14640
14688
  },
14641
14689
  async transform(code, id) {
14642
14690
  const workerConfig = getWorkerConfig2(this.environment.name);
14643
- assert10(workerConfig, "Expected a worker config");
14691
+ if (!workerConfig) {
14692
+ return;
14693
+ }
14644
14694
  const resolvedId = await this.resolve(workerConfig.main);
14645
14695
  if (id === resolvedId?.id) {
14646
14696
  return injectGlobalCode(id, code);
@@ -14669,6 +14719,25 @@ function cloudflare2(pluginConfig = {}) {
14669
14719
  );
14670
14720
  }
14671
14721
  },
14722
+ // Plugin that handles Node.js Async Local Storage (ALS) compatibility support for Vite Environments that are hosted in Cloudflare Workers.
14723
+ {
14724
+ name: "vite-plugin-cloudflare:nodejs-als",
14725
+ apply(_config, env2) {
14726
+ return !env2.isPreview;
14727
+ },
14728
+ configEnvironment(name, config) {
14729
+ if (isNodeAls(getWorkerConfig2(name))) {
14730
+ return {
14731
+ resolve: {
14732
+ builtins: ["async_hooks", "node:async_hooks"]
14733
+ },
14734
+ optimizeDeps: {
14735
+ exclude: ["async_hooks", "node:async_hooks"]
14736
+ }
14737
+ };
14738
+ }
14739
+ }
14740
+ },
14672
14741
  // Plugin that provides an __debug path for debugging the Cloudflare Workers.
14673
14742
  {
14674
14743
  name: "vite-plugin-cloudflare:debug",
@@ -14734,6 +14803,9 @@ function cloudflare2(pluginConfig = {}) {
14734
14803
  build.onResolve(
14735
14804
  { filter: NODEJS_MODULES_RE },
14736
14805
  ({ path: path10, importer }) => {
14806
+ if (isNodeAls(workerConfig) && isNodeAlsModule(path10)) {
14807
+ return;
14808
+ }
14737
14809
  const nodeJsCompatWarnings = nodeJsCompatWarningsMap.get(workerConfig);
14738
14810
  nodeJsCompatWarnings?.registerImport(path10, importer);
14739
14811
  return { path: path10, external: true };
@@ -14763,6 +14835,9 @@ function cloudflare2(pluginConfig = {}) {
14763
14835
  async resolveId(source, importer) {
14764
14836
  const workerConfig = getWorkerConfig2(this.environment.name);
14765
14837
  if (workerConfig && !isNodeCompat(workerConfig)) {
14838
+ if (isNodeAls(workerConfig) && isNodeAlsModule(source)) {
14839
+ return;
14840
+ }
14766
14841
  const nodeJsCompatWarnings = nodeJsCompatWarningsMap.get(workerConfig);
14767
14842
  if (nodejsBuiltins.has(source)) {
14768
14843
  nodeJsCompatWarnings?.registerImport(source, importer);
@@ -14781,10 +14856,16 @@ function cloudflare2(pluginConfig = {}) {
14781
14856
  }
14782
14857
  }
14783
14858
  async function getInputInspectorPortOption(pluginConfig, viteServer) {
14859
+ if (pluginConfig.inspectorPort === void 0 || pluginConfig.inspectorPort === 0) {
14860
+ const resolvedInspectorPort = await getResolvedInspectorPort(pluginConfig);
14861
+ if (resolvedInspectorPort !== null) {
14862
+ return resolvedInspectorPort;
14863
+ }
14864
+ }
14784
14865
  const inputInspectorPort = pluginConfig.inspectorPort ?? await getFirstAvailablePort(DEFAULT_INSPECTOR_PORT);
14785
14866
  if (pluginConfig.inspectorPort === void 0 && inputInspectorPort !== DEFAULT_INSPECTOR_PORT) {
14786
14867
  viteServer.config.logger.warn(
14787
- colors2.dim(
14868
+ colors3.dim(
14788
14869
  `Default inspector port ${DEFAULT_INSPECTOR_PORT} not available, using ${inputInspectorPort} instead
14789
14870
  `
14790
14871
  )
@@ -14810,6 +14891,19 @@ function getDotDevDotVarsContent(configPath, cloudflareEnv) {
14810
14891
  }
14811
14892
  return null;
14812
14893
  }
14894
+ function hasDotDevDotVarsFileChanged(resolvedPluginConfig, changedFilePath) {
14895
+ return [...resolvedPluginConfig.configPaths].some((configPath) => {
14896
+ const dotDevDotVars = path9.join(path9.dirname(configPath), ".dev.vars");
14897
+ if (dotDevDotVars === changedFilePath) {
14898
+ return true;
14899
+ }
14900
+ if (resolvedPluginConfig.cloudflareEnv) {
14901
+ const dotDevDotVarsForEnv = `${dotDevDotVars}.${resolvedPluginConfig.cloudflareEnv}`;
14902
+ return dotDevDotVarsForEnv === changedFilePath;
14903
+ }
14904
+ return false;
14905
+ });
14906
+ }
14813
14907
  export {
14814
14908
  cloudflare2 as cloudflare
14815
14909
  };
@@ -15,7 +15,7 @@ var ADDITIONAL_MODULE_TYPES = [
15
15
  // src/shared.ts
16
16
  var UNKNOWN_HOST = "http://localhost";
17
17
  var INIT_PATH = "/__vite_plugin_cloudflare_init__";
18
- var ADDITIONAL_MODULE_PATTERN = `__CLOUDFLARE_MODULE__(${ADDITIONAL_MODULE_TYPES.join("|")})__(.*?)__`;
18
+ var ADDITIONAL_MODULE_PATTERN = `__CLOUDFLARE_MODULE__(${ADDITIONAL_MODULE_TYPES.join("|")})__(.*?)__CLOUDFLARE_MODULE__`;
19
19
  var additionalModuleRE = new RegExp(ADDITIONAL_MODULE_PATTERN);
20
20
  var additionalModuleGlobalRE = new RegExp(
21
21
  ADDITIONAL_MODULE_PATTERN,
@@ -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";
@@ -1435,20 +1435,21 @@ async function getWorkerEntryExport(path, entrypoint) {
1435
1435
  }
1436
1436
 
1437
1437
  // src/runner-worker/index.ts
1438
+ var IGNORED_KEYS = ["self", "tailStream"];
1438
1439
  var WORKER_ENTRYPOINT_KEYS = [
1439
1440
  "fetch",
1441
+ "queue",
1440
1442
  "tail",
1443
+ "test",
1441
1444
  "trace",
1442
- "scheduled",
1443
- "queue",
1444
- "test"
1445
+ "scheduled"
1445
1446
  ];
1446
1447
  var DURABLE_OBJECT_KEYS = [
1447
- "fetch",
1448
1448
  "alarm",
1449
- "webSocketMessage",
1449
+ "fetch",
1450
1450
  "webSocketClose",
1451
- "webSocketError"
1451
+ "webSocketError",
1452
+ "webSocketMessage"
1452
1453
  ];
1453
1454
  var WORKFLOW_ENTRYPOINT_KEYS = ["run"];
1454
1455
  var entryPath = "";
@@ -1513,7 +1514,7 @@ function createWorkerEntrypointWrapper(entrypoint) {
1513
1514
  if (value !== void 0) {
1514
1515
  return value;
1515
1516
  }
1516
- 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)) {
1517
1518
  return;
1518
1519
  }
1519
1520
  const property = getWorkerEntrypointRpcProperty.call(
@@ -1611,7 +1612,7 @@ function createDurableObjectWrapper(className) {
1611
1612
  if (value !== void 0) {
1612
1613
  return value;
1613
1614
  }
1614
- 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)) {
1615
1616
  return;
1616
1617
  }
1617
1618
  const property = getDurableObjectRpcProperty.call(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudflare/vite-plugin",
3
- "version": "0.0.0-8b510e896",
3
+ "version": "0.0.0-8c313f145",
4
4
  "description": "Cloudflare plugin for Vite",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -33,18 +33,19 @@
33
33
  "dist"
34
34
  ],
35
35
  "dependencies": {
36
- "@hattip/adapter-node": "^0.0.49",
36
+ "@cloudflare/unenv-preset": "2.3.2",
37
+ "@mjackson/node-fetch-server": "^0.6.1",
38
+ "@rollup/plugin-replace": "^6.0.1",
37
39
  "get-port": "^7.1.0",
38
40
  "picocolors": "^1.1.1",
39
41
  "tinyglobby": "^0.2.12",
40
- "unenv": "2.0.0-rc.15",
42
+ "unenv": "2.0.0-rc.17",
41
43
  "ws": "8.18.0",
42
- "@cloudflare/unenv-preset": "0.0.0-8b510e896",
43
- "miniflare": "0.0.0-8b510e896",
44
- "wrangler": "0.0.0-8b510e896"
44
+ "miniflare": "0.0.0-8c313f145",
45
+ "wrangler": "0.0.0-8c313f145"
45
46
  },
46
47
  "devDependencies": {
47
- "@cloudflare/workers-types": "^4.20250321.0",
48
+ "@cloudflare/workers-types": "^4.20250525.0",
48
49
  "@types/node": "^22.10.1",
49
50
  "@types/ws": "^8.5.13",
50
51
  "magic-string": "^0.30.12",
@@ -53,10 +54,10 @@
53
54
  "typescript": "^5.7.2",
54
55
  "undici": "^5.28.5",
55
56
  "vite": "^6.1.0",
56
- "vitest": "~3.0.8",
57
- "@cloudflare/mock-npm-registry": "0.0.0",
57
+ "vitest": "~3.1.1",
58
58
  "@cloudflare/workers-tsconfig": "0.0.0",
59
- "@cloudflare/workers-shared": "0.0.0-8b510e896"
59
+ "@cloudflare/workers-shared": "0.0.0-8c313f145",
60
+ "@cloudflare/mock-npm-registry": "0.0.0"
60
61
  },
61
62
  "peerDependencies": {
62
63
  "vite": "^6.1.0",