@cloudflare/vite-plugin 0.1.7 → 0.1.9

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.
package/dist/index.js CHANGED
@@ -1370,6 +1370,7 @@ import {
1370
1370
  LogLevel,
1371
1371
  Response as MiniflareResponse
1372
1372
  } from "miniflare";
1373
+ import { globSync } from "tinyglobby";
1373
1374
  import "vite";
1374
1375
  import {
1375
1376
  unstable_getMiniflareWorkerOptions,
@@ -1656,7 +1657,7 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer) {
1656
1657
  const workflowEntrypointClassNames = workerToWorkflowEntrypointClassNamesMap.get(workerOptions.name);
1657
1658
  assert4(
1658
1659
  workflowEntrypointClassNames,
1659
- `WorkflowEntrypoint class names not found for worker ${workerOptions.name}`
1660
+ `WorkflowEntrypoint class names not found for worker: ${workerOptions.name}`
1660
1661
  );
1661
1662
  for (const className of [...workflowEntrypointClassNames].sort()) {
1662
1663
  wrappers.push(
@@ -1692,17 +1693,19 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer) {
1692
1693
  );
1693
1694
  const moduleRE = new RegExp(MODULE_PATTERN);
1694
1695
  const match = moduleRE.exec(rawSpecifier);
1695
- assert4(match, `Unexpected error: no match for module ${rawSpecifier}.`);
1696
+ assert4(match, `Unexpected error: no match for module: ${rawSpecifier}.`);
1696
1697
  const [full, moduleType, modulePath] = match;
1697
1698
  assert4(
1698
1699
  modulePath,
1699
- `Unexpected error: module path not found in reference ${full}.`
1700
+ `Unexpected error: module path not found in reference: ${full}.`
1700
1701
  );
1701
1702
  let source;
1702
1703
  try {
1703
1704
  source = fs2.readFileSync(modulePath);
1704
1705
  } catch (error) {
1705
- throw new Error(`Import ${modulePath} not found. Does the file exist?`);
1706
+ throw new Error(
1707
+ `Import "${modulePath}" not found. Does the file exist?`
1708
+ );
1706
1709
  }
1707
1710
  return MiniflareResponse.json({
1708
1711
  // Cap'n Proto expects byte arrays for `:Data` typed fields from JSON
@@ -1711,6 +1714,26 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer) {
1711
1714
  }
1712
1715
  };
1713
1716
  }
1717
+ function getPreviewModules(main, modulesRules) {
1718
+ assert4(modulesRules, `Unexpected error: 'modulesRules' is undefined`);
1719
+ const rootPath = path3.dirname(main);
1720
+ const entryPath = path3.basename(main);
1721
+ return {
1722
+ rootPath,
1723
+ modules: [
1724
+ {
1725
+ type: "ESModule",
1726
+ path: entryPath
1727
+ },
1728
+ ...modulesRules.flatMap(
1729
+ ({ type, include }) => globSync(include, { cwd: rootPath, ignore: entryPath }).map((path8) => ({
1730
+ type,
1731
+ path: path8
1732
+ }))
1733
+ )
1734
+ ]
1735
+ };
1736
+ }
1714
1737
  function getPreviewMiniflareOptions(vitePreviewServer, persistState) {
1715
1738
  const resolvedViteConfig = vitePreviewServer.config;
1716
1739
  const configPaths = getWorkerConfigPaths(resolvedViteConfig.root);
@@ -1719,13 +1742,12 @@ function getPreviewMiniflareOptions(vitePreviewServer, persistState) {
1719
1742
  );
1720
1743
  const workers = workerConfigs.map((config) => {
1721
1744
  const miniflareWorkerOptions = unstable_getMiniflareWorkerOptions(config);
1722
- const { ratelimits, ...workerOptions } = miniflareWorkerOptions.workerOptions;
1745
+ const { ratelimits, modulesRules, ...workerOptions } = miniflareWorkerOptions.workerOptions;
1723
1746
  return {
1724
1747
  ...workerOptions,
1725
1748
  // We have to add the name again because `unstable_getMiniflareWorkerOptions` sets it to `undefined`
1726
1749
  name: config.name,
1727
- modules: true,
1728
- ...miniflareWorkerOptions.main ? { scriptPath: miniflareWorkerOptions.main } : { script: "" }
1750
+ ...miniflareWorkerOptions.main ? getPreviewModules(miniflareWorkerOptions.main, modulesRules) : { modules: true, script: "" }
1729
1751
  };
1730
1752
  });
1731
1753
  const logger = new ViteMiniflareLogger(resolvedViteConfig);
@@ -7368,7 +7390,7 @@ var isAbsolute = function(p) {
7368
7390
  import { fileURLToPath as fileURLToPath$1, URL as URL$1, pathToFileURL as pathToFileURL$1 } from "node:url";
7369
7391
  import assert5 from "node:assert";
7370
7392
  import process$1 from "node:process";
7371
- import path4, { dirname as dirname3 } from "node:path";
7393
+ import path4, { dirname as dirname4 } from "node:path";
7372
7394
  import v8 from "node:v8";
7373
7395
  import { format as format2, inspect } from "node:util";
7374
7396
  var BUILTIN_MODULES = new Set(builtinModules);
@@ -9307,7 +9329,7 @@ function cloudflare2(pluginConfig = {}) {
9307
9329
  return;
9308
9330
  }
9309
9331
  config.no_bundle = true;
9310
- config.rules = [{ type: "ESModule", globs: ["**/*.js"] }];
9332
+ config.rules = [{ type: "ESModule", globs: ["**/*.js", "**/*.mjs"] }];
9311
9333
  if (config.unsafe && Object.keys(config.unsafe).length === 0) {
9312
9334
  config.unsafe = void 0;
9313
9335
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudflare/vite-plugin",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "Cloudflare plugin for Vite",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -35,12 +35,13 @@
35
35
  "dependencies": {
36
36
  "@cloudflare/unenv-preset": "1.1.1",
37
37
  "@hattip/adapter-node": "^0.0.49",
38
+ "tinyglobby": "^0.2.12",
38
39
  "unenv": "2.0.0-rc.1",
39
40
  "ws": "8.18.0",
40
- "miniflare": "3.20250214.1"
41
+ "miniflare": "3.20250224.0"
41
42
  },
42
43
  "devDependencies": {
43
- "@cloudflare/workers-types": "^4.20250214.0",
44
+ "@cloudflare/workers-types": "^4.20250224.0",
44
45
  "@types/node": "^22.10.1",
45
46
  "@types/ws": "^8.5.13",
46
47
  "magic-string": "^0.30.12",
@@ -51,9 +52,9 @@
51
52
  "vite": "^6.1.0",
52
53
  "vitest": "~3.0.5",
53
54
  "@cloudflare/mock-npm-registry": "0.0.0",
54
- "@cloudflare/workers-shared": "0.14.4",
55
+ "@cloudflare/workers-shared": "0.14.5",
55
56
  "@cloudflare/workers-tsconfig": "0.0.0",
56
- "wrangler": "3.111.0"
57
+ "wrangler": "3.113.0"
57
58
  },
58
59
  "peerDependencies": {
59
60
  "vite": "^6.1.0",