@cloudflare/vite-plugin 0.1.16 → 0.1.18
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 +291 -136
- package/dist/runner-worker/index.js +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -248,17 +248,17 @@ var require_ignore = __commonJS({
|
|
|
248
248
|
var throwError = (message, Ctor) => {
|
|
249
249
|
throw new Ctor(message);
|
|
250
250
|
};
|
|
251
|
-
var checkPath = (
|
|
252
|
-
if (!isString(
|
|
251
|
+
var checkPath = (path10, originalPath, doThrow) => {
|
|
252
|
+
if (!isString(path10)) {
|
|
253
253
|
return doThrow(
|
|
254
254
|
`path must be a string, but got \`${originalPath}\``,
|
|
255
255
|
TypeError
|
|
256
256
|
);
|
|
257
257
|
}
|
|
258
|
-
if (!
|
|
258
|
+
if (!path10) {
|
|
259
259
|
return doThrow(`path must not be empty`, TypeError);
|
|
260
260
|
}
|
|
261
|
-
if (checkPath.isNotRelative(
|
|
261
|
+
if (checkPath.isNotRelative(path10)) {
|
|
262
262
|
const r2 = "`path.relative()`d";
|
|
263
263
|
return doThrow(
|
|
264
264
|
`path should be a ${r2} string, but got "${originalPath}"`,
|
|
@@ -267,7 +267,7 @@ var require_ignore = __commonJS({
|
|
|
267
267
|
}
|
|
268
268
|
return true;
|
|
269
269
|
};
|
|
270
|
-
var isNotRelative = (
|
|
270
|
+
var isNotRelative = (path10) => REGEX_TEST_INVALID_PATH.test(path10);
|
|
271
271
|
checkPath.isNotRelative = isNotRelative;
|
|
272
272
|
checkPath.convert = (p) => p;
|
|
273
273
|
var Ignore = class {
|
|
@@ -326,7 +326,7 @@ var require_ignore = __commonJS({
|
|
|
326
326
|
// setting `checkUnignored` to `false` could reduce additional
|
|
327
327
|
// path matching.
|
|
328
328
|
// @returns {TestResult} true if a file is ignored
|
|
329
|
-
_testOne(
|
|
329
|
+
_testOne(path10, checkUnignored) {
|
|
330
330
|
let ignored = false;
|
|
331
331
|
let unignored = false;
|
|
332
332
|
this._rules.forEach((rule) => {
|
|
@@ -334,7 +334,7 @@ var require_ignore = __commonJS({
|
|
|
334
334
|
if (unignored === negative && ignored !== unignored || negative && !ignored && !unignored && !checkUnignored) {
|
|
335
335
|
return;
|
|
336
336
|
}
|
|
337
|
-
const matched = rule.regex.test(
|
|
337
|
+
const matched = rule.regex.test(path10);
|
|
338
338
|
if (matched) {
|
|
339
339
|
ignored = !negative;
|
|
340
340
|
unignored = negative;
|
|
@@ -347,24 +347,24 @@ var require_ignore = __commonJS({
|
|
|
347
347
|
}
|
|
348
348
|
// @returns {TestResult}
|
|
349
349
|
_test(originalPath, cache2, checkUnignored, slices) {
|
|
350
|
-
const
|
|
350
|
+
const path10 = originalPath && checkPath.convert(originalPath);
|
|
351
351
|
checkPath(
|
|
352
|
-
|
|
352
|
+
path10,
|
|
353
353
|
originalPath,
|
|
354
354
|
this._allowRelativePaths ? RETURN_FALSE : throwError
|
|
355
355
|
);
|
|
356
|
-
return this._t(
|
|
356
|
+
return this._t(path10, cache2, checkUnignored, slices);
|
|
357
357
|
}
|
|
358
|
-
_t(
|
|
359
|
-
if (
|
|
360
|
-
return cache2[
|
|
358
|
+
_t(path10, cache2, checkUnignored, slices) {
|
|
359
|
+
if (path10 in cache2) {
|
|
360
|
+
return cache2[path10];
|
|
361
361
|
}
|
|
362
362
|
if (!slices) {
|
|
363
|
-
slices =
|
|
363
|
+
slices = path10.split(SLASH);
|
|
364
364
|
}
|
|
365
365
|
slices.pop();
|
|
366
366
|
if (!slices.length) {
|
|
367
|
-
return cache2[
|
|
367
|
+
return cache2[path10] = this._testOne(path10, checkUnignored);
|
|
368
368
|
}
|
|
369
369
|
const parent = this._t(
|
|
370
370
|
slices.join(SLASH) + SLASH,
|
|
@@ -372,24 +372,24 @@ var require_ignore = __commonJS({
|
|
|
372
372
|
checkUnignored,
|
|
373
373
|
slices
|
|
374
374
|
);
|
|
375
|
-
return cache2[
|
|
375
|
+
return cache2[path10] = parent.ignored ? parent : this._testOne(path10, checkUnignored);
|
|
376
376
|
}
|
|
377
|
-
ignores(
|
|
378
|
-
return this._test(
|
|
377
|
+
ignores(path10) {
|
|
378
|
+
return this._test(path10, this._ignoreCache, false).ignored;
|
|
379
379
|
}
|
|
380
380
|
createFilter() {
|
|
381
|
-
return (
|
|
381
|
+
return (path10) => !this.ignores(path10);
|
|
382
382
|
}
|
|
383
383
|
filter(paths) {
|
|
384
384
|
return makeArray(paths).filter(this.createFilter());
|
|
385
385
|
}
|
|
386
386
|
// @returns {TestResult}
|
|
387
|
-
test(
|
|
388
|
-
return this._test(
|
|
387
|
+
test(path10) {
|
|
388
|
+
return this._test(path10, this._testCache, true);
|
|
389
389
|
}
|
|
390
390
|
};
|
|
391
391
|
var factory = (options) => new Ignore(options);
|
|
392
|
-
var isPathValid = (
|
|
392
|
+
var isPathValid = (path10) => checkPath(path10 && checkPath.convert(path10), path10, RETURN_FALSE);
|
|
393
393
|
factory.isPathValid = isPathValid;
|
|
394
394
|
factory.default = factory;
|
|
395
395
|
module.exports = factory;
|
|
@@ -400,7 +400,7 @@ var require_ignore = __commonJS({
|
|
|
400
400
|
const makePosix = (str) => /^\\\\\?\\/.test(str) || /["<>|\u0000-\u001F]+/u.test(str) ? str : str.replace(/\\/g, "/");
|
|
401
401
|
checkPath.convert = makePosix;
|
|
402
402
|
const REGIX_IS_WINDOWS_PATH_ABSOLUTE = /^[a-z]:\//i;
|
|
403
|
-
checkPath.isNotRelative = (
|
|
403
|
+
checkPath.isNotRelative = (path10) => REGIX_IS_WINDOWS_PATH_ABSOLUTE.test(path10) || isNotRelative(path10);
|
|
404
404
|
}
|
|
405
405
|
}
|
|
406
406
|
});
|
|
@@ -443,11 +443,11 @@ var require_Mime = __commonJS({
|
|
|
443
443
|
}
|
|
444
444
|
}
|
|
445
445
|
};
|
|
446
|
-
Mime.prototype.getType = function(
|
|
447
|
-
|
|
448
|
-
let last =
|
|
446
|
+
Mime.prototype.getType = function(path10) {
|
|
447
|
+
path10 = String(path10);
|
|
448
|
+
let last = path10.replace(/^.*[/\\]/, "").toLowerCase();
|
|
449
449
|
let ext = last.replace(/^.*\./, "").toLowerCase();
|
|
450
|
-
let hasPath = last.length <
|
|
450
|
+
let hasPath = last.length < path10.length;
|
|
451
451
|
let hasDot = ext.length < last.length - 1;
|
|
452
452
|
return (hasDot || !hasPath) && this._types[ext] || null;
|
|
453
453
|
};
|
|
@@ -488,8 +488,7 @@ var require_mime = __commonJS({
|
|
|
488
488
|
import assert8 from "node:assert";
|
|
489
489
|
import * as fs5 from "node:fs";
|
|
490
490
|
import * as fsp2 from "node:fs/promises";
|
|
491
|
-
import
|
|
492
|
-
import * as path8 from "node:path";
|
|
491
|
+
import * as path9 from "node:path";
|
|
493
492
|
import { createMiddleware } from "@hattip/adapter-node";
|
|
494
493
|
|
|
495
494
|
// ../../node_modules/.pnpm/@jridgewell+sourcemap-codec@1.5.0/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
|
|
@@ -1558,7 +1557,7 @@ var MagicString = class _MagicString {
|
|
|
1558
1557
|
|
|
1559
1558
|
// src/index.ts
|
|
1560
1559
|
import { Miniflare } from "miniflare";
|
|
1561
|
-
import * as
|
|
1560
|
+
import * as vite7 from "vite";
|
|
1562
1561
|
|
|
1563
1562
|
// src/constants.ts
|
|
1564
1563
|
var ROUTER_WORKER_NAME = "__router-worker__";
|
|
@@ -1726,11 +1725,11 @@ ${invalidHeaderRulesList}`
|
|
|
1726
1725
|
}
|
|
1727
1726
|
|
|
1728
1727
|
// ../workers-shared/utils/configuration/validateURL.ts
|
|
1729
|
-
var extractPathname = (
|
|
1730
|
-
if (!
|
|
1731
|
-
|
|
1728
|
+
var extractPathname = (path10 = "/", includeSearch, includeHash) => {
|
|
1729
|
+
if (!path10.startsWith("/")) {
|
|
1730
|
+
path10 = `/${path10}`;
|
|
1732
1731
|
}
|
|
1733
|
-
const url = new URL(`//${
|
|
1732
|
+
const url = new URL(`//${path10}`, "relative://");
|
|
1734
1733
|
return `${url.pathname}${includeSearch ? url.search : ""}${includeHash ? url.hash : ""}`;
|
|
1735
1734
|
};
|
|
1736
1735
|
var URL_REGEX = /^https:\/\/+(?<host>[^/]+)\/?(?<path>.*)/;
|
|
@@ -1763,8 +1762,8 @@ var validateUrl = (token, onlyRelative = false, disallowPorts = false, includeSe
|
|
|
1763
1762
|
if (!token.startsWith("/") && onlyRelative) {
|
|
1764
1763
|
token = `/${token}`;
|
|
1765
1764
|
}
|
|
1766
|
-
const
|
|
1767
|
-
if (
|
|
1765
|
+
const path10 = PATH_REGEX.exec(token);
|
|
1766
|
+
if (path10) {
|
|
1768
1767
|
try {
|
|
1769
1768
|
return [extractPathname(token, includeSearch, includeHash), void 0];
|
|
1770
1769
|
} catch {
|
|
@@ -1825,7 +1824,7 @@ function parseHeaders(input, {
|
|
|
1825
1824
|
});
|
|
1826
1825
|
}
|
|
1827
1826
|
}
|
|
1828
|
-
const [
|
|
1827
|
+
const [path10, pathError] = validateUrl(line, false, true);
|
|
1829
1828
|
if (pathError) {
|
|
1830
1829
|
invalid.push({
|
|
1831
1830
|
line,
|
|
@@ -1836,7 +1835,7 @@ function parseHeaders(input, {
|
|
|
1836
1835
|
continue;
|
|
1837
1836
|
}
|
|
1838
1837
|
rule = {
|
|
1839
|
-
path:
|
|
1838
|
+
path: path10,
|
|
1840
1839
|
line,
|
|
1841
1840
|
headers: {},
|
|
1842
1841
|
unsetHeaders: []
|
|
@@ -2411,8 +2410,8 @@ function getErrorMap() {
|
|
|
2411
2410
|
return overrideErrorMap;
|
|
2412
2411
|
}
|
|
2413
2412
|
var makeIssue = (params) => {
|
|
2414
|
-
const { data: data2, path:
|
|
2415
|
-
const fullPath = [...
|
|
2413
|
+
const { data: data2, path: path10, errorMaps, issueData } = params;
|
|
2414
|
+
const fullPath = [...path10, ...issueData.path || []];
|
|
2416
2415
|
const fullIssue = {
|
|
2417
2416
|
...issueData,
|
|
2418
2417
|
path: fullPath
|
|
@@ -2511,11 +2510,11 @@ var errorUtil;
|
|
|
2511
2510
|
errorUtil2.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
|
|
2512
2511
|
})(errorUtil || (errorUtil = {}));
|
|
2513
2512
|
var ParseInputLazyPath = class {
|
|
2514
|
-
constructor(parent, value,
|
|
2513
|
+
constructor(parent, value, path10, key) {
|
|
2515
2514
|
this._cachedPath = [];
|
|
2516
2515
|
this.parent = parent;
|
|
2517
2516
|
this.data = value;
|
|
2518
|
-
this._path =
|
|
2517
|
+
this._path = path10;
|
|
2519
2518
|
this._key = key;
|
|
2520
2519
|
}
|
|
2521
2520
|
get path() {
|
|
@@ -5905,10 +5904,12 @@ function getHeadersConfigPath(config) {
|
|
|
5905
5904
|
|
|
5906
5905
|
// src/cloudflare-environment.ts
|
|
5907
5906
|
import assert3 from "node:assert";
|
|
5908
|
-
import * as
|
|
5907
|
+
import * as vite3 from "vite";
|
|
5909
5908
|
|
|
5910
5909
|
// src/node-js-compat.ts
|
|
5911
5910
|
import assert2 from "node:assert";
|
|
5911
|
+
import { builtinModules as builtinModules2 } from "node:module";
|
|
5912
|
+
import path3 from "node:path";
|
|
5912
5913
|
import { cloudflare } from "@cloudflare/unenv-preset";
|
|
5913
5914
|
import { getNodeCompat } from "miniflare";
|
|
5914
5915
|
|
|
@@ -11460,17 +11461,17 @@ function withTrailingSlash(input = "", respectQueryAndFragment) {
|
|
|
11460
11461
|
if (hasTrailingSlash(input, true)) {
|
|
11461
11462
|
return input || "/";
|
|
11462
11463
|
}
|
|
11463
|
-
let
|
|
11464
|
+
let path10 = input;
|
|
11464
11465
|
let fragment = "";
|
|
11465
11466
|
const fragmentIndex = input.indexOf("#");
|
|
11466
11467
|
if (fragmentIndex >= 0) {
|
|
11467
|
-
|
|
11468
|
+
path10 = input.slice(0, fragmentIndex);
|
|
11468
11469
|
fragment = input.slice(fragmentIndex);
|
|
11469
|
-
if (!
|
|
11470
|
+
if (!path10) {
|
|
11470
11471
|
return fragment;
|
|
11471
11472
|
}
|
|
11472
11473
|
}
|
|
11473
|
-
const [s0, ...s] =
|
|
11474
|
+
const [s0, ...s] = path10.split("?");
|
|
11474
11475
|
return s0 + "/" + (s.length > 0 ? `?${s.join("?")}` : "") + fragment;
|
|
11475
11476
|
}
|
|
11476
11477
|
function isNonEmptyURL(url) {
|
|
@@ -11504,8 +11505,8 @@ import path2, { dirname as dirname2 } from "node:path";
|
|
|
11504
11505
|
import v8 from "node:v8";
|
|
11505
11506
|
import { format as format2, inspect } from "node:util";
|
|
11506
11507
|
var BUILTIN_MODULES = new Set(builtinModules);
|
|
11507
|
-
function normalizeSlash(
|
|
11508
|
-
return
|
|
11508
|
+
function normalizeSlash(path10) {
|
|
11509
|
+
return path10.replace(/\\/g, "/");
|
|
11509
11510
|
}
|
|
11510
11511
|
var own$1 = {}.hasOwnProperty;
|
|
11511
11512
|
var classRegExp = /^([A-Z][a-z\d]*)+$/;
|
|
@@ -11618,8 +11619,8 @@ codes.ERR_INVALID_PACKAGE_CONFIG = createError(
|
|
|
11618
11619
|
* @param {string} [base]
|
|
11619
11620
|
* @param {string} [message]
|
|
11620
11621
|
*/
|
|
11621
|
-
(
|
|
11622
|
-
return `Invalid package config ${
|
|
11622
|
+
(path10, base, message) => {
|
|
11623
|
+
return `Invalid package config ${path10}${base ? ` while importing ${base}` : ""}${message ? `. ${message}` : ""}`;
|
|
11623
11624
|
},
|
|
11624
11625
|
Error
|
|
11625
11626
|
);
|
|
@@ -11651,8 +11652,8 @@ codes.ERR_MODULE_NOT_FOUND = createError(
|
|
|
11651
11652
|
* @param {string} base
|
|
11652
11653
|
* @param {boolean} [exactUrl]
|
|
11653
11654
|
*/
|
|
11654
|
-
(
|
|
11655
|
-
return `Cannot find ${exactUrl ? "module" : "package"} '${
|
|
11655
|
+
(path10, base, exactUrl = false) => {
|
|
11656
|
+
return `Cannot find ${exactUrl ? "module" : "package"} '${path10}' imported from ${base}`;
|
|
11656
11657
|
},
|
|
11657
11658
|
Error
|
|
11658
11659
|
);
|
|
@@ -11703,8 +11704,8 @@ codes.ERR_UNKNOWN_FILE_EXTENSION = createError(
|
|
|
11703
11704
|
* @param {string} extension
|
|
11704
11705
|
* @param {string} path
|
|
11705
11706
|
*/
|
|
11706
|
-
(extension,
|
|
11707
|
-
return `Unknown file extension "${extension}" for ${
|
|
11707
|
+
(extension, path10) => {
|
|
11708
|
+
return `Unknown file extension "${extension}" for ${path10}`;
|
|
11708
11709
|
},
|
|
11709
11710
|
TypeError
|
|
11710
11711
|
);
|
|
@@ -12076,9 +12077,9 @@ Default "index" lookups for the main are deprecated for ES modules.`,
|
|
|
12076
12077
|
);
|
|
12077
12078
|
}
|
|
12078
12079
|
}
|
|
12079
|
-
function tryStatSync(
|
|
12080
|
+
function tryStatSync(path10) {
|
|
12080
12081
|
try {
|
|
12081
|
-
return statSync(
|
|
12082
|
+
return statSync(path10);
|
|
12082
12083
|
} catch {
|
|
12083
12084
|
}
|
|
12084
12085
|
}
|
|
@@ -12845,12 +12846,20 @@ function resolvePathSync(id, options) {
|
|
|
12845
12846
|
|
|
12846
12847
|
// src/node-js-compat.ts
|
|
12847
12848
|
import { defineEnv } from "unenv";
|
|
12849
|
+
import "vite";
|
|
12848
12850
|
var { env } = defineEnv({
|
|
12849
12851
|
nodeCompat: true,
|
|
12850
12852
|
presets: [cloudflare]
|
|
12851
12853
|
});
|
|
12852
12854
|
var nodeCompatExternals = new Set(env.external);
|
|
12853
12855
|
var nodeCompatEntries = getNodeCompatEntries();
|
|
12856
|
+
var nodejsBuiltins = /* @__PURE__ */ new Set([
|
|
12857
|
+
...builtinModules2,
|
|
12858
|
+
...builtinModules2.map((m) => `node:${m}`)
|
|
12859
|
+
]);
|
|
12860
|
+
var NODEJS_MODULES_RE = new RegExp(
|
|
12861
|
+
`^(node:)?(${builtinModules2.join("|")})$`
|
|
12862
|
+
);
|
|
12854
12863
|
function isNodeCompat(workerConfig) {
|
|
12855
12864
|
if (workerConfig === void 0) {
|
|
12856
12865
|
return false;
|
|
@@ -12929,6 +12938,46 @@ function getNodeCompatEntries() {
|
|
|
12929
12938
|
nodeCompatExternals.forEach((external) => entries.delete(external));
|
|
12930
12939
|
return entries;
|
|
12931
12940
|
}
|
|
12941
|
+
var NodeJsCompatWarnings = class {
|
|
12942
|
+
constructor(environment) {
|
|
12943
|
+
this.environment = environment;
|
|
12944
|
+
}
|
|
12945
|
+
sources = /* @__PURE__ */ new Map();
|
|
12946
|
+
timer;
|
|
12947
|
+
registerImport(source, importer = "<unknown>") {
|
|
12948
|
+
const importers = this.sources.get(source) ?? /* @__PURE__ */ new Set();
|
|
12949
|
+
this.sources.set(source, importers);
|
|
12950
|
+
importers.add(importer);
|
|
12951
|
+
}
|
|
12952
|
+
renderWarningsOnIdle() {
|
|
12953
|
+
if (this.timer) {
|
|
12954
|
+
clearTimeout(this.timer);
|
|
12955
|
+
}
|
|
12956
|
+
this.timer = setTimeout(() => {
|
|
12957
|
+
this.renderWarnings();
|
|
12958
|
+
this.timer = void 0;
|
|
12959
|
+
}, 500);
|
|
12960
|
+
}
|
|
12961
|
+
renderWarnings() {
|
|
12962
|
+
if (this.sources.size > 0) {
|
|
12963
|
+
let message = `
|
|
12964
|
+
|
|
12965
|
+
Unexpected Node.js imports for environment "${this.environment.name}". Do you need to enable the "nodejs_compat" compatibility flag?
|
|
12966
|
+
Refer to https://developers.cloudflare.com/workers/runtime-apis/nodejs/ for more details.
|
|
12967
|
+
`;
|
|
12968
|
+
this.sources.forEach((importers, source) => {
|
|
12969
|
+
importers.forEach((importer) => {
|
|
12970
|
+
message += ` - "${source}" imported from "${path3.relative(this.environment.config.root, importer)}"
|
|
12971
|
+
`;
|
|
12972
|
+
});
|
|
12973
|
+
});
|
|
12974
|
+
this.environment.logger.warn(message, {
|
|
12975
|
+
environment: this.environment.name
|
|
12976
|
+
});
|
|
12977
|
+
this.sources.clear();
|
|
12978
|
+
}
|
|
12979
|
+
}
|
|
12980
|
+
};
|
|
12932
12981
|
|
|
12933
12982
|
// src/shared.ts
|
|
12934
12983
|
var UNKNOWN_HOST = "http://localhost";
|
|
@@ -12942,15 +12991,15 @@ var additionalModuleGlobalRE = new RegExp(
|
|
|
12942
12991
|
var VITE_DEV_METADATA_HEADER = "__VITE_DEV_METADATA__";
|
|
12943
12992
|
|
|
12944
12993
|
// src/utils.ts
|
|
12945
|
-
import * as
|
|
12994
|
+
import * as path4 from "node:path";
|
|
12946
12995
|
import { Request as MiniflareRequest } from "miniflare";
|
|
12947
12996
|
import "vite";
|
|
12948
12997
|
function getOutputDirectory(userConfig, environmentName) {
|
|
12949
12998
|
const rootOutputDirectory = userConfig.build?.outDir ?? "dist";
|
|
12950
|
-
return userConfig.environments?.[environmentName]?.build?.outDir ??
|
|
12999
|
+
return userConfig.environments?.[environmentName]?.build?.outDir ?? path4.join(rootOutputDirectory, environmentName);
|
|
12951
13000
|
}
|
|
12952
|
-
function getRouterWorker(
|
|
12953
|
-
return
|
|
13001
|
+
function getRouterWorker(miniflare2) {
|
|
13002
|
+
return miniflare2.getWorker(ROUTER_WORKER_NAME);
|
|
12954
13003
|
}
|
|
12955
13004
|
function toMiniflareRequest(request) {
|
|
12956
13005
|
const secFetchMode = request.headers.get("Sec-Fetch-Mode");
|
|
@@ -13026,7 +13075,7 @@ function createHotChannel(webSocketContainer) {
|
|
|
13026
13075
|
}
|
|
13027
13076
|
};
|
|
13028
13077
|
}
|
|
13029
|
-
var CloudflareDevEnvironment = class extends
|
|
13078
|
+
var CloudflareDevEnvironment = class extends vite3.DevEnvironment {
|
|
13030
13079
|
#webSocketContainer;
|
|
13031
13080
|
#worker;
|
|
13032
13081
|
constructor(name, config) {
|
|
@@ -13087,7 +13136,7 @@ function createCloudflareEnvironmentOptions(workerConfig, userConfig, environmen
|
|
|
13087
13136
|
},
|
|
13088
13137
|
build: {
|
|
13089
13138
|
createEnvironment(name, config) {
|
|
13090
|
-
return new
|
|
13139
|
+
return new vite3.BuildEnvironment(name, config);
|
|
13091
13140
|
},
|
|
13092
13141
|
target,
|
|
13093
13142
|
// We need to enable `emitAssets` in order to support additional modules defined by `rules`
|
|
@@ -13130,14 +13179,14 @@ function createCloudflareEnvironmentOptions(workerConfig, userConfig, environmen
|
|
|
13130
13179
|
keepProcessEnv: isNodeCompat(workerConfig)
|
|
13131
13180
|
};
|
|
13132
13181
|
}
|
|
13133
|
-
function initRunners(resolvedPluginConfig, viteDevServer,
|
|
13182
|
+
function initRunners(resolvedPluginConfig, viteDevServer, miniflare2) {
|
|
13134
13183
|
if (resolvedPluginConfig.type === "assets-only") {
|
|
13135
13184
|
return;
|
|
13136
13185
|
}
|
|
13137
13186
|
return Promise.all(
|
|
13138
13187
|
Object.entries(resolvedPluginConfig.workers).map(
|
|
13139
13188
|
async ([environmentName, workerConfig]) => {
|
|
13140
|
-
const worker = await
|
|
13189
|
+
const worker = await miniflare2.getWorker(workerConfig.name);
|
|
13141
13190
|
return viteDevServer.environments[environmentName].initRunner(worker, viteDevServer.config.root, workerConfig);
|
|
13142
13191
|
}
|
|
13143
13192
|
)
|
|
@@ -13196,11 +13245,11 @@ function getDebugPathHtml(workerNames, inspectorPort) {
|
|
|
13196
13245
|
// src/deploy-config.ts
|
|
13197
13246
|
import assert5 from "node:assert";
|
|
13198
13247
|
import * as fs2 from "node:fs";
|
|
13199
|
-
import * as
|
|
13248
|
+
import * as path5 from "node:path";
|
|
13200
13249
|
import "vite";
|
|
13201
13250
|
import { unstable_readConfig } from "wrangler";
|
|
13202
13251
|
function getDeployConfigPath(root) {
|
|
13203
|
-
return
|
|
13252
|
+
return path5.resolve(root, ".wrangler", "deploy", "config.json");
|
|
13204
13253
|
}
|
|
13205
13254
|
function getWorkerConfigs(root) {
|
|
13206
13255
|
const deployConfigPath = getDeployConfigPath(root);
|
|
@@ -13211,22 +13260,22 @@ function getWorkerConfigs(root) {
|
|
|
13211
13260
|
{ configPath: deployConfig.configPath },
|
|
13212
13261
|
...deployConfig.auxiliaryWorkers
|
|
13213
13262
|
].map(({ configPath }) => {
|
|
13214
|
-
const resolvedConfigPath =
|
|
13215
|
-
|
|
13263
|
+
const resolvedConfigPath = path5.resolve(
|
|
13264
|
+
path5.dirname(deployConfigPath),
|
|
13216
13265
|
configPath
|
|
13217
13266
|
);
|
|
13218
13267
|
return unstable_readConfig({ config: resolvedConfigPath });
|
|
13219
13268
|
});
|
|
13220
13269
|
}
|
|
13221
13270
|
function getRelativePathToWorkerConfig(deployConfigDirectory, root, outputDirectory) {
|
|
13222
|
-
return
|
|
13271
|
+
return path5.relative(
|
|
13223
13272
|
deployConfigDirectory,
|
|
13224
|
-
|
|
13273
|
+
path5.resolve(root, outputDirectory, "wrangler.json")
|
|
13225
13274
|
);
|
|
13226
13275
|
}
|
|
13227
13276
|
function writeDeployConfig(resolvedPluginConfig, resolvedViteConfig) {
|
|
13228
13277
|
const deployConfigPath = getDeployConfigPath(resolvedViteConfig.root);
|
|
13229
|
-
const deployConfigDirectory =
|
|
13278
|
+
const deployConfigDirectory = path5.dirname(deployConfigPath);
|
|
13230
13279
|
fs2.mkdirSync(deployConfigDirectory, { recursive: true });
|
|
13231
13280
|
if (resolvedPluginConfig.type === "assets-only") {
|
|
13232
13281
|
const clientOutputDirectory = resolvedViteConfig.environments.client?.build.outDir;
|
|
@@ -13279,7 +13328,7 @@ function writeDeployConfig(resolvedPluginConfig, resolvedViteConfig) {
|
|
|
13279
13328
|
import assert6 from "node:assert";
|
|
13280
13329
|
import * as fs3 from "node:fs";
|
|
13281
13330
|
import * as fsp from "node:fs/promises";
|
|
13282
|
-
import * as
|
|
13331
|
+
import * as path6 from "node:path";
|
|
13283
13332
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
13284
13333
|
import {
|
|
13285
13334
|
kCurrentWorker,
|
|
@@ -13295,18 +13344,18 @@ function getPersistence(root, persistState) {
|
|
|
13295
13344
|
return {};
|
|
13296
13345
|
}
|
|
13297
13346
|
const defaultPersistPath = ".wrangler/state";
|
|
13298
|
-
const persistPath =
|
|
13347
|
+
const persistPath = path6.resolve(
|
|
13299
13348
|
root,
|
|
13300
13349
|
typeof persistState === "object" ? persistState.path : defaultPersistPath,
|
|
13301
13350
|
"v3"
|
|
13302
13351
|
);
|
|
13303
13352
|
return {
|
|
13304
|
-
cachePersist:
|
|
13305
|
-
d1Persist:
|
|
13306
|
-
durableObjectsPersist:
|
|
13307
|
-
kvPersist:
|
|
13308
|
-
r2Persist:
|
|
13309
|
-
workflowsPersist:
|
|
13353
|
+
cachePersist: path6.join(persistPath, "cache"),
|
|
13354
|
+
d1Persist: path6.join(persistPath, "d1"),
|
|
13355
|
+
durableObjectsPersist: path6.join(persistPath, "do"),
|
|
13356
|
+
kvPersist: path6.join(persistPath, "kv"),
|
|
13357
|
+
r2Persist: path6.join(persistPath, "r2"),
|
|
13358
|
+
workflowsPersist: path6.join(persistPath, "workflows")
|
|
13310
13359
|
};
|
|
13311
13360
|
}
|
|
13312
13361
|
function missingWorkerErrorMessage(workerName) {
|
|
@@ -13407,7 +13456,7 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer) {
|
|
|
13407
13456
|
modules: [
|
|
13408
13457
|
{
|
|
13409
13458
|
type: "ESModule",
|
|
13410
|
-
path:
|
|
13459
|
+
path: path6.join(miniflareModulesRoot, ROUTER_WORKER_PATH),
|
|
13411
13460
|
contents: fs3.readFileSync(
|
|
13412
13461
|
fileURLToPath2(new URL(ROUTER_WORKER_PATH, import.meta.url))
|
|
13413
13462
|
)
|
|
@@ -13430,7 +13479,7 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer) {
|
|
|
13430
13479
|
modules: [
|
|
13431
13480
|
{
|
|
13432
13481
|
type: "ESModule",
|
|
13433
|
-
path:
|
|
13482
|
+
path: path6.join(miniflareModulesRoot, ASSET_WORKER_PATH),
|
|
13434
13483
|
contents: fs3.readFileSync(
|
|
13435
13484
|
fileURLToPath2(new URL(ASSET_WORKER_PATH, import.meta.url))
|
|
13436
13485
|
)
|
|
@@ -13442,7 +13491,7 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer) {
|
|
|
13442
13491
|
serviceBindings: {
|
|
13443
13492
|
__VITE_ASSET_EXISTS__: async (request) => {
|
|
13444
13493
|
const { pathname } = new URL(request.url);
|
|
13445
|
-
const filePath =
|
|
13494
|
+
const filePath = path6.join(resolvedViteConfig.root, pathname);
|
|
13446
13495
|
let exists;
|
|
13447
13496
|
try {
|
|
13448
13497
|
exists = fs3.statSync(filePath).isFile();
|
|
@@ -13453,7 +13502,7 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer) {
|
|
|
13453
13502
|
},
|
|
13454
13503
|
__VITE_FETCH_ASSET__: async (request) => {
|
|
13455
13504
|
const { pathname } = new URL(request.url);
|
|
13456
|
-
const filePath =
|
|
13505
|
+
const filePath = path6.join(resolvedViteConfig.root, pathname);
|
|
13457
13506
|
try {
|
|
13458
13507
|
let html = await fsp.readFile(filePath, "utf-8");
|
|
13459
13508
|
html = await viteDevServer.transformIndexHtml(pathname, html);
|
|
@@ -13585,12 +13634,12 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer) {
|
|
|
13585
13634
|
modules: [
|
|
13586
13635
|
{
|
|
13587
13636
|
type: "ESModule",
|
|
13588
|
-
path:
|
|
13637
|
+
path: path6.join(miniflareModulesRoot, WRAPPER_PATH),
|
|
13589
13638
|
contents: wrappers.join("\n")
|
|
13590
13639
|
},
|
|
13591
13640
|
{
|
|
13592
13641
|
type: "ESModule",
|
|
13593
|
-
path:
|
|
13642
|
+
path: path6.join(miniflareModulesRoot, RUNNER_PATH),
|
|
13594
13643
|
contents: fs3.readFileSync(
|
|
13595
13644
|
fileURLToPath2(new URL(RUNNER_PATH, import.meta.url))
|
|
13596
13645
|
)
|
|
@@ -13645,8 +13694,8 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer) {
|
|
|
13645
13694
|
}
|
|
13646
13695
|
function getPreviewModules(main, modulesRules) {
|
|
13647
13696
|
assert6(modulesRules, `Unexpected error: 'modulesRules' is undefined`);
|
|
13648
|
-
const rootPath =
|
|
13649
|
-
const entryPath =
|
|
13697
|
+
const rootPath = path6.dirname(main);
|
|
13698
|
+
const entryPath = path6.basename(main);
|
|
13650
13699
|
return {
|
|
13651
13700
|
rootPath,
|
|
13652
13701
|
modules: [
|
|
@@ -13655,9 +13704,9 @@ function getPreviewModules(main, modulesRules) {
|
|
|
13655
13704
|
path: entryPath
|
|
13656
13705
|
},
|
|
13657
13706
|
...modulesRules.flatMap(
|
|
13658
|
-
({ type, include }) => globSync(include, { cwd: rootPath, ignore: entryPath }).map((
|
|
13707
|
+
({ type, include }) => globSync(include, { cwd: rootPath, ignore: entryPath }).map((path10) => ({
|
|
13659
13708
|
type,
|
|
13660
|
-
path:
|
|
13709
|
+
path: path10
|
|
13661
13710
|
}))
|
|
13662
13711
|
)
|
|
13663
13712
|
]
|
|
@@ -13695,6 +13744,7 @@ function getPreviewMiniflareOptions(vitePreviewServer, workerConfigs, persistSta
|
|
|
13695
13744
|
workers
|
|
13696
13745
|
};
|
|
13697
13746
|
}
|
|
13747
|
+
var removedMessages = [/^Ready on http/, /^Updated and ready on http/];
|
|
13698
13748
|
var ViteMiniflareLogger = class extends Log {
|
|
13699
13749
|
logger;
|
|
13700
13750
|
constructor(config) {
|
|
@@ -13702,8 +13752,10 @@ var ViteMiniflareLogger = class extends Log {
|
|
|
13702
13752
|
this.logger = config.logger;
|
|
13703
13753
|
}
|
|
13704
13754
|
logWithLevel(level, message) {
|
|
13705
|
-
|
|
13706
|
-
|
|
13755
|
+
for (const removedMessage of removedMessages) {
|
|
13756
|
+
if (removedMessage.test(message)) {
|
|
13757
|
+
return;
|
|
13758
|
+
}
|
|
13707
13759
|
}
|
|
13708
13760
|
switch (level) {
|
|
13709
13761
|
case LogLevel.ERROR:
|
|
@@ -13730,12 +13782,12 @@ function miniflareLogLevelFromViteLogLevel(level = "info") {
|
|
|
13730
13782
|
|
|
13731
13783
|
// src/plugin-config.ts
|
|
13732
13784
|
import assert7 from "node:assert";
|
|
13733
|
-
import * as
|
|
13734
|
-
import * as
|
|
13785
|
+
import * as path8 from "node:path";
|
|
13786
|
+
import * as vite6 from "vite";
|
|
13735
13787
|
|
|
13736
13788
|
// src/workers-configs.ts
|
|
13737
13789
|
import * as fs4 from "node:fs";
|
|
13738
|
-
import * as
|
|
13790
|
+
import * as path7 from "node:path";
|
|
13739
13791
|
import { unstable_readConfig as unstable_readConfig2 } from "wrangler";
|
|
13740
13792
|
var nonApplicableWorkerConfigs = {
|
|
13741
13793
|
/**
|
|
@@ -13829,7 +13881,7 @@ function getWarningForWorkersConfigs(configs) {
|
|
|
13829
13881
|
const lines2 = [
|
|
13830
13882
|
`
|
|
13831
13883
|
|
|
13832
|
-
\x1B[43mWARNING\x1B[0m: your worker config${configs.entryWorker.config.configPath ? ` (at \`${
|
|
13884
|
+
\x1B[43mWARNING\x1B[0m: your worker config${configs.entryWorker.config.configPath ? ` (at \`${path7.relative("", configs.entryWorker.config.configPath)}\`)` : ""} contains the following configuration options which are ignored since they are not applicable when using Vite:`
|
|
13833
13885
|
];
|
|
13834
13886
|
nonApplicableLines.forEach((line) => lines2.push(line));
|
|
13835
13887
|
lines2.push("");
|
|
@@ -13843,7 +13895,7 @@ function getWarningForWorkersConfigs(configs) {
|
|
|
13843
13895
|
);
|
|
13844
13896
|
if (nonApplicableLines.length > 0) {
|
|
13845
13897
|
lines.push(
|
|
13846
|
-
` - (${isEntryWorker ? "entry" : "auxiliary"}) worker${workerConfig.config.name ? ` "${workerConfig.config.name}"` : ""}${workerConfig.config.configPath ? ` (config at \`${
|
|
13898
|
+
` - (${isEntryWorker ? "entry" : "auxiliary"}) worker${workerConfig.config.name ? ` "${workerConfig.config.name}"` : ""}${workerConfig.config.configPath ? ` (config at \`${path7.relative("", workerConfig.config.configPath)}\`)` : ""}`
|
|
13847
13899
|
);
|
|
13848
13900
|
nonApplicableLines.forEach((line) => lines.push(line));
|
|
13849
13901
|
}
|
|
@@ -13944,7 +13996,7 @@ function getWorkerConfig(configPath, env2, opts) {
|
|
|
13944
13996
|
}
|
|
13945
13997
|
function findWranglerConfig(root) {
|
|
13946
13998
|
for (const extension of ["json", "jsonc", "toml"]) {
|
|
13947
|
-
const configPath =
|
|
13999
|
+
const configPath = path7.join(root, `wrangler.${extension}`);
|
|
13948
14000
|
if (fs4.existsSync(configPath)) {
|
|
13949
14001
|
return configPath;
|
|
13950
14002
|
}
|
|
@@ -13960,14 +14012,14 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
13960
14012
|
const persistState = pluginConfig.persistState ?? true;
|
|
13961
14013
|
const inspectorPort = pluginConfig.inspectorPort ?? DEFAULT_INSPECTOR_PORT;
|
|
13962
14014
|
const experimental = pluginConfig.experimental ?? {};
|
|
13963
|
-
const root = userConfig.root ?
|
|
13964
|
-
const { CLOUDFLARE_ENV: cloudflareEnv } =
|
|
14015
|
+
const root = userConfig.root ? path8.resolve(userConfig.root) : process.cwd();
|
|
14016
|
+
const { CLOUDFLARE_ENV: cloudflareEnv } = vite6.loadEnv(
|
|
13965
14017
|
viteEnv.mode,
|
|
13966
14018
|
root,
|
|
13967
14019
|
/* prefixes */
|
|
13968
14020
|
""
|
|
13969
14021
|
);
|
|
13970
|
-
const configPath = pluginConfig.configPath ?
|
|
14022
|
+
const configPath = pluginConfig.configPath ? path8.resolve(root, pluginConfig.configPath) : findWranglerConfig(root);
|
|
13971
14023
|
if (!configPath) {
|
|
13972
14024
|
throw new Error(
|
|
13973
14025
|
`Config not found. Have you created a wrangler.json(c) or wrangler.toml file?`
|
|
@@ -13999,7 +14051,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
13999
14051
|
const auxiliaryWorkersResolvedConfigs = [];
|
|
14000
14052
|
for (const auxiliaryWorker of pluginConfig.auxiliaryWorkers ?? []) {
|
|
14001
14053
|
const workerResolvedConfig = getWorkerConfig(
|
|
14002
|
-
|
|
14054
|
+
path8.resolve(root, auxiliaryWorker.configPath),
|
|
14003
14055
|
cloudflareEnv,
|
|
14004
14056
|
{
|
|
14005
14057
|
visitedConfigPaths: configPaths
|
|
@@ -14038,7 +14090,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
14038
14090
|
// src/websockets.ts
|
|
14039
14091
|
import { coupleWebSocket } from "miniflare";
|
|
14040
14092
|
import { WebSocketServer } from "ws";
|
|
14041
|
-
function handleWebSocket(httpServer,
|
|
14093
|
+
function handleWebSocket(httpServer, getFetcher) {
|
|
14042
14094
|
const nodeWebSocket = new WebSocketServer({ noServer: true });
|
|
14043
14095
|
httpServer.on(
|
|
14044
14096
|
"upgrade",
|
|
@@ -14048,6 +14100,7 @@ function handleWebSocket(httpServer, fetcher) {
|
|
|
14048
14100
|
return;
|
|
14049
14101
|
}
|
|
14050
14102
|
const headers = nodeHeadersToWebHeaders(request.headers);
|
|
14103
|
+
const fetcher = await getFetcher();
|
|
14051
14104
|
const response = await fetcher(url, {
|
|
14052
14105
|
headers,
|
|
14053
14106
|
method: request.method
|
|
@@ -14072,11 +14125,12 @@ function handleWebSocket(httpServer, fetcher) {
|
|
|
14072
14125
|
|
|
14073
14126
|
// src/index.ts
|
|
14074
14127
|
var workersConfigsWarningShown = false;
|
|
14128
|
+
var miniflare;
|
|
14075
14129
|
function cloudflare2(pluginConfig = {}) {
|
|
14076
14130
|
let resolvedPluginConfig;
|
|
14077
14131
|
let resolvedViteConfig;
|
|
14078
|
-
let miniflare;
|
|
14079
14132
|
const additionalModulePaths = /* @__PURE__ */ new Set();
|
|
14133
|
+
const nodeJsCompatWarningsMap = /* @__PURE__ */ new Map();
|
|
14080
14134
|
let hasClientBuild = false;
|
|
14081
14135
|
return [
|
|
14082
14136
|
{
|
|
@@ -14127,7 +14181,7 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14127
14181
|
builder: {
|
|
14128
14182
|
buildApp: userConfig.builder?.buildApp ?? (async (builder) => {
|
|
14129
14183
|
const clientEnvironment = builder.environments.client;
|
|
14130
|
-
const defaultHtmlPath =
|
|
14184
|
+
const defaultHtmlPath = path9.resolve(
|
|
14131
14185
|
builder.config.root,
|
|
14132
14186
|
"index.html"
|
|
14133
14187
|
);
|
|
@@ -14186,9 +14240,9 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14186
14240
|
);
|
|
14187
14241
|
workerConfig.assets = {
|
|
14188
14242
|
...workerConfig.assets,
|
|
14189
|
-
directory:
|
|
14190
|
-
|
|
14191
|
-
|
|
14243
|
+
directory: path9.relative(
|
|
14244
|
+
path9.resolve(resolvedViteConfig.root, workerOutputDirectory),
|
|
14245
|
+
path9.resolve(resolvedViteConfig.root, clientOutputDirectory)
|
|
14192
14246
|
)
|
|
14193
14247
|
};
|
|
14194
14248
|
} else {
|
|
@@ -14243,19 +14297,17 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14243
14297
|
writeDeployConfig(resolvedPluginConfig, resolvedViteConfig);
|
|
14244
14298
|
}
|
|
14245
14299
|
},
|
|
14246
|
-
|
|
14247
|
-
if (
|
|
14248
|
-
|
|
14249
|
-
|
|
14250
|
-
|
|
14251
|
-
|
|
14300
|
+
hotUpdate(options) {
|
|
14301
|
+
if (
|
|
14302
|
+
// Vite normalizes `options.file` so we use `path.resolve` for Windows compatibility
|
|
14303
|
+
resolvedPluginConfig.configPaths.has(path9.resolve(options.file)) || hasAssetsConfigChanged(
|
|
14304
|
+
resolvedPluginConfig,
|
|
14305
|
+
resolvedViteConfig,
|
|
14306
|
+
options.file
|
|
14307
|
+
)
|
|
14308
|
+
) {
|
|
14252
14309
|
options.server.restart();
|
|
14253
|
-
|
|
14254
|
-
},
|
|
14255
|
-
async buildEnd() {
|
|
14256
|
-
if (miniflare) {
|
|
14257
|
-
await miniflare.dispose();
|
|
14258
|
-
miniflare = void 0;
|
|
14310
|
+
return [];
|
|
14259
14311
|
}
|
|
14260
14312
|
},
|
|
14261
14313
|
async configureServer(viteDevServer) {
|
|
@@ -14263,20 +14315,31 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14263
14315
|
viteDevServer.httpServer,
|
|
14264
14316
|
"Unexpected error: No Vite HTTP server"
|
|
14265
14317
|
);
|
|
14266
|
-
miniflare
|
|
14267
|
-
|
|
14268
|
-
|
|
14318
|
+
if (miniflare) {
|
|
14319
|
+
await miniflare.setOptions(
|
|
14320
|
+
getDevMiniflareOptions(resolvedPluginConfig, viteDevServer)
|
|
14321
|
+
);
|
|
14322
|
+
} else {
|
|
14323
|
+
miniflare = new Miniflare(
|
|
14324
|
+
getDevMiniflareOptions(resolvedPluginConfig, viteDevServer)
|
|
14325
|
+
);
|
|
14326
|
+
}
|
|
14269
14327
|
await initRunners(resolvedPluginConfig, viteDevServer, miniflare);
|
|
14270
|
-
const routerWorker = await getRouterWorker(miniflare);
|
|
14271
14328
|
const middleware = createMiddleware(
|
|
14272
|
-
({ request }) => {
|
|
14329
|
+
async ({ request }) => {
|
|
14330
|
+
assert8(miniflare, `Miniflare not defined`);
|
|
14331
|
+
const routerWorker = await getRouterWorker(miniflare);
|
|
14273
14332
|
return routerWorker.fetch(toMiniflareRequest(request), {
|
|
14274
14333
|
redirect: "manual"
|
|
14275
14334
|
});
|
|
14276
14335
|
},
|
|
14277
14336
|
{ alwaysCallNext: false }
|
|
14278
14337
|
);
|
|
14279
|
-
handleWebSocket(viteDevServer.httpServer,
|
|
14338
|
+
handleWebSocket(viteDevServer.httpServer, async () => {
|
|
14339
|
+
assert8(miniflare, `Miniflare not defined`);
|
|
14340
|
+
const routerWorker = await getRouterWorker(miniflare);
|
|
14341
|
+
return routerWorker.fetch;
|
|
14342
|
+
});
|
|
14280
14343
|
return () => {
|
|
14281
14344
|
viteDevServer.middlewares.use((req, res, next) => {
|
|
14282
14345
|
middleware(req, res, next);
|
|
@@ -14301,7 +14364,10 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14301
14364
|
},
|
|
14302
14365
|
{ alwaysCallNext: false }
|
|
14303
14366
|
);
|
|
14304
|
-
handleWebSocket(
|
|
14367
|
+
handleWebSocket(
|
|
14368
|
+
vitePreviewServer.httpServer,
|
|
14369
|
+
() => miniflare2.dispatchFetch
|
|
14370
|
+
);
|
|
14305
14371
|
vitePreviewServer.middlewares.use((req, res, next) => {
|
|
14306
14372
|
middleware(req, res, next);
|
|
14307
14373
|
});
|
|
@@ -14357,6 +14423,7 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14357
14423
|
hotUpdate(options) {
|
|
14358
14424
|
if (additionalModulePaths.has(options.file)) {
|
|
14359
14425
|
options.server.restart();
|
|
14426
|
+
return [];
|
|
14360
14427
|
}
|
|
14361
14428
|
},
|
|
14362
14429
|
async renderChunk(code, chunk) {
|
|
@@ -14379,13 +14446,13 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14379
14446
|
}
|
|
14380
14447
|
const referenceId = this.emitFile({
|
|
14381
14448
|
type: "asset",
|
|
14382
|
-
name:
|
|
14449
|
+
name: path9.basename(modulePath),
|
|
14383
14450
|
originalFileName: modulePath,
|
|
14384
14451
|
source
|
|
14385
14452
|
});
|
|
14386
14453
|
const emittedFileName = this.getFileName(referenceId);
|
|
14387
|
-
const relativePath =
|
|
14388
|
-
|
|
14454
|
+
const relativePath = vite7.normalizePath(
|
|
14455
|
+
path9.relative(path9.dirname(chunk.fileName), emittedFileName)
|
|
14389
14456
|
);
|
|
14390
14457
|
const importPath = relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
|
|
14391
14458
|
magicString.update(
|
|
@@ -14427,10 +14494,7 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14427
14494
|
// Obviously we don't want/need the optimizer to try to process modules that are built-in;
|
|
14428
14495
|
// But also we want to avoid following the ones that are polyfilled since the dependency-optimizer import analyzer does not
|
|
14429
14496
|
// resolve these imports using our `resolveId()` hook causing the optimization step to fail.
|
|
14430
|
-
exclude: [
|
|
14431
|
-
...builtinModules2,
|
|
14432
|
-
...builtinModules2.map((m) => `node:${m}`)
|
|
14433
|
-
]
|
|
14497
|
+
exclude: [...nodejsBuiltins]
|
|
14434
14498
|
}
|
|
14435
14499
|
};
|
|
14436
14500
|
}
|
|
@@ -14500,7 +14564,7 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14500
14564
|
addDebugToVitePrintUrls(vitePreviewServer);
|
|
14501
14565
|
}
|
|
14502
14566
|
const workerNames = workerConfigs.map((worker) => {
|
|
14503
|
-
assert8(worker.name);
|
|
14567
|
+
assert8(worker.name, "Expected the Worker to have a name");
|
|
14504
14568
|
return worker.name;
|
|
14505
14569
|
});
|
|
14506
14570
|
vitePreviewServer.middlewares.use((req, res, next) => {
|
|
@@ -14515,6 +14579,97 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14515
14579
|
next();
|
|
14516
14580
|
});
|
|
14517
14581
|
}
|
|
14582
|
+
},
|
|
14583
|
+
// Plugin to warn if Node.js APIs are being used without nodejs_compat turned on
|
|
14584
|
+
{
|
|
14585
|
+
name: "vite-plugin-cloudflare:nodejs-compat-warnings",
|
|
14586
|
+
apply(_config, env2) {
|
|
14587
|
+
return !env2.isPreview;
|
|
14588
|
+
},
|
|
14589
|
+
configEnvironment(environmentName) {
|
|
14590
|
+
const workerConfig = getWorkerConfig2(environmentName);
|
|
14591
|
+
if (workerConfig && !isNodeCompat(workerConfig)) {
|
|
14592
|
+
return {
|
|
14593
|
+
optimizeDeps: {
|
|
14594
|
+
esbuildOptions: {
|
|
14595
|
+
plugins: [
|
|
14596
|
+
{
|
|
14597
|
+
name: "vite-plugin-cloudflare:nodejs-compat-warnings-resolver",
|
|
14598
|
+
setup(build) {
|
|
14599
|
+
build.onResolve(
|
|
14600
|
+
{ filter: NODEJS_MODULES_RE },
|
|
14601
|
+
({ path: path10, importer }) => {
|
|
14602
|
+
const nodeJsCompatWarnings = nodeJsCompatWarningsMap.get(workerConfig);
|
|
14603
|
+
assert8(
|
|
14604
|
+
nodeJsCompatWarnings,
|
|
14605
|
+
`expected nodeJsCompatWarnings to be defined for Worker "${workerConfig.name}"`
|
|
14606
|
+
);
|
|
14607
|
+
nodeJsCompatWarnings.registerImport(path10, importer);
|
|
14608
|
+
return { path: path10, external: true };
|
|
14609
|
+
}
|
|
14610
|
+
);
|
|
14611
|
+
build.onEnd(() => {
|
|
14612
|
+
const nodeJsCompatWarnings = nodeJsCompatWarningsMap.get(workerConfig);
|
|
14613
|
+
if (nodeJsCompatWarnings) {
|
|
14614
|
+
nodeJsCompatWarnings.renderWarnings();
|
|
14615
|
+
}
|
|
14616
|
+
});
|
|
14617
|
+
}
|
|
14618
|
+
}
|
|
14619
|
+
]
|
|
14620
|
+
}
|
|
14621
|
+
}
|
|
14622
|
+
};
|
|
14623
|
+
}
|
|
14624
|
+
},
|
|
14625
|
+
configureServer(viteDevServer) {
|
|
14626
|
+
for (const environment of Object.values(viteDevServer.environments)) {
|
|
14627
|
+
const workerConfig = getWorkerConfig2(environment.name);
|
|
14628
|
+
if (workerConfig && !isNodeCompat(workerConfig)) {
|
|
14629
|
+
nodeJsCompatWarningsMap.set(
|
|
14630
|
+
workerConfig,
|
|
14631
|
+
new NodeJsCompatWarnings(environment)
|
|
14632
|
+
);
|
|
14633
|
+
}
|
|
14634
|
+
}
|
|
14635
|
+
},
|
|
14636
|
+
buildStart() {
|
|
14637
|
+
const workerConfig = getWorkerConfig2(this.environment.name);
|
|
14638
|
+
if (workerConfig && !isNodeCompat(workerConfig)) {
|
|
14639
|
+
nodeJsCompatWarningsMap.set(
|
|
14640
|
+
workerConfig,
|
|
14641
|
+
new NodeJsCompatWarnings(this.environment)
|
|
14642
|
+
);
|
|
14643
|
+
}
|
|
14644
|
+
},
|
|
14645
|
+
buildEnd() {
|
|
14646
|
+
const workerConfig = getWorkerConfig2(this.environment.name);
|
|
14647
|
+
if (workerConfig && !isNodeCompat(workerConfig)) {
|
|
14648
|
+
const nodeJsCompatWarnings = nodeJsCompatWarningsMap.get(workerConfig);
|
|
14649
|
+
assert8(
|
|
14650
|
+
nodeJsCompatWarnings,
|
|
14651
|
+
`expected nodeJsCompatWarnings to be defined for Worker "${workerConfig.name}"`
|
|
14652
|
+
);
|
|
14653
|
+
nodeJsCompatWarnings.renderWarnings();
|
|
14654
|
+
}
|
|
14655
|
+
},
|
|
14656
|
+
// We must ensure that the `resolveId` hook runs before the built-in ones otherwise we
|
|
14657
|
+
// never see the Node.js built-in imports since they get handled by default Vite behavior.
|
|
14658
|
+
enforce: "pre",
|
|
14659
|
+
async resolveId(source, importer) {
|
|
14660
|
+
const workerConfig = getWorkerConfig2(this.environment.name);
|
|
14661
|
+
if (workerConfig && !isNodeCompat(workerConfig)) {
|
|
14662
|
+
const nodeJsCompatWarnings = nodeJsCompatWarningsMap.get(workerConfig);
|
|
14663
|
+
if (nodejsBuiltins.has(source)) {
|
|
14664
|
+
nodeJsCompatWarnings?.registerImport(source, importer);
|
|
14665
|
+
nodeJsCompatWarnings?.renderWarningsOnIdle();
|
|
14666
|
+
return {
|
|
14667
|
+
id: source,
|
|
14668
|
+
external: true
|
|
14669
|
+
};
|
|
14670
|
+
}
|
|
14671
|
+
}
|
|
14672
|
+
}
|
|
14518
14673
|
}
|
|
14519
14674
|
];
|
|
14520
14675
|
function getWorkerConfig2(environmentName) {
|
|
@@ -14523,7 +14678,7 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14523
14678
|
}
|
|
14524
14679
|
}
|
|
14525
14680
|
function getDotDevDotVarsContent(configPath, cloudflareEnv) {
|
|
14526
|
-
const configDir =
|
|
14681
|
+
const configDir = path9.dirname(configPath);
|
|
14527
14682
|
const defaultDotDevDotVarsPath = `${configDir}/.dev.vars`;
|
|
14528
14683
|
const inputDotDevDotVarsPath = `${defaultDotDevDotVarsPath}${cloudflareEnv ? `.${cloudflareEnv}` : ""}`;
|
|
14529
14684
|
const targetPath = fs5.existsSync(inputDotDevDotVarsPath) ? inputDotDevDotVarsPath : fs5.existsSync(defaultDotDevDotVarsPath) ? defaultDotDevDotVarsPath : null;
|
|
@@ -29,7 +29,7 @@ function stripInternalEnv(internalEnv) {
|
|
|
29
29
|
return userEnv;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
// ../../node_modules/.pnpm/vite@6.1.0_@types+node@18.19.76_jiti@2.4.2/node_modules/vite/dist/node/module-runner.js
|
|
32
|
+
// ../../node_modules/.pnpm/vite@6.1.0_@types+node@18.19.76_jiti@2.4.2_lightningcss@1.29.2/node_modules/vite/dist/node/module-runner.js
|
|
33
33
|
var VALID_ID_PREFIX = "/@id/";
|
|
34
34
|
var NULL_BYTE_PLACEHOLDER = "__x00__";
|
|
35
35
|
var SOURCEMAPPING_URL = "sourceMa";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudflare/vite-plugin",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.18",
|
|
4
4
|
"description": "Cloudflare plugin for Vite",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"unenv": "2.0.0-rc.15",
|
|
40
40
|
"ws": "8.18.0",
|
|
41
41
|
"@cloudflare/unenv-preset": "2.3.1",
|
|
42
|
-
"miniflare": "4.20250321.
|
|
43
|
-
"wrangler": "4.
|
|
42
|
+
"miniflare": "4.20250321.1",
|
|
43
|
+
"wrangler": "4.5.1"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@cloudflare/workers-types": "^4.20250321.0",
|