@cloudflare/vite-plugin 1.0.5 → 1.0.6

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 +37 -0
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -12880,6 +12880,15 @@ function isNodeCompat(workerConfig) {
12880
12880
  }
12881
12881
  return false;
12882
12882
  }
12883
+ function isNodeAls(workerConfig) {
12884
+ return workerConfig !== void 0 && getNodeCompat(
12885
+ workerConfig.compatibility_date,
12886
+ workerConfig.compatibility_flags ?? []
12887
+ ).mode === "als";
12888
+ }
12889
+ function isNodeAlsModule(path10) {
12890
+ return /^(node:)?async_hooks$/.test(path10);
12891
+ }
12883
12892
  function injectGlobalCode(id, code) {
12884
12893
  const injectedCode = Object.entries(env.inject).map(([globalName, globalInject]) => {
12885
12894
  if (typeof globalInject === "string") {
@@ -14187,6 +14196,9 @@ function validateWorkerEnvironmentsResolvedConfigs(resolvedPluginConfig, resolve
14187
14196
  if (cloudflareBuiltInModules.includes(entry)) {
14188
14197
  return false;
14189
14198
  }
14199
+ if (isNodeAlsModule(entry) && isNodeAls(resolvedPluginConfig.workers[envName])) {
14200
+ return false;
14201
+ }
14190
14202
  if (NODEJS_MODULES_RE.test(entry) && isNodeCompat(resolvedPluginConfig.workers[envName])) {
14191
14203
  return false;
14192
14204
  }
@@ -14681,6 +14693,25 @@ function cloudflare2(pluginConfig = {}) {
14681
14693
  );
14682
14694
  }
14683
14695
  },
14696
+ // Plugin that handles Node.js Async Local Storage (ALS) compatibility support for Vite Environments that are hosted in Cloudflare Workers.
14697
+ {
14698
+ name: "vite-plugin-cloudflare:nodejs-als",
14699
+ apply(_config, env2) {
14700
+ return !env2.isPreview;
14701
+ },
14702
+ configEnvironment(name, config) {
14703
+ if (isNodeAls(getWorkerConfig2(name))) {
14704
+ return {
14705
+ resolve: {
14706
+ builtins: ["async_hooks", "node:async_hooks"]
14707
+ },
14708
+ optimizeDeps: {
14709
+ exclude: ["async_hooks", "node:async_hooks"]
14710
+ }
14711
+ };
14712
+ }
14713
+ }
14714
+ },
14684
14715
  // Plugin that provides an __debug path for debugging the Cloudflare Workers.
14685
14716
  {
14686
14717
  name: "vite-plugin-cloudflare:debug",
@@ -14746,6 +14777,9 @@ function cloudflare2(pluginConfig = {}) {
14746
14777
  build.onResolve(
14747
14778
  { filter: NODEJS_MODULES_RE },
14748
14779
  ({ path: path10, importer }) => {
14780
+ if (isNodeAls(workerConfig) && isNodeAlsModule(path10)) {
14781
+ return;
14782
+ }
14749
14783
  const nodeJsCompatWarnings = nodeJsCompatWarningsMap.get(workerConfig);
14750
14784
  nodeJsCompatWarnings?.registerImport(path10, importer);
14751
14785
  return { path: path10, external: true };
@@ -14775,6 +14809,9 @@ function cloudflare2(pluginConfig = {}) {
14775
14809
  async resolveId(source, importer) {
14776
14810
  const workerConfig = getWorkerConfig2(this.environment.name);
14777
14811
  if (workerConfig && !isNodeCompat(workerConfig)) {
14812
+ if (isNodeAls(workerConfig) && isNodeAlsModule(source)) {
14813
+ return;
14814
+ }
14778
14815
  const nodeJsCompatWarnings = nodeJsCompatWarningsMap.get(workerConfig);
14779
14816
  if (nodejsBuiltins.has(source)) {
14780
14817
  nodeJsCompatWarnings?.registerImport(source, importer);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudflare/vite-plugin",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "Cloudflare plugin for Vite",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -41,11 +41,11 @@
41
41
  "unenv": "2.0.0-rc.15",
42
42
  "ws": "8.18.0",
43
43
  "@cloudflare/unenv-preset": "2.3.1",
44
- "miniflare": "4.20250409.0",
45
- "wrangler": "4.10.0"
44
+ "miniflare": "4.20250410.0",
45
+ "wrangler": "4.11.0"
46
46
  },
47
47
  "devDependencies": {
48
- "@cloudflare/workers-types": "^4.20250409.0",
48
+ "@cloudflare/workers-types": "^4.20250410.0",
49
49
  "@types/node": "^22.10.1",
50
50
  "@types/ws": "^8.5.13",
51
51
  "magic-string": "^0.30.12",