@cloudflare/vite-plugin 1.5.0 → 1.6.0
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 -13
- package/dist/asset-workers/router-worker.js +114 -35
- package/dist/index.js +371 -233
- package/package.json +8 -8
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 = (path11, originalPath, doThrow) => {
|
|
252
|
+
if (!isString(path11)) {
|
|
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 (!path11) {
|
|
259
259
|
return doThrow(`path must not be empty`, TypeError);
|
|
260
260
|
}
|
|
261
|
-
if (checkPath.isNotRelative(
|
|
261
|
+
if (checkPath.isNotRelative(path11)) {
|
|
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 = (path11) => REGEX_TEST_INVALID_PATH.test(path11);
|
|
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(path11, 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(path11);
|
|
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 path11 = originalPath && checkPath.convert(originalPath);
|
|
351
351
|
checkPath(
|
|
352
|
-
|
|
352
|
+
path11,
|
|
353
353
|
originalPath,
|
|
354
354
|
this._allowRelativePaths ? RETURN_FALSE : throwError
|
|
355
355
|
);
|
|
356
|
-
return this._t(
|
|
356
|
+
return this._t(path11, cache2, checkUnignored, slices);
|
|
357
357
|
}
|
|
358
|
-
_t(
|
|
359
|
-
if (
|
|
360
|
-
return cache2[
|
|
358
|
+
_t(path11, cache2, checkUnignored, slices) {
|
|
359
|
+
if (path11 in cache2) {
|
|
360
|
+
return cache2[path11];
|
|
361
361
|
}
|
|
362
362
|
if (!slices) {
|
|
363
|
-
slices =
|
|
363
|
+
slices = path11.split(SLASH);
|
|
364
364
|
}
|
|
365
365
|
slices.pop();
|
|
366
366
|
if (!slices.length) {
|
|
367
|
-
return cache2[
|
|
367
|
+
return cache2[path11] = this._testOne(path11, 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[path11] = parent.ignored ? parent : this._testOne(path11, checkUnignored);
|
|
376
376
|
}
|
|
377
|
-
ignores(
|
|
378
|
-
return this._test(
|
|
377
|
+
ignores(path11) {
|
|
378
|
+
return this._test(path11, this._ignoreCache, false).ignored;
|
|
379
379
|
}
|
|
380
380
|
createFilter() {
|
|
381
|
-
return (
|
|
381
|
+
return (path11) => !this.ignores(path11);
|
|
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(path11) {
|
|
388
|
+
return this._test(path11, this._testCache, true);
|
|
389
389
|
}
|
|
390
390
|
};
|
|
391
391
|
var factory = (options) => new Ignore(options);
|
|
392
|
-
var isPathValid = (
|
|
392
|
+
var isPathValid = (path11) => checkPath(path11 && checkPath.convert(path11), path11, 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 = (path11) => REGIX_IS_WINDOWS_PATH_ABSOLUTE.test(path11) || isNotRelative(path11);
|
|
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(path11) {
|
|
447
|
+
path11 = String(path11);
|
|
448
|
+
let last = path11.replace(/^.*[/\\]/, "").toLowerCase();
|
|
449
449
|
let ext = last.replace(/^.*\./, "").toLowerCase();
|
|
450
|
-
let hasPath = last.length <
|
|
450
|
+
let hasPath = last.length < path11.length;
|
|
451
451
|
let hasDot = ext.length < last.length - 1;
|
|
452
452
|
return (hasDot || !hasPath) && this._types[ext] || null;
|
|
453
453
|
};
|
|
@@ -485,10 +485,10 @@ var require_mime = __commonJS({
|
|
|
485
485
|
});
|
|
486
486
|
|
|
487
487
|
// src/index.ts
|
|
488
|
-
import
|
|
489
|
-
import * as
|
|
488
|
+
import assert11 from "node:assert";
|
|
489
|
+
import * as fs6 from "node:fs";
|
|
490
490
|
import * as fsp2 from "node:fs/promises";
|
|
491
|
-
import * as
|
|
491
|
+
import * as path10 from "node:path";
|
|
492
492
|
import { createRequest, sendResponse } from "@mjackson/node-fetch-server";
|
|
493
493
|
import replace from "@rollup/plugin-replace";
|
|
494
494
|
|
|
@@ -503,8 +503,8 @@ for (let i = 0; i < chars.length; i++) {
|
|
|
503
503
|
intToChar[i] = c;
|
|
504
504
|
charToInt[c] = i;
|
|
505
505
|
}
|
|
506
|
-
function encodeInteger(builder, num,
|
|
507
|
-
let delta = num -
|
|
506
|
+
function encodeInteger(builder, num, relative7) {
|
|
507
|
+
let delta = num - relative7;
|
|
508
508
|
delta = delta < 0 ? -delta << 1 | 1 : delta << 1;
|
|
509
509
|
do {
|
|
510
510
|
let clamped = delta & 31;
|
|
@@ -1558,7 +1558,7 @@ var MagicString = class _MagicString {
|
|
|
1558
1558
|
|
|
1559
1559
|
// src/index.ts
|
|
1560
1560
|
import { Miniflare } from "miniflare";
|
|
1561
|
-
import
|
|
1561
|
+
import colors4 from "picocolors";
|
|
1562
1562
|
import * as vite7 from "vite";
|
|
1563
1563
|
|
|
1564
1564
|
// src/constants.ts
|
|
@@ -1728,11 +1728,11 @@ ${invalidHeaderRulesList}`
|
|
|
1728
1728
|
}
|
|
1729
1729
|
|
|
1730
1730
|
// ../workers-shared/utils/configuration/validateURL.ts
|
|
1731
|
-
var extractPathname = (
|
|
1732
|
-
if (!
|
|
1733
|
-
|
|
1731
|
+
var extractPathname = (path11 = "/", includeSearch, includeHash) => {
|
|
1732
|
+
if (!path11.startsWith("/")) {
|
|
1733
|
+
path11 = `/${path11}`;
|
|
1734
1734
|
}
|
|
1735
|
-
const url = new URL(`//${
|
|
1735
|
+
const url = new URL(`//${path11}`, "relative://");
|
|
1736
1736
|
return `${url.pathname}${includeSearch ? url.search : ""}${includeHash ? url.hash : ""}`;
|
|
1737
1737
|
};
|
|
1738
1738
|
var URL_REGEX = /^https:\/\/+(?<host>[^/]+)\/?(?<path>.*)/;
|
|
@@ -1765,8 +1765,8 @@ var validateUrl = (token, onlyRelative = false, disallowPorts = false, includeSe
|
|
|
1765
1765
|
if (!token.startsWith("/") && onlyRelative) {
|
|
1766
1766
|
token = `/${token}`;
|
|
1767
1767
|
}
|
|
1768
|
-
const
|
|
1769
|
-
if (
|
|
1768
|
+
const path11 = PATH_REGEX.exec(token);
|
|
1769
|
+
if (path11) {
|
|
1770
1770
|
try {
|
|
1771
1771
|
return [extractPathname(token, includeSearch, includeHash), void 0];
|
|
1772
1772
|
} catch {
|
|
@@ -1827,7 +1827,7 @@ function parseHeaders(input, {
|
|
|
1827
1827
|
});
|
|
1828
1828
|
}
|
|
1829
1829
|
}
|
|
1830
|
-
const [
|
|
1830
|
+
const [path11, pathError] = validateUrl(line, false, true);
|
|
1831
1831
|
if (pathError) {
|
|
1832
1832
|
invalid.push({
|
|
1833
1833
|
line,
|
|
@@ -1838,7 +1838,7 @@ function parseHeaders(input, {
|
|
|
1838
1838
|
continue;
|
|
1839
1839
|
}
|
|
1840
1840
|
rule = {
|
|
1841
|
-
path:
|
|
1841
|
+
path: path11,
|
|
1842
1842
|
line,
|
|
1843
1843
|
headers: {},
|
|
1844
1844
|
unsetHeaders: []
|
|
@@ -2413,8 +2413,8 @@ function getErrorMap() {
|
|
|
2413
2413
|
return overrideErrorMap;
|
|
2414
2414
|
}
|
|
2415
2415
|
var makeIssue = (params) => {
|
|
2416
|
-
const { data: data2, path:
|
|
2417
|
-
const fullPath = [...
|
|
2416
|
+
const { data: data2, path: path11, errorMaps, issueData } = params;
|
|
2417
|
+
const fullPath = [...path11, ...issueData.path || []];
|
|
2418
2418
|
const fullIssue = {
|
|
2419
2419
|
...issueData,
|
|
2420
2420
|
path: fullPath
|
|
@@ -2513,11 +2513,11 @@ var errorUtil;
|
|
|
2513
2513
|
errorUtil2.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
|
|
2514
2514
|
})(errorUtil || (errorUtil = {}));
|
|
2515
2515
|
var ParseInputLazyPath = class {
|
|
2516
|
-
constructor(parent, value,
|
|
2516
|
+
constructor(parent, value, path11, key) {
|
|
2517
2517
|
this._cachedPath = [];
|
|
2518
2518
|
this.parent = parent;
|
|
2519
2519
|
this.data = value;
|
|
2520
|
-
this._path =
|
|
2520
|
+
this._path = path11;
|
|
2521
2521
|
this._key = key;
|
|
2522
2522
|
}
|
|
2523
2523
|
get path() {
|
|
@@ -5788,8 +5788,13 @@ var InternalConfigSchema = z.object({
|
|
|
5788
5788
|
script_id: z.number().optional(),
|
|
5789
5789
|
debug: z.boolean().optional()
|
|
5790
5790
|
});
|
|
5791
|
+
var StaticRoutingSchema = z.object({
|
|
5792
|
+
user_worker: z.array(z.string()),
|
|
5793
|
+
asset_worker: z.array(z.string()).optional()
|
|
5794
|
+
});
|
|
5791
5795
|
var RouterConfigSchema = z.object({
|
|
5792
5796
|
invoke_user_worker_ahead_of_assets: z.boolean().optional(),
|
|
5797
|
+
static_routing: StaticRoutingSchema.optional(),
|
|
5793
5798
|
has_user_worker: z.boolean().optional(),
|
|
5794
5799
|
...InternalConfigSchema.shape
|
|
5795
5800
|
});
|
|
@@ -5830,6 +5835,7 @@ var AssetConfigSchema = z.object({
|
|
|
5830
5835
|
not_found_handling: z.enum(["single-page-application", "404-page", "none"]).optional(),
|
|
5831
5836
|
redirects: RedirectsSchema,
|
|
5832
5837
|
headers: HeadersSchema,
|
|
5838
|
+
has_static_routing: z.boolean().optional(),
|
|
5833
5839
|
...InternalConfigSchema.shape
|
|
5834
5840
|
});
|
|
5835
5841
|
|
|
@@ -5906,14 +5912,147 @@ function getHeadersConfigPath(config) {
|
|
|
5906
5912
|
return path.join(config.publicDir, HEADERS_FILENAME);
|
|
5907
5913
|
}
|
|
5908
5914
|
|
|
5915
|
+
// src/build.ts
|
|
5916
|
+
import assert from "node:assert";
|
|
5917
|
+
import * as fs from "node:fs";
|
|
5918
|
+
import * as path2 from "node:path";
|
|
5919
|
+
import colors from "picocolors";
|
|
5920
|
+
function createBuildApp(resolvedPluginConfig) {
|
|
5921
|
+
return async (builder) => {
|
|
5922
|
+
const clientEnvironment = builder.environments.client;
|
|
5923
|
+
assert(clientEnvironment, `No "client" environment`);
|
|
5924
|
+
const defaultHtmlPath = path2.resolve(builder.config.root, "index.html");
|
|
5925
|
+
const hasClientEntry = clientEnvironment.config.build.rollupOptions.input || fs.existsSync(defaultHtmlPath);
|
|
5926
|
+
if (resolvedPluginConfig.type === "assets-only") {
|
|
5927
|
+
if (hasClientEntry) {
|
|
5928
|
+
await builder.build(clientEnvironment);
|
|
5929
|
+
} else if (getHasPublicAssets(builder.config)) {
|
|
5930
|
+
await fallbackBuild(builder, clientEnvironment);
|
|
5931
|
+
}
|
|
5932
|
+
return;
|
|
5933
|
+
}
|
|
5934
|
+
const workerEnvironments = Object.keys(resolvedPluginConfig.workers).map(
|
|
5935
|
+
(environmentName) => {
|
|
5936
|
+
const environment = builder.environments[environmentName];
|
|
5937
|
+
assert(environment, `"${environmentName}" environment not found`);
|
|
5938
|
+
return environment;
|
|
5939
|
+
}
|
|
5940
|
+
);
|
|
5941
|
+
await Promise.all(
|
|
5942
|
+
workerEnvironments.map((environment) => builder.build(environment))
|
|
5943
|
+
);
|
|
5944
|
+
const { entryWorkerEnvironmentName } = resolvedPluginConfig;
|
|
5945
|
+
const entryWorkerEnvironment = builder.environments[entryWorkerEnvironmentName];
|
|
5946
|
+
assert(
|
|
5947
|
+
entryWorkerEnvironment,
|
|
5948
|
+
`No "${entryWorkerEnvironmentName}" environment`
|
|
5949
|
+
);
|
|
5950
|
+
const entryWorkerBuildDirectory = path2.resolve(
|
|
5951
|
+
builder.config.root,
|
|
5952
|
+
entryWorkerEnvironment.config.build.outDir
|
|
5953
|
+
);
|
|
5954
|
+
const entryWorkerManifest = loadViteManifest(entryWorkerBuildDirectory);
|
|
5955
|
+
const importedAssetPaths = getImportedAssetPaths(entryWorkerManifest);
|
|
5956
|
+
if (hasClientEntry) {
|
|
5957
|
+
await builder.build(clientEnvironment);
|
|
5958
|
+
} else if (importedAssetPaths.size || getHasPublicAssets(builder.config)) {
|
|
5959
|
+
await fallbackBuild(builder, clientEnvironment);
|
|
5960
|
+
} else {
|
|
5961
|
+
const entryWorkerConfigPath = path2.join(
|
|
5962
|
+
entryWorkerBuildDirectory,
|
|
5963
|
+
"wrangler.json"
|
|
5964
|
+
);
|
|
5965
|
+
const workerConfig = JSON.parse(
|
|
5966
|
+
fs.readFileSync(entryWorkerConfigPath, "utf-8")
|
|
5967
|
+
);
|
|
5968
|
+
workerConfig.assets = void 0;
|
|
5969
|
+
fs.writeFileSync(entryWorkerConfigPath, JSON.stringify(workerConfig));
|
|
5970
|
+
return;
|
|
5971
|
+
}
|
|
5972
|
+
const clientBuildDirectory = path2.resolve(
|
|
5973
|
+
builder.config.root,
|
|
5974
|
+
clientEnvironment.config.build.outDir
|
|
5975
|
+
);
|
|
5976
|
+
const movedAssetPaths = [];
|
|
5977
|
+
for (const assetPath of importedAssetPaths) {
|
|
5978
|
+
const src = path2.join(entryWorkerBuildDirectory, assetPath);
|
|
5979
|
+
const dest = path2.join(clientBuildDirectory, assetPath);
|
|
5980
|
+
if (!fs.existsSync(src)) {
|
|
5981
|
+
continue;
|
|
5982
|
+
}
|
|
5983
|
+
if (fs.existsSync(dest)) {
|
|
5984
|
+
fs.unlinkSync(src);
|
|
5985
|
+
} else {
|
|
5986
|
+
const destDir = path2.dirname(dest);
|
|
5987
|
+
fs.mkdirSync(destDir, { recursive: true });
|
|
5988
|
+
fs.renameSync(src, dest);
|
|
5989
|
+
movedAssetPaths.push(dest);
|
|
5990
|
+
}
|
|
5991
|
+
}
|
|
5992
|
+
if (movedAssetPaths.length) {
|
|
5993
|
+
builder.config.logger.info(
|
|
5994
|
+
[
|
|
5995
|
+
`${colors.green("\u2713")} ${movedAssetPaths.length} asset${movedAssetPaths.length > 1 ? "s" : ""} moved from "${entryWorkerEnvironmentName}" to "client" build output.`,
|
|
5996
|
+
...movedAssetPaths.map(
|
|
5997
|
+
(assetPath) => colors.dim(path2.relative(builder.config.root, assetPath))
|
|
5998
|
+
)
|
|
5999
|
+
].join("\n")
|
|
6000
|
+
);
|
|
6001
|
+
}
|
|
6002
|
+
};
|
|
6003
|
+
}
|
|
6004
|
+
function getHasPublicAssets({ publicDir }) {
|
|
6005
|
+
let hasPublicAssets = false;
|
|
6006
|
+
if (publicDir) {
|
|
6007
|
+
try {
|
|
6008
|
+
const files = fs.readdirSync(publicDir);
|
|
6009
|
+
if (files.length) {
|
|
6010
|
+
hasPublicAssets = true;
|
|
6011
|
+
}
|
|
6012
|
+
} catch (error) {
|
|
6013
|
+
}
|
|
6014
|
+
}
|
|
6015
|
+
return hasPublicAssets;
|
|
6016
|
+
}
|
|
6017
|
+
async function fallbackBuild(builder, environment) {
|
|
6018
|
+
const fallbackEntryName = "__cloudflare_fallback_entry__";
|
|
6019
|
+
environment.config.build.rollupOptions = {
|
|
6020
|
+
input: "virtual:__cloudflare_fallback_entry__",
|
|
6021
|
+
logLevel: "silent",
|
|
6022
|
+
output: {
|
|
6023
|
+
entryFileNames: fallbackEntryName
|
|
6024
|
+
}
|
|
6025
|
+
};
|
|
6026
|
+
await builder.build(environment);
|
|
6027
|
+
const fallbackEntryPath = path2.resolve(
|
|
6028
|
+
builder.config.root,
|
|
6029
|
+
environment.config.build.outDir,
|
|
6030
|
+
fallbackEntryName
|
|
6031
|
+
);
|
|
6032
|
+
fs.unlinkSync(fallbackEntryPath);
|
|
6033
|
+
}
|
|
6034
|
+
function loadViteManifest(directory) {
|
|
6035
|
+
const contents = fs.readFileSync(
|
|
6036
|
+
path2.resolve(directory, ".vite", "manifest.json"),
|
|
6037
|
+
"utf-8"
|
|
6038
|
+
);
|
|
6039
|
+
return JSON.parse(contents);
|
|
6040
|
+
}
|
|
6041
|
+
function getImportedAssetPaths(viteManifest) {
|
|
6042
|
+
const assetPaths = Object.values(viteManifest).flatMap(
|
|
6043
|
+
(chunk) => chunk.assets ?? []
|
|
6044
|
+
);
|
|
6045
|
+
return new Set(assetPaths);
|
|
6046
|
+
}
|
|
6047
|
+
|
|
5909
6048
|
// src/cloudflare-environment.ts
|
|
5910
|
-
import
|
|
6049
|
+
import assert4 from "node:assert";
|
|
5911
6050
|
import * as vite3 from "vite";
|
|
5912
6051
|
|
|
5913
6052
|
// src/node-js-compat.ts
|
|
5914
|
-
import
|
|
6053
|
+
import assert3 from "node:assert";
|
|
5915
6054
|
import { builtinModules as builtinModules2 } from "node:module";
|
|
5916
|
-
import
|
|
6055
|
+
import path4 from "node:path";
|
|
5917
6056
|
import { cloudflare } from "@cloudflare/unenv-preset";
|
|
5918
6057
|
import { getNodeCompat } from "miniflare";
|
|
5919
6058
|
|
|
@@ -11446,7 +11585,7 @@ Parser.acorn = {
|
|
|
11446
11585
|
|
|
11447
11586
|
// ../../node_modules/.pnpm/mlly@1.7.4/node_modules/mlly/dist/index.mjs
|
|
11448
11587
|
import { builtinModules, createRequire } from "node:module";
|
|
11449
|
-
import
|
|
11588
|
+
import fs2, { realpathSync, statSync, promises } from "node:fs";
|
|
11450
11589
|
|
|
11451
11590
|
// ../../node_modules/.pnpm/ufo@1.5.4/node_modules/ufo/dist/index.mjs
|
|
11452
11591
|
var r = String.fromCharCode;
|
|
@@ -11465,17 +11604,17 @@ function withTrailingSlash(input = "", respectQueryAndFragment) {
|
|
|
11465
11604
|
if (hasTrailingSlash(input, true)) {
|
|
11466
11605
|
return input || "/";
|
|
11467
11606
|
}
|
|
11468
|
-
let
|
|
11607
|
+
let path11 = input;
|
|
11469
11608
|
let fragment = "";
|
|
11470
11609
|
const fragmentIndex = input.indexOf("#");
|
|
11471
11610
|
if (fragmentIndex >= 0) {
|
|
11472
|
-
|
|
11611
|
+
path11 = input.slice(0, fragmentIndex);
|
|
11473
11612
|
fragment = input.slice(fragmentIndex);
|
|
11474
|
-
if (!
|
|
11613
|
+
if (!path11) {
|
|
11475
11614
|
return fragment;
|
|
11476
11615
|
}
|
|
11477
11616
|
}
|
|
11478
|
-
const [s0, ...s] =
|
|
11617
|
+
const [s0, ...s] = path11.split("?");
|
|
11479
11618
|
return s0 + "/" + (s.length > 0 ? `?${s.join("?")}` : "") + fragment;
|
|
11480
11619
|
}
|
|
11481
11620
|
function isNonEmptyURL(url) {
|
|
@@ -11503,14 +11642,14 @@ var isAbsolute = function(p) {
|
|
|
11503
11642
|
|
|
11504
11643
|
// ../../node_modules/.pnpm/mlly@1.7.4/node_modules/mlly/dist/index.mjs
|
|
11505
11644
|
import { fileURLToPath as fileURLToPath$1, URL as URL$1, pathToFileURL as pathToFileURL$1 } from "node:url";
|
|
11506
|
-
import
|
|
11645
|
+
import assert2 from "node:assert";
|
|
11507
11646
|
import process$1 from "node:process";
|
|
11508
|
-
import
|
|
11647
|
+
import path3, { dirname as dirname3 } from "node:path";
|
|
11509
11648
|
import v8 from "node:v8";
|
|
11510
11649
|
import { format as format2, inspect } from "node:util";
|
|
11511
11650
|
var BUILTIN_MODULES = new Set(builtinModules);
|
|
11512
|
-
function normalizeSlash(
|
|
11513
|
-
return
|
|
11651
|
+
function normalizeSlash(path11) {
|
|
11652
|
+
return path11.replace(/\\/g, "/");
|
|
11514
11653
|
}
|
|
11515
11654
|
var own$1 = {}.hasOwnProperty;
|
|
11516
11655
|
var classRegExp = /^([A-Z][a-z\d]*)+$/;
|
|
@@ -11541,7 +11680,7 @@ codes.ERR_INVALID_ARG_TYPE = createError(
|
|
|
11541
11680
|
* @param {unknown} actual
|
|
11542
11681
|
*/
|
|
11543
11682
|
(name, expected, actual) => {
|
|
11544
|
-
|
|
11683
|
+
assert2(typeof name === "string", "'name' must be a string");
|
|
11545
11684
|
if (!Array.isArray(expected)) {
|
|
11546
11685
|
expected = [expected];
|
|
11547
11686
|
}
|
|
@@ -11557,14 +11696,14 @@ codes.ERR_INVALID_ARG_TYPE = createError(
|
|
|
11557
11696
|
const instances = [];
|
|
11558
11697
|
const other = [];
|
|
11559
11698
|
for (const value of expected) {
|
|
11560
|
-
|
|
11699
|
+
assert2(
|
|
11561
11700
|
typeof value === "string",
|
|
11562
11701
|
"All expected entries have to be of type string"
|
|
11563
11702
|
);
|
|
11564
11703
|
if (kTypes.has(value)) {
|
|
11565
11704
|
types2.push(value.toLowerCase());
|
|
11566
11705
|
} else if (classRegExp.exec(value) === null) {
|
|
11567
|
-
|
|
11706
|
+
assert2(
|
|
11568
11707
|
value !== "object",
|
|
11569
11708
|
'The value "object" should be written as "Object"'
|
|
11570
11709
|
);
|
|
@@ -11623,8 +11762,8 @@ codes.ERR_INVALID_PACKAGE_CONFIG = createError(
|
|
|
11623
11762
|
* @param {string} [base]
|
|
11624
11763
|
* @param {string} [message]
|
|
11625
11764
|
*/
|
|
11626
|
-
(
|
|
11627
|
-
return `Invalid package config ${
|
|
11765
|
+
(path11, base, message) => {
|
|
11766
|
+
return `Invalid package config ${path11}${base ? ` while importing ${base}` : ""}${message ? `. ${message}` : ""}`;
|
|
11628
11767
|
},
|
|
11629
11768
|
Error
|
|
11630
11769
|
);
|
|
@@ -11640,7 +11779,7 @@ codes.ERR_INVALID_PACKAGE_TARGET = createError(
|
|
|
11640
11779
|
(packagePath, key, target2, isImport = false, base = void 0) => {
|
|
11641
11780
|
const relatedError = typeof target2 === "string" && !isImport && target2.length > 0 && !target2.startsWith("./");
|
|
11642
11781
|
if (key === ".") {
|
|
11643
|
-
|
|
11782
|
+
assert2(isImport === false);
|
|
11644
11783
|
return `Invalid "exports" main target ${JSON.stringify(target2)} defined in the package config ${packagePath}package.json${base ? ` imported from ${base}` : ""}${relatedError ? '; targets must start with "./"' : ""}`;
|
|
11645
11784
|
}
|
|
11646
11785
|
return `Invalid "${isImport ? "imports" : "exports"}" target ${JSON.stringify(
|
|
@@ -11656,8 +11795,8 @@ codes.ERR_MODULE_NOT_FOUND = createError(
|
|
|
11656
11795
|
* @param {string} base
|
|
11657
11796
|
* @param {boolean} [exactUrl]
|
|
11658
11797
|
*/
|
|
11659
|
-
(
|
|
11660
|
-
return `Cannot find ${exactUrl ? "module" : "package"} '${
|
|
11798
|
+
(path11, base, exactUrl = false) => {
|
|
11799
|
+
return `Cannot find ${exactUrl ? "module" : "package"} '${path11}' imported from ${base}`;
|
|
11661
11800
|
},
|
|
11662
11801
|
Error
|
|
11663
11802
|
);
|
|
@@ -11708,8 +11847,8 @@ codes.ERR_UNKNOWN_FILE_EXTENSION = createError(
|
|
|
11708
11847
|
* @param {string} extension
|
|
11709
11848
|
* @param {string} path
|
|
11710
11849
|
*/
|
|
11711
|
-
(extension,
|
|
11712
|
-
return `Unknown file extension "${extension}" for ${
|
|
11850
|
+
(extension, path11) => {
|
|
11851
|
+
return `Unknown file extension "${extension}" for ${path11}`;
|
|
11713
11852
|
},
|
|
11714
11853
|
TypeError
|
|
11715
11854
|
);
|
|
@@ -11805,9 +11944,9 @@ var captureLargerStackTrace = hideStackFrames(
|
|
|
11805
11944
|
);
|
|
11806
11945
|
function getMessage(key, parameters, self) {
|
|
11807
11946
|
const message = messages.get(key);
|
|
11808
|
-
|
|
11947
|
+
assert2(message !== void 0, "expected `message` to be found");
|
|
11809
11948
|
if (typeof message === "function") {
|
|
11810
|
-
|
|
11949
|
+
assert2(
|
|
11811
11950
|
message.length <= parameters.length,
|
|
11812
11951
|
// Default options do not count.
|
|
11813
11952
|
`Code: ${key}; The provided arguments length (${parameters.length}) does not match the required ones (${message.length}).`
|
|
@@ -11817,7 +11956,7 @@ function getMessage(key, parameters, self) {
|
|
|
11817
11956
|
const regex = /%[dfijoOs]/g;
|
|
11818
11957
|
let expectedLength = 0;
|
|
11819
11958
|
while (regex.exec(message) !== null) expectedLength++;
|
|
11820
|
-
|
|
11959
|
+
assert2(
|
|
11821
11960
|
expectedLength === parameters.length,
|
|
11822
11961
|
`Code: ${key}; The provided arguments length (${parameters.length}) does not match the required ones (${expectedLength}).`
|
|
11823
11962
|
);
|
|
@@ -11854,7 +11993,7 @@ function read(jsonPath, { base, specifier }) {
|
|
|
11854
11993
|
}
|
|
11855
11994
|
let string;
|
|
11856
11995
|
try {
|
|
11857
|
-
string =
|
|
11996
|
+
string = fs2.readFileSync(path3.toNamespacedPath(jsonPath), "utf8");
|
|
11858
11997
|
} catch (error) {
|
|
11859
11998
|
const exception = (
|
|
11860
11999
|
/** @type {ErrnoException} */
|
|
@@ -12070,7 +12209,7 @@ Default "index" lookups for the main are deprecated for ES modules.`,
|
|
|
12070
12209
|
"DeprecationWarning",
|
|
12071
12210
|
"DEP0151"
|
|
12072
12211
|
);
|
|
12073
|
-
} else if (
|
|
12212
|
+
} else if (path3.resolve(packagePath, main) !== urlPath) {
|
|
12074
12213
|
process$1.emitWarning(
|
|
12075
12214
|
`Package ${packagePath} has a "main" field set to "${main}", excluding the full filename and extension to the resolved file at "${urlPath.slice(
|
|
12076
12215
|
packagePath.length
|
|
@@ -12081,9 +12220,9 @@ Default "index" lookups for the main are deprecated for ES modules.`,
|
|
|
12081
12220
|
);
|
|
12082
12221
|
}
|
|
12083
12222
|
}
|
|
12084
|
-
function tryStatSync(
|
|
12223
|
+
function tryStatSync(path11) {
|
|
12085
12224
|
try {
|
|
12086
|
-
return statSync(
|
|
12225
|
+
return statSync(path11);
|
|
12087
12226
|
} catch {
|
|
12088
12227
|
}
|
|
12089
12228
|
}
|
|
@@ -12177,7 +12316,7 @@ function finalizeResolution(resolved, base, preserveSymlinks) {
|
|
|
12177
12316
|
{
|
|
12178
12317
|
const real = realpathSync(filePath);
|
|
12179
12318
|
const { search, hash } = resolved;
|
|
12180
|
-
resolved = pathToFileURL$1(real + (filePath.endsWith(
|
|
12319
|
+
resolved = pathToFileURL$1(real + (filePath.endsWith(path3.sep) ? "/" : ""));
|
|
12181
12320
|
resolved.search = search;
|
|
12182
12321
|
resolved.hash = hash;
|
|
12183
12322
|
}
|
|
@@ -12717,7 +12856,7 @@ function moduleResolve(specifier, base, conditions, preserveSymlinks) {
|
|
|
12717
12856
|
resolved = packageResolve(specifier, base, conditions);
|
|
12718
12857
|
}
|
|
12719
12858
|
}
|
|
12720
|
-
|
|
12859
|
+
assert2(resolved !== void 0, "expected to be defined");
|
|
12721
12860
|
if (resolved.protocol !== "file:") {
|
|
12722
12861
|
return resolved;
|
|
12723
12862
|
}
|
|
@@ -12888,8 +13027,8 @@ function isNodeAls(workerConfig) {
|
|
|
12888
13027
|
workerConfig.compatibility_flags ?? []
|
|
12889
13028
|
).mode === "als";
|
|
12890
13029
|
}
|
|
12891
|
-
function isNodeAlsModule(
|
|
12892
|
-
return /^(node:)?async_hooks$/.test(
|
|
13030
|
+
function isNodeAlsModule(path11) {
|
|
13031
|
+
return /^(node:)?async_hooks$/.test(path11);
|
|
12893
13032
|
}
|
|
12894
13033
|
function injectGlobalCode(id, code) {
|
|
12895
13034
|
const injectedCode = Object.entries(env.inject).map(([globalName, globalInject]) => {
|
|
@@ -12900,11 +13039,11 @@ globalThis.${globalName} = var_${globalName};
|
|
|
12900
13039
|
`;
|
|
12901
13040
|
}
|
|
12902
13041
|
const [moduleSpecifier, exportName] = globalInject;
|
|
12903
|
-
|
|
13042
|
+
assert3(
|
|
12904
13043
|
moduleSpecifier !== void 0,
|
|
12905
13044
|
"Expected moduleSpecifier to be defined"
|
|
12906
13045
|
);
|
|
12907
|
-
|
|
13046
|
+
assert3(exportName !== void 0, "Expected exportName to be defined");
|
|
12908
13047
|
return `import var_${globalName} from "${moduleSpecifier}";
|
|
12909
13048
|
globalThis.${globalName} = var_${globalName}.${exportName};
|
|
12910
13049
|
`;
|
|
@@ -12940,7 +13079,7 @@ function getNodeCompatEntries() {
|
|
|
12940
13079
|
if (typeof globalInject === "string") {
|
|
12941
13080
|
entries.add(globalInject);
|
|
12942
13081
|
} else {
|
|
12943
|
-
|
|
13082
|
+
assert3(
|
|
12944
13083
|
globalInject[0] !== void 0,
|
|
12945
13084
|
"Expected first element of globalInject to be defined"
|
|
12946
13085
|
);
|
|
@@ -12979,7 +13118,7 @@ var NodeJsCompatWarnings = class {
|
|
|
12979
13118
|
`;
|
|
12980
13119
|
this.sources.forEach((importers, source) => {
|
|
12981
13120
|
importers.forEach((importer) => {
|
|
12982
|
-
message += ` - "${source}" imported from "${
|
|
13121
|
+
message += ` - "${source}" imported from "${path4.relative(this.resolvedViteConfig.root, importer)}"
|
|
12983
13122
|
`;
|
|
12984
13123
|
});
|
|
12985
13124
|
});
|
|
@@ -13003,13 +13142,13 @@ var additionalModuleGlobalRE = new RegExp(
|
|
|
13003
13142
|
var VITE_DEV_METADATA_HEADER = "__VITE_DEV_METADATA__";
|
|
13004
13143
|
|
|
13005
13144
|
// src/utils.ts
|
|
13006
|
-
import * as
|
|
13145
|
+
import * as path5 from "node:path";
|
|
13007
13146
|
import getPort, { portNumbers } from "get-port";
|
|
13008
13147
|
import { Request as MiniflareRequest } from "miniflare";
|
|
13009
13148
|
import "vite";
|
|
13010
13149
|
function getOutputDirectory(userConfig, environmentName) {
|
|
13011
13150
|
const rootOutputDirectory = userConfig.build?.outDir ?? "dist";
|
|
13012
|
-
return userConfig.environments?.[environmentName]?.build?.outDir ??
|
|
13151
|
+
return userConfig.environments?.[environmentName]?.build?.outDir ?? path5.join(rootOutputDirectory, environmentName);
|
|
13013
13152
|
}
|
|
13014
13153
|
function toMiniflareRequest(request) {
|
|
13015
13154
|
const host = request.headers.get("Host");
|
|
@@ -13042,7 +13181,7 @@ function createHotChannel(webSocketContainer) {
|
|
|
13042
13181
|
const client = {
|
|
13043
13182
|
send(payload) {
|
|
13044
13183
|
const webSocket = webSocketContainer.webSocket;
|
|
13045
|
-
|
|
13184
|
+
assert4(webSocket, webSocketUndefinedError);
|
|
13046
13185
|
webSocket.send(JSON.stringify(payload));
|
|
13047
13186
|
}
|
|
13048
13187
|
};
|
|
@@ -13056,7 +13195,7 @@ function createHotChannel(webSocketContainer) {
|
|
|
13056
13195
|
return {
|
|
13057
13196
|
send(payload) {
|
|
13058
13197
|
const webSocket = webSocketContainer.webSocket;
|
|
13059
|
-
|
|
13198
|
+
assert4(webSocket, webSocketUndefinedError);
|
|
13060
13199
|
webSocket.send(JSON.stringify(payload));
|
|
13061
13200
|
},
|
|
13062
13201
|
on(event, listener) {
|
|
@@ -13069,12 +13208,12 @@ function createHotChannel(webSocketContainer) {
|
|
|
13069
13208
|
},
|
|
13070
13209
|
listen() {
|
|
13071
13210
|
const webSocket = webSocketContainer.webSocket;
|
|
13072
|
-
|
|
13211
|
+
assert4(webSocket, webSocketUndefinedError);
|
|
13073
13212
|
webSocket.addEventListener("message", onMessage);
|
|
13074
13213
|
},
|
|
13075
13214
|
close() {
|
|
13076
13215
|
const webSocket = webSocketContainer.webSocket;
|
|
13077
|
-
|
|
13216
|
+
assert4(webSocket, webSocketUndefinedError);
|
|
13078
13217
|
webSocket.removeEventListener("message", onMessage);
|
|
13079
13218
|
}
|
|
13080
13219
|
};
|
|
@@ -13104,12 +13243,12 @@ var CloudflareDevEnvironment = class extends vite3.DevEnvironment {
|
|
|
13104
13243
|
}
|
|
13105
13244
|
}
|
|
13106
13245
|
);
|
|
13107
|
-
|
|
13246
|
+
assert4(
|
|
13108
13247
|
response.ok,
|
|
13109
13248
|
`Failed to initialize module runner, error: ${await response.text()}`
|
|
13110
13249
|
);
|
|
13111
13250
|
const webSocket = response.webSocket;
|
|
13112
|
-
|
|
13251
|
+
assert4(webSocket, "Failed to establish WebSocket");
|
|
13113
13252
|
webSocket.accept();
|
|
13114
13253
|
this.#webSocketContainer.webSocket = webSocket;
|
|
13115
13254
|
}
|
|
@@ -13122,7 +13261,7 @@ var cloudflareBuiltInModules = [
|
|
|
13122
13261
|
];
|
|
13123
13262
|
var defaultConditions = ["workerd", "module", "browser"];
|
|
13124
13263
|
var target = "es2022";
|
|
13125
|
-
function createCloudflareEnvironmentOptions(workerConfig, userConfig,
|
|
13264
|
+
function createCloudflareEnvironmentOptions(workerConfig, userConfig, environment) {
|
|
13126
13265
|
return {
|
|
13127
13266
|
resolve: {
|
|
13128
13267
|
// Note: in order for ssr pre-bundling to take effect we need to ask vite to treat all
|
|
@@ -13143,16 +13282,12 @@ function createCloudflareEnvironmentOptions(workerConfig, userConfig, environmen
|
|
|
13143
13282
|
return new vite3.BuildEnvironment(name, config);
|
|
13144
13283
|
},
|
|
13145
13284
|
target,
|
|
13146
|
-
// We need to enable `emitAssets` in order to support additional modules defined by `rules`
|
|
13147
13285
|
emitAssets: true,
|
|
13148
|
-
|
|
13286
|
+
manifest: environment.isEntry,
|
|
13287
|
+
outDir: getOutputDirectory(userConfig, environment.name),
|
|
13149
13288
|
copyPublicDir: false,
|
|
13150
13289
|
ssr: true,
|
|
13151
13290
|
rollupOptions: {
|
|
13152
|
-
// Note: vite starts dev pre-bundling crawling from either optimizeDeps.entries or rollupOptions.input
|
|
13153
|
-
// so the input value here serves both as the build input as well as the starting point for
|
|
13154
|
-
// dev pre-bundling crawling (were we not to set this input field we'd have to appropriately set
|
|
13155
|
-
// optimizeDeps.entries in the dev config)
|
|
13156
13291
|
input: workerConfig.main
|
|
13157
13292
|
}
|
|
13158
13293
|
},
|
|
@@ -13198,8 +13333,8 @@ function initRunners(resolvedPluginConfig, viteDevServer, miniflare2) {
|
|
|
13198
13333
|
}
|
|
13199
13334
|
|
|
13200
13335
|
// src/debugging.ts
|
|
13201
|
-
import
|
|
13202
|
-
import
|
|
13336
|
+
import assert5 from "node:assert";
|
|
13337
|
+
import colors2 from "picocolors";
|
|
13203
13338
|
var debuggingPath = "/__debug";
|
|
13204
13339
|
function addDebugToVitePrintUrls(server) {
|
|
13205
13340
|
const originalPrintUrls = server.printUrls;
|
|
@@ -13208,19 +13343,19 @@ function addDebugToVitePrintUrls(server) {
|
|
|
13208
13343
|
const localUrl = server.resolvedUrls?.local[0];
|
|
13209
13344
|
if (localUrl) {
|
|
13210
13345
|
const { protocol, hostname, port } = new URL(localUrl);
|
|
13211
|
-
const colorDebugUrl = (url) =>
|
|
13212
|
-
|
|
13213
|
-
url.replace(/:(\d+)\//, (_, port2) => `:${
|
|
13346
|
+
const colorDebugUrl = (url) => colors2.dim(
|
|
13347
|
+
colors2.yellow(
|
|
13348
|
+
url.replace(/:(\d+)\//, (_, port2) => `:${colors2.bold(port2)}/`)
|
|
13214
13349
|
)
|
|
13215
13350
|
);
|
|
13216
13351
|
server.config.logger.info(
|
|
13217
|
-
` ${
|
|
13352
|
+
` ${colors2.green("\u279C")} ${colors2.bold("Debug")}: ${colorDebugUrl(`${protocol}//${hostname}:${port}${debuggingPath}`)}`
|
|
13218
13353
|
);
|
|
13219
13354
|
}
|
|
13220
13355
|
};
|
|
13221
13356
|
}
|
|
13222
13357
|
function getDebugPathHtml(workerNames, inspectorPort) {
|
|
13223
|
-
|
|
13358
|
+
assert5(workerNames.length >= 1, "no workers present to debug");
|
|
13224
13359
|
const workerDevtoolsUrls = workerNames.map((workerName) => {
|
|
13225
13360
|
const localHost = `localhost:${inspectorPort}/${workerName}`;
|
|
13226
13361
|
const searchParams = new URLSearchParams({
|
|
@@ -13247,25 +13382,25 @@ function getDebugPathHtml(workerNames, inspectorPort) {
|
|
|
13247
13382
|
}
|
|
13248
13383
|
|
|
13249
13384
|
// src/deploy-config.ts
|
|
13250
|
-
import
|
|
13251
|
-
import * as
|
|
13252
|
-
import * as
|
|
13385
|
+
import assert6 from "node:assert";
|
|
13386
|
+
import * as fs3 from "node:fs";
|
|
13387
|
+
import * as path6 from "node:path";
|
|
13253
13388
|
import "vite";
|
|
13254
13389
|
import { unstable_readConfig } from "wrangler";
|
|
13255
13390
|
function getDeployConfigPath(root) {
|
|
13256
|
-
return
|
|
13391
|
+
return path6.resolve(root, ".wrangler", "deploy", "config.json");
|
|
13257
13392
|
}
|
|
13258
13393
|
function getWorkerConfigs(root, mixedModeEnabled) {
|
|
13259
13394
|
const deployConfigPath = getDeployConfigPath(root);
|
|
13260
13395
|
const deployConfig = JSON.parse(
|
|
13261
|
-
|
|
13396
|
+
fs3.readFileSync(deployConfigPath, "utf-8")
|
|
13262
13397
|
);
|
|
13263
13398
|
return [
|
|
13264
13399
|
{ configPath: deployConfig.configPath },
|
|
13265
13400
|
...deployConfig.auxiliaryWorkers
|
|
13266
13401
|
].map(({ configPath }) => {
|
|
13267
|
-
const resolvedConfigPath =
|
|
13268
|
-
|
|
13402
|
+
const resolvedConfigPath = path6.resolve(
|
|
13403
|
+
path6.dirname(deployConfigPath),
|
|
13269
13404
|
configPath
|
|
13270
13405
|
);
|
|
13271
13406
|
return unstable_readConfig(
|
|
@@ -13275,18 +13410,18 @@ function getWorkerConfigs(root, mixedModeEnabled) {
|
|
|
13275
13410
|
});
|
|
13276
13411
|
}
|
|
13277
13412
|
function getRelativePathToWorkerConfig(deployConfigDirectory, root, outputDirectory) {
|
|
13278
|
-
return
|
|
13413
|
+
return path6.relative(
|
|
13279
13414
|
deployConfigDirectory,
|
|
13280
|
-
|
|
13415
|
+
path6.resolve(root, outputDirectory, "wrangler.json")
|
|
13281
13416
|
);
|
|
13282
13417
|
}
|
|
13283
13418
|
function writeDeployConfig(resolvedPluginConfig, resolvedViteConfig) {
|
|
13284
13419
|
const deployConfigPath = getDeployConfigPath(resolvedViteConfig.root);
|
|
13285
|
-
const deployConfigDirectory =
|
|
13286
|
-
|
|
13420
|
+
const deployConfigDirectory = path6.dirname(deployConfigPath);
|
|
13421
|
+
fs3.mkdirSync(deployConfigDirectory, { recursive: true });
|
|
13287
13422
|
if (resolvedPluginConfig.type === "assets-only") {
|
|
13288
13423
|
const clientOutputDirectory = resolvedViteConfig.environments.client?.build.outDir;
|
|
13289
|
-
|
|
13424
|
+
assert6(
|
|
13290
13425
|
clientOutputDirectory,
|
|
13291
13426
|
"Unexpected error: client environment output directory is undefined"
|
|
13292
13427
|
);
|
|
@@ -13298,13 +13433,13 @@ function writeDeployConfig(resolvedPluginConfig, resolvedViteConfig) {
|
|
|
13298
13433
|
),
|
|
13299
13434
|
auxiliaryWorkers: []
|
|
13300
13435
|
};
|
|
13301
|
-
|
|
13436
|
+
fs3.writeFileSync(deployConfigPath, JSON.stringify(deployConfig));
|
|
13302
13437
|
} else {
|
|
13303
13438
|
let entryWorkerConfigPath;
|
|
13304
13439
|
const auxiliaryWorkers = [];
|
|
13305
13440
|
for (const environmentName of Object.keys(resolvedPluginConfig.workers)) {
|
|
13306
13441
|
const outputDirectory = resolvedViteConfig.environments[environmentName]?.build.outDir;
|
|
13307
|
-
|
|
13442
|
+
assert6(
|
|
13308
13443
|
outputDirectory,
|
|
13309
13444
|
`Unexpected error: ${environmentName} environment output directory is undefined`
|
|
13310
13445
|
);
|
|
@@ -13319,7 +13454,7 @@ function writeDeployConfig(resolvedPluginConfig, resolvedViteConfig) {
|
|
|
13319
13454
|
auxiliaryWorkers.push({ configPath });
|
|
13320
13455
|
}
|
|
13321
13456
|
}
|
|
13322
|
-
|
|
13457
|
+
assert6(
|
|
13323
13458
|
entryWorkerConfigPath,
|
|
13324
13459
|
`Unexpected error: entryWorkerConfigPath is undefined`
|
|
13325
13460
|
);
|
|
@@ -13327,15 +13462,15 @@ function writeDeployConfig(resolvedPluginConfig, resolvedViteConfig) {
|
|
|
13327
13462
|
configPath: entryWorkerConfigPath,
|
|
13328
13463
|
auxiliaryWorkers
|
|
13329
13464
|
};
|
|
13330
|
-
|
|
13465
|
+
fs3.writeFileSync(deployConfigPath, JSON.stringify(deployConfig));
|
|
13331
13466
|
}
|
|
13332
13467
|
}
|
|
13333
13468
|
|
|
13334
13469
|
// src/miniflare-options.ts
|
|
13335
|
-
import
|
|
13336
|
-
import * as
|
|
13470
|
+
import assert7 from "node:assert";
|
|
13471
|
+
import * as fs4 from "node:fs";
|
|
13337
13472
|
import * as fsp from "node:fs/promises";
|
|
13338
|
-
import * as
|
|
13473
|
+
import * as path7 from "node:path";
|
|
13339
13474
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
13340
13475
|
import {
|
|
13341
13476
|
getDefaultDevRegistryPath,
|
|
@@ -13344,7 +13479,7 @@ import {
|
|
|
13344
13479
|
LogLevel,
|
|
13345
13480
|
Response as MiniflareResponse
|
|
13346
13481
|
} from "miniflare";
|
|
13347
|
-
import
|
|
13482
|
+
import colors3 from "picocolors";
|
|
13348
13483
|
import { globSync } from "tinyglobby";
|
|
13349
13484
|
import "vite";
|
|
13350
13485
|
import {
|
|
@@ -13358,7 +13493,7 @@ function getPersistenceRoot(root, persistState) {
|
|
|
13358
13493
|
return;
|
|
13359
13494
|
}
|
|
13360
13495
|
const defaultPersistPath = ".wrangler/state";
|
|
13361
|
-
const persistPath =
|
|
13496
|
+
const persistPath = path7.resolve(
|
|
13362
13497
|
root,
|
|
13363
13498
|
typeof persistState === "object" ? persistState.path : defaultPersistPath,
|
|
13364
13499
|
"v3"
|
|
@@ -13377,7 +13512,7 @@ function getWorkerToWorkerEntrypointNamesMap(workers) {
|
|
|
13377
13512
|
if (typeof value === "object" && "name" in value && value.entrypoint !== void 0 && value.entrypoint !== "default") {
|
|
13378
13513
|
const targetWorkerName = value.name === kCurrentWorker ? worker.name : value.name;
|
|
13379
13514
|
const entrypointNames = workerToWorkerEntrypointNamesMap.get(targetWorkerName);
|
|
13380
|
-
|
|
13515
|
+
assert7(entrypointNames, missingWorkerErrorMessage(targetWorkerName));
|
|
13381
13516
|
entrypointNames.add(value.entrypoint);
|
|
13382
13517
|
}
|
|
13383
13518
|
}
|
|
@@ -13392,20 +13527,20 @@ function getWorkerToDurableObjectClassNamesMap(workers) {
|
|
|
13392
13527
|
for (const value of Object.values(worker.durableObjects ?? {})) {
|
|
13393
13528
|
if (typeof value === "string") {
|
|
13394
13529
|
const classNames = workerToDurableObjectClassNamesMap.get(worker.name);
|
|
13395
|
-
|
|
13530
|
+
assert7(classNames, missingWorkerErrorMessage(worker.name));
|
|
13396
13531
|
classNames.add(value);
|
|
13397
13532
|
} else if (typeof value === "object") {
|
|
13398
13533
|
if (value.scriptName) {
|
|
13399
13534
|
const classNames = workerToDurableObjectClassNamesMap.get(
|
|
13400
13535
|
value.scriptName
|
|
13401
13536
|
);
|
|
13402
|
-
|
|
13537
|
+
assert7(classNames, missingWorkerErrorMessage(value.scriptName));
|
|
13403
13538
|
classNames.add(value.className);
|
|
13404
13539
|
} else {
|
|
13405
13540
|
const classNames = workerToDurableObjectClassNamesMap.get(
|
|
13406
13541
|
worker.name
|
|
13407
13542
|
);
|
|
13408
|
-
|
|
13543
|
+
assert7(classNames, missingWorkerErrorMessage(worker.name));
|
|
13409
13544
|
classNames.add(value.className);
|
|
13410
13545
|
}
|
|
13411
13546
|
}
|
|
@@ -13423,13 +13558,13 @@ function getWorkerToWorkflowEntrypointClassNamesMap(workers) {
|
|
|
13423
13558
|
const classNames = workerToWorkflowEntrypointClassNamesMap.get(
|
|
13424
13559
|
value.scriptName
|
|
13425
13560
|
);
|
|
13426
|
-
|
|
13561
|
+
assert7(classNames, missingWorkerErrorMessage(value.scriptName));
|
|
13427
13562
|
classNames.add(value.className);
|
|
13428
13563
|
} else {
|
|
13429
13564
|
const classNames = workerToWorkflowEntrypointClassNamesMap.get(
|
|
13430
13565
|
worker.name
|
|
13431
13566
|
);
|
|
13432
|
-
|
|
13567
|
+
assert7(classNames, missingWorkerErrorMessage(worker.name));
|
|
13433
13568
|
classNames.add(value.className);
|
|
13434
13569
|
}
|
|
13435
13570
|
}
|
|
@@ -13460,8 +13595,8 @@ function logUnknownTails(tails, userWorkers, log) {
|
|
|
13460
13595
|
const found = userWorkers.some((w) => w.name === name);
|
|
13461
13596
|
if (!found) {
|
|
13462
13597
|
log(
|
|
13463
|
-
|
|
13464
|
-
|
|
13598
|
+
colors3.dim(
|
|
13599
|
+
colors3.yellow(
|
|
13465
13600
|
`Tail consumer "${name}" was not found in your config. Make sure you add it to the config or run it in another dev session if you'd like to simulate receiving tail events locally.`
|
|
13466
13601
|
)
|
|
13467
13602
|
)
|
|
@@ -13485,8 +13620,8 @@ async function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspe
|
|
|
13485
13620
|
modules: [
|
|
13486
13621
|
{
|
|
13487
13622
|
type: "ESModule",
|
|
13488
|
-
path:
|
|
13489
|
-
contents:
|
|
13623
|
+
path: path7.join(miniflareModulesRoot, ROUTER_WORKER_PATH),
|
|
13624
|
+
contents: fs4.readFileSync(
|
|
13490
13625
|
fileURLToPath2(new URL(ROUTER_WORKER_PATH, import.meta.url))
|
|
13491
13626
|
)
|
|
13492
13627
|
}
|
|
@@ -13508,8 +13643,8 @@ async function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspe
|
|
|
13508
13643
|
modules: [
|
|
13509
13644
|
{
|
|
13510
13645
|
type: "ESModule",
|
|
13511
|
-
path:
|
|
13512
|
-
contents:
|
|
13646
|
+
path: path7.join(miniflareModulesRoot, ASSET_WORKER_PATH),
|
|
13647
|
+
contents: fs4.readFileSync(
|
|
13513
13648
|
fileURLToPath2(new URL(ASSET_WORKER_PATH, import.meta.url))
|
|
13514
13649
|
)
|
|
13515
13650
|
}
|
|
@@ -13523,7 +13658,7 @@ async function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspe
|
|
|
13523
13658
|
let exists = false;
|
|
13524
13659
|
if (pathname.endsWith(".html")) {
|
|
13525
13660
|
try {
|
|
13526
|
-
const filePath =
|
|
13661
|
+
const filePath = path7.join(resolvedViteConfig.root, pathname);
|
|
13527
13662
|
const stats = await fsp.stat(filePath);
|
|
13528
13663
|
exists = stats.isFile();
|
|
13529
13664
|
} catch (error) {
|
|
@@ -13533,7 +13668,7 @@ async function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspe
|
|
|
13533
13668
|
},
|
|
13534
13669
|
__VITE_FETCH_ASSET__: async (request) => {
|
|
13535
13670
|
const { pathname } = new URL(request.url);
|
|
13536
|
-
const filePath =
|
|
13671
|
+
const filePath = path7.join(resolvedViteConfig.root, pathname);
|
|
13537
13672
|
try {
|
|
13538
13673
|
let html = await fsp.readFile(filePath, "utf-8");
|
|
13539
13674
|
html = await viteDevServer.transformIndexHtml(pathname, html);
|
|
@@ -13589,7 +13724,7 @@ async function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspe
|
|
|
13589
13724
|
__VITE_INVOKE_MODULE__: async (request) => {
|
|
13590
13725
|
const payload = await request.json();
|
|
13591
13726
|
const invokePayloadData = payload.data;
|
|
13592
|
-
|
|
13727
|
+
assert7(
|
|
13593
13728
|
invokePayloadData.name === "fetchModule",
|
|
13594
13729
|
`Invalid invoke event: ${invokePayloadData.name}`
|
|
13595
13730
|
);
|
|
@@ -13647,7 +13782,7 @@ async function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspe
|
|
|
13647
13782
|
const workerEntrypointNames = workerToWorkerEntrypointNamesMap.get(
|
|
13648
13783
|
workerOptions.name
|
|
13649
13784
|
);
|
|
13650
|
-
|
|
13785
|
+
assert7(
|
|
13651
13786
|
workerEntrypointNames,
|
|
13652
13787
|
`WorkerEntrypoint names not found for worker ${workerOptions.name}`
|
|
13653
13788
|
);
|
|
@@ -13659,7 +13794,7 @@ async function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspe
|
|
|
13659
13794
|
const durableObjectClassNames = workerToDurableObjectClassNamesMap.get(
|
|
13660
13795
|
workerOptions.name
|
|
13661
13796
|
);
|
|
13662
|
-
|
|
13797
|
+
assert7(
|
|
13663
13798
|
durableObjectClassNames,
|
|
13664
13799
|
`DurableObject class names not found for worker ${workerOptions.name}`
|
|
13665
13800
|
);
|
|
@@ -13669,7 +13804,7 @@ async function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspe
|
|
|
13669
13804
|
);
|
|
13670
13805
|
}
|
|
13671
13806
|
const workflowEntrypointClassNames = workerToWorkflowEntrypointClassNamesMap.get(workerOptions.name);
|
|
13672
|
-
|
|
13807
|
+
assert7(
|
|
13673
13808
|
workflowEntrypointClassNames,
|
|
13674
13809
|
`WorkflowEntrypoint class names not found for worker: ${workerOptions.name}`
|
|
13675
13810
|
);
|
|
@@ -13688,13 +13823,13 @@ async function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspe
|
|
|
13688
13823
|
modules: [
|
|
13689
13824
|
{
|
|
13690
13825
|
type: "ESModule",
|
|
13691
|
-
path:
|
|
13826
|
+
path: path7.join(miniflareModulesRoot, WRAPPER_PATH),
|
|
13692
13827
|
contents: wrappers.join("\n")
|
|
13693
13828
|
},
|
|
13694
13829
|
{
|
|
13695
13830
|
type: "ESModule",
|
|
13696
|
-
path:
|
|
13697
|
-
contents:
|
|
13831
|
+
path: path7.join(miniflareModulesRoot, RUNNER_PATH),
|
|
13832
|
+
contents: fs4.readFileSync(
|
|
13698
13833
|
fileURLToPath2(new URL(RUNNER_PATH, import.meta.url))
|
|
13699
13834
|
)
|
|
13700
13835
|
}
|
|
@@ -13706,18 +13841,18 @@ async function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspe
|
|
|
13706
13841
|
async unsafeModuleFallbackService(request) {
|
|
13707
13842
|
const url = new URL(request.url);
|
|
13708
13843
|
const rawSpecifier = url.searchParams.get("rawSpecifier");
|
|
13709
|
-
|
|
13844
|
+
assert7(
|
|
13710
13845
|
rawSpecifier,
|
|
13711
13846
|
`Unexpected error: no specifier in request to module fallback service.`
|
|
13712
13847
|
);
|
|
13713
13848
|
const match = additionalModuleRE.exec(rawSpecifier);
|
|
13714
|
-
|
|
13849
|
+
assert7(match, `Unexpected error: no match for module: ${rawSpecifier}.`);
|
|
13715
13850
|
const [full, moduleType, modulePath] = match;
|
|
13716
|
-
|
|
13851
|
+
assert7(
|
|
13717
13852
|
moduleType,
|
|
13718
13853
|
`Unexpected error: module type not found in reference: ${full}.`
|
|
13719
13854
|
);
|
|
13720
|
-
|
|
13855
|
+
assert7(
|
|
13721
13856
|
modulePath,
|
|
13722
13857
|
`Unexpected error: module path not found in reference: ${full}.`
|
|
13723
13858
|
);
|
|
@@ -13747,9 +13882,9 @@ async function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspe
|
|
|
13747
13882
|
};
|
|
13748
13883
|
}
|
|
13749
13884
|
function getPreviewModules(main, modulesRules) {
|
|
13750
|
-
|
|
13751
|
-
const rootPath =
|
|
13752
|
-
const entryPath =
|
|
13885
|
+
assert7(modulesRules, `Unexpected error: 'modulesRules' is undefined`);
|
|
13886
|
+
const rootPath = path7.dirname(main);
|
|
13887
|
+
const entryPath = path7.basename(main);
|
|
13753
13888
|
return {
|
|
13754
13889
|
rootPath,
|
|
13755
13890
|
modules: [
|
|
@@ -13758,9 +13893,9 @@ function getPreviewModules(main, modulesRules) {
|
|
|
13758
13893
|
path: entryPath
|
|
13759
13894
|
},
|
|
13760
13895
|
...modulesRules.flatMap(
|
|
13761
|
-
({ type, include }) => globSync(include, { cwd: rootPath, ignore: entryPath }).map((
|
|
13896
|
+
({ type, include }) => globSync(include, { cwd: rootPath, ignore: entryPath }).map((path11) => ({
|
|
13762
13897
|
type,
|
|
13763
|
-
path:
|
|
13898
|
+
path: path11
|
|
13764
13899
|
}))
|
|
13765
13900
|
)
|
|
13766
13901
|
]
|
|
@@ -13858,11 +13993,16 @@ async function maybeStartOrUpdateMixedModeSession(workerConfig) {
|
|
|
13858
13993
|
const workerRemoteBindings = experimental_pickRemoteBindings(
|
|
13859
13994
|
unstable_convertConfigBindingsToStartWorkerBindings(workerConfig) ?? {}
|
|
13860
13995
|
);
|
|
13861
|
-
|
|
13996
|
+
assert7(workerConfig.name, "Found workerConfig without a name");
|
|
13862
13997
|
let mixedModeSession = mixedModeSessionsMap.get(workerConfig.name);
|
|
13863
13998
|
if (mixedModeSession === void 0) {
|
|
13864
13999
|
if (Object.keys(workerRemoteBindings).length > 0) {
|
|
13865
|
-
mixedModeSession = await experimental_startMixedModeSession(
|
|
14000
|
+
mixedModeSession = await experimental_startMixedModeSession(
|
|
14001
|
+
workerRemoteBindings,
|
|
14002
|
+
{
|
|
14003
|
+
workerName: workerConfig.name
|
|
14004
|
+
}
|
|
14005
|
+
);
|
|
13866
14006
|
mixedModeSessionsMap.set(workerConfig.name, mixedModeSession);
|
|
13867
14007
|
}
|
|
13868
14008
|
} else {
|
|
@@ -13873,14 +14013,14 @@ async function maybeStartOrUpdateMixedModeSession(workerConfig) {
|
|
|
13873
14013
|
}
|
|
13874
14014
|
|
|
13875
14015
|
// src/plugin-config.ts
|
|
13876
|
-
import
|
|
13877
|
-
import * as
|
|
14016
|
+
import assert9 from "node:assert";
|
|
14017
|
+
import * as path9 from "node:path";
|
|
13878
14018
|
import * as vite6 from "vite";
|
|
13879
14019
|
|
|
13880
14020
|
// src/workers-configs.ts
|
|
13881
|
-
import
|
|
13882
|
-
import * as
|
|
13883
|
-
import * as
|
|
14021
|
+
import assert8 from "node:assert";
|
|
14022
|
+
import * as fs5 from "node:fs";
|
|
14023
|
+
import * as path8 from "node:path";
|
|
13884
14024
|
import { unstable_readConfig as unstable_readConfig2 } from "wrangler";
|
|
13885
14025
|
var nonApplicableWorkerConfigs = {
|
|
13886
14026
|
/**
|
|
@@ -13975,7 +14115,7 @@ function getWarningForWorkersConfigs(configs) {
|
|
|
13975
14115
|
const lines2 = [
|
|
13976
14116
|
`
|
|
13977
14117
|
|
|
13978
|
-
\x1B[43mWARNING\x1B[0m: your worker config${configs.entryWorker.config.configPath ? ` (at \`${
|
|
14118
|
+
\x1B[43mWARNING\x1B[0m: your worker config${configs.entryWorker.config.configPath ? ` (at \`${path8.relative("", configs.entryWorker.config.configPath)}\`)` : ""} contains the following configuration options which are ignored since they are not applicable when using Vite:`
|
|
13979
14119
|
];
|
|
13980
14120
|
nonApplicableLines.forEach((line) => lines2.push(line));
|
|
13981
14121
|
lines2.push("");
|
|
@@ -13989,7 +14129,7 @@ function getWarningForWorkersConfigs(configs) {
|
|
|
13989
14129
|
);
|
|
13990
14130
|
if (nonApplicableLines.length > 0) {
|
|
13991
14131
|
lines.push(
|
|
13992
|
-
` - (${isEntryWorker ? "entry" : "auxiliary"}) worker${workerConfig.config.name ? ` "${workerConfig.config.name}"` : ""}${workerConfig.config.configPath ? ` (config at \`${
|
|
14132
|
+
` - (${isEntryWorker ? "entry" : "auxiliary"}) worker${workerConfig.config.name ? ` "${workerConfig.config.name}"` : ""}${workerConfig.config.configPath ? ` (config at \`${path8.relative("", workerConfig.config.configPath)}\`)` : ""}`
|
|
13993
14133
|
);
|
|
13994
14134
|
nonApplicableLines.forEach((line) => lines.push(line));
|
|
13995
14135
|
}
|
|
@@ -14070,7 +14210,7 @@ function getWorkerConfig(configPath, env2, mixedModeEnabled, opts) {
|
|
|
14070
14210
|
if (!config.main) {
|
|
14071
14211
|
throw new Error(missingFieldErrorMessage(`'main'`, configPath, env2));
|
|
14072
14212
|
}
|
|
14073
|
-
const mainStat =
|
|
14213
|
+
const mainStat = fs5.statSync(config.main, { throwIfNoEntry: false });
|
|
14074
14214
|
if (!mainStat) {
|
|
14075
14215
|
throw new Error(
|
|
14076
14216
|
`The provided Wrangler config main field (${config.main}) doesn't point to an existing file`
|
|
@@ -14094,17 +14234,17 @@ function getWorkerConfig(configPath, env2, mixedModeEnabled, opts) {
|
|
|
14094
14234
|
}
|
|
14095
14235
|
function getValidatedWranglerConfigPath(root, requestedConfigPath, isForAuxiliaryWorker = false) {
|
|
14096
14236
|
if (requestedConfigPath) {
|
|
14097
|
-
const configPath2 =
|
|
14237
|
+
const configPath2 = path8.resolve(root, requestedConfigPath);
|
|
14098
14238
|
const forAuxiliaryWorkerErrorMessage = isForAuxiliaryWorker ? " requested for one of your auxiliary workers" : "";
|
|
14099
14239
|
const errorMessagePrefix = `The provided configPath (${configPath2})${forAuxiliaryWorkerErrorMessage}`;
|
|
14100
|
-
const fileExtension =
|
|
14240
|
+
const fileExtension = path8.extname(configPath2).slice(1);
|
|
14101
14241
|
if (!allowedWranglerConfigExtensions.includes(fileExtension)) {
|
|
14102
14242
|
const foundExtensionMessage = !fileExtension ? "no extension found" : `"${fileExtension}" found`;
|
|
14103
14243
|
throw new Error(
|
|
14104
14244
|
`${errorMessagePrefix} doesn't point to a file with the correct file extension. It should point to a jsonc, json or toml file (${foundExtensionMessage} instead)`
|
|
14105
14245
|
);
|
|
14106
14246
|
}
|
|
14107
|
-
const mainStat =
|
|
14247
|
+
const mainStat = fs5.statSync(configPath2, { throwIfNoEntry: false });
|
|
14108
14248
|
if (!mainStat) {
|
|
14109
14249
|
throw new Error(
|
|
14110
14250
|
`${errorMessagePrefix} doesn't point to an existing file`
|
|
@@ -14117,7 +14257,7 @@ function getValidatedWranglerConfigPath(root, requestedConfigPath, isForAuxiliar
|
|
|
14117
14257
|
}
|
|
14118
14258
|
return configPath2;
|
|
14119
14259
|
}
|
|
14120
|
-
|
|
14260
|
+
assert8(
|
|
14121
14261
|
isForAuxiliaryWorker === false,
|
|
14122
14262
|
"Unexpected Error: trying to find the wrangler config for an auxiliary worker"
|
|
14123
14263
|
);
|
|
@@ -14131,8 +14271,8 @@ function getValidatedWranglerConfigPath(root, requestedConfigPath, isForAuxiliar
|
|
|
14131
14271
|
}
|
|
14132
14272
|
function findWranglerConfig(root) {
|
|
14133
14273
|
for (const extension of allowedWranglerConfigExtensions) {
|
|
14134
|
-
const configPath =
|
|
14135
|
-
if (
|
|
14274
|
+
const configPath = path8.join(root, `wrangler.${extension}`);
|
|
14275
|
+
if (fs5.existsSync(configPath)) {
|
|
14136
14276
|
return configPath;
|
|
14137
14277
|
}
|
|
14138
14278
|
}
|
|
@@ -14147,7 +14287,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
14147
14287
|
const configPaths = /* @__PURE__ */ new Set();
|
|
14148
14288
|
const persistState = pluginConfig.persistState ?? true;
|
|
14149
14289
|
const experimental = pluginConfig.experimental ?? {};
|
|
14150
|
-
const root = userConfig.root ?
|
|
14290
|
+
const root = userConfig.root ? path9.resolve(userConfig.root) : process.cwd();
|
|
14151
14291
|
const { CLOUDFLARE_ENV: cloudflareEnv } = vite6.loadEnv(
|
|
14152
14292
|
viteEnv.mode,
|
|
14153
14293
|
root,
|
|
@@ -14201,7 +14341,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
14201
14341
|
}
|
|
14202
14342
|
);
|
|
14203
14343
|
auxiliaryWorkersResolvedConfigs.push(workerResolvedConfig);
|
|
14204
|
-
|
|
14344
|
+
assert9(
|
|
14205
14345
|
workerResolvedConfig.type === "worker",
|
|
14206
14346
|
"Unexpected error: received AssetsOnlyResult with auxiliary workers."
|
|
14207
14347
|
);
|
|
@@ -14267,14 +14407,14 @@ function handleWebSocket(httpServer, getFetcher) {
|
|
|
14267
14407
|
}
|
|
14268
14408
|
|
|
14269
14409
|
// src/worker-environments-validation.ts
|
|
14270
|
-
import
|
|
14410
|
+
import assert10 from "node:assert";
|
|
14271
14411
|
function validateWorkerEnvironmentsResolvedConfigs(resolvedPluginConfig, resolvedViteConfig) {
|
|
14272
14412
|
const workersEnvironmentNames = Object.keys(resolvedPluginConfig.workers);
|
|
14273
14413
|
const disallowedEnvsConfigs = /* @__PURE__ */ new Map();
|
|
14274
14414
|
for (const envName of workersEnvironmentNames) {
|
|
14275
14415
|
const workerEnvConfig = resolvedViteConfig.environments[envName];
|
|
14276
|
-
|
|
14277
|
-
const { optimizeDeps, resolve:
|
|
14416
|
+
assert10(workerEnvConfig, `Missing environment config for "${envName}"`);
|
|
14417
|
+
const { optimizeDeps, resolve: resolve8 } = workerEnvConfig;
|
|
14278
14418
|
const disallowedConfig = {};
|
|
14279
14419
|
const disallowedOptimizeDepsExcludeEntries = (optimizeDeps.exclude ?? []).filter((entry) => {
|
|
14280
14420
|
if (cloudflareBuiltInModules.includes(entry)) {
|
|
@@ -14291,8 +14431,8 @@ function validateWorkerEnvironmentsResolvedConfigs(resolvedPluginConfig, resolve
|
|
|
14291
14431
|
if (disallowedOptimizeDepsExcludeEntries.length > 0) {
|
|
14292
14432
|
disallowedConfig.optimizeDepsExclude = disallowedOptimizeDepsExcludeEntries;
|
|
14293
14433
|
}
|
|
14294
|
-
if (
|
|
14295
|
-
disallowedConfig.resolveExternal =
|
|
14434
|
+
if (resolve8.external === true || resolve8.external.length > 0) {
|
|
14435
|
+
disallowedConfig.resolveExternal = resolve8.external;
|
|
14296
14436
|
}
|
|
14297
14437
|
if (Object.keys(disallowedConfig).length > 0) {
|
|
14298
14438
|
disallowedEnvsConfigs.set(envName, disallowedConfig);
|
|
@@ -14325,7 +14465,6 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14325
14465
|
let resolvedViteConfig;
|
|
14326
14466
|
const additionalModulePaths = /* @__PURE__ */ new Set();
|
|
14327
14467
|
const nodeJsCompatWarningsMap = /* @__PURE__ */ new Map();
|
|
14328
|
-
let hasClientBuild = false;
|
|
14329
14468
|
return [
|
|
14330
14469
|
{
|
|
14331
14470
|
name: "vite-plugin-cloudflare",
|
|
@@ -14349,8 +14488,19 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14349
14488
|
console.warn(workersConfigsWarning);
|
|
14350
14489
|
}
|
|
14351
14490
|
}
|
|
14491
|
+
const defaultDeniedFiles = [
|
|
14492
|
+
".env",
|
|
14493
|
+
".env.*",
|
|
14494
|
+
"*.{crt,pem}",
|
|
14495
|
+
"**/.git/**"
|
|
14496
|
+
];
|
|
14352
14497
|
return {
|
|
14353
14498
|
appType: "custom",
|
|
14499
|
+
server: {
|
|
14500
|
+
fs: {
|
|
14501
|
+
deny: [...defaultDeniedFiles, ".dev.vars", ".dev.vars.*"]
|
|
14502
|
+
}
|
|
14503
|
+
},
|
|
14354
14504
|
environments: resolvedPluginConfig.type === "workers" ? {
|
|
14355
14505
|
...Object.fromEntries(
|
|
14356
14506
|
Object.entries(resolvedPluginConfig.workers).map(
|
|
@@ -14360,7 +14510,10 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14360
14510
|
createCloudflareEnvironmentOptions(
|
|
14361
14511
|
workerConfig,
|
|
14362
14512
|
userConfig,
|
|
14363
|
-
|
|
14513
|
+
{
|
|
14514
|
+
name: environmentName,
|
|
14515
|
+
isEntry: resolvedPluginConfig.type === "workers" && environmentName === resolvedPluginConfig.entryWorkerEnvironmentName
|
|
14516
|
+
}
|
|
14364
14517
|
)
|
|
14365
14518
|
];
|
|
14366
14519
|
}
|
|
@@ -14373,33 +14526,7 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14373
14526
|
}
|
|
14374
14527
|
} : void 0,
|
|
14375
14528
|
builder: {
|
|
14376
|
-
buildApp: userConfig.builder?.buildApp ?? (
|
|
14377
|
-
const clientEnvironment = builder.environments.client;
|
|
14378
|
-
const defaultHtmlPath = path9.resolve(
|
|
14379
|
-
builder.config.root,
|
|
14380
|
-
"index.html"
|
|
14381
|
-
);
|
|
14382
|
-
if (clientEnvironment && (clientEnvironment.config.build.rollupOptions.input || fs5.existsSync(defaultHtmlPath))) {
|
|
14383
|
-
await builder.build(clientEnvironment);
|
|
14384
|
-
}
|
|
14385
|
-
if (resolvedPluginConfig.type === "workers") {
|
|
14386
|
-
const workerEnvironments = Object.keys(
|
|
14387
|
-
resolvedPluginConfig.workers
|
|
14388
|
-
).map((environmentName) => {
|
|
14389
|
-
const environment = builder.environments[environmentName];
|
|
14390
|
-
assert10(
|
|
14391
|
-
environment,
|
|
14392
|
-
`${environmentName} environment not found`
|
|
14393
|
-
);
|
|
14394
|
-
return environment;
|
|
14395
|
-
});
|
|
14396
|
-
await Promise.all(
|
|
14397
|
-
workerEnvironments.map(
|
|
14398
|
-
(environment) => builder.build(environment)
|
|
14399
|
-
)
|
|
14400
|
-
);
|
|
14401
|
-
}
|
|
14402
|
-
})
|
|
14529
|
+
buildApp: userConfig.builder?.buildApp ?? createBuildApp(resolvedPluginConfig)
|
|
14403
14530
|
}
|
|
14404
14531
|
};
|
|
14405
14532
|
},
|
|
@@ -14431,18 +14558,18 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14431
14558
|
{ type: "ESModule", globs: ["**/*.js", "**/*.mjs"] }
|
|
14432
14559
|
];
|
|
14433
14560
|
const isEntryWorker = this.environment.name === resolvedPluginConfig.entryWorkerEnvironmentName;
|
|
14434
|
-
if (isEntryWorker
|
|
14561
|
+
if (isEntryWorker) {
|
|
14435
14562
|
const workerOutputDirectory = this.environment.config.build.outDir;
|
|
14436
14563
|
const clientOutputDirectory = resolvedViteConfig.environments.client?.build.outDir;
|
|
14437
|
-
|
|
14564
|
+
assert11(
|
|
14438
14565
|
clientOutputDirectory,
|
|
14439
14566
|
"Unexpected error: client output directory is undefined"
|
|
14440
14567
|
);
|
|
14441
14568
|
workerConfig.assets = {
|
|
14442
14569
|
...workerConfig.assets,
|
|
14443
|
-
directory:
|
|
14444
|
-
|
|
14445
|
-
|
|
14570
|
+
directory: path10.relative(
|
|
14571
|
+
path10.resolve(resolvedViteConfig.root, workerOutputDirectory),
|
|
14572
|
+
path10.resolve(resolvedViteConfig.root, clientOutputDirectory)
|
|
14446
14573
|
)
|
|
14447
14574
|
};
|
|
14448
14575
|
} else {
|
|
@@ -14490,15 +14617,12 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14490
14617
|
});
|
|
14491
14618
|
},
|
|
14492
14619
|
writeBundle() {
|
|
14493
|
-
if (this.environment.name === "client") {
|
|
14494
|
-
hasClientBuild = true;
|
|
14495
|
-
}
|
|
14496
14620
|
if (this.environment.name === (resolvedPluginConfig.type === "assets-only" ? "client" : resolvedPluginConfig.entryWorkerEnvironmentName)) {
|
|
14497
14621
|
writeDeployConfig(resolvedPluginConfig, resolvedViteConfig);
|
|
14498
14622
|
}
|
|
14499
14623
|
},
|
|
14500
14624
|
hotUpdate(options) {
|
|
14501
|
-
const changedFilePath =
|
|
14625
|
+
const changedFilePath = path10.resolve(options.file);
|
|
14502
14626
|
if (resolvedPluginConfig.configPaths.has(changedFilePath) || hasDotDevDotVarsFileChanged(resolvedPluginConfig, changedFilePath) || hasAssetsConfigChanged(
|
|
14503
14627
|
resolvedPluginConfig,
|
|
14504
14628
|
resolvedViteConfig,
|
|
@@ -14526,7 +14650,7 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14526
14650
|
await initRunners(resolvedPluginConfig, viteDevServer, miniflare);
|
|
14527
14651
|
if (viteDevServer.httpServer) {
|
|
14528
14652
|
handleWebSocket(viteDevServer.httpServer, async () => {
|
|
14529
|
-
|
|
14653
|
+
assert11(miniflare, `Miniflare not defined`);
|
|
14530
14654
|
const routerWorker = await miniflare.getWorker(ROUTER_WORKER_NAME);
|
|
14531
14655
|
return routerWorker.fetch;
|
|
14532
14656
|
});
|
|
@@ -14534,7 +14658,7 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14534
14658
|
return () => {
|
|
14535
14659
|
viteDevServer.middlewares.use(async (req, res, next) => {
|
|
14536
14660
|
try {
|
|
14537
|
-
|
|
14661
|
+
assert11(miniflare, `Miniflare not defined`);
|
|
14538
14662
|
const request = createRequest(req, res);
|
|
14539
14663
|
let response;
|
|
14540
14664
|
if (req[kRequestType] === "asset") {
|
|
@@ -14599,6 +14723,20 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14599
14723
|
});
|
|
14600
14724
|
}
|
|
14601
14725
|
},
|
|
14726
|
+
// Plugin to provide a fallback entry file
|
|
14727
|
+
{
|
|
14728
|
+
name: "vite-plugin-cloudflare:fallback-entry",
|
|
14729
|
+
resolveId(source) {
|
|
14730
|
+
if (source === "virtual:__cloudflare_fallback_entry__") {
|
|
14731
|
+
return `\0virtual:__cloudflare_fallback_entry__`;
|
|
14732
|
+
}
|
|
14733
|
+
},
|
|
14734
|
+
load(id) {
|
|
14735
|
+
if (id === "\0virtual:__cloudflare_fallback_entry__") {
|
|
14736
|
+
return ``;
|
|
14737
|
+
}
|
|
14738
|
+
}
|
|
14739
|
+
},
|
|
14602
14740
|
// Plugin to support `.wasm?init` extension
|
|
14603
14741
|
{
|
|
14604
14742
|
name: "vite-plugin-cloudflare:wasm-helper",
|
|
@@ -14658,7 +14796,7 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14658
14796
|
for (const match of matches) {
|
|
14659
14797
|
magicString ??= new MagicString(code);
|
|
14660
14798
|
const [full, _, modulePath] = match;
|
|
14661
|
-
|
|
14799
|
+
assert11(
|
|
14662
14800
|
modulePath,
|
|
14663
14801
|
`Unexpected error: module path not found in reference ${full}.`
|
|
14664
14802
|
);
|
|
@@ -14672,13 +14810,13 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14672
14810
|
}
|
|
14673
14811
|
const referenceId = this.emitFile({
|
|
14674
14812
|
type: "asset",
|
|
14675
|
-
name:
|
|
14813
|
+
name: path10.basename(modulePath),
|
|
14676
14814
|
originalFileName: modulePath,
|
|
14677
14815
|
source
|
|
14678
14816
|
});
|
|
14679
14817
|
const emittedFileName = this.getFileName(referenceId);
|
|
14680
14818
|
const relativePath = vite7.normalizePath(
|
|
14681
|
-
|
|
14819
|
+
path10.relative(path10.dirname(chunk.fileName), emittedFileName)
|
|
14682
14820
|
);
|
|
14683
14821
|
const importPath = relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
|
|
14684
14822
|
magicString.update(
|
|
@@ -14743,7 +14881,7 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14743
14881
|
return this.resolve(source, importer, options);
|
|
14744
14882
|
}
|
|
14745
14883
|
if (this.environment.mode === "dev") {
|
|
14746
|
-
|
|
14884
|
+
assert11(
|
|
14747
14885
|
this.environment.depsOptimizer,
|
|
14748
14886
|
"depsOptimizer is required in dev mode"
|
|
14749
14887
|
);
|
|
@@ -14839,7 +14977,7 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14839
14977
|
addDebugToVitePrintUrls(vitePreviewServer);
|
|
14840
14978
|
}
|
|
14841
14979
|
const workerNames = workerConfigs.map((worker) => {
|
|
14842
|
-
|
|
14980
|
+
assert11(worker.name, "Expected the Worker to have a name");
|
|
14843
14981
|
return worker.name;
|
|
14844
14982
|
});
|
|
14845
14983
|
vitePreviewServer.middlewares.use(async (req, res, next) => {
|
|
@@ -14874,13 +15012,13 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14874
15012
|
setup(build) {
|
|
14875
15013
|
build.onResolve(
|
|
14876
15014
|
{ filter: NODEJS_MODULES_RE },
|
|
14877
|
-
({ path:
|
|
14878
|
-
if (isNodeAls(workerConfig) && isNodeAlsModule(
|
|
15015
|
+
({ path: path11, importer }) => {
|
|
15016
|
+
if (isNodeAls(workerConfig) && isNodeAlsModule(path11)) {
|
|
14879
15017
|
return;
|
|
14880
15018
|
}
|
|
14881
15019
|
const nodeJsCompatWarnings = nodeJsCompatWarningsMap.get(workerConfig);
|
|
14882
|
-
nodeJsCompatWarnings?.registerImport(
|
|
14883
|
-
return { path:
|
|
15020
|
+
nodeJsCompatWarnings?.registerImport(path11, importer);
|
|
15021
|
+
return { path: path11, external: true };
|
|
14884
15022
|
}
|
|
14885
15023
|
);
|
|
14886
15024
|
}
|
|
@@ -14923,7 +15061,7 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14923
15061
|
}
|
|
14924
15062
|
];
|
|
14925
15063
|
function getWorkerConfig2(environmentName) {
|
|
14926
|
-
|
|
15064
|
+
assert11(resolvedPluginConfig, "Expected resolvedPluginConfig to be defined");
|
|
14927
15065
|
return resolvedPluginConfig.type !== "assets-only" ? resolvedPluginConfig.workers[environmentName] : void 0;
|
|
14928
15066
|
}
|
|
14929
15067
|
}
|
|
@@ -14937,7 +15075,7 @@ async function getInputInspectorPortOption(pluginConfig, viteServer) {
|
|
|
14937
15075
|
const inputInspectorPort = pluginConfig.inspectorPort ?? await getFirstAvailablePort(DEFAULT_INSPECTOR_PORT);
|
|
14938
15076
|
if (pluginConfig.inspectorPort === void 0 && inputInspectorPort !== DEFAULT_INSPECTOR_PORT) {
|
|
14939
15077
|
viteServer.config.logger.warn(
|
|
14940
|
-
|
|
15078
|
+
colors4.dim(
|
|
14941
15079
|
`Default inspector port ${DEFAULT_INSPECTOR_PORT} not available, using ${inputInspectorPort} instead
|
|
14942
15080
|
`
|
|
14943
15081
|
)
|
|
@@ -14953,19 +15091,19 @@ async function getResolvedInspectorPort(pluginConfig) {
|
|
|
14953
15091
|
return null;
|
|
14954
15092
|
}
|
|
14955
15093
|
function getDotDevDotVarsContent(configPath, cloudflareEnv) {
|
|
14956
|
-
const configDir =
|
|
15094
|
+
const configDir = path10.dirname(configPath);
|
|
14957
15095
|
const defaultDotDevDotVarsPath = `${configDir}/.dev.vars`;
|
|
14958
15096
|
const inputDotDevDotVarsPath = `${defaultDotDevDotVarsPath}${cloudflareEnv ? `.${cloudflareEnv}` : ""}`;
|
|
14959
|
-
const targetPath =
|
|
15097
|
+
const targetPath = fs6.existsSync(inputDotDevDotVarsPath) ? inputDotDevDotVarsPath : fs6.existsSync(defaultDotDevDotVarsPath) ? defaultDotDevDotVarsPath : null;
|
|
14960
15098
|
if (targetPath) {
|
|
14961
|
-
const dotDevDotVarsContent =
|
|
15099
|
+
const dotDevDotVarsContent = fs6.readFileSync(targetPath);
|
|
14962
15100
|
return dotDevDotVarsContent;
|
|
14963
15101
|
}
|
|
14964
15102
|
return null;
|
|
14965
15103
|
}
|
|
14966
15104
|
function hasDotDevDotVarsFileChanged(resolvedPluginConfig, changedFilePath) {
|
|
14967
15105
|
return [...resolvedPluginConfig.configPaths].some((configPath) => {
|
|
14968
|
-
const dotDevDotVars =
|
|
15106
|
+
const dotDevDotVars = path10.join(path10.dirname(configPath), ".dev.vars");
|
|
14969
15107
|
if (dotDevDotVars === changedFilePath) {
|
|
14970
15108
|
return true;
|
|
14971
15109
|
}
|