@cloudflare/vite-plugin 0.0.0-1f3af77c7 → 0.0.0-2138fef92
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/asset-workers/asset-worker.js +18 -21
- package/dist/asset-workers/router-worker.js +229 -228
- package/dist/index.js +43 -17
- package/package.json +7 -6
package/dist/index.js
CHANGED
|
@@ -1364,7 +1364,13 @@ import * as fs2 from "node:fs";
|
|
|
1364
1364
|
import * as fsp from "node:fs/promises";
|
|
1365
1365
|
import * as path3 from "node:path";
|
|
1366
1366
|
import { fileURLToPath } from "node:url";
|
|
1367
|
-
import {
|
|
1367
|
+
import {
|
|
1368
|
+
kCurrentWorker,
|
|
1369
|
+
Log,
|
|
1370
|
+
LogLevel,
|
|
1371
|
+
Response as MiniflareResponse
|
|
1372
|
+
} from "miniflare";
|
|
1373
|
+
import { globSync } from "tinyglobby";
|
|
1368
1374
|
import "vite";
|
|
1369
1375
|
import {
|
|
1370
1376
|
unstable_getMiniflareWorkerOptions,
|
|
@@ -1398,11 +1404,10 @@ function getWorkerToWorkerEntrypointNamesMap(workers) {
|
|
|
1398
1404
|
);
|
|
1399
1405
|
for (const worker of workers) {
|
|
1400
1406
|
for (const value of Object.values(worker.serviceBindings ?? {})) {
|
|
1401
|
-
if (typeof value === "object" && "name" in value &&
|
|
1402
|
-
const
|
|
1403
|
-
|
|
1404
|
-
);
|
|
1405
|
-
assert4(entrypointNames, missingWorkerErrorMessage(value.name));
|
|
1407
|
+
if (typeof value === "object" && "name" in value && value.entrypoint !== void 0 && value.entrypoint !== "default") {
|
|
1408
|
+
const targetWorkerName = value.name === kCurrentWorker ? worker.name : value.name;
|
|
1409
|
+
const entrypointNames = workerToWorkerEntrypointNamesMap.get(targetWorkerName);
|
|
1410
|
+
assert4(entrypointNames, missingWorkerErrorMessage(targetWorkerName));
|
|
1406
1411
|
entrypointNames.add(value.entrypoint);
|
|
1407
1412
|
}
|
|
1408
1413
|
}
|
|
@@ -1652,7 +1657,7 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer) {
|
|
|
1652
1657
|
const workflowEntrypointClassNames = workerToWorkflowEntrypointClassNamesMap.get(workerOptions.name);
|
|
1653
1658
|
assert4(
|
|
1654
1659
|
workflowEntrypointClassNames,
|
|
1655
|
-
`WorkflowEntrypoint class names not found for worker ${workerOptions.name}`
|
|
1660
|
+
`WorkflowEntrypoint class names not found for worker: ${workerOptions.name}`
|
|
1656
1661
|
);
|
|
1657
1662
|
for (const className of [...workflowEntrypointClassNames].sort()) {
|
|
1658
1663
|
wrappers.push(
|
|
@@ -1688,17 +1693,19 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer) {
|
|
|
1688
1693
|
);
|
|
1689
1694
|
const moduleRE = new RegExp(MODULE_PATTERN);
|
|
1690
1695
|
const match = moduleRE.exec(rawSpecifier);
|
|
1691
|
-
assert4(match, `Unexpected error: no match for module ${rawSpecifier}.`);
|
|
1696
|
+
assert4(match, `Unexpected error: no match for module: ${rawSpecifier}.`);
|
|
1692
1697
|
const [full, moduleType, modulePath] = match;
|
|
1693
1698
|
assert4(
|
|
1694
1699
|
modulePath,
|
|
1695
|
-
`Unexpected error: module path not found in reference ${full}.`
|
|
1700
|
+
`Unexpected error: module path not found in reference: ${full}.`
|
|
1696
1701
|
);
|
|
1697
1702
|
let source;
|
|
1698
1703
|
try {
|
|
1699
1704
|
source = fs2.readFileSync(modulePath);
|
|
1700
1705
|
} catch (error) {
|
|
1701
|
-
throw new Error(
|
|
1706
|
+
throw new Error(
|
|
1707
|
+
`Import "${modulePath}" not found. Does the file exist?`
|
|
1708
|
+
);
|
|
1702
1709
|
}
|
|
1703
1710
|
return MiniflareResponse.json({
|
|
1704
1711
|
// Cap'n Proto expects byte arrays for `:Data` typed fields from JSON
|
|
@@ -1707,6 +1714,26 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer) {
|
|
|
1707
1714
|
}
|
|
1708
1715
|
};
|
|
1709
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
|
+
}
|
|
1710
1737
|
function getPreviewMiniflareOptions(vitePreviewServer, persistState) {
|
|
1711
1738
|
const resolvedViteConfig = vitePreviewServer.config;
|
|
1712
1739
|
const configPaths = getWorkerConfigPaths(resolvedViteConfig.root);
|
|
@@ -1715,13 +1742,12 @@ function getPreviewMiniflareOptions(vitePreviewServer, persistState) {
|
|
|
1715
1742
|
);
|
|
1716
1743
|
const workers = workerConfigs.map((config) => {
|
|
1717
1744
|
const miniflareWorkerOptions = unstable_getMiniflareWorkerOptions(config);
|
|
1718
|
-
const { ratelimits, ...workerOptions } = miniflareWorkerOptions.workerOptions;
|
|
1745
|
+
const { ratelimits, modulesRules, ...workerOptions } = miniflareWorkerOptions.workerOptions;
|
|
1719
1746
|
return {
|
|
1720
1747
|
...workerOptions,
|
|
1721
1748
|
// We have to add the name again because `unstable_getMiniflareWorkerOptions` sets it to `undefined`
|
|
1722
1749
|
name: config.name,
|
|
1723
|
-
modules: true,
|
|
1724
|
-
...miniflareWorkerOptions.main ? { scriptPath: miniflareWorkerOptions.main } : { script: "" }
|
|
1750
|
+
...miniflareWorkerOptions.main ? getPreviewModules(miniflareWorkerOptions.main, modulesRules) : { modules: true, script: "" }
|
|
1725
1751
|
};
|
|
1726
1752
|
});
|
|
1727
1753
|
const logger = new ViteMiniflareLogger(resolvedViteConfig);
|
|
@@ -7364,7 +7390,7 @@ var isAbsolute = function(p) {
|
|
|
7364
7390
|
import { fileURLToPath as fileURLToPath$1, URL as URL$1, pathToFileURL as pathToFileURL$1 } from "node:url";
|
|
7365
7391
|
import assert5 from "node:assert";
|
|
7366
7392
|
import process$1 from "node:process";
|
|
7367
|
-
import path4, { dirname as
|
|
7393
|
+
import path4, { dirname as dirname4 } from "node:path";
|
|
7368
7394
|
import v8 from "node:v8";
|
|
7369
7395
|
import { format as format2, inspect } from "node:util";
|
|
7370
7396
|
var BUILTIN_MODULES = new Set(builtinModules);
|
|
@@ -9216,7 +9242,7 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
9216
9242
|
}
|
|
9217
9243
|
} : void 0,
|
|
9218
9244
|
builder: {
|
|
9219
|
-
|
|
9245
|
+
buildApp: userConfig.builder?.buildApp ?? (async (builder) => {
|
|
9220
9246
|
const clientEnvironment = builder.environments.client;
|
|
9221
9247
|
const defaultHtmlPath = path7.resolve(
|
|
9222
9248
|
builder.config.root,
|
|
@@ -9242,7 +9268,7 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
9242
9268
|
)
|
|
9243
9269
|
);
|
|
9244
9270
|
}
|
|
9245
|
-
}
|
|
9271
|
+
})
|
|
9246
9272
|
}
|
|
9247
9273
|
};
|
|
9248
9274
|
},
|
|
@@ -9303,7 +9329,7 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
9303
9329
|
return;
|
|
9304
9330
|
}
|
|
9305
9331
|
config.no_bundle = true;
|
|
9306
|
-
config.rules = [{ type: "ESModule", globs: ["**/*.js"] }];
|
|
9332
|
+
config.rules = [{ type: "ESModule", globs: ["**/*.js", "**/*.mjs"] }];
|
|
9307
9333
|
if (config.unsafe && Object.keys(config.unsafe).length === 0) {
|
|
9308
9334
|
config.unsafe = void 0;
|
|
9309
9335
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudflare/vite-plugin",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-2138fef92",
|
|
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": "0.0.0-
|
|
41
|
+
"miniflare": "0.0.0-2138fef92"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
43
|
-
"@cloudflare/workers-types": "^4.
|
|
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",
|
|
@@ -50,10 +51,10 @@
|
|
|
50
51
|
"undici": "^5.28.5",
|
|
51
52
|
"vite": "^6.1.0",
|
|
52
53
|
"vitest": "~3.0.5",
|
|
54
|
+
"@cloudflare/workers-shared": "0.0.0-2138fef92",
|
|
53
55
|
"@cloudflare/mock-npm-registry": "0.0.0",
|
|
54
|
-
"@cloudflare/workers-
|
|
55
|
-
"wrangler": "0.0.0-
|
|
56
|
-
"@cloudflare/workers-tsconfig": "0.0.0"
|
|
56
|
+
"@cloudflare/workers-tsconfig": "0.0.0",
|
|
57
|
+
"wrangler": "0.0.0-2138fef92"
|
|
57
58
|
},
|
|
58
59
|
"peerDependencies": {
|
|
59
60
|
"vite": "^6.1.0",
|