@cloudflare/vite-plugin 1.7.5 → 1.9.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/router-worker.js +4 -2
- package/dist/index.js +51 -55
- package/dist/runner-worker/index.js +437 -574
- package/package.json +6 -6
|
@@ -6168,7 +6168,7 @@ var worker_default = {
|
|
|
6168
6168
|
dispatchType: "worker" /* WORKER */
|
|
6169
6169
|
});
|
|
6170
6170
|
let shouldBlockNonImageResponse = false;
|
|
6171
|
-
if (url.pathname
|
|
6171
|
+
if (url.pathname.endsWith("/_next/image")) {
|
|
6172
6172
|
const queryURLParam = url.searchParams.get("url");
|
|
6173
6173
|
if (queryURLParam && !queryURLParam.startsWith("/")) {
|
|
6174
6174
|
if (maybeSecondRequest.method !== "GET" || maybeSecondRequest.headers.get("sec-fetch-dest") !== "image") {
|
|
@@ -6179,7 +6179,9 @@ var worker_default = {
|
|
|
6179
6179
|
}
|
|
6180
6180
|
if (shouldBlockNonImageResponse) {
|
|
6181
6181
|
const resp = await env.USER_WORKER.fetch(maybeSecondRequest);
|
|
6182
|
-
|
|
6182
|
+
const isImage = resp.headers.get("content-type")?.startsWith("image/");
|
|
6183
|
+
const isPlainText = resp.headers.get("content-type") === "text/plain";
|
|
6184
|
+
if (!isImage && !isPlainText && resp.status !== 304) {
|
|
6183
6185
|
analytics.setData({ abuseMitigationBlocked: true });
|
|
6184
6186
|
return new Response("Blocked", { status: 403 });
|
|
6185
6187
|
}
|
package/dist/index.js
CHANGED
|
@@ -13361,7 +13361,8 @@ function createCloudflareEnvironmentOptions(workerConfig, userConfig, environmen
|
|
|
13361
13361
|
optimizeDeps: {
|
|
13362
13362
|
// Note: ssr pre-bundling is opt-in and we need to enable it by setting `noDiscovery` to false
|
|
13363
13363
|
noDiscovery: false,
|
|
13364
|
-
|
|
13364
|
+
// We need to normalize the path as it is treated as a glob and backslashes are therefore treated as escape characters.
|
|
13365
|
+
entries: vite2.normalizePath(workerConfig.main),
|
|
13365
13366
|
exclude: [...cloudflareBuiltInModules],
|
|
13366
13367
|
esbuildOptions: {
|
|
13367
13368
|
platform: "neutral",
|
|
@@ -13853,7 +13854,7 @@ async function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspe
|
|
|
13853
13854
|
}
|
|
13854
13855
|
);
|
|
13855
13856
|
const { externalWorkers: externalWorkers2 } = miniflareWorkerOptions;
|
|
13856
|
-
const
|
|
13857
|
+
const workerOptions = miniflareWorkerOptions.workerOptions;
|
|
13857
13858
|
return {
|
|
13858
13859
|
externalWorkers: externalWorkers2,
|
|
13859
13860
|
worker: {
|
|
@@ -14084,7 +14085,7 @@ async function getPreviewMiniflareOptions(resolvedPluginConfig, vitePreviewServe
|
|
|
14084
14085
|
}
|
|
14085
14086
|
);
|
|
14086
14087
|
const { externalWorkers } = miniflareWorkerOptions;
|
|
14087
|
-
const {
|
|
14088
|
+
const { modulesRules, ...workerOptions } = miniflareWorkerOptions.workerOptions;
|
|
14088
14089
|
logUnknownTails(
|
|
14089
14090
|
workerOptions.tails,
|
|
14090
14091
|
resolvedPluginConfig.workers,
|
|
@@ -14611,6 +14612,44 @@ function assertIsPreview(resolvedPluginConfig) {
|
|
|
14611
14612
|
);
|
|
14612
14613
|
}
|
|
14613
14614
|
|
|
14615
|
+
// src/vite-config.ts
|
|
14616
|
+
import assert10 from "node:assert";
|
|
14617
|
+
function validateWorkerEnvironmentOptions(resolvedPluginConfig, resolvedViteConfig) {
|
|
14618
|
+
const workerEnvironmentNames = Object.keys(resolvedPluginConfig.workers);
|
|
14619
|
+
const disallowedEnvironmentOptionsMap = /* @__PURE__ */ new Map();
|
|
14620
|
+
for (const environmentName of workerEnvironmentNames) {
|
|
14621
|
+
const environmentOptions = resolvedViteConfig.environments[environmentName];
|
|
14622
|
+
assert10(
|
|
14623
|
+
environmentOptions,
|
|
14624
|
+
`Missing environment config for "${environmentName}"`
|
|
14625
|
+
);
|
|
14626
|
+
const { resolve: resolve8 } = environmentOptions;
|
|
14627
|
+
const disallowedEnvironmentOptions = {};
|
|
14628
|
+
if (resolve8.external === true || resolve8.external.length) {
|
|
14629
|
+
disallowedEnvironmentOptions.resolveExternal = resolve8.external;
|
|
14630
|
+
}
|
|
14631
|
+
if (Object.keys(disallowedEnvironmentOptions).length) {
|
|
14632
|
+
disallowedEnvironmentOptionsMap.set(
|
|
14633
|
+
environmentName,
|
|
14634
|
+
disallowedEnvironmentOptions
|
|
14635
|
+
);
|
|
14636
|
+
}
|
|
14637
|
+
}
|
|
14638
|
+
if (disallowedEnvironmentOptionsMap.size) {
|
|
14639
|
+
const errorMessage = `The following environment options are incompatible with the Cloudflare Vite plugin:
|
|
14640
|
+
${[
|
|
14641
|
+
...disallowedEnvironmentOptionsMap
|
|
14642
|
+
].map(
|
|
14643
|
+
([environmentName, disallowedEnvironmentOptions]) => disallowedEnvironmentOptions.resolveExternal && ` - "${environmentName}" environment: \`resolve.external\`: ${JSON.stringify(disallowedEnvironmentOptions.resolveExternal)}
|
|
14644
|
+
`
|
|
14645
|
+
).join(
|
|
14646
|
+
""
|
|
14647
|
+
)}To resolve this issue, avoid setting \`resolve.external\` in your Cloudflare Worker environments.
|
|
14648
|
+
`;
|
|
14649
|
+
throw new Error(errorMessage);
|
|
14650
|
+
}
|
|
14651
|
+
}
|
|
14652
|
+
|
|
14614
14653
|
// src/websockets.ts
|
|
14615
14654
|
import { createHeaders } from "@mjackson/node-fetch-server";
|
|
14616
14655
|
import { coupleWebSocket } from "miniflare";
|
|
@@ -14648,57 +14687,6 @@ function handleWebSocket(httpServer, getFetcher) {
|
|
|
14648
14687
|
);
|
|
14649
14688
|
}
|
|
14650
14689
|
|
|
14651
|
-
// src/worker-environments-validation.ts
|
|
14652
|
-
import assert10 from "node:assert";
|
|
14653
|
-
function validateWorkerEnvironmentsResolvedConfigs(resolvedPluginConfig, resolvedViteConfig) {
|
|
14654
|
-
const workersEnvironmentNames = Object.keys(resolvedPluginConfig.workers);
|
|
14655
|
-
const disallowedEnvsConfigs = /* @__PURE__ */ new Map();
|
|
14656
|
-
for (const envName of workersEnvironmentNames) {
|
|
14657
|
-
const workerEnvConfig = resolvedViteConfig.environments[envName];
|
|
14658
|
-
assert10(workerEnvConfig, `Missing environment config for "${envName}"`);
|
|
14659
|
-
const { optimizeDeps, resolve: resolve8 } = workerEnvConfig;
|
|
14660
|
-
const disallowedConfig = {};
|
|
14661
|
-
const disallowedOptimizeDepsExcludeEntries = (optimizeDeps.exclude ?? []).filter((entry) => {
|
|
14662
|
-
if (cloudflareBuiltInModules.includes(entry)) {
|
|
14663
|
-
return false;
|
|
14664
|
-
}
|
|
14665
|
-
if (isNodeAlsModule(entry) && isNodeAls(resolvedPluginConfig.workers[envName])) {
|
|
14666
|
-
return false;
|
|
14667
|
-
}
|
|
14668
|
-
if (NODEJS_MODULES_RE.test(entry) && isNodeCompat(resolvedPluginConfig.workers[envName])) {
|
|
14669
|
-
return false;
|
|
14670
|
-
}
|
|
14671
|
-
return true;
|
|
14672
|
-
});
|
|
14673
|
-
if (disallowedOptimizeDepsExcludeEntries.length > 0) {
|
|
14674
|
-
disallowedConfig.optimizeDepsExclude = disallowedOptimizeDepsExcludeEntries;
|
|
14675
|
-
}
|
|
14676
|
-
if (resolve8.external === true || resolve8.external.length > 0) {
|
|
14677
|
-
disallowedConfig.resolveExternal = resolve8.external;
|
|
14678
|
-
}
|
|
14679
|
-
if (Object.keys(disallowedConfig).length > 0) {
|
|
14680
|
-
disallowedEnvsConfigs.set(envName, disallowedConfig);
|
|
14681
|
-
}
|
|
14682
|
-
}
|
|
14683
|
-
if (disallowedEnvsConfigs.size > 0) {
|
|
14684
|
-
const errorMessage = `The following environment configurations are incompatible with the Cloudflare Vite plugin:
|
|
14685
|
-
${[
|
|
14686
|
-
...disallowedEnvsConfigs
|
|
14687
|
-
].map(
|
|
14688
|
-
([envName, disallowedConfig]) => [
|
|
14689
|
-
disallowedConfig.optimizeDepsExclude ? ` - "${envName}" environment: \`optimizeDeps.exclude\`: ${JSON.stringify(disallowedConfig.optimizeDepsExclude)}
|
|
14690
|
-
` : null,
|
|
14691
|
-
disallowedConfig.resolveExternal ? ` - "${envName}" environment: \`resolve.external\`: ${JSON.stringify(disallowedConfig.resolveExternal)}
|
|
14692
|
-
` : null
|
|
14693
|
-
].join("")
|
|
14694
|
-
).join(
|
|
14695
|
-
""
|
|
14696
|
-
)}To resolve this issue, avoid setting \`optimizeDeps.exclude\` and \`resolve.external\` in your Cloudflare Worker environments.
|
|
14697
|
-
`;
|
|
14698
|
-
throw new Error(errorMessage);
|
|
14699
|
-
}
|
|
14700
|
-
}
|
|
14701
|
-
|
|
14702
14690
|
// src/index.ts
|
|
14703
14691
|
var workersConfigsWarningShown = false;
|
|
14704
14692
|
var miniflare;
|
|
@@ -14778,7 +14766,7 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14778
14766
|
configResolved(config) {
|
|
14779
14767
|
resolvedViteConfig = config;
|
|
14780
14768
|
if (resolvedPluginConfig.type === "workers") {
|
|
14781
|
-
|
|
14769
|
+
validateWorkerEnvironmentOptions(
|
|
14782
14770
|
resolvedPluginConfig,
|
|
14783
14771
|
resolvedViteConfig
|
|
14784
14772
|
);
|
|
@@ -15224,6 +15212,10 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
15224
15212
|
enforce: "pre",
|
|
15225
15213
|
configureServer(viteDevServer) {
|
|
15226
15214
|
assertIsNotPreview(resolvedPluginConfig);
|
|
15215
|
+
const inVscodeJsDebugTerminal = !!process.env.VSCODE_INSPECTOR_OPTIONS;
|
|
15216
|
+
if (inVscodeJsDebugTerminal) {
|
|
15217
|
+
return;
|
|
15218
|
+
}
|
|
15227
15219
|
if (resolvedPluginConfig.type === "workers" && pluginConfig.inspectorPort !== false) {
|
|
15228
15220
|
addDebugToVitePrintUrls(viteDevServer);
|
|
15229
15221
|
}
|
|
@@ -15246,6 +15238,10 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
15246
15238
|
},
|
|
15247
15239
|
async configurePreviewServer(vitePreviewServer) {
|
|
15248
15240
|
assertIsPreview(resolvedPluginConfig);
|
|
15241
|
+
const inVscodeJsDebugTerminal = !!process.env.VSCODE_INSPECTOR_OPTIONS;
|
|
15242
|
+
if (inVscodeJsDebugTerminal) {
|
|
15243
|
+
return;
|
|
15244
|
+
}
|
|
15249
15245
|
if (resolvedPluginConfig.workers.length >= 1 && resolvedPluginConfig.inspectorPort !== false) {
|
|
15250
15246
|
addDebugToVitePrintUrls(vitePreviewServer);
|
|
15251
15247
|
}
|