@cloudflare/vite-plugin 0.1.4 → 0.1.5
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 +34 -26
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -8713,6 +8713,8 @@ var { env } = defineEnv({
|
|
|
8713
8713
|
nodeCompat: true,
|
|
8714
8714
|
presets: [cloudflare]
|
|
8715
8715
|
});
|
|
8716
|
+
var nodeCompatExternals = new Set(env.external);
|
|
8717
|
+
var nodeCompatEntries = getNodeCompatEntries();
|
|
8716
8718
|
function isNodeCompat(workerConfig) {
|
|
8717
8719
|
if (workerConfig === void 0) {
|
|
8718
8720
|
return false;
|
|
@@ -8736,24 +8738,6 @@ function isNodeCompat(workerConfig) {
|
|
|
8736
8738
|
}
|
|
8737
8739
|
return false;
|
|
8738
8740
|
}
|
|
8739
|
-
function getNodeCompatEntries() {
|
|
8740
|
-
const entries = new Set(Object.values(env.alias));
|
|
8741
|
-
for (const globalInject of Object.values(env.inject)) {
|
|
8742
|
-
if (typeof globalInject === "string") {
|
|
8743
|
-
entries.add(globalInject);
|
|
8744
|
-
} else {
|
|
8745
|
-
assert6(
|
|
8746
|
-
globalInject[0] !== void 0,
|
|
8747
|
-
"Expected first element of globalInject to be defined"
|
|
8748
|
-
);
|
|
8749
|
-
entries.add(globalInject[0]);
|
|
8750
|
-
}
|
|
8751
|
-
}
|
|
8752
|
-
for (const external of env.external) {
|
|
8753
|
-
entries.delete(external);
|
|
8754
|
-
}
|
|
8755
|
-
return entries;
|
|
8756
|
-
}
|
|
8757
8741
|
function injectGlobalCode(id, code) {
|
|
8758
8742
|
const injectedCode = Object.entries(env.inject).map(([globalName, globalInject]) => {
|
|
8759
8743
|
if (typeof globalInject === "string") {
|
|
@@ -8779,9 +8763,6 @@ globalThis.${globalName} = var_${globalName}.${exportName};
|
|
|
8779
8763
|
map: modified.generateMap({ hires: "boundary", source: id })
|
|
8780
8764
|
};
|
|
8781
8765
|
}
|
|
8782
|
-
function getNodeCompatExternals() {
|
|
8783
|
-
return env.external;
|
|
8784
|
-
}
|
|
8785
8766
|
function resolveNodeJSImport(source) {
|
|
8786
8767
|
const alias = env.alias[source];
|
|
8787
8768
|
if (alias) {
|
|
@@ -8790,6 +8771,28 @@ function resolveNodeJSImport(source) {
|
|
|
8790
8771
|
resolved: resolvePathSync(alias, { url: import.meta.url })
|
|
8791
8772
|
};
|
|
8792
8773
|
}
|
|
8774
|
+
if (nodeCompatEntries.has(source)) {
|
|
8775
|
+
return {
|
|
8776
|
+
unresolved: source,
|
|
8777
|
+
resolved: resolvePathSync(source, { url: import.meta.url })
|
|
8778
|
+
};
|
|
8779
|
+
}
|
|
8780
|
+
}
|
|
8781
|
+
function getNodeCompatEntries() {
|
|
8782
|
+
const entries = new Set(Object.values(env.alias));
|
|
8783
|
+
for (const globalInject of Object.values(env.inject)) {
|
|
8784
|
+
if (typeof globalInject === "string") {
|
|
8785
|
+
entries.add(globalInject);
|
|
8786
|
+
} else {
|
|
8787
|
+
assert6(
|
|
8788
|
+
globalInject[0] !== void 0,
|
|
8789
|
+
"Expected first element of globalInject to be defined"
|
|
8790
|
+
);
|
|
8791
|
+
entries.add(globalInject[0]);
|
|
8792
|
+
}
|
|
8793
|
+
}
|
|
8794
|
+
nodeCompatExternals.forEach((external) => entries.delete(external));
|
|
8795
|
+
return entries;
|
|
8793
8796
|
}
|
|
8794
8797
|
|
|
8795
8798
|
// src/plugin-config.ts
|
|
@@ -9102,9 +9105,9 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
9102
9105
|
}
|
|
9103
9106
|
|
|
9104
9107
|
// src/websockets.ts
|
|
9105
|
-
import
|
|
9108
|
+
import { WebSocketServer } from "ws";
|
|
9106
9109
|
function handleWebSocket(httpServer, fetcher, logger) {
|
|
9107
|
-
const nodeWebSocket = new
|
|
9110
|
+
const nodeWebSocket = new WebSocketServer({ noServer: true });
|
|
9108
9111
|
httpServer.on(
|
|
9109
9112
|
"upgrade",
|
|
9110
9113
|
async (request, socket, head) => {
|
|
@@ -9462,7 +9465,7 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
9462
9465
|
if (isNodeCompat(getWorkerConfig2(name2))) {
|
|
9463
9466
|
return {
|
|
9464
9467
|
resolve: {
|
|
9465
|
-
builtins:
|
|
9468
|
+
builtins: [...nodeCompatExternals]
|
|
9466
9469
|
},
|
|
9467
9470
|
optimizeDeps: {
|
|
9468
9471
|
// This is a list of dependency entry-points that should be pre-bundled.
|
|
@@ -9470,7 +9473,8 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
9470
9473
|
// ready ahead the first request to the dev server.
|
|
9471
9474
|
// Without this the dependency optimizer will try to bundle them on-the-fly in the middle of the first request,
|
|
9472
9475
|
// which can potentially cause problems if it leads to previous pre-bundling to become stale and needing to be reloaded.
|
|
9473
|
-
|
|
9476
|
+
// TODO: work out how to re-enable pre-bundling of these
|
|
9477
|
+
// include: [...getNodeCompatEntries()],
|
|
9474
9478
|
// This is a list of module specifiers that the dependency optimizer should not follow when doing import analysis.
|
|
9475
9479
|
// In this case we provide a list of all the Node.js modules, both those built-in to workerd and those that will be polyfilled.
|
|
9476
9480
|
// Obviously we don't want/need the optimizer to try to process modules that are built-in;
|
|
@@ -9501,7 +9505,11 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
9501
9505
|
this.environment.depsOptimizer,
|
|
9502
9506
|
"depsOptimizer is required in dev mode"
|
|
9503
9507
|
);
|
|
9504
|
-
|
|
9508
|
+
const { id } = this.environment.depsOptimizer.registerMissingImport(
|
|
9509
|
+
result.unresolved,
|
|
9510
|
+
result.resolved
|
|
9511
|
+
);
|
|
9512
|
+
return this.resolve(id, importer, options);
|
|
9505
9513
|
}
|
|
9506
9514
|
return this.resolve(result.resolved, importer, options);
|
|
9507
9515
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudflare/vite-plugin",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Cloudflare plugin for Vite",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@cloudflare/unenv-preset": "1.1.1",
|
|
37
37
|
"@hattip/adapter-node": "^0.0.49",
|
|
38
38
|
"unenv": "2.0.0-rc.1",
|
|
39
|
-
"ws": "
|
|
39
|
+
"ws": "8.18.0",
|
|
40
40
|
"miniflare": "3.20250214.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
@@ -50,10 +50,10 @@
|
|
|
50
50
|
"undici": "^5.28.5",
|
|
51
51
|
"vite": "^6.1.0",
|
|
52
52
|
"vitest": "~3.0.5",
|
|
53
|
-
"@cloudflare/
|
|
53
|
+
"@cloudflare/workers-shared": "0.14.3",
|
|
54
54
|
"@cloudflare/workers-tsconfig": "0.0.0",
|
|
55
55
|
"wrangler": "3.109.3",
|
|
56
|
-
"@cloudflare/
|
|
56
|
+
"@cloudflare/mock-npm-registry": "0.0.0"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"vite": "^6.1.0",
|