@cloudflare/vite-plugin 0.0.0-fce80ae8c → 0.0.0-fd9dff833
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 +89 -66
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -1200,7 +1200,6 @@ var cloudflareBuiltInModules = [
|
|
|
1200
1200
|
"cloudflare:workflows"
|
|
1201
1201
|
];
|
|
1202
1202
|
var defaultConditions = ["workerd", "module", "browser"];
|
|
1203
|
-
var target = "es2022";
|
|
1204
1203
|
function createCloudflareEnvironmentOptions(workerConfig, userConfig, environmentName) {
|
|
1205
1204
|
return {
|
|
1206
1205
|
resolve: {
|
|
@@ -1221,7 +1220,7 @@ function createCloudflareEnvironmentOptions(workerConfig, userConfig, environmen
|
|
|
1221
1220
|
createEnvironment(name2, config) {
|
|
1222
1221
|
return new vite2.BuildEnvironment(name2, config);
|
|
1223
1222
|
},
|
|
1224
|
-
target,
|
|
1223
|
+
target: "es2022",
|
|
1225
1224
|
// We need to enable `emitAssets` in order to support additional modules defined by `rules`
|
|
1226
1225
|
emitAssets: true,
|
|
1227
1226
|
outDir: getOutputDirectory(userConfig, environmentName),
|
|
@@ -1242,7 +1241,6 @@ function createCloudflareEnvironmentOptions(workerConfig, userConfig, environmen
|
|
|
1242
1241
|
exclude: [...cloudflareBuiltInModules],
|
|
1243
1242
|
esbuildOptions: {
|
|
1244
1243
|
platform: "neutral",
|
|
1245
|
-
target,
|
|
1246
1244
|
conditions: [...defaultConditions, "development"],
|
|
1247
1245
|
resolveExtensions: [
|
|
1248
1246
|
".mjs",
|
|
@@ -7535,14 +7533,14 @@ codes.ERR_INVALID_PACKAGE_TARGET = createError(
|
|
|
7535
7533
|
* @param {boolean} [isImport=false]
|
|
7536
7534
|
* @param {string} [base]
|
|
7537
7535
|
*/
|
|
7538
|
-
(packagePath, key,
|
|
7539
|
-
const relatedError = typeof
|
|
7536
|
+
(packagePath, key, target, isImport = false, base = void 0) => {
|
|
7537
|
+
const relatedError = typeof target === "string" && !isImport && target.length > 0 && !target.startsWith("./");
|
|
7540
7538
|
if (key === ".") {
|
|
7541
7539
|
assert5(isImport === false);
|
|
7542
|
-
return `Invalid "exports" main target ${JSON.stringify(
|
|
7540
|
+
return `Invalid "exports" main target ${JSON.stringify(target)} defined in the package config ${packagePath}package.json${base ? ` imported from ${base}` : ""}${relatedError ? '; targets must start with "./"' : ""}`;
|
|
7543
7541
|
}
|
|
7544
7542
|
return `Invalid "${isImport ? "imports" : "exports"}" target ${JSON.stringify(
|
|
7545
|
-
|
|
7543
|
+
target
|
|
7546
7544
|
)} defined for '${key}' in the package config ${packagePath}package.json${base ? ` imported from ${base}` : ""}${relatedError ? '; targets must start with "./"' : ""}`;
|
|
7547
7545
|
},
|
|
7548
7546
|
Error
|
|
@@ -7938,14 +7936,14 @@ var patternRegEx = /\*/g;
|
|
|
7938
7936
|
var encodedSeparatorRegEx = /%2f|%5c/i;
|
|
7939
7937
|
var emittedPackageWarnings = /* @__PURE__ */ new Set();
|
|
7940
7938
|
var doubleSlashRegEx = /[/\\]{2}/;
|
|
7941
|
-
function emitInvalidSegmentDeprecation(
|
|
7939
|
+
function emitInvalidSegmentDeprecation(target, request, match, packageJsonUrl, internal, base, isTarget) {
|
|
7942
7940
|
if (process$1.noDeprecation) {
|
|
7943
7941
|
return;
|
|
7944
7942
|
}
|
|
7945
7943
|
const pjsonPath = fileURLToPath$1(packageJsonUrl);
|
|
7946
|
-
const double = doubleSlashRegEx.exec(isTarget ?
|
|
7944
|
+
const double = doubleSlashRegEx.exec(isTarget ? target : request) !== null;
|
|
7947
7945
|
process$1.emitWarning(
|
|
7948
|
-
`Use of deprecated ${double ? "double slash" : "leading or trailing slash matching"} resolving "${
|
|
7946
|
+
`Use of deprecated ${double ? "double slash" : "leading or trailing slash matching"} resolving "${target}" for module request "${request}" ${request === match ? "" : `matched to "${match}" `}in the "${internal ? "imports" : "exports"}" field module resolution of the package at ${pjsonPath}${base ? ` imported from ${fileURLToPath$1(base)}` : ""}.`,
|
|
7949
7947
|
"DeprecationWarning",
|
|
7950
7948
|
"DEP0166"
|
|
7951
7949
|
);
|
|
@@ -8103,47 +8101,47 @@ function throwInvalidSubpath(request, match, packageJsonUrl, internal, base) {
|
|
|
8103
8101
|
base && fileURLToPath$1(base)
|
|
8104
8102
|
);
|
|
8105
8103
|
}
|
|
8106
|
-
function invalidPackageTarget(subpath,
|
|
8107
|
-
|
|
8104
|
+
function invalidPackageTarget(subpath, target, packageJsonUrl, internal, base) {
|
|
8105
|
+
target = typeof target === "object" && target !== null ? JSON.stringify(target, null, "") : `${target}`;
|
|
8108
8106
|
return new ERR_INVALID_PACKAGE_TARGET(
|
|
8109
8107
|
fileURLToPath$1(new URL$1(".", packageJsonUrl)),
|
|
8110
8108
|
subpath,
|
|
8111
|
-
|
|
8109
|
+
target,
|
|
8112
8110
|
internal,
|
|
8113
8111
|
base && fileURLToPath$1(base)
|
|
8114
8112
|
);
|
|
8115
8113
|
}
|
|
8116
|
-
function resolvePackageTargetString(
|
|
8117
|
-
if (subpath !== "" && !pattern &&
|
|
8118
|
-
throw invalidPackageTarget(match,
|
|
8119
|
-
if (!
|
|
8120
|
-
if (internal && !
|
|
8114
|
+
function resolvePackageTargetString(target, subpath, match, packageJsonUrl, base, pattern, internal, isPathMap, conditions) {
|
|
8115
|
+
if (subpath !== "" && !pattern && target[target.length - 1] !== "/")
|
|
8116
|
+
throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
8117
|
+
if (!target.startsWith("./")) {
|
|
8118
|
+
if (internal && !target.startsWith("../") && !target.startsWith("/")) {
|
|
8121
8119
|
let isURL = false;
|
|
8122
8120
|
try {
|
|
8123
|
-
new URL$1(
|
|
8121
|
+
new URL$1(target);
|
|
8124
8122
|
isURL = true;
|
|
8125
8123
|
} catch {
|
|
8126
8124
|
}
|
|
8127
8125
|
if (!isURL) {
|
|
8128
8126
|
const exportTarget = pattern ? RegExpPrototypeSymbolReplace.call(
|
|
8129
8127
|
patternRegEx,
|
|
8130
|
-
|
|
8128
|
+
target,
|
|
8131
8129
|
() => subpath
|
|
8132
|
-
) :
|
|
8130
|
+
) : target + subpath;
|
|
8133
8131
|
return packageResolve(exportTarget, packageJsonUrl, conditions);
|
|
8134
8132
|
}
|
|
8135
8133
|
}
|
|
8136
|
-
throw invalidPackageTarget(match,
|
|
8134
|
+
throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
8137
8135
|
}
|
|
8138
|
-
if (invalidSegmentRegEx.exec(
|
|
8139
|
-
if (deprecatedInvalidSegmentRegEx.exec(
|
|
8136
|
+
if (invalidSegmentRegEx.exec(target.slice(2)) !== null) {
|
|
8137
|
+
if (deprecatedInvalidSegmentRegEx.exec(target.slice(2)) === null) {
|
|
8140
8138
|
if (!isPathMap) {
|
|
8141
8139
|
const request = pattern ? match.replace("*", () => subpath) : match + subpath;
|
|
8142
8140
|
const resolvedTarget = pattern ? RegExpPrototypeSymbolReplace.call(
|
|
8143
8141
|
patternRegEx,
|
|
8144
|
-
|
|
8142
|
+
target,
|
|
8145
8143
|
() => subpath
|
|
8146
|
-
) :
|
|
8144
|
+
) : target;
|
|
8147
8145
|
emitInvalidSegmentDeprecation(
|
|
8148
8146
|
resolvedTarget,
|
|
8149
8147
|
request,
|
|
@@ -8155,14 +8153,14 @@ function resolvePackageTargetString(target2, subpath, match, packageJsonUrl, bas
|
|
|
8155
8153
|
);
|
|
8156
8154
|
}
|
|
8157
8155
|
} else {
|
|
8158
|
-
throw invalidPackageTarget(match,
|
|
8156
|
+
throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
8159
8157
|
}
|
|
8160
8158
|
}
|
|
8161
|
-
const resolved = new URL$1(
|
|
8159
|
+
const resolved = new URL$1(target, packageJsonUrl);
|
|
8162
8160
|
const resolvedPath = resolved.pathname;
|
|
8163
8161
|
const packagePath = new URL$1(".", packageJsonUrl).pathname;
|
|
8164
8162
|
if (!resolvedPath.startsWith(packagePath))
|
|
8165
|
-
throw invalidPackageTarget(match,
|
|
8163
|
+
throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
8166
8164
|
if (subpath === "") return resolved;
|
|
8167
8165
|
if (invalidSegmentRegEx.exec(subpath) !== null) {
|
|
8168
8166
|
const request = pattern ? match.replace("*", () => subpath) : match + subpath;
|
|
@@ -8170,9 +8168,9 @@ function resolvePackageTargetString(target2, subpath, match, packageJsonUrl, bas
|
|
|
8170
8168
|
if (!isPathMap) {
|
|
8171
8169
|
const resolvedTarget = pattern ? RegExpPrototypeSymbolReplace.call(
|
|
8172
8170
|
patternRegEx,
|
|
8173
|
-
|
|
8171
|
+
target,
|
|
8174
8172
|
() => subpath
|
|
8175
|
-
) :
|
|
8173
|
+
) : target;
|
|
8176
8174
|
emitInvalidSegmentDeprecation(
|
|
8177
8175
|
resolvedTarget,
|
|
8178
8176
|
request,
|
|
@@ -8203,10 +8201,10 @@ function isArrayIndex(key) {
|
|
|
8203
8201
|
if (`${keyNumber}` !== key) return false;
|
|
8204
8202
|
return keyNumber >= 0 && keyNumber < 4294967295;
|
|
8205
8203
|
}
|
|
8206
|
-
function resolvePackageTarget(packageJsonUrl,
|
|
8207
|
-
if (typeof
|
|
8204
|
+
function resolvePackageTarget(packageJsonUrl, target, subpath, packageSubpath, base, pattern, internal, isPathMap, conditions) {
|
|
8205
|
+
if (typeof target === "string") {
|
|
8208
8206
|
return resolvePackageTargetString(
|
|
8209
|
-
|
|
8207
|
+
target,
|
|
8210
8208
|
subpath,
|
|
8211
8209
|
packageSubpath,
|
|
8212
8210
|
packageJsonUrl,
|
|
@@ -8217,8 +8215,8 @@ function resolvePackageTarget(packageJsonUrl, target2, subpath, packageSubpath,
|
|
|
8217
8215
|
conditions
|
|
8218
8216
|
);
|
|
8219
8217
|
}
|
|
8220
|
-
if (Array.isArray(
|
|
8221
|
-
const targetList =
|
|
8218
|
+
if (Array.isArray(target)) {
|
|
8219
|
+
const targetList = target;
|
|
8222
8220
|
if (targetList.length === 0) return null;
|
|
8223
8221
|
let lastException;
|
|
8224
8222
|
let i = -1;
|
|
@@ -8258,8 +8256,8 @@ function resolvePackageTarget(packageJsonUrl, target2, subpath, packageSubpath,
|
|
|
8258
8256
|
}
|
|
8259
8257
|
throw lastException;
|
|
8260
8258
|
}
|
|
8261
|
-
if (typeof
|
|
8262
|
-
const keys = Object.getOwnPropertyNames(
|
|
8259
|
+
if (typeof target === "object" && target !== null) {
|
|
8260
|
+
const keys = Object.getOwnPropertyNames(target);
|
|
8263
8261
|
let i = -1;
|
|
8264
8262
|
while (++i < keys.length) {
|
|
8265
8263
|
const key = keys[i];
|
|
@@ -8277,7 +8275,7 @@ function resolvePackageTarget(packageJsonUrl, target2, subpath, packageSubpath,
|
|
|
8277
8275
|
if (key === "default" || conditions && conditions.has(key)) {
|
|
8278
8276
|
const conditionalTarget = (
|
|
8279
8277
|
/** @type {unknown} */
|
|
8280
|
-
|
|
8278
|
+
target[key]
|
|
8281
8279
|
);
|
|
8282
8280
|
const resolveResult = resolvePackageTarget(
|
|
8283
8281
|
packageJsonUrl,
|
|
@@ -8296,12 +8294,12 @@ function resolvePackageTarget(packageJsonUrl, target2, subpath, packageSubpath,
|
|
|
8296
8294
|
}
|
|
8297
8295
|
return null;
|
|
8298
8296
|
}
|
|
8299
|
-
if (
|
|
8297
|
+
if (target === null) {
|
|
8300
8298
|
return null;
|
|
8301
8299
|
}
|
|
8302
8300
|
throw invalidPackageTarget(
|
|
8303
8301
|
packageSubpath,
|
|
8304
|
-
|
|
8302
|
+
target,
|
|
8305
8303
|
packageJsonUrl,
|
|
8306
8304
|
internal,
|
|
8307
8305
|
base
|
|
@@ -8348,10 +8346,10 @@ function packageExportsResolve(packageJsonUrl, packageSubpath, packageConfig, ba
|
|
|
8348
8346
|
exports = { ".": exports };
|
|
8349
8347
|
}
|
|
8350
8348
|
if (own.call(exports, packageSubpath) && !packageSubpath.includes("*") && !packageSubpath.endsWith("/")) {
|
|
8351
|
-
const
|
|
8349
|
+
const target = exports[packageSubpath];
|
|
8352
8350
|
const resolveResult = resolvePackageTarget(
|
|
8353
8351
|
packageJsonUrl,
|
|
8354
|
-
|
|
8352
|
+
target,
|
|
8355
8353
|
"",
|
|
8356
8354
|
packageSubpath,
|
|
8357
8355
|
base,
|
|
@@ -8391,13 +8389,13 @@ function packageExportsResolve(packageJsonUrl, packageSubpath, packageConfig, ba
|
|
|
8391
8389
|
}
|
|
8392
8390
|
}
|
|
8393
8391
|
if (bestMatch) {
|
|
8394
|
-
const
|
|
8392
|
+
const target = (
|
|
8395
8393
|
/** @type {unknown} */
|
|
8396
8394
|
exports[bestMatch]
|
|
8397
8395
|
);
|
|
8398
8396
|
const resolveResult = resolvePackageTarget(
|
|
8399
8397
|
packageJsonUrl,
|
|
8400
|
-
|
|
8398
|
+
target,
|
|
8401
8399
|
bestMatchSubpath,
|
|
8402
8400
|
bestMatch,
|
|
8403
8401
|
base,
|
|
@@ -8472,10 +8470,10 @@ function packageImportsResolve(name2, base, conditions) {
|
|
|
8472
8470
|
}
|
|
8473
8471
|
}
|
|
8474
8472
|
if (bestMatch) {
|
|
8475
|
-
const
|
|
8473
|
+
const target = imports[bestMatch];
|
|
8476
8474
|
const resolveResult = resolvePackageTarget(
|
|
8477
8475
|
packageJsonUrl,
|
|
8478
|
-
|
|
8476
|
+
target,
|
|
8479
8477
|
bestMatchSubpath,
|
|
8480
8478
|
bestMatch,
|
|
8481
8479
|
base,
|
|
@@ -9037,17 +9035,6 @@ function getWorkerConfig(configPath, env2, opts) {
|
|
|
9037
9035
|
};
|
|
9038
9036
|
}
|
|
9039
9037
|
assert7(config.main, missingFieldErrorMessage(`'main'`, configPath, env2));
|
|
9040
|
-
const mainStat = fs4.statSync(config.main, { throwIfNoEntry: false });
|
|
9041
|
-
if (!mainStat) {
|
|
9042
|
-
throw new Error(
|
|
9043
|
-
`The provided Wrangler config main field (${config.main}) doesn't point to an existing file`
|
|
9044
|
-
);
|
|
9045
|
-
}
|
|
9046
|
-
if (mainStat.isDirectory()) {
|
|
9047
|
-
throw new Error(
|
|
9048
|
-
`The provided Wrangler config main field (${config.main}) points to a directory, it needs to point to a file instead`
|
|
9049
|
-
);
|
|
9050
|
-
}
|
|
9051
9038
|
return {
|
|
9052
9039
|
type: "worker",
|
|
9053
9040
|
raw,
|
|
@@ -9148,9 +9135,8 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
9148
9135
|
}
|
|
9149
9136
|
|
|
9150
9137
|
// src/websockets.ts
|
|
9151
|
-
import { coupleWebSocket } from "miniflare";
|
|
9152
9138
|
import { WebSocketServer } from "ws";
|
|
9153
|
-
function handleWebSocket(httpServer, fetcher) {
|
|
9139
|
+
function handleWebSocket(httpServer, fetcher, logger) {
|
|
9154
9140
|
const nodeWebSocket = new WebSocketServer({ noServer: true });
|
|
9155
9141
|
httpServer.on(
|
|
9156
9142
|
"upgrade",
|
|
@@ -9174,7 +9160,34 @@ function handleWebSocket(httpServer, fetcher) {
|
|
|
9174
9160
|
socket,
|
|
9175
9161
|
head,
|
|
9176
9162
|
async (clientWebSocket) => {
|
|
9177
|
-
|
|
9163
|
+
workerWebSocket.accept();
|
|
9164
|
+
workerWebSocket.addEventListener("message", (event) => {
|
|
9165
|
+
clientWebSocket.send(event.data);
|
|
9166
|
+
});
|
|
9167
|
+
workerWebSocket.addEventListener("error", (event) => {
|
|
9168
|
+
logger.error(
|
|
9169
|
+
`WebSocket error:
|
|
9170
|
+
${event.error?.stack || event.error?.message}`,
|
|
9171
|
+
{ error: event.error }
|
|
9172
|
+
);
|
|
9173
|
+
});
|
|
9174
|
+
workerWebSocket.addEventListener("close", () => {
|
|
9175
|
+
clientWebSocket.close();
|
|
9176
|
+
});
|
|
9177
|
+
clientWebSocket.on("message", (data2, isBinary) => {
|
|
9178
|
+
workerWebSocket.send(
|
|
9179
|
+
isBinary ? Array.isArray(data2) ? Buffer.concat(data2) : data2 : data2.toString()
|
|
9180
|
+
);
|
|
9181
|
+
});
|
|
9182
|
+
clientWebSocket.on("error", (error) => {
|
|
9183
|
+
logger.error(`WebSocket error:
|
|
9184
|
+
${error.stack || error.message}`, {
|
|
9185
|
+
error
|
|
9186
|
+
});
|
|
9187
|
+
});
|
|
9188
|
+
clientWebSocket.on("close", () => {
|
|
9189
|
+
workerWebSocket.close();
|
|
9190
|
+
});
|
|
9178
9191
|
nodeWebSocket.emit("connection", clientWebSocket, request);
|
|
9179
9192
|
}
|
|
9180
9193
|
);
|
|
@@ -9367,7 +9380,11 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
9367
9380
|
},
|
|
9368
9381
|
{ alwaysCallNext: false }
|
|
9369
9382
|
);
|
|
9370
|
-
handleWebSocket(
|
|
9383
|
+
handleWebSocket(
|
|
9384
|
+
viteDevServer.httpServer,
|
|
9385
|
+
entryWorker.fetch,
|
|
9386
|
+
viteDevServer.config.logger
|
|
9387
|
+
);
|
|
9371
9388
|
return () => {
|
|
9372
9389
|
viteDevServer.middlewares.use((req, res, next) => {
|
|
9373
9390
|
middleware(req, res, next);
|
|
@@ -9389,10 +9406,16 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
9389
9406
|
},
|
|
9390
9407
|
{ alwaysCallNext: false }
|
|
9391
9408
|
);
|
|
9392
|
-
handleWebSocket(
|
|
9393
|
-
|
|
9394
|
-
|
|
9395
|
-
|
|
9409
|
+
handleWebSocket(
|
|
9410
|
+
vitePreviewServer.httpServer,
|
|
9411
|
+
miniflare2.dispatchFetch,
|
|
9412
|
+
vitePreviewServer.config.logger
|
|
9413
|
+
);
|
|
9414
|
+
return () => {
|
|
9415
|
+
vitePreviewServer.middlewares.use((req, res, next) => {
|
|
9416
|
+
middleware(req, res, next);
|
|
9417
|
+
});
|
|
9418
|
+
};
|
|
9396
9419
|
}
|
|
9397
9420
|
},
|
|
9398
9421
|
// Plugin to support `CompiledWasm` modules
|
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-fd9dff833",
|
|
4
4
|
"description": "Cloudflare plugin for Vite",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"tinyglobby": "^0.2.12",
|
|
39
39
|
"unenv": "2.0.0-rc.1",
|
|
40
40
|
"ws": "8.18.0",
|
|
41
|
-
"miniflare": "0.0.0-
|
|
42
|
-
"wrangler": "0.0.0-
|
|
41
|
+
"miniflare": "0.0.0-fd9dff833",
|
|
42
|
+
"wrangler": "0.0.0-fd9dff833"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@cloudflare/workers-types": "^4.20250317.0",
|
|
@@ -53,12 +53,12 @@
|
|
|
53
53
|
"vite": "^6.1.0",
|
|
54
54
|
"vitest": "~3.0.5",
|
|
55
55
|
"@cloudflare/mock-npm-registry": "0.0.0",
|
|
56
|
-
"@cloudflare/workers-
|
|
57
|
-
"@cloudflare/workers-
|
|
56
|
+
"@cloudflare/workers-shared": "0.0.0-fd9dff833",
|
|
57
|
+
"@cloudflare/workers-tsconfig": "0.0.0"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
60
|
"vite": "^6.1.0",
|
|
61
|
-
"wrangler": "^3.101.0
|
|
61
|
+
"wrangler": "^3.101.0"
|
|
62
62
|
},
|
|
63
63
|
"publishConfig": {
|
|
64
64
|
"access": "public"
|